summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhardythe12015-07-03 12:23:43 +0530
committerhardythe12015-07-03 12:23:43 +0530
commit5a86a20b9de487553d4ef88719fb0fd76a5dd6a7 (patch)
treedb67ac5738a18b921d9a8cf6e86f402703f30bdf
parent37d315828bbfc0f5cabee669d2b9dd8cd17b5154 (diff)
downloadPython-Textbook-Companions-5a86a20b9de487553d4ef88719fb0fd76a5dd6a7.tar.gz
Python-Textbook-Companions-5a86a20b9de487553d4ef88719fb0fd76a5dd6a7.tar.bz2
Python-Textbook-Companions-5a86a20b9de487553d4ef88719fb0fd76a5dd6a7.zip
add/remove books
-rwxr-xr-xA_First_course_in_Programming_with_C/screenshots/chapter141_1.pngbin0 -> 23129 bytes
-rwxr-xr-xA_First_course_in_Programming_with_C/screenshots/chapter142_1.pngbin0 -> 32548 bytes
-rwxr-xr-xA_First_course_in_Programming_with_C/screenshots/chapter143_1.pngbin0 -> 25904 bytes
-rwxr-xr-xA_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter10_2.ipynb1
-rwxr-xr-xA_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter11_2.ipynb1
-rwxr-xr-xA_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter12_2.ipynb1
-rwxr-xr-xA_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter13_2.ipynb1
-rwxr-xr-xA_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter14_2.ipynb1
-rwxr-xr-xA_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter4_2.ipynb1
-rwxr-xr-xA_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter5_2.ipynb1
-rwxr-xr-xA_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter6_2.ipynb1
-rwxr-xr-xA_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter7_2.ipynb1
-rwxr-xr-xA_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter8_2.ipynb1
-rwxr-xr-xA_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter9_2.ipynb1
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits/screenshots/CE_CB_Configuration_ch-2.pngbin0 -> 62709 bytes
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits/screenshots/dc_load_line_Chapter-2.pngbin0 -> 12440 bytes
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits/screenshots/gm_vs_IDSS_ch-6.pngbin0 -> 9143 bytes
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter1.ipynb655
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter11.ipynb59
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter2.ipynb774
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter3.ipynb615
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter4.ipynb92
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter5.ipynb566
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter6.ipynb376
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter7.ipynb244
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter8.ipynb592
-rwxr-xr-xA_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter9.ipynb130
-rwxr-xr-xAdvanced_Mechanics_of_Materials/README.txt10
-rwxr-xr-xAnalog_And_Digital_Electronics/screenshots/Blank.pngbin0 -> 183 bytes
-rwxr-xr-xAnalog_And_Digital_Electronics/screenshots/Blank_1.pngbin0 -> 183 bytes
-rwxr-xr-xAnalog_And_Digital_Electronics/screenshots/Blank_2.pngbin0 -> 183 bytes
-rwxr-xr-xAnalog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter1.ipynb1
-rwxr-xr-xAnalog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter10.ipynb1
-rwxr-xr-xAnalog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter11.ipynb1
-rwxr-xr-xAnalog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter2.ipynb1
-rwxr-xr-xAnalog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter3.ipynb1
-rwxr-xr-xAnalog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter4.ipynb1
-rwxr-xr-xAnalog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter5.ipynb1
-rwxr-xr-xAnalog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter6.ipynb1
-rwxr-xr-xAnalog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter7.ipynb1
-rwxr-xr-xAnalog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter8.ipynb1
-rwxr-xr-xAnalog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter9.ipynb1
-rwxr-xr-xAnalog_Integrated_Circuits/screenshots/chapter2_dc_collector_current.pngbin0 -> 75376 bytes
-rwxr-xr-xAnalog_Integrated_Circuits/screenshots/chapter5_Vout_vs_time_plot.pngbin0 -> 13845 bytes
-rwxr-xr-xAnalog_Integrated_Circuits/screenshots/chapter5_vout_vs_time.pngbin0 -> 65034 bytes
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter1.ipynb417
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter10.ipynb220
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter11.ipynb243
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter12.ipynb55
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter13.ipynb417
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter2.ipynb531
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter3_.ipynb251
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter4.ipynb540
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter5.ipynb701
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter6.ipynb767
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter7.ipynb323
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter8.ipynb152
-rwxr-xr-xAnalog_Integrated_Circuits_by_R.S._Tomar/Chapter9.ipynb958
-rwxr-xr-xC++_By_Example/screenshots/Arrays_1.pngbin0 -> 32344 bytes
-rwxr-xr-xC++_By_Example/screenshots/class_1.pngbin0 -> 43323 bytes
-rwxr-xr-xC++_By_Example/screenshots/factorial_1.pngbin0 -> 31856 bytes
-rwxr-xr-xC++_By_Example_by_Greg__M._Perry/Chapter1_2.ipynb733
-rwxr-xr-xC++_By_Example_by_Greg__M._Perry/Chapter2_2.ipynb756
-rwxr-xr-xC++_By_Example_by_Greg__M._Perry/Chapter3_2.ipynb1969
-rwxr-xr-xC++_By_Example_by_Greg__M._Perry/Chapter4_2.ipynb1073
-rwxr-xr-xC++_By_Example_by_Greg__M._Perry/Chapter5_2.ipynb184
-rwxr-xr-xC++_By_Example_by_Greg__M._Perry/Chapter6_2.ipynb1457
-rwxr-xr-xC++_By_Example_by_Greg__M._Perry/Chapter7_2.ipynb1046
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm/screenshots/Caption-4.pngbin0 -> 76625 bytes
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm/screenshots/Caption-5.pngbin0 -> 87670 bytes
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm/screenshots/Caption-8.pngbin0 -> 87667 bytes
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter10ClassRelationships.ipynb351
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter11AdvancedConcepts.ipynb1117
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter12theStandardLibraryinc++.ipynb580
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter13DataStructuresandApplicationsinc++.ipynb443
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter1Overview.ipynb123
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter2DeclarationsandExpressions.ipynb244
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter3Statements.ipynb635
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter4Array,PointerandStructure.ipynb909
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter5Functions.ipynb844
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter6Preprocessordirectives.ipynb150
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter7StandardCLibraryFunctionsandStandardHeaderFiles.ipynb212
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter8DataAbstractionthroughClassesandUser-DefinedDataTypes.ipynb809
-rwxr-xr-xC++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter9OperatorOverloading.ipynb424
-rwxr-xr-xC_Programming:_A_Modern_Approach/screenshots/Untitled00.pngbin0 -> 70099 bytes
-rwxr-xr-xC_Programming:_A_Modern_Approach/screenshots/Untitled000.pngbin0 -> 66035 bytes
-rwxr-xr-xC_Programming:_A_Modern_Approach/screenshots/Untitled0000.pngbin0 -> 67010 bytes
-rwxr-xr-xC_Programming:_A_Modern_Approach/screenshots/Untitled0000_1.pngbin0 -> 67010 bytes
-rwxr-xr-xC_Programming:_A_Modern_Approach/screenshots/Untitled000_1.pngbin0 -> 66035 bytes
-rwxr-xr-xC_Programming:_A_Modern_Approach/screenshots/Untitled00_1.pngbin0 -> 70099 bytes
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter10.ipynb755
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter11.ipynb81
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter12.ipynb71
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter13.ipynb127
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter15.ipynb83
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter16.ipynb180
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter17.ipynb268
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter19.ipynb322
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter2.ipynb237
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter20.ipynb161
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter22.ipynb158
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter23.ipynb127
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter24.ipynb126
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter26.ipynb288
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter27.ipynb72
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter3.ipynb172
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter4.ipynb216
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter5.ipynb209
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter6.ipynb503
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter7.ipynb154
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter8.ipynb288
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter9.ipynb394
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter10.ipynb755
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter11.ipynb81
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter12.ipynb71
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter13.ipynb127
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter15.ipynb83
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter16.ipynb180
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter17.ipynb268
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter19.ipynb322
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter2.ipynb237
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter20.ipynb161
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter22.ipynb158
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter23.ipynb127
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter24.ipynb126
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter26.ipynb288
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter27.ipynb72
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter3.ipynb172
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter4.ipynb216
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter5.ipynb209
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter6.ipynb503
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter7.ipynb154
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter8.ipynb288
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K._N._King/Chapter9.ipynb394
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/Chapter11.ipynb62
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/Chapter2.ipynb41
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/Chapter3.ipynb293
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/Chapter4.ipynb524
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/Chapter5.ipynb1103
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/Chapter6.ipynb794
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/Chapter7.ipynb557
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/Chapter8.ipynb1027
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/Chapter9.ipynb624
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/screenshots/Screenshot_(18)_1.pngbin0 -> 40384 bytes
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/screenshots/Screenshot_(19)_1.pngbin0 -> 28732 bytes
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/screenshots/Screenshot_(20)_1.pngbin0 -> 40328 bytes
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/screenshots/chapter11.pngbin169980 -> 0 bytes
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/screenshots/chapter11_1.pngbin169980 -> 0 bytes
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/screenshots/chapter2.pngbin147743 -> 0 bytes
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/screenshots/chapter2_1.pngbin147743 -> 0 bytes
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/screenshots/chapter3.pngbin154011 -> 0 bytes
-rwxr-xr-xComputer_Programming,_Theory_and_Practice/screenshots/chapter3_1.pngbin154011 -> 0 bytes
-rwxr-xr-xComputer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_02_Fundamentals_of_C_language_1.ipynb1
-rwxr-xr-xComputer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_03_Input_Output_Functions_and_Statements_1.ipynb1
-rwxr-xr-xComputer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_04_Control_Statements_in_C_1.ipynb1
-rwxr-xr-xComputer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_05_Loop_Control_Structures_In_C_1.ipynb1
-rwxr-xr-xComputer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_06_Arrays_and_Subscripted_Variables_1.ipynb1
-rwxr-xr-xComputer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_07_String_Manipulations_in_C_1.ipynb1
-rwxr-xr-xComputer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_08_Functins_in_C_1.ipynb1
-rwxr-xr-xComputer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_09_Structures_and_Unions_1.ipynb1
-rwxr-xr-xComputer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_11_Files_1.ipynb1
-rwxr-xr-xComputer_Programming_Theory_and_Practice/Chapter11.ipynb62
-rwxr-xr-xComputer_Programming_Theory_and_Practice/Chapter2.ipynb41
-rwxr-xr-xComputer_Programming_Theory_and_Practice/Chapter3.ipynb293
-rwxr-xr-xComputer_Programming_Theory_and_Practice/Chapter4.ipynb524
-rwxr-xr-xComputer_Programming_Theory_and_Practice/Chapter5.ipynb1103
-rwxr-xr-xComputer_Programming_Theory_and_Practice/Chapter6.ipynb794
-rwxr-xr-xComputer_Programming_Theory_and_Practice/Chapter7.ipynb557
-rwxr-xr-xComputer_Programming_Theory_and_Practice/Chapter8.ipynb1027
-rwxr-xr-xComputer_Programming_Theory_and_Practice/Chapter9.ipynb624
-rwxr-xr-xComputer_Programming_Theory_and_Practice/screenshots/chapter11.pngbin169980 -> 0 bytes
-rwxr-xr-xComputer_Programming_Theory_and_Practice/screenshots/chapter2.pngbin147743 -> 0 bytes
-rwxr-xr-xComputer_Programming_Theory_and_Practice/screenshots/chapter3.pngbin154011 -> 0 bytes
-rwxr-xr-xComputer_Programming_Theory_and_Practice_/Chapter11.ipynb62
-rwxr-xr-xComputer_Programming_Theory_and_Practice_/Chapter2.ipynb41
-rwxr-xr-xComputer_Programming_Theory_and_Practice_/Chapter3.ipynb293
-rwxr-xr-xComputer_Programming_Theory_and_Practice_/Chapter4.ipynb524
-rwxr-xr-xComputer_Programming_Theory_and_Practice_/Chapter5.ipynb1103
-rwxr-xr-xComputer_Programming_Theory_and_Practice_/Chapter6.ipynb794
-rwxr-xr-xComputer_Programming_Theory_and_Practice_/Chapter7.ipynb557
-rwxr-xr-xComputer_Programming_Theory_and_Practice_/Chapter8.ipynb1027
-rwxr-xr-xComputer_Programming_Theory_and_Practice_/Chapter9.ipynb624
-rwxr-xr-xComputer_Programming_Theory_and_Practice_/screenshots/chapter11.pngbin169980 -> 0 bytes
-rwxr-xr-xComputer_Programming_Theory_and_Practice_/screenshots/chapter2.pngbin147743 -> 0 bytes
-rwxr-xr-xComputer_Programming_Theory_and_Practice_/screenshots/chapter3.pngbin154011 -> 0 bytes
-rwxr-xr-xComputer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_02_Fundamentals_of_C_language.ipynb1
-rwxr-xr-xComputer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_03_Input_Output_Functions_and_Statements.ipynb1
-rwxr-xr-xComputer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_04_Control_Statements_in_C.ipynb1
-rwxr-xr-xComputer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_05_Loop_Control_Structures_In_C.ipynb1
-rwxr-xr-xComputer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_06_Arrays_and_Subscripted_Variables.ipynb1
-rwxr-xr-xComputer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_07_String_Manipulations_in_C.ipynb1
-rwxr-xr-xComputer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_08_Functins_in_C.ipynb1
-rwxr-xr-xComputer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_09_Structures_and_Unions.ipynb1
-rwxr-xr-xComputer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_11_Files.ipynb1
-rwxr-xr-xElectrical_Measurements_Measuring_Instruments/screenshots/chap1.pngbin0 -> 72591 bytes
-rwxr-xr-xElectrical_Measurements_Measuring_Instruments/screenshots/chap2.pngbin0 -> 41817 bytes
-rwxr-xr-xElectrical_Measurements_Measuring_Instruments/screenshots/chap4.pngbin0 -> 48202 bytes
-rwxr-xr-xElectrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter1.ipynb548
-rwxr-xr-xElectrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter2.ipynb2381
-rwxr-xr-xElectrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter3.ipynb3283
-rwxr-xr-xElectrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter4.ipynb751
-rwxr-xr-xElectrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter5.ipynb769
-rwxr-xr-xElectrical_Power-i_/screenshots/Chapter5_Transmission_Efficiendy.pngbin0 -> 96728 bytes
-rwxr-xr-xElectrical_Power-i_/screenshots/Chapter7_MinPotential.pngbin0 -> 77357 bytes
-rwxr-xr-xElectrical_Power-i_/screenshots/Chapter9_Reactance.pngbin0 -> 31995 bytes
-rwxr-xr-xElectrical_Power-i__by_M.L._Anand/Chapter1.ipynb198
-rwxr-xr-xElectrical_Power-i__by_M.L._Anand/Chapter10.ipynb786
-rwxr-xr-xElectrical_Power-i__by_M.L._Anand/Chapter11.ipynb459
-rwxr-xr-xElectrical_Power-i__by_M.L._Anand/Chapter2.ipynb626
-rwxr-xr-xElectrical_Power-i__by_M.L._Anand/Chapter3.ipynb501
-rwxr-xr-xElectrical_Power-i__by_M.L._Anand/Chapter4.ipynb602
-rwxr-xr-xElectrical_Power-i__by_M.L._Anand/Chapter5.ipynb630
-rwxr-xr-xElectrical_Power-i__by_M.L._Anand/Chapter7.ipynb814
-rwxr-xr-xElectrical_Power-i__by_M.L._Anand/Chapter8.ipynb364
-rwxr-xr-xElectrical_Power-i__by_M.L._Anand/Chapter9.ipynb58
-rwxr-xr-xElectrical_Power_System/README.txt10
-rwxr-xr-xElements_Of_Heat_Transfer/README.txt10
-rwxr-xr-xElements_of_Mechanical_Engineering/README.txt10
-rwxr-xr-xElements_of_Power_System_Analysis/README.txt10
-rwxr-xr-xElements_of_Power_System_Analysis/screenshots/Chapter2.pngbin0 -> 118876 bytes
-rwxr-xr-xElements_of_Power_System_Analysis/screenshots/Chapter2_1.pngbin0 -> 118876 bytes
-rwxr-xr-xElements_of_Power_System_Analysis/screenshots/Chapter3.pngbin0 -> 127402 bytes
-rwxr-xr-xElements_of_Power_System_Analysis/screenshots/Chapter3_1.pngbin0 -> 127402 bytes
-rwxr-xr-xElements_of_Power_System_Analysis/screenshots/Chapter4.pngbin0 -> 120000 bytes
-rwxr-xr-xElements_of_Power_System_Analysis/screenshots/Chapter4_1.pngbin0 -> 120000 bytes
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo02.ipynb411
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo02_1.ipynb411
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo03.ipynb393
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo03_1.ipynb393
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo04.ipynb257
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo04_1.ipynb257
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo05.ipynb428
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo05_1.ipynb428
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo06.ipynb1199
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo06_1.ipynb660
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo07.ipynb386
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo07_1.ipynb386
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo08.ipynb348
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo08_1.ipynb348
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo09.ipynb196
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo09_1.ipynb196
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo10.ipynb416
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo10_1.ipynb416
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo11.ipynb321
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo11_1.ipynb321
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo12.ipynb592
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo12_1.ipynb592
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo13.ipynb426
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo13_1.ipynb426
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo14.ipynb428
-rwxr-xr-xElements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo14_1.ipynb428
-rwxr-xr-xEngineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/Chapter1.ipynb (renamed from Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/Chapter1.ipynb)0
-rwxr-xr-xEngineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/Chapter2.ipynb (renamed from Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/Chapter2.ipynb)0
-rwxr-xr-xEngineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/Chapter3.ipynb (renamed from Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/Chapter3.ipynb)0
-rwxr-xr-xEngineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/Chapter4.ipynb (renamed from Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/Chapter4.ipynb)0
-rwxr-xr-xEngineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot1.png (renamed from Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/screenshots/Screenshot1.png)bin208740 -> 208740 bytes
-rwxr-xr-xEngineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot2.png (renamed from Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/screenshots/Screenshot2.png)bin208693 -> 208693 bytes
-rwxr-xr-xEngineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot3.png (renamed from Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/screenshots/Screenshot3.png)bin209714 -> 209714 bytes
-rwxr-xr-xEngineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot_(1).pngbin0 -> 208740 bytes
-rwxr-xr-xEngineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot_(2).pngbin0 -> 208693 bytes
-rwxr-xr-xEngineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot_(3).pngbin0 -> 209714 bytes
-rwxr-xr-xEngineering_Mechanics/screenshots/bending_moment_diagram_.pngbin0 -> 29462 bytes
-rwxr-xr-xEngineering_Mechanics/screenshots/shear_force_diagram_.pngbin0 -> 25555 bytes
-rwxr-xr-xEngineering_Mechanics/screenshots/shear_force_diagram_1.pngbin0 -> 31916 bytes
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./appendix.ipynb1002
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter02.ipynb792
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter03.ipynb598
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter04.ipynb138
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter05.ipynb285
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter06.ipynb279
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter07.ipynb551
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter08.ipynb311
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter09.ipynb669
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter10.ipynb378
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter11.ipynb22
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter12.ipynb411
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter13.ipynb121
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter14.ipynb1056
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter15.ipynb775
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter16.ipynb471
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter17.ipynb342
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter18.ipynb620
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter19.ipynb262
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter20.ipynb546
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter21.ipynb658
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter22.ipynb282
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter23.ipynb74
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter24.ipynb349
-rwxr-xr-xEngineering_Mechanics_by_Tayal_A.K./chapter25.ipynb217
-rwxr-xr-xEngineering_Physics/Chapter11_1.ipynb620
-rwxr-xr-xEngineering_Physics/Chapter13_1.ipynb386
-rwxr-xr-xEngineering_Physics/Chapter1_1.ipynb0
-rwxr-xr-xEngineering_Physics/Chapter2_1.ipynb431
-rwxr-xr-xEngineering_Physics/Chapter4_1.ipynb553
-rwxr-xr-xEngineering_Physics/Chapter5_1.ipynb469
-rwxr-xr-xEngineering_Physics/Chapter6_1.ipynb437
-rwxr-xr-xEngineering_Physics/Chapter7_1.ipynb582
-rwxr-xr-xEngineering_Physics/Chapter8_1.ipynb360
-rwxr-xr-xEngineering_Physics/Chapter9_1.ipynb576
-rwxr-xr-xEngineering_Physics/README.txt10
-rwxr-xr-xEngineering_Physics/chapter1.ipynb862
-rwxr-xr-xEngineering_Physics/chapter10.ipynb293
-rwxr-xr-xEngineering_Physics/chapter11.ipynb60
-rwxr-xr-xEngineering_Physics/chapter12.ipynb550
-rwxr-xr-xEngineering_Physics/chapter13.ipynb101
-rwxr-xr-xEngineering_Physics/chapter2.ipynb1113
-rwxr-xr-xEngineering_Physics/chapter3.ipynb1365
-rwxr-xr-xEngineering_Physics/chapter4.ipynb541
-rwxr-xr-xEngineering_Physics/chapter5.ipynb177
-rwxr-xr-xEngineering_Physics/chapter6.ipynb230
-rwxr-xr-xEngineering_Physics/chapter7.ipynb912
-rwxr-xr-xEngineering_Physics/chapter8.ipynb620
-rwxr-xr-xEngineering_Physics/chapter9.ipynb130
-rwxr-xr-xEngineering_Physics/screenshots/1.pngbin25998 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/11.pngbin18454 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/1_converted.pngbin44159 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/2.pngbin24691 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/22.pngbin30560 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/2_converted.pngbin47567 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/3.pngbin34591 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/33.pngbin23536 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/3_converted.pngbin50153 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/U3.pngbin23536 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/Untitled.pngbin17991 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/Untitled2.pngbin30560 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/area_of_the_spot_on_the_moon.pngbin106444 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/electric_flux.pngbin195247 -> 0 bytes
-rwxr-xr-xEngineering_Physics/screenshots/velocity_of_rocket.pngbin125602 -> 0 bytes
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/Chapter1.ipynb705
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/Chapter10.ipynb70
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/Chapter2.ipynb175
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/Chapter3.ipynb91
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/Chapter4.ipynb217
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/Chapter5.ipynb175
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/Chapter6.ipynb364
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/Chapter7.ipynb485
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/Chapter8.ipynb133
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/Chapter9.ipynb70
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/screenshots/screen1.pngbin0 -> 41451 bytes
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/screenshots/screen2.pngbin0 -> 73184 bytes
-rwxr-xr-xEngineering_Physics_by_Bhattacharya_Bhaskaran/screenshots/screen3.pngbin0 -> 46735 bytes
-rwxr-xr-xEngineering_Physics_by_PV_Naik/Chapter1.ipynb (renamed from Engineering_Physics/Chapter1.ipynb)0
-rwxr-xr-xEngineering_Physics_by_PV_Naik/Chapter10.ipynb (renamed from Engineering_Physics/Chapter10.ipynb)0
-rwxr-xr-xEngineering_Physics_by_PV_Naik/Chapter11.ipynb (renamed from Engineering_Physics/Chapter11.ipynb)0
-rwxr-xr-xEngineering_Physics_by_PV_Naik/Chapter13.ipynb (renamed from Engineering_Physics/Chapter13.ipynb)0
-rwxr-xr-xEngineering_Physics_by_PV_Naik/Chapter2.ipynb (renamed from Engineering_Physics/Chapter2.ipynb)0
-rwxr-xr-xEngineering_Physics_by_PV_Naik/Chapter4.ipynb (renamed from Engineering_Physics/Chapter4.ipynb)0
-rwxr-xr-xEngineering_Physics_by_PV_Naik/Chapter5.ipynb (renamed from Engineering_Physics/Chapter5.ipynb)0
-rwxr-xr-xEngineering_Physics_by_PV_Naik/Chapter6.ipynb (renamed from Engineering_Physics/Chapter6.ipynb)0
-rwxr-xr-xEngineering_Physics_by_PV_Naik/Chapter7.ipynb (renamed from Engineering_Physics/Chapter7.ipynb)0
-rwxr-xr-xEngineering_Physics_by_PV_Naik/Chapter8.ipynb (renamed from Engineering_Physics/Chapter8.ipynb)0
-rwxr-xr-xEngineering_Physics_by_PV_Naik/Chapter9.ipynb (renamed from Engineering_Physics/Chapter9.ipynb)0
-rwxr-xr-xEngineering_Physics_by_PV_Naik/screenshots/chapter1.pngbin0 -> 45221 bytes
-rwxr-xr-xEngineering_Physics_by_PV_Naik/screenshots/chapter11.pngbin0 -> 39085 bytes
-rwxr-xr-xEngineering_Physics_by_PV_Naik/screenshots/chapter5.pngbin0 -> 54561 bytes
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter1.ipynb492
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter11.ipynb288
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter12.ipynb123
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter13.ipynb210
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter14.ipynb340
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter16.ipynb213
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter17.ipynb214
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter18.ipynb582
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter2.ipynb153
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter20.ipynb155
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter21.ipynb278
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter4.ipynb451
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter5.ipynb234
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter6.ipynb261
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter7.ipynb179
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter8.ipynb184
-rwxr-xr-xEngineering_Physics_by_Rajendran/Chapter9.ipynb101
-rwxr-xr-xEngineering_Physics_by_Rajendran/screenshots/s1.pngbin0 -> 74990 bytes
-rwxr-xr-xEngineering_Physics_by_Rajendran/screenshots/s2.pngbin0 -> 97220 bytes
-rwxr-xr-xEngineering_Physics_by_Rajendran/screenshots/s3.pngbin0 -> 93583 bytes
-rwxr-xr-xEngineering_Physics_by_S._Mani_Naidu/Chapter1.ipynb284
-rwxr-xr-xEngineering_Physics_by_S._Mani_Naidu/Chapter10.ipynb112
-rwxr-xr-xEngineering_Physics_by_S._Mani_Naidu/Chapter11.ipynb549
-rwxr-xr-xEngineering_Physics_by_S._Mani_Naidu/Chapter14.ipynb494
-rwxr-xr-xEngineering_Physics_by_S._Mani_Naidu/Chapter2.ipynb271
-rwxr-xr-xEngineering_Physics_by_S._Mani_Naidu/Chapter3.ipynb658
-rwxr-xr-xEngineering_Physics_by_S._Mani_Naidu/Chapter4.ipynb578
-rwxr-xr-xEngineering_Physics_by_S._Mani_Naidu/Chapter5.ipynb566
-rwxr-xr-xEngineering_Physics_by_S._Mani_Naidu/Chapter6.ipynb541
-rwxr-xr-xEngineering_Physics_by_S._Mani_Naidu/Chapter7.ipynb442
-rwxr-xr-xEngineering_Physics_by_S._Mani_Naidu/Chapter8.ipynb691
-rwxr-xr-xEngineering_Physics_by_S._Mani_Naidu/Chapter9.ipynb305
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter1.ipynb621
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter10.ipynb67
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter11.ipynb159
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter12.ipynb105
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter15.ipynb332
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter2.ipynb507
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter3.ipynb275
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter4.ipynb196
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter5.ipynb156
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter6.ipynb114
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter7.ipynb158
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter8.ipynb262
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/Chapter9.ipynb64
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/screenshots/s1.pngbin0 -> 68370 bytes
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/screenshots/s2.pngbin0 -> 75275 bytes
-rwxr-xr-xEngineering_Physics_by_Shyam_Rajeev/screenshots/s3.pngbin0 -> 70432 bytes
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/Chapter1.ipynb (renamed from Engineering_Physics_/Chapter1.ipynb)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/Chapter10.ipynb (renamed from Engineering_Physics_/Chapter10.ipynb)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/Chapter11.ipynb (renamed from Engineering_Physics_/Chapter11.ipynb)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/Chapter12.ipynb.bkup (renamed from Engineering_Physics_/Chapter12.ipynb.bkup)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/Chapter2.ipynb (renamed from Engineering_Physics_/Chapter2.ipynb)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/Chapter3.ipynb (renamed from Engineering_Physics_/Chapter3.ipynb)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/Chapter4.ipynb (renamed from Engineering_Physics_/Chapter4.ipynb)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/Chapter5.ipynb (renamed from Engineering_Physics_/Chapter5.ipynb)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/Chapter6.ipynb (renamed from Engineering_Physics_/Chapter6.ipynb)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/Chapter7.ipynb (renamed from Engineering_Physics_/Chapter7.ipynb)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/Chapter8.ipynb (renamed from Engineering_Physics_/Chapter8.ipynb)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/Chapter9.ipynb (renamed from Engineering_Physics_/Chapter9.ipynb)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/README.txt (renamed from Engineering_Physics_/README.txt)0
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/screenshots/11.png (renamed from Engineering_Physics_/screenshots/11.png)bin28339 -> 28339 bytes
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/screenshots/22.png (renamed from Engineering_Physics_/screenshots/22.png)bin24093 -> 24093 bytes
-rwxr-xr-xEngineering_Physics_by_Uma_Mukherji/screenshots/33.png (renamed from Engineering_Physics_/screenshots/33.png)bin26393 -> 26393 bytes
-rwxr-xr-xFluid_Power_With_Applications/screenshots/Cha7.pngbin0 -> 39753 bytes
-rwxr-xr-xFluid_Power_With_Applications/screenshots/cha6.pngbin0 -> 43012 bytes
-rwxr-xr-xFluid_Power_With_Applications/screenshots/cha9.pngbin0 -> 52910 bytes
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_10_Hydraulic_Conductors_and_Fittings.ipynb333
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_11_Ancillary_Hydraulic_Devices.ipynb302
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_13_Pneumatics_Air_Preparation_and_components.ipynb732
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_14_Pneumatics_circuits_and_Applications.ipynb661
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_17_Advanced_Electdrical_Controls_For_Fluid_Power_Systems.ipynb212
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_2_Physical_Properties_of_Hydraulic_Fluids_.ipynb851
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_3_Energy_and_Power_in_Hydraulic_Systems.ipynb1098
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_4_Frictional_Losses_in_Hydraulic_Piplines.ipynb674
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_5_Hydraulic_Pumps_.ipynb640
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_6_Hydraulic_Cylinders_and_Cushioning_Devices.ipynb415
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_7_Hydraulic_Motors.ipynb487
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_8_Hydraulic_Valves.ipynb364
-rwxr-xr-xFluid_Power_With_Applications_by_A._Esposito/Chapter_9__Hydraulic_Circuit_Design_and_Analysis.ipynb424
-rwxr-xr-xFundamentals_Of_Physical_Chemistry/screenshots/C2.pngbin0 -> 150465 bytes
-rwxr-xr-xFundamentals_Of_Physical_Chemistry/screenshots/c14.pngbin0 -> 154082 bytes
-rwxr-xr-xFundamentals_Of_Physical_Chemistry/screenshots/c3.pngbin0 -> 155891 bytes
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_10_Electmotive_Force.ipynb363
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_11_Thermodynamics_Some_Basic_Concepts.ipynb213
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_12_Thermodynamics_Thermodynamic_chemistry.ipynb265
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_13_Thermodynamics_Entropy_and_Free_Energy.ipynb631
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_14_Determination_of_hydronium.ipynb226
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_16_Oxidation_Reduction_potentials.ipynb150
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_17_Speed_of_Reaction_Catalysis.ipynb108
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_20_Radiochemistry.ipynb70
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_2_Gases.ipynb430
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_3_Liquids.ipynb187
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_4_Solutions_Nonelectrolytes.ipynb323
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_5_Solutions_Osmotic_Pressure.ipynb104
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_6_Solutions_Solutions_of_Electrolytes.ipynb113
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_7_Conductivity.ipynb261
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_8_Chemical_Equlibrium.ipynb236
-rwxr-xr-xFundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_9_Ionic_Equilibria_and_Buffer_Action.ipynb776
-rwxr-xr-xGas_Dynamics_and_Jet_Propulsion/README.txt10
-rwxr-xr-xIntegrated_Circuits/README.txt10
-rwxr-xr-xMicroprocessor_Architecture,_Programming_&_Applications_with_the_8085/README.txt10
-rwxr-xr-xObject-Oriented_Programming_in_C++/README.txt10
-rwxr-xr-xObject-Oriented_Programming_in_C++/screenshots/Caption-2.pngbin0 -> 69459 bytes
-rwxr-xr-xObject-Oriented_Programming_in_C++/screenshots/Caption-3.pngbin0 -> 71256 bytes
-rwxr-xr-xObject-Oriented_Programming_in_C++/screenshots/Caption.pngbin0 -> 71325 bytes
-rwxr-xr-xObject-Oriented_Programming_in_C++/screenshots/Caption2.pngbin0 -> 87781 bytes
-rwxr-xr-xObject-Oriented_Programming_in_C++/screenshots/Caption3.pngbin0 -> 70870 bytes
-rwxr-xr-xObject-Oriented_Programming_in_C++/screenshots/caption-1.pngbin0 -> 87504 bytes
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter10Pointers.ipynb1464
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter10Pointers_1.ipynb1461
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter11VirtualFunctions.ipynb1608
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter11VirtualFunctions_1.ipynb1608
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter12StreamsandFiles.ipynb2356
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter12StreamsandFiles_1.ipynb2349
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter13MultifilePrograms.ipynb73
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter13MultifilePrograms_1.ipynb73
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter14TemplatesandExceptions.ipynb860
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter14TemplatesandExceptions_1.ipynb860
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter15TheStandardTemplateLibrary.ipynb2625
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter15TheStandardTemplateLibrary_1.ipynb2625
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter16Object-OrientedSoftwareDevelopment.ipynb1519
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter16Object-OrientedSoftwareDevelopment_1.ipynb1519
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter2C++ProgrammingBasics.ipynb555
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter2C++ProgrammingBasics_1.ipynb555
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter3LoopsandDecisions.ipynb1544
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter3LoopsandDecisions_1.ipynb1542
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter4Structures.ipynb598
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter4Structures_1.ipynb598
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter5Functions.ipynb1207
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter5Functions_1.ipynb1207
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter6ObjectsandClasses.ipynb977
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter6ObjectsandClasses_1.ipynb977
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter7ArraysandStrings.ipynb1935
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter7ArraysandStrings_1.ipynb1935
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter8OperatorOverloading.ipynb1653
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter8OperatorOverloading_1.ipynb1653
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter9Inheritance.ipynb1833
-rwxr-xr-xObject-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter9Inheritance_1.ipynb1833
-rwxr-xr-xOptical_Communiation/screenshots/SNR.pngbin0 -> 70605 bytes
-rwxr-xr-xOptical_Communiation/screenshots/SNR_1.pngbin0 -> 70605 bytes
-rwxr-xr-xOptical_Communiation/screenshots/pulse_broadning.pngbin0 -> 52294 bytes
-rwxr-xr-xOptical_Communiation/screenshots/pulse_broadning_1.pngbin0 -> 52294 bytes
-rwxr-xr-xOptical_Communiation/screenshots/shot_noise_and_thermal_noise.pngbin0 -> 69568 bytes
-rwxr-xr-xOptical_Communiation/screenshots/shot_noise_and_thermal_noise_1.pngbin0 -> 69568 bytes
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter1.ipynb128
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter10.ipynb96
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter10_1.ipynb96
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter1_1.ipynb128
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter2.ipynb886
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter2_1.ipynb886
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter4.ipynb413
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter4_1.ipynb413
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter5.ipynb281
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter5_1.ipynb281
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter6.ipynb252
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter6_1.ipynb252
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter7.ipynb716
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter7_1.ipynb716
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter8.ipynb272
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter8_1.ipynb272
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter9.ipynb99
-rwxr-xr-xOptical_Communiation_by_Anasuya_Kalavar/chapter9_1.ipynb99
-rwxr-xr-xOptical_Communication/README.txt10
-rwxr-xr-xOptical_Communication/screenshots/SNR.pngbin0 -> 70605 bytes
-rwxr-xr-xOptical_Communication/screenshots/pulse_broadning.pngbin0 -> 52294 bytes
-rwxr-xr-xOptical_Communication/screenshots/shot_noise_and_thermal_noise.pngbin0 -> 69568 bytes
-rwxr-xr-xOptical_Communication_by_Anasuya_Kalavar/chapter1.ipynb128
-rwxr-xr-xOptical_Communication_by_Anasuya_Kalavar/chapter10.ipynb96
-rwxr-xr-xOptical_Communication_by_Anasuya_Kalavar/chapter2.ipynb886
-rwxr-xr-xOptical_Communication_by_Anasuya_Kalavar/chapter4.ipynb413
-rwxr-xr-xOptical_Communication_by_Anasuya_Kalavar/chapter5.ipynb281
-rwxr-xr-xOptical_Communication_by_Anasuya_Kalavar/chapter6.ipynb252
-rwxr-xr-xOptical_Communication_by_Anasuya_Kalavar/chapter7.ipynb716
-rwxr-xr-xOptical_Communication_by_Anasuya_Kalavar/chapter8.ipynb272
-rwxr-xr-xOptical_Communication_by_Anasuya_Kalavar/chapter9.ipynb99
-rwxr-xr-xProcess_Heat_Transfer/screenshots/CH16.pngbin0 -> 44539 bytes
-rwxr-xr-xProcess_Heat_Transfer/screenshots/CH17.pngbin0 -> 27401 bytes
-rwxr-xr-xProcess_Heat_Transfer/screenshots/Ch15.pngbin0 -> 46589 bytes
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_10_Stream_Line_Flow_and_Heat_Convection.ipynb580
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_11_Caluculations_for_Process_Heat_Conditions.ipynb1071
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_12_Condensation_of_Single_Vapours____.ipynb1348
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_14_Evapouration.ipynb1123
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_15__Vaporizers_Evapourators_and_Reboilers.ipynb1324
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_16_Extented_Surfaces.ipynb1044
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_17_Direct_Contact_Transfer__Cooling_Tower.ipynb865
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_18_Batch_and_Unsteady_State_Processes.ipynb634
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_19_Furnace_Calculations.ipynb401
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_20_Additoinal_Applications.ipynb904
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_2_Conduction.ipynb281
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_4_Radiation.ipynb208
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_5_Temperature.ipynb408
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_6_Counterflow_Double_Pipe_Exchangers.ipynb507
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_7_Parallel-Counter_flow_Shell_and_Tube_Exchangers.ipynb1093
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_8_flow_arrangements_for_increased_heat_recovery.ipynb432
-rwxr-xr-xProcess_Heat_Transfer_by_D._Q._Kern/Chapter_9_Gases.ipynb395
-rwxr-xr-xPropagation_Engineering_in_Wireless_Communications/README.txt10
-rwxr-xr-xPropagation_Engineering_in_Wireless_Communications/screenshots/Capture2.PNGbin0 -> 69029 bytes
-rwxr-xr-xPropagation_Engineering_in_Wireless_Communications/screenshots/Capture4.PNGbin0 -> 77601 bytes
-rwxr-xr-xPropagation_Engineering_in_Wireless_Communications/screenshots/Untitled1.pngbin0 -> 58773 bytes
-rwxr-xr-xPropagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter1_1.ipynb109
-rwxr-xr-xPropagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter2_1.ipynb446
-rwxr-xr-xPropagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter3_1.ipynb769
-rwxr-xr-xPropagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter4_1.ipynb534
-rwxr-xr-xPropagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter5_1.ipynb465
-rwxr-xr-xPropagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter6_1.ipynb957
-rwxr-xr-xPropagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter7_1.ipynb750
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles/screenshots/diffusion_capacitance.pngbin0 -> 41502 bytes
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles/screenshots/diffusion_current_density.pngbin0 -> 39171 bytes
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles/screenshots/possible_arrangements.pngbin0 -> 32883 bytes
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch1.ipynb93
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch10.ipynb571
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch11.ipynb557
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch2.ipynb150
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch3.ipynb312
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch4.ipynb598
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch5.ipynb342
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch6.ipynb217
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch7.ipynb284
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch8.ipynb341
-rwxr-xr-xSemiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch9.ipynb423
-rwxr-xr-xSolid_State_Devices_and_Circuits/screenshots/Quality_factor.pngbin0 -> 28472 bytes
-rwxr-xr-xSolid_State_Devices_and_Circuits/screenshots/Quality_factor_1.pngbin0 -> 28472 bytes
-rwxr-xr-xSolid_State_Devices_and_Circuits/screenshots/maximum_transconductance_Curve.pngbin0 -> 54568 bytes
-rwxr-xr-xSolid_State_Devices_and_Circuits/screenshots/maximum_transconductance_Curve_1.pngbin0 -> 54568 bytes
-rwxr-xr-xSolid_State_Devices_and_Circuits/screenshots/minimum_transconductance_Curve.pngbin0 -> 52607 bytes
-rwxr-xr-xSolid_State_Devices_and_Circuits/screenshots/minimum_transconductance_Curve_1.pngbin0 -> 52607 bytes
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_1.ipynb448
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_1_1.ipynb448
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_2.ipynb3916
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_2_1.ipynb3916
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_3.ipynb801
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_3_1.ipynb801
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_4.ipynb675
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_4_1.ipynb675
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_5.ipynb1598
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_5_1.ipynb1598
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_6.ipynb1464
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_6_1.ipynb1464
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_7.ipynb1465
-rwxr-xr-xSolid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_7_1.ipynb1465
-rwxr-xr-xUtilization_of_Electrical_Energy_and_Traction/screenshots/current_thru_negative_booster.pngbin0 -> 48404 bytes
-rwxr-xr-xUtilization_of_Electrical_Energy_and_Traction/screenshots/speed-armature_curve.pngbin0 -> 35729 bytes
-rwxr-xr-xUtilization_of_Electrical_Energy_and_Traction/screenshots/speed-time_curve.pngbin0 -> 24287 bytes
-rwxr-xr-xUtilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch1.ipynb722
-rwxr-xr-xUtilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch10.ipynb285
-rwxr-xr-xUtilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch11.ipynb401
-rwxr-xr-xUtilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch3.ipynb427
-rwxr-xr-xUtilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch4.ipynb1356
-rwxr-xr-xUtilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch5.ipynb111
-rwxr-xr-xUtilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch7.ipynb1409
-rwxr-xr-xUtilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch8.ipynb534
-rwxr-xr-xUtilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch9.ipynb332
-rwxr-xr-xWireless_Communications/screenshots/chap02.pngbin0 -> 54710 bytes
-rwxr-xr-xWireless_Communications/screenshots/chap07.pngbin0 -> 60405 bytes
-rwxr-xr-xWireless_Communications/screenshots/chap12.pngbin0 -> 86885 bytes
-rwxr-xr-xWireless_Communications_by_T._L._Singal/CHAPTER10.ipynb437
-rwxr-xr-xWireless_Communications_by_T._L._Singal/CHAPTER11.ipynb253
-rwxr-xr-xWireless_Communications_by_T._L._Singal/CHAPTER12.ipynb562
-rwxr-xr-xWireless_Communications_by_T._L._Singal/CHAPTER14.ipynb156
-rwxr-xr-xWireless_Communications_by_T._L._Singal/CHAPTER2.ipynb479
-rwxr-xr-xWireless_Communications_by_T._L._Singal/CHAPTER3.ipynb411
-rwxr-xr-xWireless_Communications_by_T._L._Singal/CHAPTER4.ipynb372
-rwxr-xr-xWireless_Communications_by_T._L._Singal/CHAPTER5.ipynb431
-rwxr-xr-xWireless_Communications_by_T._L._Singal/CHAPTER6.ipynb183
-rwxr-xr-xWireless_Communications_by_T._L._Singal/CHAPTER7.ipynb172
-rwxr-xr-xWireless_Communications_by_T._L._Singal/CHAPTER8.ipynb231
-rwxr-xr-xWireless_Communications_by_T._L._Singal/CHAPTER9.ipynb741
-rwxr-xr-x_Mastering_C++/screenshots/IMG-20150614-WA0001.pngbin0 -> 127124 bytes
-rwxr-xr-x_Mastering_C++/screenshots/IMG-20150614-WA0006.pngbin0 -> 135963 bytes
-rwxr-xr-x_Mastering_C++/screenshots/IMG-20150619-WA0002.pngbin0 -> 192323 bytes
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter10-ClassesAndObjects.ipynb1241
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter11-ObjectInitializationAndClean-Up.ipynb1781
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter12-DynamicObjects.ipynb1590
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter13-OperatorOverloading.ipynb2673
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter14-Inheritance.ipynb2736
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter15-VirtualFunctions.ipynb629
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter16-GenericProgrammingWithTemplates.ipynb1512
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter17-StreamsComputationWithConsole.ipynb1338
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter18-StreamsComputationWithFiles.ipynb1152
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter19-ExceptionHandling.ipynb1454
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter2-MovingFromCtoC++.ipynb1389
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter3-C++AtAGlance.ipynb629
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter4-DataTypes,OperatorsAndExpressions.ipynb881
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter5-ControlFlow.ipynb1280
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter6-ArraysAndStrings.ipynb1593
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter7-ModularProgrammingWithFunctions.ipynb1641
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter8-StructuresAndUnions.ipynb1202
-rwxr-xr-x_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter9-PointersAndRuntimeBinding.ipynb1663
-rwxr-xr-xsample_notebooks/AbhishekGupta/chapter16.ipynb108
-rwxr-xr-xsample_notebooks/AkshayPatil/Chapter02.ipynb108
-rwxr-xr-xsample_notebooks/AnkitKumar/chapter6.ipynb295
-rwxr-xr-xsample_notebooks/AviralYadav/Chapter7.ipynb474
-rwxr-xr-xsample_notebooks/ChaitanyaPotti/Chapter2_1.ipynb365
-rwxr-xr-xsample_notebooks/DaudIbrahir Saifi/Chapter2.ipynb228
-rwxr-xr-xsample_notebooks/Hrituraj/Chapter7.ipynb814
-rwxr-xr-xsample_notebooks/KavinkumarD/Chapter_8_FREQUENCY_EFFECTS_IN_AMPLIFIERS.ipynb120
-rwxr-xr-xsample_notebooks/LalitKumar/chapter2.ipynb347
-rwxr-xr-xsample_notebooks/MohdGufran/Chapter6.ipynb506
-rwxr-xr-xsample_notebooks/MukteshChaudhary/ch2.ipynb150
-rwxr-xr-xsample_notebooks/NirenNegandhi/ch9.ipynb332
-rwxr-xr-xsample_notebooks/PankajDoshi/Chapter1.ipynb1
-rwxr-xr-xsample_notebooks/PankajDoshi/Chapter_1.ipynb1
-rwxr-xr-xsample_notebooks/PraveenKumar/chapter2.ipynb429
-rwxr-xr-xsample_notebooks/Raj Phani/chapter_1.ipynb1118
-rwxr-xr-xsample_notebooks/Raj Phani/chapter_1_1.ipynb1118
-rwxr-xr-xsample_notebooks/RohithYeedulapalli/Chapter_7.ipynb232
-rwxr-xr-xsample_notebooks/Sabiya/Chapter9_1.ipynb460
-rwxr-xr-xsample_notebooks/SaleemAhmed/generation.ipynb429
-rwxr-xr-xsample_notebooks/SandhyaArroju/Chapter5.ipynb303
-rwxr-xr-xsample_notebooks/SoumenGanguly/ncert_Maths.ipynb355
-rwxr-xr-xsample_notebooks/Vedantam Lakshmi Manasa/Chapter_2_Electric_Fields.ipynb296
-rwxr-xr-xsample_notebooks/VidyashankarVenkatraman/Chapter_3_Kittel.ipynb79
-rwxr-xr-xsample_notebooks/VidyashankarVenkatraman/Chapter_3_Kitteldemo.ipynb79
-rwxr-xr-xsample_notebooks/WaseemAhmad Ansari/Chapter2.ipynb348
-rwxr-xr-xsample_notebooks/YogeshPatil/EDC_By_K_L_Kishore_Chapter_7.ipynb499
-rwxr-xr-xsample_notebooks/kotaDinesh Babu/samplebook(process_heat_transfer)_1.ipynb281
-rwxr-xr-xsample_notebooks/kotaDinesh Babu/samplebook(process_heat_transfer)_2.ipynb281
-rwxr-xr-xsample_notebooks/marupeddisameer chaitanya/Sample_(chapter_9).ipynb247
-rwxr-xr-xsample_notebooks/nishumittal/chapter2.ipynb710
-rwxr-xr-xsample_notebooks/pranay/CHAPTER1.ipynb372
676 files changed, 236187 insertions, 26453 deletions
diff --git a/A_First_course_in_Programming_with_C/screenshots/chapter141_1.png b/A_First_course_in_Programming_with_C/screenshots/chapter141_1.png
new file mode 100755
index 00000000..6648b8b8
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/screenshots/chapter141_1.png
Binary files differ
diff --git a/A_First_course_in_Programming_with_C/screenshots/chapter142_1.png b/A_First_course_in_Programming_with_C/screenshots/chapter142_1.png
new file mode 100755
index 00000000..87e3450d
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/screenshots/chapter142_1.png
Binary files differ
diff --git a/A_First_course_in_Programming_with_C/screenshots/chapter143_1.png b/A_First_course_in_Programming_with_C/screenshots/chapter143_1.png
new file mode 100755
index 00000000..6a0bc31a
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/screenshots/chapter143_1.png
Binary files differ
diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter10_2.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter10_2.ipynb
new file mode 100755
index 00000000..f582a1ac
--- /dev/null
+++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter10_2.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "#Chapter 10: Structures and Unions", "cell_type": "markdown", "metadata": {}}, {"source": "##Example 1, Page number: SAU - 5", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "#student structure\n\nimport sys\n\nclass student:\n rno = 0\n sname = \"\"\n tot = 0 \n \nx = student()\n\nx.rno = int(raw_input(\"\\nEnter roll number, name and total marks\"))\nx.sname = raw_input(\"\")\nx.tot = int(raw_input(\"\"))\n\nsys.stdout.write(\"\\n\\tDetails entered are \\n\")\nsys.stdout.write(\"\\nRoll No. : %d\"%(x.rno))\nsys.stdout.write(\"\\nStudent Name : %s\"%(x.sname))\nsys.stdout.write(\"\\nTotal marks : %d\"%(x.tot))\nsys.stdout.write(\"\\n\\nPress any key to continue...\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter roll number, name and total marks20147\nPRADEEP\n64\n\n\tDetails entered are \n\nRoll No. : 20147\nStudent Name : PRADEEP\nTotal marks : 64\n\nPress any key to continue..."}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 2, Page number: SAU - 6", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "\nimport sys\n\nclass student:\n rno = 0 \n sname = \"\"\n tot = 0\n \nch = 'y'\nstd = [student() for i in range(0,50)]\n\nn = int(raw_input(\"\\nHow many students ? \"))\n\nfor i in range(0,n):\n std[i].rno = int(raw_input(\"\\nRoll Number ? \"))\n std[i].sname = raw_input(\"\\nName ? \")\n std[i].tot = int(raw_input(\"\\nTotal marks ? \"))\n \nwhile ch == 'y' or ch == 'Y':\n temp = int(raw_input(\"\\nEnter student roll number to display marks : \"))\n flag = 0\n for i in range(0,n):\n if flag == 0:\n if std[i].rno == temp:\n sys.stdout.write(\"\\nMarks obtained by %d %s\"%(std[i].rno,std[i].sname))\n sys.stdout.write(\"\\nTotal : %d\"%(std[i].tot))\n flag = 1\n \n if flag == 0 :\n sys.stdout.write(\"\\n%d is not present in the list\"%(temp))\n ch = raw_input(\"\\npress y - to continue \\n any other key to stop.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many students ? 3\n\nRoll Number ? 20201\n\nName ? ARUN\n\nTotal marks ? 78\n\nRoll Number ? 20208\n\nName ? DEEPAK\n\nTotal marks ? 69\n\nRoll Number ? 20223\n\nName ? SUSMITHA\n\nTotal marks ? 88\n\nEnter student roll number to display marks : 20208\n\nMarks obtained by 20208 DEEPAK\nTotal : 69\npress y - to continue \n any other key to stop.N\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 3, Page number: SAU - 8", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "\nimport sys\n\nclass student:\n rno = 0 \n sname = \"\"\n tot = 0\n \nstd = [student() for i in range(0,50)]\n\nn = int(raw_input(\"\\nHow many students ? \"))\n\nfor i in range(0,n):\n std[i].rno = int(raw_input(\"\\nRoll Number ? \"))\n std[i].sname = raw_input(\"\\nName ? \")\n std[i].tot = int(raw_input(\"\\nTotal marks ? \"))\n \nprint \"\\n-------------------------------------------------------\"\nprint \"\\n Roll No. Name Total Marks\"\nprint \"\\n-------------------------------------------------------\"\n\nfor i in range(0,n):\n if std[i].tot >= 75:\n sys.stdout.write(\"\\n %-8d %-20s %5d\"%(std[i].rno,std[i].sname,std[i].tot))\n \nprint \"\\n-------------------------------------------------------\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many students ? 4\n\nRoll Number ? 30401\n\nName ? ANAND\n\nTotal marks ? 59\n\nRoll Number ? 30404\n\nName ? NIRMAL\n\nTotal marks ? 64\n\nRoll Number ? 30428\n\nName ? ISWARYA\n\nTotal marks ? 82\n\nRoll Number ? 30432\n\nName ? VIVEKA\n\nTotal marks ? 79\n\n-------------------------------------------------------\n\n Roll No. Name Total Marks\n\n-------------------------------------------------------\n\n 30428 ISWARYA 82\n 30432 VIVEKA 79\n-------------------------------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 4, Page number: SAU - 10", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "\nimport sys\n\nclass employee:\n eno = 0\n ename = \"\"\n epay = 0\n jdate = \"\"\n \ndef revise(temp):\n if temp <= 2000:\n return (temp + (temp*0.15))\n else:\n if temp <= 5000:\n return (temp + (temp * 0.10))\n else:\n return temp\n \n \nemploys = [employee() for i in range(0,25)]\ni = 0\nch = 'y'\n\nwhile ch.upper() == 'Y':\n employs[i].eno = int(raw_input(\"\\nEmployee No.? \"))\n employs[i].ename = raw_input(\"\\nName ? \")\n employs[i].epay = int(raw_input(\"\\nExisting pay? \"))\n employs[i].jdate = raw_input(\"\\nJoining Date ? \")\n i += 1\n ch = raw_input(\"\\nPress y - to continue any other key to stop.\")\n \nn = i\nsys.stdout.write(\"\\n\\n%d records are entered\"%(n))\nsys.stdout.write(\"\\nPress any key to print the revised salary list\")\n\nfor i in range(0,n):\n employs[i].epay = revise(employs[i].epay)\n \nprint \"\\n Employees Revised Pay List\"\nprint \"\\n----------------------------------------------------------------------------------\"\nprint \"\\n S.No Number Name Joinint date Pay\"\nprint \"\\n----------------------------------------------------------------------------------\"\n\nfor i in range(0,n):\n sys.stdout.write(\"\\n %-4d %-d %-15s %10s %-8d\"%(i+1,employs[i].eno,employs[i].ename,employs[i].jdate,employs[i].epay))\n \nprint \"\\n----------------------------------------------------------------------------------\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEmployee No.? 20101\n\nName ? ASHIKA\n\nExisting pay? 1000\n\nJoining Date ? 31/04/2001\n\nPress y - to continue any other key to stop.Y\n\nEmployee No.? 20182\n\nName ? ASHWIN\n\nExisting pay? 6000\n\nJoining Date ? 11/12/1995\n\nPress y - to continue any other key to stop.Y\n\nEmployee No.? 20204\n\nName ? PRAVEEN\n\nExisting pay? 3000\n\nJoining Date ? 18/06/1994\n\nPress y - to continue any other key to stop.N\n\n\n3 records are entered\nPress any key to print the revised salary list\n Employees Revised Pay List\n\n----------------------------------------------------------------------------------\n\n S.No Number Name Joinint date Pay\n\n----------------------------------------------------------------------------------\n\n 1 20101 ASHIKA 31/04/2001 1150 \n 2 20182 ASHWIN 11/12/1995 6000 \n 3 20204 PRAVEEN 18/06/1994 3300 \n----------------------------------------------------------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5, Page number: SAU - 13", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "\nimport sys\n\nclass cricket:\n pname = \"\"\n tname = \"\"\n bavg = 0\n \nprobable = [cricket() for i in range(0,30)]\n\nn = int(raw_input(\"\\nHow many players ? \"))\n\nfor i in range(0,n):\n probable[i].pname = raw_input(\"\\nPlayer name ? \")\n probable[i].tname = raw_input(\"\\nWhich team ? \")\n probable[i].bavg = int(raw_input(\"\\nBatting average ? \"))\n \nj = 0\nteams = ['' for i in range(0,20)]\n\nteams[j] = probable[0].tname\nj += 1\ni = 1\n\nfor i in range(1,n):\n flag = 0\n k = 0\n while k < j and flag == 0: \n if probable[i].tname == teams[k]:\n flag = 1\n k += 1\n if flag == 0:\n teams[j] = probable[i].tname\n j += 1\n i += 1\n\nfor k in range(0,j):\n sys.stdout.write(\"\\n\\t%s\"%(teams[k]))\n print \"\\n-------------------------------------------------------\"\n for i in range(0,n):\n if probable[i].tname == teams[k]:\n sys.stdout.write(\"\\n %-15s %6d\"%(probable[i].pname,probable[i].bavg))\n print \"\\n-------------------------------------------------------\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many players ? 6\n\nPlayer name ? KUMBLE\n\nWhich team ? KARNATAKA\n\nBatting average ? 22\n\nPlayer name ? KAMBLI\n\nWhich team ? MUMBAI\n\nBatting average ? 39\n\nPlayer name ? SRIKANTH\n\nWhich team ? TAMILNADU\n\nBatting average ? 52\n\nPlayer name ? SACHIN\n\nWhich team ? MUMBAI\n\nBatting average ? 69\n\nPlayer name ? RAHUL\n\nWhich team ? KARNATAKA\n\nBatting average ? 57\n\nPlayer name ? RAMESH\n\nWhich team ? TAMILNADU\n\nBatting average ? 48\n\n\tKARNATAKA\n-------------------------------------------------------\n\n KUMBLE 22\n RAHUL 57\n-------------------------------------------------------\n\n\tMUMBAI\n-------------------------------------------------------\n\n KAMBLI 39\n SACHIN 69\n-------------------------------------------------------\n\n\tTAMILNADU\n-------------------------------------------------------\n\n SRIKANTH 52\n RAMESH 48\n-------------------------------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 6, Page number: SAU - 19", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "\nimport sys\n\nclass student:\n roll_no = 0\n sname = \"\"\n marks = 0 \n \nstd = [student() for i in range(0,10)]\n\nprint \"\\n-----------------------------------------------------------------------\"\nprint \"\\n Main Menu\"\nprint \"\\n-----------------------------------------------------------------------\"\nprint \"\\nPress 1 to enter roll numbers\"\nprint \"\\n 2 to enter names\"\nprint \"\\n 3 to enter marks\"\nprint \"\\n 4 to stop\"\nch = int(raw_input(\"\\nEnter your choice : \"))\nif ch < 4:\n n = int(raw_input(\"How many students ? \"))\n\n for i in range(0,n):\n if ch == 1:\n std[i].roll_no = int(raw_input(\"\\nRoll number ? \"))\n else:\n if ch == 2:\n std[i].sname = raw_input(\"\\nStudent name ? \")\n else:\n if ch == 3:\n std[i].marks = int(raw_input(\"\\nAverage marks ? \"))\n \n if ch == 1:\n print \"\\n-------------------------------------------------------------------\"\n print \"\\n Students roll number list\"\n print \"\\n-------------------------------------------------------------------\"\n for i in range(0,n):\n sys.stdout.write(\"\\n\\t%d\"%(std[i].roll_no))\n print \"\\n-------------------------------------------------------------------\"\n else:\n if ch == 2:\n print \"\\n-------------------------------------------------------------------\"\n print \"\\n Students name list\"\n print \"\\n-------------------------------------------------------------------\"\n for i in range(0,n):\n sys.stdout.write(\"\\n\\t%s\"%(std[i].sname))\n print \"\\n-------------------------------------------------------------------\"\n else:\n if ch == 3:\n print \"\\n-------------------------------------------------------------------\"\n print \"\\n Students mark list\"\n print \"\\n-------------------------------------------------------------------\"\n for i in range(0,n):\n sys.stdout.write(\"\\n\\t%d\"%(std[i].marks))\n print \"\\n-------------------------------------------------------------------\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\n-----------------------------------------------------------------------\n\n Main Menu\n\n-----------------------------------------------------------------------\n\nPress 1 to enter roll numbers\n\n 2 to enter names\n\n 3 to enter marks\n\n 4 to stop\n\nEnter your choice : 2\nHow many students ? 4\n\nStudent name ? AJITH\n\nStudent name ? RAJU\n\nStudent name ? VIGNESH\n\nStudent name ? DIVYA\n\n-------------------------------------------------------------------\n\n Students name list\n\n-------------------------------------------------------------------\n\n\tAJITH\n\tRAJU\n\tVIGNESH\n\tDIVYA\n-------------------------------------------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter11_2.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter11_2.ipynb
new file mode 100755
index 00000000..6749cec0
--- /dev/null
+++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter11_2.ipynb
@@ -0,0 +1 @@
+{"nbformat": 4, "metadata": {"orig_nbformat": 3}, "cells": [{"source": "# Chapter 11: Pointers", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1, Page Number : PTR-5", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 1, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter two integers : 5\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "\nSum = 8\n"}], "source": "a = int(raw_input(\"\\nEnter two integers : \"))\nb = int(raw_input(\"\"))\n\nxptr = id(a)\nyptr = id(b)\n\n#There is no pointer concept in python\ns = a + b\n\nprint \"\\nSum = \",s", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 2, Page Number : PTR-6", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 2, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter two integers : 15\n"}, {"output_type": "stream", "name": "stdout", "text": "25\n"}, {"output_type": "stream", "name": "stdout", "text": "\nBiggest number is 25\n"}], "source": "a = int(raw_input(\"\\nEnter two integers : \"))\nb = int(raw_input(\"\"))\n\nxptr = id(a)\nyptr = id(b)\n\n#There is no pointer concept in python\nif a > b:\n big = a\nelse:\n big = b\n \nprint \"\\nBiggest number is \",big", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 3, Page Number : PTR-7", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 3, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nBefore function call a = 25 b = 10\n\n\nInside the function a = 35 b = 20\n\nAfter function call a = 35 b = 20\n"}], "source": "def add10(x,y):\n #There is no pointer concept in python\n x = x + 10\n y = y + 10\n print \"\\n\\nInside the function a = \",x,\" b = \",y\n return x,y\n \na = 25\nb = 10\n\nprint \"\\nBefore function call a = \",a,\" b = \",b\na,b = add10(a,b)\nprint \"\\nAfter function call a = \",a,\" b = \",b", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 4, Page Number : PTR-11", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 5, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter two integers : 25\n"}, {"output_type": "stream", "name": "stdout", "text": "500\n"}, {"output_type": "stream", "name": "stdout", "text": "\nBefore function call a = 25 b = 500\n\n\nAfter function call, values are exchanged as \n a = 500 b = 25\n"}], "source": "def swap(x,y):\n #There is no pointer concept in python\n temp = x\n x = y\n y = temp\n return x,y\n\na = int(raw_input(\"\\nEnter two integers : \"))\nb = int(raw_input(\"\"))\n\nprint \"\\nBefore function call a = \",a,\" b = \",b\n\na,b = swap(a,b)\n\nprint \"\\n\\nAfter function call, values are exchanged as \\n a = \",a,\" b = \",b", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 5, Page Number : PTR-14", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 1, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many values ? 4\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter all values in the list\n\n"}, {"output_type": "stream", "name": "stdout", "text": "3.48\n"}, {"output_type": "stream", "name": "stdout", "text": "3.54\n"}, {"output_type": "stream", "name": "stdout", "text": "3.26\n"}, {"output_type": "stream", "name": "stdout", "text": "2.98\n"}, {"output_type": "stream", "name": "stdout", "text": "\nArithmetic mean = 3.315"}], "source": "import sys\n\nx = [0.0 for i in range(0,10)]\nn = int(raw_input(\"\\nHow many values ? \"))\n\nprint \"\\nEnter all values in the list\\n\"\n\nfor i in range(0,n):\n x[i] = float(raw_input(\"\"))\n\nsum1 = 0.0\n#Since sum is a predefined function in python, sum1 is used\nfor i in range(0,n):\n sum1 = sum1 + x[i]\n #There is no pointer concept in python\n \nmean = sum1/n\n\nsys.stdout.write(\"\\nArithmetic mean = %0.3f\"%(mean))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 6, Page Number : PTR-19", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 3, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many values ? 6\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter all values\n\n"}, {"output_type": "stream", "name": "stdout", "text": "11\n"}, {"output_type": "stream", "name": "stdout", "text": "12\n"}, {"output_type": "stream", "name": "stdout", "text": "13\n"}, {"output_type": "stream", "name": "stdout", "text": "14\n"}, {"output_type": "stream", "name": "stdout", "text": "15\n"}, {"output_type": "stream", "name": "stdout", "text": "16\n"}, {"output_type": "stream", "name": "stdout", "text": "\nThe reversed list is\n\n 16 15 14 13 12 11"}], "source": "import sys\n\nxp = [0 for i in range(0,10)]\nn = int(raw_input(\"\\nHow many values ? \"))\n\n#There is no pointer concept in python\nprint \"\\nEnter all values\\n\"\n\nfor i in range(0,n):\n xp[i] = int(raw_input(\"\"))\n\nprint \"\\nThe reversed list is\\n\"\nfor i in range(n-1,0-1,-1):\n sys.stdout.write(\"%6d\"%(xp[i]))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 7, Page Number : PTR-21", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 5, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nFor A matrix \nHow many rows and columns ? 3\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter A matrix values\n\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "1\n"}, {"output_type": "stream", "name": "stdout", "text": "-2\n"}, {"output_type": "stream", "name": "stdout", "text": "0\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "-1\n"}, {"output_type": "stream", "name": "stdout", "text": "\nFor B matrix\nHow many rows and columns ? 3\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "6\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "-1\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "1\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "-5\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "\nResultant matrix is \n\n 26 9 5\n 4 -28 18\n 18 19 -3\n"}], "source": "import sys\n\na = [[0 for i in range(0,10)]for i in range(0,10)]\nb = [[0 for i in range(0,10)]for i in range(0,10)]\n\nc = [[0 for i in range(0,5)]for i in range(0,5)]\nm = int(raw_input(\"\\nFor A matrix \\nHow many rows and columns ? \"))\nn = int(raw_input(\"\"))\n\nprint \"\\nEnter A matrix values\\n\"\nfor i in range(0,m):\n for j in range(0,n):\n a[i][j] = int(raw_input(\"\"))\n \nn = int(raw_input(\"\\nFor B matrix\\nHow many rows and columns ? \"))\nl = int(raw_input(\"\"))\n\nfor i in range(0,n):\n for j in range(0,l):\n b[i][j] = int(raw_input(\"\"))\n\nfor i in range(0,m):\n for j in range(0,l):\n c[i][j] = 0\n for k in range(0,l):\n c[i][j] = c[i][j] + (a[i][k] * b[k][j])\n \nprint \"\\nResultant matrix is \\n\"\nfor i in range(0,m):\n for j in range(0,l):\n sys.stdout.write(\"%6d\"%(c[i][j]))\n sys.stdout.write(\"\\n\")", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 8, Page Number : PTR-24", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 32, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter a string : GOOD LUCK to all\n"}, {"output_type": "stream", "name": "stdout", "text": "\nNumber of vowels = 5\n"}], "source": "count = 0\n\nst = raw_input(\"\\nEnter a string : \")\nsptr = st\ni = 0\n\nwhile i < len(st):\n if st[i].upper() == 'A' or st[i].upper() == 'E' or st[i].upper() == 'I' or st[i].upper() == 'O' or st[i].upper() == 'U':\n count = count + 1\n i = i + 1\n \nprint \"\\nNumber of vowels = \",count", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 9, Page Number : PTR-25", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 2, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many names ?4\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter all names \n\n"}, {"output_type": "stream", "name": "stdout", "text": "DEEPAK\n"}, {"output_type": "stream", "name": "stdout", "text": "SHERIN\n"}, {"output_type": "stream", "name": "stdout", "text": "SONIKA\n"}, {"output_type": "stream", "name": "stdout", "text": "ARUN\n"}, {"output_type": "stream", "name": "stdout", "text": "\nThe name list in alphabetical order\nARUN\nDEEPAK\nSHERIN\nSONIKA\n"}], "source": "def sort_names(sn,n):\n for i in range(0,n):\n for j in range(i+1,n):\n if sn[i] > sn[j]:\n temp = sn[i]\n sn[i] = sn[j]\n sn[j] = temp\n \n\nn = int(raw_input(\"\\nHow many names ?\"))\n\nsnames = [\"\" for i in range(0,10)]\n\nprint \"\\nEnter all names \\n\"\nfor i in range(0,n):\n snames[i] = raw_input(\"\")\n \nsort_names(snames,n)\n\nprint \"\\nThe name list in alphabetical order\"\nfor i in range(0,n):\n print snames[i]", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 10, Page Number : PTR-27", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 4, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter a string : \n"}, {"output_type": "stream", "name": "stdout", "text": "LIRIL\n"}, {"output_type": "stream", "name": "stdout", "text": "LIRIL is a palindrome string\n"}], "source": "print \"\\nEnter a string : \"\nst = raw_input(\"\")\nrst = ['' for i in range(0,80)]\n\nrst = st[::-1]\n \nif st == rst:\n print st,\" is a palindrome string\"\nelse:\n print st,\" is not a palindrome string\"", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 11, Page Number : PTR-28", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 5, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter a string : \n"}, {"output_type": "stream", "name": "stdout", "text": "NEW DELHI\n"}, {"output_type": "stream", "name": "stdout", "text": "\nThe copied string : NEW DELHI\n"}], "source": "print \"\\nEnter a string : \"\nst = raw_input(\"\")\n\n#There is no pointer concept in python\ncity = st\n\nprint \"\\nThe copied string : \",city", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 12, Page Number : PTR-30", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 9, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter register No.:101\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter student name : Ashwin\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter total marks : 89\n"}, {"output_type": "stream", "name": "stdout", "text": "\n\tDetails entered are \n\n\nReg.No, : 101\n\nName : Ashwin\n\nTotal : 89\n"}], "source": "#class is used instead of structure in python\n\nclass student():\n rno = 0\n sname = ''\n tot = 0\n\nsptr = student()\nsptr.rno = int(raw_input(\"\\nEnter register No.:\"))\nsptr.sname = raw_input(\"\\nEnter student name : \")\nsptr.tot = int(raw_input(\"\\nEnter total marks : \"))\n\nprint \"\\n\\tDetails entered are \\n\"\nprint \"\\nReg.No, : \",sptr.rno\nprint \"\\nName : \",sptr.sname\nprint \"\\nTotal : \",sptr.tot\n\n", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 13, Page Number : PTR-32", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 10, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter two integers : 5\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "Sum a + b = 8\n\nProduct a * b = 15\n"}], "source": "#There is no pointer concept in python\ndef add(x,y):\n return x+y\n\ndef multiply(x,y):\n return x*y\n\na = int(raw_input(\"\\nEnter two integers : \"))\nb = int(raw_input(\"\"))\n\nsum1 = add(a,b)\n\nprint \"Sum a + b = \",sum1\n\nproduct = multiply(a,b)\nprint \"\\nProduct a * b = \",product", "metadata": {"collapsed": false, "trusted": false}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": "", "metadata": {"collapsed": false, "trusted": false}}], "nbformat_minor": 0} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter12_2.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter12_2.ipynb
new file mode 100755
index 00000000..688e408b
--- /dev/null
+++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter12_2.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 12: Files", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1, Page Number : FLS-7", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "fp = open(\"SAMPLE.TXT\",\"w\")\n\nprint \"\\nType the text press enter key at end.\\n\\n\"\n\nch = raw_input(\"\")\nfp.write(ch)\n\nfp.close()", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nType the text press enter key at end.\n\n\nComputer Programming in C language is widely used for Science and Engineering applications.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2, Page Number : FLS-8", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "import sys\n\ncount = 0 \n\nfp = open(\"SAMPLE.TXT\",\"r\")\n\nprint \"\\nThe content of the text file is : \\n\\n\"\n\nch = fp.read()\n\nfor i in ch:\n sys.stdout.write(\"%c\"%(i))\n if i.upper() == 'A' or i.upper() == 'E' or i.upper() == 'I' or i.upper() == 'O' or i.upper() == 'U':\n count = count + 1\n \nprint \"\\nNumber of vowels present = \",count\nfp.close()", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nThe content of the text file is : \n\n\nComputer Programming in C language is widely used for Science and Engineering applications.\nNumber of vowels present = 31\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3, Page Number : FLS-10", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "fp = open(\"STUDENT.DAT\",\"w\")\n\nn = int(raw_input(\"\\nHow many students ? \"))\n\nfor i in range(0,n):\n rno = int(raw_input(\"\\nStudent roll no., name, total ? \"))\n sname = raw_input(\"\")\n tot = int(raw_input(\"\"))\n fp.write(\"%d %s %d\\n\"%(rno,sname,tot))\n \nfp.close()", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many students ? 3\n\nStudent roll no., name, total ? 101\nARUN\n78\n\nStudent roll no., name, total ? 102\nDEEPAK\n72\n\nStudent roll no., name, total ? 103\nSUSHMITHA\n86\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4, Page Number : FLS-11", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "fptr = open(\"STUDENT.DAT\",\"r\")\n\nprint \"\\n--------------------------------------------------------\"\nprint \"\\n Roll No Name Total \"\nprint \"\\n--------------------------------------------------------\"\n\nrno = 0\nsname = ''\ntot = 0\n\nlines = fptr.readlines()\n\nfor line in lines:\n rno,sname,tot = line.split(' ')\n tot = int(tot)\n if tot >= 75:\n print \"\\n \",rno,\"\\t\",sname,\"\\t\\t\",tot\n \nprint \"\\n--------------------------------------------------------\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\n--------------------------------------------------------\n\n Roll No Name Total \n\n--------------------------------------------------------\n\n 101 \tARUN \t\t78\n\n 103 \tSUSHMITHA \t\t86\n\n--------------------------------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5, Page Number : FLS-12", "cell_type": "markdown", "metadata": {}}, {"execution_count": 23, "cell_type": "code", "source": "ch = 'y'\n\nfp = open(\"STUDENT.DAT\",\"a\")\n\nwhile ch.upper() == 'Y':\n rno = int(raw_input(\"\\nStudent roll no., name, total ? \"))\n sname = raw_input(\"\")\n tot = int(raw_input(\"\"))\n fp.write(\"%d %s %d\\n\"%(rno,sname,tot))\n print \"\\nPress y - to add more records\"\n print \"\\n any other key to stop.\"\n ch = raw_input(\"\")\n \nprint \"\\n-------------------------------------------------------\"\nprint \"\\n Roll No. Name Total\"\nprint \"\\n-------------------------------------------------------\"\n\nrno = 0\nsname = ''\ntot = 0\n\nfp.close()\nfp = open(\"STUDENT.DAT\",\"r\")\n\nlines = fp.readlines()\n\nfor line in lines:\n rno,sname,tot = line.split(' ')\n print \"\\n \",rno,\"\\t\\t\",sname,\"\\t\\t\",tot\n \nprint \"\\n--------------------------------------------------------\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nStudent roll no., name, total ? 104\nRAHUL\n67\n\nPress y - to add more records\n\n any other key to stop.\nN\n\n-------------------------------------------------------\n\n Roll No. Name Total\n\n-------------------------------------------------------\n\n 101 \t\tARUN \t\t78\n\n\n 102 \t\tDEEPAK \t\t72\n\n\n 103 \t\tSUSHMITHA \t\t86\n\n\n 104 \t\tRAHUL \t\t67\n\n\n--------------------------------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6, Page Number : FLS-14", "cell_type": "markdown", "metadata": {}}, {"execution_count": 26, "cell_type": "code", "source": "source_name = raw_input(\"\\nEnter the source file name : \")\n\nsource_fptr = open(source_name,\"r\")\n\ntarget_name = raw_input(\"\\nEnter the target file name : \")\ntarget_fptr = open(target_name,\"w+\")\n\nif source_fptr == 0:\n print \"\\nNo content/source file !!!\"\n print \"\\n press any key...\"\nelse:\n while True:\n ch = source_fptr.read(1)\n if not ch:\n break\n target_fptr.write(\"%c\"%(ch))\n \ntarget_fptr.close()\ntarget_fptr = open(target_name,\"r\")\n\nprint \"\\nThe contents of the target file are\"\nprint \"\\n---------------------------------------\\n\"\nlines = target_fptr.readlines()\n\nfor line in lines:\n print line\n \ntarget_fptr.close()\nsource_fptr.close()\nprint \"\\n\\n Press any key...\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter the source file name : SAMPLE.TXT\n\nEnter the target file name : SAMPLE.BAK\n\nThe contents of the target file are\n\n---------------------------------------\n\nComputer Programming in C language is widely used for Science and Engineering applications.\n\n\n Press any key...\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7, Page Number : FLS-15", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "ch = 'y'\n\nwhile ch == 'y' or ch == 'Y':\n print \"\\n\\t MENU\"\n print \"\\n\\t-------------------------------------------\"\n print \"\\n\\tPress 1 to create data file\"\n print \"\\n\\t 2 to find smallest & largest integer\"\n \n choice = int(raw_input(\"\\n\\n\\tEnter your choice : \"))\n \n if choice == 1:\n data_file = open(\"DATAFILE\",\"w\")\n n = int(raw_input(\"\\nEnter data, enter 0 at end of reading\\n\"))\n while n != 0:\n data_file.write(\"%d\\n\"%(n))\n n = int(raw_input(\"\"))\n data_file.close()\n else:\n if choice == 2:\n data_file = open(\"DATAFILE\",\"r\")\n n1 = data_file.readlines()\n n = n1[0]\n big = n\n small = n\n for n in n1:\n if n > big:\n big = n \n if n < small:\n small = n\n \n data_file.close()\n print \"\\nLargest integer is \",big\n print \"\\nSmallest integer is \",small\n else:\n print \"\\nWrong choice !!!\" \n ch = raw_input(\"\\n\\nPress Y to continue, any other key to stop...\")\n \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\n\t MENU\n\n\t-------------------------------------------\n\n\tPress 1 to create data file\n\n\t 2 to find smallest & largest integer\n\n\n\tEnter your choice : 1\n\nEnter data, enter 0 at end of reading\n23\n6\n76\n-56\n876\n52\n0\n\n\nPress Y to continue, any other key to stop...y\n\n\t MENU\n\n\t-------------------------------------------\n\n\tPress 1 to create data file\n\n\t 2 to find smallest & largest integer\n\n\n\tEnter your choice : 2\n\nLargest integer is 876\n\n\nSmallest integer is -56\n\n\n\nPress Y to continue, any other key to stop...n\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8, Page Number : FLS-20", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "import os\n\nclass emp_record:\n eno = 0\n ename = ''\n bpay = 0.0\n \nerec = emp_record()\n\ndef creatfile():\n choice = 'y'\n efile = open(\"EMPLOY.DAT\",\"w\")\n while choice.upper() == 'Y':\n erec.eno = int(raw_input(\"\\nEnter the employee No.\"))\n erec.ename = raw_input(\"\\nEmployee Name ?\")\n erec.bpay = float(raw_input(\"\\nBasic pay ?\"))\n efile.write(\"%d %s %f\\n\"%(erec.eno,erec.ename,erec.bpay))\n print \"\\n Press Y - to continue\"\n print \"\\n any other key to stop.\"\n choice = raw_input(\"\")\n efile.close()\n \ndef readfile():\n eno = 0\n ename = ''\n bpay = 0.0\n efile = open(\"EMPLOY.DAT\",\"r\")\n print \"\\n----------------------------------------------------\"\n print \"\\n Emp.No. Employee Name Basic pay\"\n print \"\\n----------------------------------------------------\"\n lines = efile.readlines()\n \n for line in lines:\n eno,ename,bpay = line.split(' ')\n print \"\\n\",eno,\"\\t\",ename,\"\\t\",bpay\n print \"\\n----------------------------------------------------\"\n\ndef appendrec():\n choice = 'y'\n efile = open(\"EMPLOY.DAT\",\"a\")\n while choice.upper() == 'Y':\n erec.eno = int(raw_input(\"\\nEnter the employee No. \"))\n erec.ename = raw_input(\"\\nEmployee Name ? \")\n erec.bpay = float(raw_input(\"\\nBasic pay ?\"))\n efile.write(\"%d %s %f\\n\"%(erec.eno,erec.ename,erec.bpay))\n print \"\\nPress Y - to continue\"\n print \"\\n any other key to stop.\"\n choice = raw_input(\"\")\n efile.close()\n \ndef modirec():\n flag = 0\n eno = 0\n ename = ''\n bpay = 0.0\n efile = open(\"EMPLOY.DAT\",\"r+\")\n print \"\\nTo modify a record \"\n print \"\\n------------------\"\n temp = int(raw_input(\"\\nEnter the Roll No.\"))\n lines = efile.readlines()\n for line in lines:\n #while True and flag == 0:\n eno,ename,bpay = line.split(' ')\n if eno == temp:\n print \"\\nExisting record details\"\n print \"\\n\",eno,\"\\t\",ename,\"\\t\",bpay\n print \"\\n\\nEnter the modified details\"\n print \"\\n------------------------------\"\n erec.eno = int(raw_input(\"\\nEnter the employee No. \"))\n erec.ename = raw_input(\"\\nEmployee Name ? \")\n erec.bpay = float(raw_input(\"\\nBasic pay ?\"))\n efile.write(\"%d %s %f\\n\"%(erec.eno,erec.ename,erec.bpay))\n flag = 1\n print \"\\nThe record has been modified!\"\n efile.close()\n if flag == 0:\n print \"\\nThe given record is not present in the file!!!\"\n print \"\\nPress any key to continue ...\"\n \ndef deleterec():\n flag = 0\n eno = 0\n ename = ''\n bpay = 0.0\n efile = open(\"EMPLOY.DAT\",\"r\")\n tfile = open(\"TEMP.DAT\",\"w\")\n print \"\\nTo delete a record\"\n print \"\\n------------------\"\n temp = int(raw_input(\"\\nEnter the Roll No.\"))\n while True:\n eno,ename,bpay = efile.readline().split(' ')\n if eno == temp:\n print \"\\nExisting record details\"\n print \"\\n\",eno,\"\\t\",ename,\"\\t\",bpay\n print \"\\n is deleted!!!\"\n flag = 1\n tfile.write(\"%d %s %f\\n\"%(eno,ename,bpay))\n tfile.close()\n efile.close()\n os.remove(\"EMPLOY.DAT\")\n os.rename(\"TEMP.DAT\",\"EMPLOY.DAT\")\n if flag == 0:\n print \"\\nThe given record is not present in the file!!!\"\n print \"\\n\\tpress any key to continue...\"\n \nn = 0\nwhile n != 6:\n print \"\\n\\tMain Menu\"\n print \"\\n\\t Press 1 - file creation\"\n print \"\\n\\t 2 - reading\"\n print \"\\n\\t 3 - appending\"\n print \"\\n\\t 4 - modify a record\"\n print \"\\n\\t 5 - delete a record\"\n print \"\\n\\t 6 - quit\"\n n = int(raw_input(\"\\n\\nEnter your choice : \"))\n \n if n == 1:\n creatfile()\n else:\n if n == 2:\n readfile()\n else:\n if n == 3:\n appendrec()\n else:\n if n == 4:\n modirec()\n else:\n if n == 5:\n deleterec()\n \n \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\n\tMain Menu\n\n\t Press 1 - file creation\n\n\t 2 - reading\n\n\t 3 - appending\n\n\t 4 - modify a record\n\n\t 5 - delete a record\n\n\t 6 - quit\n\n\nEnter your choice : 1\n\nEnter the employee No.2101\n\nEmployee Name ?ARUN\n\nBasic pay ?8500\n\n Press Y - to continue\n\n any other key to stop.\nY\n\nEnter the employee No.2102\n\nEmployee Name ?DEEPAK\n\nBasic pay ?8000\n\n Press Y - to continue\n\n any other key to stop.\nN\n\n\tMain Menu\n\n\t Press 1 - file creation\n\n\t 2 - reading\n\n\t 3 - appending\n\n\t 4 - modify a record\n\n\t 5 - delete a record\n\n\t 6 - quit\n\n\nEnter your choice : 2\n\n----------------------------------------------------\n\n Emp.No. Employee Name Basic pay\n\n----------------------------------------------------\n\n2101 \tARUN \t8500.000000\n\n\n2102 \tDEEPAK \t8000.000000\n\n\n----------------------------------------------------\n\n\tMain Menu\n\n\t Press 1 - file creation\n\n\t 2 - reading\n\n\t 3 - appending\n\n\t 4 - modify a record\n\n\t 5 - delete a record\n\n\t 6 - quit\n\n\nEnter your choice : 3\n\nEnter the employee No. 2103\n\nEmployee Name ? SUSHMITHA\n\nBasic pay ?6400\n\nPress Y - to continue\n\n any other key to stop.\nY\n\nEnter the employee No. 2104\n\nEmployee Name ? ASHIKA\n\nBasic pay ?6200\n\nPress Y - to continue\n\n any other key to stop.\nN\n\n\tMain Menu\n\n\t Press 1 - file creation\n\n\t 2 - reading\n\n\t 3 - appending\n\n\t 4 - modify a record\n\n\t 5 - delete a record\n\n\t 6 - quit\n\n\nEnter your choice : 4\n\nTo modify a record \n\n------------------\n\nEnter the Roll No.2101\n\nThe given record is not present in the file!!!\n\nPress any key to continue ...\n\n\tMain Menu\n\n\t Press 1 - file creation\n\n\t 2 - reading\n\n\t 3 - appending\n\n\t 4 - modify a record\n\n\t 5 - delete a record\n\n\t 6 - quit\n\n\nEnter your choice : 6\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter13_2.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter13_2.ipynb
new file mode 100755
index 00000000..12f74896
--- /dev/null
+++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter13_2.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 13: C Preprocessor and Command Line Arguments", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1, Page Number : PCL-3", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "def BIG(a,b):\n if a > b:\n return a\n else:\n return b\n \ndef WAITMSG():\n return \"\\nPress any key to continue...\"\n \nx = int(raw_input(\"\\nEnter two integers : \"))\ny = int(raw_input(\"\"))\n\nprint \"\\nBiggest integer is \",BIG(x,y),WAITMSG()", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter two integers : 5\n8\n\nBiggest integer is 8 \nPress any key to continue...\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2, Page Number : PCL-6", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "import time\n\nargv1 = \"SAMPLE.TXT\"\nargv2 = \"SAMPLE.BAK\"\n\nsource_fptr = open(\"SAMPLE.TXT\",\"r\")\ntarget_fptr = open(\"SAMPLE.BAK\",\"w+\")\n\nif source_fptr == 0:\n print \"\\nNo content/source file!!!\"\n print \"\\n press any key to continue...\"\nelse:\n print \"\\nCopying source file \",argv1,\" to target file \",argv2\n print \"\\n please wait.\"\n print \".\"\n print \".\"\n print \".\"\n print \".\"\n\n if target_fptr == 0:\n print \"\\nNo content/target file!!!\"\n print \"\\n\\n Press any key to continue...\"\n else:\n while True:\n ch = source_fptr.read(1)\n if not ch:\n break\n target_fptr.write(\"%c\"%(ch))\n print \"\\n\\nCopy completed, the target file contents\"\n print \"\\n----------------------------------------\\n\"\n target_fptr.close()\n target_fptr = open(\"SAMPLE.BAK\",\"r\")\n ch = target_fptr.readlines()\n for line in ch:\n print line\n source_fptr.close()\n target_fptr.close()\n print \"\\n\\n press any key to continue...\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nCopying source file SAMPLE.TXT to target file SAMPLE.BAK\n\n please wait.\n.\n.\n.\n.\n\n\nCopy completed, the target file contents\n\n----------------------------------------\n\nComputer Programming in C language is widely used for Science and Engineering applications.\n\n\n press any key to continue...\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter14_2.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter14_2.ipynb
new file mode 100755
index 00000000..97af65db
--- /dev/null
+++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter14_2.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 14: Graphics Using C", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1, Page Number : GUC-4", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "\n\na = int(raw_input(\"Enter the first number : \"))\nb = int(raw_input(\"Enter the second number : \"))\n\nif a > b:\n print a, \" IS THE BIGGEST NUMBER\"\nelse:\n print b, \" IS THE BIGGEST NUMBER\"\n \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the first number : 5\nEnter the second number : 3\n5 IS THE BIGGEST NUMBER\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2, Page Number : GUC-10", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "%matplotlib inline\n\nimport pylab\nimport matplotlib.pyplot as plt\n\nx1 = int(raw_input(\"Enter start point coordinate : \"))\ny1 = int(raw_input())\n\nx2 = int(raw_input(\"Enter end point coordinate : \"))\ny2 = int(raw_input())\n\n\npylab.plot([x1,y1],[x2,y2])", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter start point coordinate : 100\n200\nEnter end point coordinate : 150\n200\n"}, {"execution_count": 2, "output_type": "execute_result", "data": {"text/plain": "[<matplotlib.lines.Line2D at 0x9feae48>]"}, "metadata": {}}, {"output_type": "display_data", "data": {"image/png": "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\n", "text/plain": "<matplotlib.figure.Figure at 0x9ef5a90>"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3, Page Number : GUC-11", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "%matplotlib inline\n\n\nimport pylab\nimport matplotlib.pyplot as plt\n#Tkinter package is used for graphics\nfrom matplotlib.patches import Rectangle\nfrom matplotlib.collections import PatchCollection\n\ne = Rectangle(xy=(35, -50), width=80, height=80)\nfig = plt.gcf()\nfig.gca().add_artist(e)\n#e.set_clip_box(ax.bbox)\ne.set_alpha(0.7)\npylab.xlim([20, 50])\npylab.ylim([-65, -35])\n", "outputs": [{"execution_count": 3, "output_type": "execute_result", "data": {"text/plain": "(-65, -35)"}, "metadata": {}}, {"output_type": "display_data", "data": {"image/png": "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\nHUnSMubJTp+MlaTmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6Tm\nDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJ\nas6gl6TmDHpJas6gl6TmDHpJam7uoE+yJ8nBJPuHn7cN7ackeXqi/frVK1eSNKstIz5bwHVVdd2U\nvgeq6uwR55YkrZKxWzdZlSokSWtmbNBfnuSeJDckeelE+45h22YhyZtHXkOSNEKqavnOZC+wdUrX\nVcCdwGPD8UeAE6vq/UmOAV5cVYeSnAPcBpxRVU8uOXcBfzvRtFBVC3OPRJIaSrIL2DXR9OGqmmk3\nZcWgn6GQU4Dbq+rVU/ruAK6oqruWtNesxUrS89082TnmrpsTJw7fAdw3tB+f5IXD653AqcCD815H\nkjTOmLturk1yFot33zwE7B7azweuTnIYOALsrqonxpUpSZrXqmzdzHVht24kaWbrunUjSdocDHpJ\nas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6g\nl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6Tm\nDHpJam5U0Ce5PMm3knwjybUT7VcmuT/Jt5NcOL5MSdK8tsz7wSRvAS4GXlNVh5P8xtB+OvBO4HTg\nZGBfktOq6shqFCxJms2YFf2lwDVVdRigqh4b2i8Bbqqqw1X1MPAAcN6oKiVJcxsT9KcC5ye5M8lC\nktcN7ScBByfed5DFlb0kaQOsuHWTZC+wdUrXVcNnX1ZVb0zyeuBmYOcyp6pRVUqS5rZi0FfVBcv1\nJbkUuHV4338mOZLkeOARYPvEW7cNbdPOsWficKGqFp5d2ZL0/JBkF7Br1Dmq5ltsJ9kNnFRVH05y\nGrCvql4x/DL2syzuy58M7ANeWUsulKSqKmOKl6Tnm3myc+67boAbgRuT3Af8FHgPQFUdSHIzcAD4\nGXDZ0pCXJK2fuVf0oy/sil6SZjZPdvpkrCQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BL\nUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMG\nvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnOjgj7J5Um+leQbSa4d2k5J8nSS/cPP\n9atTqiRpHnMHfZK3ABcDr6mqM4G/n+h+oKrOHn4uG1vkZpRk10bXsJYc3+bWeXydxzavMSv6S4Fr\nquowQFU9tjoltbFrowtYY7s2uoA1tmujC1hjuza6gDW0a6MLeK4ZE/SnAucnuTPJQpLXTfTtGLZt\nFpK8eWSNkqQRtqzUmWQvsHVK11XDZ19WVW9M8nrgZmAn8D1ge1UdSnIOcFuSM6rqyVWuXZL0LKSq\n5vtg8u/AR6vqS8PxA8AbqupHS953B3BFVd21pH2+C0vS81xVZZb3r7ii/3/cBrwV+FKS04BjqupH\nSY4HDlXVM0l2srjF8+DYQiVJ8xkT9DcCNya5D/gp8J6h/Xzg6iSHgSPA7qp6YlyZkqR5zb11I0na\nHNblydgk25PckeSbw8NVfza0vzzJ3iTfSfKFJC9dj3pW2wrj25Pk4MTDY2/b6FpnleRXk3wlyd1J\nDiS5ZmjvMnfLjW/Tz92kJC8cxnH7cNxi/o6aMr4285fk4ST3DuP46tA20/yty4o+yVZga1XdneQl\nwNeB3wPeB/ywqj6W5K9ZvIvng2te0CpbYXx/ADxZVddtaIEjJfm1qnoqyRbgy8Bfsviw3KafO1h2\nfL9Ng7k7KslfAOcCx1bVxUk+RpP5g6nj+zBN5i/JQ8C5VfX4RNtM87cuK/qq+u+qunt4/RPgW8DJ\nLIbFp4a3fYrFcNx0VhgfwKb/pXNVPTW8PAZ4IXCIJnMHy44PGswdQJJtwO8Cn+QXY2ozf8uMLzSZ\nv8HSscw0f+v+j5olOQU4G/gKcEJV/WDo+gFwwnrXs9omxnfn0HR5knuS3LBZvx4neUGSu1mcozuq\n6ps0mrtlxgcN5m7wD8BfsXhzxFFt5o/p4yv6zF8B+5J8LcmfDG0zzd+6Bv2wrXEL8OdLH6CqxT2k\nTf2b4WF8/8Li+H4CfALYAZwFfB/4+AaWN7eqOlJVZwHbWHwa+i1L+jf13E0Z3y6azF2Si4BHq2o/\ny6xwN/P8rTC+FvM3eFNVnQ28HfjTJL812fls5m/dgj7Jr7AY8p+pqtuG5h8M+9skORF4dL3qWW0T\n4/uno+OrqkdrwOLXyvM2ssaxqurHwL+yuBfaZu6Omhjf6xrN3W8CFw/7vDcBb03yGfrM37TxfbrR\n/FFV3x/+fAz4HItjmWn+1uuumwA3AAeq6h8nuj4PvHd4/V4WH8LadJYb3zABR70DuG+9axsryfFH\nv/YmeRFwAbCfPnM3dXxH/xINNuXcAVTVh6pqe1XtAN4F/EdVvZsm87fM+N7T4e8eLN4okOTY4fWL\ngQtZHMtM8zfmgalZvAn4I+DeJPuHtiuBjwI3J3k/8DCLd6lsRtPG9yHgD5OcxeLXqoeA3RtU3xgn\nAp9K8gIWFwafqaovDuPsMHfLje/TDeZumqNf8bv83ZsUfjG+jyV5LZt//k4APre4lmQL8M9V9YUk\nX2OG+fOBKUlqzv+VoCQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnP/C7+GpbcMbuV8\nAAAAAElFTkSuQmCC\n", "text/plain": "<matplotlib.figure.Figure at 0x9ed2f60>"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4, Page Number : GUC-13", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "%matplotlib inline\n\nimport pylab\nimport matplotlib.pyplot as plt\n\n\npylab.plot([20,50],[40,100])\npylab.plot([50,70],[100,40])\npylab.plot([20,70],[40,40])\n", "outputs": [{"execution_count": 5, "output_type": "execute_result", "data": {"text/plain": "[<matplotlib.lines.Line2D at 0xa289e80>]"}, "metadata": {}}, {"output_type": "display_data", "data": {"image/png": "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\n", "text/plain": "<matplotlib.figure.Figure at 0xa126748>"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5, Page Number: GUC-17", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "%matplotlib inline\n\n\nimport pylab\nimport matplotlib.pyplot as plt\n#Tkinter package is used for graphics\nfrom matplotlib.patches import Rectangle\nfrom matplotlib.collections import PatchCollection\n\ne = Rectangle(xy=(35, -50), width=80, height=80)\nfig = plt.gcf()\nfig.gca().add_artist(e)\n#e.set_clip_box(ax.bbox)\ne.set_alpha(0.7)\npylab.xlim([20, 50])\npylab.ylim([-65, -35])", "outputs": [{"execution_count": 6, "output_type": "execute_result", "data": {"text/plain": "(-65, -35)"}, "metadata": {}}, {"output_type": "display_data", "data": {"image/png": "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\nHUnSMubJTp+MlaTmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6Tm\nDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJ\nas6gl6TmDHpJas6gl6TmDHpJam7uoE+yJ8nBJPuHn7cN7ackeXqi/frVK1eSNKstIz5bwHVVdd2U\nvgeq6uwR55YkrZKxWzdZlSokSWtmbNBfnuSeJDckeelE+45h22YhyZtHXkOSNEKqavnOZC+wdUrX\nVcCdwGPD8UeAE6vq/UmOAV5cVYeSnAPcBpxRVU8uOXcBfzvRtFBVC3OPRJIaSrIL2DXR9OGqmmk3\nZcWgn6GQU4Dbq+rVU/ruAK6oqruWtNesxUrS89082TnmrpsTJw7fAdw3tB+f5IXD653AqcCD815H\nkjTOmLturk1yFot33zwE7B7azweuTnIYOALsrqonxpUpSZrXqmzdzHVht24kaWbrunUjSdocDHpJ\nas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6g\nl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6Tm\nDHpJam5U0Ce5PMm3knwjybUT7VcmuT/Jt5NcOL5MSdK8tsz7wSRvAS4GXlNVh5P8xtB+OvBO4HTg\nZGBfktOq6shqFCxJms2YFf2lwDVVdRigqh4b2i8Bbqqqw1X1MPAAcN6oKiVJcxsT9KcC5ye5M8lC\nktcN7ScBByfed5DFlb0kaQOsuHWTZC+wdUrXVcNnX1ZVb0zyeuBmYOcyp6pRVUqS5rZi0FfVBcv1\nJbkUuHV4338mOZLkeOARYPvEW7cNbdPOsWficKGqFp5d2ZL0/JBkF7Br1Dmq5ltsJ9kNnFRVH05y\nGrCvql4x/DL2syzuy58M7ANeWUsulKSqKmOKl6Tnm3myc+67boAbgRuT3Af8FHgPQFUdSHIzcAD4\nGXDZ0pCXJK2fuVf0oy/sil6SZjZPdvpkrCQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BL\nUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMG\nvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnOjgj7J5Um+leQbSa4d2k5J8nSS/cPP\n9atTqiRpHnMHfZK3ABcDr6mqM4G/n+h+oKrOHn4uG1vkZpRk10bXsJYc3+bWeXydxzavMSv6S4Fr\nquowQFU9tjoltbFrowtYY7s2uoA1tmujC1hjuza6gDW0a6MLeK4ZE/SnAucnuTPJQpLXTfTtGLZt\nFpK8eWSNkqQRtqzUmWQvsHVK11XDZ19WVW9M8nrgZmAn8D1ge1UdSnIOcFuSM6rqyVWuXZL0LKSq\n5vtg8u/AR6vqS8PxA8AbqupHS953B3BFVd21pH2+C0vS81xVZZb3r7ii/3/cBrwV+FKS04BjqupH\nSY4HDlXVM0l2srjF8+DYQiVJ8xkT9DcCNya5D/gp8J6h/Xzg6iSHgSPA7qp6YlyZkqR5zb11I0na\nHNblydgk25PckeSbw8NVfza0vzzJ3iTfSfKFJC9dj3pW2wrj25Pk4MTDY2/b6FpnleRXk3wlyd1J\nDiS5ZmjvMnfLjW/Tz92kJC8cxnH7cNxi/o6aMr4285fk4ST3DuP46tA20/yty4o+yVZga1XdneQl\nwNeB3wPeB/ywqj6W5K9ZvIvng2te0CpbYXx/ADxZVddtaIEjJfm1qnoqyRbgy8Bfsviw3KafO1h2\nfL9Ng7k7KslfAOcCx1bVxUk+RpP5g6nj+zBN5i/JQ8C5VfX4RNtM87cuK/qq+u+qunt4/RPgW8DJ\nLIbFp4a3fYrFcNx0VhgfwKb/pXNVPTW8PAZ4IXCIJnMHy44PGswdQJJtwO8Cn+QXY2ozf8uMLzSZ\nv8HSscw0f+v+j5olOQU4G/gKcEJV/WDo+gFwwnrXs9omxnfn0HR5knuS3LBZvx4neUGSu1mcozuq\n6ps0mrtlxgcN5m7wD8BfsXhzxFFt5o/p4yv6zF8B+5J8LcmfDG0zzd+6Bv2wrXEL8OdLH6CqxT2k\nTf2b4WF8/8Li+H4CfALYAZwFfB/4+AaWN7eqOlJVZwHbWHwa+i1L+jf13E0Z3y6azF2Si4BHq2o/\ny6xwN/P8rTC+FvM3eFNVnQ28HfjTJL812fls5m/dgj7Jr7AY8p+pqtuG5h8M+9skORF4dL3qWW0T\n4/uno+OrqkdrwOLXyvM2ssaxqurHwL+yuBfaZu6Omhjf6xrN3W8CFw/7vDcBb03yGfrM37TxfbrR\n/FFV3x/+fAz4HItjmWn+1uuumwA3AAeq6h8nuj4PvHd4/V4WH8LadJYb3zABR70DuG+9axsryfFH\nv/YmeRFwAbCfPnM3dXxH/xINNuXcAVTVh6pqe1XtAN4F/EdVvZsm87fM+N7T4e8eLN4okOTY4fWL\ngQtZHMtM8zfmgalZvAn4I+DeJPuHtiuBjwI3J3k/8DCLd6lsRtPG9yHgD5OcxeLXqoeA3RtU3xgn\nAp9K8gIWFwafqaovDuPsMHfLje/TDeZumqNf8bv83ZsUfjG+jyV5LZt//k4APre4lmQL8M9V9YUk\nX2OG+fOBKUlqzv+VoCQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnP/C7+GpbcMbuV8\nAAAAAElFTkSuQmCC\n", "text/plain": "<matplotlib.figure.Figure at 0x9ed2f98>"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6, Page Number : GUC-18", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "%matplotlib inline\n\n\nimport pylab\nimport matplotlib.pyplot as plt\n#Tkinter package is used for graphics\nfrom matplotlib.patches import Rectangle\nfrom matplotlib.collections import PatchCollection\n\ne = Rectangle(xy=(35, -50), width=80, height=80)\nfig = plt.gcf()\nfig.gca().add_artist(e)\n#e.set_clip_box(ax.bbox)\ne.set_alpha(0.7)\npylab.xlim([20, 50])\npylab.ylim([-65, -35])", "outputs": [{"execution_count": 7, "output_type": "execute_result", "data": {"text/plain": "(-65, -35)"}, "metadata": {}}, {"output_type": "display_data", "data": {"image/png": "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\nHUnSMubJTp+MlaTmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6Tm\nDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJ\nas6gl6TmDHpJas6gl6TmDHpJam7uoE+yJ8nBJPuHn7cN7ackeXqi/frVK1eSNKstIz5bwHVVdd2U\nvgeq6uwR55YkrZKxWzdZlSokSWtmbNBfnuSeJDckeelE+45h22YhyZtHXkOSNEKqavnOZC+wdUrX\nVcCdwGPD8UeAE6vq/UmOAV5cVYeSnAPcBpxRVU8uOXcBfzvRtFBVC3OPRJIaSrIL2DXR9OGqmmk3\nZcWgn6GQU4Dbq+rVU/ruAK6oqruWtNesxUrS89082TnmrpsTJw7fAdw3tB+f5IXD653AqcCD815H\nkjTOmLturk1yFot33zwE7B7azweuTnIYOALsrqonxpUpSZrXqmzdzHVht24kaWbrunUjSdocDHpJ\nas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6g\nl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6TmDHpJas6gl6Tm\nDHpJam5U0Ce5PMm3knwjybUT7VcmuT/Jt5NcOL5MSdK8tsz7wSRvAS4GXlNVh5P8xtB+OvBO4HTg\nZGBfktOq6shqFCxJms2YFf2lwDVVdRigqh4b2i8Bbqqqw1X1MPAAcN6oKiVJcxsT9KcC5ye5M8lC\nktcN7ScBByfed5DFlb0kaQOsuHWTZC+wdUrXVcNnX1ZVb0zyeuBmYOcyp6pRVUqS5rZi0FfVBcv1\nJbkUuHV4338mOZLkeOARYPvEW7cNbdPOsWficKGqFp5d2ZL0/JBkF7Br1Dmq5ltsJ9kNnFRVH05y\nGrCvql4x/DL2syzuy58M7ANeWUsulKSqKmOKl6Tnm3myc+67boAbgRuT3Af8FHgPQFUdSHIzcAD4\nGXDZ0pCXJK2fuVf0oy/sil6SZjZPdvpkrCQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BL\nUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMG\nvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnOjgj7J5Um+leQbSa4d2k5J8nSS/cPP\n9atTqiRpHnMHfZK3ABcDr6mqM4G/n+h+oKrOHn4uG1vkZpRk10bXsJYc3+bWeXydxzavMSv6S4Fr\nquowQFU9tjoltbFrowtYY7s2uoA1tmujC1hjuza6gDW0a6MLeK4ZE/SnAucnuTPJQpLXTfTtGLZt\nFpK8eWSNkqQRtqzUmWQvsHVK11XDZ19WVW9M8nrgZmAn8D1ge1UdSnIOcFuSM6rqyVWuXZL0LKSq\n5vtg8u/AR6vqS8PxA8AbqupHS953B3BFVd21pH2+C0vS81xVZZb3r7ii/3/cBrwV+FKS04BjqupH\nSY4HDlXVM0l2srjF8+DYQiVJ8xkT9DcCNya5D/gp8J6h/Xzg6iSHgSPA7qp6YlyZkqR5zb11I0na\nHNblydgk25PckeSbw8NVfza0vzzJ3iTfSfKFJC9dj3pW2wrj25Pk4MTDY2/b6FpnleRXk3wlyd1J\nDiS5ZmjvMnfLjW/Tz92kJC8cxnH7cNxi/o6aMr4285fk4ST3DuP46tA20/yty4o+yVZga1XdneQl\nwNeB3wPeB/ywqj6W5K9ZvIvng2te0CpbYXx/ADxZVddtaIEjJfm1qnoqyRbgy8Bfsviw3KafO1h2\nfL9Ng7k7KslfAOcCx1bVxUk+RpP5g6nj+zBN5i/JQ8C5VfX4RNtM87cuK/qq+u+qunt4/RPgW8DJ\nLIbFp4a3fYrFcNx0VhgfwKb/pXNVPTW8PAZ4IXCIJnMHy44PGswdQJJtwO8Cn+QXY2ozf8uMLzSZ\nv8HSscw0f+v+j5olOQU4G/gKcEJV/WDo+gFwwnrXs9omxnfn0HR5knuS3LBZvx4neUGSu1mcozuq\n6ps0mrtlxgcN5m7wD8BfsXhzxFFt5o/p4yv6zF8B+5J8LcmfDG0zzd+6Bv2wrXEL8OdLH6CqxT2k\nTf2b4WF8/8Li+H4CfALYAZwFfB/4+AaWN7eqOlJVZwHbWHwa+i1L+jf13E0Z3y6azF2Si4BHq2o/\ny6xwN/P8rTC+FvM3eFNVnQ28HfjTJL812fls5m/dgj7Jr7AY8p+pqtuG5h8M+9skORF4dL3qWW0T\n4/uno+OrqkdrwOLXyvM2ssaxqurHwL+yuBfaZu6Omhjf6xrN3W8CFw/7vDcBb03yGfrM37TxfbrR\n/FFV3x/+fAz4HItjmWn+1uuumwA3AAeq6h8nuj4PvHd4/V4WH8LadJYb3zABR70DuG+9axsryfFH\nv/YmeRFwAbCfPnM3dXxH/xINNuXcAVTVh6pqe1XtAN4F/EdVvZsm87fM+N7T4e8eLN4okOTY4fWL\ngQtZHMtM8zfmgalZvAn4I+DeJPuHtiuBjwI3J3k/8DCLd6lsRtPG9yHgD5OcxeLXqoeA3RtU3xgn\nAp9K8gIWFwafqaovDuPsMHfLje/TDeZumqNf8bv83ZsUfjG+jyV5LZt//k4APre4lmQL8M9V9YUk\nX2OG+fOBKUlqzv+VoCQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnMGvSQ1Z9BLUnP/C7+GpbcMbuV8\nAAAAAElFTkSuQmCC\n", "text/plain": "<matplotlib.figure.Figure at 0x3ab59e8>"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7: Page Number: GUC-22", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "\n%matplotlib inline\n\nimport pylab\ncir = pylab.Circle((.5,.5),radius = 0.25)\n\nax =pylab.axes(aspect=1)\nax.add_patch(cir)", "outputs": [{"execution_count": 8, "output_type": "execute_result", "data": {"text/plain": "<matplotlib.patches.Circle at 0x9d8cd68>"}, "metadata": {}}, {"output_type": "display_data", "data": {"image/png": "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\nAAAAAElFTkSuQmCC\n", "text/plain": "<matplotlib.figure.Figure at 0xa041630>"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8, Page Number:GUC-24", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "\n%matplotlib inline\n\nimport pylab\ncir = pylab.Circle((.5,.5),radius = 0.25)\nrect = pylab.Rectangle([5,5],1,1)\n\nax =pylab.axes(aspect=1)\nax.add_patch(cir)\nax.add_patch(rect)", "outputs": [{"execution_count": 9, "output_type": "execute_result", "data": {"text/plain": "<matplotlib.patches.Rectangle at 0x9ffc4a8>"}, "metadata": {}}, {"output_type": "display_data", "data": {"image/png": "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\nAAAAAElFTkSuQmCC\n", "text/plain": "<matplotlib.figure.Figure at 0xa225be0>"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9, Page Number : GUC-25", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "\n%matplotlib inline\n\nimport pylab\ncir = pylab.Circle((.5,.5),radius = 0.5)\n\nax =pylab.axes(aspect=1)\nax.add_patch(cir)", "outputs": [{"execution_count": 10, "output_type": "execute_result", "data": {"text/plain": "<matplotlib.patches.Circle at 0x9f3f4a8>"}, "metadata": {}}, {"output_type": "display_data", "data": {"image/png": "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\n", "text/plain": "<matplotlib.figure.Figure at 0xa4680b8>"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10, Page Number : GUC-26", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "\nimport turtle\n\n\nturtle.left(90)\nturtle.forward(50)\ni=0\nwhile i < 180:\n turtle.forward(1)\n turtle.left(1)\n i+=1\n \nturtle.forward(150)\nturtle.left(90)\nturtle.forward(250)\nturtle.left(90)\nturtle.forward(100)\nturtle.left(90)\nturtle.forward(140)", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 11, Page Number : GUC-28", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "%matplotlib inline\nimport numpy as np\nfrom matplotlib import pyplot as plt\n\nOX = [1,2,3,4]\nOY = [200,590,670,435]\n\nfig = plt.figure()\n\nwidth = .35\nind = np.arange(len(OY))\nplt.bar(ind, OY)\nplt.xticks(ind + width / 2, OX)\n\nfig.autofmt_xdate()", "outputs": [{"output_type": "display_data", "data": {"image/png": "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\necN4Y04AAAAASUVORK5CYII=\n", "text/plain": "<matplotlib.figure.Figure at 0xa9aec88>"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 12, Page Number : GUC-30", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "%matplotlib inline\n\nfrom mpl_toolkits.mplot3d import Axes3D\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfig = plt.figure()\nax = fig.add_subplot(111, projection='3d')\nfor c, z in zip(['r'], [200,590,670,435]):\n xs = np.arange(20)\n ys = np.random.rand(20)\n ax.bar(xs, ys, zs=z)\n \nax.set_xlabel('X')\nax.set_ylabel('Y')\nax.set_zlabel('Z')\n\nplt.show()\n", "outputs": [{"output_type": "display_data", "data": {"image/png": "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\n", "text/plain": "<matplotlib.figure.Figure at 0x39024a8>"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 13, Page Number : GUC-31", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "%matplotlib inline\n\nfrom pylab import *\n\n# make a square figure and axes\nfigure(1, figsize=(6,6))\nax = axes([0.1, 0.1, 0.8, 0.8])\n\n# The slices will be ordered and plotted counter-clockwise.\n\nsales = [200, 590, 670, 435]\nexplode=(0, 0.05, 0, 0)\n\npie(sales, explode=explode,\n autopct='%1.1f%%', shadow=True, startangle=90)\n # The default startangle is 0, which would start\n # the Frogs slice on the x-axis. With startangle=90,\n # everything is rotated counter-clockwise by 90 degrees,\n # so the plotting starts on the positive y-axis.\n\n\n\nshow()", "outputs": [{"output_type": "display_data", "data": {"image/png": "iVBORw0KGgoAAAANSUhEUgAAAWcAAAFnCAYAAAB6uIiNAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3Xd8VFX6x/HPmT6TBEJCKBI6GLrSVSyoYEGNqLggYF37\nurrurq7rFnd/u6u7brEXrKurYFdEBBsWsGADO6H3XkPK9PP748yQEOkkuffOPO/XK6+EezPhCUy+\nuXPuc85RWmuEEELYi8vqAoQQQvyYhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQ\nhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQ\nQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQ\nhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQQtiQhLMQ\nQtiQhLMQQtiQhLMQQtiQhLMQQtiQx+oChNgVpZQPaA60AIpSby3A0xJyisHTHPACHlAe0B6obkGe\nW+FyrQXiQByt40CMZLKKSGQ5sdgqYB2wNvV+HbBRa5204NsUYreU1trqGkQWUkp5ga5AD3D1gvxB\nQDuIF0KkKcT8kBeGgjgUaWjtgkN80MoHLRQ0w2SzG3ON4QFugOGtYNgwSCR2fguHYetW2LgxyoYN\nETZsSLJli6K83Eck4sPn247XuxmXaz1aryQcXkYs9j3wFfCd1rraqn8rkZ0knEWDSoVwF6AHuHtB\n08GQ6AWVraEoDL2S0D8HermhPTUXyfns/6jbULiwA1x00f49LB6HLVtq3jZvhk2bYOHCSubPT7B+\nfYhAYC0u11y2b/8QE9hfAWu0/ACJBiLDGqJeKaUKgeMg52TwDgdPW2heK4R7u6EnUAIEcy0u1/B4\noKjIvO0sB4BoFJYvL2bRomIWLDiZ77+vYulSP4lEXDVtOo9w+BOi0c+Bj4EFEtiiPsiVszgoSql8\n4FgInQy+U6G6DQwKw2l5MFRBbyDUSNUMPbAr5wOhtbm6XrQIFi3SfP99JV9/7SIerwRep7p6MvCO\n1rq84YsRmUjCWewXpVQecAwEToLACKhuD/3CcFounOCCAZixYCsMbbxw3hWtYelS+PRTzcyZ25k/\nP0Ag8ANVVS+SSEwDvpQbj2JfSTiLvVJKNQdGQrOLoXIA9AnDaTlwohsGAX6rS0wZam041xUOw9df\nwyefRPnwwyhbt4LPN4OKipeAN7XWa6wuUdiXhLPYJaVUEXAONLsEqg+Dk6IwPhdOBewxVPxjQ+0V\nznWtWweffQazZlUwd64Xr3cBFRX3AM9qrbdZXZ6wFwlnsYNSKgSUQv5VEB4Mp8Th/Bw4hcYbNz4Y\nQ+0dzrXF4yaoX321gi++8ODzTaey8j5ghgx9CJBwznpKKQUcD02ugMgZMCgOl+fBSOx7hbw7Q50T\nzrVt2wZvv6155ZUKNm6Mkkw+TDT6qNZ6odWlCetIOGcppVQQ1DjI+z0UFsI1OTBWQSurSzsIQ50Z\nzrUtXAivvx7hjTc0Lte81LDH81rr7VaXJhqXhHOWUUq1huC1wM/gSAU358IJgLK6tHow1PnhnBaL\nwezZMHlyBV995cHrfZWqqr9qrb+xujTROCScs4RSqi80uRlip8N4Bb/2w6FWl1XPhmZOONe2eTNM\nm5Zg0qQoMIvKypu11p9bXZZoWLIqXQZTSrmVUiOVyv8CCmfBb8+ClQF4KAODOYMVFMC4cW5eeCHI\nxRefSJMm76vc3A+UUkdbXZpoOBLOGUgp5VHKcxnkroJeT8KEfrAmBDe5ocDq8sSBCgTgnHNcPP98\niCuvPJpmzaar3NzPlVLDUjd2RQaRcM4gyiiFvEXQ/w6Y3hK+yYPRWDdrT9Q7nw9OP13x/PM5XHdd\nf1q0eIWcnG+UUmdISGcOCecMoZQ6Epp8AZ0mwjPt4JMcGGJ1WaIhud0wfDhMnJjDDTf0pLh4IqHQ\nAqXUuUop+dl2OPkPdDilVIlSTadD87fhzsNhfg6MIDO6L8Q+cbvhuOPgySdz+f3vO9Ohw2OEQl8p\npfpZXZo4cBLODqWUaq1U3n8hdw7cNAyWh+BiZRafF1lJKTjySHj00VyuuaYnOTmzVCj0qFJKbjQ4\nkISzwyil8pQK3QrBRXDJWFgahN+6IWh1acIuXC449VTFpElBhg0bi9+/RLndl8pQh7PIf5aDKKVO\nhpzFMOJ6+D4Id3mh0OqyhF3l5cEvfxngnnua0KnTHamhjv5WlyX2jYSzAyilminVZCK0eBleag4v\nBKCD1WUJp+jaFSZMSA91zFSh0GMy1GF/Es42p5Q6E0KL4bxRsDAIJ1ldknCinYc6zksNdVwmQx32\nJf8xNqWUKlKqySvQ5hmYlg8TvJBndVnC6XYe6vgPodBcpVRnq8sSPybhbDNmHolrDIQWwSWnwfwA\nHGt1WSLTpIc6LrmkB37/V8rlGmt1SWJnEs42YlaMa/IGdHgMZuTBnR5nLHIvHMnlgnPOcXPvvTkU\nFT2kQqFJSimnLeKdsSScbcKMLQfnw9UnwA9BGGx1SSJbdOkC//1vDkOGjCQY/MGsYCisJuFsMaWU\nV6mcu6HoWZiRC7e57bNhqsgawSD87ncBfvWrNgQCHyqv93pZp8NaEs4WUkq1hSZz4Igr4Ac/HGF1\nSSLbnXii4pFHgrRt+xdCoXdSG/0KC0g4NyCllEsp5dvNuZMh9APc2B3e8slkEmEbbdrAhAk5nH76\nEPz+eUqp460uKRtJODcQpVQTfEzHx6M/PlfqhTZnQUEArnPJf4OwHa8XrrrKx1/+UkBu7lQVDP5d\nKSULtzQiSYUGoJTqho9v6ckxhDhbudWlNedKC4FfQ78AJH+A8TGQrcKETQ0cCE88EaRTp58TCk2T\nbo7GI+Fcz5RSZ+LlC06hDWcSYBwh3NytlOqvVGkH4E9Ae2Ap9JkMM7fBv5NW1izEHhUUwJ13hjjq\nqGMIBr9QSrWxuqRsIOFcj5RX3UCQ57mQEP1S/7ZFwEiCeHkdvkgAVUDcPMIbh+5Pw59j8IFVZQux\nd14v3HxzgLFjO+H3fyXtdg1PwrkeKKVcKqAeJpe/cTleiut8Qk+gP/n4Vz8N4fswvXKpNT4LtkL7\n52FkHFY3buFC7A+lYPx4DzfdVIDfP0spdYbVJWUyCeeDpJTyE+AtCriIy/HSbDefOBwfRfTH+9ZV\nwMNAa3asjN9pETT5EM6IQbRxChfiQA0dqrjjjhC5uc8oj+cyq8vJVBLOB0G5VT4B5tKO47gEzx5n\nWruBMYTwcB1MaQFMA9rWfEKv92HVSvhFomGrFqIedO8ODzwQomnTO5Xf/yeZsFL/JJwPkHKrdniZ\nR2+6Mgb3Pm1unQuMJYiXSfDWHKAMcwUNuDT0eg6eroanG65wIepLcTE89FCIFi1+TSDwkLTa1S8J\n5wOgPKoXHr7jWFpwGu79+ldsCwwjhC/8Gqx4EogATc3JUBhKnoIrY/BN/RcuRH0rLIQHHsihY8ex\nhEIvK6Vk7YF6IuG8n5RfHY6b2ZxKDkMOcIvrQbjoyiH45t4FyXuBZkBqJmGrddD6NRgRg231VrcQ\nDSY317Ta9ekzjFDodaXUvryOFHsh4bwfVI4aBHzECIL0PcBgBlDAmQTJ5RTcU0/CjGMUp84A3b4G\nvoExMZAWaOEAPh/85S9Bunc/gmDwBRniOHgSzvtI5aojiPM+Iwhw+EEEc5oPGEcObm6HqZXAR1C7\nCa/36/DZFrhV0lk4g8cDt94aolOnYQSDT8gWWAdH/vH2gcpVRxDjXUbgr5dgTisEziGIN/kqfDwN\nWAc0Nyc9CejxNPwjCm/X218pRIPy+eCf/wzRps1IAoH7pIvjwEk470WDBXNaCTCYJvg2PgeV92Ou\nqVNNefnl0OlZODcOy+v9rxaiQQSDcMcdORQVnU8gcJvV5TiVhPMeqDw1oEGDOe0EvLSmF94ZvwYe\nBFqxY4JK+6WQ/x6cHjONHUI4QG4u3H13Dk2b/lz5fL+1uhwnknDeDVWgSojxLsMaOJjB/C+MJoSP\ny1BTOgKTgXY1n9DrQ9iwFK6KN2gdQtSn/Hy4554QeXm/V17vz6wux2kknHdBtVZtCTOLAYQY1MDB\nnBYCxhLCwxMwfR7wLTsmqCig9wvwciU8KuuLCucoKjIBHQrdrtzuC6wux0kknOtQHVQB2/mAzuQz\nrJH/fdoApxLEF5sKCyYC1UC+ORmImgkq18Xhy0YtS4iDcsghcPfdIYLBB5XLdbbV5TiFhHMtqrMK\nspm3KaSYkXga6Zp5Z/1w0Z2W+OY9CIm7MbMHU7OuWmyE4lfM+PNmC4oT4gC1bw933BEkEPifUupI\nq8txAgnnFFWiPGzkBXz0ZiwePBYWczoBmnI87tfPAZ7AXFOnflUc+j145sA5MkFFOEvXrvCHP4QI\nBF5TSrWyuhy7k3AGVIlSrONeEpzMhXgIWFyQFzNBxcOfYYoG3menFex6vwHfbYBbJJ2Fsxx5JJx7\nbh6h0GsyzXvPJJwBNnMd1VzKhbhpYnUxKfnAuQTx8grMfBdYAbQwJ91J6DkR7orAVAuLFOIAXHSR\nl27duhMM3m11KXaW9eGs2qoRbOc2zsSdjj7b6AIcTS6+rS/Blocx/1+pDTbzKqHzJBgbh8UWFinE\nfnK54E9/ChEKXaDc7vOtLseusjqcVRfViy08Rl+89LS6mt04Bg9t6Ypv1h+A+zC7EqZGxNuugOZv\nmxXsqiwsUoj9lJcHt98ewud7UCl1uNXl2FHWhrMqUUVs4gmaUcBw7LuClgsYRQg/42FKH+Aldhp/\n7jEbyhfCJXGQFmjhIJ06wQ03BAkEpiulCqwux26yMpxVifKzmbuI0ocxeG0czUYQGEcILw/B68uA\nOZgODlITVF6GN7fDA5LOwllOOEExYkQ+odArsszozrIunFWJUlRwLeWM4jw86RFc22sFnE4Qb2Iq\nfPsCZiX+1NWGPwbdn4IbYzDbwiKFOABXX+2nfft++P1/s7oUO8m6cCbOCWzhD5yIp/bggCMchuIw\nCvEt+S/E7sXcHEw1/hVuhnYvmR281zfAX34J0BLoXevYZmA4cChwErB1N4/dCowCugM9qPkF8hvg\nMODCWp/7FHBXvVUtHMDthr/9LYdA4OdKqTOtLscusiqcVYnqyGbupJhAo62ZUd9OwU8BR+CZfgHw\nKHAIO/4fu5RB8FMYGYP6XiPpYmB6nWN/x4TzfODE1J935TpgBPAD8DXQDXPhPwf4CrNK6reY2er/\nBa6p39KF/TVrZhbq9/v/JxNUjKwJZ1WimlDObYTpxki8Do1m06cxlhw83ARTcjAr8deeoPIOLFoL\nNyXq9y8+BrPVYW2vUnPVeyHwyi4etw2YibnyBvMNNMU89WKYm5hVmJk3/wKuBdvfBBANokcPGDnS\nTyj0mNWl2EFWhLMqUS7iXMkWShmJhxyrKzpITYDRBPHyPMz4CFiCGXMAXBp6PgMPR0xjR0NaV/PX\n0jL157qWYLr/Lgb6AZdhwjgPczXdD3Px3wT4FCht2JKFvV1yiY/c3GOVUudYXYrVsiKcgaPZyOUc\nipduVpdSTzoCQ8nBV/kqrHsUcwmaZ07mVkGXp+GiGJQ1UkEKdvlyJI5ZRe/q1PscaoY/bsAMbfwT\n+CPwF+ARYDQg94ayks8Hf/hDDn7/I0qpQqvLsVLGh7MqUS3Zym9J0J7TLF3OqP4dhZuOdMD36W3A\nvZhdCVPrFbRZDS3eMBNUKhqogJbA2tTHa2CXUyyLU28DU38exY+XPJ2Ten8o8ALwLLAIWFifxQqn\n6NULTjklSCj0oNWlWCmjw1mVKDdRrmErxzPKBgsa1TcFnE2QIOfgmnIU8BwmCVOXsN2/gPA8OD/W\nMBNUSjGL5pF6P3IXn9MKMyQ+P/Xnt+FH0zHTV81RID1U7sLcIBRZ6Yor/AQCI5RSI6wuxSoZHc7A\nMDZzAYfhoaPVpTQQPzCeEG7uhqnrgc/ZeYLKq/BBOfznIFewOw84CjNM0hZ4HLgJeAtzxTsj9WeA\n1cBptR57DzAO0zb3NXBzrXOTMVfVrTCrPR0O9MHsl1i7bU9klWAQbr45RCDwpFLKLsuRNSqldWZO\nKlMlqi3lTGA7w7kODz6rK2pg3wGvsJ5Y8UDoew1mXuEmc3JzPsy9Cqb5TNdFphoKF3aAiy6yuA5R\nb/7+9zAffPCMrqq62OpSGltGXjmrEuUjyZVs5RhOz4JgBjNS0J98/CufgvB9mHAOmpMFW6HD86b/\neY2FRQqxn665JoDX+xOl1FCrS2lsGRnOwEls4mRa4c+Y7ox9MRwfRfTD+9YVwEOYDWJTTcOdFkLe\nR2YGYczCIoXYD7m5cNNNIQKBiUqpkNXlNKaMC2dVoloSYSwV9OEMB082ORBuYAw5eLgOprQAprHT\nBJVe78OKVfCLep6gIkQDOvJIGDQon0DgL1aX0pgyKpxViVLAGDZzJINwk41dkrnAWEJ4mQhvfYlp\nk0hNh3Vp6P0sPFUNEy0sUoj9dM01QbS+SinVxupSGktGhTPQm3JGkKQNx2Xc97bv2gLDCOELvwYr\nnsCMY6TueIfCUPIUXBEz61kI4QBFRXDmmW6CwVutLqWxZEyAqRIVIMnFbOVITsebFTcB92QQbrrS\nBt/cOyB5D2Z50dS/Sqt10GqqmaCyzcoqhdh348f7gHOVUiVWl9IYMiacgeFsZiDNCWTVTcDdUcCZ\nBMllBK6pw4Gn2XmCyleQ/BbGxEA28RYOkJcH48b5yMn5t9WlNIaMCGdVolqS5Bwq6MfJWXYTcE98\nwDhy8PBPmFoBfIQJ6JQ+U+GzLXCbpHNjWb8err/e9GJffDG8+KI5/thj8NOfwqWXwi9/aT5vVz79\nFC64AMaPh0mTao5PmGAef9ttNcfeegteeKHBvhVLnHOOG5freKXUAKtLaWiOD+cdNwE30ZViBy6g\n39AKgXMI4k1OgdnTMEvHNTcnPQno8TT8PWamVYsG5/HAz34G//0v3H8/TJ4My5bBmDHw6KPwyCNw\n9NHwxBM/fmwiAXfdBbffbh7/zjvmsRUVsHChebzXC0uWQCQC06fDWWc19nfYsAIBuPTSIDk5d1td\nSkNzfDgDnUkwgEr6c1J60R+xkxJgME3wrX8WKh/AXFOnekbzy6HjM3BuHJZbWGSWKCiALl3Mx8Eg\ntGsHGzdCqFYLb3U1NG3648fOmwdt2kCrVibkTzgBPvzQ7CQSj4PWEA6bPz/7LJx9tvk404wYoQgG\n+yilhlldSkNydDinrppHsYmudMKF7J+weyfgpRW98c74JfAgpr0u9ZPbYSnkvw+nx8yaFqJRrF1r\nrnh79DB/fuQRGD0a3ngDxo798edv3Agtaq38V1RkjgWDMHgwXH45NG8OOTkmyIcMaZzvo7F5PHDV\nVTmEQvcopTJ2ENPR4Qx0I04fKunHMLlq3iMXMJoQPi6HKR0x25i0q/mEXrNgwzK4qr73txK7Ul0N\nt9wC11xjwhXMePOzz8Ipp8B99+3f1xszBh5+GK68Eh5/HC65BKZOhT//GZ56qv7rt9rQoVBYWAxk\n7KL8jg1nVaJcwE/YxKF0R6VHUcUe5JCeoPIETP8Bs1zSIeakAnq/AC9VwaOZuRqWXcTj8Mc/wvDh\nZny5rhNPNFe+dRUV7XyjcP16c6y2BQvM++JieP998wtg1SrzlklcLrjmmlyCwTuVUpm1TnuKY8MZ\n6EWcEqrowwkZtoh+Q2oDnEIQX2wqLH4as2dUvjkZiEC3p+C6+I8XxBf1QmtzQ69DBxg1qub4ypU1\nH3/4IXTt+uPHlpSYkF27FmIxePddOOqonT8nfdUcj0My1YTjcpkbhJlm4EDo0KEpZj3ajOPIcFYl\nyqwisYn2lKDS0SL2UX9cdKclvu8egMQ9mB1X/eZkiw3QZrIZf95sZZWZ6dtv4e23Yc4cuOwy8zZ7\nthmSuOQSM7Qxdy5cdZX5/I0b4abUOtluN1x7Ldx4o2nFO/54aN++5mvPmmUCvKDALBjUpYtpr4vF\noFOnRv9WG5xScMEFueTk3JyJY8+OXM9ZlagBJLmO5ZzLT/Hv2GNU7LsY8BCVbOZPJM74HLM99hJ2\nbJky51To0hfe8Trnd/hQWc852ySTcO65lWzePExr/YnV5dQnp/zU7ZAaax7FJlrSGiXBfIC8wFhy\n8PB/MCUJfMBOK9j1eQO+3QC3yAQVYV8uF4weHSQn50arS6lvjgtnoCeaVlQziOOyfgWNg9MMOJcg\nXibDzHeAVezYpdWdhJ6T4K4IvG5hkULsxamnuojFTlVKZdSlmqPCOdXXfAbl5BMkmLH7AjamLsAQ\ncvBtfRm2TMA8J3LMySYV0HkSnBeHxRYWKcQe5OWZCTle75VWl1KfHBXOQEegK5UcxtH4ZA2NenIs\nXorpim/W74H7MVfPqQ6Ytiug8G2zgp3shi1s6pxzArjd1ymlMma+g9PCeTjV+IlRTB+rS8kgLuBc\nQvg5H6b0Al5ip/HnnrOhfBH8NL7jfqEQdtKlC7Rr5wHOtLqU+uKYcFYlqhAYzDY60g8l8wHrWRAY\nRwgvD8O0pcBcTFc0qQkqL8H07fCgpLOwpzFj8sjN/a3VZdQXx4QzMAQNhDmcfmTgai420Ao4nSDe\n+Ovw3XNAOea2IeCPmQkqN8RgtoVFCrEbxxwDSnVTSvW2upT64IhwViXKD5zCVnJoiqJorw8RB+ow\nFH0oxL/4cYjdi9mVMGBONt8MbV8yO3hvsLJKIX7M44Gzz/YRDP7K6lLqgyPCGegJBAlzOAPTM9lE\ngzkVP/kchWf6eOBxzPobqedK1zIIfgYjYyBrJAmbKS31kEiMVko5ft6wU8L5eOLEqKYTvawuJQt4\nSE9Q+S1MCQLvsNMNwt5vw4K1cFPCogqF2LWCAjjssDhQanUpB8v24axKVAHQk80cQieShPb6EFEf\nmgKjCeLlBXjvQ2AppOdjujT0egYeisDL1tUoxK4MH55LXt6FVpdxsGwfzkBfAGIMZIDMCGxUHYGh\n5ODb/iqsfxTTR5dnTuZWQdeJcGEM5ltYpBB1HHEEhMNDlFK5VpdyMGwdzqkZgSdThSZBAZ2trigL\nHYWbDnTAN/tvwL2YXQlTjYxtVkHRG3BqDCosLFKIWvLyoFu3KHCK1aUcDFuHM9ABKKKcTvRGSQOd\nBRRmg9gg56CmHAk8jxl/Ts3P7PEFhMvgfJmgIuxj2LA8cnPPt7qMg2H3cD4SiBOnNz0kmi3jB8aT\ng4e7Yepa4DN2nqAyGT7YBnfICnbCHo4+GiKR4Uopx3Z32TacVYnyAccQoYoY+bV3uxMWKAJGEsSb\nfB3mTMasxF9oTvri0P0p+GMcZlpYpBApBQXQvn0MONHqUg6UbcMZ6Az42UYnupCQ62Yb6ImiH03x\nrXwKwvdhJn2ndict2Artn4eRcVhjZZVCGCedlEcotIttzJ3BzuF8OJAgTh96SpeGbZyEnyL64Xnr\ncuBhoDU7nkedF0LuR1AaM1utCGGhY45RJBKlSilHXtrZMpxTu50cSZxtVNOGLlZXJHZwA+eRg5df\nwJQiYDrUHnTq/R4sXwXXywQVYa1WraBFCw3sYotz+7NlOAPFQC7bKOYQ4umVHYRN5ALnEcLDJHjr\nc0yjcytz0qWh97Pwv2qYZGGRQgDDh+cQCIyxuowDYddw7gloovSil6ylYUvtgOEE8YWnwoonMOMY\nTczJUBgOfRouj8F3FhYpst4xx7iBnzhxd267hvMQNFuJ0JmuVpcidmsQbrrQBt/c/0DyXqAA0vcH\nWq+FVlPNDirbrKxSZLP27cHrDYDzNrWzXTirEtUcaEM1Xty406sJCxtSmPa6XE7DNfVEYCJmSCp1\nldL9K0h8C+fFZIKKsIRS0KNHAjNnwlFsF85AN0BTSTvao2WfQJvzAePIwcO/YGo58DEmoFN6T4VP\nt8BtMkFFWKNv31yCwaFWl7G/7BjOhwNVxOlMZ2mhc4RC4GyCeJOvwezXgfWQ3hLBm4AeT8NtMbPy\nqBCNrGdPhds91Ooy9petwjnVQtcT2EaMDjIr0EG6AYPJw7f+Wai8H3NNnVrgNb8cOj4Lo+KwwsIi\nRVY69FAIh9srpXKsLmV/2CqcMe1YfiL4SRKQ7agc5gR8tKI33hnXAw9i/j9TEwA6LIH89+H0GEQs\nLFJkHZ8PiourgYFWl7I/7BbO5lp5O+0pJmG76sSeuYDRhPBxBUxpD0xhpwkqvWbBumVwtexvJRpX\nv34BlDrK6jL2h93irxcQIUZHOkt/syPlAGMJ4eVJeOM7TKPzIeakAvq8AC9WwWPSviEaT+/ePnJz\nT7K6jP1hm3BOLazfG9hKgo4y3uxgbYBTCOKLToXFTwNVQGrDzUAESp6C6+Iwx8IiRVbp2RMikf5O\nmoxim3DG3PPPQxMlQj4trC5HHJT+uOhOK3zf3Q+JezC7EqZeDbXcAIdMhtNiZuVRIRpYUREEAi5w\nzn5Kdgrn9gBUUUCQuAxqZIDTCdCUE3G/PhJ4EnNNnbpyKfkO3HNhVAykBVo0gp49HTUZxU7h3AWI\nE6YlLWQ6WUbwAmPJwcNfYEoc+ACzxVVKn+nwzUa4RVawEw2vb988J01GsVM4dwYqidKSNjL5JGM0\nA84liJfJMOttYBWkB63cSeg5Ee6KwusWFimyQteu4PEMtrqMfWWLcE7dDGwHVAJtaSmTtjNKF2AI\nufi2vAzlD2J6n1MTAppUQKdn4Lw4LLawSJHxioshEnFMq4EtwhlzfeUF4sQooqXV5Yh6dyxeijkU\n7/u/B+7DXD17zMl2y6HwHXODsNrCIkVGKywErQNKqaZWl7Iv7BLO5mVuHC9RQhRYXI2ofy7gXEIE\nuACm9AReZqfx556fwLZF8NO4rGAnGoRSUFRUDc5YiNgu4dwKcFFNEfnEZDPXDBUExhHCyyMwbTHw\nFaaDA9PE0fslmL4dHpR0Fg2jXTuFhPN+6QSEiZIv6zdnuFbAaQTxxl+HH54DyiH9v+6PQben4cYY\nzLawSJFBQTNJAAAgAElEQVSRYjFo0SIHpRxxU9BjdQEpnYAKYnSkwDY1iYZyOIoVNOebhY8R7XIF\neP+AGWwOQ/NNUPwynHE2fOdFVr8S+yqZhE2bYM0aWL3avF+6NMmqVYr16xWVleDzubxKnWh1qfvC\n8iBUJcoNtAZWomlGvgxqZIVT8bOSo9g0fRzxMx4DLgeWAknoOg8qP4ezBsD7XuQpIQC0hvJyE7pr\n1sDatbBsWZLlyxXr1im2bQOPB5/Ho5slk7pjOOwq0drVG7Mc3SDgw3CY0Wa/S9uzPJyBvNR7DRTi\niPuo4qB5MBNU7udm4lM+gTPeAYYCy8wn9H4bPmsLN7WGf0o6Z4vqahO66QBesUKzbJlmzRrF5s0K\nwOPz6TytdbtIRB2aSLh6Av2Bo4CCRAIiEQW7bsdtB0R33OewNzuEcxPSt+eT5Es4Z5GmwBiCTORF\nYu/1h6EdMKPS68wElV6TYMLPYEgIRlpbq6gfsRisX18TvqtX1ww9bNyoiEZx+f3kKJVsFY1yaCzm\n6g7qcEz4djRfY7fhuzfFQBUUKqVcWmtbrxtgh3BuSvofOkYuTawtRjSyjsBxhPhg+ytEN54MzX+H\neTW1HXKroOtEuOAi+NwDh1pbq9i79Lhv+up39Woz9LBixY5xX+XzEXC7dfNEQncOh1U3cB0ODMas\nGeypqoIGalYIAjkQLTftu2sb4u+oL3YI5yaAiyRuYvh2DHKI7DEED8voyLKP/0r0jH8BNwJhIAZt\nVsHWN2DESfCVd8fEQmGN9Lhv7aGH5ctrxn23bt0x7ptfa9y3FzXjvqFwGMwFmSUzgQshVm5eoUk4\n70URkCBCHkHiuPBaXZBoZAo4hxAP8BNiU2aiz3gO+AnmBqGGHp/Dl+3hgm7wgsein+nskR73TQdw\n3XHfZBKP369ztdZtU+O+PYABmCXfivYy7mu1pmYY1fYDqHYI51ZAmBg5hGTtyKwVwExQeZh7iE09\nFk77HDgMWJmaoDIZ3m0NdxbA9bb8oXeMeHzncd9Vq8zQQ3rcNxzG5fcTcrl0q1hMHxqNurqB6osJ\n346AKx63bfjuTaqpXsJ5HxQBEZLkyVp0Wa4FcCZBJienEps7EA5vi9mEYRP44tD9afjDlTDQB0db\nXKyNJZOweXNNu5np99WsXAnr1ikqKlA+H/464759MMMOhwOe6mqwcOihITUzvZkSzvugOVBJAj+5\nVpciLNcLxQrymbPiKaI9zgffHzH3caqhcAu0fx5G/gS+8Zr2+Cy1fXvdfl/N8uWwdq0Z93W78Xq9\nOj+Z1B0iEVdJMql6Y4YeBgG5Fo/7WqnQ5J6E856klgrNBbaSxI8/+54oYhdOws9K+rPujSuIn/EI\ncDU7Jqh0XgiVn8CZR8CHXjL1FkU4XHPVu3YtrFypWbbMdD9s2qRIJnH7fDpPKV0cDqtDEwnVA+iH\nGXpolUhANJqV4bs3heBDwnmf/n4FaJL4CNhmrQ9hJTcwhhzu5xfEp3wEZ0wHTsIENNDrXTNB5ZfF\ncI/Vz+EDk0j8uN932bIkK1cqNmzYMe4bdLl0y1hMl0SjrhLMkMNRmJ0pnDzua6V8cPnNcJmtWf3E\nrtkpMImfoMzTFSl5wHmE+B+TiL0zEE7siFlidC24NPR6Dp78GQzxwBiLi90FrWvGfdNvy5bVjPtu\n375j3LcwkdCdIxFVorWrD6bfty+ZPe5rpaZAwAyn2podwtl0aGj8BORJKGppB5xIiBlVU4iuOB7a\n3oTpiy+HnGo49Cm47FLo7YaejV9fRcXO477Ll2uWL9esXeti8+Yd475Ntdbtw2FVkkyqXphx38FA\nkywe97VSU8AtV857VdOf4SIk3RriRwbjZjnFLJz7H6Jt/giu32JWsItB67V4t31EfMQQ9Df1PyQW\njZrQTa9wtmqVZulS0++7aZMiHsft9+tc0G2iUVUSj6vuoNLjvofIuK8tpaYk235xYqvD2V/r44CE\ns/gRBYwkyAOcRnzq+yTPmAiMB5YAGn/nRQS+7cb2Mfmg9+/uYCIBGzbsep2HDRsU1dU7xn1bpPp9\nS1LrPBwBlACuqioJX4dRO72zLzuFs+x+IXbNB4wnhwn8i+jUE+C0jzGjAysAaNtuMQs+6Ugs0SK1\nNI6hNWzZUnedB82KFbB+vaK8HOX14vN4dGEioTuFw66SVL9vetzXJ+O+GSex0zv7slc4SzyL3SkE\nzibIi8kpxD7tD4PakV6J3+XWdCt+mm++v46ZM118+WWStWtdbNkCSuH1+XRTrXW71LhvT2qmGjeJ\nRGw91VjUv1Qqx62tYu+sDud0Kx1AUsJZ7FE3oBNNmL/uWjT/Af6MJghAMFjpV8noMYsXBwaAKz3u\nWwwHtcSkyDypNSLkynkv9E4fSziLPSkHFpNAc7/Wr65WqvRBtPorgHvJkkFHgPsti0sU9pdKZduv\n42OncLb/lXMM+C/mBVECcyU3DPgOeA/YCFwGHLKbx78CLMCsenl1reNvAQsxS0CdlTr2FaYn4Yh6\nrN/p3qAauE9rvRhA61e/yMs/6gPCW69KbNw46EGtZRKT2CunDGtY/WTWtT7Stv9d5gUuBK5KvS3B\nbKrUAhgNtN/L4/ti+gxqCwNrUl/PDazD/BKYi1kEQRgrgPmEifF/6UOlSqkjqr4gb/FC78Va624W\nliecQ4Y19o0mHdDKAVfOUNOZncBUHmTfN4huD2ypc0xhni0aE8pu4CNMu4DVvzrtIglMoYoY12ut\nt9c607MiFj2qCpr/VXaBFfso9aMr4bwXNdfK2iHhnAQmYEJ2AOaq+WD4ga6pr9kp9edVwHEH+XUz\nyTdotrEU+F/6UKlSXg3nL4aBfwO37WcUCNuQcN43tYc1oo7YsNyFGYIIY6JiCTu11h6QIak3gFeB\n44EvgMVAS+DYg/z6ThYBphMmwmV1NuQ8dgkMzIOCK6QTQ+yHMJA0d3RszeoXzjXh7KKaatuPOtcI\nYPYbXV2PX3NN6n0h8D1wLrAZ2FSPf4fTzCROkula64/Sh0qVahqHMStg0ATwWn2FIZxlE1AFK62u\nY2/sFM4Rqm3+UqOSmt+3MWAR9bve+7uYq+b0eDaYa0Lb31duIFuAT4gR4bo6Z84og75Hge9EK+oS\njrYGojFz693WrL7oiO74yEWYKptfOVcAL1NzG/MwzDjxD8A0oAp4GhPY4zF9uVOAcanHv4BZkbga\n+A8miPumzs3DtOCldx9vBdyfet+y4b4lW5tONfBvrfWK9KFSpdpWwOnroM+bGbvSvmhIa03ubLS6\njr2xOpzDOz5yU237UaCWwJW7ON499VZXE2qCGWDUHr52t9Rb2kmpt2y1FFhMJXFuSx8qVUoBYxdA\n/yvB1dmy4oSTrTGvTTdYXcfeWD2sURPOHqqosrASYR81rXM/11rXflYctg6OqYQOt0jrnDhA6807\n2185Wx3OEdJ32r1UUW15PcIO5qCpYD7wbPpQqVJ+DeOXwOB/gidvDw8XYk+2mBEDuXLei+odNXip\nIoLHEb3OouGEgTcJE+FSrXXtZ8PQRTCwCJpcbFVtIiNsM7MJJJz3RJfpBOY2mgc3cRSJWgMdIhu9\nRwzNK1rrL9KHSpVqFoXRK2HgBPBZfUUhnKuKHY1Qth9EtcPzfDvpu+5+KthqbTHCQpuAz4kR5Zd1\nzoycD31PBM/RVtQlMsYGIADldV6V2ZIdwnkb6XB2s+VHa0+I7PE61Wj+prVemz5UqlSHchixHnrd\nJa1z4iAtAfwOmIAC9gjnTdTsiLJBwjlLLQJWsI0E/04fKlXKBYxbAP1/Aa521lUnMkQZEDeL/Nqe\nHcJ5FWYyNLjYyMasnQ+XvRKY1rkoV2utI7XO9FsDQ6JQ/Ft7PFeFw30PsW1mQV7bs8MTfgPpdjof\nW9ho8yncov59jqaabzDbEQBQqlQgCeOWwOC7wJtjYXkic3xtbgSWWV3HvrB6hiCYFRTMtG0fW9kq\nK4xllSrgHSJEuazOTZphC2FAW8g9z6raRMYpM5OX5ltdx76wSzibQA6wlTV4SWKPa3rR8GYQBZ7R\nWn+TPlSqVPMIjFoFA2eAT35bi/oQBTaY7TEWWV3LvrBDBG7FhLPCTRwPEbZZXZJoFOuBucSIcmOd\nM2fPh36ng3ugFXWJjLQYCMJGrXV0r59sA5aHsy7TcczVs+nY8LMxPfldZDANTKWaJH/UWu+YrVWq\nVJetcPJG6P5ve7yyExliPuAzWyw7guXhnLKGdMcGLGe1TOLOePOBNWwiyT3pQ6VKuYHxC2HAjeDa\n3SbmQhyIMqDK7GvvCHYJ51WYsSDwsYoVOOJlhzhAcWAqVUS5XGtde3OygSvhSA2tb7DPc1NkiC+g\nstpB4WyXl41LSc/+CrKGtfKDmdFmkyTC51rraelDpUqFEjBuGQx+CLyBPT1eiAMw0wymfWJ1HfvK\nLiG4hnQ7XZAtRFFUWFuQaCAVwHtEiXBFnTMnL4T+XSB0thV1iYy20bx5MLtzOoJdwnktphaFAgJs\nYO1eHiGc6W2iKB7XWs9LHypVqkU1nL0a+k8Ar7TOifr2CZAL32itHTPJzRbhrMt0GBPQZtxZyU3B\njLQG+JYIUX6XPpTaeurc+dBvFLgOt646kcE+gsR2eMvqOvaHLcI5ZT7p7U29rGIFsT1/unAUDbxG\nFUlu0lrXXt6qZDMM2wKH/sM+90BEhnkHKmLwodV17A87hfMC0r3OIVaxEiXXzhnkB2ADa0nyUPpQ\nqVIeYPwiGPhHcLewrjqRwRLAV+ZVuWNuBoK9wrn2TcHNJImzydqCRD2JkW6du0xrXXvVwSOXwxFe\naHEtsqaKaBjfAn4zM3Cz1bXsDzuFc/qmoPkx9bGYxZbWI+rLRySIM0trPSN9qFSp3ASMXQ6D7gev\nz8r6REb7GFAOG9IAG4WzLtNVwGogFwAP81kgk1EcrxyYRZQIV9c5c+p86NcHAqdZUZfIGjOgahu8\nY3Ud+8s24ZzyJZAPQB5LWIY7NdAhnOpNIsADWusdK4GVKtW6Ckaugb73S+ucaEAJYLrJuTesrmV/\n2S2c55GuKcB2XFSxztqCxEFYCZRRTYw/pQ+lWudGz4d+54Orh2XFiWzwGeCCdVrrpVbXsr/sFs5L\nMU1X5mLKy0IWS8+GI6Vb52L8Umu9vdaZHhvh+G3Q5W9m4XMhGswUiEfgBavrOBC2CufUuPNS0v3O\nPhYwX8adHekbYAvLgSfSh0qV8mo4fxEM+iu4C6yrTmSJ56AqXGv7MyexVTinfAE0BaAJS1mFR+LZ\nYaLANKqJcJnWuvZdg6OXwqBcKLxKWudEA1tp3tw4rL85zY7hXLMYtpdqAqxloYXViP03kzhJ3tJa\nz0ofKlWqSRzOWwGDJoBXpgKKhjYVCMBbdXrrHcOO4bwcM2JpavMwl29kKrdjbAU+JkaEn9c5c3oZ\n9BsMvmFW1CWyznOwfSs8Z3UdB8p24azLdAT4DmgGQFPmsRAXjvzdl4WmEwbu0FovTx8qVaq4EkrX\nQp970+t2C9GAqoEPzXIQjmuhS7NdOKd8COQA4KcCHxudsV9ullsGLKKSOLemD6Va586bD/0uB1dX\n66oTWWQGEIIfnDZluza7hnN6rV9z08jDHBnasLkkMIUqYlyrta6sdabPeji2Ajr+WVrnRCN5FKq2\nwsNW13EwbBnOukyXYwI6PbTxA/NROGaZ7Cw0F812FgKT0odKlfJpGL8YBv8D3E0sLE9kj63ANHBr\neMbqWg6GLcM5ZSbpdTYClONlC0usLUjsRhh4kzARLtVa1540NHQxDCyEpj+V1jnRSJ4DAvCu1trR\n61raOZx/SL2vGdqYK7cFbel94mimaK0/Sx8qVSo/BqNXwqCHwCfjGaKx3G+6NO6zuo6DZdtw1mV6\nK7CQ9EJIzfiKeSiqLS1L1LUZ+IwYEa6vc+bMMug7FDzHWFCWyE7zzZvGwV0aabYN55SZ1EzlriLI\nIr6xtiBRx+tUo7lVa706fahUqQ7lcNp66HWXtM6JRvQ4xBU8qbV2fAOB3cP529R7U2eQ2XxCVJZC\nsonFwDLKSfCv9KFSpVzA2IUw4Ofg7mBZcSLbJIFHIFrl8C6NNFuHsy7TW4A5QHMAmrKESmKs3uPD\nRGNIkG6d+5nWOlzrzOFr4OgwFP/O5s8vkVneBWKwWmv9tdW11Acn/PDMwGzOCApNgE/5VG4MWu4L\nNFV8B7yUPlSqVCAJ5y+FwXeAN9e66kQWehCqtmfAjcA0J4RzGbCNdEDn8yXfo4hYWlN2qwbeIZxa\nda72INOJC6H/IZA7zqraRFZaA7wGriQ8aXUt9cX24azLdBx4CygCzHRuP8t2jEaLxjeDKJrntdZf\npQ+VKlUYhVGrYOBD4LP9E0tklHsh7oGJTp6uXZdTfoZmp96bnucgHzFLbgxaYgMwhxhRfl3nzFll\n0G8EuAdbUZfIWtXAvRCrgNutrqU+OSKcdZneiOncMDcG81lEmMpaKz+LxjKVKjR/0lpvSB8qVarz\nNjhlA/T4j7TOiUb2FGgFs7XWZVbXUp8cEc4pbwMhwFw/B5nBe7JHSqOaD6xmCwnuTh9Ktc6NWwgD\nbgBXG+uqE1koCfwVKrfBX62upb45KZy/x6xpYpYSLeB7NhFj+R4fI+pLArNha5QrtNa1fykOXAVH\nJeCQG531fBIZ4FVgq9mRaobVtdQ3x/wwpW4Mvkx6aMNFkiDvy9VzI5lNkghfAq+nD5UqFUzC+KUw\n+B7wBq2rTmQhDfweKsrh93W6hjKCY8I55VPM+H8AgELmsALNektrynyVwHtEiXBFnR+CkxZAv04Q\nGmVVbSJrvQ8sN222jtxde28cFc66TIeB14AWALiJE+RjPpBJKQ3qbaLAE1rr79OHSpVqETatc/0f\nAp+sByoa2++gogJu0Vpn5ErvjgrnlJmYEVDTFVDIbOYBW6wsKYOtBb4lQpSb04dSW0+NKoO+54C7\nr3XViSz1FvA1bNMZNOmkLseFsy7T2zHLAbYEwEuYEJ/wtmxjVe805iZggpvrNPd33QLDN0PJ7eCx\nqjyRnZLAz81V83WZsPrc7jgunFPexTTUmTXcmzOL+SRZY2lNmWcesJ71JHkwfahUKTcwfiEM+D24\nWlpXnchSk4A1Zjvhl/b2uU7myHDWZXoTZnijFQAeIuQwg+ly9VxvYpgJJ1Eu01rXHtM/cjkc6YaW\n1zv0+dNQwsBg4HCgB/Db1PE/AcVA39Tb9D18jUTqc86odew3wGHAhbWOPQXcVR9FO0wE+BVUlcPV\nmdihUZuTf7imYuo3L6ub8wVribDI0poyx8ckiPGR1vrt9KFSpXISMHY5DLofvD4r67OhAOYl3Vzg\n69THszAv8X6JWft2DnDKHr7GXZhgT99g3ZZ6zFeADzNNthr4L3BNfX8DDnAvJMNmNuAHVtfS0Bwb\nzrpMb8BchLQGwEWCHKYzjShJS0tzvu3ATKJEuKrOmVPnQ9+eEDhjV48TqSmsEMVcBTdL/XlfLvFW\nYprIL631+S7MixgNVGHugv8LuJb0mF722Ab8GaLbzLef8RwbzinTMc9dPwCFfEcl22TFuoP0JhFg\ngtZ6YfpQqVKtquGsNdDvQWmd260kZlijJXA80DN1/B7M0MRPMdNcd+V64J/s/EOZB4wA+gGHAE0w\nzf6l9V24A9xqtqB6RWudFT/hjg7nVOfGi6THnhWQx1TeJCadzwdoFTCPMDFuSR9Ktc6Nng/9xoGr\n5+4fnfVcmGGNlcAHwHvAVcCS1PHWwK928bh0835ffnyVfQNmaOOfwB+BvwCPAKOBv9X3N2BTK4F7\nIFZu/jmygqPDOeUDzCses/FGPsuAlXwogxv7Ld06F+fXWuvyWme6b4QTtkKXW6V1bp80BU4DPseE\nrkq9XYq58q3rI8w6ER2B8zALRVxQ53PmpN4fCrwAPAsswmxRn+mugmoFd2utV1pdS2NxfDjrMh0B\nniG9GD9AM15lFkmZmLKfvgU2sRLN4+lDpUp5NJy/GAb+H7gLLSzP7jZSM2RRjZko0RczjyftZaD3\nLh57K7ACc4X9DHACP55dkb5qTo9ng/kBrq6H2u1sMvAebK4yjS9Zw/HhnPIZ5pWPuf8SZCshZjFF\nWuv2WRSYRjVRLq0zHfboZTAoCM2vrmkiELuwBhOqh2Na6s4ATgRuBPpgxpzfB+5Iff5qzNX1rtT9\nh54MDMSM3+Wn/o4+mNayXYV9pigHfgrVFTC+zkbCGU9lSqugKlHdgZuApYAmgZtVXMuZNKG7tbU5\nwgzizGa6DusdjRilSuXF4Z8fwbhnIfdkK+sTWekKiE2C58q1Hm91LY0tU66cwcxn+4h0a52bBE14\niSnEyKrftwdgG/AxMSI/ap09fT70Hwh+CWbR2D4GnjI7av/c6lqskDHhrMu0Bp7D3NYyS4rmsww3\n3/Om9G7s0XTCaO7SWi9LHypVqk0llK6Bw+6TradEI4sC46G6Cq7QWmfl3aOMCWcAXaa3YO6ntN5x\nsDnT+ZY4y3b7sOy2HFhIFfGabX5SrXPnLYD+l4LrUOuqE1nqNkhshE8wF1xZKaPCOWUmpsPIdG94\nCZPHZF4kRsTSuuwnCUyhihjXaa0ra53pvR6O2w4d/y/7JqIJi5UB/4BoOVyU6etn7EnGhXNqO6vH\nMTNpTU9uIfNIUsZUGd7YyVdoylkMTEwfKlXKp2H8Yhh0G7ibWlieyD4R4GwIx+E3Wuus3iE048IZ\nQJfpFZjuo5rNoFswhTKq+c6ysuwlArxBmAiXaq1rT9g5djEMbAbNLpPWOdHIfg3xFTAzBvdaXYvV\nMjKcU6ZhWk/NvAkPUZrxLK8SZ5ulddnD+8TRTNVaz04fKlUqPwZjVsKgh8Ar4xmiMb0GPA7btsOY\nbB7OSMvYcE7NHHwQyMGstghNWEWAWTxHLKsnd28GPiVGhF/UOVNaBn2PAe9xVtQlstZKYDxEKuHM\nOrvuZK2MDWcAXaaXY8ZTaw9vfMAWNjAzi+N5GtXAP7TWq9KHSpVqvx1OWwd97pHWOdGI4sBZEI3A\nrVrrD62uxy4yOpxTZmDWKj8EAIWmOc8yizhZs4RKLUuApWwnzu3pQ7Va5wZcA66O1lUnstAtkJwP\nc8LUtHOKLAhnXaaTmO6NGOmV6wKU04TJPEOMyj09OsPUtM5do7WuvV7O4WvhmGpo+4cseE4I+3gX\nuAsqy2FknRvTWS8rfhBTk1MmYFZvNN9zId/j4nMmESOxp0dnkC/QVPIDZsVJAEqV8ifh/CUw+N/g\nzbWwPJFd1gLnmnHmUVrrtXt9QJbJinAG0GX6a8zOKcU7DrbkLbawitezIJ6rgbcJE+GyOnfCT1wE\nA1pBXt31g4VoKFXAcIhWwe1a6zetrseOsiacU17CLJvbAjDjzy14lm+p5It92ubNud4lhuZFrXV6\nzXZKlSqIwqhVMPAh8GXbk0FYIwmMhvhymF5NzY47YmdZ9fOoy3QY09yuMduxmendzfkf04mxwsrq\nGtBG4EtiRPl1nTNnlUHfk8B9pBV1iaz0G0jOhAXl8BPpZ969rApn2LFr991AAen+5xw20pQXmEiM\n8j092qGmUk2SP2ut16UPlSrVaRucugF63Smtc6KRPAp6AmzdBsdqrWW1mz3IunAG0GW6DHgCM/5s\n/g0KWICPWTxFjKiV1dWzBcAqtpLkzvShUqVcwLiF0P9X4Cre/aOFqDfvAddBpAKGaK03Wl2P3WVl\nOKe8B7wDtN1xpAUfUEUZEzNk9+4EZsPWKFdorWv/yhmwGobEoc1vsvs5IBrJfOBMiEWgNKn1PKvr\ncYKs/cFMLc4/CXNtadZ/VkArXmYDK3iRuOPnEH5KkjBzMcsWAFCqVDAJ45fAoLvB+//t3Xtw3WWZ\nB/DPL03S+5XeoJS2lFIv3FqggOJlARV2JcLKqqzihVHEXWfW2R2dZdRdV11GZHYcZgUFEV3xsriu\nSpSbKHeVAgotlzWUQlto7YW0lCZtzzlJ3v3jPWnTci2kPSfJ85k5TeZ32pM37eR73r6/533eUTUc\nXhga2nEylTL/WEnp5lqPZ6AYsuEMqS2VcZlc2ZMbJDXoMd2PrLTe9boHbA1HJ25VVnLebjddTlnG\nwjmMfk+txhaGjE14M11buHJbSkO+09yeGNLhDKktPYP/kHs/5/bFw3SZ5nsestltA7QG+jfKuDql\ntKNJaktRTNnOWWs45nKaox9o2Js24y10/ZlrNvP3tR7PQDPkwxlSW3pKDuixchc7mpRM8x132+ae\nATZ/Xoelysou2O2Zdz/KwjMYdnQtxhWGjC04ia41XL+Jc6Jkbs9FOFeltvQYLpGPt8oHxA7XYaqr\n/Np2D9ZydHsgyTcBe3wupdTee7mlKOZt4u3tvObi3hNiQtgLOnFKbpp/RztnRjC/MhHOfaS29KDc\nA/oAvTXQI20y2Xf9QsmSATCDbsM6G/S4rPdSS1EMwznLOeYCGqbXbnRhkNuGt9P1BL9r5G3RzOiV\ni3DeTWpLd9tZA51nmGOsN8W3XadU19u8u3CdrcrOSylV+jxz/JMcXzD9n+LfPOwl23Ea3cu4r4eT\n1kQwvyrxg/r8bpH7cByk9/Tp0TaY6ltuss3ddRrQv9etbHHfRjItRTG6m79dyaJLaRpey/GFQWsb\nTqf7ER4o86anUxqYN9LrSITz86jWQF8r1wfP0hvQo2w0zbfcaqu76qwKugN3qCg5f7dnTl3Gwtcw\n8l21GFcY9DbK5XJLuH8bJzyT0mDYwlVzEc4voBrQ/4OfyQGdlzhGesY0V7hTh1vrqA76V0r4Vkrp\n0d5LLUUxbRtnrmFhlM6FvWEVjqHrKW6ZyPFbdl1OC69ChPOLqAb0z/FjeYkjNwga4VnTXWGxZ92k\nu+Zz6DV4REnF53svVY+ees+jLHgfDYfXbnRhkFqKY+iu8JNjOa0tljL6VYTzS6gG9HX4vtyHI1dx\nDNdpuist8bRrVNRqvpDko6e6fTqltLnPM69p5+RNHPqVKJ0L/ewWvInuUVy6gA+0xs2/fhfh/DKk\nthpqrqIAAAv7SURBVJRSW/oVrpJP8s731ZptdYArrbbclSo6ajC4h9FujeTbvZdaiqIx5dK5Y/+N\nYZNrMKwweP0Q76JrMhccwadaY8a8V0Q474HUlm6TzyLcH7ln0DBd9neN7e72TRXr9+GAKrjeNmUf\nTbv+gLxxJYtGMOWTuZ1TCK9awlfp+QSlA/jQ8pQubo0NJntNhPMeSm3pd/ia3Kx/InL8TXOLZr90\npS6P7aPB/Fa3bremlG7vvdRSFGO7OHsVx32DpuiiH/rDNpxD91foPDCvL/+w1mMa7CKcX4HUlpbg\nS/JkYtqOJyZbaqKr/VjJvXu5jmMzfqus9JyGMn/1KAuPZvhpe3UAYahYjgV03cqKeSx6OKVbaz2m\noSDC+RVKbWmlHNDr9W3YP94qU13h17b4ma69dqPwJtslX08prei91FIUMzppWctRl8XRU6EfXIuF\nuSLjliM5YXE0yt9nIpxfhdSW2vEVPIA5+m5WmeFSyy33DRX9fSDPk1hmmy5f7L1ULZ177zIWfpiG\n+f38JcPQ0oVP0/1BSnP45us56/qUNtR6XENJhPOrlNrSNrlh/w3yZpVcydGobH//LfmVK1Qs7acv\n2COXzlV8KqXUtz7ksA289Vnmfqn3TSKEV2Ad3kzlajYewScOyhUZW2o9rqEmwrkfpLbUjWvwbXkN\neueNwinuM9lVrrPFtf2wzLFUstkKue4atBRFU+IDj7PoQoZNfJVfIgxdv8VhuUH+wws49c6UvtMa\n27FrIsK5n1RroW+X16Ercle7XMY2xlozXGqZx31TRfuLvNCLKeFG25V8dLdWjG9+gmPHMem8KJ0L\nr0AZ/0zPO6hM5X8P57QbUvpjrcc1lEU497PUlp7AF3C/vA6ddxQ2Ktnfj3S72eUq7pH2eNv3Hbok\nN6SUft97qaUoxndx9pMcdzlNsRUw7KkHcQSV77F+AZ+Zy4dbU1pb63ENdRHOe0FqSx34Br6L6fou\nc0x1rymucKsNrlKx8WW+6CYsVlHyD7s9c/qfOOqNNJ3UP8MPQ0QXLqTnhPzp4oW8dyKXtKa0vdZj\nCxSxwWfvKuYXc/BJ+fDY1VTrn5PCBm/Q6a1ONswixYu+Vf7Qdo/7aqqkf+291FIUB3Vw8T2cuZSm\ng/fmNxIGlaU4m0o7m+bx04lc1NqnLDPUXoTzPlDML8bggzhOrovu3PHkVvvZ6Czj7ecsTfZ7nhdY\ngR94WsVBKaVt7Cid+8z9fOx9zL44KjTCy1DCF+m5hO4DuXce/1nw85gt158I532kmF8UOBofkdeh\n19h1Fn2cTid5i2FO0LAjantwqa3anZtSuqb39VqK4qh1/Psy3r6SxrH79tsJA9CNOJ9KmfWHct04\nvtYam0rqVoTzPlbML8bjbJyADfTpZbfVRJv8tWbTtGgyB/dJbvaAkqN7TzFuKYrhiQvv5oMXMfnc\nWnwjYcD4E/6Oyv2UZ7J4Ft8t+GlrSp0v+YdDzUQ410B1Fn0UzsVIu65Fs9FrdTjdbE1WqCg5MfUp\na2opilOXccFaTlxJw7gafA+h/m3E5+j+Ht3788A87mrkitaU2mo9tvDSIpxrqJhfjMN7cSLa8eyO\nJ7sdYo2yLl2pnM7rvdxSFBNx0TOUH+OkEodcRNNHxKJzyCq4jPQvdE/gsXncPyoft/aLWFseOCKc\na6w6iz4MH8J++DPGyhOfL1Z3H+7QUhTnyksiq+VfZjzJOycw6es0v03sQhmqEm7CJ6hs4+mDuXcy\nt+Oa1pRW13h4YQ9FONeJYn4xHCfjTIyQg3lZ39/TUhT748vyTfcdbf0TlvHadZx6ECMupPkvRUgP\nFUm+2fdZyk9Qmsk9s/hDwdV4OBriD0wRznWmmF9MxmHVU1eeo6UoDpFvKB6Cp7GjIU0PxTJe9zQn\nT2H0hTSfIXYaDVY98unDn6W8nq3TeOBg2hpyn5e7WuMk7AEtwnkAaimKBizA++Xdh+vlwyqQQ/px\nDl3PKeMZ92Wa3yPWpAeLLjl9P095C89O577ZrC3yqsZ10UFucIhwHsBaimK4fDPxDIyRS/O29j6f\n8ARz1/O24Uz6Ek3vF134B6oS/gtfoNJN+/78YSYbitzH5SetKa2p7QhDf4pwHgSqIX28vF49Xq78\n2FE/nbCK2es4pcS0j9NwPg2zazLasKdW4nJ6Lqe7ibUzeGBG/jf+PW5oTenJGg8x7AURzoNIS1E0\n4xi8W6782KhveR7WM3k1izZy1LGkT9H8TkQ3u/pSwXW4hPI9FJN4cCZPTM7/nnfixtaU/lzbUYa9\nKcJ5EGopikYslEN6mnwc7Ka+v6dM42O8bgtv7GLi+Qz7OA0H1WC8YacVuKI6S25k4zgWH8KmprzU\n/Bv8ujWOixoSIpwHsZaiGIYjcTpmyz/g69n1PJZ1TK3Opo94A+lj1VK86Nexb3TielxK+d48S15y\nIP83hW65D/7N+E1rSpte9IXCoBLhPARUO9jNlG8evkVuvPSMPKPeoUzTY7x+Kws2MeNEus+h+XS9\nDalDf9mEX+IHlG9n2ATWjuEPh9DelEvUV8jly0tbq50Iw9AS4TzEtBTFSLmvx2lyYHfJZ3ruck7c\nVkas4NBtHNXOQYvoOofhZ2DKvh70ILEO1+L7lO6hcRKrRrFkNmtH5Y1HJdwmH+X3VGweGdoinIeo\n6mx6Ft5UfTTJZXgb5f9O71CieQXzOjhyI3MOp/tvGP4XcsrHzcTn140luAU/ovQIwybx+JgcyKuH\n55WjYWKWHJ5HhHPQUhSj8Dq5Z8eR8qbCklyutcuMukzjSuZu4dDtzN3GmOPoegfNJ1EsMHTDugt/\nlKe+N1JaTOMIOkfyxDgemcX6phzIhfx3e6dcoxyz5PAcEc5hF9Vlj/ly3fRCOWvLcpg8ZzvwFkav\nYVYnc7czd2s1rE+l+U0Uhxu8NxY75JnxbaQbKd9H42g6RrB8NMsPYNXYPDMeLwfyGtyBh7AmAjm8\nmAjn8IKqm1sOxSIca+fmwi1yve1zzg/vYNQaZnUwt8yczUyYSNfhpGNpPqoa2PMMnBl2BcvkU6qX\nkO6j/BDF0zRO4JnmvFSx/ABWjcl/JxMw3I5Nmu7Cw9gQgRxergjn8LJUN7jMwsFyX49D7Gx894Jh\n3UPRzqSNTOvMNdczO5naycg5VI6k4VCaZmJGn8dk+65hU4/834LV8tR2NZ4iPURlCWkVTWPYOiqX\nIT41mnWTWD+JjcNyCE+w841rs3x+6kNY3prSyz1fPYRdRDiHV6Q6q56JuXYN60JuwtSB7XpPeNlN\nieYNTNnM1O2Mb2BSYkKJsZ2MrtC4H5XppJkUM2gYTcNYGkbKx8eMqn7s+0jyTLfc5+PW6mA65XeR\njXSvpOsprKVhE43NdI1iazNbhvFMN5tGsHEi6yezoTm/XCNGVx+Ndq4dL5VnxivRHrPj0B8inEO/\n6BPWs+WgPlieACc5xHrszMiXbGVZpnELYzsYt42xJUb30NhDU8HwguYi12s399CcaOqhsfru0F3k\nYonugq6CcmJ79VFqpDSCjlE8O5otY+lo2vXGZ4Oc/aPlEree6vdQxiosl1c6VmBThHHYGyKcw15T\nDeyp8nLGgXJoz5Enub2BV8gBXurzKHueJZJ+1CQvRwxXDfjq1+t9IyGvcCyX14zXyUsaEcRhn4lw\nDvtUtb56rLzpcCzGYZIc4lPk2fZEefb6fAFd9PlY7HY92bmM0vdzu/2ZDnk5ol1us7pBXjN/Vl4z\nbm9NqUsINRThHOpONcBHyz2qm+T13aYX+LxZDtwueSmjp/px96XnshzKHRG8YSCIcA4hhDoUx8uF\nEEIdinAOIYQ6FOEcQgh1KMI5hBDqUIRzCCHUoQjnEEKoQxHOIYRQhyKcQwihDkU4hxBCHYpwDiGE\nOhThHEIIdSjCOYQQ6lCEcwgh1KEI5xBCqEMRziGEUIcinEMIoQ5FOIcQQh2KcA4hhDoU4RxCCHUo\nwjmEEOpQhHMIIdShCOcQQqhDEc4hhFCHIpxDCKEORTiHEEIdinAOIYQ6FOEcQgh1KMI5hBDqUIRz\nCCHUoQjnEEKoQxHOIYRQhyKcQwihDkU4hxBCHYpwDiGEOhThHEIIdSjCOYQQ6lCEcwgh1KH/B9mF\n53AKZYwqAAAAAElFTkSuQmCC\n", "text/plain": "<matplotlib.figure.Figure at 0x3902fd0>"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 14, Page Number : GUC-34", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": " \nimport turtle\n\ni=0\nwhile i < 360:\n turtle.forward(3)\n turtle.left(3)\n i+=3\n \nturtle.penup()\nturtle.forward(200)\n\nturtle.pendown()\ni=0\nwhile i < 360:\n turtle.forward(3)\n turtle.left(3)\n i+=3\n \nturtle.penup()\nturtle.forward(100)\nturtle.left(90)\nturtle.forward(50)\nturtle.pendown()\nturtle.forward(100)\nturtle.left(90)\nturtle.forward(400)\nturtle.left(90)\nturtle.forward(100)\nturtle.right(90)\nturtle.forward(100)\nturtle.right(90)\nturtle.forward(150)\nturtle.right(90)\nturtle.forward(100)\nturtle.left(90)\nturtle.forward(50)\nturtle.right(90)\nturtle.forward(400)\nturtle.right(90)\nturtle.forward(50)\nturtle.left(90)\nturtle.forward(50)\nturtle.right(90)\nturtle.forward(100)\nturtle.left(90)\nturtle.forward(100)", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter4_2.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter4_2.ipynb
new file mode 100755
index 00000000..ab2c382f
--- /dev/null
+++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter4_2.ipynb
@@ -0,0 +1 @@
+{"nbformat": 4, "metadata": {"orig_nbformat": 3}, "cells": [{"source": "# Chapter 4: Input/Output Functions and Statements", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1.0, Page number: IOF-5", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 1, "outputs": [{"output_type": "stream", "name": "stdout", "text": "5\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "8 15\n"}], "source": "\n#Variable Declaration and Initialization\na = int(raw_input(\"\"))\nb = int(raw_input(\"\"))\n\n#Calculation\nsum1 = a + b\nproduct = a * b\n#Since sum is a keyword in python, sum1 is used\n\n#Output\nprint sum1, product", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 1.1, Page number: IOF-6", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 2, "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter Value to A : 5\n"}, {"output_type": "stream", "name": "stdout", "text": "Enter Value to B : 3\n"}, {"output_type": "stream", "name": "stdout", "text": "SUM = 8 \nPRODUCT = 15\n"}], "source": "\n#Variable initialization\na = int(raw_input(\"Enter Value to A : \"))\nb = int(raw_input(\"Enter Value to B : \"))\n\n#Calculation\nsum1 = a + b\nproduct = a * b\n#Since sum is a keyword in python, sum1 is used\n\n#Output\nprint \"SUM = \",sum1,\"\\nPRODUCT = \", product", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 2, Page number: IOF-10", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 8, "outputs": [{"output_type": "stream", "name": "stdout", "text": "Degree fahrenheit ? 105\n"}, {"output_type": "stream", "name": "stdout", "text": "Degree centigrade = 40.56"}], "source": "\n\nimport sys\n\n#Variable Initialization\nf = int(raw_input(\"Degree fahrenheit ? \"))\n\n#Calculation\nc = 5.0/9.0 * (f-32)\n\n#Output\nsys.stdout.write(\"Degree centigrade = %6.2f\"%(c))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 3, Page number: IOF-10", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 14, "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter three sides : 5\n"}, {"output_type": "stream", "name": "stdout", "text": "Enter three sides : 4\n"}, {"output_type": "stream", "name": "stdout", "text": "Enter three sides : 6\n"}, {"output_type": "stream", "name": "stdout", "text": "Area of Triangle = 6.48 Sq.units"}], "source": "\nimport sys\nimport math\n\n#Variable Initialization\na = int(raw_input(\"Enter three sides : \"))\nb = int(raw_input(\"Enter three sides : \"))\nc = int(raw_input(\"Enter three sides : \"))\n\n#Calculation\ns = (a+b+c)/2\narea = math.sqrt(s * (s-a) * (s-b) * (s-c))\n\n#Output\nsys.stdout.write(\"Area of Triangle = %6.2f Sq.units\"%(area))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 4, Page number: IOF-16", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 17, "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a character : A\n"}, {"output_type": "stream", "name": "stdout", "text": "\n\nASCII value of A is 65\nPress any key to stop..."}], "source": "\n#Variable Initialization\nch = raw_input(\"Enter a character : \")\n\n#Output\nsys.stdout.write(\"\\n\\nASCII value of %c is %u\"%(ch,ord(ch)))\nsys.stdout.write(\"\\nPress any key to stop...\")", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 5, Page number: IOF-16", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 18, "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter service number : TMR65358\n"}, {"output_type": "stream", "name": "stdout", "text": "\nPrevious month reading ? 4305\n"}, {"output_type": "stream", "name": "stdout", "text": "\nCurrent month reading ? 4410\n"}, {"output_type": "stream", "name": "stdout", "text": "\n Electricity Bill\n ________________\nService No. TMR65358\nUnits Consumed : 105\nElectricity Charges Rs. 157.50"}], "source": "\nimport sys\n\n#Variable initialization\nsno = raw_input(\"Enter service number : \")\npmr = int(raw_input(\"\\nPrevious month reading ? \"))\ncmr = int(raw_input(\"\\nCurrent month reading ? \"))\n\n#Calculation\nunits = cmr - pmr\namt = units * 1.50\n\n#Output\nsys.stdout.write(\"\\n Electricity Bill\")\nsys.stdout.write(\"\\n ________________\")\nsys.stdout.write(\"\\nService No. %s\"%(sno))\nsys.stdout.write(\"\\nUnits Consumed : %d\"%(units))\nsys.stdout.write(\"\\nElectricity Charges Rs. %0.2f\"%(amt))\n", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 6, Page number: IOF-17", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 19, "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to A : 15\n"}, {"output_type": "stream", "name": "stdout", "text": "Enter value to B : 250\n"}, {"output_type": "stream", "name": "stdout", "text": "\n\nValue of A = 250\nValue of B = 15"}], "source": "\n\nimport sys\n\n#Variable Initialization\na = int(raw_input(\"Enter value to A : \"))\nb = int(raw_input(\"Enter value to B : \"))\n\n#Calculation\ntemp = a\na = b\nb = temp\n\n#Output\nsys.stdout.write(\"\\n\\nValue of A = %d\"%(a))\nsys.stdout.write(\"\\nValue of B = %d\"%(b))", "metadata": {"collapsed": false, "trusted": false}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": "", "metadata": {"collapsed": false, "trusted": false}}], "nbformat_minor": 0} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter5_2.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter5_2.ipynb
new file mode 100755
index 00000000..964fe7b6
--- /dev/null
+++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter5_2.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 5: Control Statements in C", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1, Page Number : CSC-3", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "import sys\n\n#Variable Initialization\na = int(raw_input(\"\\nEnter two numbers : \"))\nb = int(raw_input(\"\"))\nbig = a\n\n#Processing\nif b > big:\n big = b\n\n#Output\nprint \"\\nBiggest number is \",big\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter two numbers : 5\n8\n\nBiggest number is 8\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2, Page Number : CSC-4", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "import sys\n\n#Variable Initialization\na = int(raw_input(\"\\nEnter three numbers : \"))\nb = int(raw_input(\"\"))\nc = int(raw_input(\"\"))\nbig = a\n\n#Processing\nif b > big:\n big = b\n \nif c > big:\n big = c\n \n#Output\nprint \"\\nBiggest number is \",big", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter three numbers : 5\n13\n8\n\nBiggest number is 13\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3, Page Number : CSC-6", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "import sys\n\n#Variable Initialization\na = int(raw_input(\"\\nEnter three numbers : \"))\nb = int(raw_input(\"\"))\nc = int(raw_input(\"\"))\n\n#Processing\nif a > b:\n if a > c:\n big = a\n else:\n big = c\nelse:\n if b > c:\n big = b\n else:\n big = c\n \n#Output\nprint \"\\nBiggest number is \",big", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter three numbers : 18\n-5\n13\n\nBiggest number is 18\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4, Page Number : CSC-7", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "import sys\n\nx = float(raw_input(\"\\nEnter value to x and n : \"))\nn = int(raw_input(\"\"))\n\nif n == 1:\n y = 1 + x\nelse:\n if n == 2:\n y = 1 + x/n\n else:\n if n == 3:\n y = 1 + pow(x,n)\n else:\n y = 1 + n*x\n \nprint \"\\nValue of y(x,n) = \",y", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter value to x and n : 0.42\n5\n\nValue of y(x,n) = 3.1\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5, Page Number : CSC-9", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "import sys\n\nx = float(raw_input(\"\\nEnter value to x and n : \"))\nn = int(raw_input(\"\"))\n\n#There is no switch statement in python\nif n == 1:\n y = 1 + x\nelse:\n if n == 2:\n y = 1 + x/n\n else:\n if n == 3:\n y = 1 + pow(x,n)\n else:\n y = 1 + n*x\n \nsys.stdout.write(\"\\nValue of y(x,n) = %6.2f\"%(y))", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter value to x and n : 0.42\n5\n\nValue of y(x,n) = 3.10"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6, Page Number : CSC-11", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "import sys\n\nsales = int(raw_input(\"\\nSales amount ? \"))\n\nif sales <= 500:\n comm = 0.05 * sales\nelse:\n if sales <= 2000:\n comm = 35 + 0.10 * (sales - 500)\n else:\n if sales <= 5000:\n comm = 185 + 0.12 * (sales - 2000)\n else:\n comm = 0.125 * sales\n \nsys.stdout.write(\"\\nCommission Amount Rs. %0.2f\"%(comm))", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nSales amount ? 4500\n\nCommission Amount Rs. 485.00"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7, Page Number : CSC-12", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "import sys\nimport math\n\na = int(raw_input(\"\\nEnter coefficients a,b and c : \"))\nb = int(raw_input())\nc = int(raw_input())\n\nd = b*b - 4*a*c\n\nif d > 0:\n x1 = (-b + math.sqrt(d))/(2*a)\n x2 = (-b - math.sqrt(d))/(2*a)\n sys.stdout.write(\"\\nRoots are real and unequal\\n %6.2f %6.2f\"%(x1,x2))\nelse:\n if d == 0:\n x = -b / (2*a)\n sys.stdout.write(\"\\nRoots are real and equal \\n %6.2f\"%(x))\n else:\n sys.stdout.write(\"\\nNo Real roots,roots are complex\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter coefficients a,b and c : 1\n3\n2\n\nRoots are real and unequal\n -1.00 -2.00"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8, Page Number : CSC-13", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "avg_marks = int(raw_input(\"\\nAverage Marks ? \"))\n\nif avg_marks >= 80 and avg_marks <= 100:\n print \"\\nHonours\"\nelse:\n if avg_marks >= 60 and avg_marks <= 79:\n print \"\\nFirst Division\"\n else:\n if avg_marks >= 50 and avg_marks <= 59:\n print \"\\nSecond Division\"\n else:\n if avg_marks <= 49 and avg_marks >= 0:\n print \"\\nFail\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nAverage Marks ? 84\n\nHonours\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9, Page Number : CSC-14", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "import sys\n\nunits = int(raw_input(\"\\nEnter consumed units : \"))\n\nif units <= 200:\n amt = 0.5 * units\nelse:\n if units <= 400:\n amt = 100 + 0.65 * (units - 200)\n else:\n if units <= 600:\n amt = 230 + 0.8 * (units - 400)\n else:\n amt = 425 + 1.25 * (units - 600)\n \nsys.stdout.write(\"\\nAmount to be paid Rs.%0.2f\"%(amt))", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter consumed units : 348\n\nAmount to be paid Rs.196.20"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10, Page Number : CSC-16", "cell_type": "markdown", "metadata": {}}, {"execution_count": 13, "cell_type": "code", "source": "ts = int(raw_input(\"\\nEnter tensile strength : \"))\nrh = int(raw_input(\"\\nEnter rockwell hardness : \"))\ncc = int(raw_input(\"\\nEnter carbon content : \"))\n\nif ts >= 700:\n if rh >= 200:\n if cc <= 6:\n print \"\\nGrade is A\"\n else:\n print \"\\nGrade is B\"\n else:\n if cc <= 6:\n print \"\\nGrade is C\"\n else:\n print \"\\nGrade is E\"\nelse:\n if rh >= 200:\n if cc <= 6:\n print \"\\nGrade is D\"\n else:\n print \"\\nGrade is E\"\n else:\n if cc <= 6:\n print \"\\nGrade is E\"\n else:\n print \"\\nGrade is F\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter tensile strength : 800\n\nEnter rockwell hardness : 180\n\nEnter carbon content : 3\n\nGrade is C\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter6_2.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter6_2.ipynb
new file mode 100755
index 00000000..5895262e
--- /dev/null
+++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter6_2.ipynb
@@ -0,0 +1 @@
+{"nbformat": 4, "metadata": {"orig_nbformat": 3}, "cells": [{"source": "# Chapter 6: Loop Control Structures in C", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1, Page Number : LCS-2", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 2, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter value to n : 15\n"}, {"output_type": "stream", "name": "stdout", "text": " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"}], "source": "import sys\n\nn = int(raw_input(\"\\nEnter value to n : \"))\n\nfor i in range(1,n+1):\n sys.stdout.write(\"%8d\"%(i))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 2, Page Number : LCS-3", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 8, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\n--------------------------------\n X Y \n--------------------------------\n\n 1.00 6.07\n 1.20 7.06\n 1.40 8.23\n 1.60 9.60\n 1.80 11.20\n 2.00 13.09\n 2.20 15.30\n 2.40 17.91\n 2.60 20.99\n 2.80 24.64\n 3.00 28.97\n--------------------------------\n"}], "source": "import sys\nimport numpy\nimport math\n\nprint \"\\n--------------------------------\"\nprint \" X Y \"\nprint \"--------------------------------\"\n\nfor x in numpy.arange(1.0,3.0+0.2,0.2):\n y = 1.36*math.sqrt(1+x+x*x*x)+ pow(x,1.0/4) + math.exp(x)\n sys.stdout.write(\"\\n %6.2f %6.2f\"%(x,y))\n \nprint \"\\n--------------------------------\"", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 3, Page Number : LCS-4", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 9, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter the number : 4\n"}, {"output_type": "stream", "name": "stdout", "text": "4 factorial is 24\n"}], "source": "k = int(raw_input(\"\\nEnter the number : \"))\n\nkfact = 1\n\nfor i in range(1,k+1):\n kfact = kfact * i\n \nprint k,\" factorial is \",kfact", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 4, Page Number : LCS-6", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 10, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter value to N : 4\n"}, {"output_type": "stream", "name": "stdout", "text": "\nSum of the series S = 20\n"}], "source": "n = int(raw_input(\"\\nEnter value to N : \"))\n\ns = 0\n\nfor i in range(1,n+1):\n term = 0\n for j in range(1,i+1):\n term = term + j\n s = s + term\n \nprint \"\\nSum of the series S = \",s", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 5, Page Number : LCS-7", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 11, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\n\nValue of y(-1.50,0.00) = -18.75\n\nValue of y(-1.50,1.00) = -16.75\n\nValue of y(-1.50,2.00) = -2.75\n\nValue of y(-1.50,3.00) = 35.25\n\nValue of y(-1.00,0.00) = -22.50\n\nValue of y(-1.00,1.00) = -20.50\n\nValue of y(-1.00,2.00) = -6.50\n\nValue of y(-1.00,3.00) = 31.50\n\nValue of y(-0.50,0.00) = -24.75\n\nValue of y(-0.50,1.00) = -22.75\n\nValue of y(-0.50,2.00) = -8.75\n\nValue of y(-0.50,3.00) = 29.25\n\nValue of y(0.00,0.00) = -25.50\n\nValue of y(0.00,1.00) = -23.50\n\nValue of y(0.00,2.00) = -9.50\n\nValue of y(0.00,3.00) = 28.50\n\nValue of y(0.50,0.00) = -24.75\n\nValue of y(0.50,1.00) = -22.75\n\nValue of y(0.50,2.00) = -8.75\n\nValue of y(0.50,3.00) = 29.25\n\nValue of y(1.00,0.00) = -22.50\n\nValue of y(1.00,1.00) = -20.50\n\nValue of y(1.00,2.00) = -6.50\n\nValue of y(1.00,3.00) = 31.50\n\nValue of y(1.50,0.00) = -18.75\n\nValue of y(1.50,1.00) = -16.75\n\nValue of y(1.50,2.00) = -2.75\n\nValue of y(1.50,3.00) = 35.25"}], "source": "import numpy\nimport sys\n\nfor x in numpy.arange(-1.5,1.5+0.5,0.5):\n for y in numpy.arange(0,3.0+1.0,1.0):\n z = 3*x*x + 2*y*y*y - 25.5\n sys.stdout.write(\"\\n\\nValue of y(%0.2f,%0.2f) = %6.2f\"%(x,y,z))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 6, Page Number : LCS-12", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 13, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter value to N : 10\n"}, {"output_type": "stream", "name": "stdout", "text": "\nSum of odd integers = 25\n"}], "source": "n = int(raw_input(\"\\nEnter value to N : \"))\n\ns = 0\ni = 1\n\nwhile i <= n:\n s = s + i\n i = i + 2\n \nprint \"\\nSum of odd integers = \",s", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 7, Page Number : LCS-13", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 15, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nInteger divisible by 7\n 7 14 21 28 35 42 49 56 63 70 77 84 91 98 105 112 119 126 133 140 147 154 161 168 175 182 189 196 203 210 217 224 231 238 245 252 259 266 273 280 287 294 301 308 315 322 329 336 343 350"}], "source": "import sys\n\nprint \"\\nInteger divisible by 7\"\n\nn = 7\n\nfor i in range(1,50+1):\n sys.stdout.write(\"%8d\"%(n))\n n = n + 7", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 8, Page Number : LCS-14", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 16, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter the end value N : 20\n"}, {"output_type": "stream", "name": "stdout", "text": "\nIntegers not divisible by 7\n 1 2 3 4 5 6 8 9 10 11 12 13 15 16 17 18 19 20"}], "source": "import sys\n\nn = int(raw_input(\"\\nEnter the end value N : \"))\n\nprint \"\\nIntegers not divisible by 7\"\n\nfor k in range(1,n+1):\n r = k % 7\n if r != 0:\n sys.stdout.write(\"%8d\"%(k))\n ", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 9, Page Number : LCS-15", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 17, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter a positive integer : 2466\n"}, {"output_type": "stream", "name": "stdout", "text": "\nSum of digits = 18\n"}], "source": "n = int(raw_input(\"\\nEnter a positive integer : \"))\n\nq = n\ns = 0\n\nwhile q > 0:\n r = q % 10\n s = s + r\n q = q/ 10\n \nprint \"\\nSum of digits = \",s", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 10, Page Number : LCS-16", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 18, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter an integer number : 153\n"}, {"output_type": "stream", "name": "stdout", "text": "\n153 is an Armstrong number\n"}], "source": "n = int(raw_input(\"\\nEnter an integer number : \"))\n\nq = n\ns = 0\nwhile q > 0:\n r = q % 10\n s = s + r*r*r\n q = q/10\n \nif n == s:\n print \"\\n\",n,\" is an Armstrong number\"\nelse:\n print \"\\n\",n,\" is not an Armstrong number\"", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 11, Page Number : LCS-17", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 19, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter an integer number : 18532\n"}, {"output_type": "stream", "name": "stdout", "text": "\n18532 is reversed as 23581\n"}], "source": "n = int(raw_input(\"\\nEnter an integer number : \"))\n\nq = n\nrn = 0\n\nwhile q > 0:\n r = q % 10\n rn = rn*10 + r\n q = q/10\n \nprint \"\\n\",n,\" is reversed as \",rn", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 12, Page Number : LCS-18", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 20, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter an integer number : 4352\n"}, {"output_type": "stream", "name": "stdout", "text": "Four\nThree\nFive\nTwo\n"}], "source": "n = int(raw_input(\"\\nEnter an integer number : \"))\n\nq = n\nrn = 0\n\nwhile q > 0:\n r = q % 10\n rn = rn*10 + r\n q = q/10\n\nwhile rn > 0:\n r = rn % 10\n \n #There is no switch statement in python\n if r == 1:\n print \"One\"\n else:\n if r == 2:\n print \"Two\"\n else:\n if r == 3:\n print \"Three\"\n else:\n if r == 4:\n print \"Four\"\n else:\n if r == 5:\n print \"Five\"\n else:\n if r == 6:\n print \"Six\"\n else:\n if r == 7:\n print \"Seven\"\n else:\n if r == 8:\n print \"Eight\"\n else:\n if r == 9:\n print \"Nine\"\n else:\n print \"Zero\"\n rn = rn/10", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 13, Page Number : LCS-20", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 21, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter a positive integer : 17\n"}, {"output_type": "stream", "name": "stdout", "text": "\n17 is a prime number\n"}], "source": "flag = 0\n\nn = int(raw_input(\"\\nEnter a positive integer : \"))\n\nfor k in range(2,n/2+1):\n if flag == 0:\n r = n % k\n if r == 0:\n flag = 1\n \nif flag == 0:\n print \"\\n\",n,\" is a prime number\"\nelse:\n print \"\\n\",n,\" is not a prime number\"", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 14, Page Number : LCS-21", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 22, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter the final term of the series : 25\n"}, {"output_type": "stream", "name": "stdout", "text": " 0 1 1 2 3 5 8 13 21"}], "source": "import sys\n\nn = int(raw_input(\"\\nEnter the final term of the series : \"))\n\nn1 = 0\nn2 = 1\n\nsys.stdout.write(\"%8d%8d\"%(n1,n2))\n\nnewterm = n1 + n2\n\nwhile newterm <= n:\n sys.stdout.write(\"%8d\"%(newterm))\n n1 = n2\n n2 = newterm\n newterm = n1 + n2\n ", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 15, Page Number : LCS-22", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 23, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter x in radians : 0.52\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter end term power (n) : 10\n"}, {"output_type": "stream", "name": "stdout", "text": "\nSum of the series = 0.496880137863\n"}], "source": "x = float(raw_input(\"\\nEnter x in radians : \"))\nn = int(raw_input(\"\\nEnter end term power (n) : \"))\n\ns = 0\nterm = x\ni = 1\n\nwhile i <= n:\n s = s + term\n term = (term*x*x*(-1))/((i+1)*(i+2))\n i = i + 2\n \nprint \"\\nSum of the series = \",s", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 16, Page Number : LCS-24", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 24, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter x in radians : 0.52\n"}, {"output_type": "stream", "name": "stdout", "text": "\nSum of the series = 0.867819179677\n"}], "source": "x = float(raw_input(\"\\nEnter x in radians : \"))\n\ns = 0\nterm = 1\ni = 0\n\nwhile i <= n:\n s = s + term\n term = (term*x*x*(-1))/((i+1)*(i+2))\n i = i + 2\n \nprint \"\\nSum of the series = \",s", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 17, Page Number : LCS-25", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 27, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nValue of pie is 3.14"}], "source": "import sys\nimport math\n\ns = 0\ndr = 1\nsign = 1\nterm = 1.0/dr * sign\n\nwhile (math.fabs(term) >= 1.0e-4):\n s = s + term\n dr = dr + 2\n sign = sign * (-1)\n term = (1.0/dr) * sign\n \npie = s * 4\n\nsys.stdout.write(\"\\nValue of pie is %0.2f\"%(pie))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 18, Page Number : LCS-27", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 29, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter value to N : 15\n"}, {"output_type": "stream", "name": "stdout", "text": "\nSum of series = 3.3182"}], "source": "import sys\n\nn = int(raw_input(\"\\nEnter value to N : \"))\n\ns = 0\n\nfor i in range(1,n+1):\n s = s + 1.0/i\n \nsys.stdout.write(\"\\nSum of series = %8.4f\"%(s))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 19, Page Number : LCS-28", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 35, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many lines ? 5\n"}, {"output_type": "stream", "name": "stdout", "text": " 1\n 2 3 2\n 3 4 5 4 3\n 4 5 6 7 6 5 4\n 5 6 7 8 9 8 7 6 5\n"}], "source": "import sys\n\nn = int(raw_input(\"\\nHow many lines ? \"))\n\nfor l in range(1,n+1):\n for i in range(1,n-l+1):\n sys.stdout.write(\" \")\n \n m = l\n for j in range(1,l+1):\n sys.stdout.write(\"%6d\"%(m))\n m = m + 1\n m = m - 2\n \n for k in range(1,l):\n sys.stdout.write(\"%6d\"%(m))\n m = m - 1\n \n sys.stdout.write(\"\\n\")\n \n", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 20, Page Number : LCS-29", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 38, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many rows ? 6\n"}, {"output_type": "stream", "name": "stdout", "text": "\n\t\t\t\t PASCAL TRIANGLE\n\n 1\n 1 1\n 1 2 1\n 1 3 3 1\n 1 4 6 4 1\n 1 5 10 10 5 1\n"}], "source": "import sys\n\nn = int(raw_input(\"\\nHow many rows ? \"))\n\nprint \"\\n\\t\\t\\t\\t PASCAL TRIANGLE\\n\"\n\nm = 1\n\nfor l in range(0,n):\n for i in range(40-3*l,0,-1):\n sys.stdout.write(\" \")\n \n for j in range(0,l+1):\n if j == 0 or l == 0:\n m = 1\n else:\n m = (m*(l-j+1))/j\n sys.stdout.write(\"%6d\"%(m))\n sys.stdout.write(\"\\n\")", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 21, Page Number : LCS-31", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 39, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\n\nMultiplication table for 1\n\n 1 x 1 = 1\n 2 x 1 = 2\n 3 x 1 = 3\n 4 x 1 = 4\n 5 x 1 = 5\n 6 x 1 = 6\n 7 x 1 = 7\n 8 x 1 = 8\n 9 x 1 = 9\n 10 x 1 = 10\n\nPress any key to continue...\n\nMultiplication table for 2\n\n 1 x 2 = 2\n 2 x 2 = 4\n 3 x 2 = 6\n 4 x 2 = 8\n 5 x 2 = 10\n 6 x 2 = 12\n 7 x 2 = 14\n 8 x 2 = 16\n 9 x 2 = 18\n 10 x 2 = 20\n\nPress any key to continue...\n\nMultiplication table for 3\n\n 1 x 3 = 3\n 2 x 3 = 6\n 3 x 3 = 9\n 4 x 3 = 12\n 5 x 3 = 15\n 6 x 3 = 18\n 7 x 3 = 21\n 8 x 3 = 24\n 9 x 3 = 27\n 10 x 3 = 30\n\nPress any key to continue...\n\nMultiplication table for 4\n\n 1 x 4 = 4\n 2 x 4 = 8\n 3 x 4 = 12\n 4 x 4 = 16\n 5 x 4 = 20\n 6 x 4 = 24\n 7 x 4 = 28\n 8 x 4 = 32\n 9 x 4 = 36\n 10 x 4 = 40\n\nPress any key to continue...\n\nMultiplication table for 5\n\n 1 x 5 = 5\n 2 x 5 = 10\n 3 x 5 = 15\n 4 x 5 = 20\n 5 x 5 = 25\n 6 x 5 = 30\n 7 x 5 = 35\n 8 x 5 = 40\n 9 x 5 = 45\n 10 x 5 = 50\n\nPress any key to continue..."}], "source": "import sys\n\nfor i in range(1,5+1):\n sys.stdout.write(\"\\n\\nMultiplication table for %d\\n\"%(i))\n \n for j in range(1,10+1):\n sys.stdout.write(\"\\n%4d x %2d = %4d\"%(j,i,j*i))\n \n sys.stdout.write(\"\\n\\nPress any key to continue...\")", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 22, Page Number : LCS-32", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 40, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter the binary number : 1101\n"}, {"output_type": "stream", "name": "stdout", "text": "\nThe decimal number is : 13\n"}], "source": "\nn = int(raw_input(\"\\nEnter the binary number : \"))\n\nq = n\ns = 0\nk = 0\n\nwhile q > 0:\n r = q % 10\n s = s + r * pow(2,k)\n q = q/10\n k = k + 1\n \nprint \"\\nThe decimal number is : \",s", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 13, Page Number : LCS-34", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 41, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter the decimal number : 28\n"}, {"output_type": "stream", "name": "stdout", "text": "\nThe binary number is 11100\n"}], "source": "flag = 0\nk = 0\n\nn = int(raw_input(\"\\nEnter the decimal number : \"))\n\nq = n\nrbi = 0\n\nwhile q > 0:\n r = q % 2\n if r == 0 and flag == 0:\n k = k + 1\n else:\n flag = 1\n rbi = rbi *10 + r\n q = q/2\n \nq = rbi\nbi = 0\n\nwhile q > 0:\n r = q % 10\n bi = bi * 10 + r\n q = q/10\n if q == 0:\n for i in range(1,k+1):\n bi = bi * 10\n \nprint \"\\nThe binary number is \",bi", "metadata": {"collapsed": false, "trusted": false}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": "", "metadata": {"collapsed": false, "trusted": false}}], "nbformat_minor": 0} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter7_2.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter7_2.ipynb
new file mode 100755
index 00000000..a38c0b28
--- /dev/null
+++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter7_2.ipynb
@@ -0,0 +1 @@
+{"nbformat": 4, "metadata": {"orig_nbformat": 3}, "cells": [{"source": "# Chapter 7: Arrays and Subscripted Variables", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1, Page Number : ASV-4", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 10, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many integers ? 5\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the 1th value : 36\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the 2th value : 45\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the 3th value : 52\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the 4th value : 44\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the 5th value : 62\n"}, {"output_type": "stream", "name": "stdout", "text": "\nSum of all integers = 239"}], "source": "import sys\n\n#Variable Initialization\nn = int(raw_input(\"\\nHow many integers ? \"))\nx = [0 for i in range(0,n)]\n\nfor i in range(0,n):\n x[i] = int(raw_input(\"\\nEnter the %dth value : \"%(i+1)))\n \n#Processing\n#sum is a predefined function in python. so sum1 is used\nsum1 = 0\nfor i in range(0,n):\n sum1 = sum1 + x[i]\n \n#Output\nsys.stdout.write(\"\\nSum of all integers = %d\"%(sum1))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 2, Page Number : ASV-5", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 11, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many numbers ? 5\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter all those numbers "}, {"output_type": "stream", "name": "stdout", "text": "25\n"}, {"output_type": "stream", "name": "stdout", "text": "-228\n"}, {"output_type": "stream", "name": "stdout", "text": "0\n"}, {"output_type": "stream", "name": "stdout", "text": "185\n"}, {"output_type": "stream", "name": "stdout", "text": "36\n"}, {"output_type": "stream", "name": "stdout", "text": "\n185 is the biggest number"}], "source": "import sys\n\n#Variable initialization\nn = int(raw_input(\"\\nHow many numbers ? \"))\nsys.stdout.write(\"\\nEnter all those numbers \")\nx = [0 for i in range(0,n)]\n\nfor i in range(0,n):\n x[i] = int(raw_input(\"\"))\n \n#Processing\nbig = x[0]\nfor i in range(0,n):\n if x[i] > big:\n big = x[i]\n \n#Output\nsys.stdout.write(\"\\n%d is the biggest number\"%(big))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 3, Page Number : ASV-6", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 13, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many values ? 6\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter all values in the list\n"}, {"output_type": "stream", "name": "stdout", "text": "3.1\n"}, {"output_type": "stream", "name": "stdout", "text": "3.8\n"}, {"output_type": "stream", "name": "stdout", "text": "3.6\n"}, {"output_type": "stream", "name": "stdout", "text": "4.0\n"}, {"output_type": "stream", "name": "stdout", "text": "3.4\n"}, {"output_type": "stream", "name": "stdout", "text": "3.8\n"}, {"output_type": "stream", "name": "stdout", "text": "\nArithmetic mean = 3.617\nVariance = 0.088\nStandard deviation = 0.297"}], "source": "import sys\nimport math\n\n#Variable Initialization\nn = int(raw_input(\"\\nHow many values ? \"))\nx = [0.0 for i in range(0,n)]\n\nsys.stdout.write(\"\\nEnter all values in the list\\n\")\nfor i in range(0,n):\n x[i] = float(raw_input(\"\"))\n \n#Processing\nsum1 = 0\n#Since sum is a predefined function in python, sum1 is used\nfor i in range(0,n):\n sum1 = sum1 + x[i]\nxbar = sum1 / n\nvsum = 0\n\nfor i in range(0,n):\n vsum = vsum + (x[i] - xbar) * (x[i] - xbar)\nsigmax = vsum / n\nsd = math.sqrt(sigmax)\n\n#Output\nsys.stdout.write(\"\\nArithmetic mean = %0.3f\"%(xbar))\nsys.stdout.write(\"\\nVariance = %0.3f\"%(sigmax))\nsys.stdout.write(\"\\nStandard deviation = %0.3f\"%(sd))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 4, Page Number : ASV-8", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 15, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many students ? 5\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter all the marks \n"}, {"output_type": "stream", "name": "stdout", "text": "58\n"}, {"output_type": "stream", "name": "stdout", "text": "63\n"}, {"output_type": "stream", "name": "stdout", "text": "68\n"}, {"output_type": "stream", "name": "stdout", "text": "54\n"}, {"output_type": "stream", "name": "stdout", "text": "48\n"}, {"output_type": "stream", "name": "stdout", "text": "\nMean = 58.20\n\nMarks greater than mean : 63 68"}], "source": "import sys\n\n#Variable Initialization\nn = int(raw_input(\"\\nHow many students ? \"))\n\nsys.stdout.write(\"\\nEnter all the marks \\n\")\nfor i in range(0,n):\n x[i] = int(raw_input(\"\"))\n \n#Processing\nsum1 = 0.0\n#Since sum is a predefined function in python, sum1 is used\nfor i in range(0,n):\n sum1 = sum1 + x[i]\n \nmean = float(sum1/n)\n\n#Output\nsys.stdout.write(\"\\nMean = %6.2f\"%(mean))\nsys.stdout.write(\"\\n\\nMarks greater than mean : \")\n\nfor i in range(0,n):\n if x[i] > mean:\n sys.stdout.write(\"%5d\"%(x[i]))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 5, Page Number : ASV-9", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 16, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many values ? 6\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter all values in the list \n"}, {"output_type": "stream", "name": "stdout", "text": "8\n"}, {"output_type": "stream", "name": "stdout", "text": "-12\n"}, {"output_type": "stream", "name": "stdout", "text": "-16\n"}, {"output_type": "stream", "name": "stdout", "text": "12\n"}, {"output_type": "stream", "name": "stdout", "text": "-9\n"}, {"output_type": "stream", "name": "stdout", "text": "5\n"}, {"output_type": "stream", "name": "stdout", "text": "\nSum of positive values = 25.00\nSum of negative values = -37.00\nNegative sum is greater in magnitude\nDifference in magnitude = 12.00"}], "source": "import sys\nimport math\n\n#Variable Initialization\nn = int(raw_input(\"\\nHow many values ? \"))\n\nsys.stdout.write(\"\\nEnter all values in the list \\n\")\nfor i in range(0,n):\n x[i] = float(raw_input(\"\"))\n \npsum = 0\nnsum = 0\n\n#Processing\nfor i in range(0,n):\n if x[i] > 0:\n psum = psum + x[i]\n else:\n nsum = nsum + x[i]\n \n#Output\nsys.stdout.write(\"\\nSum of positive values = %0.2f\"%(psum))\nsys.stdout.write(\"\\nSum of negative values = %0.2f\"%(nsum))\nif psum > math.fabs(nsum):\n sys.stdout.write(\"\\nPositive sum is greater in magnitude\")\nelse:\n sys.stdout.write(\"\\nNegative sum is greater in magnitude\")\n \ndiff = math.fabs(psum - math.fabs(nsum))\nsys.stdout.write(\"\\nDifference in magnitude = %0.2f\"%(diff))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 6, Page Number : ASV-11", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 18, "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many numbers ? 4\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the list of 4 numbers\n"}, {"output_type": "stream", "name": "stdout", "text": "32\n"}, {"output_type": "stream", "name": "stdout", "text": "-10\n"}, {"output_type": "stream", "name": "stdout", "text": "20\n"}, {"output_type": "stream", "name": "stdout", "text": "5\n"}, {"output_type": "stream", "name": "stdout", "text": "\nNumbers in ascending order\n -10 5 20 32"}], "source": "import sys\n\n#Variable Initialization\nn = int(raw_input(\"How many numbers ? \"))\n\nsys.stdout.write(\"\\nEnter the list of %d numbers\\n\"%(n))\nfor i in range(0,n):\n x[i] = int(raw_input(\"\"))\n \n#Processing\nfor i in range(0,n):\n for j in range(i+1,n):\n if x[i] > x[j]:\n temp = x[i]\n x[i] = x[j]\n x[j] = temp\n \n#Output\nsys.stdout.write(\"\\nNumbers in ascending order\\n\")\nfor i in range(0,n):\n sys.stdout.write(\"%5d\"%(x[i]))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 7, Page Number : ASV-13", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 2, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many values in the list ? 6\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter all values in the list\n"}, {"output_type": "stream", "name": "stdout", "text": "6\n"}, {"output_type": "stream", "name": "stdout", "text": "-2\n"}, {"output_type": "stream", "name": "stdout", "text": "8\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "13\n"}, {"output_type": "stream", "name": "stdout", "text": "10\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the key value to be searched : 3\n"}, {"output_type": "stream", "name": "stdout", "text": "\n3 is available in 4th location"}], "source": "import sys\n\nx = [0 for i in range(0,50)]\n\n#Variable Initialization\nn = int(raw_input(\"\\nHow many values in the list ? \"))\n\nsys.stdout.write(\"\\nEnter all values in the list\\n\")\nfor i in range(0,n):\n x[i] = int(raw_input(\"\"))\ns = int(raw_input(\"\\nEnter the key value to be searched : \"))\n\n#Processing\nfor i in range(0,n):\n if s == x[i]:\n sys.stdout.write(\"\\n%d is available in %dth location\"%(s,i+1))\n \nif i == n+1:\n sys.stdout.write(\"\\nThe key value %d is not present in the list\"%(s))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 8, Page Number : ASV-15", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 22, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many numbers ? 4\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter all numbers in the list\n"}, {"output_type": "stream", "name": "stdout", "text": "6\n"}, {"output_type": "stream", "name": "stdout", "text": "-2\n"}, {"output_type": "stream", "name": "stdout", "text": "8\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "\nThe sorted list is\n -2 3 6 8\nSorted in 3 passes and 3 exchanges"}], "source": "import sys\n\n#Variable Initialization\nexchng = 0\nn = int(raw_input(\"\\nHow many numbers ? \"))\nsys.stdout.write(\"\\nEnter all numbers in the list\\n\")\nfor i in range(0,n):\n x[i] = int(raw_input(\"\"))\n\n#Processing\nfor i in range(0,n-1):\n for j in range(0,n-i-1):\n if x[j] > x[j+1]:\n temp = x[j]\n x[j] = x[j+1]\n x[j+1] = temp\n exchng = exchng + 1\n \n#Output\nsys.stdout.write(\"\\nThe sorted list is\\n\")\nfor i in range(0,n):\n sys.stdout.write(\"%5d\"%(x[i]))\n \nsys.stdout.write(\"\\nSorted in %d passes and %d exchanges\"%(n-1,exchng))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 9, Page Number : ASV-17", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 33, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many rows and columns ? 2\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter A matrix\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "-2\n"}, {"output_type": "stream", "name": "stdout", "text": "0\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter B matrix\n"}, {"output_type": "stream", "name": "stdout", "text": "6\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "-5\n"}, {"output_type": "stream", "name": "stdout", "text": "\nResultant matrix is \n 8 0\n 4 -1\n"}], "source": "import sys\n\n#Variable declaration and initialization\n\nm = int(raw_input(\"\\nHow many rows and columns ? \"))\nn = int(raw_input(\"\"))\n\na = [[0 for i in range(0,m)] for j in range(0,n)]\nb = [[0 for i in range(0,m)] for j in range(0,n)]\nc = [[0 for i in range(0,m)] for j in range(0,n)]\n\nsys.stdout.write(\"\\nEnter A matrix\\n\")\nfor i in range(0,m):\n for j in range(0,n):\n a[i][j] = int(raw_input(\"\"))\n \nsys.stdout.write(\"\\nEnter B matrix\\n\")\nfor i in range(0,m):\n for j in range(0,n):\n b[i][j] = int(raw_input(\"\"))\n \n#Processing\nfor i in range(0,m):\n for j in range(0,n):\n c[i][j] = a[i][j] + b[i][j]\n \n#Output\nsys.stdout.write(\"\\nResultant matrix is \\n\")\nfor i in range(0,m):\n for j in range(0,n):\n sys.stdout.write(\"%6d\"%(c[i][j]))\n sys.stdout.write(\"\\n\")", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 10, Page Number : ASV-18", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 34, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter order of A matrix : 2\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter A matrix\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "-2\n"}, {"output_type": "stream", "name": "stdout", "text": "0\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter order of B matrix : 2\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter B matrix\n"}, {"output_type": "stream", "name": "stdout", "text": "6\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "-5\n"}, {"output_type": "stream", "name": "stdout", "text": "\nResultant matrix is \n 4 14\n 16 -20\n"}], "source": "import sys\n\n#Variable declaration and initialization\n\nm = int(raw_input(\"\\nEnter order of A matrix : \"))\nn = int(raw_input(\"\"))\n\na = [[0 for i in range(0,m)] for j in range(0,n)]\nb = [[0 for i in range(0,m)] for j in range(0,n)]\nc = [[0 for i in range(0,m)] for j in range(0,n)]\n\nsys.stdout.write(\"\\nEnter A matrix\\n\")\nfor i in range(0,m):\n for j in range(0,n):\n a[i][j] = int(raw_input(\"\"))\n\nn = int(raw_input(\"\\nEnter order of B matrix : \"))\nl = int(raw_input(\"\"))\n\nsys.stdout.write(\"\\nEnter B matrix\\n\")\nfor i in range(0,n):\n for j in range(0,l):\n b[i][j] = int(raw_input(\"\"))\n \n#Processing\nfor i in range(0,n):\n for j in range(0,l):\n c[i][j] = 0\n for k in range(0,n):\n c[i][j] = c[i][j] + a[i][k] * b[k][j]\n \n#Output\nsys.stdout.write(\"\\nResultant matrix is \\n\")\nfor i in range(0,m):\n for j in range(0,l):\n sys.stdout.write(\"%6d\"%(c[i][j]))\n sys.stdout.write(\"\\n\")", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 11, Page Number : ASV-20", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 35, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter order of the matrix : 2\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the matrix values\n"}, {"output_type": "stream", "name": "stdout", "text": "-3\n"}, {"output_type": "stream", "name": "stdout", "text": "6\n"}, {"output_type": "stream", "name": "stdout", "text": "0\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "8\n"}, {"output_type": "stream", "name": "stdout", "text": "\nThe transposed matrix is\n -3 3\n 6 2\n 0 8\n"}], "source": "import sys\n\n#Variable declaration and initialization\n\nm = int(raw_input(\"\\nEnter order of the matrix : \"))\nn = int(raw_input(\"\"))\n\na = [[0 for i in range(0,10)] for j in range(0,10)]\nat = [[0 for i in range(0,10)] for j in range(0,10)]\n\nsys.stdout.write(\"\\nEnter the matrix values\\n\")\nfor i in range(0,m):\n for j in range(0,n):\n a[i][j] = int(raw_input(\"\"))\n\n#Processing\nfor i in range(0,m):\n for j in range(0,n):\n at[j][i] = a[i][j]\n \n#Output\nsys.stdout.write(\"\\nThe transposed matrix is\\n\")\nfor i in range(0,n):\n for j in range(0,m):\n sys.stdout.write(\"%6d\"%(at[i][j]))\n sys.stdout.write(\"\\n\")", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 12, Page Number : ASV-21", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 38, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter order of the square matrix : 3\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the matrix\n"}, {"output_type": "stream", "name": "stdout", "text": "5\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "8\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "1\n"}, {"output_type": "stream", "name": "stdout", "text": "-7\n"}, {"output_type": "stream", "name": "stdout", "text": "8\n"}, {"output_type": "stream", "name": "stdout", "text": "-7\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "\nThe given matrix is a symmetric matrix"}], "source": "import sys\n\n#Variable declaration and initialization\n\nm = int(raw_input(\"\\nEnter order of the square matrix : \"))\n\na = [[0 for i in range(0,10)] for j in range(0,10)]\n\nsys.stdout.write(\"\\nEnter the matrix\\n\")\nfor i in range(0,m):\n for j in range(0,m):\n a[i][j] = int(raw_input(\"\"))\n\n#Processing\nflag = 0\nfor i in range(0,m):\n if flag == 0:\n for j in range(0,m):\n if flag == 0:\n if a[i][j] == a[j][i]:\n continue\n else:\n flag = 1\n\n#Output\nif flag == 0:\n sys.stdout.write(\"\\nThe given matrix is a symmetric matrix\")\nelse:\n sys.stdout.write(\"\\nThe given matrix is not a symmetric matrix\")", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 13, Page Number : ASV-23", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 39, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter order of the square matrix : 3\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the matrix\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "-1\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "1\n"}, {"output_type": "stream", "name": "stdout", "text": "8\n"}, {"output_type": "stream", "name": "stdout", "text": "6\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "\nTrace of the matrix = 6"}], "source": "import sys\n\n#Variable declaration and initialization\n\nm = int(raw_input(\"\\nEnter order of the square matrix : \"))\n\na = [[0 for i in range(0,10)] for j in range(0,10)]\n\nsys.stdout.write(\"\\nEnter the matrix\\n\")\nfor i in range(0,m):\n for j in range(0,m):\n a[i][j] = int(raw_input(\"\"))\n\n#Processing \nsum1 = 0\n#since sum is a predefined function in python, sum1 is used\nfor i in range(0,m):\n sum1 = sum1 + a[i][i]\n \n#Output\nsys.stdout.write(\"\\nTrace of the matrix = %d\"%(sum1))", "metadata": {"collapsed": false, "trusted": false}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": "", "metadata": {"collapsed": false, "trusted": false}}], "nbformat_minor": 0} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter8_2.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter8_2.ipynb
new file mode 100755
index 00000000..9752076e
--- /dev/null
+++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter8_2.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "#Chapter 8: String Manipulations in C", "cell_type": "markdown", "metadata": {}}, {"source": "##Example 1, Page number: SMC-4", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "#Count a character in a string\n\nimport sys\n\n#Variable Initialization\nst = raw_input(\"Enter the string : \")\nch = raw_input(\"Which char to be counted ?\")\n\n#Checking\nl = len(st)\ncount = 0\nfor i in st:\n if i == ch:\n count = count + 1\n \n#Output\nsys.stdout.write(\"\\nThe character %c occurs %d times\"%(ch,count))", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the string : MISSISSIPPI\nWhich char to be counted ?S\n\nThe character S occurs 4 times"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 2, Page number: SMC-5", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "#Counting vowels\n\nimport sys\n\n#Variable Initialization\nst = raw_input(\"Enter the sentence :\")\ncount = 0\n\n#Processing\nfor i in st:\n if i == 'A'or i == 'E' or i == 'I' or i == 'O' or i == 'U' or i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u':\n count = count + 1\n\n#Result\nsys.stdout.write(\"%d vowels are present in the sentence\"%(count))\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the sentence :This is a book\n5 vowels are present in the sentence"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 3, Page number: SMC-6", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "#Palindrome or not \n\nimport sys\n\n#Variable Initialization\nrst = ['' for i in range(0,20)]\nst = raw_input(\"Enter the string : \")\nj = len(st)-1\n\n#Processing\nrst = st[::-1]\n\n#Result\nif st == rst:\n sys.stdout.write(\"%s is a palindrome string\"%(st))\nelse:\n sys.stdout.write(\"%s is not a palindrome string\"%(st))\n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the string : HYDERABAD\nHYDERABAD is not a palindrome string"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 4, Page number: SMC-8", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "#String Concatenation\n\nimport sys\n\n#Variable Initialization\nst1 = raw_input(\"Enter first string : \")\nst2 = raw_input(\"Enter second string : \")\n\n#Processing\nst = st1 + \" \" + st2\n\n#Result\nsys.stdout.write(\"\\nResultant string is %s\"%(st))", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter first string : NEW\nEnter second string : DELHI\n\nResultant string is NEW DELHI"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 5, Page number: SMC-10", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "#Print greater string\n\nimport sys\n\n#Variable Initialization\nst1 = raw_input(\"Enter string 1 : \")\nst2 = raw_input(\"Enter string 2 : \")\n\n\n#Result\nif st1 > st2:\n sys.stdout.write(\"%s is alphabetically greater string\"%(st1))\nelse:\n sys.stdout.write(\"%s is alphabetically greater string\"%(st2))", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter string 1 : ALPHA\nEnter string 2 : BETA\nBETA is alphabetically greater string"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 6, Page number: SMC-11", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "#String sorting\n\nimport sys\n\n#Variable Initialization\nnames = [\"\" for i in range(0,50)]\nn = int(raw_input(\"How many names ? \"))\nsys.stdout.write(\"\\nEnter the %d names one by one\"%(n))\n\nfor i in range(0,n):\n names[i] = raw_input(\"\")\n \nfor i in range(0,n):\n for j in range(i+1,n):\n if names[i] > names[j]:\n temp = names[i]\n names[i] = names[j]\n names[j] = temp\n \n#Result\nsys.stdout.write(\"\\nNames in alphabetical order\")\nfor i in range(0,n):\n sys.stdout.write(\"\\n%s\"%(names[i]))", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many names ? 4\n\nEnter the 4 names one by oneDEEPAK\nSHERIN\nSONIKA\nARUN\n\nNames in alphabetical order\nARUN\nDEEPAK\nSHERIN\nSONIKA"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 7, Page number: SMC-13", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "#Lower case text to upper case\n\nimport sys\n\n#Variable Initialization\nst = raw_input(\"Enter a sentence : \")\n\n#Result\nst = st.upper()\n\nsys.stdout.write(\"\\nThe converted upper case string is \\n%s\"%(st))", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a sentence : logical thinking is a must to learn programming\n\nThe converted upper case string is \nLOGICAL THINKING IS A MUST TO LEARN PROGRAMMING"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 8, Page number: SMC-14", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "#Determine the longest word\n\nimport sys\n\n\n#Variable Initialization\nst = raw_input(\"Enter a sentence \")\n\n#Processing\nlngst = max(st.split(), key=len)\n\n#Result\nsys.stdout.write(\"\\nLongest word is %s\"%(lngst))\nsys.stdout.write(\"\\nPress any key to continue...\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a sentence SMALL THINGS MAKE PERFECTION BUT PERFECTION IS NO SMALL THING\n\nLongest word is PERFECTION\nPress any key to continue..."}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 9, Page number: SMC-16", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "#Remove particular word in a text\n\nimport sys\n\n#Variable Initialization\nst = raw_input(\"Enter a sentence : \")\n\nomit = raw_input(\"\\nEnter word to omit : \")\nword = st.split()\nnewst = ' '.join([i for i in word if i not in omit])\n\n#Result\nsys.stdout.write(\"\\nAfter omitting the word %s\\n%s\"%(omit,newst))\nsys.stdout.write(\"\\nPress any key to continue...\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a sentence : TO ACCESS THE NAME OF THE CITY IN THE LIST\n\nEnter word to omit : THE\n\nAfter omitting the word THE\nTO ACCESS NAME OF CITY IN LIST\nPress any key to continue..."}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 10, Page number: SMC-17", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "#Telegram expense calculation\n\nimport sys\n\n#Variable Initialization\nst = raw_input(\"Type the sentence for Telegram : \")\n\ncount = len(st.split())\n\nif count <= 10:\n amt = 5\nelse:\n amt = 5 + (count - 10) * 1.25\n \n#Result\nsys.stdout.write(\"\\nAmount to be paid for telegram = Rs. %6.2f\"%(amt))", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Type the sentence for Telegram : Congratulations on your success in Examinations.\n\nAmount to be paid for telegram = Rs. 5.00"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "##Example 11, Page number: SMC-19", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "#Count lines, words and characters\n\nimport sys\n\n#Variable Initialization\ntxt = raw_input(\"Enter the text, type $st end\\n\\n\")\n\nwds = 0\nlns = 0\nchs = 0\n\n#Processing\nfor i in txt:\n if i == ',' or i == '!' or i == '\\t' or i == ' ':\n wds += 1\n chs += 1\n else:\n if i == '?' :\n \n lns += 1\n else:\n if i == '.':\n wds += 1\n lns += 1\n else:\n chs += 1\n \n#Result\nsys.stdout.write(\"\\n\\nNumber of char(incl.blanks) = %d\"%(chs))\nsys.stdout.write(\"\\nNumber of words = %d\"%(wds))\nsys.stdout.write(\"\\nNumber of lines = %d\"%(lns))\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the text, type $st end\n\nWhat is a string? How do you initialize it? Explain with example.$\n\n\nNumber of char(incl.blanks) = 63\nNumber of words = 12\nNumber of lines = 3"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter9_2.ipynb b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter9_2.ipynb
new file mode 100755
index 00000000..372f38eb
--- /dev/null
+++ b/A_First_course_in_Programming_with_C_by_T_Jeyapoovan/Chapter9_2.ipynb
@@ -0,0 +1 @@
+{"nbformat": 4, "metadata": {"orig_nbformat": 3}, "cells": [{"source": "# Chapter 9: Functions in C", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1, Page Number: FNC-5", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 1, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter value to n and r : 5\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "\nValue of nCr = 10\n"}], "source": "def fact(k):\n p = 1\n for i in range(1,k+1):\n p = p * i\n return p\n\nn = int(raw_input(\"\\nEnter value to n and r : \"))\nr = int(raw_input(\"\"))\n\nncr = fact(n)/ (fact(r)*fact(n-r))\n\nprint \"\\nValue of nCr = \",ncr", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 2, Page Number: FNC-6", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 2, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter three test scores : 62\n"}, {"output_type": "stream", "name": "stdout", "text": "70\n"}, {"output_type": "stream", "name": "stdout", "text": "58\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter three assignment scores : 17\n"}, {"output_type": "stream", "name": "stdout", "text": "21\n"}, {"output_type": "stream", "name": "stdout", "text": "23\n"}, {"output_type": "stream", "name": "stdout", "text": "\nTotal marks = 93\n"}], "source": "def big(a,b,c):\n if a > b:\n if a > c:\n return a\n else:\n return c\n else:\n if b > c:\n return b\n else:\n return c\n \nt1 = int(raw_input(\"\\nEnter three test scores : \"))\nt2 = int(raw_input(\"\"))\nt3 = int(raw_input(\"\"))\n\na1 = int(raw_input(\"\\nEnter three assignment scores : \"))\na2 = int(raw_input(\"\"))\na3 = int(raw_input(\"\"))\n\ntotal = big(t1,t2,t3) + big(a1,a2,a3)\n\nprint \"\\nTotal marks = \",total", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 3, Page Number: FNC-8", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 5, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\n------------------------------------\n x in degrees cos(x) \n------------------------------------\n\n\t 0 1.00\n\t 30 0.87\n\t 60 0.50\n\t 90 0.00\n\t 120 -0.50\n\t 150 -0.87\n\t 180 -1.00\n------------------------------------\n"}], "source": "import sys\n\ndef cosine(x):\n x = x * 3.14/180\n \n s = 0\n term = 1\n i = 0\n \n for k in range(1,15+1):\n s = s + term\n term = term*x*x*(-1)/((i+1)*(i+2))\n i = i + 2\n return s\n\nx = 0\nprint \"\\n------------------------------------\"\nprint \" x in degrees cos(x) \"\nprint \"------------------------------------\"\n\nwhile x <= 180:\n sys.stdout.write(\"\\n\\t%6.0f %6.2f\"%(x,cosine(x)))\n x = x + 30\n \nprint \"\\n------------------------------------\"", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 4, Page Number: FNC-9", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 6, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter three integers : 45\n"}, {"output_type": "stream", "name": "stdout", "text": "27\n"}, {"output_type": "stream", "name": "stdout", "text": "81\n"}, {"output_type": "stream", "name": "stdout", "text": "\nGreatest common divisor is 9\n\n\nPress any key to continue...\n"}], "source": "def gcd(x,y):\n if x >= y:\n nr = x\n dr = y\n else:\n nr = y\n dr = x\n r = nr % dr\n while r != 0:\n nr = dr\n dr = r\n r = nr % dr\n \n return dr\n\na = int(raw_input(\"\\nEnter three integers : \"))\nb = int(raw_input(\"\"))\nc = int(raw_input(\"\"))\n\nd1 = gcd(a,b)\nd2 = gcd(a,c)\nd3 = gcd(b,c)\n\nif d1 == d2:\n if d1 == d3:\n print \"\\nGreatest common divisor is \",d1\n else:\n print \"\\nGreatest common divisor is \",gcd(d1,d3)\nelse:\n print \"\\nGreatest common divisor is \",gcd(d1,d2)\n \nprint \"\\n\\nPress any key to continue...\"", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 5, Page Number: FNC-10", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 7, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter the integer : 2846\n"}, {"output_type": "stream", "name": "stdout", "text": "\n2846 is erversed as 6482\n\nPress any key to continue...\n"}], "source": "def reverse(n):\n rn = 0\n while n > 0:\n r = n % 10\n rn = rn * 10 + r\n n = n / 10\n return rn\n\nn = int(raw_input(\"\\nEnter the integer : \"))\n\nprint \"\\n\",n,\" is erversed as \",reverse(n)\nprint \"\\nPress any key to continue...\"", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 6, Page Number: FNC-11", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 9, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter the first string : MUMBAI\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the second string : MYSORE\n"}, {"output_type": "stream", "name": "stdout", "text": "\nThe result is -1\n"}], "source": "def compare(s1,s2):\n if s1 == s2:\n return 0\n if s1 > s2:\n return 1\n if s1 < s2:\n return -1\n \ns1 = raw_input(\"\\nEnter the first string : \")\ns2 = raw_input(\"\\nEnter the second string : \")\n\nprint \"\\nThe result is \",compare(s1,s2)", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 7, Page Number: FNC-13", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 12, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many values? 6\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter all values\n\n"}, {"output_type": "stream", "name": "stdout", "text": "3.1\n"}, {"output_type": "stream", "name": "stdout", "text": "3.8\n"}, {"output_type": "stream", "name": "stdout", "text": "3.6\n"}, {"output_type": "stream", "name": "stdout", "text": "4.0\n"}, {"output_type": "stream", "name": "stdout", "text": "3.4\n"}, {"output_type": "stream", "name": "stdout", "text": "3.8\n"}, {"output_type": "stream", "name": "stdout", "text": "\nArithmetic mean = 3.62"}], "source": "import sys\n\ndef amean(x,n):\n s = 0\n for i in range(0,n):\n s = s + x[i]\n return s/n\n\nn = int(raw_input(\"\\nHow many values? \"))\nprint \"\\nEnter all values\\n\"\n\nx = [0.0 for i in range(0,10)]\n\nfor i in range(0,n):\n x[i] = float(raw_input(\"\"))\n \nsys.stdout.write(\"\\nArithmetic mean = %6.2f\"%(amean(x,n)))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 8, Page Number: FNC-14", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 2, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many rows and columns : 3\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the matrix values\n\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "0\n"}, {"output_type": "stream", "name": "stdout", "text": "1\n"}, {"output_type": "stream", "name": "stdout", "text": "\nSum of all elements in the matrix = 12\n"}], "source": "def elem_sum(a,m,n):\n s = 0\n for i in xrange(m):\n for j in xrange(n):\n s = s + a[i][j]\n \n return s\n\nm = int(raw_input(\"\\nHow many rows and columns : \"))\nn = int(raw_input(\"\"))\n\na = [[0 for i in range(0,10)] for i in range(0,10)]\n\nprint \"\\nEnter the matrix values\\n\"\n\nfor i in range(0,m):\n for j in range(0,n):\n a[i][j] = int(raw_input(\"\"))\n\n\nprint \"\\nSum of all elements in the matrix = \",elem_sum(a,m,n)", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 9, Page Number: FNC-15", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 20, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter a string : NEW DELHI\n"}, {"output_type": "stream", "name": "stdout", "text": " \nNEW DELHI is reversed as IHLED WEN\n"}], "source": "def reverse(st):\n \n i = len(st) - 1\n rst = \"\"\n while i >= 0:\n rst = rst + st[i]\n i = i -1\n \n return rst\n\nst = raw_input(\"\\nEnter a string : \")\n\nprint \"\\n\",st,\" is reversed as \",reverse(st)", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 10, Page Number: FNC-16", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 21, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many numbers ? 10\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter all numbers in the list\n\n"}, {"output_type": "stream", "name": "stdout", "text": "-3\n"}, {"output_type": "stream", "name": "stdout", "text": "8\n"}, {"output_type": "stream", "name": "stdout", "text": "13\n"}, {"output_type": "stream", "name": "stdout", "text": "19\n"}, {"output_type": "stream", "name": "stdout", "text": "21\n"}, {"output_type": "stream", "name": "stdout", "text": "25\n"}, {"output_type": "stream", "name": "stdout", "text": "26\n"}, {"output_type": "stream", "name": "stdout", "text": "29\n"}, {"output_type": "stream", "name": "stdout", "text": "35\n"}, {"output_type": "stream", "name": "stdout", "text": "42\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the number to be searched : 19\n"}, {"output_type": "stream", "name": "stdout", "text": "\nThe number 19 is present in the list\n"}], "source": "def bi_search(x,n,s):\n flag = 0\n start = 0\n end = n\n \n while start < end and flag == 0:\n mid = (start+end)/2\n if x[mid] > s:\n end = mid\n else:\n if x[mid] < s:\n start = mid + 1\n else:\n flag = 1\n return flag\n\nn = int(raw_input(\"\\nHow many numbers ? \"))\n\nprint \"\\nEnter all numbers in the list\\n\"\n\nfor i in range(0,n):\n x[i] = int(raw_input(\"\"))\n \ns = int(raw_input(\"\\nEnter the number to be searched : \"))\n\nif bi_search(x,n,s):\n print \"\\nThe number \",s,\" is present in the list\"\nelse:\n print \"\\nThe number \",s,\" is not present in the list\"", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 11, Page Number: FNC-19", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 22, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter values to n and r : 5\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "\nValue of nCr = 10\n"}], "source": "def fact(k):\n if k == 1:\n return 1\n else:\n return k*fact(k-1)\n \nn = int(raw_input(\"\\nEnter values to n and r : \"))\nr = int(raw_input(\"\"))\n\nncr = fact(n)/(fact(r)*fact(n-r))\n\nprint \"\\nValue of nCr = \",ncr\n", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 12, Page Number: FNC-20", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 24, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter value to x : 4.2\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter its power : 3\n"}, {"output_type": "stream", "name": "stdout", "text": "\n 4.20 raise to 3 is 74.09"}], "source": "import sys\n\ndef power(x,n):\n if n == 1:\n return x\n else:\n return x*power(x,n-1)\n \nx = float(raw_input(\"\\nEnter value to x : \"))\nn = int(raw_input(\"\\nEnter its power : \"))\n\nsys.stdout.write(\"\\n%6.2f raise to %d is %6.2f\"%(x,n,power(x,n)))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 13, Page Number: FNC-21", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 4, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many terms to be printed ? 10\n"}, {"output_type": "stream", "name": "stdout", "text": "\nThe first 10 terms in Fibonacci series are\n\n 0 1 1 2 3 5 8 13 21 34"}], "source": "import sys\n\n\ndef fibo(t1,t2,count):\n if count >= n:\n return\n else:\n t3 = t1 + t2\n sys.stdout.write(\"%5d\"%(t3))\n count = count + 1\n t1 = t2\n t2 = t3\n fibo(t1,t2,count)\n \nn = int(raw_input(\"\\nHow many terms to be printed ? \"))\nt1 = 0\nt2 = 1\n\nprint \"\\nThe first \",n,\" terms in Fibonacci series are\\n\"\nsys.stdout.write(\"%5d %5d\"%(t1,t2))\n\ncount = 2\nfibo(t1,t2,count)", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 14, Page Number: FNC-28", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 3, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many rows and columns ?2\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter A matrix values\n\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "-2\n"}, {"output_type": "stream", "name": "stdout", "text": "0\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter B matrix values\n\n"}, {"output_type": "stream", "name": "stdout", "text": "6\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "-5\n"}, {"output_type": "stream", "name": "stdout", "text": "\nResultant matrix is \n\n 8 0\n 4 -1\n"}], "source": "import sys\n\ndef matadd():\n for i in xrange(m):\n for j in xrange(n):\n c[i][j] = a[i][j] + b[i][j]\n \nm = int(raw_input(\"\\nHow many rows and columns ?\"))\nn = int(raw_input(\"\"))\n\na = [[0 for i in range(0,10)]for i in range(0,10)]\nb = [[0 for i in range(0,10)]for i in range(0,10)]\nc = [[0 for i in range(0,10)]for i in range(0,10)]\n\n#Read matrices\nprint \"\\nEnter A matrix values\\n\"\nfor i in range(0,m):\n for j in range(0,n):\n a[i][j] = int(raw_input(\"\"))\n \nprint \"\\nEnter B matrix values\\n\"\nfor i in range(0,m):\n for j in range(0,n):\n b[i][j] = int(raw_input(\"\"))\n\nmatadd()\n\nprint \"\\nResultant matrix is \\n\"\nfor i in range(0,m):\n for j in range(0,n):\n sys.stdout.write(\"%5d\"%(c[i][j]))\n sys.stdout.write(\"\\n\")", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 15, Page Number: FNC-29", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 4, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nEnter order of A matrix (m x n) : 2\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter A matrix values\n\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "-2\n"}, {"output_type": "stream", "name": "stdout", "text": "0\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter order of B matrix (n x l) : 2\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter B matrix values\n\n"}, {"output_type": "stream", "name": "stdout", "text": "6\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "4\n"}, {"output_type": "stream", "name": "stdout", "text": "-5\n"}, {"output_type": "stream", "name": "stdout", "text": "\nResultant matrix is \n\n 4 14\n 16 -20\n"}], "source": "import sys\n\ndef matmul():\n for i in xrange(m):\n for j in xrange(l):\n c[i][j] = 0\n for k in xrange(n):\n c[i][j] = c[i][j] + a[i][k] * b[k][j]\n \nm = int(raw_input(\"\\nEnter order of A matrix (m x n) : \"))\nn = int(raw_input(\"\"))\n\n\na = [[0 for i in range(0,10)]for i in range(0,10)]\nb = [[0 for i in range(0,10)]for i in range(0,10)]\nc = [[0 for i in range(0,10)]for i in range(0,10)]\n\n#Read matrices\nprint \"\\nEnter A matrix values\\n\"\nfor i in range(0,m):\n for j in range(0,n):\n a[i][j] = int(raw_input(\"\"))\n\nn = int(raw_input(\"\\nEnter order of B matrix (n x l) : \"))\nl = int(raw_input(\"\"))\n\nprint \"\\nEnter B matrix values\\n\"\nfor i in range(0,n):\n for j in range(0,l):\n b[i][j] = int(raw_input(\"\"))\n\nmatmul()\n\nprint \"\\nResultant matrix is \\n\"\nfor i in range(0,m):\n for j in range(0,l):\n sys.stdout.write(\"%5d\"%(c[i][j]))\n sys.stdout.write(\"\\n\")", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 16, Page Number: FNC-31", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 5, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many rows and columns ?2\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the matrix values\n\n"}, {"output_type": "stream", "name": "stdout", "text": "-3\n"}, {"output_type": "stream", "name": "stdout", "text": "6\n"}, {"output_type": "stream", "name": "stdout", "text": "0\n"}, {"output_type": "stream", "name": "stdout", "text": "3\n"}, {"output_type": "stream", "name": "stdout", "text": "2\n"}, {"output_type": "stream", "name": "stdout", "text": "8\n"}, {"output_type": "stream", "name": "stdout", "text": "\nTranspose of the matrix is \n\n -3 3\n 6 2\n 0 8\n"}], "source": "import sys\n\nat = [[0,0],[0,0],[0,0]]\n\ndef transpose():\n for i in xrange(m):\n for j in xrange(n):\n at[j][i] = a[i][j] \n \nm = int(raw_input(\"\\nHow many rows and columns ?\"))\nn = int(raw_input(\"\"))\n\nprint \"\\nEnter the matrix values\\n\"\nfor i in range(0,m):\n for j in range(0,n):\n a[i][j] = int(raw_input(\"\"))\n\ntranspose()\n\nprint \"\\nTranspose of the matrix is \\n\"\nfor i in xrange(n):\n for j in xrange(m):\n sys.stdout.write(\"%5d\"%(at[i][j]))\n sys.stdout.write(\"\\n\")", "metadata": {"collapsed": false, "trusted": false}}, {"source": "## Example 17, Page Number: FNC-32", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 7, "outputs": [{"output_type": "stream", "name": "stdout", "text": "\nHow many numbers ? 4\n"}, {"output_type": "stream", "name": "stdout", "text": "\nEnter the list of values\n\n"}, {"output_type": "stream", "name": "stdout", "text": "32\n"}, {"output_type": "stream", "name": "stdout", "text": "-10\n"}, {"output_type": "stream", "name": "stdout", "text": "20\n"}, {"output_type": "stream", "name": "stdout", "text": "5\n"}, {"output_type": "stream", "name": "stdout", "text": "\nThe sorted list is\n\n -10 5 20 32"}], "source": "import sys\n\n\ndef sort():\n for i in xrange(n):\n for j in range(i+1,n):\n if x[i] > x[j]:\n temp = x[i]\n x[i] = x[j]\n x[j] = temp\n \nx = [0 for i in range(0,50)]\nn = int(raw_input(\"\\nHow many numbers ? \"))\nprint \"\\nEnter the list of values\\n\"\n\nfor i in range(0,n):\n x[i] = int(raw_input(\"\"))\n\nsort()\n\nprint \"\\nThe sorted list is\\n\"\n\nfor i in xrange(n):\n sys.stdout.write(\"%5d\"%(x[i]))", "metadata": {"collapsed": false, "trusted": false}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": "", "metadata": {"collapsed": false, "trusted": false}}], "nbformat_minor": 0} \ No newline at end of file
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits/screenshots/CE_CB_Configuration_ch-2.png b/A_Textbook_Of_Electronic_Devices_And_Circuits/screenshots/CE_CB_Configuration_ch-2.png
new file mode 100755
index 00000000..b97beae2
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits/screenshots/CE_CB_Configuration_ch-2.png
Binary files differ
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits/screenshots/dc_load_line_Chapter-2.png b/A_Textbook_Of_Electronic_Devices_And_Circuits/screenshots/dc_load_line_Chapter-2.png
new file mode 100755
index 00000000..d09c7848
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits/screenshots/dc_load_line_Chapter-2.png
Binary files differ
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits/screenshots/gm_vs_IDSS_ch-6.png b/A_Textbook_Of_Electronic_Devices_And_Circuits/screenshots/gm_vs_IDSS_ch-6.png
new file mode 100755
index 00000000..da93e3dd
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits/screenshots/gm_vs_IDSS_ch-6.png
Binary files differ
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter1.ipynb b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter1.ipynb
new file mode 100755
index 00000000..1d7aa613
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter1.ipynb
@@ -0,0 +1,655 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter1 - Special diodes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1, page 9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division \n",
+ "from numpy import exp\n",
+ "#Given data\n",
+ "I=40 #in mA\n",
+ "V=0.25 #in Volt\n",
+ "T=20 #in degree C\n",
+ "T=T+273 #in Kelvin\n",
+ "ETA=1 #For Ge\n",
+ "e=1.6*10**-19 #in Coulamb(electronic charge)\n",
+ "k=1.38*10**-23 #in J/K(Boltzman Constant)\n",
+ "#Formula : I=Io*(exp(%e*V/(ETA*k*T))-1)\n",
+ "y=(e*V/(ETA*k*T)) #Assumed\n",
+ "y=round(y)\n",
+ "Io=I*10**-3/(exp(y)-1) #in mA\n",
+ "print \"Reverse saturation current =\",round(Io*10**6,2),\" micro Ampere\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reverse saturation current = 1.82 micro Ampere\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.2, page 9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import log\n",
+ "#Given data\n",
+ "Io=10 #in uA\n",
+ "I=1 #in Ampere\n",
+ "ETA=2 #For Si\n",
+ "T=27 #in degree C\n",
+ "T=T+273 #in Kelvin\n",
+ "e=1.6*10**-19 #in Coulamb(electronic charge)\n",
+ "k=1.38*10**-23 #in J/K(Boltzman Constant)\n",
+ "#Formula : I=Io*(exp(%e*V/(ETA*k*T))-1)\n",
+ "V=(ETA*k*T/e)*log(I/(Io*10**-6)+1) #in Volt\n",
+ "print \"Forward Voltage across the diode =\",round(V,3),\" Volt\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Forward Voltage across the diode = 0.596 Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.3, page 22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi\n",
+ "#Given data\n",
+ "RL=1 #in kOhm\n",
+ "#rf<<RL\n",
+ "Vrms=200 #in Volt\n",
+ "#Part (i)\n",
+ "Vo=Vrms*sqrt(2) #in Volt\n",
+ "Idc=Vo/(RL*10**3*pi) #in Ampere\n",
+ "print \"DC current in load =\",round(Idc*10**3),\"mA\" \n",
+ "#Part (ii)\n",
+ "Vdc=RL*10**3*Idc #in Volt\n",
+ "print \"DC voltage across load =\",round(Vdc),\"Volt\"\n",
+ "#Part (iii)\n",
+ "#Gamma=sqrt((Irms/Idc)**2-1)=sqrt((Io/2)/(Io/pi)-1)=sqrt((pi/2)**2-1)\n",
+ "Gamma=sqrt((pi/2)**2-1) #unitless\n",
+ "print \"Ripple factor =\",round(Gamma,2)\n",
+ "#Part (iv)\n",
+ "PIV=Vrms*sqrt(2) #in volt\n",
+ "print \"Peak Inverse Voltage = %d Volt\" %PIV"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "DC current in load = 90.0 mA\n",
+ "DC voltage across load = 90.0 Volt\n",
+ "Ripple factor = 1.21\n",
+ "Peak Inverse Voltage = 282 Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.4, page 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi\n",
+ "#Given data\n",
+ "rf=20 #in ohm\n",
+ "RL=980 #in Ohm\n",
+ "Vrms=50 #in Volt\n",
+ "Vo=Vrms*sqrt(2) #in Volt\n",
+ "Io=Vo/(RL+rf) #in Ampere\n",
+ "#Part (i)\n",
+ "Idc=2*Io/pi #in Ampere\n",
+ "print \"Average DC current = %0.f mA\" %round(Idc*10**3)\n",
+ "#Part (ii)\n",
+ "Irms=Io/sqrt(2) #in Ampere\n",
+ "print \"rms value of load current = %0.f mA\" %(Irms*1000)\n",
+ "#Part (iii)\n",
+ "Vdc=RL*Idc #in Volt\n",
+ "print \"DC output voltage = %0.1f Volt\" %Vdc\n",
+ "#Part (iv)\n",
+ "ETA=(Idc**2*RL/(Irms**2*(RL+rf)))*100 #Rectification Efficiency in %\n",
+ "print \"Rectification Efficiency is \",round(ETA,1),\" %\"\n",
+ "#Part (v)\n",
+ "PIV=2*Vo #in volt\n",
+ "print \"Peak Inverse Voltage = %0.1f Volt\" %PIV"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average DC current = 45 mA\n",
+ "rms value of load current = 50 mA\n",
+ "DC output voltage = 44.1 Volt\n",
+ "Rectification Efficiency is 79.4 %\n",
+ "Peak Inverse Voltage = 141.4 Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.5, page 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "Vin=40 #in volt\n",
+ "VZ=10 #in volt\n",
+ "Vo=10 #in volt\n",
+ "IZmax=50 #in mA\n",
+ "IL=0 #in mA\n",
+ "#Formula : I=IZ+IL=IZmax+0\n",
+ "I=IZmax+0 #in mA\n",
+ "#Formula : VZ=Vin-R*I\n",
+ "Rmin=(Vin-VZ)/(I*10**-3) #in Ohm\n",
+ "print \"Minimum value of resistance =\",Rmin,\"Ohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Minimum value of resistance = 600.0 Ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.6, page 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "Vmin=15 #Minimum input voltage in volt\n",
+ "VZ=6.8 #Voltage across zener in volt\n",
+ "Vo=VZ #output voltage in volt\n",
+ "Vsr1=Vmin-Vo #Voltage aross series resistance in volt\n",
+ "print \"If R is the series esistance, Total current in series resistance in Ampere : I=Vsr/R=8.2/R \"\n",
+ "ILmin=5 #in mA\n",
+ "print \"current in zener diode in Ampere :IZ=I-IL=(8.2/R-IL*10-3) eqn(1)\"\n",
+ "Vmax=20 #mximum output voltage\n",
+ "Vo=VZ #output voltage in volt\n",
+ "Vsr2=Vmax-Vo #Voltage aross series resistance in volt\n",
+ "print \"Current in series resistance circuit in Ampere : I=Vsr/R\"\n",
+ "ILmax=15 #in mA\n",
+ "print \"current in zener diode in Ampere :IZ=I-IL=(Rs/R-IL*10-3) eqn(2)\"\n",
+ "print \"For Zener diode to work as voltage regulator,(1) and (2) must be same.\"\n",
+ "print \"(8.2/R-IL*10-3)=(13.2/R-IL*10-3)\"\n",
+ "R=(Vsr2-Vsr1)/(ILmax*10**-3-ILmin*10**-3) #in Ohm\n",
+ "print \"Required value of Series Resistor =\",R,\"ohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "If R is the series esistance, Total current in series resistance in Ampere : I=Vsr/R=8.2/R \n",
+ "current in zener diode in Ampere :IZ=I-IL=(8.2/R-IL*10-3) eqn(1)\n",
+ "Current in series resistance circuit in Ampere : I=Vsr/R\n",
+ "current in zener diode in Ampere :IZ=I-IL=(Rs/R-IL*10-3) eqn(2)\n",
+ "For Zener diode to work as voltage regulator,(1) and (2) must be same.\n",
+ "(8.2/R-IL*10-3)=(13.2/R-IL*10-3)\n",
+ "Required value of Series Resistor = 500.0 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.7, page 27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "Vin=18 #in volt\n",
+ "IZ=20 #in mA\n",
+ "ILav=(5+35)/2 #in mA\n",
+ "VZ=12 #in volt\n",
+ "Vo=12 #in volt\n",
+ "I=IZ+ILav #in mA\n",
+ "R=(Vin-Vo)/(I*10**-3) #in Ohm\n",
+ "print \"Current limiting resistance =\",R,\"Ohm\"\n",
+ "P=(I*10**-3)**2*R #in Watts\n",
+ "print \"Power disspation in resistance =\",P,\"Watt\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current limiting resistance = 150.0 Ohm\n",
+ "Power disspation in resistance = 0.24 Watt\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.8, page 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "R=1 #in kOhm\n",
+ "RL=5 #in kOhm\n",
+ "VZ=10 #in volt\n",
+ "Vo=10 #in volt\n",
+ "P=250 #in mW\n",
+ "IL=Vo/RL #in mA\n",
+ "IZmin=0 #in mA\n",
+ "IZmax=P/VZ #in mA\n",
+ "Imin=IZmin+IL #in mA\n",
+ "Imax=IZmax+IL #in mA\n",
+ "Vin_min=VZ+Imin*10**-3*R*10**3 #in volt\n",
+ "Vin_max=VZ+Imax*10**-3*R*10**3 #in volt\n",
+ "print \"The input voltage ranges from \",Vin_min,\"V to \",Vin_max,\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The input voltage ranges from 12.0 V to 37.0 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.9, page 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "R=5 #in kOhm\n",
+ "R=R*1000 #in Ohm\n",
+ "RL=10 #in kOhm\n",
+ "RL=RL*1000 #in Ohm\n",
+ "Vin=120 #in Volt\n",
+ "VZ=50 #in Volt\n",
+ "#Part (i)\n",
+ "Vo=VZ #in Volt\n",
+ "print \"Output voltage =\",Vo,\" Volt\"\n",
+ "#Part (ii)\n",
+ "VR=Vin-VZ #in Volt\n",
+ "print \"Voltage drop across series resistance =\",VR,\"Volt\"\n",
+ "#Part (iii)\n",
+ "IL=Vo/RL #in Ampere\n",
+ "print \"Load Current =\",IL*1000,\"mA\"\n",
+ "I=VR/R #in Ampere\n",
+ "print \"Current through resistance R =\",I*1000,\"mA\"\n",
+ "IZ=I-IL #in Ampere\n",
+ "print \"Load Current =\",IZ*1000,\"mA\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output voltage = 50 Volt\n",
+ "Voltage drop across series resistance = 70 Volt\n",
+ "Load Current = 5.0 mA\n",
+ "Current through resistance R = 14.0 mA\n",
+ "Load Current = 9.0 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.10, page 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "VDmin=1.5 #in Volt\n",
+ "VDmax=2.3 #in Volt\n",
+ "VS=5 #in Volt\n",
+ "RS=270 #in Ohm\n",
+ "Imin=(VS-VDmax)/RS #in Ampere\n",
+ "print \"Minimum value of LED current = %0.f mA\" %(Imin*1000) \n",
+ "Imax=(VS-VDmin)/RS #in Ampere\n",
+ "print \"Maximum value of LED current = %0.f mA \" %(round(Imax*1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Minimum value of LED current = 10 mA\n",
+ "Maximum value of LED current = 13 mA \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.11, page 32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi\n",
+ "#Given data\n",
+ "C1min=10 #in pF\n",
+ "C2max=50 #in pF\n",
+ "L=5 #in mH\n",
+ "L=L*10**-3 #in H\n",
+ "#Formula : CT=C1*C2/(C1+C2)\n",
+ "#Minimum\n",
+ "C1=10 #in pF\n",
+ "C2=10 #in pF\n",
+ "CTmin=C1*C2/(C1+C2) #in pF\n",
+ "CTmin=CTmin*10**-12 #in F\n",
+ "#Maximum\n",
+ "C1=50 #in pF\n",
+ "C2=50 #in pF\n",
+ "CTmax=C1*C2/(C1+C2) #in pF\n",
+ "CTmax=CTmax*10**-12 #in F\n",
+ "#Formula : f=1/(2*pi*sqrt(L*C))\n",
+ "#maximum :\n",
+ "fmax=1/(2*pi*sqrt(L*CTmin)) \n",
+ "#minimum :\n",
+ "fmin=1/(2*pi*sqrt(L*CTmax)) \n",
+ "print \"The frequency of tuning circuit ranges from \",round(fmin/10**6,2),\"MHz to \",round(fmax/10**6,1),\"MHz.\"\n",
+ "#Note : Answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The frequency of tuning circuit ranges from 0.45 MHz to 1.0 MHz.\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.12, page 33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given data\n",
+ "C1=21 #in pF\n",
+ "V1=4 #in volt\n",
+ "V2=9 #in volt\n",
+ "#C2/C1=sqrt(V1/V2)\" \n",
+ "C2=sqrt(V1/V2)*C1 #in pF\n",
+ "print \"At reverse bias 9V, Diode capacitance =\",C2,\" pF\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "At reverse bias 9V, Diode capacitance = 14.0 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.13, page 39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "R=0.90 #in A/W\n",
+ "Pop=1 #in mW\n",
+ "#Part (i)\n",
+ "IP=R*Pop #in mA\n",
+ "print \"Power of incident light = %0.f mW, Photocurrent is %0.2f mA\" %(Pop,IP)\n",
+ "#Part (ii)\n",
+ "print \"Here IP is not proportional to Pop(for Pop>1.5mW)\"\n",
+ "print \"Hence Photourrent can not be calculated.\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Power of incident light = 1 mW, Photocurrent is 0.90 mA\n",
+ "Here IP is not proportional to Pop(for Pop>1.5mW)\n",
+ "Hence Photourrent can not be calculated.\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.14, page 39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "ETA=70 #in %\n",
+ "Eg=0.75 #in eV\n",
+ "Eg=Eg*1.6*10**-19 #in Joule\n",
+ "h=6.63*10**-34 #Planks constant in J-s\n",
+ "c=3*10**8 #speed of light in m/s\n",
+ "e=1.6*10**-19 #in coulamb\n",
+ "lamda=h*c/Eg #in meter\n",
+ "print \"Wavelength =\",lamda*10**9,\" nm\"\n",
+ "R=(ETA/100)*e*lamda/(h*c) #in A/W\n",
+ "print \"Responsivity of InGaAs photodiode =\",round(R,3),\" A/W\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavelength = 1657.5 nm\n",
+ "Responsivity of InGaAs photodiode = 0.933 A/W\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.15, page 41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "W1=2.5 #in eV\n",
+ "W2=1.9 #in eV\n",
+ "ContactPotential=W1-W2 #in Volt\n",
+ "print \"Contact potential =\",ContactPotential,\"Volts\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Contact potential = 0.6 Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter11.ipynb b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter11.ipynb
new file mode 100755
index 00000000..f804a94c
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter11.ipynb
@@ -0,0 +1,59 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter11 - Multivibrators"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 11.1, page 323"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "R1=15 #in kohm\n",
+ "R2=15 #in kohm\n",
+ "C1=0.005 #in uF\n",
+ "C2=0.005 #in uF\n",
+ "R=R1 #in Kohm\n",
+ "C=C1 #in uF\n",
+ "T=0.69*(R*10**3*C*10**-6+R*10**3*C*10**-6) #in second\n",
+ "f=1/T #in Hz\n",
+ "print \"Frequency of oscillators = %0.2f kHz\" %(f*10**-3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frequency of oscillators = 9.66 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter2.ipynb b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter2.ipynb
new file mode 100755
index 00000000..2912a3a1
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter2.ipynb
@@ -0,0 +1,774 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter2 - Bipolar junction transistors(BJTs)"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.1, page 63"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from fractions import Fraction\n",
+ "#Given data\n",
+ "deltaIB=50 #in uA\n",
+ "deltaIC=1 #in mA\n",
+ "deltaIC=deltaIC*10**3 #in uA\n",
+ "Beta=deltaIC/deltaIB #unitless\n",
+ "print \"Current Amplification Factor, Beta =\",Beta \n",
+ "Alfa=Beta/(1+Beta) #unittless\n",
+ "print \"Current Amplification Factor, Alfa =\",Fraction(Alfa).limit_denominator()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current Amplification Factor, Beta = 20.0\n",
+ "Current Amplification Factor, Alfa = 20/21\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.2, page 63"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "IB=25 #in uA\n",
+ "Beta=40 #unitless\n",
+ "IC=Beta*IB #in uA\n",
+ "IE=IB+IC #in uA\n",
+ "print \"The value of IE =\",IE,\" micro Ampere\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of IE = 1025 micro Ampere\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.3, page 63"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "alfa=0.98 #unitless\n",
+ "deltaIB=0.2 #in mA\n",
+ "Beta=alfa/(1-alfa) #unitless\n",
+ "deltaIC=Beta*deltaIB #in mA\n",
+ "print \"Change in collector curent =\",deltaIC,\" milli Ampere.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Change in collector curent = 9.8 milli Ampere.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.4, page 64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "Beta=45 #unitless\n",
+ "RL=1 #in kOhm\n",
+ "deltaVCE=1 #in volt\n",
+ "print \"Part (i) : CE coniguration\"\n",
+ "IC=deltaVCE/(RL*1000) #in Ampere\n",
+ "#Formula : Beta=deltaIC/deltaIB\n",
+ "IB=IC/Beta #in Ampere\n",
+ "print \"Input Base Current, IB =\",round(IB*10**3,3),\" mA\" \n",
+ "print \"Part (ii) : CB coniguration\"\n",
+ "IC=deltaVCE/(RL*1000) #in Ampere\n",
+ "#Formula : Beta=deltaIC/deltaIB\n",
+ "IE=IB+IC #in Ampere\n",
+ "print \"Input Emitter Current, IE =\",round(IE*10**3,3),\" mA\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Part (i) : CE coniguration\n",
+ "Input Base Current, IB = 0.022 mA\n",
+ "Part (ii) : CB coniguration\n",
+ "Input Emitter Current, IE = 1.022 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.5, page 64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "Ileakage=12.5 #in uA\n",
+ "ICBO=12.5 #in uA\n",
+ "IE=2 #in mA\n",
+ "IC=1.97 #in mA\n",
+ "#Formula : IC=alfa*IE+ICBO\n",
+ "alfa=(IC-ICBO/10**3)/IE #unitless\n",
+ "print \"Current Gain =\",round(alfa,3)\n",
+ "IB=IE-IC #in mA\n",
+ "print \"Base current =\",IB,\" mA\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current Gain = 0.979\n",
+ "Base current = 0.03 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.6, page 64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "deltaVBE=200 #in mVolt\n",
+ "deltaIB=100 #in uA\n",
+ "ri=deltaVBE*10**-3/(deltaIB*10**-6) #in Ohm\n",
+ "print \"Input resistane of transistor =\",ri/1000,\" kohm\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input resistane of transistor = 2.0 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.7, page 64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "deltaVEB=200 #in mVolt\n",
+ "deltaIE=5 #in mA\n",
+ "ri=deltaVEB*10**-3/(deltaIE*10**-3) #in Ohm\n",
+ "print \"Input resistane of transistor =\",ri,\"Ohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input resistane of transistor = 40.0 Ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.9, page 72"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "Ri=500 #in Ohm\n",
+ "RL=1 #in kOhm\n",
+ "hie=1 #in kOhm\n",
+ "hre=2*10**-4 #unitless\n",
+ "hfe=50 #unitless\n",
+ "hoe=25 #micro mho\n",
+ "#Part (a) :\n",
+ "Ai=-hfe/(1+hoe*10**-6*RL*10**3) #unitless\n",
+ "print \"Current Gain = \",round(Ai,1) \n",
+ "#Part (b) :\n",
+ "Rin=hie*10**3-(hre*hfe/(hoe*10**-6+1/RL*10**3)) #in Ohm\n",
+ "print \"Input Resistance =\",round(Rin,2),\" Ohm\"\n",
+ "#Part (c) :\n",
+ "Av=Ai*RL*10**3/Ri #unitless\n",
+ "print \"Voltage Gain =\",round(Av,1) \n",
+ "# Calculation error in the book hence answer wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current Gain = -48.8\n",
+ "Input Resistance = 1000.0 Ohm\n",
+ "Voltage Gain = -97.6\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.10. page 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log\n",
+ "#Given data\n",
+ "alfaF=0.99 #unitless\n",
+ "alfaR=0.20 #unitless\n",
+ "IC=1 #in mA\n",
+ "IB=50 #in micro Ampere\n",
+ "T=300 #in kelvin\n",
+ "k=1.38*10**-23 #Boltzman constant\n",
+ "e=1.6*10**-19 #in cooulamb\n",
+ "Vth=k*T/e #in Volt\n",
+ "VCEsat=Vth*log(((IC*10**-3*(1-alfaR)+IB*10**-6)*alfaF)/((alfaF*IB*10**-6-(1-alfaF)*IC*10**-3)*alfaR)) #in volt\n",
+ "print \"Collector-Emitter saturation voltage =\",round(VCEsat,3),\" Volt\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector-Emitter saturation voltage = 0.121 Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.11, page 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "IES=10**-14 #in A\n",
+ "alfaF=1.0 #unitless\n",
+ "alfaR=0.1 #unitless\n",
+ "#Formula : alfaF*IES=alfaR*ICS\n",
+ "ICS=(alfaF/alfaR)*IES #in Ampere\n",
+ "print \"Collector base junction saturation current =\",ICS,\"Ampere\"\n",
+ "RelativeSize=ICS/IES #unitless\n",
+ "print \"Collector is \",RelativeSize,\" times larger in size than emitter.\"\n",
+ "BetaR=alfaR/(1-alfaR) #unitless\n",
+ "print \"Value of BetaR = \",round(BetaR,2) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector base junction saturation current = 1e-13 Ampere\n",
+ "Collector is 10.0 times larger in size than emitter.\n",
+ "Value of BetaR = 0.11\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.12, page 87"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "%matplotlib inline\n",
+ "import matplotlib.pylab as plt\n",
+ "import numpy as np\n",
+ "# Given Data \n",
+ "from __future__ import division\n",
+ "#Given data\n",
+ "Beta=100 #unitless\n",
+ "VCC=6 #in volt\n",
+ "RB=530 #in kOhm\n",
+ "RC=2 #in kOhm\n",
+ "VBE=0.7 #in volt(For Si)\n",
+ "#Part (i)\n",
+ "IC1=0 #in A\n",
+ "VCE1=VCC-IC1*RC #in volt\n",
+ "#If VCE=0 #in volt\n",
+ "VCE2=0 #in volt\n",
+ "IC2=VCC/RC #in Ampere\n",
+ "#Formula : VCC=VBE+IB*RB\n",
+ "IB=(VCC-VBE)/(RB*10**3) #in Ampere\n",
+ "IC=Beta*IB #in Ampere\n",
+ "VCE=VCC-IC*RC*10**3 #in volt\n",
+ "print \"Q point coordinates are :\"\n",
+ "print \"IC=\",IC*10**3,\" mA and VCE=\",VCE,\" Volt.\"\n",
+ "plt.plot([VCE1,IC1],[VCE2,IC2])\n",
+ "plt.xlabel('Time')\n",
+ "plt.ylabel('Voltage')\n",
+ "plt.title('DC load line')\n",
+ "plt.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Q point coordinates are :\n",
+ "IC= 1.0 mA and VCE= 4.0 Volt.\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x7fe5272b9490>"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.13, page 88"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "Beta=100 #unitless\n",
+ "IC=1 #in mA\n",
+ "VCC=12 #in volt\n",
+ "VBE=0.3 #in volt(For Ge)\n",
+ "#Prt (i)\n",
+ "IB=IC/Beta #in mA\n",
+ "#Formula : VCC=VBE+IB*RB\n",
+ "RB=(VCC-VBE)/(IB*10**-3) #in Ampere\n",
+ "print \"Resistance RB =\",RB/10**3,\" kOhm\" \n",
+ "#part (ii)\n",
+ "Beta=50 #unitless\n",
+ "IB=(VCC-VBE)/RB #in Ampere\n",
+ "IC=Beta*IB #in Ampere\n",
+ "print \"Zero signal IC =\",IC*10**3,\"mA\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance RB = 1170.0 kOhm\n",
+ "Zero signal IC = 0.5 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.14, page 88"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import array\n",
+ "#Given data :\n",
+ "print \"To set the required operating point, value of RB will be find out. \"\n",
+ "IC=1 #in mA\n",
+ "VCE=8 #in volt\n",
+ "Beta=100 #unitless\n",
+ "VCC=12 #in volt\n",
+ "VBE=0.3 #in volt(For Ge)\n",
+ "#Prt (i)\n",
+ "RC=(VCC-VCE)/(IC*10**-3) #in ohm\n",
+ "IB=IC/Beta #in mA\n",
+ "RB=(VCC-VBE-Beta*(IB*10**-3)*RC)/(IB*10**-3) #in Ohm\n",
+ "print \"Value of RB =\",RB/1000,\"kOhm\" \n",
+ "#Part (ii)\n",
+ "Beta=50 #unitless\n",
+ "IB=(VCC-VBE)/(RB+Beta*RC) #in mA\n",
+ "IC=Beta*IB #in Ampere\n",
+ "VCE=VCC-IC*RC #in volt\n",
+ "print \"New operating point is (\",round(VCE,1),\"V,\",round(IC*10**3,1),\"mA)\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "To set the required operating point, value of RB will be find out. \n",
+ "Value of RB = 770.0 kOhm\n",
+ "New operating point is ( 9.6 V, 0.6 mA)\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.15, page 93"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "R1=50 #in kohm\n",
+ "R2=10 #in kohm\n",
+ "RE=1 #in kohm\n",
+ "VCC=12 #in volt\n",
+ "#Part (i)\n",
+ "VBE=0.1 #in volt\n",
+ "VBBdash=(R2/(R1+R2))*VCC #in volt\n",
+ "IC1=(VBBdash-VBE)/(RE*1000) #in mA\n",
+ "print \"At VBE=0.1V, Value of IC = %0.1f mA\" %(IC1*1000)\n",
+ "#Part (ii)\n",
+ "VBE=0.3 #in volt\n",
+ "IC2=(VBBdash-VBE)/(RE*1000) #in mA\n",
+ "print \"At VBE=0.3V, Value of IC = %0.1f mA\" %(IC2*1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "At VBE=0.1V, Value of IC = 1.9 mA\n",
+ "At VBE=0.3V, Value of IC = 1.7 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 52
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.16, page 94"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "R1=10 #in kohm\n",
+ "R2=5 #in kohm\n",
+ "RE=2 #in kohm\n",
+ "RC=1 #in kohm\n",
+ "VCC=12 #in volt\n",
+ "Beta=100 #unitless\n",
+ "VBE=0.7 #in volt\n",
+ "#Part (i)\n",
+ "#Formula : VBE=VBBdash-IB*RBdash-IE*RE\n",
+ "print \"IB is very small : VBE=VBBdash-IE*RE\"\n",
+ "VBBdash=(R2/(R1+R2))*VCC #in volt\n",
+ "IE=(VBBdash-VBE)/(RE*10**3) #in Ampere\n",
+ "print \"As base current is very small IC=IE\"\n",
+ "IC=IE #in mA\n",
+ "#Formul : VCC=IC*RC+VCE+IE*RE\n",
+ "VCE=VCC-IC*RC*10**3-IE*RE*10**3 #in Volt\n",
+ "print \"Operating point is (\",VCE,\"V,\",IC*10**3,\"mA)\" \n",
+ "#Part (ii)\n",
+ "RBdash=(R1*R2/(R1+R2)) #in kOhm\n",
+ "S=(Beta+1)/(1+Beta*(RE/(RBdash+RE))) \n",
+ "print \"Staility factor S =\",round(S,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "IB is very small : VBE=VBBdash-IE*RE\n",
+ "As base current is very small IC=IE\n",
+ "Operating point is ( 7.05 V, 1.65 mA)\n",
+ "Staility factor S = 2.62\n"
+ ]
+ }
+ ],
+ "prompt_number": 56
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.17, page 97"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "R1=200 #in kohm\n",
+ "R2=100 #in kohm\n",
+ "RE=1 #in kohm\n",
+ "RC=1 #in kohm\n",
+ "VCC=9 #in volt\n",
+ "he=2 #in kohm\n",
+ "hfe=100 #unitless\n",
+ "hoe=0 #unitless\n",
+ "hre=0 #unitless\n",
+ "VBE=0.7 #in volt(For Si)\n",
+ "#Part (i)\n",
+ "RB=R1*R2/(R1+R2) #in kohm\n",
+ "VBBdash=(R2/(R1+R2))*VCC #in volt\n",
+ "#Applying Kirchoff Law \n",
+ "IB=(VBBdash-VBE)/(RB*10**3+RE*10**3*(1+hfe)) #in Ampere\n",
+ "IC=hfe*IB #in Ampere\n",
+ "print \"Value of IC = %0.2f mA\" %(IC*10**3)\n",
+ "#Part (ii)\n",
+ "#Applying Kirchoff Law \n",
+ "VCE=VCC-IC*RC*10**3-RE*1063*IB*(hfe+1) #in volt\n",
+ "print \"VCE = %0.1f Volt\" %(VCE,)\n",
+ "#Note : Ans of VCE is wrong in the book as VCC=10 V has been taken instead of 9 volt."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of IC = 1.37 mA\n",
+ "VCE = 6.2 Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 58
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.18, page 99"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "RB=50 #in kohm\n",
+ "RC=3 #in kohm\n",
+ "VCC=10 #in volt\n",
+ "VEE=5 #in volt\n",
+ "hfe=100 #unitless\n",
+ "VCEsat=0.2 #in volt\n",
+ "VBEsat=0.8 #in volt\n",
+ "VBEactive=0.7 #in volt\n",
+ "VBE=0.7 #in volt(For Si)\n",
+ "#Applying \n",
+ "IB=(VEE-VBE)/(RB*10**3) #in Ampere: Kirchoff 2nd Law : VEE-RB*IB-VBE=0\n",
+ "IC=hfe*IB #in Ampere \n",
+ "VCB=VCC-IC*RC*10**3-VBEactive #in volt: #Applying Kirchoff 2nd Law to collector-emitter loop: VCC-IC*RC-VCB-VBEactive=0\n",
+ "print \"Collector to base voltage, VCB = %0.1f V\" %VCB\n",
+ "print \"This shows that the base collector junction is forward biased. This implies that the transistor is in saturation region.\"\n",
+ "IB=(VEE-VBEsat)/(RB*10**3) #in Ampere\n",
+ "print \"Value of IB = %0.3f mA\" %(IB*10**3)\n",
+ "IC=(VCC-VCEsat)/(RC*10**3) \n",
+ "print \"Value of IC = %0.2f mA\" %(IC*10**3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector to base voltage, VCB = -16.5 V\n",
+ "This shows that the base collector junction is forward biased. This implies that the transistor is in saturation region.\n",
+ "Value of IB = 0.084 mA\n",
+ "Value of IC = 3.27 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 61
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.19, page 100"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "VCC=20 #in volt\n",
+ "VBE=0.7 #in volt(For Si)\n",
+ "Beta=50 #unitless\n",
+ "RE=200 #in ohm\n",
+ "R1=60 #in kohm\n",
+ "R2=30 #in kohm\n",
+ "V2=VCC*R2/(R1+R2) #in volt\n",
+ "VEO=V2-VBE #in volt\n",
+ "print \"Voltage across RE = %0.2f Volt\" %VEO"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage across RE = 5.97 Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 62
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter3.ipynb b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter3.ipynb
new file mode 100755
index 00000000..90f9fcf9
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter3.ipynb
@@ -0,0 +1,615 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter3 - Transistor amplifiers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.1, page 117"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "ib=10 #in uA\n",
+ "ic=1 #in mA\n",
+ "ic=ic*10**3 #in uA\n",
+ "vi=0.02 #in Volt\n",
+ "RC=5 #in kohm\n",
+ "RL=10 #in kohm\n",
+ "#Part (i)\n",
+ "Ai=-ic/ib #unitless\n",
+ "Beta=Ai #unitless\n",
+ "print \"Current gain =\",Ai\n",
+ "#Part (ii)\n",
+ "Rie=vi/(ib*10**-6) #in Ohm\n",
+ "print \"Input impedence = %0.1f kohm\" %(Rie*10**-3,)\n",
+ "#Part (iii)\n",
+ "Rac=RC*RL/(RC+RL) #in kohm\n",
+ "print \"AC load = %0.1f kohm\" %Rac\n",
+ "#Part (iv)\n",
+ "Av=-Rac*10**3*Beta/Rie #unitless\n",
+ "print \"Voltage gain = %0.1f \" %(Av) \n",
+ "#Part (v)\n",
+ "PowerGain=Av*Ai #unitless\n",
+ "print \"Power Gain =\",round(PowerGain,2) \n",
+ "#Note : Ans of Av and Power gain is wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = -100.0\n",
+ "Input impedence = 2.0 kohm\n",
+ "AC load = 3.3 kohm\n",
+ "Voltage gain = 166.7 \n",
+ "Power Gain = -16666.67\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.2, page 125"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "RL=10.0 #in kohm\n",
+ "RS=1.0 #in kohm\n",
+ "hie=1.1 #in kOhm\n",
+ "hre=2.5*10**-4 #unitless\n",
+ "hfe=50.0 #unitless\n",
+ "hoe=25.0 #in u mho\n",
+ "Aie=-hfe/(1+hoe*10**-6*RL*10**3) #unitless\n",
+ "Zie=hie+hre*Aie*RL #in kOhm\n",
+ "Zie=round(Zie) \n",
+ "Ave=Aie*RL/Zie #unitless\n",
+ "Avs_e=Ave*Zie/(Zie+RS) #\n",
+ "deltah=hoe*10**-6*hie*10**3-hfe*hre \n",
+ "Zoe=(hie*10**3+RS*10**3)/(hoe*10**-6*RS*10**3+deltah) \n",
+ "Ais_e=Aie*RS/(Zie+RS) \n",
+ "Ape=Ave*Aie \n",
+ "Aps_e=Avs_e*Ais_e \n",
+ "print \"Current gain : \",Aie\n",
+ "print \"Current gain with source resistance : \",Ais_e\n",
+ "print \"Voltage gain : \",Ave,\n",
+ "print \"Voltage gain with source resistance : \",Avs_e\n",
+ "print \"Power gain : \",Ape\n",
+ "print \"Power gain with source resistance : \",Aps_e\n",
+ "print \"Input impedence = %0.2f kohm :\"%Zie\n",
+ "print \"Output impedence = %0.2f kohm\" %(Zoe/10**3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain : -40.0\n",
+ "Current gain with source resistance : -20.0\n",
+ "Voltage gain : -400.0 Voltage gain with source resistance : -200.0\n",
+ "Power gain : 16000.0\n",
+ "Power gain with source resistance : 4000.0\n",
+ "Input impedence = 1.00 kohm :\n",
+ "Output impedence = 52.50 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.3, page 126"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "InputVoltage=1 #in mV\n",
+ "RL=5.6 #in kohm\n",
+ "RS=600 #in ohm\n",
+ "hre=6.5*10**-4 #unitless\n",
+ "hie=1.7 #in kOhm\n",
+ "hfe=125 #unitless\n",
+ "hoe=80 #in uA/V\n",
+ "deltah=hoe*10**-6*hie*10**3-hfe*hre \n",
+ "Zie=(hie*10**3+RL*10**3*deltah)/(1+hoe*10**-6*RL*10**3) #in Ohm\n",
+ "Zoe=(hie*10**3+RS)/(hoe*10**-6*RS+deltah) #in Ohm\n",
+ "Ave=-(hfe*RL*10**3)/(hie*10**3+RL*10**3*deltah) #unitless\n",
+ "Avs_e=Ave*Zie/(Zie+RS) #\n",
+ "OutputVoltage=Avs_e*InputVoltage #in \n",
+ "print \"Input impedence = %0.3f kohm\" %(Zie/1000)\n",
+ "print \"Output impedence = %0.2f kohm\" %(Zoe/10**3)\n",
+ "print \"Voltage gain =\",round(Ave,1) \n",
+ "print \"Voltage gain with source resistance =\", round(Avs_e,2)\n",
+ "print \"Output Voltage = %0.2f mV\" %(OutputVoltage)\n",
+ "#Note : Ans of output impedence is wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input impedence = 1.386 kohm\n",
+ "Output impedence = 22.38 kohm\n",
+ "Voltage gain = -348.8\n",
+ "Voltage gain with source resistance = -243.44\n",
+ "Output Voltage = -243.44 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.4, page 129"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log10\n",
+ "#Given data : \n",
+ "A1=100 #unitless\n",
+ "A2=200 #unitless\n",
+ "A3=400 #unitless\n",
+ "A1=20*log10(A1) #in dB\n",
+ "A2=20*log10(A2) #in dB\n",
+ "A3=20*log10(A3) #in dB\n",
+ "NetVoltageGain=A1+A2+A3 #in dB\n",
+ "print \"Net Voltage Gain = %0.f decibels\" %NetVoltageGain\n",
+ "#Note : Answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Net Voltage Gain = 138 decibels\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.5, page 129"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "MaxGain=1000 #unitless(at 2kHz)\n",
+ "f1=50 #in Hz\n",
+ "f2=10 #in KHz\n",
+ "print \"Bandwidth is from \",f1,\"Hz to \",f2,\"kHz\" \n",
+ "print \"Lower cutoff frequency \" ,f1,\"Hz\" \n",
+ "print \"Upper cutoff frequency \",f2,\"kHz\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bandwidth is from 50 Hz to 10 kHz\n",
+ "Lower cutoff frequency 50 Hz\n",
+ "Upper cutoff frequency 10 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.6, page 137"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "RC=10.0 #in kohm\n",
+ "hfe=330.0 #unitless\n",
+ "hie=4.5 #in kOhm\n",
+ "#RS<<hie\n",
+ "AVM=hfe*RC*10**3/(hie*10**3+RC*10**3) #unitless\n",
+ "AVM1=AVM #Gain of 1st stage\n",
+ "AVM2=AVM #Gain of 2nd stage\n",
+ "AVM3=hfe*RC*10**3/(hie*10**3) #unitless(#Gain of 3rd stage)\n",
+ "OverallGain=AVM1*AVM2*AVM3 #unitless\n",
+ "print \"Gain in mid frequeny range = %0.1f\" %AVM \n",
+ "print \"This is the gain of 1st and 2nd stage.\"\n",
+ "print \"Overall Voltage gain for mid frequency range = %0.1e\" %OverallGain "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gain in mid frequeny range = 227.6\n",
+ "This is the gain of 1st and 2nd stage.\n",
+ "Overall Voltage gain for mid frequency range = 3.8e+07\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.7, page 138"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import pi\n",
+ "#Given data : \n",
+ "RC=5.5 #in kohm\n",
+ "hfe=330 #unitless\n",
+ "hie=4.5 #in kohm\n",
+ "f1=30.0 #in Hz\n",
+ "#Formula : f1=1/(2*pi*C*(hie+RC))\n",
+ "C=1/(2*pi*f1*(hie*10**3+RC*10**3)) #in F\n",
+ "print \"Value of coupling capacitor = %0.2f micro Farad\" %(C*10**6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of coupling capacitor = 0.53 micro Farad\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.8, page 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "RC=10 #in kohm\n",
+ "Rin=1 #in kohm\n",
+ "Beta=100 #unitless\n",
+ "RL=100 #in ohm\n",
+ "RCdash=RC*10**3*RL/(RC*10**3+RL) #in ohm\n",
+ "VoltageGain=Beta*RCdash/(Rin*10**3) #in volt\n",
+ "print \"Voltage Gain : \",round(VoltageGain,1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage Gain : 9.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.9, page 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import pi\n",
+ "#Given data : \n",
+ "Rout=10 #in kohm\n",
+ "Rin=2.5 #in kohm\n",
+ "f=200 #in Hz\n",
+ "#Formula : Rout=omega*Lp=2*pi*f*Lp\n",
+ "Lp=Rout*10**3/(2*pi*f) #in H\n",
+ "print \"Inductance of primary %0.1f Henry\" %round(Lp)\n",
+ "#Formula : Rin=omega*Ls=2*pi*f*Ls\n",
+ "Ls=Rin*10**3/(2*pi*f) #in H\n",
+ "print \"Inductance of seondary = %0.1f Henry\" %round(Ls)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inductance of primary 8.0 Henry\n",
+ "Inductance of seondary = 2.0 Henry\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.10, page 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "#Given data : \n",
+ "ZL=10 #in ohm\n",
+ "ZP=1000 #in ohm\n",
+ "#For max power : ZP=n**2*ZL\n",
+ "n=sqrt(ZP/ZL) #turn ratio\n",
+ "print \"Turn ratio : \",n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Turn ratio : 10.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.11, page 149"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "Po_dc=10 #in watt\n",
+ "Po_ac=3.5 #in watt\n",
+ "#Part (i) :\n",
+ "ETAcollector=Po_ac/Po_dc #unitless\n",
+ "ETAcollector=ETAcollector*100 #collector efficiency in %\n",
+ "print \"Collector Efficiency = %.f %%\" %ETAcollector \n",
+ "#Part (ii)\n",
+ "print \"Power Rating of transistor = %0.1f Watt\" %Po_dc"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector Efficiency = 35 %\n",
+ "Power Rating of transistor = 10.0 Watt\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.12, page 149"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given data : \n",
+ "VCC=20 #in volt\n",
+ "RC=20 #in ohm\n",
+ "VCEQ=10 #in volt\n",
+ "ICQ=500 #in mA\n",
+ "#part (i) :\n",
+ "Pin_dc=VCC*ICQ*10**-3 #in watt\n",
+ "print \"Total dc power taken by the circuit = %0.f Watt\" %Pin_dc\n",
+ "#part (ii) :\n",
+ "PRc_dc=ICQ**2*10**-6*RC #in watt\n",
+ "print \"dc power dissipated by the collector load = %0.f Watt\" %PRc_dc\n",
+ "#part (iii) :\n",
+ "Io=250 #in mA(maximum value of output ac current)\n",
+ "Irms=Io/sqrt(2) #in mA\n",
+ "Po_ac=Irms**2*10**-6*RC #in watt\n",
+ "print \"Power developed across the load = %0.3f Watt\" %Po_ac\n",
+ "#part (iv) :\n",
+ "Ptr_dc=Pin_dc-PRc_dc #in watt\n",
+ "print \"dc power dissipated by the collector load = %0.f Watt\" %Ptr_dc\n",
+ "#part (v) :\n",
+ "PC_dc=Pin_dc-PRc_dc-Po_ac #in watt\n",
+ "print \"dc power dissipated by the collector load = %0.3f Watt\" %PC_dc\n",
+ "#part (vi) :\n",
+ "ETAoverall=Po_ac*100/Pin_dc #Overall Efficiency (in %)\n",
+ "print \"Overall Efficiency = %0.2f %%\" %ETAoverall\n",
+ "#part (vii) :\n",
+ "ETAcollector=Po_ac*100/PRc_dc #Collector Efficiency (in %)\n",
+ "print \"Collector Efficiency = %0.1f %%\" %ETAcollector"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total dc power taken by the circuit = 10 Watt\n",
+ "dc power dissipated by the collector load = 5 Watt\n",
+ "Power developed across the load = 0.625 Watt\n",
+ "dc power dissipated by the collector load = 5 Watt\n",
+ "dc power dissipated by the collector load = 4.375 Watt\n",
+ "Overall Efficiency = 6.25 %\n",
+ "Collector Efficiency = 12.5 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.13, page 151"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "n=10 #turn ratio\n",
+ "RL=100 #in ohm\n",
+ "ICQ=100 #in mA\n",
+ "RLdash=n**2*RL #in ohm\n",
+ "MaxPowerOut=(ICQ*10**-3)**2*RLdash/2 #in watt\n",
+ "print \"Maximum Power output = %0.1f watt\" %MaxPowerOut"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum Power output = 50.0 watt\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.14, page 152"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "#Part (i) : without heat sink\n",
+ "ThetaMax=90 #in degree C\n",
+ "Theta_o=30 #in degree C\n",
+ "R=300 #in degree C/W\n",
+ "Pr=(ThetaMax-Theta_o)/R #in watt\n",
+ "print \"Without heat sink, Maximum permissible power dissipatio = %0.1f watt\" %Pr\n",
+ "#Part (ii) : with heat sink\n",
+ "ThetaMax=90 #in degree C\n",
+ "Theta_o=30 #in degree C\n",
+ "R=60 #in degree C/W\n",
+ "Pr=(ThetaMax-Theta_o)/R #in watt\n",
+ "print \"With heat sink, Maximum permissible power dissipatio = %0.f watt\" %Pr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Without heat sink, Maximum permissible power dissipatio = 0.2 watt\n",
+ "With heat sink, Maximum permissible power dissipatio = 1 watt\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter4.ipynb b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter4.ipynb
new file mode 100755
index 00000000..4a3dedcc
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter4.ipynb
@@ -0,0 +1,92 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter4 - Frequency response"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.1, page 170"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given data\n",
+ "Omega_Z1=0 #in Radian/sec\n",
+ "Omega_Z2=10 #in Radian/sec\n",
+ "Omega_P1=100 #in Radian/sec\n",
+ "Omega_P2=25 #in Radian/sec\n",
+ "WL=sqrt(Omega_P1**2+Omega_P2**2-2*Omega_Z1**2-2*Omega_Z2**2) #in radian/sec\n",
+ "print \"Approximate value of lower 3dB Frequency = %0.1f radian/sec\"%WL"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Approximate value of lower 3dB Frequency = 102.1 radian/sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.2, page 171"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given data\n",
+ "Omega_P1=10**4 #in Radian/sec\n",
+ "Omega_P2=2*10**4 #in Radian/sec\n",
+ "Omega_Z1=10**5 #in Radian/sec\n",
+ "omegaH=1/sqrt(1/Omega_P1**2+1/Omega_P2**2-2/Omega_Z1**2) #in radian/sec\n",
+ "print \"Approximate value of lower 3dB Frequency = %0.f radian/sec\" %round(omegaH)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Approximate value of lower 3dB Frequency = 9017 radian/sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter5.ipynb b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter5.ipynb
new file mode 100755
index 00000000..8b98db8f
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter5.ipynb
@@ -0,0 +1,566 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter5 - Feed back"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.1, page 192"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data :\n",
+ "A=50 #gain(unitless)\n",
+ "Af=10 #gain(unitless)\n",
+ "#Formula : Af=A/(1+A*Beta)\n",
+ "Beta=(A/Af-1)/A #feedback ratio (unitless)\n",
+ "print \"Percentage of output fed back = %0.f %%\" %(Beta*100)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Percentage of output fed back = 8 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.2, page 192"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "A=1000 #gainWithoutFeedback(unitless)\n",
+ "#Part (i) : \n",
+ "print \"At normal collector supply :\"\n",
+ "print \"with feedback gain reduces by a factor 0.40\" \n",
+ "Af=A-A*0.40 #gainWithFeedback(unitless)\n",
+ "print \"At normal collector supply, Gain with feedback =\",Af \n",
+ "#Formula : Af=A/(1+A*Beta)\n",
+ "Beta=(A/Af-1)/A #feedback factor (unitless)\n",
+ "print \"At reduced power supply :\"\n",
+ "Adash=800 #gainWithoutFeedback(unitless)\n",
+ "Af_dash=Adash/(1+Adash*Beta)\n",
+ "print \"At Reduced collector supply, Gain with feedback \",round(Af_dash) \n",
+ "#Part (ii)\n",
+ "Reduction=((A-Adash)/A)*100 #% reduction without feedback\n",
+ "print \"percentage reduction in gain without feedback = %0.1f %%\" %Reduction \n",
+ "Reduction1=((Af-Af_dash)/Af)*100 #% reduction without feedback\n",
+ "print \"percentage reduction in gain with feedback = %0.1f %%\" %round(Reduction1)\n",
+ "#Note : answer of Af is wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "At normal collector supply :\n",
+ "with feedback gain reduces by a factor 0.40\n",
+ "At normal collector supply, Gain with feedback = 600.0\n",
+ "At reduced power supply :\n",
+ "At Reduced collector supply, Gain with feedback 522.0\n",
+ "percentage reduction in gain without feedback = 20.0 %\n",
+ "percentage reduction in gain with feedback = 13.0 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.3, page 192"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "A=100 #gain without feedback(unitless)\n",
+ "Beta=1/25 #feedback ratio (unitless)\n",
+ "Vi=50 #in mV\n",
+ "#Part (i) :\n",
+ "Af=A/(1+A*Beta) #gain with feedback(unitless)\n",
+ "print \"(i) Gain with feedback =\",Af\n",
+ "#Part (ii) :\n",
+ "FeedbackFactor=Beta*A #unitless\n",
+ "print \"(ii) Feedback Factor =\",FeedbackFactor \n",
+ "#Part (iii) :\n",
+ "Vo_dash=Af*Vi*10**-3 #in volt\n",
+ "print \"(iii) Output Voltage =\",Vo_dash,\" Volts\"\n",
+ "#Part (iv) :\n",
+ "FeedbackVoltage=Beta*Vo_dash #in volt\n",
+ "print \"(iv) Feedback Voltage =\",FeedbackVoltage,\" Volts\"\n",
+ "#Part (v) :\n",
+ "Vi_dash=Vi*(1+Beta*A) #in mv\n",
+ "print \"(v) New Increased Input Voltage =\",Vi_dash,\" milli Volts\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Gain with feedback = 20.0\n",
+ "(ii) Feedback Factor = 4.0\n",
+ "(iii) Output Voltage = 1.0 Volts\n",
+ "(iv) Feedback Voltage = 0.04 Volts\n",
+ "(v) New Increased Input Voltage = 250.0 milli Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.4, page 193"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "BW=200 #in kHz\n",
+ "A=40 #gain without feedback(in dB)\n",
+ "Beta=5 #negative feedback in %\n",
+ "Beta=Beta/100 #feedback factor\n",
+ "#Formula : Af=A/(1+A*Beta)\n",
+ "Af=A/(1+A*Beta) #gain with feedback(in dB)\n",
+ "print \"Since gain bandwidth product remains constant, A*BW=Af*BW_dash\"\n",
+ "BW_dash=A*BW/Af #in kHz\n",
+ "print \"New Bandwidth =\",BW_dash,\" kHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Since gain bandwidth product remains constant, A*BW=Af*BW_dash\n",
+ "New Bandwidth = 600.0 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.5, page 193"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from fractions import Fraction\n",
+ "#Given data :\n",
+ "A=140 #gain without feedback(unitless)\n",
+ "Af=17.5 #gain with feedback(unitless)\n",
+ "#Formula : Af=A/(1+A*Beta)\n",
+ "Beta=(A/Af-1)/A #feedback ratio (unitless)\n",
+ "print \"Fraction of output fed back to input : \",Fraction(Beta).limit_denominator()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Fraction of output fed back to input : 1/20\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.6, page 205"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "A=200 #gain without feedback(unitless)\n",
+ "Beta=0.25 #fraction ratio(unitless)\n",
+ "print \"We have, Af=A/(1+Beta*A) eqn(1)\"\n",
+ "print \"Differentiating it with respect to A, we get\"\n",
+ "print \"dAf/dA=((1+Beta*A)-Beta*A)/(1+Beta*A)**2=1/(1+Beta*A)**2\"\n",
+ "print \"dAf=dA/(1+Beta*A)**2 eqn(2)\"\n",
+ "print \"Dividing eqn(2) by eqn(1),\"\n",
+ "print \"dAf/Af=(dA/((1+Beta*A)**2))*((1+Beta*A)/A)=(1/(1+Beta*A))*(dA/A)\"\n",
+ "#Given : Normal gain changes by 10 %, it means dA/A=10/100\n",
+ "dABYA=10/100 #change in gain\n",
+ "dAfBYAf=(1/(1+Beta*A))*(dABYA) #change in gain\n",
+ "print \"Change in gain : %0.5f\"%dAfBYAf"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "We have, Af=A/(1+Beta*A) eqn(1)\n",
+ "Differentiating it with respect to A, we get\n",
+ "dAf/dA=((1+Beta*A)-Beta*A)/(1+Beta*A)**2=1/(1+Beta*A)**2\n",
+ "dAf=dA/(1+Beta*A)**2 eqn(2)\n",
+ "Dividing eqn(2) by eqn(1),\n",
+ "dAf/Af=(dA/((1+Beta*A)**2))*((1+Beta*A)/A)=(1/(1+Beta*A))*(dA/A)\n",
+ "Change in gain : 0.00196\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.7, page 206"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "A=200 #gain without feedback(unitless)\n",
+ "Dn=10 #Distortion in %\n",
+ "Vi=0.5 #Initial input voltage in volt\n",
+ "Beta=0.05 #feedback ratio (unitless)\n",
+ "#Formula : Af=A/(1+A*Beta)\n",
+ "Af=A/(1+A*Beta) #gain with feedback(unitless)\n",
+ "print \"New gain :\",round(Af,2) \n",
+ "Dn_dash=Dn/(1+A*Beta) #new distortion in %\n",
+ "print \"Distortion with negative feedback =\",round(Dn_dash,3),\" %\"\n",
+ "InitialOutputVoltage=A*Vi #in Volt\n",
+ "print \"Initial Output Voltage =\",InitialOutputVoltage,\" Volt\"\n",
+ "NewInputVoltage=InitialOutputVoltage/Af #in volt\n",
+ "print \"New Input Voltage =\",NewInputVoltage,\" Volts\"\n",
+ "#Note :Ans of Af and NewInputVoltage is not acurate in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "New gain : 18.18\n",
+ "Distortion with negative feedback = 0.909 %\n",
+ "Initial Output Voltage = 100.0 Volt\n",
+ "New Input Voltage = 5.5 Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.8, page 206"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "A=10000 #gain without feedback(unitless)\n",
+ "Zi=10 #in kOhm\n",
+ "Zo=100 #in Ohm\n",
+ "R1=2 #in Ohm\n",
+ "R2=18 #in Ohm\n",
+ "#Part (i) :\n",
+ "Beta=R1/(R1+R2) #feedback fraction(unitless)\n",
+ "print \"(i) Feedback Fraction :\",round(Beta,2) \n",
+ "#Part (ii) :\n",
+ "Af=A/(1+A*Beta) #Gain with negative feedback(unitless)\n",
+ "print \"(ii) Gain with negative feedback :\",round(Af)\n",
+ "#Part (iii) :\n",
+ "inputVoltge=0.5 #in mV\n",
+ "outputVoltge=Af*inputVoltge #in mV\n",
+ "print \"(iii) Output Voltage =\",round(outputVoltge),\" milli Volts\"\n",
+ "#Part (iv) :\n",
+ "Zif=Zi*(1+Beta*A) #in kOhm\n",
+ "print \"(iv) Input impedance of feedback amplifier =\",Zif*10**-3,\" Mohm\"\n",
+ "#Part (v) :\n",
+ "Zof=Zo/(1+Beta*A) #in kOhm\n",
+ "print \"(v) Output impedance with feedback =\",round(Zof,1),\" ohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Feedback Fraction : 0.1\n",
+ "(ii) Gain with negative feedback : 10.0\n",
+ "(iii) Output Voltage = 5.0 milli Volts\n",
+ "(iv) Input impedance of feedback amplifier = 10.01 Mohm\n",
+ "(v) Output impedance with feedback = 0.1 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.9, page 207"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "A=200 #gain without feedback(unitless)\n",
+ "Ri=2 #in kOhm\n",
+ "Ro=12 #in kOhm\n",
+ "Beta=0.02 #feedbak ratio(unitless)\n",
+ "#Part (i) :\n",
+ "Af=A/(1+A*Beta) #gain with feedback(unitless)\n",
+ "print \"(i) Gain with Negative Feedback :\",Af \n",
+ "#Part (ii) :\n",
+ "Rif=Ri*(1+A*Beta) #in kOhm\n",
+ "print \"(ii) Input resistance with feedback =\",Rif,\" kOhm\"\n",
+ "#Part (ii) :\n",
+ "Rof=Ro/(1+A*Beta) #in kOhm\n",
+ "print \"(ii) Output resistance with feedback =\",Rof,\" kOhm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Gain with Negative Feedback : 40.0\n",
+ "(ii) Input resistance with feedback = 10.0 kOhm\n",
+ "(ii) Output resistance with feedback = 2.4 kOhm\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.10, page 207"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log10\n",
+ "#Given data :\n",
+ "A=1000 #gain(unitless)\n",
+ "Beta=1/20 #feedback ratio (unitless)\n",
+ "#Formula : Af=A/(1+A*Beta)\n",
+ "Af=A/(1+A*Beta) #gain with feedback(unitless)\n",
+ "Af=20*log10(Af) #in dB\n",
+ "print \"Gain with feedback =\",round(Af,1),\" dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gain with feedback = 25.8 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.11, page 208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "A=800 #gain(unitless)\n",
+ "f1=40 #in Hz\n",
+ "f2=16 #in kHz\n",
+ "Beta=2/100 #feedback fator (unitless)\n",
+ "#Formula : Af=A/(1+A*Beta)\n",
+ "Af=A/(1+A*Beta) #gain with feedback(unitless)\n",
+ "print \"Voltage gain with feedback : %0.f\" %Af \n",
+ "BW=f2*10**3-f1 #Bandwidth of amplifier in Hz\n",
+ "print \"Bandwidth of amplifier =\",BW*10**-3,\" kHz\"\n",
+ "f1_f=f1/(1+A*Beta) #in Hz\n",
+ "f2_f=f2*(1+A*Beta) #in kHz\n",
+ "BW_f=f2_f*10**3-f1_f #Bandwith after feedback in Hz\n",
+ "print \"Bandwith after feedback =\",round(BW_f*10**-3),\" KHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage gain with feedback : 47\n",
+ "Bandwidth of amplifier = 15.96 kHz\n",
+ "Bandwith after feedback = 272.0 KHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.12, page 208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "A=100 #gain(unitless)\n",
+ "BW=10 #in Hz\n",
+ "Beta=5 #in %\n",
+ "#Part (i) :\n",
+ "#Formula : Af=A/(1+A*Beta)\n",
+ "Af=A/(1+A*Beta/100) #gain with feedback(unitless)\n",
+ "print \"Voltage gain with feedback : %0.1f\" %Af\n",
+ "#Part (ii)\n",
+ "BW_f=BW*(1+A*Beta/100) #Bandwith after feedback in Hz\n",
+ "print \"Bandwith with negative feedback =\",BW_f,\" KHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage gain with feedback : 16.7\n",
+ "Bandwith with negative feedback = 60.0 KHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.13, page 208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "hfe=50 #unitless\n",
+ "hie=1.1 #in kOhm\n",
+ "hoe=0 #unitless\n",
+ "hre=0 #unitless\n",
+ "RL=4 #in kOhm\n",
+ "Rs=10 #in kOhm\n",
+ "RB=40 #in kOhm\n",
+ "RLdash=RB*RL/(RB+RL) #in Kohm\n",
+ "AV=-hfe*RLdash/hie #unitless\n",
+ "#Part (i) \n",
+ "Rif=hie*(RB/(1-AV))/(hie+(RB/(1-AV))) #in kOhm\n",
+ "print \"Input resistance with feedback =\",round(Rif*1000),\" Ohm\"\n",
+ "#Part (ii) :\n",
+ "AVf=AV*(Rif/(Rs+Rif)) #unitless\n",
+ "print \"Voltage gain with feedback : %0.2f\" %AVf "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input resistance with feedback = 197.0 Ohm\n",
+ "Voltage gain with feedback : -3.20\n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter6.ipynb b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter6.ipynb
new file mode 100755
index 00000000..e486ebd1
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter6.ipynb
@@ -0,0 +1,376 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter6 - Field effect transistors and MOSFETS"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 6.1, page 219"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given data\n",
+ "VGS1=-3.1 #in Volt\n",
+ "VGS2=-3 #in Volt\n",
+ "ID1=1 #in mA\n",
+ "ID2=1.3 #in mA\n",
+ "delVGS=VGS2-VGS1 #in Volts\n",
+ "delID=ID2-ID1 #in mA\n",
+ "gm=delID*10**-3/delVGS #in mhos\n",
+ "print \"Transconductance = %0.e mhos\" %gm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Transconductance = 3e-03 mhos\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 6.2 page 219"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given data\n",
+ "VGS1=0 #in Volt\n",
+ "VGS2=0 #in Volt\n",
+ "VGS3=-0.2 #in Volt\n",
+ "VDS1=7 #in Volt\n",
+ "VDS2=15 #in Volt\n",
+ "VDS3=15 #in Volt\n",
+ "ID1=10 #in mA\n",
+ "ID2=10.25 #in mA\n",
+ "ID3=9.65 #in mA\n",
+ "delVDS=VDS2-VDS1 #in Volts\n",
+ "delID=ID2-ID1 #in mA\n",
+ "rd=delVDS/delID #in Kohm\n",
+ "print \"AC drain resistance = %0.f kohm\" %rd\n",
+ "delVGS=VGS3-VGS2 #in Volts\n",
+ "delID=ID3-ID2 #in mA\n",
+ "gm=delID*10**-3/delVGS #in mhos\n",
+ "print \"Transconductance = %0.e mhos\" %gm\n",
+ "mu=rd*10**3*gm #unitless\n",
+ "print \"Amplification factor : %0.f\" %mu "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "AC drain resistance = 32 kohm\n",
+ "Transconductance = 3e-03 mhos\n",
+ "Amplification factor : 96\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 6.5, page 224"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given data\n",
+ "gm=2.0 #in milli-mho\n",
+ "RL=10.0 #in Kohm\n",
+ "print \"assuming rd>>RL\" \n",
+ "Av=gm*10**-3*RL*10**3 #unitless\n",
+ "print \"Voltage amplification : \",Av"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "assuming rd>>RL\n",
+ "Voltage amplification : 20.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 6.6, page 224"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import pi\n",
+ "#given data\n",
+ "RL=20 #in Kohm\n",
+ "RS=1 #in Kohm\n",
+ "RG=1 #in Mohm\n",
+ "Cs=25 #in uF\n",
+ "mu=20 #unitless\n",
+ "rd=100 #in Kohm\n",
+ "Vs=2 #in Volt\n",
+ "f=1 #in KHz\n",
+ "Xc=1/(2*pi*f*10**3*Cs*10**-6) #in Ohm\n",
+ "print \"Xc = %0.1f\"%Xc,\" Ohm\"\n",
+ "print \"As Xc<<Rs, therefore Cs bypasses all ac components. \"\n",
+ "Av=mu*RL/(rd+RL) #unitless\n",
+ "Vo=Av*Vs #in Volt\n",
+ "print \"Output voltage = %0.2f\" %Vo,\" Volt\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Xc = 6.4 Ohm\n",
+ "As Xc<<Rs, therefore Cs bypasses all ac components. \n",
+ "Output voltage = 6.67 Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 6.7, page 224"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#given data\n",
+ "R1=2.1 #in Mohm\n",
+ "R2=270 #in Kohm\n",
+ "RD=4.7 #in Kohm\n",
+ "RS=1.5 #in Kohm\n",
+ "VDD=20 #in Volt\n",
+ "VP=-4 #in Volt\n",
+ "IDSS=8 #in mA\n",
+ "#step 1 : Find VGS :\n",
+ "VG=R2*10**3*VDD/(R1*10**6+R2*10**3) #in Volt\n",
+ "print \"VS=ID*RS-VGS Volt\"\n",
+ "print \"VGS=VG-VS=2.28-1.5*ID\"\n",
+ "#step 2 : Find ID :\n",
+ "print \"ID=IDSS*[1-VGS/VP]**2 mA\" \n",
+ "print \"ID=8*[1-(2.28-1.5*ID)/4]**2 mA\" \n",
+ "print \"2*ID=39.44-18.84*ID+2.25*ID**2\" \n",
+ "print \"2.25*ID**2-20.84*ID39.44=0\"\n",
+ "print \"ID=6.6mA or 2.65mA\" \n",
+ "print \"For ID =6.6mA VDS=-ve\" \n",
+ "print \"So discard the value so IDQ = 2.65mA.\"\n",
+ "ID=2.65 #in mA\n",
+ "#step 3 : Find VGSQ :\n",
+ "IDQ=ID #in mA\n",
+ "VGS=2.28 #in Volt\n",
+ "VGSQ=VGS-1.5*IDQ #/in Volt\n",
+ "#step 4 : Find VDSQ :\n",
+ "VDSQ=VDD-IDQ*(RD+RS) #in Volt\n",
+ "#step 5 : Find VD,VS and VDG :\n",
+ "VDS=VDSQ #in Volt\n",
+ "VG=VGS #in Volt\n",
+ "VS=ID*RS #in Volt\n",
+ "VD=VS+VDS#in Volt\n",
+ "VDG=VD-VG #in Volt\n",
+ "print \"IDQ =\",IDQ,\" mA\"\n",
+ "print \"VGSQ =\",VGSQ,\" Volt\" \n",
+ "print \"VD =\",VD,\" Volt\"\n",
+ "print \"VS =\",VS,\" Volt\" \n",
+ "print \"VDS =\",VDS,\" Volt\" \n",
+ "print \"VDG =\",VDG,\" Volt\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "VS=ID*RS-VGS Volt\n",
+ "VGS=VG-VS=2.28-1.5*ID\n",
+ "ID=IDSS*[1-VGS/VP]**2 mA\n",
+ "ID=8*[1-(2.28-1.5*ID)/4]**2 mA\n",
+ "2*ID=39.44-18.84*ID+2.25*ID**2\n",
+ "2.25*ID**2-20.84*ID39.44=0\n",
+ "ID=6.6mA or 2.65mA\n",
+ "For ID =6.6mA VDS=-ve\n",
+ "So discard the value so IDQ = 2.65mA.\n",
+ "IDQ = 2.65 mA\n",
+ "VGSQ = -1.695 Volt\n",
+ "VD = 7.545 Volt\n",
+ "VS = 3.975 Volt\n",
+ "VDS = 3.57 Volt\n",
+ "VDG = 5.265 Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 6.8, page 226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given data\n",
+ "a=5.6*10**-6/2 #in meter\n",
+ "k=12 #unitless\n",
+ "epsilon_o=8.86*10**-12 #in F/m\n",
+ "epsilon=k*epsilon_o #in F/m\n",
+ "ND=10**15 #in cm**-3\n",
+ "ND=10**15*10**6 #in m**-3\n",
+ "e=1.6*10**-19 #in Coulamb\n",
+ "VP=e*ND*a**2/(2*epsilon) #in Volt\n",
+ "print \"Pinch off voltage =\",round(VP,2),\" Volts\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pinch off voltage = 5.9 Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 6.10, page 226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "%matplotlib inline\n",
+ "from __future__ import division\n",
+ "import matplotlib.pylab as plt\n",
+ "VP=-6 # in V\n",
+ "IDSS=8 # in mA\n",
+ "VGS =0 # V(arbitrary value for plottig graph)\n",
+ "gm=-2*IDSS/VP*(1-VGS/VP)\n",
+ "plt.plot([gm,IDSS])\n",
+ "plt.title('gm versus IDSS') \n",
+ "plt.xlabel('gm(in mS)') \n",
+ "plt.ylabel('IDSS(in mA)') \n",
+ "plt.show() \n",
+ "# Plot in the textbook is not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x7fc9d0808090>"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 6.11, page 234"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given data\n",
+ "L=1.25 #in um\n",
+ "mu_n=0.065 #in m**2/V-s\n",
+ "Cox=6.9*10**-4 #in F/m**2\n",
+ "VT=0.65#in Volt\n",
+ "ID_sat=4 #in mA\n",
+ "VGS=5 #in Volt\n",
+ "#Formula : ID_sat=W*mu_n*Cox*(VGS-VT)**2/(2*L)\n",
+ "W=ID_sat*10**-3*2*L*10**-6/(mu_n*Cox*(VGS-VT)**2) #in meter\n",
+ "print \"Channel Width = %0.1f\" %(W*10**6),\" micro meter\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Channel Width = 11.8 micro meter\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter7.ipynb b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter7.ipynb
new file mode 100755
index 00000000..b7106c74
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter7.ipynb
@@ -0,0 +1,244 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter7 - Magnetic materials"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 7.1, page 252"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import pi\n",
+ "#Given data\n",
+ "Bo=1.7*10**-5 #in weber/m**2\n",
+ "meu_o=4*pi*10**-7 #permeability of free space in weber/amp-meter\n",
+ "H=Bo/meu_o #in A/m\n",
+ "print \"Horizontal component of magnetic filed intensity = %0.1f\"%H,\" A/m\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Horizontal component of magnetic filed intensity = 13.5 A/m\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 7.2, page 252"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "H=5*10**3 #in Ampere-turns/m\n",
+ "l=10 #in cm\n",
+ "l=l*10**-2 #in meter\n",
+ "N=50 #no. of turns\n",
+ "n=N/l #no. of turns per unit length\n",
+ "#Formula : H=n*i\n",
+ "i=H/n #in Ampere\n",
+ "print \"Current should be sent through solenoid = %0.1f Ampere\" %i"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current should be sent through solenoid = 10.0 Ampere\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 7.3, page 252"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "meu_r=1000 #relative permeability\n",
+ "n=5 #turns/cm\n",
+ "n=n*10**2 #turns/meter\n",
+ "i=0.5 #in Ampere\n",
+ "Volume=10**-4 #in m**3\n",
+ "I=(meu_r-1)*n*i #in Ampere\n",
+ "MagneticMoment=I*Volume #in Ameter**2\n",
+ "print \"Magnetic moment of the rod = %0.1f Ampere-meter2\" %round(MagneticMoment)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Magnetic moment of the rod = 25.0 Ampere-meter2\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 7.4, page 253"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "l=30 #in cm\n",
+ "l=l*10**-2 #in meter\n",
+ "A=1 #in cm**2\n",
+ "A=A*10**-4 #in meter**2\n",
+ "N=300 #turns of wire\n",
+ "i=0.032 #in Ampere\n",
+ "FI_B=2*10**-6 #in weber\n",
+ "meu_o=4*pi*10**-7 #permeability of free space in weber/amp-meter\n",
+ "B=FI_B/A #in weber/meter**2\n",
+ "print \"Flux Density = %0.1e\"%B,\" weber/meter2\"\n",
+ "H=N*i/l #in amp-turn/meter\n",
+ "print \"magnetic Intensity = %0.1f amp-turn/meter\" %H\n",
+ "meu=B/H #in weber/Amp-meter\n",
+ "print \"Permeability = %0.2e weber/amp-meter\" %meu\n",
+ "meu_r=meu/meu_o #Relative Permeability\n",
+ "print \"Relative Permeability = %0.1f\" %meu_r \n",
+ "#Answer of relative permeability is wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Flux Density = 2.0e-02 weber/meter2\n",
+ "magnetic Intensity = 32.0 amp-turn/meter\n",
+ "Permeability = 6.25e-04 weber/amp-meter\n",
+ "Relative Permeability = 497.4\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 7.5, page 253"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "Xci_m=9.48*10**-9 #usceptibility of medium(unitless)\n",
+ "meu_r=1+Xci_m #relative permeability(unitless)\n",
+ "print \"Relative Permeability : \",meu_r "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Relative Permeability : 1.00000000948\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 7.6, page 253"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data\n",
+ "n=10 #turns/cm\n",
+ "n=n*10**2 #turns/meter\n",
+ "i=2 #in Ampere\n",
+ "B=1 #in weber/meter**2\n",
+ "meu_o=4*pi*10**-7 #permeability of free space in weber/amp-meter\n",
+ "H=n*i #in amp-turn/meter\n",
+ "print \"Magnetising Force = %0.2f amp-turn/meter \" %H\n",
+ "#Formula : B=meu_o*(H+I)\n",
+ "I=B/meu_o-H #in amp-turn/meter\n",
+ "print \"Magnetisation of material = %0.2e amp-turn/meter\" %I \n",
+ "meu_r=B/(meu_o*H) #relative permeability(unitless)\n",
+ "print \"Relative Permeability : %d\" %meu_r"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Magnetising Force = 2000.00 amp-turn/meter \n",
+ "Magnetisation of material = 7.94e+05 amp-turn/meter\n",
+ "Relative Permeability : 397\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter8.ipynb b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter8.ipynb
new file mode 100755
index 00000000..212cffad
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter8.ipynb
@@ -0,0 +1,592 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter8 - Oscillators"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.1, page 272"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data\n",
+ "A=50 #unitless\n",
+ "print \"Barkhausen criterion for oscillator : Beta*A=1\"\n",
+ "Beta=1/A #unitless\n",
+ "print \"Feedback Factor to make oscillator : \",Beta"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Barkhausen criterion for oscillator : Beta*A=1\n",
+ "Feedback Factor to make oscillator : 0.02\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.2, page 277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi\n",
+ "#Given data\n",
+ "L=100 #in uH\n",
+ "L=L*10**-6 #in H\n",
+ "f1=500 #in kHz\n",
+ "f1=f1*10**3 #in Hz\n",
+ "f2=1500 #in kHz\n",
+ "f2=f2*10**3 #in Hz\n",
+ "#Formula : f=1/(2*pi*sqrt(L*C))\n",
+ "C1=1/(4*pi**2*f1**2*L) #in F\n",
+ "C2=1/(4*pi**2*f2**2*L) #in F\n",
+ "print \"Range of capacitor : %0.f\" %(C2*10**12),\" pF to %0.f\" %(C1*10**12),\" pF\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Range of capacitor : 113 pF to 1013 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.3, page 283"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi\n",
+ "#Given data\n",
+ "L=100 #in mH\n",
+ "L=L*10**-3 #in H\n",
+ "C1=0.1 #in uF\n",
+ "C1=C1*10**-6 #in F\n",
+ "f=100 #in kHz\n",
+ "f=f*10**3 #in Hz\n",
+ "#Formula : f=1/(2*pi*sqrt(L*C))\n",
+ "C=1/(4*pi**2*f**2*L) #in F\n",
+ "#Formula : C=C1*C2/(C1+C2)\n",
+ "C2=C*C1/(C1-C)*10**9\n",
+ "print \"C2 = %0.3f nano Farad\" %C2\n",
+ "#Note : Answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C2 = 0.025 nano Farad\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.4, page 288"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi\n",
+ "#Given data\n",
+ "R=100 #in kOhm\n",
+ "R=R*10**3 #in Ohm\n",
+ "C=0.01 #in uF\n",
+ "C=C*10**-6 #in F\n",
+ "fo=sqrt(6)/(2*pi*R*C) #in Hz\n",
+ "print \"Frequency of oscillation = %0.1f Hz\" %fo\n",
+ "#Note : Answer in the book is not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frequency of oscillation = 389.8 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.5, page 288"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi\n",
+ "#Given data\n",
+ "print \"Put alfa=sqrt(6) to find the gain\"\n",
+ "alfa=sqrt(6) #unitless\n",
+ "Beta=1/(1-5*alfa**2) \n",
+ "#Barkhausen critera : A*|Beta|>=1\n",
+ "Beta=-Beta #\n",
+ "A=1/Beta #unitless\n",
+ "print \"Minimum Gain of Amplifier must be %0.1f \" %A"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Put alfa=sqrt(6) to find the gain\n",
+ "Minimum Gain of Amplifier must be 29.0 \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.6, page 292"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "R1=50 #in kohm\n",
+ "R1=R1*10**3 #in ohm\n",
+ "C1=0.001 #in uF\n",
+ "C1=C1*10**-6 #in F\n",
+ "R2=1 #in kohm\n",
+ "R2=R2*10**3 #in ohm\n",
+ "C2=0.01 #in uF\n",
+ "C2=C2*10**-6 #in F\n",
+ "#Part (i)\n",
+ "#Formula : f=1/(2*pi*sqrt(C1*C2*R1*R2))\n",
+ "f=1/(2*pi*sqrt(C1*C2*R1*R2)) #in Hz\n",
+ "print \"Frequency of oscillations = %0.2f kHz\" %(f/1000)\n",
+ "#Part (ii)\n",
+ "CurrentGain=1+C2/C1+R1/R2 #unitless\n",
+ "print \"Current Gain = %0.2f \" %CurrentGain\n",
+ "# Answer in the textbook is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frequency of oscillations = 7.12 kHz\n",
+ "Current Gain = 61.00 \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.7, page 292"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data :\n",
+ "fmin=20 #in Hz\n",
+ "fmax=20 #in kHz\n",
+ "Cmin=30 #in pF\n",
+ "Cmax=300 #in pF\n",
+ "#Formula : fo=1/(2*pi*R*C))\n",
+ "print \"Minimum Fequeny correspond to maximum capacitance.\"\n",
+ "R=1/(2*pi*fmin*Cmax*10**-12)\n",
+ "print \"Required resistance = %0.2f Mohm\" %(R/10**6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Minimum Fequeny correspond to maximum capacitance.\n",
+ "Required resistance = 26.53 Mohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.8, page 296"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "f=500 #in kHz\n",
+ "T1=50 #in degree C\n",
+ "T2=60 #in degree C\n",
+ "TC=-20 #in ppm/degree C\n",
+ "ChangeInFreq=TC*(f*10**-3)*(T1-T2) #in Hz\n",
+ "ResonantFreq=f*1000-ChangeInFreq #in Hz\n",
+ "print \"Resonant frequency = %0.2f kHz\" %(ResonantFreq/1000)\n",
+ "#Note : answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resonant frequency = 499.90 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.9, page 296"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "f=450 #in kHz\n",
+ "T1=30 #in degree C\n",
+ "T2=50 #in degree C\n",
+ "TC=-10 #in ppm/degree C\n",
+ "PercentChange=-TC*100/10**6 #in %\n",
+ "TotalChangeInFreq=(PercentChange/100)*(f*10**3)*(T2-T1) #in Hz\n",
+ "ResonantFreq=f*1000-TotalChangeInFreq #in Hz\n",
+ "print \"Resonant frequency = %0.2f kHz\" %(ResonantFreq/1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resonant frequency = 449.91 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.10, page 297"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import pi, sqrt\n",
+ "#Given data :\n",
+ "L=0.5 #in H\n",
+ "C=0.05 #in pF\n",
+ "R=1 #in kohm\n",
+ "Cm=1 #in pF\n",
+ "fs=1/(2*pi*sqrt(L*C*10**-12)) #in Hz\n",
+ "print \"Series resonant frequency = %0.5f MHz\" %(fs/10**6) \n",
+ "fp=1/(2*pi*sqrt((L*C*10**-12*Cm*10**-12)/(C*10**-12+Cm*10**-12))) #in Hz\n",
+ "print \"Parallel resonant frequency = %0.2f MHz\" %(fp/10**6) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Series resonant frequency = 1.00658 MHz\n",
+ "Parallel resonant frequency = 1.03 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa Misc 8.1, page 302"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import pi, sqrt\n",
+ "#given data\n",
+ "L2=0.4 #in mH\n",
+ "C=0.004 #in \u00b5F\n",
+ "f=120 #in KHz\n",
+ "L1=1/(4*pi**2*(f*10**3)**2*C*10**-6)-L2*10**-3 #in H\n",
+ "print \"Value of L1 = %0.2f mH\" %(L1*10**3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of L1 = 0.04 mH\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa Misc 8.2, page 303"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given data\n",
+ "fo=10 #in KHz\n",
+ "R1=25 #in kohm\n",
+ "R2=60 #in kohm\n",
+ "Rc=40 #in kohm\n",
+ "R=7.1 #in kohm\n",
+ "hie=1.8 #in kohm\n",
+ "C=1/(2*pi*fo*10**3*R*10**3*sqrt(6+4*Rc/R)) #in F\n",
+ "print \"Value of Capacito = %0.2f nF\" %(C*10**9)\n",
+ "hfe=23+29*R/Rc+4*Rc/R #unitless\n",
+ "print \"Value of hfe is \u2265 \",round(hfe,2) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of Capacito = 0.42 nF\n",
+ "Value of hfe is \u2265 50.68\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa Misc 8.3, page 303"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given data\n",
+ "R=100 #in kohm\n",
+ "fo=10 #in KHz\n",
+ "C=1/(2*pi*fo*10**3*R*10**3) #in F\n",
+ "print \"Value of Capacitor = %0.f pF\" %(C*10**12)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of Capacitor = 159 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa Misc 8.4, page 304"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi\n",
+ "#given data\n",
+ "L=40 #in mH\n",
+ "C1=100 #in pF\n",
+ "C2=500 #in pF\n",
+ "Vout=10 #in volt\n",
+ "fo=1/(2*pi*sqrt(L*10**-3*C1*10**-12*C2*10**-12/(C1*10**-12+C2*10**-12)))\n",
+ "print \"Frequency of oscillation = %0.1f kHz\" %(fo*10**-3)\n",
+ "Vf=Vout*C1/C2 #in volt\n",
+ "print \"Feedback voltage = %0.f Volt\" %Vf\n",
+ "Gain=C2/C1 #unitless\n",
+ "print \"Minimum Gain = %0.f\" %Gain \n",
+ "#if Gain=10\n",
+ "Gain=10 #given\n",
+ "C1=C2/Gain #in pF\n",
+ "print \"For a gain of 10 C1 = %0.f pF\" %C1 \n",
+ "fo=1/(2*pi*sqrt(L*10**-3*C1*10**-12*C2*10**-12/(C1*10**-12+C2*10**-12)))\n",
+ "print \"New frequency of oscillation = %0.1f kHz\" %(fo*10**-3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frequency of oscillation = 87.2 kHz\n",
+ "Feedback voltage = 2 Volt\n",
+ "Minimum Gain = 5\n",
+ "For a gain of 10 C1 = 50 pF\n",
+ "New frequency of oscillation = 118.0 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa Misc 8.5, page 305"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt, pi\n",
+ "from __future__ import division \n",
+ "#given data\n",
+ "L=0.5 #in H\n",
+ "Cs=0.06 #in pF\n",
+ "Cp=1 #in pF\n",
+ "R=5 #in Kohm\n",
+ "fs=1/(2*pi*sqrt(L*Cs*10**-12)) #in Hz\n",
+ "Q=2*pi*fs*L/(R*10**3) #Q-factor\n",
+ "print \"Seies resonance frequency = %0.1f kHz \" %(fs/10**3)\n",
+ "print \"Q-factor of the crystal at fs is %0.f\" %round(Q) \n",
+ "fp=(1/(2*pi))*sqrt((Cs*10**-12+Cp*10**-12)/(L*Cs*10**-12*Cp*10**-12)) #in Hz\n",
+ "Q=2*pi*fp*L/(R*10**3) #Q-factor\n",
+ "print \"Seies resonance frequency = %0.f kHz\" %(fp/10**3)\n",
+ "print \"Q-factor of the crystal at fs is %0.f\" %round(Q) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Seies resonance frequency = 918.9 kHz \n",
+ "Q-factor of the crystal at fs is 577\n",
+ "Seies resonance frequency = 946 kHz\n",
+ "Q-factor of the crystal at fs is 594\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter9.ipynb b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter9.ipynb
new file mode 100755
index 00000000..ec194fbe
--- /dev/null
+++ b/A_Textbook_Of_Electronic_Devices_And_Circuits_by_Satya_Prakash_And_Saurabh_Rawat/chapter9.ipynb
@@ -0,0 +1,130 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter9 - Unijunction transistor"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 9.1, page 310"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "VBB=20 #in volt\n",
+ "VB=0.7 #in volt(For Si)\n",
+ "ETA=0.6 #intrinsic stand off ratio\n",
+ "#Part (i)\n",
+ "StandOffVoltage=ETA*VBB #in volt\n",
+ "print \"Stand Off Voltage = %0.f Volts\" %StandOffVoltage\n",
+ "#Part (ii)\n",
+ "VP=ETA*VBB+VB #in volts\n",
+ "print \"Peak point Voltage = %0.1f Volts\" %VP"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Stand Off Voltage = 12 Volts\n",
+ "Peak point Voltage = 12.7 Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 9.2, page 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log\n",
+ "#Given data :\n",
+ "VP=10 #in volt\n",
+ "R=100 #in Kohm\n",
+ "C=1000 #in pF\n",
+ "VBB=20 #in Volts\n",
+ "ETA=VP/VBB #intrinsic stand off ratio\n",
+ "T=R*10**3*C*10**-12*log(1/(1-ETA)) #in sec\n",
+ "print \"Time period of sawtooth wave = %0.2f micro seconds \" %(T*10**6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time period of sawtooth wave = 69.31 micro seconds \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 9.3, page 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data :\n",
+ "RBB=10 #in Kohm\n",
+ "ETA=0.6 #intrinsic stand off ratio\n",
+ "RB1=ETA*RBB #in Kohm\n",
+ "RB2=RBB-RB1 #in Kohm\n",
+ "print \"Resistance RB1 = %0.f kohm\" %RB1\n",
+ "print \"Resistance RB2 = %0.f kohm\" %RB2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance RB1 = 6 kohm\n",
+ "Resistance RB2 = 4 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/Advanced_Mechanics_of_Materials/README.txt b/Advanced_Mechanics_of_Materials/README.txt
new file mode 100755
index 00000000..b691aa00
--- /dev/null
+++ b/Advanced_Mechanics_of_Materials/README.txt
@@ -0,0 +1,10 @@
+Contributed By: bharth kumar
+Course: btech
+College/Institute/Organization: J.B. Institute of Engineering and Technology
+Department/Designation: computer science
+Book Title: Advanced Mechanics of Materials
+Author: A. P. Boresi and R. J. Schmidt
+Publisher: John Wiley and Sons, USA
+Year of publication: 2013
+Isbn: 978-0-471-43881-6
+Edition: 6 \ No newline at end of file
diff --git a/Analog_And_Digital_Electronics/screenshots/Blank.png b/Analog_And_Digital_Electronics/screenshots/Blank.png
new file mode 100755
index 00000000..df8f3f8f
--- /dev/null
+++ b/Analog_And_Digital_Electronics/screenshots/Blank.png
Binary files differ
diff --git a/Analog_And_Digital_Electronics/screenshots/Blank_1.png b/Analog_And_Digital_Electronics/screenshots/Blank_1.png
new file mode 100755
index 00000000..df8f3f8f
--- /dev/null
+++ b/Analog_And_Digital_Electronics/screenshots/Blank_1.png
Binary files differ
diff --git a/Analog_And_Digital_Electronics/screenshots/Blank_2.png b/Analog_And_Digital_Electronics/screenshots/Blank_2.png
new file mode 100755
index 00000000..df8f3f8f
--- /dev/null
+++ b/Analog_And_Digital_Electronics/screenshots/Blank_2.png
Binary files differ
diff --git a/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter1.ipynb b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter1.ipynb
new file mode 100755
index 00000000..91492796
--- /dev/null
+++ b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 1", "cell_type": "markdown", "metadata": {}}, {"source": "# Special Diodes", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1.1 Page No. 1-11", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Assumption\nprint(\"Assume the drop across the LED as 2 V\\n\"); \nprint(\"Therefore, VD = 2 V\\n\");\n\n# Given Data\nprint(\"From fig. 1.11, Rs = 2.2 kohm and Vs = 15 V\\n\"); \n\n# Calculation in mA\nIs =(15-2)/(2.2); \n\n# Result\nprint \"Therefore, Is(mA) = (Vs-VD/Rs) = \",round(Is,2),\"mA\"; ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Assume the drop across the LED as 2 V\n\nTherefore, VD = 2 V\n\nFrom fig. 1.11, Rs = 2.2 kohm and Vs = 15 V\n\nTherefore, Is(mA) = (Vs-VD/Rs) = 5.91 mA\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 1.2 Page No. 1-20", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "import math\n\n# Formula\nprint(\"The transistor capacitance is given by,\"); \nprint(\"CT = C(0)/[1+|VR/VJ|^n]\\n\");\n\n# Given Data\nprint(\"Now C(0) = 80pF , n = 1/3 as diffused junction\"); \nprint(\"VR = 4.2 V, VJ = 0.7 V\\n\");\n\n# Calculation in pF\nct = round((80*pow(10,-12))/((pow((1+(4.2/0.7)),(0.3333))))*pow(10,12),2); # Note here, 1/3 = 0.3333 \n\n# Result\nprint \"Therefore, CT(pF) = \",ct,\"pF\"; \n\n# Formula\nprint(\"\\nThe transistor capacitance is also given by, \" )\nprint(\"CT = K/[VR+VJ]^n\\n\") \n\n#Calculation\nk = round((41.82*pow(10,-12))*(pow((4.2+0.7),(0.3333)))*pow(10,12),2); # Note here, 1/3 = 0.3333 \n\n# Result\nprint \"Therefore, K = \",k,\"* 10^-12\"; ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The transistor capacitance is given by,\nCT = C(0)/[1+|VR/VJ|^n]\n\nNow C(0) = 80pF , n = 1/3 as diffused junction\nVR = 4.2 V, VJ = 0.7 V\n\nTherefore, CT(pF) = 41.82 pF\n\nThe transistor capacitance is also given by, \nCT = K/[VR+VJ]^n\n\nTherefore, K = 71.03 * 10^-12\n"}], "metadata": {"scrolled": true, "collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter10.ipynb b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter10.ipynb
new file mode 100755
index 00000000..05c099d1
--- /dev/null
+++ b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter10.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 10", "cell_type": "markdown", "metadata": {}}, {"source": "# Voltage Regulators", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 10.1 Page No. 10-13", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "import math\n\nprint(\"ZZ = 7ohm,R3 = 330ohm,V0 = 4.7V,Vin = 15V\")\nprint(\"The specified change in Vin is 10%,\")\nvin = 0.1*15\nprint \"Therefore,delta Vin(in V) = 10% of Vin=\",vin,\"V\"\nvo = (1.5*7)/330\nprint \"Therefore,delta V0(in V) = delta Vin\u2217ZZ/R3=\",round(vo,5),\"V\"\nlr = 0.03181*100/4.7\nprint \"Therefore,Line regulation(in percentage) = deltaV0*100/V0=\",round(lr,3),\"%\"\nprint(\"For IL(max) = 50mA,\")\ndvo=(20.0*7.0*50.0*pow(10,-3))/330.0\nprint \"Therefore,delta V0(in V) = IL(max)\u2217RS\u2217ZZ/R3=\",round(dvo,5),\"V\"\nlr=0.02121*100/4.7\nprint \"Therefore,Line regulation(in precentage) = deltaV0\u2217100/V0=\",round(lr,4),\"%\"\nprint(\"Now VR(out) = VR(in)\u2217ZZ/R3\")\nzz=7.0/330.00\nprint \"Therefore,VR(out)/VR(in) = ZZ/R3 = \",round(zz,5)\nrr=20*math.log10(0.02121)\nprint \"Therefore,RR (in dB) = 20\u2217log(0.02121)=\",round(rr,2),\"dB\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "ZZ = 7ohm,R3 = 330ohm,V0 = 4.7V,Vin = 15V\nThe specified change in Vin is 10%,\nTherefore,delta Vin(in V) = 10% of Vin= 1.5 V\nTherefore,delta V0(in V) = delta Vin\u2217ZZ/R3= 0.03182 V\nTherefore,Line regulation(in percentage) = deltaV0*100/V0= 0.677 %\nFor IL(max) = 50mA,\nTherefore,delta V0(in V) = IL(max)\u2217RS\u2217ZZ/R3= 0.02121 V\nTherefore,Line regulation(in precentage) = deltaV0\u2217100/V0= 0.4513 %\nNow VR(out) = VR(in)\u2217ZZ/R3\nTherefore,VR(out)/VR(in) = ZZ/R3 = 0.02121\nTherefore,RR (in dB) = 20\u2217log(0.02121)= -33.47 dB\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10.2 Page No. 10-15 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "import math\n\nprint(\"Vo = (1+R1/R2)Vz\")\nprint(\"9 = (1+R1/R2)5.6\")\nprint(\"Therefore R1/R2 = 0.6071\")\nprint(\"Let R1 = 10KOhm\")\nprint(\"Therefore R2 = 16.47KOhm\")\nprint(\"Minimum zener current is say 5 mA, which is same as current through R3\")\nprint(\"Therefore Izmin = (Vinmin - Vz)/R3\")\nprint(\"Therefore 5x10^-3 = ([18-3] - 5.6)/R3\")\nprint(\"R3 = 1.88KOhm\")\nprint(\"For Vmax = 18+3 = 21V we get,\")\nprint(\"Iz = (21-5.6)/1.88x10^3 = 8.19 mA\")\nprint(\"Pd = IzxVz = 8.19x10^-3 x 5.6 = 0.045W\")\nprint(\"Thus Pd < Pzmax\")\nprint(\"Thus the designed elements are\")\nprint(\"R1 = 10KOhm\")\nprint(\"R2 = 16.47KOhm\")\nprint(\"R3 = 1.88KOhm\")\nprint(\"Assume Beta of the series transistor as 30\")\nprint(\"IB = IE/(Beta +1) = Iomax/(Beta + 1)\")\nprint(\"IB = 50/31 = 1.61 mA\")\nprint(\"The Op-amp must be capable of supplying this current. The op-amp 741 has output current rating of 25mA. Hence op-amp 741 can be used\")\nprint(\"\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Vo = (1+R1/R2)Vz\n9 = (1+R1/R2)5.6\nTherefore R1/R2 = 0.6071\nLet R1 = 10KOhm\nTherefore R2 = 16.47KOhm\nMinimum zener current is say 5 mA, which is same as current through R3\nTherefore Izmin = (Vinmin - Vz)/R3\nTherefore 5x10^-3 = ([18-3] - 5.6)/R3\nR3 = 1.88KOhm\nFor Vmax = 18+3 = 21V we get,\nIz = (21-5.6)/1.88x10^3 = 8.19 mA\nPd = IzxVz = 8.19x10^-3 x 5.6 = 0.045W\nThus Pd < Pzmax\nThus the designed elements are\nR1 = 10KOhm\nR2 = 16.47KOhm\nR3 = 1.88KOhm\nAssume Beta of the series transistor as 30\nIB = IE/(Beta +1) = Iomax/(Beta + 1)\nIB = 50/31 = 1.61 mA\nThe Op-amp must be capable of supplying this current. The op-amp 741 has output current rating of 25mA. Hence op-amp 741 can be used\n\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10.3 Page No. 10-17 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "import math\n\nprint(\"DVin = 3V\")\nprint(\"DVo = (DVinZz/R3)*(1+R1/R2) = (3x7/1.8x10^3)*(1+10/16.4) = 0.01878 V\")\nprint(\"%Line Regulation = (Dvo for given change x 100)/Vo = (0.01878*100)/18 = 0.1043 %\")\nprint(\"Change in IL = 50-10 = 40mA\")\nprint(\"DVo = (DIL(max)RsZz/R3)*(1+R1/R2)\")\nprint(\"DVo = ((40*10^-3*10*7)/(1.8*10^3))*(1+(10/16.4)) = 2.504mV\")\nprint(\"% Load Regulation = (DVo for given DIL(max)*100)/Vo\")\nprint(\"= (2.504*10^-3 * 100)/18 = 0.0139 %\")\nprint(\"and VR(out) = (VR(in)Zz/R3)*(1+R1/R2)\")\nprint(\"VR(out)/VR(in) = (7/1.8*10^3)*(1+10/16.4) = 6.26*10^-3\")\nprint(\"RR = 20*log(VR(out)/VR(in))\")\nprint(\"= -44.068dB\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "DVin = 3V\nDVo = (DVinZz/R3)*(1+R1/R2) = (3x7/1.8x10^3)*(1+10/16.4) = 0.01878 V\n%Line Regulation = (Dvo for given change x 100)/Vo = (0.01878*100)/18 = 0.1043 %\nChange in IL = 50-10 = 40mA\nDVo = (DIL(max)RsZz/R3)*(1+R1/R2)\nDVo = ((40*10^-3*10*7)/(1.8*10^3))*(1+(10/16.4)) = 2.504mV\n% Load Regulation = (DVo for given DIL(max)*100)/Vo\n= (2.504*10^-3 * 100)/18 = 0.0139 %\nand VR(out) = (VR(in)Zz/R3)*(1+R1/R2)\nVR(out)/VR(in) = (7/1.8*10^3)*(1+10/16.4) = 6.26*10^-3\nRR = 20*log(VR(out)/VR(in))\n= -44.068dB\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10.4 Page No. 10-28", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "import math\n\nprint(\"R1 = 5kohm, R2 = 10kohm\")\nprint(\"The IC is 7808 i.e. Vreg = +8V\")\nvt=8*(3)\nprint \"Therefore,Vout(in V) = Vreg\u2217[1+R2/R1]=\",vt,\"V\"\nprint(\"Now R2=1kohm then,\")\nvo=8.0*(1.0+(1.0/5.0))\nprint \"Vout(in V) = 8\u2217[1+1/5]=\",round(vo,1),\"V\"\nprint(\"Thus the Vout can be varied from 9.6V to 24V,by varing R2 from 1kohm to 10kohm.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "R1 = 5kohm, R2 = 10kohm\nThe IC is 7808 i.e. Vreg = +8V\nTherefore,Vout(in V) = Vreg\u2217[1+R2/R1]= 24 V\nNow R2=1kohm then,\nVout(in V) = 8\u2217[1+1/5]= 9.6 V\nThus the Vout can be varied from 9.6V to 24V,by varing R2 from 1kohm to 10kohm.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10.5 Page No. 10-29", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "import math\n\nprint(\"The (Io)max of 7805 regulator is 1A\")\nprint(\"IL = (1+B)Io - B(Vbe/R1)\")\nprint(\"(IL)max = (1+B)(Io)max - B(Vbe/R1)\")\nprint(\"(IL)max = (1+15)x1 - (15 x 1/7) = 13.85 A\")\nprint(\"Thus IC which can supply maximum of 1A can supply maximum load of 13.85A, with the help of the current boosting arrangement\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The (Io)max of 7805 regulator is 1A\nIL = (1+B)Io - B(Vbe/R1)\n(IL)max = (1+B)(Io)max - B(Vbe/R1)\n(IL)max = (1+15)x1 - (15 x 1/7) = 13.85 A\nThus IC which can supply maximum of 1A can supply maximum load of 13.85A, with the help of the current boosting arrangement\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10.6 Page No. 10-30", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "import math\n\nprint(\"The Fig. 10.25 shows the connection diagram of IC 7805 used as current source\")\nprint(\"The current through RL is given by\")\nprint(\"IL = IR+IQ = VR/R + IQ\")\nprint(\"Now, IQ = 4.2m=A for 7805 IC\")\nprint(\"and VR = 5V for 7805 IC\")\nprint(\"Therefore, IL = 5/R + 4.2x10^-3\")\nprint(\"We want IL = 0.15A\")\nprint(\"Therefore 0.15 = 5/R+4.2x10^-3\")\nprint(\"Therfore R = 34.293 Ohm (Use 35 Ohm)\")\nprint(\"Now RL = 20 Ohm given\")\nprint(\"Vo = VR+VL = 5+ILRL = 5+0.15x20 = 8V\")\nprint(\"Therefore Vin = Vo + dropout voltage = 8+2 = 10V\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The Fig. 10.25 shows the connection diagram of IC 7805 used as current source\nThe current through RL is given by\nIL = IR+IQ = VR/R + IQ\nNow, IQ = 4.2m=A for 7805 IC\nand VR = 5V for 7805 IC\nTherefore, IL = 5/R + 4.2x10^-3\nWe want IL = 0.15A\nTherefore 0.15 = 5/R+4.2x10^-3\nTherfore R = 34.293 Ohm (Use 35 Ohm)\nNow RL = 20 Ohm given\nVo = VR+VL = 5+ILRL = 5+0.15x20 = 8V\nTherefore Vin = Vo + dropout voltage = 8+2 = 10V\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10.7 Page No. 10-33 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "import math\n\nprint(\"The resistance use dare,\")\nprint(\"R1 = 220ohm and R2 = 1.5kohm\")\nprint(\"while for LM317,IADJ = 100uA\")\nprint(\"Therefore,V0 = 1.25\u2217[1+R2/R1]+IADJ\u2217R2\")\nvo=(1.25*(1+((1.5*pow(10,3))/220)))+(100*1.5*pow(10,-3))\nprint \"Therefore,V0(in V)=\",round(vo,2),\"V\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The resistance use dare,\nR1 = 220ohm and R2 = 1.5kohm\nwhile for LM317,IADJ = 100uA\nTherefore,V0 = 1.25\u2217[1+R2/R1]+IADJ\u2217R2\nTherefore,V0(in V)= 9.92 V\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10.8 Page No. 10-33", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "import math\n\nprint(\"For LM317,the current IADJ = 100uA\")\nprint(\"When R2 is maximum i.e. R2 = 0 then,\")\nprint(\"V0 = 1.25\u2217[1+R2/R1]+IADJ\u2217R2 = 1.25V\")\nprint(\"When R2 is maximum, i.e. R2 = 10kohm then\")\nvo=(1.25*(1.0+((10.0*pow(10,3))/820.0)))+(100.0*10.0*pow(10,-3))\nprint \"V0(in V)=\",round(vo,2),\"V\"\nprint(\"Thus the output voltage can be varied in the range 1.25V to 17.49V\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For LM317,the current IADJ = 100uA\nWhen R2 is maximum i.e. R2 = 0 then,\nV0 = 1.25\u2217[1+R2/R1]+IADJ\u2217R2 = 1.25V\nWhen R2 is maximum, i.e. R2 = 10kohm then\nV0(in V)= 17.49 V\nThus the output voltage can be varied in the range 1.25V to 17.49V\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10.9 Page No. 10-47", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": 10, "cell_type": "code", "source": "import math\n\nprint(\"Switching Frequency f = 25Hz\")\nprint(\"Therefore T = 1/f\")\nprint(\"T = 1/25 = 40msec\")\nprint(\"while ton = 22msec and Vin = 200V\")\nprint(\"For Step down regulator\")\nprint(\"Vout = Delta*Vin where Delta = ton/T\")\nprint(\"Therefore Vout = 22/40*200 = 110V\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Switching Frequency f = 25Hz\nTherefore T = 1/f\nT = 1/25 = 40msec\nwhile ton = 22msec and Vin = 200V\nFor Step down regulator\nVout = Delta*Vin where Delta = ton/T\nTherefore Vout = 22/40*200 = 110V\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10.10 Page No. 10-47", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "import math\n\nprint(\"Vin = 190V, Vout = 540V, toff = 120usec\")\nprint(\"Vout = Vin/Delta\")\nprint(\"Therefore Delta = Vin/Vout = 190/540 = 0.3518\")\nprint(\"Now, Delta = ton/T = ton/(ton+toff)\")\nprint(\"Therfore 0.3518 = ton/(120x10^-6+ton)\")\nprint(\"Therefore ton = 65.1428 usec\")\nprint(\"T = ton + toff = 185.1428 usec\")\nprint(\"f = 1/T = 1/185.1428x10^-6 = 5.4012 KHz\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Vin = 190V, Vout = 540V, toff = 120usec\nVout = Vin/Delta\nTherefore Delta = Vin/Vout = 190/540 = 0.3518\nNow, Delta = ton/T = ton/(ton+toff)\nTherfore 0.3518 = ton/(120x10^-6+ton)\nTherefore ton = 65.1428 usec\nT = ton + toff = 185.1428 usec\nf = 1/T = 1/185.1428x10^-6 = 5.4012 KHz\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter11.ipynb b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter11.ipynb
new file mode 100755
index 00000000..72a8ea65
--- /dev/null
+++ b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter11.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 11", "cell_type": "markdown", "metadata": {}}, {"source": "# Memories", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 11.3 Page No. 11-22 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "print(\"The maximum data transfer rate is given by\")\nprint(\"d= storage density/Track x tape speed x No. of tracks/8\")\nprint(\"= 100 x 10^3 x 50 x 120 /8\")\nprint(\"= 75 Mbytes/sec\")\nprint(\"The storage capacity of the tape is given by\")\nprint(\"S = (d x Tape length in inches)/tape speed\")\nprint(\"= 75x450x12/50 = 8.1 Gbyte\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The maximum data transfer rate is given by\nd= storage density/Track x tape speed x No. of tracks/8\n= 100 x 10^3 x 50 x 120 /8\n= 75 Mbytes/sec\nThe storage capacity of the tape is given by\nS = (d x Tape length in inches)/tape speed\n= 75x450x12/50 = 8.1 Gbyte\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 11.4 Page No. 11-22 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "print(\"From the given data the block length can be given as,\")\nprint(\"BL = Block storage capacity/Storage density = 6x10^3/3000 = 2 inches\")\nprint(\"Therefore the utilization factor of tape,\")\nprint(\"u = 2/(2+0.5) = 0.8\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "From the given data the block length can be given as,\nBL = Block storage capacity/Storage density = 6x10^3/3000 = 2 inches\nTherefore the utilization factor of tape,\nu = 2/(2+0.5) = 0.8\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 11.5 Page No. 11-23 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "print(\"Tape Speed = 200 in/sec\")\nprint(\"Data transfer rate = 10Mbits/sec\")\nprint(\"From the given data the tape recording density to achieve data transfer rate of 10Mbytes/sec is given as\")\nprint(\"Tape recording density = (10/200)*(1/8) = 6.25 Kbytes/in\")\nprint(\"The block length can be given as\")\nprint(\"BL = Block storage capacity/storage density = 32/6.25 = 5.12 in\")\nprint(\"The number of blocks on the tape = Tape length/(BL + GL) = (2400x12)/(5.12+0.3) = 5313.6 ~= 5313\")\nprint(\"Therefore storage capacity of tape is\")\nprint(\"S = no. of blocks x storage capacity of block\")\nprint(\"=5315x32 Kbytes = 170.016 Mbytes\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Tape Speed = 200 in/sec\nData transfer rate = 10Mbits/sec\nFrom the given data the tape recording density to achieve data transfer rate of 10Mbytes/sec is given as\nTape recording density = (10/200)*(1/8) = 6.25 Kbytes/in\nThe block length can be given as\nBL = Block storage capacity/storage density = 32/6.25 = 5.12 in\nThe number of blocks on the tape = Tape length/(BL + GL) = (2400x12)/(5.12+0.3) = 5313.6 ~= 5313\nTherefore storage capacity of tape is\nS = no. of blocks x storage capacity of block\n=5315x32 Kbytes = 170.016 Mbytes\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter2.ipynb b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter2.ipynb
new file mode 100755
index 00000000..4c590bfa
--- /dev/null
+++ b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter2.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 2", "cell_type": "markdown", "metadata": {}}, {"source": "# Frequency Response", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 2.1 Page No. 2-3", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "import math\n\nprint(\"We know that maximum voltage gain of voltage amplifier is given as:\\n\");\nmv = 200*(math.sqrt(2));\nprint \"Therefore, Maximum voltage gain = Gain at cut off x*sqrt(2) =\",round(mv,2);", "outputs": [{"output_type": "stream", "name": "stdout", "text": "We know that maximum voltage gain of voltage amplifier is given as:\n\nTherefore, Maximum voltage gain = Gain at cut off x*sqrt(2) = 282.84\n"}], "metadata": {"scrolled": true, "collapsed": false, "trusted": true}}, {"source": "## Example 2.2 Page No. 2-6", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "import math\n\nprint(\"We know that,\")\n\na = 100/(math.sqrt(1+(pow((1000/20),2))))\nprint \"Below midband : A = A_mid/sqrt(1+(f1/f)^2) =\", round(a,1)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "We know that,\nBelow midband : A = A_mid/sqrt(1+(f1/f)^2) = 2.0\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2.3 Page No. 2-6", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "import math\n\na = 200* (math.sqrt(2))\nprint \"We know that A_mid = 3dB gain x*sqrt(2) =\", round(a,2)\nam = 282.84/(math.sqrt (1+(pow((10/2),2))))\nprint \"\\nAbove midband:A = A_mid/sqrt(1+(f1/f)^2) =\", round(am,2) ## Answer in textbook is wrong!", "outputs": [{"output_type": "stream", "name": "stdout", "text": "We know that A_mid = 3dB gain x*sqrt(2) = 282.84\n\nAbove midband:A = A_mid/sqrt(1+(f1/f)^2) = 55.47\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2.4 Page No. 2-11 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "import math \n\nprint(\"It is necessary to analyze each network to determine the critical frequency of the amplifier\");\n\n\nprint(\"(a) Input RC network \")\nfc1 = 1/(2*(math.pi)*(680+1031.7)*(0.1*pow(10,-6)) )\nprint \"fc(input) (in Hz) = 1/2*pi*[RS+(R1||R2||hie)]C1 =\",round(fc1,1),\"Hz\"\n\n\nprint(\"\\n\\n(b) Output RC network \")\nfc2 = 1/(2* (math.pi) *((2.2+10)*pow(10,3)) *(0.1*pow(10,-6)))\nprint \"fc(output) (in Hz) = 1/2*pi*(RC+RL)*C2 =\",round(fc2,2),\"Hz\"\n\n\nprint(\"\\n\\n(c) Bypass RC network\")\nrth = ((68*22*0.680) /((22*0.680) +(68*0.680) +(68*22)))*pow(10,3)\nprint \"Rth (in ohm) = R1||R2||RS =\",rth\nfc3 = 1/(2* (math.pi) *17.23*10*pow(10,-6))\nprint \" fc (bypass) (in Hz) = 1/2*pi*[ (Rth+hie/beta)||RE]*CE = \",round(fc3,1),\"Hz\"\n\nprint(\"\\n\\nWe have calculated all the three critical frequencies: \")\nprint(\"(a) fc (input) = 929.8 Hz\")\nprint(\"(b) fc (output) = 130.45 Hz\")\nprint(\"(c) fc (bypass) = 923.7 Hz\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "It is necessary to analyze each network to determine the critical frequency of the amplifier\n(a) Input RC network \nfc(input) (in Hz) = 1/2*pi*[RS+(R1||R2||hie)]C1 = 929.8 Hz\n\n\n(b) Output RC network \nfc(output) (in Hz) = 1/2*pi*(RC+RL)*C2 = 130.45 Hz\n\n\n(c) Bypass RC network\nRth (in ohm) = R1||R2||RS = 653.27510917\n fc (bypass) (in Hz) = 1/2*pi*[ (Rth+hie/beta)||RE]*CE = 923.7 Hz\n\n\nWe have calculated all the three critical frequencies: \n(a) fc (input) = 929.8 Hz\n(b) fc (output) = 130.45 Hz\n(c) fc (bypass) = 923.7 Hz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2.5 Page No. 2-14", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "import math\n\nprint(\"It is necessary to analyze each network to determine the critical frequency of the amplifier\")\n\n\nprint(\"\\n(a) Input RC Network\")\nprint(\"fc = 1/2*pi*Rin*C1\")\nrin =(100*100)/(100+100)\nprint \"where Rin(in Mohm) = RG||Rin(gate)= RG|| |VGS/IGSS| =\",rin,\"MOhm\"\nfc1 =1/(2* (math.pi)*50*pow(10,6)*0.001*pow(10,-6))\nprint \"Therefore, fc(in Hz) =\",round(fc1,2),\"Hz\"\n\n\nprint(\"\\n(b) Output RC Network\")\nfc2 =1/(2* (math.pi) *(24.2*pow(10,3)) *(1*pow(10,-6)))\nprint \"fc (in Hz) = 1/2*pi*(RD+RL)*C2 =\",round(fc2,3),\"Hz\"\nprint(\"\\nWe have calculated two critical frequencies\")\n\n\nprint(\"(a) fc(input) = 3.18 Hz\")\nprint(\"(b) fc(output) = 6.577 Hz\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "It is necessary to analyze each network to determine the critical frequency of the amplifier\n\n(a) Input RC Network\nfc = 1/2*pi*Rin*C1\nwhere Rin(in Mohm) = RG||Rin(gate)= RG|| |VGS/IGSS| = 50 MOhm\nTherefore, fc(in Hz) = 3.18 Hz\n\n(b) Output RC Network\nfc (in Hz) = 1/2*pi*(RD+RL)*C2 = 6.577 Hz\n\nWe have calculated two critical frequencies\n(a) fc(input) = 3.18 Hz\n(b) fc(output) = 6.577 Hz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2.6 Page No. 2-17 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "import math\n\nprint(\"Before calculating critical frequencies it is necessary calculate mid frequency gain of the given circuit. This is required to calculate Cin(miller) and Cout(miller)\")\nprint(\"\\nAv= hfe*Ro/Ri\")\nprint(\"where Ri = hie||R1||R2\")\nprint(\"and Ro = RC||RL\")\n\nav = (-100*1.8)/1.032\nprint \"\\nTherefore, Av = hfe(RC||RL)/hie||R1||R2=\",round(av,1)\nprint(\"Negative sign indicates 180 degree shift between input and output\")\n\ncin =(4*(174.4+1))*pow(10,-3)\nprint \"\\nCin(miller)(in nF) = C_bc*(Av+1) =\",round(cin,4),\"nF\"\n\ncout =(4*175.4) /(174.4)\nprint \"\\nCout(miller)(in pF) = C_bc*(Av+1)/Av =\",round(cout,1),\"pF\"\nprint(\"We know analyze input and output network for critical frequency\")\n\nfci =(1/(2* (math.pi) *410*0.7216*pow(10,-9)) ) *pow(10,-3)\nprint \"\\nfc(input)(in kHz) = 1/2*pi*(Rs||R1||R2||hie)*(C_be+Cin(miller)) =\",round(fci,3),\"Hz\"\n\nfco =(1/(2* (math.pi) *((22*pow(10,6)) /(12.2*pow(10,3)) ) *(4*pow(10,-12)) ))*pow(10,-6)\nprint \"\\nfc(output)(in MHz) = 1/2*pi*(RC||RL)*Cout(miller) =\",round(fco,1),\"MHz\"\n\nprint(\"\\nWe have calculated both the critical frequencies\")\nprint(\"(a) fc(input) = 537.947 kHz\")\nprint(\"(b) fc(output) = 22.1 MHz\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Before calculating critical frequencies it is necessary calculate mid frequency gain of the given circuit. This is required to calculate Cin(miller) and Cout(miller)\n\nAv= hfe*Ro/Ri\nwhere Ri = hie||R1||R2\nand Ro = RC||RL\n\nTherefore, Av = hfe(RC||RL)/hie||R1||R2= -174.4\nNegative sign indicates 180 degree shift between input and output\n\nCin(miller)(in nF) = C_bc*(Av+1) = 0.7016 nF\n\nCout(miller)(in pF) = C_bc*(Av+1)/Av = 4.0 pF\nWe know analyze input and output network for critical frequency\n\nfc(input)(in kHz) = 1/2*pi*(Rs||R1||R2||hie)*(C_be+Cin(miller)) = 537.947 Hz\n\nfc(output)(in MHz) = 1/2*pi*(RC||RL)*Cout(miller) = 22.1 MHz\n\nWe have calculated both the critical frequencies\n(a) fc(input) = 537.947 kHz\n(b) fc(output) = 22.1 MHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2.7 Page No. 2-21 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "import math\n\nprint(\"Before calculating critical frequencies it is necessary to calculate mid frequency gain of the given amplifier circuit. This is required to calculate Cin(miller) and Cout(miller)\")\nprint(\"\\nAv = gm*RD\")\nprint(\"Here, RD should be replaced by RD||RL\")\nav = -6*2;\nprint \"\\nTherefore,Av = gm*(RD||RL) =\",av\n\ncin = 2*(12+1) \nprint \"\\nCin(miller)(in pF) = C_gd*(Av+1) = C_rss*(Av+1) =\",cin,\"pF\"\n\ncout = (2.0*13.0)/12.0\nprint \"\\nCout (miller)(in pF) = C_gd*(Av+1) / Av =\",round(cout,4),\"pF\" ## Here the intension is to get the answer same as textbook, hence four decimal places are used!\n\nprint(\"G_gs = C_iss - C_rss = 4 pF\")\nprint(\"We know analyze input and output network for critical frequency\")\nprint(\"fc (input) = 1/2*pi*RS*CT = 1/2*pi*RS*[Cgs+Cin(miller)]\")\n\n\nfc1 =(1/(2* (math.pi) *100*30*pow(10,-12)) )*pow(10,-6)\nprint \"\\nfc (input) (in MHz)= \",round(fc1,0),\"MHz\"\n\n\nfc2 =(1/(2* (math.pi) *((48.4*pow(10,6)) /(24.2*pow(10,3)) ) *(2.166*pow(10,-12)) ))*pow(10,-6)\nprint \"\\nfc (output) (in MHz) = 1/2*pi*(RD||RL)*Cout(miller) =\",round(fc2,2),\"MHz\"\n\n\nprint(\"\\nWe have calculated both the critical frequencies:\")\nprint(\"(a) fc(input) = 53 MHz\")\nprint(\"(b) fc(output) = 36.74 MHz\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Before calculating critical frequencies it is necessary to calculate mid frequency gain of the given amplifier circuit. This is required to calculate Cin(miller) and Cout(miller)\n\nAv = gm*RD\nHere, RD should be replaced by RD||RL\n\nTherefore,Av = gm*(RD||RL) = -12\n\nCin(miller)(in pF) = C_gd*(Av+1) = C_rss*(Av+1) = 26 pF\n\nCout (miller)(in pF) = C_gd*(Av+1) / Av = 2.1667 pF\nG_gs = C_iss - C_rss = 4 pF\nWe know analyze input and output network for critical frequency\nfc (input) = 1/2*pi*RS*CT = 1/2*pi*RS*[Cgs+Cin(miller)]\n\nfc (input) (in MHz)= 53.0 MHz\n\nfc (output) (in MHz) = 1/2*pi*(RD||RL)*Cout(miller) = 36.74 MHz\n\nWe have calculated both the critical frequencies:\n(a) fc(input) = 53 MHz\n(b) fc(output) = 36.74 MHz\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter3.ipynb b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter3.ipynb
new file mode 100755
index 00000000..4338f463
--- /dev/null
+++ b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter3.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 3", "cell_type": "markdown", "metadata": {}}, {"source": "# Feedback Amplifiers", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 3.1 Page No. 3-24", "cell_type": "markdown", "metadata": {}}, {"execution_count": 15, "cell_type": "code", "source": "import math\n\nprint (\"Gain with feedback\")\nav = 1000/(1+(0.05*1000))\nprint \"\\n(a)AV_mid = Av_mid/1+beta*Av_mid=\",round(av,1)\nflf =50/(1+(0.05*1000))\nprint \"\\n(b)fLf(in Hz) = fL/1+beta*Av_mid=\",round(flf,2),\"Hz\"\nfhf =((50*pow(10,3)) *(1+(0.05*1000)))*pow(10,-6)\nprint \"\\n(c)fHf(in MHz) = fH*(1+beta*Av_mid) =\",round(fhf,2),\"MHz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Gain with feedback\n\n(a)AV_mid = Av_mid/1+beta*Av_mid= 19.6\n\n(b)fLf(in Hz) = fL/1+beta*Av_mid= 0.98 Hz\n\n(c)fHf(in MHz) = fH*(1+beta*Av_mid) = 2.55 MHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.2 Page No. 3-24", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "import math\n\nprint (\"(a)beta: 40 = 20*log[1+ beta*A]\")\nprint (\"Therefore,1+beta*A = 100\")\nb =99.0/1000.0\nprint \"Therefore,beta =\",round(b,3)\nprint (\"Gain of the amplifier with feedback is given as\")\navf =1000/100\nprint \"AVf = AV/1+beta*AV=\",avf\nprint (\"\\n(b)To maintain output power 10W,we should maintain output voltage constant and to maintain output constant with feedback gain required Vs is\")\nvsf =10*100*pow(10,-3)\nprint \"Vsf(in V) = Vs*100 =\",vsf,\"V\"\nprint (\"\\n(c)Second harmonic distortion is reduced by factor 1 + beta*A\")\nd2f =(0.1/100.0) *100.0\nprint \"D2f (in percentage) = D2/1+beta*A =\",d2f,\"%\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "(a)beta: 40 = 20*log[1+ beta*A]\nTherefore,1+beta*A = 100\nTherefore,beta = 0.099\nGain of the amplifier with feedback is given as\nAVf = AV/1+beta*AV= 10\n\n(b)To maintain output power 10W,we should maintain output voltage constant and to maintain output constant with feedback gain required Vs is\nVsf(in V) = Vs*100 = 1.0 V\n\n(c)Second harmonic distortion is reduced by factor 1 + beta*A\nD2f (in percentage) = D2/1+beta*A = 0.1 %\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.3 Page No. 3-25", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "import math\n\nprint (\"(a) We know that\")\nprint (\"dAf/Af = 0.1/1+beta*A*dA/A\")\nprint (\"Therefore, 1+beta*A = 37.5\")\nb = (36.5/2000.0) *100.0\nprint \"Therefore, beta(in percentage) =\",round(b,3),\"%\"\naf =2000/(1+(0.01825*2000) )\nprint \"\\n(b) Af = A/1+beta*A =\",round(af,2)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "(a) We know that\ndAf/Af = 0.1/1+beta*A*dA/A\nTherefore, 1+beta*A = 37.5\nTherefore, beta(in percentage) = 1.825 %\n\n(b) Af = A/1+beta*A = 53.33\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.4 Page No. 3-32", "cell_type": "markdown", "metadata": {}}, {"execution_count": 18, "cell_type": "code", "source": "import math\n\nprint(\"Step1: Identify topology\")\nprint(\"The feedback voltage is applied across the resistance Re1 and it is in series with input signal. Hence feedback is voltage series feedback.\")\nprint (\" \")\nprint (\"Step2 and Step3: Find input and output circuit.\")\nprint (\"To find input circuit, set Vo = 0 (connecting C2 to ground), which gives parallel combination of Re with Rf at E1. To find output circuit, set Ii = 0 (opening the input node E1 at emitter of Q1), which gives series combination of Rf and Re1 across the output. The resultant circuit is shown in Fig.3.32\")\nprint (\" \")\nprint (\"Step4: Find open loop voltage gain(Av)\")\nrl2 =(4.7*10.1) /(4.7+10.1)\nprint \"RL2(in kohm) = Rc2||(Re1+Rf) =\",round(rl2,2),\"KOhm\"\nprint (\"Ai2 = -hfe = -100\")\nprint (\"Ri2 = hie = 1100 ohm\")\nav2 =( -100*3.21*pow(10,3)) /1100\nprint \"Av2 = Ai2*RL2/Ri2 =\",round(av2,2)\nprint (\"Ai1 = -hfe = -100\")\nrl1 =(22*220*22*1.100) /((220*22*1.100) +(22*22*1.100)+(22*220*1.100) +(22*220*22) )\nprint \"RL1 (in ohm) = Rc1||R3||R4||Ri2 =\",round(rl1*pow(10,3),0),\"Ohm\"\nri1 =1.1+(101.0*((0.1*10.0) /(0.1+10.0) ))\nprint \"Ri1(in kohm) = hie + (1+hfe )*Re1_eff = where Re1_eff = (Re1||Rf) = \",round(ri1,3),\"KOhm\" #11.099Kohm ~= 11.01Kohm --> Round function limit\nav1 =(-100*995) /(11.099*pow(10,3))\nprint \"Therefore, Av1 = Ai1*RL1/Ri1 =\",round(av1,2)\nprint (\"The overall voltage gain without feed back is given as,\")\nav = -291.82* -8.96\nprint \"Av = Av1 * Av2 =\",round(av,1)\nprint (\"The overall voltage gain taking Rs in account is given as,\")\naV =(2614.7*11.099*pow(10,3)) /((11.099*pow(10,3)) +100)\nprint \"Av = Vo/Vs = Av*Ri1/ Ri1+Rs =\",round(aV,2)\nprint (\" \")\nprint (\"Step5: Calculate beta\")\nprint (\"Looking at Fig.3.33.\")\nbeta =100.0/(100.0+(10.0*pow(10,3)))\nprint \"beta = Vf/Vo =\",round(beta,4)\nd =1+(0.0099*2591.35)\nprint \"D = 1 + beta*Av =\",round(d,2)\navf =2591.35/26.65\nprint \"Avf = Av/D =\",round(avf,2)\nrif =26.65*11.099\nprint \"Rif(in kohm) = Ri1*D =\",round(rif,3),\"KOhm\"\nriff =(295.788*220*22) /((220*22) +(295.788*22)+(295.788*220) )\nprint \"Rif (in kohm) = Rif||R1||R2 =\",round(riff,2),\"KOhm\"\nprint (\"Rof = Ro/D = infinity/D = infinity \")\nprint (\"Therefore, Rof = Ro/D where Ro = RL2 \")\nroff =(3.21*pow(10,3)) /26.65\nprint \"Therefore, Rof (in ohm) = \",round(roff,2),\"Ohm\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Step1: Identify topology\nThe feedback voltage is applied across the resistance Re1 and it is in series with input signal. Hence feedback is voltage series feedback.\n \nStep2 and Step3: Find input and output circuit.\nTo find input circuit, set Vo = 0 (connecting C2 to ground), which gives parallel combination of Re with Rf at E1. To find output circuit, set Ii = 0 (opening the input node E1 at emitter of Q1), which gives series combination of Rf and Re1 across the output. The resultant circuit is shown in Fig.3.32\n \nStep4: Find open loop voltage gain(Av)\nRL2(in kohm) = Rc2||(Re1+Rf) = 3.21 KOhm\nAi2 = -hfe = -100\nRi2 = hie = 1100 ohm\nAv2 = Ai2*RL2/Ri2 = -291.82\nAi1 = -hfe = -100\nRL1 (in ohm) = Rc1||R3||R4||Ri2 = 995.0 Ohm\nRi1(in kohm) = hie + (1+hfe )*Re1_eff = where Re1_eff = (Re1||Rf) = 11.1 KOhm\nTherefore, Av1 = Ai1*RL1/Ri1 = -8.96\nThe overall voltage gain without feed back is given as,\nAv = Av1 * Av2 = 2614.7\nThe overall voltage gain taking Rs in account is given as,\nAv = Vo/Vs = Av*Ri1/ Ri1+Rs = 2591.35\n \nStep5: Calculate beta\nLooking at Fig.3.33.\nbeta = Vf/Vo = 0.0099\nD = 1 + beta*Av = 26.65\nAvf = Av/D = 97.24\nRif(in kohm) = Ri1*D = 295.788 KOhm\nRif (in kohm) = Rif||R1||R2 = 18.73 KOhm\nRof = Ro/D = infinity/D = infinity \nTherefore, Rof = Ro/D where Ro = RL2 \nTherefore, Rof (in ohm) = 120.45 Ohm\n"}], "metadata": {"scrolled": true, "collapsed": false, "trusted": true}}, {"source": "## Example 3.5 Page No. 3-46 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 19, "cell_type": "code", "source": "import math\n\nprint(\"Step1:Identify topology\")\nprint(\"The feedback voltage is applied across R1(100ohm),which is in series with input signal.Hence feedback is voltage series feedback\")\nprint(\"\")\nprint(\"Step2 and Step3:Find input and output circuit\")\nprint(\"To find input circuit,set Vo=0,which gives parallel combination of R1 with R2 at E1 as shown in the fig.3.45.To find output circuit, set Ii=0 by opening the input node,E1 at emitter of Q1,which gives the series combination of R2 and R1 across the output.The resultant circuit is shown in fig.3.45\")\nprint(\"\")\nprint(\"Step4:Find the open loop voltage gain(Av)\")\nrl2=(4.7*4.8)/(4.7+4.8)\nprint \"RL2(in kohm)=\",round(rl2,2),\"KOhm\"\nprint(\"Since hoe = hre = 0 we can use approximate analysis\")\nprint(\"Ai2 = -hfe = -50\")\nprint(\"Ri2 = hie = 1.1kohm\")\nav2=(-50*2.37)/1.1\nprint \"Av2 = Ai2*RL2/Ri2=\",round(av2,2)\nrl1=(10.0*47.0*33.0*1.1)/((47.0*33.0*1.1)+(10.0*33.0*1.1)+(10.0*47.0*1.1)+(10.0*47.0*33.0))\nprint \"RL1(in ohm)=\",round(rl1*pow(10,3),0),\"Ohm\" #943Ohm ~= 942Ohm --> Round function limit\nprint(\"Ai1 = -hfe = -50\")\nri1=1.1+(51.0*((0.1*4.7)/(4.8)))\nprint \"Ri1(in kohm) = hie+(1+hfe)*Re=\",round(ri1,3),\"KOhm\"\nav1=(-50*942)/(6.093*pow(10,3))\nprint \"Av1=Ai1*RL1/Ri1=\",round(av1,2)\nav=-7.73*-107.73\nprint \"Therefore,Av=Av1*Av2=\",round(av,2)\nprint(\"\")\nprint(\"Step5:Calculate beta and D\")\nprint(\"beta=R1/R1+R2=1/48\")\nd=1.0+(832.75/48.0)\nprint \"D(in ohm)=1+A*beta=\",round(d,2),\"Ohm\"\nprint(\"\")\nprint(\"Step6:Calculate Avf,Rof and Rif\")\navf=832.75/18.35\nprint \"Avf = Av/D =\",round(avf,2)\nrif=6.093*18.35\nprint \"Rif(in kohm) = Ri1*D=\",round(rif,1),\"KOhm\"\nrof=(2.37*pow(10,3))/18.35\nprint \"Rof(in ohm) = Ro/D =\",round(rof,2),\"Ohm\" #129.15Ohm ~= 129.16Ohm --> Round function limit", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Step1:Identify topology\nThe feedback voltage is applied across R1(100ohm),which is in series with input signal.Hence feedback is voltage series feedback\n\nStep2 and Step3:Find input and output circuit\nTo find input circuit,set Vo=0,which gives parallel combination of R1 with R2 at E1 as shown in the fig.3.45.To find output circuit, set Ii=0 by opening the input node,E1 at emitter of Q1,which gives the series combination of R2 and R1 across the output.The resultant circuit is shown in fig.3.45\n\nStep4:Find the open loop voltage gain(Av)\nRL2(in kohm)= 2.37 KOhm\nSince hoe = hre = 0 we can use approximate analysis\nAi2 = -hfe = -50\nRi2 = hie = 1.1kohm\nAv2 = Ai2*RL2/Ri2= -107.73\nRL1(in ohm)= 943.0 Ohm\nAi1 = -hfe = -50\nRi1(in kohm) = hie+(1+hfe)*Re= 6.094 KOhm\nAv1=Ai1*RL1/Ri1= -7.73\nTherefore,Av=Av1*Av2= 832.75\n\nStep5:Calculate beta and D\nbeta=R1/R1+R2=1/48\nD(in ohm)=1+A*beta= 18.35 Ohm\n\nStep6:Calculate Avf,Rof and Rif\nAvf = Av/D = 45.38\nRif(in kohm) = Ri1*D= 111.8 KOhm\nRof(in ohm) = Ro/D = 129.16 Ohm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.6 Page No. 3-49 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 20, "cell_type": "code", "source": "import math\n\nprint(\"Step1:Identify topology\")\nprint(\"The feedback voltage is applied across Re1 =1.5kohm,which is in series with input signal.Hence feedback is voltage series feedback\")\nprint(\"\")\nprint(\"Step2 and step3:Find input and output circuit\")\nprint(\"To find input circuit,set Vo=0,which gives parallel combination of Re1 with Rf at E1 as shown in fig.3.47.To find ouput circuit,set Ii=0 by opening the input node,E1 at emitter of Q1,which gives the series combination of Rf and Re1 across the output.The resultant circuit is shown in fig.3.47\")\nprint(\"\")\nprint(\"Step4:Find the open loop voltage gain(Av)\")\nrl2 = (2.2*57.5)/(2.2+57.5)\nprint \"RL2(in kohm) = Rc2||(Rf+Re1) = \",round(rl2,3),\"KOhm\"\nprint(\"Since hoe*RL2 = 10^6*2.119kohm = 0.002119 is less than 0.1 we use approximate analysis.\")\nprint(\"Ai2 = -hfe = -200\")\nprint(\"Ri2 = hie = 2kohm\")\nav2=(-200*2.119)/2.0\nprint \"Av2 = Ai2*RL2/Ri2 =\",round(av2,1)\nrl1=(120.0*2.0)/(122.0)\nprint \"RL1(in kohm) = RC1||Ri2 =\",round(rl1,3),\"KOhm\"\nprint(\"Since hoe*RL1 = 10^6*1.967 = 0.001967 is less than 0.1 we use approximate analysis.\")\nprint(\"Ai1 = -hfe = -200\")\nri1=2.0+(201.0*((1.5*56.0)/(57.5)))\nprint \"Ri1(in kohm) = hie+(1+hfe)*Re =\",round(ri1,2),\"KOhm\"\nav1=(-200.0*1.967)/295.63\nprint \"Therefore, Av1 = Ai1*RL1/Ri1 =\",round(av1,2)\nprint(\"The overall gain without feedback is\")\nav=-1.33*-211.9\nprint \"Av = Av1*Av2 =\",round(av,2)\nprint(\"\")\nprint(\"Step5:Calculate beta\")\nbeta=1.5/57.5\nprint \"beta = Vf/Vo =\",round(beta,3)\nprint(\"\")\nprint(\"Step6:calculate D,Avf,Rif,Rof\")\nd=1+(0.026*281.82)\nprint \"D = 1+Av*beta =\",round(d,3)\navf=281.82/8.327\nprint \"Therefore, Avf = Av/D =\",round(avf,2)\nri=(295.63*150)/(295.63+150)\nprint \"Ri(in kohm) = Ri1||R =\",round(ri,1),\"KOhm\"\nrif=99.5*8.327\nprint \"Rif(in kohm) = Ri*D =\",round(rif,2),\"KOhm\" # Round function limit\nprint(\"Ro = 1/hoe = 1Mohm\")\nrof=((1*pow(10,6))/8.327)*(pow(10,-3))\nprint \"Rof(in kohm) = Ro/D =\",round(rof,0),\"KOhm\"\nro=(1000*2.119)/(2.119+1000)\nprint \"Ro(in kohm) = Ro||Rc2||(Rf+Re1)=Ro||RL2 =\",round(ro,4),\"KOhm\"\nrof=(2.1145*pow(10,3))/8.327\nprint \"Rof(in ohm) = Ro/D =\",round(rof,0),\"Ohm\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Step1:Identify topology\nThe feedback voltage is applied across Re1 =1.5kohm,which is in series with input signal.Hence feedback is voltage series feedback\n\nStep2 and step3:Find input and output circuit\nTo find input circuit,set Vo=0,which gives parallel combination of Re1 with Rf at E1 as shown in fig.3.47.To find ouput circuit,set Ii=0 by opening the input node,E1 at emitter of Q1,which gives the series combination of Rf and Re1 across the output.The resultant circuit is shown in fig.3.47\n\nStep4:Find the open loop voltage gain(Av)\nRL2(in kohm) = Rc2||(Rf+Re1) = 2.119 KOhm\nSince hoe*RL2 = 10^6*2.119kohm = 0.002119 is less than 0.1 we use approximate analysis.\nAi2 = -hfe = -200\nRi2 = hie = 2kohm\nAv2 = Ai2*RL2/Ri2 = -211.9\nRL1(in kohm) = RC1||Ri2 = 1.967 KOhm\nSince hoe*RL1 = 10^6*1.967 = 0.001967 is less than 0.1 we use approximate analysis.\nAi1 = -hfe = -200\nRi1(in kohm) = hie+(1+hfe)*Re = 295.63 KOhm\nTherefore, Av1 = Ai1*RL1/Ri1 = -1.33\nThe overall gain without feedback is\nAv = Av1*Av2 = 281.83\n\nStep5:Calculate beta\nbeta = Vf/Vo = 0.026\n\nStep6:calculate D,Avf,Rif,Rof\nD = 1+Av*beta = 8.327\nTherefore, Avf = Av/D = 33.84\nRi(in kohm) = Ri1||R = 99.5 KOhm\nRif(in kohm) = Ri*D = 828.54 KOhm\nRo = 1/hoe = 1Mohm\nRof(in kohm) = Ro/D = 120.0 KOhm\nRo(in kohm) = Ro||Rc2||(Rf+Re1)=Ro||RL2 = 2.1145 KOhm\nRof(in ohm) = Ro/D = 254.0 Ohm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.7 Page No. 3-51 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 21, "cell_type": "code", "source": "import math\n\nprint(\"Step1:Identify topology\")\nprint(\"By shorting output voltage(Vo=0),feedback voltage Vf becomes zero and hence it is voltage sampling. The feedback voltage is applied in series with input voltage hence the topology is voltage series feedback.\")\nprint(\"\")\nprint(\"Step2 and Step3:Find input and output circuit.\")\nprint(\"To find input circuit,set Vo=0.This places the parallel combination of resistor 10K and 200 ohm at first source.To find output circuit,set Ii=0.This places the resistor 10K and 200ohm in series across the output.The resultant circuit is shown in fig.3.50.\")\nprint(\"\")\nprint(\"Step4:Replace FET with its equivalent circuit as shown in fig.3.51\")\nprint(\"\")\nprint(\"Step5:Find open loop transfer gain.\")\nprint(\"Av = Vo/Vs = Av1*Av2\")\nprint(\"Av2 = u*RL2/RL2+rd\")\nrl2=(10.2*47.0)/(10.2+47.0)\nprint \"where RL2(in kohm)=\",round(rl2,2),\"KOhm\"\nav2=(-40.0*8.38)/(8.38+10.0)\nprint \"Therefore, Av2=\",round(av2,3)\nprint(\"Av1 = u*RDeff/rd+RDeff+(1+u)*Rseff\")\nrdeff=(47.0*1000.0)/(47.0+1000.0)\nprint \"where RDeff(in kohm) = RD||RG2=\",round(rdeff,2),\"KOhm\"\nprint(\"Rseff = 200||10K\")\nav1=(-40*44.98*pow(10,3))/((10*pow(10,3))+(44.89*pow(10,3))+(41*2/10.2)*pow(10,3))\nprint \"Av1=\",round(av1,2)\noav=-28.59*-18.237\nprint \"Therefore,Overall Av =\",round(oav,2) # Round function limit\nprint(\"\")\nprint(\"Step6:Calculate beta\")\nbeta=200.0/(10.2*pow(10,3))\nprint \"beta = Vf/Vo = \",round(beta,4)\nprint(\"\")\nprint(\"Step7:Calculate D,Avf,Rif,Rof\")\nd=1+(0.0196*521.39)\nprint \"D=1+Av*beta=\",round(d,2)\navf=521.39/11.22\nprint \"Avf=Av/D=\",round(avf,2)\nprint(\"Ri = RG = 1Mohm\")\nrif=11.22\nprint \"Rif(in Mohm) = Ri*D =\",round(rif,2),\"MOhm\"\nprint(\"Ro = rd = 10kohm\")\nro = (10.0*8.38)/(18.38)\nprint \"Ro(in kohm) = rd||RL2=\",round(ro,3),\"KOhm\"\nrof = (4.559*pow(10,3))/11.22\nprint \"Rof(in ohm) = Ro/D=\",round(rof,0)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Step1:Identify topology\nBy shorting output voltage(Vo=0),feedback voltage Vf becomes zero and hence it is voltage sampling. The feedback voltage is applied in series with input voltage hence the topology is voltage series feedback.\n\nStep2 and Step3:Find input and output circuit.\nTo find input circuit,set Vo=0.This places the parallel combination of resistor 10K and 200 ohm at first source.To find output circuit,set Ii=0.This places the resistor 10K and 200ohm in series across the output.The resultant circuit is shown in fig.3.50.\n\nStep4:Replace FET with its equivalent circuit as shown in fig.3.51\n\nStep5:Find open loop transfer gain.\nAv = Vo/Vs = Av1*Av2\nAv2 = u*RL2/RL2+rd\nwhere RL2(in kohm)= 8.38 KOhm\nTherefore, Av2= -18.237\nAv1 = u*RDeff/rd+RDeff+(1+u)*Rseff\nwhere RDeff(in kohm) = RD||RG2= 44.89 KOhm\nRseff = 200||10K\nAv1= -28.59\nTherefore,Overall Av = 521.4\n\nStep6:Calculate beta\nbeta = Vf/Vo = 0.0196\n\nStep7:Calculate D,Avf,Rif,Rof\nD=1+Av*beta= 11.22\nAvf=Av/D= 46.47\nRi = RG = 1Mohm\nRif(in Mohm) = Ri*D = 11.22 MOhm\nRo = rd = 10kohm\nRo(in kohm) = rd||RL2= 4.559 KOhm\nRof(in ohm) = Ro/D= 406.0\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.8 Page No. 3-54", "cell_type": "markdown", "metadata": {}}, {"execution_count": 22, "cell_type": "code", "source": "import math\n\nprint(\"Here,output voltage is sampled and fed in series with the input signal.Hence the topology is voltage series feedback.\")\nprint(\"The open loop voltage gain for one stage is given as,\")\nprint(\"Av=gm*Req\")\nreq=(8.0*40.0*1000.0)/((40.0*1000.0)+(8.0*1000.0)+(8.0*40.0))\nprint \"Req(in kohm)=rd||Rd||(Ri1+R2)=\",round(req,2),\"KOhm\"\nav = -5.0*6.62\nprint \"Av=\",round(av,3) #Answer in textbook is wrong\navm = pow(-33.11,3)\nprint \"Av = Overall voltage gain = Avmid^3=\",round(avm,0) #Answer in textbook is wrong\nbeta = -50.0/pow(10,6)\nprint \"beta = Vf/Vo=R1/Rg=R1/R1+R2=\",beta\nd = 1 +((-5.0*pow(10,-5))*-36306.0)\nprint \"D = 1+Av*beta=\",round(d,3)\navf = -36306.0/(2.8153*pow(10,3))\nprint \"Avf = Av/D =\",round(avf,3),\"x 10^3\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Here,output voltage is sampled and fed in series with the input signal.Hence the topology is voltage series feedback.\nThe open loop voltage gain for one stage is given as,\nAv=gm*Req\nReq(in kohm)=rd||Rd||(Ri1+R2)= 6.62 KOhm\nAv= -33.1\nAv = Overall voltage gain = Avmid^3= -36298.0\nbeta = Vf/Vo=R1/Rg=R1/R1+R2= -5e-05\nD = 1+Av*beta= 2.815\nAvf = Av/D = -12.896 x 10^3\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.9 Page No. 3-55", "cell_type": "markdown", "metadata": {}}, {"execution_count": 23, "cell_type": "code", "source": "import math\n\nprint(\"Here,output terminals are Bandground, thus the forward gain is the gain of Q1 and it is,\")\nprint(\"ABN = -33.11\")\nprint(\"However, Q2 and Q3 must be considered as a part of feedback loop\")\nprint(\"Here beta BN = Vf/VB = Vf/Vo*Vo/VC*VC/VB\")\nprint(\"where VB and VC are voltages at point Band C,respectively.\")\nprint(\"Therefore,beta BN = Vf/Vo*Av3*Av2 because Vo/VC = Av3 and VC/VB = Av2\")\nbbn = -(5*pow(10,-5))*pow(33.11,2)\nprint \"Therefore, beta BN = R1/Rg*Av3*Av2 =\",round(bbn,4)\nprint(\"Note that the loop gain beta BN*ABN = A^3Vo*R1/Rg = -1.815 = -A*beta\")\nprint(\"It should be clear tht regardless of where the output terminals are taken,the loop gain is unchanged.\")\navf=-33.11/2.815\nprint \"Therefore, Avf=ABN/1+A*beta=\",round(avf,2)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Here,output terminals are Bandground, thus the forward gain is the gain of Q1 and it is,\nABN = -33.11\nHowever, Q2 and Q3 must be considered as a part of feedback loop\nHere beta BN = Vf/VB = Vf/Vo*Vo/VC*VC/VB\nwhere VB and VC are voltages at point Band C,respectively.\nTherefore,beta BN = Vf/Vo*Av3*Av2 because Vo/VC = Av3 and VC/VB = Av2\nTherefore, beta BN = R1/Rg*Av3*Av2 = -0.0548\nNote that the loop gain beta BN*ABN = A^3Vo*R1/Rg = -1.815 = -A*beta\nIt should be clear tht regardless of where the output terminals are taken,the loop gain is unchanged.\nTherefore, Avf=ABN/1+A*beta= -11.76\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.10 Page No. 3-56", "cell_type": "markdown", "metadata": {}}, {"execution_count": 24, "cell_type": "code", "source": "import math\n\nprint(\"Step1:Identify topology\")\nprint(\"By shorting output voltage(Vo=0), feedback voltage Vf becomes zero and hence it is voltage sampling.The feedback voltage is applied in series with the input voltage hence the topology is voltage series feedback.\")\nprint(\"\")\nprint(\"Step2 and Step3:Find input and output circuit.\")\nprint(\"To find input circuit, set Vo =0 .This places the parallel combination of resistor 10K and 300 ohm at first source.To find output circuit,set Ii = 0.This places the resistor 10K and 300 ohm in series across the output.The resultant circuit is shown in fig.3.54.\")\nprint(\"\")\nprint(\"Step4:Replace FET with its equivalent circuit as shown in fig.3.55.\")\nprint(\"\")\nprint(\"Step5:Find open loop transfer gain.\")\nprint(\"Av = Vo/Vs = Av1*Av2\")\nprint(\"Av2 = u*RL2/RL2+rd\")\nrl2=(10.3*22.0)/(10.3+22.0)\nprint \"where RL2(in kohm)=\",round(rl2,0),\"KOhm\"\nav2=(-50.0*7.0)/17.0\nprint \"Av2 =\",round(av2,2)\nprint(\"Av1 = u*RDeff/rd+RDeff+(1+u)*Rseff\")\nrdeff=(22.0*1000.0)/(22.0+1000.0)\nprint \"RDeff(in kohm) = RD||RG2 = \",round(rdeff,2),\"KOhm\"\nprint(\"Rseff=330||10K\")\nav1=(-50.0*21.53)/(10.0+21.53+(51.0*((0.33*10.0)/(10.0+0.33))))\nprint \"Therefore,Av1=\",round(av1,2)\nav=-20.59*-22.51\nprint \"Overall Av = Av1*Av2=\",round(av,1)\nprint(\"\")\nprint(\"Step6:Calculate beta\")\nbeta=330.0/(330.0+10000.0)\nprint \"beta = Vf/Vo = Rs/Rs+Rf=\",round(beta,4)\nprint(\"\")\nprint(\"Step7:Calculate D,Avf,Rif,Rof\")\nd=1+(0.0319*463.5)\nprint \"D=1+Av*beta=\",round(d,3)\navf=463.5/15.785\nprint \"Avf=Av/D=\",round(avf,2)\nprint(\"Ri = RG = 1Mohm\")\nrif=15.785\nprint \"Rif(in kohm)=Ri*D=\",round(rif,3),\"MOhm\"\nro=(10.0*7.0)/(10.0+7.0)\nprint \"Ro(in kohm)=rd||RL2=\",round(ro,3),\"KOhm\"\nrof=(4.118*pow(10,3))/15.785\nprint \"Rof(in ohm)=Ro/D = \",round(rof,0),\"Ohm\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Step1:Identify topology\nBy shorting output voltage(Vo=0), feedback voltage Vf becomes zero and hence it is voltage sampling.The feedback voltage is applied in series with the input voltage hence the topology is voltage series feedback.\n\nStep2 and Step3:Find input and output circuit.\nTo find input circuit, set Vo =0 .This places the parallel combination of resistor 10K and 300 ohm at first source.To find output circuit,set Ii = 0.This places the resistor 10K and 300 ohm in series across the output.The resultant circuit is shown in fig.3.54.\n\nStep4:Replace FET with its equivalent circuit as shown in fig.3.55.\n\nStep5:Find open loop transfer gain.\nAv = Vo/Vs = Av1*Av2\nAv2 = u*RL2/RL2+rd\nwhere RL2(in kohm)= 7.0 KOhm\nAv2 = -20.59\nAv1 = u*RDeff/rd+RDeff+(1+u)*Rseff\nRDeff(in kohm) = RD||RG2 = 21.53 KOhm\nRseff=330||10K\nTherefore,Av1= -22.51\nOverall Av = Av1*Av2= 463.5\n\nStep6:Calculate beta\nbeta = Vf/Vo = Rs/Rs+Rf= 0.0319\n\nStep7:Calculate D,Avf,Rif,Rof\nD=1+Av*beta= 15.786\nAvf=Av/D= 29.36\nRi = RG = 1Mohm\nRif(in kohm)=Ri*D= 15.785 MOhm\nRo(in kohm)=rd||RL2= 4.118 KOhm\nRof(in ohm)=Ro/D = 261.0 Ohm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.11 Page No. 3-59", "cell_type": "markdown", "metadata": {}}, {"execution_count": 25, "cell_type": "code", "source": "import math\n\nprint(\"Step1:Identify topology\")\nprint(\"The feedback voltage is applied across the resistance Re1 and it is in series with input signal.Hence feedback is voltage series feedback.\")\nprint(\"\")\nprint(\"step2 and Step3:Find input and output circuit.\")\nprint(\"To find input circuit,set Vo=0(connecting C2 to ground),which gives parllel combination of Re with Rf at E1.To find output ciruit, set Ii=0(opening the input node E1 at emitter of Q1),which gives series combination of Rf and Re1 across the output.The resultant circuit is shown in fig.3.57\")\nprint(\"\")\nprint(\"Step4:Find open loop voltage gain(Av)\")\nrl2=(4.7*3.42)/(4.7+3.42)\nprint \"RL2(in kohm) = Rc2||(Rs+R)=\",round(rl2,2),\"KOhm\"\nprint(\"Ai2 = -hfe = -50\")\nprint(\"Ri2 = hie = 1000ohm = 1kohm\")\nav2=-50*1.98\nprint \"Av2 = Ai2*RL2/Ri2=\",av2\nprint(\"Ai1 = -hfe = -50\")\nrl1=((10.0*100.0*22.0*1.0)/((100.0*22.0)+(10.0*22.0)+(10.0*100.0)+(10.0*100.0*22.0)))*pow(10,3)\nprint \"RL1(in ohm)=Rc1||R3||R4||Ri2=\",round(rl1,2),\"Ohm\"\nprint(\"Ri1 = hie+(1+hfe)*Re1eff\")\nre1=1+(51*((3.3*0.12)/(3.42)))\nprint \"where Re1eff(in kohm)= Rs||R =\",round(re1,1),\"KOhm\"\nav1=(-50*865.46)/6900\nprint \"Av1 = Ai1*RL1/Ri1=\",round(av1,2)\nprint(\"The overall voltage gain,\")\nav=-6.27*-99\nprint \"Av=Av1*Av2=\",round(av,2)\nprint(\"\")\nprint(\"Step5:Calculate beta\")\nbeta=120.0/(120.0+3300.0)\nprint \"beta = Vf/Vo = Rs/Rs+R=\",round(beta,3)\nprint(\"\")\nprint(\"Step6: Calculate D,Avf,Rif,Rof and Rof\")\nd=1+(0.035*620.73)\nprint \"D=1+Av*beta=\",round(d,3) ##Round of limit\navf = 620.73/22.725\nprint \"Avf=Av/D=\",round(avf,1)\nrif = 6.9*22.725\nprint \"Rif(in kohm)=Ri1*D = \",round(rif,1),\"KOhm\"\nprint(\"Rof = Ro/D = infinity\")\nrof=(1.98*pow(10,3))/22.725\nprint \"Rof(in ohm)=Ro/D = RL2/D = \",round(rof,2),\"Ohm\" ##Round of limit", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Step1:Identify topology\nThe feedback voltage is applied across the resistance Re1 and it is in series with input signal.Hence feedback is voltage series feedback.\n\nstep2 and Step3:Find input and output circuit.\nTo find input circuit,set Vo=0(connecting C2 to ground),which gives parllel combination of Re with Rf at E1.To find output ciruit, set Ii=0(opening the input node E1 at emitter of Q1),which gives series combination of Rf and Re1 across the output.The resultant circuit is shown in fig.3.57\n\nStep4:Find open loop voltage gain(Av)\nRL2(in kohm) = Rc2||(Rs+R)= 1.98 KOhm\nAi2 = -hfe = -50\nRi2 = hie = 1000ohm = 1kohm\nAv2 = Ai2*RL2/Ri2= -99.0\nAi1 = -hfe = -50\nRL1(in ohm)=Rc1||R3||R4||Ri2= 865.46 Ohm\nRi1 = hie+(1+hfe)*Re1eff\nwhere Re1eff(in kohm)= Rs||R = 6.9 KOhm\nAv1 = Ai1*RL1/Ri1= -6.27\nThe overall voltage gain,\nAv=Av1*Av2= 620.73\n\nStep5:Calculate beta\nbeta = Vf/Vo = Rs/Rs+R= 0.035\n\nStep6: Calculate D,Avf,Rif,Rof and Rof\nD=1+Av*beta= 22.726\nAvf=Av/D= 27.3\nRif(in kohm)=Ri1*D = 156.8 KOhm\nRof = Ro/D = infinity\nRof(in ohm)=Ro/D = RL2/D = 87.13 Ohm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.12 Page No. 3-61", "cell_type": "markdown", "metadata": {}}, {"execution_count": 26, "cell_type": "code", "source": "import math\n\nprint(\"Step1:Identify topology\")\nprint(\"The feebdack is given from emitter of Q2 to the base of Q2.If Io=0 then feedback current through 5K register is zero,hence it is current sampling.As feedback signal is mixed in shunt with input,the amplifier is current shunt feedback amplifier.\")\nprint(\"\")\nprint(\"Step2 and Step3:Find input and output\")\nprint(\"The input circuit of the amplifier without feedback is obtained by opening the output loop at the emitter of Q2(Io=0).This places R(5K)in series with Re from base to emitter of Q1. The output circuit is found by shorting the input node,i.e. making Vi=0.This places R(5K) in parallel with Re.The resultant equivalent circuit is shown in fig.3.59\")\nprint(\"\")\nprint(\"Step4:Find open circuit transfer gain.\")\nprint(\"AI = Io/Is = Ic/Ib2*Ib2/Ic1*Ic1/Ib1*Ib1/Is\")\nprint(\"We know that Ic2/Ib2 = Ai2 = -hfe = -50 and\")\nprint(\"Ic1/Ib1 = Ai1 = -hfe = 50\")\nprint(\"Ic1/Ib1 = 50\")\nprint(\"Looking at fig.3.59 we can write,\")\nprint(\"Ib2/Ic1 = Rc1/Rc1+Ri2\")\nri2=1.5+(51.0*((5.0*0.5)/(5.5)))\nprint \"where Ri2(in kohm) = hie+(1+hfe)*(Re2||R)=\",round(ri2,4),\"KOhm\"\nx1=-2/(2+24.6818)\nprint \"Ib2/Ic1=\",round(x1,5)\nprint(\"Ib1/Is = R/R+Ri1 where R=Rs||(R+Re2)\")\nr = ((1.0*5.5)/(1.0+5.5))*pow(10,3)\nprint \"Therefore,R(in ohm)=\",round(r,4),\"Ohm\"\nprint(\"and Ri1 = hie+(1+hfe)*Re1 = 16.8kohm\")\nx1=846.1538/(846.1538+(16.8*pow(10,3)))\nprint \"Therefore,Ib1/Is = \",round(x1,5)\nai=50.0*0.07495*50.0*0.04795\nprint \"AI=\",round(ai,4) ##Round of limit\nprint(\"\")\nprint(\"Step5:Calculate beta\")\nbeta=500.0/(500.0+(5.0*pow(10,3)))\nprint \"beta = If/Io = Re2/Re2||R = \",round(beta,4)\nprint(\"\")\nprint(\"Step6:Calculate D,AIf\")\nd=1+(0.0909*8.9848)\nprint \"D = 1+AI*beta = \",round(d,4) ##Round of limit\naif = 8.9848/1.8168\nprint \"AIf = AI/D = \",round(aif,4)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Step1:Identify topology\nThe feebdack is given from emitter of Q2 to the base of Q2.If Io=0 then feedback current through 5K register is zero,hence it is current sampling.As feedback signal is mixed in shunt with input,the amplifier is current shunt feedback amplifier.\n\nStep2 and Step3:Find input and output\nThe input circuit of the amplifier without feedback is obtained by opening the output loop at the emitter of Q2(Io=0).This places R(5K)in series with Re from base to emitter of Q1. The output circuit is found by shorting the input node,i.e. making Vi=0.This places R(5K) in parallel with Re.The resultant equivalent circuit is shown in fig.3.59\n\nStep4:Find open circuit transfer gain.\nAI = Io/Is = Ic/Ib2*Ib2/Ic1*Ic1/Ib1*Ib1/Is\nWe know that Ic2/Ib2 = Ai2 = -hfe = -50 and\nIc1/Ib1 = Ai1 = -hfe = 50\nIc1/Ib1 = 50\nLooking at fig.3.59 we can write,\nIb2/Ic1 = Rc1/Rc1+Ri2\nwhere Ri2(in kohm) = hie+(1+hfe)*(Re2||R)= 24.6818 KOhm\nIb2/Ic1= -0.07496\nIb1/Is = R/R+Ri1 where R=Rs||(R+Re2)\nTherefore,R(in ohm)= 846.1538 Ohm\nand Ri1 = hie+(1+hfe)*Re1 = 16.8kohm\nTherefore,Ib1/Is = 0.04795\nAI= 8.9846\n\nStep5:Calculate beta\nbeta = If/Io = Re2/Re2||R = 0.0909\n\nStep6:Calculate D,AIf\nD = 1+AI*beta = 1.8167\nAIf = AI/D = 4.9454\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.13 Page No. 3-63 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 27, "cell_type": "code", "source": "import math\n\nprint(\"Step1:Identify topology\")\nprint(\"The feedback voltage is applied across R1(150ohm),which is in series with input signal.Hence feedback is voltage series feedback.\")\nprint(\"\")\nprint(\"Step2 and Step3:Find input and output circuit\")\nprint(\"To find input circuit,set Vo=0,which gives parallel combination of R1 with R2 at E1 as shown in the fig.3.61.To find output circuit,set Ii=0 by opening the input node,E1 at emitter of Q1,which gives the series combination of R2 and R1 across the output.The resultant circuit is shown in fig.3.61.\")\nprint(\"\")\nprint(\"Step4:Find the open loop voltage gain(Av)\")\nrl2=(4.7*15.15)/(4.7+15.15)\nprint \"RL2(in kohm)=\",round(rl2,2),\"KOhm\"\nprint(\"Since hoe = hre = 0,we can use approximate analysis.\")\nprint(\"Ai2 = -hfe = -500\")\nprint(\"Ri2 = hie = 1100ohm\")\nav2=(-500.0*3.59*pow(10,3))/1100.0\nprint \"Av2 = Ai2*RL2/Ri2 = \",round(av2,0)\nrl1=((10*47*33*1.1)/((47*33*1.1)+(10*33*1.1)+(10*47*1.1)+(10*47*33)))*pow(10,3)\nprint \"RL1(in ohm) = 10K||47K||33K||Ri2 = \",round(rl1,0),\"Ohm\" ##Round of limit\nprint(\"Ai1 = -hfe = -500\")\nri1=1.1+(501.0*((0.15*15.0)/(0.15+15.0)))\nprint \"Ri1(in kohm)=hie+(1+hfe)*Re=\",round(ri1,1),\"KOhm\"\nav1=(-500.0*942.0)/(75.5*pow(10,3))\nprint \"Av1 = Ai1*RL1/Ri1 = \",round(av1,3)\nav=-6.238*-1632\nprint \"Av = Av1*Av2 = \",round(av,0)\nprint(\"\")\nprint(\"Step5:Calculate beta and D\")\nbeta=150.0/(150.0+15000.0)\nprint \"beta = R1/R1+R2 =\",round(beta,4)\nd=1+(10180*0.0099)\nprint \"D = 1+A*beta = \",round(d,3)\nprint(\"\")\nprint(\"Step6:Calculate Avf,Rof and Rif\")\navf=10180.0/101.782\nprint \"Avf = Av/D = \",round(avf,0)\nrif=75.5*101.782*pow(10,-3)\nprint \"Rif(in Mohm) = Ri1*D = \",round(rif,3),\"MOhm\"\nrof=(3.59*pow(10,3))/101.782\nprint \"Rof(in ohm) = Ro/D = RL2/D = \",round(rof,2),\"Ohm\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Step1:Identify topology\nThe feedback voltage is applied across R1(150ohm),which is in series with input signal.Hence feedback is voltage series feedback.\n\nStep2 and Step3:Find input and output circuit\nTo find input circuit,set Vo=0,which gives parallel combination of R1 with R2 at E1 as shown in the fig.3.61.To find output circuit,set Ii=0 by opening the input node,E1 at emitter of Q1,which gives the series combination of R2 and R1 across the output.The resultant circuit is shown in fig.3.61.\n\nStep4:Find the open loop voltage gain(Av)\nRL2(in kohm)= 3.59 KOhm\nSince hoe = hre = 0,we can use approximate analysis.\nAi2 = -hfe = -500\nRi2 = hie = 1100ohm\nAv2 = Ai2*RL2/Ri2 = -1632.0\nRL1(in ohm) = 10K||47K||33K||Ri2 = 943.0 Ohm\nAi1 = -hfe = -500\nRi1(in kohm)=hie+(1+hfe)*Re= 75.5 KOhm\nAv1 = Ai1*RL1/Ri1 = -6.238\nAv = Av1*Av2 = 10180.0\n\nStep5:Calculate beta and D\nbeta = R1/R1+R2 = 0.0099\nD = 1+A*beta = 101.782\n\nStep6:Calculate Avf,Rof and Rif\nAvf = Av/D = 100.0\nRif(in Mohm) = Ri1*D = 7.685 MOhm\nRof(in ohm) = Ro/D = RL2/D = 35.27 Ohm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.14 Page No. 3-65 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 28, "cell_type": "code", "source": "import math\n\nprint(\"Given:Avmid = 500,fL = 100kHz,fH = 20kHz and beta = 0.01\")\navf=500/(1+(0.01*500))\nprint \"\\nAvf = Avmid/1+beta*Avmid=\",round(avf,2)\nflf = 100/(1+(0.01*500))\nprint \"\\nfLf(in Hz)=fL/1+beta*Avmid=\",round(flf,2),\"Hz\"\nfhf = 20*(1+(0.01*500))\nprint \"\\nfHf(in kHz)=fH*(1+beta*Avmid)=\",round(fhf,0),\"KHz\"\nbw = 120.0-0.01667\nprint \"\\nBWf(in kHz)=fHf - fLf=\",round(bw,4),\"KHz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Given:Avmid = 500,fL = 100kHz,fH = 20kHz and beta = 0.01\n\nAvf = Avmid/1+beta*Avmid= 83.33\n\nfLf(in Hz)=fL/1+beta*Avmid= 16.67 Hz\n\nfHf(in kHz)=fH*(1+beta*Avmid)= 120.0 KHz\n\nBWf(in kHz)=fHf - fLf= 119.9833 KHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.15 Page No. 3-66 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 29, "cell_type": "code", "source": "import math\n\nprint(\"Step1:Identify topology\")\nprint(\"By shorting output(Vo=0),feedback voltage doesnot become zero.By opening the output loop feedback becomes zero and hence it is current sampling.The feedback is applied in series with the input signal,hence topology used is current series feedback.\")\nprint(\"\")\nprint(\"Step2 and Step3:Find input and output circuit.\")\nprint(\"To find input circuit,set Io=0.This places Re in series with input.To find output circuit Ii=0.This places Re in outputs. The resultant circuit is shown in fig.3.63.\")\nprint(\"\")\nprint(\"Step4:Replace transistor with its h parameter equivalent as shown in fig.3.64.\")\nprint(\"\")\nprint(\"Step5:Find open loop transfer gain.\")\nprint(\"From equation(5) of section 3.9.1 we have\")\nprint(\"Avf = Io*RL/Vs = GMf*RL = hfe*RL/Rs+hie+(1+hfe)*Re\")\nprint(\"Here Rs=Rs||R1||R2 = Rs||Rb because Rb=R1||R2\")\nprint(\"Therefore, Vo/Vs = Vo/Vi*Vi/Vs\")\nprint(\"where Vi/Vs = Rb/Rs+Rb\")\nprint(\"Therefore, Vo/Vs=(hfe*RL/Rs+hie+(1+hfe)*Re)*(Rb/Rs+Rb)\")\nprint(\"Dividing both numerator and denominator by Rs+Rb we get,\")\nprint(\"Avf = Vo/Vs = [hfe*Rc*(Rb/Rb+Rs)]/Rs+hie+(1+hfe)*Re because RL=Rc =hfe*Rc*[1/1+(Rs/Rb)]/Rs+hie+(1+hfe)*Re\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Step1:Identify topology\nBy shorting output(Vo=0),feedback voltage doesnot become zero.By opening the output loop feedback becomes zero and hence it is current sampling.The feedback is applied in series with the input signal,hence topology used is current series feedback.\n\nStep2 and Step3:Find input and output circuit.\nTo find input circuit,set Io=0.This places Re in series with input.To find output circuit Ii=0.This places Re in outputs. The resultant circuit is shown in fig.3.63.\n\nStep4:Replace transistor with its h parameter equivalent as shown in fig.3.64.\n\nStep5:Find open loop transfer gain.\nFrom equation(5) of section 3.9.1 we have\nAvf = Io*RL/Vs = GMf*RL = hfe*RL/Rs+hie+(1+hfe)*Re\nHere Rs=Rs||R1||R2 = Rs||Rb because Rb=R1||R2\nTherefore, Vo/Vs = Vo/Vi*Vi/Vs\nwhere Vi/Vs = Rb/Rs+Rb\nTherefore, Vo/Vs=(hfe*RL/Rs+hie+(1+hfe)*Re)*(Rb/Rs+Rb)\nDividing both numerator and denominator by Rs+Rb we get,\nAvf = Vo/Vs = [hfe*Rc*(Rb/Rb+Rs)]/Rs+hie+(1+hfe)*Re because RL=Rc =hfe*Rc*[1/1+(Rs/Rb)]/Rs+hie+(1+hfe)*Re\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.16 Page No. 3-68 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 30, "cell_type": "code", "source": "import math\n\nprint(\"Refer example 3.15\")\nprint(\"Avf = hfe*Rc*[1/1+(Rs/Rb)]/Rs+hie+(1+hfe)*Re where Rs=Rs||R1||R2\")\navf=(-50.0*(1.8*pow(10,3))*(1.0/(1.0+(1000.0/4272.0))))/(810.0+1000.0+((1.0+50.0)*1000.0))\nprint \"Avf =\",round(avf,2)\nprint \"GMf = Avf/RL = -1.38/1.8 = -7.66 x 10^-4\"\nprint(\"beta = Vf/Io = Ie*Re/Io = -Io*Re/Io = -Re = -1K\")\nprint(\"GMf = GM/1+beta*GM = 1/((1/(-7.66*10^-4))+1000)\")\nprint \"Therefore, GM = -3.2735 x 10^-3\"\nd=1+(-1000*-3.2735*pow(10,-3))\nprint \"D = 1+GM*beta = \",round(d,4)\nri=(1+1.36)\nprint \"Ri(in kohm) = Rs+(hie+Re)||RD = \",round(ri,2),\"KOhm\"\nrif=2.36*4.2735\nprint \"Rif(in kohm) = Ri*D = \",round(rif,0),\"KOhm\"\nprint(\"Ro = infinity\")\nprint(\"Rof = Ro*D = infinity\")\nprint(\"Rof = Rof||RL = RL = 1.8kohm\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Refer example 3.15\nAvf = hfe*Rc*[1/1+(Rs/Rb)]/Rs+hie+(1+hfe)*Re where Rs=Rs||R1||R2\nAvf = -1.38\nGMf = Avf/RL = -1.38/1.8 = -7.66 x 10^-4\nbeta = Vf/Io = Ie*Re/Io = -Io*Re/Io = -Re = -1K\nGMf = GM/1+beta*GM = 1/((1/(-7.66*10^-4))+1000)\nTherefore, GM = -3.2735 x 10^-3\nD = 1+GM*beta = 4.2735\nRi(in kohm) = Rs+(hie+Re)||RD = 2.36 KOhm\nRif(in kohm) = Ri*D = 10.0 KOhm\nRo = infinity\nRof = Ro*D = infinity\nRof = Rof||RL = RL = 1.8kohm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.17 Page No. 3-69", "cell_type": "markdown", "metadata": {}}, {"execution_count": 31, "cell_type": "code", "source": "import math\n\nprint(\"Refer example 3.15\")\nprint(\"Avf = hfe*Rc*[1/1+(Rs/Rb)]/Rs+hie+(1+hfe)*Re where Rs=Rs||R1||R2\")\navf=(-50.0*(4.0*pow(10,3))*(1.0/(1.0+(1000.0/9000.0))))/(900.0+1000.0+((1.0+150.0)*1000.0))\nprint \"Avf=\",round(avf,3)\nprint \"GMf = Avf/RL = -1.177/(4*10^3) = -2.943 x 10^-4\"\nprint(\"beta = Vf/Io = Ie*Re/Io = -Io*Re/Io = -Re = -1K\")\nprint(\"GMf = GM/1+beta*GM\")\nprint \"Therefore, GM = 1/((1/(-2.943*pow(10,-4)))+1000) = -4.17 x 10^-4\"\nd=1+(-1000*-4.17*pow(10,-4))\nprint \"D = 1+GM*beta = \",round(d,3)\nri=1.0+((2.0*9.0)/(2.0+9.0))\nprint \"Ri(in kohm) = Rs+(hie+Re)||RD=\",round(ri,3),\"KOhm\"\nrif=2.636*1.417\nprint \"Rif(in kohm) = Ri*D = \",round(rif,3),\"KOhm\"\nprint(\"Ro = infinity\")\nprint(\"Rof = Ro*D = infinity\")\nprint(\"Rof = Rof||RL = RL = 4 kohm\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Refer example 3.15\nAvf = hfe*Rc*[1/1+(Rs/Rb)]/Rs+hie+(1+hfe)*Re where Rs=Rs||R1||R2\nAvf= -1.177\nGMf = Avf/RL = -1.177/(4*10^3) = -2.943 x 10^-4\nbeta = Vf/Io = Ie*Re/Io = -Io*Re/Io = -Re = -1K\nGMf = GM/1+beta*GM\nTherefore, GM = 1/((1/(-2.943*pow(10,-4)))+1000) = -4.17 x 10^-4\nD = 1+GM*beta = 1.417\nRi(in kohm) = Rs+(hie+Re)||RD= 2.636 KOhm\nRif(in kohm) = Ri*D = 3.735 KOhm\nRo = infinity\nRof = Ro*D = infinity\nRof = Rof||RL = RL = 4 kohm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.18 Page No. 3-71 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 32, "cell_type": "code", "source": "import math\n\nprint (\"Given: Avmid = 40, fL = 100Hz, fH = 15kHz and beta = 0.01\")\navf = 400/(1+(0.01*400))\nprint \"\\nAvf = Avmid/1+beta*Avmid =\",round(avf,0)\nflf = 100/(1+(0.01*400))\nprint \"\\nfLf = fL/1+beta*Avmid =\",round(flf,0)\nfhf = (15)*(1+(0.01*400))\nprint \"\\nfHf(in kHz) = fH*(1+beta*Avmid) =\",round(fhf,0),\"KHz\"\nbw = 75 - 0.02 \nprint \"\\nBWf(in kHz) = fHf - fLf =\",round(bw,2),\"KHz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Given: Avmid = 40, fL = 100Hz, fH = 15kHz and beta = 0.01\n\nAvf = Avmid/1+beta*Avmid = 80.0\n\nfLf = fL/1+beta*Avmid = 20.0\n\nfHf(in kHz) = fH*(1+beta*Avmid) = 75.0 KHz\n\nBWf(in kHz) = fHf - fLf = 74.98 KHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3.19 Page No. 3-71", "cell_type": "markdown", "metadata": {}}, {"execution_count": 33, "cell_type": "code", "source": "import math\n\nprint(\"Given: Av=10, BW=1*10^3, n=3\")\nprint(\"\\n(i)Overall voltage gain\")\nprint(\"The gain of cascaded amplifier without feedback=10*10*10 = 1000\")\navf = 1000.0/(1+(0.1*1000.0))\nprint \"Avf = Av/1+Av*beta=\",round(avf,1)\nprint(\"\\n(ii)Bandwidth of cascaded stage\")\nprint(\"Bandwidth of cascaded amplifier without feedback\")\nbw=((1.0*pow(10,6))*(math.sqrt(pow(2.0,0.333)-1)))*pow(10,-3) ## Complier to Complier differnce in calculations\nprint \"BW(cascade)(in kHz) = BW*sqrt(2^(1/n)1)=\",round(bw,2),\"KHz\"\nbwf=(509.82*pow(10,3)*(1+(0.1*1000)))*pow(10,-6)\nprint \"BWf(in MHz) = BW*(1+beta*Avmid)=\",round(bwf,2),\"KHz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Given: Av=10, BW=1*10^3, n=3\n\n(i)Overall voltage gain\nThe gain of cascaded amplifier without feedback=10*10*10 = 1000\nAvf = Av/1+Av*beta= 9.9\n\n(ii)Bandwidth of cascaded stage\nBandwidth of cascaded amplifier without feedback\nBW(cascade)(in kHz) = BW*sqrt(2^(1/n)1)= 509.54 KHz\nBWf(in MHz) = BW*(1+beta*Avmid)= 51.49 KHz\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter4.ipynb b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter4.ipynb
new file mode 100755
index 00000000..11a20d13
--- /dev/null
+++ b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter4.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 4", "cell_type": "markdown", "metadata": {}}, {"source": "# Oscillators", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 4.1 Page No. 4-16 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "import math\n\nprint(\"Refering to equation(1),\")\nri=(25.0*57.0*1.8)/((57.0*1.8)+(25.0*1.8)+(25.0*57.0))\nprint \"R\u2019\u2019i(in kohm)=R1||R2||hie=\",round(ri,3),\"KOhm\"\nprint(\"Now R\u2019\u2019i+R3=R\")\nr3=7.1-1.631\nprint \"Therefore, R3(in kohm)=R\u2212R\u2019\u2019i=\",round(r3,2),\"KOhm\"\nk=20/7.1\nprint \"K =RC/R =\",round(k,3)\nprint(\"Now f =1/2\u2217pi\u2217R\u2217C\u2217sqrt(6+4K)\")\nc = (1.0/(math.sqrt(6.0+(4.0*2.816))*2.0*(math.pi)*7.1*10.0*pow(10,6)))*pow(10,12)\nprint \"Therefore, C (in pF)=\",round(c,2),\"pF\" #C= 539.45 ~= 539.5pF\nprint(\"hfe >= 4K+23+29/K\")\nhfe=(4*2.816)+23+(29/2.816)\nprint \"hfe >= \",round(hfe,3)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Refering to equation(1),\nR\u2019\u2019i(in kohm)=R1||R2||hie= 1.631 KOhm\nNow R\u2019\u2019i+R3=R\nTherefore, R3(in kohm)=R\u2212R\u2019\u2019i= 5.47 KOhm\nK =RC/R = 2.817\nNow f =1/2\u2217pi\u2217R\u2217C\u2217sqrt(6+4K)\nTherefore, C (in pF)= 539.5 pF\nhfe >= 4K+23+29/K\nhfe >= 44.562\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.2 Page No. 4-17", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "import math\n\nprint(\"The given values are, R = 4.7kohm and C = 0.47uF\")\nf=1.0/(2.0*math.pi*math.sqrt(6)*(4.7*pow(10,3))*(0.47*pow(10,-6)))\nprint \"f(in Hz) =1/2\u2217pi\u2217sqrt(6)\u2217R\u2217C =\",round(f,3),\"Hz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The given values are, R = 4.7kohm and C = 0.47uF\nf(in Hz) =1/2\u2217pi\u2217sqrt(6)\u2217R\u2217C = 29.414 Hz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.3 Page No. 4-17", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "import math\n\nprint(\"f=1kHz\")\nprint(\"Now f=1/2\u2217pi\u2217sqrt(6)\u2217R\u2217C\")\nprint(\"Choose C=0.1uF\")\nr=1.0/(math.sqrt(6)*2.0*math.pi*0.1*1.0*pow(10,-3))\nprint \"Therefore,R(in ohm)=\",round(r,3),\"Ohm\"\nprint(\"Choose R = 680ohm standard value\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "f=1kHz\nNow f=1/2\u2217pi\u2217sqrt(6)\u2217R\u2217C\nChoose C=0.1uF\nTherefore,R(in ohm)= 649.747 Ohm\nChoose R = 680ohm standard value\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.4 Page No. 4-19", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "import math\n\nprint(\"Using the expression for the frequency\")\nprint(\"Now,f=1/2\u2217pi\u2217R\u2217C\u2217sqrt(6)\")\nf=(1/(math.sqrt(6)*2*math.pi*9.7*5*pow(10,6)))*pow(10,9)\nprint \"Therefore,C(in nF)=\",round(f,2),\"nF\"\nprint(\"Now using the equation(27)\")\nprint(\"|A|=gm\u2217RL\")\nprint(\"Therefore,|A|>=29\")\nprint(\"Therefore,gm\u2217RL>=29\")\nrl=(29.0/(5000))*pow(10,3)\nprint \"Therefore,RL(in kohm) >= 29/gm >=\",round(rl,1),\"KOhm\"\nprint(\"RL=RD\u2217rd/RD+rd\")\nrd=(40.0)/4.8823\nprint\"Therefore,RD(in kohm)=\",round(rd,2),\"KOhm\" ##Answer in textbook is wrong \nprint(\"While for minimum value of RL = 5.8kohm\")\nprint(\"RD = 6.78 kohm\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Using the expression for the frequency\nNow,f=1/2\u2217pi\u2217R\u2217C\u2217sqrt(6)\nTherefore,C(in nF)= 1.34 nF\nNow using the equation(27)\n|A|=gm\u2217RL\nTherefore,|A|>=29\nTherefore,gm\u2217RL>=29\nTherefore,RL(in kohm) >= 29/gm >= 5.8 KOhm\nRL=RD\u2217rd/RD+rd\nTherefore,RD(in kohm)= 8.19 KOhm\nWhile for minimum value of RL = 5.8kohm\nRD = 6.78 kohm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.5 Page No. 4-26", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "import math\n\nprint(\"The frequency of the oscillator is given by,\")\nprint(\"f=1/2\u2217pi\u2217sqrt(R1\u2217R2\u2217C1\u2217C2)\")\nprint(\"For f=10kHz,\")\nr2=(1/(4*(pow(math.pi,2))*(100*pow(10,6))*(10*pow(10,3))*(0.001*pow(10,-12))))\nprint \"Therefore,R2(in kohm)=\",round(r2,2),\"KOhm\"\nprint(\"For f=50kHz,\")\nr2=(1/(4*(pow(math.pi,2))*(2500*pow(10,6))*(10*pow(10,3))*(0.001*pow(10,-12))))\nprint \"Therefore,R2(in kohm)=\",round(r2,3),\"KOhm\"\nprint(\"So minimum value of R2 is 1.013kohm while the maximum value of R2 is 25.33kohm\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The frequency of the oscillator is given by,\nf=1/2\u2217pi\u2217sqrt(R1\u2217R2\u2217C1\u2217C2)\nFor f=10kHz,\nTherefore,R2(in kohm)= 25.33 KOhm\nFor f=50kHz,\nTherefore,R2(in kohm)= 1.013 KOhm\nSo minimum value of R2 is 1.013kohm while the maximum value of R2 is 25.33kohm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.6 Page No. 4-38 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "import math\n\nprint(\"The frequency is given by,\")\nprint(\"f=1/2\u2217pi\u2217sqrt(C\u2217Leq)\")\nleq=(2*pow(10,-3))+(20*pow(10,-6))\nprint \"where Leq=L1+L2=\",round(leq,6)\nprint(\"For f = fmax = 2050 kHz\")\nc=(1/(4*(pow(math.pi,2))*(pow((2050*pow(10,3)),2))*0.00202))*pow(10,12)\nprint \"Therefore,C(in pF)=\",round(c,2),\"pF\"\nprint(\"For f = fmin = 950 kHz\")\nc=(1/(4*(pow(math.pi,2))*(pow((950*pow(10,3)),2))*0.00202))*pow(10,12)\nprint \"Therefore,C(inpF)=\",round(c,2),\"pF\"\nprint(\"Hence C must be varied from 2.98pF to 13.89pF,to get the required frequency variation.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The frequency is given by,\nf=1/2\u2217pi\u2217sqrt(C\u2217Leq)\nwhere Leq=L1+L2= 0.00202\nFor f = fmax = 2050 kHz\nTherefore,C(in pF)= 2.98 pF\nFor f = fmin = 950 kHz\nTherefore,C(inpF)= 13.89 pF\nHence C must be varied from 2.98pF to 13.89pF,to get the required frequency variation.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.7 Page No. 4-40 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 13, "cell_type": "code", "source": "import math\n\nprint(\"The given values are,\")\nprint(\"L1=0.5mH, L2=1mH, C=0.2uF\")\nprint(\"Now f=1/2\u2217pi\u2217sqrt(C\u2217Leq)\")\nleq=0.5+1.0\nprint \"and Leq(in mH)=L1+L2=\",round(leq,1),\"mH\"\nf=(1/(2*math.pi*math.sqrt(1.5*0.2*pow(10,-9))))*pow(10,-3)\nprint \"Therefore,f(in kHz)=\",round(f,2),\"KHz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The given values are,\nL1=0.5mH, L2=1mH, C=0.2uF\nNow f=1/2\u2217pi\u2217sqrt(C\u2217Leq)\nand Leq(in mH)=L1+L2= 1.5 mH\nTherefore,f(in kHz)= 9.19 KHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.8 Page No. 4-45", "cell_type": "markdown", "metadata": {}}, {"execution_count": 18, "cell_type": "code", "source": "import math\n\nprint(\"The equivalent capacitance is given by,\")\nceq=((150*1.5*pow(10,-21))/((150*pow(10,-12))+(1.5*pow(10,-9))))*pow(10,12)\nprint \"Ceq(in F)=C1\u2217C2/C1+C2=\",round(ceq,3),\"x 10^-12 F\"\nprint(\"Now,f = 1/2\u2217pi\u2217sqrt(L\u2217Ceq)\")\nf=(1/(2*math.pi*math.sqrt(50*136.363*pow(10,-18))))*pow(10,-6)\nprint \"f(in MHz)=\",round(f,3),\"MHz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The equivalent capacitance is given by,\nCeq(in F)=C1\u2217C2/C1+C2= 136.364 x 10^-12 F\nNow,f = 1/2\u2217pi\u2217sqrt(L\u2217Ceq)\nf(in MHz)= 1.927 MHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.9 Page No. 4-45", "cell_type": "markdown", "metadata": {}}, {"execution_count": 19, "cell_type": "code", "source": "import math\n\nprint(\"The given values are,\")\nprint(\"L=100uH, C1=C2=C and f=500kHz\")\nprint(\"Now,f=1/2\u2217pi\u2217sqrt(L\u2217Ceq)\")\nceq=(1/(4*(pow(math.pi,2))*(100*pow(10,-6))*(pow((500*pow(10,3)),2))))*pow(10,9)\nprint \"Therefore,Ceq(in F)=\",round(ceq,4),\"x10^-9 F\"\nprint(\"but Ceq =C1\u2217C2/C1+C2 and C1=C2=C\")\nprint(\"Therefore,Ceq=C/2\")\nc=1.0132*2.0\nprint \"Therefore,C(in nF)=\",round(c,3),\"nF\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The given values are,\nL=100uH, C1=C2=C and f=500kHz\nNow,f=1/2\u2217pi\u2217sqrt(L\u2217Ceq)\nTherefore,Ceq(in F)= 1.0132 x10^-9 F\nbut Ceq =C1\u2217C2/C1+C2 and C1=C2=C\nTherefore,Ceq=C/2\nTherefore,C(in nF)= 2.026 nF\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.10 Page No. 4-58", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "import math\n\nfs=(1.0/(2.0*math.pi*math.sqrt(0.4*0.085*pow(10,-12))))*pow(10,-6) ##Sqrt --> Complier to Complier differnce \nprint \"(i)fs(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217C)=\",round(fs,3),\"MHz\"\nceq=0.085/1.085\nprint \"(ii)Ceq(in pF)=C\u2217CM/C+CM=\",round(ceq,3),\"pF\"\nfp=(1.0/(2.0*math.pi*math.sqrt(0.4*0.078*pow(10,-12))))*pow(10,-6) ##Sqrt --> Complier to Complier differnce\nprint \"Therefore,fp(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217Ceq)=\",round(fp,3),\"MHz\"\ninc=((0.899-0.856)/0.856)*100\nprint \"(iii)%increase=\",round(inc,3),\"%\"\nq=(2*math.pi*0.4*0.856*pow(10,6))/(5*pow(10,3))\nprint \"(iv)Q=omegas\u2217L/R=2\u2217pi\u2217fs\u2217L/R=\",round(q,3)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "(i)fs(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217C)= 0.863 MHz\n(ii)Ceq(in pF)=C\u2217CM/C+CM= 0.078 pF\nTherefore,fp(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217Ceq)= 0.901 MHz\n(iii)%increase= 5.023 %\n(iv)Q=omegas\u2217L/R=2\u2217pi\u2217fs\u2217L/R= 430.273\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.11 Page No. 4-58", "cell_type": "markdown", "metadata": {}}, {"execution_count": 25, "cell_type": "code", "source": "import math\n\nprint(\"CM=2pF\")\nfs=(1/(2*math.pi*math.sqrt(2*0.01*pow(10,-12))))*pow(10,-6)\nprint \"Now fs(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217C)=\",round(fs,3),\"MHz\"\nprint \"Ceq(in F)=CM\u2217C/CM+C = (2*0.01*10^-24))/(2.01*10^-12)) = 9.95x10^-15\",\"F\"\nfp=(1/(2*math.pi*math.sqrt(2*9.95*pow(10,-15))))*pow(10,-6)\nprint \"fp=1/2\u2217pi\u2217sqrt(L\u2217Ceq)=\",round(fp,3),\"MHz\"\nprint(\"S of s and fp values are almost same.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "CM=2pF\nNow fs(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217C)= 1.125 MHz\nCeq(in F)=CM\u2217C/CM+C = (2*0.01*10^-24))/(2.01*10^-12)) = 9.95x10^-15 F\nfp=1/2\u2217pi\u2217sqrt(L\u2217Ceq)= 1.128 MHz\nS of s and fp values are almost same.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.12 Page No. 4-59", "cell_type": "markdown", "metadata": {}}, {"execution_count": 26, "cell_type": "code", "source": "import math\n\nprint(\"From the given information we can write,\")\nprint(\"A = \u221216\u221710\u02c66/j\u2217omegaandbeta=10\u02c63/[2\u221710\u02c63+j\u2217omega]\u02c62\")\nprint(\"To verify the Barkhausen condition means to verify whether|A\u2217beta|=1 at a frequency for which A\u2217beta=0 degree.Let us express,A\u2217beta in its rectangluar form.\")\nprint(\"A\u2217beta=\u221216\u221710\u02c66\u221710\u02c63/j\u2217omega\u2217[2\u221710\u02c63+j\u2217omega]\u02c62=\u221216\u221710\u02c69/j\u2217omega\u2217[4\u221710\u02c66+4\u221710\u02c63\u2217j\u2217omega+(j\u2217omega)\u02c62]\")\nprint(\"=\u221216\u221710\u02c69/j\u2217omega\u2217[4\u221710\u02c66+4\u221710\u02c63\u2217j\u2217omega\u2212omega\u02c62] as j\u22172=\u22121\")\nprint(\"=\u221216\u221710\u02c69/4\u221710\u02c66\u2217j\u2217omega+4\u221710\u02c63\u2217j\u02c62\u2217omega\u02c62\u2212j\u2217omega\u02c63]\")\nprint(\"=\u221216\u221710\u02c69/j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]\u2212[omega\u02c62\u22174\u221710\u02c63]\")\nprint(\"Rationalising the denominator function we get,\")\nprint(\"A\u2217beta=\u221216\u221710\u02c69[\u2212omega\u02c62\u22174\u221710\u02c63\u2212j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]]/[\u2212[omega\u02c62\u22174\u221710\u02c63]\u2212j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]]\u2217[\u2212omega\u02c62\u22174\u221710\u02c63\u2212j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]]\")\nprint(\"Using (a\u2212b)(a+b)=a\u02c62\u2212b\u02c62 in the denominator,\")\nprint(\"A\u2217beta=16\u221710\u02c69[omega\u02c62\u22174\u221710\u02c63+j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]]/[\u2212omega\u02c62\u22174\u221710\u02c63]\u02c62\u2212[j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]\u02c62\")\nprint(\"A\u2217beta=16\u221710\u02c69[omega\u02c62\u22174\u221710\u02c63+j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]]/16\u221710\u02c66\u2217omega\u02c64+omega\u02c62(4\u221710\u02c66\u2212omega\u02c62)\u02c62\")\nprint(\"Now to have A\u2217beta=0degree,the imaginary part of A\u2217beta must be zero.This is possible when,\")\nprint(\"Therefore,omega\u2217(4\u221710\u02c66\u2212omega\u02c62)=0\")\nprint(\"Therefore,omega=0 or 4\u221710\u02c66\u2212omega\u02c62=0\")\nprint(\"Therefore,omega\u02c62=4\u221710\u02c66 Neglecting zero value of frequency\")\nprint(\"Therefore,omega=2\u221710\u02c63rad/sec\")\nprint(\"At this frequency |A\u2217beta| can be obtained as,\")\nprint(\"|A\u2217beta| = 16\u221710\u02c69[4\u221710\u02c63\u2217omega\u02c62]/16\u221710\u02c66\u2217omega\u02c64+omega\u02c62[4\u221710\u02c66\u2212omega\u02c62]\u02c62atomega=2\u221710\u02c63\")\nab=(2.56*pow(10,20))/(2.56*pow(10,20))\nprint \"|A\u2217beta|=\",round(ab,1)\nprint(\"Therefore,At omega=2\u221710\u02c63rad/sec,A\u2217beta = 0 degree as imaginary part is zero while |A\u2217beta|=1.Thus Barkhausen Criterion is satisfied.\")\nprint(\"The frequency at which circuit will oscillate is the value of omega for which|A\u2217beta| = 1 and A\u2217beta=0 degree at the same time\")\nprint(\"i.e.omega=2\u221710\u02c63rad/sec\")\nprint(\"But omega=2\u2217pi\u2217f\")\nf=(2.0*pow(10,3))/(2.0*math.pi)\nprint \"Therefore,f(in Hz)=omega/2pi=\",round(f,3),\"Hz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "From the given information we can write,\nA = \u221216\u221710\u02c66/j\u2217omegaandbeta=10\u02c63/[2\u221710\u02c63+j\u2217omega]\u02c62\nTo verify the Barkhausen condition means to verify whether|A\u2217beta|=1 at a frequency for which A\u2217beta=0 degree.Let us express,A\u2217beta in its rectangluar form.\nA\u2217beta=\u221216\u221710\u02c66\u221710\u02c63/j\u2217omega\u2217[2\u221710\u02c63+j\u2217omega]\u02c62=\u221216\u221710\u02c69/j\u2217omega\u2217[4\u221710\u02c66+4\u221710\u02c63\u2217j\u2217omega+(j\u2217omega)\u02c62]\n=\u221216\u221710\u02c69/j\u2217omega\u2217[4\u221710\u02c66+4\u221710\u02c63\u2217j\u2217omega\u2212omega\u02c62] as j\u22172=\u22121\n=\u221216\u221710\u02c69/4\u221710\u02c66\u2217j\u2217omega+4\u221710\u02c63\u2217j\u02c62\u2217omega\u02c62\u2212j\u2217omega\u02c63]\n=\u221216\u221710\u02c69/j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]\u2212[omega\u02c62\u22174\u221710\u02c63]\nRationalising the denominator function we get,\nA\u2217beta=\u221216\u221710\u02c69[\u2212omega\u02c62\u22174\u221710\u02c63\u2212j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]]/[\u2212[omega\u02c62\u22174\u221710\u02c63]\u2212j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]]\u2217[\u2212omega\u02c62\u22174\u221710\u02c63\u2212j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]]\nUsing (a\u2212b)(a+b)=a\u02c62\u2212b\u02c62 in the denominator,\nA\u2217beta=16\u221710\u02c69[omega\u02c62\u22174\u221710\u02c63+j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]]/[\u2212omega\u02c62\u22174\u221710\u02c63]\u02c62\u2212[j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]\u02c62\nA\u2217beta=16\u221710\u02c69[omega\u02c62\u22174\u221710\u02c63+j\u2217omega\u2217[4\u221710\u02c66\u2212omega\u02c62]]/16\u221710\u02c66\u2217omega\u02c64+omega\u02c62(4\u221710\u02c66\u2212omega\u02c62)\u02c62\nNow to have A\u2217beta=0degree,the imaginary part of A\u2217beta must be zero.This is possible when,\nTherefore,omega\u2217(4\u221710\u02c66\u2212omega\u02c62)=0\nTherefore,omega=0 or 4\u221710\u02c66\u2212omega\u02c62=0\nTherefore,omega\u02c62=4\u221710\u02c66 Neglecting zero value of frequency\nTherefore,omega=2\u221710\u02c63rad/sec\nAt this frequency |A\u2217beta| can be obtained as,\n|A\u2217beta| = 16\u221710\u02c69[4\u221710\u02c63\u2217omega\u02c62]/16\u221710\u02c66\u2217omega\u02c64+omega\u02c62[4\u221710\u02c66\u2212omega\u02c62]\u02c62atomega=2\u221710\u02c63\n|A\u2217beta|= 1.0\nTherefore,At omega=2\u221710\u02c63rad/sec,A\u2217beta = 0 degree as imaginary part is zero while |A\u2217beta|=1.Thus Barkhausen Criterion is satisfied.\nThe frequency at which circuit will oscillate is the value of omega for which|A\u2217beta| = 1 and A\u2217beta=0 degree at the same time\ni.e.omega=2\u221710\u02c63rad/sec\nBut omega=2\u2217pi\u2217f\nTherefore,f(in Hz)=omega/2pi= 318.31 Hz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.13 Page No. 4-60", "cell_type": "markdown", "metadata": {}}, {"execution_count": 28, "cell_type": "code", "source": "import math\n\nprint(\"The frequency of the oscillator is given by,\")\nprint(\"f=1/2\u2217pi\u2217sqrt(R1\u2217R2\u2217C1\u2217C2)\")\nprint(\"For f=20kHz,\")\nr2=(1/(4*(pow(math.pi,2))*(pow((20*pow(10,3)),2))*(10*pow(10,3))*(pow((0.001*pow(10,-6)),2))))*pow(10,-3)\nprint \"Therefore,R2(in kohm)=\",round(r2,2),\"KOhm\"\nprint(\"For f=70kHz,\")\nr2=(1/(4*(pow(math.pi,2))*(pow((70*pow(10,3)),2))*(10*pow(10,3))*(pow((0.001*pow(10,-6)),2))))*pow(10,-3)\nprint \"Therefore,R2(in kohm)=\",round(r2,3),\"KOhm\"\nprint(\"So minimum value of R2 is 0.517kohm while the maximum value of R2 is 6.33kohm\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The frequency of the oscillator is given by,\nf=1/2\u2217pi\u2217sqrt(R1\u2217R2\u2217C1\u2217C2)\nFor f=20kHz,\nTherefore,R2(in kohm)= 6.33 KOhm\nFor f=70kHz,\nTherefore,R2(in kohm)= 0.517 KOhm\nSo minimum value of R2 is 0.517kohm while the maximum value of R2 is 6.33kohm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.14 Page No. 4-61", "cell_type": "markdown", "metadata": {}}, {"execution_count": 30, "cell_type": "code", "source": "import math\n\nprint(\"R=6kohm, C=1500pF, RC=18kohm\")\nk=18/6\nprint \"Now K=RC/R=\",round(k,1)\nprint(\"Therefore,f=1/2\u2217pi\u2217R\u2217C\u2217sqrt(6+4K)\")\nf=(1/(2*math.pi*(6*pow(10,3))*(1500*pow(10,-12))*math.sqrt(6+12)))*pow(10,-3)\nprint \"f(in kHz)=\",round(f,3),\"KHz\"\nhfe=(4.0*3.0)+23.0+(29.0/3.0)\nprint \"(hfe)min =4K+23+29/K=\",round(hfe,2)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "R=6kohm, C=1500pF, RC=18kohm\nNow K=RC/R= 3.0\nTherefore,f=1/2\u2217pi\u2217R\u2217C\u2217sqrt(6+4K)\nf(in kHz)= 4.168 KHz\n(hfe)min =4K+23+29/K= 44.67\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.15 Page No. 4-61", "cell_type": "markdown", "metadata": {}}, {"execution_count": 32, "cell_type": "code", "source": "import math\n\nprint(\"For a Wien bridge oscillator,\")\nprint(\"f=1/2\u2217pi\u2217R\u2217C\")\nfm=(1/(2*(math.pi)*(100*pow(10,3))*(50*pow(10,-12))))*pow(10,-3)\nprint \"Therefore,fmax(in kHz)=\",round(fm,2),\"KHz\"\nfmi=(1/(2*(math.pi)*(100*pow(10,3))*(500*pow(10,-12))))*pow(10,-3)\nprint \"and fmin(in kHz)=\",round(fmi,3),\"KHz\"\nfn=31.83+50\nprint \"Now fnew(in kHz)=fmax+50\u221710\u02c63=\",round(fn,2),\"KHz\"\nprint(\"The corresponding R=R\u2019\u2019 with an additional resistance Rx in parallel\")\nprint(\"Therefore,f=1/2\u2217pi\u2217R\u2019\u2019\u2217C\")\nr=(1/(2*(math.pi)*(50*pow(10,-12))*(81.83*pow(10,3))))*pow(10,-3)\nprint \"Therefore,R\u2019\u2019(in kohm)=\",round(r,2),\"KOhm\"\nrx=1.0/((1.0/38.89)-(1.0/100.0))\nprint(\"Therefore,R\u2019\u2019 = R\u2217Rx/R+Rx\")\nprint \"Therefore,Rx(in kohm) = in parallel with 100 kohm\",round(rx,2),\"KOhm\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For a Wien bridge oscillator,\nf=1/2\u2217pi\u2217R\u2217C\nTherefore,fmax(in kHz)= 31.83 KHz\nand fmin(in kHz)= 3.183 KHz\nNow fnew(in kHz)=fmax+50\u221710\u02c63= 81.83 KHz\nThe corresponding R=R\u2019\u2019 with an additional resistance Rx in parallel\nTherefore,f=1/2\u2217pi\u2217R\u2019\u2019\u2217C\nTherefore,R\u2019\u2019(in kohm)= 38.9 KOhm\nTherefore,R\u2019\u2019 = R\u2217Rx/R+Rx\nTherefore,Rx(in kohm) = in parallel with 100 kohm 63.64 KOhm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.16 Page No. 4-62", "cell_type": "markdown", "metadata": {}}, {"execution_count": 33, "cell_type": "code", "source": "import math\n\nprint(\"For a Hartley oscillator the frequency is given by,\")\nprint(\"f=1/2\u2217pi\u2217sqrt(Leq\u2217C)whereLeq=L1+L2\")\nleq=20+5\nprint \"Therefore,Leq(in mH)=20+5=\",round(leq,0),\"mH\"\nf=(1/(2*(math.pi)*math.sqrt(25*500*pow(10,-15))))*pow(10,-3)\nprint \"Therefore,f(in kHz)=\",round(f,2),\"KHz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For a Hartley oscillator the frequency is given by,\nf=1/2\u2217pi\u2217sqrt(Leq\u2217C)whereLeq=L1+L2\nTherefore,Leq(in mH)=20+5= 25.0 mH\nTherefore,f(in kHz)= 45.02 KHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.17 Page No. 4-62", "cell_type": "markdown", "metadata": {}}, {"execution_count": 35, "cell_type": "code", "source": "import math\n\nprint(\"For a Hartley oscillator,\")\nprint(\"f=1/2\u2217pi\u2217sqrt(Leq\u2217C) where Leq=L1+L2+2M\")\nleq=(1/(4*(pow((math.pi),2))*(pow((168*pow(10,3)),2))*(50*pow(10,-12))))*pow(10,3)\nprint \"Therefore,Leq(in mH)=\",round(leq,2),\"mH\"\nl2=((17.95*pow(10,-3))-(15*pow(10,-3))-(5*pow(10,-6)))*pow(10,3)\nprint \"Therefore,L2(in mH)=\",round(l2,3),\"mH\"\nhfe=((15*pow(10,-3))+(5*pow(10,-6)))/((2.945*pow(10,-3))+(5*pow(10,-6)))\nprint \"Now hfe=L1+M/L2+M=\",round(hfe,2)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For a Hartley oscillator,\nf=1/2\u2217pi\u2217sqrt(Leq\u2217C) where Leq=L1+L2+2M\nTherefore,Leq(in mH)= 17.95 mH\nTherefore,L2(in mH)= 2.945 mH\nNow hfe=L1+M/L2+M= 5.09\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.18 Page No. 4-63", "cell_type": "markdown", "metadata": {}}, {"execution_count": 37, "cell_type": "code", "source": "import math\n\nprint(\"For a Colpitts oscillator,\")\nprint(\"f=1/2\u2217pi\u2217sqrt(L\u2217Ceq)\")\nprint(\"where Ceq=C1\u2217C2/C1+C2 but C1=C2=0.001uF\")\nceq=(pow((0.001*pow(10,-6)),2))/(2*(0.001*pow(10,-6)))\nprint \"Therefore,Ceq(in F)=\",ceq,\"F\"\nprint(\"L=5\u221710\u02c6\u22126H\")\nf=(1/(2*(math.pi)*math.sqrt(25*pow(10,-16))))*pow(10,-6)\nprint \"Therefore,f(in MHz)=\",round(f,3),\"MHz\"\nprint(\"Now L is doubled i.e. 10uH\")\nf1=(1/(2*(math.pi)*math.sqrt(50*pow(10,-16))))*pow(10,-6) \nprint \"Therefore,f(in MHz)=\",round(f1,2),\"MHz\"\nnf=2*3.183\nprint \"New frequency(in MHz)=2\u22173.183=\",round(nf,3),\"MHz\"\nl=(1/(4*(pow((math.pi),2))*(pow((6.366*pow(10,6)),2))*(5*pow(10,-10))))*pow(10,6)\nprint \"Therefore,L(in uH)=\",round(l,2),\"uH\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For a Colpitts oscillator,\nf=1/2\u2217pi\u2217sqrt(L\u2217Ceq)\nwhere Ceq=C1\u2217C2/C1+C2 but C1=C2=0.001uF\nTherefore,Ceq(in F)= 5e-10 F\nL=5\u221710\u02c6\u22126H\nTherefore,f(in MHz)= 3.183 MHz\nNow L is doubled i.e. 10uH\nTherefore,f(in MHz)= 2.25 MHz\nNew frequency(in MHz)=2\u22173.183= 6.366 MHz\nTherefore,L(in uH)= 1.25 uH\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.19 Page No. 4-64", "cell_type": "markdown", "metadata": {}}, {"execution_count": 38, "cell_type": "code", "source": "import math\n\nprint(\"For a Clapp oscillator,\")\nprint(\"f=1/2\u2217pi\u2217sqrt(L\u2217C3)\")\nprint(\"where C3=63pF\")\nf=(1/(2*(math.pi)*math.sqrt(315*pow(10,-18))))*pow(10,-6)\nprint \"Therefore,f(in MHz)=\",round(f,3),\"MHz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For a Clapp oscillator,\nf=1/2\u2217pi\u2217sqrt(L\u2217C3)\nwhere C3=63pF\nTherefore,f(in MHz)= 8.967 MHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.20 Page No. 4-64", "cell_type": "markdown", "metadata": {}}, {"execution_count": 41, "cell_type": "code", "source": "import math\n\nprint(\"Refering to equation(1) of section4.5.3, the input impedance is given by,\")\nprint(\"R\u2019\u2019i=R1||R2||hie\")\nprint(\"Now R1=25k\u2212ohm,R2=47k\u2212ohm,and hie=2k\u2212ohm\")\nri=(25.0*47.0*2.0)/((47.0*2.0)+(25.0*2.0)+(25.0*47.0))\nprint \"Therefore,R\u2019\u2019i(inkohm)=\",round(ri,4),\"KOhm\"\nprint(\"K=RC/R\")\nprint(\"Now RC=10kohm...given\")\nprint(\"Now f=1/2\u2217pi\u2217R\u2217C\u2217sqrt(6+4K)\")\nprint(\"Therefore,R\u2217sqrt(6+4K)=31830.989\")\nprint(\"Now K=RC/R=10\u221710\u02c63/R\")\nprint(\"Therefore,R\u2217sqrt(6+(40\u221710\u221710\u02c63/R))=31830.989\")\nprint(\"Therefore,R\u02c62\u2217(6+(40\u221710\u221710\u02c63/R))=(31830.989)\u02c62\")\nprint(\"Therefore,R = (-40x10^3 +- sqrt((40x10^3)^2) + 4x6x(31830.989)^2)/(2x6)\")\nprint(\"Therefore R = 16.74 KOhm ...... Neglecting the negative values\") \nk = 10.0/16.74\nprint \"Therefore,K = RC/R = \",round(k,4)\nprint(\"Therefore,hfe >= 4K+23+29/K\")\nhfe=(4.0*0.5973)+23.0+(29.0/0.5973)\nprint \"hfe >=\",round(hfe,2)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Refering to equation(1) of section4.5.3, the input impedance is given by,\nR\u2019\u2019i=R1||R2||hie\nNow R1=25k\u2212ohm,R2=47k\u2212ohm,and hie=2k\u2212ohm\nTherefore,R\u2019\u2019i(inkohm)= 1.7817 KOhm\nK=RC/R\nNow RC=10kohm...given\nNow f=1/2\u2217pi\u2217R\u2217C\u2217sqrt(6+4K)\nTherefore,R\u2217sqrt(6+4K)=31830.989\nNow K=RC/R=10\u221710\u02c63/R\nTherefore,R\u2217sqrt(6+(40\u221710\u221710\u02c63/R))=31830.989\nTherefore,R\u02c62\u2217(6+(40\u221710\u221710\u02c63/R))=(31830.989)\u02c62\nTherefore,R = (-40x10^3 +- sqrt((40x10^3)^2) + 4x6x(31830.989)^2)/(2x6)\nTherefore R = 16.74 KOhm ...... Neglecting the negative values\nTherefore,K = RC/R = 0.5974\nTherefore,hfe >= 4K+23+29/K\nhfe >= 73.94\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.21 Page No. 4-65", "cell_type": "markdown", "metadata": {}}, {"execution_count": 42, "cell_type": "code", "source": "import math\n\nprint(\"The frequency is given by,\")\nprint(\"f=1/2\u2217pi\u2217R\u2217C\")\nprint(\"Let the resistance value to be selected as,\")\nprint(\"R1=R2=R=50kohm\")\nprint(\"f=1/2\u2217pi\u221750\u221710\u02c63\u2217C\")\nf=(1/(2*(math.pi)*(50*pow(10,3))*100))*pow(10,9)\nprint \"f(in nF)=\",round(f,2),\"nF\"\nprint(\"and fmax=1/2\u2217pi\u221750\u221710\u02c63\u2217C\")\nc=(1/(2*(math.pi)*(50*pow(10,3))*(10*pow(10,3))))*pow(10,9)\nprint \"C(in nF)=\",round(c,3),\"nF\"\nprint(\"Thus to vary the frequency from 100Hz to 10kHz,the capacitor range should be selected as 0.318nF to 31.83nF\")\nprint(\"Similarly keeping the capacitor value constant,the range of the resistance values can be obtained.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The frequency is given by,\nf=1/2\u2217pi\u2217R\u2217C\nLet the resistance value to be selected as,\nR1=R2=R=50kohm\nf=1/2\u2217pi\u221750\u221710\u02c63\u2217C\nf(in nF)= 31.83 nF\nand fmax=1/2\u2217pi\u221750\u221710\u02c63\u2217C\nC(in nF)= 0.318 nF\nThus to vary the frequency from 100Hz to 10kHz,the capacitor range should be selected as 0.318nF to 31.83nF\nSimilarly keeping the capacitor value constant,the range of the resistance values can be obtained.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.22 Page No. 4-66", "cell_type": "markdown", "metadata": {}}, {"execution_count": 43, "cell_type": "code", "source": "import math\n\nprint(\"f=2.5MHz, L=10uH, C1=0.02uF\")\nprint(\"For Colpitts oscillator,the frequency is given by,\")\nprint(\"f=1/2pi\u2217sqrt(L\u2217Ceq)\")\nceq=(1/(4*(pow((math.pi),2))*(pow((2.5*pow(10,6)),2))*(10*pow(10,-6))))*pow(10,12)\nprint \"Therefore,Ceq(in pF)=\",round(ceq,3),\"pF\"\nprint(\"(i)But Ceq=C1\u2217C2/C1+C2\")\nc2=((0.02*pow(10,-6))/49.348)*pow(10,9)\nprint \"Therefore,C2(in nF)=\",round(c2,4),\"nF\"\nprint(\"(ii)L=2\u221710=20uH\")\nprint(\"and Ceq=405.284pF\")\nf=(1/(2*(math.pi)*math.sqrt(20*405.284*pow(10,-18))))*pow(10,-6)\nprint \"f(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217Ceq)=\",round(f,4),\"MHz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "f=2.5MHz, L=10uH, C1=0.02uF\nFor Colpitts oscillator,the frequency is given by,\nf=1/2pi\u2217sqrt(L\u2217Ceq)\nTherefore,Ceq(in pF)= 405.285 pF\n(i)But Ceq=C1\u2217C2/C1+C2\nTherefore,C2(in nF)= 0.4053 nF\n(ii)L=2\u221710=20uH\nand Ceq=405.284pF\nf(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217Ceq)= 1.7678 MHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.23 Page No. 4-67", "cell_type": "markdown", "metadata": {}}, {"execution_count": 44, "cell_type": "code", "source": "import math\n\nf=(1/(2*math.pi*math.sqrt(0.33*0.065*pow(10,-12))))*pow(10,-6)\nprint \"(i)f(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217C)=\",round(f,3),\"MHz\"\nceq=0.065/1.065\nprint \"(ii)Ceq(in pF)=C\u2217CM/C+CM=\",round(ceq,3),\"pF\"\nfp=(1/(2*(math.pi)*math.sqrt(0.33*0.061*pow(10,-12))))*pow(10,-6)\nprint \"(iii)fp(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217Ceq)=\",round(fp,3),\"MHz\"\npi=((1.121-1.087)/1.087)*100\nprint \"(iii)%increase=\",round(pi,3),\"%\"\nq=(2*(math.pi)*1.087*0.33*pow(10,6))/(5.5*pow(10,3))\nprint \"(iv)Q=omegax\u2217L/R=2\u2217pi\u2217fs\u2217L/R=\",round(q,3)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "(i)f(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217C)= 1.087 MHz\n(ii)Ceq(in pF)=C\u2217CM/C+CM= 0.061 pF\n(iii)fp(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217Ceq)= 1.122 MHz\n(iii)%increase= 3.128 %\n(iv)Q=omegax\u2217L/R=2\u2217pi\u2217fs\u2217L/R= 409.789\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.24 Page No. 4-68", "cell_type": "markdown", "metadata": {}}, {"execution_count": 45, "cell_type": "code", "source": "import math\n\nprint(\"(i)Assume one particular coupling direction for which,\")\nprint(\"Leq=L1+L2+2M=0.25mH\")\nf=(1/(2*(math.pi)*math.sqrt(0.25*100*pow(10,-15))))*pow(10,-6)\nprint \"Therefore,f(in MHz)=1/2\u2217pi\u2217sqrt(Leq\u2217C)=\",round(f,5),\"MHz\"\nprint(\"Let the direction of coupling is reversed,\")\nprint(\"Leq=L1+L2\u22122M=0.15mH\")\nfd=(1/(2*(math.pi)*math.sqrt(0.15*100*pow(10,-15))))*pow(10,-6)\nprint \"Therefore,f\u2019\u2019(in MHz)=1/2\u2217pi\u2217sqrt(Leq\u2217C)=\",round(fd,4),\"MHz\"\npc=((1.2994-1.00658)/1.00658)*100\nprint \"Therefore, %change = f\u2019\u2019\u2212f/f\u2217100=\",round(pc,2),\"%\"\nprint(\"(ii)Let us assume direction of coupling such that,\")\nprint(\"Leq=L1+L2+2M=0.25mH\")\nprint(\"Ct=Trimcapacitor=100pF\")\nprint(\"Therefore,Ceq=C\u2217Ct/C+Ct=50pF\")\nf1=(1/(2*(math.pi)*math.sqrt(0.25*50*pow(10,-15))))*pow(10,-6)\nprint \"Therefore,f=1/2\u2217pi\u2217sqrt(Leq\u2217Ceq)=\",round(f1,4),\"MHz\"\nprint(\"If now direction of coupling is reversed,\")\nprint(\"Leq=L1+L2\u22122M=0.15mH\")\nf2=(1/(2*(math.pi)*math.sqrt(0.15*50*pow(10,-15))))*pow(10,-6)\nprint \"Therefore,f\u2019\u2019=1/2\u2217pi\u2217sqrt(Leq\u2217Ceq)=\",round(f2,5),\"MHz\"\npc1=((1.83776-1.4235)/1.4235)*100\nprint \"Therefore,%change=f\u2019\u2019\u2212f/f\u2217100=\",round(pc1,3),\"%\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "(i)Assume one particular coupling direction for which,\nLeq=L1+L2+2M=0.25mH\nTherefore,f(in MHz)=1/2\u2217pi\u2217sqrt(Leq\u2217C)= 1.00658 MHz\nLet the direction of coupling is reversed,\nLeq=L1+L2\u22122M=0.15mH\nTherefore,f\u2019\u2019(in MHz)=1/2\u2217pi\u2217sqrt(Leq\u2217C)= 1.2995 MHz\nTherefore, %change = f\u2019\u2019\u2212f/f\u2217100= 29.09 %\n(ii)Let us assume direction of coupling such that,\nLeq=L1+L2+2M=0.25mH\nCt=Trimcapacitor=100pF\nTherefore,Ceq=C\u2217Ct/C+Ct=50pF\nTherefore,f=1/2\u2217pi\u2217sqrt(Leq\u2217Ceq)= 1.4235 MHz\nIf now direction of coupling is reversed,\nLeq=L1+L2\u22122M=0.15mH\nTherefore,f\u2019\u2019=1/2\u2217pi\u2217sqrt(Leq\u2217Ceq)= 1.83776 MHz\nTherefore,%change=f\u2019\u2019\u2212f/f\u2217100= 29.102 %\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.25 Page No. 4-69", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "import math\n\nprint(\"For RC phase shift oscillator,\")\nprint(\"hfe=4K+23+29/K...given hfe=150\")\nprint(\"Therefore,150 = 4K+23+29/K\")\nprint(\"Therefore,4K\u02c62\u2212127K+29 = 0\")\nprint(\"Therefore,K= 31.52,0.23\")\nprint(\"f=1/2\u2217pi\u2217R\u2217C\u2217sqrt(6+4K)...givenf=5kHz\")\nprint(\"Therefore,Choose C=100pF\")\nr=(1/(2*(math.pi)*(1000*pow(10,-12))*(5*pow(10,3))*math.sqrt(6+(4*0.23))))*pow(10,-3)\nprint \"Therefore,R(in kohm)=\",round(r,0),\"KOhm\"\nprint(\"K=RC/R i.e. RC=K R = 2.7kohm\")\nprint(\"Neglecting effect of biasing resistances assuming them to be large and selecting transistor with hie=2kohm\")\nprint(\"R\u2019\u2019i =hie =2kohm\")\nprint(\"Therefore,Last resistance in phase network\")\nr3=12-2\nprint \"R3=R\u2212R\u2019\u2019i=\",round(r3,0),\"KOhm\"\nprint(\"Using the backtoback connected zener diodes of 9.3V(Vz) each at the output of emitter follower and using this at the output of the oscillator,the output amplitude can be controlled to 10V i.e. 20Vpeaktopeak. The zener diode 9.3V and forward biased diode of 0.7V gives to tal 10V\")\nprint(\"The designed circuit is shown in fig.4.49\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For RC phase shift oscillator,\nhfe=4K+23+29/K...given hfe=150\nTherefore,150 = 4K+23+29/K\nTherefore,4K\u02c62\u2212127K+29 = 0\nTherefore,K= 31.52,0.23\nf=1/2\u2217pi\u2217R\u2217C\u2217sqrt(6+4K)...givenf=5kHz\nTherefore,Choose C=100pF\nTherefore,R(in kohm)= 12.0 KOhm\nK=RC/R i.e. RC=K R = 2.7kohm\nNeglecting effect of biasing resistances assuming them to be large and selecting transistor with hie=2kohm\nR\u2019\u2019i =hie =2kohm\nTherefore,Last resistance in phase network\nR3=R\u2212R\u2019\u2019i= 10.0 KOhm\nUsing the backtoback connected zener diodes of 9.3V(Vz) each at the output of emitter follower and using this at the output of the oscillator,the output amplitude can be controlled to 10V i.e. 20Vpeaktopeak. The zener diode 9.3V and forward biased diode of 0.7V gives to tal 10V\nThe designed circuit is shown in fig.4.49\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.26 Page No. 4-70", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "import math\n\nprint(\"L1=20uH, L2=2mH\")\nleq=((20.0*pow(10,-6))+(2.0*pow(10,-3)))*pow(10,3)\nprint \"Therefore,Leq(in mH)=L1+L2=\",round(leq,3),\"x 10^-3 H\"\nprint(\"For f = fmax = 2.5 MHz\")\nprint(\"f=1/2\u2217pi\u2217sqrt(C\u2217Leq)\")\nc=(1/(4*(pow((math.pi),2))*(pow((2.5*pow(10,6)),2))*(2.002*pow(10,-3))))*pow(10,12)\nprint \"Therefore,C(in pF)=\",round(c,4),\"pF\"\nprint(\"For f=fmin=1MHz\")\nprint(\"f=1/2\u2217pi\u2217sqrt(C\u2217Leq)\")\nc1=(1/(4*(pow((math.pi),2))*(pow((1*pow(10,6)),2))*(2.002*pow(10,-3))))*pow(10,12)\nprint \"Therefore,C(in pF)=\",round(c1,4),\"pF\"\nprint(\"Thus C must be varied from 2.0244pF to 12.6525pF\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "L1=20uH, L2=2mH\nTherefore,Leq(in mH)=L1+L2= 2.02 x 10^-3 H\nFor f = fmax = 2.5 MHz\nf=1/2\u2217pi\u2217sqrt(C\u2217Leq)\nTherefore,C(in pF)= 2.0244 pF\nFor f=fmin=1MHz\nf=1/2\u2217pi\u2217sqrt(C\u2217Leq)\nTherefore,C(in pF)= 12.6525 pF\nThus C must be varied from 2.0244pF to 12.6525pF\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4.27 Page No. 4-71", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "import math\n\nceq = (0.02*12*(math.pow(10,-24))/(12.02*pow(10,-12)))*pow(10,12)\nprint \"Ceq(in pF)=C1\u2217C2/C1+C2=\",round(ceq,5),\"pF\"\nfs=(1/(2*(math.pi)*math.sqrt(50*0.02*pow(10,-15))))*pow(10,-6)\nprint \"Therefore,fs(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217C1)=\",round(fs,4),\"MHz\"\nfp=(1/(2*(math.pi)*math.sqrt(50*0.01996*pow(10,-15))))*pow(10,-6)\nprint \"Therefore,fp(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217Ceq)=\",round(fp,4),\"MHz\"\nprint(\"Let Cs=5pF connected across the crystal\")\nc2=12+5\nprint \"Therefore,C\u2019\u20192(in pF)=C2+Cx=\",round(c2,0),\"pF\"\nceq1=0.019976\nprint \"Therefore,C\u2019\u2019eq(in pF)=C1\u2217C\u2019\u20192/C1+C\u2019\u20192=\",round(ceq1,6),\"pF\"\nfp1=5.03588\nprint \"Therefore,f\u2019\u2019p(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217Ceq)=\",round(fp1,5),\"MHz\"\nprint(\"New Cx=6pF is connected then,\")\nc21=12+6\nprint \"C\u2019\u2019\u2019\u20192(in pF)=C2+Cx=\",round(c21,0),\"pF\"\nceq2=0.0199778\nprint \"Therefore,C\u2019\u2019\u2019\u2019eq(in pF)=C1\u2217C\u2019\u2019\u2019\u20192/C1+C\u2019\u2019\u2019\u20192=\",round(ceq2,7),\"pF\"\nfp2=5.035716\nprint \"Therefore,f\u2019\u2019\u2019\u2019p(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217C\u2019\u2019\u2019\u2019eq)=\",round(fp2,6),\"MHz\"\nc=(5.03588-5.035716)*pow(10,6)\nprint \"Therefore,Change(in Hz)=f\u2019\u2019p\u2212f\u2019\u2019\u2019\u2019p=\",round(c,0),\"Hz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Ceq(in pF)=C1\u2217C2/C1+C2= 0.01997 pF\nTherefore,fs(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217C1)= 5.0329 MHz\nTherefore,fp(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217Ceq)= 5.038 MHz\nLet Cs=5pF connected across the crystal\nTherefore,C\u2019\u20192(in pF)=C2+Cx= 17.0 pF\nTherefore,C\u2019\u2019eq(in pF)=C1\u2217C\u2019\u20192/C1+C\u2019\u20192= 0.019976 pF\nTherefore,f\u2019\u2019p(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217Ceq)= 5.03588 MHz\nNew Cx=6pF is connected then,\nC\u2019\u2019\u2019\u20192(in pF)=C2+Cx= 18.0 pF\nTherefore,C\u2019\u2019\u2019\u2019eq(in pF)=C1\u2217C\u2019\u2019\u2019\u20192/C1+C\u2019\u2019\u2019\u20192= 0.0199778 pF\nTherefore,f\u2019\u2019\u2019\u2019p(in MHz)=1/2\u2217pi\u2217sqrt(L\u2217C\u2019\u2019\u2019\u2019eq)= 5.035716 MHz\nTherefore,Change(in Hz)=f\u2019\u2019p\u2212f\u2019\u2019\u2019\u2019p= 164.0 Hz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter5.ipynb b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter5.ipynb
new file mode 100755
index 00000000..cd33b3de
--- /dev/null
+++ b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter5.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 5", "cell_type": "markdown", "metadata": {}}, {"source": "# Combinational Logic Circuits", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 5.1 Page No. 5-2", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "print(\"Given problem specific that there are three input variables and one output variable. We assign A, B and C letter symbols to three input variables and assign Y letter symbol to one output variable. The relationship between input variables and output variable can be tabulated as shown in truth table 5.1\")\nprint (\" A B C Y\")\nprint (\" 0 0 0 0 \")\nprint (\" 0 0 1 0 \")\nprint (\" 0 1 0 0 \")\nprint (\" 0 1 1 1 \")\nprint (\" 1 0 0 0 \")\nprint (\" 1 0 1 1 \")\nprint (\" 1 1 0 1 \")\nprint (\" 1 1 1 1 \")\nprint (\"Now we obtain the simplified Boolean expression for output variable Y using K\u2212map simplification.\")\nprint (\"BC BC\u2019\u2019 B\u2019\u2019C\u2019\u2019 B\u2019\u2019C\")\nprint (\"A 0 0 1 0\")\nprint (\"A\u2019\u2019 0 1 1 1 \")\nprint (\"Y = AC + BC + AB\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Given problem specific that there are three input variables and one output variable. We assign A, B and C letter symbols to three input variables and assign Y letter symbol to one output variable. The relationship between input variables and output variable can be tabulated as shown in truth table 5.1\n A B C Y\n 0 0 0 0 \n 0 0 1 0 \n 0 1 0 0 \n 0 1 1 1 \n 1 0 0 0 \n 1 0 1 1 \n 1 1 0 1 \n 1 1 1 1 \nNow we obtain the simplified Boolean expression for output variable Y using K\u2212map simplification.\nBC BC\u2019\u2019 B\u2019\u2019C\u2019\u2019 B\u2019\u2019C\nA 0 0 1 0\nA\u2019\u2019 0 1 1 1 \nY = AC + BC + AB\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.2 Page No. 5-3 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "print (\"The truth table for the given problem is as shown below.\")\nprint (\" C D3 D2 D1 Output \")\nprint (\" 0 x x x 0 \")\nprint (\" 0 0 0 0 0 \")\nprint (\" 0 0 0 1 1 \")\nprint (\" 0 0 1 0 1 \")\nprint (\" 0 1 0 0 1 \")\nprint (\" \")\nprint (\"K\u2212map simplification\")\nprint (\"D1\u2019\u2019D2\u2019\u2019 D1\u2019\u2019D2 D1D2 D1D2\u2019\u2019\")\nprint (\"C\u2019\u2019D3\u2019\u2019 0 0 0 0 \")\nprint (\"C\u2019\u2019D3 0 0 0 0 \")\nprint (\"CD3 1 X X X\")\nprint (\"CD3\u2019\u2019 0 1 X 1\")\nprint (\" \")\nprint (\"Therefore, Y = CD3 + CD2 + CD1\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The truth table for the given problem is as shown below.\n C D3 D2 D1 Output \n 0 x x x 0 \n 0 0 0 0 0 \n 0 0 0 1 1 \n 0 0 1 0 1 \n 0 1 0 0 1 \n \nK\u2212map simplification\nD1\u2019\u2019D2\u2019\u2019 D1\u2019\u2019D2 D1D2 D1D2\u2019\u2019\nC\u2019\u2019D3\u2019\u2019 0 0 0 0 \nC\u2019\u2019D3 0 0 0 0 \nCD3 1 X X X\nCD3\u2019\u2019 0 1 X 1\n \nTherefore, Y = CD3 + CD2 + CD1\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.3 Page No. 5-4 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "print (\"Truth table\")\nprint (\"Input Output\")\nprint (\"Decimal Digit Digit1 Digit0\")\nprint (\"A B C D Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0\")\nprint (\"0 0 0 0 0 0 0 0 0 0 0 0 \")\nprint (\"0 0 0 1 0 0 0 0 0 1 0 1 \")\nprint (\"0 0 1 0 0 0 0 1 0 0 0 0 \")\nprint (\"0 0 1 1 0 0 0 1 0 1 0 1 \")\nprint (\"0 1 0 0 0 0 1 0 0 0 0 0 \")\nprint (\"0 1 0 1 0 0 1 0 0 1 0 1 \")\nprint (\"0 1 1 0 0 0 1 1 0 0 0 0 \")\nprint (\"0 1 1 1 0 0 1 1 0 1 0 1 \")\nprint (\"1 0 0 0 0 1 0 0 0 0 0 0 \")\nprint (\"1 0 0 1 0 1 0 0 0 1 0 1 \")\nprint (\" \")\nprint (\"Here Y0 = D, Y1 = 0 , Y2 = D, Y3 = 0 , Y4 = C, Y5 = B, Y6 = A and Y7 = 0.Therefore, the given circuit can be obtained from the input lines without using any logic gates\")\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Truth table\nInput Output\nDecimal Digit Digit1 Digit0\nA B C D Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0\n0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 1 0 0 0 0 0 1 0 1 \n0 0 1 0 0 0 0 1 0 0 0 0 \n0 0 1 1 0 0 0 1 0 1 0 1 \n0 1 0 0 0 0 1 0 0 0 0 0 \n0 1 0 1 0 0 1 0 0 1 0 1 \n0 1 1 0 0 0 1 1 0 0 0 0 \n0 1 1 1 0 0 1 1 0 1 0 1 \n1 0 0 0 0 1 0 0 0 0 0 0 \n1 0 0 1 0 1 0 0 0 1 0 1 \n \nHere Y0 = D, Y1 = 0 , Y2 = D, Y3 = 0 , Y4 = C, Y5 = B, Y6 = A and Y7 = 0.Therefore, the given circuit can be obtained from the input lines without using any logic gates\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.4 Page No. 5-5 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "print (\"Let us consider D for Door, If orignition, L for Light.Then conditions to activate the alarm are: \")\nprint (\"1.The headlights are ON while the ignition is OFF.\")\nprint (\"i.e.L = 1 ,I = 0 and D maybe anything.\")\nprint (\"2.The d door is open while the ignition is ON\")\nprint (\"i.e.D = 1,I = 1, L maybe anything.\")\nprint (\"Also alarm will sound if logic circuit output is zero.\")\nprint (\"Therefore, output for above condition is zero and for rest of the condition it is 1 which is summarized in the following table.\")\nprint (\"D I L Y\")\nprint (\"0 0 0 1 \")\nprint (\"X 0 1 0 \")\nprint (\"0 1 0 1 \")\nprint (\"0 1 1 1 \")\nprint (\"1 0 0 1 \")\nprint (\"1 1 X 0 \")\nprint (\"Therefore, K\u2212map for logic circuit.\")\nprint (\"I\u2019\u2019L\u2019\u2019 I\u2019\u2019L IL IL\u2019\u2019\")\nprint (\"D\u2019\u2019 1 0 1 1 \")\nprint (\"D 1 0 0 0 \")\nprint (\"Output = Y = I\u2019\u2019L\u2019\u2019+D\u2019\u2019I\")\nprint (\"As AND\u2212OR logic can be directly replaced by NAND\u2212NAND,logic circuit using only NAND gates is as shown in fig.5.9 and fig.5.10\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Let us consider D for Door, If orignition, L for Light.Then conditions to activate the alarm are: \n1.The headlights are ON while the ignition is OFF.\ni.e.L = 1 ,I = 0 and D maybe anything.\n2.The d door is open while the ignition is ON\ni.e.D = 1,I = 1, L maybe anything.\nAlso alarm will sound if logic circuit output is zero.\nTherefore, output for above condition is zero and for rest of the condition it is 1 which is summarized in the following table.\nD I L Y\n0 0 0 1 \nX 0 1 0 \n0 1 0 1 \n0 1 1 1 \n1 0 0 1 \n1 1 X 0 \nTherefore, K\u2212map for logic circuit.\nI\u2019\u2019L\u2019\u2019 I\u2019\u2019L IL IL\u2019\u2019\nD\u2019\u2019 1 0 1 1 \nD 1 0 0 0 \nOutput = Y = I\u2019\u2019L\u2019\u2019+D\u2019\u2019I\nAs AND\u2212OR logic can be directly replaced by NAND\u2212NAND,logic circuit using only NAND gates is as shown in fig.5.9 and fig.5.10\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.5 Page No. 5-7 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "print (\"Truth table \")\nprint (\"Dec A B C D Output Y\")\nprint (\"0 0 0 0 0 0 \")\nprint (\"1 0 0 0 1 0 \")\nprint (\"2 0 0 1 0 0 \")\nprint (\"3 0 0 1 1 0 \")\nprint (\"4 0 1 0 0 0 \")\nprint (\"5 0 1 0 1 0 \")\nprint (\"6 0 1 1 0 0 \")\nprint (\"7 0 1 1 1 0 \")\nprint (\"8 1 0 0 0 0 \")\nprint (\"9 1 0 0 1 0 \")\nprint (\"10 1 0 1 0 1 \")\nprint (\"11 1 0 1 1 1 \")\nprint (\"12 1 1 0 0 1 \")\nprint (\"13 1 1 0 1 1 \")\nprint (\"14 1 1 1 0 1 \")\nprint (\"15 1 1 1 1 1 \")\nprint (\" \")\nprint (\"K\u2212map simplification\")\nprint (\"C\u2019\u2019D\u2019\u2019 C\u2019\u2019D CD CD\u2019\u2019\")\nprint (\"A\u2019\u2019B\u2019\u2019 0 0 0 0 \")\nprint (\"A\u2019\u2019B 0 0 0 0 \")\nprint (\"AB 1 1 1 1 \")\nprint (\"AB\u2019\u2019 0 0 1 1 \")\nprint (\"Y = AB + AC\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Truth table \nDec A B C D Output Y\n0 0 0 0 0 0 \n1 0 0 0 1 0 \n2 0 0 1 0 0 \n3 0 0 1 1 0 \n4 0 1 0 0 0 \n5 0 1 0 1 0 \n6 0 1 1 0 0 \n7 0 1 1 1 0 \n8 1 0 0 0 0 \n9 1 0 0 1 0 \n10 1 0 1 0 1 \n11 1 0 1 1 1 \n12 1 1 0 0 1 \n13 1 1 0 1 1 \n14 1 1 1 0 1 \n15 1 1 1 1 1 \n \nK\u2212map simplification\nC\u2019\u2019D\u2019\u2019 C\u2019\u2019D CD CD\u2019\u2019\nA\u2019\u2019B\u2019\u2019 0 0 0 0 \nA\u2019\u2019B 0 0 0 0 \nAB 1 1 1 1 \nAB\u2019\u2019 0 0 1 1 \nY = AB + AC\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.6 Page No. 5-8 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "print (\"Input 1 \u2212> Pressure in fuel tank\")\nprint (\"Input 2 \u2212> Pressure in oxidizer tank\")\nprint (\"Input = 1 Indicates pressure is equal to or above the required minimum\")\nprint (\"= 0 Otherwise \")\nprint (\"Input 3 \u2212> From timer\")\nprint (\"if input 3 = 1 Indicates that there are less than or exactly 10 minutes for lift off\")\nprint (\"= 0 Otherwise\")\nprint (\"Output \u2212> Panel light, if light goes on then\")\nprint (\"Output = 1 \")\nprint (\"else Output = 0 \")\nprint (\" \")\nprint (\"Truth table\")\nprint (\"Let input 1 = A, input 2 = B, input 3 = C.\")\nprint (\"Inputs Output\")\nprint (\"A B C Y\")\nprint (\"0 0 0 1 \")\nprint (\"0 0 1 0 \")\nprint (\"0 1 0 1 \")\nprint (\"0 1 1 0 \")\nprint (\"1 0 0 1 \")\nprint (\"1 0 1 0 \")\nprint (\"1 1 0 0 \")\nprint (\"1 1 1 1 \")\nprint (\" \")\nprint (\"K\u2212map simplification\")\nprint (\"B\u2019\u2019C\u2019\u2019 B\u2019\u2019C BC BC\u2019\u2019\")\nprint (\"A\u2019\u2019 1 0 0 1 \")\nprint (\"A 1 0 1 0 \")\nprint (\"Y = ABC + A\u2019\u2019B\u2019\u2019C\u2019\u2019 + B\u2019\u2019C\u2019\u2019\")\nprint (\"= ABC + C\u2019\u2019(B\u2019\u2019+A\u2019\u2019B) \")\nprint (\"= ABC + C\u2019\u2019(B\u2019\u2019+A\u2019\u2019) [ A\u2019\u2019+A\u2019\u2019B = A + B] \")\nprint (\"= ABC + C\u2019\u2019(A\u2019\u2019B\u2019\u2019)\")\nprint (\"= A\u2019\u2019B\u2019\u2019 XOR C\u2019\u2019\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Input 1 \u2212> Pressure in fuel tank\nInput 2 \u2212> Pressure in oxidizer tank\nInput = 1 Indicates pressure is equal to or above the required minimum\n= 0 Otherwise \nInput 3 \u2212> From timer\nif input 3 = 1 Indicates that there are less than or exactly 10 minutes for lift off\n= 0 Otherwise\nOutput \u2212> Panel light, if light goes on then\nOutput = 1 \nelse Output = 0 \n \nTruth table\nLet input 1 = A, input 2 = B, input 3 = C.\nInputs Output\nA B C Y\n0 0 0 1 \n0 0 1 0 \n0 1 0 1 \n0 1 1 0 \n1 0 0 1 \n1 0 1 0 \n1 1 0 0 \n1 1 1 1 \n \nK\u2212map simplification\nB\u2019\u2019C\u2019\u2019 B\u2019\u2019C BC BC\u2019\u2019\nA\u2019\u2019 1 0 0 1 \nA 1 0 1 0 \nY = ABC + A\u2019\u2019B\u2019\u2019C\u2019\u2019 + B\u2019\u2019C\u2019\u2019\n= ABC + C\u2019\u2019(B\u2019\u2019+A\u2019\u2019B) \n= ABC + C\u2019\u2019(B\u2019\u2019+A\u2019\u2019) [ A\u2019\u2019+A\u2019\u2019B = A + B] \n= ABC + C\u2019\u2019(A\u2019\u2019B\u2019\u2019)\n= A\u2019\u2019B\u2019\u2019 XOR C\u2019\u2019\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.7 Page No. 5-15 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "print (\"Fig.5.20 shows a 32 to 1 multiplexer using 74LS150 ICs.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Fig.5.20 shows a 32 to 1 multiplexer using 74LS150 ICs.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.8 Page No. 5-15 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "print (\"Fig.5.21 shows a 32 to 1 multiplexer using four 8 to 1 multiplxeres and 2 to 4 decoder.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Fig.5.21 shows a 32 to 1 multiplexer using four 8 to 1 multiplxeres and 2 to 4 decoder.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.9 Page No. 5-18 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "print (\"The function can be implemented with a 8 to 1 multiplexer, as shown in fig.5.22. Three variables A, B and C are applied to the select lines.The minterms to be included (1,3,5 and 6) are chosen by making their corresponding input lines equal to 1. Mintems 0,2,4 and 7 are not included by making their input lines equal to 0.\")\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The function can be implemented with a 8 to 1 multiplexer, as shown in fig.5.22. Three variables A, B and C are applied to the select lines.The minterms to be included (1,3,5 and 6) are chosen by making their corresponding input lines equal to 1. Mintems 0,2,4 and 7 are not included by making their input lines equal to 0.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.10 Page No. 5-18 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "print (\"Fig.5.23 shows the implementation of function with 4 to 1 multiplexer. Two of the variables, B and C, are applied to the selection lines. B is connected to S1 and C is connected to S0. The inputs for multiplexer are derived from the implementation table.\")\nprint (\"Truth table \")\nprint (\"Minterm A B C F\")\n\nprint (\"0 0 0 0 0 \")\nprint (\"1 0 0 1 1 \")\nprint (\"2 0 1 0 0 \")\nprint (\"3 0 1 1 1 \")\nprint (\"4 1 0 0 0 \")\nprint (\"5 1 0 1 1 \")\nprint (\"6 1 1 0 1 \")\nprint (\"7 1 1 1 0 \")\nprint (\" \")\nprint (\"Implementation table\")\nprint (\"D0 D1 D2 D3\")\nprint (\"A\u2019\u2019 0 1 2 3 Row1 \")\nprint (\"A 4 5 6 7 Row2 \")\nprint (\"0 1 A A\u2019\u2019\")\nprint (\" \")\nprint (\"As shown in fig.5.23 (c) the implementation table is nothing but the list of the inputs of the miltiplexers and under them list of all theminterms in two rows. The first row lists all those minterms where A is complemented, and the second row lists all the minterms with A uncomplemented. The minterms given in the function are circled and then each column is inserted separately as follows.\")\nprint (\"1. If the two minterms in a column are not circled, O is applied to the corresponding multiplexer input(see column 1).\")\nprint (\"2. If the two minterms in a column are circled, 1 is applied to the corresponding multiplexer input(see column 2).\")\nprint (\"3. If the minterm in the second row is circled and minterms in the first row is not circled,A is applied to the corresponding multiplexer input (see column 3).\")\nprint (\"4. If the minterm in the first row is circled and minterm in the second row is not circled, A\u2019\u2019 is applied to the corresponding multiplexer input(see column 4).\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Fig.5.23 shows the implementation of function with 4 to 1 multiplexer. Two of the variables, B and C, are applied to the selection lines. B is connected to S1 and C is connected to S0. The inputs for multiplexer are derived from the implementation table.\nTruth table \nMinterm A B C F\n0 0 0 0 0 \n1 0 0 1 1 \n2 0 1 0 0 \n3 0 1 1 1 \n4 1 0 0 0 \n5 1 0 1 1 \n6 1 1 0 1 \n7 1 1 1 0 \n \nImplementation table\nD0 D1 D2 D3\nA\u2019\u2019 0 1 2 3 Row1 \nA 4 5 6 7 Row2 \n0 1 A A\u2019\u2019\n \nAs shown in fig.5.23 (c) the implementation table is nothing but the list of the inputs of the miltiplexers and under them list of all theminterms in two rows. The first row lists all those minterms where A is complemented, and the second row lists all the minterms with A uncomplemented. The minterms given in the function are circled and then each column is inserted separately as follows.\n1. If the two minterms in a column are not circled, O is applied to the corresponding multiplexer input(see column 1).\n2. If the two minterms in a column are circled, 1 is applied to the corresponding multiplexer input(see column 2).\n3. If the minterm in the second row is circled and minterms in the first row is not circled,A is applied to the corresponding multiplexer input (see column 3).\n4. If the minterm in the first row is circled and minterm in the second row is not circled, A\u2019\u2019 is applied to the corresponding multiplexer input(see column 4).\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.11 Page No. 5-20", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "print (\"Fig 5.25 shows the implementation of given Booolean function with 8 : 1 miltiplexer. \")\nprint (\"Implementation table \")\nprint (\"D0 D1 D2 D3 D4 D5 D6 D7\")\nprint (\"A\u2019\u2019 0 1 2 3 4 5 6 7 \")\nprint (\"A 8 9 10 11 12 13 14 15 \")\nprint (\"1 1 0 A\u2019\u2019 A\u2019\u2019 0 0 A\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Fig 5.25 shows the implementation of given Booolean function with 8 : 1 miltiplexer. \nImplementation table \nD0 D1 D2 D3 D4 D5 D6 D7\nA\u2019\u2019 0 1 2 3 4 5 6 7 \nA 8 9 10 11 12 13 14 15 \n1 1 0 A\u2019\u2019 A\u2019\u2019 0 0 A\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.12 Page No. 5-21", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "print (\"The function has four variables. To implement this function we require 8:1 multiplexer. i.e., two 4:1 multiplexers. We have already seen how to construct 8:1 multiplexer using two 4:1 multiplexers.The same concept is used here to implemen t given Boolean function.\")\nprint (\" \")\nprint (\"Implementation table\")\nprint (\"D0 D1 D2 D3 D4 D5 D6 D7\")\nprint (\"A\u2019\u2019 0 1 2 3 4 5 6 7 \")\nprint (\"A 8 9 10 11 12 13 14 15 \")\nprint (\"A\u2019\u2019 1 A\u2019\u2019 0 1 0 1 0 \")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The function has four variables. To implement this function we require 8:1 multiplexer. i.e., two 4:1 multiplexers. We have already seen how to construct 8:1 multiplexer using two 4:1 multiplexers.The same concept is used here to implemen t given Boolean function.\n \nImplementation table\nD0 D1 D2 D3 D4 D5 D6 D7\nA\u2019\u2019 0 1 2 3 4 5 6 7 \nA 8 9 10 11 12 13 14 15 \nA\u2019\u2019 1 A\u2019\u2019 0 1 0 1 0 \n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.13 Page No. 5-22", "cell_type": "markdown", "metadata": {}}, {"execution_count": 30, "cell_type": "code", "source": "print (\"The given Boolean expression is not in standard SOP form. Let us first convert this in standard form.\")\nprint (\" F (A, B, C, D) = A\u2019\u2019BD\u2019\u2019(C+C\u2019\u2019) + ACD(B+B\u2019\u2019) + B\u2019\u2019CD(A+A\u2019\u2019) + A\u2019\u2019C\u2019\u2019D(B+B\u2019\u2019)\")\nprint (\" = A\u2019\u2019BCD\u2019\u2019 + A\u2019\u2019BC\u2019\u2019D\u2019\u2019 + ABCD + AB\u2019\u2019CD + AB\u2019\u2019CD + A\u2019\u2019B\u2019\u2019CD + A\u2019\u2019BC\u2019 \u2019D + A\u2019\u2019B\u2019\u2019C\u2019\u2019D\")\nprint (\" = A\u2019\u2019BCD\u2019\u2019 + A\u2019\u2019BC\u2019\u2019D\u2019\u2019 + ABCD + AB\u2019\u2019CD + A\u2019\u2019B\u2019\u2019CD + A\u2019\u2019BC\u2019\u2019D + A\u2019\u2019B\u2019\u2019C\u2019\u2019D\")\nprint (\" \")\nprint (\"The truth table for this standard SOP form can be given as\")\nprint (\"No. Minterms A B C D Y\")\nprint (\"0 0 0 0 0 0 \")\nprint (\"1 A\u2019\u2019B\u2019\u2019C\u2019\u2019D 0 0 0 1 1 \")\nprint (\"2 0 0 1 0 0 \")\nprint (\"3 A\u2019\u2019B\u2019\u2019CD 0 0 1 1 1 \")\nprint (\"4 A\u2019\u2019BC\u2019\u2019D\u2019\u2019 0 1 0 0 1 \")\nprint (\"5 A\u2019\u2019BC\u2019\u2019D 0 1 0 1 1 \")\nprint (\"6 A\u2019\u2019BCD\u2019\u2019 0 1 1 0 1 \")\nprint (\"7 0 1 1 1 0 \")\nprint (\"8 1 0 0 0 0 \")\nprint (\"9 1 0 0 1 0 \")\nprint (\"10 1 0 1 0 0 \")\nprint (\"11 AB\u2019\u2019CD 1 0 1 1 1 \")\nprint (\"12 1 1 0 0 0 \")\nprint (\"13 1 1 0 1 0 \")\nprint (\"14 1 1 1 0 0 \")\nprint (\"15 ABCD 1 1 1 1 1 \")\nprint (\" \")\nprint (\"From the truth table Boolean function can be implemented using 8 : 1 multiplexer as follows:\")\nprint (\"Implementation table: \")\nprint (\"D0 D1 D2 D3 D4 D5 D6 D7\")\nprint (\"A\u2019\u2019 0 1 2 3 4 5 6 7 \")\nprint (\"A 8 9 10 11 12 13 14 15 \")\nprint (\"0 A\u2019\u2019 0 1 A\u2019\u2019 A\u2019\u2019 A\u2019\u2019 A\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The given Boolean expression is not in standard SOP form. Let us first convert this in standard form.\n F (A, B, C, D) = A\u2019\u2019BD\u2019\u2019(C+C\u2019\u2019) + ACD(B+B\u2019\u2019) + B\u2019\u2019CD(A+A\u2019\u2019) + A\u2019\u2019C\u2019\u2019D(B+B\u2019\u2019)\n = A\u2019\u2019BCD\u2019\u2019 + A\u2019\u2019BC\u2019\u2019D\u2019\u2019 + ABCD + AB\u2019\u2019CD + AB\u2019\u2019CD + A\u2019\u2019B\u2019\u2019CD + A\u2019\u2019BC\u2019 \u2019D + A\u2019\u2019B\u2019\u2019C\u2019\u2019D\n = A\u2019\u2019BCD\u2019\u2019 + A\u2019\u2019BC\u2019\u2019D\u2019\u2019 + ABCD + AB\u2019\u2019CD + A\u2019\u2019B\u2019\u2019CD + A\u2019\u2019BC\u2019\u2019D + A\u2019\u2019B\u2019\u2019C\u2019\u2019D\n \nThe truth table for this standard SOP form can be given as\nNo. Minterms A B C D Y\n0 0 0 0 0 0 \n1 A\u2019\u2019B\u2019\u2019C\u2019\u2019D 0 0 0 1 1 \n2 0 0 1 0 0 \n3 A\u2019\u2019B\u2019\u2019CD 0 0 1 1 1 \n4 A\u2019\u2019BC\u2019\u2019D\u2019\u2019 0 1 0 0 1 \n5 A\u2019\u2019BC\u2019\u2019D 0 1 0 1 1 \n6 A\u2019\u2019BCD\u2019\u2019 0 1 1 0 1 \n7 0 1 1 1 0 \n8 1 0 0 0 0 \n9 1 0 0 1 0 \n10 1 0 1 0 0 \n11 AB\u2019\u2019CD 1 0 1 1 1 \n12 1 1 0 0 0 \n13 1 1 0 1 0 \n14 1 1 1 0 0 \n15 ABCD 1 1 1 1 1 \n \nFrom the truth table Boolean function can be implemented using 8 : 1 multiplexer as follows:\nImplementation table: \nD0 D1 D2 D3 D4 D5 D6 D7\nA\u2019\u2019 0 1 2 3 4 5 6 7 \nA 8 9 10 11 12 13 14 15 \n0 A\u2019\u2019 0 1 A\u2019\u2019 A\u2019\u2019 A\u2019\u2019 A\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.14 Page No. 5-24 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "print (\"Here,instead of minterms,maxterms are specified.Thus,we have to circle maxterms which are not included in the Boolean function. Fig.5.28 shows the implementation of Boolean function with 8 : 1 multiplexer.\")\nprint (\" \")\nprint (\"Implementation table: \")\nprint (\"D0 D1 D2 D3 D4 D5 D6 D7\")\nprint (\"A\u2019\u2019 0 1 2 3 4 5 6 7\")\nprint (\"A 8 9 10 11 12 13 14 15 \")\nprint (\"0 A\u2019\u2019A\u2019\u2019 AA\u2019\u2019 A 0 1\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Here,instead of minterms,maxterms are specified.Thus,we have to circle maxterms which are not included in the Boolean function. Fig.5.28 shows the implementation of Boolean function with 8 : 1 multiplexer.\n \nImplementation table: \nD0 D1 D2 D3 D4 D5 D6 D7\nA\u2019\u2019 0 1 2 3 4 5 6 7\nA 8 9 10 11 12 13 14 15 \n0 A\u2019\u2019A\u2019\u2019 AA\u2019\u2019 A 0 1\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.15 Page No. 5-24", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "print (\"In the given Boolean function three don\u2019t care conditions are also specified. We know that dont care conditions can be treated as either 0s or 1s.Fig.5.29 shows the implementation of given Boolean function using 8 : 1 multiplexer.\")\nprint (\" \")\nprint (\"Im pl em e n t a ti o n t a b l e : \")\nprint (\"D0 D1 D2 D3 D4 D5 D6 D7\")\nprint (\"A\u2019 \u2019 0 1 2 3 4 5 6 7 \")\nprint (\"A 8 9 10 11 12 13 14 15 \")\nprint (\"1 0 1 1 A A 1 0 \")\nprint (\" \")\nprint (\"In this example, by taking dont care conditions 8 and 14 we have eliminated A\u2019\u2019 term and hence the inverter.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "In the given Boolean function three don\u2019t care conditions are also specified. We know that dont care conditions can be treated as either 0s or 1s.Fig.5.29 shows the implementation of given Boolean function using 8 : 1 multiplexer.\n \nIm pl em e n t a ti o n t a b l e : \nD0 D1 D2 D3 D4 D5 D6 D7\nA\u2019 \u2019 0 1 2 3 4 5 6 7 \nA 8 9 10 11 12 13 14 15 \n1 0 1 1 A A 1 0 \n \nIn this example, by taking dont care conditions 8 and 14 we have eliminated A\u2019\u2019 term and hence the inverter.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.16 Page No. 5-25 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 29, "cell_type": "code", "source": "print (\"D\u2019\u2019 D\")\nprint (\"D 0 1 \")\nprint (\"0 2 3 \")\nprint (\"0 4 5 \")\nprint (\"1 6 7 \")\nprint (\"D 8 9 \")\nprint (\"1 10 11 \")\nprint (\"D\u2019\u2019 12 13 \")\nprint (\"0 14 15 \")\nprint (\" \")\nprint (\"Here, implementation table is listed for least significant bits i.e.D. The first column list all minterm swith D is complementated and these cond column lists all the minterms with Duncomplemented,as shown in fig.5.30(a).Then according to data inputs given to the multiplexer minterms are circled applying following rules.\")\nprint (\"1. If multipler input is 0, dont circle any minterm in the corresponding row.\")\nprint (\"2. If multipler input is 1, circle both the minterms in the corresponding row\")\nprint (\"3. If multipler input is D, circle the minterm belongs to cloumn D in the corresponding row\")\nprint (\"4. If multipler input is D\u2019\u2019,circle the minterm belongs to column D\u2019\u2019 in the corresponding row\")\nprint (\"This is illustrated in fig.5.30(b).Now circled minterms can be written to get Boolean expression as follows:\")\nprint (\"Y = A\u2019\u2019B\u2019\u2019C\u2019\u2019D + A\u2019\u2019BCD\u2019\u2019 + A\u2019\u2019BCD + AB\u2019\u2019C\u2019\u2019D + AB\u2019\u2019CD\u2019\u2019 + AB\u2019\u2019CD + ABC\u2019\u2019D\u2019\u2019 \")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "D\u2019\u2019 D\nD 0 1 \n0 2 3 \n0 4 5 \n1 6 7 \nD 8 9 \n1 10 11 \nD\u2019\u2019 12 13 \n0 14 15 \n \nHere, implementation table is listed for least significant bits i.e.D. The first column list all minterm swith D is complementated and these cond column lists all the minterms with Duncomplemented,as shown in fig.5.30(a).Then according to data inputs given to the multiplexer minterms are circled applying following rules.\n1. If multipler input is 0, dont circle any minterm in the corresponding row.\n2. If multipler input is 1, circle both the minterms in the corresponding row\n3. If multipler input is D, circle the minterm belongs to cloumn D in the corresponding row\n4. If multipler input is D\u2019\u2019,circle the minterm belongs to column D\u2019\u2019 in the corresponding row\nThis is illustrated in fig.5.30(b).Now circled minterms can be written to get Boolean expression as follows:\nY = A\u2019\u2019B\u2019\u2019C\u2019\u2019D + A\u2019\u2019BCD\u2019\u2019 + A\u2019\u2019BCD + AB\u2019\u2019C\u2019\u2019D + AB\u2019\u2019CD\u2019\u2019 + AB\u2019\u2019CD + ABC\u2019\u2019D\u2019\u2019 \n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.17 Page No. 5-26", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "print (\"D0 D1 D2 D3\")\nprint (\"w\u2019\u2019x\u2019\u2019 0 1 2 3 \")\nprint (\"w\u2019\u2019x 4 5 6 7 \")\nprint (\"wx\u2019\u2019 8 9 10 11 \")\nprint (\"wx 12 13 14 15 \")\nprint (\" \")\nprint (\"D0 = w\u2019\u2019x + wx\u2019\u2019 = w XOR x\")\nprint (\"D1 = w\u2019\u2019x\u2019\u2019 + wx\u2019\u2019 = x\u2019\u2019 \")\nprint (\"D2 = w\u2019\u2019x + wx\u2019\u2019 = w XOR x\")\nprint (\"D3 = w\u2019\u2019x + wx\u2019\u2019 + wx = x + wx\u2019\u2019 = w + x\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "D0 D1 D2 D3\nw\u2019\u2019x\u2019\u2019 0 1 2 3 \nw\u2019\u2019x 4 5 6 7 \nwx\u2019\u2019 8 9 10 11 \nwx 12 13 14 15 \n \nD0 = w\u2019\u2019x + wx\u2019\u2019 = w XOR x\nD1 = w\u2019\u2019x\u2019\u2019 + wx\u2019\u2019 = x\u2019\u2019 \nD2 = w\u2019\u2019x + wx\u2019\u2019 = w XOR x\nD3 = w\u2019\u2019x + wx\u2019\u2019 + wx = x + wx\u2019\u2019 = w + x\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.18 Page No. 5-28 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "print (\"The cascading of demultiplexers is similar to the cascading of decoder.Fig.5.33 shows cascading of two 1 : 4 demultiplexers to form 1 :8 demultiplexer.\")\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The cascading of demultiplexers is similar to the cascading of decoder.Fig.5.33 shows cascading of two 1 : 4 demultiplexers to form 1 :8 demultiplexer.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.19 Page No. 5-28 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "print (\"Let us see the truthtable of full subtractor.\")\nprint (\"A B Bin D Bout \")\nprint (\"0 0 0 0 0 \")\nprint (\"0 0 1 1 1 \")\nprint (\"0 1 0 1 1 \")\nprint (\"0 1 1 0 1 \")\nprint (\"1 0 0 1 0 \")\nprint (\"1 0 1 0 0 \")\nprint (\"1 1 0 0 0 \")\nprint (\"1 1 1 1 1 \")\nprint (\" \")\nprint (\"For full subtractor difference D function can be written as D = f(A,B,C) = summation m(1,2,4,7) and Bout function can be written as\")\nprint (\"Bout = F (A, B, C) = summation m( 1 , 2 , 3 ,7 ) \")\nprint (\"With Din input 1, demultiplexer gives minterms at the output so by logically ORing required minterms we can implement Boolean functions for full subtractor. Fig.5.34 shows the implementation of full subtractor using demultiplexer.\")\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Let us see the truthtable of full subtractor.\nA B Bin D Bout \n0 0 0 0 0 \n0 0 1 1 1 \n0 1 0 1 1 \n0 1 1 0 1 \n1 0 0 1 0 \n1 0 1 0 0 \n1 1 0 0 0 \n1 1 1 1 1 \n \nFor full subtractor difference D function can be written as D = f(A,B,C) = summation m(1,2,4,7) and Bout function can be written as\nBout = F (A, B, C) = summation m( 1 , 2 , 3 ,7 ) \nWith Din input 1, demultiplexer gives minterms at the output so by logically ORing required minterms we can implement Boolean functions for full subtractor. Fig.5.34 shows the implementation of full subtractor using demultiplexer.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.20 Page No. 5-32", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "print (\"The fig.5.37 shows the implmentation of 1 to demultiplexer using two 74X154 ICs.Here,the most significant bit of select signal(A4) is used to enable either upper 1 to 16 demultiplexer or lower 1 to 16 demultiplexr.The data input and other select signals are connected parallel to both the demultiplexer ICs.When A4 = 0,upper demultiplexer is enabled and the data input is routed to the output corresponds to the status of A0 A1 A2 and A3 lines.When A4 = 1,lower multiplexer is enabled and the data input is routed to the output corresponds to the status of A0 A1 A2 and A3 lines.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The fig.5.37 shows the implmentation of 1 to demultiplexer using two 74X154 ICs.Here,the most significant bit of select signal(A4) is used to enable either upper 1 to 16 demultiplexer or lower 1 to 16 demultiplexr.The data input and other select signals are connected parallel to both the demultiplexer ICs.When A4 = 0,upper demultiplexer is enabled and the data input is routed to the output corresponds to the status of A0 A1 A2 and A3 lines.When A4 = 1,lower multiplexer is enabled and the data input is routed to the output corresponds to the status of A0 A1 A2 and A3 lines.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.21 Page No. 5-34", "cell_type": "markdown", "metadata": {}}, {"execution_count": 28, "cell_type": "code", "source": "print (\"Fig.5.40 shows 3 to 8 line decoder.Here,3 inputs are decoded into eight outputs, each output represent one of the minterms of the 3 input variables.The three inverters provide the complement of the inputs, and each one of the eight AND gates generates one of the minterms.Enable input is provided to activate decoded output based on data inputs A, B and C. The table shows the truth table for 3 to 8 decoder.\")\nprint (\" \")\nprint (\"Truth table for a 3 to 8 decoder\")\nprint (\"Inputs | Outputs \")\nprint (\"EN A B C | Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0\")\nprint (\"0 X X X | 0 0 0 0 0 0 0 0 \")\nprint (\"1 0 0 0 | 0 0 0 0 0 0 0 1 \")\nprint (\"1 0 0 1 | 0 0 0 0 0 0 1 0 \")\nprint (\"1 0 1 0 | 0 0 0 0 0 1 0 0 \")\nprint (\"1 0 1 1 | 0 0 0 0 1 0 0 0 \")\nprint (\"1 1 0 0 | 0 0 0 1 0 0 0 0 \")\nprint (\"1 1 0 1 | 0 0 1 0 0 0 0 0 \")\nprint (\"1 1 1 0 | 0 1 0 0 0 0 0 0 \")\nprint (\"1 1 1 1 | 1 0 0 0 0 0 0 0 \")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Fig.5.40 shows 3 to 8 line decoder.Here,3 inputs are decoded into eight outputs, each output represent one of the minterms of the 3 input variables.The three inverters provide the complement of the inputs, and each one of the eight AND gates generates one of the minterms.Enable input is provided to activate decoded output based on data inputs A, B and C. The table shows the truth table for 3 to 8 decoder.\n \nTruth table for a 3 to 8 decoder\nInputs | Outputs \nEN A B C | Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0\n0 X X X | 0 0 0 0 0 0 0 0 \n1 0 0 0 | 0 0 0 0 0 0 0 1 \n1 0 0 1 | 0 0 0 0 0 0 1 0 \n1 0 1 0 | 0 0 0 0 0 1 0 0 \n1 0 1 1 | 0 0 0 0 1 0 0 0 \n1 1 0 0 | 0 0 0 1 0 0 0 0 \n1 1 0 1 | 0 0 1 0 0 0 0 0 \n1 1 1 0 | 0 1 0 0 0 0 0 0 \n1 1 1 1 | 1 0 0 0 0 0 0 0 \n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.22 Page No. 5-38 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 27, "cell_type": "code", "source": "print (\"The Fig.5.45 shows the construction of 5 to 32 decoder using four 74LS138s and half 74LS139. The half section of 74LS139 IC used as a 2 to 4 decoder to decode the two higher order inputs,D and E.The four outputs of this decoder are used to enable one of the four 3 to 8 decoders . The three lower inputs A, B and C a reconnected in parallel to four 3 to 8 decoders.This means that the same output pin of each of the four 3 to 8 decoders is selected but only one is enable.The remaining enables signals of four 3 to 8 decoders ICs are connected in parallel to construct enable signals for 5 to 32 decoder.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The Fig.5.45 shows the construction of 5 to 32 decoder using four 74LS138s and half 74LS139. The half section of 74LS139 IC used as a 2 to 4 decoder to decode the two higher order inputs,D and E.The four outputs of this decoder are used to enable one of the four 3 to 8 decoders . The three lower inputs A, B and C a reconnected in parallel to four 3 to 8 decoders.This means that the same output pin of each of the four 3 to 8 decoders is selected but only one is enable.The remaining enables signals of four 3 to 8 decoders ICs are connected in parallel to construct enable signals for 5 to 32 decoder.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.23 Page No. 5-40 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 26, "cell_type": "code", "source": "print (\"4 line to 16 line decoder using 1 line to 4 line decoder\")\nprint (\"As shown in fig.5.46 five numbers of 2:4 decoder are required to design 4:16 decoder. Decoder 1 is used to enable one of the decoder 2, 3,4 and 5.Inputs off irstd ecoder are the A and B MSB inputs of 4 : 16 decoder. The inputs of decoder are connected together forming C and D LSB inputs of 4 : 16 decoder.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "4 line to 16 line decoder using 1 line to 4 line decoder\nAs shown in fig.5.46 five numbers of 2:4 decoder are required to design 4:16 decoder. Decoder 1 is used to enable one of the decoder 2, 3,4 and 5.Inputs off irstd ecoder are the A and B MSB inputs of 4 : 16 decoder. The inputs of decoder are connected together forming C and D LSB inputs of 4 : 16 decoder.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.24 Page No. 5-43 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 25, "cell_type": "code", "source": "print (\"In this example, we use IC74LS138,3:8 decoder to implement multiple output function. The outputs of 74LS138 a reactive low, therefore, SOP function(function F1)can be implemented using NAND gate and POS function (function F2) can be implemented using AND gate, as shown in fig.5.50\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "In this example, we use IC74LS138,3:8 decoder to implement multiple output function. The outputs of 74LS138 a reactive low, therefore, SOP function(function F1)can be implemented using NAND gate and POS function (function F2) can be implemented using AND gate, as shown in fig.5.50\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.25 Page No. 5-43 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 18, "cell_type": "code", "source": "print (\"The truth table for full subtractor is as shown below\")\nprint (\" \")\nprint (\"Inputs Outputs \")\nprint (\"A B Bin D Bout \")\nprint (\"0 0 0 0 0 \")\nprint (\"0 0 1 1 1 \")\nprint (\"0 1 0 1 1 \")\nprint (\"0 1 1 0 1 \")\nprint (\"1 0 0 1 0 \")\nprint (\"1 0 1 0 0 \")\nprint (\"1 1 0 0 0 \")\nprint (\"1 1 1 1 1 \")\nprint (\" \")\nprint (\"Implementation of full subtractor using 3:8 decoder is shown in fig.5.51\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The truth table for full subtractor is as shown below\n \nInputs Outputs \nA B Bin D Bout \n0 0 0 0 0 \n0 0 1 1 1 \n0 1 0 1 1 \n0 1 1 0 1 \n1 0 0 1 0 \n1 0 1 0 0 \n1 1 0 0 0 \n1 1 1 1 1 \n \nImplementation of full subtractor using 3:8 decoder is shown in fig.5.51\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.26 Page No. 5-44 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 24, "cell_type": "code", "source": "print (\"The truth table for 3\u2212bit binary to gray code converter is as shown below \")\nprint (\" \")\nprint (\"A B C G2 G1 G0\")\nprint (\"0 0 0 0 0 0 \")\nprint (\"0 0 1 0 0 1 \")\nprint (\"0 1 0 0 1 1 \")\nprint (\"0 1 1 0 1 0 \")\nprint (\"1 0 0 1 1 0 \")\nprint (\"1 0 1 1 1 1 \")\nprint (\"1 1 0 1 0 1 \")\nprint (\"1 1 1 1 0 0 \")\nprint (\" \")\nprint (\"The fig.5.52 shows the implementation of 3\u2212bit binary to gray code converter using 3:8 decoder. As outputs of 74138 are active low we have to use NAND gate instead of OR gate. The active low output from the decoder forces output(s) of connected NAND gate(s)to become HIGH,thus implementing the function.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The truth table for 3\u2212bit binary to gray code converter is as shown below \n \nA B C G2 G1 G0\n0 0 0 0 0 0 \n0 0 1 0 0 1 \n0 1 0 0 1 1 \n0 1 1 0 1 0 \n1 0 0 1 1 0 \n1 0 1 1 1 1 \n1 1 0 1 0 1 \n1 1 1 1 0 0 \n \nThe fig.5.52 shows the implementation of 3\u2212bit binary to gray code converter using 3:8 decoder. As outputs of 74138 are active low we have to use NAND gate instead of OR gate. The active low output from the decoder forces output(s) of connected NAND gate(s)to become HIGH,thus implementing the function.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.27 Page No. 5-45 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 19, "cell_type": "code", "source": "print (\" \")\nprint (\"A1 A0 B1 B0 A>B A=B A<B\")\nprint (\"0 0 0 0 0 0 0 \")\nprint (\"0 0 0 1 0 0 1 \")\nprint (\"0 0 1 0 0 0 1 \")\nprint (\"0 0 1 1 0 0 1 \")\nprint (\"0 1 0 0 1 0 0 \")\nprint (\"0 1 0 1 0 1 0 \")\nprint (\"0 1 1 0 0 0 1 \")\nprint (\"0 1 1 1 0 0 1 \")\nprint (\"1 0 0 0 1 0 0 \")\nprint (\"1 0 0 1 1 0 0 \")\nprint (\"1 0 1 0 0 1 0 \")\nprint (\"1 0 1 1 0 0 1 \")\nprint (\"1 1 0 0 1 0 0 \")\nprint (\"1 1 0 1 1 0 0 \")\nprint (\"1 1 1 0 1 0 0 \")\nprint (\"1 1 1 1 0 1 0 \")", "outputs": [{"output_type": "stream", "name": "stdout", "text": " \nA1 A0 B1 B0 A>B A=B A<B\n0 0 0 0 0 0 0 \n0 0 0 1 0 0 1 \n0 0 1 0 0 0 1 \n0 0 1 1 0 0 1 \n0 1 0 0 1 0 0 \n0 1 0 1 0 1 0 \n0 1 1 0 0 0 1 \n0 1 1 1 0 0 1 \n1 0 0 0 1 0 0 \n1 0 0 1 1 0 0 \n1 0 1 0 0 1 0 \n1 0 1 1 0 0 1 \n1 1 0 0 1 0 0 \n1 1 0 1 1 0 0 \n1 1 1 0 1 0 0 \n1 1 1 1 0 1 0 \n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.28 Page No. 5-46 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 20, "cell_type": "code", "source": "print (\"Truth table for full adder is as shown below\")\nprint (\"Inputs Outputs\")\nprint (\"A B Cin Carry Sum\")\nprint (\"0 0 0 0 0 \")\nprint (\"0 0 1 0 1 \")\nprint (\"0 1 0 0 1 \")\nprint (\"0 1 1 1 0 \")\nprint (\"1 0 0 0 1 \")\nprint (\"1 0 1 1 0 \")\nprint (\"1 1 0 1 0 \")\nprint (\"1 1 1 1 1 \")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Truth table for full adder is as shown below\nInputs Outputs\nA B Cin Carry Sum\n0 0 0 0 0 \n0 0 1 0 1 \n0 1 0 0 1 \n0 1 1 1 0 \n1 0 0 0 1 \n1 0 1 1 0 \n1 1 0 1 0 \n1 1 1 1 1 \n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.29 Page No. 5-51 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 22, "cell_type": "code", "source": "print (\"BCD\u2212to\u2212common anode 7\u2212segment decoder \")\nprint (\"Digit A B C D a b c d e f g \")\nprint (\"0 0 0 0 0 0 0 0 0 0 0 1 \")\nprint (\"1 0 0 0 1 1 0 0 1 1 1 1 \")\nprint (\"2 0 0 1 0 0 0 1 0 0 1 0 \")\nprint (\"3 0 0 1 1 0 0 0 0 1 1 0 \")\nprint (\"4 0 1 0 0 1 0 0 0 1 1 0 \")\nprint (\"5 0 1 0 1 0 1 0 0 1 0 0 \")\nprint (\"6 0 1 1 0 0 1 0 0 0 0 0 \")\nprint (\"7 0 1 1 1 0 0 0 1 1 1 1 \")\nprint (\"8 1 0 0 0 0 0 0 0 0 0 0 \")\nprint (\"9 1 0 0 1 0 0 0 0 1 0 0 \")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "BCD\u2212to\u2212common anode 7\u2212segment decoder \nDigit A B C D a b c d e f g \n0 0 0 0 0 0 0 0 0 0 0 1 \n1 0 0 0 1 1 0 0 1 1 1 1 \n2 0 0 1 0 0 0 1 0 0 1 0 \n3 0 0 1 1 0 0 0 0 1 1 0 \n4 0 1 0 0 1 0 0 0 1 1 0 \n5 0 1 0 1 0 1 0 0 1 0 0 \n6 0 1 1 0 0 1 0 0 0 0 0 \n7 0 1 1 1 0 0 0 1 1 1 1 \n8 1 0 0 0 0 0 0 0 0 0 0 \n9 1 0 0 1 0 0 0 0 1 0 0 \n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5.31 Page No. 5-65 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 23, "cell_type": "code", "source": "print (\"Fig.5.75 shows how four 74LS148 can be connected to accept 32 inputs and produce a 5\u2212bit encoded output,A0\u2212A4.EO\u2019\u2019 signal is connected to the EI\u2019\u2019 input of then ext lower priority encoder and EI\u2019\u2019 input of the highest priority encoder is g rounded.Therefore,at anytim e only one encoder is enabled.Since,the A2\u2212A0 outputs of at the most one 74LS148 will be enable data time,the outputs of the individual 74LS148s can be ORed to produce A2\u2212A0.Likewise,the individual GS\u2019\u2019 outputs can be combined in a 4 to 2 encoder to produce A4 and A3.The GS output for 32\u2212bit encoder is produced by ORing GS\u2019\u2019 outputs of all encoders.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Fig.5.75 shows how four 74LS148 can be connected to accept 32 inputs and produce a 5\u2212bit encoded output,A0\u2212A4.EO\u2019\u2019 signal is connected to the EI\u2019\u2019 input of then ext lower priority encoder and EI\u2019\u2019 input of the highest priority encoder is g rounded.Therefore,at anytim e only one encoder is enabled.Since,the A2\u2212A0 outputs of at the most one 74LS148 will be enable data time,the outputs of the individual 74LS148s can be ORed to produce A2\u2212A0.Likewise,the individual GS\u2019\u2019 outputs can be combined in a 4 to 2 encoder to produce A4 and A3.The GS output for 32\u2212bit encoder is produced by ORing GS\u2019\u2019 outputs of all encoders.\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter6.ipynb b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter6.ipynb
new file mode 100755
index 00000000..61bbad86
--- /dev/null
+++ b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter6.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 6", "cell_type": "markdown", "metadata": {}}, {"source": "# Sequential Logic Circuits", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 6.3 Page No. 6-28", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "print(\"For SR Flip-Flop\")\nprint(\"Q_n+1 = S+/RQ_n\")\nprint(\"Q_n+1 = S+SQ_n\")\nprint(\"Q_n+1 = S(1+Q_n)\")\nprint(\"Q_n+1 = S\")\nprint(\"We have, S = Q_n XOR T\")\nprint(\"Therfore Q_n+1 = Q_n XOR T\")\nprint(\"Therfore Q_n+1 = TQ_n + /TQ_n\")\nprint (\"CLK T Q_n S = Q_n XOR T R=/S Q_n+1 = S\")\nprint (\"down 0 0 0 1 0 \")\nprint (\"down 0 1 1 0 1 \")\nprint (\"down 1 0 1 0 1 \")\nprint (\"down 1 1 0 1 0 \")\nprint(\"Looking at column 1 and column 5 of the table 6.12 we can conclude that when T=0, the output doesnot change and when T=1, the output toggles. The given circuit acts as T flip-flop. This is another way of implementing T flip-flop using SR flip-flop\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For SR Flip-Flop\nQ_n+1 = S+/RQ_n\nQ_n+1 = S+SQ_n\nQ_n+1 = S(1+Q_n)\nQ_n+1 = S\nWe have, S = Q_n XOR T\nTherfore Q_n+1 = Q_n XOR T\nTherfore Q_n+1 = TQ_n + /TQ_n\nCLK T Q_n S = Q_n XOR T R=/S Q_n+1 = S\ndown 0 0 0 1 0 \ndown 0 1 1 0 1 \ndown 1 0 1 0 1 \ndown 1 1 0 1 0 \nLooking at column 1 and column 5 of the table 6.12 we can conclude that when T=0, the output doesnot change and when T=1, the output toggles. The given circuit acts as T flip-flop. This is another way of implementing T flip-flop using SR flip-flop\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6.4 Page No. 6-31", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "print (\"To analyze the circuit means to drive the truth table for it.\")\nprint (\"We have, D = Input XOR Q_n\")\nprint (\" \")\nprint (\"CLK Input Q_n D = input XOR Q_n Q_n+1\")\nprint (\"down 0 0 0 0 \")\nprint (\"down 0 1 1 1 \")\nprint (\"down 1 0 1 1 \")\nprint (\"down 1 1 0 0 \")\nprint (\" \")\nprint (\"In the circuit fig. 6.53,output does not change when input is 0 and it toggles when input is 1. This is the characteristics of T flip flop. Hence,the given circuit is T flip flop constructed using D Flip-flop\");", "outputs": [{"output_type": "stream", "name": "stdout", "text": "To analyze the circuit means to drive the truth table for it.\nWe have, D = Input XOR Q_n\n \nCLK Input Q_n D = input XOR Q_n Q_n+1\ndown 0 0 0 0 \ndown 0 1 1 1 \ndown 1 0 1 1 \ndown 1 1 0 0 \n \nIn the circuit fig. 6.53,output does not change when input is 0 and it toggles when input is 1. This is the characteristics of T flip flop. Hence,the given circuit is T flip flop constructed using D Flip-flop\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter7.ipynb b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter7.ipynb
new file mode 100755
index 00000000..1e06d06e
--- /dev/null
+++ b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter7.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 7", "cell_type": "markdown", "metadata": {}}, {"source": "# Shift Registers", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 7.1 Page No. 7-2", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "print (\"(i)A 6 bit binary number requires register with 6 flip flops\");\nprint (\" \")\nprint (\"(ii)(32)10 = (100000)2.The number of bits required to represent 32 in binary are six,therefore, 6flip flops are needed to construct a register capable of storing 32 decimal.\")\nprint (\" \")\nprint (\"(iii)(F)16 = (1111)2.The number of bits required to represent (F)16 in binary are four,thereforefour flip flops are needed to construct a register capable of storing (F)16 \")\nprint (\" \")\nprint (\"(iv)(10)8 = (1000)2.The number of bits required to represent (10)8 in binary are four, therefore, four flip flops are needed to construct a register capable of storing (10)8.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "(i)A 6 bit binary number requires register with 6 flip flops\n \n(ii)(32)10 = (100000)2.The number of bits required to represent 32 in binary are six,therefore, 6flip flops are needed to construct a register capable of storing 32 decimal.\n \n(iii)(F)16 = (1111)2.The number of bits required to represent (F)16 in binary are four,thereforefour flip flops are needed to construct a register capable of storing (F)16 \n \n(iv)(10)8 = (1000)2.The number of bits required to represent (10)8 in binary are four, therefore, four flip flops are needed to construct a register capable of storing (10)8.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7.2 Page No. 7-10", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": 5, "cell_type": "code", "source": "print(\"We can load the data word ABCD = 1101 as follows\")\nprint(\"Apply input at serial data in for left shift input \")\nprint(\"Connect Right/\\Left line to ground \")\nprint(\"Apply four clock pulses\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "We can load the data word ABCD = 1101 as follows\nApply input at serial data in for left shift input \nConnect Right/\\Left line to ground \nApply four clock pulses\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7.3 Page No. 7-10", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "print(\"To multiply the 4-bit number by 16 and to divide it by 8 using the same circuit we need 8-bit bidirectional shift register. So that by shifting the number 4-bit positions towards the left we can multiply it by 16 and by shifting the number 3-bit positions towards right we can multiply it by 8\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "To multiply the 4-bit number by 16 and to divide it by 8 using the same circuit we need 8-bit bidirectional shift register. So that by shifting the number 4-bit positions towards the left we can multiply it by 16 and by shifting the number 3-bit positions towards right we can multiply it by 8\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7.4 Page No. 7-10", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "print(\"The Fig.7.13 shows the 3-bit bidirectional shift register using JK-flip flop. This circuit is same as the 4-bit bidirectional shift register discussed in previous section expect that the D flip-flop is implemented using JK Flip flop\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The Fig.7.13 shows the 3-bit bidirectional shift register using JK-flip flop. This circuit is same as the 4-bit bidirectional shift register discussed in previous section expect that the D flip-flop is implemented using JK Flip flop\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter8.ipynb b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter8.ipynb
new file mode 100755
index 00000000..47f025c6
--- /dev/null
+++ b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter8.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 8 ", "cell_type": "markdown", "metadata": {}}, {"source": "# Counters", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 8.1 Page No. 8-1", "cell_type": "markdown", "metadata": {}}, {"execution_count": 24, "cell_type": "code", "source": "print(\"After 12 pulses,the count will be (1 1 0 0)2, i.e. 12 in decimal.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "After 12 pulses,the count will be (1 1 0 0)2, i.e. 12 in decimal.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.2 Page No. 8-2", "cell_type": "markdown", "metadata": {}}, {"execution_count": 25, "cell_type": "code", "source": "a = bin (144)\nprint \"decimal (144) =\",a\nprint(\"Since counter is a 5 bit counter, it resets after 2^5 = 32 clock pulses.\")\nprint(\"Dividing 144 by 32 we get quotient 2 and remainder 6\")\nprint(\"Therefore, counter resets four times and then it counts remaining 16 clock pulses. Thus, the count will be binary (1 1 0 0 0 0), i.e., 16 in decimal\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "decimal (144) = 0b10010000\nSince counter is a 5 bit counter, it resets after 2^5 = 32 clock pulses.\nDividing 144 by 32 we get quotient 2 and remainder 6\nTherefore, counter resets four times and then it counts remaining 16 clock pulses. Thus, the count will be binary (1 1 0 0 0 0), i.e., 16 in decimal\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.4 Page No. 8-4", "cell_type": "markdown", "metadata": {}}, {"execution_count": 26, "cell_type": "code", "source": "print(\"When flip\u2212flops are negatively edge triggered,the Q output of previous stage is connected to the clock input of the next stage. Fig.8.5 shows 3\u2212stage asynchronous counter with negative edge triggered flip\u2212flops.\")\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "When flip\u2212flops are negatively edge triggered,the Q output of previous stage is connected to the clock input of the next stage. Fig.8.5 shows 3\u2212stage asynchronous counter with negative edge triggered flip\u2212flops.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.5 Page No. 8-4", "cell_type": "markdown", "metadata": {}}, {"execution_count": 28, "cell_type": "code", "source": "of=50.0/14.0\nprint \"Output frequency = 50kHz/14=\",round(of,2),\"KHz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Output frequency = 50kHz/14= 3.57 KHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.6 Page No. 8-4", "cell_type": "markdown", "metadata": {}}, {"execution_count": 29, "cell_type": "code", "source": "print(\"We know that MOD\u221232 uses five flip\u2212flops.With tpd=50ns,the fmax for ripple counter can be given as,\")\nfm=(1/(250*pow(10,-9)))*pow(10,-6)\nprint \"fmax(ripple)=\",fm,\"MHz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "We know that MOD\u221232 uses five flip\u2212flops.With tpd=50ns,the fmax for ripple counter can be given as,\nfmax(ripple)= 4.0 MHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.8 Page No. 8-9", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "print(\"The 4\u2212bit counter needs four flip\u2212flops.The circuit for 4\u2212bitup/down ripple counter is similar to 3\u2212bitup/down ripple counter except that 4\u2212bit counter has one more flip\u2212flop and its clock driving circuiting.\")\nprint(\"The fig.8.14 shows the 4\u2212bit up/down ripple counter.\")\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The 4\u2212bit counter needs four flip\u2212flops.The circuit for 4\u2212bitup/down ripple counter is similar to 3\u2212bitup/down ripple counter except that 4\u2212bit counter has one more flip\u2212flop and its clock driving circuiting.\nThe fig.8.14 shows the 4\u2212bit up/down ripple counter.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.9 Page No. 8-13", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "print(\"Internal structure of 7492 is as shown in fig.8.16.\")\nprint(\"\")\nprint(\"The circuit diagram for divide\u2212by\u22129counter is as shown in fig.8.17.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Internal structure of 7492 is as shown in fig.8.16.\n\nThe circuit diagram for divide\u2212by\u22129counter is as shown in fig.8.17.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.10 Page No. 8-13", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "print(\"Since 128=16x8,a divide\u2212by\u221216 counter followed by a divide\u2212by\u22128counter will be come a divide\u2212by\u2212128 counter.IC7493 is a 4\u2212bit binary counter(i.e.mod\u221216 or divide\u2212by\u221216),therefore, two IC packages will be required.\")\nprint(\"The circuit diagram is as shown in fig.8.18.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Since 128=16x8,a divide\u2212by\u221216 counter followed by a divide\u2212by\u22128counter will be come a divide\u2212by\u2212128 counter.IC7493 is a 4\u2212bit binary counter(i.e.mod\u221216 or divide\u2212by\u221216),therefore, two IC packages will be required.\nThe circuit diagram is as shown in fig.8.18.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.11 Page No. 8-14", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "print(\"Since 78=13x6,we have to use 7493 as mod\u2212a3 and 7492 as mod\u22126 counters.For the mod\u221213 counter QD,QC and QA outputs of 7493 ans ANDed and used to clear the count when the count reaches 1101.For the mod\u22126 counter,clock is applied to B input of 7492.\")\nprint(\"The circuit diagram is as shown in the fig.8.19\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Since 78=13x6,we have to use 7493 as mod\u2212a3 and 7492 as mod\u22126 counters.For the mod\u221213 counter QD,QC and QA outputs of 7493 ans ANDed and used to clear the count when the count reaches 1101.For the mod\u22126 counter,clock is applied to B input of 7492.\nThe circuit diagram is as shown in the fig.8.19\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.12 Page No. 8-14", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "print(\"The fig.8.20 shows divided\u2212by\u22126(MOD6) counter using 7493.As shown in the fig.8.20,the clock is applied to inout B of IC7493 and the output count sequence is taken from QD,QCandQB. As soon as count is 110,i.e.QD and QC=1,the internal NAND gate output goes low and it resets the counter.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The fig.8.20 shows divided\u2212by\u22126(MOD6) counter using 7493.As shown in the fig.8.20,the clock is applied to inout B of IC7493 and the output count sequence is taken from QD,QCandQB. As soon as count is 110,i.e.QD and QC=1,the internal NAND gate output goes low and it resets the counter.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.13 Page No. 8-19", "cell_type": "markdown", "metadata": {}}, {"execution_count": 30, "cell_type": "code", "source": "print(\"For asynchronous counter the total delay that must be allowed between input clock pulses is equal to flip\u2212flop tpd+AND gate tpd.Thus Tclock>=50+20=70ns and so the counter has\")\nfm=(1/(70*pow(10,-9)))*pow(10,-6)\nprint \"fmax(in MHz)=\",round(fm,1),\"MHz\"\nprint(\"We know that MOD\u221216 ripple counter used four flip\u2212flops. With flip\u2212flop tpd=50ns,the fmax for ripple counter can be given as,\")\nfma=(1/(4*(50*pow(10,-9))))*pow(10,-6)\nprint \"fmax(ripple)(in MHz)=\",fma,\"MHz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For asynchronous counter the total delay that must be allowed between input clock pulses is equal to flip\u2212flop tpd+AND gate tpd.Thus Tclock>=50+20=70ns and so the counter has\nfmax(in MHz)= 14.3 MHz\nWe know that MOD\u221216 ripple counter used four flip\u2212flops. With flip\u2212flop tpd=50ns,the fmax for ripple counter can be given as,\nfmax(ripple)(in MHz)= 5.0 MHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.14 Page No. 8-25", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "print(\"IC74191 is a 4\u2212bit counter.Thus it is MOD\u221216 counter.However,we require MOD\u221211 counter.The difference between 16 and 11 is 5.Hence 5 steps must be skipped from the full modulus sequence. This can be achieved by presetting counter to value 5.Each time when counter recycles it starts counting from 5 upto 16 on each full cycle.Therefore,each full cycle of the counter consists of 11 states.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "IC74191 is a 4\u2212bit counter.Thus it is MOD\u221216 counter.However,we require MOD\u221211 counter.The difference between 16 and 11 is 5.Hence 5 steps must be skipped from the full modulus sequence. This can be achieved by presetting counter to value 5.Each time when counter recycles it starts counting from 5 upto 16 on each full cycle.Therefore,each full cycle of the counter consists of 11 states.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.15 Page No. 8-26", "cell_type": "markdown", "metadata": {}}, {"execution_count": 13, "cell_type": "code", "source": "print(\"IC74191 is a 4\u2212bit counter.Thus it is MOD\u221216 counter.However,we require MOD\u221210 counter.The difference between 16 and 10 is 6.Hence 6 steps must be skipped from the full modulus sequence. This can be achieved by presetting counter to value 6.Each time when counter recycles it starts counting from 6 upto 16 on each full cycle.Therefore,each full cycle of the counter consists of 10 states.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "IC74191 is a 4\u2212bit counter.Thus it is MOD\u221216 counter.However,we require MOD\u221210 counter.The difference between 16 and 10 is 6.Hence 6 steps must be skipped from the full modulus sequence. This can be achieved by presetting counter to value 6.Each time when counter recycles it starts counting from 6 upto 16 on each full cycle.Therefore,each full cycle of the counter consists of 10 states.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.16 Page No. 8-26", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "print(\"The fig8.36 shows the connections for 74LS191 to get desire operation.We can design the combinational circuit for such counter from the truth table shown below.\")\nprint(\"\")\nprint(\"Q3Q2Q1Q0Y\")\nprint(\"00000\")\nprint(\"00010\")\nprint(\"00100\")\nprint(\"00111\")\nprint(\"01001\")\nprint(\"01011\")\nprint(\"01101\")\nprint(\"01111\")\nprint(\"10001\")\nprint(\"10011\")\nprint(\"10101\")\nprint(\"10111\")\nprint(\"11001\")\nprint(\"11011\")\nprint(\"11100\")\nprint(\"11110\")\nprint(\"\")\nprint(\"Kmap simplification\")\nprint(\"Q1\u2019\u2019Q0\u2019\u2019Q1\u2019\u2019Q0Q1Q0Q1Q0\u2019\u2019\")\nprint(\"Q3\u2019\u2019Q2\u2019\u20190010\")\nprint(\"Q3\u2019\u2019Q21111\")\nprint(\"Q3Q21100\")\nprint(\"Q3Q2\u2019\u20191111\")\nprint(\"\")\nprint(\"Therefore,PL\u2019\u2019=Y=Q3\u2019\u2019Q1Q0+Q3\u2019\u2019Q2+Q3Q1\u2019\u2019+Q3Q2\u2019\u2019\")\nprint(\"After switch ON,if the counter output is other than 1101 through 0011,the PL\u2019\u2019 goes low and count 1101 is loaded in the counter.The counter is then decremented on the occurrence of clock pulses.When counter reaches 0010,the PL\u2019\u2019 again goes low and count 1101 is loaded in the counter\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The fig8.36 shows the connections for 74LS191 to get desire operation.We can design the combinational circuit for such counter from the truth table shown below.\n\nQ3Q2Q1Q0Y\n00000\n00010\n00100\n00111\n01001\n01011\n01101\n01111\n10001\n10011\n10101\n10111\n11001\n11011\n11100\n11110\n\nKmap simplification\nQ1\u2019\u2019Q0\u2019\u2019Q1\u2019\u2019Q0Q1Q0Q1Q0\u2019\u2019\nQ3\u2019\u2019Q2\u2019\u20190010\nQ3\u2019\u2019Q21111\nQ3Q21100\nQ3Q2\u2019\u20191111\n\nTherefore,PL\u2019\u2019=Y=Q3\u2019\u2019Q1Q0+Q3\u2019\u2019Q2+Q3Q1\u2019\u2019+Q3Q2\u2019\u2019\nAfter switch ON,if the counter output is other than 1101 through 0011,the PL\u2019\u2019 goes low and count 1101 is loaded in the counter.The counter is then decremented on the occurrence of clock pulses.When counter reaches 0010,the PL\u2019\u2019 again goes low and count 1101 is loaded in the counter\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.17 Page No. 8-27", "cell_type": "markdown", "metadata": {}}, {"execution_count": 15, "cell_type": "code", "source": "print(\"The IC74191 is a 4\u2212bit binary counter, therefore fout=fCLK/16 in up and down counter mode.If fCLK=500Hz and fout=50Hz we need mod10(500/50)counter.The fig.8.39 shows the mod\u221210 counter using IC74191\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The IC74191 is a 4\u2212bit binary counter, therefore fout=fCLK/16 in up and down counter mode.If fCLK=500Hz and fout=50Hz we need mod10(500/50)counter.The fig.8.39 shows the mod\u221210 counter using IC74191\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.18 Page No. 8-28", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "print(\"The fig shows the connections for 74LS191 to get desire operation.We can design the combinational circuit for such counter from the truth table shown below.\")\nprint(\"\")\nprint(\"Q3Q2Q1Q0Y\")\nprint(\"00000\")\nprint(\"00010\")\nprint(\"00100\")\nprint(\"00111\")\nprint(\"01001\")\nprint(\"01011\")\nprint(\"01101\")\nprint(\"01111\")\nprint(\"10001\")\nprint(\"10011\")\nprint(\"10101\")\nprint(\"10111\")\nprint(\"11001\")\nprint(\"11011\")\nprint(\"11101\")\nprint(\"11110\")\nprint(\"\")\nprint(\"Kmap simplification\")\nprint(\"Q1\u2019\u2019Q0\u2019\u2019Q1\u2019\u2019Q0Q1Q0Q1Q0\u2019\u2019\")\nprint(\"Q3\u2019\u2019Q2\u2019\u20190010\")\nprint(\"Q3\u2019\u2019Q21111\")\nprint(\"Q3Q21101\")\nprint(\"Q3Q2\u2019\u20191111\")\nprint(\"\")\nprint(\"Therefore,PL\u2019\u2019=Y=Q3\u2019\u2019Q1Q0+Q3\u2019\u2019Q2+Q3Q1\u2019\u2019+Q3Q2\u2019\u2019+Q2Q1Q0\u2019\u2019\")\nprint(\"After switch ON,if the counter output is other than 1110 through 0011,the PL\u2019\u2019 goes low and count 1110 is loaded in the counter.The counter is then decremented on the occurrence of clock pulses.When counter reaches 0010,the PL\u2019\u2019 again goes low and count 1110 is loaded in the counter\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The fig shows the connections for 74LS191 to get desire operation.We can design the combinational circuit for such counter from the truth table shown below.\n\nQ3Q2Q1Q0Y\n00000\n00010\n00100\n00111\n01001\n01011\n01101\n01111\n10001\n10011\n10101\n10111\n11001\n11011\n11101\n11110\n\nKmap simplification\nQ1\u2019\u2019Q0\u2019\u2019Q1\u2019\u2019Q0Q1Q0Q1Q0\u2019\u2019\nQ3\u2019\u2019Q2\u2019\u20190010\nQ3\u2019\u2019Q21111\nQ3Q21101\nQ3Q2\u2019\u20191111\n\nTherefore,PL\u2019\u2019=Y=Q3\u2019\u2019Q1Q0+Q3\u2019\u2019Q2+Q3Q1\u2019\u2019+Q3Q2\u2019\u2019+Q2Q1Q0\u2019\u2019\nAfter switch ON,if the counter output is other than 1110 through 0011,the PL\u2019\u2019 goes low and count 1110 is loaded in the counter.The counter is then decremented on the occurrence of clock pulses.When counter reaches 0010,the PL\u2019\u2019 again goes low and count 1110 is loaded in the counter\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.19 Page No. 8-28", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "print(\"IC74191 is a 4\u2212bit binary counter.Thus it divides the input frequency by 16.However,we can design MOD\u2212N counter using IC74191.For MOD\u2212 N counter the output frequency will be fout= fin/N.Thus by changing N we can change the output frequency.The fig.8.40 shows the programmable frequncy divider using IC74191.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "IC74191 is a 4\u2212bit binary counter.Thus it divides the input frequency by 16.However,we can design MOD\u2212N counter using IC74191.For MOD\u2212 N counter the output frequency will be fout= fin/N.Thus by changing N we can change the output frequency.The fig.8.40 shows the programmable frequncy divider using IC74191.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.20 Page No. 8-28", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "print(\"Fig.8.41 shows Dividing\u2212by\u22122 for up counting\")\nprint(\"Divide\u2212by\u22122 is a mod\u22122counter. Since,after preset above counter goes through 2 states 1110 and 1111,it is a mod\u22122counter.Thus,above circuit is a divide\u2212by\u22122counter for up counting mode.\")\nprint(\"\")\nprint(\"Divide\u2212by\u22125 for down counting mode:\")\nprint(\"\")\nprint(\"Q3Q2Q1Q0Y\")\nprint(\"00000\")\nprint(\"00010\")\nprint(\"00100\")\nprint(\"00110\")\nprint(\"01000\")\nprint(\"01010\")\nprint(\"01100\")\nprint(\"01110\")\nprint(\"10000\")\nprint(\"10010\")\nprint(\"10100\")\nprint(\"10111\")\nprint(\"11001\")\nprint(\"11011\")\nprint(\"11101\")\nprint(\"11111\")\nprint(\"\")\nprint(\"K=map simplification\")\nprint(\"Q1\u2019\u2019Q0\u2019\u2019Q1\u2019\u2019Q0Q1Q0Q1Q0\u2019\u2019\")\nprint(\"Q3\u2019\u2019Q2\u2019\u20190000\")\nprint(\"Q3\u2019\u2019Q20000\")\nprint(\"Q3Q21111\")\nprint(\"Q3Q2\u2019\u20190010\")\nprint(\"\")\nprint(\"Therefore,Y = Q3Q2+Q3Q1Q0\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Fig.8.41 shows Dividing\u2212by\u22122 for up counting\nDivide\u2212by\u22122 is a mod\u22122counter. Since,after preset above counter goes through 2 states 1110 and 1111,it is a mod\u22122counter.Thus,above circuit is a divide\u2212by\u22122counter for up counting mode.\n\nDivide\u2212by\u22125 for down counting mode:\n\nQ3Q2Q1Q0Y\n00000\n00010\n00100\n00110\n01000\n01010\n01100\n01110\n10000\n10010\n10100\n10111\n11001\n11011\n11101\n11111\n\nK=map simplification\nQ1\u2019\u2019Q0\u2019\u2019Q1\u2019\u2019Q0Q1Q0Q1Q0\u2019\u2019\nQ3\u2019\u2019Q2\u2019\u20190000\nQ3\u2019\u2019Q20000\nQ3Q21111\nQ3Q2\u2019\u20190010\n\nTherefore,Y = Q3Q2+Q3Q1Q0\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.21 Page No. 8-30", "cell_type": "markdown", "metadata": {}}, {"execution_count": 15, "cell_type": "code", "source": "print(\"IC74191 is a 4\u2212bit counter.Thus it is MOD\u221216 counter.However, we require MOD\u22129 counter.The difference between 16 and 9 is 7.Hence 7 steps must be skipped from the full modulus sequence. This can be achieved by presetting counter to value 7.Each time when counter recycles it starts counting from 7 upto 16 on each full cycle.Therefore,each fullcycle of the counter consists of 9 states.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "IC74191 is a 4\u2212bit counter.Thus it is MOD\u221216 counter.However, we require MOD\u22129 counter.The difference between 16 and 9 is 7.Hence 7 steps must be skipped from the full modulus sequence. This can be achieved by presetting counter to value 7.Each time when counter recycles it starts counting from 7 upto 16 on each full cycle.Therefore,each fullcycle of the counter consists of 9 states.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.22 Page No. 8-32", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "print(\"Clock frequency = 256kHz\")\nprint(\"Output frequency = 2kHz\")\nmn=256/2\nprint \"Therefore, Modnumber = n = \",mn\nprint(\"Therefore,Counter is MOD\u2212128 counter\")\nprint(\"Mod\u2212128 counter can count the numbers from 0 to 127.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Clock frequency = 256kHz\nOutput frequency = 2kHz\nTherefore, Modnumber = n = 128\nTherefore,Counter is MOD\u2212128 counter\nMod\u2212128 counter can count the numbers from 0 to 127.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.23 Page No. 8-36", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "print(\"Internal structure of 7490 ripple counter IC is as shown in fig.8.50\")\nprint(\"\")\nprint(\"We know that,one IC can work as mod\u221210(BCD) counter.Therefore,we need two ICs.The counter will go through states 0\u221219 and should be reset on state 20 .i.e.\")\nprint(\"QDQCQBQAQDQCQBQA\")\nprint(\"00100000\")\nprint(\"7490(2)7490(1)\")\nprint(\"\")\nprint(\"The diagram of divide\u2212by\u221220 counter using IC7490 is as shown in fig.8.51\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Internal structure of 7490 ripple counter IC is as shown in fig.8.50\n\nWe know that,one IC can work as mod\u221210(BCD) counter.Therefore,we need two ICs.The counter will go through states 0\u221219 and should be reset on state 20 .i.e.\nQDQCQBQAQDQCQBQA\n00100000\n7490(2)7490(1)\n\nThe diagram of divide\u2212by\u221220 counter using IC7490 is as shown in fig.8.51\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.24 Page No. 8-37", "cell_type": "markdown", "metadata": {}}, {"execution_count": 18, "cell_type": "code", "source": "print(\"IC7490 is a decade counter.When two such ICs are cascaded,it becomes a divide\u2212by\u2212100 counter.To get a divide\u2212by\u221296 counter,the counter is reset as soon as it becomes 10010110.The diagram is shown in fig.8.52.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "IC7490 is a decade counter.When two such ICs are cascaded,it becomes a divide\u2212by\u2212100 counter.To get a divide\u2212by\u221296 counter,the counter is reset as soon as it becomes 10010110.The diagram is shown in fig.8.52.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.25 Page No. 8-37", "cell_type": "markdown", "metadata": {}}, {"execution_count": 19, "cell_type": "code", "source": "print(\"IC7490 is a decadecounter.When two such ICs are cascaded,it becomes a divide\u2212by\u2212100 counter. To get a divide\u2212by\u221293counter,the counter is reset as soon as ot becomes 10010011.The diagram is as shown in fig.8.53\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "IC7490 is a decadecounter.When two such ICs are cascaded,it becomes a divide\u2212by\u2212100 counter. To get a divide\u2212by\u221293counter,the counter is reset as soon as ot becomes 10010011.The diagram is as shown in fig.8.53\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.26 Page No. 8-38", "cell_type": "markdown", "metadata": {}}, {"execution_count": 20, "cell_type": "code", "source": "print(\"IC7490 is a decade counter.When two such ICs are cascaded,it becomes a divide\u2212by\u2212100 counter.To get a divide by 78 or MOD\u221278 counter,the counter is reset as soon as ot becomes 01111000 as shown in fig.8.54\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "IC7490 is a decade counter.When two such ICs are cascaded,it becomes a divide\u2212by\u2212100 counter.To get a divide by 78 or MOD\u221278 counter,the counter is reset as soon as ot becomes 01111000 as shown in fig.8.54\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.28 Page No. 8-38", "cell_type": "markdown", "metadata": {}}, {"execution_count": 21, "cell_type": "code", "source": "print(\"If the QD output is connected to A input of 7490IC and,input clock is applied to B input 100 divide by ten squarewave is obtained at output QA.\")\nprint(\"Clock Outputs\")\nprint(\"QAQDQCQB\")\nprint(\"0LLLL\")\nprint(\"1LLLH\")\nprint(\"2LLHL\")\nprint(\"3LLHH\")\nprint(\"4LHLL\")\nprint(\"5HLLL\")\nprint(\"6HLLH\")\nprint(\"7HLHL\")\nprint(\"8HLHH\")\nprint(\"9HHLL\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "If the QD output is connected to A input of 7490IC and,input clock is applied to B input 100 divide by ten squarewave is obtained at output QA.\nClock Outputs\nQAQDQCQB\n0LLLL\n1LLLH\n2LLHL\n3LLHH\n4LHLL\n5HLLL\n6HLLH\n7HLHL\n8HLHH\n9HHLL\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.29 Page No. 8-39", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "print(\"IC 7490 is a decade counter. When two sunch ICs are cascaded, it becomes a divide-by-100 counter. To get a divide-by-25 counter, the counter is reset as soon as it becomes 0010 0101. The diagram is shown in Fig. 8.57.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "IC 7490 is a decade counter. When two sunch ICs are cascaded, it becomes a divide-by-100 counter. To get a divide-by-25 counter, the counter is reset as soon as it becomes 0010 0101. The diagram is shown in Fig. 8.57.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.31 Page No. 8-42", "cell_type": "markdown", "metadata": {}}, {"execution_count": 22, "cell_type": "code", "source": "print(\"The fig.8.63 shows the cascaded connection of 4\u2212bit binary counters.Let us see the circuit operation.ThecounterIC1operatesasacounter for countion in the UP direction since CLEAR = LOAD = 1.When the count reaches the maximum value(1111)its RC(Ripple Carry Output)goes HIGH which makes PandT(Enable)inputs of IC2 HIGH for one clockcycle advancing its output by 1 and making Q outputs of IC1,0 at the next clockcycle.After this clockcycle P=T=0 for IC2 and IC1 will go on counting the pulses.When the outputs of IC1 and IC2 both reach the maximum count,RC outputs of both of these ICs will go HIGH.This will make P=T of IC3 HIGH and therefore,in the next clockcycle IC3 count will be incrementeda nd simultaneously IC1 and IC2 will be cleared.This way the counting will continue.\")\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The fig.8.63 shows the cascaded connection of 4\u2212bit binary counters.Let us see the circuit operation.ThecounterIC1operatesasacounter for countion in the UP direction since CLEAR = LOAD = 1.When the count reaches the maximum value(1111)its RC(Ripple Carry Output)goes HIGH which makes PandT(Enable)inputs of IC2 HIGH for one clockcycle advancing its output by 1 and making Q outputs of IC1,0 at the next clockcycle.After this clockcycle P=T=0 for IC2 and IC1 will go on counting the pulses.When the outputs of IC1 and IC2 both reach the maximum count,RC outputs of both of these ICs will go HIGH.This will make P=T of IC3 HIGH and therefore,in the next clockcycle IC3 count will be incrementeda nd simultaneously IC1 and IC2 will be cleared.This way the counting will continue.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.32 Page No. 8-44", "cell_type": "markdown", "metadata": {}}, {"execution_count": 23, "cell_type": "code", "source": "print(\"Cascading four 74161(each 4\u2212bit)counters we get 16(4x4) bit counter as shown in fig8.63.\")\nprint(\"Therefore,we get 2\u02c616 = 65,536 modulus counter\")\nprint(\"However,we require divide\u2212by\u221240,000 counter.The difference between 65,536 and 40,000 is 25,536,which is the number of states those must be skipped from the full modulus sequence.This can be achieved by presetting the counting from 25,536 upto 65,536 on each fullcycle.Therefore, each fullcycle of the counter consists of 40,000 states.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Cascading four 74161(each 4\u2212bit)counters we get 16(4x4) bit counter as shown in fig8.63.\nTherefore,we get 2\u02c616 = 65,536 modulus counter\nHowever,we require divide\u2212by\u221240,000 counter.The difference between 65,536 and 40,000 is 25,536,which is the number of states those must be skipped from the full modulus sequence.This can be achieved by presetting the counting from 25,536 upto 65,536 on each fullcycle.Therefore, each fullcycle of the counter consists of 40,000 states.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.33 Page No. 8-48", "cell_type": "markdown", "metadata": {}}, {"execution_count": 13, "cell_type": "code", "source": "print(\"Although the 74X163 is a modulo\u221216 counter,it can be made to count in a modulus less than 16 by using the CLR\u2019\u2019or LD\u2019\u2019 input to shorten the normal counting sequence.The fig.8.69 shows circuit connections for modulo\u221211 counter.Here, load input is activated upon activation of RCO(ripple\u2212carry\u2212output).Since load input is adjusted to state 5,counter counts from 5 to 15 and then starts at 5 again,for a total of 11 states per counting cycle.\")\nprint(\"\")\nprint(\"We can also design modulo\u221211 counter using CLR\u2019\u2019 input as shown in fig.8.70.Here,NAND gate is used to detect state 10 and force the next state to 0. A2\u2212input gate is used to detect state 10 (binary 1010)by connecting Q1 and Q3 to the inputs of the NAND gate.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Although the 74X163 is a modulo\u221216 counter,it can be made to count in a modulus less than 16 by using the CLR\u2019\u2019or LD\u2019\u2019 input to shorten the normal counting sequence.The fig.8.69 shows circuit connections for modulo\u221211 counter.Here, load input is activated upon activation of RCO(ripple\u2212carry\u2212output).Since load input is adjusted to state 5,counter counts from 5 to 15 and then starts at 5 again,for a total of 11 states per counting cycle.\n\nWe can also design modulo\u221211 counter using CLR\u2019\u2019 input as shown in fig.8.70.Here,NAND gate is used to detect state 10 and force the next state to 0. A2\u2212input gate is used to detect state 10 (binary 1010)by connecting Q1 and Q3 to the inputs of the NAND gate.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.34 Page No. 8-49", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "print(\"An excess\u22123 decimal counter should start counting from count3(binary0011) and count upto count 12(binary1100).Starting count is adjusted by loading 0011 at load inputs.To recycle count from 1100 to 0011,Q3 and Q2 output are connected as inputs for 2\u2212input NAND gate. Thus,NAND gate detects state 1100 and forces 0011 to be loaded as the next state.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "An excess\u22123 decimal counter should start counting from count3(binary0011) and count upto count 12(binary1100).Starting count is adjusted by loading 0011 at load inputs.To recycle count from 1100 to 0011,Q3 and Q2 output are connected as inputs for 2\u2212input NAND gate. Thus,NAND gate detects state 1100 and forces 0011 to be loaded as the next state.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.35 Page No. 8-50", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "print(\"A binary counter with a modulus greater than 16 can be built by cascading 74X163s.When counters are cascaded,CLK,CLR\u2019\u2019and LD\u2019\u2019 of all the 74X163s are connected in parallel,so that all of them count or are cleared or loaded at the sametime.The RCO signal drives the ENT input of the next counter.The fig.8.73 shows modulo\u221260 counter.To have a modulo 60 count we need at least 6\u2212bit counter,thus two 74X163s are cascaded.Counter is designed to count from 196 to 255.The MAXCNT signal detects the state 255 and stops the counter util GO\u2019\u2019is asserted.When GO\u2019\u2019 is asserted the counter is reloaded with 196(binary 11000100) and counts upto 255.To enable counting, CNTEN is connected to the ENP inputs in parallel.A NAND gate assets RELOAD\u2019\u2019 to get back to state only if GO\u2019\u2019 is asserted and the counter is in state 255.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "A binary counter with a modulus greater than 16 can be built by cascading 74X163s.When counters are cascaded,CLK,CLR\u2019\u2019and LD\u2019\u2019 of all the 74X163s are connected in parallel,so that all of them count or are cleared or loaded at the sametime.The RCO signal drives the ENT input of the next counter.The fig.8.73 shows modulo\u221260 counter.To have a modulo 60 count we need at least 6\u2212bit counter,thus two 74X163s are cascaded.Counter is designed to count from 196 to 255.The MAXCNT signal detects the state 255 and stops the counter util GO\u2019\u2019is asserted.When GO\u2019\u2019 is asserted the counter is reloaded with 196(binary 11000100) and counts upto 255.To enable counting, CNTEN is connected to the ENP inputs in parallel.A NAND gate assets RELOAD\u2019\u2019 to get back to state only if GO\u2019\u2019 is asserted and the counter is in state 255.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.36 Page No. 8-50", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "print(\"A binary counter maybe combined with a decoder to obtain a set of 1\u2212out\u2212of\u2212M coded signals,where one signal is asserted in each count state.This is useful when countersare used to control a set of devices,where a different devices is enabled in each counter state.\")\nprint(\"The fig.8.74 shows a 74X163 connected as a modulo\u22128 counter can be combined with a 74X138 3\u22128 decoder to provide eight signals,each one representing a counter state.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "A binary counter maybe combined with a decoder to obtain a set of 1\u2212out\u2212of\u2212M coded signals,where one signal is asserted in each count state.This is useful when countersare used to control a set of devices,where a different devices is enabled in each counter state.\nThe fig.8.74 shows a 74X163 connected as a modulo\u22128 counter can be combined with a 74X138 3\u22128 decoder to provide eight signals,each one representing a counter state.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.37 Page No. 8-62", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "print(\"Excitation table\")\nprint(\"PresentState NextState Flip\u2212flop Inputs\")\nprint(\"QDQCQBQAQD+1QC+1QB+1QA+1JKDJKCJKBJKA\")\nprint(\"000000010001\")\nprint(\"000100100011\")\nprint(\"001000110001\")\nprint(\"001101000111\")\nprint(\"010001010001\")\nprint(\"010101100011\")\nprint(\"011001110001\")\nprint(\"011110001111\")\nprint(\"100010010001\")\nprint(\"100100001001\")\nprint(\"1010XXXXXXX1\")\nprint(\"1011XXXXXXX1\")\nprint(\"1100XXXXXXXX\")\nprint(\"1101XXXXXXXX\")\nprint(\"1110XXXXXXXX\")\nprint(\"1111XXXXXXXX\")\nprint(\"\")\nprint(\"K\u2212map Simplification\")\nprint(\"For JKD\")\nprint(\"QB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\")\nprint(\"QD\u2019\u2019QC\u2019\u20190000\")\nprint(\"QD\u2019\u2019QC0010\")\nprint(\"QDQCXXXX\")\nprint(\"QDQC\u2019\u201901XX\")\nprint(\"JKD = QAQD+QAQBQC\")\nprint(\"\")\nprint(\"For JKC\")\nprint(\"QB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\")\nprint(\"QD\u2019\u2019QC\u2019\u20190010\")\nprint(\"QD\u2019\u2019QC0010\")\nprint(\"QDQCXXXX\")\nprint(\"QDQC\u2019\u201900XX\")\nprint(\"JKC = QAQB\")\nprint(\"\")\nprint(\"For JKB\")\nprint(\"QB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\")\nprint(\"QD\u2019\u2019QC\u2019\u20190110\")\nprint(\"QD\u2019\u2019QC0110\")\nprint(\"QDQCXXXX\")\nprint(\"QDQC\u2019\u201900XX\")\nprint(\"JKB = QAQD\u2019\u2019\")\nprint(\"\")\nprint(\"For JKA\")\nprint(\"QB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\")\nprint(\"QD\u2019\u2019QC\u2019\u20191111\")\nprint(\"QD\u2019\u2019QC1111\")\nprint(\"QDQCXXXX\")\nprint(\"QDQC\u2019\u201911XX\")\nprint(\"JKA = 1\")\nprint(\"\")\nprint(\"Fig shows the logic diagram for the synchronous decade counter using JK flip\u2212flop\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Excitation table\nPresentState NextState Flip\u2212flop Inputs\nQDQCQBQAQD+1QC+1QB+1QA+1JKDJKCJKBJKA\n000000010001\n000100100011\n001000110001\n001101000111\n010001010001\n010101100011\n011001110001\n011110001111\n100010010001\n100100001001\n1010XXXXXXX1\n1011XXXXXXX1\n1100XXXXXXXX\n1101XXXXXXXX\n1110XXXXXXXX\n1111XXXXXXXX\n\nK\u2212map Simplification\nFor JKD\nQB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\nQD\u2019\u2019QC\u2019\u20190000\nQD\u2019\u2019QC0010\nQDQCXXXX\nQDQC\u2019\u201901XX\nJKD = QAQD+QAQBQC\n\nFor JKC\nQB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\nQD\u2019\u2019QC\u2019\u20190010\nQD\u2019\u2019QC0010\nQDQCXXXX\nQDQC\u2019\u201900XX\nJKC = QAQB\n\nFor JKB\nQB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\nQD\u2019\u2019QC\u2019\u20190110\nQD\u2019\u2019QC0110\nQDQCXXXX\nQDQC\u2019\u201900XX\nJKB = QAQD\u2019\u2019\n\nFor JKA\nQB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\nQD\u2019\u2019QC\u2019\u20191111\nQD\u2019\u2019QC1111\nQDQCXXXX\nQDQC\u2019\u201911XX\nJKA = 1\n\nFig shows the logic diagram for the synchronous decade counter using JK flip\u2212flop\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.38 Page No. 8-64", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "print(\"Excitation table\")\nprint(\"Input PresentState NextState Flip\u2212flop Inputs\")\nprint(\"UP/DOWN\u2019\u2019QCQBQAQC+1QB+1QA+1JKCJKBJKA\")\nprint(\"UD\")\nprint(\"0000111111\")\nprint(\"0001000001\")\nprint(\"0010001011\")\nprint(\"0011010001\")\nprint(\"0100011111\")\nprint(\"0101100001\")\nprint(\"0110101011\")\nprint(\"0111110001\")\nprint(\"1000001001\")\nprint(\"1001010011\")\nprint(\"1010011001\")\nprint(\"1011100111\")\nprint(\"1100101001\")\nprint(\"1101110011\")\nprint(\"1110111001\")\nprint(\"1111000111\")\nprint(\"\")\nprint(\"K\u2212map Simplification\")\nprint(\"For JKC\")\nprint(\"QB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\")\nprint(\"QD\u2019\u2019QC\u2019\u20191000\")\nprint(\"QD\u2019\u2019QC1000\")\nprint(\"QDQC0010\")\nprint(\"QDQC\u2019\u20190010\")\nprint(\"JKC = UD\u2019\u2019QB\u2019\u2019QB\u2019\u2019+UDQBQA\")\nprint(\"\")\nprint(\"For JKB\")\nprint(\"QB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\")\nprint(\"QD\u2019\u2019QC\u2019\u20191001\")\nprint(\"QD\u2019\u2019QC1001\")\nprint(\"QDQC0110\")\nprint(\"QDQC\u2019\u20190110\")\nprint(\"TB = UD\u2019\u2019QA\u2019\u2019+UDQA\")\nprint(\"\")\nprint(\"For JKA\")\nprint(\"QB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\")\nprint(\"QD\u2019\u2019QC\u2019\u20191111\")\nprint(\"QD\u2019\u2019QC1111\")\nprint(\"QDQC1111\")\nprint(\"QDQC\u2019\u20191111\")\nprint(\"TA = 1\")\nprint(\"\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Excitation table\nInput PresentState NextState Flip\u2212flop Inputs\nUP/DOWN\u2019\u2019QCQBQAQC+1QB+1QA+1JKCJKBJKA\nUD\n0000111111\n0001000001\n0010001011\n0011010001\n0100011111\n0101100001\n0110101011\n0111110001\n1000001001\n1001010011\n1010011001\n1011100111\n1100101001\n1101110011\n1110111001\n1111000111\n\nK\u2212map Simplification\nFor JKC\nQB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\nQD\u2019\u2019QC\u2019\u20191000\nQD\u2019\u2019QC1000\nQDQC0010\nQDQC\u2019\u20190010\nJKC = UD\u2019\u2019QB\u2019\u2019QB\u2019\u2019+UDQBQA\n\nFor JKB\nQB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\nQD\u2019\u2019QC\u2019\u20191001\nQD\u2019\u2019QC1001\nQDQC0110\nQDQC\u2019\u20190110\nTB = UD\u2019\u2019QA\u2019\u2019+UDQA\n\nFor JKA\nQB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\nQD\u2019\u2019QC\u2019\u20191111\nQD\u2019\u2019QC1111\nQDQC1111\nQDQC\u2019\u20191111\nTA = 1\n\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.39 Page No. 8-66", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "print(\"For mod\u22125 counter we require 3 flip\u2212flops.\")\nprint(\"Excitation table\")\nprint(\"PresentState NextState Flip\u2212flop Inputs\")\nprint(\"QCQBQAQA+1QB+1QC+1TATBTC\")\nprint(\"0000001001\")\nprint(\"1001010011\")\nprint(\"2010011001\")\nprint(\"3011100111\")\nprint(\"4100000100\")\nprint(\"\")\nprint(\"K\u2212map Simplification\")\nprint(\"QB\u2019\u2019QC\u2019\u2019QB\u2019\u2019QCQBQCQBQC\u2019\u2019\")\nprint(\"QA\u2019\u20190010\")\nprint(\"QA1XXX\")\nprint(\"TA = QA+QBQC\")\nprint(\"\")\nprint(\"QB\u2019\u2019QC\u2019\u2019QB\u2019\u2019QCQBQCQBQC\u2019\u2019\")\nprint(\"QA\u2019\u20190110\")\nprint(\"QA0XXX\")\nprint(\"TB = QC\")\nprint(\"\")\nprint(\"QB\u2019\u2019QC\u2019\u2019QB\u2019\u2019QCQBQCQBQC\u2019\u2019\")\nprint(\"QA\u2019\u20191111\")\nprint(\"QA0XXX\")\nprint(\"TC = QA\u2019\u2019\")\nprint(\"\")\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For mod\u22125 counter we require 3 flip\u2212flops.\nExcitation table\nPresentState NextState Flip\u2212flop Inputs\nQCQBQAQA+1QB+1QC+1TATBTC\n0000001001\n1001010011\n2010011001\n3011100111\n4100000100\n\nK\u2212map Simplification\nQB\u2019\u2019QC\u2019\u2019QB\u2019\u2019QCQBQCQBQC\u2019\u2019\nQA\u2019\u20190010\nQA1XXX\nTA = QA+QBQC\n\nQB\u2019\u2019QC\u2019\u2019QB\u2019\u2019QCQBQCQBQC\u2019\u2019\nQA\u2019\u20190110\nQA0XXX\nTB = QC\n\nQB\u2019\u2019QC\u2019\u2019QB\u2019\u2019QCQBQCQBQC\u2019\u2019\nQA\u2019\u20191111\nQA0XXX\nTC = QA\u2019\u2019\n\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.40 Page No. 8-67", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "print(\"Excitation table\")\nprint(\"PresentState NextState Flip\u2212flop Inputs\")\nprint(\"QCQBA+B+JAKAJBKB\")\nprint(\"00111X1X\")\nprint(\"01000XX1\")\nprint(\"1001X11X\")\nprint(\"1110X0X1\")\nprint(\"\")\nprint(\"K\u2212map Simplification\")\nprint(\"For JA\")\nprint(\"B\u2019\u2019B\")\nprint(\"A\u2019\u201910\")\nprint(\"AXX\")\nprint(\"JA = B\u2019\u2019\")\nprint(\"\")\nprint(\"For KA\")\nprint(\"B\u2019\u2019B\")\nprint(\"A\u2019\u2019XX\")\nprint(\"A10\")\nprint(\"KA = B\u2019\u2019\")\nprint(\"\")\nprint(\"For JB\")\nprint(\"B\u2019\u2019B\")\nprint(\"A\u2019\u20191X\")\nprint(\"A1X\")\nprint(\"JB = 1\")\nprint(\"\")\nprint(\"For KB\")\nprint(\"B\u2019\u2019B\")\nprint(\"A\u2019\u2019X1\")\nprint(\"AX1\")\nprint(\"KB = 1\")\nprint(\"\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Excitation table\nPresentState NextState Flip\u2212flop Inputs\nQCQBA+B+JAKAJBKB\n00111X1X\n01000XX1\n1001X11X\n1110X0X1\n\nK\u2212map Simplification\nFor JA\nB\u2019\u2019B\nA\u2019\u201910\nAXX\nJA = B\u2019\u2019\n\nFor KA\nB\u2019\u2019B\nA\u2019\u2019XX\nA10\nKA = B\u2019\u2019\n\nFor JB\nB\u2019\u2019B\nA\u2019\u20191X\nA1X\nJB = 1\n\nFor KB\nB\u2019\u2019B\nA\u2019\u2019X1\nAX1\nKB = 1\n\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.41 Page No. 8-67", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "print(\"Mod\u221212 synchronous counter using D flip\u2212flop:\")\nprint(\"Let Number of flip\u2212flop required=n\")\nprint(\"2\u02c6n >= 12\")\nprint(\"n = 4\")\nprint(\"Excitation table\")\nprint(\"PresentState NextState\")\nprint(\"QDQCQBQAQD+1QC+1QB+1QA+1\")\nprint(\"00000001\")\nprint(\"00010010\")\nprint(\"00100011\")\nprint(\"00110100\")\nprint(\"01000101\")\nprint(\"01010110\")\nprint(\"01100111\")\nprint(\"01111000\")\nprint(\"10001001\")\nprint(\"10011010\")\nprint(\"10101011\")\nprint(\"10110000\")\nprint(\"\")\nprint(\"K\u2212map Simplification\")\nprint(\"For DA\")\nprint(\"QB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\")\nprint(\"QD\u2019\u2019QC\u2019\u20191001\")\nprint(\"QD\u2019\u2019QC1001\")\nprint(\"QDQCXXXX\")\nprint(\"QDQC\u2019\u20191001\")\nprint(\"DA = QA\u2019\u2019\")\nprint(\"\")\nprint(\"For DB\")\nprint(\"QB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\")\nprint(\"QD\u2019\u2019QC\u2019\u20190101\")\nprint(\"QD\u2019\u2019QC0101\")\nprint(\"QDQCXXXX\")\nprint(\"QDQC\u2019\u20190101\")\nprint(\"DB = QB\u2019\u2019QaA+QA\u2019\u2019QB\")\nprint(\"DB = QA XOR QB\")\nprint(\"\")\nprint(\"For DC\")\nprint(\"QB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\")\nprint(\"QD\u2019\u2019QC\u2019\u20190010\")\nprint(\"QD\u2019\u2019QC1101\")\nprint(\"QDQCXXXX\")\nprint(\"QDQC\u2019\u20190000\")\nprint(\"DC = QCQB\u2019\u2019+QCQA\u2019\u2019+QD\u2019\u2019QC\u2019\u2019QBQA\")\nprint(\"\")\nprint(\"For DD\")\nprint(\"QB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\")\nprint(\"QD\u2019\u2019QC\u2019\u20190000\")\nprint(\"QD\u2019\u2019QC0010\")\nprint(\"QDQCXXXX\")\nprint(\"QDQC\u2019\u20191101\")\nprint(\"DD = QDQB\u2019\u2019+QCQBQA+QDQA\u2019\u2019\")\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Mod\u221212 synchronous counter using D flip\u2212flop:\nLet Number of flip\u2212flop required=n\n2\u02c6n >= 12\nn = 4\nExcitation table\nPresentState NextState\nQDQCQBQAQD+1QC+1QB+1QA+1\n00000001\n00010010\n00100011\n00110100\n01000101\n01010110\n01100111\n01111000\n10001001\n10011010\n10101011\n10110000\n\nK\u2212map Simplification\nFor DA\nQB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\nQD\u2019\u2019QC\u2019\u20191001\nQD\u2019\u2019QC1001\nQDQCXXXX\nQDQC\u2019\u20191001\nDA = QA\u2019\u2019\n\nFor DB\nQB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\nQD\u2019\u2019QC\u2019\u20190101\nQD\u2019\u2019QC0101\nQDQCXXXX\nQDQC\u2019\u20190101\nDB = QB\u2019\u2019QaA+QA\u2019\u2019QB\nDB = QA XOR QB\n\nFor DC\nQB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\nQD\u2019\u2019QC\u2019\u20190010\nQD\u2019\u2019QC1101\nQDQCXXXX\nQDQC\u2019\u20190000\nDC = QCQB\u2019\u2019+QCQA\u2019\u2019+QD\u2019\u2019QC\u2019\u2019QBQA\n\nFor DD\nQB\u2019\u2019QA\u2019\u2019QB\u2019\u2019QAQBQAQBQA\u2019\u2019\nQD\u2019\u2019QC\u2019\u20190000\nQD\u2019\u2019QC0010\nQDQCXXXX\nQDQC\u2019\u20191101\nDD = QDQB\u2019\u2019+QCQBQA+QDQA\u2019\u2019\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.42 Page No. 8-71", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "print(\"The fig.8.99 shows the circuit diagram for a 4\u2212bit,4\u2212statering counter with a single circulating 1.Here,74X194 universal shift register is connected so that it normally preforms a left\u2212shift.However,when RESET is asserted it loads 0001.Once RESET is negated, the 74194 shifts left on each clock pulse.The DSL serial input is connected to the leftmost output(Q3:MSB),so the next states are 0010, 0100,1000,0001,0010,.....Thus the counter counter visits four unique states before repeating.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The fig.8.99 shows the circuit diagram for a 4\u2212bit,4\u2212statering counter with a single circulating 1.Here,74X194 universal shift register is connected so that it normally preforms a left\u2212shift.However,when RESET is asserted it loads 0001.Once RESET is negated, the 74194 shifts left on each clock pulse.The DSL serial input is connected to the leftmost output(Q3:MSB),so the next states are 0010, 0100,1000,0001,0010,.....Thus the counter counter visits four unique states before repeating.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.44 Page No. 8-76", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "print(\"Johnson counter is basically at wistedring counter.The fig.8.104(a) shows the basic circuit for a Johnson counter.The table shows the states of a 4\u2212bit Johnson counter.\")\nprint(\"\")\nprint(\"States of 4\u2212bit Johnson counter\")\nprint(\"Statename Q3 Q2 Q1 Q0\")\nprint(\"S1 0 0 0 0\")\nprint(\"S2 0 0 0 1\")\nprint(\"S3 0 0 1 1\")\nprint(\"S4 0 1 1 1\")\nprint(\"S5 1 1 1 1\")\nprint(\"S6 1 1 1 0\")\nprint(\"S7 1 1 0 0\")\nprint(\"S8 1 0 0 0\")\nprint(\"\")\nprint(\"This counter can be modified to have self correcting Johnson counter as shown in fig.8.104(c).Here,the connections are made such that circuit loads 0001 as the next state whenever the current state is 0XX0.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Johnson counter is basically at wistedring counter.The fig.8.104(a) shows the basic circuit for a Johnson counter.The table shows the states of a 4\u2212bit Johnson counter.\n\nStates of 4\u2212bit Johnson counter\nStatename Q3 Q2 Q1 Q0\nS1 0 0 0 0\nS2 0 0 0 1\nS3 0 0 1 1\nS4 0 1 1 1\nS5 1 1 1 1\nS6 1 1 1 0\nS7 1 1 0 0\nS8 1 0 0 0\n\nThis counter can be modified to have self correcting Johnson counter as shown in fig.8.104(c).Here,the connections are made such that circuit loads 0001 as the next state whenever the current state is 0XX0.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8.45 Page No. 8-78", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "print(\"Johnson counter will produce a modulus of 2xn where n is the number of stages (i.e. flip\u2212flops) in the counter.Therefore, Mod10 requires 5 flip\u2212flops and Mod16 requires 8 flip\u2212flops.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Johnson counter will produce a modulus of 2xn where n is the number of stages (i.e. flip\u2212flops) in the counter.Therefore, Mod10 requires 5 flip\u2212flops and Mod16 requires 8 flip\u2212flops.\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter9.ipynb b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter9.ipynb
new file mode 100755
index 00000000..d9462e91
--- /dev/null
+++ b/Analog_And_Digital_Electronics_by__U._A._Bakshi_And_A._P._Godse/Chapter9.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 9", "cell_type": "markdown", "metadata": {}}, {"source": "# Op amp Applications", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 9.1 Page No. 9-6", "cell_type": "markdown", "metadata": {}}, {"execution_count": 41, "cell_type": "code", "source": "import math\n\nprint(\"The differential amplifier is represented as shown in fig.9.5.\")\nprint(\"(i)CMRR = 100\")\nvd = 300-240\nprint \"Vd(in uV)=V1\u2212V2=\",vd,\"uV\"\nvc=(300+240)/2\nprint \"Vc(in uV)=V1+V2/2=\",vc,\"uV\"\nprint(\"CMRR=Ad/Ac\")\nac=5000/100\nprint \"Therefore,Ac=\",ac\nvo=((5000*60)+(50*270))*pow(10,-3)\nprint \"Therefore,Vo(in mV)=Ad\u2217Vd+Ac\u2217Vc=\",vo,\"mV\"\nprint(\"(ii)CMRR=10\u02c65\")\nac=5000.0/pow(10,5)\nprint \"Therefore,Ac=Ad/CMRR=\",ac\nvo=((5000*60)+(0.05*270))*pow(10,-3)\nprint\"Therefore,Vo(in mV)=Ad\u2217Vd+Ac\u2217Vc=\",vo,\"mV\"\nprint(\"Ideally Ac must be zero and output should be only Ad\u2217Vd which is 5000\u221760\u221710\u02c6\u22126 i.e.300mV.It can be seen that higher the value of CMRR,the output is almost proportional to the difference voltage Vd,rejecting the common mode signal.So ideal value of CMRR for a differential amplifier is infinity.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The differential amplifier is represented as shown in fig.9.5.\n(i)CMRR = 100\nVd(in uV)=V1\u2212V2= 60 uV\nVc(in uV)=V1+V2/2= 270 uV\nCMRR=Ad/Ac\nTherefore,Ac= 50\nTherefore,Vo(in mV)=Ad\u2217Vd+Ac\u2217Vc= 313.5 mV\n(ii)CMRR=10\u02c65\nTherefore,Ac=Ad/CMRR= 0.05\nTherefore,Vo(in mV)=Ad\u2217Vd+Ac\u2217Vc= 300.0135 mV\nIdeally Ac must be zero and output should be only Ad\u2217Vd which is 5000\u221760\u221710\u02c6\u22126 i.e.300mV.It can be seen that higher the value of CMRR,the output is almost proportional to the difference voltage Vd,rejecting the common mode signal.So ideal value of CMRR for a differential amplifier is infinity.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.2 Page No. 9-13", "cell_type": "markdown", "metadata": {}}, {"execution_count": 42, "cell_type": "code", "source": "import math\n\nprint(\"The two input base currents are\")\nprint(\"Ibi = 18uA and Ib2 = 22uA\")\nprint(\"i) The input bias current is\")\nprint(\"Ib = (Ib1+Ib2)/2\")\nIb = (18+22)/2\nprint \"Ib = \",Ib,\"uA\"\nprint(\"ii) The input offset current is\")\nprint(\"Iios = |Ib1 - Ib2|\")\nIios = abs(18-22)\nprint \"Iios = \",Iios,\"uA\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The two input base currents are\nIbi = 18uA and Ib2 = 22uA\ni) The input bias current is\nIb = (Ib1+Ib2)/2\nIb = 20 uA\nii) The input offset current is\nIios = |Ib1 - Ib2|\nIios = 4 uA\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.3 Page No. 9-14", "cell_type": "markdown", "metadata": {}}, {"execution_count": 43, "cell_type": "code", "source": "import math\n\nprint(\"IiOS = 20nA,Ib = 60nA\")\nprint(\"Now IiOS = Ib1\u2212Ib2 = 20\")\nprint(\"Ib = Ib1+Ib2/2 = 60\")\nprint(\"Therefore,Ib1+Ib2 = 120\")\nprint(\"Therefore,2\u2217Ib1 = 140\")\nprint(\"Therefore,Ib1 = 70nA,Ib2 = 50nA\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "IiOS = 20nA,Ib = 60nA\nNow IiOS = Ib1\u2212Ib2 = 20\nIb = Ib1+Ib2/2 = 60\nTherefore,Ib1+Ib2 = 120\nTherefore,2\u2217Ib1 = 140\nTherefore,Ib1 = 70nA,Ib2 = 50nA\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.4 Page No. 9-30", "cell_type": "markdown", "metadata": {}}, {"execution_count": 44, "cell_type": "code", "source": "import math\n\nprint(\"VUT = +4V,VLT = \u22124V,Supply = +\u221215V\")\nprint(\"+\u2212Vsat = 0.9x[Supply] = +\u221213.5V = Vo\")\nprint(\"For op\u2212amp741,IB(max) = 500nA\")\nprint(\"Therefore,I2 = 100IB(max) = 50uA\")\nr2=(4.0/(50.0*pow(10,-6)))*pow(10,-3)\nprint \"Therefore,R2(in kohm) = VUT/I2 =\",r2,\"KOhm\"\ni2=(4.0/(82.0*pow(10,3)))*pow(10,6)\nprint \"Recalculating I2, I2 = VUT/R2 =\",round(i2,2),\"uA\"\nr1=((13.5-4)/(48.78*pow(10,-6)))*pow(10,-3)\nprint \"Therefore,R1 = Vo\u2212VUT/I2 = +Vsat\u2212VUT/I2 =\",round(r1,2),\"KOhm (Use 180KOhm Standard)\"\nprint(\"The designed circuit is shown in fig 9.32\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "VUT = +4V,VLT = \u22124V,Supply = +\u221215V\n+\u2212Vsat = 0.9x[Supply] = +\u221213.5V = Vo\nFor op\u2212amp741,IB(max) = 500nA\nTherefore,I2 = 100IB(max) = 50uA\nTherefore,R2(in kohm) = VUT/I2 = 80.0 KOhm\nRecalculating I2, I2 = VUT/R2 = 48.78 uA\nTherefore,R1 = Vo\u2212VUT/I2 = +Vsat\u2212VUT/I2 = 194.75 KOhm (Use 180KOhm Standard)\nThe designed circuit is shown in fig 9.32\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.5 Page No. 9-32", "cell_type": "markdown", "metadata": {}}, {"execution_count": 45, "cell_type": "code", "source": "import math\n\nprint(\"VCC = +15V\")\nvsat=0.9*15\nprint \"Therefore,Vsat(in V) = 0.9VCC =\",vsat,\"V\"\nprint(\"R1 = 51kohm, R2 = 120ohm\")\nvut=(13.5*120)/((51*pow(10,3))+120)\nprint \"VUT(in V) = +Vsat\u2217R2/R1+R2 =\",round(vut,5),\"V\"\nvlt=(-13.5*120)/((51*pow(10,3))+120)\nprint \"VLT(in V) =\u2212Vsat\u2217R2/R1+R2 =\",round(vlt,5),\"V\"\nh=(0.03169*2)*pow(10,3)\nprint \"H(in mV) = VUT\u2212VLT =\",h,\"mV\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "VCC = +15V\nTherefore,Vsat(in V) = 0.9VCC = 13.5 V\nR1 = 51kohm, R2 = 120ohm\nVUT(in V) = +Vsat\u2217R2/R1+R2 = 0.03169 V\nVLT(in V) =\u2212Vsat\u2217R2/R1+R2 = -0.03169 V\nH(in mV) = VUT\u2212VLT = 63.38 mV\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.6 Page No. 9-33", "cell_type": "markdown", "metadata": {}}, {"execution_count": 46, "cell_type": "code", "source": "import math\n\nprint(\"As input is applied to the non\u2212inverting terminal, the circuit is non\u2212inverting Schmitt trigger.\")\nprint(\"R1 = 100kohm,R2 = 1kohm\")\nvut=13.5*(0.01) #Note 1/100 = 0.01\nprint \"Therefore,VUT(in V) = +Vsat\u2217R2/R1=\",vut,\"V\"\nvlt=-13.5*(0.01) #Note 1/100 = 0.01\nprint \"Therefore,VLT(in V) = \u2212Vsat\u2217R2/R1 =\",vlt,\"V\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "As input is applied to the non\u2212inverting terminal, the circuit is non\u2212inverting Schmitt trigger.\nR1 = 100kohm,R2 = 1kohm\nTherefore,VUT(in V) = +Vsat\u2217R2/R1= 0.135 V\nTherefore,VLT(in V) = \u2212Vsat\u2217R2/R1 = -0.135 V\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.7 Page No. 9-36", "cell_type": "markdown", "metadata": {}}, {"execution_count": 47, "cell_type": "code", "source": "import math\n\nprint(\"The given comparator is inverting Schmitt trigger with R1 = 4KOhm and R2 = 1KOhm\")\nprint(\"Vsat = 0.9 Vcc = 0.9x12 = 10.8 V\")\nprint(\"The threshold levels are,\")\nprint(\"Vut = (+Vsat*R2)/(R1+r2)\")\nVut = (10.8*1.0)/(1.0+4.0)\nprint \"Vut = \",Vut,\"V\"\nprint(\"VLt = (-Vsat*R2)/(R1+r2)\")\nVut = (-10.8*1.0)/(1.0+4.0)\nprint \"Vut = \",Vut,\"V\"\nprint(\"Vin = 10V\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The given comparator is inverting Schmitt trigger with R1 = 4KOhm and R2 = 1KOhm\nVsat = 0.9 Vcc = 0.9x12 = 10.8 V\nThe threshold levels are,\nVut = (+Vsat*R2)/(R1+r2)\nVut = 2.16 V\nVLt = (-Vsat*R2)/(R1+r2)\nVut = -2.16 V\nVin = 10V\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.8 Page No. 9-38", "cell_type": "markdown", "metadata": {}}, {"execution_count": 48, "cell_type": "code", "source": "import math\n\nprint(\"LTP =\u22121.5V and H=2V\")\nprint(\"Now H=UTP\u2212LTP\")\nprint(\"Therefore,2=UTP\u2212(\u22121.5)\")\nprint(\"Therefore,UTP=0.5V\")\nprint(\"Inthefig.9.47,the angle theta can be obtained from equation of sinewave. Sinewave is represented as,\")\nprint(\"Vin=Vp\u2217sin(pi+thata) when pi<omega\u2217t<2pi\")\nprint(\"At LTP,\u22121.5=5\u2217sin(pi+theta)\")\nprint(\"=\u22125\u2217sin(theta)\")\nprint(\"Therefore,sin(theta)=0.3\")\nprint \"Therefore,theta(in degree) = 17.45 degrees\"\nprint(\"The time period of sinewave is,\")\nT=1\nprint \"T(in ms)=1/f=\",T,\"msec\"\nprint(\"At UTP,0.5=Vp\u2217sin(theta)\")\nprint(\"Therefore,0.5=5\u2217sin(theta)\")\nprint(\"Therefore,sin(theta)=0.1\")\nprint \"Therefore,theta(in degree) = 5.739 degrees\"\nprint(\"The time T1 for output is from 5.739degree to (180degree+17.45degree)\")\nt1=197.45-5.739\nprint \"Therefore,T1(in degree)=\",round(t1,2),\"degrees\"\nT1=(191.71/360)\nprint \"i.e.T1(ms)=\",round(T1,4),\"msec\"\nt2=1-0.5325\nprint \"andT2(in ms)=T\u2212T1=\",round(t2,4),\"msec\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "LTP =\u22121.5V and H=2V\nNow H=UTP\u2212LTP\nTherefore,2=UTP\u2212(\u22121.5)\nTherefore,UTP=0.5V\nInthefig.9.47,the angle theta can be obtained from equation of sinewave. Sinewave is represented as,\nVin=Vp\u2217sin(pi+thata) when pi<omega\u2217t<2pi\nAt LTP,\u22121.5=5\u2217sin(pi+theta)\n=\u22125\u2217sin(theta)\nTherefore,sin(theta)=0.3\nTherefore,theta(in degree) = 17.45 degrees\nThe time period of sinewave is,\nT(in ms)=1/f= 1 msec\nAt UTP,0.5=Vp\u2217sin(theta)\nTherefore,0.5=5\u2217sin(theta)\nTherefore,sin(theta)=0.1\nTherefore,theta(in degree) = 5.739 degrees\nThe time T1 for output is from 5.739degree to (180degree+17.45degree)\nTherefore,T1(in degree)= 191.71 degrees\ni.e.T1(ms)= 0.5325 msec\nandT2(in ms)=T\u2212T1= 0.4675 msec\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.9 Page No. 9-39", "cell_type": "markdown", "metadata": {}}, {"execution_count": 49, "cell_type": "code", "source": "import math\n\nprint(\"Given +Vsat=12V,\u2212Vsat=\u221212V,VH=6V\")\nprint(\"We know that hysteres is width is given as\")\nprint(\"VH=(R2/R1+R2)[+Vsat\u2212Vsat]\")\nprint(\"Therefore,R2/R1+R2=VH/+Vsat\u2212Vsat\")\nr=6.0/(24.0)\nprint \"Therefore,R2/R1+R2=\",r\nprint(\"Therefore,R2=0.25R1+0.25R2\")\nprint(\"Therefore,0.75R2=0.25R1\")\nr2=0.25/0.75\nprint \"Therefore,R2/R1=\",round(r2,4)\nprint(\"Assuming R2 = 10kohm\")\nr1=(10000/0.3333)*pow(10,-3)\nprint \"R1(in kohm)=\",round(r1,0),\"KOhm\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Given +Vsat=12V,\u2212Vsat=\u221212V,VH=6V\nWe know that hysteres is width is given as\nVH=(R2/R1+R2)[+Vsat\u2212Vsat]\nTherefore,R2/R1+R2=VH/+Vsat\u2212Vsat\nTherefore,R2/R1+R2= 0.25\nTherefore,R2=0.25R1+0.25R2\nTherefore,0.75R2=0.25R1\nTherefore,R2/R1= 0.3333\nAssuming R2 = 10kohm\nR1(in kohm)= 30.0 KOhm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.10 Page No. 9-40", "cell_type": "markdown", "metadata": {}}, {"execution_count": 50, "cell_type": "code", "source": "import math\n\nprint(\"From fig9.45,R1=68k\u2212ohm,R2=1.5k\u2212ohm and Vsat=13.5V\")\nvut=(1.5/(1.5+68))*13.5\nprint \"VUT(in V)=R2/R1+R2\u2217Vsat=\",round(vut,4),\"V\"\nvlt=(-1.5/(1.5+68))*13.5\nprint \"VLT(in V)=\u2212R2/R1+R2\u2217Vsat=\",round(vlt,4),\"V\"\nh=2*0.2913\nprint \"Therefore,H(in V)=VUT\u2212VLT=\",h,\"V\"\nprint(\"Now H =(2\u2217R2/R1+R2)\u2217Vsat\")\nprint(\"For minimum H,R2 must be minimum and R1 must be maximum\")\nr2min=((1.5)-(0.05*1.5))\nprint \"Therefore,R2min(in kohm)=R2\u22125%\u2217R2=\",r2min,\"KOhm\"\nr2max=((68)+(0.05*68))\nprint \"Therefore,R1max(in kohm)=R1+5%\u2217R1=\",r2max,\"KOhm\"\nhm=((2*1.425)/(71.4+1.425))*13.5\nprint \"Therefore,Hmin(in V)=\",round(hm,3),\"V\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "From fig9.45,R1=68k\u2212ohm,R2=1.5k\u2212ohm and Vsat=13.5V\nVUT(in V)=R2/R1+R2\u2217Vsat= 0.2914 V\nVLT(in V)=\u2212R2/R1+R2\u2217Vsat= -0.2914 V\nTherefore,H(in V)=VUT\u2212VLT= 0.5826 V\nNow H =(2\u2217R2/R1+R2)\u2217Vsat\nFor minimum H,R2 must be minimum and R1 must be maximum\nTherefore,R2min(in kohm)=R2\u22125%\u2217R2= 1.425 KOhm\nTherefore,R1max(in kohm)=R1+5%\u2217R1= 71.4 KOhm\nTherefore,Hmin(in V)= 0.528 V\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.11 Page No. 9-40", "cell_type": "markdown", "metadata": {}}, {"execution_count": 51, "cell_type": "code", "source": "import math\n\nprint(\"Choose op\u2212ampLM318 with Vsat as +\u221213.5V with supply voltage +\u221215V\")\nprint(\"VUT = +5V\")\nprint(\"Now VUT=(R2/R1+R2)\u2217Vsat\")\nprint(\"Therefore,5=(R2/R1+R2)\u221713.5\")\nprint(\"Therefore,R1+R2=2.7\u2217R2\")\nprint(\"Therefore,R1=1.7\u2217R2\")\nprint(\"Choose R2=10kohm\")\nr1=1.7*10\nprint \"Therefore, R1(in kohm)=\",r1\nprint(\"The designed circuit is shown in fig.9.46\")\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Choose op\u2212ampLM318 with Vsat as +\u221213.5V with supply voltage +\u221215V\nVUT = +5V\nNow VUT=(R2/R1+R2)\u2217Vsat\nTherefore,5=(R2/R1+R2)\u221713.5\nTherefore,R1+R2=2.7\u2217R2\nTherefore,R1=1.7\u2217R2\nChoose R2=10kohm\nTherefore, R1(in kohm)= 17.0\nThe designed circuit is shown in fig.9.46\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.12 Page No. 9-46", "cell_type": "markdown", "metadata": {}}, {"execution_count": 52, "cell_type": "code", "source": "import math\n\nprint(\"For the Schmitt trigger\")\nprint(\"VUT=2V,VLT=\u22124V,+\u2212Vsat=+\u221210V\")\nprint(\"For unequal UTP and LTP values,a modified circuit is required as shown in the fig.9.52.\")\nprint(\"The voltage V1 decides the UTP and LTP levels.Applying KVL to the output circuit and neglecting op\u2212amp input current we can write,\")\nprint(\"\u2212IR2\u2212IR1\u2212x+V0=0\")\nprint(\"Therefore,I=V0\u2212x/R1+R2\")\nprint(\"And V1=IR1+x\")\nprint(\"Therefore,V1=(V0\u2212x/R1+R2)\u2217R1+x\")\nprint(\"For +Vsat=10V,\")\nprint(\"V1=VUT=2V,\")\nprint(\"V0=10V\")\nprint(\"Therefore,2=(10\u2212x/R1+R2)\u2217R1+x(1)\")\nprint(\"For \u2212Vsat=\u221210V,\")\nprint(\"V1=VLT=\u22124V,\")\nprint(\"V0=\u221210V\")\nprint(\"Therefore,\u22124=(\u221210\u2212x/R1+R2)\u2217R1+x(2)\")\nprint(\"Subtracting equations (2) and (1),\")\nprint(\"Therefore,6=20\u2217R1/R1+R2\")\nprint(\"Therefore,R1+R2=3.333\u2217R1\")\nprint(\"Therefore,R2=2.333\u2217R1(3)\")\nprint(\"Substituting(3) in equation(1)\")\nprint(\"2=((10\u2212x)\u2217R1/3.333\u2217R1)+x\")\nprint(\"Therefore,2.333\u2217x=\u22123.3334\")\nx=-3.3334/2.333\nprint \"Therefore,x=\",round(x,4)\nprint(\"So actually polarity of the voltage source x must be opposite to what is assumed earlier as shown in fig.9.52.\")\nprint(\"Choose R1=1kohm hence R2=2.333kohm\")\nprint(\"Therefore,Rcomp=R1||R2=0.7kohm\")\nprint(\"Now as long as Vin is less than VUT,the output is at +Vsat=10V and when Vin>VUT,the output switches from +Vsat to \u2212Vsat.While as long as Vin>VLT,the output is at \u2212Vsat= \u221210V and when Vin<VLT, the output switches from \u2212Vsat to +Vsat.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For the Schmitt trigger\nVUT=2V,VLT=\u22124V,+\u2212Vsat=+\u221210V\nFor unequal UTP and LTP values,a modified circuit is required as shown in the fig.9.52.\nThe voltage V1 decides the UTP and LTP levels.Applying KVL to the output circuit and neglecting op\u2212amp input current we can write,\n\u2212IR2\u2212IR1\u2212x+V0=0\nTherefore,I=V0\u2212x/R1+R2\nAnd V1=IR1+x\nTherefore,V1=(V0\u2212x/R1+R2)\u2217R1+x\nFor +Vsat=10V,\nV1=VUT=2V,\nV0=10V\nTherefore,2=(10\u2212x/R1+R2)\u2217R1+x(1)\nFor \u2212Vsat=\u221210V,\nV1=VLT=\u22124V,\nV0=\u221210V\nTherefore,\u22124=(\u221210\u2212x/R1+R2)\u2217R1+x(2)\nSubtracting equations (2) and (1),\nTherefore,6=20\u2217R1/R1+R2\nTherefore,R1+R2=3.333\u2217R1\nTherefore,R2=2.333\u2217R1(3)\nSubstituting(3) in equation(1)\n2=((10\u2212x)\u2217R1/3.333\u2217R1)+x\nTherefore,2.333\u2217x=\u22123.3334\nTherefore,x= -1.4288\nSo actually polarity of the voltage source x must be opposite to what is assumed earlier as shown in fig.9.52.\nChoose R1=1kohm hence R2=2.333kohm\nTherefore,Rcomp=R1||R2=0.7kohm\nNow as long as Vin is less than VUT,the output is at +Vsat=10V and when Vin>VUT,the output switches from +Vsat to \u2212Vsat.While as long as Vin>VLT,the output is at \u2212Vsat= \u221210V and when Vin<VLT, the output switches from \u2212Vsat to +Vsat.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.13 Page No. 9-56", "cell_type": "markdown", "metadata": {}}, {"execution_count": 53, "cell_type": "code", "source": "import math\n\nprint(\"(a) We know that,\")\nvut=(86.0*15.0)/(86.0+100.0)\nprint \"VUT(in V)=R1\u2217+Vsat/R1+R2 =\",round(vut,2),\"V\"\nvlt=(86.0*-15.0)/(86.0+100.0)\nprint(\"(b) We know that,\")\nprint \"VLT(inV)=R1\u2217\u2212Vsat/R1+R2 =\",round(vlt,2),\"V\"\nprint(\"(c)We know that,\")\nf0=1.0/0.02\nprint \"f0(in Hz)=1/2\u2217Rf\u2217Cin\u2217[+Vsat\u2212VLT/+Vsat\u2212VUT] =\",f0,\"Hz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "(a) We know that,\nVUT(in V)=R1\u2217+Vsat/R1+R2 = 6.94 V\n(b) We know that,\nVLT(inV)=R1\u2217\u2212Vsat/R1+R2 = -6.94 V\n(c)We know that,\nf0(in Hz)=1/2\u2217Rf\u2217Cin\u2217[+Vsat\u2212VLT/+Vsat\u2212VUT] = 50.0 Hz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.14 Page No. 9-56 ", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": 54, "cell_type": "code", "source": "import math\n\nprint(\"We Know that,\")\nprint(\"T = 2*Rf*C*ln((+Vsat - VLT)/(+Vsat - VUT))\")\nprint(\"Substituting the values of VUT and VLT we get and if the magnitudes of +Vsat and -Vsat are equal,\")\nprint(\"T = 2*Rf*C*ln((2*R1 + R2)/(R2))\")\nprint(\"Given, R1 = 0.86R2\")\nprint(\"Therefore, T = 2*Rf*C .........since ln(2.72) = 1\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "We Know that,\nT = 2*Rf*C*ln((+Vsat - VLT)/(+Vsat - VUT))\nSubstituting the values of VUT and VLT we get and if the magnitudes of +Vsat and -Vsat are equal,\nT = 2*Rf*C*ln((2*R1 + R2)/(R2))\nGiven, R1 = 0.86R2\nTherefore, T = 2*Rf*C .........since ln(2.72) = 1\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.15 Page No. 9-57 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 55, "cell_type": "code", "source": "import math\n\nprint(\"This is a astable multivibrator using op-amp. Its time period is given by,\")\nprint(\"T = 2*Rf*C*ln((2*R1 + R2)/(R2)) if R1= 0.86*R2\")\nprint(\"T = 2*100*10^3*0.01*10^-6*ln((2*0.86R2 + R2)/(R2))\")\nprint(\"T = 2x10^-3 Sec\")\nprint(\"f = 1/T = 499.68 Hz\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "This is a astable multivibrator using op-amp. Its time period is given by,\nT = 2*Rf*C*ln((2*R1 + R2)/(R2)) if R1= 0.86*R2\nT = 2*100*10^3*0.01*10^-6*ln((2*0.86R2 + R2)/(R2))\nT = 2x10^-3 Sec\nf = 1/T = 499.68 Hz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.16 Page No. 9-57 ", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": 56, "cell_type": "code", "source": "import math\n\nprint(\"Let us design the circuit for f = 2.5 KHz\")\nprint(\"Assume R1 = R2 = 10KOhm\")\nprint(\"And Vo = +- Vsat = +- 15V. When Vo = +Vsat then C will charge through R3 due to foward biased diode D1\")\nprint(\"When Vo = -Vsat then C will discharge through R4 due to foward biased diode D2. Selecting different combitions for R3 and R4, charging and discharging time can be varied and non-symmetrical square wave can be obtained\")\nprint(\"Now, Vut = (R1*(+Vsat)/(R1+R2)) = 0.5*15 = 7.5V\")\nprint(\"Vlt = (R1*(-Vsat)/(R1+R2)) = 0.5*-15 = -7.5V\")\nprint(\"Choose C = 0.1uF\")\nprint(\"The charging equation is,\")\nprint(\"Vut = +Vsat +(Vlt - Vsat)*e^(TON/R3C)\")\nprint(\"Therefore 7.5 = 15 +(-7.5-15)*e^(TON/R3C)\")\nprint(\"TON/R3C = ln(0.333)\")\nprint(\"Now assume 50% duty cycle and design hence R3 = R4 and\")\nprint(\"TON = 2*10^-4 Sec\")\nprint(\"R3 = (-2*10^-4)/(0.1*10^-6*ln(0.333)) = 1.8203KOhm\")\nprint(\"R4 = 1.8203KOhm\")\nprint(\"Now to vary the duty cycle from 30% to 70% divide R3+R4 in the ratio 3:4:3 as shown in the figure. The modified circuit will give f = 2.5KHz with variable duty cycle from 30% to 70%\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Let us design the circuit for f = 2.5 KHz\nAssume R1 = R2 = 10KOhm\nAnd Vo = +- Vsat = +- 15V. When Vo = +Vsat then C will charge through R3 due to foward biased diode D1\nWhen Vo = -Vsat then C will discharge through R4 due to foward biased diode D2. Selecting different combitions for R3 and R4, charging and discharging time can be varied and non-symmetrical square wave can be obtained\nNow, Vut = (R1*(+Vsat)/(R1+R2)) = 0.5*15 = 7.5V\nVlt = (R1*(-Vsat)/(R1+R2)) = 0.5*-15 = -7.5V\nChoose C = 0.1uF\nThe charging equation is,\nVut = +Vsat +(Vlt - Vsat)*e^(TON/R3C)\nTherefore 7.5 = 15 +(-7.5-15)*e^(TON/R3C)\nTON/R3C = ln(0.333)\nNow assume 50% duty cycle and design hence R3 = R4 and\nTON = 2*10^-4 Sec\nR3 = (-2*10^-4)/(0.1*10^-6*ln(0.333)) = 1.8203KOhm\nR4 = 1.8203KOhm\nNow to vary the duty cycle from 30% to 70% divide R3+R4 in the ratio 3:4:3 as shown in the figure. The modified circuit will give f = 2.5KHz with variable duty cycle from 30% to 70%\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.17 Page No. 9-60", "cell_type": "markdown", "metadata": {}}, {"execution_count": 57, "cell_type": "code", "source": "import math\n\nprint(\"The monostable multivibrator using op\u2212amp produces the pulse waveform.The pulse width is given by,\")\nprint(\"T = RC\u2217ln[1+VD1/Vsat/1\u2212beta]\")\nprint(\"where VD1 = 0.7V, +vsat = +\u221212V for op\u2212amp741\")\nprint(\"beta = R2/R1+R2 = 0.5 with R1 = R2\")\nt=(0.5)*math.pow(10,-3) #Note 1/2 = 0.5\nprint \"T(in sec) = 1/f = \",t*math.pow(10,4),\"X 10^-4Sec\"\nprint(\"Choose C = 0.1uF\")\nprint(\"Therefore,5\u221710\u02c6\u22124 = R\u22170.1\u221710\u02c6\u22126\u2217ln[1+(0.7/12)/1\u22120.5]\")\nprint(\"Therefore,R = 6.7kohm\")\nprint(\"Choose R1 = R2 = 10kohm\")\nprint(\"The designed circuit is shown in fig.9.63\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The monostable multivibrator using op\u2212amp produces the pulse waveform.The pulse width is given by,\nT = RC\u2217ln[1+VD1/Vsat/1\u2212beta]\nwhere VD1 = 0.7V, +vsat = +\u221212V for op\u2212amp741\nbeta = R2/R1+R2 = 0.5 with R1 = R2\nT(in sec) = 1/f = 5.0 X 10^-4Sec\nChoose C = 0.1uF\nTherefore,5\u221710\u02c6\u22124 = R\u22170.1\u221710\u02c6\u22126\u2217ln[1+(0.7/12)/1\u22120.5]\nTherefore,R = 6.7kohm\nChoose R1 = R2 = 10kohm\nThe designed circuit is shown in fig.9.63\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.18 Page No. 9-73", "cell_type": "markdown", "metadata": {}}, {"execution_count": 58, "cell_type": "code", "source": "import math\n\nprint(\"The required pulse width is,\")\nprint(\"W = 10ms\")\nprint(\"The pulse width is given by,\")\nprint(\"W = 1.1\u2217R\u2217C\")\nprint(\"Therefore,10\u221710\u02c6\u22123 = 1.1\u2217R\u2217C\")\nprint(\"Therefore,RC = 9.0909\u221710\u02c6\u22123\")\nprint(\"Choose C = 0.1uF\")\nprint(\"Therefore,R = 90.909kohm ~= 91kohm\")\nprint(\"The designed circuit is shown in fig.9.78\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The required pulse width is,\nW = 10ms\nThe pulse width is given by,\nW = 1.1\u2217R\u2217C\nTherefore,10\u221710\u02c6\u22123 = 1.1\u2217R\u2217C\nTherefore,RC = 9.0909\u221710\u02c6\u22123\nChoose C = 0.1uF\nTherefore,R = 90.909kohm ~= 91kohm\nThe designed circuit is shown in fig.9.78\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.19 Page No. 9-73", "cell_type": "markdown", "metadata": {}}, {"execution_count": 59, "cell_type": "code", "source": "import math\n\nprint(\"Fig.9.79 shows monostable circuit used to drive the relay.\")\nprint(\"This relay should be energized for 5 second to hold heater ON for 5 seconds.Thus,TON for monostable is 5 seconds.\")\nprint(\"We know that the pulse width is given by,\")\nprint(\"W = 1.1RC\")\nprint(\"Therefore, 5 = 1.1RC\")\nprint(\"Now,there are two unknowns.In this case,we have to select value for capacitor and with the selected value we have to find the value of resistance from the formula.\")\nprint(\"Therefore,If capacitor value is 10uF\")\nprint(\"then 5 = 1.1\u2217R\u221710uF\")\nr=(5/(1.1*10*pow(10,-6)))*pow(10,-3)\nprint \"Therefore,R(in kohm)=\",round(r,2),\"KOhm\"\nprint(\"The calculated value is not standard value,but we can adjust this value by connecting variable resistance i.e. potentiometer.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Fig.9.79 shows monostable circuit used to drive the relay.\nThis relay should be energized for 5 second to hold heater ON for 5 seconds.Thus,TON for monostable is 5 seconds.\nWe know that the pulse width is given by,\nW = 1.1RC\nTherefore, 5 = 1.1RC\nNow,there are two unknowns.In this case,we have to select value for capacitor and with the selected value we have to find the value of resistance from the formula.\nTherefore,If capacitor value is 10uF\nthen 5 = 1.1\u2217R\u221710uF\nTherefore,R(in kohm)= 454.55 KOhm\nThe calculated value is not standard value,but we can adjust this value by connecting variable resistance i.e. potentiometer.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.20 Page No. 9-74", "cell_type": "markdown", "metadata": {}}, {"execution_count": 60, "cell_type": "code", "source": "import math\n\nprint(\"The requirement is that the door must be open for 15sec after receiving a trigger signal and then gets shutdoor automatically.This requires IC555 in a monostable mode with a pulsewidth of 15sec.\")\nprint(\"Therefore,W = 15sec\")\nprint(\"Now W = 1.1RC\")\nprint(\"Therefore, 15 = 1.1RC\")\nprint(\"Choose C = 100uF\")\nr=(15.0/(1.1*100.0*pow(10,-6)))*pow(10,-3)\nprint \"Therefore,R(in kohm)=\",round(r,3),\"KOhm\"\nprint(\"The designed circuit is shown in the fig.9.80\")\nprint(\"The supply voltage 10 or 15V has no effect on the operation of the circuit or the values of R and C selected.\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The requirement is that the door must be open for 15sec after receiving a trigger signal and then gets shutdoor automatically.This requires IC555 in a monostable mode with a pulsewidth of 15sec.\nTherefore,W = 15sec\nNow W = 1.1RC\nTherefore, 15 = 1.1RC\nChoose C = 100uF\nTherefore,R(in kohm)= 136.364 KOhm\nThe designed circuit is shown in the fig.9.80\nThe supply voltage 10 or 15V has no effect on the operation of the circuit or the values of R and C selected.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.21 Page No. 9-82", "cell_type": "markdown", "metadata": {}}, {"execution_count": 61, "cell_type": "code", "source": "import math\n\nprint(\"The frequency of output is given by,\")\nf=(1.44/(12.0*0.01*pow(10,-3)))*pow(10,-3)\nprint \"f(in kHz) = 1.44/(RA+2\u2217RB)\u2217C = \",f,\"KHz\"\nprint(\"The duty cycle is given by,\")\nd=8.0/12.0\nprint \"D = RA+RB/RA+2\u2217RB = \",round(d,4)\nprint(\"Thus the duty cycle 66.67%\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The frequency of output is given by,\nf(in kHz) = 1.44/(RA+2\u2217RB)\u2217C = 12.0 KHz\nThe duty cycle is given by,\nD = RA+RB/RA+2\u2217RB = 0.6667\nThus the duty cycle 66.67%\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.22 Page No. 9-85 ", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": 62, "cell_type": "code", "source": "import math\n\nprint(\"This relay should be energized for 3 seconds and then de-energize by 1 seconds\")\nprint(\"Hence charging time of capacitor is 3 seconds which is a pulse width W\")\nprint(\"Therefore W = 3 Seconds\")\nprint(\"While total time of one cycle is,\")\nprint(\"T = 3+1 = 4 seconds\")\nprint(\"D = W/T = 3/4 = Duty Cycle = 0.75\")\nprint(\"But D = (RA+RB)/(RA+2RB)\")\nprint(\"0.75 = (RA+RB)/(RA+2RB)\")\nprint(\"RA = 2RB ......... (1)\")\nprint(\"Now the charging time is given by\")\nprint(\"Tc = 0.693(RA + RB)C\")\nprint(\"Choose C = 10uF\")\nprint(\"RA + RB = 4.329 x 10^5 ............ (2)\")\nprint(\"Solving (1) and (2) we get\")\nprint(\"RA = 288.6 KOhm and RB = 144.3 KOhm\")\nprint(\"The values are not standard but can be adjusted using the potentiometers\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "This relay should be energized for 3 seconds and then de-energize by 1 seconds\nHence charging time of capacitor is 3 seconds which is a pulse width W\nTherefore W = 3 Seconds\nWhile total time of one cycle is,\nT = 3+1 = 4 seconds\nD = W/T = 3/4 = Duty Cycle = 0.75\nBut D = (RA+RB)/(RA+2RB)\n0.75 = (RA+RB)/(RA+2RB)\nRA = 2RB ......... (1)\nNow the charging time is given by\nTc = 0.693(RA + RB)C\nChoose C = 10uF\nRA + RB = 4.329 x 10^5 ............ (2)\nSolving (1) and (2) we get\nRA = 288.6 KOhm and RB = 144.3 KOhm\nThe values are not standard but can be adjusted using the potentiometers\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.23 Page No. 9-86 ", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": 63, "cell_type": "code", "source": "import math\n\nprint(\"The circuit used for the square wave generator is shown in the figure. For square wave charging and discharging resistors must be equal\")\nprint(\"The resistance R1 is a combination of a fixed resistor and a potentiometer. So that potentiometer can be adjusted for the extact square wave\")\nprint(\"f = 1KHz\")\nprint(\"T = 1/f = 1x10^-3 Sec\")\nprint(\"Td = Discharge = T/2 = 0.5 mSec\")\nprint(\"Now Td = 0.69*R2*C\")\nprint(\"Choose C = 0.1uF\")\nprint(\"Therefore R2 = 7.25KOhm\")\nprint(\"For square wave, R1 = R2\")\nprint(\"Therefore R1 = 100 Ohm + 10 KOhm pot\")\nprint(\"With pot precise square wave can be obtained\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The circuit used for the square wave generator is shown in the figure. For square wave charging and discharging resistors must be equal\nThe resistance R1 is a combination of a fixed resistor and a potentiometer. So that potentiometer can be adjusted for the extact square wave\nf = 1KHz\nT = 1/f = 1x10^-3 Sec\nTd = Discharge = T/2 = 0.5 mSec\nNow Td = 0.69*R2*C\nChoose C = 0.1uF\nTherefore R2 = 7.25KOhm\nFor square wave, R1 = R2\nTherefore R1 = 100 Ohm + 10 KOhm pot\nWith pot precise square wave can be obtained\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.24 Page No. 9-88 ", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": 64, "cell_type": "code", "source": "import math\n\nprint(\"Now f = 1.44/(C*(R1+R2+R3))\")\nprint(\"Choose C = 0.1uF\")\nprint(\"Therefore 1x10^3 = 1.44/(0.1x10^-6*(R1+R2+R3))\")\nprint(\"Therefore R1+R2+R3 = 14400 ..... (1)\")\nprint(\"%Dmin = (R1/(R1+R2+R3))*100\")\nprint(\"Using (1) R1 = 4.32KOhm ...... (2)\")\nprint(\"Now %Dmax = (R1+R2/(R1+R2+R3))*100\")\nprint(\"Using (1) and (2) R2 = 5.76KOhm\")\nprint(\"Using (1) R3 = 4.32KOhm\")\nprint \"Thus the various component values are,\"\nprint \"C = 0.1uf, R1 = R3 = 4.32KOhm, R2 = 5.76KOhm\" ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Now f = 1.44/(C*(R1+R2+R3))\nChoose C = 0.1uF\nTherefore 1x10^3 = 1.44/(0.1x10^-6*(R1+R2+R3))\nTherefore R1+R2+R3 = 14400 ..... (1)\n%Dmin = (R1/(R1+R2+R3))*100\nUsing (1) R1 = 4.32KOhm ...... (2)\nNow %Dmax = (R1+R2/(R1+R2+R3))*100\nUsing (1) and (2) R2 = 5.76KOhm\nUsing (1) R3 = 4.32KOhm\nThus the various component values are,\nC = 0.1uf, R1 = R3 = 4.32KOhm, R2 = 5.76KOhm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.25 Page No. 9-90 ", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": 65, "cell_type": "code", "source": "import math\n\nprint \"The frequency of output is given by,\"\nprint \"f = 1.44/((RA + 2*RB)*C) = 1.44/((4+2*4)*10^3*0.01*10^-6) = 12 KHz\"\nprint \"The duty cycle is given by,\"\nprint \"D = (RA + RB)/(RA + 2*RB) = (4+4)/(4+(2*4)) = 0.6667\"\nprint \"Thus the duty cycle is 66.67%\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The frequency of output is given by,\nf = 1.44/((RA + 2*RB)*C) = 1.44/((4+2*4)*10^3*0.01*10^-6) = 12 KHz\nThe duty cycle is given by,\nD = (RA + RB)/(RA + 2*RB) = (4+4)/(4+(2*4)) = 0.6667\nThus the duty cycle is 66.67%\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.26 Page No. 9-92", "cell_type": "markdown", "metadata": {}}, {"execution_count": 66, "cell_type": "code", "source": "import math\n\nprint(\"f = 1kHz\")\nprint(\"D = 75% = 0.75\")\nprint(\"Now f = 1.44/(RA+2\u2217RB)\u2217C\")\nprint(\"Therefore,1\u221710\u02c63 = 1.44/(RA+2\u2217RB)\u2217C\")\nprint(\"Therefore,(RA+2\u2217RB)\u2217C = 1.44\u221710\u02c6\u22123....(1)\")\nprint(\"Therefore,while %D = ((RA+RB)/(RA+2\u2217RB))\u2217100\")\nprint(\"Therefore,0.75 = RA+RB/RA+2\u2217RB\")\nprint(\"Therefore,RA+2\u2217RB = (RA+RB)/0.75\")\nprint(\"Therefore,RA+2\u2217RB = 1.33\u2217(RA+RB)\")\nprint(\"Therefore,0.66\u2217RB = 0.33\u2217RA\")\nprint(\"Therefore,RB = 0.5\u2217RA....(2)\")\nprint(\"Choose C = 0.1uF\")\nprint(\"Substituting in (1),\")\nprint(\"(RA+2\u2217RB)\u22170.1\u221710\u02c6\u22126 = 1.44\u221710\u02c6\u22123\")\nprint(\"Therefore,RA+2\u2217RB = 14400....(3)\")\nprint(\"Substituting(2) in (3),\")\nprint(\"RA+2(0.5\u2217RA) = 14400\")\nra=(14400/2)*pow(10,-3)\nprint \"Therefore,RA(in kohm)=\",ra,\"KOhm\"\nrb=0.5*7.2\nprint \"Therefore,RB(in kohm)=\",rb,\"KOhm\"\nprint(\"and C = 0.1uF\")\nprint(\"Hence the circuit diagram is as shown in fig.9.100\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "f = 1kHz\nD = 75% = 0.75\nNow f = 1.44/(RA+2\u2217RB)\u2217C\nTherefore,1\u221710\u02c63 = 1.44/(RA+2\u2217RB)\u2217C\nTherefore,(RA+2\u2217RB)\u2217C = 1.44\u221710\u02c6\u22123....(1)\nTherefore,while %D = ((RA+RB)/(RA+2\u2217RB))\u2217100\nTherefore,0.75 = RA+RB/RA+2\u2217RB\nTherefore,RA+2\u2217RB = (RA+RB)/0.75\nTherefore,RA+2\u2217RB = 1.33\u2217(RA+RB)\nTherefore,0.66\u2217RB = 0.33\u2217RA\nTherefore,RB = 0.5\u2217RA....(2)\nChoose C = 0.1uF\nSubstituting in (1),\n(RA+2\u2217RB)\u22170.1\u221710\u02c6\u22126 = 1.44\u221710\u02c6\u22123\nTherefore,RA+2\u2217RB = 14400....(3)\nSubstituting(2) in (3),\nRA+2(0.5\u2217RA) = 14400\nTherefore,RA(in kohm)= 7.2 KOhm\nTherefore,RB(in kohm)= 3.6 KOhm\nand C = 0.1uF\nHence the circuit diagram is as shown in fig.9.100\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.27 Page No. 9-93", "cell_type": "markdown", "metadata": {}}, {"execution_count": 67, "cell_type": "code", "source": "import math\n\nprint(\"TON = 0.6ms,T = 1ms\")\nd=0.6*100\nprint \"Therefore, D(in percentage) = tON/T = \",d,\"%\"\nprint(\"Now D = RA+RB/RA+2\u2217RB = 0.6\")\nprint(\"Therefore, RA+RB = 0.6\u2217RA+1.2\u2217RB\")\nprint(\"Therefore, 0.4\u2217RB = 0.2\u2217RB\")\nprint(\"Therefore, RB = 2\u2217RA ....(1)\")\nprint(\"f = 1.44/(RA+2\u2217RB)\u2217C = 1/T = 1000\")\nprint(\"Choose C = 0.1uF\")\nprint(\"Therefore, RA+2\u2217RB = 14400\")\nprint(\"Using(1),5\u2217RA = 14400\")\nra=(14400.0/5.0)*pow(10,-3)\nprint \"Therefore, RA(in kohm)=\",ra,\"KOhm\"\nrb=2.88*2.0\nprint \"RB(in kohm)=\",rb,\"KOhm\"\nprint(\"The circuit is shown in the fig.9.101\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "TON = 0.6ms,T = 1ms\nTherefore, D(in percentage) = tON/T = 60.0 %\nNow D = RA+RB/RA+2\u2217RB = 0.6\nTherefore, RA+RB = 0.6\u2217RA+1.2\u2217RB\nTherefore, 0.4\u2217RB = 0.2\u2217RB\nTherefore, RB = 2\u2217RA ....(1)\nf = 1.44/(RA+2\u2217RB)\u2217C = 1/T = 1000\nChoose C = 0.1uF\nTherefore, RA+2\u2217RB = 14400\nUsing(1),5\u2217RA = 14400\nTherefore, RA(in kohm)= 2.88 KOhm\nRB(in kohm)= 5.76 KOhm\nThe circuit is shown in the fig.9.101\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.28 Page No. 9-94", "cell_type": "markdown", "metadata": {}}, {"execution_count": 68, "cell_type": "code", "source": "import math\n\nprint(\"TON = TOFF = 0.5ms\")\nprint(\"Therefore,T = TON+TOFF = 1ms\")\nprint(\"i.e. f = 1/T = 1kHz\")\nprint(\"Now Td = TOFF = 0.69\u2217RB\u2217C\")\nprint(\"Choose C = 0.1uF\")\nrb=((0.5*pow(10,-3))/(0.69*0.1*pow(10,-6)))*pow(10,-3)\nprint \"Therefore, RB(in kohm)=\",round(rb,3),\"KOhm\"\nprint(\"Now duty cycle is 50% so RA = RB = 7.246kohm\")\nprint(\"Practically a modified circuit is required for 50% duty cycle where diode is connected across RB and charging takes place through RA and diode.And RB must be equal to sum of RA and diode forward resistance.So to have perfect square wave,RA is kept variable i.e. pot of say 10kohm in this case.It is then adjusted to obtain precise square wave.The resistance required in series with LED to be connected is,\")\nprint(\"R = V0\u2212VLED/ILED\")\nprint(\"Assuming VLED = 0.7V\")\nr = (5.0-0.7)/(50*pow(10,-3))\nprint \"Current limiting R(ohm)=\",r,\"Ohm\"\nprint(\"The voltage of R is\")\nprint(\"P = (50\u221710\u02c6\u22123)\u02c62\u2217100\")\np=(pow((50*pow(10,-3)),2))*100\nprint \"P(in W)=\",p,\"W\"\nprint(\"Both resistors R canbe of 1/4W\")\nprint(\"The required circuit is shown in the fig.9.102\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "TON = TOFF = 0.5ms\nTherefore,T = TON+TOFF = 1ms\ni.e. f = 1/T = 1kHz\nNow Td = TOFF = 0.69\u2217RB\u2217C\nChoose C = 0.1uF\nTherefore, RB(in kohm)= 7.246 KOhm\nNow duty cycle is 50% so RA = RB = 7.246kohm\nPractically a modified circuit is required for 50% duty cycle where diode is connected across RB and charging takes place through RA and diode.And RB must be equal to sum of RA and diode forward resistance.So to have perfect square wave,RA is kept variable i.e. pot of say 10kohm in this case.It is then adjusted to obtain precise square wave.The resistance required in series with LED to be connected is,\nR = V0\u2212VLED/ILED\nAssuming VLED = 0.7V\nCurrent limiting R(ohm)= 86.0 Ohm\nThe voltage of R is\nP = (50\u221710\u02c6\u22123)\u02c62\u2217100\nP(in W)= 0.25 W\nBoth resistors R canbe of 1/4W\nThe required circuit is shown in the fig.9.102\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.29 Page No. 9-95 ", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": 69, "cell_type": "code", "source": "import math\n\nprint \"f = 5KHz, Vcc = +5 V\"\nprint \"Assume Vd = Vbe = 0.7 V\"\nprint \"Ic = Vcc-Vd/R = Vcc-0.7/R = 4.3/R\"\nprint \"and f = 3*Ic/(Vcc * C)\"\nprint \"Therefore RC = 5.16 x 10^-4\"\nprint \"Choose C = 0.05uF\"\nprint \"Therefore R = 5.16*10^-4/0.05*10^-6 = 10.32KOhm\"\nprint \"Use 10Kohm resistance and 1KOhm pot for precise adjustment\"\nprint \"Ic = 4.3/10.32*10^3 = 0.416 mA\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "f = 5KHz, Vcc = +5 V\nAssume Vd = Vbe = 0.7 V\nIc = Vcc-Vd/R = Vcc-0.7/R = 4.3/R\nand f = 3*Ic/(Vcc * C)\nTherefore RC = 5.16 x 10^-4\nChoose C = 0.05uF\nTherefore R = 5.16*10^-4/0.05*10^-6 = 10.32KOhm\nUse 10Kohm resistance and 1KOhm pot for precise adjustment\nIc = 4.3/10.32*10^3 = 0.416 mA\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.30 Page No. 9-96 ", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": 70, "cell_type": "code", "source": "import math\n\nprint \"f = 10KHz and %D = 25%\"\nprint \"T = 1/f = 1/10*10^3 = 0.1msec\"\nprint \"D = TON/T i.e. TON = 0.25*T = 0.025msec\"\nprint \"and Toff = T- TON = 0.075 msec\"\nprint \"Duty cycle is less than 50% hence the modified circuit must be used\"\nprint \"Choose C = 0.01uF\"\nprint \"The charging of C takes place through RA and diode D while the discharging of C takes place through RB only\"\nprint \"Assuming ideal diode\"\nprint \"TON = 0.693*RA*C and TOFF = 0.693*RB*C\"\nprint \"Therefore, RA = 3.607 KOhm\"\nprint \"RB = 10.82 KOhm\"\nprint \"Thus for C = 0.01uF, RA = 3.607KOhm and RB = 10.82KOhm the modified circuit gives duty cycle of 25%\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "f = 10KHz and %D = 25%\nT = 1/f = 1/10*10^3 = 0.1msec\nD = TON/T i.e. TON = 0.25*T = 0.025msec\nand Toff = T- TON = 0.075 msec\nDuty cycle is less than 50% hence the modified circuit must be used\nChoose C = 0.01uF\nThe charging of C takes place through RA and diode D while the discharging of C takes place through RB only\nAssuming ideal diode\nTON = 0.693*RA*C and TOFF = 0.693*RB*C\nTherefore, RA = 3.607 KOhm\nRB = 10.82 KOhm\nThus for C = 0.01uF, RA = 3.607KOhm and RB = 10.82KOhm the modified circuit gives duty cycle of 25%\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.31 Page No. 9-97 ", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": 71, "cell_type": "code", "source": "import math\n\nprint \"For proper operation of LED, which must remain ON for 10 msec the timer must be set in monoshot mode\"\nprint \"Now T = 1.1*R*C \\nLet C = 0.22uF\"\nprint \"10x10^-3 = 1.1*R*0.22*10^-6\"\nprint \"R = 41.4KOhm\"\nprint \"Now the output of timer is given as, \\n Vo = Vcc - 2Vbe - Vcesat\"\nprint \"Let Vcc = 15V, Vbe = 0.7V and Vcesat = 0.2V\"\nprint \"Vo = 15-2*0.7-0.2 = 13.4V\"\nprint \"Now the drop across LED is 1.4V. There must be resistance in series with LED say RLED. The LED current is 20mA\"\nprint \"RLED = Vo-VLED/ILED = 13.4 - 1.4/20*10^-3 = 600 Ohm\"\nprint \"To improve noise immunity connect a 0.01uF capacitor between pin 5 and ground.\"\nprint \"The second circuit is an astable with frequency 1KHz and 95% duty cycle\"\nprint \"f = 1.44/(RA + 2RB)*C\"\nprint \"Let C = 0.01uF\"\nprint \"Therefore RA + 2RB = 144x10^3\"\nprint \"Duty cycle = RA + RB/RA+2RB\"\nprint \"RB = 0.0555RA as Duty cycle is 95%\"\nprint \"Therefore RA = 129.6KOhm\"\nprint \"Therefore RB = 7.19KOhm\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For proper operation of LED, which must remain ON for 10 msec the timer must be set in monoshot mode\nNow T = 1.1*R*C \nLet C = 0.22uF\n10x10^-3 = 1.1*R*0.22*10^-6\nR = 41.4KOhm\nNow the output of timer is given as, \n Vo = Vcc - 2Vbe - Vcesat\nLet Vcc = 15V, Vbe = 0.7V and Vcesat = 0.2V\nVo = 15-2*0.7-0.2 = 13.4V\nNow the drop across LED is 1.4V. There must be resistance in series with LED say RLED. The LED current is 20mA\nRLED = Vo-VLED/ILED = 13.4 - 1.4/20*10^-3 = 600 Ohm\nTo improve noise immunity connect a 0.01uF capacitor between pin 5 and ground.\nThe second circuit is an astable with frequency 1KHz and 95% duty cycle\nf = 1.44/(RA + 2RB)*C\nLet C = 0.01uF\nTherefore RA + 2RB = 144x10^3\nDuty cycle = RA + RB/RA+2RB\nRB = 0.0555RA as Duty cycle is 95%\nTherefore RA = 129.6KOhm\nTherefore RB = 7.19KOhm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.32 Page No. 9-102", "cell_type": "markdown", "metadata": {}}, {"execution_count": 72, "cell_type": "code", "source": "import math\n\nprint(\"For the given DAC,\")\nprint(\"n = Number of bits = 8\")\nprint(\"(i) Resolution = 2\u02c6n = 2\u02c68 = 256\")\nprint(\"i.e.the output voltage can have 256 different values including zero.\")\nprint(\"(ii) V0FS = Full scale output voltage\")\nprint(\"= 2.55V\")\nprint(\"Therefore,Resolution = V0FS/2\u02c6n\u22121 = 2.55/2\u02c68\u22121 = 10mV/1LSB\")\nprint(\"Thus an input change of 1LSB causes the output to change by 10mV\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For the given DAC,\nn = Number of bits = 8\n(i) Resolution = 2\u02c6n = 2\u02c68 = 256\ni.e.the output voltage can have 256 different values including zero.\n(ii) V0FS = Full scale output voltage\n= 2.55V\nTherefore,Resolution = V0FS/2\u02c6n\u22121 = 2.55/2\u02c68\u22121 = 10mV/1LSB\nThus an input change of 1LSB causes the output to change by 10mV\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.33 Page No. 9-102", "cell_type": "markdown", "metadata": {}}, {"execution_count": 73, "cell_type": "code", "source": "import math\n\nprint(\"For given DAC,\")\nprint(\"n = 4\")\nprint(\"Therefore,V0FS = 15V\")\nprint(\"Therefore,Resolution = V0FS/2\u02c6n\u22121 = 1V/LSB\")\nprint(\"Therefore,V0 = Resolution\u2217D\")\nprint(\"Now D = Decimal of 0110 = 6\")\nprint(\"Therefore,V0 = 1V/LSB\u22176 = 6V\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For given DAC,\nn = 4\nTherefore,V0FS = 15V\nTherefore,Resolution = V0FS/2\u02c6n\u22121 = 1V/LSB\nTherefore,V0 = Resolution\u2217D\nNow D = Decimal of 0110 = 6\nTherefore,V0 = 1V/LSB\u22176 = 6V\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.34 Page No. 9-103", "cell_type": "markdown", "metadata": {}}, {"execution_count": 74, "cell_type": "code", "source": "import math\n\nprint(\"Resolution = V0FS/2\u02c6n\u22121\")\nprint(\"Therefore, 20 = V0FS/2\u02c6n\u22121\")\nprint(\"Therefore,V0FS = 5.1V\")\nprint(\"D = Equivalent of 10000000 = 128\")\nprint(\"Therefore,V0 = Resolution\u2217D = 20\u2217128 = 2.56V\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Resolution = V0FS/2\u02c6n\u22121\nTherefore, 20 = V0FS/2\u02c6n\u22121\nTherefore,V0FS = 5.1V\nD = Equivalent of 10000000 = 128\nTherefore,V0 = Resolution\u2217D = 20\u2217128 = 2.56V\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.35 Page No. 9-103", "cell_type": "markdown", "metadata": {}}, {"execution_count": 75, "cell_type": "code", "source": "import math\n\nprint(\"For given DAC, n=4, V0FS=+5V\")\nprint(\"Resolution = V0FS/2\u02c6n\u22121 = 1/3V/LSB\")\nprint(\"Therefore,V0 = Resolution\u2217D\")\nprint(\"For D = Decimal of 10000=8\")\nprint(\"V0 = 1/3\u22178=2.6667V\")\nprint(\"For D = Decimal of 1111=15\")\nprint(\"V0 = 1/3\u221715 = 5V\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For given DAC, n=4, V0FS=+5V\nResolution = V0FS/2\u02c6n\u22121 = 1/3V/LSB\nTherefore,V0 = Resolution\u2217D\nFor D = Decimal of 10000=8\nV0 = 1/3\u22178=2.6667V\nFor D = Decimal of 1111=15\nV0 = 1/3\u221715 = 5V\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.36 Page No. 9-103", "cell_type": "markdown", "metadata": {}}, {"execution_count": 76, "cell_type": "code", "source": "import math\n\nprint(\"For 12\u2212bit DAC, step size is 8mV\")\nv=(8*pow(10,-3))*((pow(2,12))-1)\nprint \"V0FS = 8mV\u22172\u02c612\u22121 = \",v\nr=((8*pow(10,-3))/32.76)*100\nprint \"%Resolution = 8mV/32.76V\u2217100 = \",r\nq=(8*pow(10,-3))*1389\nprint \"The output voltage for the input 010101101101 is = 8mV\u22171389 = \",q", "outputs": [{"output_type": "stream", "name": "stdout", "text": "For 12\u2212bit DAC, step size is 8mV\nV0FS = 8mV\u22172\u02c612\u22121 = 32.76\n%Resolution = 8mV/32.76V\u2217100 = 0.02442002442\nThe output voltage for the input 010101101101 is = 8mV\u22171389 = 11.112\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.37 Page No. 9-109 ", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": 77, "cell_type": "code", "source": "import math\n\nprint \"Resolution = (1/2^n)*(VR/R)*Rf\"\nprint \"Let VR = 10V n = 4 and resolution = 0.5\"\nprint \"0.5 = (1/2^4)*(10/R)*Rf\"\nprint \"Choose Rf = 10KOhm\"\nprint \"Therefore R = 12.5KOhm\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Resolution = (1/2^n)*(VR/R)*Rf\nLet VR = 10V n = 4 and resolution = 0.5\n0.5 = (1/2^4)*(10/R)*Rf\nChoose Rf = 10KOhm\nTherefore R = 12.5KOhm\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.38 Page No. 9-113", "cell_type": "markdown", "metadata": {}}, {"execution_count": 78, "cell_type": "code", "source": "import math\n\nprint(\"(a)From equation(1) we have,\")\nr=pow(2,8)\nprint \"Resolution=2\u02c68=\",r\nprint(\"and from equation(2) we have,\")\nprint(\"Resolution = 5.1V/(2\u02c68\u22121) = 20mV/LSB\")\nprint(\"Therefore,we can say that to change output by 1 LSB we have to change input by 20mV\")\nprint(\"(b)For 1.28V analog input, digital output can be calculated as,\")\nd=1.28/(20*pow(10,-3))\nprint \"D(in LSBs) = 1.28V/20mV/LSB = \",d\nprint(\"The binary equivalent of 64 is 01000000\")", "outputs": [{"output_type": "stream", "name": "stdout", "text": "(a)From equation(1) we have,\nResolution=2\u02c68= 256\nand from equation(2) we have,\nResolution = 5.1V/(2\u02c68\u22121) = 20mV/LSB\nTherefore,we can say that to change output by 1 LSB we have to change input by 20mV\n(b)For 1.28V analog input, digital output can be calculated as,\nD(in LSBs) = 1.28V/20mV/LSB = 64.0\nThe binary equivalent of 64 is 01000000\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.39 Page No. 9-113", "cell_type": "markdown", "metadata": {}}, {"execution_count": 79, "cell_type": "code", "source": "import math\n\nprint(\"From equation(3) we get\")\nqe=(4.095/(4095*2))*pow(10,3)\nprint \"QE(in mV) = 4.095/(4096\u22121)\u22172 = \",qe,\"mV\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "From equation(3) we get\nQE(in mV) = 4.095/(4096\u22121)\u22172 = 0.5 mV\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.40 Page No. 9-117", "cell_type": "markdown", "metadata": {}}, {"execution_count": 80, "cell_type": "code", "source": "import math\n\nprint(\"We know that,\")\nprint(\"t2 = (V1/VR)\u2217t1\")\nt2 = 83.33\nprint \"(i) t2(in ms) = (100/100)\u221783.33 = \",t2,\"msec\"\nprint(\"(ii) V1=200mV\")\nt2=83.33*2\nprint \"Therefore,t2(in ms)=(200/100)\u221783.33 = \",round(t2,1),\"msec\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "We know that,\nt2 = (V1/VR)\u2217t1\n(i) t2(in ms) = (100/100)\u221783.33 = 83.33 msec\n(ii) V1=200mV\nTherefore,t2(in ms)=(200/100)\u221783.33 = 166.7 msec\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.41 Page No. 9-117", "cell_type": "markdown", "metadata": {}}, {"execution_count": 81, "cell_type": "code", "source": "import math\n\nprint(\"The digital output is given as,\")\nprint(\"Digital output=(Counts/Second)\u2217t1\u2217(Vi/VR)\")\nprint(\"Now Clock frequency = 12kHz\")\nprint(\"i.e. = 12000 counts/second\")\nd=12000*83.33*(100/100)*pow(10,-3)\nprint \"Therefore,Digital output(in counts) = 12000\u221783.33\u2217(100/100)\u221710\u02c6\u22123 =\",round(d,0)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The digital output is given as,\nDigital output=(Counts/Second)\u2217t1\u2217(Vi/VR)\nNow Clock frequency = 12kHz\ni.e. = 12000 counts/second\nTherefore,Digital output(in counts) = 12000\u221783.33\u2217(100/100)\u221710\u02c6\u22123 = 1000.0\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.42 Page No. 9-120", "cell_type": "markdown", "metadata": {}}, {"execution_count": 82, "cell_type": "code", "source": "import math\n\nprint(\"f = 1MHz\")\nprint(\"Therefore,T=1/f=1/1\u221710\u02c66=1usec\")\nprint(\"n=8\")\ntc = 1*(8+1)\nprint \"Therefore, TC(in usec)=T\u2217(n+1) =\",tc,\"usec\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "f = 1MHz\nTherefore,T=1/f=1/1\u221710\u02c66=1usec\nn=8\nTherefore, TC(in usec)=T\u2217(n+1) = 9 usec\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9.43 Page No. 9-122", "cell_type": "markdown", "metadata": {}}, {"execution_count": 83, "cell_type": "code", "source": "import math\n\nprint(\"The maximum frequency is given by,\")\nf=1/(2*(math.pi)*(9*pow(10,-6))*pow(2,8))\nprint \"fmax(in Hz) = 1/2\u2217pi\u2217(TC)\u22172\u02c6n =\",round(f,2),\"Hz\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The maximum frequency is given by,\nfmax(in Hz) = 1/2\u2217pi\u2217(TC)\u22172\u02c6n = 69.08 Hz\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits/screenshots/chapter2_dc_collector_current.png b/Analog_Integrated_Circuits/screenshots/chapter2_dc_collector_current.png
new file mode 100755
index 00000000..dfe25237
--- /dev/null
+++ b/Analog_Integrated_Circuits/screenshots/chapter2_dc_collector_current.png
Binary files differ
diff --git a/Analog_Integrated_Circuits/screenshots/chapter5_Vout_vs_time_plot.png b/Analog_Integrated_Circuits/screenshots/chapter5_Vout_vs_time_plot.png
new file mode 100755
index 00000000..870d3fa5
--- /dev/null
+++ b/Analog_Integrated_Circuits/screenshots/chapter5_Vout_vs_time_plot.png
Binary files differ
diff --git a/Analog_Integrated_Circuits/screenshots/chapter5_vout_vs_time.png b/Analog_Integrated_Circuits/screenshots/chapter5_vout_vs_time.png
new file mode 100755
index 00000000..d691901e
--- /dev/null
+++ b/Analog_Integrated_Circuits/screenshots/chapter5_vout_vs_time.png
Binary files differ
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter1.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter1.ipynb
new file mode 100755
index 00000000..24ac5ea2
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter1.ipynb
@@ -0,0 +1,417 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1cb6068538d8c97f156cb67d11e52aad1d6c0b391f69a34791cef94fb6857610"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter1 - Constant current sources"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 1.1 - page 4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Iout=8 #micro A\n",
+ "VBE=0.7 #V\n",
+ "Beta=80 #unitless\n",
+ "VCC=20 #V\n",
+ "IREF=Iout*(1+2/Beta) #micro A\n",
+ "R=(VCC-VBE)/IREF #Mohm\n",
+ "print \"Reference current is %0.2f uA\" %IREF\n",
+ "print \"Resistance required is %0.2f Mohm\" %R"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reference current is 8.20 uA\n",
+ "Resistance required is 2.35 Mohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 1.2 - page 5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Iout=1 #mA\n",
+ "VBE=0.7 #V\n",
+ "Beta=100 #unitless\n",
+ "VCC=30 #V\n",
+ "IREF=Iout*(1+2/Beta) #mA\n",
+ "R=(VCC-VBE)/IREF #kohm\n",
+ "print \"Reference current is %0.2f mA\" %IREF \n",
+ "print \"Resistance required is %0.1f kohm\" %R"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reference current is 1.02 mA\n",
+ "Resistance required is 28.7 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 1.3 - page 5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Iout=0.5 #mA\n",
+ "Beta=50 #unitless\n",
+ "VEB=0.7 #V\n",
+ "VCC=5 #V\n",
+ "IREF=Iout*(1+2/Beta) #mA\n",
+ "R=(VCC-VEB)/IREF #kohm\n",
+ "print \"Reference current is %0.2f mA\" %IREF \n",
+ "print \"Resistance required is %0.2f kohm\" %R"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reference current is 0.52 mA\n",
+ "Resistance required is 8.27 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 1.4 - page 8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Iout=8 #micro A\n",
+ "Beta=100 #unitless\n",
+ "VBE=0.7 #V\n",
+ "VCC=20 #V\n",
+ "IREF=Iout/(1+2/Beta/(1+Beta)) #micro A\n",
+ "R=(VCC-2*VBE)/IREF #Mohm\n",
+ "print \"Reference current is %0.2f micro A\" %IREF \n",
+ "print \"Resistance required is %0.2f Mohm\" %R"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reference current is 8.00 micro A\n",
+ "Resistance required is 2.33 Mohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 1.5 - page 8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Iout=60 #micro A\n",
+ "VBE=0.7 #V\n",
+ "Beta=150 #unitless\n",
+ "VCC=30 #V\n",
+ "IREF=Iout*(1+2/Beta/(1+Beta)) #micro A\n",
+ "R=(VCC-2*VBE)/IREF #Mohm\n",
+ "R*=10**3 #kohm\n",
+ "print \"Reference current is %0.3f mA\" %IREF \n",
+ "print \"Resistance required is %0.1f kohm\" %R"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reference current is 60.005 mA\n",
+ "Resistance required is 476.6 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 1.6 - page 9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "VBE=0.7 #V\n",
+ "Beta=120 #unitless\n",
+ "VCC=10 #V\n",
+ "R=5.6 #kohm\n",
+ "#KCL at node x : IREF=IC1+I1 #as Beta>>1\n",
+ "#KCL at node y : I1=IC2+IB3 #as Beta>>1\n",
+ "IREF=(VCC-VBE)/R #mA\n",
+ "#as IREF=2*IC+IB3=IC*(2+1/Beta)=2*IC #as Beta>>1\n",
+ "IC=IREF/2 #mA\n",
+ "Iout=IC #mA\n",
+ "print \"Output current is %0.2f mA\" %Iout"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output current is 0.83 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 1.7 - page 13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import math\n",
+ "Iout=6 #micro A\n",
+ "IREF=1.2 #mA\n",
+ "VBE2=0.7 #V\n",
+ "VT=26 #mV\n",
+ "Beta=120 #unitless\n",
+ "VCC=20 #V\n",
+ "R=(VCC-VBE2)/IREF #kohm\n",
+ "print \"Value of resistance R is %0.f kohm \" %R\n",
+ "IC1=Iout #micro A\n",
+ "IC2=(IREF-IC1*10**-3/Beta)/(1+1/Beta) #mA\n",
+ "RS=1/(IC1*10**-6)*VT*10**-3*math.log(IC2*1000/IC1) #ohm\n",
+ "RS/=10**3 #kohm\n",
+ "print \"Value of resistance RS is %0.1f kohm\" %RS"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of resistance R is 16 kohm \n",
+ "Value of resistance RS is 22.9 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 1.8 - page 14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "IREF=1 #mA\n",
+ "Io2=20 #micro A\n",
+ "Io3=40 #micro A\n",
+ "VBE1=0.7 #V\n",
+ "VT=26 #mV\n",
+ "VCC=10 #V\n",
+ "VEE=-10 #V\n",
+ "R=(VCC-VBE1-VEE)/IREF #kohm\n",
+ "print \"Value of resistance R is %0.2f kohm \" %R \n",
+ "RE2=VT/Io2*math.log(IREF*1000/Io2) #kohm\n",
+ "print \"Value of resistance RE2 is %0.2f kohm\" %RE2 \n",
+ "RE3=VT/Io3*math.log(IREF*1000/Io3) #kohm\n",
+ "print \"Value of resistance RE3 is %0.2f kohm \" %RE3 \n",
+ "VBE2=VBE1-RE2*Io2/1000 #V\n",
+ "print \"Value of Base emitter voltage of transistor Q2 is %0.4f V\" %VBE2 \n",
+ "VBE3=VBE1-RE3*Io3/1000 #V\n",
+ "print \"Value of Base emitter voltage of transistor Q3 is %0.4f V\" %VBE3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of resistance R is 19.30 kohm \n",
+ "Value of resistance RE2 is 5.09 kohm\n",
+ "Value of resistance RE3 is 2.09 kohm \n",
+ "Value of Base emitter voltage of transistor Q2 is 0.5983 V\n",
+ "Value of Base emitter voltage of transistor Q3 is 0.6163 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 1.9 - page 18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Beta=100 #unitless\n",
+ "VBE=0.715 #V\n",
+ "R=5.6 #kohm\n",
+ "RC=1 #kohm\n",
+ "VCC=10 #V\n",
+ "VCB1=0 #V(Q1 will act as diode)\n",
+ "IREF=(VCC-VBE)/R #mA\n",
+ "#KCL at node x : IREF=IC1+2*IB \n",
+ "#KCL at node y : I1=IC2+IB3 #as Beta>>1\n",
+ "IREF=(VCC-VBE)/R #mA\n",
+ "#as IREF=2*IC1/Beta+IC1\n",
+ "IC1=IREF/(1+2/Beta) #mA\n",
+ "IC2=IC1 #mA\n",
+ "IC3=IC1 #mA\n",
+ "print \"Collector current in each transistor, IC1=IC2=IC3 is %0.2f mA\" %IC1\n",
+ "IRC=IC1+IC2+IC3 #mA\n",
+ "print \"Current through RC is %0.2f mA\" %IRC\n",
+ "#Answer wrong in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current in each transistor, IC1=IC2=IC3 is 1.63 mA\n",
+ "Current through RC is 4.88 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 1.10 - page 19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Vout=5 #V\n",
+ "Beta=180 #unitless\n",
+ "R=22 #kohm\n",
+ "VCC=10 #V\n",
+ "VBE=0.7 #V\n",
+ "IREF=(VCC-VBE)/R #mA\n",
+ "IC=(IREF-VBE/R)/(1+2/Beta) #mA\n",
+ "RC=(VCC-Vout)/IC #kohm\n",
+ "print \"IC1 & IC2 are %0.2f mA\" %IC\n",
+ "print \"RC is %0.2f kohm\" %RC\n",
+ "#Answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "IC1 & IC2 are 0.39 mA\n",
+ "RC is 12.93 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter10.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter10.ipynb
new file mode 100755
index 00000000..9fe9f6c7
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter10.ipynb
@@ -0,0 +1,220 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:f64bf7a670dc36e359e5aa56e0bfa29f09c70f7a0babc95be4c64434f164d9d6"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter10 - Comparators"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 10.1 - page : 334"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sin\n",
+ "t=range(0,5) #sec(Assumed)\n",
+ "Vin=5*sin(2*pi*t[0]) #V\n",
+ "VCC=15 #V\n",
+ "R2=1 #kohm\n",
+ "R1=6.8 #kohm\n",
+ "VEE=-15 #V\n",
+ "Vsat=13 #V\n",
+ "Vref=R2*VCC/(R1+R2) #V\n",
+ "print \"Reference Voltage = %0.2f V \" %Vref\n",
+ "print \"If Vin>Vref , Vout = %0.2f V \" %Vsat \n",
+ "print \"If Vin<Vref , Vout = %0.2f V \" %-Vsat"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reference Voltage = 1.92 V \n",
+ "If Vin>Vref , Vout = 13.00 V \n",
+ "If Vin<Vref , Vout = -13.00 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 10.2 - page 340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Vsat=7 #V\n",
+ "R1=68 #kohm\n",
+ "R2=82 #kohm\n",
+ "VUTP=R2*Vsat/(R1+R2) #V\n",
+ "VLTP=R2*-Vsat/(R1+R2) #V\n",
+ "print \"Upper trip point = %0.2f V \" %VUTP \n",
+ "print \"Lower trip point = %0.2f V \" %VLTP"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Upper trip point = 3.83 V \n",
+ "Lower trip point = -3.83 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 10.3 - page : 340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import arcsin, pi\n",
+ "#Vin=5*sin(omega*t)\n",
+ "Vm=5 #V\n",
+ "Vsat=7 #V\n",
+ "R1=68 #kohm\n",
+ "R2=82 #kohm\n",
+ "VUTP=R2*Vsat/(R1+R2) #V\n",
+ "fi=arcsin(VUTP/Vm)*180/pi #degree\n",
+ "print \"Phase shift = %0.2f degree \" %fi \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Phase shift = 49.94 degree \n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 10.4 - page : 344"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "VZ1=4.7 #V\n",
+ "VZ2=4.7 #V\n",
+ "R1=68 #kohm\n",
+ "R2=15 #kohm\n",
+ "Vout=VZ1+0.7 #V(As one zener diode is always forward biased)\n",
+ "VR1=Vout #V\n",
+ "IR1=VR1/R1*1000 #micro A\n",
+ "IR2=IR1 #micro A\n",
+ "VR2=IR2*10**-3*R2 #V\n",
+ "Vout=VR1+VR2 #V\n",
+ "VUTP=(R2/(R1+R2))*Vout #V\n",
+ "VLTP=(R2/(R1+R2))*(-Vout) #V\n",
+ "print \"VUTP = %0.2f V \" %VUTP \n",
+ "print \"VLTP = %0.2f V \" %VLTP"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "VUTP = 1.19 V \n",
+ "VLTP = -1.19 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 10.5 - page : 346"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Vsat=12.5 #V\n",
+ "Vref=-12.5 #V\n",
+ "R1=80 #kohm\n",
+ "R2=20 #kohm\n",
+ "Beta=R2/(R1+R2) #unitless\n",
+ "UTP=Beta*Vsat+(1-Beta)*Vref #V\n",
+ "LTP=-Beta*Vsat+(1-Beta)*Vref #V\n",
+ "VH=UTP-LTP #V\n",
+ "R3=R1*R2/(R1+R2) #kohm\n",
+ "print \"UTP = %0.2f V \" %UTP \n",
+ "print \"LTP = %0.2f V \" %LTP \n",
+ "print \"Hysteresis Voltage, VH = %0.2f V \" %VH \n",
+ "print \"Use R3 = %0.2f kohm \" %R3 "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "UTP = -7.50 V \n",
+ "LTP = -12.50 V \n",
+ "Hysteresis Voltage, VH = 5.00 V \n",
+ "Use R3 = 16.00 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter11.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter11.ipynb
new file mode 100755
index 00000000..85a26955
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter11.ipynb
@@ -0,0 +1,243 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4938ab1cbcdde4c79a4edd16b6b058287ba152a41695f11025117cf99374b771"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter11 - Non linear applications of op-amp"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 11.1 - page : 354"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import log\n",
+ "Vin=12.5 #V\n",
+ "Ri=10 #kohm\n",
+ "IS=10**-13 #A\n",
+ "T=27 #degree C\n",
+ "VT=26 #mV\n",
+ "Vref=Ri*IS*1000 #V\n",
+ "Vout=-VT*10**-3*log(Vin/Vref) #V\n",
+ "print \"Output Voltage, Vout = %0.1f V \" %Vout"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output Voltage, Vout = -0.6 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 11.3 - page : 362"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "R1=10 #kohm\n",
+ "k=1.38*10**-23 #J/K\n",
+ "T=298 #K\n",
+ "q=1.6*10**-19 #C\n",
+ "Kdash=k*T/q #Kdash=k*T/q assumed for temporary calculation\n",
+ "print \"Output Voltage, Vout(V) is \",round(-Kdash,4),\"*log(Vin/%0.f*10**3)\" %R1\n",
+ "#Not possible to tale log of symbols."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output Voltage, Vout(V) is -0.0257 *log(Vin/10*10**3)\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 11.4 - page : 362"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "R1=10 #kohm\n",
+ "R2=10 #kohm\n",
+ "k=1.38*10**-23 #J/K\n",
+ "T=298 #K\n",
+ "q=1.6*10**-19 #C\n",
+ "Kdash=k*T/q #Kdash=k*T/q assumed for temporary calculation\n",
+ "print \"Output Voltahe, Vout(V) is -R1*(log(\",round(-1/Kdash,1),\"*Vin)**-1\"\n",
+ "#Not possible to tale log of symbols."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output Voltahe, Vout(V) is -R1*(log( -38.9 *Vin)**-1\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 11.7 - page : 366"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import log10\n",
+ "k=1 #for the givn connection\n",
+ "#(a)\n",
+ "Vin=5 #V\n",
+ "Vout=-k*log10(Vin/0.1) #V\n",
+ "print \"(a) For 5V input, Output Voltage = %0.2f V \" %Vout\n",
+ "#(b)\n",
+ "Vin=2 #V\n",
+ "Vout=-k*log10(Vin/0.1) #V\n",
+ "print \"(b) For 2V input, Output Voltage = %0.1f V \" %Vout \n",
+ "#(c)\n",
+ "Vin=0.1 #V\n",
+ "Vout=-k*log10(Vin/0.1) #V\n",
+ "print \"(c) For 0.1V input, Output Voltage = %0.f V \" %Vout \n",
+ "#(d)\n",
+ "Vin=50 #mV\n",
+ "Vout=-k*log10(Vin/1000/0.1) #V\n",
+ "print \"(d) For 50mV input, Output Voltage = %0.1f V \" %Vout \n",
+ "#(e)\n",
+ "Vin=5 #mV\n",
+ "Vout=-k*log10(Vin/1000/0.1) #V\n",
+ "print \"(e) For 5mV input, Output Voltage = %0.1f V \" %Vout "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) For 5V input, Output Voltage = -1.70 V \n",
+ "(b) For 2V input, Output Voltage = -1.3 V \n",
+ "(c) For 0.1V input, Output Voltage = -0 V \n",
+ "(d) For 50mV input, Output Voltage = 0.3 V \n",
+ "(e) For 5mV input, Output Voltage = 1.3 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 11.8 - page : 367"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import log10\n",
+ "k=1 #for the givn connection\n",
+ "#For 755N module\n",
+ "Rin=10 #kohm\n",
+ "Iref=10 #micro A\n",
+ "Vref=Rin*Iref/1000 #V\n",
+ "#(a)\n",
+ "Vin=5 #V\n",
+ "Vout1=-k*log10(Vin/0.1) #V\n",
+ "Vout=Vref*10**(-Vout1/k) #V\n",
+ "print \"(a) For 5V input to log amp, Antilog amp Output = %0.f V \" %Vout \n",
+ "#(b)\n",
+ "Vin=2 #V\n",
+ "Vout1=-k*log10(Vin/0.1) #V\n",
+ "Vout=Vref*10**(-Vout1/k) #V\n",
+ "print \"(b) For 2V input to log amp, Antilog amp Output = %0.f V \" %Vout \n",
+ "#(c)\n",
+ "Vin=0.1 #V\n",
+ "Vout1=-k*log10(Vin/0.1) #V\n",
+ "Vout=Vref*10**(-Vout1/k) #V\n",
+ "print \"(c) For 0.1V input to log amp, Antilog amp Output = %0.1f V \" %Vout \n",
+ "#(d)\n",
+ "Vin=50 #mV\n",
+ "Vout1=-k*log10(Vin/1000/0.1) #V\n",
+ "Vout=Vref*10**(-Vout1/k) #V\n",
+ "print \"(d) For 50mV input to log amp, Antilog amp Output = %0.f mV \" %(Vout*1000)\n",
+ "#(e)\n",
+ "Vin=5 #mV\n",
+ "Vout1=-k*log10(Vin/1000/0.1) #V\n",
+ "Vout=Vref*10**(-Vout1/k) #V\n",
+ "print \"(e) For 5mV input to log amp, Antilog amp Output = %0.f mV \" %(Vout*1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) For 5V input to log amp, Antilog amp Output = 5 V \n",
+ "(b) For 2V input to log amp, Antilog amp Output = 2 V \n",
+ "(c) For 0.1V input to log amp, Antilog amp Output = 0.1 V \n",
+ "(d) For 50mV input to log amp, Antilog amp Output = 50 mV \n",
+ "(e) For 5mV input to log amp, Antilog amp Output = 5 mV \n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter12.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter12.ipynb
new file mode 100755
index 00000000..f7130d0d
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter12.ipynb
@@ -0,0 +1,55 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d42d30351aabb6bc90d7502a456567ddf1351b8975d43ecacef103597b7b4953"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter12 - Operational transconductance amplifier"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 12.1 - page : 404"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "gm=55 #micro U\n",
+ "C=8.75 #pF\n",
+ "f3dB=gm/(2*pi*C) #MHz\n",
+ "print \"f-3dB frequency is %0.2f MHz \" %f3dB"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "f-3dB frequency is 1.00 MHz \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter13.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter13.ipynb
new file mode 100755
index 00000000..69086860
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter13.ipynb
@@ -0,0 +1,417 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:f4a83e38558e2bc6592fc86c02570a86bc0530de75031ae379e4ed7bef896b2d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter13 - Voltage Regulators"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 13.1 - page : 414"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "deltaVin=4 #V\n",
+ "deltaVout=0.4 #V\n",
+ "Vout=20 #V\n",
+ "LR=(deltaVout/Vout)*100/deltaVin #%/V(Line Regulation)\n",
+ "print \"Line Regulation = %0.1f %%/V \" %LR"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Line Regulation = 0.5 %/V \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 13.2 - page : 414"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "VNL=18.0 #V\n",
+ "VFL=17.8 #V\n",
+ "IL=50.0 #mA\n",
+ "LR=(VNL-VFL)*100/VFL #%(Line Regulation)\n",
+ "LdR=LR/IL #%/mA(Load Regulation)\n",
+ "print \"Load Regulation = %0.3f %%/mA \" %LdR "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Load Regulation = 0.022 %/mA \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 13.3 - page : 419"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "VBE=0.65 #V\n",
+ "RCL=1.2 #ohm\n",
+ "ILmax=VBE/RCL #A\n",
+ "#For Vout=0, IL=ILmax\n",
+ "IL=ILmax #A\n",
+ "print \"Load current = %0.2f A \" %IL "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Load current = 0.54 A \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 13.4 - page : 420"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "R=20 #kohm\n",
+ "R1=20 #kohm\n",
+ "R2=10 #kohm\n",
+ "VZ=4.7 #V\n",
+ "Vref=VZ #V\n",
+ "Vout=Vref*(1+R1/R2) #V\n",
+ "print \"Output Voltage = %0.1f V \" %Vout"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output Voltage = 14.1 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 13.5 - page : 427"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Vout=15 #V\n",
+ "Vin=20 #V\n",
+ "INL=2 #mA(INL=Iadj+Iref)\n",
+ "Iadj=60 #mA(Assumed)\n",
+ "Iref=INL-Iadj/1000 #mA\n",
+ "Vref=1.25 #V\n",
+ "R1=Vref/Iref*1000 #ohm\n",
+ "VR2=Vout-Vref #V\n",
+ "R2=VR2/INL*1000 #ohm\n",
+ "print \"Design values are : \"\n",
+ "print \"Resistance, R1 = %0.f ohm \" %R1 \n",
+ "print \"Resistance, R2 = %0.3f kohm \" %(R2/1000 )"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Design values are : \n",
+ "Resistance, R1 = 644 ohm \n",
+ "Resistance, R2 = 6.875 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 13.6 - page : 429"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "RL1=100 #ohm\n",
+ "RL2=1 #ohm\n",
+ "RCS=7 #ohm\n",
+ "VEB=0.7 #V\n",
+ "Beta=25 #unitless\n",
+ "#For 100 ohm Load\n",
+ "Vout=5 #V(as 7805 used)\n",
+ "IL=Vout/RL1 #A\n",
+ "VRCS=IL*RCS #V(Voltage across RCS)\n",
+ "#VRCS<VEB, hence Q1 is off\n",
+ "Iout=IL; Iin=IL #A\n",
+ "Iext=Iout-Iin #A\n",
+ "print \"For 100 ohm load, Output current Iext = %0.2f A \" %Iext\n",
+ "#For 1 ohm Load\n",
+ "Vout=5 #V(as 7805 used)\n",
+ "IL=Vout/RL2 #A\n",
+ "ILmax=IL #A\n",
+ "VRCS=IL*RCS #V(Voltage across RCS)\n",
+ "#VRCS>VEB, hence Q1 is on\n",
+ "Iout=(ILmax+Beta*VEB/RCS)/(Beta+1) #A\n",
+ "Iext=ILmax-Iout #A\n",
+ "print \"For 10 ohm load, Output current Iext = %0.3f A \" %Iext "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For 100 ohm load, Output current Iext = 0.00 A \n",
+ "For 10 ohm load, Output current Iext = 4.712 A \n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 13.7 - page : 431"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "RL=range(1,11) #ohm\n",
+ "R1=5 #ohm\n",
+ "Vref=5 #V\n",
+ "IL=1 #A\n",
+ "IQ=0 #A\n",
+ "Iref=IL #A\n",
+ "R1=Vref/Iref #ohm\n",
+ "print \"Value of resistor R1 = %0.f ohm \" %R1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of resistor R1 = 5 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 13.8 - page : 432"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Vout=range(15,21) #V\n",
+ "Vin=24 #V\n",
+ "VR1=12 #V\n",
+ "Vref=12 #V\n",
+ "I4=0 #A(Assumed)\n",
+ "Iout=1 #A(Assumed)\n",
+ "R1=VR1/Iout #ohm\n",
+ "#Vout=VR1*(1+R2/R1)\n",
+ "R2min=R1*(min(Vout)/VR1-1) #Putting min Vout\n",
+ "R2max=R1*(max(Vout)/VR1-1) #Putting min Vout\n",
+ "print \"Resistance R1 = %0.f ohm \" %R1 \n",
+ "print \"Minimum & maximum value of R2 are %0.f ohm & %0.f ohm \" %(R2min,R2max) \n",
+ "#A pot of 10 ohm should be used.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance R1 = 12 ohm \n",
+ "Minimum & maximum value of R2 are 3 ohm & 8 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 13.9 - page : 438"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Vout=6 #V\n",
+ "IL=100 #mA\n",
+ "Vref=7.15 #V(For LM 723)\n",
+ "Iref=1 #mA(Assumed)\n",
+ "R1=(Vref-Vout)/Iref #kohm\n",
+ "R2=Vout/Iref #kohm\n",
+ "print \"Design values are : \"\n",
+ "print \"R1 should be used 1.2kohm. Calculated R1 %0.2f kohm \" %R1 \n",
+ "print \"R2 should be used 6.2kohm. Calculated R2 = %0.2f kohm \" %R2 \n",
+ "R1=1.2; R2=6.2 #kohm\n",
+ "R3=R1*R2/(R1+R2) #kohm\n",
+ "print \"Resistance R3 = %0.f kohm \" %R3 \n",
+ "RCL=0.65/(IL/1000) #kohm\n",
+ "print \"Resistance RCL = %0.1f kohm \" %RCL "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Design values are : \n",
+ "R1 should be used 1.2kohm. Calculated R1 1.15 kohm \n",
+ "R2 should be used 6.2kohm. Calculated R2 = 6.00 kohm \n",
+ "Resistance R3 = 1 kohm \n",
+ "Resistance RCL = 6.5 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 13.10 - page : 442"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Vout=15 #V\n",
+ "IL=50 #mA\n",
+ "Vin=20 #V\n",
+ "PDmax=1 #W(For LM 723)\n",
+ "Iref=3 #mA(From datasheet)\n",
+ "PD=Vout*(IL+Iref) #mW\n",
+ "print \"Required PD = %0.3f W \" %(PD/1000) \n",
+ "print \"PDmax supplied by LM723 = %0.2f mW \" %PDmax \n",
+ "print \"PD<PDmax, so we can use it.\"\n",
+ "Vref=7.15 #V(For LM 723)\n",
+ "R3=1.5 #kohm(choosen)\n",
+ "R1BYR2=(Vout-Vref)/Vref \n",
+ "R1=R3*(R1BYR2+1) #ohm\n",
+ "print \"Resistance R1 = %0.2f kohm\" %R1 \n",
+ "R2=R1/R1BYR2 #ohm\n",
+ "print \"Resistance R2 = %0.2f kohm \" %R2 \n",
+ "print \"Resistance R3 = %0.2f kohm \" %R3 \n",
+ "RCL=0.65/(IL/1000) #ohm\n",
+ "print \"Resistance RCL = %0.2f ohm \" %RCL "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Required PD = 0.795 W \n",
+ "PDmax supplied by LM723 = 1.00 mW \n",
+ "PD<PDmax, so we can use it.\n",
+ "Resistance R1 = 3.15 kohm\n",
+ "Resistance R2 = 2.87 kohm \n",
+ "Resistance R3 = 1.50 kohm \n",
+ "Resistance RCL = 13.00 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter2.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter2.ipynb
new file mode 100755
index 00000000..415497af
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter2.ipynb
@@ -0,0 +1,531 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:08f6666963b63d68f1720253f0e8a698e5752723f4515bbc0a7b3ce6b79e7e0a"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter2 - Differential amplifiers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Ex 2.1 - page 31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "v1=7 #mV\n",
+ "v2=9 #mV\n",
+ "Ad=80 #dB\n",
+ "CMRR=90 #dB\n",
+ "vid=v2-v1 #mV\n",
+ "vcm=(v1+v2)/2 #mV\n",
+ "Ad=10**(Ad/20) #unitless\n",
+ "CMRR=10**(CMRR/20) #unitless\n",
+ "vout=Ad*(vid+vcm/CMRR)/1000 #V\n",
+ "print \"Output Voltage is %0.2f V\" %vout"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output Voltage is 20.00 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.2 - page 31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "v1=50.0 #micro V\n",
+ "v2=55.0 #micro V\n",
+ "Ad=2*10**5 #unitless\n",
+ "CMRR=80 #dB\n",
+ "vid=v2-v1 #micro V\n",
+ "vcm=(v1+v2)/2 #mV\n",
+ "CMRR=10**(CMRR/20) #unitless\n",
+ "vout=Ad*(vid+vcm/CMRR)/10**6 #V\n",
+ "print \"Output Voltage is %0.3f V\" %vout \n",
+ "Verror=vout-Ad*vid/10**6 #V\n",
+ "print \"Error Voltage is %0.3f V\" %Verror\n",
+ "error_p=(Verror/vout)*100 #% error\n",
+ "print \"Percentage error is %0.3f %%\" %error_p \n",
+ "#Percentage error answer is not correct in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output Voltage is 1.001 V\n",
+ "Error Voltage is 0.001 V\n",
+ "Percentage error is 0.105 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.3 - page 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import math\n",
+ "IT=1.0 #mA\n",
+ "VCC=15 #V\n",
+ "RE=50 #kohm\n",
+ "RC=15 #kohm\n",
+ "Beta=120 #unitless\n",
+ "alfa=Beta/(Beta+1) #unitless\n",
+ "Vid=6 #mV\n",
+ "VT=26 #mV\n",
+ "#Part (a)\n",
+ "iC1=alfa*IT/(1+math.exp(-Vid/VT)) #mA\n",
+ "iC2=IT-iC1 #mA\n",
+ "print \"dc Collector current through transistors is %0.3f mA\" %iC2 \n",
+ "#Part (b)\n",
+ "iC=IT/2 #mA(let iC1=iC2=iC)\n",
+ "re=VT/iC #ohm(let re1=re2=re)\n",
+ "Ad=-RC*1000/re #unitless\n",
+ "Acm=-RC*1000/(re+2*RE*1000) #unitless\n",
+ "Acm=abs(Acm) ##unitless\n",
+ "CMRR=abs(Ad/Acm) ##unitless\n",
+ "print \"Ad is %0.2f\" %Ad \n",
+ "print \"Acm is %0.2f \" %Acm \n",
+ "CMRR=20*math.log10(CMRR) #dB\n",
+ "print \"CMRR is %0.1f dB\" %CMRR"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dc Collector current through transistors is 0.447 mA\n",
+ "Ad is -288.46\n",
+ "Acm is 0.15 \n",
+ "CMRR is 65.7 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.4 - page 44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "RC=2 #kohm\n",
+ "RE=4.3 #kohm\n",
+ "VEE=5 #V\n",
+ "VBE=0.7 #V\n",
+ "IT=(VEE-VBE)/RE #mA\n",
+ "VT=26 #mV\n",
+ "re=2*VT/IT #ohm\n",
+ "Ad=-RC*1000/2/re #unitless\n",
+ "print \"Ad = \",round(Ad,2) \n",
+ "Acm=-RC*1000/(re+2*RE*1000) #unitless\n",
+ "print \"Acm = \",round(Acm,2)\n",
+ "CMRR=abs(Ad/Acm) ##unitless\n",
+ "print \"CMRR = \",round(CMRR,1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ad = -19.23\n",
+ "Acm = -0.23\n",
+ "CMRR = 83.2\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.5 - page 45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Beta=100 #unitless\n",
+ "VBE=0.715 \n",
+ "VD1=0.715 #V\n",
+ "VZ=6.2 #V\n",
+ "VT=26 #mV\n",
+ "IZt=41 #mA\n",
+ "VCC=10 #V\n",
+ "VEE=10 #V\n",
+ "RE=2.7 #kohm\n",
+ "RC=4.7 #kohm\n",
+ "VB=-VEE+VZ+VD1 #V\n",
+ "VE=VB-VBE #V\n",
+ "IE3=(VE-(-VEE))/(RE) #mA\n",
+ "IT=IE3 #mA\n",
+ "ICQ=IT/2 #mA(let ICQ1=ICQ2=ICQ)\n",
+ "VCEQ=VCC+VBE-ICQ*RC #V\n",
+ "#Q=[ICQ,VCEQ] #[mA V](Q point)\n",
+ "print \"Q point (ICQ(mA), VCEQ(V)), ICQ is \",round(ICQ,2),\"mA & VCEQ is \",round(VCEQ,2),\"V\"\n",
+ "re=2*VT/IT #ohm\n",
+ "Ad=-RC*1000/re #unitless\n",
+ "Rid=2*Beta*re/1000 #kohm\n",
+ "print \"Ad = \",round(Ad)\n",
+ "print \"Rid is %0.2f kohm\" %Rid"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Q point (ICQ(mA), VCEQ(V)), ICQ is 1.15 mA & VCEQ is 5.32 V\n",
+ "Ad = -208.0\n",
+ "Rid is 4.53 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.6 - page 47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Beta=100 #unitless\n",
+ "VBE=0.7 #V\n",
+ "VCC=10 #V\n",
+ "VEE=10 #V\n",
+ "VT=26 #mV\n",
+ "RC=2.7 #kohm\n",
+ "R=2.2 #kohm\n",
+ "IExt=(VEE-VBE)/R #mA\n",
+ "IC3=IExt \n",
+ "IT=IExt #mA\n",
+ "ICQ=IT/2 #mA\n",
+ "re=2*VT/IT #ohm(let re1=re2=re)\n",
+ "Ad=-RC*1000/re #unitless\n",
+ "Rid=2*Beta*re/1000 #kohm(let Rid1=Rid2=Rid)\n",
+ "print \"Differntial mode gain, Ad = \", round(Ad,1) \n",
+ "print \"Differntial input resistance, Rid is %0.2f kohm\" %Rid"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Differntial mode gain, Ad = -219.5\n",
+ "Differntial input resistance, Rid is 2.46 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.7 - page 49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Beta=100 #unitless\n",
+ "VBE=0.7 #V\n",
+ "VD1=0.7 #V\n",
+ "VD2=0.7#V\n",
+ "VCC=15 #V\n",
+ "VEE=15 #V\n",
+ "VT=26 #mV\n",
+ "RE=560 #ohm\n",
+ "RC=6.8 #kohm\n",
+ "R=220 #ohm\n",
+ "VB=-VEE+VD1+VD2 #V\n",
+ "VE=VB-VBE #V\n",
+ "IE3=(VE-(-VEE))/RE*1000 #mA\n",
+ "IT=IE3 #mA\n",
+ "ICQ=IT/2 #mA\n",
+ "VCEQ=VCC+VBE-ICQ*RC #V\n",
+ "#Q=[ICQ VCEQ] #[mA V](Q point)\n",
+ "print \"Q point (ICQ(mA), VCEQ(V)), ICQ is \",round(ICQ,3),\"mA & VCEQ is \",round(VCEQ,2),\"V\"\n",
+ "re=2*VT/IT #ohm\n",
+ "Ad=-RC*1000/re #unitless\n",
+ "print \"Differntial mode gain, Ad = \",round(Ad,2) \n",
+ "#Answer in the book is wrong for Q point."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Q point (ICQ(mA), VCEQ(V)), ICQ is 0.625 mA & VCEQ is 11.45 V\n",
+ "Differntial mode gain, Ad = -163.46\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.8 - page 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "ICQ=200.0 #micro A\n",
+ "Beta=1000.0 #unitless\n",
+ "Ad=180.0 #unitless\n",
+ "CMRR=80.0 #dB\n",
+ "VT=26.0 #mV\n",
+ "re=VT/(ICQ/1000) #ohm(Let re=re1=re2)\n",
+ "RC=Ad*re/1000 #kohm\n",
+ "CMRR=10**(CMRR/20) #untless\n",
+ "RE=(CMRR-1)*re/2/1000 #kohm\n",
+ "print \"Value of RC is %0.2f kohm & RE is %0.f kohm\" %(RC,RE) \n",
+ "Rid=2*Beta*re/1000 #kohm(Let Rid=Rid1=Rid2)\n",
+ "print \"Differntial input resistance, Rid is %0.f kohm \" %Rid \n",
+ "Ric=(Beta+1)*(re+2*RE*1000)/10**6 #Mohm\n",
+ "print \"Common mode input resistance, Ric is %0.f Mohm \" %Ric\n",
+ "#Answer for last part is wrong in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of RC is 23.40 kohm & RE is 650 kohm\n",
+ "Differntial input resistance, Rid is 260 kohm \n",
+ "Common mode input resistance, Ric is 1301 Mohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.9 - page 51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Beta=110 #unitless\n",
+ "VBE=0.7 #V\n",
+ "VT=26 #mV\n",
+ "VCC=10 #V\n",
+ "VEE=10 #V\n",
+ "RC=1.8 #kohm\n",
+ "R=3.9 #kohm\n",
+ "IExt=(VCC-VBE-(-VEE))/R #mA\n",
+ "IT=IExt #mA\n",
+ "ICQ=IT/2 #mA\n",
+ "V1=0 \n",
+ "V2=0 #V\n",
+ "VE=-2*VBE #V\n",
+ "VC=VCC-ICQ*RC #V\n",
+ "VCEQ=VC-VE #V\n",
+ "# Q=[ICQ VCEQ] #[mA V](Q point)\n",
+ "print \"Q point (ICQ(mA), VCEQ(V)), ICQ is \",round(ICQ,2),\"mA & VCEQ is \",round(VCEQ,2),\"V\"\n",
+ "re=2*VT/IT #ohm(let re1=re2=re)\n",
+ "reD=2*re #ohm\n",
+ "Ad=-RC*1000/reD #unitless\n",
+ "print \"Differntial mode gain, Ad = \",round(Ad,1) \n",
+ "BetaD=Beta**2 #unitless\n",
+ "Rid=2*BetaD*reD/1000 #kohm(let Rid1=Rid2=Rid)\n",
+ "print \"Differntial input resistance, Rid is %0.1f kohm\" %Rid\n",
+ "#Answer for Ad is wrong(+ve) in the book while it is negative."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Q point (ICQ(mA), VCEQ(V)), ICQ is 2.47 mA & VCEQ is 6.95 V\n",
+ "Differntial mode gain, Ad = -85.7\n",
+ "Differntial input resistance, Rid is 508.6 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.10 - page 54"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Beta=100 #unitless\n",
+ "VBE=0.7 #V\n",
+ "R=18.6 #kohm\n",
+ "VT=26 #mV\n",
+ "VCC=5 #V\n",
+ "VEE=5 #V\n",
+ "IExt=(VCC-VBE-(-VEE))/R #mA\n",
+ "IT=IExt #mA\n",
+ "re=2*VT/IT #ohm(let re1=re2=re)\n",
+ "Rid=2*Beta*re/1000 #kohm(let Rid1=Rid2=Rid)\n",
+ "print \"Differntial input resistances, Rid1=Rid2 is %0.1f kohm\" %Rid"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Differntial input resistances, Rid1=Rid2 is 20.8 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.11 - page 55"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Beta=100 #unitless\n",
+ "VBE=0.7 #V\n",
+ "RC=2.7 #kohm\n",
+ "R=2.2 #kohm\n",
+ "VT=26 #mV\n",
+ "VCC=10 #V\n",
+ "VEE=10 #V\n",
+ "IExt=(VEE-VBE)/R #mA\n",
+ "IT=IExt #mA\n",
+ "IE=IT/2 #mA(Let IE1=IE2=IE)\n",
+ "re=2*VT/IT \n",
+ "re1=re #ohm \n",
+ "re2=re #ohm \n",
+ "re3=re #ohm\n",
+ "re4=re #ohm\n",
+ "reD=re1+re2 #ohm\n",
+ "BetaD=Beta**2 #unitless\n",
+ "Ad=-RC*1000/reD #unitless\n",
+ "print \"Differential voltage gain, Ad = \",round(Ad,2)\n",
+ "Rid=2*BetaD*reD/1000 #kohm(let Rid1=Rid2=Rid)\n",
+ "print \"Differntial input resistances, Rid1=Rid2 is %0.2f kohm \" %Rid \n",
+ "#Answer in the book is not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Differential voltage gain, Ad = -109.75\n",
+ "Differntial input resistances, Rid1=Rid2 is 492.04 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter3_.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter3_.ipynb
new file mode 100755
index 00000000..c139e7d8
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter3_.ipynb
@@ -0,0 +1,251 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3abfc8b685644532e1ae7daae315a3441663a126a87262c40494af559e8472c7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter3 - Operational amplifiers and their parameters"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 3.1 - page : 76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fBW=4 #MHz\n",
+ "fo=10 #Hz\n",
+ "AOL=fBW*10**6/fo #unitless\n",
+ "print \"Open loop gain is %0.e\" %AOL"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Open loop gain is 4e+05\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 3.2 - page : 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "V1=-10 #V\n",
+ "V2=10 #V\n",
+ "SR=0.5 #V/micro second\n",
+ "delta_Vo=V2-V1 #V\n",
+ "delta_t=delta_Vo/SR #micro second\n",
+ "print \"Time taken by op-amp is %0.f micro sec\" %delta_t"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time taken by op-amp is 40 micro sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 3.3 - page : 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "SR=0.6 #V/micro second\n",
+ "f=100 #kHz\n",
+ "Vm=(SR/10**-6)/(2*math.pi*f*1000) #V\n",
+ "print \"Maximum voltage, Vm is %0.3f V\" %Vm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum voltage, Vm is 0.955 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 3.4 - page : 79"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "SR=0.5 #V/micro second\n",
+ "Vm=10 #V\n",
+ "f=100 #kHz\n",
+ "fm=(SR/10**-6)/(2*math.pi*Vm) #Hz\n",
+ "fm/=1000 #kHz\n",
+ "print \"Maximum frequency, fm is %0.2f kHz \" %fm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum frequency, fm is 7.96 kHz \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 3.5 - page : 79"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "delta_t=0.3/2 #micro second\n",
+ "V1=-3 #V\n",
+ "V2=3 #V\n",
+ "delta_Vo=V2-V1 #V\n",
+ "SR=delta_Vo/delta_t #V/micro second\n",
+ "print \"Slew rate is %0.f V/micro second \" %SR\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Slew rate is 40 V/micro second \n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 3.6 - page: 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "SR=2 #V/micro second\n",
+ "delta_Vin=0.8 #V\n",
+ "delta_t=10 #micro second\n",
+ "Acl_max=SR/(delta_Vin/delta_t) #unitless\n",
+ "print \"Maximum close loop voltage gain is\",Acl_max"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum close loop voltage gain is 25.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 3.7 - page : 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "SR=6 #V/micro second\n",
+ "#Part (i)\n",
+ "Vm=1 #V\n",
+ "fm=(SR/10**-6)/(2*math.pi*Vm) #Hz\n",
+ "fm/=1000 #kHz\n",
+ "print \"part (i) Maximum frequency, fm is %0.f kHz \" %fm\n",
+ "#Part (ii)\n",
+ "Vm=10 #V\n",
+ "fm=(SR/10**-6)/(2*math.pi*Vm) #Hz\n",
+ "fm/=1000 #kHz\n",
+ "print \"part (ii) Maximum frequency, fm is %0.1f kHz \" %fm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (i) Maximum frequency, fm is 955 kHz \n",
+ "part (ii) Maximum frequency, fm is 95.5 kHz \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter4.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter4.ipynb
new file mode 100755
index 00000000..c8040bf9
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter4.ipynb
@@ -0,0 +1,540 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:044922821cb1a1b0c88578b071d30db5925d3f145784f5c6308641fcf8036e67"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter4 - Op-amps with negative feedback"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.1 - page 91"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "AOL=2*10**5 #unitless\n",
+ "fo=5 #Hz\n",
+ "ACL=100 #unitless\n",
+ "SF=AOL/ACL #unitless\n",
+ "fodash=SF*fo #Hz\n",
+ "fodash/=1000 #kHz\n",
+ "print \"Bandwidth with feedback is %0.2f kHz\" %fodash\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bandwidth with feedback is 10.00 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.2 - page : 99"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "AOL=2*10**5 #unitless\n",
+ "Ri=1.5 #kohm\n",
+ "Rf=12 #kohm\n",
+ "Rio=1 #Mohm\n",
+ "Ro=100 #ohm\n",
+ "fo=5 #Hz\n",
+ "Beta=Ri/(Ri+Rf) #unitless\n",
+ "SF=(1+AOL)*Beta #unitless\n",
+ "ACL=AOL/SF #unitless\n",
+ "print \"Value of ACL is %0.2f\" % ACL\n",
+ "#In case of ideal opamp\n",
+ "ACL=1+Rf/Ri #unitless\n",
+ "print \"In case of ideal opamp, Value of ACL is %0.2f \" %ACL \n",
+ "Rif=Rio*SF #kohm\n",
+ "print \"Value of Rif is %0.2f Mohm\" %Rif\n",
+ "print \"This is a large value can be assumed as infity resistance.\"\n",
+ "Rof=Ro/SF #ohm\n",
+ "Rof*=1000 #mohm\n",
+ "print \"Value of Rof is %0.2f mohm\" %Rof\n",
+ "fodash=SF*fo #Hz\n",
+ "fodash/=1000 #kHz\n",
+ "print \"Bandwidth with feedback, fo_dash is %0.f kHz\" %fodash\n",
+ "#Answer for Rif in the book has mistake of unit."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of ACL is 9.00\n",
+ "In case of ideal opamp, Value of ACL is 9.00 \n",
+ "Value of Rif is 22222.33 Mohm\n",
+ "This is a large value can be assumed as infity resistance.\n",
+ "Value of Rof is 4.50 mohm\n",
+ "Bandwidth with feedback, fo_dash is 111 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.3 - page : 99"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import math\n",
+ "AOL=float(\"inf\") #unitless\n",
+ "Rio=float(\"inf\") #ohm\n",
+ "Ri=1.0 #kohm\n",
+ "Rf=15.0 #kohm\n",
+ "SF=float(\"inf\") #unitless #as SF=1+AOL*Beta\n",
+ "Beta=Ri/(Ri+Rf) #unitless\n",
+ "ACL=1/Beta #unitless\n",
+ "print \"Input impedence(ohm) for ideal opamp is %0.2f \" %Rio \n",
+ "print \"Gain of the circuit, ACL is %0.f \" %ACL "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input impedence(ohm) for ideal opamp is inf \n",
+ "Gain of the circuit, ACL is 16 \n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.4 - page : 100"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "AOL=400 #unitless\n",
+ "Rio=500 #kohm\n",
+ "Ro=75 #ohm\n",
+ "ACL=100 #unitlessc\n",
+ "SF=AOL/ACL #unitless\n",
+ "Rif=Rio*SF #kohm\n",
+ "Rif/=1000 #Mohm\n",
+ "print \"Input impedence, Rif is %0.2f Mohm \" %Rif \n",
+ "Rof=Ro/SF #ohm\n",
+ "print \"Output impedence, Rof is %0.2f ohm \" %Rof\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input impedence, Rif is 2.00 Mohm \n",
+ "Output impedence, Rof is 18.75 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.5 - page : 100"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "ACL=200.0 #unitless\n",
+ "AOL=2*10.0**5 #unitless\n",
+ "Rio=2.0 #Mohm\n",
+ "Ro=75 #ohm\n",
+ "Ri=1 #kohm(Assumed)\n",
+ "SF=AOL/ACL #unitless\n",
+ "Beta=(SF-1)/AOL #unitless\n",
+ "Rf=Ri*(1-Beta)/Beta #kohm\n",
+ "print \"Input impedence, Rif is %0.f kohm\" %Ri \n",
+ "print \"Feedback impedence, Rf is %0.f kohm \" %Rf \n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input impedence, Rif is 1 kohm\n",
+ "Feedback impedence, Rf is 199 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.6 - page : 101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "AOL=50 #unitless\n",
+ "Beta=0.8 #unitless\n",
+ "deltaAOL=-20 #%(Change in open loop gain)\n",
+ "deltaBeta=15 #%(Change in feedback factor)\n",
+ "AOLnew=AOL+AOL*deltaAOL/100 #unitless(AOL after change)\n",
+ "Betanew=Beta+Beta*deltaBeta/100 #unitless(Beta after change)\n",
+ "ACL=AOLnew/(1+AOLnew*Betanew) #unitless\n",
+ "print \"Close loop gain, ACL is %0.2f \" %ACL "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Close loop gain, ACL is 1.06 \n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.7 - page : 102"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "AOL=500 #unitless\n",
+ "Rio=300 #kohm\n",
+ "Ro=100 #ohm\n",
+ "ACL=AOL/(1+AOL) #unitless\n",
+ "Rif=Rio*(1+AOL)/1000 #Mohm\n",
+ "Rof=Ro/(1+AOL) #ohm\n",
+ "print \"Close loop gain, ACL is %0.2f \" %ACL \n",
+ "print \"Value of Rif is %0.f Mohm \" %Rif\n",
+ "print \"Value of Rof is %0.1f ohm \" %Rof "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Close loop gain, ACL is 1.00 \n",
+ "Value of Rif is 150 Mohm \n",
+ "Value of Rof is 0.2 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.8 - page : 111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Iin=1 #mA\n",
+ "Rf=1 #kohm\n",
+ "IB=0 #for ideal opamp\n",
+ "If=Iin-IB #mA\n",
+ "Vout=-If*Rf #V\n",
+ "print \"Output Voltage is %0.2f V \" %Vout "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output Voltage is -1.00 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.9 - page : 111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "I2=1 #mA\n",
+ "Rf=4.7 #kohm\n",
+ "#Case 1st\n",
+ "I1=500 #micro A\n",
+ "Vout1=-I1*10**-6*Rf*10**3 #V\n",
+ "print \"For 500 uA current, Output Voltage is %0.2f V \" %Vout1 \n",
+ "#Case 2nd\n",
+ "I2=1 #mA\n",
+ "Vout2=-I2*10**-3*Rf*10**3 #V\n",
+ "print \"For 1 mA current, Output Voltage is %0.2f V \" %Vout2 \n",
+ "deltaVout=Vout2-Vout1 #V\n",
+ "print \"Variation in Output Voltage is %0.2f V \" %deltaVout "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For 500 uA current, Output Voltage is -2.35 V \n",
+ "For 1 mA current, Output Voltage is -4.70 V \n",
+ "Variation in Output Voltage is -2.35 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.10 - page : 112"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "AOL=2*10**5 #unitless\n",
+ "Rio=2 #Mohm\n",
+ "Ro=75 #ohm\n",
+ "Ri=1 #kohm\n",
+ "Rf=10 #kohm\n",
+ "ACL=-AOL*Rf/(Rf+Ri+AOL*Ri) #unitless(Exact)\n",
+ "print \"Exact close loop voltage gain is %0.2f \" %ACL \n",
+ "ACL=-Rf/Ri #unitless(Approximate)\n",
+ "print \"Approximate close loop voltage gain is %0.2f \" %ACL\n",
+ "Beta=Ri/(Ri+Rf) #unitless\n",
+ "SF=1+AOL*Beta #unitless\n",
+ "Rif=Rio*10**6/SF #ohm\n",
+ "print \"Input impedence after feedback is %0.f ohm\" %Rif\n",
+ "# Answer for last part wrong in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Exact close loop voltage gain is -10.00 \n",
+ "Approximate close loop voltage gain is -10.00 \n",
+ "Input impedence after feedback is 110 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.11 - page : 113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Ri=2 #kohm\n",
+ "Rf=200 #kohm\n",
+ "#For 741C\n",
+ "fo=5 #Hz\n",
+ "AOL=2*10**5 #unitless\n",
+ "UGB=1 #MHz\n",
+ "ACL=-AOL*Rf/(Rf+Ri+AOL*Ri) #unitless(Exact)\n",
+ "print \"Close loop voltage gain is %0.2f \" %ACL \n",
+ "fodash=fo*AOL/-ACL #Hz\n",
+ "fodash/=1000 #kHz\n",
+ "print \"Bandwidth, fo_dash is %0.f kHz \" %fodash "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Close loop voltage gain is -99.95 \n",
+ "Bandwidth, fo_dash is 10 kHz \n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.12 - page : 113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sqrt\n",
+ "Beta=0.06 #feedback factor\n",
+ "fo=100 #Hz\n",
+ "AOL=40000 #unitless(at dc)\n",
+ "SFdc=1+AOL*Beta #sacrifice factor at dc\n",
+ "f=1 #kHz\n",
+ "f=f*10**3 #Hz\n",
+ "SF1=1+AOL*Beta/sqrt(1+f**2/fo**2) #sacrifice factor at 1 kHz\n",
+ "#(a)\n",
+ "ACL=AOL/SFdc #(unitless)exact close loop gain at dc\n",
+ "print \"Exact close loop gain at dc is %0.2f \" %ACL \n",
+ "#(b)\n",
+ "ACL=1/Beta #(unitless)approximate close loop gain at dc\n",
+ "print \"Approximate close loop gain at dc is %0.2f \" %ACL \n",
+ "#(c)\n",
+ "AOL=3980 #unitless(at dc)\n",
+ "ACL=AOL/SF1 #(unitless)exact close loop gain at 1kHz\n",
+ "print \"Exact close loop gain at 1kHz is %0.2f \" %ACL\n",
+ "# Answer not accurate in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Exact close loop gain at dc is 16.66 \n",
+ "Approximate close loop gain at dc is 16.67 \n",
+ "Exact close loop gain at 1kHz is 16.60 \n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 4.13 - page : 115"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Beta=0.04 #feedback factor\n",
+ "AOL=5000 #unitless(at dc)\n",
+ "Rio=40 #kohm\n",
+ "Ro=1 #kohm\n",
+ "SF=1+AOL*Beta #sacrifice factor at dc\n",
+ "Rif=Rio/SF*1000 #ohm\n",
+ "print \"Input impedence is %0.f ohm \" %Rif \n",
+ "Rof=Ro*1000/SF #ohm\n",
+ "print \"Output impedence is %0.2f ohm \" %Rof "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input impedence is 199 ohm \n",
+ "Output impedence is 4.98 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter5.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter5.ipynb
new file mode 100755
index 00000000..a645b224
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter5.ipynb
@@ -0,0 +1,701 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c46b787f46e559a89b9f3dea169c413775f674cf749212a8be6652dfc9f37b52"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter5 - Linear applications of op-amps"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.1 - page : 121"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "V1=2 #V\n",
+ "V2=3 #V\n",
+ "V3=4 #V\n",
+ "V4=5 #V\n",
+ "R1=10 #kohm\n",
+ "R2=15 #kohm\n",
+ "R3=22 #kohm\n",
+ "R4=50 #kohm\n",
+ "Rf=10 #kohm\n",
+ "Vout=-Rf/R1*V1-Rf/R2*V2-Rf/R3*V3-Rf/R4*V4 #V\n",
+ "print \"Output voltage of the circuit is %0.2f V \" %Vout "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output voltage of the circuit is -6.82 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.2 - page : 129"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Rf=240 #kohm\n",
+ "#Vout=-4*Vx+3*Vy \n",
+ "#case 1st\n",
+ "Vy=0 #V(But Vx is not=0)\n",
+ "#Vox=-Rf/R1*Vx=-4*Vx\n",
+ "R1=Rf/4 #kohm\n",
+ "#case 2nd\n",
+ "Vx=0 #V(But Vy is not=0)\n",
+ "#Voy=(1+Rf/R1)*R2*Vy/(R1+R2)=3*Vy\n",
+ "R2=3/(1+Rf/R1)*R1/((1-3/(1+Rf/R1)))\n",
+ "print \"Resistance R1 is %0.f kohm \" %R1 \n",
+ "print \"Resistance R2 is %0.f kohm \" %R2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance R1 is 60 kohm \n",
+ "Resistance R2 is 90 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.3 - page : 130"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "V1=-2 #V\n",
+ "V2=3 #V\n",
+ "R1=50 #kohm\n",
+ "R2=100 #kohm\n",
+ "Rf=250 #kohm\n",
+ "#I1+I2=If with IB=0 & Vx=0\n",
+ "Vout=-(V1/R1+V2/R2)*Rf #V\n",
+ "print \"Output Voltage is %0.1f V \" %Vout"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output Voltage is 2.5 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.4 - page : 130"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "V1=-2 #V\n",
+ "V2=3 #V\n",
+ "R1=12 #kohm\n",
+ "R2=12 #kohm\n",
+ "R3=10 #kohm\n",
+ "Rf=12 #kohm\n",
+ "Ri=12 #kohm\n",
+ "Rt=2 #kohm\n",
+ "Vyx=200*10**-6 #V\n",
+ "Vout=Rf/Ri*(1+2*R3/Rt)*Vyx #V\n",
+ "Vout*=1000 #mV\n",
+ "print \"Output Voltage is %0.1f mV \" %Vout "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output Voltage is 2.2 mV \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.5 - page : 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Ad=range(5,201) #Gain\n",
+ "R1max=50 #kohm(Potentiometer)\n",
+ "R4=10 #kohm\n",
+ "R3=10 #kohm\n",
+ "#Case 1st : Ad=Admin &R1=R1max\n",
+ "R1=R1max #kohm\n",
+ "R2=(min(Ad)-1)/2*R1max #kohm\n",
+ "#Case 2nd : Ad=Admax &R1=R1min\n",
+ "R1min=2*R2/(max(Ad)-1) #kohm\n",
+ "print \"Resistance R2 is %0.f kohm \" %R2 \n",
+ "print \"Minimum value of resistance R1 is %0.f kohm \" %R1min \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance R2 is 100 kohm \n",
+ "Minimum value of resistance R1 is 1 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.6 - page : 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "R3=1 #kohm\n",
+ "Rt=5 #kohm\n",
+ "Ri=1.8 #kohm\n",
+ "R1=1.8 #kohm\n",
+ "Rf=18 #kohm\n",
+ "R2=18 #kohm\n",
+ "Vs=15 #V\n",
+ "AoL=2*10**5 #Gain(for 741C)\n",
+ "Rio=2#Mohm\n",
+ "Ro=75#Mohm\n",
+ "fo=5 #Hz\n",
+ "fBW=1 #MHz\n",
+ "Ad=Rf/Ri*(1+2*R3/Rt) #differential gain\n",
+ "print \"Differential gain is %0.2f \" %Ad \n",
+ "Beta=(R3+Rt)/(2*R3+Rt) #unitless\n",
+ "Rix=Rio*10**6*(1+AoL*Beta) #ohm\n",
+ "print \"Input impedence, Rix is %0.2e ohm \" %Rix \n",
+ "Rof=Ro/(1+AoL/Ad) #ohm\n",
+ "print \"Output impedence is %0.1e Rof ohm \" %Rof \n",
+ "#Answer in the book is wrong for Rix."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Differential gain is 14.00 \n",
+ "Input impedence, Rix is 3.43e+11 ohm \n",
+ "Output impedence is 5.2e-03 Rof ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.8 - page : 134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Ri=10 #kohm\n",
+ "Rf=15 #kohm\n",
+ "Vs=9 #V\n",
+ "#Part (a)\n",
+ "Ra=120 #ohm\n",
+ "Rb=120 #ohm\n",
+ "Rc=120 #ohm\n",
+ "Rd=120 #ohm \n",
+ "Vx=0 #V\n",
+ "Vy=0 #V (as Bridge is balanced)\n",
+ "Vout=(Vy-Vx)*Rf/Ri #V\n",
+ "print \"(a) Output Voltage is %0.2f V \" %Vout \n",
+ "#Part (b)\n",
+ "Ra=120 #ohm\n",
+ "Rb=120 #ohm\n",
+ "Rc=120 #ohm\n",
+ "Rd=150 #ohm\n",
+ "Vx=Rb*Vs/(Ra+Rb) #V\n",
+ "Vy=Rc*Vs/(Rc+Rd)#V\n",
+ "Vyx=Vy-Vx #V\n",
+ "Vout=(Vy-Vx)*Rf/Ri #V\n",
+ "print \"(b) Output Voltage is %0.2f V \" %Vout "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) Output Voltage is 0.00 V \n",
+ "(b) Output Voltage is -0.75 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.9 - page : 135"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Vin=2 #V\n",
+ "Rf=2*2/(2+2)+2 #kohm\n",
+ "R1=1 #kohm\n",
+ "Vout=-Rf/R1*Vin #V\n",
+ "print \"Output Voltage is %0.f V \" %Vout "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output Voltage is -6 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.11 - page : 144"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import math\n",
+ "G=20 #dB(Gain)\n",
+ "f3dB=2 #kHz\n",
+ "Cf=0.05 #micro F\n",
+ "Rf=1/(f3dB*1000*2*math.pi*Cf/1000000)/1000 #kohm\n",
+ "G=10**(G/20) #Gain(unitless)\n",
+ "Ri=Rf*1000/G #ohm\n",
+ "print \"Resistance Rf is %0.1f kohm \" %Rf \n",
+ "print \"Resistance Ri is %0.f ohm \" %Ri \n",
+ "# Answer in wrong in thetextbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance Rf is 1.6 kohm \n",
+ "Resistance Ri is 159 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.13 - page : 146"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "%matplotlib inline\n",
+ "import matplotlib.pylab as plt\n",
+ "import numpy as np\n",
+ "from __future__ import division\n",
+ "t2=50 #ms(After open the switch)\n",
+ "R=40 #kohm\n",
+ "C=0.2 #micro F\n",
+ "V2=3 #V\n",
+ "Vin=5 #V\n",
+ "#For Ideal op-amp V1=V2\n",
+ "t1=0 #s\n",
+ "Vout1=V2 #V\n",
+ "V1=V2 #V\n",
+ "t2=t2*10**-3 #s\n",
+ "f=lambda T:(Vin-V1)\n",
+ "def integrate(a,b,f):\n",
+ " # def function before using this\n",
+ " # f=lambda t:200**2*t**2\n",
+ " #a=lower limit;b=upper limit;f is a function\n",
+ " import numpy\n",
+ " N=1000 # points for iteration\n",
+ " t=numpy.linspace(a,b,N)\n",
+ " ft=f(t)\n",
+ " ans=numpy.sum(ft)*(b-a)/N\n",
+ " ans/=3\n",
+ " ans**=1.0/2\n",
+ " return ans\n",
+ "Vout2=-1/(R*10**3*C*10**-6)*integrate(0,t2,f)+Vout1 #V\n",
+ "#Here we have t=0 switch closed Vout=3V \n",
+ "t=np.array([t1*1000,t2*1000]) #ms\n",
+ "Vout=np.array([Vout1,Vout2]) #V\n",
+ "plt.plot(t, Vout) \n",
+ "plt.title('Vout Vs time after switch is opened') \n",
+ "plt.xlabel('t(ms)') \n",
+ "plt.ylabel('Vout(V)') \n",
+ "plt.show()\n",
+ "#Plot in the textbook is not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\nrkJggg==\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x7fc6c229f310>"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.14 : page - 147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "R1=1 #kohm\n",
+ "R2=1 #kohm\n",
+ "R3=1 #kohm\n",
+ "Rf=R2+R3 #kohm\n",
+ "Vin=1 #V\n",
+ "#Capacitor remains open circuited for steady state in both cases.\n",
+ "Vout=-Rf/R1*Vin #V\n",
+ "print \"Output Voltage is %0.2f V \" %Vout "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output Voltage is -2.00 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.16 - page : 148"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#From the given equationVout=-integrate('5*Vx+2*Vy+4*Vz','t',0,t) :\n",
+ "R1Cf=1.0/5 #ratio\n",
+ "R2Cf=1.0/2 #ratio\n",
+ "R3Cf=1.0/4 #ratio\n",
+ "print \"Various design parameters are : \"\n",
+ "Cf=10 #micro F##Chosen for the design\n",
+ "print \"Capacitance is %0.2f micro F \" %Cf \n",
+ "R1=R1Cf/(Cf*10**-6)/1000 #kohm\n",
+ "R2=R2Cf/(Cf*10**-6)/1000 #kohm\n",
+ "R3=R3Cf/(Cf*10**-6)/1000 #kohm\n",
+ "print \"Resistance R1 is %0.2f kohm \" %R1 \n",
+ "print \"Resistance R2 is %0.2f kohm \" %R2\n",
+ "print \"Resistance R3 is %0.2f kohm \" %R3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are : \n",
+ "Capacitance is 10.00 micro F \n",
+ "Resistance R1 is 20.00 kohm \n",
+ "Resistance R2 is 50.00 kohm \n",
+ "Resistance R3 is 25.00 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.17 - page : 153"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "f=10 #kHz\n",
+ "Rf=3.2 #kohm\n",
+ "Ci=0.001 #micro F\n",
+ "dt=5 #micro seconds\n",
+ "dVin=5-(-5) #V(When voltage changes from -5V to +5V)\n",
+ "Vout=-Rf*1000*Ci*10**-6*dVin/(dt*10**-6) #V\n",
+ "print \"When voltage changes from -5V to +5V, The output Voltage is %0.2f V \" %Vout \n",
+ "dVin=-5-(+5) #V(When voltage changes from +5V to -5V)\n",
+ "Vout=-Rf*1000*Ci*10**-6*dVin/(dt*10**-6) #V\n",
+ "print \"When voltage changes from +5V to -5V, The output Voltage is %0.2f V \" %Vout "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "When voltage changes from -5V to +5V, The output Voltage is -6.40 V \n",
+ "When voltage changes from +5V to -5V, The output Voltage is 6.40 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.18 page : 154"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import math\n",
+ "fmin=200 #Hz\n",
+ "fmax=1 #kHz\n",
+ "fa=fmax #kHz\n",
+ "print \"Various design parameters are : \"\n",
+ "Ci=0.05 #micro F##Chosen for the design\n",
+ "print \"Capacitance Ci is %0.2f micro F \" %Ci \n",
+ "fb=10*fa #kHz\n",
+ "Rf=1/(2*math.pi*fa*10**3*Ci*10**-6)/1000 #kohm\n",
+ "print \"Resistance Rf is %0.1f kohm \" %Rf \n",
+ "Ri=1/(2*math.pi*fb*10**3*Ci*10**-6) #ohm\n",
+ "print \"Resistance Ri is %0.f ohm \" %Ri \n",
+ "Cf=Ri*Ci/(Rf*10**3) #micro F\n",
+ "print \"Capacitance Cf is %0.3f micro F \" %Cf\n",
+ "# Answer in the textbook is not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are : \n",
+ "Capacitance Ci is 0.05 micro F \n",
+ "Resistance Rf is 3.2 kohm \n",
+ "Resistance Ri is 318 ohm \n",
+ "Capacitance Cf is 0.005 micro F \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.19 - page : 156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import math\n",
+ "fmax=100 #Hz\n",
+ "fa=fmax #Hz\n",
+ "print \"Various design parameters are : \"\n",
+ "Ci=0.1 #micro F##Chosen for the design\n",
+ "print \"Capacitance Ci is %0.2f micro F \" %Ci \n",
+ "Rf=1/(2*math.pi*fa*Ci*10**-6)/1000 #kohm\n",
+ "print \"Resistance Rf is %0.1f kohm \" %Rf \n",
+ "print \"Use f=15 kohm\"\n",
+ "fb=15*fa #kHz\n",
+ "Ri=1/(2*math.pi*fb*Ci*10**-6)/1000 #kohm\n",
+ "print \"Resistance Ri is %0.2f ohm \" %Ri \n",
+ "print \"Use Ri=1 kohm\"\n",
+ "Cf=Ri*Ci/Rf #micro F\n",
+ "print \"Capacitance Cf is %0.3f micro F \" %Cf\n",
+ "#Answer in the book is not accurate for Cf."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are : \n",
+ "Capacitance Ci is 0.10 micro F \n",
+ "Resistance Rf is 15.9 kohm \n",
+ "Use f=15 kohm\n",
+ "Resistance Ri is 1.06 ohm \n",
+ "Use Ri=1 kohm\n",
+ "Capacitance Cf is 0.007 micro F \n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 5.20 -page : 157"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "f=50 #Hz\n",
+ "T=1/f #s(Period)\n",
+ "Ci=0.05 #micro F\n",
+ "RiCi=0.01*T #Given\n",
+ "Ri=RiCi/(Ci*10**-6)/1000 #kohm\n",
+ "print \"Resistance Ri is %0.2f kohm \" %Ri \n",
+ "#Vout=-.002*dVin/dt given\n",
+ "#On comparing with Vout=-Rf*Ci*dVin/dt\n",
+ "RfCi=0.002 #on comparing\n",
+ "Rf=RfCi/(Ci*10**-6)/1000 #kohm\n",
+ "print \"Resistance Rf is %0.2f kohm \" %Rf\n",
+ "Cf=Ri*Ci/Rf #micro F\n",
+ "print \"Capacitance Cf is %0.3f micro F \" %Cf "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance Ri is 4.00 kohm \n",
+ "Resistance Rf is 40.00 kohm \n",
+ "Capacitance Cf is 0.005 micro F \n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter6.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter6.ipynb
new file mode 100755
index 00000000..b4790d59
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter6.ipynb
@@ -0,0 +1,767 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7063e92d4f64e517cc0dbce51d65911cbb3639cdb52d68efbfa4c03a57d713df"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter6 - Oscillators and waveform generators"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.1 - page 170"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt, ceil\n",
+ "f0=600 #Hz#Oscillating Frequency\n",
+ "print \"Various design parameters are :-\"\n",
+ "C=0.05 #micro F#Chosen for the design\n",
+ "print \"Capacitance = %0.2f micro F\" %C\n",
+ "R=1/(2*pi*f0*sqrt(6)*C*10**-6) #ohm\n",
+ "R=R/1000 #kohm\n",
+ "print \"Resistance R = %0.1f kohm\" %R\n",
+ "#To avoid loading effect\n",
+ "Ri=10*R #kohm#Ri>=10*R\n",
+ "Ri=ceil(Ri) #kohm\n",
+ "print \"Resistance Ri = %0.1f kohm\" % Ri\n",
+ "Rf=29*Ri #kohm#Rf>=29*Ri\n",
+ "print \"Resistance Rf = %0.1f kohm\" %Rf\n",
+ "Rf=640 #kohm\n",
+ "#Balancing the circuit\n",
+ "Rom=Rf*Ri/(Rf+Ri) #kohm\n",
+ "Rom=ceil(Rom) #kohm\n",
+ "print \"Resistance Rom = %0.1f kohm\" %Rom"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance = 0.05 micro F\n",
+ "Resistance R = 2.2 kohm\n",
+ "Resistance Ri = 22.0 kohm\n",
+ "Resistance Rf = 638.0 kohm\n",
+ "Resistance Rom = 22.0 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.3 - page 181"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "f0=12 #kHz#Oscillating Frequency\n",
+ "print \"Various design parameters are :-\"\n",
+ "C=0.01 #micro F#Chosen for the design between 0.01 & 1 micro F\n",
+ "print \"Capacitance = %0.2f micro F \" % C\n",
+ "R=1/(2*pi*f0*1000*C*10**-6) #ohm\n",
+ "R=R/1000 #kohm\n",
+ "print \"Resistance R = %0.1f kohm\" %R\n",
+ "Ri=3*R/2 #kohm#Ri>=3*R/2\n",
+ "print \"Resistance Ri = %0.2f kohm\" %Ri\n",
+ "Ri=2.2 #kohm\n",
+ "Rf=2*Ri #kohm\n",
+ "print \"Resistance Rf = %.1f kohm\" %Rf"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance = 0.01 micro F \n",
+ "Resistance R = 1.3 kohm\n",
+ "Resistance Ri = 1.99 kohm\n",
+ "Resistance Rf = 4.4 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.5 - page 184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "f0=2 #kHz#Oscillating Frequency\n",
+ "print \"Various design parameters are :-\"\n",
+ "C=0.05 #micro F#Chosen for the design\n",
+ "print \"Capacitance = %0.2f micro F \" %C\n",
+ "R=1/(2*pi*f0*1000*C*10**-6) #ohm\n",
+ "R=R/1000 #kohm\n",
+ "print \"Resistance R = %0.1f kohm \" %R \n",
+ "Ri=3*R/2 #kohm#Ri>=3*R/2\n",
+ "print \"Resistance Ri = %0.1f kohm \" %Ri \n",
+ "Rf=2*Ri #kohm\n",
+ "print \"Resistance Rf = %0.1f kohm \" %Rf "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance = 0.05 micro F \n",
+ "Resistance R = 1.6 kohm \n",
+ "Resistance Ri = 2.4 kohm \n",
+ "Resistance Rf = 4.8 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.6 - page : 184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "#Data given\n",
+ "R1=1 #kohm\n",
+ "R2=1 #kohm\n",
+ "R=1 #kohm\n",
+ "C=4.7 #micro F\n",
+ "f0=1/(2*pi*R*10**3*C*10**-6) #Hz#Oscillating Frequency\n",
+ "print \"Oscillation frequency = %0.2f Hz \" %f0 "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Oscillation frequency = 33.86 Hz \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.7 - page : 188"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "f0=200 #Hz#Oscillating Frequency\n",
+ "print \"Various design parameters are :-\" \n",
+ "C=0.05 #micro F#Chosen for the design\n",
+ "print \"Capacitance = %0.2f micro F \" %C \n",
+ "R=0.159/(f0*C*10**-6) #ohm\n",
+ "R=R/1000 #kohm\n",
+ "print \"Resistance R = %0.1f kohm \" %R \n",
+ "R=510 #kohm\n",
+ "C1=C;C2=C;C3=C #micro F\n",
+ "print \"Capacitance C1 = C2 = C3 = %0.2f micro F \" %(C3) \n",
+ "R2=R;R3=R #kohm\n",
+ "print \"Resistance R2 = %0.1f kohm, R3 = %0.1f kohm \" %(R3,R2)\n",
+ "#Answer for R is calculated wrong in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance = 0.05 micro F \n",
+ "Resistance R = 15.9 kohm \n",
+ "Capacitance C1 = C2 = C3 = 0.05 micro F \n",
+ "Resistance R2 = 510.0 kohm, R3 = 510.0 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.8 - page : 189"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Rf=570 #kohm\n",
+ "Ri=15 #kohm\n",
+ "A=Rf/Ri #Gain of the circuit\n",
+ "Amin=29 #Minimum Gain requirement of RC phase shift oscillator\n",
+ "deltaA=(A-Amin)/Amin*100 #%(Exceeding Gain)\n",
+ "print \"Gain is exceeded by %0.f %% \" %deltaA "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gain is exceeded by 31 % \n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.9 - page : 192"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt\n",
+ "print \"Part (a)\"\n",
+ "L1=25 #micro H\n",
+ "L2=10 #micro H\n",
+ "Rf=22 #kohm\n",
+ "C=0.01 #micro F\n",
+ "LT=L1+L2 #micro H\n",
+ "fr=1/(2*pi*sqrt(C*10**-6*LT*10**-6)) #Hz\n",
+ "fr=fr/1000 #kHz\n",
+ "f0=fr #/kHz\n",
+ "print \"Oscillation frequency = %0.1f kHz \" %f0 \n",
+ "Ri=Rf/(L1/L2) #kohm\n",
+ "print \"Resistance Ri = %0.1f kohm \" %Ri \n",
+ "print \"Part (b)\"\n",
+ "C1=220 #pF\n",
+ "C2=680 #pF\n",
+ "Rf=22 #kohm\n",
+ "L=1 #mH\n",
+ "CT=C1*C2/(C1+C2) #pF\n",
+ "fr=1/(2*pi*sqrt(L*10**-3*CT*10**-12)) #Hz\n",
+ "fr=fr/1000 #kHz\n",
+ "f0=fr #/kHz\n",
+ "f0=round(f0) #kHz\n",
+ "print \"Oscillation frequency = %0.1f kHz \" %f0\n",
+ "Ri=Rf/(C1/C2) #kohm\n",
+ "print \"Resistance Ri = %0.1f kohm \" %Ri"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Part (a)\n",
+ "Oscillation frequency = 269.0 kHz \n",
+ "Resistance Ri = 8.8 kohm \n",
+ "Part (b)\n",
+ "Oscillation frequency = 390.0 kHz \n",
+ "Resistance Ri = 68.0 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.10 - page : 198"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "f0=1 #/kHz\n",
+ "Vsat=14 #V\n",
+ "print \"Various design parameters are :-\"\n",
+ "C1=0.05 #micro F#Chosen for the design\n",
+ "print \"Capacitance = %0.2f micro F \" %C1\n",
+ "Rf=1/(2*f0*10**3*C1*10**-6)/1000 #kohm\n",
+ "print \"Resistance Rf = %0.1f kohm \" %Rf \n",
+ "#R2=0.86*R1 and Rf=R1||R2\n",
+ "R2byR1=0.86 #from R2=0.86*R1 \n",
+ "R2=Rf*(1+R2byR1) #kohm\n",
+ "R1=R2/R2byR1 #kohm\n",
+ "print \"Resistance R1 = %0.1f kohm \" %R1 \n",
+ "print \"Resistance R2 = %0.1f kohm \" %R2 "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance = 0.05 micro F \n",
+ "Resistance Rf = 10.0 kohm \n",
+ "Resistance R1 = 21.6 kohm \n",
+ "Resistance R2 = 18.6 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.11 - page 199"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division \n",
+ "from math import log\n",
+ "T=10 #ms#(Time period)\n",
+ "f0=1/(T*10**-3) #Hz\n",
+ "C=0.05 #micro F#Chosen for the design\n",
+ "#Formula : f0=1/{2*Rf*C*log(1+2*R2/R1)}\n",
+ "Rf=1/(f0*2*C*10**-6*log(1+2))/1000 #kohm#By putting R1=R2 for this case\n",
+ "Rf=round(Rf) #kohm\n",
+ "print \"Resistance Rf = %0.1f kohm \" %Rf \n",
+ "print \"Capacitance for the design is %0.2f micro F \" %C "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance Rf = 91.0 kohm \n",
+ "Capacitance for the design is 0.05 micro F \n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.12 - page : 200"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division \n",
+ "from math import log\n",
+ "R1=4.7 #kohm\n",
+ "R2=3.3 #kohm\n",
+ "Rf=2 #kohm\n",
+ "C=0.1 #micro F\n",
+ "f0=1/2/(Rf*1000)/(C*10**-6)/log(1+2*R2/R1)/1000 #kHz\n",
+ "print \"Frequency of output signal is %0.2f kHz \" %f0 "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frequency of output signal is 2.85 kHz \n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.13 - page : 204"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division \n",
+ "f0=1.5 #kHz\n",
+ "Vout=6 #V##peak to peak\n",
+ "Vsat=13.5 #V\n",
+ "print \"Various design parameters are : \"\n",
+ "R2=10 #kohm#/choosen for the design\n",
+ "R1=R2*2*Vsat/Vout #kohm\n",
+ "print \"R1 = %0.2f kohm \" %R1 \n",
+ "print \"R2 = %0.2f kohm \" %R2 \n",
+ "#Let Cf=0.05 micro F for the design\n",
+ "Cf=0.05 #micro F\n",
+ "print \"Cf = %0.2f micro F \" %Cf \n",
+ "Ri=R1*1000/(f0*1000)/4/(Cf*10**-6*R2*1000)/1000 #kohm\n",
+ "print \"Ri = %0.2f kohm \" %Ri "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are : \n",
+ "R1 = 45.00 kohm \n",
+ "R2 = 10.00 kohm \n",
+ "Cf = 0.05 micro F \n",
+ "Ri = 15.00 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Ex 6.14\n",
+ "from __future__ import division \n",
+ "#Data given\n",
+ "R1=6.8 #kohm\n",
+ "Ri=100 #kohm\n",
+ "R2=1.5 #kohm\n",
+ "Cf=0.01 #micro F\n",
+ "Vsat=14 #V\n",
+ "Vo_pp=2*R2/R1*Vsat #V##Peak to peak output of triangular wave\n",
+ "print \"Peak to peak output of triangular wave is %0.1f V \" %Vo_pp\n",
+ "f0=R1*1000/(4*Ri*10**3*Cf*10**-6*R2*10**3)/1000 #kHz#Oscillating Frequency\n",
+ "print \"Oscillation frequency is %0.2f Hz\" %f0"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Peak to peak output of triangular wave is 6.2 V \n",
+ "Oscillation frequency is 1.13 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.15 - page : 205"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division \n",
+ "#Data given\n",
+ "f0=1 #kHz\n",
+ "Vo_pp=7 #V\n",
+ "Vsat=14 #V\n",
+ "print \"Various design parameters are :-\"\n",
+ "#Let R2=10 #kohm for the design\n",
+ "R2=10 #kohm\n",
+ "R1=2*R2*Vsat/Vo_pp #kohm\n",
+ "print \"R1 = %0.2f kohm \" %R1 \n",
+ "print \"R2 = %0.2f kohm \" %R2 \n",
+ "#Choose Cf=0.1 micro F for the design\n",
+ "Cf=0.1 #micro F\n",
+ "print \"Cf = %0.2f micro F \" %Cf \n",
+ "Ri=R1*10**3/(4*f0*10**3*Cf*10**-6*R2*10**3)/1000 #kohm\n",
+ "print \"Ri = %0.2f kohm \" %Ri "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "R1 = 40.00 kohm \n",
+ "R2 = 10.00 kohm \n",
+ "Cf = 0.10 micro F \n",
+ "Ri = 10.00 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.16 - page : 208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division \n",
+ "from math import log\n",
+ "#Data given\n",
+ "tau=1 #ms(time period)\n",
+ "R1byR2_min=1.8 # min R1/R2\n",
+ "R1byR2_max=9 # max R1/R2\n",
+ "Beta_min=1/(1+R1byR2_min) #minimum value of Beta\n",
+ "Beta_max=1/(1+R1byR2_max) #maximum value of Beta\n",
+ "Tmax=2*tau*log((1+Beta_min)/(1-Beta_min)) #ms##For minimum value of Beta\n",
+ "fmin=1/(Tmax*10**-3) #Hz\n",
+ "Tmin=2*tau*log((1+Beta_max)/(1-Beta_max)) #ms##For maximum value of Beta\n",
+ "fmax=1/(Tmin*10**-3)/1000 #kHz\n",
+ "print \"Frequency range is %d Hz to %0.1f kHz.\" %(fmin, fmax)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frequency range is 669 Hz to 2.5 kHz.\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.17 : page 211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division \n",
+ "from math import sqrt, pi\n",
+ "#Data given\n",
+ "Ls=3 #H\n",
+ "Cs=0.05 #pF\n",
+ "Rs=2 #kohm\n",
+ "Cm=10 #pF\n",
+ "fS=1/2/pi/sqrt(Ls*Cs*10**-12)/1000 #kHz\n",
+ "print \"Series resonant frequency is %0.f kHz \" %fS \n",
+ "CT=Cm*Cs/(Cm+Cs) #pF##Equivalent capacitance\n",
+ "fP=1/2/pi/sqrt(Ls*CT*10**-12)/1000 #kHz\n",
+ "print \"Parallel resonant frequency is %0.f kHz \" %fP "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Series resonant frequency is 411 kHz \n",
+ "Parallel resonant frequency is 412 kHz \n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.18 - page : 220"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division \n",
+ "#Data given\n",
+ "f0=5 #kHz\n",
+ "D=60 #%##duty cycle\n",
+ "VCC=12 #V\n",
+ "#As D=t1/(t1+t2)\n",
+ "t2BYt1=1/(D/100)-1 #ratio of t1 & t2\n",
+ "#RB/(2*RA-RB)=t2/t1\n",
+ "RAbyRB=(1/t2BYt1+1)/2 #Ratio of RA & RB\n",
+ "print \"Various design parameters are :\"\n",
+ "#Let CT=0.05 micro F for this design choosing between 0.01 & 1 microo F\n",
+ "CT=0.05 #micro F\n",
+ "print \"CT = %0.2f micro F \" %CT \n",
+ "RA=1/(f0*10**3)/(5/3)**2/(CT*10**-6)/1000 #kohm\n",
+ "print \"RA = %0.2f kohm \" %RA\n",
+ "RB=RA/RAbyRB #kohm\n",
+ "print \"RB = %0.2f kohm \" %RB"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :\n",
+ "CT = 0.05 micro F \n",
+ "RA = 1.44 kohm \n",
+ "RB = 1.15 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 6.19 - page : 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division \n",
+ "#Data given\n",
+ "Rf=15 #kohm\n",
+ "RT1=4.7 #kohm\n",
+ "R1=56 #kohm\n",
+ "R2=6.8 #kohm\n",
+ "R3=10 #kohm\n",
+ "R4=1 #kohm\n",
+ "R5=1 #kohm\n",
+ "CB=1 #micro F\n",
+ "CT=0.05 #mic\n",
+ "VCC=15 #V\n",
+ "V1=-15 #V##Voltage given through the resistance(R1) 56 kohm\n",
+ "print \"Part (i)\"\n",
+ "Vin=2 #V\n",
+ "Vo=Rf/R1*(-V1)-Rf/R2*Vin #V\n",
+ "print \"Voltage Vo = %0.3f V \" %Vo \n",
+ "N_VCC=0 #V##-VCC##voltage given to the 12th pin of IC\n",
+ "V7=N_VCC+3 #V\n",
+ "print \"Voltage V7 = %0.2f V \" %V7\n",
+ "I=(V7-Vo)/RT1 #mA\n",
+ "print \"Current I = %0.2f mA \" %I \n",
+ "Rmult=R4*R5/(R4+R5)+R3 #kohm##on pin 3\n",
+ "print \"Total resistance on pin 3, Rmult = %0.2f kohm \" %Rmult\n",
+ "f0=0.32*I*10**-3/(CT*10**-6)/1000 #kHz\n",
+ "print \"Oscillation frequency is %0.1f kHz \" %f0\n",
+ "print \"Part (ii)\"\n",
+ "Vin=5 #V\n",
+ "Vo=Rf/R1*(-V1)-Rf/R2*Vin #V\n",
+ "print \"Voltage Vo = %0.f V \" %Vo \n",
+ "N_VCC=0 #V##-VCC##voltage given to the 12th pin of IC\n",
+ "V7=N_VCC+3 #V\n",
+ "print \"Voltage V7 = %0.f V \" %V7 \n",
+ "I=(V7-Vo)/RT1 #mA\n",
+ "print \"Current I = %0.2f mA \" %I \n",
+ "Rmult=R4*R5/(R4+R5)+R3 #kohm##on pin 3\n",
+ "print \"Total resistance on pin 3, Rmult = %0.2f kohm \" %Rmult \n",
+ "f0=0.32*I*10**-3/(CT*10**-6)/1000 #kHz\n",
+ "print \"Oscillation frequency is %0.2f kHz\" %f0"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Part (i)\n",
+ "Voltage Vo = -0.394 V \n",
+ "Voltage V7 = 3.00 V \n",
+ "Current I = 0.72 mA \n",
+ "Total resistance on pin 3, Rmult = 10.50 kohm \n",
+ "Oscillation frequency is 4.6 kHz \n",
+ "Part (ii)\n",
+ "Voltage Vo = -7 V \n",
+ "Voltage V7 = 3 V \n",
+ "Current I = 2.13 mA \n",
+ "Total resistance on pin 3, Rmult = 10.50 kohm \n",
+ "Oscillation frequency is 13.63 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter7.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter7.ipynb
new file mode 100755
index 00000000..2e5c30d1
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter7.ipynb
@@ -0,0 +1,323 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:da9731a08909e4ad4cafbaaa3667ca4e507b854221c0c6168fb27a7fc7f1c9cc"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter7 - The 555 timer"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 7.1 - page : 233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "th=4 #ms\n",
+ "VCC=10 #V\n",
+ "C=0.05 #micro F(choosen between 0.01<=C<=1)\n",
+ "R=th*10**-3/(1.1*C*10**-6)/1000 #kohm\n",
+ "C1=0.01 #micro F(assumed)\n",
+ "C2=0.01 #micro F(choosen between 0.01<=C<=1)\n",
+ "R2=th*10**-3/(10*C2*10**-6)/1000 #kohm\n",
+ "C3=10 #micro F\n",
+ "print \"Design values are : \"\n",
+ "print \"Capacitance C = %0.2f micro F \" %C \n",
+ "print \"Resistance R = %0.1f kohm \" %R \n",
+ "print \"Capacitance C1 = %0.2f micro F \" %C1 \n",
+ "print \"Capacitance C2 = %0.2f micro F \" %C2 \n",
+ "print \"Resistance R2 = %0.2f kohm \" %R2 \n",
+ "print \"Capacitance C3 = %0.2f micro F \" %C3 \n",
+ "#Answer of R2 is wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Design values are : \n",
+ "Capacitance C = 0.05 micro F \n",
+ "Resistance R = 72.7 kohm \n",
+ "Capacitance C1 = 0.01 micro F \n",
+ "Capacitance C2 = 0.01 micro F \n",
+ "Resistance R2 = 40.00 kohm \n",
+ "Capacitance C3 = 10.00 micro F \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 7.2 - page : 236"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "ft=2 #kHz\n",
+ "C=0.01 #micro F\n",
+ "T=1/ft #ms\n",
+ "n=3 #for divide-by-3 circuit\n",
+ "th=(0.2+(n-1))*T #ms\n",
+ "R=th/(1.1*C) #kohm\n",
+ "print \"Value of Resistance R = %0.2f kohm \" %R"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of Resistance R = 100.00 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 7.3 - page 239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "fo=2 #kHz\n",
+ "D=70 #%(duty cycle)\n",
+ "T=1/fo #ms\n",
+ "VCC=12 #V\n",
+ "tC=D*T/100 #ms\n",
+ "tD=T-tC #ms\n",
+ "C=0.05 #micro F(choosen between 0.01<=C<=1)\n",
+ "RB=tD*10**-3/(0.69*C*10**-6)/1000 #kohm\n",
+ "RA=tC*10**-3/(0.69*C*10**-6)/1000-RB #kohm\n",
+ "print \"Design values are : \"\n",
+ "print \"Capacitance C = %0.2f micro F \" %C \n",
+ "print \"Resistance RA = %0.1f kohm \" %RA \n",
+ "print \"Resistance RB = %0.1f kohm \" %RB\n",
+ "#Answer is not accurate in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Design values are : \n",
+ "Capacitance C = 0.05 micro F \n",
+ "Resistance RA = 5.8 kohm \n",
+ "Resistance RB = 4.3 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 7.4 : page 243"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "fo=2 #kHz\n",
+ "D=50 #%(duty cycle)\n",
+ "T=1/fo #ms\n",
+ "VCC=10 #V\n",
+ "tC=D*T/100 #ms\n",
+ "tD=T-tC #ms\n",
+ "C=0.1 #micro F(choosen between 0.01<=C<=1)\n",
+ "RB=tD*10**-3/(0.69*C*10**-6)/1000 #kohm\n",
+ "RA=T*10**-3*1.45/(C*10**-6)/1000-RB #kohm\n",
+ "print \"Design values are : \"\n",
+ "print \"Capacitance C= %0.2f micro F \" %C \n",
+ "print \"Resistance RA = %0.1f kohm \" % RA \n",
+ "print \"Resistance RB = %0.1f kohm \" %RB \n",
+ "# RA & RB should be equal for 50% duty cycle."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Design values are : \n",
+ "Capacitance C= 0.10 micro F \n",
+ "Resistance RA = 3.6 kohm \n",
+ "Resistance RB = 3.6 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 7.5 - page : 244"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "fo=2 #kHz\n",
+ "D=40 #%(duty cycle)\n",
+ "T=1/fo #ms\n",
+ "VCC=10 #V\n",
+ "tC=D*T/100 #ms\n",
+ "tD=T-tC #ms\n",
+ "C=0.22 #micro F(choosen between 0.01<=C<=1)\n",
+ "RB=tD*10**-3/(0.69*C*10**-6)/1000 #kohm\n",
+ "RA=T*10**-3*1.45/(C*10**-6)/1000-RB #kohm\n",
+ "print \"Design values are : \" \n",
+ "print \"Capacitance C = %0.2f micro F \" %C \n",
+ "print \"Resistance RA = %0.1f kohm \" %RA \n",
+ "print \"Resistance RB = %0.f kohm \" %round(RB) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Design values are : \n",
+ "Capacitance C = 0.22 micro F \n",
+ "Resistance RA = 1.3 kohm \n",
+ "Resistance RB = 2 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 7.6 - page : 245"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "fo=700 #Hz\n",
+ "D=50 #%(duty cycle)\n",
+ "T=1/fo*1000 #ms\n",
+ "VCC=10 #V\n",
+ "tC=D*T/100 #ms\n",
+ "tD=T-tC #ms\n",
+ "C=0.05 #micro F(choosen between 0.01<=C<=1)\n",
+ "RB=tD*10**-3/(0.69*C*10**-6)/1000 #kohm\n",
+ "RA=T*10**-3*1.45/(C*10**-6)/1000-RB #kohm\n",
+ "print \"Design values are : \"\n",
+ "print \"Capacitance C = %0.2f micro F \" %C \n",
+ "print \"Resistance RA = %0.2f kohm \" %round(RA) \n",
+ "print \"Resistance RB = %0.2f kohm \" %round(RB) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Design values are : \n",
+ "Capacitance C = 0.05 micro F \n",
+ "Resistance RA = 21.00 kohm \n",
+ "Resistance RB = 21.00 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 7.7 - page : 246"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "fo=800 #Hz\n",
+ "D=60 #%(duty cycle)\n",
+ "T=1/fo*1000 #ms\n",
+ "VCC=10 #V\n",
+ "tC=D*T/100 #ms\n",
+ "tD=T-tC #ms\n",
+ "C=0.047 #micro F(choosen between 0.01<=C<=1)\n",
+ "RB=tD*10**-3/(0.69*C*10**-6)/1000 #kohm\n",
+ "RA=tC*10**-3*1.45/(C*10**-6)/1000-RB #kohm\n",
+ "print \"Design values are : \"\n",
+ "print \"Capacitance C = %0.3f micro F \" %C \n",
+ "print \"Resistance RA = %0.2f kohm \" %round(RA) \n",
+ "print \"Resistance RB = %0.2f kohm \" %round(RB)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Design values are : \n",
+ "Capacitance C = 0.047 micro F \n",
+ "Resistance RA = 8.00 kohm \n",
+ "Resistance RB = 15.00 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter8.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter8.ipynb
new file mode 100755
index 00000000..daf49de6
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter8.ipynb
@@ -0,0 +1,152 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:f8edf8ce3087d3427d18e8cd2380d8c52cf11f5604fcdfa69ecbcc1dd7de5bc3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter8 - Frequency synthesizers and PLL"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 8.1 - page : 255"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sqrt, pi\n",
+ "VCC=6 #V\n",
+ "VEE=6 #V\n",
+ "RT=4 #kohm\n",
+ "CT=330 #pF\n",
+ "C=240 #pF\n",
+ "fo=0.3/(RT*1000*CT*10**-12)/1000 #kHz\n",
+ "print \"Free running frequency is %0.f kHz \" %fo\n",
+ "Vplus=(VCC-(-VEE))/2 #V\n",
+ "deltafL=8*fo/Vplus #kHz\n",
+ "print \"Lock Range(+ve & -ve) is %0.f kHz \" %deltafL \n",
+ "#For LM 565\n",
+ "R=3.6 #kohm\n",
+ "deltafC=sqrt(deltafL*1000/(2*pi*R*1000*C*10**-12))/1000 #kHz\n",
+ "print \"Capture Range(+ve & -ve) is %0.f kHz \" %deltafC\n",
+ "deltafP=2*deltafC/2 #kHz\n",
+ "print \"Pull-in Range is %0.f kHz \" %deltafP "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Free running frequency is 227 kHz \n",
+ "Lock Range(+ve & -ve) is 303 kHz \n",
+ "Capture Range(+ve & -ve) is 236 kHz \n",
+ "Pull-in Range is 236 kHz \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 8.2 - page : 256"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sqrt, pi, floor\n",
+ "fo=450 #kHz\n",
+ "deltafL=240 #kHz(+ve & -ve)\n",
+ "deltafC=40 #kHz(+ve & -ve)\n",
+ "Vplus=8*fo/deltafL #V\n",
+ "#Vplus=(VCC-(-VEE))/2 but |VCC|=|-VEE|\n",
+ "VCC=Vplus #V\n",
+ "VEE=Vplus #V\n",
+ "print \"For the design |VCC|=|-VEE| is %d Volt\" %VCC\n",
+ "RT=4.7 #kohm(Assumed for design)\n",
+ "R=3.6 #kohm\n",
+ "CT=0.3/(RT*1000*fo*1000)*10**12 #pF\n",
+ "C=1/((deltafC*10**3)**2*(2*pi*R*10**3)/(deltafL*1000))*10**9 #nF\n",
+ "print \"Value of RT = %0.2f kohm \" %RT\n",
+ "print \"Value of CT = %0.f pF \" %CT\n",
+ "print \"Value of C = %0.f nF \" % floor(C)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For the design |VCC|=|-VEE| is 15 Volt\n",
+ "Value of RT = 4.70 kohm \n",
+ "Value of CT = 142 pF \n",
+ "Value of C = 6 nF \n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 8.3 - page : 264"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import log\n",
+ "fmax=160 #kHz\n",
+ "fr=4 #Hz(Resolution)\n",
+ "M=2.4 #unitless\n",
+ "fclk=M*fmax #kHz\n",
+ "print \"Clock frequency is %0.2f kHz \" %fclk\n",
+ "N=log(fclk*1000/fr)/log(2) #no. of bits\n",
+ "print \"No. of bits = %0.f \" % round(N) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Clock frequency is 384.00 kHz \n",
+ "No. of bits = 17 \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter9.ipynb b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter9.ipynb
new file mode 100755
index 00000000..c99919b0
--- /dev/null
+++ b/Analog_Integrated_Circuits_by_R.S._Tomar/Chapter9.ipynb
@@ -0,0 +1,958 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:37cf075e7171812be5843be8bfa73abd6fa4ec1e75c4ee917f74396ed076786b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter9 - Active filters"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.2 - page : 273"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "fH=1 #kHz\n",
+ "Ap=2 #Pass band gain\n",
+ "print \"Various design parameters are :-\"\n",
+ "C=0.05 #micro F#Chosen for the design\n",
+ "print \"Capacitance is %0.2f micro F \" %C\n",
+ "R=1/(2*pi*fH*1000*C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R = %0.1f kohm \" %R \n",
+ "#Ap=1+Rf/Ri\n",
+ "RfBYRi=Ap-1 #Rf=Ri here\n",
+ "#R=Rf||Ri\n",
+ "Ri=2*R #kohm\n",
+ "Rf=Ri #kohm\n",
+ "print \"Resistance Ri = %0.1f kohm \" %Ri\n",
+ "print \"Resistance Rf = %0.1f kohm \" %Rf"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance is 0.05 micro F \n",
+ "Resistance R = 3.2 kohm \n",
+ "Resistance Ri = 6.4 kohm \n",
+ "Resistance Rf = 6.4 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.3 - page : 273"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "f0=800 #Hz\n",
+ "#For Butterworth filter : f0=fH=f_3dB\n",
+ "fH=f0 #Hz\n",
+ "f_3dB=f0 #Hz\n",
+ "BW=fH #Hz\n",
+ "print \"Bandwidth = %0.2f Hz \" %BW "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bandwidth = 800.00 Hz \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.4 - page 274"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "fH=2 #kHz(Cutoff frequency)\n",
+ "Ap=1 #Pass band gain\n",
+ "print \"Various design parameters are :-\"\n",
+ "C=0.05 #micro F#Chosen for the design between 0.01 & 1 micro F\n",
+ "print \"Capacitance = %0.2f micro F \" %C\n",
+ "R=1/(2*pi*fH*1000*C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R = %0.1f kohm \" %R\n",
+ "Rdash=R #/kohm(To eliminate the effect of offset)\n",
+ "print \"Resistance R* = %0.1f kohm \" %Rdash "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance = 0.05 micro F \n",
+ "Resistance R = 1.6 kohm \n",
+ "Resistance R* = 1.6 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.5 - page : 275"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "f0=1 #kHz(Cutoff frequency)\n",
+ "f0dash=1.5 #kHz(Cutoff frequency)\n",
+ "print \"Various design parameters are :-\"\n",
+ "#For Butterworth filter\n",
+ "fH=f0 #kHz\n",
+ "fHdash=f0dash #kHz\n",
+ "K=f0/f0dash #ratio\n",
+ "R=3.2 #kohm\n",
+ "Rdash=K*R #kohm\n",
+ "print \"Resistance Rdash = %0.1f kohm \" %Rdash \n",
+ "C=0.05 #micro F#Chosen for the design\n",
+ "print \"Capacitance = %0.2f micro F \" %C\n",
+ "fHdash=1/(2*pi*Rdash*1000*C*10**-6)/1000 #kHz\n",
+ "print \"Cutoff frequency is %0.1f kHz \" %fHdash "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Resistance Rdash = 2.1 kohm \n",
+ "Capacitance = 0.05 micro F \n",
+ "Cutoff frequency is 1.5 kHz \n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.6 - page : 278"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "fL=400 #Hz\n",
+ "Ap=2 #Pass band gain\n",
+ "print \"Various design parameters are :-\"\n",
+ "C=0.05 #micro F#Chosen for the design between 0.01 & 1 micro F\n",
+ "print \"Capacitance is %0.2f micro F \" %C\n",
+ "R=1/(2*pi*fL*C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R = %0.2f kohm \" %R\n",
+ "#Ap=1+Rf/Ri\n",
+ "RfBYRi=Ap-1 #Rf=Ri here\n",
+ "#R=Rf||Ri\n",
+ "Ri=2*R #kohm\n",
+ "Rf=Ri #kohm\n",
+ "print \"Resistance Ri = %0.1f kohm \" %Ri\n",
+ "print \"Resistance Rf = %0.1f kohm \" %Rf\n",
+ "# Answer in the textbook are inaccurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance is 0.05 micro F \n",
+ "Resistance R = 7.96 kohm \n",
+ "Resistance Ri = 15.9 kohm \n",
+ "Resistance Rf = 15.9 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.7 - page : 279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi\n",
+ "fL=400 #Hz\n",
+ "fLdash=800 #Hz\n",
+ "K=fL/fLdash #ratio\n",
+ "print \"Various parameters for retuning are :-\"\n",
+ "R=8.2 #kohm\n",
+ "Rdash=K*R #kohm\n",
+ "print \"Resistance Rdash = %0.2f kohm \" %Rdash\n",
+ "Rf=2*Rdash #kohm\n",
+ "Ri=2*Rdash #kohm\n",
+ "print \"Resistance Ri = %0.1f kohm \" %Ri\n",
+ "print \"Resistance Rf = %0.1f kohm \" %Rf "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various parameters for retuning are :-\n",
+ "Resistance Rdash = 4.10 kohm \n",
+ "Resistance Ri = 8.2 kohm \n",
+ "Resistance Rf = 8.2 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.8 - page : 285"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt\n",
+ "f0=3 #kHz(Critical frequency)\n",
+ "Ap=4 #Pass band gain\n",
+ "#For Butterworth filter using sallen key\n",
+ "alfa=1.414; klp=1 #constant\n",
+ "fH=f0 #kHz\n",
+ "f_3dB=f0 #kHz\n",
+ "print \"Various design parameters are :-\"\n",
+ "C1=0.01 #micro F#Chosen for the design\n",
+ "print \"Capacitance C1 = %0.2f micro F \" %C1 \n",
+ "C2=alfa**2*C1/4 #micro F\n",
+ "print \"Capacitance C2 = %0.3f micro F \" %C2 \n",
+ "C2=0.004 # micro F\n",
+ "R=1/(2*pi*fH*10**3*sqrt(C1*10**-6*C2*10**-6))/1000 #kohm\n",
+ "print \"Resistance R = %0.1f kohm \" %R\n",
+ "R=8.2 #kohm\n",
+ "#For offset minimization\n",
+ "Rdash=2*R #kohm\n",
+ "print \"Resistance R* = %0.2f kohm \" %Rdash \n",
+ "RfBYRi=Ap-1 #Rf=Ri here\n",
+ "#Ri=10 kohm chosen for design\n",
+ "Ri=10 #kohm\n",
+ "Rf=RfBYRi*Ri #kohm\n",
+ "print \"Resistance Ri = %0.1f kohm \" %Ri\n",
+ "print \"Resistance Rf = %0.1f kohm \" %Rf "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance C1 = 0.01 micro F \n",
+ "Capacitance C2 = 0.005 micro F \n",
+ "Resistance R = 8.4 kohm \n",
+ "Resistance R* = 16.40 kohm \n",
+ "Resistance Ri = 10.0 kohm \n",
+ "Resistance Rf = 30.0 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.9 - page : 288"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt\n",
+ "f0=2 #kHz(Critical frequency)\n",
+ "Ap=5 #dc gain\n",
+ "#For Butterworth filter using sallen key\n",
+ "alfa=1.414; klp=1 #constant\n",
+ "fH=f0 #kHz\n",
+ "f_3dB=f0 #kHz\n",
+ "Ap1=3-alfa #gain\n",
+ "RfBYRi=Ap1-1 #ratio\n",
+ "print \"Various design parameters are :-\" \n",
+ "C=0.05 #micro F#Chosen for the design\n",
+ "print \"Capacitance C = %0.2f micro F \" %C \n",
+ "R=klp/(2*pi*fH*10**3*C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R = %0.1f kohm \" %R \n",
+ "#For offset minimization\n",
+ "#2*R=Rf||Ri=Rf/(RfBYRi+1)\n",
+ "Rf=2*R*(RfBYRi+1) #kohm\n",
+ "print \"Resistance Rf = %0.1f kohm \" %Rf \n",
+ "Ri=Rf/RfBYRi #kohm\n",
+ "print \"Resistance Ri = %0.1f kohm \" %Ri \n",
+ "#Ap=4 #dc gain in this case\n",
+ "Ap=4 #dc gain\n",
+ "Ap2=Ap/Ap1 #remainimg gain after 2nd order butterworth filter\n",
+ "RfdashBYRidash=Ap2-1 #ratio\n",
+ "#Ridash=10 #kohm chosen for design\n",
+ "Ridash=10 #kohm\n",
+ "print \"Resistance Ridash = %0.2f kohm \" %Ridash \n",
+ "Rfdash=RfdashBYRidash*Ridash #kohm\n",
+ "print \"Resistance Rfdash = %0.f kohm \" %Rfdash"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance C = 0.05 micro F \n",
+ "Resistance R = 1.6 kohm \n",
+ "Resistance Rf = 5.0 kohm \n",
+ "Resistance Ri = 8.6 kohm \n",
+ "Resistance Ridash = 10.00 kohm \n",
+ "Resistance Rfdash = 15 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.10 - page : 289"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt\n",
+ "f0=2 #kHz(Critical frequency)\n",
+ "fH=f0 #kHz\n",
+ "f_3dB=f0 #kHz\n",
+ "#For Butterworth filter using sallen key\n",
+ "alfa=1.414; klp=1 #constant\n",
+ "Ap=3-alfa # band pass gain\n",
+ "RfBYRi=Ap-1 #ratio\n",
+ "print \"Various design parameters are :-\"\n",
+ "C=0.05 #micro F#Chosen for the design\n",
+ "print \"Capacitance C = %0.2f micro F \" %C\n",
+ "R=1/(2*pi*fH*10**3*C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R = %0.1f kohm \" %R \n",
+ "#For offset minimization\n",
+ "#2*R=Rf||Ri=Rf/(RfBYRi+1)\n",
+ "Rf=2*R*(RfBYRi+1) #kohm\n",
+ "print \"Resistance Rf = %0.1f kohm \" %Rf \n",
+ "Ri=Rf/RfBYRi #kohm\n",
+ "print \"Resistance Ri = %0.1f kohm \" %Ri \n",
+ "#Answer in the book is not accurate. Some calculation mistake is there while working for offset minimization."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance C = 0.05 micro F \n",
+ "Resistance R = 1.6 kohm \n",
+ "Resistance Rf = 5.0 kohm \n",
+ "Resistance Ri = 8.6 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.11 - page : 290"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt\n",
+ "f0=2 #kHz(Critical frequency)\n",
+ "fH=f0 #kHz\n",
+ "f_3dB=f0 #kHz\n",
+ "#For Bessel filter of 2nd order\n",
+ "alfa=1.73; klp=0.785 #constant\n",
+ "Ap=3-alfa # band pass gain\n",
+ "RfBYRi=Ap-1 #ratio\n",
+ "print \"Various design parameters are :-\" \n",
+ "C=0.05 #micro F#Chosen for the design\n",
+ "print \"Capacitance C = %0.2f micro F \" %C \n",
+ "R=klp/(2*pi*fH*10**3*C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R = %0.2f kohm \" %R\n",
+ "#For offset minimization\n",
+ "#2*R=Rf||Ri=Rf/(RfBYRi+1)\n",
+ "Rf=2*R*(RfBYRi+1) #kohm\n",
+ "print \"Resistance Rf = %0.2f kohm \" %Rf \n",
+ "Ri=Rf/RfBYRi #kohm\n",
+ "print \"Resistance Ri = %0.2f kohm \" %Ri\n",
+ "# Answer in the textbook are inaccurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance C = 0.05 micro F \n",
+ "Resistance R = 1.25 kohm \n",
+ "Resistance Rf = 3.17 kohm \n",
+ "Resistance Ri = 11.75 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.12 - page : 291"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt\n",
+ "f0=.12 #kHz(Cutoff frequency)\n",
+ "fH=f0 #kHz\n",
+ "#For Butterworth filter of 2nd order\n",
+ "alfa=1.414; klp=1 #constant\n",
+ "Ap=3-alfa # band pass gain\n",
+ "RfBYRi=Ap-1 #ratio\n",
+ "print \"Various design parameters are :-\"\n",
+ "C=0.33 #micro F#Chosen for the design choosing between 0.01 & 1 micro F\n",
+ "print \"Capacitance C = %0.2f micro F \" %C \n",
+ "R=klp/(2*pi*fH*10**3*C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R = %0.f kohm \" %R \n",
+ "#For offset minimization\n",
+ "#2*R=Rf||Ri=Rf/(RfBYRi+1)\n",
+ "Rf=2*R*(RfBYRi+1) #kohm\n",
+ "print \"Resistance Rf = %0.2f kohm \" %Rf\n",
+ "Ri=Rf/RfBYRi #kohm\n",
+ "print \"Resistance Ri = %0.f kohm \" %Ri \n",
+ "# Answer in the textbook are inaccurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance C = 0.33 micro F \n",
+ "Resistance R = 4 kohm \n",
+ "Resistance Rf = 12.75 kohm \n",
+ "Resistance Ri = 22 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.13 - page : 295"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt, floor\n",
+ "fL=20 #Hz(Cutoff frequency)\n",
+ "#For Butterworth filter of 2nd order\n",
+ "alfa=1.414; klp=1 #constant\n",
+ "Ap=3-alfa # band pass gain\n",
+ "RfBYRi=Ap-1 #ratio\n",
+ "print \"Various design parameters are :-\"\n",
+ "C=0.22 #micro F#Chosen for the design choosing between 0.01 & 1 micro F\n",
+ "print \"Capacitance C = %0.2f micro F \" %C\n",
+ "R=klp/(2*pi*fL*C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R = %0.2f kohm \" %R \n",
+ "#For offset minimization\n",
+ "#R=Rf||Ri=Rf/(RfBYRi+1)\n",
+ "Rf=R*(RfBYRi+1) #kohm\n",
+ "print \"Resistance Rf = %0.f kohm \" %Rf \n",
+ "Ri=Rf/RfBYRi #kohm\n",
+ "Ri=floor(Ri) #kohm\n",
+ "print \"Resistance Ri = %0.f kohm \" %Ri "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance C = 0.22 micro F \n",
+ "Resistance R = 36.17 kohm \n",
+ "Resistance Rf = 57 kohm \n",
+ "Resistance Ri = 97 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.14 - page : 297"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt\n",
+ "fH=2 #kHz(Cutoff frequency)\n",
+ "Ap=4 #Pass band gain\n",
+ "print \"Butterworth filter = cascading of 1st and 2nd order high pass filter.\"\n",
+ "#Butterworth polynomial is (s+1)*(s**2+s+1)\n",
+ "alfa=1 #for sallen key\n",
+ "Ap2=3-alfa #gain for 2nd order filter\n",
+ "Ap1=Ap/Ap2 #gain for 1st order filter\n",
+ "#Design parameters for 1st order filter : \n",
+ "print \"Various design parameters for 1st order filter are :-\"\n",
+ "C=0.01 #micro F#Chosen for the design\n",
+ "print \"Capacitance C = %0.2f micro F \" %C \n",
+ "R=1/(2*pi*fH*10**3*C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R = %0.2f kohm \" %R\n",
+ "R=8.2 #kohm\n",
+ "#Ap1=Rf/Ri+1 with Ap1=2 we have Rf=Ri\n",
+ "Rf=2*R #kohm\n",
+ "Ri=2*R #kohm\n",
+ "print \"Resistance Rf = %0.2f kohm & Ri = %0.2f kohm \" %(Rf,Ri) \n",
+ "#Design parameters for 2nd order filter : \n",
+ "kLp=1/alfa #unitless\n",
+ "#Ap2=Rfdash/Ridash+1 with Ap2=2 we have Rfdash=Ridash\n",
+ "print \"Various design parameters for 2nd order filter are :-\" \n",
+ "C=0.033 #micro F#Chosen for the design\n",
+ "print \"Capacitance C = %0.3f micro F \" %C \n",
+ "R=kLp/(2*pi*fH*10**3*C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R = %0.2f kohm \" %R\n",
+ "Rf=2*R #kohm\n",
+ "Ri=2*R #kohm\n",
+ "print \"Resistance Rfdash =%0.1f kohm & Ridash = %0.1f kohm \" %(Rf,Ri) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Butterworth filter = cascading of 1st and 2nd order high pass filter.\n",
+ "Various design parameters for 1st order filter are :-\n",
+ "Capacitance C = 0.01 micro F \n",
+ "Resistance R = 7.96 kohm \n",
+ "Resistance Rf = 16.40 kohm & Ri = 16.40 kohm \n",
+ "Various design parameters for 2nd order filter are :-\n",
+ "Capacitance C = 0.033 micro F \n",
+ "Resistance R = 2.41 kohm \n",
+ "Resistance Rfdash =4.8 kohm & Ridash = 4.8 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.15 - page : 301"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt\n",
+ "fL=200 #Hz\n",
+ "fH=1 #kHz\n",
+ "Ap=4 #Pass band gain\n",
+ "fc=sqrt(fH*1000*fL) #Hz(Cutoff frequency)\n",
+ "BW=fH*1000-fL #Hz\n",
+ "Q=fc/BW #Quality Factor\n",
+ "print \"Quality factor is %0.2f \" %Q\n",
+ "print \"As Q<12, it is a wide band filter.\"\n",
+ "Ap1=2 #Pass band gain for high pass section\n",
+ "print \"Various design parameters for high pass section are :-\"\n",
+ "C=0.033 #micro F#Chosen for the design\n",
+ "print \"Capacitance C = %0.3f micro F \" %C\n",
+ "R=1/(2*pi*fL*C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R = %0.1f kohm \" %R \n",
+ "#Ap1=Rf/Ri+1 with Ap1=2 we have Rf=Ri\n",
+ "Rf=2*R #kohm\n",
+ "Ri=2*R #kohm\n",
+ "print \"Resistance Rf = %0.f kohm & Ri = %0.f kohm \" %(Rf,Ri) \n",
+ "Ap2=2 #Pass band gain for low pass section\n",
+ "print \"Various design parameters for low pass section are :-\"\n",
+ "C=0.033 #micro F#Chosen for the design\n",
+ "print \"Capacitance C = %0.3f micro F \" %C \n",
+ "K=fL/(fH*1000) #unitless\n",
+ "Rdash=K*R #kohm\n",
+ "print \"Resistance Rdash = %0.1f kohm \" %Rdash \n",
+ "#Ap1=Rf/Ri+1 with Ap1=2 we have Rf=Ri\n",
+ "Rf=2*Rdash #kohm\n",
+ "Ri=2*Rdash #kohm\n",
+ "print \"Resistance Rf = %0.f kohm & Ri = %0.f kohm \" %(Rf,Ri) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quality factor is 0.56 \n",
+ "As Q<12, it is a wide band filter.\n",
+ "Various design parameters for high pass section are :-\n",
+ "Capacitance C = 0.033 micro F \n",
+ "Resistance R = 24.1 kohm \n",
+ "Resistance Rf = 48 kohm & Ri = 48 kohm \n",
+ "Various design parameters for low pass section are :-\n",
+ "Capacitance C = 0.033 micro F \n",
+ "Resistance Rdash = 4.8 kohm \n",
+ "Resistance Rf = 10 kohm & Ri = 10 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.16 - page : 306"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt\n",
+ "print \"Part(a)\"\n",
+ "fc=1.2 #kHz\n",
+ "Q=4 #Quality Factor\n",
+ "Ap=10 #Pass band gain\n",
+ "print \"Here 2*Q**2=32>AP=10, hence it can be designed using single op-amp.\"\n",
+ "print \"Various design parameters are :-\"\n",
+ "C=0.05 #micro F#Chosen for the design\n",
+ "print \"Capacitance C = %0.2f micro F \" %C \n",
+ "#fc/Q=1/(pi*R2*C)\n",
+ "R2=Q/(fc*1000)/pi/(C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R2 = %0.1f kohm \" %R2 \n",
+ "R1=R2/(2*Ap) #kohm\n",
+ "print \"Resistance R1 = %0.2f kohm \" %R1 \n",
+ "R3=R1*1000/(4*pi**2*R1*1000*R2*1000*(C*10**-6)**2*(fc*1000)**2-1) #ohm\n",
+ "print \"Resistance R3 = %0.2f ohm \" %R3 \n",
+ "print \"Part(b)\"\n",
+ "R3=460 #ohm\n",
+ "fc_new=1.5 #kHz\n",
+ "fc_old=1.2 #kHz\n",
+ "R3new=R3*(fc_old/fc_new)**2 #ohm\n",
+ "print \"Resistance R3 should be changed from %0.2f ohm to %0.2f ohm\" %(R3, R3new) \n",
+ "#Answer for R3 is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Part(a)\n",
+ "Here 2*Q**2=32>AP=10, hence it can be designed using single op-amp.\n",
+ "Various design parameters are :-\n",
+ "Capacitance C = 0.05 micro F \n",
+ "Resistance R2 = 21.2 kohm \n",
+ "Resistance R1 = 1.06 kohm \n",
+ "Resistance R3 = 482.29 ohm \n",
+ "Part(b)\n",
+ "Resistance R3 should be changed from 460.00 ohm to 294.40 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 52
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.17 - page : 308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt\n",
+ "fL=3 #kHz\n",
+ "fH=3.6 #kHz\n",
+ "Ap=-6 #Pass band gain\n",
+ "fc=sqrt(fH*fL)*1000 #Hz\n",
+ "BW=(fH-fL)*1000 #Hz\n",
+ "Q=fc/BW #Quality factor\n",
+ "print \"Quality factor is %0.2f\" %Q\n",
+ "print \"Here 1<=Q<=12 criteria fulfills, hence it can be designed using single op-amp.\"\n",
+ "print \"Various design parameters are :-\"\n",
+ "C=0.01 #micro F#Chosen for the design\n",
+ "print \"Capacitance C = %0.2f micro F \" %C \n",
+ "#fc/Q=1/(pi*R2*C)\n",
+ "R2=1/pi/(BW)/(C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R2 = %0.f kohm \" %R2 \n",
+ "R1=-R2/(2*Ap) #kohm\n",
+ "print \"Resistance R1 = %0.2f kohm \" %R1 \n",
+ "R3=R1*1000/(4*pi**2*R1*1000*R2*1000*(C*10**-6)**2*(fc)**2-1) #ohm\n",
+ "print \"Resistance R3 = %0.f ohm \" %R3\n",
+ "print \"Design Verification : \"\n",
+ "print \"(i) Is 2*Q**2>|Ap| ?\\n\", 2*Q**2>abs(Ap) \n",
+ "print \"For op-amp 741, GBW=1 MHz\"\n",
+ "GBW=1 #MHz\n",
+ "print \"Is GBW*10**6>20*Q**2*fc ?\\n\",GBW*10**6>20*Q**2*fc\n",
+ "print \"2nd criteria failed. The op-amp should have higher GBW product. Use LF411\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quality factor is 5.48\n",
+ "Here 1<=Q<=12 criteria fulfills, hence it can be designed using single op-amp.\n",
+ "Various design parameters are :-\n",
+ "Capacitance C = 0.01 micro F \n",
+ "Resistance R2 = 53 kohm \n",
+ "Resistance R1 = 4.42 kohm \n",
+ "Resistance R3 = 491 ohm \n",
+ "Design Verification : \n",
+ "(i) Is 2*Q**2>|Ap| ?\n",
+ "True\n",
+ "For op-amp 741, GBW=1 MHz\n",
+ "Is GBW*10**6>20*Q**2*fc ?\n",
+ "False\n",
+ "2nd criteria failed. The op-amp should have higher GBW product. Use LF411\n"
+ ]
+ }
+ ],
+ "prompt_number": 56
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.18 - page : 310"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt\n",
+ "Ap=-10 #Pass band gain\n",
+ "Q=22 #Quality factor\n",
+ "fc=50 #Hz\n",
+ "R=60 #dB/decade(Roll off rate)\n",
+ "print \"\"\"Roll off rate of single op-amp=20 dB/decade.\n",
+ "No. of stages will be 3.\n",
+ "Desired design can be obtained by cascading three stages.\"\"\"\n",
+ "n=3 #no. of op-amps(as single op-amp has 20 dB/decade)\n",
+ "fc1=fc #Hz\n",
+ "fc2=fc #Hz\n",
+ "fc3=fc #Hz\n",
+ "Q1=Q*sqrt(2**(1/n)-1) #Quality factor of each stage\n",
+ "Q2=Q1 #Quality factor\n",
+ "Q3=Q1 #Quality factor\n",
+ "Ap1=-(-Ap)**(1/n) #Band pass gain of each stage\n",
+ "Ap2=Ap1 #Band pass gain\n",
+ "Ap3=Ap1 #Band pass gain\n",
+ "#Design of a single op-amp\n",
+ "C=0.1 #micro F#Chosen for the design\n",
+ "print \"Various design parameters for a single stages are :\"\n",
+ "print \"Capacitance C = %0.2f micro F \" %C \n",
+ "R2=Q1/pi/(fc)/(C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R2 = %0.f kohm \" %R2 \n",
+ "R1=-R2/(2*Ap1) #kohm\n",
+ "print \"Resistance R1 = %.f kohm \" %R1 \n",
+ "R3=R1/(4*pi**2*R1*1000*R2*1000*(C*10**-6)**2*(fc)**2-1) #kohm\n",
+ "print \"Resistance R3 = %0.1f ohm \" %R3 \n",
+ "#Answer for R2 is wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll off rate of single op-amp=20 dB/decade.\n",
+ "No. of stages will be 3.\n",
+ "Desired design can be obtained by cascading three stages.\n",
+ "Various design parameters for a single stages are :\n",
+ "Capacitance C = 0.10 micro F \n",
+ "Resistance R2 = 714 kohm \n",
+ "Resistance R1 = 166 kohm \n",
+ "Resistance R3 = 1.4 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 60
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 9.20 - page : 326"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import pi, sqrt\n",
+ "fNO=50 #Hz\n",
+ "Q=20 #Quality Factor\n",
+ "print \"Various design parameters are :-\"\n",
+ "C=1 #micro F#Chosen for the design\n",
+ "print \"Capacitance C = %0.2f micro F \" %C \n",
+ "R=1/(2*pi*fNO)/(C*10**-6)/1000 #kohm\n",
+ "print \"Resistance R = %0.2f kohm \" %R \n",
+ "#Q=(RA+RB)/4/RA\n",
+ "RA=1 #kohm(chosen for the design)\n",
+ "RB=Q*4*RA-RA #kohm\n",
+ "print \"Resistance RA = %0.f kohm \" %RA \n",
+ "print \"Resistance RB = %0.f kohm \" %RB"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Various design parameters are :-\n",
+ "Capacitance C = 1.00 micro F \n",
+ "Resistance R = 3.18 kohm \n",
+ "Resistance RA = 1 kohm \n",
+ "Resistance RB = 79 kohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 62
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_By_Example/screenshots/Arrays_1.png b/C++_By_Example/screenshots/Arrays_1.png
new file mode 100755
index 00000000..007cedf4
--- /dev/null
+++ b/C++_By_Example/screenshots/Arrays_1.png
Binary files differ
diff --git a/C++_By_Example/screenshots/class_1.png b/C++_By_Example/screenshots/class_1.png
new file mode 100755
index 00000000..651cb5fc
--- /dev/null
+++ b/C++_By_Example/screenshots/class_1.png
Binary files differ
diff --git a/C++_By_Example/screenshots/factorial_1.png b/C++_By_Example/screenshots/factorial_1.png
new file mode 100755
index 00000000..c8d8f20a
--- /dev/null
+++ b/C++_By_Example/screenshots/factorial_1.png
Binary files differ
diff --git a/C++_By_Example_by_Greg__M._Perry/Chapter1_2.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter1_2.ipynb
new file mode 100755
index 00000000..98d9cbdf
--- /dev/null
+++ b/C++_By_Example_by_Greg__M._Perry/Chapter1_2.ipynb
@@ -0,0 +1,733 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:846e4f1aaa1db87dad144e6583289406d6871f19fbfd727f22b3926e50573c01"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1: Introduction to C++"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C3FIRST, Page number:52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable Declaration\n",
+ "i=4\n",
+ "j=i+7\n",
+ "c='A'\n",
+ "x=9.087\n",
+ "x=x*4.5\n",
+ "#Result\n",
+ "print i,c,j,x"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4 A 11 40.8915\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C4ST1, Page number:85"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Result\n",
+ "print \"C++ programming is fun!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C++ programming is fun!\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C4ST2, Page number:86"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Declaration\n",
+ "tax_rate=0.08\n",
+ "sale=22.54\n",
+ "#Calculation\n",
+ "tax=sale*tax_rate\n",
+ "#Result\n",
+ "print \"The sales tax is :\" ,tax"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sales tax is : 1.8032\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C4AREAC,Page number:95"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Declaration\n",
+ "PI=3.14159\n",
+ "radius=5\n",
+ "#Calculation\n",
+ "area=radius*radius*PI\n",
+ "#Result\n",
+ "print \"The area is \",area\n",
+ "radius=20\n",
+ "#Calculation\n",
+ "area=radius*radius*PI\n",
+ "#Result\n",
+ "print \"The area is \",area"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The area is 78.53975\n",
+ "The area is 1256.636\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C5INIT,Page number:108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Get input\n",
+ "#first=raw_input(\"Enter your first name:\")\n",
+ "#last=raw_input(\"Enter your last name\")\n",
+ "first=\"perry\"\n",
+ "last=\"greg\"\n",
+ "#Print the Initials\n",
+ "print \"Your initials are \",first[0],last[0] "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your initials are p g\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C6PRE,Page number:114"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Declaration\n",
+ "AGE=28\n",
+ "MESSAGE=\"Hello, world\"\n",
+ "i=10\n",
+ "age=5\n",
+ "# 'AGE' is different from 'age'\n",
+ "i=i*AGE \n",
+ "#Result\n",
+ "print i,\" \",age,\" \",AGE,\"\\n\"\n",
+ "print MESSAGE "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "280 5 28 \n",
+ "\n",
+ "Hello, world\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C6INCL1,Page number:119"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Result\n",
+ "print \"Kelly Jane Peterson\\n\"\n",
+ "print \"Apartment #217\\n\"\n",
+ "print \"4323 East Skelly Drive\\n\"\n",
+ "print \"New York, New York\\n\"\n",
+ "print \" 10012\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Kelly Jane Peterson\n",
+ "\n",
+ "Apartment #217\n",
+ "\n",
+ "4323 East Skelly Drive\n",
+ "\n",
+ "New York, New York\n",
+ "\n",
+ " 10012\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C6INCL3,Page number:120"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "source = \"This is fun!\"\n",
+ "#source is copied to message\n",
+ "import copy\n",
+ "message=copy.copy(source)\n",
+ "#Result\n",
+ "print message"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This is fun!\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C6DEF1,Page number:121"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MYNAME=\"Phil Ward\"\n",
+ "name=MYNAME\n",
+ "#Result\n",
+ "print \"My name is \",name,\"\\n\"\n",
+ "print \"My name is \",MYNAME,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "My name is Phil Ward \n",
+ "\n",
+ "My name is Phil Ward \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C6DEF2,Page number:122"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#function definition\n",
+ "def X4(b,c,d):\n",
+ " return 2*b+c+3*b+c+b+c+4*b+c+b+c*c+b+c-d\n",
+ "b=2\n",
+ "c=3\n",
+ "d=4\n",
+ "e= X4 (b,c,d)\n",
+ "#Result\n",
+ "print e,\",\",b+c,\",\",b+c+b+c,\",\",b+c+b+c*c+b+c-d,\",\",X4(b,c,d)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "44 , 5 , 10 , 17 , 44\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C7PRNT1,Page number:136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Declaration\n",
+ "first='E'\n",
+ "middle='W'\n",
+ "last='C'\n",
+ "age=32\n",
+ "dependents=2\n",
+ "salary=25000.00\n",
+ "bonus=575.25\n",
+ "#Result\n",
+ "print \"Here are the initials: \"\n",
+ "print first,middle,last\n",
+ "print \"The age and number of dependents are \"\n",
+ "print age,\" \",dependents\n",
+ "print \"The salary and bonus are \"\n",
+ "print salary,\" \",bonus"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Here are the initials: \n",
+ "E W C\n",
+ "The age and number of dependents are \n",
+ "32 2\n",
+ "The salary and bonus are \n",
+ "25000.0 575.25\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C7TEAM, Page number:138"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#table of team names and hits for three weeks\n",
+ "print \"Parrots\\tRams\\tKings\\tTitans\\tChargers\"\n",
+ "print \"3\\t5\\t3\\t1\\t0\"\n",
+ "print \"2\\t5\\t1\\t0\\t1\"\n",
+ "print \"2\\t6\\t4\\t3\\t0\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Parrots\tRams\tKings\tTitans\tChargers\n",
+ "3\t5\t3\t1\t0\n",
+ "2\t5\t1\t0\t1\n",
+ "2\t6\t4\t3\t0\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C7PAY1,Page number:141"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Computes and prints payroll data properly in dollars and cents.\n",
+ "emp_name=\"Larry Payton\"\n",
+ "pay_date=\"03/09/92\"\n",
+ "hours_worked=43\n",
+ "rate=7.75 #pay per hour\n",
+ "tax_rate=.32 #Tax percentage rate\n",
+ "#Compute the pay amount\n",
+ "gross_pay=hours_worked*rate\n",
+ "taxes=tax_rate*gross_pay\n",
+ "net_pay=gross_pay-taxes\n",
+ "#Results\n",
+ "print \"As of: \",pay_date\n",
+ "print emp_name,\" worked \",hours_worked,\"hours\"\n",
+ "print \"and got paid\",round(gross_pay,2)\n",
+ "print \"After taxes of: \",round(taxes,2)\n",
+ "print \"his take-home pay was $\",round(net_pay,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "As of: 03/09/92\n",
+ "Larry Payton worked 43 hours\n",
+ "and got paid 333.25\n",
+ "After taxes of: 106.64\n",
+ "his take-home pay was $ 226.61\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C7SLTX1, Page number:146"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#getting total sale as float number.\n",
+ "#print \"What is the total amount of the sale?\"\n",
+ "#total_sale=float(raw_input()) \n",
+ "total_sale=50\n",
+ "#Compute sales tax\n",
+ "stax=total_sale*0.07 \n",
+ "#Results\n",
+ "print \"The sales tax for\",float(round(total_sale,2)),\"is\",round(stax,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sales tax for 50.0 is 3.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C7PHON1, Page number:147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#request user's name and print it as it would appeat in a phone book\n",
+ "#get name\n",
+ "#first=raw_input(\"What is your first name?\\n\")\n",
+ "#last=raw_input(\"What is your last name?\\n\")\n",
+ "first=\"perry\"\n",
+ "last=\"greg\"\n",
+ "print \"\\n\\n\"\n",
+ "print \"In a phone book,your name would look like this :\\n\"\n",
+ "print last,\",\",first "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "\n",
+ "In a phone book,your name would look like this :\n",
+ "\n",
+ "greg , perry\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C7MATH, Page number:148"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Simple Addition\n",
+ "print \"*** Math Practice ***\\n\"\n",
+ "#num1=input(\"What is the first number:\")\n",
+ "#num2=input(\"What is the second number:\")\n",
+ "num1=10\n",
+ "num2=20\n",
+ "ans=num1+num2\n",
+ "#get user answer\n",
+ "#her_ans=input(\"\\nWhat do you think is the answer?\")\n",
+ "her_ans=30\n",
+ "#Result\n",
+ "print \"\\n\",num1,\"plus\",num2,\"is\",ans,\"\\n\\nHope you got it right!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "*** Math Practice ***\n",
+ "\n",
+ "\n",
+ "10 plus 20 is 30 \n",
+ "\n",
+ "Hope you got it right!\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C7PS2, Page number:150"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "message=\"Please turn on your printer.\"\n",
+ "#Result\n",
+ "print message"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please turn on your printer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C7PRNTF, Page number:153"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Declaration\n",
+ "first='E'\n",
+ "middle='W'\n",
+ "last='C'\n",
+ "age=32\n",
+ "dependents=2\n",
+ "salary=25000.00\n",
+ "bonus=575.25\n",
+ "#Result\n",
+ "print \"Here are the initials: \"\n",
+ "print first,\" \",middle,\" \",last,\"\\n\"\n",
+ "print \"The age and number of dependents are: \"\n",
+ "print age,\" \",dependents,\"\\n\"\n",
+ "print \"The salary and bonus are: \"\n",
+ "print \"%.6f\" %salary,\" \",\"%.6f\" %bonus"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Here are the initials: \n",
+ "E W C \n",
+ "\n",
+ "The age and number of dependents are: \n",
+ "32 2 \n",
+ "\n",
+ "The salary and bonus are: \n",
+ "25000.000000 575.250000\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C7SLTXS, Page number:156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#prompt for a sales amount and print sales tax\n",
+ "#getting total sale as float number\n",
+ "#print \"What is the total amount of the sale?\"\n",
+ "#total_sale=float(raw_input()) \n",
+ "total_sale=10\n",
+ "#compute sales tax\n",
+ "stax=total_sale*0.07 \n",
+ "#Result\n",
+ "print \"The sales tax for\",float(round(total_sale,3)),\"is\",round(stax,3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sales tax for 10.0 is 0.7\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_By_Example_by_Greg__M._Perry/Chapter2_2.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter2_2.ipynb
new file mode 100755
index 00000000..16b4b2bc
--- /dev/null
+++ b/C++_By_Example_by_Greg__M._Perry/Chapter2_2.ipynb
@@ -0,0 +1,756 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5641a94ed238f5f3bc00f944b1535145b962a2fb8c9b581876b500af4b0fc420"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2: Using C++ Operators"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C8NEG :Page 166"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "temp=-12\n",
+ "#Result\n",
+ "print -temp"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C8DIV :Page 167"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To compute weekly pay\n",
+ "#Get input\n",
+ "#yearly=input(\"What is your annual pay?\")\n",
+ "yearly=38000.00\n",
+ "weekly=yearly/52\n",
+ "#Result\n",
+ "print \"\\nYour weekly pay is \",float(weekly)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Your weekly pay is 730.769230769\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C8AVG1 :Page 172"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Compute the average of three grades\n",
+ "grade1=87.5\n",
+ "grade2=92.4\n",
+ "grade3=79.6\n",
+ "#Average calculation\n",
+ "avg=grade1+grade2+grade3/3.0\n",
+ "#Result\n",
+ "print \"The average is: \",avg"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average is: 206.433333333\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C8DATA :Page 179"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Declaration\n",
+ "bonus=50\n",
+ "salary=1400.50\n",
+ "#Calculation\n",
+ "total=salary+bonus\n",
+ "#Result\n",
+ "print \"The total is \",\"%.2f\" %total"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The total is 1450.50\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C8INT1 :Page 181"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Calculate interest\n",
+ "days=45\n",
+ "principle=3500.00\n",
+ "interest_rate=0.155\n",
+ "#daily interest rate\n",
+ "daily_interest=interest_rate/365 \n",
+ "daily_interest=principle*daily_interest*days\n",
+ "#Update principle\n",
+ "principle+=daily_interest \n",
+ "#Result\n",
+ "print \"The balance you owe is:\",\"%.2f\" %principle"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The balance you owe is: 3566.88\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C9PAY1 :Page 193"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Calculate salesperson's pay based on his or her sales\n",
+ "print \"Payroll Calculation\\n\"\n",
+ "print \"------------------------\\n\"\n",
+ "#Get input\n",
+ "sal_name=raw_input(\"What is salesperson's last name? \")\n",
+ "hours=input(\"How many hours did the salesperson work? \")\n",
+ "total_sales=input(\"What were the total sales? \")\n",
+ "bonus=0\n",
+ "#Compute base pay\n",
+ "pay=4.10*float(hours) \n",
+ "if total_sales>8500.00:\n",
+ " bonus=500.00\n",
+ "#Result\n",
+ "print sal_name,\"made $\",\"%.2f\" %pay, \"\\n and got a bonus of $\",\"%.2f\" %bonus"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Payroll Calculation\n",
+ "\n",
+ "------------------------\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is salesperson's last name? Harrison\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many hours did the salesperson work? 40\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What were the total sales? 6050.64\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Harrison made $ 164.00 \n",
+ " and got a bonus of $ 0.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C9AGE :Page 195"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Get input\n",
+ "age=input(\"What is the student's age?\")\n",
+ "if age<10:\n",
+ " print \"\\n*** The age cannot be less than 10 ***\\n\"\n",
+ " print \"Try again...\\n\"\n",
+ " age=input(\"What is the student's age?\")\n",
+ "#Result\n",
+ "print \"\\nThank you. You entered a valid age.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the student's age?3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "*** The age cannot be less than 10 ***\n",
+ "\n",
+ "Try again...\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the student's age?21\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Thank you. You entered a valid age.\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C9SQR1 :Page 197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "##Print square of the input value if it is lessthan 180\n",
+ "#Get input\n",
+ "num=input(\"What number do you want to see the square of?\")\n",
+ "if num<=180:\n",
+ " square=num*num\n",
+ " print \"The square of \",num,\"is \",square,\"\\n\"\n",
+ " print \"\\nThank you for requesting square roots.\\n\" \n",
+ "num=input(\"What number do you want to see the square of?\")\n",
+ "if num>180:\n",
+ " import os\n",
+ " os.system('\\a')\n",
+ " print \"\\n* Square is not allowed for numbers over 180 *\"\n",
+ " print \"\\nRun this program again trying a smaller value.\"\n",
+ "print \"\\nThank you for requesting square roots.\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What number do you want to see the square of?45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The square of 45 is 2025 \n",
+ "\n",
+ "\n",
+ "Thank you for requesting square roots.\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What number do you want to see the square of?212\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "* Square is not allowed for numbers over 180 *\n",
+ "\n",
+ "Run this program again trying a smaller value.\n",
+ "\n",
+ "Thank you for requesting square roots.\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C9IFEL1 :Page 200"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Get input\n",
+ "#num=input(\"What is your answer?\\n\")\n",
+ "num=1\n",
+ "if num>0:\n",
+ " print \"\\nMore than 0\\n\"\n",
+ "else:\n",
+ " print \"\\nLess or equal to 0\\n\"\n",
+ "\n",
+ "print \"\\nThanks for your time.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "More than 0\n",
+ "\n",
+ "\n",
+ "Thanks for your time.\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C9IFEL2 :Page 200"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Test user's first initial and prints a message.\n",
+ "#Get input\n",
+ "#last=raw_input(\"\\nWhat is your last name?\\n\")\n",
+ "last=\"Praveen\"\n",
+ "#test the initial\n",
+ "if last[0] <= 'P':\n",
+ " print \"Your name is early in the alphabet.\\n\"\n",
+ "else:\n",
+ " print \"You have to wait a while for Your name to be called\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your name is early in the alphabet.\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C9PAY2 :Page 201"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Get input\n",
+ "#hours=input(\"\\nHow many hours were worked?\")\n",
+ "#rate=input(\"\\nWhat is the regular hourly pay?\")\n",
+ "hours=44\n",
+ "rate=0.20\n",
+ "#Compute pay\n",
+ "if hours>50:\n",
+ " dt=2.0*rate*float(hours-50)\n",
+ " ht=1.5*rate*10.0\n",
+ "else:\n",
+ " dt=0.0\n",
+ "#Time and a half\n",
+ "if hours>40:\n",
+ " ht=1.5*rate*float(hours-40)\n",
+ "#Regular pay\n",
+ "if hours>=40:\n",
+ " rp=40*rate\n",
+ "else:\n",
+ " rp=float(hours)*rate\n",
+ "#Payroll\n",
+ "pay=dt+ht+rp \n",
+ "#Result\n",
+ "print \"\\nThe pay is \",\"%.2f\" %pay"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The pay is 9.20\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C9SERV :Page 202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#if...else...if\n",
+ "#yrs=input(\"\\nHow many years of service?\")\n",
+ "yrs=25\n",
+ "if yrs>20:\n",
+ " print \"\\nGive a gold watch\"\n",
+ "else:\n",
+ " if yrs>10:\n",
+ " print \"\\nGive a paper weight\"\n",
+ " else:\n",
+ " print \"\\nGive a pat on the back\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Give a gold watch\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C10YEAR :Page 212"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To determine if it is Summer Olympics year\n",
+ "#year=input(\"\\nWhat is a year for the test?\")\n",
+ "year=2004\n",
+ "#Test the Year\n",
+ "if year%4==0 and year%10==0:\n",
+ " print \"\\nBoth Olympics and U.S. Census!\"\n",
+ " exit(0)\n",
+ "if year%4==0:\n",
+ " print \"\\nSummer Olympics only\"\n",
+ "else:\n",
+ " if year%10==0:\n",
+ " print \"\\nU.S. Census only\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Summer Olympics only\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C10AGE :Page 213"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Get input\n",
+ "#age=input(\"\\nWhat is your age?\\n\")\n",
+ "age=20\n",
+ "if age<10 or age>100:\n",
+ " print \"*** The age must be between 10 and 100 ***\\n\"\n",
+ "else:\n",
+ " print \"You entered a valid age.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered a valid age.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C10VIDEO :Page 214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# -*- coding: cp1252 -*-\n",
+ "#Program that computes video rental amounts and gives\n",
+ "# appropriate discounts based on the day or customer status.\n",
+ "print \"\\n *** Video Rental Computation ***\\n\"\n",
+ "print \"--------------------------------------\\n\"\n",
+ "tape_charge=2.00 #Before-discount tape fee-per tape.\n",
+ "first_name=raw_input(\"\\nWhat is customer's first name? \")\n",
+ "last_name=raw_input(\"\\nWhat is customer's last name? \")\n",
+ "num_tapes=input(\"\\nHow many tapes are being rented? \")\n",
+ "val_day=raw_input(\"Is this a Value day (Y/N)?\")\n",
+ "sp_stat=raw_input(\"Is this a Special Status customer (Y/N)?\")\n",
+ "\n",
+ "# Calculate rental amount.\n",
+ "discount=0.0\n",
+ "if val_day=='Y' or sp_stat=='Y':\n",
+ " discount=0.5\n",
+ " x=num_tapes*tape_charge\n",
+ " y=discount*num_tapes\n",
+ " rental_amt=x-y\n",
+ "print \"\\n** Rental club **\\n\"\n",
+ "print first_name,last_name,\"rented \",num_tapes,\" tapes \"\n",
+ "print \"The total was \",\"%.2f\" %rental_amt\n",
+ "print \"The discount was \",\"%.2f\" %discount,\"per tape\\n\"\n",
+ "if sp_stat=='Y':\n",
+ " print \"\\nThank them for being a special Status customer\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " *** Video Rental Computation ***\n",
+ "\n",
+ "--------------------------------------\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "What is customer's first name? Jerry\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "What is customer's last name? Parker\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many tapes are being rented? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Is this a Value day (Y/N)?Y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Is this a Special Status customer (Y/N)?Y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "** Rental club **\n",
+ "\n",
+ "Jerry Parker rented 3 tapes \n",
+ "The total was 4.50\n",
+ "The discount was 0.50 per tape\n",
+ "\n",
+ "\n",
+ "Thank them for being a special Status customer\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_By_Example_by_Greg__M._Perry/Chapter3_2.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter3_2.ipynb
new file mode 100755
index 00000000..7bf3f7ef
--- /dev/null
+++ b/C++_By_Example_by_Greg__M._Perry/Chapter3_2.ipynb
@@ -0,0 +1,1969 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:2f60b7cc87bacc3ca0350839f24c16d5959454ed43a60a8db422fa8483e17f84"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3: C++ Constructs"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C11SIZE1, Page number:232"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Size of floating-point values\n",
+ "import sys\n",
+ "x=0.0\n",
+ "print \"The size of floating-point variables on this computer is \"\n",
+ "print sys.getsizeof(x) #depends on the compiler "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The size of floating-point variables on this computer is \n",
+ "24\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C11COM1, Page number:233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Illustrates the sequence point.\n",
+ "num=5\n",
+ "sq,cube=num*num,num*num*num\n",
+ "#Result\n",
+ "print \"The square of \",num,\"is\",sq\n",
+ "print \"and the cube is \",cube"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The square of 5 is 25\n",
+ "and the cube is 125\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C11ODEV, Page number:239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Uses a bitwise & to determine whether a number is odd or even.\n",
+ "input1=input(\"What number do you want me to test?\")\n",
+ "if input1&1:\n",
+ " print \"The number \",input1,\"is odd\"\n",
+ "else:\n",
+ " print \"The number \",input1,\"is even\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What number do you want me to test?5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The number 5 is odd\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C12WHIL1, Page number:248"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ans=raw_input(\"Do you want to continue (Y/N)\")\n",
+ "while ans!='Y' and ans!='N':\n",
+ " print \"\\nYou must type a Y or an N\\n\"\n",
+ " ans=raw_input( \"Do you want to continue(Y/N)?\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to continue (Y/N)k\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "You must type a Y or an N\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to continue(Y/N)?c\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "You must type a Y or an N\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to continue(Y/N)?s\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "You must type a Y or an N\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to continue(Y/N)?5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "You must type a Y or an N\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to continue(Y/N)?Y\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C12WHIL3, Page number:251"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Number of letters in the user's name\n",
+ "name=raw_input(\"What is your first name?\")\n",
+ "count=len(name)\n",
+ "print \"Your name has \",count,\"characters\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your first name?greg\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your name has 4 characters\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C12INV1, Page number:253"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"*** Inventory computation ***\\n\"\n",
+ "while True:\n",
+ " part_no=input(\"What is the next part number(-999 to end)?\\n\")\n",
+ " if part_no!=-999:\n",
+ " quantity=input(\"How many were bought?\\n\")\n",
+ " cost=input(\"What is the unit price of this item?\\n\")\n",
+ " ext_cost=cost*quantity\n",
+ " print \"\\n\",quantity,\"of #\",part_no,\"will cost\",\"%.2f\" %ext_cost,\"\\n\"\n",
+ " else:\n",
+ " break\n",
+ "print \"End of Inventory computation\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "*** Inventory computation ***\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next part number(-999 to end)?\n",
+ "213\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many were bought?\n",
+ "12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the unit price of this item?\n",
+ "5.66\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "12 of # 213 will cost 67.92 \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next part number(-999 to end)?\n",
+ "92\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many were bought?\n",
+ "53\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the unit price of this item?\n",
+ ".23\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "53 of # 92 will cost 12.19 \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next part number(-999 to end)?\n",
+ "-999\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "End of Inventory computation\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C12BRK, Page number:257"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Demonstrates the Break statement\n",
+ "while True:\n",
+ " print \"C++ is fun!\\n\"\n",
+ " break\n",
+ " user_ans=raw_input( \"Do you want to see the message again(Y/N)?\")\n",
+ "print \"That's all for now\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C++ is fun!\n",
+ "\n",
+ "That's all for now\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C12CNT1, Page number:261"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ctr=0\n",
+ "while ctr<10:\n",
+ " print \"Computers are fun!\\n\"\n",
+ " ctr+=1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Computers are fun!\n",
+ "\n",
+ "Computers are fun!\n",
+ "\n",
+ "Computers are fun!\n",
+ "\n",
+ "Computers are fun!\n",
+ "\n",
+ "Computers are fun!\n",
+ "\n",
+ "Computers are fun!\n",
+ "\n",
+ "Computers are fun!\n",
+ "\n",
+ "Computers are fun!\n",
+ "\n",
+ "Computers are fun!\n",
+ "\n",
+ "Computers are fun!\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C12PASS1, Page number:263"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "stored_pass=11862\n",
+ "num_tries=0\n",
+ "while num_tries<3:\n",
+ " user_pass=input(\"\\nWhat is the password? (you get 3 tries...)?\")\n",
+ " num_tries+=1\n",
+ " if user_pass==stored_pass:\n",
+ " print \"You entered the correct password.\\n\"\n",
+ " print \"The cash safe is behind the picture of the ship.\"\n",
+ " exit()\n",
+ " else:\n",
+ " print \"You entered the wrong password.\\n\"\n",
+ " if num_tries==3:\n",
+ " print \"Sorry, you get no more chances\"\n",
+ " else:\n",
+ " print \"you get \",3-num_tries,\"more tries...\\n\"\n",
+ "exit(0)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "What is the password? (you get 3 tries...)?11202\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered the wrong password.\n",
+ "\n",
+ "you get 2 more tries...\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "What is the password? (you get 3 tries...)?23265\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered the wrong password.\n",
+ "\n",
+ "you get 1 more tries...\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "What is the password? (you get 3 tries...)?36963\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered the wrong password.\n",
+ "\n",
+ "Sorry, you get no more chances\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C12GRAD1, Page number:266"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Adds grades and determines whether you earned an A.\n",
+ "total_grade=0.0\n",
+ "while 1:\n",
+ " grade=input(\"What is your grade?(-1 to end)\")\n",
+ " if grade>=0.0:\n",
+ " total_grade+=grade\n",
+ " if grade==-1:\n",
+ " break\n",
+ "#Result\n",
+ "print \"\\n\\nYou made a total of \",\"%.1f\" %total_grade,\"points\\n\"\n",
+ "if total_grade>=450.00:\n",
+ " print \"** You made an A !!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your grade?(-1 to end)87.6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your grade?(-1 to end)92.4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your grade?(-1 to end)78.7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your grade?(-1 to end)-1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "You made a total of 258.7 points\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C12GRAD2, Page number:267"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "total_grade=0.0\n",
+ "grade_avg=0.0\n",
+ "grade_ctr=0\n",
+ "while 1:\n",
+ " grade=input(\"What is your grade?(-1 to end)\")\n",
+ " if grade>=0.0:\n",
+ " total_grade+=grade\n",
+ " grade_ctr+=1\n",
+ " if grade==-1:\n",
+ " break\n",
+ "grade_avg=total_grade/grade_ctr\n",
+ "#Result\n",
+ "print \"\\n\\nYou made a total of \",'%.1f' %total_grade,\"points\\n\"\n",
+ "print \"Your average was \",'%.1f' %grade_avg,\"\\n\"\n",
+ "if total_grade>=450.00:\n",
+ " print \"** You made an A !!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your grade?(-1 to end)67.8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your grade?(-1 to end)98.7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your grade?(-1 to end)67.8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your grade?(-1 to end)92.4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your grade?(-1 to end)-1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "You made a total of 326.7 points\n",
+ "\n",
+ "Your average was 81.7 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C13FOR1, Page number:276"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#for loop example\n",
+ "for ctr in range(1,11):\n",
+ " print ctr,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 \n",
+ "\n",
+ "2 \n",
+ "\n",
+ "3 \n",
+ "\n",
+ "4 \n",
+ "\n",
+ "5 \n",
+ "\n",
+ "6 \n",
+ "\n",
+ "7 \n",
+ "\n",
+ "8 \n",
+ "\n",
+ "9 \n",
+ "\n",
+ "10 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C13FOR2, Page number:278"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Demonstrates totaling using a for loop.\n",
+ "total=0\n",
+ "for ctr in range(100,201):\n",
+ " total+=ctr\n",
+ "#Result\n",
+ "print \"The total is \",total"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The total is 15150\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C13EVOD, Page number:281"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Even numbers below 21\"\n",
+ "#Result\n",
+ "for num in range(2,21,2):\n",
+ " print num,\" \",\n",
+ " print \"\\n\\nOdd numbers below 20\"\n",
+ "#Result\n",
+ "for num in range(1,21,2):\n",
+ " print num,\" \","
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Even numbers below 21\n",
+ "2 4 6 8 10 12 14 16 18 20 \n",
+ "\n",
+ "Odd numbers below 20\n",
+ "1 3 5 7 9 11 13 15 17 19 \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C13CNTD1, Page number:282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for ctr in range(10,0,-1):\n",
+ " print ctr\n",
+ "print \"*** Blast off! ***\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n",
+ "9\n",
+ "8\n",
+ "7\n",
+ "6\n",
+ "5\n",
+ "4\n",
+ "3\n",
+ "2\n",
+ "1\n",
+ "*** Blast off! ***\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C13FOR4, Page number:283"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "total=0.0\n",
+ "print \"\\n*** Grade Calculation ***\\n\"\n",
+ "num=input(\"How many students are there?\\n\")\n",
+ "for loopvar in range(0,num,1):\n",
+ " grade=input(\"What is the next student's grade?\\n\")\n",
+ " total=total+grade\n",
+ "avg=total/num\n",
+ "#Result\n",
+ "print \"\\n the average of this class is\",'%.1f' %avg"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "*** Grade Calculation ***\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many students are there?\n",
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next student's grade?\n",
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next student's grade?\n",
+ "9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next student's grade?\n",
+ "7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " the average of this class is 8.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C13FOR6, Page number:285"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "num=5\n",
+ "print \"\\nCounting by 5s:\\n\"\n",
+ "for num in range(5,101,5):\n",
+ " print \"\\n\",num"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Counting by 5s:\n",
+ "\n",
+ "\n",
+ "5\n",
+ "\n",
+ "10\n",
+ "\n",
+ "15\n",
+ "\n",
+ "20\n",
+ "\n",
+ "25\n",
+ "\n",
+ "30\n",
+ "\n",
+ "35\n",
+ "\n",
+ "40\n",
+ "\n",
+ "45\n",
+ "\n",
+ "50\n",
+ "\n",
+ "55\n",
+ "\n",
+ "60\n",
+ "\n",
+ "65\n",
+ "\n",
+ "70\n",
+ "\n",
+ "75\n",
+ "\n",
+ "80\n",
+ "\n",
+ "85\n",
+ "\n",
+ "90\n",
+ "\n",
+ "95\n",
+ "\n",
+ "100\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C13NEST1, Page number:288"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for times in range(1,4,1):\n",
+ " for num in range(1,6,1):\n",
+ " print num,\n",
+ " print \"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 2 3 4 5 \n",
+ "\n",
+ "1 2 3 4 5 \n",
+ "\n",
+ "1 2 3 4 5 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C13NEST2, Page number:289"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#for loop\n",
+ "for outer in range(6,-1,-1):\n",
+ " for inner in range(1,outer,1):\n",
+ " print inner,\n",
+ " print \"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 2 3 4 5 \n",
+ "\n",
+ "1 2 3 4 \n",
+ "\n",
+ "1 2 3 \n",
+ "\n",
+ "1 2 \n",
+ "\n",
+ "1 \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C13FACT, Page number:291"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#factorial\n",
+ "num=input(\"What factorial do you want to see?\")\n",
+ "total=1\n",
+ "for fact in range(1,num+1,1):\n",
+ " total=total*fact \n",
+ "print \"The factorial for \",num,\"is\",total"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What factorial do you want to see?7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The factorial for 7 is 5040\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C14CNTD1, Page number:297"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for cd in range(10,0,-1):\n",
+ " for delay in range(1,10,1): #for delay in range(1,30001,1):\n",
+ " print \" \"\n",
+ " print cd,\"\\n\"\n",
+ "print \"*** Blast off! ***\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "10 \n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "9 \n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "8 \n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "7 \n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "6 \n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "5 \n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "4 \n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "3 \n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "2 \n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "1 \n",
+ "\n",
+ "*** Blast off! ***\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C14TIM, Page number:298"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "age=input(\"What is your age?\\n\") #Get age\n",
+ "while age<=0:\n",
+ " print \"*** Your age cannot be that small ! ***\"\n",
+ " for outer in range(1,3,1): #outer loop\n",
+ " for inner in range(1,50,1): #inner loop\n",
+ " print \"\"\n",
+ " print \"\\r\\n\\n\"\n",
+ " age=input(\"What is your age?\\n\")\n",
+ "print \"Thanks, I did not think you would actually tell me your age!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your age?\n",
+ "20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Thanks, I did not think you would actually tell me your age!\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C14BRAK1, Page number:299"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Here are the numbers from 1 to 20\\n\"\n",
+ "for num in range(1,21,1):\n",
+ " print num,\"\\n\"\n",
+ " break #break statement\n",
+ "print \"That's all, folks!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Here are the numbers from 1 to 20\n",
+ "\n",
+ "1 \n",
+ "\n",
+ "That's all, folks!\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C14BRAK2, Page number:300"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#A for loop running at the user\u2019s request.\n",
+ "print \"Here are the numbers from 1 to 20\\n\"\n",
+ "for num in range(1,21,1):\n",
+ " print num\n",
+ " ans=raw_input(\"Do you want to see another (Y/N)?\")\n",
+ " if ans=='N' or ans=='n':\n",
+ " break\n",
+ "print \"That's all, folks!\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Here are the numbers from 1 to 20\n",
+ "\n",
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to see another (Y/N)?y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to see another (Y/N)?y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to see another (Y/N)?y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to see another (Y/N)?y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to see another (Y/N)?y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to see another (Y/N)?y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to see another (Y/N)?y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to see another (Y/N)?y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to see another (Y/N)?y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to see another (Y/N)?N\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "That's all, folks!\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C14BRAK3, Page number:302"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "total=0.0\n",
+ "count=0\n",
+ "print \"\\n*** Grade Calculation ***\\n\"\n",
+ "num=input(\"How many students are there?\")\n",
+ "for loopvar in range(1,num+1,1):\n",
+ " grade=input(\"What is the next student's grade? (-99 to quit)\")\n",
+ " if grade<0.0:\n",
+ " break\n",
+ " count+=1\n",
+ " total+=grade\n",
+ "avg=total/count\n",
+ "#Result\n",
+ "print \"The average of this class is \",'%.1f' %avg"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "*** Grade Calculation ***\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many students are there?10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next student's grade? (-99 to quit)87\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next student's grade? (-99 to quit)97\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next student's grade? (-99 to quit)67\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next student's grade? (-99 to quit)89\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next student's grade? (-99 to quit)94\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next student's grade? (-99 to quit)-99\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average of this class is 86.8\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C14CON1, Page number:305"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Demonstrates the use of the continue statement.\n",
+ "for ctr in range(1,11,1):\n",
+ " print ctr,\n",
+ " continue\n",
+ " print \"C++ programming\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 2 3 4 5 6 7 8 9 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C14CON3, Page number:306"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Average salaries over $10,000\n",
+ "avg=0.0\n",
+ "total=0.0\n",
+ "month=1.0\n",
+ "count=0\n",
+ "while month>0.0:\n",
+ " month=input(\"What is the next monthly salary (-1) to quit\")\n",
+ " year=month*12.00\n",
+ " if year <= 10000.00: #Do not add low salaries\n",
+ " continue\n",
+ " if month<0.0:\n",
+ " break\n",
+ " count+=1\n",
+ " total+=year #Add yearly salary to total.\n",
+ "avg=total/float(count)\n",
+ "#Result\n",
+ "print \"\\nThe average of high salaries is $\",'%.2f' %avg"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next monthly salary (-1) to quit500\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next monthly salary (-1) to quit2000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next monthly salary (-1) to quit750\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next monthly salary (-1) to quit4000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next monthly salary (-1) to quit5000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next monthly salary (-1) to quit1200\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the next monthly salary (-1) to quit-1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The average of high salaries is $ 36600.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C15BEEP1, Page number:314"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def beep():\n",
+ " import os\n",
+ " os.system('\\a')\n",
+ "num=input(\"Please enter a number:\")\n",
+ "#Use multiple if statements to beep.\n",
+ "if num==1:\n",
+ " beep()\n",
+ "else:\n",
+ " if num==2:\n",
+ " beep()\n",
+ " beep()\n",
+ " else:\n",
+ " if num==3:\n",
+ " beep()\n",
+ " beep()\n",
+ " beep()\n",
+ " else:\n",
+ " if num==4:\n",
+ " beep()\n",
+ " beep()\n",
+ " beep()\n",
+ " beep()\n",
+ " else:\n",
+ " if num==5:\n",
+ " beep()\n",
+ " beep()\n",
+ " beep()\n",
+ " beep()\n",
+ " beep()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter a number:2\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C15SALE, Page number:319"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Prints daily, weekly, and monthly sales totals.\n",
+ "daily=2343.34\n",
+ "weekly=13432.65\n",
+ "monthly=43468.97\n",
+ "ans=raw_input(\"Is this the end of the month? (Y/N) :\")\n",
+ "if ans=='Y' or ans=='y':\n",
+ " day=6\n",
+ "else:\n",
+ " day=input(\"What day number , 1 through 5( for mon-fri) :\")\n",
+ "if day==6:\n",
+ " print \"The monthly total is \",'%.2f' %monthly\n",
+ "else:\n",
+ " if day==5:\n",
+ " print \"The weekly total is \",'%.2f' %weekly\n",
+ " else:\n",
+ " print \"The daily total is \",'%.2f' %daily "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Is this the end of the month? (Y/N) :Y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The monthly total is 43468.97\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C15DEPT1, Page number:320"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "choice=\"R\"\n",
+ "while choice!='S' and choice!='A' and choice!='E' and choice!='P':\n",
+ " print \"\\n choose your department :\"\n",
+ " print \"S - Sales\"\n",
+ " print \"A - Accounting\"\n",
+ " print \"E - Engineering\"\n",
+ " print \"P - Payroll\"\n",
+ " choice=raw_input( \"What is your choice? (upper case)\")\n",
+ "if choice=='E':\n",
+ " print \"Your meeting is at 2:30\"\n",
+ "else:\n",
+ " if choice=='S':\n",
+ " print \"Your meeting is at 8:30\"\n",
+ " else:\n",
+ " if choice=='A':\n",
+ " print \"Your meeting is at 10:00\"\n",
+ " else:\n",
+ " if choice=='P':\n",
+ " print \"your meeting has been cancelled\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " choose your department :\n",
+ "S - Sales\n",
+ "A - Accounting\n",
+ "E - Engineering\n",
+ "P - Payroll\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your choice? (upper case)E\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your meeting is at 2:30\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_By_Example_by_Greg__M._Perry/Chapter4_2.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter4_2.ipynb
new file mode 100755
index 00000000..af8938df
--- /dev/null
+++ b/C++_By_Example_by_Greg__M._Perry/Chapter4_2.ipynb
@@ -0,0 +1,1073 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4df8567d0a6ab5b81136865656edfa550f51aea32b240bc480ecbc37fd6ab9bf"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: Variable Scope and Modular Programming"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C16FUN1, Page number:338"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Function Definition\n",
+ "def next_fun(): \n",
+ " print \"Inside next_fun()\" \n",
+ "def third_fun(): \n",
+ " print \"Inside third_fun()\"\n",
+ "def main(): \n",
+ " print \"First function called main()\"\n",
+ " #Function Call\n",
+ " next_fun() \n",
+ " third_fun() \n",
+ " print \"main() is completed\"\n",
+ "#Function Call\n",
+ "main() "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First function called main()\n",
+ "Inside next_fun()\n",
+ "Inside third_fun()\n",
+ "main() is completed\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C16FUN2, Page number:347"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Function Calls\n",
+ "def name_print():\n",
+ " print \"C++ is Fun!\\tC++ is Fun!\\tC++ is Fun!\"\n",
+ " print \" C++ i s F u n ! \\t C++ i s F u n ! \\t C++ i s F u n ! \"\n",
+ " reverse_print() \n",
+ "def reverse_print():\n",
+ " print \"!nuF si ++C\\t!nuF si ++C\\t!nuF si ++C\"\n",
+ "def one_per_line():\n",
+ " print \"C++\\n i\\n s\\n F\\n u\\n n\\n !\"\n",
+ "def main():\n",
+ " for ctr in range(1,6,1):\n",
+ " name_print() #Calls function five times.\n",
+ " one_per_line() #Calls the program's last function once \n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C++ is Fun!\tC++ is Fun!\tC++ is Fun!\n",
+ " C++ i s F u n ! \t C++ i s F u n ! \t C++ i s F u n ! \n",
+ "!nuF si ++C\t!nuF si ++C\t!nuF si ++C\n",
+ "C++ is Fun!\tC++ is Fun!\tC++ is Fun!\n",
+ " C++ i s F u n ! \t C++ i s F u n ! \t C++ i s F u n ! \n",
+ "!nuF si ++C\t!nuF si ++C\t!nuF si ++C\n",
+ "C++ is Fun!\tC++ is Fun!\tC++ is Fun!\n",
+ " C++ i s F u n ! \t C++ i s F u n ! \t C++ i s F u n ! \n",
+ "!nuF si ++C\t!nuF si ++C\t!nuF si ++C\n",
+ "C++ is Fun!\tC++ is Fun!\tC++ is Fun!\n",
+ " C++ i s F u n ! \t C++ i s F u n ! \t C++ i s F u n ! \n",
+ "!nuF si ++C\t!nuF si ++C\t!nuF si ++C\n",
+ "C++ is Fun!\tC++ is Fun!\tC++ is Fun!\n",
+ " C++ i s F u n ! \t C++ i s F u n ! \t C++ i s F u n ! \n",
+ "!nuF si ++C\t!nuF si ++C\t!nuF si ++C\n",
+ "C++\n",
+ " i\n",
+ " s\n",
+ " F\n",
+ " u\n",
+ " n\n",
+ " !\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C17GLO, Page number:356"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def do_fun():\n",
+ " global sales #global variable\n",
+ " global profit #global variable \n",
+ " sales = 20000.00\n",
+ " profit=5000.00\n",
+ " print \"The sales in the second function are: \",sales\n",
+ " print \"The profit in the second function is: \",profit\n",
+ " third_fun() #Call third function to show that globals are visible\n",
+ "def third_fun():\n",
+ " print \"\\nIn the third function:\"\n",
+ " print \"The sales in the third function are\",sales\n",
+ " print \"The profit in the third function is \",profit\n",
+ "def main():\n",
+ " print \"No variable defined in main()\\n\"\n",
+ " do_fun()\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No variable defined in main()\n",
+ "\n",
+ "The sales in the second function are: 20000.0\n",
+ "The profit in the second function is: 5000.0\n",
+ "\n",
+ "In the third function:\n",
+ "The sales in the third function are 20000.0\n",
+ "The profit in the third function is 5000.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C17GLLO, page number:358"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def pr_again():\n",
+ " j=5 #Local to only pr_again().\n",
+ " print j,\",\",z,\",\",i\n",
+ "global i\n",
+ "i=0\n",
+ "def main():\n",
+ " p=9.0 #Local to main() only\n",
+ " print i,\",\",p\n",
+ " pr_again() #Calls next function.\n",
+ "\n",
+ "global z\n",
+ "z=9.0\n",
+ "main() "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0 , 9.0\n",
+ "5 , 9.0 , 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C17LOC1, Page number:359"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " age=input(\"What is your age? \") #Variable age is local to main()\n",
+ " get_age()\n",
+ " print \"main()'s age is still\",age \n",
+ "def get_age():\n",
+ " age=input(\"What is your age again? \") #A different age. This one is local to get_age().\n",
+ "main() "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your age? 28\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your age again? 56\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "main()'s age is still 28\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C17LOC2, Page number:360"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " for ctr in range(0,11,1): #Loop counter\n",
+ " print \"main()'s ctr is \",ctr,\"\\n\"\n",
+ " do_fun() #Call second function\n",
+ "\n",
+ "def do_fun():\n",
+ " for ctr in range(10,0,-1):\n",
+ " print \"do_fun()'s ctr is \",ctr,\"\\n\"\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "main()'s ctr is 0 \n",
+ "\n",
+ "main()'s ctr is 1 \n",
+ "\n",
+ "main()'s ctr is 2 \n",
+ "\n",
+ "main()'s ctr is 3 \n",
+ "\n",
+ "main()'s ctr is 4 \n",
+ "\n",
+ "main()'s ctr is 5 \n",
+ "\n",
+ "main()'s ctr is 6 \n",
+ "\n",
+ "main()'s ctr is 7 \n",
+ "\n",
+ "main()'s ctr is 8 \n",
+ "\n",
+ "main()'s ctr is 9 \n",
+ "\n",
+ "main()'s ctr is 10 \n",
+ "\n",
+ "do_fun()'s ctr is 10 \n",
+ "\n",
+ "do_fun()'s ctr is 9 \n",
+ "\n",
+ "do_fun()'s ctr is 8 \n",
+ "\n",
+ "do_fun()'s ctr is 7 \n",
+ "\n",
+ "do_fun()'s ctr is 6 \n",
+ "\n",
+ "do_fun()'s ctr is 5 \n",
+ "\n",
+ "do_fun()'s ctr is 4 \n",
+ "\n",
+ "do_fun()'s ctr is 3 \n",
+ "\n",
+ "do_fun()'s ctr is 2 \n",
+ "\n",
+ "do_fun()'s ctr is 1 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C17MULI, Page number:362"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " i=10\n",
+ " i=20\n",
+ " print i,\" \",i,\"\\n\"\n",
+ " i=30\n",
+ " print i,\" \",i,\" \",i,\"\\n\" \n",
+ " i=10\n",
+ " print i,\" \",i,\" \",i \n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "20 20 \n",
+ "\n",
+ "30 30 30 \n",
+ "\n",
+ "10 10 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C17LOC3, Page number:367"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def pr_init(initial):\n",
+ " print \"Your initial is \",initial\n",
+ "def pr_other(age,salary):\n",
+ " print \"You look young for\",age,\"and \",'%.2f' %salary,\"is a lot of money\"\n",
+ "initial=raw_input(\"What is your initial?\")\n",
+ "age=input(\"What is your age?\")\n",
+ "salary=input(\"What is your salary?\")\n",
+ "pr_init(initial) #call pr_init() and pass it initial\n",
+ "pr_other(age,salary) #call pr_other and pass age and salary"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your initial?Jerry\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your age?30\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your salary?50000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your initial is Jerry\n",
+ "You look young for 30 and 50000.00 is a lot of money\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C17LOC4, Page number:368"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def compute_sale(gallons):\n",
+ " #local variable\n",
+ " price_per=12.45 \n",
+ " x=price_per*float(gallons) #type casting gallons because it was integer\n",
+ " print \"The total is \",'%.2f' %x\n",
+ "def main():\n",
+ " print \"Richard's Paint Service\"\n",
+ " gallons=input(\"How many gallons of paint did you buy?\")\n",
+ " compute_sale(gallons) #Function Call\n",
+ "main()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Richard's Paint Service\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many gallons of paint did you buy?20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The total is 249.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C17STA2, Page number:372"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " for ctr in range(1,26,1):\n",
+ " triple_it(ctr)\n",
+ "def triple_it(ctr):\n",
+ " total=0\n",
+ " ans=ctr*3\n",
+ " total+=ans\n",
+ " print \"The number \",ctr,\"multiplied by 3 is \",ans\n",
+ " if total>300:\n",
+ " print \"The total of triple numbers is over 300\"\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The number 1 multiplied by 3 is 3\n",
+ "The number 2 multiplied by 3 is 6\n",
+ "The number 3 multiplied by 3 is 9\n",
+ "The number 4 multiplied by 3 is 12\n",
+ "The number 5 multiplied by 3 is 15\n",
+ "The number 6 multiplied by 3 is 18\n",
+ "The number 7 multiplied by 3 is 21\n",
+ "The number 8 multiplied by 3 is 24\n",
+ "The number 9 multiplied by 3 is 27\n",
+ "The number 10 multiplied by 3 is 30\n",
+ "The number 11 multiplied by 3 is 33\n",
+ "The number 12 multiplied by 3 is 36\n",
+ "The number 13 multiplied by 3 is 39\n",
+ "The number 14 multiplied by 3 is 42\n",
+ "The number 15 multiplied by 3 is 45\n",
+ "The number 16 multiplied by 3 is 48\n",
+ "The number 17 multiplied by 3 is 51\n",
+ "The number 18 multiplied by 3 is 54\n",
+ "The number 19 multiplied by 3 is 57\n",
+ "The number 20 multiplied by 3 is 60\n",
+ "The number 21 multiplied by 3 is 63\n",
+ "The number 22 multiplied by 3 is 66\n",
+ "The number 23 multiplied by 3 is 69\n",
+ "The number 24 multiplied by 3 is 72\n",
+ "The number 25 multiplied by 3 is 75\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C18PASS1, Page number:381"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def moon(weight): \n",
+ " weight/=6 \n",
+ " print \"You weigh only \",weight,\"pounds on the moon !\"\n",
+ "def main(): \n",
+ " weight=input(\"How many pounds do you weigh? \")\n",
+ " moon(weight) #call the moon() function and pass weight\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many pounds do you weigh? 120\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You weigh only 20 pounds on the moon !\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C18PASS3, Page number:383"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " Igrade=raw_input(\"What letter grade do you want?\")\n",
+ " average=input(\"What is your current test average\")\n",
+ " tests=input(\"How many tests do you have left?\")\n",
+ " check_grade(Igrade,average,tests) #// Calls function and passes three variables by value\n",
+ "def check_grade(Igrade,average,tests):\n",
+ " if tests==0:\n",
+ " print \"You will get your current grade of \",Igrade\n",
+ " else:\n",
+ " if tests==1:\n",
+ " print \"You still have time to bring up your average of\",'%.1f' %average,\"up . Study hard !\"\n",
+ " else :\n",
+ " print \"Relax. You still have plenty of time.\" \n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What letter grade do you want?A\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your current test average1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many tests do you have left?3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Relax. You still have plenty of time.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C19AVG, Page number:398"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def calc_av(num1,num2,num3):\n",
+ " local_avg=(num1+num2+num3) / 3 #Holds the average for these numbers\n",
+ " return local_avg\n",
+ "print \"please type three numbers (such as 23 54 85) \"\n",
+ "num1=input()\n",
+ "num2=input()\n",
+ "num3=input()\n",
+ "avg=calc_av(num1,num2,num3) #call function and pass the numbers\n",
+ "print \"\\n\\nThe average is \",avg #Print the return value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "please type three numbers (such as 23 54 85) \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "30\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "40\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "The average is 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C19DOUB, Page number:401"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def doub(number):\n",
+ " d_num=number*2 #Doubles the number.\n",
+ " return d_num #Returns the result.\n",
+ "number=input(\"What number do you want doubled? \")\n",
+ "d_number= doub(number) #Assigns return value.\n",
+ "print number,\" doubled is \",d_number"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What number do you want doubled? 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5 doubled is 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C19SUMD, Page number:403"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def sums(num):\n",
+ " sumd=0\n",
+ " if num<=0:\n",
+ " sumd=num\n",
+ " else:\n",
+ " for ctr in range(1,num+1,1):\n",
+ " sumd=sumd+ctr\n",
+ " return sumd\n",
+ "num=input(\"Please type a number: \")\n",
+ "sumd= sums(num)\n",
+ "print \"The sum of the digits is \" , sumd"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please type a number: 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sum of the digits is 21\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C19MINMX, Page number:404"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def maximum(num1,num2): \n",
+ " if num1>num2:\n",
+ " maxi=num1\n",
+ " else:\n",
+ " maxi=num2\n",
+ " return maxi\n",
+ "def minimum(num1,num2):\n",
+ " if num1>num2:\n",
+ " mini=num2\n",
+ " else:\n",
+ " mini=num1\n",
+ " return mini\n",
+ "print \"Please type two numbers ( such as 46 75 ) \"\n",
+ "num1 = input()\n",
+ "num2 = input()\n",
+ "maxi=maximum(num1,num2) #Assign the return value of each function to variables\n",
+ "mini=minimum(num1,num2) \n",
+ "print \"The minimum number is \",mini\n",
+ "print \"The maximum number is \", maxi"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please type two numbers ( such as 46 75 ) \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "72\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "55\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum number is 55\n",
+ "The maximum number is 72\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C19PRO1, Page number:409"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "tax_rate=0.07 #Assume seven percent tax rate\n",
+ "total_sale=input(\"What is the sale amount? \")\n",
+ "total_sale+=tax_rate*total_sale\n",
+ "print \"The total sale is \",'%.2f' %total_sale"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the sale amount? 4000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The total sale is 4280.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C19ASC, Page number:410"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def ascii(num):\n",
+ " asc_char=chr(num) #Type cast to a character\n",
+ " return asc_char\n",
+ "num=input(\"Enter an ASCII number? \")\n",
+ "asc_char=ascii(num) #Number is passed to the function ascii()\n",
+ "print \"The ASCII character for \",num,\"is \",asc_char"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an ASCII number? 67\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The ASCII character for 67 is C\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C19NPAY, Page number:411"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def netpayfun(hours,rate,taxrate):\n",
+ " gross_pay=hours*rate\n",
+ " taxes=taxrate*gross_pay\n",
+ " net_pay=gross_pay-taxes\n",
+ " return net_pay\n",
+ "net_pay=netpayfun(40.0,3.50,0.20)\n",
+ "print \"The pay for 40 hours at $3.50/hr., and a 20% tax rate is $ \",net_pay\n",
+ "net_pay=netpayfun(50.0,10.00,0.30)\n",
+ "print \"The pay for 40 hours at $10.00/hr., and a 30% tax rate is $ \",net_pay\n",
+ "net_pay=netpayfun(10.0,5.00,0.10)\n",
+ "print \"The pay for 40 hours at $5.00/hr., and a 10% tax rate is $ \",net_pay"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The pay for 40 hours at $3.50/hr., and a 20% tax rate is $ 112.0\n",
+ "The pay for 40 hours at $10.00/hr., and a 30% tax rate is $ 350.0\n",
+ "The pay for 40 hours at $5.00/hr., and a 10% tax rate is $ 45.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C20OVF1, Page number:423"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i=-15\n",
+ "x=-64.53\n",
+ "ians=abs(i) #abs() function is a built in function that returns a positive value \n",
+ "print \"Integer absolute value of -15 is \",ians\n",
+ "fans=abs(x)\n",
+ "print \"Float absolute value of -64.53 is \",'%.2f' %fans"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Integer absolute value of -15 is 15\n",
+ "Float absolute value of -64.53 is 64.53\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C20OVF2, Page number:424"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#function definition\n",
+ "def output(x):\n",
+ " if isinstance(x,int):\n",
+ " print x\n",
+ " else:\n",
+ " if isinstance(x,float):\n",
+ " print '%.2f' %x\n",
+ " else:\n",
+ " print x\n",
+ "#Variable Decleration\n",
+ "name=\"C++ By Example makes C++ easy!\"\n",
+ "Ivalue=2543\n",
+ "fvalue=39.4321\n",
+ "#calling function\n",
+ "output(name)\n",
+ "output(Ivalue)\n",
+ "output(fvalue)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C++ By Example makes C++ easy!\n",
+ "2543\n",
+ "39.43\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_By_Example_by_Greg__M._Perry/Chapter5_2.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter5_2.ipynb
new file mode 100755
index 00000000..92b07a7b
--- /dev/null
+++ b/C++_By_Example_by_Greg__M._Perry/Chapter5_2.ipynb
@@ -0,0 +1,184 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1663500e8fbe5ad2cc16ca34f15e5b3a438d37780443ea138d094544e9484c86"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5: Character Input/Output and String Functions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C22INI, Page number:452"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Get input\n",
+ "print \"What is your first initial?\"\n",
+ "initial=raw_input()\n",
+ "\n",
+ "#Check if it is an alphabet\n",
+ "while not initial.isalpha():\n",
+ " print \"That was not a valid initial!\"\n",
+ " print \"What is your first initial?\"\n",
+ " initial=raw_input()\n",
+ "print \"Thanks\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your first initial?\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "p\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Thanks\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C22GB, Page number:454"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Get input\n",
+ "#ans=raw_input(\"Are you a girl or a boy (G/B)? \") \n",
+ "ans=\"b\"\n",
+ "#convert answer to uppercase\n",
+ "ans=ans.upper() \n",
+ "if ans=='G':\n",
+ " print \"You look pretty today!\\n\"\n",
+ "else:\n",
+ " if ans=='B':\n",
+ " print \"You look handsome today!\\n\"\n",
+ " else:\n",
+ " print \"Your answer makes no sense!\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You look handsome today!\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C22GPS1, Page number:459"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#get book title\n",
+ "#book=raw_input(\"What is the book title? \") \n",
+ "book=\"Mary and Her Lambs\"\n",
+ "#print book title\n",
+ "print book \n",
+ "print \"Thanks for the book!\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mary and Her Lambs\n",
+ "Thanks for the book!\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C22ABS, Page number:463"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Get input\n",
+ "#age1=input(\"\\nWhat is the first child's age? \")\n",
+ "#age2=input(\"\\nWhat is the second child's age? \")\n",
+ "age1=10\n",
+ "age2=12\n",
+ "diff=age1-age2 \n",
+ "# abs() function determines absolute value\n",
+ "diff=abs(diff) \n",
+ "#Result\n",
+ "print \"\\nThey are \",diff,\" years apart.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "They are 2 years apart.\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_By_Example_by_Greg__M._Perry/Chapter6_2.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter6_2.ipynb
new file mode 100755
index 00000000..0905d8e9
--- /dev/null
+++ b/C++_By_Example_by_Greg__M._Perry/Chapter6_2.ipynb
@@ -0,0 +1,1457 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d11a5d1aed8c464716c568d4d8be1f78c4ea2b8f130a5adc4fa9ba5c3703fc04"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Arrays and pointers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C23ARA1, Page number:482"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s_name=\"Tri Star University\"\n",
+ "scores = [88.7,90.4,76.0,97.0,100.0,86.7] #integer array\n",
+ "average=0.0\n",
+ "for ctr in range(0,6,1): #computes total of scores\n",
+ " average+=scores[ctr]\n",
+ "average/=float(6) #computes the average\n",
+ "print \"At \",s_name,\", your class average is \",'%.2f' %average,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "At Tri Star University , your class average is 89.80 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C23ARA2, Page number:483"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def pr_scores(scores):\n",
+ " print \"Here are your scores:\\n\"\n",
+ " for ctr in range(0,6,1):\n",
+ " print '%.2f' %scores[ctr],\"\\n\" \n",
+ "s_name=\"Tri Star University\"\n",
+ "scores = [88.7,90.4,76.0,97.0,100.0,86.7] #integer array\n",
+ "average=0.0\n",
+ "pr_scores(scores) #Function call to print scores\n",
+ "for ctr in range(0,6,1): #computes total of scores\n",
+ " average+=scores[ctr]\n",
+ "average/=float(6) #computes the average\n",
+ "print \"At \",s_name,\", your class average is \",'%.2f' %average,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Here are your scores:\n",
+ "\n",
+ "88.70 \n",
+ "\n",
+ "90.40 \n",
+ "\n",
+ "76.00 \n",
+ "\n",
+ "97.00 \n",
+ "\n",
+ "100.00 \n",
+ "\n",
+ "86.70 \n",
+ "\n",
+ "At Tri Star University , your class average is 89.80 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C23ARA3, Page number:485"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "CLASS_NUM=6\n",
+ "def pr_scores(scores): #Function definition \n",
+ " print \"Here are your scores:\\n\"\n",
+ " for ctr in range(0,CLASS_NUM,1):\n",
+ " print '%.2f' %scores[ctr],\"\\n\" \n",
+ "s_name=\"Tri Star University\"\n",
+ "scores = [88.7,90.4,76.0,97.0,100.0,86.7] #Integer array\n",
+ "average=0.0\n",
+ "pr_scores(scores) #Function call to print scores\n",
+ "for ctr in range(0,CLASS_NUM,1): #Computes total of scores\n",
+ " average+=scores[ctr]\n",
+ "average/=float(6) #Computes the average\n",
+ "print \"At \",s_name,\", your class average is \",'%.2f' %average,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Here are your scores:\n",
+ "\n",
+ "88.70 \n",
+ "\n",
+ "90.40 \n",
+ "\n",
+ "76.00 \n",
+ "\n",
+ "97.00 \n",
+ "\n",
+ "100.00 \n",
+ "\n",
+ "86.70 \n",
+ "\n",
+ "At Tri Star University , your class average is 89.80 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C23ARA4, Page number:487"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NUM_TEMPS=10\n",
+ "temps=[]\n",
+ "#Adding values into temps variable\n",
+ "temps.append(78.6)\n",
+ "temps.append(82.1)\n",
+ "temps.append(79.5)\n",
+ "temps.append(75.0)\n",
+ "temps.append(75.4)\n",
+ "temps.append(71.8)\n",
+ "temps.append(73.3)\n",
+ "temps.append(69.5)\n",
+ "temps.append(74.1)\n",
+ "temps.append(75.7)\n",
+ "#Print the temperatures\n",
+ "print \"Daily temperatures for the last \",NUM_TEMPS,\"days:\\n\"\n",
+ "for ctr in range(0,NUM_TEMPS,1):\n",
+ " print '%.2f' %temps[ctr],\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Daily temperatures for the last 10 days:\n",
+ "\n",
+ "78.60 \n",
+ "\n",
+ "82.10 \n",
+ "\n",
+ "79.50 \n",
+ "\n",
+ "75.00 \n",
+ "\n",
+ "75.40 \n",
+ "\n",
+ "71.80 \n",
+ "\n",
+ "73.30 \n",
+ "\n",
+ "69.50 \n",
+ "\n",
+ "74.10 \n",
+ "\n",
+ "75.70 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C23TOT, Page number:488"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NUM=8\n",
+ "nums=[]\n",
+ "total=0\n",
+ "for ctr in range(0,NUM,1):\n",
+ " print \"Please enter the next number...\",\n",
+ " nums.append(input())\n",
+ " total+=nums[ctr]\n",
+ "#Prints the sum of eight values \n",
+ "print \"The total of the numbers is \",total,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Please enter the next number..."
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Please enter the next number..."
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Please enter the next number..."
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Please enter the next number..."
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Please enter the next number..."
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Please enter the next number..."
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Please enter the next number..."
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Please enter the next number..."
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The total of the numbers is 36 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C23SAL, Page number:489"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NUM=12\n",
+ "sales=[] \n",
+ "print \"Please enter the twelve monthly sales values\\n\"\n",
+ "#Fill the array with input values entered by the user\n",
+ "for ctr in range(0,NUM,1):\n",
+ " print \"What are sales for month number \",ctr+1,\"?\\n\"\n",
+ " sales.append(input())\n",
+ "#for ctr in range(0,25,1):\n",
+ "# print \"\\n\" #Clears the screen\n",
+ "print \"\\n\\n*** Sales Printing Program ***\\n\"\n",
+ "print \"Prints any sales from the last \",NUM,\" months\\n\"\n",
+ "ans='Y'\n",
+ "while ans=='Y':\n",
+ " print \"For what month (1-\",NUM,\") do you want to see a sales value? \" \n",
+ " req_month=input()\n",
+ " print \"\\nMonth \",req_month,\"'s sales are\",'%.2f' %sales[req_month-1]\n",
+ " print \"\\nDo you want to see another (Y/N)? \"\n",
+ " ans=raw_input().upper()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter the twelve monthly sales values\n",
+ "\n",
+ "What are sales for month number 1 ?\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "363.25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What are sales for month number 2 ?\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "433.22\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What are sales for month number 3 ?\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "652.36\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What are sales for month number 4 ?\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "445.52\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What are sales for month number 5 ?\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "123.45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What are sales for month number 6 ?\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "780.2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What are sales for month number 7 ?\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "125.36\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What are sales for month number 8 ?\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "425.15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What are sales for month number 9 ?\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "325.96\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What are sales for month number 10 ?\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "109.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What are sales for month number 11 ?\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "123.65\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What are sales for month number 12 ?\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "253.84\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "*** Sales Printing Program ***\n",
+ "\n",
+ "Prints any sales from the last 12 months\n",
+ "\n",
+ "For what month (1- 12 ) do you want to see a sales value? \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Month 2 's sales are 433.22\n",
+ "\n",
+ "Do you want to see another (Y/N)? \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For what month (1- 12 ) do you want to see a sales value? \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Month 5 's sales are 123.45\n",
+ "\n",
+ "Do you want to see another (Y/N)? \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C24HIGH, Page number:496"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "SIZE=15 #Maximum size of array\n",
+ "ara=[None]*SIZE #Empty Array declaration with maximum size\n",
+ "ara=[5,2,7,8,36,4,2,86,11,43,22,12,45,6,85]\n",
+ "high_val=ara[0] #initialize wit first array element\n",
+ "for ctr in range(1,SIZE,1):\n",
+ " if ara[ctr]>high_val: #Compares with rest of the elements in the array \n",
+ " high_val=ara[ctr] #Stores higher value in high_val\n",
+ "print \"The highest number in the list is \",high_val,\".\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The highest number in the list is 86 .\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C24HILO, Page number:498"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Maximum size of array\n",
+ "SIZE=15 \n",
+ "#Initialize empty array\n",
+ "ara=[None]*SIZE \n",
+ "#Fill array with random numbers from 0 to 99\n",
+ "import random\n",
+ "for ctr in range(0,SIZE,1):\n",
+ " ara[ctr]=random.randint(0,99) %100 \n",
+ "print \"Here are the \",SIZE,\"random numbers:\\n\" \n",
+ "for ctr in range(0,SIZE,1):\n",
+ " print ara[ctr],\"\\n\" #Prints the array \n",
+ "print \"\\n\\n\"\n",
+ "#Initialize first element to both high_val and low_val\n",
+ "high_val=ara[0] \n",
+ "low_val=ara[0]\n",
+ "for ctr in range(1,SIZE,1):\n",
+ " if ara[ctr]>high_val: #Compares with rest of the elements in the array\n",
+ " high_val=ara[ctr] #Stores higher valure in high_val\n",
+ " if ara[ctr]<low_val:\n",
+ " low_val=ara[ctr] #Stores lower valure in low_val\n",
+ "print \"The highest number in the list is \",high_val,\"\\n\"\n",
+ "print \"The lowest number in the list is \",low_val,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Here are the 15 random numbers:\n",
+ "\n",
+ "81 \n",
+ "\n",
+ "96 \n",
+ "\n",
+ "31 \n",
+ "\n",
+ "1 \n",
+ "\n",
+ "34 \n",
+ "\n",
+ "53 \n",
+ "\n",
+ "70 \n",
+ "\n",
+ "9 \n",
+ "\n",
+ "23 \n",
+ "\n",
+ "89 \n",
+ "\n",
+ "51 \n",
+ "\n",
+ "73 \n",
+ "\n",
+ "53 \n",
+ "\n",
+ "85 \n",
+ "\n",
+ "79 \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "The highest number in the list is 96 \n",
+ "\n",
+ "The lowest number in the list is 1 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C24SERCH, Page number:499"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX=100\n",
+ "def fill_parts(parts): #Function assigns first five parts to array for testing\n",
+ " parts[0]=12345\n",
+ " parts[1]=24724\n",
+ " parts[2]=54154\n",
+ " parts[3]=73496\n",
+ " parts[4]=83925\n",
+ " return parts\n",
+ "parts=[None]*MAX\n",
+ "num_parts=5 #Beginning inventory count\n",
+ "fill_parts(parts) #Fills the first five elements\n",
+ "search_part=0\n",
+ "while search_part != -9999:\n",
+ " print \"\\n\\nPlease type a part number...(-9999 ends program)\",\n",
+ " search_part=input()\n",
+ " if search_part==-9999:\n",
+ " break #Exits the loop if user wants \n",
+ " for ctr in range(0,num_parts,1): #Scans array to see whether part is in inventory\n",
+ " if search_part==parts[ctr]:\n",
+ " print \"\\nPart \",search_part,\"is already in inventory\"\n",
+ " break\n",
+ " else:\n",
+ " if ctr==num_parts-1:\n",
+ " parts[num_parts]=search_part #If not then it is added to end of the array\n",
+ " num_parts+=1\n",
+ " print search_part,\"was added to inventory\\n\"\n",
+ " break "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Please type a part number...(-9999 ends program)"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "34234\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 34234 was added to inventory\n",
+ "\n",
+ "\n",
+ "\n",
+ "Please type a part number...(-9999 ends program)"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "83925\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Part 83925 is already in inventory\n",
+ "\n",
+ "\n",
+ "Please type a part number...(-9999 ends program)"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "52786\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 52786 was added to inventory\n",
+ "\n",
+ "\n",
+ "\n",
+ "Please type a part number...(-9999 ends program)"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-9999\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C24SORT1, Page number:504"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX=10\n",
+ "#Fill array with random numbers from 0 to 99\n",
+ "def fill_array(ara):\n",
+ " import random\n",
+ " for ctr in range(0,MAX,1):\n",
+ " ara[ctr]=random.randint(0,99) %100\n",
+ "#Prints the array ara[]\n",
+ "def print_array(ara):\n",
+ " for ctr in range(0,MAX,1):\n",
+ " print ara[ctr],\"\\n\"\n",
+ "#Sorts the array\n",
+ "def sort_array(ara):\n",
+ " for ctr1 in range(0,MAX-1,1):\n",
+ " for ctr2 in range(ctr1+1,MAX,1):\n",
+ " if ara[ctr1]>ara[ctr2]: #Swap if this part is not in order\n",
+ " temp=ara[ctr1] #Temporary variable to swap\n",
+ " ara[ctr1]=ara[ctr2]\n",
+ " ara[ctr2]=temp\n",
+ "ara=[None]*MAX\n",
+ "fill_array(ara)\n",
+ "print \"Here are the unsorted numbers:\\n\"\n",
+ "print_array(ara) #Prints the unsorted array\n",
+ "sort_array(ara) #Sorts the array in ascending order\n",
+ "print \"\\n\\nHere are the sorted numbers:\\n\"\n",
+ "print_array(ara) #Prints the sorted array"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Here are the unsorted numbers:\n",
+ "\n",
+ "68 \n",
+ "\n",
+ "41 \n",
+ "\n",
+ "53 \n",
+ "\n",
+ "40 \n",
+ "\n",
+ "69 \n",
+ "\n",
+ "65 \n",
+ "\n",
+ "64 \n",
+ "\n",
+ "48 \n",
+ "\n",
+ "87 \n",
+ "\n",
+ "18 \n",
+ "\n",
+ "\n",
+ "\n",
+ "Here are the sorted numbers:\n",
+ "\n",
+ "18 \n",
+ "\n",
+ "40 \n",
+ "\n",
+ "41 \n",
+ "\n",
+ "48 \n",
+ "\n",
+ "53 \n",
+ "\n",
+ "64 \n",
+ "\n",
+ "65 \n",
+ "\n",
+ "68 \n",
+ "\n",
+ "69 \n",
+ "\n",
+ "87 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C24SORT2, Page number:506"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX=10\n",
+ "#Fill array with random numbers from 0 to 99\n",
+ "def fill_array(ara):\n",
+ " import random\n",
+ " for ctr in range(0,MAX,1):\n",
+ " ara[ctr]=random.randint(0,99) %100\n",
+ "#Prints the array ara[]\n",
+ "def print_array(ara):\n",
+ " for ctr in range(0,MAX,1):\n",
+ " print ara[ctr],\"\\n\"\n",
+ "#Sorts the array\n",
+ "def sort_array(ara):\n",
+ " for ctr1 in range(0,MAX-1,1):\n",
+ " for ctr2 in range(ctr1+1,MAX,1):\n",
+ " if ara[ctr1]<ara[ctr2]: #Swap if this part is not in order\n",
+ " temp=ara[ctr1] #Temporary variable to swap\n",
+ " ara[ctr1]=ara[ctr2]\n",
+ " ara[ctr2]=temp\n",
+ "\n",
+ "ara=[None]*MAX\n",
+ "fill_array(ara)\n",
+ "print \"Here are the unsorted numbers:\\n\"\n",
+ "print_array(ara) #Prints the unsorted array\n",
+ "sort_array(ara) #Sorts the array in descending order\n",
+ "print \"\\n\\nHere are the sorted numbers:\\n\"\n",
+ "print_array(ara) #Prints the newly sorted array"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Here are the unsorted numbers:\n",
+ "\n",
+ "40 \n",
+ "\n",
+ "22 \n",
+ "\n",
+ "4 \n",
+ "\n",
+ "78 \n",
+ "\n",
+ "20 \n",
+ "\n",
+ "45 \n",
+ "\n",
+ "60 \n",
+ "\n",
+ "93 \n",
+ "\n",
+ "85 \n",
+ "\n",
+ "22 \n",
+ "\n",
+ "\n",
+ "\n",
+ "Here are the sorted numbers:\n",
+ "\n",
+ "93 \n",
+ "\n",
+ "85 \n",
+ "\n",
+ "78 \n",
+ "\n",
+ "60 \n",
+ "\n",
+ "45 \n",
+ "\n",
+ "40 \n",
+ "\n",
+ "22 \n",
+ "\n",
+ "22 \n",
+ "\n",
+ "20 \n",
+ "\n",
+ "4 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C25DISK1, Page number:533"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Two dimensional array declaration\n",
+ "disks= [[[] for ni in range(4)] for mi in range(2)]\n",
+ "#Assign values to the 2Darray\n",
+ "disks[0][0]=2.39\n",
+ "disks[0][1]=2.75\n",
+ "disks[0][2]=3.29\n",
+ "disks[0][3]=3.59\n",
+ "disks[1][0]=1.75\n",
+ "disks[1][1]=2.19\n",
+ "disks[1][2]=2.69\n",
+ "disks[1][3]=2.95\n",
+ "#Print the values in the array\n",
+ "for row in range(0,2,1):\n",
+ " for col in range(0,4,1):\n",
+ " print \"$\",'%.2f'%disks[row][col],\"\\n\","
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "$ 2.39 \n",
+ "$ 2.75 \n",
+ "$ 3.29 \n",
+ "$ 3.59 \n",
+ "$ 1.75 \n",
+ "$ 2.19 \n",
+ "$ 2.69 \n",
+ "$ 2.95 \n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C25DISK2, Page number:534"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Two dimensional array declaration\n",
+ "disks= [[[] for ni in range(4)] for mi in range(2)]\n",
+ "#Assign values to the 2Darray\n",
+ "disks[0][0]=2.39\n",
+ "disks[0][1]=2.75\n",
+ "disks[0][2]=3.29\n",
+ "disks[0][3]=3.59\n",
+ "disks[1][0]=1.75\n",
+ "disks[1][1]=2.19\n",
+ "disks[1][2]=2.69\n",
+ "disks[1][3]=2.95\n",
+ "#Print the values in the array\n",
+ "for row in range(0,2,1):\n",
+ " for col in range(0,4,1):\n",
+ " print \"$\",'%.2f'%disks[row][col],\"\\t\",\n",
+ " print \"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "$ 2.39 \t$ 2.75 \t$ 3.29 \t$ 3.59 \t\n",
+ "\n",
+ "$ 1.75 \t$ 2.19 \t$ 2.69 \t$ 2.95 \t\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C25DISK3, Page number:535"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Two dimensional array declaration\n",
+ "disks= [[[] for ni in range(4)] for mi in range(2)]\n",
+ "#Assign values to the 2Darray\n",
+ "disks[0][0]=2.39\n",
+ "disks[0][1]=2.75\n",
+ "disks[0][2]=3.29\n",
+ "disks[0][3]=3.59\n",
+ "disks[1][0]=1.75\n",
+ "disks[1][1]=2.19\n",
+ "disks[1][2]=2.69\n",
+ "disks[1][3]=2.95\n",
+ "#Print the column titles.\n",
+ "print \"\\tSingle-sided\\tDouble-sided\\tSingle-sided\\tDouble-sided\"\n",
+ "print \"\\tDouble-density\\tDouble-density\\tHigh-density\\tHigh-density\"\n",
+ "#Print the prices\n",
+ "for row in range(0,2,1):\n",
+ " if row==0:\n",
+ " print \"3-1/2\\\"\\t\",\n",
+ " else:\n",
+ " print \"5-1/2\\\"\\t\",\n",
+ " for col in range(0,4,1):\n",
+ " print \"$\",'%.2f'%disks[row][col],\"\\t\\t\",\n",
+ " print \"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tSingle-sided\tDouble-sided\tSingle-sided\tDouble-sided\n",
+ "\tDouble-density\tDouble-density\tHigh-density\tHigh-density\n",
+ "3-1/2\"\t$ 2.39 \t\t$ 2.75 \t\t$ 3.29 \t\t$ 3.59 \t\t\n",
+ "\n",
+ "5-1/2\"\t$ 1.75 \t\t$ 2.19 \t\t$ 2.69 \t\t$ 2.95 \t\t\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C26SWAP, Page number:551"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Function definition\n",
+ "def swap_them(num1,num2):\n",
+ " num1,num2=num2,num1\n",
+ " return num1,num2\n",
+ "#Variable declaration\n",
+ "i=10\n",
+ "j=20\n",
+ "print \"\\nBefore swap, i is \",i,\"and j is \",j,\"\\n\"\n",
+ "i,j=swap_them(i,j) # Function call\n",
+ "print \"\\nAfter swap, i is \",i,\"and j is \",j,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Before swap, i is 10 and j is 20 \n",
+ "\n",
+ "\n",
+ "After swap, i is 20 and j is 10 \n",
+ "\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C27CP1, Page number:565"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable Declaration\n",
+ "c=\"Bettye Lou Horn\"\n",
+ "#Result\n",
+ "print \"My sister's name is \",c,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "My sister's name is Bettye Lou Horn \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C27CP2, Page number:566"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable Declaration\n",
+ "c=\"Bettye Lou Horn\"\n",
+ "print \"My sister's maiden was \",c,\"\\n\"\n",
+ "#Assigns new string to c\n",
+ "c=\"Bettye Lou Henderson\" \n",
+ "#Result\n",
+ "print \"My sister's married name is \",c,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "My sister's maiden was Bettye Lou Horn \n",
+ "\n",
+ "My sister's married name is Bettye Lou Henderson \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C27CP3, Page number:566"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable Declaration\n",
+ "c=\"Bettye Lou Horn\"\n",
+ "print \"My sister's maiden was \",c,\"\\n\"\n",
+ "c+=str(11) #makes c points to the last name\n",
+ "c=\"Henderson\" #Assigns new string to c\n",
+ "#Result\n",
+ "print \"My sister's married name is \",c,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "My sister's maiden was Bettye Lou Horn \n",
+ "\n",
+ "My sister's married name is Henderson \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C27PTST1, Page number:576"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Array declaration\n",
+ "name=[\"George\",\"Michelle\",\"Joe\",\"Marcus\",\"Stephanie\"]\n",
+ "#Result\n",
+ "for ctr in range(0,5,1):\n",
+ " print \"String #\",(ctr+1),\"is\",name[ctr],\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "String # 1 is George \n",
+ "\n",
+ "String # 2 is Michelle \n",
+ "\n",
+ "String # 3 is Joe \n",
+ "\n",
+ "String # 4 is Marcus \n",
+ "\n",
+ "String # 5 is Stephanie \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_By_Example_by_Greg__M._Perry/Chapter7_2.ipynb b/C++_By_Example_by_Greg__M._Perry/Chapter7_2.ipynb
new file mode 100755
index 00000000..4f861159
--- /dev/null
+++ b/C++_By_Example_by_Greg__M._Perry/Chapter7_2.ipynb
@@ -0,0 +1,1046 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:75d9b3e202f1b623d68374a7f029f2643cd152423fdceca49ae347a494dcf861"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Structures and File Input/Output"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C28ST1 :Page 592"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from collections import namedtuple\n",
+ "#Structure declaration and definition\n",
+ "struct_cd_collection = namedtuple(\"struct_cd_collection\", \"title artist num_songs price date_purch\")\n",
+ "#Structure for Cd Collection\n",
+ "cd1 = struct_cd_collection(\"Red Moon Men\", \"Sam and the Sneeds\", 12,11.95,\"02/13/92\")\n",
+ "\n",
+ "#Result\n",
+ "print \"Here is the CD information :\\n\\n\"\n",
+ "print \"Title:\",cd1.title,\"\\n\"\n",
+ "print \"Artist:\",cd1.artist,\"\\n\"\n",
+ "print \"Songs:\",cd1.num_songs,\"\\n\"\n",
+ "print \"Price:\",cd1.price,\"\\n\"\n",
+ "print \"Date purchased:\",cd1.date_purch,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Here is the CD information :\n",
+ "\n",
+ "\n",
+ "Title: Red Moon Men \n",
+ "\n",
+ "Artist: Sam and the Sneeds \n",
+ "\n",
+ "Songs: 12 \n",
+ "\n",
+ "Price: 11.95 \n",
+ "\n",
+ "Date purchased: 02/13/92 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C28ST2 :Page 593"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from collections import namedtuple\n",
+ "\n",
+ "#Structure initial declaration\n",
+ "students = namedtuple(\"students\", \"name age average\")\n",
+ "#Get data\n",
+ "print \"What is first student's name? \",\n",
+ "x=raw_input()\n",
+ "print \"What is the first student's age? \",\n",
+ "y=input()\n",
+ "print \"What is the first student's average ? \",\n",
+ "z=input()\n",
+ "#Assign data to the structure variable\n",
+ "student1=students(x,y,z)\n",
+ "print \"\\n\"\n",
+ "#Get data\n",
+ "print \"What is second student's name? \",\n",
+ "x=raw_input()\n",
+ "print \"What is the second student's age? \",\n",
+ "y=input()\n",
+ "print \"What is the second student's average ? \",\n",
+ "z=input()\n",
+ "#Assign data to the structure variable\n",
+ "student2=students(x,y,z)\n",
+ "#Result\n",
+ "print \"\\n\\nHere is the student information you entered:\\n\\n\"\n",
+ "print \"Student #1:\\n\"\n",
+ "print \"Name: \",student1.name,\"\\n\"\n",
+ "print \"Age: \",student1.age,\"\\n\"\n",
+ "print \"Average: \",'%.2f'%student1.average,\"\\n\"\n",
+ "print \"Student #2:\\n\"\n",
+ "print \"Name: \",student2.name,\"\\n\"\n",
+ "print \"Age: \",student2.age,\"\\n\"\n",
+ "print \"Average: \",'%.2f'%student2.average,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is first student's name? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Larry\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " What is the first student's age? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "14\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " What is the first student's average ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "87.67\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "What is second student's name? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Judy\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " What is the second student's age? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " What is the second student's average ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "95.38\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Here is the student information you entered:\n",
+ "\n",
+ "\n",
+ "Student #1:\n",
+ "\n",
+ "Name: Larry \n",
+ "\n",
+ "Age: 14 \n",
+ "\n",
+ "Average: 87.67 \n",
+ "\n",
+ "Student #2:\n",
+ "\n",
+ "Name: Judy \n",
+ "\n",
+ "Age: 15 \n",
+ "\n",
+ "Average: 95.38 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C28ST3 :Page 596"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Function definitions\n",
+ "def fill_structs(student_var):\n",
+ " #Get student data\n",
+ " print \"What is student's name? \",\n",
+ " x=raw_input()\n",
+ " print \"What is the student's age? \",\n",
+ " y=input()\n",
+ " print \"What is the student's average ? \",\n",
+ " z=input()\n",
+ " student_var=students(x,y,z)\n",
+ " return student_var\n",
+ "def pr_students(student_var):\n",
+ " print \"Name: \",student_var.name,\"\\n\",\n",
+ " print \"Age: \",student_var.age,\"\\n\",\n",
+ " print \"Average: \",student_var.average,\"\\n\",\n",
+ "#Structure declaration\n",
+ "from collections import namedtuple\n",
+ "students=namedtuple(\"students\",\"name age average\")\n",
+ "#Structure variable declaration\n",
+ "student1=students(\" \",0,0.0)\n",
+ "student2=students(\" \",0,0.0)\n",
+ "#Stucture variable is passed as copy to the function\n",
+ "student1=fill_structs(student1)\n",
+ "student2=fill_structs(student2)\n",
+ "#Result\n",
+ "print \"\\n\\nHere is the student information you entered:\\n\\n\"\n",
+ "pr_students(student1)\n",
+ "pr_students(student2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is student's name? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Larry\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " What is the student's age? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "14\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " What is the student's average ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "87.67\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " What is student's name? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Judy\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " What is the student's age? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " What is the student's average ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "97.38\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Here is the student information you entered:\n",
+ "\n",
+ "\n",
+ "Name: Larry \n",
+ "Age: 14 \n",
+ "Average: 87.67 \n",
+ "Name: Judy \n",
+ "Age: 15 \n",
+ "Average: 97.38 \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C28CUST :Page 598"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Structure definition\n",
+ "from collections import namedtuple\n",
+ "customer_rec=namedtuple(\"customer_rec\",\"cust_name balance dist_rate\")\n",
+ "customer=customer_rec(\"Steve Thompson\",431.23,.25)\n",
+ "print \"Before the update\",customer.cust_name,\" has a balance of $\",'%.2f' %customer.balance,\"\\n\",\n",
+ "#Update the balance\n",
+ "customer_rec.balance=customer.balance*(1.0-customer.dist_rate)\n",
+ "#Result\n",
+ "print \"After the update\",customer.cust_name,\" has a balance of $\",'%.2f' %customer.balance,\"\\n\","
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Before the update Steve Thompson has a balance of $ 431.23 \n",
+ "After the update Steve Thompson has a balance of $ 323.42 \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C28STCPY :Page 599"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Structure declaration\n",
+ "from collections import namedtuple\n",
+ "students=namedtuple(\"students\",\"st_name grade age average\")\n",
+ "#Structure variable declaration\n",
+ "std1=students(\"Joe Brown\",'A',13,91.4)\n",
+ "std2=students(\" \",\" \",0,0.0)\n",
+ "std3=students(\" \",\" \",0,0.0)\n",
+ "#Assigning one structure variable to another.\n",
+ "std2=std1\n",
+ "std3=std1\n",
+ "#Result\n",
+ "print \"The contents of std2:\\n\",\n",
+ "print std2.st_name,\", \",std2.grade,\", \",std2.age,\", \",'%.1f' %std2.average,\"\\n\\n\"\n",
+ "print \"The contents of std3:\\n\",\n",
+ "print std3.st_name,\", \",std3.grade,\", \",std3.age,\", \",'%.1f' %std3.average,\"\\n\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The contents of std2:\n",
+ "Joe Brown , A , 13 , 91.4 \n",
+ "\n",
+ "\n",
+ "The contents of std3:\n",
+ "Joe Brown , A , 13 , 91.4 \n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C30WR1 :Page 635"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#open a new file in write mode\n",
+ "fp = open (\"NAMES.txt\", \"w\" ) \n",
+ "fp.writelines(\"Michel Langston\\n\")\n",
+ "fp.writelines(\"Sally Redding\\n\")\n",
+ "fp.writelines(\"Jane Kirk\\n\")\n",
+ "fp.writelines(\"Stacy Wikert\\n\")\n",
+ "fp.writelines(\"Joe Hiquet\\n\")\n",
+ "#Close file\n",
+ "fp.close()\n",
+ "#Result\n",
+ "print \"names were written into the file\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "names were written into the file\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C30WR2 :Page 636"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Creates a file in write mode\n",
+ "fp = open ( \"NUMS.1.txt\", \"w\" ) \n",
+ "if not fp:\n",
+ " print \"Error opening file.\\n\"\n",
+ "else:\n",
+ " for ctr in range(1,101,1):\n",
+ " fp.write('%d' %ctr) #Writes number from 1-100 into the file\n",
+ "fp.close()\n",
+ "#Result\n",
+ "print \"ctr value is written into the file\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ctr value is written into the file\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C30AP1 :Page 638"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#opens existing file\n",
+ "fp = open ( \"NAMES.txt\", \"a\" ) \n",
+ "#Adds to file\n",
+ "fp.writelines(\"Johnny Smith\\n\")\n",
+ "fp.writelines(\"Laura Hull \\n\")\n",
+ "fp.writelines(\"Mark Brown\\n\")\n",
+ "#Close file\n",
+ "fp.close()\n",
+ "#Result\n",
+ "print \"Names are added to the existing file\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Names are added to the existing file\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C30RE2 :Page 641"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#File1 to take backup\n",
+ "print \"What is the name of the file you want to back up? \"\n",
+ "in_filename=raw_input()\n",
+ "#File2 to copy contents\n",
+ "print \"What is the name of the file you want to copy \",in_filename,\"to? \"\n",
+ "out_filename=raw_input()\n",
+ "in_fp=open(in_filename,\"r\")\n",
+ "if not in_fp:\n",
+ " print \"\\n\\n*** \",in_filename,\"does not exist***\\n\"\n",
+ " exit(0)\n",
+ "else:\n",
+ " out_fp=open(out_filename,\"w\")\n",
+ " if not out_fp:\n",
+ " print \"\\n\\n*** Error opening \",out_filename,\"***\\n\"\n",
+ " exit(0)\n",
+ " else:\n",
+ " print \"\\nCopying...\\n\" #Reads from old file \n",
+ " for in_char in in_fp.readlines(): #and copies it to new file\n",
+ " out_fp.writelines(in_char)\n",
+ " print \"\\nThe file is copied.\\n\"\n",
+ "#Close all files\n",
+ "in_fp.close()\n",
+ "out_fp.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the name of the file you want to back up? \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "NAMES.txt\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the name of the file you want to copy NAMES.txt to? \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "NEW_NAMES.txt\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Copying...\n",
+ "\n",
+ "\n",
+ "The file is copied.\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C32CON :Page 664"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI = 3.14159\n",
+ "class Sphere: #Class declaration\n",
+ " def __init__(self, xcoord,ycoord,zcoord,radius):\n",
+ " self.r = radius\n",
+ " self.x = xcoord\n",
+ " self.y = ycoord\n",
+ " self.z = zcoord\n",
+ " \n",
+ " def volume(self):\n",
+ " return r*r*r*4*PI/3\n",
+ "\n",
+ " def surface_area(self):\n",
+ " return r*r*4*PI\n",
+ "def main():\n",
+ " s = Sphere(1.0,2.0,3.0,4.0) #Class object \n",
+ " print \"X=\",s.x,\", Y=\",s.y,\", Z=\",s.z,\", R=\",s.r #Result\n",
+ "\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X= 1.0 , Y= 2.0 , Z= 3.0 , R= 4.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C32DES :Page 665"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI = 3.14159\n",
+ "#Class declaration\n",
+ "class Sphere: \n",
+ " def __init__( self,xcoord,ycoord,zcoord,radius):\n",
+ " self.r = radius\n",
+ " self.x = xcoord\n",
+ " self.y = ycoord\n",
+ " self.z = zcoord\n",
+ " def __del__(self):\n",
+ " print \"Sphere(\",self.x,\",\" ,self.y,\",\",self.z,\",\",self.r,\") destroyed\"\n",
+ " def volume(self):\n",
+ " return self.r*self.r*self.r*4*PI/3\n",
+ " def surface_area(self):\n",
+ " return self.r*self.r*4*PI\n",
+ "def main():\n",
+ " #Class object\n",
+ " s = Sphere(1.0,2.0,3.0,4.0) \n",
+ " #Result\n",
+ " print \"X=\",s.x,\", Y=\",s.y,\", Z=\",s.z,\", R=\",s.r \n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X= 1.0 , Y= 2.0 , Z= 3.0 , R= 4.0\n",
+ "Sphere( 1.0 , 2.0 , 3.0 , 4.0 ) destroyed\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C32MEM :Page 667"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI = 3.14159\n",
+ "#Class declaration\n",
+ "class Sphere: \n",
+ " def __init__( self,xcoord,ycoord,zcoord,radius):\n",
+ " self.r = radius\n",
+ " self.x = xcoord\n",
+ " self.y = ycoord\n",
+ " self.z = zcoord\n",
+ " def __del__(self):\n",
+ " print \"Sphere(\",self.x,\",\" ,self.y,\",\",self.z,\",\",self.r,\") destroyed\"\n",
+ " def volume(self):\n",
+ " return self.r*self.r*self.r*4*PI/3\n",
+ " def surface_area(self):\n",
+ " return self.r*self.r*4*PI\n",
+ "def main():\n",
+ " #Class object\n",
+ " s = Sphere(1.0,2.0,3.0,4.0) \n",
+ " #Result\n",
+ " print \"X=\",s.x,\", Y=\",s.y,\", Z=\",s.z,\", R=\",s.r \n",
+ " print \"The volume is \",s.volume(),\"\\n\",\n",
+ " print \"The surface area is \",s.surface_area(),\"\\n\",\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X= 1.0 , Y= 2.0 , Z= 3.0 , R= 4.0\n",
+ "The volume is 268.082346667 \n",
+ "The surface area is 201.06176 \n",
+ "Sphere( 1.0 , 2.0 , 3.0 , 4.0 ) destroyed\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C32MEM1 :Page 668"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI = 3.14159\n",
+ "#Class declaration\n",
+ "class Sphere: \n",
+ " def __init__( self,xcoord,ycoord,zcoord,radius):\n",
+ " self.r = radius\n",
+ " self.x = xcoord\n",
+ " self.y = ycoord\n",
+ " self.z = zcoord\n",
+ " def __del__(self):\n",
+ " print \"Sphere(\",self.x,\",\" ,self.y,\",\",self.z,\",\",self.r,\") destroyed\"\n",
+ " def volume(self):\n",
+ " return self.r*self.r*self.r*4*PI/3\n",
+ " def surface_area(self):\n",
+ " return self.r*self.r*4*PI\n",
+ "def main():\n",
+ " #Class object\n",
+ " s = Sphere(1.0,2.0,3.0,4.0) \n",
+ " #Result\n",
+ " print \"X=\",s.x,\", Y=\",s.y,\", Z=\",s.z,\", R=\",s.r \n",
+ " print \"The volume is \",s.volume(),\"\\n\", \n",
+ " print \"The surface area is \",s.surface_area(),\"\\n\",\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X= 1.0 , Y= 2.0 , Z= 3.0 , R= 4.0\n",
+ "The volume is 268.082346667 \n",
+ "The surface area is 201.06176 \n",
+ "Sphere( 1.0 , 2.0 , 3.0 , 4.0 ) destroyed\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C32MEM1A :Page 669"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI = 3.14159\n",
+ "#Class declaration\n",
+ "class Sphere: \n",
+ " def __init__( self,xcoord,ycoord,zcoord,radius):\n",
+ " self.r = radius\n",
+ " self.x = xcoord\n",
+ " self.y = ycoord\n",
+ " self.z = zcoord\n",
+ " def __del__(self):\n",
+ " print \"Sphere(\",self.x,\",\" ,self.y,\",\",self.z,\",\",self.r,\") destroyed\"\n",
+ " def volume(self):\n",
+ " return self.r*self.r*self.r*4*PI/3\n",
+ " def surface_area(self):\n",
+ " return self.r*self.r*4*PI\n",
+ "def main():\n",
+ " #Class object\n",
+ " s = Sphere(1.0,2.0,3.0,4.0) \n",
+ " #Result\n",
+ " print \"X=\",s.x,\", Y=\",s.y,\", Z=\",s.z,\", R=\",s.r \n",
+ " print \"The volume is \",(s.r*s.r*s.r*4*PI/3),\"\\n\", #volume() function is expanded here\n",
+ " print \"The surface area is \",s.surface_area(),\"\\n\",\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X= 1.0 , Y= 2.0 , Z= 3.0 , R= 4.0\n",
+ "The volume is 268.082346667 \n",
+ "The surface area is 201.06176 \n",
+ "Sphere( 1.0 , 2.0 , 3.0 , 4.0 ) destroyed\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C32DEF :Page 671"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI = 3.14159\n",
+ "#Class declaration\n",
+ "class Sphere: \n",
+ " def __init__( self,xcoord,ycoord=2.0,zcoord=2.5,radius=1.0):\n",
+ " self.r = radius\n",
+ " self.x = xcoord\n",
+ " self.y = ycoord\n",
+ " self.z = zcoord\n",
+ " def __del__(self):\n",
+ " print \"Sphere(\",self.x,\",\" ,self.y,\",\",self.z,\",\",self.r,\") destroyed\"\n",
+ " def volume(self):\n",
+ " return self.r*self.r*self.r*4*PI/3\n",
+ " def surface_area(self):\n",
+ " return self.r*self.r*4*PI\n",
+ "def main():\n",
+ " #Class objects\n",
+ " s = Sphere(1.0) \n",
+ " t = Sphere(1.0,1.1)\n",
+ " u = Sphere(1.0,1.1,1.2)\n",
+ " v = Sphere(1.0,1.1,1.2,1.3)\n",
+ " #Result\n",
+ " print \"s: X=\",s.x,\", Y=\",s.y,\", Z=\",s.z,\", R=\",s.r \n",
+ " print \"The volume is \",s.volume(),\"\\n\", \n",
+ " print \"The surface area is \",s.surface_area(),\"\\n\",\n",
+ " print \"t: X=\",t.x,\", Y=\",t.y,\", Z=\",t.z,\", R=\",t.r \n",
+ " print \"The volume is \",t.volume(),\"\\n\", \n",
+ " print \"The surface area is \",t.surface_area(),\"\\n\",\n",
+ " print \"u: X=\",u.x,\", Y=\",u.y,\", Z=\",u.z,\", R=\",u.r \n",
+ " print \"The volume is \",u.volume(),\"\\n\", \n",
+ " print \"The surface area is \",u.surface_area(),\"\\n\",\n",
+ " print \"v: X=\",v.x,\", Y=\",v.y,\", Z=\",v.z,\", R=\",v.r \n",
+ " print \"The volume is \",v.volume(),\"\\n\", \n",
+ " print \"The surface area is \",v.surface_area(),\"\\n\",\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s: X= 1.0 , Y= 2.0 , Z= 2.5 , R= 1.0\n",
+ "The volume is 4.18878666667 \n",
+ "The surface area is 12.56636 \n",
+ "t: X= 1.0 , Y= 1.1 , Z= 2.5 , R= 1.0\n",
+ "The volume is 4.18878666667 \n",
+ "The surface area is 12.56636 \n",
+ "u: X= 1.0 , Y= 1.1 , Z= 1.2 , R= 1.0\n",
+ "The volume is 4.18878666667 \n",
+ "The surface area is 12.56636 \n",
+ "v: X= 1.0 , Y= 1.1 , Z= 1.2 , R= 1.3\n",
+ "The volume is 9.20276430667 \n",
+ "The surface area is 21.2371484 \n",
+ "Sphere( 1.0 , 2.0 , 2.5 , 1.0 ) destroyed\n",
+ "Sphere( 1.0 , 1.1 , 2.5 , 1.0 ) destroyed\n",
+ "Sphere( 1.0 , 1.1 , 1.2 , 1.0 ) destroyed\n",
+ "Sphere( 1.0 , 1.1 , 1.2 , 1.3 ) destroyed\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "C32OVCON :Page 673"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI = 3.14159\n",
+ "#Class declaration\n",
+ "class Sphere: \n",
+ " def __init__( self,xcoord,ycoord,zcoord,radius):\n",
+ " self.r = radius\n",
+ " self.x = xcoord\n",
+ " self.y = ycoord\n",
+ " self.z = zcoord\n",
+ " def __del__(self):\n",
+ " print \"Sphere(\",self.x,\",\" ,self.y,\",\",self.z,\",\",self.r,\") destroyed\"\n",
+ " def volume(self):\n",
+ " return self.r*self.r*self.r*4*PI/3\n",
+ " def surface_area(self):\n",
+ " return self.r*self.r*4*PI\n",
+ "def main():\n",
+ " #Class object\n",
+ " s = Sphere(1.0,2.0,3.0,4.0) \n",
+ " #Result\n",
+ " print \"X=\",s.x,\", Y=\",s.y,\", Z=\",s.z,\", R=\",s.r \n",
+ " print \"The volume is \",(s.r*s.r*s.r*4*PI/3),\"\\n\", #volume() function is expanded here\n",
+ " print \"The surface area is \",s.surface_area(),\"\\n\",\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X= 1.0 , Y= 2.0 , Z= 3.0 , R= 4.0\n",
+ "The volume is 268.082346667 \n",
+ "The surface area is 201.06176 \n",
+ "Sphere( 1.0 , 2.0 , 3.0 , 4.0 ) destroyed\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm/screenshots/Caption-4.png b/C++_and_Object-oriented_Programming_Paradigm/screenshots/Caption-4.png
new file mode 100755
index 00000000..603431ba
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm/screenshots/Caption-4.png
Binary files differ
diff --git a/C++_and_Object-oriented_Programming_Paradigm/screenshots/Caption-5.png b/C++_and_Object-oriented_Programming_Paradigm/screenshots/Caption-5.png
new file mode 100755
index 00000000..e25191ff
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm/screenshots/Caption-5.png
Binary files differ
diff --git a/C++_and_Object-oriented_Programming_Paradigm/screenshots/Caption-8.png b/C++_and_Object-oriented_Programming_Paradigm/screenshots/Caption-8.png
new file mode 100755
index 00000000..87ac7784
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm/screenshots/Caption-8.png
Binary files differ
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter10ClassRelationships.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter10ClassRelationships.ipynb
new file mode 100755
index 00000000..8c01f8ff
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter10ClassRelationships.ipynb
@@ -0,0 +1,351 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:83279fb4e6365b68b383d1ff340a5b71a91d27144fe4d632bdfec2e21f0afda3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10 Class Relationships"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 10.1, page no: 286"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "import string\n",
+ "class Super: #class super (base class)\n",
+ " \n",
+ " \n",
+ " def __init__(self,x=0): #constructor\n",
+ " self.__a=x\n",
+ " print 'Super constructor called'\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " print 'Super destructor called'\n",
+ " def _printInfo(self):\n",
+ " print 'a= ',self.__a,\n",
+ " print 'size of data component of Super class is ',sys.getsizeof(self.__a)\n",
+ " def print1():\n",
+ " Super.printInfo()\n",
+ " \n",
+ "class Sub(Super): #derived class\n",
+ " \n",
+ " def __init__(self,y=0): #constructor\n",
+ " Super.__init__(self,y)\n",
+ " self.__b=y+10\n",
+ " print 'Sub constructor called'\n",
+ " def _del__(self): #destructor\n",
+ " print 'Sub destructor called'\n",
+ " def _printInfo(self):\n",
+ " Super._printInfo(self)\n",
+ " print 'b= ',self.__b,\n",
+ " print 'size of data component of Sub class is ',sys.getsizeof(self.__b) #sizeof(self.__b) \n",
+ "\n",
+ " \n",
+ "#variable declaration\n",
+ "super1=Super(100 )\n",
+ "sub1=Sub(200 )\n",
+ "super1._printInfo()\n",
+ "sub1._printInfo()\n",
+ "print 'Size of super1 is',sys.getsizeof(super1)\n",
+ "print 'Size of sub1 is',sys.getsizeof(sub1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Super constructor called\n",
+ "Super constructor called\n",
+ "Sub constructor called\n",
+ "a= 100 size of data component of Super class is 24\n",
+ "a= 200 size of data component of Super class is 24\n",
+ "b= 210 size of data component of Sub class is 24\n",
+ "Size of super1 is 64\n",
+ "Size of sub1 is 64\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 10.2, page no: 295"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A: #base class\n",
+ " def __init__(self,x): #constructor\n",
+ " self.__a=x+10 \n",
+ " print 'A constructor called A: a',self.__a\n",
+ " def __del__(self):\n",
+ " print 'A des'\n",
+ " \n",
+ "class B(A): #derived class\n",
+ " def __init__(self,x): #constructor\n",
+ " self.__b=x+20\n",
+ " print 'B constructor called B: b',self.__b\n",
+ " def __del__(self):\n",
+ " print 'B des'\n",
+ " \n",
+ "class C(A,B): \n",
+ " def __init__(self,x): #constructor\n",
+ " self.__c=x+30\n",
+ " print 'C constructor called C: c',self.__c\n",
+ " def __del__(self):\n",
+ " print 'C des'\n",
+ " \n",
+ "class D(A,B):\n",
+ " def __init__(self,x): #constructor\n",
+ " self.__d=x+60\n",
+ " print 'D constructor called D: d',self.__d\n",
+ " def __del__(self):\n",
+ " print 'D des'\n",
+ " \n",
+ " \n",
+ "class E(C,D):\n",
+ " def __init__(self,x): #constructor\n",
+ " self.__e=x+90\n",
+ " A.__init__(self,x+100)\n",
+ " B.__init__(self,x+110)\n",
+ " C.__init__(self,x+120)\n",
+ " D.__init__(self,x+130)\n",
+ " print 'E constructor called E: e',self.__e\n",
+ " def __del__(self):\n",
+ " print 'E des'\n",
+ "#variable declaration \n",
+ "e=E(1000)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "A constructor called A: a 1110\n",
+ "B constructor called B: b 1130\n",
+ "C constructor called C: c 1150\n",
+ "D constructor called D: d 1190\n",
+ "E constructor called E: e 1090\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 10.3, page no: 299"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Aclass:\n",
+ " def __init__(self): #constructor\n",
+ " pass\n",
+ " def __del__(self):\n",
+ " pass \n",
+ " def printFraction(self,f): #friend function\n",
+ " print 'Function AClass:: printFraction, prints Fraction: ',f._Fraction__num,'/',f._Fraction__denom\n",
+ " \n",
+ " def setFractionToZero(self,f):\n",
+ " f.__num=0\n",
+ " f.__denom=1\n",
+ " print 'Function AClass:: setfractionToZero, sets fraction to zero: '\n",
+ " \n",
+ "class Bclass:\n",
+ " def __init__(self): #constructor\n",
+ " pass\n",
+ " def __del__(self):\n",
+ " pass\n",
+ " def printFraction(self,f): #friend function\n",
+ " print 'Function BClass:: printFraction, prints Fraction: ',f._Fraction__num,'/',f._Fraction__denom\n",
+ " def setFractionToZero(self,f):\n",
+ " print 'Function BClass:: setfractionToZero CANNOT, CANT set fraction to 0 '\n",
+ " \n",
+ " \n",
+ "class Fraction:\n",
+ " def __init__(self,a=0,b=1): #constructor\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " def __del__(self):\n",
+ " pass\n",
+ " def printFraction(self):\n",
+ " print 'Function Fraction::printFraction,print Fraction',self.__num,'/',self.__denom\n",
+ " \n",
+ " def setFractionToZero(self):\n",
+ " self.__num=0\n",
+ " self.__denom=1\n",
+ " print 'Function Fraction::setfractionToZero, sets fraction to zero '\n",
+ " \n",
+ "def printFraction(f):\n",
+ " print 'printFraction cannot print Fraction'\n",
+ "def setFractionToZero(f):\n",
+ " #f.__num=0\n",
+ " #f.__denom=1\n",
+ " print 'setfractionToZero, sets fraction to zero '\n",
+ "\n",
+ " \n",
+ "#variable declaration\n",
+ "aobj=Aclass() #object initialised\n",
+ "bobj=Bclass()\n",
+ "print 'Please enter values of numberator and denominator: '\n",
+ "n=input() #user input\n",
+ "d=input()\n",
+ "f1=Fraction(n,d)\n",
+ "\n",
+ "f1.printFraction() #function call\n",
+ "f1.setFractionToZero()\n",
+ "print ''\n",
+ "aobj.printFraction(f1)\n",
+ "aobj.setFractionToZero(f1)\n",
+ "print ''\n",
+ "bobj.printFraction(f1)\n",
+ "bobj.setFractionToZero(f1)\n",
+ "print ''\n",
+ "printFraction(f1)\n",
+ "setFractionToZero(f1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter values of numberator and denominator: \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": [
+ "Function Fraction::printFraction,print Fraction 4 / 5\n",
+ "Function Fraction::setfractionToZero, sets fraction to zero \n",
+ "\n",
+ "Function AClass:: printFraction, prints Fraction: 0 / 1\n",
+ "Function AClass:: setfractionToZero, sets fraction to zero: \n",
+ "\n",
+ "Function BClass:: printFraction, prints Fraction: 0 / 1\n",
+ "Function BClass:: setfractionToZero CANNOT, CANT set fraction to 0 \n",
+ "\n",
+ "printFraction cannot print Fraction\n",
+ "setfractionToZero, sets fraction to zero \n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 10.4, page no: 312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Employee: #base class\n",
+ " def whoAmI(self):\n",
+ " pass\n",
+ " \n",
+ "class Manager(Employee): #derived class\n",
+ " def whoAmI(self):\n",
+ " return Manager\n",
+ " \n",
+ "class Programmer(Employee): #derived class\n",
+ " def whoAmI(self):\n",
+ " return Programmer\n",
+ "class Tester(Employee): #derived class\n",
+ " def whoAmI(self):\n",
+ " return Tester\n",
+ " \n",
+ "e=Employee() #object of Employee()\n",
+ "e=[Employee() for j in range(5)]\n",
+ "e[0]=Programmer()\n",
+ "e[1]=Manager()\n",
+ "e[2]=Programmer()\n",
+ "e[3]=Tester()\n",
+ "e[4]=Tester()\n",
+ "for i in range(len(e)):\n",
+ " print 'Employee ',i+1,'is: ',e[i].whoAmI().__name__"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee 1 is: Programmer\n",
+ "Employee 2 is: Manager\n",
+ "Employee 3 is: Programmer\n",
+ "Employee 4 is: Tester\n",
+ "Employee 5 is: Tester\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter11AdvancedConcepts.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter11AdvancedConcepts.ipynb
new file mode 100755
index 00000000..716180f8
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter11AdvancedConcepts.ipynb
@@ -0,0 +1,1117 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:ff5f63ece19f30c7278116e9764883595e73fb5c30a2afada8462ceec112d5aa"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Advanced Concepts"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 11.1, page no: 324"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Array:\n",
+ " def __init__(self,size=0): #constructor being called\n",
+ " print 'Constructor called'\n",
+ " self._length=size\n",
+ " if size>0:\n",
+ " self._arr=[]*self._length #size intialised\n",
+ " else:\n",
+ " self._length=0\n",
+ " self._arr=[]\n",
+ " \n",
+ " def __del__(self): #destructor being called\n",
+ " print 'Destructor called'\n",
+ " \n",
+ " #del self._arr\n",
+ " \n",
+ " #Implementing the [] overloading\n",
+ " def op1(self,index):\n",
+ " if (index>=0 and index<self._length):\n",
+ " return self._arr[index]\n",
+ " \n",
+ " else:\n",
+ " print 'Error: out of range'\n",
+ " return -1\n",
+ "\n",
+ "#variable declaration\n",
+ "numbers = [\"zero\", \"one\", \"two\", \"three\", \"four\"]\n",
+ "integers=Array(5)\n",
+ "charptrs=Array(5)\n",
+ "integers=[None]*5\n",
+ "charptrs=[None]*5\n",
+ "for i in range(5):\n",
+ " integers[i]=i\n",
+ " charptrs[i]=numbers[i]\n",
+ "print 'The integers object has: ',\n",
+ "for i in range(5):\n",
+ " print integers[i],\n",
+ " \n",
+ "print ''\n",
+ "print 'The Charptrs object has:',\n",
+ "for i in range(5):\n",
+ " print charptrs[i],\n",
+ "print '' \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor called\n",
+ "Constructor called\n",
+ "Destructor called\n",
+ "Destructor called\n",
+ "The integers object has: 0 1 2 3 4 \n",
+ "The Charptrs object has: zero one two three four \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 11.2, page no: 328"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Array:\n",
+ " def __init__(self,size=0): #constructor being called\n",
+ " print 'Constructor called'\n",
+ " self._length=size\n",
+ " if size>0:\n",
+ " self._arr=[]*self._length #size intialised\n",
+ " else:\n",
+ " self._length=0\n",
+ " self._arr=[]\n",
+ " \n",
+ " def __del__(self): #destructor being called\n",
+ " print 'Destructor called'\n",
+ " \n",
+ " #del self._arr\n",
+ " \n",
+ " #Implementing the [] overloading\n",
+ " def op1(self,index):\n",
+ " if (index>=0 and index<self._length):\n",
+ " return self._arr[index]\n",
+ " \n",
+ " else:\n",
+ " print 'Error: out of range'\n",
+ " return -1\n",
+ "\n",
+ "def swap(a,b): #function defined\n",
+ " temp=a\n",
+ " a=b\n",
+ " b=temp\n",
+ " return a,b\n",
+ " \n",
+ "def bubblesort(arrayobj,size): #function bubblesort\n",
+ " for i in range(size-1):\n",
+ " for j in range(i+1,size,+1):\n",
+ " if arrayobj[i] < arrayobj[j]:\n",
+ " arrayobj[i],arrayobj[j]=swap(arrayobj[i],arrayobj[j])\n",
+ " return arrayobj\n",
+ "\n",
+ "#variable declaration\n",
+ "numbers = [\"zero\", \"one\", \"two\", \"three\", \"four\"]\n",
+ "integers=Array(5)\n",
+ "charptrs=Array(5)\n",
+ "integers=[None]*5\n",
+ "charptrs=[None]*5\n",
+ "for i in range(5):\n",
+ " integers[i]=i\n",
+ " charptrs[i]=numbers[i]\n",
+ "print 'The integers object has (before sorting): '\n",
+ "for i in range(5):\n",
+ " print integers[i],\n",
+ " \n",
+ "print ''\n",
+ "print 'The Charptrs object has (before sorting):'\n",
+ "for i in range(5):\n",
+ " print charptrs[i],\n",
+ "print '' \n",
+ "bubblesort(integers,5)\n",
+ "charptrs=bubblesort(charptrs,5)\n",
+ "print ''\n",
+ "print 'The integers object has (after sorting): '\n",
+ "for i in range(5):\n",
+ " print integers[i],\n",
+ "print ''\n",
+ "print 'The Charptrs object has (after sorting): '\n",
+ "for i in range(5):\n",
+ " print charptrs[i],\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor called\n",
+ "Constructor called\n",
+ "Destructor called\n",
+ "Destructor called\n",
+ "The integers object has (before sorting): \n",
+ "0 1 2 3 4 \n",
+ "The Charptrs object has (before sorting):\n",
+ "zero one two three four \n",
+ "\n",
+ "The integers object has (after sorting): \n",
+ "4 3 2 1 0 \n",
+ "The Charptrs object has (after sorting): \n",
+ "zero two three one four\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 11.3, page no: 331"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Array:\n",
+ " def __init__(self,size=0): #constructor being called\n",
+ " print 'Constructor called'\n",
+ " self._length=size\n",
+ " if size>0:\n",
+ " self._arr=[]*self._length #size intialised\n",
+ " else:\n",
+ " self._length=0\n",
+ " self._arr=[]\n",
+ " \n",
+ " def __del__(self): #destructor being called\n",
+ " print 'Destructor called'\n",
+ " \n",
+ " #del self._arr\n",
+ " \n",
+ " #Implementing the [] overloading\n",
+ " def op1(self,index):\n",
+ " if (index>=0 and index<self._length):\n",
+ " return self._arr[index]\n",
+ " \n",
+ " else:\n",
+ " print 'Error: out of range'\n",
+ " return -1\n",
+ " \n",
+ " \n",
+ "def less(a,b):\n",
+ " if a<b:\n",
+ " return True\n",
+ " else:\n",
+ " return false\n",
+ "\n",
+ "def swap(a,b): #swap function\n",
+ " temp=a\n",
+ " a=b\n",
+ " b=temp\n",
+ " return a,b\n",
+ "def bubblesort(arrayobj,size): #bubblesort sort\n",
+ " for i in range(size-1):\n",
+ " for j in range(i+1,size,+1):\n",
+ " if arrayobj[i] < arrayobj[j]:\n",
+ " arrayobj[i],arrayobj[j]=swap(arrayobj[i],arrayobj[j])\n",
+ " return arrayobj\n",
+ "\n",
+ "#variable declaration\n",
+ "numbers = [\"zero\", \"one\", \"two\", \"three\", \"four\"]\n",
+ "integers=Array(5)\n",
+ "charptrs=Array(5)\n",
+ "integers=[None]*5\n",
+ "charptrs=[None]*5\n",
+ "for i in range(5):\n",
+ " integers[i]=i\n",
+ " charptrs[i]=numbers[i]\n",
+ "print 'The integers object has (before sorting): '\n",
+ "for i in range(5):\n",
+ " print integers[i],\n",
+ " \n",
+ "print ''\n",
+ "print 'The Charptrs object has (before sorting):'\n",
+ "for i in range(5):\n",
+ " print charptrs[i],\n",
+ "print '' \n",
+ "integrs=bubblesort(integers,5)\n",
+ "charptrs=bubblesort(charptrs,5)\n",
+ "print ''\n",
+ "print 'The integers object has (after sorting): '\n",
+ "for i in range(5):\n",
+ " print integers[i],\n",
+ "print ''\n",
+ "print 'The Charptrs object has (after sorting): '\n",
+ "for i in range(5):\n",
+ " print charptrs[i],\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor called\n",
+ "Constructor called\n",
+ "Destructor called\n",
+ "Destructor called\n",
+ "The integers object has (before sorting): \n",
+ "0 1 2 3 4 \n",
+ "The Charptrs object has (before sorting):\n",
+ "zero one two three four \n",
+ "\n",
+ "The integers object has (after sorting): \n",
+ "4 3 2 1 0 \n",
+ "The Charptrs object has (after sorting): \n",
+ "zero two three one four\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Program Source Code 11.4, page no: 333"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Array:\n",
+ " def __init__(self,size=0): #constructor being called\n",
+ " print 'Constructor called'\n",
+ " self._length=size\n",
+ " if size>0:\n",
+ " self._arr=[]*self._length #size intialised\n",
+ " else:\n",
+ " self._length=0\n",
+ " self._arr=[]\n",
+ " \n",
+ " def __del__(self): #destructor being called\n",
+ " print 'Destructor called'\n",
+ " \n",
+ " #del self._arr\n",
+ " \n",
+ " #Implementing the [] overloading\n",
+ " def op1(self,index):\n",
+ " if (index>=0 and index<self._length):\n",
+ " return self._arr[index]\n",
+ " \n",
+ " else:\n",
+ " print 'Error: out of range'\n",
+ " return -1\n",
+ "\n",
+ "#variable declaration\n",
+ "numbers = [\"zero\", \"one\", \"two\", \"three\", \"four\"]\n",
+ "integers=Array(5)\n",
+ "charptrs=Array(5)\n",
+ "integers=[None]*5\n",
+ "charptrs=[None]*5\n",
+ "for i in range(5):\n",
+ " integers[i]=i\n",
+ " charptrs[i]=numbers[i]\n",
+ "print 'The integers object has: ',\n",
+ "for i in range(5):\n",
+ " print integers[i],\n",
+ " \n",
+ "print ''\n",
+ "print 'The Charptrs object has:',\n",
+ "for i in range(5):\n",
+ " print charptrs[i],\n",
+ "print '' \n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor called\n",
+ "Constructor called\n",
+ "Destructor called\n",
+ "Destructor called\n",
+ "The integers object has: 0 1 2 3 4 \n",
+ "The Charptrs object has: zero one two three four \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Program Source Code 11.5, page no: 335"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Array: \n",
+ " def __init__(self,size=0): #constructor being called\n",
+ " self._length=size\n",
+ " if size>0:\n",
+ " self._arr=[]*self._length #size intialised\n",
+ " else:\n",
+ " self._length=0\n",
+ " self._arr=[]\n",
+ " \n",
+ " def __del__(self): #destructor being called\n",
+ " del self._arr\n",
+ " \n",
+ " #Implementing the [] overloading\n",
+ " def op1(self,index):\n",
+ " if (index>=0 and index<self._length):\n",
+ " return self._arr[index]\n",
+ " \n",
+ " else:\n",
+ " print 'Error: out of range'\n",
+ " return -1\n",
+ " \n",
+ " \n",
+ " def op2(self,value):\n",
+ " self._arr.append(value)\n",
+ " \n",
+ " \n",
+ " def print1(self): #print function\n",
+ " for i in range(self._length):\n",
+ " print self._arr[i],\n",
+ " print ''\n",
+ " \n",
+ " def bubblesort(self): #bubblesort function\n",
+ " for i in range(self._length-1):\n",
+ " for j in range(i+1,self._length,1):\n",
+ " if self._arr[i]<self._arr[j]:\n",
+ " self._arr[i],self._arr[j]=swap(self._arr[i],self._arr[j])\n",
+ " return self._arr\n",
+ "\n",
+ " \n",
+ " \n",
+ "def swap(a,b): #function defined\n",
+ " temp=a\n",
+ " a=b\n",
+ " b=temp\n",
+ " return a,b\n",
+ "\n",
+ "def change1(arr,size):\n",
+ " a=Array(size)\n",
+ " for j in range(size):\n",
+ " if arr.op1(0)==\"zero\":\n",
+ " a.op2(0)\n",
+ " if arr.op1(1)==\"one\":\n",
+ " a.op2(1)\n",
+ " if arr.op1(2)==\"two\":\n",
+ " a.op2(2)\n",
+ " if arr.op1(3)==\"three\":\n",
+ " a.op2(3)\n",
+ " if arr.op1(4)==\"four\":\n",
+ " a.op2(4)\n",
+ " return a\n",
+ "\n",
+ "def change2(arr,size):\n",
+ " a=[\"\" for j in range(size)]\n",
+ " for j in range(size):\n",
+ " if arr[4]==0:\n",
+ " a[4]=\"zero\"\n",
+ " if arr[3]==1:\n",
+ " a[3]=\"one\"\n",
+ " if arr[2]==2:\n",
+ " a[2]=\"two\"\n",
+ " if arr[1]==3:\n",
+ " a[1]=\"three\"\n",
+ " if arr[0]==4:\n",
+ " a[0]=\"four\"\n",
+ " return a\n",
+ "\n",
+ "\n",
+ "\n",
+ " \n",
+ "#variable declaration\n",
+ "numbers = [\"zero\",\"one\",\"two\",\"three\",\"four\"]\n",
+ "\n",
+ "integers=Array(5)\n",
+ "floats=Array(5)\n",
+ "charptrs=Array(5)\n",
+ "\n",
+ "\n",
+ "for i in range(5):\n",
+ " integers.op2(i)\n",
+ " floats.op2(i+0.5)\n",
+ " charptrs.op2(numbers[i])\n",
+ " \n",
+ " \n",
+ "Message=\"before sorting\"\n",
+ "\n",
+ "print \"The integers(\",Message,\")...\",\n",
+ "integers.print1()\n",
+ "\n",
+ "\n",
+ "print \"The floats(\",Message,\")...\",\n",
+ "floats.print1()\n",
+ "\n",
+ "print \"The charptrs(\",Message,\")...\",\n",
+ "charptrs.print1()\n",
+ "\n",
+ "print ''\n",
+ "Message =\"being sorted\"\n",
+ "print \"The integers(\",Message,\")...\",\n",
+ "print \"The charptrs(\",Message,\")...\",\n",
+ "print \"The floats(\",Message,\")...\",\n",
+ "\n",
+ "print ''\n",
+ "print ''\n",
+ "Message =\"after sorting\"\n",
+ "print \"The integers(\",Message,\")...\",\n",
+ "integers=integers.bubblesort()\n",
+ "for j in range(5):\n",
+ " print integers[j],\n",
+ "\n",
+ "print ''\n",
+ "print \"The floats(\",Message,\")...\",\n",
+ "floats=floats.bubblesort()\n",
+ "for j in range(5):\n",
+ " print floats[j],\n",
+ " \n",
+ " \n",
+ "print ''\n",
+ "print \"The charptrs(\",Message,\")...\",\n",
+ "charptrs=change1(charptrs,5)\n",
+ "charptrs=charptrs.bubblesort()\n",
+ "charptrs=change2(charptrs,5)\n",
+ "for j in range(5):\n",
+ " print charptrs[j],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The integers( before sorting )... 0 1 2 3 4 \n",
+ "The floats( before sorting )... 0.5 1.5 2.5 3.5 4.5 \n",
+ "The charptrs( before sorting )... zero one two three four \n",
+ "\n",
+ "The integers( being sorted )... The charptrs( being sorted )... The floats( being sorted )... \n",
+ "\n",
+ "The integers( after sorting )... 4 3 2 1 0 \n",
+ "The floats( after sorting )... 4.5 3.5 2.5 1.5 0.5 \n",
+ "The charptrs( after sorting )... four three two one zero\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Program Source Code 11.6, page no: 339"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "(FALSE,TRUE)=(0,1)\n",
+ "def less(a,b):\n",
+ " if a<b:\n",
+ " return TRUE\n",
+ " else:\n",
+ " return FALSE\n",
+ "class Array: \n",
+ " def __init__(self,size=0): #constructor being called\n",
+ " self._length=size\n",
+ " if size>0:\n",
+ " self._arr=[]*self._length #size intialised\n",
+ " else:\n",
+ " self._length=0\n",
+ " self._arr=[]\n",
+ " \n",
+ " def __del__(self): #destructor being called\n",
+ " del self._arr\n",
+ " \n",
+ " #Implementing the [] overloading\n",
+ " def op1(self,index):\n",
+ " if (index>=0 and index<self._length):\n",
+ " return self._arr[index]\n",
+ " \n",
+ " else:\n",
+ " print 'Error: out of range'\n",
+ " return -1\n",
+ " \n",
+ " \n",
+ " def op2(self,value):\n",
+ " self._arr.append(value)\n",
+ " \n",
+ " \n",
+ " def print1(self): #print function\n",
+ " for i in range(self._length):\n",
+ " print self._arr[i],\n",
+ " print ''\n",
+ " \n",
+ " def bubblesort(self): #bubblesort function\n",
+ " for i in range(self._length-1):\n",
+ " for j in range(i+1,self._length,1):\n",
+ " if self._arr[i]<self._arr[j]:\n",
+ " self._arr[i],self._arr[j]=swap(self._arr[i],self._arr[j])\n",
+ " return self._arr\n",
+ "\n",
+ " \n",
+ " \n",
+ "def swap(a,b): #function defined\n",
+ " temp=a\n",
+ " a=b\n",
+ " b=temp\n",
+ " return a,b\n",
+ "\n",
+ "def change1(arr,size):\n",
+ " a=Array(size)\n",
+ " for j in range(size):\n",
+ " if arr.op1(0)==\"zero\":\n",
+ " a.op2(0)\n",
+ " if arr.op1(1)==\"one\":\n",
+ " a.op2(1)\n",
+ " if arr.op1(2)==\"two\":\n",
+ " a.op2(2)\n",
+ " if arr.op1(3)==\"three\":\n",
+ " a.op2(3)\n",
+ " if arr.op1(4)==\"four\":\n",
+ " a.op2(4)\n",
+ " return a\n",
+ "\n",
+ "def change2(arr,size):\n",
+ " a=[\"\" for j in range(size)]\n",
+ " for j in range(size):\n",
+ " if arr[4]==0:\n",
+ " a[4]=\"zero\"\n",
+ " if arr[3]==1:\n",
+ " a[3]=\"one\"\n",
+ " if arr[2]==2:\n",
+ " a[2]=\"two\"\n",
+ " if arr[1]==3:\n",
+ " a[1]=\"three\"\n",
+ " if arr[0]==4:\n",
+ " a[0]=\"four\"\n",
+ " return a\n",
+ "\n",
+ "\n",
+ "#variable declarartion\n",
+ "numbers = [\"zero\",\"one\",\"two\",\"three\",\"four\"]\n",
+ "\n",
+ "integers=Array(5)\n",
+ "floats=Array(5)\n",
+ "charptrs=Array(5)\n",
+ "\n",
+ "\n",
+ "for i in range(5):\n",
+ " integers.op2(i)\n",
+ " floats.op2(i+0.5)\n",
+ " charptrs.op2(numbers[i])\n",
+ " \n",
+ " \n",
+ "Message=\"before sorting\"\n",
+ "\n",
+ "print \"The integers(\",Message,\")...\",\n",
+ "integers.print1()\n",
+ "\n",
+ "\n",
+ "print \"The floats(\",Message,\")...\",\n",
+ "floats.print1()\n",
+ "\n",
+ "print \"The charptrs(\",Message,\")...\",\n",
+ "charptrs.print1()\n",
+ "\n",
+ "print ''\n",
+ "Message =\"being sorted\"\n",
+ "print \"The integers(\",Message,\")...\",\n",
+ "print \"The charptrs(\",Message,\")...\",\n",
+ "print \"The floats(\",Message,\")...\",\n",
+ "\n",
+ "print ''\n",
+ "print ''\n",
+ "Message =\"after sorting\"\n",
+ "print \"The integers(\",Message,\")...\",\n",
+ "integers=integers.bubblesort()\n",
+ "for j in range(5):\n",
+ " print integers[j],\n",
+ "\n",
+ "print ''\n",
+ "print \"The floats(\",Message,\")...\",\n",
+ "floats=floats.bubblesort()\n",
+ "for j in range(5):\n",
+ " print floats[j],\n",
+ " \n",
+ " \n",
+ "print ''\n",
+ "print \"The charptrs(\",Message,\")...\",\n",
+ "charptrs=change1(charptrs,5)\n",
+ "charptrs=charptrs.bubblesort()\n",
+ "charptrs=change2(charptrs,5)\n",
+ "for j in range(5):\n",
+ " print charptrs[j],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The integers( before sorting )... 0 1 2 3 4 \n",
+ "The floats( before sorting )... 0.5 1.5 2.5 3.5 4.5 \n",
+ "The charptrs( before sorting )... zero one two three four \n",
+ "\n",
+ "The integers( being sorted )... The charptrs( being sorted )... The floats( being sorted )... \n",
+ "\n",
+ "The integers( after sorting )... 4 3 2 1 0 \n",
+ "The floats( after sorting )... 4.5 3.5 2.5 1.5 0.5 \n",
+ "The charptrs( after sorting )... four three two one zero\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 11.7, page no: 340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Array:\n",
+ " def __init__(self,size=0): #constructor being called\n",
+ " print 'Constructor called'\n",
+ " self._length=size\n",
+ " if size>0:\n",
+ " self._arr=[]*self._length #size intialised\n",
+ " else:\n",
+ " self._length=0\n",
+ " self._arr=[]\n",
+ " \n",
+ " def __del__(self): #desstructor being called\n",
+ " print 'Destructor called'\n",
+ " \n",
+ " #del self._arr\n",
+ " \n",
+ " #Implementing the [] overloading\n",
+ " def op1(self,index):\n",
+ " if (index>=0 and index<self._length):\n",
+ " return self._arr[index]\n",
+ " \n",
+ " else:\n",
+ " print 'Error: out of range'\n",
+ " return -1\n",
+ " \n",
+ "class stack(Array): #derived class\n",
+ " def __init__(self,Size): #constructor \n",
+ " \n",
+ " Array.__init__(self,Size)\n",
+ " self.__sp=-1\n",
+ " self.__Maxsize=Size\n",
+ " \n",
+ " def __del__(self): #destructor \n",
+ " pass\n",
+ " \n",
+ " def push(self,data): #push function\n",
+ " if self.__sp==self.__Maxsize:\n",
+ " return False\n",
+ " self.__sp+=1\n",
+ " self._arr.append(data)\n",
+ " #return \n",
+ " def pop(self): #pop function\n",
+ " if self.__sp==-1:\n",
+ " return False\n",
+ " data=self._arr[self.__sp]\n",
+ " self.__sp-=1\n",
+ " return True\n",
+ " \n",
+ " def print1(self):\n",
+ " if self.__sp==-1:\n",
+ " print 'stack empty'\n",
+ " \n",
+ " for i in range(self.__sp+1):\n",
+ " print self._arr[i],\n",
+ " \n",
+ "\n",
+ " \n",
+ " \n",
+ " #variable declarartion \n",
+ "numbers = [\"zero\", \"one\", \"two\", \"three\", \"four\"]\n",
+ "integers=stack(5)\n",
+ "floats=stack(5)\n",
+ "charptrs=stack(5)\n",
+ "\n",
+ "\n",
+ "for i in range(5):\n",
+ " integers.push(i)\n",
+ " floats.push(i+0.5)\n",
+ " charptrs.push(numbers[i])\n",
+ "print 'the contents of integers stack(after five pushes):',\n",
+ "integers.print1() \n",
+ "print ''\n",
+ "print 'the contents of integers stack(after five pushes):',\n",
+ "floats.print1() \n",
+ "print ''\n",
+ "print 'the contents of integers stack(after five pushes):',\n",
+ "charptrs.print1() \n",
+ "print ''\n",
+ "\n",
+ "integers.pop();integers.pop();integers.pop()\n",
+ "floats.pop();floats.pop();charptrs.pop()\n",
+ "print ''\n",
+ "print 'the contents of integers stack(after three pops):',\n",
+ "integers.print1() \n",
+ "print ''\n",
+ "print 'the contents of integers stack(after two pops):',\n",
+ "floats.print1()\n",
+ "print ''\n",
+ "print 'the contents of integers stack(after one pop):',\n",
+ "charptrs.print1() \n",
+ "print ''"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor called\n",
+ "Constructor called\n",
+ "Constructor called\n",
+ "the contents of integers stack(after five pushes): 0 1 2 3 4 \n",
+ "the contents of integers stack(after five pushes): 0.5 1.5 2.5 3.5 4.5 \n",
+ "the contents of integers stack(after five pushes): zero one two three four \n",
+ "\n",
+ "the contents of integers stack(after three pops): 0 1 \n",
+ "the contents of integers stack(after two pops): 0.5 1.5 2.5 \n",
+ "the contents of integers stack(after one pop): zero one two three \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Program Source Code 11.8, page no: 351"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAXLENGTH=30 #size initialised\n",
+ "\n",
+ "class MyException: #class declared\n",
+ " __Error=[None]*MAXLENGTH\n",
+ " def __init__(self,a,arg=None): #constructor \n",
+ " if arg==None:\n",
+ " print 'MyException constructor called'\n",
+ " #__Error[MAXLENGTH-1]='\\0'\n",
+ " \n",
+ " else:\n",
+ " print 'myException copy constructor called'\n",
+ " __Error=arg.__Error\n",
+ " \n",
+ " def __del__(self): #destructor \n",
+ " print 'MyException desstructor called ' \n",
+ " \n",
+ " def __ShowError(self):\n",
+ " return __Error\n",
+ " \n",
+ "class TestException: #class declared\n",
+ " def __init__(self):\n",
+ " print 'TestException constructor called '\n",
+ " \n",
+ " def __del__(self):\n",
+ " print 'TestException desstructor called '\n",
+ " \n",
+ "def TestFunc():\n",
+ " e=TestException()\n",
+ " print 'In TestFunc(). Throwing exception object MyException '\n",
+ " raise MyException('TestFunc(): Thrown exception')\n",
+ " \n",
+ " \n",
+ "print 'main program started... try block about to start '\n",
+ "try: #try block\n",
+ " print 'Inside main functions try block... calling TestFunc() '\n",
+ " TestFunc()\n",
+ " print 'Inside main functions try block... raising exception'\n",
+ " raise exception(1)\n",
+ " \n",
+ "except MyException as E: #catch block\n",
+ " print 'Inside first catch handler: caught Myexception object '\n",
+ " #print E.__ShowError()\n",
+ " \n",
+ " \n",
+ " \n",
+ "except Exception as code: #catch block\n",
+ " print 'Inside second catch handler: caught exception code '\n",
+ " \n",
+ "print 'Main program returning.. outside try. catch blocks'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "main program started... try block about to start \n",
+ "Inside main functions try block... calling TestFunc() \n",
+ "TestException constructor called \n",
+ "In TestFunc(). Throwing exception object MyException \n",
+ "MyException constructor called\n",
+ "Inside first catch handler: caught Myexception object \n",
+ "TestException desstructor called \n",
+ "Main program returning.. outside try. catch blocks\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Program Source Code 11.9, page no: 358"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#enumeration type\n",
+ "(E, D, C, B, A) = (0,1,2,3,4)\n",
+ "\n",
+ "def printGrade(arg): #function defined\n",
+ " if(arg==A):\n",
+ " print 'Grade A'\n",
+ " elif(arg==B):\n",
+ " print 'Grade B'\n",
+ " elif(arg==B):\n",
+ " print 'Grade C'\n",
+ " elif(arg==B):\n",
+ " print 'Grade D'\n",
+ " elif(arg==B):\n",
+ " print 'Grade E'\n",
+ " \n",
+ " \n",
+ " #variable declaration\n",
+ "X=100\n",
+ "Y=3\n",
+ "g=Y #static_cast\n",
+ "XbyY1=X/Y\n",
+ "XbyY2=(X)/Y #static_cast\n",
+ "\n",
+ "print 'X/Y= ',XbyY1\n",
+ "print 'static cast<double> (X)/Y= ',XbyY2\n",
+ "print ''\n",
+ "print 'static cast<Grade> (',Y,')=>',\n",
+ "printGrade(g)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "MyException desstructor called \n",
+ "X/Y= 33\n",
+ "static cast<double> (X)/Y= 33\n",
+ "\n",
+ "static cast<Grade> ( 3 )=> Grade B\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 11.10, page no: 360"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class X: #polymorphic class\n",
+ " def __init__(self):\n",
+ " self.__x=0\n",
+ " def __del__(self): #virtual destructor\n",
+ " pass\n",
+ " def vf1(): #virtual function\n",
+ " pass\n",
+ " \n",
+ "class Y(X): #derived class\n",
+ " def __init__(self):\n",
+ " X.__init__(self)\n",
+ " \n",
+ " def __del__(self): \n",
+ " pass\n",
+ " \n",
+ "#try: #start a try block\n",
+ "try: \n",
+ " px1=[X()]\n",
+ " px2=[X()]\n",
+ " px1.append(X())\n",
+ " px2.append(X())\n",
+ " py1=[Y()]\n",
+ " py2=[Y()]\n",
+ " \n",
+ "\n",
+ " print 'Initially: px1= ',id(px1),\n",
+ " print ', px2= ',id(px2)\n",
+ " print ''\n",
+ " py1=px1\n",
+ " py2=px2\n",
+ " \n",
+ " print 'Result of dynamic cast: '\n",
+ " print 'py1= px1 gets ',id(py1), ', py2=px2 gets ',id(py2)\n",
+ " print ''\n",
+ " py1=px1\n",
+ " py2=px2\n",
+ " print 'Result of static cast: '\n",
+ " print 'py1= px1 gets ',id(py1), ', py2=px2 gets ',id(py2)\n",
+ "except Exception,e: #catch block\n",
+ " print \"Allocation failure.\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Initially: px1= 66575944 , px2= 66575432\n",
+ "\n",
+ "Result of dynamic cast: \n",
+ "py1= px1 gets 66575944 , py2=px2 gets 66575432\n",
+ "\n",
+ "Result of static cast: \n",
+ "py1= px1 gets 66575944 , py2=px2 gets 66575432\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 11.11, page no: 362"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class X: #base class\n",
+ " def __init__(self):\n",
+ " self.__x=0\n",
+ " def __del__(self):\n",
+ " pass\n",
+ " \n",
+ "class Y(X): #derived class\n",
+ " def __init__(self):\n",
+ " X.__init__(self)\n",
+ " def __del__(self):\n",
+ " pass\n",
+ " \n",
+ "xobj=X()\n",
+ "yobj=Y()\n",
+ "pxobj1=[X()]\n",
+ "pxobj2=[X()]\n",
+ "pxobj1[0]=X()\n",
+ "pxobj2[0]=X()\n",
+ "print 'type of xobj= ',xobj.__class__.__name__ #typeid(xobj).name()\n",
+ "print 'type of yobj= ',yobj.__class__.__name__ #typeid(yobj).name()\n",
+ "print 'type of pxobj1= ',pxobj1[0].__class__.__name__ #typeid(pxobj1).name()\n",
+ "print 'type of pxobj2= ',pxobj2[0].__class__.__name__ #typeid(pxobj2).name()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "type of xobj= X\n",
+ "type of yobj= Y\n",
+ "type of pxobj1= X\n",
+ "type of pxobj2= X\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter12theStandardLibraryinc++.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter12theStandardLibraryinc++.ipynb
new file mode 100755
index 00000000..fb1e2d10
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter12theStandardLibraryinc++.ipynb
@@ -0,0 +1,580 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:168943ae0a9b06ffd8f2b90d98087fc3a021e558a57b861e6482e21670d5825f"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12: the Standard Library in C++"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 12.1, page no: 368"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "FormatString=[] #for taking input\n",
+ "a=10\n",
+ "b=20\n",
+ "c=a+b\n",
+ "print 'ok...I have added them: ', a,'+' ,b,'=',c\n",
+ "print 'Now you tell me your format string',\n",
+ "print '(Max 40 characters)'\n",
+ "print 'I will use that to show input numbers',\n",
+ "print 'and their sum'\n",
+ "sys.stdout.flush() #fflush stdin \n",
+ "FormatString='The sum of two numbers'\n",
+ "print FormatString,a,'and',b,'is',c #displaying the numbers and their sum\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ok...I have added them: 10 + 20 = 30\n",
+ "Now you tell me your format string (Max 40 characters)\n",
+ "I will use that to show input numbers and their sum\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sum of two numbers 10 and 20 is 30\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 12.2, page no: 375"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#variable declaration\n",
+ "value=100\n",
+ "print 'The decimal value is: ',value\n",
+ "print 'The octal value is: ',oct(value)\n",
+ "print 'The hexadecimal value is: ',hex(value)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The decimal value is: 100\n",
+ "The octal value is: 0144\n",
+ "The hexadecimal value is: 0x64\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Program Source Code 12.3, page no: 378"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import*\n",
+ "import math\n",
+ "PI=22.0/7.0\n",
+ "print '123456789012345678901234567890'\n",
+ "print ''\n",
+ "f=0.0\n",
+ "\n",
+ "while f<6.28571428:\n",
+ " print '{0:>8.3f}'.format(f), #width(8)\n",
+ " print '{0:>13.4}'.format(math.sin(f)) #width(13)\n",
+ " f+=0.52380952\n",
+ "print ''\n",
+ "print 'sin(2.0*PI)=',math.sin(2.0*PI)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "123456789012345678901234567890\n",
+ "\n",
+ " 0.000 0.0\n",
+ " 0.524 0.5002\n",
+ " 1.048 0.8662\n",
+ " 1.571 1.0\n",
+ " 2.095 0.8656\n",
+ " 2.619 0.4991\n",
+ " 3.143 -0.001264\n",
+ " 3.667 -0.5013\n",
+ " 4.190 -0.8669\n",
+ " 4.714 -1.0\n",
+ " 5.238 -0.865\n",
+ " 5.762 -0.498\n",
+ " 6.286 0.002529\n",
+ "\n",
+ "sin(2.0*PI)= 0.00252897583892\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 12.4, page no: 379"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import string \n",
+ "print '1234567890123456789012345678901234567890'\n",
+ "print '{:*>10}'.format(100)\n",
+ "print ''\n",
+ "\n",
+ "print '1234567890123456789012345678901234567890'\n",
+ "if(-12.34567>0):\n",
+ " i='{0:>15.3e}'.format(-12.34567) #for ios::scientific\n",
+ " i='+'+i\n",
+ " print i\n",
+ "else :\n",
+ " print '{0:e}'.format(123.23)\n",
+ "i='{0:*>15.3f}'.format(-12.34567) #for ios::scientific\n",
+ "\n",
+ "print i\n",
+ "print ''\n",
+ "\n",
+ "print '1234567890123456789012345678901234567890'\n",
+ "print '{0:*>+10.3f}'.format(275.5) #for ios::showpos\n",
+ "print ''\n",
+ "\n",
+ "print '1234567890123456789012345678901234567890'\n",
+ "print '{:.>5}'.format('n'), #for ios::fill\n",
+ "print '{:.>15}'.format(\"inverse_of_n\"),\n",
+ "print '{:.>15}'.format(\"sum_of_terms\")\n",
+ "\n",
+ "sum=0\n",
+ "n=1\n",
+ "for n in xrange(1,11):\n",
+ " term=1.0/float(n)\n",
+ " sum+=term\n",
+ " print '+{:.>5}'.format(n),\n",
+ " print '{:.>14.4f}+'.format(term),\n",
+ " i='{0:.>13.4f}'.format(sum) #for ios::scientific\n",
+ " # i='+'+i\n",
+ " print i"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1234567890123456789012345678901234567890\n",
+ "*******100\n",
+ "\n",
+ "1234567890123456789012345678901234567890\n",
+ "1.232300e+02\n",
+ "********-12.346\n",
+ "\n",
+ "1234567890123456789012345678901234567890\n",
+ "**+275.500\n",
+ "\n",
+ "1234567890123456789012345678901234567890\n",
+ "....n ...inverse_of_n ...sum_of_terms\n",
+ "+....1 ........1.0000+ .......1.0000\n",
+ "+....2 ........0.5000+ .......1.5000\n",
+ "+....3 ........0.3333+ .......1.8333\n",
+ "+....4 ........0.2500+ .......2.0833\n",
+ "+....5 ........0.2000+ .......2.2833\n",
+ "+....6 ........0.1667+ .......2.4500\n",
+ "+....7 ........0.1429+ .......2.5929\n",
+ "+....8 ........0.1250+ .......2.7179\n",
+ "+....9 ........0.1111+ .......2.8290\n",
+ "+...10 ........0.1000+ .......2.9290\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 12.5, page no: 380"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def currency(s):\n",
+ " i='Rs.'\n",
+ " return i\n",
+ "\n",
+ "def form(s):\n",
+ " i= '{:.>+10.2f}'.format(s) #showpoint,fill,precision\n",
+ " \n",
+ " return i\n",
+ "\n",
+ "print currency(1234.5),form(1234.5)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rs. ..+1234.50\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 12.6, page no: 382"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str = raw_input('please input a line of message: ') \n",
+ "print str #display"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "please input a line of message: hello, do you like C++ I/O\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "hello, do you like C++ I/O\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 12.7, page no: 383"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "SIZE=40\n",
+ "line=[]*SIZE\n",
+ "str = raw_input('please input a line terminated by .: ')\n",
+ "if str!='.':\n",
+ " print str #display"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "please input a line terminated by .: I am line\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I am line\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 12.8, page no: 383"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "infile=open('TEST.DAT')\n",
+ "while i:\n",
+ " print i\n",
+ "infile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "NameError",
+ "evalue": "name 'i' is not defined",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m<ipython-input-3-d2d48edc5708>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0minfile\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'TEST.DAT'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mwhile\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0minfile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mNameError\u001b[0m: name 'i' is not defined"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 12.9, page no: 386"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "data1 = input(\"Please input a number: \") #user input \n",
+ "data2 = input(\"Please input another number: \") #user input \n",
+ "\n",
+ "print 'Now I will add your numbers:',data1,'and',data2\n",
+ "\n",
+ "data3 = data1 + data2\n",
+ "\n",
+ "print 'And the result of this addition is:',data3\n",
+ "\n",
+ "print 'now I will store all these numbers (comma seperated) \\nIn file TEST.txt'\n",
+ "\n",
+ "outfile = open('TEST.txt','w')\n",
+ "\n",
+ "outfile.write(str(data1)) #writing in file\n",
+ "outfile.write(',')\n",
+ "outfile.write(str(data2))\n",
+ "outfile.write(',')\n",
+ "outfile.write(str(data3))\n",
+ "\n",
+ "print 'Now I will close the file TEST.txt'\n",
+ "outfile.close()\n",
+ "\n",
+ "\n",
+ "print 'Now I will reopen the file TEST.txt'\n",
+ "infile = open('TEST.txt','r')\n",
+ "\n",
+ "a = infile.read(len(str(data1))) #reading from file\n",
+ "b = infile.read(1)\n",
+ "c = infile.read(len(str(data2)))\n",
+ "d = infile.read(1)\n",
+ "e = infile.read(len(str(data3)))\n",
+ "\n",
+ "print 'value retrieved in first line is',\n",
+ "print a,b,c,d,e\n",
+ "\n",
+ "infile.close() #closing the file\n",
+ "\n",
+ "print 'And the retrieved data are:'\n",
+ "print a\n",
+ "print c\n",
+ "print e"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input a number: 40\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input another number: 50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Now I will add your numbers: 40 and 50\n",
+ "And the result of this addition is: 90\n",
+ "now I will store all these numbers (comma seperated) \n",
+ "In file TEST.txt\n",
+ "Now I will close the file TEST.txt\n",
+ "Now I will reopen the file TEST.txt\n",
+ "value retrieved in first line is 40 , 50 , 90\n",
+ "And the retrieved data are:\n",
+ "40\n",
+ "50\n",
+ "90\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 12.10, page no: 387"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "data1 = input(\"Please input a number: \") #user input \n",
+ "data2 = input(\"Please input another number: \") #user input \n",
+ "\n",
+ "print 'Now I will add your numbers:',data1,'and',data2\n",
+ "\n",
+ "data3 = data1 + data2\n",
+ "\n",
+ "print 'And the result of this addition is:',data3\n",
+ "\n",
+ "print 'now I will store all these numbers (comma seperated) \\nIn file TEST.txt'\n",
+ "\n",
+ "outfile = open('TEST.txt','w')\n",
+ "\n",
+ "outfile.write(str(data1)) #writing in file\n",
+ "outfile.write(',')\n",
+ "outfile.write(str(data2))\n",
+ "outfile.write(',')\n",
+ "outfile.write(str(data3))\n",
+ "\n",
+ "print 'Now I will close the file TEST.txt'\n",
+ "outfile.close()\n",
+ "\n",
+ "\n",
+ "print 'Now I will reopen the file TEST.txt'\n",
+ "infile = open('TEST.txt','r')\n",
+ "\n",
+ "a = infile.read(len(str(data1))) #reading from file\n",
+ "b = infile.read(1)\n",
+ "c = infile.read(len(str(data2)))\n",
+ "d = infile.read(1)\n",
+ "e = infile.read(len(str(data3)))\n",
+ "\n",
+ "print 'value retrieved in first line is',\n",
+ "print a,b,c,d,e\n",
+ "\n",
+ "infile.close() #closing the file\n",
+ "\n",
+ "print 'And the retrieved data are:'\n",
+ "print a\n",
+ "print c\n",
+ "print e"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input a number: 40\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input another number: 50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Now I will add your numbers: 40 and 50\n",
+ "And the result of this addition is: 90\n",
+ "now I will store all these numbers (comma seperated) \n",
+ "In file TEST.txt\n",
+ "Now I will close the file TEST.txt\n",
+ "Now I will reopen the file TEST.txt\n",
+ "value retrieved in first line is 40 , 50 , 90\n",
+ "And the retrieved data are:\n",
+ "40\n",
+ "50\n",
+ "90\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter13DataStructuresandApplicationsinc++.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter13DataStructuresandApplicationsinc++.ipynb
new file mode 100755
index 00000000..00726b56
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter13DataStructuresandApplicationsinc++.ipynb
@@ -0,0 +1,443 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:adccc5ea30710f1dbd64653bd40f3c72a49317cd6bf29189cca44f9890890d10"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13: Data Structures and Applications in c++"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 13.1, page no: 415"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "(SORTEDASCENDING,SORTEDDESCENDING,UNSORTED) = (0,1,2) #enum declared\n",
+ "\n",
+ "INSERT_AT_END = -1\n",
+ "INSERT_SORT_ASCENDING = -2\n",
+ "INSERT_SORT_DESCENDING = -3\n",
+ "\n",
+ "class NODE: #class declared\n",
+ " \n",
+ " def __init__(self,d=None): #constructor\n",
+ " self.__data = d\n",
+ " self.__next = None\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " self.purge()\n",
+ " \n",
+ " def search(self,d):\n",
+ " \n",
+ " if self.__data == d:\n",
+ " return self\n",
+ " \n",
+ " elif self.__next == None:\n",
+ " return None\n",
+ " \n",
+ " else:\n",
+ " return self.__next.search(d)\n",
+ " \n",
+ " def remove(self,d): #remove function\n",
+ " \n",
+ " n = NODE() #NODE *n\n",
+ " \n",
+ " if self.__data == d:\n",
+ " return self.__next\n",
+ " \n",
+ " else:\n",
+ " \n",
+ " if not self.__next == None:\n",
+ " n = self.__next.remove(d)\n",
+ " \n",
+ " if not n==self.__next:\n",
+ " del self.__next\n",
+ " return self\n",
+ " \n",
+ " def insertAtEnd(self,n): #insert function\n",
+ " \n",
+ " if self.__next == None:\n",
+ " self.__next = n\n",
+ " \n",
+ " else:\n",
+ " self.__next.insertAtEnd(n)\n",
+ " \n",
+ " return False\n",
+ " \n",
+ " \n",
+ " def insert(self,n,pos): #insert function\n",
+ " \n",
+ " if pos == INSERT_AT_END:\n",
+ " self.insertAtEnd(n)\n",
+ " \n",
+ " elif pos == INSERT_SORT_ASCENDING:\n",
+ " \n",
+ " if (((pos == INSERT_SORT_ASCENDING)and(n.__data<self.__data)) or ((pos == INSERT_SORT_DESCENDING)and(n.__data>self.__data))):\n",
+ " n.__next = self\n",
+ " return True\n",
+ " \n",
+ " else:\n",
+ " \n",
+ " if self.__next == None:\n",
+ " self.__next = n\n",
+ " \n",
+ " else:\n",
+ " \n",
+ " if self.__next.insert(n,pos) == True:\n",
+ " self.__next = n\n",
+ " \n",
+ " \n",
+ " elif pos == INSERT_SORT_DESCENDING:\n",
+ " \n",
+ " if (((pos == INSERT_SORT_ASCENDING)and(n.__data<self.__data)) or ((pos == INSERT_SORT_DESCENDING)and(n.__data>self.__data))):\n",
+ " n.__next = self\n",
+ " return True\n",
+ " \n",
+ " else:\n",
+ " \n",
+ " if self.__next == None:\n",
+ " self.__next = n\n",
+ " \n",
+ " else:\n",
+ " \n",
+ " if self.__next.insert(n,pos) == True:\n",
+ " self.__next = n\n",
+ " \n",
+ " else:\n",
+ " \n",
+ " if pos == 0:\n",
+ " n.__next = self\n",
+ " return True\n",
+ " \n",
+ " else:\n",
+ " \n",
+ " if self.__next == None:\n",
+ " self.__next = n\n",
+ " \n",
+ " else:\n",
+ " if self.__next.insert(n,pos-1) == True:\n",
+ " self.__next = n\n",
+ " \n",
+ " return False\n",
+ " \n",
+ " def Print(self): #print function\n",
+ " print self.__data,'->',\n",
+ " \n",
+ " if self.__next == None:\n",
+ " print 'NULL'\n",
+ " else:\n",
+ " self.__next.Print()\n",
+ " \n",
+ " def purge(self): #purge function\n",
+ " \n",
+ " if not self.__next == None:\n",
+ " del self.__next\n",
+ " self.__next = None\n",
+ " \n",
+ " \n",
+ "class LINKEDLIST: #class declared\n",
+ " \n",
+ " def __init__(self,Ord = UNSORTED): #constructor\n",
+ " \n",
+ " self.__header = NODE()\n",
+ " self.__order = Ord\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " self.purge()\n",
+ " \n",
+ " \n",
+ " def search(self,d): #search \n",
+ " \n",
+ " if (not self.__header == None) and (not self.__header.search(d) == None):\n",
+ " return True\n",
+ " return False\n",
+ " \n",
+ " def remove(self,d): #remove\n",
+ " \n",
+ " n = NODE()\n",
+ " \n",
+ " if not self.__header == None:\n",
+ " n = self.__header.remove(d)\n",
+ " \n",
+ " if not n==self.__header:\n",
+ " del self.__header\n",
+ " self.__header = n\n",
+ " \n",
+ " \n",
+ " def insert(self,d,pos = UNSORTED):\n",
+ " \n",
+ " if self.__order == SORTEDASCENDING: #considering all cases and position\n",
+ " pos = INSERT_SORT_ASCENDING\n",
+ " \n",
+ " elif self.__order == SORTEDDESCENDING:\n",
+ " pos = INSERT_SORT_DESCENDING\n",
+ " \n",
+ " n=[None]*d\n",
+ " \n",
+ " n = NODE(d)\n",
+ " \n",
+ " if self.__header == None or self.__header.insert(n,pos) == True:\n",
+ " self.__header = n\n",
+ " \n",
+ " \n",
+ " def Print(self): #printing the list\n",
+ " print '---------------------------------'\n",
+ " \n",
+ " if self.__header._NODE__next == None:\n",
+ " print 'Empty Linked List.....'\n",
+ " \n",
+ " else:\n",
+ " self.__header.Print()\n",
+ " \n",
+ " print '----------------------------------'\n",
+ " \n",
+ " \n",
+ " def purge(self):\n",
+ " \n",
+ " if not self.__header == None:\n",
+ " del self.__header\n",
+ " self.__header = None\n",
+ " \n",
+ " #variable declaration\n",
+ " \n",
+ "print 'Empty LinkedListCreated'\n",
+ "\n",
+ "aList = LINKEDLIST()\n",
+ "bList = LINKEDLIST(SORTEDASCENDING)\n",
+ "cList = LINKEDLIST(SORTEDDESCENDING)\n",
+ "\n",
+ "aList.Print()\n",
+ "\n",
+ "print 'Inserting 3, 5, 2 to be inserted at end'\n",
+ "\n",
+ "aList.insert(3, INSERT_AT_END)\n",
+ "aList.insert(5, INSERT_AT_END)\n",
+ "aList.insert(2, INSERT_AT_END)\n",
+ "\n",
+ "aList.Print()\n",
+ "\n",
+ "print 'Inserting 3, 5, 2 to be inserted in sort ascending order'\n",
+ "\n",
+ "bList.insert(3)\n",
+ "bList.insert(5)\n",
+ "bList.insert(2)\n",
+ "\n",
+ "bList.Print()\n",
+ "\n",
+ "\n",
+ "print 'Inserting 3, 5, 2 to be inserted in sort descending order'\n",
+ "\n",
+ "cList.insert(3)\n",
+ "cList.insert(5)\n",
+ "cList.insert(2)\n",
+ "\n",
+ "cList.Print()\n",
+ "\n",
+ "\n",
+ "print 'Inserting 3, 5, 2 to be inserted always (like stack) at the beginning'\n",
+ "aList.purge()\n",
+ "aList.insert(3,0)\n",
+ "aList.insert(5,0)\n",
+ "aList.insert(2,0)\n",
+ "aList.Print()\n",
+ "\n",
+ "\n",
+ "print 'Inserting 3, 5, 2 to be inserted at position 0, 1, 1 respectively'\n",
+ "aList.purge()\n",
+ "aList.insert(3,0)\n",
+ "aList.insert(5,1)\n",
+ "aList.insert(2,1)\n",
+ "aList.Print()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Empty LinkedListCreated\n",
+ "---------------------------------\n",
+ "Empty Linked List.....\n",
+ "----------------------------------\n",
+ "Inserting 3, 5, 2 to be inserted at end\n",
+ "---------------------------------\n",
+ "None -> 3 -> 5 -> 2 -> NULL\n",
+ "----------------------------------\n",
+ "Inserting 3, 5, 2 to be inserted in sort ascending order\n",
+ "---------------------------------\n",
+ "None -> 2 -> 3 -> 5 -> NULL\n",
+ "----------------------------------\n",
+ "Inserting 3, 5, 2 to be inserted in sort descending order\n",
+ "---------------------------------\n",
+ "5 -> 3 -> 2 -> None -> NULL\n",
+ "----------------------------------\n",
+ "Inserting 3, 5, 2 to be inserted always (like stack) at the beginning\n",
+ "---------------------------------\n",
+ "2 -> 5 -> 3 -> NULL\n",
+ "----------------------------------\n",
+ "Inserting 3, 5, 2 to be inserted at position 0, 1, 1 respectively\n",
+ "---------------------------------\n",
+ "3 -> 2 -> 5 -> NULL\n",
+ "----------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 13.2, page no: 423"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "(FALSE, TRUE)= (0,1) #enum declaration\n",
+ "\n",
+ "class Employee: #class employee declared\n",
+ " def __init__(self, nm=None, sal=0): #constructor\n",
+ " self.__name=None\n",
+ " if(nm!=None):\n",
+ " self.__name=[]\n",
+ " \n",
+ " self.__name.append(nm)\n",
+ " nm=self.__name\n",
+ " self.__salary=sal\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " if(self.__name!=None):\n",
+ " del self.__name\n",
+ " \n",
+ " def display(self): #display function\n",
+ " if(self.__name==None):\n",
+ " print 'No Name available for employee'\n",
+ " print ''\n",
+ " else:\n",
+ " print 'Name of the employee: ',self.__name\n",
+ " \n",
+ " \n",
+ "class Manager(Employee): #derived class declared\n",
+ " def __init__(self, nm, sal): #constructor\n",
+ " Employee.__init__(self,nm,sal)\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " pass\n",
+ " def display(self):\n",
+ " Employee.display(self)\n",
+ " print 'Employee type: Manager'\n",
+ " \n",
+ "class Programmer(Employee): #derived class declared\n",
+ " def __init__(self, nm, sal,lang): #constructor\n",
+ " Employee.__init__(self,nm,sal)\n",
+ " self.__language=None\n",
+ " if lang!=None:\n",
+ " self.__language=[len(lang)+1]\n",
+ " self.__language=lang\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " pass\n",
+ " \n",
+ " def display(self): #display\n",
+ " Employee.display(self)\n",
+ " print 'Employee type: programmer'\n",
+ " if self.__language==None:\n",
+ " print 'Language known: None specific'\n",
+ " else:\n",
+ " print 'language known: ',self.__language\n",
+ " \n",
+ " \n",
+ "class Secretary(Employee): #derived class declared\n",
+ " def __init__(self, nm, sal,Isteno,typespeed): #constructor\n",
+ " Employee.__init__(self,nm,sal)\n",
+ " self.__steno=Isteno\n",
+ " self.__Typingspeed=typespeed\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " pass\n",
+ " \n",
+ " def display(self): #displaying the characteristic of secretary\n",
+ " Employee.display(self)\n",
+ " print 'Employee type: Secretary'\n",
+ " if self.__steno== False:\n",
+ " print 'Cannot perform job of a steno'\n",
+ " else:\n",
+ " print 'can perform job of a steno'\n",
+ " print 'typing speed is: ',self.__Typingspeed\n",
+ " \n",
+ " \n",
+ " \n",
+ " #objects declared and initialised \n",
+ " \n",
+ "e=[Employee() for j in range(5)]\n",
+ "e[0]=Manager('A. Pal',1000)\n",
+ "e[1]=Programmer('D.Ghosh',6000,'C++')\n",
+ "e[2]=Programmer('R.Das',5000,'Java')\n",
+ "e[3]=Secretary('S.Ray',3000,False,40)\n",
+ "e[4]=Secretary('A.Chatterjee',2500,True,50)\n",
+ "for i in range(5):\n",
+ " e[i].display()\n",
+ "del e[0]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name of the employee: ['A. Pal']\n",
+ "Employee type: Manager\n",
+ "Name of the employee: ['D.Ghosh']\n",
+ "Employee type: programmer\n",
+ "language known: C++\n",
+ "Name of the employee: ['R.Das']\n",
+ "Employee type: programmer\n",
+ "language known: Java\n",
+ "Name of the employee: ['S.Ray']\n",
+ "Employee type: Secretary\n",
+ "Cannot perform job of a steno\n",
+ "typing speed is: 40\n",
+ "Name of the employee: ['A.Chatterjee']\n",
+ "Employee type: Secretary\n",
+ "can perform job of a steno\n",
+ "typing speed is: 50\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter1Overview.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter1Overview.ipynb
new file mode 100755
index 00000000..6ae80ebf
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter1Overview.ipynb
@@ -0,0 +1,123 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:a2620efb94db708e6086d420b3c506261b40f632e20974c274835811d307c6f2"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1 Overview"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 1.1, page no: 21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Hi There\" #displaying"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hi There\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 1.2, page no: 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Hi There\", #displaying\n",
+ "print \"I am Here\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hi There I am Here\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 1.3, page no: 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "num=input(\"Please enter an integer number: \") #user input\n",
+ "print(\"The value you entered is: \"),num,\n",
+ "print(\"and its square is \"),num*num"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter an integer number: 25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value you entered is: 25 and its square is 625\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter2DeclarationsandExpressions.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter2DeclarationsandExpressions.ipynb
new file mode 100755
index 00000000..169bb98a
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter2DeclarationsandExpressions.ipynb
@@ -0,0 +1,244 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:acb52340884de8495a61f4193d51509f25747719e472ce4d24e701adb17c63d5"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2 Declarations and Expressions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 2.1, page no: 41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "SignedInt = c_int(2000000000)\n",
+ "\n",
+ "unsignVar = c_uint(2000000000)\n",
+ "SignedResult=c_int(0)\n",
+ "UnsignedInt=c_uint(0)\n",
+ "\n",
+ "#calculation result exceeds range of permitted values\n",
+ "SignedResult.value = (SignedInt.value * 2) \n",
+ "SignedResult.value =SignedResult.value / 3\n",
+ "\n",
+ "#calculation result is within permissible range\n",
+ "UnsignedResult = (SignedInt.value * 2) / 3;\n",
+ "\n",
+ "print \"Demonstrates wrong result caused by exceeding range\"\n",
+ "print \"Signed Integer Calculation giving result as: \"\n",
+ "print \"(\",SignedInt.value,\n",
+ "print \"*2)/3= \",SignedResult.value\n",
+ "print \"Demonstrates correct result caused by permissible range\"\n",
+ "print \"Unsigned Integer Calculation giving result as: \"\n",
+ "print \"(\",UnsignedInt.value,\n",
+ "print \"*2)/3= \",UnsignedResult"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Demonstrates wrong result caused by exceeding range\n",
+ "Signed Integer Calculation giving result as: \n",
+ "( 2000000000 *2)/3= -98322432\n",
+ "Demonstrates correct result caused by permissible range\n",
+ "Unsigned Integer Calculation giving result as: \n",
+ "( 0 *2)/3= 1333333333\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 2.2, page no: 47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#variable declaraton\n",
+ "a=10\n",
+ "b=5\n",
+ "print 'a= ',a, #printing the values\n",
+ "print ', b= ',b\n",
+ "a=b\n",
+ "print 'a= ',a,\n",
+ "print ', b= ',b\n",
+ "b=7\n",
+ "print 'a= ',a,\n",
+ "print ', b= ',b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a= 10 , b= 5\n",
+ "a= 5 , b= 5\n",
+ "a= 5 , b= 7\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 2.3, page no: 49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#The ++ operator is not available in Python\n",
+ "a=10\n",
+ "b=5\n",
+ "c=15\n",
+ "print 'a= ',a,\n",
+ "print ', b= ',b,\n",
+ "print ', c= ',c\n",
+ "a=a+1 #no preincrement syntax in python\n",
+ "c=a+b\n",
+ "b=b+1\n",
+ "print 'a= ',a,\n",
+ "print ', b= ',b,\n",
+ "print ', c= ',c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a= 10 , b= 5 , c= 15\n",
+ "a= 11 , b= 6 , c= 16\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Program Source Code 2.4, page no: 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=10\n",
+ "b=5\n",
+ "c=15\n",
+ "print 'a= ',a,\n",
+ "print ', b= ',b,\n",
+ "print ', c= ',c #no preincrement syntax in python\n",
+ "c=a+b\n",
+ "a=a+1\n",
+ "b=b+1\n",
+ "print 'a= ',a,\n",
+ "print ', b= ',b,\n",
+ "print ', c= ',c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a= 10 , b= 5 , c= 15\n",
+ "a= 11 , b= 6 , c= 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 2.5, page no: 54"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ " \n",
+ "SignedShort = c_short(30000)\n",
+ "\n",
+ "SignedShort.value=SignedShort.value*10\n",
+ "SignedShort.value=SignedShort.value/10\n",
+ "print 'SignedShort= ',SignedShort.value #wrong answer\n",
+ "\n",
+ "SignedShort=30000\n",
+ "\n",
+ "#result within limits\n",
+ "SignedLong=(c_long)(SignedShort*10)\n",
+ "SignedLong=(c_long)(SignedShort/10)\n",
+ "print 'SignedShort= ',SignedShort #right answer"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "SignedShort= -2768\n",
+ "SignedShort= 30000\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter3Statements.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter3Statements.ipynb
new file mode 100755
index 00000000..e5ccfcb1
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter3Statements.ipynb
@@ -0,0 +1,635 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d0b2f54d8b90df73579d2fb4713e9b1d5d6613dfc23d06e8223dcef9eaa180b2"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3 Statements"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.1, page no: 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "numb = input(\"Enter a number\") #user input\n",
+ "\n",
+ "print 'numb<10 is',int(numb < 10)\n",
+ "print 'numb>10 is',int(numb > 10)\n",
+ "print 'numb==10 is',int(numb == 10),'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "numb<10 is 0\n",
+ "numb>10 is 1\n",
+ "numb==10 is 0 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.2, page no: 67"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=input( 'Please Enter two numbers, a: ') #takes input\n",
+ "b=input('b: ')\n",
+ "\n",
+ "if a>b: #prints which is greater\n",
+ " print a,\n",
+ " print 'is greater' \n",
+ " print b,\n",
+ " print 'is smaller'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please Enter two numbers, a: 30\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "b: 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "30 is greater\n",
+ "20 is smaller\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.3, page no: 69"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=input('Please Enter two numbers, a: ') #takes input\n",
+ "b=input('b: ')\n",
+ "if a>b: \n",
+ " print a,\n",
+ " print 'is greater' \n",
+ " print b,\n",
+ " print 'is smaller'\n",
+ "else:\n",
+ " print b,\n",
+ " print 'is greater' \n",
+ " print a,\n",
+ " print 'is smaller'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please Enter two numbers, a: 20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "b: 30\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "30 is greater\n",
+ "20 is smaller\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.4, page no: 71"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print 'Enter three number, a, b, c:' #user input\n",
+ "a = input()\n",
+ "b = input()\n",
+ "c = input()\n",
+ "\n",
+ "if a==b:\n",
+ " if b==c:\n",
+ " print 'a, b, and c are equal\\n'\n",
+ " \n",
+ "else:\n",
+ " print 'a and b are different\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter three number, a, b, c:\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": [
+ "30\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a and b are different\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.5, page no: 75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "marks=input('Please input the marks obtained out of 100: ') #user input\n",
+ "if marks>=0 and marks<=100: #prints grade according to marks\n",
+ " range=marks / 10\n",
+ " print 'Equivalent letter Grade Award is : ',\n",
+ " if range<=10 and range>=8:\n",
+ " print ' A'\n",
+ " \n",
+ " elif range<8 and range>=7:\n",
+ " print ' B'\n",
+ " \n",
+ " elif range<7 and range>=6:\n",
+ " print ' C'\n",
+ " \n",
+ " elif range<6:\n",
+ " print ' D' \n",
+ "else:\n",
+ " print 'Incorrect range: '\n",
+ " print 'Marks should be within 0 to 100'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input the marks obtained out of 100: 76\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Equivalent letter Grade Award is : B\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.6, page no: 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "count=input('Enter the value of count: ')\n",
+ "while count>0: #while loop \n",
+ " print 'count=',count\n",
+ " count-=1\n",
+ "print 'done'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the value of count: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "count= 5\n",
+ "count= 4\n",
+ "count= 3\n",
+ "count= 2\n",
+ "count= 1\n",
+ "done\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.7, page no: 81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "count=input('Enter the value of count: ')\n",
+ "#no do while loop in python\n",
+ "while True:\n",
+ " print 'count=',count\n",
+ " count-=1\n",
+ " if count==0: #fail condition\n",
+ " break\n",
+ "print 'done'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the value of count: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "count= 5\n",
+ "count= 4\n",
+ "count= 3\n",
+ "count= 2\n",
+ "count= 1\n",
+ "done\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.8, page no: 82"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for i in range(15):\n",
+ " print i*i, #displaying"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0 1 4 9 16 25 36 49 64 81 100 121 144 169 196\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.9, page no: 85"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "count=input('Enter the value of count: ') #user input\n",
+ "for x in range(count): #for loop\n",
+ " print 'count=',count\n",
+ " count-=1\n",
+ "print 'done'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the value of count: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "count= 5\n",
+ "count= 4\n",
+ "count= 3\n",
+ "count= 2\n",
+ "count= 1\n",
+ "done\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.10, page no: 86"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print 'count up'\n",
+ "for i in range(5): #for loop\n",
+ " print i\n",
+ "print 'count down'\n",
+ "i+=1\n",
+ "for i in range(5,-1,-1):\n",
+ " print i\n",
+ "\n",
+ "print 'done'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "count up\n",
+ "0\n",
+ "1\n",
+ "2\n",
+ "3\n",
+ "4\n",
+ "count down\n",
+ "5\n",
+ "4\n",
+ "3\n",
+ "2\n",
+ "1\n",
+ "0\n",
+ "done\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.11, page no: 87"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for i in range(5):\n",
+ " print i #displaying"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n",
+ "1\n",
+ "2\n",
+ "3\n",
+ "4\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.12, page no: 88"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "count=input('Enter the value of count: ') #user input\n",
+ "while True: #while loop\n",
+ " if count<=0:\n",
+ " break\n",
+ " print 'count= ',count\n",
+ " count-=1\n",
+ "print 'done'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the value of count: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "count= 5\n",
+ "count= 4\n",
+ "count= 3\n",
+ "count= 2\n",
+ "count= 1\n",
+ "done\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 3.13, page no: 89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "count1 = input(\"Enter the value of count: \") #user input\n",
+ "\n",
+ "for count1 in range(count1,0,-1):\n",
+ " if count1 == 3:\n",
+ " continue\n",
+ " print 'count =',count1\n",
+ " \n",
+ "print 'done'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the value of count: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "count = 5\n",
+ "count = 4\n",
+ "count = 2\n",
+ "count = 1\n",
+ "done\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter4Array,PointerandStructure.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter4Array,PointerandStructure.ipynb
new file mode 100755
index 00000000..4720cffa
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter4Array,PointerandStructure.ipynb
@@ -0,0 +1,909 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e99725723841b6e891c1e1d29697e0bb89c4c06632a6f1194c68aec646ba1649"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4 Array,Pointer and Structure"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.1, page no: 100"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "SIZE=6\n",
+ "sales=[] #array declared\n",
+ "print 'Please input sales figure for',SIZE,'days' #user input\n",
+ "for i in range(SIZE):\n",
+ " x=input()\n",
+ " sales.append(x)\n",
+ "total=0\n",
+ "for j in range(SIZE):\n",
+ " total+=sales[j]\n",
+ "average=0 \n",
+ "average=total/SIZE\n",
+ "print 'Average Sales=',average"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input sales figure for 6 days\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "352.44\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "867.70\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "781.32\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "867.35\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "746.21\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "189.45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average Sales= 634.078333333\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.2, page no: 102"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "b=[[1,2,3,4],[5,6,7,8],[9,10,11,12]] #2-dimensional array declared\n",
+ "\n",
+ "for i in range(len(b)): #for loop\n",
+ " for j in range(len(b[i])):\n",
+ " print 'b[',i,']',\n",
+ " print '[',j,']=',b[i][j]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "b[ 0 ] [ 0 ]= 1\n",
+ "b[ 0 ] [ 1 ]= 2\n",
+ "b[ 0 ] [ 2 ]= 3\n",
+ "b[ 0 ] [ 3 ]= 4\n",
+ "b[ 1 ] [ 0 ]= 5\n",
+ "b[ 1 ] [ 1 ]= 6\n",
+ "b[ 1 ] [ 2 ]= 7\n",
+ "b[ 1 ] [ 3 ]= 8\n",
+ "b[ 2 ] [ 0 ]= 9\n",
+ "b[ 2 ] [ 1 ]= 10\n",
+ "b[ 2 ] [ 2 ]= 11\n",
+ "b[ 2 ] [ 3 ]= 12\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.3, page no: 104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "DISTRICTS=4\n",
+ "MONTHS=3\n",
+ "sales=[[0] * (DISTRICTS +1)for i in range(MONTHS+1)]\n",
+ "for d in range(DISTRICTS):\n",
+ " for m in range(MONTHS):\n",
+ " print 'Enter sales for district ',d+1,\n",
+ " print 'months',m+1\n",
+ " sales[d][m]=input()\n",
+ "print ' Month'\n",
+ "print ' 1 2 3' \n",
+ "for d in range(DISTRICTS):\n",
+ " print ''\n",
+ " print 'District',d+1,\n",
+ " for m in range(MONTHS):\n",
+ " print ' ',sales[d][m],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sales for district 1 months 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3964.23\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sales for district 1 months 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4135.87\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sales for district 1 months 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4397.98\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sales for district 2 months 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "867.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sales for district 2 months 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "923.59\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sales for district 2 months 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1037.01\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sales for district 3 months 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12.77\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sales for district 3 months 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "378.32\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sales for district 3 months 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "798.22\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sales for district 4 months 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2983.53\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sales for district 4 months 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3903.73\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sales for district 4 months 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9494.98\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Month\n",
+ " 1 2 3\n",
+ "\n",
+ "District 1 3964.23 4135.87 4397.98 \n",
+ "District 2 867.75 923.59 1037.01 \n",
+ "District 3 12.77 378.32 798.22 \n",
+ "District 4 2983.53 3903.73 9494.98\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.4, page no: 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "DISRICTS = 4\n",
+ "MONTHS = 3\n",
+ "\n",
+ "sales = [[1432.07,234.6,654.01],\n",
+ " [327,13838.3,12589.9],\n",
+ " [9328.34,934,4492.3],\n",
+ " [12838.3,2332.63,32.93]]\n",
+ " \n",
+ "print '\\n'\n",
+ "print ' month'\n",
+ "print ' 1 2 3',\n",
+ "\n",
+ "for d in range(DISRICTS):\n",
+ " print '\\nDistrict',d+1,\n",
+ " for m in range(MONTHS):\n",
+ " print '%10.2f' %(sales[d][m]),"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ " month\n",
+ " 1 2 3 \n",
+ "District 1 1432.07 234.60 654.01 \n",
+ "District 2 327.00 13838.30 12589.90 \n",
+ "District 3 9328.34 934.00 4492.30 \n",
+ "District 4 12838.30 2332.63 32.93\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.5, page no: 109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Var1=11\n",
+ "Var2=22.0\n",
+ "Var3=33\n",
+ "print 'main starts at '\n",
+ "print 'Var1 of type int is located at ',(id(Var1)),\n",
+ "print 'having value= ',Var1\n",
+ "print 'Var1 of type double is located at ',(id(Var2)),\n",
+ "print 'having value= ',Var2\n",
+ "print 'Var1 of type int is located at ',(id(Var3)),\n",
+ "print 'having value= ',Var3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "main starts at \n",
+ "Var1 of type int is located at 30963240 having value= 11\n",
+ "Var1 of type double is located at 47572144 having value= 22.0\n",
+ "Var1 of type int is located at 30962712 having value= 33\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.6, page no: 114"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "i=c_int(6)\n",
+ "j=c_int(7)\n",
+ "\n",
+ "ptr=pointer(i)\n",
+ "ptr[0]=10 #*ptr=10\n",
+ "\n",
+ "ptr=pointer(j)\n",
+ "ptr[0]=20 #*ptr=20\n",
+ "\n",
+ "print 'i=',i.value,'j=',j.value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i= 10 j= 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.6a, page no: 115 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import * \n",
+ "\n",
+ "#variable declaration\n",
+ "i=c_int(6)\n",
+ "j=c_int(7)\n",
+ "\n",
+ "\n",
+ "ptri=pointer(i) #*ptri=&i\n",
+ "ptrj=pointer(j)\n",
+ "ptri[0]=10\n",
+ "ptrj[0]=ptri[0]\n",
+ "ptrj=ptri\n",
+ "ptrj[0]=20\n",
+ "print 'i=',i.value,'j=',j.value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i= 20 j= 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.7, page no: 117"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i=c_int(6)\n",
+ "ptri=pointer(i) \n",
+ "pptri=pointer(ptri) #**pptri\n",
+ "\n",
+ "print 'i=',i.value\n",
+ "print '*ptri=',ptri[0]\n",
+ "print '**pptri=',pptri[0][0]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i= 6\n",
+ "*ptri= 6\n",
+ "**pptri= 6\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.8, page no: 121"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import * \n",
+ "iarr=[65,66,67,68] #array declared\n",
+ "ptri=iarr\n",
+ "\n",
+ "\n",
+ "ptrc=POINTER(c_char)\n",
+ "ptrs=POINTER(c_long)\n",
+ "\n",
+ " #type case int to char\n",
+ "for i in range(4): #for loop\n",
+ " print 'ptri[',i,']=',ptri[i] #getting the pointer value\n",
+ "print ''\n",
+ "for i in range(4):\n",
+ " ptrc=pointer(c_char(chr(iarr[i]))) \n",
+ " print 'ptrc[',i,']=',ptrc[0] #getting the pointer value\n",
+ "print ''\n",
+ "\n",
+ "for i in range(4):\n",
+ " ptrc=pointer(c_long(long(iarr[i]))) \n",
+ " print 'ptrs[',i,']=',ptrs[i] #getting the pointer value\n",
+ "print ''"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ptri[ 0 ]= 65\n",
+ "ptri[ 1 ]= 66\n",
+ "ptri[ 2 ]= 67\n",
+ "ptri[ 3 ]= 68\n",
+ "\n",
+ "ptrc[ 0 ]= A\n",
+ "ptrc[ 1 ]= B\n",
+ "ptrc[ 2 ]= C\n",
+ "ptrc[ 3 ]= D\n",
+ "\n",
+ "ptrs[ 0 ]="
+ ]
+ },
+ {
+ "ename": "TypeError",
+ "evalue": "'_ctypes.PyCPointerType' object does not support indexing",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m<ipython-input-1-f102211db7ad>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 18\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[0mptrc\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mpointer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mc_long\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlong\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0miarr\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\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[1;32m---> 20\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[1;34m'ptrs['\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m']='\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mptrs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;31m#getting the pointer value\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 21\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m''\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mTypeError\u001b[0m: '_ctypes.PyCPointerType' object does not support indexing"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.9, page no: 123"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "DateLabel=['Date of birth','Date of anniversary'] #array defined\n",
+ "class DATE: #class date\n",
+ " day=None\n",
+ " month=None\n",
+ " year=None\n",
+ " \n",
+ "DateOfBirth=DATE\n",
+ "DateOfBirth.day=07\n",
+ "DateOfBirth.month=12\n",
+ "DateOfBirth.year=1966\n",
+ "\n",
+ "print 'Date of Birth',':', #printing the characteristics\n",
+ "print DateOfBirth.day,'/',\n",
+ "print DateOfBirth.month,'/',\n",
+ "print DateOfBirth.year\n",
+ "\n",
+ "DatesOfAnniversary=DATE\n",
+ "DatesOfAnniversary.day=11\n",
+ "DatesOfAnniversary.month=07\n",
+ "DatesOfAnniversary.year=1993\n",
+ "\n",
+ "print 'Date Of Anniversary',':', #printing the characteristics\n",
+ "print DatesOfAnniversary.day,'/',\n",
+ "print DatesOfAnniversary.month,'/',\n",
+ "print DatesOfAnniversary.year"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Date of Birth : 7 / 12 / 1966\n",
+ "Date Of Anniversary : 11 / 7 / 1993\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.10, page no: 124"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "DateLabel=['Date of birth','Date of anniversary'] #array declared\n",
+ "class DATE:\n",
+ " day=None\n",
+ " month=None\n",
+ " year=None\n",
+ " \n",
+ "Dates=[DATE() for j in range(2)]\n",
+ "Dates[0].day=7\n",
+ "Dates[0].month=12\n",
+ "Dates[0].year=1966\n",
+ "Dates[1].day=11\n",
+ "Dates[1].month=7\n",
+ "Dates[1].year=1993\n",
+ "\n",
+ "for i in range(2):\n",
+ " print DateLabel[i],':',Dates[i].day,'/',Dates[i].month,'/',Dates[i].year #printing the characteristics\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Date of birth : 7 / 12 / 1966\n",
+ "Date of anniversary : 11 / 7 / 1993\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.11, page no: 125"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "DateLabel=['Date of birth','Date of anniversary'] #array declared\n",
+ "\n",
+ "class DATE: #class date\n",
+ " day=None\n",
+ " month=None\n",
+ " year=None\n",
+ "\n",
+ "DateOfBirth=DATE\n",
+ "DatesOfAnniversary=DATE\n",
+ "\n",
+ "pDates1=DATE()\n",
+ "\n",
+ "\n",
+ "pDates1.day=07\n",
+ "pDates1.month=12\n",
+ "pDates1.year=1966\n",
+ "\n",
+ "print DateLabel[0],':', #printing the characteristics\n",
+ "print pDates1.day,'/',\n",
+ "print pDates1.month,'/',\n",
+ "print pDates1.year\n",
+ "\n",
+ "pDates2=DATE()\n",
+ "pDates2.day=11\n",
+ "pDates2.month=07\n",
+ "pDates2.year=1993\n",
+ "\n",
+ "print DateLabel[1],':', #printing the characteristics\n",
+ "print pDates2.day,'/',\n",
+ "print pDates2.month,'/',\n",
+ "print pDates2.year"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Date of birth : 7 / 12 / 1966\n",
+ "Date of anniversary : 11 / 7 / 1993\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 4.12, page no: 126"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class DATE:\n",
+ " day=None\n",
+ " month=None\n",
+ " year=None\n",
+ "\n",
+ "class PERSON:\n",
+ " name=None\n",
+ " DateOfBirth=DATE\n",
+ " \n",
+ "aPerson=PERSON()\n",
+ "print 'Please input the name of the person: '#user input\n",
+ "aPerson.name=raw_input()\n",
+ "print 'Please input the date of birth of the person: '#user input\n",
+ "aPerson.DateOfBirth.day=input()\n",
+ "aPerson.DateOfBirth.month=input()\n",
+ "aPerson.DateOfBirth.year=input()\n",
+ "\n",
+ "print 'We have got one person whose: '\n",
+ "print 'name is: ',aPerson.name\n",
+ "print 'Date of Birth is: ',aPerson.DateOfBirth.day,'/',aPerson.DateOfBirth.month,'/',aPerson.DateOfBirth.year #printing the characteristics"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input the name of the person: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Soumen\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input the date of birth of the person: \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": [
+ "1991\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "We have got one person whose: \n",
+ "name is: Soumen\n",
+ "Date of Birth is: 5 / 6 / 1991\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter5Functions.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter5Functions.ipynb
new file mode 100755
index 00000000..28eaf14c
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter5Functions.ipynb
@@ -0,0 +1,844 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:18c18a8950d6866dabbc678abd9c440412f60e539895a2291f7c03ee3f45cf8d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5: Functions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.1, page no: 134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def product(x,y): #function product\n",
+ " return x*y\n",
+ "\n",
+ "a=input('Please input a number: ') #user input\n",
+ "b=input('Please input another number: ')\n",
+ "c=product(a,b)\n",
+ "print 'the product of ',a,'and',b,'is',c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input a number: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input another number: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the product of 4 and 5 is 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.2, page no: 135"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def product(x,y): #function product\n",
+ " return x*y\n",
+ "\n",
+ "a=input('Please input a floating point number: ') #user input\n",
+ "b=input('Please input another floating point number: ')\n",
+ "c=product(a,b) #function call\n",
+ "print 'the product of ',a,'and',b,'is',c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input a floating point number: 1.2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input another floating point number: 1.3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the product of 1.2 and 1.3 is 1.56\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.3, page no: 136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def printProduct(x,y): #function product\n",
+ " c=0\n",
+ " c=a*b\n",
+ " print 'The product of ',a,'and',b,'is',c\n",
+ " return\n",
+ "\n",
+ "a=input('Please input an intger: ') #user input\n",
+ "b=input('Please input another integer: ')\n",
+ "c=printProduct(a,b)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input an intger: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input another integer: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The product of 3 and 4 is 12\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.4, page no: 138"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def product(x,y): #function product\n",
+ " return x*y\n",
+ "\n",
+ "a=input('Please input a number: ') #user input\n",
+ "b=input('Please input another number: ')\n",
+ "c=product(a,b)\n",
+ "print 'the product of ',a,'and',b,'is',c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input a number: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input another number: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the product of 4 and 5 is 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.5, page no: 140"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "\n",
+ "i =c_int(4) \n",
+ "j=i\n",
+ "pi=pointer(i)\n",
+ "value=pi[0]\n",
+ "pj=pi[0]\n",
+ "print 'Before incrementing *pi'\n",
+ "print 'i= ',i.value,'j= ',j.value,'*pi= ',pi[0],'*pj= ',pj\n",
+ "pi[0]+=1 #no prefix and postfix in python\n",
+ "pj=pi[0]\n",
+ "print 'After incrementing *pi'\n",
+ "print 'i= ',i.value,'j= ',j.value,'*pi= ',pi[0],'*pj= ',pj"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Before incrementing *pi\n",
+ "i= 4 j= 4 *pi= 4 *pj= 4\n",
+ "After incrementing *pi\n",
+ "i= 5 j= 5 *pi= 5 *pj= 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.6, page no: 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Product(x,y): #function product\n",
+ " return x*y\n",
+ "\n",
+ "print 'Please input two integer: ' #user input\n",
+ "a=input()\n",
+ "b=input()\n",
+ "c=Product(a,b) #call function product\n",
+ "print 'The product of ',a,'and',b,'is',c\n",
+ "\n",
+ "print 'Please input two floating point numbers: '\n",
+ "f=input()\n",
+ "g=input()\n",
+ "h=Product(f,g) #call function product\n",
+ "print 'The product of ',f,'and',g,'is',h"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input two integer: \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 product of 4 and 5 is 20\n",
+ "Please input two floating point numbers: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1.2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2.3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The product of 1.2 and 2.3 is 2.76\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.7, page no: 143"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import*\n",
+ "\n",
+ "def fracval(numerator =0, denominator =1): #function declaration with default parameters\n",
+ " val=(numerator/denominator)\n",
+ " return val\n",
+ "\n",
+ "print 'please input numerator and denominator of a fraction: '\n",
+ "a=input()\n",
+ "b=input()\n",
+ "f=fracval(a,b) #function call\n",
+ "\n",
+ "print 'The fraction value ',a,'/',b,'=',f\n",
+ "\n",
+ "print 'please input the numerator (denominator assumed to be 1: )'\n",
+ "a=input()\n",
+ "f=fracval(a)\n",
+ "print 'The fraction value ',a,'/1','=',f\n",
+ "\n",
+ "print 'And the defaukt fraction value is (num=0, denom=1): '\n",
+ "f=fracval()\n",
+ "print 'the fraction value 0/1=',f"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "please input numerator and denominator of a fraction: \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": [
+ "The fraction value 3 / 4 = 0\n",
+ "please input the numerator (denominator assumed to be 1: )\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The fraction value 3 /1 = 3\n",
+ "And the defaukt fraction value is (num=0, denom=1): \n",
+ "the fraction value 0/1= 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.8, page no: 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(a,b):\n",
+ " temp=a\n",
+ " a=b\n",
+ " b=temp\n",
+ "\n",
+ " \n",
+ "#variable declaration\n",
+ "x=3\n",
+ "y=4\n",
+ "print 'before swap: x= ',x,'y= ',y\n",
+ "swap(x,y)\n",
+ "print 'After swap: x= ',x,'y= ',y"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "before swap: x= 3 y= 4\n",
+ "After swap: x= 3 y= 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.9, page no: 146"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(a,b): #function swap\n",
+ " temp = a\n",
+ " a = b\n",
+ " b = temp\n",
+ " return a,b\n",
+ " \n",
+ "#variable declaration\n",
+ "x=3\n",
+ "y=4\n",
+ "print 'before swap: x= ',x,'y= ',y\n",
+ "x,y=swap(x,y)\n",
+ "print 'After swap: x= ',x,'y= ',y "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "before swap: x= 3 y= 4\n",
+ "After swap: x= 4 y= 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.10, page no: 147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(a,b): #function swap\n",
+ " temp = a\n",
+ " a = b\n",
+ " b = temp\n",
+ " return a,b\n",
+ " \n",
+ "#variable declaration\n",
+ "x=3\n",
+ "y=4\n",
+ "print 'before swap: x= ',x,'y= ',y\n",
+ "x,y=swap(x,y)\n",
+ "print 'After swap: x= ',x,'y= ',y "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "before swap: x= 3 y= 4\n",
+ "After swap: x= 4 y= 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.11, page no: 147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def PrintCharManyTimes(ch,n): #function declarator\n",
+ " for j in range(n): #function body\n",
+ " print ch,\n",
+ " print\n",
+ " \n",
+ "PrintCharManyTimes('-',40) #call to function\n",
+ "print 'Data type Range'\n",
+ "PrintCharManyTimes('=',18) #call to function\n",
+ "print 'Char -128 to 127'\n",
+ "print 'int -32,768 to 32,767'\n",
+ "print 'double -2,147,483,648 to 2,147,483,647'\n",
+ "PrintCharManyTimes('-',40) #call to function"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n",
+ "Data type Range\n",
+ "= = = = = = = = = = = = = = = = = =\n",
+ "Char -128 to 127\n",
+ "int -32,768 to 32,767\n",
+ "double -2,147,483,648 to 2,147,483,647\n",
+ "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.12, page no: 149"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def factfunc(a): #calls itself to calculate factorials\n",
+ " if a>1:\n",
+ " return a * factfunc(a-1)\n",
+ " else:\n",
+ " return 1\n",
+ " \n",
+ "n = input(\"Please input a number: \") #get number from user\n",
+ "fact = factfunc(n) #function call for factorial\n",
+ "print 'Factorial of',n,'! is',fact,'\\n' #dsplay factorial"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input a number: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Factorial of 4 ! is 24 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.13, page no: 152"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "gi=1 #global variable declared\n",
+ "si = 1 #static variable declared\n",
+ "\n",
+ "def func():\n",
+ " global si\n",
+ " i=1\n",
+ " i+=1\n",
+ " si+=1\n",
+ " global gi\n",
+ " gi+=1\n",
+ " \n",
+ " print 'i= ',i,'si= ',si,'gi= ',gi\n",
+ " \n",
+ "for i in range(10):\n",
+ " print '(',i,')Call to func(): ',\n",
+ " gi+=1\n",
+ " func()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "( 0 )Call to func(): i= 2 si= 2 gi= 3\n",
+ "( 1 )Call to func(): i= 2 si= 3 gi= 5\n",
+ "( 2 )Call to func(): i= 2 si= 4 gi= 7\n",
+ "( 3 )Call to func(): i= 2 si= 5 gi= 9\n",
+ "( 4 )Call to func(): i= 2 si= 6 gi= 11\n",
+ "( 5 )Call to func(): i= 2 si= 7 gi= 13\n",
+ "( 6 )Call to func(): i= 2 si= 8 gi= 15\n",
+ "( 7 )Call to func(): i= 2 si= 9 gi= 17\n",
+ "( 8 )Call to func(): i= 2 si= 10 gi= 19\n",
+ "( 9 )Call to func(): i= 2 si= 11 gi= 21\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.14, page no: 154"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def max(x,y): #function defined\n",
+ " if x>y:\n",
+ " return x\n",
+ " else:\n",
+ " return y \n",
+ "\n",
+ "a=5\n",
+ "b=6\n",
+ "c=max(a,b)\n",
+ "\n",
+ "if c==a: # no return by refernce function so declared a simple case\n",
+ " c=8\n",
+ " a=c\n",
+ "elif c==b:\n",
+ " c=8\n",
+ " b=c\n",
+ " \n",
+ "\n",
+ "print 'a=',a,'b=',b,'c=',c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a= 5 b= 8 c= 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.15, page no: 157"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def op1(v): #for displaying numbers\n",
+ " for j in range(len(v)):\n",
+ " print v[j],\n",
+ " \n",
+ "def remove_if(v,x): #for removing elements\n",
+ " for a in v:\n",
+ " if not a%x==0:\n",
+ " v.remove(a)\n",
+ " return v\n",
+ "nos=[10,12,15,20,25,27]\n",
+ "print '(before): ',;op1(nos)\n",
+ "x=5\n",
+ "print ''\n",
+ "nos=remove_if(nos,5)\n",
+ "print '(after): ',;op1(nos)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(before): 10 12 15 20 25 27 \n",
+ "(after): 10 15 20 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Program Source Code 5.16, page no: 158"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def sort(number): #for sorting\n",
+ " size=len(number)\n",
+ " for i in range(size-1 ):\n",
+ " if int(number[i])>int(number[i+1]):\n",
+ " temp=number[i]\n",
+ " number[i]=number[i+1]\n",
+ " number[i+1]=temp\n",
+ " return number\n",
+ " \n",
+ "def op1(v): #for displaying numbers\n",
+ " for j in range(len(v)):\n",
+ " print v[j],\n",
+ " \n",
+ "number=[\"1\",\"12\",\"23\",\"2\"]\n",
+ "\n",
+ "print '(original): ',;op1(number)\n",
+ "\n",
+ "print ''\n",
+ "number=sort(number) # 1st sort\n",
+ "print '(after 1st sort): ',;op1(number)\n",
+ "print ''\n",
+ "\n",
+ "number=sort(number)\n",
+ "print '(after 2nd sort): ',;op1(number) # 2nd sort\n",
+ "print ''"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(original): 1 12 23 2 \n",
+ "(after 1st sort): 1 12 2 23 \n",
+ "(after 2nd sort): 1 2 12 23 \n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter6Preprocessordirectives.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter6Preprocessordirectives.ipynb
new file mode 100755
index 00000000..96c0d0d8
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter6Preprocessordirectives.ipynb
@@ -0,0 +1,150 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5024dce07a05d728e7d0831eea4c105433b851727d0b20000d5575dd27ac5527"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Preprocessor directives"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Program Source Code 6.1, page no: 169"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def concat(a): #macro expansion\n",
+ " return str(a)\n",
+ "\n",
+ "def foot(a): #macro expansion\n",
+ " return str(a)\n",
+ "\n",
+ "p='sport'\n",
+ "b=foot(p)\n",
+ "\n",
+ "#Result\n",
+ "exec(\"print %s\")%concat('b')\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "sport\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Program Source Code 6.2, page no: 172"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "import os\n",
+ "\n",
+ "approot=os.path.dirname(os.path.abspath(sys.argv[0])) #to include file\n",
+ "def line():\n",
+ " line=1\n",
+ " line=2\n",
+ " return line\n",
+ "\n",
+ "print approot,\n",
+ "x-\n",
+ "y+"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "SyntaxError",
+ "evalue": "invalid syntax (<ipython-input-1-fb4ad1541578>, line 11)",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;36m File \u001b[1;32m\"<ipython-input-1-fb4ad1541578>\"\u001b[1;36m, line \u001b[1;32m11\u001b[0m\n\u001b[1;33m x-\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Program Source Code 6.3, page no: 173"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "True=1\n",
+ "False=0\n",
+ "approot=os.path.dirname(os.path.abspath(sys.argv[0])) #filename shown\n",
+ "\n",
+ "def lineno(): #to print lineno\n",
+ " return inspect.currentframe().f_back.f_lineno\n",
+ " \n",
+ "if __debug__: #assertion\n",
+ " print 'assertion error line',lineno(),'file(',os.path.dirname(os.path.abspath(sys.argv[0])),')'\n",
+ " \n",
+ " \n",
+ "assert(True)\n",
+ "i=0\n",
+ "assert(__debug__)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "assertion error line 11 file( C:\\Users\\nita\\Documents\\IPython Notebooks )\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter7StandardCLibraryFunctionsandStandardHeaderFiles.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter7StandardCLibraryFunctionsandStandardHeaderFiles.ipynb
new file mode 100755
index 00000000..0c816120
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter7StandardCLibraryFunctionsandStandardHeaderFiles.ipynb
@@ -0,0 +1,212 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:71a1607f81df85e7f66ec997402b3b0f17b7cc56cc9b8e6e1c153f5dfb4890d1"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7 Standard C Library Functions and Standard Header Files"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 7.1, page no: 179"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import*\n",
+ "\n",
+ "\n",
+ "def lineno(): #to print lineno\n",
+ " return inspect.currentframe().f_back.f_lineno\n",
+ "x=10\n",
+ "print 'First call to assert ' #assert\n",
+ "assert(x==10)\n",
+ "print 'Second call to assert '\n",
+ "\n",
+ "assert(x!=10) #assertion failed\n",
+ "print 'Done '\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First call to assert \n",
+ "Second call to assert \n"
+ ]
+ },
+ {
+ "ename": "AssertionError",
+ "evalue": "",
+ "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-6-9a53f01a2f85>\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'Second call to assert '\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 11\u001b[1;33m \u001b[1;32massert\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m!=\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 12\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m'Done '\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mAssertionError\u001b[0m: "
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 7.2, page no: 181"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "SIZE=3\n",
+ "\n",
+ "str=['ab12cd','34ef56','gh78jk'] #str array declared\n",
+ "\n",
+ "NoofAlphabets=[0,0,0]\n",
+ "temp=0\n",
+ "for i in range(SIZE):\n",
+ " NoofAlphabets[i]=0\n",
+ "\n",
+ " temp=str[i]\n",
+ " for j in range(len(temp)):\n",
+ " if temp[j].isalpha(): #isalpha to find if its alphabet\n",
+ " NoofAlphabets[i]=NoofAlphabets[i]+1\n",
+ " print 'Number of alphabets in string : ',str[i],\n",
+ " print 'is',NoofAlphabets[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of alphabets in string : ab12cd is 4\n",
+ "Number of alphabets in string : 34ef56 is 2\n",
+ "Number of alphabets in string : gh78jk is 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 7.3, page no: 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "import math\n",
+ "\n",
+ "PI=3.1415926535\n",
+ "\n",
+ "x=PI/2.0\n",
+ "y=4.5\n",
+ "z=2.30258093\n",
+ "n=0\n",
+ "print 'sine of PI/2 is',\n",
+ "print int(math.sin(x))\n",
+ "print 'cosine of PI/2 is',\n",
+ "print math.cos(x)\n",
+ "print 'exponent of %.5f'%z,'is',\n",
+ "print math.exp(z)\n",
+ "\n",
+ "#frexp() take single argument and return a pair of values,rather than returning their second return value through output parameters\n",
+ "#therefore no such thing occurs in python\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "sine of PI/2 is 1\n",
+ "cosine of PI/2 is 4.48965921698e-11\n",
+ "exponent of 2.30258 is 9.99995837015\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 7.4, page no: 188"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def sum(first): #function declared to compute the sum\n",
+ " j=1\n",
+ " i=first[0]\n",
+ " s=0\n",
+ " while not i==-1:\n",
+ " s+=i\n",
+ " i=first[j]\n",
+ " j+=1\n",
+ " return s\n",
+ " \n",
+ " \n",
+ "print 'sum is: ',sum([2,3,4,-1]) #function called\n",
+ "print 'sum is: ',sum([5,7,9,11,-1])\n",
+ "print 'sum is: ',sum([-1])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "sum is: 9\n",
+ "sum is: 32\n",
+ "sum is: 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter8DataAbstractionthroughClassesandUser-DefinedDataTypes.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter8DataAbstractionthroughClassesandUser-DefinedDataTypes.ipynb
new file mode 100755
index 00000000..8db5c66a
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter8DataAbstractionthroughClassesandUser-DefinedDataTypes.ipynb
@@ -0,0 +1,809 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:71f6272ff80fba8dd35a6c67e596d2f16e7cd4c25b1ec9c26734fd97740b426d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: Data Abstraction through Classes and User-Defined Data Types"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.1, page no:208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Super:\n",
+ " def __init__(self):\n",
+ " self.__IntegerData=None #private member\n",
+ " #public functions\n",
+ " def SetData(self,i):\n",
+ " self.__IntegerData=i #refer to IntegerData\n",
+ " def ShowData(self):\n",
+ " print \"Data is \",self.__IntegerData,' '\n",
+ "\n",
+ "ob1=Super()\n",
+ "ob2=Super()\n",
+ "ob1.SetData(1000)\n",
+ "ob2.SetData(2000)\n",
+ "ob1.ShowData()\n",
+ "ob2.ShowData()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Data is 1000 \n",
+ "Data is 2000 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.2, page no:211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class X:\n",
+ " def __init__(self):\n",
+ " self.a=None #private members\n",
+ " self.b=None #private members\n",
+ " \n",
+ "#no structure type present in python \n",
+ "x = X()\n",
+ "\n",
+ "x.a=0\n",
+ "x.b=1\n",
+ "print \"x.a=\",x.a,\",x.b=\",x.b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x.a= 0 ,x.b= 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.3, page no:214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ " \n",
+ " def SetValue(self,a,b): #public functions\n",
+ " self.__num=a \n",
+ " self.__denom=b \n",
+ " def GetValue(self,a,b):\n",
+ " a=self.__num\n",
+ " b=self.__denom\n",
+ " \n",
+ "f=Fraction()\n",
+ "n=input(\"Enter n: \") #user input\n",
+ "d=input(\"Enter d: \") #user input\n",
+ "print \"enter the numerator and denominator: \", ' ',n,d\n",
+ "\n",
+ "f.SetValue(n,d) #call function SetValue\n",
+ "print \"Numerator value set: \", ' ',n\n",
+ "print \"Denominator value set: \", ' ',d\n",
+ "f.GetValue(n,d) #call function GetData\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter n: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter d: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter the numerator and denominator: 3 4\n",
+ "Numerator value set: 3\n",
+ "Denominator value set: 4\n",
+ "Numerator value retrieved: 3\n",
+ "Denominator value retrieved: 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.4, page no:216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class SimpleClass:\n",
+ " def __init__(self):\n",
+ " self.__i=None #private member\n",
+ " \n",
+ " def __init__(self):\n",
+ " self.__i=500 #constructor\n",
+ " \n",
+ " def SetData(self,d):\n",
+ " self.__i=d\n",
+ " \n",
+ " def GetData(self):\n",
+ " return self.__i\n",
+ " \n",
+ "#Initializing\n",
+ "s1=SimpleClass()\n",
+ "s2=SimpleClass()\n",
+ "print \"s1 has data: \",s1.GetData()\n",
+ "print \"s2 has data: \",s2.GetData()\n",
+ "s1.SetData(1000) #function call\n",
+ "s2.SetData(2000)\n",
+ "print \"s1 has data: \",s1.GetData(),' '\n",
+ "print \"s2 has data: \", s2.GetData(),' '\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s1 has data: 500\n",
+ "s2 has data: 500\n",
+ "s1 has data: 1000 \n",
+ "s2 has data: 2000 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.5, page no:217"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class SimpleClass:\n",
+ " __IntegerData=None\n",
+ " def __init__(self,data=None):\n",
+ " if data==None:\n",
+ " self.__IntegerData=500 #default constructor\n",
+ " else:\n",
+ " self.__IntegerData=data #parameterised constructor\n",
+ " \n",
+ " def SetData(self,d):\n",
+ " self.__IntegerData=d\n",
+ " \n",
+ " def GetData(self):\n",
+ " return self.__IntegerData\n",
+ " \n",
+ "#Initializing\n",
+ "s1=SimpleClass()\n",
+ "s2=SimpleClass()\n",
+ "s3=SimpleClass(400)\n",
+ "s4=SimpleClass(600)\n",
+ "print \"s1 has data: \",s1.GetData(),' '\n",
+ "print \"s2 has data: \",s2.GetData(),' '\n",
+ "print \"s3 has data: \",s3.GetData(),' '\n",
+ "print \"s4 has data: \",s4.GetData(),' '\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s1 has data: 500 \n",
+ "s2 has data: 500 \n",
+ "s3 has data: 400 \n",
+ "s4 has data: 600 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.6, page no:218"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction: \n",
+ " def_init_num=None #private members\n",
+ " def_init_denom=None #private members\n",
+ " def __init__(self,a=0,b=1):\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " print \"Numerator set inside constructor\",' ',n\n",
+ " print \"Denominator set inside constructor\",' ',d\n",
+ " \n",
+ " def SetValue(self,a,b):\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " def GetValue(self,a,b):\n",
+ " a= self.__num\n",
+ " b= self.__denom\n",
+ " return a,b\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " pass\n",
+ " \n",
+ "n=input(\"Enter n: \") #user input\n",
+ "d=input(\"Enter d: \") #user input\n",
+ "print \"Please enter value of numerator and denominator: \",' ',n,d\n",
+ "f=Fraction(n,d)\n",
+ "f.GetValue(n,d)\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter n: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter d: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter value of numerator and denominator: 3 4\n",
+ "Numerator set inside constructor 3\n",
+ "Denominator set inside constructor 4\n",
+ "Numerator value retrieved: 3\n",
+ "Denominator value retrieved: 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.7, page no:221"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ " \n",
+ " def __init__(self,a=0,b=1): #constructor\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " print \"Numerator set inside constructor: \",self.__num\n",
+ " print \"Denominator set inside constructor: \",self.__denom \n",
+ " \n",
+ " def GetValue(self,a,b):\n",
+ " return self.__num,self.__denom\n",
+ "n=input(\"Enter n: \") #user input\n",
+ "d=input(\"Enter d: \") #user input\n",
+ "print \"Please enter the value of the numerator and denominator: \",n,d\n",
+ "f=Fraction(n,d)\n",
+ "n,d=f.GetValue(n,d)\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d\n",
+ "n=input(\"Please enter the value of numerator only: \")\n",
+ "f1=Fraction(n)\n",
+ "n,d=f1.GetValue(n,d)\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d\n",
+ "print 'ok..now I will create a fraction-no input please'\n",
+ "f2=Fraction()\n",
+ "n,d=f2.GetValue(n,d)\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter n: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter d: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter the value of the numerator and denominator: 3 4\n",
+ "Numerator set inside constructor: 3\n",
+ "Denominator set inside constructor: 4\n",
+ "Numerator value retrieved: 3\n",
+ "Denominator value retrieved: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter the value of numerator only: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numerator set inside constructor: 3\n",
+ "Denominator set inside constructor: 1\n",
+ "Numerator value retrieved: 3\n",
+ "Denominator value retrieved: 1\n",
+ "ok..now I will create a fraction-no input please\n",
+ "Numerator set inside constructor: 0\n",
+ "Denominator set inside constructor: 1\n",
+ "Numerator value retrieved: 0\n",
+ "Denominator value retrieved: 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.8, page no:223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ " def_init_num=None #private members\n",
+ " def_init_denom=None #private members\n",
+ " \n",
+ " def __init__(self,anotherFraction=None): \n",
+ " if anotherFraction==None: #normal constructor\n",
+ " self.__num=anotherFraction\n",
+ " self.__denom=anotherFraction\n",
+ " else: #copy constructor\n",
+ " self.__num=anotherFraction.self.__num\n",
+ " self.__denom=anotherFraction.self.__denom\n",
+ " \n",
+ " \n",
+ " #public functions\n",
+ " def SetValue(self,a,b):\n",
+ " self.__num=a\n",
+ " self.__denom=b#refer to IntegerData\n",
+ " def GetValue(self,a,b):\n",
+ " a=self.__num\n",
+ " b=self.__denom\n",
+ " return a,b\n",
+ " \n",
+ "f=Fraction()\n",
+ "n=input(\"Enter n: \") #user input\n",
+ "d=input(\"Enter d: \") #user input\n",
+ "print \"enter the numerator and denominator: \", ' ',n,d\n",
+ "\n",
+ "f.SetValue(n,d) #call function SetValue\n",
+ "print \"Numerator value set: \", ' ',n\n",
+ "print \"Denominator value set: \", ' ',d\n",
+ "f.GetValue(n,d) #call function GetData\n",
+ "print \"Numerator value retrieved: \", ' ',n\n",
+ "print \"Denominator value retrieved: \", ' ',d\n",
+ "print \"Now a second clone copy is being created: \",''\n",
+ "f1=f\n",
+ "f1.GetValue(n,d)\n",
+ "print \"Clone's numerator value retrieved: \", ' ',n\n",
+ "print \"Clone's denominator value retrieved: \", ' ',d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter n: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter d: 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter the numerator and denominator: 5 6\n",
+ "Numerator value set: 5\n",
+ "Denominator value set: 6\n",
+ "Numerator value retrieved: 5\n",
+ "Denominator value retrieved: 6\n",
+ "Now a second clone copy is being created: \n",
+ "Clone's numerator value retrieved: 5\n",
+ "Clone's denominator value retrieved: 6\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.9, page no:229"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def MyNewHandler():\n",
+ " print \"Sorry operator new failed to allocate memory\"\n",
+ " exit(0)\n",
+ " \n",
+ "def _set_new_handler(s):\n",
+ " s()\n",
+ "#In python there is no in-built _set_new_handler function, so i made this function and passed MyNewHandler function as a parameters\n",
+ "_set_new_handler(MyNewHandler)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sorry operator new failed to allocate memory\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.10, page no:230"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import * \n",
+ "class Fraction: \n",
+ " def __init__(self,a=0,b=1): \n",
+ " if isinstance(a,int): \n",
+ " c = c_int(a) \n",
+ " d = c_int(b) \n",
+ " self.__num = pointer(c) \n",
+ " self.__denom = pointer(d) \n",
+ " print 'constructor sets numerator = ', self.__num[0] , ', denominator = ', self.__denom[0] \n",
+ " else:\n",
+ " c=c_int(a.__num[0])\n",
+ " d = c_int(a.__denom[0])\n",
+ " self.__num = pointer(c) \n",
+ " self.__denom = pointer(d)\n",
+ " print 'copy constructor sets numerator = ', self.__num[0] , ', denominator = ', self.__denom[0] \n",
+ " \n",
+ " def __del__(self): \n",
+ " print 'destructor deallocates numerator = ', self.__num[0] , ', denominator = ', self.__denom[0] \n",
+ " \n",
+ "n = input(\"Please enter values of numerator: \") \n",
+ "d = input(\"Please enter values of denominator: \") \n",
+ "f = Fraction(n,d) \n",
+ "print 'Please enter another set of ' \n",
+ "n = input(\"numerator: \") \n",
+ "d = input(\"denominator: \") \n",
+ "print 'Creating fraction *pf : ' \n",
+ "pf = Fraction(n,d) \n",
+ "print 'Now a clone copy (f2) created from *pf: ' \n",
+ "f2 = Fraction(pf)\n",
+ "print 'Now another clone copy (*pf2) created from f:' \n",
+ "pf2 = Fraction(f) \n",
+ "print '*pf2 is being destroyed:' \n",
+ "del pf2\n",
+ "print '*pf is being destroyed:' \n",
+ "del pf \n",
+ "print 'now objects f2 and f automatically destroyed : '"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter values of numerator: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter values of denominator: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "constructor sets numerator = 3 , denominator = 4\n",
+ "Please enter another set of \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "numerator: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "denominator: 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Creating fraction *pf : \n",
+ "constructor sets numerator = 5 , denominator = 6\n",
+ "Now a clone copy (f2) created from *pf: \n",
+ "copy constructor sets numerator = 5 , denominator = 6\n",
+ "Now another clone copy (*pf2) created from f:\n",
+ "copy constructor sets numerator = 3 , denominator = 4\n",
+ "*pf2 is being destroyed:\n",
+ "*pf is being destroyed:\n",
+ "now objects f2 and f automatically destroyed : \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.11, page no:234"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Memfail(self,s):\n",
+ " print \"Sorry Unable to allocate memory\"\n",
+ " sys.exit(0)\n",
+ "\n",
+ "MAX_SIZE = 60 + 1\n",
+ "\n",
+ "MAX_SIZE=[[0 for col in range(MAX_SIZE)]for row in range(MAX_SIZE)]\n",
+ "nChar=0\n",
+ "chArr=\"Hello\"\n",
+ "\n",
+ "print \"Please input a string( 60 characters max.): \",chArr\n",
+ "\n",
+ "nChar=len(chArr)+1\n",
+ "szStr=chArr\n",
+ "print \"required memory space for\",nChar,\n",
+ "print \"characters\"\n",
+ "chArr=szStr #string copy\n",
+ "szStr=chArr\n",
+ "print \"String copied in allocated space: \",szStr\n",
+ "print \"Memory space dellocated\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please input a string( 60 characters max.): Hello\n",
+ "required memory space for 6 characters\n",
+ "String copied in allocated space: Hello\n",
+ "Memory space dellocated\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.12, page no:236"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ " \n",
+ " def __init__(self,a=0,b=1): #constructor\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " pass\n",
+ " \n",
+ " def GetValue(self,a,b):\n",
+ " a=self.__num\n",
+ " b=self.__denom\n",
+ " return self.__num,self.__denom\n",
+ "n=4\n",
+ "d=5\n",
+ "f=Fraction(4,5)\n",
+ "n,d=f.GetValue(n,d)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 8.13, page no:239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class X:\n",
+ " __sa=20 #initialising static member\n",
+ " a = None\n",
+ " def __init__(self):\n",
+ " self.a=None #public member\n",
+ " def f(self,b):\n",
+ " a=30\n",
+ " print \"Global a= \",b\n",
+ " print \"Local a= \",a\n",
+ " print \"Nonstatic member a= \",self.a\n",
+ " print \"static member sa= \",self.__sa\n",
+ "\n",
+ "a=10\n",
+ "\n",
+ "aXobj=X()\n",
+ "aXobj.a=40\n",
+ "aXobj.f(a)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Global a= 10\n",
+ "Local a= 30\n",
+ "Nonstatic member a= 40\n",
+ "static member sa= 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter9OperatorOverloading.ipynb b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter9OperatorOverloading.ipynb
new file mode 100755
index 00000000..12cad0bc
--- /dev/null
+++ b/C++_and_Object-oriented_Programming_Paradigm_by_Debasish_Jana/Chapter9OperatorOverloading.ipynb
@@ -0,0 +1,424 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:da54693f4a47e29d6add6a87ce31b222819e27a7eec6b27b19e48f41a0d957d8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Operator Overloading"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 9.1, page no: 246"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def gcd(a,b): #function gcd\n",
+ " if a>b:\n",
+ " c=a\n",
+ " a=b\n",
+ " b=c\n",
+ " c=b%a\n",
+ " \n",
+ " while c!=0:\n",
+ " b=a\n",
+ " a=c\n",
+ " c=b%a\n",
+ " return a\n",
+ "\n",
+ "def lcm(a,b): #function lcm\n",
+ " g=gcd(a,b)\n",
+ " l=g*(a/g)*(b/g)\n",
+ " return l\n",
+ "\n",
+ "class Fraction: #class\n",
+ "\n",
+ " def __init__(self,a=0,b=1,anotherfraction=None): \n",
+ " if anotherfraction==None: #normal constructor\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " print 'fraction object (',self.__num,'/',self.__denom,') created'\n",
+ " else: #copy constructor\n",
+ " self.__num=aanotherfraction.self.__num\n",
+ " self.__denom=anotherfraction.self.__denom\n",
+ " print 'fraction object (',self.__num,'/',self.__denom,')created(copy)'\n",
+ " \n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " print 'fraction object (',self.__num,'/',self.__denom,') destroyed' \n",
+ " \n",
+ " \n",
+ " \n",
+ " #Overload +\n",
+ " def __add__(self,operand2):\n",
+ " tmp=Fraction()\n",
+ " l=lcm(self.__denom,operand2.__denom)\n",
+ " tmp.__num=self.__num*(l/self.__denom)+operand2.__num*(l/operand2.__denom)\n",
+ " tmp.__denom=l\n",
+ " g=gcd(tmp.__num,tmp.__denom)\n",
+ " tmp.__num/=g\n",
+ " tmp.__denom/=g\n",
+ " print 'In overloaded Fraction::operator + : ( ',self.__num,'/',self.__denom,') + (',operand2.__num,'/',operand2.__denom,') = (',tmp.__num,'/',tmp.__denom,')'\n",
+ " return tmp\n",
+ " \n",
+ " #overloading = \n",
+ " def __assign__(self,rval):\n",
+ " self.__num=rval.self.__num\n",
+ " self.__denom=rval.self.__denom\n",
+ " print 'In overloaded Fraction::operator = : ( ',rval.self.__num,'/',rval.self.__denom,') -> (',self.__num,'/',self.__denom,')'\n",
+ " return self\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "print 'Please enter values of numerator and denominator:' \n",
+ "n=input()\n",
+ "d=input()\n",
+ "f1=Fraction(n,d)\n",
+ "\n",
+ "print 'Please enter another set of numerator and denominator: '\n",
+ "n=input()\n",
+ "d=input()\n",
+ "f2=Fraction(n,d)\n",
+ "b=f2\n",
+ "f3=Fraction()\n",
+ "f3=f1+f2\n",
+ "f3=f2=f1\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter values of numerator and denominator:\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": [
+ "fraction object ( 3 / 4 ) created\n",
+ "Please enter another set of numerator and denominator: \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": [
+ "fraction object ( 5 / 6 ) created\n",
+ "fraction object ( 0 / 1 ) created\n",
+ "fraction object ( 0 / 1 ) created\n",
+ "In overloaded Fraction::operator + : ( 3 / 4 ) + ( 5 / 6 ) = ( 19 / 12 )\n",
+ "fraction object ( 0 / 1 ) destroyed\n",
+ "fraction object ( 19 / 12 ) destroyed\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 9.2, page no: 265"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Integer: #class defined\n",
+ " def __init__(self,a=None,arg=None): #constructor\n",
+ " if arg==None:\n",
+ " self.__i=a\n",
+ " else:\n",
+ " self.__i=arg.__i\n",
+ " \n",
+ " def __del__(self):\n",
+ " pass\n",
+ " \n",
+ " #Overload +\n",
+ " def __add__(self,arg): \n",
+ " tmp=Integer()\n",
+ " tmp.__i=self.__i + arg.__i #These are integer additions\n",
+ " return tmp \n",
+ " \n",
+ " #Overload assignment\n",
+ " def __assign__(self,arg):\n",
+ " self.__i=arg.__i #These are integer assignments \n",
+ " return self\n",
+ " \n",
+ " #Overload the increment operator\n",
+ " def __iadd__(self,arg):\n",
+ " tmp=Integer()\n",
+ " tmp=self\n",
+ " self.__i+=arg\n",
+ " return self\n",
+ " \n",
+ " def __int(self):\n",
+ " return self.__i\n",
+ "a=5\n",
+ "b=Integer() #object of integer class\n",
+ "b=5\n",
+ "a+=1\n",
+ "a=a+a\n",
+ "a+=1\n",
+ "b=b+1\n",
+ "b=b+b\n",
+ "print 'a=',a\n",
+ "print 'b=',b\n",
+ "\n",
+ "\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a= 13\n",
+ "b= 12\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 9.3, page no: 269"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "class Fraction:\n",
+ " __num=None\n",
+ " __denom=None\n",
+ " def __init__(self,a=0,b=1): #constructor\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " print 'Constructor call: Fraction object (',self.__num,'/',self.__denom,') created'\n",
+ " \n",
+ " def __del__(self):\n",
+ " print 'Fraction object (',self.__num,'/',self.__denom,') destroyed'\n",
+ " \n",
+ " # Python doesn't have >> operator for input so we are just using input function \n",
+ " def input(self):\n",
+ " self.__num = int(raw_input())\n",
+ " self.__denom = int(raw_input())\n",
+ " \n",
+ " \n",
+ " #Python does not use << operator for printing. So here we are just declaring function name as print_ \n",
+ " def _repr_(self):\n",
+ " print 'The fraction is ',\n",
+ " print self.__num , '/', self.__denom\n",
+ " \n",
+ " \n",
+ "f1=Fraction()\n",
+ "print 'Please enter the values of numerator and denominator: '\n",
+ "f1.input()\n",
+ "f1._repr_()\n",
+ "\n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor call: Fraction object ( 0 / 1 ) created\n",
+ "Please enter the values of numerator and denominator: \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": [
+ "The fraction is 3 / 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Program Source Code 9.4, page no: 272"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Fraction:\n",
+ "\n",
+ " def __init__(self,a=0,b=1): \n",
+ " #normal constructor\n",
+ " self.__num=a\n",
+ " self.__denom=b\n",
+ " print 'Constructor Call : fraction object (',self.__num,'/',self.__denom,') created'\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " print 'fraction object (',self.__num,'/',self.__denom,') destroyed' \n",
+ " \n",
+ " def __new__(typ, sz):\n",
+ " print 'Fraction:: operator new called to'\n",
+ " print 'allocate ',sz,'bytes'\n",
+ " return AllocateMem(sz) \n",
+ " \n",
+ "def AllocateMem(sz):\n",
+ " if pm==NULL:\n",
+ " print 'failed to allocate memory'\n",
+ " exit(0)\n",
+ " else:\n",
+ " print 'Memory successfully allocated '\n",
+ " return pm\n",
+ "\n",
+ "def FreeMem(m):\n",
+ " pass\n",
+ "def __new__(typ, *args, **kwargs):\n",
+ " obj = object.__new__(typ, *args, **kwargs)\n",
+ " print 'Global operator new called to'\n",
+ " print 'allocate ',sz,'bytes'\n",
+ " return AllocateMem(sz)\n",
+ " \n",
+ "\n",
+ "pf1=[]*4\n",
+ "pf2=[]\n",
+ "\n",
+ "print 'Memory succesfully allocated'\n",
+ "for i in xrange(4): #allocate array\n",
+ " pf1.append(Fraction())\n",
+ "print 'Memory succesfully allocated'\n",
+ "for i in range(1):\n",
+ " pf2.append(Fraction()) \n",
+ "\n",
+ "del pf2[0] #delete object\n",
+ "print 'Fraction::operator delete called'\n",
+ "\n",
+ "for i in range(3,-1,-1):\n",
+ " del pf1[i] #delete array\n",
+ " \n",
+ "\n",
+ "print 'Global operator delete called'\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Memory succesfully allocated\n",
+ "Constructor Call : fraction object ( 0 / 1 ) created\n",
+ "Constructor Call : fraction object ( 0 / 1 ) created\n",
+ "Constructor Call : fraction object ( 0 / 1 ) created\n",
+ "Constructor Call : fraction object ( 0 / 1 ) created\n",
+ "Memory succesfully allocated\n",
+ "Constructor Call : fraction object ( 0 / 1 ) created\n",
+ "fraction object ( 0 / 1 ) destroyed\n",
+ "Fraction::operator delete called\n",
+ "fraction object ( 0 / 1 ) destroyed\n",
+ "fraction object ( 0 / 1 ) destroyed\n",
+ "fraction object ( 0 / 1 ) destroyed\n",
+ "fraction object ( 0 / 1 ) destroyed\n",
+ "Global operator delete called\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach/screenshots/Untitled00.png b/C_Programming:_A_Modern_Approach/screenshots/Untitled00.png
new file mode 100755
index 00000000..6525342f
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach/screenshots/Untitled00.png
Binary files differ
diff --git a/C_Programming:_A_Modern_Approach/screenshots/Untitled000.png b/C_Programming:_A_Modern_Approach/screenshots/Untitled000.png
new file mode 100755
index 00000000..3f565299
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach/screenshots/Untitled000.png
Binary files differ
diff --git a/C_Programming:_A_Modern_Approach/screenshots/Untitled0000.png b/C_Programming:_A_Modern_Approach/screenshots/Untitled0000.png
new file mode 100755
index 00000000..0bca8b3f
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach/screenshots/Untitled0000.png
Binary files differ
diff --git a/C_Programming:_A_Modern_Approach/screenshots/Untitled0000_1.png b/C_Programming:_A_Modern_Approach/screenshots/Untitled0000_1.png
new file mode 100755
index 00000000..0bca8b3f
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach/screenshots/Untitled0000_1.png
Binary files differ
diff --git a/C_Programming:_A_Modern_Approach/screenshots/Untitled000_1.png b/C_Programming:_A_Modern_Approach/screenshots/Untitled000_1.png
new file mode 100755
index 00000000..3f565299
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach/screenshots/Untitled000_1.png
Binary files differ
diff --git a/C_Programming:_A_Modern_Approach/screenshots/Untitled00_1.png b/C_Programming:_A_Modern_Approach/screenshots/Untitled00_1.png
new file mode 100755
index 00000000..6525342f
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach/screenshots/Untitled00_1.png
Binary files differ
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter10.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter10.ipynb
new file mode 100755
index 00000000..dcc36e8b
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter10.ipynb
@@ -0,0 +1,755 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:89fb3fef5984e311e1eb6ac1f3a0c24d3e369a1266fe562ec873d32c24f96971"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10: Program Organization"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 219"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def sum_digits(n):\n",
+ " sum = 0 #local variable\n",
+ " while(n>0):\n",
+ " sum =sum+(n%10)\n",
+ " n=n/10\n",
+ " return sum\n",
+ "#sum_digits(10)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 1,
+ "text": [
+ "1"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "STACK_SIZE=100\n",
+ "contents=[None]*STACK_SIZE\n",
+ "top=0\n",
+ "def make_empty():\n",
+ " top=0\n",
+ "def is_empty():\n",
+ " return top==0\n",
+ "def is_full():\n",
+ " return top==STACK_SIZE\n",
+ "def push(i):\n",
+ " if(is_full()):\n",
+ " call_stackoverflow=0\n",
+ " #stack_overflow()\n",
+ " else:\n",
+ " contents[top+1]=i\n",
+ "def pop():\n",
+ " if(is_empty()):\n",
+ " call_stackoverflow=0\n",
+ " #stack_underflow()\n",
+ " else:\n",
+ " return contents[top-1]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example guess.c, Page 224"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import random\n",
+ "MAX_NUMBER=100\n",
+ "#def initialize_number_generator():\n",
+ "def choose_new_secret_number():\n",
+ " secret_number=random.randint(1,MAX_NUMBER) #generate random number\n",
+ " return secret_number\n",
+ "def read_guesses():\n",
+ " num_guesses=0\n",
+ " while(1):\n",
+ " num_guesses=num_guesses+1\n",
+ " guess=int(raw_input(\"Enter guess: \")) #guesses\n",
+ " if(guess==secret_number):\n",
+ " print \"You have won in %d guesses: \"%num_guesses\n",
+ " print \"\"\n",
+ " return\n",
+ " elif (guess<secret_number):\n",
+ " print \"Too low, try again\"\n",
+ " else:\n",
+ " print \"Too high, try again\"\n",
+ "print \"Guess the secret number between 1 and %d.\"%MAX_NUMBER\n",
+ "print \"\"\n",
+ "secret_number=choose_new_secret_number()\n",
+ "print \"A new number has been chosen.\"\n",
+ "read_guesses()\n",
+ "command=raw_input( \"Play again? (Y/N) \")\n",
+ "while(command=='y' or command=='Y'):\n",
+ " secret_number=choose_new_secret_number()\n",
+ " print \"A new number has been chosen\"\n",
+ " read_guesses()\n",
+ " command=raw_input( \"Play again? (Y/N) \") \n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Guess the secret number between 1 and 100.\n",
+ "\n",
+ "A new number has been chosen.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 55\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 88\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too high, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 80\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 85\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 86\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You have won in 6 guesses: \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Play again? (Y/N) y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "A new number has been chosen\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 70\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 90\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 95\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 99\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too high, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 97\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 98\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You have won in 7 guesses: \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Play again? (Y/N) n\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example guess2.c, Page 226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import random\n",
+ "MAX_NUMBER=100\n",
+ "#def initialize_number_generator():\n",
+ "def new_secret_number():\n",
+ " return (random.randint(1,MAX_NUMBER))#generate random number\n",
+ "def read_guesses(secret_number):\n",
+ " num_guesses=0\n",
+ " while(1): #guesses\n",
+ " num_guesses=num_guesses+1\n",
+ " guess=int(raw_input(\"Enter guess: \"))\n",
+ " if(guess==secret_number):\n",
+ " print \"You have won in %d guesses: \"%num_guesses\n",
+ " print \"\"\n",
+ " return\n",
+ " elif (guess<secret_number):\n",
+ " print \"Too low, try again\"\n",
+ " else:\n",
+ " print \"Too high, try again\"\n",
+ "print \"Guess the secret number between 1 and %d.\"%MAX_NUMBER\n",
+ "print \"\"\n",
+ "secret_number=new_secret_number()\n",
+ "print \"A new number has been chosen.\"\n",
+ "read_guesses(secret_number)\n",
+ "command=raw_input( \"Play again? (Y/N) \")\n",
+ "while(command=='y' or command=='Y'):\n",
+ " secret_number=new_secret_number()\n",
+ " print \"A new number has been chosen\"\n",
+ " read_guesses(secret_number)\n",
+ " command=raw_input( \"Play again? (Y/N) \") \n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Guess the secret number between 1 and 100.\n",
+ "\n",
+ "A new number has been chosen.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 55\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 88\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too high, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 66\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 77\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 83\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too high, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 80\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too high, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 79\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too high, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 78\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You have won in 8 guesses: \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Play again? (Y/N) n\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example poker.c, Page 233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "pairs=0\n",
+ "\n",
+ "def read_cards():\n",
+ " cards_read=0\n",
+ " card_exists = [[False for i in xrange(NUM_SUITS)] for i in xrange(NUM_RANKS)]\n",
+ " while(cards_read<NUM_CARDS):\n",
+ " bad_card=False\n",
+ " cardd=raw_input(\"Enter a card\")\n",
+ " a = cardd.split()\n",
+ " rank_ch=a[0]\n",
+ " suit_ch=a[1]\n",
+ " if (rank_ch=='0'):\n",
+ " exit(EXIT_SUCCESS)\n",
+ " elif(rank_ch=='2'):\n",
+ " rank=0\n",
+ " elif(rank_ch=='3'):\n",
+ " rank=1\n",
+ " elif(rank_ch=='4'):\n",
+ " rank=2\n",
+ " elif(rank_ch=='5'):\n",
+ " rank=3\n",
+ " elif(rank_ch=='6'):\n",
+ " rank=4\n",
+ " elif(rank_ch=='7'):\n",
+ " rank=5\n",
+ " elif(rank_ch=='8'):\n",
+ " rank=6\n",
+ " elif(rank_ch=='9'):\n",
+ " rank=7\n",
+ " elif(rank_ch=='t' or rank_ch=='T'):\n",
+ " rank=8\n",
+ " elif(rank_ch=='j' or rank_ch=='J'):\n",
+ " rank=9\n",
+ " elif(rank_ch=='q' or rank_ch=='Q'):\n",
+ " rank=10\n",
+ " elif(rank_ch=='k' or rank_ch=='K'):\n",
+ " rank=11\n",
+ " elif(rank_ch=='a' or rank_ch=='A'):\n",
+ " rank=12\n",
+ " else:\n",
+ " bad_card=True\n",
+ " if(suit_ch=='c'or suit_ch=='C'):\n",
+ " suit=0\n",
+ " elif(suit_ch=='d' or suit_ch=='D'):\n",
+ " suit=1\n",
+ " elif(suit_ch=='h' or suit_ch=='H'):\n",
+ " suit=1\n",
+ " elif(suit_ch=='s' or suit_ch=='S'):\n",
+ " suit=1\n",
+ " else:\n",
+ " bad_card=True\n",
+ " if(bad_card):\n",
+ " print \"Bad card; ignored\"\n",
+ " elif (card_exists[rank][suit]):\n",
+ " print \"Duplicate card; ignored\"\n",
+ " else:\n",
+ " num_in_rank[rank]=num_in_rank[rank]+1\n",
+ " num_in_suit[suit]=num_in_suit[suit]+1\n",
+ " card_exists[rank][suit]=True\n",
+ " cards_read=cards_read+1\n",
+ "\n",
+ "def analyse_hand():\n",
+ " num_consec=0\n",
+ " for suit in range(NUM_SUITS):\n",
+ " if(num_in_suit[suit]==NUM_CARDS):\n",
+ " flush=True\n",
+ " rank=0\n",
+ " while(num_in_rank[rank]==0):\n",
+ " rank=rank+1\n",
+ " while(rank<NUM_RANKS and num_in_rank[rank]>0):\n",
+ " num_consec=num_consec+1\n",
+ " rank=rank+1\n",
+ " if(num_consec==NUM_CARDS):\n",
+ " straight=True\n",
+ " return\n",
+ " for rank in range(NUM_RANKS):\n",
+ " if(num_in_rank[rank]==4):\n",
+ " four=True\n",
+ " if(num_in_rank[rank]==3):\n",
+ " three=True\n",
+ " if(num_in_rank[rank]==2):\n",
+ " pairs=pairs+1\n",
+ " \n",
+ "def print_result():\n",
+ " if(straight==True and flush==True):\n",
+ " print \"Straight flush\"\n",
+ " elif(four):\n",
+ " print \"Four of a kind\"\n",
+ " elif(three==True and pairs==1):\n",
+ " print \"Full house\"\n",
+ " elif(flush):\n",
+ " print \"Flush\"\n",
+ " elif(straight):\n",
+ " print \"Straight\"\n",
+ " elif(three):\n",
+ " print \"Three of a kind\"\n",
+ " elif(pairs==2):\n",
+ " print \"Two pairs\"\n",
+ " elif(pairs==1):\n",
+ " print \"Pair\"\n",
+ " else:\n",
+ " print \"High card\"\n",
+ " print \"\"\n",
+ " \n",
+ "while(1):\n",
+ " straight=False\n",
+ " flush=False\n",
+ " four=False\n",
+ " three=False\n",
+ " NUM_RANKS=13\n",
+ " NUM_SUITS=4\n",
+ " NUM_CARDS=5\n",
+ " num_in_rank=[0]*NUM_RANKS\n",
+ " num_in_suit=[0]*NUM_SUITS\n",
+ "\n",
+ " read_cards()\n",
+ " analyse_hand()\n",
+ " print_result()\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a card2 s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a card5 s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a card4 s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a card3 s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a card6 s\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "High card\n",
+ "\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter11.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter11.ipynb
new file mode 100755
index 00000000..ce091d42
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter11.ipynb
@@ -0,0 +1,81 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:74e91fb616db3aa96bac711fa075c7c19a951b52d2e8ba98c61929ac216b2aca"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Pointers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example maxmin.c, Page 250"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "N=10\n",
+ "def max_min(a,n): #function definition\n",
+ " max=a[0]\n",
+ " min=a[0]\n",
+ " for i in range(n-1): #calculating max and min from list\n",
+ " if(a[i+1]>max):\n",
+ " max=a[i+1]\n",
+ " elif(a[i+1]<min):\n",
+ " min=a[i+1]\n",
+ " return (max,min)\n",
+ "li=raw_input(\"Enter %d numbers: \" % N) #input of numbers from user\n",
+ "b=map(int, li.split())\n",
+ "big,small=max_min(b,N) #call function to calculate max and min\n",
+ "print \"Largest: %d\"%big #print max and min\n",
+ "print \"Smallest: %d\"%small\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 10 numbers: 34 82 49 102 7 94 23 11 50 31\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Largest: 102\n",
+ "Smallest: 7\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter12.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter12.ipynb
new file mode 100755
index 00000000..a6dddf65
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter12.ipynb
@@ -0,0 +1,71 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:2d5527cee2d14f67c2f5fd4cdfcbb27ae6cb62aa3eec37f9815dae10c6c114db"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12: Pointers and Arrays"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example reverse3.c, Page 264"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "N=10\n",
+ "li = raw_input(\"Enter %d numbers: \" % N) #accepting input in list\n",
+ "a = map(int, li.split()) \n",
+ "print \"In reverse order: \",\n",
+ "for i in a[::-1]: #print reversed list\n",
+ " print i,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 10 numbers: 34 82 49 102 7 94 23 11 50 31\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In reverse order: 31 50 11 23 94 7 102 49 82 34\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter13.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter13.ipynb
new file mode 100755
index 00000000..03c83450
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter13.ipynb
@@ -0,0 +1,127 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:00fb09fcd8819c39a88f9cac94eaa93d1e9e72c864c95cc17c2c19aa93c94143"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13: Strings"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example remind.c, Page 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_REMIND=50\n",
+ "MSG_LEN=60\n",
+ "reminders = [['' for i in xrange(MSG_LEN+3)] for i in xrange(MAX_REMIND)]\n",
+ "num_remind=0\n",
+ "while(1):\n",
+ " if(num_remind==MAX_REMIND):\n",
+ " print \"--No space left --\"\n",
+ " break\n",
+ " li=raw_input( \"Enter day and reminder: \")\n",
+ " li1=li.split()\n",
+ " day_str=li1[0]\n",
+ " if(day_str=='0'):\n",
+ " break\n",
+ " msg_str=li1[1:]\n",
+ " i=0\n",
+ " for i in range(num_remind):\n",
+ " if(day_str<reminders[i]):\n",
+ " break\n",
+ " j=num_remind\n",
+ " while(j>i):\n",
+ " reminders[j]=reminders[j-1]\n",
+ " j=j-1\n",
+ " reminders[i]=day_str\n",
+ " reminders[i]=str(reminders[i])+str(msg_str)\n",
+ " \n",
+ " num_remind=num_remind+1\n",
+ "print \"\"\n",
+ "print \"Day Reminder\"\n",
+ "for i in range(num_remind):\n",
+ " print \"%s\"%reminders[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example planet.c, Page 303"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NUM_PLANETS=9\n",
+ "li=raw_input()\n",
+ "argv=li.split()\n",
+ "planets=['Mercury','Venus','Earth','Mars','Jupiter','Saturn','Uranus','Neptune','Pluto']\n",
+ "argc=len(argv)\n",
+ "for i in range(argc-1):\n",
+ " for j in range(NUM_PLANETS):\n",
+ " if( argv[i+1]==planets[j]):\n",
+ " print \"%s is a planet %d\"%(argv[i+1],(j+1))\n",
+ " break\n",
+ " if(argv[i] not in planets):\n",
+ " print \"%s is not a planet\"%argv[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "planet Jupiter Venus Earth fred\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Jupiter is a planet 5\n",
+ "planet is not a planet\n",
+ "Venus is a planet 2\n",
+ "Earth is a planet 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter15.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter15.ipynb
new file mode 100755
index 00000000..8429721c
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter15.ipynb
@@ -0,0 +1,83 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:66fb80b57a6473ffca1e8f425382d8ae7bda3cbb5a42b72a09573b1379da5aa8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 15: Writing Large Programs"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example justify.c, Page 359\n",
+ "Other files- word.h, line.h, word.c, line.c"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import textwrap\n",
+ "quote2=''\n",
+ "quote= (' C is quirky, flawed, and an '\n",
+ " 'enormous success. Although accidents of history '\n",
+ " ' surely helped, it evidently satisfied a need '\n",
+ " ''\n",
+ " 'for a system implementation language efficient '\n",
+ " 'enough to displace assembly language, '\n",
+ " ' yet sufficiently abstract and fluent to describe '\n",
+ " ' algorithms and interactions in a wide variety '\n",
+ " 'of environments.'\n",
+ " ' -- Dennis M. Ritchie')\n",
+ "for i in quote:\n",
+ " if (len(i)>20):\n",
+ " i=(i[:20] + '*')\n",
+ " quote2=quote2+i\n",
+ "quote2=' '.join(quote2.split()) \"\"\"Python has inbuilt functions for removing \n",
+ "white spaces and textwrap, justifying text hence reduces the amount of code as required in C\"\"\"\n",
+ "quotee= textwrap.fill(quote2)\n",
+ "print quotee"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C is quirky, flawed, and an enormous success. Although accidents of\n",
+ "history surely helped, it evidently satisfied a need for a system\n",
+ "implementation language efficient enough to displace assembly\n",
+ "language, yet sufficiently abstract and fluent to describe algorithms\n",
+ "and interactions in a wide variety of environments. -- Dennis M.\n",
+ "Ritchie\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter16.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter16.ipynb
new file mode 100755
index 00000000..20e3b1e5
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter16.ipynb
@@ -0,0 +1,180 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:9fe9374bd25aac8dfc98eab84988bb008dcfb464faf94260bebab61ae764fb98"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16: Structures, Unions and Enumerations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example inventory.c, Page 391"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NAME_LEN=25\n",
+ "MAX_PARTS=100\n",
+ "num_parts=0\n",
+ "number1=[0]*100\n",
+ "on_hand1=[0]*100\n",
+ "name1=[0]*100\n",
+ "def find_part(number):\n",
+ " i=0\n",
+ " for i in range (i,num_parts):\n",
+ " if(number1[i]==number):\n",
+ " return i\n",
+ " return -1\n",
+ "def insert():\n",
+ " num_parts=0\n",
+ " if(num_parts==MAX_PARTS):\n",
+ " print \"Database is full, cant add more parts\"\n",
+ " return\n",
+ " part_number=int(raw_input(\"Enter part number: \"))\n",
+ " if(find_part(part_number)>=0):\n",
+ " print \"Part already exists\"\n",
+ " return\n",
+ " number1[num_parts]=part_number\n",
+ " name1[num_parts]=raw_input(\"Enter part name: \")\n",
+ " on_hand1[num_parts]=raw_input(\"Enter quality on hand: \")\n",
+ " num_parts=num_parts+1\n",
+ " \n",
+ "def search():\n",
+ " number=int(raw_input(\"Enter part number: \"))\n",
+ " i=find_part(number)\n",
+ " if(i>=0):\n",
+ " print \"Part name: %s\" %name1[i]\n",
+ " print \"Quantity on hand: %d\"%on_hand1[i]\n",
+ " else:\n",
+ " print \"Part not found\"\n",
+ " \n",
+ "def update():\n",
+ " number=int(raw_input(\"Enter part number: \"))\n",
+ " i=find_part(number)\n",
+ " if(i>=0):\n",
+ " change=int(raw_input(\"Enter change in quantity on hand: \")) \n",
+ " on_hand1[i]=on_hand1[i]+change\n",
+ " else:\n",
+ " print \"Part not found\"\n",
+ "\n",
+ "while(1):\n",
+ " code=raw_input(\"Enter operation code: \")\n",
+ " if code=='i':\n",
+ " insert()\n",
+ " break\n",
+ " elif code=='s':\n",
+ " search()\n",
+ " break\n",
+ " elif code=='u':\n",
+ " update()\n",
+ " break\n",
+ " elif(code=='p'):\n",
+ " print()\n",
+ " break\n",
+ "\n",
+ "print \"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter operation code: i\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part number: 528\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part name: Disk Drive\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter quality on hand: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example readline.c, Page 395"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def read_line(str,n):\n",
+ " ch=0\n",
+ " i=0\n",
+ " EOF='\\n'\n",
+ " ch=raw_input()\n",
+ " while(isspace(ch)):\n",
+ " donothing=0\n",
+ " while(ch!='\\n' and ch!=EOF):\n",
+ " if(i<n):\n",
+ " str[i+1]=ch\n",
+ " ch=raw_input()\n",
+ " str[i]='\\0'\n",
+ " return i"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter17.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter17.ipynb
new file mode 100755
index 00000000..f25aa999
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter17.ipynb
@@ -0,0 +1,268 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8ebda07d5e13c6b4a8132b67344e9246eeb8703f2dcc433e1b4e350db4cace07"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 17: Advanced Uses of Pointers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example remind2.c, Page 418"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_REMIND=50\n",
+ "MSG_LEN=60\n",
+ "reminders = [['' for i in xrange(MSG_LEN+3)] for i in xrange(MAX_REMIND)]\n",
+ "num_remind=0\n",
+ "while(1):\n",
+ " if(num_remind==MAX_REMIND):\n",
+ " print \"--No space left --\"\n",
+ " break\n",
+ " li=raw_input( \"Enter day and reminder: \")\n",
+ " li1=li.split()\n",
+ " day_str=li1[0]\n",
+ " if(day_str=='0'):\n",
+ " breakb n\n",
+ " msg_str=li1[1:]\n",
+ " i=0\n",
+ " for i in range(num_remind):\n",
+ " if(day_str<reminders[i]):\n",
+ " break\n",
+ " j=num_remind\n",
+ " while(j>i):\n",
+ " reminders[j]=reminders[j-1]\n",
+ " j=j-1\n",
+ " reminders[i]=day_str\n",
+ " reminders[i]=str(reminders[i])+str(msg_str)\n",
+ " \n",
+ " num_remind=num_remind+1\n",
+ "print \"\"\n",
+ "print \"Day Reminder\"\n",
+ "for i in range(num_remind):\n",
+ " print \"%s\"%reminders[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example inventory2.c, Page 434"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NAME_LEN=25\n",
+ "MAX_PARTS=100\n",
+ "num_parts=0\n",
+ "number1=[0]*100\n",
+ "on_hand1=[0]*100\n",
+ "name1=[0]*100\n",
+ "def find_part(number):\n",
+ " i=0\n",
+ " for i in range (i,num_parts):\n",
+ " if(number1[i]==number):\n",
+ " return i\n",
+ " return -1\n",
+ "def insert():\n",
+ " num_parts=0\n",
+ " if(num_parts==MAX_PARTS):\n",
+ " print \"Database is full, cant add more parts\"\n",
+ " return\n",
+ " part_number=int(raw_input(\"Enter part number: \"))\n",
+ " if(find_part(part_number)>=0):\n",
+ " print \"Part already exists\"\n",
+ " return\n",
+ " number1[num_parts]=part_number\n",
+ " name1[num_parts]=raw_input(\"Enter part name: \")\n",
+ " on_hand1[num_parts]=raw_input(\"Enter quality on hand: \")\n",
+ " num_parts=num_parts+1\n",
+ " \n",
+ "def search():\n",
+ " number=int(raw_input(\"Enter part number: \"))\n",
+ " i=find_part(number)\n",
+ " if(i>=0):\n",
+ " print \"Part name: %s\" %name1[i]\n",
+ " print \"Quantity on hand: %d\"%on_hand1[i]\n",
+ " else:\n",
+ " print \"Part not found\"\n",
+ " \n",
+ "def update():\n",
+ " number=int(raw_input(\"Enter part number: \"))\n",
+ " i=find_part(number)\n",
+ " if(i>=0):\n",
+ " change=int(raw_input(\"Enter change in quantity on hand: \")) \n",
+ " on_hand1[i]=on_hand1[i]+change\n",
+ " else:\n",
+ " print \"Part not found\"\n",
+ "\n",
+ "while(1):\n",
+ " code=raw_input(\"Enter operation code: \")\n",
+ " if code=='i':\n",
+ " insert()\n",
+ " break\n",
+ " elif code=='s':\n",
+ " search()\n",
+ " break\n",
+ " elif code=='u':\n",
+ " update()\n",
+ " break\n",
+ " elif(code=='p'):\n",
+ " print()\n",
+ " break\n",
+ "\n",
+ "print \"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tabulate.c, Page 444"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "initial=float(raw_input(\"Enter initial value: \"))\n",
+ "final=float(raw_input(\"Enter final value: \"))\n",
+ "increment=float(raw_input(\"Enter increment: \"))\n",
+ "print \"\"\n",
+ "print \" x cos(x)\"\n",
+ "print \"-------------------------\"\n",
+ "\n",
+ "def tabulatec( first, last, incr):\n",
+ " num_intervals=int(math.ceil((last-first)/incr))\n",
+ " for i in range(num_intervals):\n",
+ " x=first+i*incr\n",
+ " print \"%10.5f %10.5f\"%(x,math.cos(x))\n",
+ "def tabulates( first, last, incr):\n",
+ " num_intervals=int(math.ceil((last-first)/incr))\n",
+ " for i in range(num_intervals):\n",
+ " x=first+i*incr\n",
+ " print \"%10.5f %10.5f\"%(x,math.sin(x))\n",
+ "def tabulatet( first, last, incr):\n",
+ " num_intervals=int(math.ceil((last-first)/incr))\n",
+ " for i in range(num_intervals):\n",
+ " x=first+i*incr\n",
+ " print \"%10.5f %10.5f\"%(x,math.tan(x))\n",
+ "\n",
+ " \n",
+ "tabulatec(initial,final, increment)\n",
+ "print \"\"\n",
+ "print \" x sin(x)\"\n",
+ "print \"\"\n",
+ "print \"-------------------------\"\n",
+ "tabulates(initial,final, increment)\n",
+ "print \"\"\n",
+ "print \" x tan(x)\"\n",
+ "print \"\"\n",
+ "print \"-------------------------\"\n",
+ "tabulatet(initial,final, increment)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter initial value: 0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter final value: .5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter increment: .1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " x cos(x)\n",
+ "--------------------------\n",
+ " 0.00000 1.00000\n",
+ " 0.10000 0.99500\n",
+ " 0.20000 0.98007\n",
+ " 0.30000 0.95534\n",
+ " 0.40000 0.92106\n",
+ "\n",
+ " x sin(x)\n",
+ "\n",
+ "-------------------------\n",
+ " 0.00000 0.00000\n",
+ " 0.10000 0.09983\n",
+ " 0.20000 0.19867\n",
+ " 0.30000 0.29552\n",
+ " 0.40000 0.38942\n",
+ "\n",
+ " x tan(x)\n",
+ "\n",
+ "-------------------------\n",
+ " 0.00000 0.00000\n",
+ " 0.10000 0.10033\n",
+ " 0.20000 0.20271\n",
+ " 0.30000 0.30934\n",
+ " 0.40000 0.42279\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter19.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter19.ipynb
new file mode 100755
index 00000000..42d5374c
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter19.ipynb
@@ -0,0 +1,322 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:6b5cf549b3fdac88be0a759d2fc29d02814154da669e9ab30e73ad0c8e2bbf9e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 19: Program Design"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example stack1.c, Page 488. Other files- stack.h\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "STACK_SIZE=100\n",
+ "contents=[None]*STACK_SIZE\n",
+ "top=0\n",
+ "def terminate(message):\n",
+ " print message\n",
+ " sys.exit()\n",
+ "def make_empty():\n",
+ " top=0\n",
+ "def is_empty():\n",
+ " if(top==0):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def is_full():\n",
+ " if(top==STACK_SIZE):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def push(i):\n",
+ " if(is_full()):\n",
+ " terminate(\"Error in push: stack is full.\")\n",
+ " contents[top+1]=i\n",
+ "def pop():\n",
+ " if(is_empty()):\n",
+ " terminate(\"Error in push: stack is empty.\")\n",
+ " return contents[top-1]\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example stack2.c, Page 489"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "STACK_SIZE=100\n",
+ "contents=[None]*STACK_SIZE\n",
+ "top=0\n",
+ "def terminate(message):\n",
+ " print message\n",
+ " sys.exit()\n",
+ "def make_empty():\n",
+ " top=0\n",
+ "def is_empty():\n",
+ " if(top==0):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def is_full():\n",
+ " if(top==STACK_SIZE):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def push(i):\n",
+ " if(is_full()):\n",
+ " terminate(\"Error in push: stack is full.\")\n",
+ " contents[top+1]=i\n",
+ "def pop():\n",
+ " if(is_empty()):\n",
+ " terminate(\"Error in push: stack is empty.\")\n",
+ " return contents[top-1]\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example stackclient.c, Page 494"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Stack:\n",
+ " def __init__(self):\n",
+ " self.items = []\n",
+ " def is_empty(self):\n",
+ " return self.items == []\n",
+ " def push(self, item):\n",
+ " self.items.append(item)\n",
+ " def pop(self):\n",
+ " return self.items.pop()\n",
+ " def size(self):\n",
+ " return len(self.items)\n",
+ " def make_empty(self):\n",
+ " while len(self.items) > 0 : self.items.pop()\n",
+ "s1=Stack()\n",
+ "s2=Stack()\n",
+ "s1.push(1)\n",
+ "s1.push(2)\n",
+ "n=s1.pop()\n",
+ "print \"Popped %d from s1\"%n\n",
+ "s2.push(n)\n",
+ "n=s1.pop()\n",
+ "print \"Popped %d from s1\"%n\n",
+ "s2.push(n)\n",
+ "while(s2.is_empty()!=True):\n",
+ " print \"Popped %d from s2\"%s2.pop()\n",
+ "s2.push(3)\n",
+ "s2.make_empty()\n",
+ "if(s2.is_empty()):\n",
+ " print \"s2 is empty\"\n",
+ "else:\n",
+ " print \"s2 is not empty\"\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Popped 2 from s1\n",
+ "Popped 1 from s1\n",
+ "Popped 1 from s2\n",
+ "Popped 2 from s2\n",
+ "s2 is empty\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example stackADT.c, Page 495"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "STACK_SIZE=100\n",
+ "contents=[None]*STACK_SIZE\n",
+ "top=0\n",
+ "def terminate(message):\n",
+ " print message\n",
+ " sys.exit()\n",
+ "def make_empty():\n",
+ " top=0\n",
+ "def is_empty():\n",
+ " if(top==0):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def is_full():\n",
+ " if(top==STACK_SIZE):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def push(i):\n",
+ " if(is_full()):\n",
+ " terminate(\"Error in push: stack is full.\")\n",
+ " contents[top+1]=i\n",
+ "def pop():\n",
+ " if(is_empty()):\n",
+ " terminate(\"Error in push: stack is empty.\")\n",
+ " return contents[top-1]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example stackADT2.c, Page 498"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#similar as above since Python doesn't have pointers\n",
+ "import sys\n",
+ "STACK_SIZE=100\n",
+ "contents=[None]*STACK_SIZE\n",
+ "top=0\n",
+ "def terminate(message):\n",
+ " print message\n",
+ " sys.exit()\n",
+ "def make_empty():\n",
+ " top=0\n",
+ "def is_empty():\n",
+ " if(top==0):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def is_full():\n",
+ " if(top==STACK_SIZE):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def push(i):\n",
+ " if(is_full()):\n",
+ " terminate(\"Error in push: stack is full.\")\n",
+ " contents[top+1]=i\n",
+ "def pop():\n",
+ " if(is_empty()):\n",
+ " terminate(\"Error in push: stack is empty.\")\n",
+ " return contents[top-1]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example stackADT3.c, Page 500"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#similar as above since Python doesn't have pointers\n",
+ "import sys\n",
+ "STACK_SIZE=100\n",
+ "contents=[None]*STACK_SIZE\n",
+ "top=0\n",
+ "def terminate(message):\n",
+ " print message\n",
+ " sys.exit()\n",
+ "def make_empty():\n",
+ " top=0\n",
+ "def is_empty():\n",
+ " if(top==0):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def is_full():\n",
+ " if(top==STACK_SIZE):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def push(i):\n",
+ " if(is_full()):\n",
+ " terminate(\"Error in push: stack is full.\")\n",
+ " contents[top+1]=i\n",
+ "def pop():\n",
+ " if(is_empty()):\n",
+ " terminate(\"Error in push: stack is empty.\")\n",
+ " return contents[top-1]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter2.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter2.ipynb
new file mode 100755
index 00000000..c925dc1b
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter2.ipynb
@@ -0,0 +1,237 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1970948843f0abe57577274c22e34507ff26124029c8f4289139bc598d62eb66"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2: C Fundamentals"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example pun.c on Page 10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " print \"To C, or not to C: that is the question.\" #print statement demo\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "To C, or not to C: that is the question.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#ways for printing on a single line\n",
+ "print \"To C, or not to C: that is the question.\" \n",
+ "print \"To C, or not to C:\",\n",
+ "print \"that is the question.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "To C, or not to C: that is the question.\n",
+ "To C, or not to C: that is the question.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example dweight.c on Page 20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " #variable declaration\n",
+ " height = 8 \n",
+ " length = 12\n",
+ " width =10\n",
+ " volume = height * length * width #volume calculation\n",
+ " weight = (volume + 165)/166 #weight calculation\n",
+ " \n",
+ " #print statements\n",
+ " print \"Dimensions: %dx%dx%d\" % (length,width,height) \n",
+ " print \"Volume (cubic inches): %d\" % volume\n",
+ " print \"Dimensional weight (pounds): %d\" % weight\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dimensions: 12x10x8\n",
+ "Volume (cubic inches): 960\n",
+ "Dimensional weight (pounds): 6\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example dweight2.c on Page 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " #input from user\n",
+ " height = int(raw_input(\"Enter height of box: \"))\n",
+ " length = int(raw_input(\"Enter length of box: \"))\n",
+ " width = int(raw_input(\"Enter width of box: \"))\n",
+ " volume = height * length * width #volume calculation\n",
+ " weight = (volume + 165)/166 #weight calculation\n",
+ " \n",
+ " #print statements\n",
+ " print \"Volume (cubic inches): %d\" % volume\n",
+ " print \"Dimensional weight (pounds): %d\" % weight\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter height of box: 8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter length of box: 12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter width of box: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Volume (cubic inches): 960\n",
+ "Dimensional weight (pounds): 6\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example celsius.c on Page 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " #variable declaration\n",
+ " FREEZING_PT=32.0\n",
+ " SCALE_FACTOR= 5.02/9.0\n",
+ " \n",
+ " #input from user\n",
+ " farenheit=float(raw_input(\"Enter Farenheit temperature: \"))\n",
+ " celsius=(farenheit-FREEZING_PT) * SCALE_FACTOR #convert farenheit to celcius\n",
+ " print \"Celsius equivalent: %.1f\" % celsius\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Farenheit temperature: 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Celsius equivalent: 37.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter20.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter20.ipynb
new file mode 100755
index 00000000..10d6049f
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter20.ipynb
@@ -0,0 +1,161 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4a14f929c77abfd0a54b26e2baa48a2c7f478d22968a4f6231afc128a12dd480"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 20: Low-Level Programming"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example xor.c, Page 515"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "KEY='&'\n",
+ "orig=raw_input()\n",
+ "orig_char=list(orig)\n",
+ "new_char=[]\n",
+ "\n",
+ "def sxor(s1,s2): \n",
+ " return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip(s1,s2))\n",
+ "for i in orig_char:\n",
+ " N=sxor(i,KEY)\n",
+ " new_char.append(N)\n",
+ "print ''.join(new_char)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Trust not him with your secrets, who, when left alone in your room, turns over your papers. Johann Kaspar Lavater \n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rTSUR\u0006HIR\u0006NOK\u0006QORN\u0006_IST\u0006UCETCRU\n",
+ "\u0006QNI\n",
+ "\u0006QNCH\u0006JC@R\u0006GJIHC\u0006OH\u0006_IST\u0006TIIK\n",
+ "\u0006RSTHU\u0006IPCT\u0006_IST\u0006VGVCTU\b\u0006lINGHH\u0006mGUVGT\u0006jGPGRCT\u0006\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example viewmemory.c, Page 521"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from itertools import product\n",
+ "def main():\n",
+ " \n",
+ " addr=\"\"\n",
+ " i=0\n",
+ " n=0\n",
+ " print \"Address of main function: %s\" % hex(id(main))\n",
+ " print \"Address of addr variable: %s\" % hex(id(addr))\n",
+ " addr=raw_input( \"Enter a (hex) address: \")\n",
+ " n=int(raw_input( \"Enter number of bytes to view: \"))\n",
+ " #printf(\"\\n\");\n",
+ " print \" Address Bytes Characters\\n\"\n",
+ " print \" - - - - - - - - - - - - - - - - - - - - - - \"\n",
+ " ptr = addr;\n",
+ " for nn in range(n,0,-10):\n",
+ " print \"%8s \"% hex(id(addr))\n",
+ " # for i,i in product(range(0//10), range(0//n)) :\n",
+ " #print \"%.2X \", *(ptr + i)); \n",
+ " #for (; i <10; i++)\n",
+ " # printf(\" \"); #pointer dereferencing not in python\n",
+ " #printf(\" \");\n",
+ " #for (i = 0; i < 10 && i < n; i++) {\n",
+ " # BYTE ch = *(ptr + i);\n",
+ " #if (!isprint(ch))\n",
+ " # ch = '.';\n",
+ " # printf(\"%c\", ch);\n",
+ " #}\n",
+ " #printf(\"\\n\");\n",
+ " #ptr += 10;\n",
+ " #} \n",
+ " #return 0;\n",
+ " #}\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address of main function: 0x4117eb8L\n",
+ "Address of addr variable: 0x1c3c148L\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a (hex) address: 8048000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of bytes to view: 40\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Address Bytes Characters\n",
+ "\n",
+ " - - - - - - - - - - - - - - - - - - - - - - \n",
+ "0x41884b8L \n",
+ "0x41884b8L \n",
+ "0x41884b8L \n",
+ "0x41884b8L \n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter22.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter22.ipynb
new file mode 100755
index 00000000..e47d926c
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter22.ipynb
@@ -0,0 +1,158 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:61ba7fc12caccdde58e5c478fe47afe52c6e4084264f0cb759e096ea4f746518"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 22: File Operations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example canopen.c, Page 547"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "try:\n",
+ " fname=raw_input()\n",
+ " fp=open('noexist',r)\n",
+ "except:\n",
+ " print \"Can't be opened\"\n",
+ "else:\n",
+ " print \"Can be opened\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "file\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Can't be opened\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example fcopy.c, Page 568"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "try:\n",
+ " s=raw_input(\"Source\")\n",
+ " d=raw_input(\"Destination\")\n",
+ " source_fp=open(s,'rb')\n",
+ " dest_fp = open(d,wb)\n",
+ "\n",
+ " for line in source_fp.readlines():\n",
+ " dest_fp.write(line) \n",
+ "\n",
+ " dest_fp.close()\n",
+ " source_fp.close()\n",
+ "except:\n",
+ " print \"Can't be opened\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sourcef1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Destinationf2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Can't be opened\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example invclear.c, Page 574"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NAME_LEN=25\n",
+ "max_parts=100\n",
+ "char name=None*(NAME_LEN+1)\n",
+ "on_hand=list()\n",
+ "try:\n",
+ " fp=open('inventory.dat','r')\n",
+ "except:\n",
+ " print \"Cant open inventory file\"\n",
+ "num_parts=fp.read()\n",
+ "for i in range (num_parts):\n",
+ " on_hand[i]=0\n",
+ "fp.seek(0,0)\n",
+ "fp.write(on_hand)\n",
+ "fp.close\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter23.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter23.ipynb
new file mode 100755
index 00000000..d6c12ffe
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter23.ipynb
@@ -0,0 +1,127 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5233b8440acc7b2d62016ba76634e04bd09fd81a7f83bcd9847657fe204b0cea"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 23: Library Support for Numbers and Character Data"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tclassify.c, Page 613"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import string\n",
+ "print \" alnum alpha digit graph lower print punct space upper xdigit\"\n",
+ "p=\"azAZ0 !\\t\"\n",
+ "p1=list(p)\n",
+ "for i in p1:\n",
+ " listt=[\" \"]*10\n",
+ " print i,\n",
+ " if(i.isalnum()):\n",
+ " listt[0]=\" X\"\n",
+ " if(i.isalpha()):\n",
+ " listt[1]=\" X\"\n",
+ " if(i.isdigit()):\n",
+ " listt[2]=\" X\"\n",
+ " if(i.isspace()!=True):\n",
+ " listt[3]=\" X\"\n",
+ " if(i.islower()):\n",
+ " listt[4]=\" X\"\n",
+ " if(i in string.printable):\n",
+ " listt[5]=\" X\"\n",
+ " if(i in string.punctuation):\n",
+ " listt[6]=\" X\"\n",
+ " if(i.isspace()):\n",
+ " listt[7]=\" X\"\n",
+ " if(i.isupper()):\n",
+ " listt[8]=\" X\"\n",
+ " if(i in string.hexdigits):\n",
+ " listt[9]=\" X\"\n",
+ " print listt"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " alnum alpha digit graph lower print punct space upper xdigit\n",
+ "a [' X', ' X', ' ', ' X', ' X', ' X', ' ', ' ', ' ', ' X']\n",
+ "z [' X', ' X', ' ', ' X', ' X', ' X', ' ', ' ', ' ', ' ']\n",
+ "A [' X', ' X', ' ', ' X', ' ', ' X', ' ', ' ', ' X', ' X']\n",
+ "Z [' X', ' X', ' ', ' X', ' ', ' X', ' ', ' ', ' X', ' ']\n",
+ "0 [' X', ' ', ' X', ' X', ' ', ' X', ' ', ' ', ' ', ' X']\n",
+ " [' ', ' ', ' ', ' ', ' ', ' X', ' ', ' X', ' ', ' ']\n",
+ "! [' ', ' ', ' ', ' X', ' ', ' X', ' X', ' ', ' ', ' ']\n",
+ "\t[' ', ' ', ' ', ' ', ' ', ' X', ' ', ' X', ' ', ' ']\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tcasemap.c, Page 615"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "p=\"aA0!\"\n",
+ "pl=list(p)\n",
+ "for i in pl:\n",
+ " print \"tolower('%c') is '%c'; \"% (i,i.lower()),\n",
+ " print \"toupper('%c') is '%c'; \"% (i,i.upper())"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tolower('a') is 'a'; toupper('a') is 'A'; \n",
+ "tolower('A') is 'a'; toupper('A') is 'A'; \n",
+ "tolower('0') is '0'; toupper('0') is '0'; \n",
+ "tolower('!') is '!'; toupper('!') is '!'; \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter24.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter24.ipynb
new file mode 100755
index 00000000..05dd8488
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter24.ipynb
@@ -0,0 +1,126 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:70182e1ed50aea78649f1bef2946ce2b6e335126b84963ba06fce0660ac72886"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 24: Error Handling"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tsignal.c, Page 634"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import signal\n",
+ "import sys\n",
+ "def handler(sig,frame):\n",
+ " print \"Handler called for signal\",sig\n",
+ "print \"Installing handler for signal\", signal.SIGINT\n",
+ "orig_handler=signal.signal(signal.SIGINT,handler)\n",
+ "print \"Changing handler to SIG_IGN\"\n",
+ "signal.signal(signal.SIGINT,signal.SIG_IGN)\n",
+ "print \"Restoring original handler\"\n",
+ "signal.signal(signal.SIGINT,orig_handler)\n",
+ "print \"Program terminates normally\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Installing handler for signal 2\n",
+ "Changing handler to SIG_IGN\n",
+ "Restoring original handler\n",
+ "Program terminates normally\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tsetjmp.c, Page 636"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " def f1():\n",
+ " print \"f1 begins\"\n",
+ " f2()\n",
+ " return\n",
+ " print \"f1 returns\"\n",
+ "\n",
+ " def f2():\n",
+ " print \"f2 begins\"\n",
+ " #longjmp(env, 1)\n",
+ " setjmp=1\n",
+ " print \"Program terminates: longjmp called\"\n",
+ " return\n",
+ " print \"f2 returns\"\n",
+ "\n",
+ " setjmp=0\n",
+ " if (setjmp == 0):\n",
+ " print \"setjmp returned 0\"\n",
+ " else:\n",
+ " print \"Program terminates: longjmp called\"\n",
+ " f1()\n",
+ " return\n",
+ " print \"Program terminates normally\"\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "setjmp returned 0\n",
+ "f1 begins\n",
+ "f2 begins\n",
+ "Program terminates: longjmp called\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter26.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter26.ipynb
new file mode 100755
index 00000000..17b301ac
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter26.ipynb
@@ -0,0 +1,288 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:fbcb6cde8c1e1138fc13f2fa3b7cd67cad612fd1bfdb61df6d4f852067025cc4"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 26: Miscellaneous Library Functions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tnumconv.c, Page 684"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import ctypes, ctypes.util\n",
+ "whereislib = ctypes.util.find_library('c')\n",
+ "whereislib\n",
+ "clib = ctypes.cdll.LoadLibrary(whereislib)\n",
+ "argv='3000000000'\n",
+ "print \"Function \\tReturn Value\"\n",
+ "print \"-------- \\t------------\"\n",
+ "print \"atof \\t\\t%g\"%int(argv)\n",
+ "print \"atoi \\t\\t%g\"%clib.atoi(argv)\n",
+ "print \"atol \\t\\t%ld\"%clib.atol(argv)\n",
+ "print \"\"\n",
+ "print \"Function \\tReturn Value \\tValid? \\tString consumed?\"\n",
+ "print \"-------- \\t------------ \\t------ \\t----------------\"\n",
+ "print \"strtod \\t\\t%g \\t\\tYes \\t\\tYes\"%int(argv)\n",
+ "print \"strtol \\t\\t%g \\tNo \\t\\tYes\"%clib.atoi(argv)\n",
+ "print \"strtoul \\t3000000000 \\tYes \\t\\tYes\"\n",
+ "argv2='123.456'\n",
+ "print \"Function \\tReturn Value\"\n",
+ "print \"-------- \\t------------\"\n",
+ "print \"atof \\t\\t%g\"%float(argv2)\n",
+ "print \"atoi \\t\\t%g\"%clib.atoi(argv2)\n",
+ "print \"atol \\t\\t%ld\"%clib.atol(argv2)\n",
+ "print \"\"\n",
+ "print \"Function \\tReturn Value \\tValid? \\tString consumed?\"\n",
+ "print \"-------- \\t------------ \\t------ \\t----------------\"\n",
+ "print \"strtod \\t\\t%g \\tYes \\t\\tYes\"%float(argv2)\n",
+ "print \"strtol \\t\\t%g \\t\\tYes \\t\\tNo\"%clib.atoi(argv2)\n",
+ "print \"strtoul \\t%ld \\t\\tYes \\t\\tNo\"%clib.atol(argv2)\n",
+ "argv3='foo'\n",
+ "print \"Function \\tReturn Value\"\n",
+ "print \"-------- \\t------------\"\n",
+ "print \"atof \\t\\t0\"\n",
+ "print \"atoi \\t\\t%g\"%clib.atoi(argv3)\n",
+ "print \"atol \\t\\t%ld\"%clib.atol(argv3)\n",
+ "print \"\"\n",
+ "print \"Function \\tReturn Value \\tValid? \\tString consumed?\"\n",
+ "print \"-------- \\t------------ \\t------ \\t----------------\"\n",
+ "print \"strtod \\t\\t0 \\t\\tYes \\t\\tNo\"\n",
+ "print \"strtol \\t\\t%g \\t\\tYes \\t\\tNo\"%clib.atoi(argv3)\n",
+ "print \"strtoul \\t%ld \\t\\tYes \\t\\tNo\"%clib.atol(argv3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Function \tReturn Value\n",
+ "-------- \t------------\n",
+ "atof \t\t3e+09\n",
+ "atoi \t\t2.14748e+09\n",
+ "atol \t\t2147483647\n",
+ "\n",
+ "Function \tReturn Value \tValid? \tString consumed?\n",
+ "-------- \t------------ \t------ \t----------------\n",
+ "strtod \t\t3e+09 \t\tYes \t\tYes\n",
+ "strtol \t\t2.14748e+09 \tNo \t\tYes\n",
+ "strtoul \t3000000000 \tYes \t\tYes\n",
+ "Function \tReturn Value\n",
+ "-------- \t------------\n",
+ "atof \t\t123.456\n",
+ "atoi \t\t123\n",
+ "atol \t\t123\n",
+ "\n",
+ "Function \tReturn Value \tValid? \tString consumed?\n",
+ "-------- \t------------ \t------ \t----------------\n",
+ "strtod \t\t123.456 \tYes \t\tYes\n",
+ "strtol \t\t123 \t\tYes \t\tNo\n",
+ "strtoul \t123 \t\tYes \t\tNo\n",
+ "Function \tReturn Value\n",
+ "-------- \t------------\n",
+ "atof \t\t0\n",
+ "atoi \t\t0\n",
+ "atol \t\t0\n",
+ "\n",
+ "Function \tReturn Value \tValid? \tString consumed?\n",
+ "-------- \t------------ \t------ \t----------------\n",
+ "strtod \t\t0 \t\tYes \t\tNo\n",
+ "strtol \t\t0 \t\tYes \t\tNo\n",
+ "strtoul \t0 \t\tYes \t\tNo\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example trand.c, Page 687"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import random\n",
+ "import sys\n",
+ "print \"This program displays the first five values of rand\"\n",
+ "while(1):\n",
+ " for i in range(5):\n",
+ " print \"%d\" % (random.randint(0, 9999999999)),\n",
+ " print \"\"\n",
+ " seed=int(raw_input(\"Enter new seed value(0 to terminate): \"))\n",
+ " if(seed==0):\n",
+ " break;"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program displays the first five values of rand\n",
+ "5761431435 9955887404 277948394 6605189227 2803280817 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter new seed value(0 to terminate): 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1100098189 5276410883 9528246424 9889916914 9838545564 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter new seed value(0 to terminate): 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3822278888 5608424328 9674817256 1259089032 3611877211 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter new seed value(0 to terminate): 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example airmiles.c, Page 690"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "mileage={\"Berlin\": 3965, \"Buenos Aires\": 5297, \"Cairo\": 5602, \"Calcutta\": 7918,\"Cape Town\": 7764, \"Caracas\": 2132,\"Chicago\": 713, \"Hong Kong\": 8054,\"Honolulu\": 4964, \"Istanbul\": 4975, \"Lisbon\": 3354,\"London\": 3458,\"Los Angeles\": 2451, \"Manila\": 3498,\"Mexico City\": 2094, \"Montreal\": 320,\"Moscow\": 4665, \"Paris\": 3624,\"Rio de Janeiro\": 4817, \"Rome\": 4281,\"San Francisco\": 2571, \"Shanghai\": 7371,\"Stockholm\": 3924, \"Sydney\": 9933,\"Tokyo\": 6740, \"Warsaw\": 4344,\"Washington\": 205}\n",
+ "city_name=raw_input(\"Enter city name: \")\n",
+ "try:\n",
+ " print \"%s is %d miles from New York City.\"%(city_name,mileage[city_name])\n",
+ "except:\n",
+ " print \"%s wasn't found.\"%city_name\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter city name: Shanghai\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Shanghai is 7371 miles from New York City.\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example datetime.c, Page 700"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import datetime\n",
+ "import time\n",
+ "\n",
+ "current=datetime.date.today()\n",
+ "print current.ctime()\n",
+ "print time.strftime(\"%m-%d-%Y %I:%M%p\")\n",
+ "hour=time.localtime().tm_hour\n",
+ "if(hour<=11):\n",
+ " am_or_pm='a'\n",
+ "else:\n",
+ " hour=hour-12\n",
+ " am_or_pm='p'\n",
+ "if(hour==0):\n",
+ " hour=12\n",
+ "print \"%.2d-%.2d-%d %2d:%.2d%c\"%((time.localtime().tm_mon),time.localtime().tm_mday,( time.localtime().tm_year+1900),hour,time.localtime().tm_min, am_or_pm )\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wed Oct 1 00:00:00 2014\n",
+ "10-01-2014 05:33PM\n",
+ "10-01-3914 5:33p\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter27.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter27.ipynb
new file mode 100755
index 00000000..15629cee
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter27.ipynb
@@ -0,0 +1,72 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d596457391df308a57bb59fde4173c6f3b60829cc798d3f2ffccce6ed1d54b31"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 27: Additional C99 Support for Mathematics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example quadratic.c, Page 723"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import cmath\n",
+ "\n",
+ "a =5\n",
+ "b = 2\n",
+ "c = 1\n",
+ "\n",
+ "# calculate the discriminant\n",
+ "d = (b**2) - (4*a*c)\n",
+ "\n",
+ "# find two solutions\n",
+ "sol1 = (-b-cmath.sqrt(d))/(2*a)\n",
+ "sol2 = (-b+cmath.sqrt(d))/(2*a)\n",
+ "\n",
+ "print('root1 = {0} \\nroot2 = {1}'.format(sol1,sol2))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "root1 = (-0.2-0.4j) \n",
+ "root2 = (-0.2+0.4j)\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter3.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter3.ipynb
new file mode 100755
index 00000000..1b9cd25e
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter3.ipynb
@@ -0,0 +1,172 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4fe639aabf754893fb9526618dc70b095a7daac92032a0be83397e28da6d3261"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3: Formatted I/O"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#variable declaration\n",
+ "i=10\n",
+ "j=20\n",
+ "x=43.2892\n",
+ "y=5527.0\n",
+ "#print statement\n",
+ "print \"i = %d, j = %d, x = %f, y = %f\" % (i,j,x,y)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i = 10, j = 20, x = 43.289200, y = 5527.000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tprintf.c on Page 40"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " #variable declaration\n",
+ " i=40\n",
+ " x=839.21\n",
+ " \n",
+ " #formatted printing\n",
+ " print \"|%d|%5d|%-5d|%5.3d|\" % (i,i,i,i)\n",
+ " print \"|%10.3f|%10.3e|%-10g|\" % (x,x,x)\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "|40| 40|40 | 040|\n",
+ "| 839.210| 8.392e+02|839.21 |\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example addfrac.c on Page 46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ "\n",
+ " print \" Enter first fraction: \",\n",
+ " #accepting numerator and denominator separated by '/'\n",
+ " num1,denom1=map(int,raw_input().split('/')) \n",
+ " print \"Enter second fraction: \",\n",
+ " num2,denom2=map(int,raw_input().split('/'))\n",
+ " #adding the fractions\n",
+ " result_num = num1*denom2 + num2*denom1 \n",
+ " result_denom = denom1*denom2\n",
+ " print \"The sum is %d/%d\" % (result_num,result_denom)\n",
+ "\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter first fraction: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5/6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter second fraction: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3/4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The sum is 38/24\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter4.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter4.ipynb
new file mode 100755
index 00000000..35e91eab
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter4.ipynb
@@ -0,0 +1,216 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:fc3a82351dcd292af7cdc66294a40a180758bb26d4545d98b8be5c4947393f3d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: Expressions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example upc.c, Page Number-57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "def main():\n",
+ " #input from user\n",
+ " d=int(raw_input(\"Enter the first (single) digit: \")) \n",
+ " firstfive= raw_input(\"Enter first group of five digits\")\n",
+ " list1=list(firstfive) \n",
+ " i1=list1[0]\n",
+ " i2=list1[1]\n",
+ " i3=list1[2]\n",
+ " i4=list1[3]\n",
+ " i5=list1[4]\n",
+ " secondfive= raw_input(\"Enter second group of five digits\")\n",
+ " list2=list(firstfive) \n",
+ " j1=list2[0]\n",
+ " j2=list2[1]\n",
+ " j3=list2[2]\n",
+ " j4=list2[3]\n",
+ " j5=list2[4]\n",
+ " first_sum=d+int(i2)+int(i4)+int(j1)+int(j3)+int(j5)\n",
+ " second_sum=int(i1)+int(i3)+int(i5)+int(j2)+int(j4)\n",
+ " total=3*first_sum+second_sum\n",
+ " s=9-((total - 1) % 10)\n",
+ " print \"Check digit: %d\" % s #print result\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the first (single) digit: 0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter first group of five digits13800\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter second group of five digits15713\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Check digit: 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page number-59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#variable declaration\n",
+ "i = 1\n",
+ "#k = l + (j=i)\n",
+ "j=i\n",
+ "k=1+j\n",
+ "print \"%d %d %d\" % (i,j,k) #prints \"1 1 2\" \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 1 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page number-61"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i=1 #variable declaration\n",
+ "i+=1\n",
+ "print \"i is %d\" % i #++i\n",
+ "print \"i is %d\" % i #i\n",
+ "\n",
+ "i = 1\n",
+ "j=i+1\n",
+ "print \"i is %d\" % i #i++\n",
+ "print \"i is %d\" % j #i\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i is 2\n",
+ "i is 2\n",
+ "i is 1\n",
+ "i is 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page number-62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i=1 #variable declaration\n",
+ "i-=1\n",
+ "print \"i is %d\" % i #--i\n",
+ "print \"i is %d\" % i #i\n",
+ "\n",
+ "i = 1\n",
+ "j=i-1\n",
+ "print \"i is %d\" % i #i--\n",
+ "print \"i is %d\" % j #i"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i is 0\n",
+ "i is 0\n",
+ "i is 1\n",
+ "i is 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter5.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter5.ipynb
new file mode 100755
index 00000000..c7353250
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter5.ipynb
@@ -0,0 +1,209 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e0e8d285e21d88c99025668fa4fa5ab37c188ffb30c516ae4e90ff1d9747226e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5: Selection Statements"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example broker.c on Page 81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " commission=0.0 #variable declaration\n",
+ " value=float(raw_input(\"Enter value of trade: \")) #accepting the trade value\n",
+ " \n",
+ " #calculating commission according to the value of trade\n",
+ " if(value < 2500.00):\n",
+ " commission = 30.00 + 0.017 * value\n",
+ " elif (value < 6250.00):\n",
+ " commission = 56.00 + 0.0066 * value\n",
+ " elif (value < 20000.00):\n",
+ " commission = 76.00 + 0.0034 * value\n",
+ " elif (value < 50000.00):\n",
+ " commission = 100.00 + 0.0022 * value\n",
+ " elif (value < 500000.00):\n",
+ " commission = 155.00 + 0.0011 * value\n",
+ " else:\n",
+ " commission = 255.00 + 0.0009 * value\n",
+ " \n",
+ " if (commission < 39.00):\n",
+ " commission = 39.00\n",
+ " \n",
+ " print \"Commission: $%0.2f\" % commission #printing the value of commission\n",
+ "\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter value of trade: 7000.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Commission: $99.80\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 83"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " #variable declaration\n",
+ " i=1\n",
+ " j=2\n",
+ " \n",
+ " if(i>j): #k=i>j?i:j\n",
+ " k=i \n",
+ " else: \n",
+ " k=j #k is now 2\n",
+ " \n",
+ " if(i>=0): #k=(i>=0?i:0)+j\n",
+ " k=i+j #k is now 3\n",
+ " else:\n",
+ " k=0+j\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example date.c on Page 89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " date=raw_input(\"Enter date (mm/dd/yy): \") #accepting the date in mm/dd/yy format\n",
+ " date1=date.split(\"/\")\n",
+ " #day, moth and year separation\n",
+ " day=int(date1[1])\n",
+ " month= int(date1[0])\n",
+ " year=int(date1[2])\n",
+ " \n",
+ " #printing day as an ordinal number\n",
+ " print \"Dated this\", day,\n",
+ " if (day==1 or day==21 or day==31):\n",
+ " print \"st\",\n",
+ " elif (day==2 or day==22):\n",
+ " print \"nd\",\n",
+ " elif (day==3 or day==23):\n",
+ " print \"rd\",\n",
+ " else:\n",
+ " print \"th\",\n",
+ " print \"day of\",\n",
+ " \n",
+ " #printing month\n",
+ " if (month==1):\n",
+ " print \"January\",\n",
+ " elif(month==2):\n",
+ " print \"February\",\n",
+ " elif(month==3):\n",
+ " print \"March\",\n",
+ " elif(month==4):\n",
+ " print \"April\",\n",
+ " elif(month==5):\n",
+ " print \"May\",\n",
+ " elif(month==6):\n",
+ " print \"June\",\n",
+ " elif(month==7):\n",
+ " print \"July\",\n",
+ " elif(month==8):\n",
+ " print \"August\",\n",
+ " elif(month==9):\n",
+ " print \"September\",\n",
+ " elif(month==10):\n",
+ " print \"October\",\n",
+ " elif(month==11):\n",
+ " print \"November\",\n",
+ " elif(month==12):\n",
+ " print \"December\",\n",
+ " \n",
+ " #printing year\n",
+ " print \", 20%0.2d.\" % year\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter date (mm/dd/yy): 7/19/14\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dated this 19 th day of July , 2014.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter6.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter6.ipynb
new file mode 100755
index 00000000..ebb30975
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter6.ipynb
@@ -0,0 +1,503 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7be64d50608515e43ddcf6d9a0311be1c6e260d1acc2eec7e9577015cf19d4da"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Loops"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example square.c, Page 102"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " print \"This program prints a table of squares.\"\n",
+ " n=int(raw_input(\"Enter number of entries in table: \")) #input number of entries\n",
+ " i=1 #variable declaration\n",
+ " while(i<=n):\n",
+ " print \"%10d%10d\" % (i,i * i) #printing number and it's square\n",
+ " i=i+1\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program prints a table of squares.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of entries in table: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 1\n",
+ " 2 4\n",
+ " 3 9\n",
+ " 4 16\n",
+ " 5 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example sum.c, Page 103"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " sum=0\n",
+ " print \"This program sums a series of integers.\"\n",
+ " n=int(raw_input(\"Enter integers (0 to terminate): \")) #input the integers to operate on\n",
+ " while(n!=0):\n",
+ " sum=sum+n #calculating sum till 0 encountered\n",
+ " n=input()\n",
+ " print \"The sum is: %d\" % sum #printing sum\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program sums a series of integers.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter integers (0 to terminate): 8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "71\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sum is: 107\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example numdigits.c, Page 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " digits=0 #initialise\n",
+ " n=int(raw_input(\"Enter a nonnegative integer: \")) #input the number\n",
+ " n=n/10\n",
+ " digits=digits+1\n",
+ " #finding number of digits\n",
+ " while(n>0):\n",
+ " n=n/10\n",
+ " digits=digits+1\n",
+ " print \"The number has %d digit(s).\" % digits #printing answer\n",
+ "\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a nonnegative integer: 60\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The number has 2 digit(s).\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example square2.c, Page 110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " print \"This program prints a table of squares.\" \n",
+ " n=int(raw_input(\"Enter number of entries in table: \")) #input number of entries\n",
+ " for i in range (1,(n+1)):\n",
+ " print \"%10d%10d\" % (i,i * i) #printing number and it's square\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program prints a table of squares.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of entries in table: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 1\n",
+ " 2 4\n",
+ " 3 9\n",
+ " 4 16\n",
+ " 5 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example square3.c,Page 110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " print \"This program prints a table of squares.\" \n",
+ " n=int(raw_input(\"Enter number of entries in table: \")) #input number of entries\n",
+ " \n",
+ " #variable declaration\n",
+ " i=1\n",
+ " odd=3\n",
+ " square=1\n",
+ " #calculation\n",
+ " for i in range (1,(n+1)):\n",
+ " print \"%10d%10d\" % (i,square)\n",
+ " square=square+odd \n",
+ " odd=odd+2\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program prints a table of squares.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of entries in table: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 1\n",
+ " 2 4\n",
+ " 3 9\n",
+ " 4 16\n",
+ " 5 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example checking.c, Page 115"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " balance=0.0 #initialise\n",
+ " print \"*** ACME checkbook-balancing program ***\"\n",
+ " print \"Commands: 0=clear, 1=credits, 2=debit, 3=balance, 4=exit\"\n",
+ " print \"\"\n",
+ " while(1):\n",
+ " cmd=int(raw_input(\"Enter command: \")) \n",
+ " \n",
+ " #operate on balance according to the option selected\n",
+ " if cmd==0:\n",
+ " balance=0.0 #clear balance\n",
+ " elif cmd==1:\n",
+ " credit=float(raw_input(\"Enter amount of credit: \"))\n",
+ " balance=balance+credit #credit\n",
+ " elif cmd==2:\n",
+ " debit=float(raw_input(\"Enter amount of debit: \"))\n",
+ " balance=balance-debit #debit\n",
+ " elif cmd==3:\n",
+ " print \"Current balance: $%0.2f\" % balance #show current balance\n",
+ " elif cmd==4:\n",
+ " return 0 #exit\n",
+ " else:\n",
+ " print \"Commands: 0=clear, 1=credits, 2=debit, 3=balance, 4=exit\" \n",
+ " \n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "*** ACME checkbook-balancing program ***\n",
+ "Commands: 0=clear, 1=credits, 2=debit, 3=balance, 4=exit\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount of credit: 1042.56\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount of debit: 133.79\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount of credit: 1754.32\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount of debit: 1400\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount of debit: 68\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount of debit: 50\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current balance: $1145.09\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter7.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter7.ipynb
new file mode 100755
index 00000000..dde0a9b8
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter7.ipynb
@@ -0,0 +1,154 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:f68b9bfb9c3fa936de40e570b5ee8d7a82f02160fce8cc4fc8384697c0b86ac7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Basic Types"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example sum2.c, Page 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " sum=0\n",
+ " print \"This program sums a series of integers.\"\n",
+ " n=int(raw_input(\"Enter integers (0 to terminate): \")) #input the integers to operate on\n",
+ " while(n!=0):\n",
+ " sum=sum+n #calculating sum till 0 encountered\n",
+ " n=input()\n",
+ " print \"The sum is: %d\" % sum #printing sum\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program sums a series of integers.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter integers (0 to terminate): 8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "71\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sum is: 107\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example length.c, Page 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " str=raw_input(\"Enter a message: \") #input string\n",
+ " length=len(str) #calculate length\n",
+ " print \"Your message was %d character(s) long\" % length #display length\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a message: Brevity is the soul of wit.\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your message was 27 character(s) long\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter8.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter8.ipynb
new file mode 100755
index 00000000..32171653
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter8.ipynb
@@ -0,0 +1,288 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7c77241a39b4d43ac95986ef692466eff990f0d448827fcae58b424fe3cd8b1d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: Arrays"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example reverse.c, Page 164"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "N=10\n",
+ "li = raw_input(\"Enter %d numbers: \" % N) #accepting input in list\n",
+ "a = map(int, li.split()) \n",
+ "print \"In reverse order: \",\n",
+ "for i in a[::-1]: #print reversed list\n",
+ " print i,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 10 numbers: 34 82 49 102 7 94 23 11 50 31\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In reverse order: 31 50 11 23 94 7 102 49 82 34\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example repdigit.c, Page 166"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "digit_seen=[False]*10 #initialise with false\n",
+ "n=int(raw_input(\"Enter a number: \"))#input number\n",
+ "while(n>0): #calculate if any digit repeated\n",
+ " digit=n%10\n",
+ " if (digit_seen[digit]==True):\n",
+ " break\n",
+ " digit_seen[digit]=True\n",
+ " n=n/10\n",
+ "if(n>0): \n",
+ " print \"Repeated digit\" #print result\n",
+ "else:\n",
+ " print \"No repeated digit\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 28212\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Repeated digit\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example interest.c, Page 169"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "#initialisation\n",
+ "value=[None]*5 \n",
+ "NUM_RATES=int(sys.getsizeof(value)/sys.getsizeof(value[0]))-1\n",
+ "INITIAL_BALANCE=100.00\n",
+ "#accept input\n",
+ "low_rate=int(raw_input(\"Enter interest rate: \"))\n",
+ "num_years=int(raw_input(\"Enter number of years: \"))\n",
+ "print \"\"\n",
+ "#print calculated result table\n",
+ "print \"Years\",\n",
+ "for i in range (NUM_RATES):\n",
+ " print \"%6d%%\" % (low_rate + i),\n",
+ " value[i]=INITIAL_BALANCE\n",
+ "print \"\"\n",
+ "for year in range (num_years):\n",
+ " print \"%3d\\t\"%(year+1),\n",
+ " for i in range (NUM_RATES):\n",
+ " value[i]=value[i]+ (low_rate+i)/100.0*value[i]\n",
+ " print \"%7.2f\"%value[i],\n",
+ " print \"\"\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter interest rate: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of years: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Years 6% 7% 8% 9% 10% \n",
+ " 1\t 106.00 107.00 108.00 109.00 110.00 \n",
+ " 2\t 112.36 114.49 116.64 118.81 121.00 \n",
+ " 3\t 119.10 122.50 125.97 129.50 133.10 \n",
+ " 4\t 126.25 131.08 136.05 141.16 146.41 \n",
+ " 5\t 133.82 140.26 146.93 153.86 161.05 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example deal.c, Page 173"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import random\n",
+ "#initialisation\n",
+ "NUM_SUITS=4\n",
+ "NUM_RANKS=13\n",
+ "in_hand = [[False for i in xrange(13)] for i in xrange(4)]\n",
+ "rank_code=['2','3','4','5','6','7','8','9','t','j','q','k','a']\n",
+ "suit_code=['c','d','h','s']\n",
+ "#accet input\n",
+ "num_cards=int(raw_input(\"Enter number of cards in hand: \"))\n",
+ "print \"Your hand: \",\n",
+ "while(num_cards>0):\n",
+ " suit=random.randint(0,(NUM_SUITS-1)) #generate random suit\n",
+ " rank=random.randint(0,(NUM_RANKS-1)) #generate random rank\n",
+ " if (in_hand[suit][rank]!=True):\n",
+ " in_hand[suit][rank]=True\n",
+ " num_cards=num_cards-1\n",
+ " #print hand\n",
+ " print \"%c%c\" % (rank_code[rank],suit_code[suit]),\n",
+ "print \"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of cards in hand: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your hand: 9h 4d 5d 3d ad \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example reverse2.c, Page 174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n=int(raw_input(\"How many numbers do you want to reverse?\")) #accept number of elements\n",
+ "li = raw_input(\"Enter %d numbers: \" % n) #accepting input in list\n",
+ "a = map(int, li.split())\n",
+ "print \"In reverse order: \", #print reversed list\n",
+ "for i in a[::-1]:\n",
+ " print i,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many numbers do you want to reverse?10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 10 numbers: 34 82 49 102 7 94 23 11 50 31\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In reverse order: 31 50 11 23 94 7 102 49 82 34\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter9.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter9.ipynb
new file mode 100755
index 00000000..bc87a6c7
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter9.ipynb
@@ -0,0 +1,394 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:6212a1681da4032325cbede0a51614855911a11a6baad9f5e6fd0a0ecd4b5da9"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Functions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example average.c, Page 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def average(a,b): #function to calculate average\n",
+ " return (a+b)/2\n",
+ "nums = raw_input(\"Enter three numbers: \") #input numbers from user\n",
+ "list1 = map(float, nums.split()) \n",
+ "x=list1[0]\n",
+ "y=list1[1]\n",
+ "z=list1[2]\n",
+ "print \"Average of %.1f and %.1f: %.2f\" % (x,y,average(x,y)) #print average using function\n",
+ "print \"Average of %.1f and %.1f: %.2f\" % (y,z,average(y,z))\n",
+ "print \"Average of %.1f and %.1f: %.2f\" % (x,z,average(x,z))\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter three numbers: 3.5 9.6 10.2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average of 3.5 and 9.6: 6.55\n",
+ "Average of 9.6 and 10.2: 9.90\n",
+ "Average of 3.5 and 10.2: 6.85\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example countdown.c, Page 186"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def print_count(n): #function definition\n",
+ " print \"T minus %d and counting\" % n\n",
+ "for i in range (10,0,-1):\n",
+ " print_count(i) #print using function\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "T minus 10 and counting\n",
+ "T minus 9 and counting\n",
+ "T minus 8 and counting\n",
+ "T minus 7 and counting\n",
+ "T minus 6 and counting\n",
+ "T minus 5 and counting\n",
+ "T minus 4 and counting\n",
+ "T minus 3 and counting\n",
+ "T minus 2 and counting\n",
+ "T minus 1 and counting\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example pun2.c, Page 187"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def print_pun(): #function definition\n",
+ " print \"To C, or not to C: that is the question.\"\n",
+ "print_pun() #function call"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "To C, or not to C: that is the question.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example prime.c, Page 190"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def is_prime(n): #function to check for prime number\n",
+ " if (n<=1):\n",
+ " return False\n",
+ " divisor=2\n",
+ " while(divisor*divisor<=n):\n",
+ " if(n%divisor==0):\n",
+ " return False\n",
+ " return True\n",
+ "n=int(raw_input(\"Enter a number: \")) #input number\n",
+ "if(is_prime(n)): #check if prime using function\n",
+ " print \"Prime\" #print result of check\n",
+ "else:\n",
+ " print \"Not prime\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 34\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Not prime\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 192"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " nums = raw_input(\"Enter three numbers: \") #input numbers from user\n",
+ " list1 = map(float, nums.split()) \n",
+ " x=list1[0]\n",
+ " y=list1[1]\n",
+ " z=list1[2]\n",
+ " \n",
+ " #function usage before definition\n",
+ " \n",
+ " print \"Average of %.1f and %.1f: %.2f\" % (x,y,average(x,y)) #print average using function\n",
+ " print \"Average of %.1f and %.1f: %.2f\" % (y,z,average(y,z))\n",
+ " print \"Average of %.1f and %.1f: %.2f\" % (x,z,average(x,z))\n",
+ " \n",
+ "if __name__==\"__main__\":\n",
+ " main()\n",
+ " \n",
+ "def average(a,b): #function to calculate average\n",
+ " return (a+b)/2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter three numbers: 3.5 9.6 10.2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average of 3.5 and 9.6: 6.55\n",
+ "Average of 9.6 and 10.2: 9.90\n",
+ "Average of 3.5 and 10.2: 6.85\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 195"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x=3.0\n",
+ "print \"Square: %d\" % square(x) #gives error since function prototype doesnt exist before\n",
+ "def square(n):\n",
+ " return n*n\n",
+ "\n",
+ "\"\"\"\n",
+ "def main():\n",
+ " x=3.0\n",
+ " print \"Square: %d\" % square(x) \n",
+ " \n",
+ "#Now wouldn't give an error since writing the line below loads up all functions before starting main()\n",
+ "\n",
+ "if __name__==\"__main__\":\n",
+ " main()\n",
+ " \n",
+ "def square(n):\n",
+ " return n*n\n",
+ "\"\"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "NameError",
+ "evalue": "name 'square' is not defined",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m<ipython-input-3-2c761040ea35>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m3.0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"Square: %d\"\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0msquare\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#gives error since function prototype doesnt exist before\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0msquare\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mn\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mNameError\u001b[0m: name 'square' is not defined"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def store_zeroes(a,n):\n",
+ " for i in range(0,n):\n",
+ " a[i]=0\n",
+ "b=[None]*200\n",
+ "store_zeroes(b,100) #First 100 elements of b are now 100.\n",
+ "print b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example qsort.c, Page 207"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "N=10 #number of elements to sort\n",
+ "def split(a,low,high): #function to split list while sorting\n",
+ " part_element=a[low]\n",
+ " while(1):\n",
+ " while(low<high and part_element<=a[high]):\n",
+ " high=high-1\n",
+ " if(low>=high):\n",
+ " break\n",
+ " a[low+1]=a[high]\n",
+ " \n",
+ " while(low<high and a[low]<=part_element):\n",
+ " low=low+1\n",
+ " if(low>=high):\n",
+ " break\n",
+ " a[high-1]=a[low]\n",
+ " \n",
+ " a[high]=part_element\n",
+ " return high\n",
+ " \n",
+ "def quicksort(a,low,high): #recursive function for quicksort\n",
+ " if(low>=high):\n",
+ " return\n",
+ " middle=split(a,low,high)\n",
+ " quicksort(a,low,(middle-1))\n",
+ " quicksort(a,(middle+1),high)\n",
+ " \n",
+ "nums = raw_input(\"Enter %d numbers to be sorted: \"%N) #input numbers to sort\n",
+ "a = map(int, nums.split())\n",
+ "a.sort()\n",
+ "quicksort(a,0,(N-1)) #call quicksort function\n",
+ "print \"In sorted order: \", #print sorted result\n",
+ "for i in a:\n",
+ " print i,\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 10 numbers to be sorted: 9 16 47 82 4 66 12 3 25 51\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In sorted order: 3 4 9 12 16 25 47 51 66 82\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter10.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter10.ipynb
new file mode 100755
index 00000000..dcc36e8b
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter10.ipynb
@@ -0,0 +1,755 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:89fb3fef5984e311e1eb6ac1f3a0c24d3e369a1266fe562ec873d32c24f96971"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10: Program Organization"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 219"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def sum_digits(n):\n",
+ " sum = 0 #local variable\n",
+ " while(n>0):\n",
+ " sum =sum+(n%10)\n",
+ " n=n/10\n",
+ " return sum\n",
+ "#sum_digits(10)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 1,
+ "text": [
+ "1"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "STACK_SIZE=100\n",
+ "contents=[None]*STACK_SIZE\n",
+ "top=0\n",
+ "def make_empty():\n",
+ " top=0\n",
+ "def is_empty():\n",
+ " return top==0\n",
+ "def is_full():\n",
+ " return top==STACK_SIZE\n",
+ "def push(i):\n",
+ " if(is_full()):\n",
+ " call_stackoverflow=0\n",
+ " #stack_overflow()\n",
+ " else:\n",
+ " contents[top+1]=i\n",
+ "def pop():\n",
+ " if(is_empty()):\n",
+ " call_stackoverflow=0\n",
+ " #stack_underflow()\n",
+ " else:\n",
+ " return contents[top-1]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example guess.c, Page 224"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import random\n",
+ "MAX_NUMBER=100\n",
+ "#def initialize_number_generator():\n",
+ "def choose_new_secret_number():\n",
+ " secret_number=random.randint(1,MAX_NUMBER) #generate random number\n",
+ " return secret_number\n",
+ "def read_guesses():\n",
+ " num_guesses=0\n",
+ " while(1):\n",
+ " num_guesses=num_guesses+1\n",
+ " guess=int(raw_input(\"Enter guess: \")) #guesses\n",
+ " if(guess==secret_number):\n",
+ " print \"You have won in %d guesses: \"%num_guesses\n",
+ " print \"\"\n",
+ " return\n",
+ " elif (guess<secret_number):\n",
+ " print \"Too low, try again\"\n",
+ " else:\n",
+ " print \"Too high, try again\"\n",
+ "print \"Guess the secret number between 1 and %d.\"%MAX_NUMBER\n",
+ "print \"\"\n",
+ "secret_number=choose_new_secret_number()\n",
+ "print \"A new number has been chosen.\"\n",
+ "read_guesses()\n",
+ "command=raw_input( \"Play again? (Y/N) \")\n",
+ "while(command=='y' or command=='Y'):\n",
+ " secret_number=choose_new_secret_number()\n",
+ " print \"A new number has been chosen\"\n",
+ " read_guesses()\n",
+ " command=raw_input( \"Play again? (Y/N) \") \n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Guess the secret number between 1 and 100.\n",
+ "\n",
+ "A new number has been chosen.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 55\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 88\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too high, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 80\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 85\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 86\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You have won in 6 guesses: \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Play again? (Y/N) y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "A new number has been chosen\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 70\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 90\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 95\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 99\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too high, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 97\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 98\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You have won in 7 guesses: \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Play again? (Y/N) n\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example guess2.c, Page 226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import random\n",
+ "MAX_NUMBER=100\n",
+ "#def initialize_number_generator():\n",
+ "def new_secret_number():\n",
+ " return (random.randint(1,MAX_NUMBER))#generate random number\n",
+ "def read_guesses(secret_number):\n",
+ " num_guesses=0\n",
+ " while(1): #guesses\n",
+ " num_guesses=num_guesses+1\n",
+ " guess=int(raw_input(\"Enter guess: \"))\n",
+ " if(guess==secret_number):\n",
+ " print \"You have won in %d guesses: \"%num_guesses\n",
+ " print \"\"\n",
+ " return\n",
+ " elif (guess<secret_number):\n",
+ " print \"Too low, try again\"\n",
+ " else:\n",
+ " print \"Too high, try again\"\n",
+ "print \"Guess the secret number between 1 and %d.\"%MAX_NUMBER\n",
+ "print \"\"\n",
+ "secret_number=new_secret_number()\n",
+ "print \"A new number has been chosen.\"\n",
+ "read_guesses(secret_number)\n",
+ "command=raw_input( \"Play again? (Y/N) \")\n",
+ "while(command=='y' or command=='Y'):\n",
+ " secret_number=new_secret_number()\n",
+ " print \"A new number has been chosen\"\n",
+ " read_guesses(secret_number)\n",
+ " command=raw_input( \"Play again? (Y/N) \") \n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Guess the secret number between 1 and 100.\n",
+ "\n",
+ "A new number has been chosen.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 55\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 88\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too high, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 66\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 77\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too low, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 83\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too high, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 80\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too high, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 79\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Too high, try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter guess: 78\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You have won in 8 guesses: \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Play again? (Y/N) n\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example poker.c, Page 233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "pairs=0\n",
+ "\n",
+ "def read_cards():\n",
+ " cards_read=0\n",
+ " card_exists = [[False for i in xrange(NUM_SUITS)] for i in xrange(NUM_RANKS)]\n",
+ " while(cards_read<NUM_CARDS):\n",
+ " bad_card=False\n",
+ " cardd=raw_input(\"Enter a card\")\n",
+ " a = cardd.split()\n",
+ " rank_ch=a[0]\n",
+ " suit_ch=a[1]\n",
+ " if (rank_ch=='0'):\n",
+ " exit(EXIT_SUCCESS)\n",
+ " elif(rank_ch=='2'):\n",
+ " rank=0\n",
+ " elif(rank_ch=='3'):\n",
+ " rank=1\n",
+ " elif(rank_ch=='4'):\n",
+ " rank=2\n",
+ " elif(rank_ch=='5'):\n",
+ " rank=3\n",
+ " elif(rank_ch=='6'):\n",
+ " rank=4\n",
+ " elif(rank_ch=='7'):\n",
+ " rank=5\n",
+ " elif(rank_ch=='8'):\n",
+ " rank=6\n",
+ " elif(rank_ch=='9'):\n",
+ " rank=7\n",
+ " elif(rank_ch=='t' or rank_ch=='T'):\n",
+ " rank=8\n",
+ " elif(rank_ch=='j' or rank_ch=='J'):\n",
+ " rank=9\n",
+ " elif(rank_ch=='q' or rank_ch=='Q'):\n",
+ " rank=10\n",
+ " elif(rank_ch=='k' or rank_ch=='K'):\n",
+ " rank=11\n",
+ " elif(rank_ch=='a' or rank_ch=='A'):\n",
+ " rank=12\n",
+ " else:\n",
+ " bad_card=True\n",
+ " if(suit_ch=='c'or suit_ch=='C'):\n",
+ " suit=0\n",
+ " elif(suit_ch=='d' or suit_ch=='D'):\n",
+ " suit=1\n",
+ " elif(suit_ch=='h' or suit_ch=='H'):\n",
+ " suit=1\n",
+ " elif(suit_ch=='s' or suit_ch=='S'):\n",
+ " suit=1\n",
+ " else:\n",
+ " bad_card=True\n",
+ " if(bad_card):\n",
+ " print \"Bad card; ignored\"\n",
+ " elif (card_exists[rank][suit]):\n",
+ " print \"Duplicate card; ignored\"\n",
+ " else:\n",
+ " num_in_rank[rank]=num_in_rank[rank]+1\n",
+ " num_in_suit[suit]=num_in_suit[suit]+1\n",
+ " card_exists[rank][suit]=True\n",
+ " cards_read=cards_read+1\n",
+ "\n",
+ "def analyse_hand():\n",
+ " num_consec=0\n",
+ " for suit in range(NUM_SUITS):\n",
+ " if(num_in_suit[suit]==NUM_CARDS):\n",
+ " flush=True\n",
+ " rank=0\n",
+ " while(num_in_rank[rank]==0):\n",
+ " rank=rank+1\n",
+ " while(rank<NUM_RANKS and num_in_rank[rank]>0):\n",
+ " num_consec=num_consec+1\n",
+ " rank=rank+1\n",
+ " if(num_consec==NUM_CARDS):\n",
+ " straight=True\n",
+ " return\n",
+ " for rank in range(NUM_RANKS):\n",
+ " if(num_in_rank[rank]==4):\n",
+ " four=True\n",
+ " if(num_in_rank[rank]==3):\n",
+ " three=True\n",
+ " if(num_in_rank[rank]==2):\n",
+ " pairs=pairs+1\n",
+ " \n",
+ "def print_result():\n",
+ " if(straight==True and flush==True):\n",
+ " print \"Straight flush\"\n",
+ " elif(four):\n",
+ " print \"Four of a kind\"\n",
+ " elif(three==True and pairs==1):\n",
+ " print \"Full house\"\n",
+ " elif(flush):\n",
+ " print \"Flush\"\n",
+ " elif(straight):\n",
+ " print \"Straight\"\n",
+ " elif(three):\n",
+ " print \"Three of a kind\"\n",
+ " elif(pairs==2):\n",
+ " print \"Two pairs\"\n",
+ " elif(pairs==1):\n",
+ " print \"Pair\"\n",
+ " else:\n",
+ " print \"High card\"\n",
+ " print \"\"\n",
+ " \n",
+ "while(1):\n",
+ " straight=False\n",
+ " flush=False\n",
+ " four=False\n",
+ " three=False\n",
+ " NUM_RANKS=13\n",
+ " NUM_SUITS=4\n",
+ " NUM_CARDS=5\n",
+ " num_in_rank=[0]*NUM_RANKS\n",
+ " num_in_suit=[0]*NUM_SUITS\n",
+ "\n",
+ " read_cards()\n",
+ " analyse_hand()\n",
+ " print_result()\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a card2 s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a card5 s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a card4 s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a card3 s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a card6 s\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "High card\n",
+ "\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter11.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter11.ipynb
new file mode 100755
index 00000000..ce091d42
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter11.ipynb
@@ -0,0 +1,81 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:74e91fb616db3aa96bac711fa075c7c19a951b52d2e8ba98c61929ac216b2aca"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Pointers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example maxmin.c, Page 250"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "N=10\n",
+ "def max_min(a,n): #function definition\n",
+ " max=a[0]\n",
+ " min=a[0]\n",
+ " for i in range(n-1): #calculating max and min from list\n",
+ " if(a[i+1]>max):\n",
+ " max=a[i+1]\n",
+ " elif(a[i+1]<min):\n",
+ " min=a[i+1]\n",
+ " return (max,min)\n",
+ "li=raw_input(\"Enter %d numbers: \" % N) #input of numbers from user\n",
+ "b=map(int, li.split())\n",
+ "big,small=max_min(b,N) #call function to calculate max and min\n",
+ "print \"Largest: %d\"%big #print max and min\n",
+ "print \"Smallest: %d\"%small\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 10 numbers: 34 82 49 102 7 94 23 11 50 31\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Largest: 102\n",
+ "Smallest: 7\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter12.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter12.ipynb
new file mode 100755
index 00000000..a6dddf65
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter12.ipynb
@@ -0,0 +1,71 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:2d5527cee2d14f67c2f5fd4cdfcbb27ae6cb62aa3eec37f9815dae10c6c114db"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12: Pointers and Arrays"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example reverse3.c, Page 264"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "N=10\n",
+ "li = raw_input(\"Enter %d numbers: \" % N) #accepting input in list\n",
+ "a = map(int, li.split()) \n",
+ "print \"In reverse order: \",\n",
+ "for i in a[::-1]: #print reversed list\n",
+ " print i,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 10 numbers: 34 82 49 102 7 94 23 11 50 31\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In reverse order: 31 50 11 23 94 7 102 49 82 34\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter13.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter13.ipynb
new file mode 100755
index 00000000..03c83450
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter13.ipynb
@@ -0,0 +1,127 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:00fb09fcd8819c39a88f9cac94eaa93d1e9e72c864c95cc17c2c19aa93c94143"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13: Strings"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example remind.c, Page 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_REMIND=50\n",
+ "MSG_LEN=60\n",
+ "reminders = [['' for i in xrange(MSG_LEN+3)] for i in xrange(MAX_REMIND)]\n",
+ "num_remind=0\n",
+ "while(1):\n",
+ " if(num_remind==MAX_REMIND):\n",
+ " print \"--No space left --\"\n",
+ " break\n",
+ " li=raw_input( \"Enter day and reminder: \")\n",
+ " li1=li.split()\n",
+ " day_str=li1[0]\n",
+ " if(day_str=='0'):\n",
+ " break\n",
+ " msg_str=li1[1:]\n",
+ " i=0\n",
+ " for i in range(num_remind):\n",
+ " if(day_str<reminders[i]):\n",
+ " break\n",
+ " j=num_remind\n",
+ " while(j>i):\n",
+ " reminders[j]=reminders[j-1]\n",
+ " j=j-1\n",
+ " reminders[i]=day_str\n",
+ " reminders[i]=str(reminders[i])+str(msg_str)\n",
+ " \n",
+ " num_remind=num_remind+1\n",
+ "print \"\"\n",
+ "print \"Day Reminder\"\n",
+ "for i in range(num_remind):\n",
+ " print \"%s\"%reminders[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example planet.c, Page 303"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NUM_PLANETS=9\n",
+ "li=raw_input()\n",
+ "argv=li.split()\n",
+ "planets=['Mercury','Venus','Earth','Mars','Jupiter','Saturn','Uranus','Neptune','Pluto']\n",
+ "argc=len(argv)\n",
+ "for i in range(argc-1):\n",
+ " for j in range(NUM_PLANETS):\n",
+ " if( argv[i+1]==planets[j]):\n",
+ " print \"%s is a planet %d\"%(argv[i+1],(j+1))\n",
+ " break\n",
+ " if(argv[i] not in planets):\n",
+ " print \"%s is not a planet\"%argv[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "planet Jupiter Venus Earth fred\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Jupiter is a planet 5\n",
+ "planet is not a planet\n",
+ "Venus is a planet 2\n",
+ "Earth is a planet 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter15.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter15.ipynb
new file mode 100755
index 00000000..8429721c
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter15.ipynb
@@ -0,0 +1,83 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:66fb80b57a6473ffca1e8f425382d8ae7bda3cbb5a42b72a09573b1379da5aa8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 15: Writing Large Programs"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example justify.c, Page 359\n",
+ "Other files- word.h, line.h, word.c, line.c"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import textwrap\n",
+ "quote2=''\n",
+ "quote= (' C is quirky, flawed, and an '\n",
+ " 'enormous success. Although accidents of history '\n",
+ " ' surely helped, it evidently satisfied a need '\n",
+ " ''\n",
+ " 'for a system implementation language efficient '\n",
+ " 'enough to displace assembly language, '\n",
+ " ' yet sufficiently abstract and fluent to describe '\n",
+ " ' algorithms and interactions in a wide variety '\n",
+ " 'of environments.'\n",
+ " ' -- Dennis M. Ritchie')\n",
+ "for i in quote:\n",
+ " if (len(i)>20):\n",
+ " i=(i[:20] + '*')\n",
+ " quote2=quote2+i\n",
+ "quote2=' '.join(quote2.split()) \"\"\"Python has inbuilt functions for removing \n",
+ "white spaces and textwrap, justifying text hence reduces the amount of code as required in C\"\"\"\n",
+ "quotee= textwrap.fill(quote2)\n",
+ "print quotee"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C is quirky, flawed, and an enormous success. Although accidents of\n",
+ "history surely helped, it evidently satisfied a need for a system\n",
+ "implementation language efficient enough to displace assembly\n",
+ "language, yet sufficiently abstract and fluent to describe algorithms\n",
+ "and interactions in a wide variety of environments. -- Dennis M.\n",
+ "Ritchie\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter16.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter16.ipynb
new file mode 100755
index 00000000..20e3b1e5
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter16.ipynb
@@ -0,0 +1,180 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:9fe9374bd25aac8dfc98eab84988bb008dcfb464faf94260bebab61ae764fb98"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16: Structures, Unions and Enumerations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example inventory.c, Page 391"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NAME_LEN=25\n",
+ "MAX_PARTS=100\n",
+ "num_parts=0\n",
+ "number1=[0]*100\n",
+ "on_hand1=[0]*100\n",
+ "name1=[0]*100\n",
+ "def find_part(number):\n",
+ " i=0\n",
+ " for i in range (i,num_parts):\n",
+ " if(number1[i]==number):\n",
+ " return i\n",
+ " return -1\n",
+ "def insert():\n",
+ " num_parts=0\n",
+ " if(num_parts==MAX_PARTS):\n",
+ " print \"Database is full, cant add more parts\"\n",
+ " return\n",
+ " part_number=int(raw_input(\"Enter part number: \"))\n",
+ " if(find_part(part_number)>=0):\n",
+ " print \"Part already exists\"\n",
+ " return\n",
+ " number1[num_parts]=part_number\n",
+ " name1[num_parts]=raw_input(\"Enter part name: \")\n",
+ " on_hand1[num_parts]=raw_input(\"Enter quality on hand: \")\n",
+ " num_parts=num_parts+1\n",
+ " \n",
+ "def search():\n",
+ " number=int(raw_input(\"Enter part number: \"))\n",
+ " i=find_part(number)\n",
+ " if(i>=0):\n",
+ " print \"Part name: %s\" %name1[i]\n",
+ " print \"Quantity on hand: %d\"%on_hand1[i]\n",
+ " else:\n",
+ " print \"Part not found\"\n",
+ " \n",
+ "def update():\n",
+ " number=int(raw_input(\"Enter part number: \"))\n",
+ " i=find_part(number)\n",
+ " if(i>=0):\n",
+ " change=int(raw_input(\"Enter change in quantity on hand: \")) \n",
+ " on_hand1[i]=on_hand1[i]+change\n",
+ " else:\n",
+ " print \"Part not found\"\n",
+ "\n",
+ "while(1):\n",
+ " code=raw_input(\"Enter operation code: \")\n",
+ " if code=='i':\n",
+ " insert()\n",
+ " break\n",
+ " elif code=='s':\n",
+ " search()\n",
+ " break\n",
+ " elif code=='u':\n",
+ " update()\n",
+ " break\n",
+ " elif(code=='p'):\n",
+ " print()\n",
+ " break\n",
+ "\n",
+ "print \"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter operation code: i\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part number: 528\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part name: Disk Drive\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter quality on hand: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example readline.c, Page 395"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def read_line(str,n):\n",
+ " ch=0\n",
+ " i=0\n",
+ " EOF='\\n'\n",
+ " ch=raw_input()\n",
+ " while(isspace(ch)):\n",
+ " donothing=0\n",
+ " while(ch!='\\n' and ch!=EOF):\n",
+ " if(i<n):\n",
+ " str[i+1]=ch\n",
+ " ch=raw_input()\n",
+ " str[i]='\\0'\n",
+ " return i"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter17.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter17.ipynb
new file mode 100755
index 00000000..f25aa999
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter17.ipynb
@@ -0,0 +1,268 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8ebda07d5e13c6b4a8132b67344e9246eeb8703f2dcc433e1b4e350db4cace07"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 17: Advanced Uses of Pointers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example remind2.c, Page 418"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_REMIND=50\n",
+ "MSG_LEN=60\n",
+ "reminders = [['' for i in xrange(MSG_LEN+3)] for i in xrange(MAX_REMIND)]\n",
+ "num_remind=0\n",
+ "while(1):\n",
+ " if(num_remind==MAX_REMIND):\n",
+ " print \"--No space left --\"\n",
+ " break\n",
+ " li=raw_input( \"Enter day and reminder: \")\n",
+ " li1=li.split()\n",
+ " day_str=li1[0]\n",
+ " if(day_str=='0'):\n",
+ " breakb n\n",
+ " msg_str=li1[1:]\n",
+ " i=0\n",
+ " for i in range(num_remind):\n",
+ " if(day_str<reminders[i]):\n",
+ " break\n",
+ " j=num_remind\n",
+ " while(j>i):\n",
+ " reminders[j]=reminders[j-1]\n",
+ " j=j-1\n",
+ " reminders[i]=day_str\n",
+ " reminders[i]=str(reminders[i])+str(msg_str)\n",
+ " \n",
+ " num_remind=num_remind+1\n",
+ "print \"\"\n",
+ "print \"Day Reminder\"\n",
+ "for i in range(num_remind):\n",
+ " print \"%s\"%reminders[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example inventory2.c, Page 434"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NAME_LEN=25\n",
+ "MAX_PARTS=100\n",
+ "num_parts=0\n",
+ "number1=[0]*100\n",
+ "on_hand1=[0]*100\n",
+ "name1=[0]*100\n",
+ "def find_part(number):\n",
+ " i=0\n",
+ " for i in range (i,num_parts):\n",
+ " if(number1[i]==number):\n",
+ " return i\n",
+ " return -1\n",
+ "def insert():\n",
+ " num_parts=0\n",
+ " if(num_parts==MAX_PARTS):\n",
+ " print \"Database is full, cant add more parts\"\n",
+ " return\n",
+ " part_number=int(raw_input(\"Enter part number: \"))\n",
+ " if(find_part(part_number)>=0):\n",
+ " print \"Part already exists\"\n",
+ " return\n",
+ " number1[num_parts]=part_number\n",
+ " name1[num_parts]=raw_input(\"Enter part name: \")\n",
+ " on_hand1[num_parts]=raw_input(\"Enter quality on hand: \")\n",
+ " num_parts=num_parts+1\n",
+ " \n",
+ "def search():\n",
+ " number=int(raw_input(\"Enter part number: \"))\n",
+ " i=find_part(number)\n",
+ " if(i>=0):\n",
+ " print \"Part name: %s\" %name1[i]\n",
+ " print \"Quantity on hand: %d\"%on_hand1[i]\n",
+ " else:\n",
+ " print \"Part not found\"\n",
+ " \n",
+ "def update():\n",
+ " number=int(raw_input(\"Enter part number: \"))\n",
+ " i=find_part(number)\n",
+ " if(i>=0):\n",
+ " change=int(raw_input(\"Enter change in quantity on hand: \")) \n",
+ " on_hand1[i]=on_hand1[i]+change\n",
+ " else:\n",
+ " print \"Part not found\"\n",
+ "\n",
+ "while(1):\n",
+ " code=raw_input(\"Enter operation code: \")\n",
+ " if code=='i':\n",
+ " insert()\n",
+ " break\n",
+ " elif code=='s':\n",
+ " search()\n",
+ " break\n",
+ " elif code=='u':\n",
+ " update()\n",
+ " break\n",
+ " elif(code=='p'):\n",
+ " print()\n",
+ " break\n",
+ "\n",
+ "print \"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tabulate.c, Page 444"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "initial=float(raw_input(\"Enter initial value: \"))\n",
+ "final=float(raw_input(\"Enter final value: \"))\n",
+ "increment=float(raw_input(\"Enter increment: \"))\n",
+ "print \"\"\n",
+ "print \" x cos(x)\"\n",
+ "print \"-------------------------\"\n",
+ "\n",
+ "def tabulatec( first, last, incr):\n",
+ " num_intervals=int(math.ceil((last-first)/incr))\n",
+ " for i in range(num_intervals):\n",
+ " x=first+i*incr\n",
+ " print \"%10.5f %10.5f\"%(x,math.cos(x))\n",
+ "def tabulates( first, last, incr):\n",
+ " num_intervals=int(math.ceil((last-first)/incr))\n",
+ " for i in range(num_intervals):\n",
+ " x=first+i*incr\n",
+ " print \"%10.5f %10.5f\"%(x,math.sin(x))\n",
+ "def tabulatet( first, last, incr):\n",
+ " num_intervals=int(math.ceil((last-first)/incr))\n",
+ " for i in range(num_intervals):\n",
+ " x=first+i*incr\n",
+ " print \"%10.5f %10.5f\"%(x,math.tan(x))\n",
+ "\n",
+ " \n",
+ "tabulatec(initial,final, increment)\n",
+ "print \"\"\n",
+ "print \" x sin(x)\"\n",
+ "print \"\"\n",
+ "print \"-------------------------\"\n",
+ "tabulates(initial,final, increment)\n",
+ "print \"\"\n",
+ "print \" x tan(x)\"\n",
+ "print \"\"\n",
+ "print \"-------------------------\"\n",
+ "tabulatet(initial,final, increment)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter initial value: 0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter final value: .5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter increment: .1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " x cos(x)\n",
+ "--------------------------\n",
+ " 0.00000 1.00000\n",
+ " 0.10000 0.99500\n",
+ " 0.20000 0.98007\n",
+ " 0.30000 0.95534\n",
+ " 0.40000 0.92106\n",
+ "\n",
+ " x sin(x)\n",
+ "\n",
+ "-------------------------\n",
+ " 0.00000 0.00000\n",
+ " 0.10000 0.09983\n",
+ " 0.20000 0.19867\n",
+ " 0.30000 0.29552\n",
+ " 0.40000 0.38942\n",
+ "\n",
+ " x tan(x)\n",
+ "\n",
+ "-------------------------\n",
+ " 0.00000 0.00000\n",
+ " 0.10000 0.10033\n",
+ " 0.20000 0.20271\n",
+ " 0.30000 0.30934\n",
+ " 0.40000 0.42279\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter19.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter19.ipynb
new file mode 100755
index 00000000..42d5374c
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter19.ipynb
@@ -0,0 +1,322 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:6b5cf549b3fdac88be0a759d2fc29d02814154da669e9ab30e73ad0c8e2bbf9e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 19: Program Design"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example stack1.c, Page 488. Other files- stack.h\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "STACK_SIZE=100\n",
+ "contents=[None]*STACK_SIZE\n",
+ "top=0\n",
+ "def terminate(message):\n",
+ " print message\n",
+ " sys.exit()\n",
+ "def make_empty():\n",
+ " top=0\n",
+ "def is_empty():\n",
+ " if(top==0):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def is_full():\n",
+ " if(top==STACK_SIZE):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def push(i):\n",
+ " if(is_full()):\n",
+ " terminate(\"Error in push: stack is full.\")\n",
+ " contents[top+1]=i\n",
+ "def pop():\n",
+ " if(is_empty()):\n",
+ " terminate(\"Error in push: stack is empty.\")\n",
+ " return contents[top-1]\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example stack2.c, Page 489"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "STACK_SIZE=100\n",
+ "contents=[None]*STACK_SIZE\n",
+ "top=0\n",
+ "def terminate(message):\n",
+ " print message\n",
+ " sys.exit()\n",
+ "def make_empty():\n",
+ " top=0\n",
+ "def is_empty():\n",
+ " if(top==0):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def is_full():\n",
+ " if(top==STACK_SIZE):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def push(i):\n",
+ " if(is_full()):\n",
+ " terminate(\"Error in push: stack is full.\")\n",
+ " contents[top+1]=i\n",
+ "def pop():\n",
+ " if(is_empty()):\n",
+ " terminate(\"Error in push: stack is empty.\")\n",
+ " return contents[top-1]\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example stackclient.c, Page 494"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Stack:\n",
+ " def __init__(self):\n",
+ " self.items = []\n",
+ " def is_empty(self):\n",
+ " return self.items == []\n",
+ " def push(self, item):\n",
+ " self.items.append(item)\n",
+ " def pop(self):\n",
+ " return self.items.pop()\n",
+ " def size(self):\n",
+ " return len(self.items)\n",
+ " def make_empty(self):\n",
+ " while len(self.items) > 0 : self.items.pop()\n",
+ "s1=Stack()\n",
+ "s2=Stack()\n",
+ "s1.push(1)\n",
+ "s1.push(2)\n",
+ "n=s1.pop()\n",
+ "print \"Popped %d from s1\"%n\n",
+ "s2.push(n)\n",
+ "n=s1.pop()\n",
+ "print \"Popped %d from s1\"%n\n",
+ "s2.push(n)\n",
+ "while(s2.is_empty()!=True):\n",
+ " print \"Popped %d from s2\"%s2.pop()\n",
+ "s2.push(3)\n",
+ "s2.make_empty()\n",
+ "if(s2.is_empty()):\n",
+ " print \"s2 is empty\"\n",
+ "else:\n",
+ " print \"s2 is not empty\"\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Popped 2 from s1\n",
+ "Popped 1 from s1\n",
+ "Popped 1 from s2\n",
+ "Popped 2 from s2\n",
+ "s2 is empty\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example stackADT.c, Page 495"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "STACK_SIZE=100\n",
+ "contents=[None]*STACK_SIZE\n",
+ "top=0\n",
+ "def terminate(message):\n",
+ " print message\n",
+ " sys.exit()\n",
+ "def make_empty():\n",
+ " top=0\n",
+ "def is_empty():\n",
+ " if(top==0):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def is_full():\n",
+ " if(top==STACK_SIZE):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def push(i):\n",
+ " if(is_full()):\n",
+ " terminate(\"Error in push: stack is full.\")\n",
+ " contents[top+1]=i\n",
+ "def pop():\n",
+ " if(is_empty()):\n",
+ " terminate(\"Error in push: stack is empty.\")\n",
+ " return contents[top-1]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example stackADT2.c, Page 498"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#similar as above since Python doesn't have pointers\n",
+ "import sys\n",
+ "STACK_SIZE=100\n",
+ "contents=[None]*STACK_SIZE\n",
+ "top=0\n",
+ "def terminate(message):\n",
+ " print message\n",
+ " sys.exit()\n",
+ "def make_empty():\n",
+ " top=0\n",
+ "def is_empty():\n",
+ " if(top==0):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def is_full():\n",
+ " if(top==STACK_SIZE):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def push(i):\n",
+ " if(is_full()):\n",
+ " terminate(\"Error in push: stack is full.\")\n",
+ " contents[top+1]=i\n",
+ "def pop():\n",
+ " if(is_empty()):\n",
+ " terminate(\"Error in push: stack is empty.\")\n",
+ " return contents[top-1]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example stackADT3.c, Page 500"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#similar as above since Python doesn't have pointers\n",
+ "import sys\n",
+ "STACK_SIZE=100\n",
+ "contents=[None]*STACK_SIZE\n",
+ "top=0\n",
+ "def terminate(message):\n",
+ " print message\n",
+ " sys.exit()\n",
+ "def make_empty():\n",
+ " top=0\n",
+ "def is_empty():\n",
+ " if(top==0):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def is_full():\n",
+ " if(top==STACK_SIZE):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ "def push(i):\n",
+ " if(is_full()):\n",
+ " terminate(\"Error in push: stack is full.\")\n",
+ " contents[top+1]=i\n",
+ "def pop():\n",
+ " if(is_empty()):\n",
+ " terminate(\"Error in push: stack is empty.\")\n",
+ " return contents[top-1]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter2.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter2.ipynb
new file mode 100755
index 00000000..c925dc1b
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter2.ipynb
@@ -0,0 +1,237 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1970948843f0abe57577274c22e34507ff26124029c8f4289139bc598d62eb66"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2: C Fundamentals"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example pun.c on Page 10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " print \"To C, or not to C: that is the question.\" #print statement demo\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "To C, or not to C: that is the question.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#ways for printing on a single line\n",
+ "print \"To C, or not to C: that is the question.\" \n",
+ "print \"To C, or not to C:\",\n",
+ "print \"that is the question.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "To C, or not to C: that is the question.\n",
+ "To C, or not to C: that is the question.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example dweight.c on Page 20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " #variable declaration\n",
+ " height = 8 \n",
+ " length = 12\n",
+ " width =10\n",
+ " volume = height * length * width #volume calculation\n",
+ " weight = (volume + 165)/166 #weight calculation\n",
+ " \n",
+ " #print statements\n",
+ " print \"Dimensions: %dx%dx%d\" % (length,width,height) \n",
+ " print \"Volume (cubic inches): %d\" % volume\n",
+ " print \"Dimensional weight (pounds): %d\" % weight\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dimensions: 12x10x8\n",
+ "Volume (cubic inches): 960\n",
+ "Dimensional weight (pounds): 6\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example dweight2.c on Page 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " #input from user\n",
+ " height = int(raw_input(\"Enter height of box: \"))\n",
+ " length = int(raw_input(\"Enter length of box: \"))\n",
+ " width = int(raw_input(\"Enter width of box: \"))\n",
+ " volume = height * length * width #volume calculation\n",
+ " weight = (volume + 165)/166 #weight calculation\n",
+ " \n",
+ " #print statements\n",
+ " print \"Volume (cubic inches): %d\" % volume\n",
+ " print \"Dimensional weight (pounds): %d\" % weight\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter height of box: 8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter length of box: 12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter width of box: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Volume (cubic inches): 960\n",
+ "Dimensional weight (pounds): 6\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example celsius.c on Page 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " #variable declaration\n",
+ " FREEZING_PT=32.0\n",
+ " SCALE_FACTOR= 5.02/9.0\n",
+ " \n",
+ " #input from user\n",
+ " farenheit=float(raw_input(\"Enter Farenheit temperature: \"))\n",
+ " celsius=(farenheit-FREEZING_PT) * SCALE_FACTOR #convert farenheit to celcius\n",
+ " print \"Celsius equivalent: %.1f\" % celsius\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Farenheit temperature: 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Celsius equivalent: 37.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter20.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter20.ipynb
new file mode 100755
index 00000000..10d6049f
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter20.ipynb
@@ -0,0 +1,161 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4a14f929c77abfd0a54b26e2baa48a2c7f478d22968a4f6231afc128a12dd480"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 20: Low-Level Programming"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example xor.c, Page 515"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "KEY='&'\n",
+ "orig=raw_input()\n",
+ "orig_char=list(orig)\n",
+ "new_char=[]\n",
+ "\n",
+ "def sxor(s1,s2): \n",
+ " return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip(s1,s2))\n",
+ "for i in orig_char:\n",
+ " N=sxor(i,KEY)\n",
+ " new_char.append(N)\n",
+ "print ''.join(new_char)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Trust not him with your secrets, who, when left alone in your room, turns over your papers. Johann Kaspar Lavater \n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rTSUR\u0006HIR\u0006NOK\u0006QORN\u0006_IST\u0006UCETCRU\n",
+ "\u0006QNI\n",
+ "\u0006QNCH\u0006JC@R\u0006GJIHC\u0006OH\u0006_IST\u0006TIIK\n",
+ "\u0006RSTHU\u0006IPCT\u0006_IST\u0006VGVCTU\b\u0006lINGHH\u0006mGUVGT\u0006jGPGRCT\u0006\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example viewmemory.c, Page 521"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from itertools import product\n",
+ "def main():\n",
+ " \n",
+ " addr=\"\"\n",
+ " i=0\n",
+ " n=0\n",
+ " print \"Address of main function: %s\" % hex(id(main))\n",
+ " print \"Address of addr variable: %s\" % hex(id(addr))\n",
+ " addr=raw_input( \"Enter a (hex) address: \")\n",
+ " n=int(raw_input( \"Enter number of bytes to view: \"))\n",
+ " #printf(\"\\n\");\n",
+ " print \" Address Bytes Characters\\n\"\n",
+ " print \" - - - - - - - - - - - - - - - - - - - - - - \"\n",
+ " ptr = addr;\n",
+ " for nn in range(n,0,-10):\n",
+ " print \"%8s \"% hex(id(addr))\n",
+ " # for i,i in product(range(0//10), range(0//n)) :\n",
+ " #print \"%.2X \", *(ptr + i)); \n",
+ " #for (; i <10; i++)\n",
+ " # printf(\" \"); #pointer dereferencing not in python\n",
+ " #printf(\" \");\n",
+ " #for (i = 0; i < 10 && i < n; i++) {\n",
+ " # BYTE ch = *(ptr + i);\n",
+ " #if (!isprint(ch))\n",
+ " # ch = '.';\n",
+ " # printf(\"%c\", ch);\n",
+ " #}\n",
+ " #printf(\"\\n\");\n",
+ " #ptr += 10;\n",
+ " #} \n",
+ " #return 0;\n",
+ " #}\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address of main function: 0x4117eb8L\n",
+ "Address of addr variable: 0x1c3c148L\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a (hex) address: 8048000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of bytes to view: 40\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Address Bytes Characters\n",
+ "\n",
+ " - - - - - - - - - - - - - - - - - - - - - - \n",
+ "0x41884b8L \n",
+ "0x41884b8L \n",
+ "0x41884b8L \n",
+ "0x41884b8L \n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter22.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter22.ipynb
new file mode 100755
index 00000000..e47d926c
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter22.ipynb
@@ -0,0 +1,158 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:61ba7fc12caccdde58e5c478fe47afe52c6e4084264f0cb759e096ea4f746518"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 22: File Operations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example canopen.c, Page 547"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "try:\n",
+ " fname=raw_input()\n",
+ " fp=open('noexist',r)\n",
+ "except:\n",
+ " print \"Can't be opened\"\n",
+ "else:\n",
+ " print \"Can be opened\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "file\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Can't be opened\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example fcopy.c, Page 568"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "try:\n",
+ " s=raw_input(\"Source\")\n",
+ " d=raw_input(\"Destination\")\n",
+ " source_fp=open(s,'rb')\n",
+ " dest_fp = open(d,wb)\n",
+ "\n",
+ " for line in source_fp.readlines():\n",
+ " dest_fp.write(line) \n",
+ "\n",
+ " dest_fp.close()\n",
+ " source_fp.close()\n",
+ "except:\n",
+ " print \"Can't be opened\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sourcef1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Destinationf2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Can't be opened\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example invclear.c, Page 574"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NAME_LEN=25\n",
+ "max_parts=100\n",
+ "char name=None*(NAME_LEN+1)\n",
+ "on_hand=list()\n",
+ "try:\n",
+ " fp=open('inventory.dat','r')\n",
+ "except:\n",
+ " print \"Cant open inventory file\"\n",
+ "num_parts=fp.read()\n",
+ "for i in range (num_parts):\n",
+ " on_hand[i]=0\n",
+ "fp.seek(0,0)\n",
+ "fp.write(on_hand)\n",
+ "fp.close\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter23.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter23.ipynb
new file mode 100755
index 00000000..d6c12ffe
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter23.ipynb
@@ -0,0 +1,127 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5233b8440acc7b2d62016ba76634e04bd09fd81a7f83bcd9847657fe204b0cea"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 23: Library Support for Numbers and Character Data"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tclassify.c, Page 613"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import string\n",
+ "print \" alnum alpha digit graph lower print punct space upper xdigit\"\n",
+ "p=\"azAZ0 !\\t\"\n",
+ "p1=list(p)\n",
+ "for i in p1:\n",
+ " listt=[\" \"]*10\n",
+ " print i,\n",
+ " if(i.isalnum()):\n",
+ " listt[0]=\" X\"\n",
+ " if(i.isalpha()):\n",
+ " listt[1]=\" X\"\n",
+ " if(i.isdigit()):\n",
+ " listt[2]=\" X\"\n",
+ " if(i.isspace()!=True):\n",
+ " listt[3]=\" X\"\n",
+ " if(i.islower()):\n",
+ " listt[4]=\" X\"\n",
+ " if(i in string.printable):\n",
+ " listt[5]=\" X\"\n",
+ " if(i in string.punctuation):\n",
+ " listt[6]=\" X\"\n",
+ " if(i.isspace()):\n",
+ " listt[7]=\" X\"\n",
+ " if(i.isupper()):\n",
+ " listt[8]=\" X\"\n",
+ " if(i in string.hexdigits):\n",
+ " listt[9]=\" X\"\n",
+ " print listt"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " alnum alpha digit graph lower print punct space upper xdigit\n",
+ "a [' X', ' X', ' ', ' X', ' X', ' X', ' ', ' ', ' ', ' X']\n",
+ "z [' X', ' X', ' ', ' X', ' X', ' X', ' ', ' ', ' ', ' ']\n",
+ "A [' X', ' X', ' ', ' X', ' ', ' X', ' ', ' ', ' X', ' X']\n",
+ "Z [' X', ' X', ' ', ' X', ' ', ' X', ' ', ' ', ' X', ' ']\n",
+ "0 [' X', ' ', ' X', ' X', ' ', ' X', ' ', ' ', ' ', ' X']\n",
+ " [' ', ' ', ' ', ' ', ' ', ' X', ' ', ' X', ' ', ' ']\n",
+ "! [' ', ' ', ' ', ' X', ' ', ' X', ' X', ' ', ' ', ' ']\n",
+ "\t[' ', ' ', ' ', ' ', ' ', ' X', ' ', ' X', ' ', ' ']\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tcasemap.c, Page 615"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "p=\"aA0!\"\n",
+ "pl=list(p)\n",
+ "for i in pl:\n",
+ " print \"tolower('%c') is '%c'; \"% (i,i.lower()),\n",
+ " print \"toupper('%c') is '%c'; \"% (i,i.upper())"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tolower('a') is 'a'; toupper('a') is 'A'; \n",
+ "tolower('A') is 'a'; toupper('A') is 'A'; \n",
+ "tolower('0') is '0'; toupper('0') is '0'; \n",
+ "tolower('!') is '!'; toupper('!') is '!'; \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter24.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter24.ipynb
new file mode 100755
index 00000000..05dd8488
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter24.ipynb
@@ -0,0 +1,126 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:70182e1ed50aea78649f1bef2946ce2b6e335126b84963ba06fce0660ac72886"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 24: Error Handling"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tsignal.c, Page 634"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import signal\n",
+ "import sys\n",
+ "def handler(sig,frame):\n",
+ " print \"Handler called for signal\",sig\n",
+ "print \"Installing handler for signal\", signal.SIGINT\n",
+ "orig_handler=signal.signal(signal.SIGINT,handler)\n",
+ "print \"Changing handler to SIG_IGN\"\n",
+ "signal.signal(signal.SIGINT,signal.SIG_IGN)\n",
+ "print \"Restoring original handler\"\n",
+ "signal.signal(signal.SIGINT,orig_handler)\n",
+ "print \"Program terminates normally\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Installing handler for signal 2\n",
+ "Changing handler to SIG_IGN\n",
+ "Restoring original handler\n",
+ "Program terminates normally\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tsetjmp.c, Page 636"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " def f1():\n",
+ " print \"f1 begins\"\n",
+ " f2()\n",
+ " return\n",
+ " print \"f1 returns\"\n",
+ "\n",
+ " def f2():\n",
+ " print \"f2 begins\"\n",
+ " #longjmp(env, 1)\n",
+ " setjmp=1\n",
+ " print \"Program terminates: longjmp called\"\n",
+ " return\n",
+ " print \"f2 returns\"\n",
+ "\n",
+ " setjmp=0\n",
+ " if (setjmp == 0):\n",
+ " print \"setjmp returned 0\"\n",
+ " else:\n",
+ " print \"Program terminates: longjmp called\"\n",
+ " f1()\n",
+ " return\n",
+ " print \"Program terminates normally\"\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "setjmp returned 0\n",
+ "f1 begins\n",
+ "f2 begins\n",
+ "Program terminates: longjmp called\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter26.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter26.ipynb
new file mode 100755
index 00000000..17b301ac
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter26.ipynb
@@ -0,0 +1,288 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:fbcb6cde8c1e1138fc13f2fa3b7cd67cad612fd1bfdb61df6d4f852067025cc4"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 26: Miscellaneous Library Functions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tnumconv.c, Page 684"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import ctypes, ctypes.util\n",
+ "whereislib = ctypes.util.find_library('c')\n",
+ "whereislib\n",
+ "clib = ctypes.cdll.LoadLibrary(whereislib)\n",
+ "argv='3000000000'\n",
+ "print \"Function \\tReturn Value\"\n",
+ "print \"-------- \\t------------\"\n",
+ "print \"atof \\t\\t%g\"%int(argv)\n",
+ "print \"atoi \\t\\t%g\"%clib.atoi(argv)\n",
+ "print \"atol \\t\\t%ld\"%clib.atol(argv)\n",
+ "print \"\"\n",
+ "print \"Function \\tReturn Value \\tValid? \\tString consumed?\"\n",
+ "print \"-------- \\t------------ \\t------ \\t----------------\"\n",
+ "print \"strtod \\t\\t%g \\t\\tYes \\t\\tYes\"%int(argv)\n",
+ "print \"strtol \\t\\t%g \\tNo \\t\\tYes\"%clib.atoi(argv)\n",
+ "print \"strtoul \\t3000000000 \\tYes \\t\\tYes\"\n",
+ "argv2='123.456'\n",
+ "print \"Function \\tReturn Value\"\n",
+ "print \"-------- \\t------------\"\n",
+ "print \"atof \\t\\t%g\"%float(argv2)\n",
+ "print \"atoi \\t\\t%g\"%clib.atoi(argv2)\n",
+ "print \"atol \\t\\t%ld\"%clib.atol(argv2)\n",
+ "print \"\"\n",
+ "print \"Function \\tReturn Value \\tValid? \\tString consumed?\"\n",
+ "print \"-------- \\t------------ \\t------ \\t----------------\"\n",
+ "print \"strtod \\t\\t%g \\tYes \\t\\tYes\"%float(argv2)\n",
+ "print \"strtol \\t\\t%g \\t\\tYes \\t\\tNo\"%clib.atoi(argv2)\n",
+ "print \"strtoul \\t%ld \\t\\tYes \\t\\tNo\"%clib.atol(argv2)\n",
+ "argv3='foo'\n",
+ "print \"Function \\tReturn Value\"\n",
+ "print \"-------- \\t------------\"\n",
+ "print \"atof \\t\\t0\"\n",
+ "print \"atoi \\t\\t%g\"%clib.atoi(argv3)\n",
+ "print \"atol \\t\\t%ld\"%clib.atol(argv3)\n",
+ "print \"\"\n",
+ "print \"Function \\tReturn Value \\tValid? \\tString consumed?\"\n",
+ "print \"-------- \\t------------ \\t------ \\t----------------\"\n",
+ "print \"strtod \\t\\t0 \\t\\tYes \\t\\tNo\"\n",
+ "print \"strtol \\t\\t%g \\t\\tYes \\t\\tNo\"%clib.atoi(argv3)\n",
+ "print \"strtoul \\t%ld \\t\\tYes \\t\\tNo\"%clib.atol(argv3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Function \tReturn Value\n",
+ "-------- \t------------\n",
+ "atof \t\t3e+09\n",
+ "atoi \t\t2.14748e+09\n",
+ "atol \t\t2147483647\n",
+ "\n",
+ "Function \tReturn Value \tValid? \tString consumed?\n",
+ "-------- \t------------ \t------ \t----------------\n",
+ "strtod \t\t3e+09 \t\tYes \t\tYes\n",
+ "strtol \t\t2.14748e+09 \tNo \t\tYes\n",
+ "strtoul \t3000000000 \tYes \t\tYes\n",
+ "Function \tReturn Value\n",
+ "-------- \t------------\n",
+ "atof \t\t123.456\n",
+ "atoi \t\t123\n",
+ "atol \t\t123\n",
+ "\n",
+ "Function \tReturn Value \tValid? \tString consumed?\n",
+ "-------- \t------------ \t------ \t----------------\n",
+ "strtod \t\t123.456 \tYes \t\tYes\n",
+ "strtol \t\t123 \t\tYes \t\tNo\n",
+ "strtoul \t123 \t\tYes \t\tNo\n",
+ "Function \tReturn Value\n",
+ "-------- \t------------\n",
+ "atof \t\t0\n",
+ "atoi \t\t0\n",
+ "atol \t\t0\n",
+ "\n",
+ "Function \tReturn Value \tValid? \tString consumed?\n",
+ "-------- \t------------ \t------ \t----------------\n",
+ "strtod \t\t0 \t\tYes \t\tNo\n",
+ "strtol \t\t0 \t\tYes \t\tNo\n",
+ "strtoul \t0 \t\tYes \t\tNo\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example trand.c, Page 687"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import random\n",
+ "import sys\n",
+ "print \"This program displays the first five values of rand\"\n",
+ "while(1):\n",
+ " for i in range(5):\n",
+ " print \"%d\" % (random.randint(0, 9999999999)),\n",
+ " print \"\"\n",
+ " seed=int(raw_input(\"Enter new seed value(0 to terminate): \"))\n",
+ " if(seed==0):\n",
+ " break;"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program displays the first five values of rand\n",
+ "5761431435 9955887404 277948394 6605189227 2803280817 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter new seed value(0 to terminate): 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1100098189 5276410883 9528246424 9889916914 9838545564 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter new seed value(0 to terminate): 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3822278888 5608424328 9674817256 1259089032 3611877211 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter new seed value(0 to terminate): 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example airmiles.c, Page 690"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "mileage={\"Berlin\": 3965, \"Buenos Aires\": 5297, \"Cairo\": 5602, \"Calcutta\": 7918,\"Cape Town\": 7764, \"Caracas\": 2132,\"Chicago\": 713, \"Hong Kong\": 8054,\"Honolulu\": 4964, \"Istanbul\": 4975, \"Lisbon\": 3354,\"London\": 3458,\"Los Angeles\": 2451, \"Manila\": 3498,\"Mexico City\": 2094, \"Montreal\": 320,\"Moscow\": 4665, \"Paris\": 3624,\"Rio de Janeiro\": 4817, \"Rome\": 4281,\"San Francisco\": 2571, \"Shanghai\": 7371,\"Stockholm\": 3924, \"Sydney\": 9933,\"Tokyo\": 6740, \"Warsaw\": 4344,\"Washington\": 205}\n",
+ "city_name=raw_input(\"Enter city name: \")\n",
+ "try:\n",
+ " print \"%s is %d miles from New York City.\"%(city_name,mileage[city_name])\n",
+ "except:\n",
+ " print \"%s wasn't found.\"%city_name\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter city name: Shanghai\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Shanghai is 7371 miles from New York City.\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example datetime.c, Page 700"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import datetime\n",
+ "import time\n",
+ "\n",
+ "current=datetime.date.today()\n",
+ "print current.ctime()\n",
+ "print time.strftime(\"%m-%d-%Y %I:%M%p\")\n",
+ "hour=time.localtime().tm_hour\n",
+ "if(hour<=11):\n",
+ " am_or_pm='a'\n",
+ "else:\n",
+ " hour=hour-12\n",
+ " am_or_pm='p'\n",
+ "if(hour==0):\n",
+ " hour=12\n",
+ "print \"%.2d-%.2d-%d %2d:%.2d%c\"%((time.localtime().tm_mon),time.localtime().tm_mday,( time.localtime().tm_year+1900),hour,time.localtime().tm_min, am_or_pm )\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wed Oct 1 00:00:00 2014\n",
+ "10-01-2014 05:33PM\n",
+ "10-01-3914 5:33p\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter27.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter27.ipynb
new file mode 100755
index 00000000..15629cee
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter27.ipynb
@@ -0,0 +1,72 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d596457391df308a57bb59fde4173c6f3b60829cc798d3f2ffccce6ed1d54b31"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 27: Additional C99 Support for Mathematics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example quadratic.c, Page 723"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import cmath\n",
+ "\n",
+ "a =5\n",
+ "b = 2\n",
+ "c = 1\n",
+ "\n",
+ "# calculate the discriminant\n",
+ "d = (b**2) - (4*a*c)\n",
+ "\n",
+ "# find two solutions\n",
+ "sol1 = (-b-cmath.sqrt(d))/(2*a)\n",
+ "sol2 = (-b+cmath.sqrt(d))/(2*a)\n",
+ "\n",
+ "print('root1 = {0} \\nroot2 = {1}'.format(sol1,sol2))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "root1 = (-0.2-0.4j) \n",
+ "root2 = (-0.2+0.4j)\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter3.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter3.ipynb
new file mode 100755
index 00000000..1b9cd25e
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter3.ipynb
@@ -0,0 +1,172 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4fe639aabf754893fb9526618dc70b095a7daac92032a0be83397e28da6d3261"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3: Formatted I/O"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#variable declaration\n",
+ "i=10\n",
+ "j=20\n",
+ "x=43.2892\n",
+ "y=5527.0\n",
+ "#print statement\n",
+ "print \"i = %d, j = %d, x = %f, y = %f\" % (i,j,x,y)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i = 10, j = 20, x = 43.289200, y = 5527.000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tprintf.c on Page 40"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " #variable declaration\n",
+ " i=40\n",
+ " x=839.21\n",
+ " \n",
+ " #formatted printing\n",
+ " print \"|%d|%5d|%-5d|%5.3d|\" % (i,i,i,i)\n",
+ " print \"|%10.3f|%10.3e|%-10g|\" % (x,x,x)\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "|40| 40|40 | 040|\n",
+ "| 839.210| 8.392e+02|839.21 |\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example addfrac.c on Page 46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ "\n",
+ " print \" Enter first fraction: \",\n",
+ " #accepting numerator and denominator separated by '/'\n",
+ " num1,denom1=map(int,raw_input().split('/')) \n",
+ " print \"Enter second fraction: \",\n",
+ " num2,denom2=map(int,raw_input().split('/'))\n",
+ " #adding the fractions\n",
+ " result_num = num1*denom2 + num2*denom1 \n",
+ " result_denom = denom1*denom2\n",
+ " print \"The sum is %d/%d\" % (result_num,result_denom)\n",
+ "\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter first fraction: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5/6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter second fraction: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3/4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The sum is 38/24\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter4.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter4.ipynb
new file mode 100755
index 00000000..35e91eab
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter4.ipynb
@@ -0,0 +1,216 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:fc3a82351dcd292af7cdc66294a40a180758bb26d4545d98b8be5c4947393f3d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: Expressions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example upc.c, Page Number-57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "def main():\n",
+ " #input from user\n",
+ " d=int(raw_input(\"Enter the first (single) digit: \")) \n",
+ " firstfive= raw_input(\"Enter first group of five digits\")\n",
+ " list1=list(firstfive) \n",
+ " i1=list1[0]\n",
+ " i2=list1[1]\n",
+ " i3=list1[2]\n",
+ " i4=list1[3]\n",
+ " i5=list1[4]\n",
+ " secondfive= raw_input(\"Enter second group of five digits\")\n",
+ " list2=list(firstfive) \n",
+ " j1=list2[0]\n",
+ " j2=list2[1]\n",
+ " j3=list2[2]\n",
+ " j4=list2[3]\n",
+ " j5=list2[4]\n",
+ " first_sum=d+int(i2)+int(i4)+int(j1)+int(j3)+int(j5)\n",
+ " second_sum=int(i1)+int(i3)+int(i5)+int(j2)+int(j4)\n",
+ " total=3*first_sum+second_sum\n",
+ " s=9-((total - 1) % 10)\n",
+ " print \"Check digit: %d\" % s #print result\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the first (single) digit: 0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter first group of five digits13800\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter second group of five digits15713\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Check digit: 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page number-59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#variable declaration\n",
+ "i = 1\n",
+ "#k = l + (j=i)\n",
+ "j=i\n",
+ "k=1+j\n",
+ "print \"%d %d %d\" % (i,j,k) #prints \"1 1 2\" \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 1 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page number-61"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i=1 #variable declaration\n",
+ "i+=1\n",
+ "print \"i is %d\" % i #++i\n",
+ "print \"i is %d\" % i #i\n",
+ "\n",
+ "i = 1\n",
+ "j=i+1\n",
+ "print \"i is %d\" % i #i++\n",
+ "print \"i is %d\" % j #i\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i is 2\n",
+ "i is 2\n",
+ "i is 1\n",
+ "i is 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page number-62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i=1 #variable declaration\n",
+ "i-=1\n",
+ "print \"i is %d\" % i #--i\n",
+ "print \"i is %d\" % i #i\n",
+ "\n",
+ "i = 1\n",
+ "j=i-1\n",
+ "print \"i is %d\" % i #i--\n",
+ "print \"i is %d\" % j #i"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i is 0\n",
+ "i is 0\n",
+ "i is 1\n",
+ "i is 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter5.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter5.ipynb
new file mode 100755
index 00000000..c7353250
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter5.ipynb
@@ -0,0 +1,209 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e0e8d285e21d88c99025668fa4fa5ab37c188ffb30c516ae4e90ff1d9747226e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5: Selection Statements"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example broker.c on Page 81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " commission=0.0 #variable declaration\n",
+ " value=float(raw_input(\"Enter value of trade: \")) #accepting the trade value\n",
+ " \n",
+ " #calculating commission according to the value of trade\n",
+ " if(value < 2500.00):\n",
+ " commission = 30.00 + 0.017 * value\n",
+ " elif (value < 6250.00):\n",
+ " commission = 56.00 + 0.0066 * value\n",
+ " elif (value < 20000.00):\n",
+ " commission = 76.00 + 0.0034 * value\n",
+ " elif (value < 50000.00):\n",
+ " commission = 100.00 + 0.0022 * value\n",
+ " elif (value < 500000.00):\n",
+ " commission = 155.00 + 0.0011 * value\n",
+ " else:\n",
+ " commission = 255.00 + 0.0009 * value\n",
+ " \n",
+ " if (commission < 39.00):\n",
+ " commission = 39.00\n",
+ " \n",
+ " print \"Commission: $%0.2f\" % commission #printing the value of commission\n",
+ "\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter value of trade: 7000.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Commission: $99.80\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 83"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " #variable declaration\n",
+ " i=1\n",
+ " j=2\n",
+ " \n",
+ " if(i>j): #k=i>j?i:j\n",
+ " k=i \n",
+ " else: \n",
+ " k=j #k is now 2\n",
+ " \n",
+ " if(i>=0): #k=(i>=0?i:0)+j\n",
+ " k=i+j #k is now 3\n",
+ " else:\n",
+ " k=0+j\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example date.c on Page 89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " date=raw_input(\"Enter date (mm/dd/yy): \") #accepting the date in mm/dd/yy format\n",
+ " date1=date.split(\"/\")\n",
+ " #day, moth and year separation\n",
+ " day=int(date1[1])\n",
+ " month= int(date1[0])\n",
+ " year=int(date1[2])\n",
+ " \n",
+ " #printing day as an ordinal number\n",
+ " print \"Dated this\", day,\n",
+ " if (day==1 or day==21 or day==31):\n",
+ " print \"st\",\n",
+ " elif (day==2 or day==22):\n",
+ " print \"nd\",\n",
+ " elif (day==3 or day==23):\n",
+ " print \"rd\",\n",
+ " else:\n",
+ " print \"th\",\n",
+ " print \"day of\",\n",
+ " \n",
+ " #printing month\n",
+ " if (month==1):\n",
+ " print \"January\",\n",
+ " elif(month==2):\n",
+ " print \"February\",\n",
+ " elif(month==3):\n",
+ " print \"March\",\n",
+ " elif(month==4):\n",
+ " print \"April\",\n",
+ " elif(month==5):\n",
+ " print \"May\",\n",
+ " elif(month==6):\n",
+ " print \"June\",\n",
+ " elif(month==7):\n",
+ " print \"July\",\n",
+ " elif(month==8):\n",
+ " print \"August\",\n",
+ " elif(month==9):\n",
+ " print \"September\",\n",
+ " elif(month==10):\n",
+ " print \"October\",\n",
+ " elif(month==11):\n",
+ " print \"November\",\n",
+ " elif(month==12):\n",
+ " print \"December\",\n",
+ " \n",
+ " #printing year\n",
+ " print \", 20%0.2d.\" % year\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter date (mm/dd/yy): 7/19/14\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dated this 19 th day of July , 2014.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter6.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter6.ipynb
new file mode 100755
index 00000000..ebb30975
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter6.ipynb
@@ -0,0 +1,503 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7be64d50608515e43ddcf6d9a0311be1c6e260d1acc2eec7e9577015cf19d4da"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Loops"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example square.c, Page 102"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " print \"This program prints a table of squares.\"\n",
+ " n=int(raw_input(\"Enter number of entries in table: \")) #input number of entries\n",
+ " i=1 #variable declaration\n",
+ " while(i<=n):\n",
+ " print \"%10d%10d\" % (i,i * i) #printing number and it's square\n",
+ " i=i+1\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program prints a table of squares.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of entries in table: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 1\n",
+ " 2 4\n",
+ " 3 9\n",
+ " 4 16\n",
+ " 5 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example sum.c, Page 103"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " sum=0\n",
+ " print \"This program sums a series of integers.\"\n",
+ " n=int(raw_input(\"Enter integers (0 to terminate): \")) #input the integers to operate on\n",
+ " while(n!=0):\n",
+ " sum=sum+n #calculating sum till 0 encountered\n",
+ " n=input()\n",
+ " print \"The sum is: %d\" % sum #printing sum\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program sums a series of integers.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter integers (0 to terminate): 8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "71\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sum is: 107\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example numdigits.c, Page 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " digits=0 #initialise\n",
+ " n=int(raw_input(\"Enter a nonnegative integer: \")) #input the number\n",
+ " n=n/10\n",
+ " digits=digits+1\n",
+ " #finding number of digits\n",
+ " while(n>0):\n",
+ " n=n/10\n",
+ " digits=digits+1\n",
+ " print \"The number has %d digit(s).\" % digits #printing answer\n",
+ "\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a nonnegative integer: 60\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The number has 2 digit(s).\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example square2.c, Page 110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " print \"This program prints a table of squares.\" \n",
+ " n=int(raw_input(\"Enter number of entries in table: \")) #input number of entries\n",
+ " for i in range (1,(n+1)):\n",
+ " print \"%10d%10d\" % (i,i * i) #printing number and it's square\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program prints a table of squares.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of entries in table: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 1\n",
+ " 2 4\n",
+ " 3 9\n",
+ " 4 16\n",
+ " 5 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example square3.c,Page 110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " print \"This program prints a table of squares.\" \n",
+ " n=int(raw_input(\"Enter number of entries in table: \")) #input number of entries\n",
+ " \n",
+ " #variable declaration\n",
+ " i=1\n",
+ " odd=3\n",
+ " square=1\n",
+ " #calculation\n",
+ " for i in range (1,(n+1)):\n",
+ " print \"%10d%10d\" % (i,square)\n",
+ " square=square+odd \n",
+ " odd=odd+2\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program prints a table of squares.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of entries in table: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 1\n",
+ " 2 4\n",
+ " 3 9\n",
+ " 4 16\n",
+ " 5 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example checking.c, Page 115"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " balance=0.0 #initialise\n",
+ " print \"*** ACME checkbook-balancing program ***\"\n",
+ " print \"Commands: 0=clear, 1=credits, 2=debit, 3=balance, 4=exit\"\n",
+ " print \"\"\n",
+ " while(1):\n",
+ " cmd=int(raw_input(\"Enter command: \")) \n",
+ " \n",
+ " #operate on balance according to the option selected\n",
+ " if cmd==0:\n",
+ " balance=0.0 #clear balance\n",
+ " elif cmd==1:\n",
+ " credit=float(raw_input(\"Enter amount of credit: \"))\n",
+ " balance=balance+credit #credit\n",
+ " elif cmd==2:\n",
+ " debit=float(raw_input(\"Enter amount of debit: \"))\n",
+ " balance=balance-debit #debit\n",
+ " elif cmd==3:\n",
+ " print \"Current balance: $%0.2f\" % balance #show current balance\n",
+ " elif cmd==4:\n",
+ " return 0 #exit\n",
+ " else:\n",
+ " print \"Commands: 0=clear, 1=credits, 2=debit, 3=balance, 4=exit\" \n",
+ " \n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "*** ACME checkbook-balancing program ***\n",
+ "Commands: 0=clear, 1=credits, 2=debit, 3=balance, 4=exit\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount of credit: 1042.56\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount of debit: 133.79\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount of credit: 1754.32\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount of debit: 1400\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount of debit: 68\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount of debit: 50\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current balance: $1145.09\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter command: 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter7.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter7.ipynb
new file mode 100755
index 00000000..dde0a9b8
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter7.ipynb
@@ -0,0 +1,154 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:f68b9bfb9c3fa936de40e570b5ee8d7a82f02160fce8cc4fc8384697c0b86ac7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Basic Types"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example sum2.c, Page 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " sum=0\n",
+ " print \"This program sums a series of integers.\"\n",
+ " n=int(raw_input(\"Enter integers (0 to terminate): \")) #input the integers to operate on\n",
+ " while(n!=0):\n",
+ " sum=sum+n #calculating sum till 0 encountered\n",
+ " n=input()\n",
+ " print \"The sum is: %d\" % sum #printing sum\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program sums a series of integers.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter integers (0 to terminate): 8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "71\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sum is: 107\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example length.c, Page 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " str=raw_input(\"Enter a message: \") #input string\n",
+ " length=len(str) #calculate length\n",
+ " print \"Your message was %d character(s) long\" % length #display length\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a message: Brevity is the soul of wit.\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your message was 27 character(s) long\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter8.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter8.ipynb
new file mode 100755
index 00000000..32171653
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter8.ipynb
@@ -0,0 +1,288 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7c77241a39b4d43ac95986ef692466eff990f0d448827fcae58b424fe3cd8b1d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: Arrays"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example reverse.c, Page 164"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "N=10\n",
+ "li = raw_input(\"Enter %d numbers: \" % N) #accepting input in list\n",
+ "a = map(int, li.split()) \n",
+ "print \"In reverse order: \",\n",
+ "for i in a[::-1]: #print reversed list\n",
+ " print i,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 10 numbers: 34 82 49 102 7 94 23 11 50 31\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In reverse order: 31 50 11 23 94 7 102 49 82 34\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example repdigit.c, Page 166"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "digit_seen=[False]*10 #initialise with false\n",
+ "n=int(raw_input(\"Enter a number: \"))#input number\n",
+ "while(n>0): #calculate if any digit repeated\n",
+ " digit=n%10\n",
+ " if (digit_seen[digit]==True):\n",
+ " break\n",
+ " digit_seen[digit]=True\n",
+ " n=n/10\n",
+ "if(n>0): \n",
+ " print \"Repeated digit\" #print result\n",
+ "else:\n",
+ " print \"No repeated digit\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 28212\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Repeated digit\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example interest.c, Page 169"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "#initialisation\n",
+ "value=[None]*5 \n",
+ "NUM_RATES=int(sys.getsizeof(value)/sys.getsizeof(value[0]))-1\n",
+ "INITIAL_BALANCE=100.00\n",
+ "#accept input\n",
+ "low_rate=int(raw_input(\"Enter interest rate: \"))\n",
+ "num_years=int(raw_input(\"Enter number of years: \"))\n",
+ "print \"\"\n",
+ "#print calculated result table\n",
+ "print \"Years\",\n",
+ "for i in range (NUM_RATES):\n",
+ " print \"%6d%%\" % (low_rate + i),\n",
+ " value[i]=INITIAL_BALANCE\n",
+ "print \"\"\n",
+ "for year in range (num_years):\n",
+ " print \"%3d\\t\"%(year+1),\n",
+ " for i in range (NUM_RATES):\n",
+ " value[i]=value[i]+ (low_rate+i)/100.0*value[i]\n",
+ " print \"%7.2f\"%value[i],\n",
+ " print \"\"\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter interest rate: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of years: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Years 6% 7% 8% 9% 10% \n",
+ " 1\t 106.00 107.00 108.00 109.00 110.00 \n",
+ " 2\t 112.36 114.49 116.64 118.81 121.00 \n",
+ " 3\t 119.10 122.50 125.97 129.50 133.10 \n",
+ " 4\t 126.25 131.08 136.05 141.16 146.41 \n",
+ " 5\t 133.82 140.26 146.93 153.86 161.05 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example deal.c, Page 173"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import random\n",
+ "#initialisation\n",
+ "NUM_SUITS=4\n",
+ "NUM_RANKS=13\n",
+ "in_hand = [[False for i in xrange(13)] for i in xrange(4)]\n",
+ "rank_code=['2','3','4','5','6','7','8','9','t','j','q','k','a']\n",
+ "suit_code=['c','d','h','s']\n",
+ "#accet input\n",
+ "num_cards=int(raw_input(\"Enter number of cards in hand: \"))\n",
+ "print \"Your hand: \",\n",
+ "while(num_cards>0):\n",
+ " suit=random.randint(0,(NUM_SUITS-1)) #generate random suit\n",
+ " rank=random.randint(0,(NUM_RANKS-1)) #generate random rank\n",
+ " if (in_hand[suit][rank]!=True):\n",
+ " in_hand[suit][rank]=True\n",
+ " num_cards=num_cards-1\n",
+ " #print hand\n",
+ " print \"%c%c\" % (rank_code[rank],suit_code[suit]),\n",
+ "print \"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of cards in hand: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your hand: 9h 4d 5d 3d ad \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example reverse2.c, Page 174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n=int(raw_input(\"How many numbers do you want to reverse?\")) #accept number of elements\n",
+ "li = raw_input(\"Enter %d numbers: \" % n) #accepting input in list\n",
+ "a = map(int, li.split())\n",
+ "print \"In reverse order: \", #print reversed list\n",
+ "for i in a[::-1]:\n",
+ " print i,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many numbers do you want to reverse?10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 10 numbers: 34 82 49 102 7 94 23 11 50 31\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In reverse order: 31 50 11 23 94 7 102 49 82 34\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter9.ipynb b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter9.ipynb
new file mode 100755
index 00000000..bc87a6c7
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K._N._King/Chapter9.ipynb
@@ -0,0 +1,394 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:6212a1681da4032325cbede0a51614855911a11a6baad9f5e6fd0a0ecd4b5da9"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Functions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example average.c, Page 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def average(a,b): #function to calculate average\n",
+ " return (a+b)/2\n",
+ "nums = raw_input(\"Enter three numbers: \") #input numbers from user\n",
+ "list1 = map(float, nums.split()) \n",
+ "x=list1[0]\n",
+ "y=list1[1]\n",
+ "z=list1[2]\n",
+ "print \"Average of %.1f and %.1f: %.2f\" % (x,y,average(x,y)) #print average using function\n",
+ "print \"Average of %.1f and %.1f: %.2f\" % (y,z,average(y,z))\n",
+ "print \"Average of %.1f and %.1f: %.2f\" % (x,z,average(x,z))\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter three numbers: 3.5 9.6 10.2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average of 3.5 and 9.6: 6.55\n",
+ "Average of 9.6 and 10.2: 9.90\n",
+ "Average of 3.5 and 10.2: 6.85\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example countdown.c, Page 186"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def print_count(n): #function definition\n",
+ " print \"T minus %d and counting\" % n\n",
+ "for i in range (10,0,-1):\n",
+ " print_count(i) #print using function\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "T minus 10 and counting\n",
+ "T minus 9 and counting\n",
+ "T minus 8 and counting\n",
+ "T minus 7 and counting\n",
+ "T minus 6 and counting\n",
+ "T minus 5 and counting\n",
+ "T minus 4 and counting\n",
+ "T minus 3 and counting\n",
+ "T minus 2 and counting\n",
+ "T minus 1 and counting\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example pun2.c, Page 187"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def print_pun(): #function definition\n",
+ " print \"To C, or not to C: that is the question.\"\n",
+ "print_pun() #function call"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "To C, or not to C: that is the question.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example prime.c, Page 190"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def is_prime(n): #function to check for prime number\n",
+ " if (n<=1):\n",
+ " return False\n",
+ " divisor=2\n",
+ " while(divisor*divisor<=n):\n",
+ " if(n%divisor==0):\n",
+ " return False\n",
+ " return True\n",
+ "n=int(raw_input(\"Enter a number: \")) #input number\n",
+ "if(is_prime(n)): #check if prime using function\n",
+ " print \"Prime\" #print result of check\n",
+ "else:\n",
+ " print \"Not prime\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 34\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Not prime\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 192"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " nums = raw_input(\"Enter three numbers: \") #input numbers from user\n",
+ " list1 = map(float, nums.split()) \n",
+ " x=list1[0]\n",
+ " y=list1[1]\n",
+ " z=list1[2]\n",
+ " \n",
+ " #function usage before definition\n",
+ " \n",
+ " print \"Average of %.1f and %.1f: %.2f\" % (x,y,average(x,y)) #print average using function\n",
+ " print \"Average of %.1f and %.1f: %.2f\" % (y,z,average(y,z))\n",
+ " print \"Average of %.1f and %.1f: %.2f\" % (x,z,average(x,z))\n",
+ " \n",
+ "if __name__==\"__main__\":\n",
+ " main()\n",
+ " \n",
+ "def average(a,b): #function to calculate average\n",
+ " return (a+b)/2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter three numbers: 3.5 9.6 10.2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average of 3.5 and 9.6: 6.55\n",
+ "Average of 9.6 and 10.2: 9.90\n",
+ "Average of 3.5 and 10.2: 6.85\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 195"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x=3.0\n",
+ "print \"Square: %d\" % square(x) #gives error since function prototype doesnt exist before\n",
+ "def square(n):\n",
+ " return n*n\n",
+ "\n",
+ "\"\"\"\n",
+ "def main():\n",
+ " x=3.0\n",
+ " print \"Square: %d\" % square(x) \n",
+ " \n",
+ "#Now wouldn't give an error since writing the line below loads up all functions before starting main()\n",
+ "\n",
+ "if __name__==\"__main__\":\n",
+ " main()\n",
+ " \n",
+ "def square(n):\n",
+ " return n*n\n",
+ "\"\"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "NameError",
+ "evalue": "name 'square' is not defined",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m<ipython-input-3-2c761040ea35>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m3.0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"Square: %d\"\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0msquare\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#gives error since function prototype doesnt exist before\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0msquare\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mn\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mNameError\u001b[0m: name 'square' is not defined"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example on Page 197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def store_zeroes(a,n):\n",
+ " for i in range(0,n):\n",
+ " a[i]=0\n",
+ "b=[None]*200\n",
+ "store_zeroes(b,100) #First 100 elements of b are now 100.\n",
+ "print b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example qsort.c, Page 207"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "N=10 #number of elements to sort\n",
+ "def split(a,low,high): #function to split list while sorting\n",
+ " part_element=a[low]\n",
+ " while(1):\n",
+ " while(low<high and part_element<=a[high]):\n",
+ " high=high-1\n",
+ " if(low>=high):\n",
+ " break\n",
+ " a[low+1]=a[high]\n",
+ " \n",
+ " while(low<high and a[low]<=part_element):\n",
+ " low=low+1\n",
+ " if(low>=high):\n",
+ " break\n",
+ " a[high-1]=a[low]\n",
+ " \n",
+ " a[high]=part_element\n",
+ " return high\n",
+ " \n",
+ "def quicksort(a,low,high): #recursive function for quicksort\n",
+ " if(low>=high):\n",
+ " return\n",
+ " middle=split(a,low,high)\n",
+ " quicksort(a,low,(middle-1))\n",
+ " quicksort(a,(middle+1),high)\n",
+ " \n",
+ "nums = raw_input(\"Enter %d numbers to be sorted: \"%N) #input numbers to sort\n",
+ "a = map(int, nums.split())\n",
+ "a.sort()\n",
+ "quicksort(a,0,(N-1)) #call quicksort function\n",
+ "print \"In sorted order: \", #print sorted result\n",
+ "for i in a:\n",
+ " print i,\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 10 numbers to be sorted: 9 16 47 82 4 66 12 3 25 51\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In sorted order: 3 4 9 12 16 25 47 51 66 82\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice/Chapter11.ipynb b/Computer_Programming,_Theory_and_Practice/Chapter11.ipynb
deleted file mode 100755
index c046ab93..00000000
--- a/Computer_Programming,_Theory_and_Practice/Chapter11.ipynb
+++ /dev/null
@@ -1,62 +0,0 @@
-{
- "metadata": {
- "name": "Chapter11"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 11, Files"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 1, Page Number:CP-277"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "# Program to create a text file\n\nfp = open(\"sample.txt\",\"w\") # open file in write mode\n\nprint \"Type the text and Press enter key at end.\"\nprint\nprint \"Computer Programming in C language is widely used for Science and Engineering applications\"\n# input data to file\nch = ['Computer ','Programming ','in ','C ','language ','is ','widely ','used ','for ','Science ','and ' ,'Engineering ','applications.']\nfor i in ch:\n fp.write(i)\nfp.close()\n ",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Type the text and Press enter key at end.\n\nComputer Programming in C language is widely used for Science and Engineering applications\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2, Page Number:CP-278"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "# Program to read text file and count number of vowels\n\nfp = open(\"sample.txt\",\"r\") # open file in read mode\ncount = 0\nprint \"The Content of the file is:\"\n\nwhile (1): \n ch = fp.read(1)\n if not ch:\n break\n print ch\n # switch statements\n if ch == \"A\" or ch == \"a\": # case 'A' or 'a'\n count = count + 1\n elif ch == \"E\" or ch == \"e\": # case 'E' or 'e'\n count = count + 1\n elif ch == \"I\" or ch == \"i\": # case 'I' or 'i'\n count = count + 1\n elif ch == \"O\" or ch == \"o\": # case 'O' or 'o'\n count = count + 1\n elif ch == \"U\" or ch == \"u\": # case 'U' or 'u'\n count = count + 1\n\n\n\nfp.close() \nprint \"Number of vowels present =\",count \n ",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "The Content of the file is:\nC\no\nm\np\nu\nt\ne\nr\n \nP\nr\no\ng\nr\na\nm\nm\ni\nn\ng\n \ni\nn\n \nC\n \nl\na\nn\ng\nu\na\ng\ne\n \ni\ns\n \nw\ni\nd\ne\nl\ny\n \nu\ns\ne\nd\n \nf\no\nr\n \nS\nc\ni\ne\nn\nc\ne\n \na\nn\nd\n \nE\nn\ng\ni\nn\ne\ne\nr\ni\nn\ng\n \na\np\np\nl\ni\nc\na\nt\ni\no\nn\ns\n.\nNumber of vowels present = 31\n"
- }
- ],
- "prompt_number": 2
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice/Chapter2.ipynb b/Computer_Programming,_Theory_and_Practice/Chapter2.ipynb
deleted file mode 100755
index c4bc71ff..00000000
--- a/Computer_Programming,_Theory_and_Practice/Chapter2.ipynb
+++ /dev/null
@@ -1,41 +0,0 @@
-{
- "metadata": {
- "name": "Chapter2"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 2, Fundamentals of C language"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3, Page Number: CP-22"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "# variable declaration\n\na = 5\nb = 7\nc = 2\n\n# calculation \n\ny = a + b / c - a % c + 2 * a\n\n# result \n\nprint \"The result is \",y\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "The result is 17\n"
- }
- ],
- "prompt_number": 1
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice/Chapter3.ipynb b/Computer_Programming,_Theory_and_Practice/Chapter3.ipynb
deleted file mode 100755
index 04d24871..00000000
--- a/Computer_Programming,_Theory_and_Practice/Chapter3.ipynb
+++ /dev/null
@@ -1,293 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:0ff7bb47f00bae9dc5a49237df7011debd17443ba836341d55e8fe830338ade7"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 3: Input/Output Functions and Statements"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-39"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#program to add and find product of two numbers\n",
- "\n",
- "#variable declaration\n",
- "a = 5\n",
- "b = 3\n",
- "\n",
- "# calculation of sum and product \n",
- "\n",
- "summ = a + b\n",
- "product = a * b\n",
- "\n",
- "print a,b\n",
- "print summ,product"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "5 3\n",
- "8 15\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-45"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to convert degree fahrenheit to celcius \n",
- "# variable declaration\n",
- "\n",
- "f = 105.00\n",
- "print \"Degree fahrenheit ? %d\" % f\n",
- "# calculation of degree in celcius \n",
- "\n",
- "c = 5.0/9.0 * (f-32)\n",
- "\n",
- "# result \n",
- "print\n",
- "print \"Degree centigrade =%6.2f\" % c"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Degree fahrenheit ? 105\n",
- "\n",
- "Degree centigrade = 40.56\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-45"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# To find area of a triangle\n",
- "# variable declaration\n",
- "\n",
- "a = 5\n",
- "b = 4\n",
- "c = 6\n",
- "\n",
- "\n",
- "# calculation of area\n",
- "s = float((a+b+c))/2\n",
- "area = (s*(s-a)*(s-b)*(s-c)) ** 0.5\n",
- "\n",
- "# result\n",
- "print \"Enter three sides : %d\" % a,b,c\n",
- "print \n",
- "print \"Area of triangle = %0.2f Sq.units\" % area"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three sides : 5 4 6\n",
- "\n",
- "Area of triangle = 9.92 Sq.units\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-51"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# To print ASCII value of a given character \n",
- "# Variable declaration\n",
- "\n",
- "ch = \"A\"\n",
- "print \"Enter a character : \" , ch\n",
- "\n",
- "# Calculation of ASCII value of a character\n",
- "\n",
- "print \n",
- "print \"ASCII value of \" + ch + \" is\" ,ord(ch)\n",
- "print \"Press any key to stop. . .\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a character : A\n",
- "\n",
- "ASCII value of A is 65\n",
- "Press any key to stop. . .\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-51"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# To print electricity for consumers\n",
- "# Variable declaration\n",
- "\n",
- "sno = \"TMR65358\"\n",
- "pmr = 4305\n",
- "cmr = 4410\n",
- "\n",
- "print \"Enter service number :\" ,sno\n",
- "print \"Previous meter reading ?\",pmr\n",
- "print \"Current meter reading ?\",cmr\n",
- "\n",
- "# Calculation of electricity charges\n",
- "\n",
- "units = cmr - pmr\n",
- "amt = units * 1.50\n",
- "\n",
- "# Result\n",
- "\n",
- "print\n",
- "print \" Electricity Bill\"\n",
- "print \" ----------------\"\n",
- "print \"Service No :\",sno\n",
- "print \"Unit Consumed :\",units\n",
- "print \"Electricity Charges : Rs.%0.2f\" % amt"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter service number : TMR65358\n",
- "Previous meter reading ? 4305\n",
- "Current meter reading ? 4410\n",
- "\n",
- " Electricity Bill\n",
- " ----------------\n",
- "Service No : TMR65358\n",
- "Unit Consumed : 105\n",
- "Electricity Charges : Rs.157.50\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-52"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to swap value of two variables\n",
- "# Variable declaration\n",
- "\n",
- "a = 15\n",
- "b = 250 \n",
- "\n",
- "print \"Enter value to A :\",a\n",
- "print \"Enter value to B :\",b\n",
- "\n",
- "# Swapping\n",
- "\n",
- "temp = a\n",
- "a = b\n",
- "b = temp\n",
- "\n",
- "print \n",
- "print \"Value of A =\",a\n",
- "print \"Value of B =\",b"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to A : 15\n",
- "Enter value to B : 250\n",
- "\n",
- "Value of A = 250\n",
- "Value of B = 15\n"
- ]
- }
- ],
- "prompt_number": 7
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice/Chapter4.ipynb b/Computer_Programming,_Theory_and_Practice/Chapter4.ipynb
deleted file mode 100755
index 368164f3..00000000
--- a/Computer_Programming,_Theory_and_Practice/Chapter4.ipynb
+++ /dev/null
@@ -1,524 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:c9e723d7feeae217ee8ddaf1b9cf8cfab2d696821fa911ff65107b9da6bec9f0"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 4: Control Statements in C "
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-60"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the biggest of two numbers\n",
- "# Variable declaration\n",
- "\n",
- "a = 5\n",
- "b = 8\n",
- "\n",
- "print \"Enter two numbers : %d\" % a,b\n",
- "\n",
- "# Calculation\n",
- "\n",
- "big = a\n",
- "if (b>big):\n",
- " big = b\n",
- "\n",
- "print \"Biggest number is \",big"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter two numbers : 5 8\n",
- "Biggest number is 8\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-61"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find biggest of three numbers\n",
- "# Variable declaration\n",
- "\n",
- "a = 5\n",
- "b = 13\n",
- "c = 8\n",
- "\n",
- "print \"Enter three numbers : %d\" % a,b,c\n",
- "\n",
- "# Calculate\n",
- "\n",
- "big = a\n",
- "if (b>big):\n",
- " big = b\n",
- "if (c>big):\n",
- " big = c\n",
- "\n",
- "print \"Biggest number is\",big"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three numbers : 5 13 8\n",
- "Biggest number is 13\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-63"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find biggest of three numbers\n",
- "# Variable declaration\n",
- "\n",
- "a = 18\n",
- "b = -5\n",
- "c = 13\n",
- " \n",
- "print \"Enter three numbers : %d\" % a,b,c\n",
- "\n",
- "# Calculation to find biggest number\n",
- "\n",
- "if (a>b):\n",
- " if(a>c):\n",
- " big = a\n",
- " else:\n",
- " big = c\n",
- "else:\n",
- " if(b>c):\n",
- " big = b\n",
- " else:\n",
- " big = c\n",
- "\n",
- "print \"Biggest number is\",big"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three numbers : 18 -5 13\n",
- "Biggest number is 18\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-64"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the value of y \n",
- "# Variable declration\n",
- "\n",
- "x = 0.42\n",
- "n = 5\n",
- "\n",
- "print \"Enter value to x and n :\" , x,n \n",
- "\n",
- "# Calculation\n",
- "\n",
- "if (n==1):\n",
- " y = 1 + x\n",
- "elif (n==2):\n",
- " y = 1 + x / n\n",
- "elif (n==3):\n",
- " y = 1 + (x ** n)\n",
- "else:\n",
- " y = 1 + n * x\n",
- "\n",
- "\n",
- "print \"Value of y(x,n) = %0.2f\" % y"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to x and n : 0.42 5\n",
- "Value of y(x,n) = 3.10\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-66"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the value of y\n",
- "# Variable declaration\n",
- "\n",
- "x = 0.42\n",
- "n = 5\n",
- "\n",
- "\n",
- "print \"Enter value to x and n :\", x,n\n",
- "\n",
- "# Calculation\n",
- "\n",
- "# Switch case statements \n",
- "if n == 1: # case 1\n",
- " y = 1 + x\n",
- "elif n == 2: # case 2\n",
- " y = 1 + x / n\n",
- "elif n == 3: # case 3\n",
- " y = 1 + (x ** n)\n",
- "else: # default\n",
- " y = 1 + n * x\n",
- "\n",
- "print \"Value of y(x,n) = %0.2f\" % y "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to x and n : 0.42 5\n",
- "Value of y(x,n) = 3.10\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-68"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to caculate the commission for sales representatives\n",
- "# Variable declaration\n",
- "\n",
- "sales = 4500\n",
- "\n",
- "print \"Sales amount ? :\" , sales\n",
- "\n",
- "# Calculation of commission\n",
- "\n",
- "if (sales <= 500):\n",
- " comm = 0.05 * sales\n",
- "elif (sales <= 2000):\n",
- " comm = 35 + 0.10 * (sales - 500)\n",
- "elif (sales <= 5000):\n",
- " comm = 185 + 0.12 * (sales - 2000)\n",
- "else:\n",
- " comm = 0.125 * sales\n",
- "\n",
- "\n",
- "print \"Commission Amount Rs.%0.2f\" % comm"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Sales amount ? : 4500\n",
- "Commission Amount Rs.485.00\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-69"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find roots of a quadratic equation\n",
- "# Variable declaration\n",
- "\n",
- "a = 1\n",
- "b = 3\n",
- "c = 2\n",
- "\n",
- "print \"Enter coefficients a, b, and c :\", a,b,c\n",
- "\n",
- "d = b * b - 4 * a * c\n",
- "\n",
- "# Calculation of roots\n",
- "\n",
- "if (d > 0):\n",
- " x1 = (-b + (d ** 0.5)) / (2 * a)\n",
- " x2 = (-b - (d ** 0.5)) / (2 * a)\n",
- " print \"Roots are real and unequal \"\n",
- " print x1,x2\n",
- " \n",
- "\n",
- "elif(d == 0):\n",
- " x = -b / (2 * a)\n",
- " print \"Roots are real and equal\"\n",
- " print \"%6.2f\" % x\n",
- "\n",
- "else:\n",
- " print \"No Real roots, roots are complex\"\n",
- "\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter coefficients a, b, and c : 1 3 2\n",
- "Roots are real and unequal \n",
- "-1.0 -2.0\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8 , Page number: CP-70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print grade\n",
- "# Variable declaration\n",
- "\n",
- "avg_marks = 84\n",
- "\n",
- "print \"Average marks ?\",avg_marks\n",
- "\n",
- "# Calculation of grade\n",
- "\n",
- "if (avg_marks >= 80) and (avg_marks <= 100):\n",
- " print \"Honours\"\n",
- "elif (avg_marks >= 60) and (avg_marks <=79):\n",
- " print \"First Division\"\n",
- "elif (avg_marks >= 50) and (avg_marks <= 59):\n",
- " print \"Second Division\"\n",
- "else:\n",
- " print \"Fail\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Average marks ? 84\n",
- "Honours\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to calculate electirc charges for domestic consumers\n",
- "# Variable declaration\n",
- "\n",
- "units = 348\n",
- "\n",
- "print \"Enter consumed units :\",units\n",
- "\n",
- "# Calculation of electric charges\n",
- "\n",
- "if (units <= 200):\n",
- " amt = 0.5 * units\n",
- "elif (units <= 400):\n",
- " amt = 100 + 0.65 * (units - 200)\n",
- "elif (units <= 600):\n",
- " amt = 230 + 0.8 * (units - 400)\n",
- "else:\n",
- " amt = 425 + 1.25 * (units - 600)\n",
- "print \n",
- "print \"Amount to be paid Rs.%0.2f\" % amt"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter consumed units : 348\n",
- "\n",
- "Amount to be paid Rs.196.20\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-73"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the grade of steel samples\n",
- "# Variable declaration\n",
- "\n",
- "ts = 800\n",
- "rh = 180\n",
- "cc = 3\n",
- "\n",
- "print \"Enter tensile strength :\",ts\n",
- "print \"Enter rockwell hardness :\",rh\n",
- "print \"Enter carbon content :\",cc\n",
- "\n",
- "# Calculation of grade\n",
- "\n",
- "if (ts >= 700):\n",
- " if (rh >= 200):\n",
- " if (cc <= 6):\n",
- " print \"Grade is A\"\n",
- " else:\n",
- " print \"Grade is B\" \n",
- " elif (cc <= 6):\n",
- " print \"Grade is C\"\n",
- " else:\n",
- " print \"Grade is E\" \n",
- "elif (rh >= 200):\n",
- " if (cc <= 6):\n",
- " print \"Grade is D\"\n",
- " else:\n",
- " print \"Grade is E\"\n",
- "elif (cc <= 6):\n",
- " print \"Grade is E\"\n",
- "else:\n",
- " print \"Grade is F\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter tensile strength : 800\n",
- "Enter rockwell hardness : 180\n",
- "Enter carbon content : 3\n",
- "Grade is C\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice/Chapter5.ipynb b/Computer_Programming,_Theory_and_Practice/Chapter5.ipynb
deleted file mode 100755
index 52adbd63..00000000
--- a/Computer_Programming,_Theory_and_Practice/Chapter5.ipynb
+++ /dev/null
@@ -1,1103 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:1c1423d8954dc10aa9bbb2818169dfeb793cb3bc9435852c4188cde598c54111"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 5: Loop Control Structures in C"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-79"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print natural numbers from 1 to n\n",
- "# Variable decalration\n",
- "\n",
- "n = 15\n",
- "\n",
- "print \"Enter value to n :\",n\n",
- "\n",
- "# Loop to print natural numbers\n",
- "for r in range(15):\n",
- " r = r + 1\n",
- " print r,\n",
- " \n",
- " \n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to n : 15\n",
- "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-80"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the value of y and print a table for values of x\n",
- "# Variable declaration\n",
- "import math\n",
- "x = 1.0\n",
- "print \"------------------------\"\n",
- "print \" x y \"\n",
- "print \"------------------------\"\n",
- "while x <= 3.2:\n",
- " y = 1.36 * ((1 + x + x * x * x) ** 0.5) + ((x) ** (1.0/4)) + math.exp(x)\n",
- " print \" %0.2f \" %x + \" %0.2f\" % y\n",
- " x = x + 0.2"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "------------------------\n",
- " x y \n",
- "------------------------\n",
- " 1.00 6.07\n",
- " 1.20 7.06\n",
- " 1.40 8.23\n",
- " 1.60 9.60\n",
- " 1.80 11.20\n",
- " 2.00 13.09\n",
- " 2.20 15.30\n",
- " 2.40 17.91\n",
- " 2.60 20.99\n",
- " 2.80 24.64\n",
- " 3.00 28.97\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-81"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find factorial of given number\n",
- "# Variable declaration\n",
- "\n",
- "k = 4\n",
- "kfact = 1\n",
- "\n",
- "print \"Enter an integer :\",k\n",
- "\n",
- "# Loop to generate numbers from 1 to n\n",
- "\n",
- "for i in range(1,k + 1):\n",
- " kfact = kfact*i\n",
- "\n",
- " \n",
- "print \"4 factorial is\",kfact "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter an integer : 4\n",
- "4 factorial is 24\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-83"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print sum of the following series\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "s = 0\n",
- "\n",
- "print \"Enter value to N :\",n\n",
- "# Calculation of sum\n",
- "i = 1\n",
- "j = 1\n",
- "\n",
- "for i in range(1,n+1):\n",
- " term = 0\n",
- " for j in range(i+1):\n",
- " term = term + j\n",
- " s = s + term\n",
- "\n",
- "\n",
- "print \"Sum of the series S =\",s "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to N : 4\n",
- "Sum of the series S = 20\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-84"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to compute the values of z based on x and y\n",
- "# Variable declaration\n",
- "\n",
- "x = -1.5\n",
- "y = 0\n",
- "\n",
- "# Loops to generate values of x and y to find z\n",
- "\n",
- "while x <= 1.5:\n",
- " while y <= 3.0:\n",
- " z = 3 * x * x + 2 * y * y * y - 25.5\n",
- " print \"Value of y(\",x,\n",
- " print \",\",y,\n",
- " print \") =\",z\n",
- " y = y + 1.0\n",
- " x = x + 0.5\n",
- " y = 0\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Value of y( -1.5 , 0 ) = -18.75\n",
- "Value of y( -1.5 , 1.0 ) = -16.75\n",
- "Value of y( -1.5 , 2.0 ) = -2.75\n",
- "Value of y( -1.5 , 3.0 ) = 35.25\n",
- "Value of y( -1.0 , 0 ) = -22.5\n",
- "Value of y( -1.0 , 1.0 ) = -20.5\n",
- "Value of y( -1.0 , 2.0 ) = -6.5\n",
- "Value of y( -1.0 , 3.0 ) = 31.5\n",
- "Value of y( -0.5 , 0 ) = -24.75\n",
- "Value of y( -0.5 , 1.0 ) = -22.75\n",
- "Value of y( -0.5 , 2.0 ) = -8.75\n",
- "Value of y( -0.5 , 3.0 ) = 29.25\n",
- "Value of y( 0.0 , 0 ) = -25.5\n",
- "Value of y( 0.0 , 1.0 ) = -23.5\n",
- "Value of y( 0.0 , 2.0 ) = -9.5\n",
- "Value of y( 0.0 , 3.0 ) = 28.5\n",
- "Value of y( 0.5 , 0 ) = -24.75\n",
- "Value of y( 0.5 , 1.0 ) = -22.75\n",
- "Value of y( 0.5 , 2.0 ) = -8.75\n",
- "Value of y( 0.5 , 3.0 ) = 29.25\n",
- "Value of y( 1.0 , 0 ) = -22.5\n",
- "Value of y( 1.0 , 1.0 ) = -20.5\n",
- "Value of y( 1.0 , 2.0 ) = -6.5\n",
- "Value of y( 1.0 , 3.0 ) = 31.5\n",
- "Value of y( 1.5 , 0 ) = -18.75\n",
- "Value of y( 1.5 , 1.0 ) = -16.75\n",
- "Value of y( 1.5 , 2.0 ) = -2.75\n",
- "Value of y( 1.5 , 3.0 ) = 35.25\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-89"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find sum of odd integers between 1 to n\n",
- "# Variable declararion\n",
- "\n",
- "n = 10\n",
- "\n",
- "print \"Enter value to N :\",n\n",
- "\n",
- "s = 0\n",
- "i = 1\n",
- "\n",
- "while (i <= n):\n",
- " s = s + i\n",
- " i = i + 2\n",
- "\n",
- "print \"Sum of odd integers =\",s"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to N : 10\n",
- "Sum of odd integers = 25\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-90"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to generate first 50 positive integers that are divisible by 7\n",
- "# Variable declaration\n",
- "\n",
- "n = 7\n",
- "print \"Integers divisible by 7\"\n",
- "\n",
- "#loop to print numbers divisible by 7\n",
- "for n in range(7,353,7):\n",
- " print n,\n",
- " \n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Integers divisible by 7\n",
- "7 14 21 28 35 42 49 56 63 70 77 84 91 98 105 112 119 126 133 140 147 154 161 168 175 182 189 196 203 210 217 224 231 238 245 252 259 266 273 280 287 294 301 308 315 322 329 336 343 350\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8 , Page number: CP-91"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print integers from 1 to n that are not divisible by 7\n",
- "# Variable declaration\n",
- "\n",
- "n = 20\n",
- "print \"Enter the end value N :\",n\n",
- "\n",
- "# Loop to print numbers that are not divisible by 7\n",
- "\n",
- "print \"Integers not divisible by 7\"\n",
- "for k in range(1,n + 1,1):\n",
- " r = k % 7\n",
- " if (r != 0):\n",
- " print k,"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the end value N : 20\n",
- "Integers not divisible by 7\n",
- "1 2 3 4 5 6 8 9 10 11 12 13 15 16 17 18 19 20\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-92 "
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print sum of digits of an integer\n",
- "# Variable declaration\n",
- "\n",
- "n = 2466\n",
- "\n",
- "print \"Enter a positive integer :\",n\n",
- "\n",
- "q = n\n",
- "s = 0\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " s = s + r\n",
- " q = q / 10\n",
- "\n",
- "\n",
- "print \"Sum of digits =\",s\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a positive integer : 2466\n",
- "Sum of digits = 18\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-93"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to check whether a given number is an armstrong number or not\n",
- "# Variable declaration\n",
- "\n",
- "n = 153\n",
- "q = n\n",
- "s = 0\n",
- "\n",
- "print \"Enter an integer number :\",n\n",
- "\n",
- "# To check armstrong or not\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " s = s + r * r * r\n",
- " q = q / 10\n",
- "\n",
- "if (n == s):\n",
- " print \"%d is an Armstrong number\" % n\n",
- "else:\n",
- " print \"%d is not an Armstrong number\" % n\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter an integer number : 153\n",
- "153 is an Armstrong number\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11 , Page number: CP-94"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to reverse a given integer\n",
- "# Variable declaration\n",
- "\n",
- "n = 18532\n",
- "q = n\n",
- "rn = 0\n",
- "\n",
- "print \"Enter an integer number :\",n\n",
- "# Reversing\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " rn = (rn * 10) + r\n",
- " q = q / 10\n",
- "\n",
- "\n",
- "print \"18532 is reversed as\",rn "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter an integer number : 18532\n",
- "18532 is reversed as 23581\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 12 , Page number: CP-95"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to accept an integer and print digits using words\n",
- "# Variable declaration\n",
- "\n",
- "n = 4352\n",
- "q = n\n",
- "rn = 0\n",
- "\n",
- "print \"Enter an integer number :\",n\n",
- "# converting to digits\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " rn = rn * 10 + r\n",
- " q = q / 10\n",
- "\n",
- "\n",
- "while (rn > 0):\n",
- " r = rn % 10\n",
- " if (r == 1):\n",
- " s = \"One\"\n",
- " print s,\n",
- " elif (r == 2):\n",
- " s = \"Two\"\n",
- " print s,\n",
- " elif (r == 3):\n",
- " s = \"Three\"\n",
- " print s,\n",
- " elif (r == 4):\n",
- " s = \"Four\"\n",
- " print s,\n",
- " elif (r == 5):\n",
- " s = \"Five\"\n",
- " print s,\n",
- " elif (r == 6):\n",
- " s = \"Six\"\n",
- " print s,\n",
- " elif (r == 7):\n",
- " s = \"Seven\"\n",
- " print s,\n",
- " elif (r == 8):\n",
- " s = \"Eight\"\n",
- " print s,\n",
- " elif (r == 9):\n",
- " s = \"Nine\"\n",
- " print s,\n",
- " elif (r == 0):\n",
- " s = \"Zero\"\n",
- " print s,\n",
- " rn = rn / 10\n",
- "\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter an integer number : 4352\n",
- "Four Three Five Two\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 13 , Page number: CP-97"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find whether a number is prime or not\n",
- "# Variable declaration\n",
- "\n",
- "n = 17\n",
- "\n",
- "print \"Enter a positive integer :\",n\n",
- "\n",
- "# prime numbers are greater than 1\n",
- "if n > 1:\n",
- " # check for factors\n",
- " for i in range(2,n):\n",
- " if (n % i) == 0:\n",
- " print(n,\"is not a prime number\")\n",
- " print(i,\"times\",n//i,\"is\",num)\n",
- " break\n",
- " else:\n",
- " print \"%d is a prime number\" % n\n",
- "\n",
- "else:\n",
- " print \"%d is not a prime number\" % n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a positive integer : 17\n",
- "17 is a prime number\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 14 , Page number: CP-98"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to generate Fibonacci series\n",
- "# Variable declaration\n",
- "\n",
- "n = 25\n",
- "n1 = 0\n",
- "n2 = 1\n",
- "\n",
- "print \"Enter the final term of the series :\",n\n",
- "\n",
- "print n1,n2,\n",
- "\n",
- "\n",
- "newterm = n1 + n2\n",
- "\n",
- "# Loop to print fibonacci series\n",
- "while (newterm <= n):\n",
- " print newterm,\n",
- " n1 = n2\n",
- " n2 = newterm\n",
- " newterm = n1 + n2\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the final term of the series : 25\n",
- "0 1 1 2 3 5 8 13 21\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 15 , Page number: CP-99"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to solve the sine series\n",
- "# Variable declaration\n",
- "\n",
- "x = 0.52\n",
- "n = 10\n",
- "s = 0\n",
- "term = x\n",
- "i = 1\n",
- "\n",
- "print \"Enter x in radians :\",x\n",
- "print \"Enter end term power (n):\",n\n",
- "\n",
- "while (i <= n):\n",
- " s = s + term\n",
- " term = (term * x * x *(-1)) / ((i + 1) * (i + 2))\n",
- " i = i + 2\n",
- "\n",
- "print \"Sum of the series = %0.6f\" % s\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter x in radians : 0.52\n",
- "Enter end term power (n): 10\n",
- "Sum of the series = 0.496880\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 16 , Page number: CP-101"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to solve the cosine series\n",
- "# Variable declaration\n",
- "\n",
- "x = 0.52\n",
- "s = 0\n",
- "term = 1\n",
- "i = 0\n",
- "n = 10\n",
- "print \"Enter x in radians :\",x\n",
- "\n",
- "# Calculation of cosine series\n",
- "\n",
- "while (i <= n):\n",
- " s = s + term\n",
- " term = (term * x * x * (-1)) / ((i + 1) * (i + 2))\n",
- " i = i + 2\n",
- "\n",
- "\n",
- "print \"Sum of the series = %0.6f\" % s "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter x in radians : 0.52\n",
- "Sum of the series = 0.867819\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 17 , Page number: CP-102"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "\n",
- "# Program to compute the value of pie\n",
- "# Variable declaration\n",
- "\n",
- "s = 0.0\n",
- "dr = 1\n",
- "sign = 1\n",
- "term = (1.0/dr) * sign\n",
- "while (math.fabs(term) >= 1.0e-4):\n",
- " s = s + term\n",
- " dr = dr + 2\n",
- " sign = sign * -1\n",
- " term = (1.0 / dr) * sign\n",
- "\n",
- "pie = s * 4\n",
- "\n",
- "print \"Value of pie is %.6f\"%pie"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Value of pie is 3.141393\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 18 , Page number: CP-104"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to evaluate the series\n",
- "# Variable declaration\n",
- "\n",
- "n = 15\n",
- "s = 0.00\n",
- "\n",
- "print \"Enter value to N :\",n\n",
- "\n",
- "# Evaluation of series\n",
- "\n",
- "for i in range(1,n + 1,1):\n",
- " s = float(s) + float(1.0 / i)\n",
- " \n",
- "\n",
- "print \"Sum of series = %0.4f\" % s \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to N : 15\n",
- "Sum of series = 3.3182\n"
- ]
- }
- ],
- "prompt_number": 18
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 21 , Page number: CP-108"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print multiplication table\n",
- "# Variable declaration\n",
- "\n",
- "i = 1\n",
- "j = 1\n",
- "\n",
- "# nested loop to print multiplication tables\n",
- "\n",
- "for i in range(1,6):\n",
- " print \"Multiplication table for\",i\n",
- " for j in range(1,11):\n",
- " print \" \",j,\"x\" , i ,\" =\" , j*i\n",
- " print \"Press any key to continue. . .\" "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Multiplication table for 1\n",
- " 1 x 1 = 1\n",
- " 2 x 1 = 2\n",
- " 3 x 1 = 3\n",
- " 4 x 1 = 4\n",
- " 5 x 1 = 5\n",
- " 6 x 1 = 6\n",
- " 7 x 1 = 7\n",
- " 8 x 1 = 8\n",
- " 9 x 1 = 9\n",
- " 10 x 1 = 10\n",
- "Press any key to continue. . .\n",
- "Multiplication table for 2\n",
- " 1 x 2 = 2\n",
- " 2 x 2 = 4\n",
- " 3 x 2 = 6\n",
- " 4 x 2 = 8\n",
- " 5 x 2 = 10\n",
- " 6 x 2 = 12\n",
- " 7 x 2 = 14\n",
- " 8 x 2 = 16\n",
- " 9 x 2 = 18\n",
- " 10 x 2 = 20\n",
- "Press any key to continue. . .\n",
- "Multiplication table for 3\n",
- " 1 x 3 = 3\n",
- " 2 x 3 = 6\n",
- " 3 x 3 = 9\n",
- " 4 x 3 = 12\n",
- " 5 x 3 = 15\n",
- " 6 x 3 = 18\n",
- " 7 x 3 = 21\n",
- " 8 x 3 = 24\n",
- " 9 x 3 = 27\n",
- " 10 x 3 = 30\n",
- "Press any key to continue. . .\n",
- "Multiplication table for 4\n",
- " 1 x 4 = 4\n",
- " 2 x 4 = 8\n",
- " 3 x 4 = 12\n",
- " 4 x 4 = 16\n",
- " 5 x 4 = 20\n",
- " 6 x 4 = 24\n",
- " 7 x 4 = 28\n",
- " 8 x 4 = 32\n",
- " 9 x 4 = 36\n",
- " 10 x 4 = 40\n",
- "Press any key to continue. . .\n",
- "Multiplication table for 5\n",
- " 1 x 5 = 5\n",
- " 2 x 5 = 10\n",
- " 3 x 5 = 15\n",
- " 4 x 5 = 20\n",
- " 5 x 5 = 25\n",
- " 6 x 5 = 30\n",
- " 7 x 5 = 35\n",
- " 8 x 5 = 40\n",
- " 9 x 5 = 45\n",
- " 10 x 5 = 50\n",
- "Press any key to continue. . .\n"
- ]
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 22 , Page number: CP-109"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "\n",
- "# Program to convert a binary number to a decimal number\n",
- "# Variable declaration\n",
- "\n",
- "q = 1101\n",
- "s = 0\n",
- "k = 0\n",
- "\n",
- "print \"Enter the binary number :\",q\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " s = s + r * pow(2,k)\n",
- " q = q / 10\n",
- " k = k + 1\n",
- "\n",
- "\n",
- "print \"The decimal number is :\",s\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the binary number : 1101\n",
- "The decimal number is : 13\n"
- ]
- }
- ],
- "prompt_number": 20
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 23 , Page number: CP-110"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to convert a decimal number to a binary number\n",
- "# Variable declaration\n",
- "\n",
- "n = 28\n",
- "q = n\n",
- "rbi = 0\n",
- "flag = 0\n",
- "k = 0\n",
- "\n",
- "print \"Enter the decimal number :\",n\n",
- "\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 2\n",
- " if (r == 0) and (flag == 0):\n",
- " k = k + 1\n",
- " else:\n",
- " flag = 1\n",
- " rbi = rbi * 10 + r\n",
- " q = q / 2\n",
- " \n",
- "q = rbi\n",
- "bi = 0\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " bi = bi * 10 + r\n",
- " q = q / 10\n",
- " i = 1\n",
- " if (q == 0):\n",
- " while (i <= k):\n",
- " bi = bi * 10\n",
- " i = i + 1\n",
- "\n",
- "\n",
- "print \"The binary number is \",bi "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the decimal number : 28\n",
- "The binary number is 11100\n"
- ]
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice/Chapter6.ipynb b/Computer_Programming,_Theory_and_Practice/Chapter6.ipynb
deleted file mode 100755
index 14969fc1..00000000
--- a/Computer_Programming,_Theory_and_Practice/Chapter6.ipynb
+++ /dev/null
@@ -1,794 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:aced1a8512bbd1c950b44a0ce98d7bb529f62e617c89b1c73eec08ce49b27311"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 6: Arrays and Subscribed Variables"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-122"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the sum of n numbers using array\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "x = [36,45,52,44,62]\n",
- "\n",
- "print \"How many integers ?\",n\n",
- "print \"Enter the 1th value :\",x[0]\n",
- "print \"Enter the 2th value :\",x[1]\n",
- "print \"Enter the 3th value :\",x[2]\n",
- "print \"Enter the 4th value :\",x[3]\n",
- "print \"Enter the 5th value :\",x[4]\n",
- "\n",
- "summ = 0 \n",
- "\n",
- "# Calculation of sum of numbers\n",
- "for i in x:\n",
- " summ = summ + i\n",
- " \n",
- "\n",
- "print \"Sum of all integers =\",summ\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many integers ? 5\n",
- "Enter the 1th value : 36\n",
- "Enter the 2th value : 45\n",
- "Enter the 3th value : 52\n",
- "Enter the 4th value : 44\n",
- "Enter the 5th value : 62\n",
- "Sum of all integers = 239\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-123"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the biggest of n numbers\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "x = [25,-228,0,185,36]\n",
- "\n",
- "print \"How many numbers ?\",n\n",
- "print \"Enter all those numbers\"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "\n",
- "big = x[0]\n",
- "\n",
- "\n",
- "for i in x:\n",
- " if (i > big):\n",
- " big = i\n",
- "\n",
- "\n",
- "print \"%d is the biggest number\" % big "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers ? 5\n",
- "Enter all those numbers\n",
- "25 -228 0 185 36\n",
- "185 is the biggest number\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: Cp-124"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the arithmetic mean, variance and standard deviation\n",
- "# Variable declaration\n",
- "\n",
- "n = 6\n",
- "x = [3.1,3.8,3.6,4.0,3.4,3.8]\n",
- "summ = 0\n",
- "vsum = 0\n",
- "\n",
- "print \"How many values ?\",n\n",
- "print \"Enter all values in the list \"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "\n",
- "# Loop to find sum of all values\n",
- "\n",
- "for i in x:\n",
- " summ = summ + i\n",
- "\n",
- "xbar = summ / n\n",
- "\n",
- "# Loop to find the numerator vsum to find variance\n",
- "\n",
- "for i in x:\n",
- " vsum = vsum + (i - xbar) * (i - xbar)\n",
- "\n",
- "\n",
- "sigmax = vsum / n\n",
- "sd = sigmax ** 0.5\n",
- "\n",
- "print \"Arithmetic mean = %0.3f\" % xbar\n",
- "print \"Variance = %0.3f \" % sigmax\n",
- "print \"Standard deviation = %0.3f\" % sd"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many values ? 6\n",
- "Enter all values in the list \n",
- "3.1 3.8 3.6 4.0 3.4 3.8\n",
- "Arithmetic mean = 3.617\n",
- "Variance = 0.088 \n",
- "Standard deviation = 0.297\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-126"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to calculate mean of marks and print list of marks greater than mean\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "x = [58,63,68,54,48]\n",
- "summ = 0 # Used summ instead of sum since it was a inbuilt function\n",
- "i = 0\n",
- "\n",
- "print \"How many students ?\",n\n",
- "print \"Enter all the marks \"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "\n",
- "for i in x:\n",
- " summ = summ + i\n",
- "\n",
- "mean = float(summ) / n\n",
- "\n",
- "print \"Mean = %0.2f\" % mean\n",
- "print \"Marks greater than mean :\",\n",
- "\n",
- "i = 0\n",
- "for i in x:\n",
- " if (i > mean):\n",
- " print i,\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many students ? 5\n",
- "Enter all the marks \n",
- "58 63 68 54 48\n",
- "Mean = 58.20\n",
- "Marks greater than mean : 63 68\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-127"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find sum of all positive and negative numbers and to find out which is larger in magnitude\n",
- "# Variable declaration\n",
- "import math\n",
- "\n",
- "n = 6\n",
- "x = [8,-12,-16,12,-9,5]\n",
- "psum = 0\n",
- "nsum = 0\n",
- "\n",
- "print \"How many values ?\",n\n",
- "print \"Enter all values in the list\"\n",
- "for i in x:\n",
- " print i,\n",
- "print \n",
- "\n",
- "# Loop to calculate sum of positive and negative values\n",
- "\n",
- "for i in x:\n",
- " if i > 0:\n",
- " psum = psum + i\n",
- " else:\n",
- " nsum = nsum + i\n",
- "\n",
- "print \"Sum of positive values = %0.2f\" % psum\n",
- "print \"Sum of negative values = %0.2f\" % nsum\n",
- "\n",
- "if (psum > abs(nsum)):\n",
- " print \"Positive sum is greater in magnitude\"\n",
- "else:\n",
- " print \"Negative sum is greater in magnitude\"\n",
- "\n",
- "diff = abs(psum) - abs(nsum)\n",
- "print \"Difference in magnitude = %0.2f\" % abs(diff)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many values ? 6\n",
- "Enter all values in the list\n",
- "8 -12 -16 12 -9 5\n",
- "Sum of positive values = 25.00\n",
- "Sum of negative values = -37.00\n",
- "Negative sum is greater in magnitude\n",
- "Difference in magnitude = 12.00\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-129"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to sort n numbers in ascending order\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "x = [32,-10,20,5]\n",
- "i = 0\n",
- "\n",
- "\n",
- "print \"How many numbers ?\",n\n",
- "print \"Enter the list of 4 numbers\"\n",
- "for a in x:\n",
- " print a,\n",
- "print\n",
- "\n",
- "# Loop to arrange the numbers in ascending order\n",
- "\n",
- "while i < n-1:\n",
- " j = i + 1\n",
- " while j < n:\n",
- " if x[i] > x[j]:\n",
- " temp = x[i]\n",
- " x[i] = x[j]\n",
- " x[j] = temp\n",
- " j = j + 1\n",
- " i = i + 1\n",
- "\n",
- "print \"Numbers in ascending order \"\n",
- "\n",
- "for a in x:\n",
- " print a,\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers ? 4\n",
- "Enter the list of 4 numbers\n",
- "32 -10 20 5\n",
- "Numbers in ascending order \n",
- "-10 5 20 32\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-131"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to search the key value and to print it if the search is successful\n",
- "# Variable declaration\n",
- "\n",
- "n = 6\n",
- "x = [6,-2,8,3,13,10]\n",
- "s = 3\n",
- "\n",
- "print \"How many values in the list ?\",n\n",
- "print \"Enter all values in the list\"\n",
- "for i in x:\n",
- " print i,\n",
- "print \n",
- "print \"Enter the key value to be searched :\",s\n",
- "\n",
- "# loop to search key value in the list\n",
- "\n",
- "for i in range(n):\n",
- " if s == x[i]:\n",
- " print s,\" is available in\",i+1,\"th location\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many values in the list ? 6\n",
- "Enter all values in the list\n",
- "6 -2 8 3 13 10\n",
- "Enter the key value to be searched : 3\n",
- "3 is available in 4 th location\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8 , Page number: CP-133"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to sort n numbers using bubble sort and find number of exchanges and passes\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "x = [6,-2,8,3]\n",
- "exchng = 0\n",
- "\n",
- "print \"How many numbers?\",n\n",
- "print \"Enter all the numbers in the list\"\n",
- "for i in x:\n",
- " print i,\n",
- "\n",
- "print\n",
- "\n",
- "for i in range(0,n-1):\n",
- " for j in range(0,n-i-1):\n",
- " if x[j] > x[j+1]:\n",
- " temp = x[j]\n",
- " x[j] = x[j+1]\n",
- " x[j+1] = temp\n",
- " exchng = exchng + 1\n",
- " \n",
- "\n",
- "print \"The sorted list is\"\n",
- "for i in x:\n",
- " print i,\n",
- "\n",
- "print \n",
- "\n",
- "print \"Sorted in\",n-1,\"passes and\",exchng,\"exchanges\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers? 4\n",
- "Enter all the numbers in the list\n",
- "6 -2 8 3\n",
- "The sorted list is\n",
- "-2 3 6 8\n",
- "Sorted in 3 passes and 3 exchanges\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-135"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to add two matrices\n",
- "# Variable declaration\n",
- "\n",
- "a = [[2,-2],\n",
- " [0,4]]\n",
- "b = [[6,2],\n",
- " [4,-5]]\n",
- "\n",
- "c = [[0,0],\n",
- " [0,0]]\n",
- "\n",
- "m = 2\n",
- "n = 2\n",
- "\n",
- "print \"How many rows and columns ?\",m,n\n",
- "print \"Enter A matrix\"\n",
- "for i in a:\n",
- " print i\n",
- "\n",
- "print \"Enter B matrix\"\n",
- "for j in b:\n",
- " print j\n",
- "\n",
- "# Loop to add two matrices\n",
- "\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " c[i][j] = a[i][j] + b[i][j]\n",
- "\n",
- "\n",
- "print \"Resultant matrix is\"\n",
- "for ci in c:\n",
- " print ci"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many rows and columns ? 2 2\n",
- "Enter A matrix\n",
- "[2, -2]\n",
- "[0, 4]\n",
- "Enter B matrix\n",
- "[6, 2]\n",
- "[4, -5]\n",
- "Resultant matrix is\n",
- "[8, 0]\n",
- "[4, -1]\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-136"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to multiply two matrices\n",
- "# Variable declaration\n",
- "\n",
- "m = 2\n",
- "n = 2\n",
- "l = 2\n",
- "a = [[2,-2],\n",
- " [0,4]]\n",
- "b = [[6,2],\n",
- " [4,-5]]\n",
- "c = [[0,0],\n",
- " [0,0]]\n",
- "\n",
- "print \"Enter order of A matrix :\",m,n\n",
- "print \"Enter A matrix\"\n",
- "for i in a:\n",
- " print i\n",
- "print \"Enter order of B matrix :\",m,n\n",
- "print \"Enter B matrix\"\n",
- "for j in b:\n",
- " print j\n",
- "\n",
- "# Loop to multiply two matrices\n",
- "# iterate through rowa of A\n",
- "for i in range(m):\n",
- " # iterate through columns of B\n",
- " for j in range(l):\n",
- " c[i][j] = 0\n",
- " # iterate through rows of B\n",
- " for k in range(n):\n",
- " c[i][j] = c[i][j] + a[i][k] * b[k][j]\n",
- "\n",
- "\n",
- "print \"Resultant matrix is\"\n",
- "\n",
- "for i in c:\n",
- " print i\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter order of A matrix : 2 2\n",
- "Enter A matrix\n",
- "[2, -2]\n",
- "[0, 4]\n",
- "Enter order of B matrix : 2 2\n",
- "Enter B matrix\n",
- "[6, 2]\n",
- "[4, -5]\n",
- "Resultant matrix is\n",
- "[4, 14]\n",
- "[16, -20]\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11 , Page number: CP-138"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find and print the transpose of the matrix\n",
- "# Variable declaration\n",
- "\n",
- "m = 2\n",
- "n = 3\n",
- "a = [[-3,6,0],\n",
- " [3,2,8]]\n",
- "at = [[0,0],\n",
- " [0,0],\n",
- " [0,0]]\n",
- "\n",
- "print \"Enter order of the matrix :\",m,n\n",
- "print \"Enter the matrix values\"\n",
- "for i in a :\n",
- " print i\n",
- "\n",
- "# Loop to calculate transpose\n",
- "\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " at[j][i] = a[i][j]\n",
- "\n",
- "print \"The transposed matrix is \"\n",
- "for i in at:\n",
- " print i\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter order of the matrix : 2 3\n",
- "Enter the matrix values\n",
- "[-3, 6, 0]\n",
- "[3, 2, 8]\n",
- "The transposed matrix is \n",
- "[-3, 3]\n",
- "[6, 2]\n",
- "[0, 8]\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 12 ,Page number: CP-139"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to check whether a given matrix is symmetric or not\n",
- "# Variable declaration\n",
- "\n",
- "m = 3\n",
- "a = [[5,3,8],\n",
- " [3,1,-7],\n",
- " [8,-7,4]]\n",
- "\n",
- "print \"Enter order of the square matrix :\",m\n",
- "for i in a:\n",
- " print i\n",
- "\n",
- "# Loop to check whether symmetric or not\n",
- "\n",
- "for i in range(m):\n",
- " flag = 0\n",
- " for j in range(m):\n",
- " flag = 0\n",
- " if a[i][j] == a[j][i]:\n",
- " continue\n",
- " else:\n",
- " flag = 1\n",
- "\n",
- "if flag == 0:\n",
- " print \"The given matrix is a symmetric matrix\"\n",
- "else:\n",
- " print \"The given matrix is not a symmetric matrix\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter order of the square matrix : 3\n",
- "[5, 3, 8]\n",
- "[3, 1, -7]\n",
- "[8, -7, 4]\n",
- "The given matrix is a symmetric matrix\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 13 , Page number: CP-141"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the trace of a given square matrix\n",
- "# Variable dclaration\n",
- "\n",
- "m = 3\n",
- "a = [[3,2,-1],\n",
- " [4,1,8],\n",
- " [6,4,2]]\n",
- "summ = 0\n",
- "\n",
- "print \"Enter order of the square matrix :\",m\n",
- "print \"Enter the matrix\"\n",
- "for i in a:\n",
- " print i\n",
- "\n",
- "# Loop to find trace\n",
- "for i in range(m):\n",
- " summ = summ + a[i][i]\n",
- "\n",
- "print \"Trace of the matrix =\",summ "
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice/Chapter7.ipynb b/Computer_Programming,_Theory_and_Practice/Chapter7.ipynb
deleted file mode 100755
index 0d79c17f..00000000
--- a/Computer_Programming,_Theory_and_Practice/Chapter7.ipynb
+++ /dev/null
@@ -1,557 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:37ae6cc76fe6f4a8cc8dba62582a6a103f99da5c7579d1a782cb95241f542fd8"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-148"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to count the occurence of a particular in a string\n",
- "# Variable declaration\n",
- "\n",
- "st = \"MISSISSIPPI\"\n",
- "ch = \"S\"\n",
- "count = 0\n",
- "\n",
- "print \"Enter the string :\",st\n",
- "print \"Which character to be counted ?\",ch\n",
- "\n",
- "# Loop to check occurrence of aa character\n",
- "\n",
- "l = len(st)\n",
- "\n",
- "for i in st:\n",
- " if i == ch:\n",
- " count = count + 1\n",
- "\n",
- "print \"The character \" + ch + \" occurs %d times\" % count "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the string : MISSISSIPPI\n",
- "Which character to be counted ? S\n",
- "The character S occurs 4 times\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-149"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to count the number of vowels in a sentence\n",
- "# Variable declaration\n",
- "\n",
- "st = \"This is a book\"\n",
- "count = 0\n",
- "\n",
- "print \"Enter the sentence :\"\n",
- "print st\n",
- "\n",
- "# Loop to count the vowels in the string\n",
- "\n",
- "for i in st:\n",
- " if i == \"A\":\n",
- " count = count + 1\n",
- " elif i == \"E\":\n",
- " count = count + 1\n",
- " elif i == \"I\":\n",
- " count = count + 1\n",
- " elif i == \"O\":\n",
- " count = count + 1\n",
- " elif i == \"U\":\n",
- " count = count + 1\n",
- " elif i == \"a\":\n",
- " count = count + 1\n",
- " elif i == \"e\":\n",
- " count = count + 1\n",
- " elif i == \"i\":\n",
- " count = count + 1\n",
- " elif i == \"o\":\n",
- " count = count + 1\n",
- " elif i == \"u\":\n",
- " count = count + 1\n",
- "\n",
- "print \"%d vowels are present in the sentence\" % count\n",
- " \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the sentence :\n",
- "This is a book\n",
- "5 vowels are present in the sentence\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-150"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to test whether a given string is a palindrome or not\n",
- "# Variable declaration\n",
- "\n",
- "st = \"HYDERABAD\"\n",
- "rst = \"\"\n",
- "i = 0\n",
- "j = len(st) - 1\n",
- "\n",
- "print \"Enter the string :\",st\n",
- "\n",
- "# Palindrome or not \n",
- "\n",
- "rst = reversed(st)\n",
- "\n",
- "if list(st) == list(rst):\n",
- " print \"%s is a palindrome string \" % st\n",
- "else:\n",
- " print \"%s is not a palindrome string \" % st"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the string : HYDERABAD\n",
- "HYDERABAD is not a palindrome string \n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-152"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to conctenate two strings\n",
- "# Variable declaration\n",
- "\n",
- "st1 = \"NEW \"\n",
- "st2 = \"DELHI\"\n",
- "\n",
- "# input of two strings to be concatenated\n",
- "\n",
- "print \"Enter first string :\",st1\n",
- "print \"Enter second string :\",st2\n",
- "\n",
- "# concatenation of two strings\n",
- "st = st1 + st2\n",
- "\n",
- "print \"Resultant string is \",st "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter first string : NEW \n",
- "Enter second string : DELHI\n",
- "Resultant string is NEW DELHI\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-154"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to compare two strings\n",
- "# Variable declaration\n",
- "\n",
- "st1 = \"ALPHA\"\n",
- "st2 = \"BETA\"\n",
- "\n",
- "print \"Enter string 1:\",st1\n",
- "print \"Enter string 2:\",st2\n",
- "\n",
- "# compare strings\n",
- "\n",
- "if (cmp(st1,st2)>0):\n",
- " print \"%s \" + st1 + \"is alphabetically greater string\"\n",
- "else:\n",
- " print st2 + \" is alphabetically greater string\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter string 1: ALPHA\n",
- "Enter string 2: BETA\n",
- "BETA is alphabetically greater string\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-155"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to sort an array of names in alphabetical order\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "names = [\"DEEPAK\",\"SHERIN\",\"SONIKA\",\"ARUN\"]\n",
- "\n",
- "print \"How many names ?\",n\n",
- "print \"Enter the 4 names one by one\"\n",
- "for i in names:\n",
- " print i\n",
- "\n",
- "# Loop to arrange names in alphabetical order\n",
- "\n",
- "for i in range(0,n-1):\n",
- " for j in range(i+1,n):\n",
- " if cmp(names[i],names[j])>0:\n",
- " \n",
- " temp = names[i]\n",
- " names[i] = names[j]\n",
- " names[j] = temp\n",
- "\n",
- "print \"Names in alphabetical order\"\n",
- "for i in names:\n",
- " print i"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many names ? 4\n",
- "Enter the 4 names one by one\n",
- "DEEPAK\n",
- "SHERIN\n",
- "SONIKA\n",
- "ARUN\n",
- "Names in alphabetical order\n",
- "ARUN\n",
- "DEEPAK\n",
- "SHERIN\n",
- "SONIKA\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-157"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to convert a line from lower case to upper case\n",
- "# Variable declaretion\n",
- "\n",
- "import sys\n",
- "\n",
- "st = ['l','o','g','i','c','a','l',' ','t','h','i','n','k','i','n','g',' ','i','s',' ','a',' ','m','u','s','t',' ','t','o',' ','l','e','a','r','n',' ','p','r','o','g','r','a','m','m','i','n','g']\n",
- "\n",
- "print \"Enter a sentence :\"\n",
- "for i in st:\n",
- " print i,\n",
- "print \n",
- "print \"The converted upper case string is\"\n",
- "# loop to convert lower case alphabet to upper case text\n",
- "for i in range(len(st)):\n",
- " if st[i] >= 'a' and st[i] <= 'z':\n",
- " st[i] = chr(ord(st[i])-32)\n",
- "\n",
- "\n",
- " sys.stdout.write(st[i])"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a sentence :\n",
- "l o g i c a l t h i n k i n g i s a m u s t t o l e a r n p r o g r a m m i n g\n",
- "The converted upper case string is\n",
- "LOGICAL THINKING IS A MUST TO LEARN PROGRAMMING"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-160"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to read a text and to omit al occurrences of a particular word\n",
- "# Variable declartion\n",
- "\n",
- "st = \"TO ACCESS THE NAME OF THE CITY IN THE LIST\"\n",
- "i = 0\n",
- "omit = \"THE\"\n",
- "l = len(st)\n",
- "j = 0\n",
- "word = []\n",
- "newst = \"\"\n",
- "onesps = \"\"\n",
- "print \"Enter a sentence :\"\n",
- "print st\n",
- "print \"Enter word to omit :\",omit\n",
- "\n",
- "# loop to omit the given word\n",
- "\n",
- "for i in range(l):\n",
- " ch = i\n",
- " if ch == ' ':\n",
- " for j in word:\n",
- " j = \" \" \n",
- " if j == omit:\n",
- " newst = j\n",
- " newst = onesps\n",
- " j = \" \"\n",
- " j = 0\n",
- " else:\n",
- " j = ch\n",
- " j = j + 1\n",
- " i = i + 1\n",
- "\n",
- "print \"After omiting the word \" + omit\n",
- "print newst\n",
- "print \"Press any key to continue\"\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a sentence :\n",
- "TO ACCESS THE NAME OF THE CITY IN THE LIST\n",
- "Enter word to omit : THE\n",
- "After omiting the word THE\n",
- "\n",
- "Press any key to continue\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-161"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to calculate the amount to be paid for the telegram\n",
- "# Variable declaration\n",
- "\n",
- "count = 0\n",
- "st = \"Congratulations on your success in Examinations.\"\n",
- "l = len(st)\n",
- "\n",
- "print \"Type the sentence for Telegram\"\n",
- "print st\n",
- "\n",
- "# loop to count number of words\n",
- "\n",
- "for i in range(l):\n",
- " if st[i] == '?':\n",
- " count = count + 1\n",
- "\n",
- "if count <= 10:\n",
- " amt = 5\n",
- "else:\n",
- " amt = 5 + (count - 10) * 1.25\n",
- "\n",
- "print \"Amount to be paid for telegram = Rs.%0.2f\" % amt "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Type the sentence for Telegram\n",
- "Congratulations on your success in Examinations.\n",
- "Amount to be paid for telegram = Rs.5.00\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11 , Page number: CP-163"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to count number of lines,words and characters\n",
- "# Variable declaration\n",
- "\n",
- "txt = \"What is a string? How do you initialize it? Explain with example.$\"\n",
- "st = \"\"\n",
- "i = 0\n",
- "lns = 0\n",
- "wds = 0\n",
- "chs = 0\n",
- "\n",
- "print \"Enter the text, type $ at end.\"\n",
- "print txt\n",
- "\n",
- "# loop to count lines,words and characters in text\n",
- "\n",
- "while txt[i] != '$':\n",
- " # switch case statements\n",
- " if txt[i] == ' ':\n",
- " wds = wds + 1\n",
- " chs = chs + 1\n",
- " elif txt[i] == '.':\n",
- " wds = wds + 1\n",
- " lns = lns + 1\n",
- " chs = chs + 1\n",
- " elif txt[i] == '?':\n",
- " lns = lns + 1\n",
- " else: # default\n",
- " chs = chs + 1\n",
- "\n",
- " i = i + 1\n",
- "\n",
- "print \"Number of char (incl. blanks) =\",chs\n",
- "print \"Number of words =\",wds\n",
- "print \"Number of lines =\",lns\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the text, type $ at end.\n",
- "What is a string? How do you initialize it? Explain with example.$\n",
- "Number of char (incl. blanks) = 63\n",
- "Number of words = 12\n",
- "Number of lines = 3\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice/Chapter8.ipynb b/Computer_Programming,_Theory_and_Practice/Chapter8.ipynb
deleted file mode 100755
index 49edb490..00000000
--- a/Computer_Programming,_Theory_and_Practice/Chapter8.ipynb
+++ /dev/null
@@ -1,1027 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:0c7b2e51d9ff140f666ba709dd09beff8baf4fe046109218b6f3ac69ed4bb2fe"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-173"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to write a function to find factorial and use it to find nCr\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "r = 3\n",
- "\n",
- "print \"Enter value to n and r :\",n,r\n",
- "\n",
- "# function subprogram to find factorial\n",
- "\n",
- "def fact(k):\n",
- " p = 1\n",
- " for i in range(1,k+1):\n",
- " p = p * i\n",
- " return p\n",
- "\n",
- "\n",
- "ncr = fact(n) / (fact(r) * fact(n-r))\n",
- "\n",
- "\n",
- "print \"Value of nCr =\",ncr"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to n and r : 5 3\n",
- "Value of nCr = 10\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-174"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the biggest of given three values using function and use it to find total marks of the student\n",
- "# Variable declaration\n",
- "\n",
- "t1 = 62\n",
- "t2 = 70\n",
- "t3 = 58\n",
- "a1 = 17\n",
- "a2 = 21\n",
- "a3 = 23\n",
- "\n",
- "print \"Enter three test scores :\",t1,t2,t3\n",
- "print \"Enter three assignment scores :\",a1,a2,a3\n",
- "\n",
- "# function to find biggest of three values\n",
- "\n",
- "def big(a,b,c):\n",
- " if a > b:\n",
- " if a > c:\n",
- " return a\n",
- " else:\n",
- " return c\n",
- " elif b > c:\n",
- " return b\n",
- " else:\n",
- " return c\n",
- "\n",
- "total = big(t1,t2,t3) + big(a1,a2,a3)\n",
- "\n",
- "print \"Total marks =\",total"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three test scores : 62 70 58\n",
- "Enter three assignment scores : 17 21 23\n",
- "Total marks = 93\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-176"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to create a function to compute the cos(x) series upto 15 terms\n",
- "# Variable declaration\n",
- "\n",
- "x = 0\n",
- "\n",
- "print \"----------------------------------\"\n",
- "print \" x in degrees cos(x) \"\n",
- "print \"----------------------------------\"\n",
- "\n",
- "# function for computing cosine function\n",
- "\n",
- "def cosine(x):\n",
- " s = 0\n",
- " i = 0\n",
- " term = 1\n",
- " x = x * (3.14) / 180\n",
- " k = 1\n",
- " # loop to find summation of 15 terms\n",
- " while k <= 15:\n",
- " s = s + term\n",
- " term = term * x * x * (-1) / ((i + 1) * (i + 2))\n",
- " i = i + 2\n",
- " k = k + 1\n",
- " return s\n",
- "\n",
- "\n",
- "# calling function\n",
- "\n",
- "while x <= 180:\n",
- " print \" %d \" % x,\" %0.2f \"%cosine(x)\n",
- " x = x + 30\n",
- "\n",
- "print \"-----------------------------------\" "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "----------------------------------\n",
- " x in degrees cos(x) \n",
- "----------------------------------\n",
- " 0 1.00 \n",
- " 30 0.87 \n",
- " 60 0.50 \n",
- " 90 0.00 \n",
- " 120 -0.50 \n",
- " 150 -0.87 \n",
- " 180 -1.00 \n",
- "-----------------------------------\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-177"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find GCD of two integers\n",
- "# Variable declaration\n",
- "\n",
- "a = 45\n",
- "b = 27\n",
- "c = 81\n",
- "\n",
- "print \"Enter three integers :\",a,b,c\n",
- "\n",
- "def gcd(x,y):\n",
- " if x >= y:\n",
- " nr = x\n",
- " dr = y\n",
- " else:\n",
- " nr = y\n",
- " dr = x\n",
- " r = nr % dr\n",
- " while r != 0:\n",
- " nr = dr\n",
- " dr = r\n",
- " r = nr % dr\n",
- "\n",
- " return dr\n",
- "\n",
- "d1 = gcd(a,b)\n",
- "d2 = gcd(a,c)\n",
- "d3 = gcd(b,c)\n",
- "\n",
- "if d1 == d2:\n",
- " if d1 == d3:\n",
- " print \"Greatest common divisor is\",d1\n",
- " else:\n",
- " print \"Greatest common divisor is \",gcd(d1,d3)\n",
- "else:\n",
- " print \"Greatest common divisr is\",gcd(d1,d2)\n",
- "\n",
- "\n",
- "print \"Press any key to continue. . .\" "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three integers : 45 27 81\n",
- "Greatest common divisor is 9\n",
- "Press any key to continue. . .\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-178"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to reverse the given integer\n",
- "# Variable declaration\n",
- "\n",
- "n = 2846\n",
- "\n",
- "print \"Enter the integer :\",n\n",
- "\n",
- "# function to reverse an integer\n",
- "\n",
- "def reverse(n):\n",
- " rn = 0\n",
- " while n > 0:\n",
- " r = n % 10\n",
- " rn = rn * 10 + r\n",
- " n = n /10\n",
- " return rn\n",
- "\n",
- "\n",
- "# call the function to print the reverse integer\n",
- "\n",
- "print n,\"is reversed as \",reverse(n)\n",
- "print \"Press any key to continue. . .\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the integer : 2846\n",
- "2846 is reversed as 6482\n",
- "Press any key to continue. . .\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-179"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to compare two strings S1 and S2 and return the result 0,1,-1\n",
- "# Variable declaration\n",
- "\n",
- "s1 = \"MUMBAI\"\n",
- "s2 = \"MYSORE\"\n",
- "\n",
- "print \"Enter the first string :\",s1\n",
- "print \"Enter the second string :\",s2\n",
- "\n",
- "\n",
- "# function to compare the strings\n",
- "\n",
- "def compare(s1,s2):\n",
- " if cmp(s1,s2) == 0:\n",
- " return 0\n",
- " if cmp(s1,s2) > 0:\n",
- " return 1\n",
- " if cmp(s1,s2) < 0:\n",
- " return -1\n",
- "\n",
- "# call the function to print the result\n",
- "\n",
- "print \"The result is \", compare(s1,s2)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the first string : MUMBAI\n",
- "Enter the second string : MYSORE\n",
- "The result is -1\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-181"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the arithmetic mean of n values using a function\n",
- "# Variable declaration\n",
- "\n",
- "n = 6\n",
- "x = [3.1,3.8,3.6,4.0,3.4,3.8]\n",
- "\n",
- "print \"How many values ?\",n\n",
- "print \"Enter all values\"\n",
- "for i in x:\n",
- " print i,\n",
- "print \n",
- "# function to find arithmetic mean\n",
- "\n",
- "def amean(x,n):\n",
- " s = 0\n",
- " for i in range(n):\n",
- " s = s + x[i]\n",
- " return (s/n)\n",
- "\n",
- "# call function to print arithmetic mean\n",
- "\n",
- "print \"Arithmetic mean = %0.2f\" % amean(x,n)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many values ? 6\n",
- "Enter all values\n",
- "3.1 3.8 3.6 4.0 3.4 3.8\n",
- "Arithmetic mean = 3.62\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8 , Page number: CP-182"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to read a matrix of order m x n and print the sum of all elements using functions\n",
- "# Variable declaration\n",
- "\n",
- "m = 3\n",
- "n = 2\n",
- "a = [[2,3,4],\n",
- " [2,0,1]]\n",
- "\n",
- "\n",
- "print \"How many rows and columns :\",m,n\n",
- "print \"Enter the matrix values\"\n",
- "for i in range(n):\n",
- " for j in range(m):\n",
- " print a[i][j],\n",
- " print \n",
- "\n",
- "# function to add all elements in the matrix\n",
- "def elem_sum(a,m,n):\n",
- " i = 0\n",
- " j = 0\n",
- " s = 0\n",
- " for i in range(n):\n",
- " for j in range(m):\n",
- " s = s + a[i][j]\n",
- " j = j + 1\n",
- " i = i + 1 \n",
- " return s\n",
- "\n",
- "# call function to print the result\n",
- "\n",
- "print \"Sum of all elements in the matrix =\",\n",
- "print elem_sum(a,m,n)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many rows and columns : 3 2\n",
- "Enter the matrix values\n",
- "2 3 4\n",
- "2 0 1\n",
- "Sum of all elements in the matrix = 12\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-183"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to reverse a string\n",
- "# Variable declaration\n",
- "\n",
- "st = \"NEW DELHI\"\n",
- "print \"Enter a string :\",st\n",
- "def reverse(st):\n",
- " rst = \"\"\n",
- " for i in range(0 ,len(st)):\n",
- " rst += st[(len(st) -1) - i]\n",
- " return rst\n",
- "\n",
- "print st,\"is reversed as \",\n",
- "print reverse(st)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a string : NEW DELHI\n",
- "NEW DELHI is reversed as IHLED WEN\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-184"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to apply binary search to set of N numbers using a function\n",
- "# Variable declaration\n",
- "\n",
- "n = 10\n",
- "x = [-3,8,13,19,21,25,26,29,35,42]\n",
- "s = 19\n",
- "\n",
- "\n",
- "print \"How many numbers ?\",n\n",
- "print \"Enter all numbers in the list\"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "print \"Enter the number to be searched :\",s\n",
- "\n",
- "# function to search the number\n",
- "\n",
- "def bi_search(x,n,s):\n",
- " flag = 0\n",
- " start = 0\n",
- " end = n\n",
- " while start < end and flag ==0:\n",
- " mid = (start + end) / 2\n",
- " if x[mid] > s:\n",
- " end = mid\n",
- " elif x[mid] < s:\n",
- " start = mid + 1\n",
- " else:\n",
- " flag = 1\n",
- " return flag\n",
- "\n",
- "# calling the function\n",
- "\n",
- "if bi_search(x,n,s):\n",
- " print \"The number\",s,\"is present in the list\"\n",
- "else:\n",
- " print \"The number\",s,\"is not present in list\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers ? 10\n",
- "Enter all numbers in the list\n",
- "-3 8 13 19 21 25 26 29 35 42\n",
- "Enter the number to be searched : 19\n",
- "The number 19 is present in the list\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11 , Page number: CP-187"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find factorial of a given number using recursive function\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "r = 3\n",
- "\n",
- "print \"Enter the values to n and r :\",n,r\n",
- "\n",
- "# recursive function to find factorial\n",
- "\n",
- "def fact(k):\n",
- " if k ==1:\n",
- " return 1\n",
- " else:\n",
- " return (k * fact(k-1))\n",
- "\n",
- "ncr = fact(n)/(fact(r) * fact(n-r))\n",
- "print \"Value of nCr =\",ncr "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the values to n and r : 5 3\n",
- "Value of nCr = 10\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 12 , Page number: CP-188"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to compute the value of x power n using a recursive function\n",
- "# Variable declaration\n",
- "\n",
- "x = 4.20\n",
- "n = 3\n",
- "\n",
- "print \"Enter value to x :\",x\n",
- "print \"Enter its power :\",n\n",
- "\n",
- "# recursive function to find x rise to n\n",
- "\n",
- "def power(x,n):\n",
- " if n == 1:\n",
- " return x\n",
- " else:\n",
- " return (x * power(x,n-1))\n",
- "\n",
- "\n",
- "print \"%0.2f\" %x,\"raise to \",n,\"is %0.2f\" % power(x,n) "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to x : 4.2\n",
- "Enter its power : 3\n",
- "4.20 raise to 3 is 74.09\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 13 , Page number: CP-189"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to display first n terms of the fibonacci series using recursive function\n",
- "\n",
- "# Variable declaration\n",
- "\n",
- "n = 10\n",
- "t1 = 0\n",
- "t2 = 1\n",
- "i = 0\n",
- "count = 2\n",
- "\n",
- "# recursive function to print the terms in series\n",
- "def fibo(t1,t2):\n",
- " global count\n",
- " if (count >= n):\n",
- " return\n",
- " else:\n",
- " t3 = t1 + t2\n",
- " print t3,\n",
- " count = count + 1\n",
- " t1 = t2\n",
- " t2 = t3\n",
- " return fibo(t1,t2)\n",
- " \n",
- "\n",
- "\n",
- "print \"How many terms to be printed ?\",n\n",
- "print \"The first\",n,\"terms in Fibonacci series are\"\n",
- "print t1,\n",
- "print t2,\n",
- "\n",
- "fibo(t1,t2)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many terms to be printed ? 10\n",
- "The first 10 terms in Fibonacci series are\n",
- "0 1 1 2 3 5 8 13 21 34\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 14 , Page number: CP-196"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to add two matrices of order m x n and to print the resultant values\n",
- "# Variable declaration\n",
- "\n",
- "m = 2\n",
- "n = 2\n",
- "a = [[2,-2],\n",
- " [0,4]]\n",
- "b = [[6,2],\n",
- " [4,-5]]\n",
- "c = [[0,0],\n",
- " [0,0]]\n",
- "\n",
- "print \"How many rows and columns ?\",m,n\n",
- "print \"Enter A matrix value\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print a[i][j],\n",
- " print \n",
- "print \"Enter B matrix values\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print b[i][j],\n",
- " print \n",
- "\n",
- "# function to add matrices\n",
- "def matadd():\n",
- " for i in range(m):\n",
- " for j in range(n):\n",
- " c[i][j] = a[i][j] + b[i][j]\n",
- "\n",
- "\n",
- "\n",
- "# call function\n",
- "matadd()\n",
- "print \"Resultant matrix is\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print c[i][j],\n",
- " print \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many rows and columns ? 2 2\n",
- "Enter A matrix value\n",
- "2 -2\n",
- "0 4\n",
- "Enter B matrix values\n",
- "6 2\n",
- "4 -5\n",
- "Resultant matrix is\n",
- "8 0\n",
- "4 -1\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 15 , Page number: CP-197"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to multiply A matrix of order of m x n with B matrix of order n x l and print the resultant matrix\n",
- "# Variable declaration\n",
- "\n",
- "a = [[2,-2],\n",
- " [0,4]]\n",
- "b = [[6,2,],\n",
- " [4,-5]]\n",
- "c = [[0,0],\n",
- " [0,0]]\n",
- "\n",
- "m = 2\n",
- "n = 2\n",
- "l = 2\n",
- "\n",
- "print \"Enter order of A matrix (m x n) :\",m,n\n",
- "print \"Enter A matrix values\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print a[i][j],\n",
- " print\n",
- " \n",
- "print \"Enter order of B matrix (n x l) :\",n,l\n",
- "print \"Enter B matrix values\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print b[i][j],\n",
- " print \n",
- " \n",
- "\n",
- "# function to multiply matrices\n",
- "\n",
- "def matmul():\n",
- " for i in range(m):\n",
- " for j in range(l):\n",
- " c[i][j] = 0\n",
- " for k in range(n):\n",
- " c[i][j] = c[i][j] + a[i][k] * b[k][j]\n",
- " return c\n",
- "\n",
- "# call function\n",
- "matmul()\n",
- "print \"Resultant matix is\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print c[i][j],\n",
- " print\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter order of A matrix (m x n) : 2 2\n",
- "Enter A matrix values\n",
- "2 -2\n",
- "0 4\n",
- "Enter order of B matrix (n x l) : 2 2\n",
- "Enter B matrix values\n",
- "6 2\n",
- "4 -5\n",
- "Resultant matix is\n",
- "4 14\n",
- "16 -20\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 16 , Page number: CP-199"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to transpose a matrix of order m x n\n",
- "# Variable declaration\n",
- "\n",
- "a = [[-3,6,0],\n",
- " [3,2,8]]\n",
- "at = [[0,0],\n",
- " [0,0],\n",
- " [0,0]]\n",
- "m = 2\n",
- "n = 3\n",
- "ch = \"y\"\n",
- "\n",
- "print \"How many rows and columns ?\",m,n\n",
- "print \"Enter the matrix values\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print a[i][j],\n",
- " print \n",
- " \n",
- "\n",
- "# function to transpose a matrix\n",
- "\n",
- "def transpose(a,at,m,n):\n",
- " for i in range(m):\n",
- " for j in range(n):\n",
- " at[j][i] = a[i][j]\n",
- " return at\n",
- "\n",
- "while ch == 'y' or ch == 'Y' :\n",
- " # call function to transpose the matrix\n",
- " transpose(a,at,m,n)\n",
- " print \"Transpose of the matrix is\"\n",
- " for i in range(n):\n",
- " for j in range(m):\n",
- " print at[i][j],\n",
- " print\n",
- " ch = \"N\"\n",
- " print \"Press y to continue\"\n",
- " print \" any other key to stop.\",ch"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many rows and columns ? 2 3\n",
- "Enter the matrix values\n",
- "-3 6 0\n",
- "3 2 8\n",
- "Transpose of the matrix is\n",
- "-3 3\n",
- "6 2\n",
- "0 8\n",
- "Press y to continue\n",
- " any other key to stop. N\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 17 , Page number: CP-200"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to create a function to sort the elements of an array in ascending order\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "x = [32,-10,20,5]\n",
- "\n",
- "print \"How many numbers ?\",n\n",
- "print \"Enter the list of values\"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "\n",
- "# function to sort the numbers\n",
- "def sort(x,n):\n",
- " for i in range(n-1):\n",
- " for j in range(i+1,n):\n",
- " if x[i] > x[j]:\n",
- " temp = x[i]\n",
- " x[i] = x[j]\n",
- " x[j] = temp\n",
- " return x\n",
- "\n",
- "# call function to sort the numbers\n",
- "sort(x,n)\n",
- "print \"The sorted list is\"\n",
- "for a in x:\n",
- " print a,\n",
- "print\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers ? 4\n",
- "Enter the list of values\n",
- "32 -10 20 5\n",
- "The sorted list is\n",
- "-10 5 20 32\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice/Chapter9.ipynb b/Computer_Programming,_Theory_and_Practice/Chapter9.ipynb
deleted file mode 100755
index 2113c5af..00000000
--- a/Computer_Programming,_Theory_and_Practice/Chapter9.ipynb
+++ /dev/null
@@ -1,624 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:93c2825491a65ebd6dbc85e6208fc8a03cf21f92da06cf2457eda56a011645f1"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-211"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to display student details\n",
- "# class declaration instead of a structure\n",
- "\n",
- "class student:\n",
- " rno = 0\n",
- " sname = \"\"\n",
- " tot = 0\n",
- "\n",
- "# class object variable\n",
- "\n",
- "x = student()\n",
- "x.rno = 20147\n",
- "x.sname = \"PRADEEP\"\n",
- "x.tot = 64\n",
- "\n",
- "print \"Enter roll number, name and total marks\"\n",
- "print x.rno,x.sname,x.tot\n",
- "print \" Details entered are\"\n",
- "print \"Roll No. :\",x.rno\n",
- "print \"Student name :\",x.sname\n",
- "print \"Total marks :\",x.tot\n",
- "print \"Press any key to continue. . .\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter roll number, name and total marks\n",
- "20147 PRADEEP 64\n",
- " Details entered are\n",
- "Roll No. : 20147\n",
- "Student name : PRADEEP\n",
- "Total marks : 64\n",
- "Press any key to continue. . .\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-212"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to input student details and print the marks of a specified student as output\n",
- "\n",
- "# class declaration for structure\n",
- "\n",
- "class student:\n",
- " def __init__(self,rno,sname,tot):\n",
- " self.rno = rno\n",
- " self.sname = sname\n",
- " self.tot = tot\n",
- " \n",
- "# variable declaration\n",
- "\n",
- "ch = \"y\"\n",
- "n = 3\n",
- "\n",
- "# details of n students\n",
- "std = []\n",
- "std.append(student(20201,\"ARUN\",78))\n",
- "std.append(student(20208,\"DEEPAK\",69))\n",
- "std.append(student(20223,\"SUSMITHA\",88))\n",
- "\n",
- "print \"How many students ?\",n\n",
- "print \"Roll number ?\",std[0].rno\n",
- "print \"Name ?\",std[0].sname\n",
- "print \"Total marks ?\",std[0].tot\n",
- "print \"Roll number ?\",std[1].rno\n",
- "print \"Name ?\",std[1].sname\n",
- "print \"Total marks ?\",std[1].tot\n",
- "print \"Roll number ?\",std[2].rno\n",
- "print \"Name ?\",std[2].sname\n",
- "print \"Total marks ?\",std[2].tot\n",
- "print \n",
- "\n",
- "\n",
- "# To display marks of the student\n",
- "while ch == \"y\" or ch == \"Y\":\n",
- " temp = 20208\n",
- " print \"Enter student roll number to display marks :\",temp\n",
- " print \n",
- " flag = 0\n",
- " #loop to search and display details\n",
- " for i in range(3):\n",
- " if flag == 0:\n",
- " if std[i].rno == temp:\n",
- " print \"Marks obtained by \",std[i].rno,std[i].sname\n",
- " print \"Total :\",std[i].tot\n",
- " flag = 1\n",
- " if flag == 0:\n",
- " print temp,\" is not present in the list \"\n",
- " \n",
- " ch = \"n\" \n",
- " print \"press y - to continue\"\n",
- " print \" any other key to stop.\",ch\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many students ? 3\n",
- "Roll number ? 20201\n",
- "Name ? ARUN\n",
- "Total marks ? 78\n",
- "Roll number ? 20208\n",
- "Name ? DEEPAK\n",
- "Total marks ? 69\n",
- "Roll number ? 20223\n",
- "Name ? SUSMITHA\n",
- "Total marks ? 88\n",
- "\n",
- "Enter student roll number to display marks : 20208\n",
- "\n",
- "Marks obtained by 20208 DEEPAK\n",
- "Total : 69\n",
- "press y - to continue\n",
- " any other key to stop. n\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-214"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to declare a structure for student details and display list of students who obtained more than 75 marks\n",
- "\n",
- "# class for student structure\n",
- "\n",
- "class student:\n",
- " def __init__(self,rno,sname,tot):\n",
- " self.rno = rno\n",
- " self.sname = sname\n",
- " self.tot = tot\n",
- "\n",
- "std = []\n",
- "std.append(student(30401,\"ANAND\",59))\n",
- "std.append(student(30404,\"NIRMAL\",64))\n",
- "std.append(student(30428,\"ISWARYA\",82))\n",
- "std.append(student(30432,\"VIVEKA\",79))\n",
- "\n",
- "n = 4\n",
- "print \"How many students ?\",n\n",
- "print \"Roll Number ?\",std[0].rno\n",
- "print \"Name ?\",std[0].sname\n",
- "print \"Total marks ?\",std[0].tot\n",
- "print \"Roll Number ?\",std[1].rno\n",
- "print \"Name ?\",std[1].sname\n",
- "print \"Total marks ?\",std[1].tot\n",
- "print \"Roll Number ?\",std[2].rno\n",
- "print \"Name ?\",std[2].sname\n",
- "print \"Total marks ?\",std[2].tot\n",
- "print \"Roll Number ?\",std[3].rno\n",
- "print \"Name ?\",std[3].sname\n",
- "print \"Total marks ?\",std[3].tot\n",
- "print \n",
- "\n",
- "\n",
- "print \"----------------------------------------------------\"\n",
- "print \" Roll No. Name Total marks \"\n",
- "print \"----------------------------------------------------\"\n",
- "for i in range(n):\n",
- " if std[i].tot >= 75:\n",
- " print \" \",std[i].rno,\" \",std[i].sname,\" \",std[i].tot\n",
- "\n",
- "print \"----------------------------------------------------\"\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many students ? 4\n",
- "Roll Number ? 30401\n",
- "Name ? ANAND\n",
- "Total marks ? 59\n",
- "Roll Number ? 30404\n",
- "Name ? NIRMAL\n",
- "Total marks ? 64\n",
- "Roll Number ? 30428\n",
- "Name ? ISWARYA\n",
- "Total marks ? 82\n",
- "Roll Number ? 30432\n",
- "Name ? VIVEKA\n",
- "Total marks ? 79\n",
- "\n",
- "----------------------------------------------------\n",
- " Roll No. Name Total marks \n",
- "----------------------------------------------------\n",
- " 30428 ISWARYA 82\n",
- " 30432 VIVEKA 79\n",
- "----------------------------------------------------\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-216"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to store employee information and to compute employee's pay\n",
- "\n",
- "import math\n",
- "# class declaration for employee\n",
- "class employee:\n",
- " def __init__(self,eno,ename,epay,jdate):\n",
- " self.eno = eno\n",
- " self.ename = ename\n",
- " self.epay = epay\n",
- " self.jdate = jdate\n",
- "\n",
- "employs = []\n",
- "employs.append(employee(20101,\"ASHIKA\",1000,\"31/04/2001\"))\n",
- "employs.append(employee(20182,\"ASHWIN\",6000,\"11/12/1995\"))\n",
- "employs.append(employee(20204,\"PRAVEEN\",3000,\"18/06/1994\"))\n",
- "\n",
- "n = 3\n",
- "\n",
- "print \"Employee No. ?\",employs[0].eno\n",
- "print \"Name ?\",employs[0].ename\n",
- "print \"Existing date ?\",employs[0].epay\n",
- "print \"Joinin date ?\",employs[0].jdate\n",
- "print \n",
- "print \"Press y- to continue any other key to stop. y\"\n",
- "print \"Employee No. ?\",employs[1].eno\n",
- "print \"Name ?\",employs[1].ename\n",
- "print \"Existing date ?\",employs[1].epay\n",
- "print \"Joinin date ?\",employs[1].jdate\n",
- "print\n",
- "print \"Press y- to continue any other key to stop. y\"\n",
- "print \"Employee No. ?\",employs[2].eno\n",
- "print \"Name ?\",employs[2].ename\n",
- "print \"Existing date ?\",employs[2].epay\n",
- "print \"Joinin date ?\",employs[2].jdate\n",
- "print\n",
- "print \"Press y- to continue any other key to stop. N\"\n",
- "print\n",
- "print n,\" records are entered\"\n",
- "print \"Press any key to print the revised salary list\"\n",
- "print \n",
- "\n",
- "\n",
- "\n",
- "def revise(temp):\n",
- " if temp <= 2000:\n",
- " temp = int(temp + math.ceil(temp * 0.15))\n",
- " return temp\n",
- " elif temp <= 5000:\n",
- " temp = int(temp + temp * 0.10)\n",
- " return temp\n",
- " else:\n",
- " return temp\n",
- "\n",
- " \n",
- "# loop to increment salary\n",
- "for i in range(n):\n",
- " employs[i].epay = revise(employs[i].epay)\n",
- "\n",
- " \n",
- "\n",
- "\n",
- "# loop to print revised salary list\n",
- "print \" Employees Revised Pay List \"\n",
- "print \"---------------------------------------------------------\"\n",
- "print \" S.No. Number Name Joining date Pay \"\n",
- "print \"---------------------------------------------------------\"\n",
- "\n",
- "for i in range(n):\n",
- " print \" \",i+1,\" \",employs[i].eno,\" \",employs[i].ename,\" \",employs[i].jdate,\" \",employs[i].epay\n",
- "\n",
- "print \"---------------------------------------------------------\" \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Employee No. ? 20101\n",
- "Name ? ASHIKA\n",
- "Existing date ? 1000\n",
- "Joinin date ? 31/04/2001\n",
- "\n",
- "Press y- to continue any other key to stop. y\n",
- "Employee No. ? 20182\n",
- "Name ? ASHWIN\n",
- "Existing date ? 6000\n",
- "Joinin date ? 11/12/1995\n",
- "\n",
- "Press y- to continue any other key to stop. y\n",
- "Employee No. ? 20204\n",
- "Name ? PRAVEEN\n",
- "Existing date ? 3000\n",
- "Joinin date ? 18/06/1994\n",
- "\n",
- "Press y- to continue any other key to stop. N\n",
- "\n",
- "3 records are entered\n",
- "Press any key to print the revised salary list\n",
- "\n",
- " Employees Revised Pay List \n",
- "---------------------------------------------------------\n",
- " S.No. Number Name Joining date Pay \n",
- "---------------------------------------------------------\n",
- " 1 20101 ASHIKA 31/04/2001 1150\n",
- " 2 20182 ASHWIN 11/12/1995 6000\n",
- " 3 20204 PRAVEEN 18/06/1994 3300\n",
- "---------------------------------------------------------\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-219"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to store cricket details and to display a team-wise list with batting average\n",
- "\n",
- "# class for cricket structure\n",
- "\n",
- "class cricket:\n",
- " def __init__(self,pname,tname,bavg):\n",
- " self.pname = pname\n",
- " self.tname = tname\n",
- " self.bavg = bavg\n",
- "\n",
- "n = 6\n",
- "probable = []\n",
- "probable.append(cricket(\"KUMBLE\",\"KARNATAKA\",22))\n",
- "probable.append(cricket(\"KAMBLI\",\"MUMBAI\",39))\n",
- "probable.append(cricket(\"SRIKANTH\",\"TAMILNADU\",52))\n",
- "probable.append(cricket(\"SACHIM\",\"MUMBAI\",69))\n",
- "probable.append(cricket(\"RAHUL\",\"KARNATAKA\",57))\n",
- "probable.append(cricket(\"RAMESH\",\"TAMILNADU\",48))\n",
- "\n",
- "print \"How many players ?\",n\n",
- "print\n",
- "print \"Player name ?\",probable[0].pname\n",
- "print \"Which team ?\",probable[0].tname\n",
- "print \"Batting average ?\",probable[0].bavg\n",
- "print \"Player name ?\",probable[1].pname\n",
- "print \"Which team ?\",probable[1].tname\n",
- "print \"Batting average ?\",probable[1].bavg\n",
- "print \"Player name ?\",probable[2].pname\n",
- "print \"Which team ?\",probable[2].tname\n",
- "print \"Batting average ?\",probable[2].bavg\n",
- "print \"Player name ?\",probable[3].pname\n",
- "print \"Which team ?\",probable[3].tname\n",
- "print \"Batting average ?\",probable[3].bavg\n",
- "print \"Player name ?\",probable[4].pname\n",
- "print \"Which team ?\",probable[4].tname\n",
- "print \"Batting average ?\",probable[4].bavg\n",
- "print \"Player name ?\",probable[5].pname\n",
- "print \"Which team ?\",probable[5].tname\n",
- "print \"Batting average ?\",probable[5].bavg\n",
- "print\n",
- "print \n",
- "j = 0\n",
- "teams = []\n",
- "teams.append(probable[0].tname)\n",
- "j = j + 1\n",
- "for i in range(n):\n",
- " flag = 0\n",
- " for k in range(j):\n",
- " if flag == 0:\n",
- " if probable[i].tname == teams[k]:\n",
- " flag = 1\n",
- " if flag == 0 :\n",
- " teams.append(probable[i].tname)\n",
- " j = j + 1\n",
- "\n",
- "# loop to print team-wise list\n",
- "\n",
- "for k in range(3):\n",
- " print \" \",teams[k]\n",
- " print \"---------------------------------------------\"\n",
- " for i in range(n):\n",
- " if probable[i].tname == teams[k]:\n",
- " print \" \",probable[i].pname,\" \",probable[i].bavg\n",
- " print \"---------------------------------------------\" \n",
- "\n",
- "\n",
- "\n",
- "\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many players ? 6\n",
- "\n",
- "Player name ? KUMBLE\n",
- "Which team ? KARNATAKA\n",
- "Batting average ? 22\n",
- "Player name ? KAMBLI\n",
- "Which team ? MUMBAI\n",
- "Batting average ? 39\n",
- "Player name ? SRIKANTH\n",
- "Which team ? TAMILNADU\n",
- "Batting average ? 52\n",
- "Player name ? SACHIM\n",
- "Which team ? MUMBAI\n",
- "Batting average ? 69\n",
- "Player name ? RAHUL\n",
- "Which team ? KARNATAKA\n",
- "Batting average ? 57\n",
- "Player name ? RAMESH\n",
- "Which team ? TAMILNADU\n",
- "Batting average ? 48\n",
- "\n",
- "\n",
- " KARNATAKA\n",
- "---------------------------------------------\n",
- " KUMBLE 22\n",
- " RAHUL 57\n",
- "---------------------------------------------\n",
- " MUMBAI\n",
- "---------------------------------------------\n",
- " KAMBLI 39\n",
- " SACHIM 69\n",
- "---------------------------------------------\n",
- " TAMILNADU\n",
- "---------------------------------------------\n",
- " SRIKANTH 52\n",
- " RAMESH 48\n",
- "---------------------------------------------\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-235"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to illustrate the use of union using integer,string and float\n",
- "\n",
- "class student:\n",
- " def __init__(self,roll_no,sname,marks):\n",
- " self.roll_no = roll_no\n",
- " self.sname = sname\n",
- " self.marks = marks\n",
- "\n",
- "std = []\n",
- "std.append(student(0,\"AJITH\",0))\n",
- "std.append(student(0,\"RAJU\",0))\n",
- "std.append(student(0,\"VIGNESH\",0))\n",
- "std.append(student(0,\"DIVYA\",0))\n",
- "\n",
- "ch = 2\n",
- "print \"-----------------------------\"\n",
- "print \" Main menu \"\n",
- "print \"-----------------------------\"\n",
- "print \"Press 1 to enter roll numbers\"\n",
- "print \" 2 to enter names \"\n",
- "print \" 3 to enter marks \"\n",
- "print \" 4 to stop \"\n",
- "print \n",
- "print \"Enter your choice :\",ch\n",
- "\n",
- "n = 4\n",
- "print \"How many students?\",n\n",
- "for i in range(n):\n",
- " print \" Student name ? \",std[i].sname\n",
- "\n",
- "print\n",
- "print \n",
- "# display required list\n",
- "# switch case\n",
- "if ch == 1: #case 1\n",
- " print \"------------------------------\"\n",
- " print \" Students roll number list \"\n",
- " print \"------------------------------\"\n",
- " for i in range(n):\n",
- " print std[i].roll_no\n",
- " print \"-------------------------------\"\n",
- "elif ch == 2: # case 2\n",
- " print \"------------------------------\"\n",
- " print \" Students name list \"\n",
- " print \"------------------------------\"\n",
- " for i in range(n):\n",
- " print std[i].sname\n",
- " print \"-------------------------------\"\n",
- "elif ch == 3: # case 3\n",
- " print \"------------------------------\"\n",
- " print \" Students mark list \"\n",
- " print \"------------------------------\"\n",
- " for i in range(n):\n",
- " print \"Student marks\",std[i].roll_no\n",
- " print \"-------------------------------\"\n",
- " \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "-----------------------------\n",
- " Main menu \n",
- "-----------------------------\n",
- "Press 1 to enter roll numbers\n",
- " 2 to enter names \n",
- " 3 to enter marks \n",
- " 4 to stop \n",
- "\n",
- "Enter your choice : 2\n",
- "How many students? 4\n",
- " Student name ? AJITH\n",
- " Student name ? RAJU\n",
- " Student name ? VIGNESH\n",
- " Student name ? DIVYA\n",
- "\n",
- "\n",
- "------------------------------\n",
- " Students name list \n",
- "------------------------------\n",
- "AJITH\n",
- "RAJU\n",
- "VIGNESH\n",
- "DIVYA\n",
- "-------------------------------\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice/screenshots/Screenshot_(18)_1.png b/Computer_Programming,_Theory_and_Practice/screenshots/Screenshot_(18)_1.png
new file mode 100755
index 00000000..85bfb4d3
--- /dev/null
+++ b/Computer_Programming,_Theory_and_Practice/screenshots/Screenshot_(18)_1.png
Binary files differ
diff --git a/Computer_Programming,_Theory_and_Practice/screenshots/Screenshot_(19)_1.png b/Computer_Programming,_Theory_and_Practice/screenshots/Screenshot_(19)_1.png
new file mode 100755
index 00000000..dc328128
--- /dev/null
+++ b/Computer_Programming,_Theory_and_Practice/screenshots/Screenshot_(19)_1.png
Binary files differ
diff --git a/Computer_Programming,_Theory_and_Practice/screenshots/Screenshot_(20)_1.png b/Computer_Programming,_Theory_and_Practice/screenshots/Screenshot_(20)_1.png
new file mode 100755
index 00000000..b62b1efb
--- /dev/null
+++ b/Computer_Programming,_Theory_and_Practice/screenshots/Screenshot_(20)_1.png
Binary files differ
diff --git a/Computer_Programming,_Theory_and_Practice/screenshots/chapter11.png b/Computer_Programming,_Theory_and_Practice/screenshots/chapter11.png
deleted file mode 100755
index c5895710..00000000
--- a/Computer_Programming,_Theory_and_Practice/screenshots/chapter11.png
+++ /dev/null
Binary files differ
diff --git a/Computer_Programming,_Theory_and_Practice/screenshots/chapter11_1.png b/Computer_Programming,_Theory_and_Practice/screenshots/chapter11_1.png
deleted file mode 100755
index c5895710..00000000
--- a/Computer_Programming,_Theory_and_Practice/screenshots/chapter11_1.png
+++ /dev/null
Binary files differ
diff --git a/Computer_Programming,_Theory_and_Practice/screenshots/chapter2.png b/Computer_Programming,_Theory_and_Practice/screenshots/chapter2.png
deleted file mode 100755
index 05fde2b5..00000000
--- a/Computer_Programming,_Theory_and_Practice/screenshots/chapter2.png
+++ /dev/null
Binary files differ
diff --git a/Computer_Programming,_Theory_and_Practice/screenshots/chapter2_1.png b/Computer_Programming,_Theory_and_Practice/screenshots/chapter2_1.png
deleted file mode 100755
index 05fde2b5..00000000
--- a/Computer_Programming,_Theory_and_Practice/screenshots/chapter2_1.png
+++ /dev/null
Binary files differ
diff --git a/Computer_Programming,_Theory_and_Practice/screenshots/chapter3.png b/Computer_Programming,_Theory_and_Practice/screenshots/chapter3.png
deleted file mode 100755
index 685e290b..00000000
--- a/Computer_Programming,_Theory_and_Practice/screenshots/chapter3.png
+++ /dev/null
Binary files differ
diff --git a/Computer_Programming,_Theory_and_Practice/screenshots/chapter3_1.png b/Computer_Programming,_Theory_and_Practice/screenshots/chapter3_1.png
deleted file mode 100755
index 685e290b..00000000
--- a/Computer_Programming,_Theory_and_Practice/screenshots/chapter3_1.png
+++ /dev/null
Binary files differ
diff --git a/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_02_Fundamentals_of_C_language_1.ipynb b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_02_Fundamentals_of_C_language_1.ipynb
new file mode 100755
index 00000000..2c500315
--- /dev/null
+++ b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_02_Fundamentals_of_C_language_1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 02: Fundamentals of C language", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 3, Page Number: CP-22", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# variable declaration\n\na = 5\nb = 7\nc = 2\n\n# calculation \n\ny = a + b / c - a % c + 2 * a\n\n# result \n\nprint \"The result is \",y\n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The result is 17\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_03_Input_Output_Functions_and_Statements_1.ipynb b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_03_Input_Output_Functions_and_Statements_1.ipynb
new file mode 100755
index 00000000..e0941e6f
--- /dev/null
+++ b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_03_Input_Output_Functions_and_Statements_1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 03: Input/Output Functions and Statements", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-39", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "#program to add and find product of two numbers\n\n#variable declaration\na = 5\nb = 3\n\n# calculation of sum and product \n\nsumm = a + b\nproduct = a * b\n\nprint a,b\nprint summ,product", "outputs": [{"output_type": "stream", "name": "stdout", "text": "5 3\n8 15\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-45", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to convert degree fahrenheit to celcius \n# variable declaration\n\nf = 105.00\nprint \"Degree fahrenheit ? %d\" % f\n# calculation of degree in celcius \n\nc = 5.0/9.0 * (f-32)\n\n# result \nprint\nprint \"Degree centigrade =%6.2f\" % c", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Degree fahrenheit ? 105\n\nDegree centigrade = 40.56\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: CP-45", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# To find area of a triangle\n# variable declaration\n\na = 5\nb = 4\nc = 6\n\n\n# calculation of area\ns = float((a+b+c))/2\narea = (s*(s-a)*(s-b)*(s-c)) ** 0.5\n\n# result\nprint \"Enter three sides : %d\" % a,b,c\nprint \nprint \"Area of triangle = %0.2f Sq.units\" % area", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter three sides : 5 4 6\n\nArea of triangle = 9.92 Sq.units\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-51", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# To print ASCII value of a given character \n# Variable declaration\n\nch = \"A\"\nprint \"Enter a character : \" , ch\n\n# Calculation of ASCII value of a character\n\nprint \nprint \"ASCII value of \" + ch + \" is\" ,ord(ch)\nprint \"Press any key to stop. . .\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a character : A\n\nASCII value of A is 65\nPress any key to stop. . .\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-51", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# To print electricity for consumers\n# Variable declaration\n\nsno = \"TMR65358\"\npmr = 4305\ncmr = 4410\n\nprint \"Enter service number :\" ,sno\nprint \"Previous meter reading ?\",pmr\nprint \"Current meter reading ?\",cmr\n\n# Calculation of electricity charges\n\nunits = cmr - pmr\namt = units * 1.50\n\n# Result\n\nprint\nprint \" Electricity Bill\"\nprint \" ----------------\"\nprint \"Service No :\",sno\nprint \"Unit Consumed :\",units\nprint \"Electricity Charges : Rs.%0.2f\" % amt", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter service number : TMR65358\nPrevious meter reading ? 4305\nCurrent meter reading ? 4410\n\n Electricity Bill\n ----------------\nService No : TMR65358\nUnit Consumed : 105\nElectricity Charges : Rs.157.50\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-52", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to swap value of two variables\n# Variable declaration\n\na = 15\nb = 250 \n\nprint \"Enter value to A :\",a\nprint \"Enter value to B :\",b\n\n# Swapping\n\ntemp = a\na = b\nb = temp\n\nprint \nprint \"Value of A =\",a\nprint \"Value of B =\",b", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to A : 15\nEnter value to B : 250\n\nValue of A = 250\nValue of B = 15\n"}], "metadata": {"scrolled": true, "collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_04_Control_Statements_in_C_1.ipynb b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_04_Control_Statements_in_C_1.ipynb
new file mode 100755
index 00000000..6dcd833e
--- /dev/null
+++ b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_04_Control_Statements_in_C_1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 04: Control Statements in C ", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-60", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to find the biggest of two numbers\n# Variable declaration\n\na = 5\nb = 8\n\nprint \"Enter two numbers : %d\" % a,b\n\n# Calculation\n\nbig = a\nif (b>big):\n big = b\n\nprint \"Biggest number is \",big", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter two numbers : 5 8\nBiggest number is 8\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-61", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to find biggest of three numbers\n# Variable declaration\n\na = 5\nb = 13\nc = 8\n\nprint \"Enter three numbers : %d\" % a,b,c\n\n# Calculate\n\nbig = a\nif (b>big):\n big = b\nif (c>big):\n big = c\n\nprint \"Biggest number is\",big", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter three numbers : 5 13 8\nBiggest number is 13\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: CP-63", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to find biggest of three numbers\n# Variable declaration\n\na = 18\nb = -5\nc = 13\n \nprint \"Enter three numbers : %d\" % a,b,c\n\n# Calculation to find biggest number\n\nif (a>b):\n if(a>c):\n big = a\n else:\n big = c\nelse:\n if(b>c):\n big = b\n else:\n big = c\n\nprint \"Biggest number is\",big", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter three numbers : 18 -5 13\nBiggest number is 18\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-64", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to find the value of y \n# Variable declration\n\nx = 0.42\nn = 5\n\nprint \"Enter value to x and n :\" , x,n \n\n# Calculation\n\nif (n==1):\n y = 1 + x\nelif (n==2):\n y = 1 + x / n\nelif (n==3):\n y = 1 + (x ** n)\nelse:\n y = 1 + n * x\n\n\nprint \"Value of y(x,n) = %0.2f\" % y", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to x and n : 0.42 5\nValue of y(x,n) = 3.10\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-66", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to find the value of y\n# Variable declaration\n\nx = 0.42\nn = 5\n\n\nprint \"Enter value to x and n :\", x,n\n\n# Calculation\n\n# Switch case statements \nif n == 1: # case 1\n y = 1 + x\nelif n == 2: # case 2\n y = 1 + x / n\nelif n == 3: # case 3\n y = 1 + (x ** n)\nelse: # default\n y = 1 + n * x\n\nprint \"Value of y(x,n) = %0.2f\" % y ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to x and n : 0.42 5\nValue of y(x,n) = 3.10\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-68", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to caculate the commission for sales representatives\n# Variable declaration\n\nsales = 4500\n\nprint \"Sales amount ? :\" , sales\n\n# Calculation of commission\n\nif (sales <= 500):\n comm = 0.05 * sales\nelif (sales <= 2000):\n comm = 35 + 0.10 * (sales - 500)\nelif (sales <= 5000):\n comm = 185 + 0.12 * (sales - 2000)\nelse:\n comm = 0.125 * sales\n\n\nprint \"Commission Amount Rs.%0.2f\" % comm", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Sales amount ? : 4500\nCommission Amount Rs.485.00\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7 , Page number: CP-69", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "# Program to find roots of a quadratic equation\n# Variable declaration\n\na = 1\nb = 3\nc = 2\n\nprint \"Enter coefficients a, b, and c :\", a,b,c\n\nd = b * b - 4 * a * c\n\n# Calculation of roots\n\nif (d > 0):\n x1 = (-b + (d ** 0.5)) / (2 * a)\n x2 = (-b - (d ** 0.5)) / (2 * a)\n print \"Roots are real and unequal \"\n print x1,x2\n \n\nelif(d == 0):\n x = -b / (2 * a)\n print \"Roots are real and equal\"\n print \"%6.2f\" % x\n\nelse:\n print \"No Real roots, roots are complex\"\n\n\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter coefficients a, b, and c : 1 3 2\nRoots are real and unequal \n-1.0 -2.0\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8 , Page number: CP-70", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "# Program to print grade\n# Variable declaration\n\navg_marks = 84\n\nprint \"Average marks ?\",avg_marks\n\n# Calculation of grade\n\nif (avg_marks >= 80) and (avg_marks <= 100):\n print \"Honours\"\nelif (avg_marks >= 60) and (avg_marks <=79):\n print \"First Division\"\nelif (avg_marks >= 50) and (avg_marks <= 59):\n print \"Second Division\"\nelse:\n print \"Fail\"\n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Average marks ? 84\nHonours\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9 , Page number: CP-70", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "# Program to calculate electirc charges for domestic consumers\n# Variable declaration\n\nunits = 348\n\nprint \"Enter consumed units :\",units\n\n# Calculation of electric charges\n\nif (units <= 200):\n amt = 0.5 * units\nelif (units <= 400):\n amt = 100 + 0.65 * (units - 200)\nelif (units <= 600):\n amt = 230 + 0.8 * (units - 400)\nelse:\n amt = 425 + 1.25 * (units - 600)\nprint \nprint \"Amount to be paid Rs.%0.2f\" % amt", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter consumed units : 348\n\nAmount to be paid Rs.196.20\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10 , Page number: CP-73", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "# Program to find the grade of steel samples\n# Variable declaration\n\nts = 800\nrh = 180\ncc = 3\n\nprint \"Enter tensile strength :\",ts\nprint \"Enter rockwell hardness :\",rh\nprint \"Enter carbon content :\",cc\n\n# Calculation of grade\n\nif (ts >= 700):\n if (rh >= 200):\n if (cc <= 6):\n print \"Grade is A\"\n else:\n print \"Grade is B\" \n elif (cc <= 6):\n print \"Grade is C\"\n else:\n print \"Grade is E\" \nelif (rh >= 200):\n if (cc <= 6):\n print \"Grade is D\"\n else:\n print \"Grade is E\"\nelif (cc <= 6):\n print \"Grade is E\"\nelse:\n print \"Grade is F\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter tensile strength : 800\nEnter rockwell hardness : 180\nEnter carbon content : 3\nGrade is C\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_05_Loop_Control_Structures_In_C_1.ipynb b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_05_Loop_Control_Structures_In_C_1.ipynb
new file mode 100755
index 00000000..87019e9b
--- /dev/null
+++ b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_05_Loop_Control_Structures_In_C_1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 05: Loop Control Structures in C", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-79", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to print natural numbers from 1 to n\n# Variable decalration\n\nn = 15\n\nprint \"Enter value to n :\",n\n\n# Loop to print natural numbers\nfor r in range(15):\n r = r + 1\n print r,\n \n \n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to n : 15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-80", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to find the value of y and print a table for values of x\n# Variable declaration\nimport math\nx = 1.0\nprint \"------------------------\"\nprint \" x y \"\nprint \"------------------------\"\nwhile x <= 3.2:\n y = 1.36 * ((1 + x + x * x * x) ** 0.5) + ((x) ** (1.0/4)) + math.exp(x)\n print \" %0.2f \" %x + \" %0.2f\" % y\n x = x + 0.2", "outputs": [{"output_type": "stream", "name": "stdout", "text": "------------------------\n x y \n------------------------\n 1.00 6.07\n 1.20 7.06\n 1.40 8.23\n 1.60 9.60\n 1.80 11.20\n 2.00 13.09\n 2.20 15.30\n 2.40 17.91\n 2.60 20.99\n 2.80 24.64\n 3.00 28.97\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: CP-81", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to find factorial of given number\n# Variable declaration\n\nk = 4\nkfact = 1\n\nprint \"Enter an integer :\",k\n\n# Loop to generate numbers from 1 to n\n\nfor i in range(1,k + 1):\n kfact = kfact*i\n\nprint \"4 factorial is\",kfact ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter an integer : 4\n4 factorial is 24\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-83", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to print sum of the following series\n# Variable declaration\n\nn = 4\ns = 0\n\nprint \"Enter value to N :\",n\n# Calculation of sum\ni = 1\nj = 1\n\nfor i in range(1,n+1):\n term = 0\n for j in range(i+1):\n term = term + j\n s = s + term\n\n\nprint \"Sum of the series S =\",s ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to N : 4\nSum of the series S = 20\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-84", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to compute the values of z based on x and y\n# Variable declaration\n\nx = -1.5\ny = 0\n\n# Loops to generate values of x and y to find z\n\nwhile x <= 1.5:\n while y <= 3.0:\n z = 3 * x * x + 2 * y * y * y - 25.5\n print \"Value of y(\",x,\n print \",\",y,\n print \") =\",z\n y = y + 1.0\n x = x + 0.5\n y = 0\n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Value of y( -1.5 , 0 ) = -18.75\nValue of y( -1.5 , 1.0 ) = -16.75\nValue of y( -1.5 , 2.0 ) = -2.75\nValue of y( -1.5 , 3.0 ) = 35.25\nValue of y( -1.0 , 0 ) = -22.5\nValue of y( -1.0 , 1.0 ) = -20.5\nValue of y( -1.0 , 2.0 ) = -6.5\nValue of y( -1.0 , 3.0 ) = 31.5\nValue of y( -0.5 , 0 ) = -24.75\nValue of y( -0.5 , 1.0 ) = -22.75\nValue of y( -0.5 , 2.0 ) = -8.75\nValue of y( -0.5 , 3.0 ) = 29.25\nValue of y( 0.0 , 0 ) = -25.5\nValue of y( 0.0 , 1.0 ) = -23.5\nValue of y( 0.0 , 2.0 ) = -9.5\nValue of y( 0.0 , 3.0 ) = 28.5\nValue of y( 0.5 , 0 ) = -24.75\nValue of y( 0.5 , 1.0 ) = -22.75\nValue of y( 0.5 , 2.0 ) = -8.75\nValue of y( 0.5 , 3.0 ) = 29.25\nValue of y( 1.0 , 0 ) = -22.5\nValue of y( 1.0 , 1.0 ) = -20.5\nValue of y( 1.0 , 2.0 ) = -6.5\nValue of y( 1.0 , 3.0 ) = 31.5\nValue of y( 1.5 , 0 ) = -18.75\nValue of y( 1.5 , 1.0 ) = -16.75\nValue of y( 1.5 , 2.0 ) = -2.75\nValue of y( 1.5 , 3.0 ) = 35.25\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-89", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to find sum of odd integers between 1 to n\n# Variable declararion\n\nn = 10\n\nprint \"Enter value to N :\",n\n\ns = 0\ni = 1\n\nwhile (i <= n):\n s = s + i\n i = i + 2\n\nprint \"Sum of odd integers =\",s", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to N : 10\nSum of odd integers = 25\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7 , Page number: CP-90", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "# Program to generate first 50 positive integers that are divisible by 7\n# Variable declaration\n\nn = 7\nprint \"Integers divisible by 7\"\n\n#loop to print numbers divisible by 7\nfor n in range(7,353,7):\n print n,\n \n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Integers divisible by 7\n7 14 21 28 35 42 49 56 63 70 77 84 91 98 105 112 119 126 133 140 147 154 161 168 175 182 189 196 203 210 217 224 231 238 245 252 259 266 273 280 287 294 301 308 315 322 329 336 343 350\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8 , Page number: CP-91", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "# Program to print integers from 1 to n that are not divisible by 7\n# Variable declaration\n\nn = 20\nprint \"Enter the end value N :\",n\n\n# Loop to print numbers that are not divisible by 7\n\nprint \"Integers not divisible by 7\"\nfor k in range(1,n + 1,1):\n r = k % 7\n if (r != 0):\n print k,", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the end value N : 20\nIntegers not divisible by 7\n1 2 3 4 5 6 8 9 10 11 12 13 15 16 17 18 19 20\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9 , Page number: CP-92 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "# Program to print sum of digits of an integer\n# Variable declaration\n\nn = 2466\n\nprint \"Enter a positive integer :\",n\n\nq = n\ns = 0\n\nwhile (q > 0):\n r = q % 10\n s = s + r\n q = q / 10\n\n\nprint \"Sum of digits =\",s\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a positive integer : 2466\nSum of digits = 18\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10 , Page number: CP-93", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "# Program to check whether a given number is an armstrong number or not\n# Variable declaration\n\nn = 153\nq = n\ns = 0\n\nprint \"Enter an integer number :\",n\n\n# To check armstrong or not\n\nwhile (q > 0):\n r = q % 10\n s = s + r * r * r\n q = q / 10\n\nif (n == s):\n print \"%d is an Armstrong number\" % n\nelse:\n print \"%d is not an Armstrong number\" % n\n\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter an integer number : 153\n153 is an Armstrong number\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 11 , Page number: CP-94", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "# Program to reverse a given integer\n# Variable declaration\n\nn = 18532\nq = n\nrn = 0\n\nprint \"Enter an integer number :\",n\n# Reversing\n\nwhile (q > 0):\n r = q % 10\n rn = (rn * 10) + r\n q = q / 10\n\n\nprint \"18532 is reversed as\",rn ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter an integer number : 18532\n18532 is reversed as 23581\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 12 , Page number: CP-95", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "# Program to accept an integer and print digits using words\n# Variable declaration\n\nn = 4352\nq = n\nrn = 0\n\nprint \"Enter an integer number :\",n\n# converting to digits\n\nwhile (q > 0):\n r = q % 10\n rn = rn * 10 + r\n q = q / 10\n\n\nwhile (rn > 0):\n r = rn % 10\n if (r == 1):\n s = \"One\"\n print s,\n elif (r == 2):\n s = \"Two\"\n print s,\n elif (r == 3):\n s = \"Three\"\n print s,\n elif (r == 4):\n s = \"Four\"\n print s,\n elif (r == 5):\n s = \"Five\"\n print s,\n elif (r == 6):\n s = \"Six\"\n print s,\n elif (r == 7):\n s = \"Seven\"\n print s,\n elif (r == 8):\n s = \"Eight\"\n print s,\n elif (r == 9):\n s = \"Nine\"\n print s,\n elif (r == 0):\n s = \"Zero\"\n print s,\n rn = rn / 10\n\n\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter an integer number : 4352\nFour Three Five Two\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 13 , Page number: CP-97", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to find whether a number is prime or not\n# Variable declaration\n\nn = 17\n\nprint \"Enter a positive integer :\",n\n\n# prime numbers are greater than 1\nif n > 1:\n for i in range(2,n):\n if (n % i) == 0:\n print(n,\"is not a prime number\")\n print(i,\"times\",n//i,\"is\",num)\n break\n else:\n print \"%d is a prime number\" % n\n\nelse:\n print \"%d is not a prime number\" % n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a positive integer : 17\n17 is a prime number\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 14 , Page number: CP-98", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "# Program to generate Fibonacci series\n# Variable declaration\n\nn = 25\nn1 = 0\nn2 = 1\n\nprint \"Enter the final term of the series :\",n\n\nprint n1,n2,\n\n\nnewterm = n1 + n2\n\n# Loop to print fibonacci series\nwhile (newterm <= n):\n print newterm,\n n1 = n2\n n2 = newterm\n newterm = n1 + n2\n\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the final term of the series : 25\n0 1 1 2 3 5 8 13 21\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 15 , Page number: CP-99", "cell_type": "markdown", "metadata": {}}, {"execution_count": 15, "cell_type": "code", "source": "# Program to solve the sine series\n# Variable declaration\n\nx = 0.52\nn = 10\ns = 0\nterm = x\ni = 1\n\nprint \"Enter x in radians :\",x\nprint \"Enter end term power (n):\",n\n\nwhile (i <= n):\n s = s + term\n term = (term * x * x *(-1)) / ((i + 1) * (i + 2))\n i = i + 2\n\nprint \"Sum of the series = %0.6f\" % s\n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter x in radians : 0.52\nEnter end term power (n): 10\nSum of the series = 0.496880\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 16 , Page number: CP-101", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "# Program to solve the cosine series\n# Variable declaration\n\nx = 0.52\ns = 0\nterm = 1\ni = 0\nn = 10\nprint \"Enter x in radians :\",x\n\n# Calculation of cosine series\n\nwhile (i <= n):\n s = s + term\n term = (term * x * x * (-1)) / ((i + 1) * (i + 2))\n i = i + 2\n\n\nprint \"Sum of the series = %0.6f\" % s ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter x in radians : 0.52\nSum of the series = 0.867819\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 17 , Page number: CP-102", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "import math\n\n# Program to compute the value of pie\n# Variable declaration\n\ns = 0.0\ndr = 1\nsign = 1\nterm = (1.0/dr) * sign\nwhile (math.fabs(term) >= 1.0e-4):\n s = s + term\n dr = dr + 2\n sign = sign * -1\n term = (1.0 / dr) * sign\n\npie = s * 4\n\nprint \"Value of pie is %.6f\"%pie", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Value of pie is 3.141393\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 18 , Page number: CP-104", "cell_type": "markdown", "metadata": {}}, {"execution_count": 18, "cell_type": "code", "source": "# Program to evaluate the series\n# Variable declaration\n\nn = 15\ns = 0.00\n\nprint \"Enter value to N :\",n\n\n# Evaluation of series\n\nfor i in range(1,n + 1,1):\n s = float(s) + float(1.0 / i)\n \n\nprint \"Sum of series = %0.4f\" % s \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to N : 15\nSum of series = 3.3182\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 21 , Page number: CP-108", "cell_type": "markdown", "metadata": {}}, {"execution_count": 19, "cell_type": "code", "source": "# Program to print multiplication table\n# Variable declaration\n\ni = 1\nj = 1\n\n# nested loop to print multiplication tables\n\nfor i in range(1,6):\n print \"Multiplication table for\",i\n for j in range(1,11):\n print \" \",j,\"x\" , i ,\" =\" , j*i\n print \"Press any key to continue. . .\" ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Multiplication table for 1\n 1 x 1 = 1\n 2 x 1 = 2\n 3 x 1 = 3\n 4 x 1 = 4\n 5 x 1 = 5\n 6 x 1 = 6\n 7 x 1 = 7\n 8 x 1 = 8\n 9 x 1 = 9\n 10 x 1 = 10\nPress any key to continue. . .\nMultiplication table for 2\n 1 x 2 = 2\n 2 x 2 = 4\n 3 x 2 = 6\n 4 x 2 = 8\n 5 x 2 = 10\n 6 x 2 = 12\n 7 x 2 = 14\n 8 x 2 = 16\n 9 x 2 = 18\n 10 x 2 = 20\nPress any key to continue. . .\nMultiplication table for 3\n 1 x 3 = 3\n 2 x 3 = 6\n 3 x 3 = 9\n 4 x 3 = 12\n 5 x 3 = 15\n 6 x 3 = 18\n 7 x 3 = 21\n 8 x 3 = 24\n 9 x 3 = 27\n 10 x 3 = 30\nPress any key to continue. . .\nMultiplication table for 4\n 1 x 4 = 4\n 2 x 4 = 8\n 3 x 4 = 12\n 4 x 4 = 16\n 5 x 4 = 20\n 6 x 4 = 24\n 7 x 4 = 28\n 8 x 4 = 32\n 9 x 4 = 36\n 10 x 4 = 40\nPress any key to continue. . .\nMultiplication table for 5\n 1 x 5 = 5\n 2 x 5 = 10\n 3 x 5 = 15\n 4 x 5 = 20\n 5 x 5 = 25\n 6 x 5 = 30\n 7 x 5 = 35\n 8 x 5 = 40\n 9 x 5 = 45\n 10 x 5 = 50\nPress any key to continue. . .\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 22 , Page number: CP-109", "cell_type": "markdown", "metadata": {}}, {"execution_count": 20, "cell_type": "code", "source": "import math\n\n# Program to convert a binary number to a decimal number\n# Variable declaration\n\nq = 1101\ns = 0\nk = 0\n\nprint \"Enter the binary number :\",q\nwhile (q > 0):\n r = q % 10\n s = s + r * pow(2,k)\n q = q / 10\n k = k + 1\n\n\nprint \"The decimal number is :\",s\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the binary number : 1101\nThe decimal number is : 13\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 23 , Page number: CP-110", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to convert a decimal number to a binary number\n# Variable declaration\n\nn = 28\nq = n\nrbi = 0\nflag = 0\nk = 0\n\nprint \"Enter the decimal number :\",n\n\n\nwhile (q > 0):\n r = q % 2\n if (r == 0) and (flag == 0):\n k = k + 1\n else:\n flag = 1\n rbi = rbi * 10 + r\n q = q / 2\n\nq = rbi\nbi = 0\nwhile (q > 0):\n r = q % 10\n bi = bi * 10 + r\n q = q / 10\n i = 1\n if (q == 0):\n while (i <= k):\n bi = bi * 10\n i = i + 1\n\n\nprint \"The binary number is \",bi ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the decimal number : 28\nThe binary number is 11100\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_06_Arrays_and_Subscripted_Variables_1.ipynb b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_06_Arrays_and_Subscripted_Variables_1.ipynb
new file mode 100755
index 00000000..4d310a43
--- /dev/null
+++ b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_06_Arrays_and_Subscripted_Variables_1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 06: Arrays and Subscribed Variables", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-122", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to find the sum of n numbers using array\n# Variable declaration\n\nn = 5\nx = [36,45,52,44,62]\n\nprint \"How many integers ?\",n\nprint \"Enter the 1th value :\",x[0]\nprint \"Enter the 2th value :\",x[1]\nprint \"Enter the 3th value :\",x[2]\nprint \"Enter the 4th value :\",x[3]\nprint \"Enter the 5th value :\",x[4]\n\nsumm = 0 \n\n# Calculation of sum of numbers\nfor i in x:\n summ = summ + i\n \n\nprint \"Sum of all integers =\",summ\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many integers ? 5\nEnter the 1th value : 36\nEnter the 2th value : 45\nEnter the 3th value : 52\nEnter the 4th value : 44\nEnter the 5th value : 62\nSum of all integers = 239\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-123", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to find the biggest of n numbers\n# Variable declaration\n\nn = 5\nx = [25,-228,0,185,36]\n\nprint \"How many numbers ?\",n\nprint \"Enter all those numbers\"\nfor a in x:\n print a,\nprint \n\nbig = x[0]\n\n\nfor i in x:\n if (i > big):\n big = i\n\n\nprint \"%d is the biggest number\" % big ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many numbers ? 5\nEnter all those numbers\n25 -228 0 185 36\n185 is the biggest number\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: Cp-124", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to find the arithmetic mean, variance and standard deviation\n# Variable declaration\n\nn = 6\nx = [3.1,3.8,3.6,4.0,3.4,3.8]\nsumm = 0\nvsum = 0\n\nprint \"How many values ?\",n\nprint \"Enter all values in the list \"\nfor a in x:\n print a,\nprint \n\n# Loop to find sum of all values\n\nfor i in x:\n summ = summ + i\n\nxbar = summ / n\n\n# Loop to find the numerator vsum to find variance\n\nfor i in x:\n vsum = vsum + (i - xbar) * (i - xbar)\n\n\nsigmax = vsum / n\nsd = sigmax ** 0.5\n\nprint \"Arithmetic mean = %0.3f\" % xbar\nprint \"Variance = %0.3f \" % sigmax\nprint \"Standard deviation = %0.3f\" % sd", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many values ? 6\nEnter all values in the list \n3.1 3.8 3.6 4.0 3.4 3.8\nArithmetic mean = 3.617\nVariance = 0.088 \nStandard deviation = 0.297\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-126", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to calculate mean of marks and print list of marks greater than mean\n# Variable declaration\n\nn = 5\nx = [58,63,68,54,48]\nsumm = 0 # Used summ instead of sum since it was a inbuilt function\ni = 0\n\nprint \"How many students ?\",n\nprint \"Enter all the marks \"\nfor a in x:\n print a,\nprint \n\nfor i in x:\n summ = summ + i\n\nmean = float(summ) / n\n\nprint \"Mean = %0.2f\" % mean\nprint \"Marks greater than mean :\",\n\ni = 0\nfor i in x:\n if (i > mean):\n print i,\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many students ? 5\nEnter all the marks \n58 63 68 54 48\nMean = 58.20\nMarks greater than mean : 63 68\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-127", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to find sum of all positive and negative numbers and to find out which is larger in magnitude\n# Variable declaration\nimport math\n\nn = 6\nx = [8,-12,-16,12,-9,5]\npsum = 0\nnsum = 0\n\nprint \"How many values ?\",n\nprint \"Enter all values in the list\"\nfor i in x:\n print i,\nprint \n\n# Loop to calculate sum of positive and negative values\n\nfor i in x:\n if i > 0:\n psum = psum + i\n else:\n nsum = nsum + i\n\nprint \"Sum of positive values = %0.2f\" % psum\nprint \"Sum of negative values = %0.2f\" % nsum\n\nif (psum > abs(nsum)):\n print \"Positive sum is greater in magnitude\"\nelse:\n print \"Negative sum is greater in magnitude\"\n\ndiff = abs(psum) - abs(nsum)\nprint \"Difference in magnitude = %0.2f\" % abs(diff)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many values ? 6\nEnter all values in the list\n8 -12 -16 12 -9 5\nSum of positive values = 25.00\nSum of negative values = -37.00\nNegative sum is greater in magnitude\nDifference in magnitude = 12.00\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-129", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to sort n numbers in ascending order\n# Variable declaration\n\nn = 4\nx = [32,-10,20,5]\ni = 0\n\n\nprint \"How many numbers ?\",n\nprint \"Enter the list of 4 numbers\"\nfor a in x:\n print a,\nprint\n\n# Loop to arrange the numbers in ascending order\n\nwhile i < n-1:\n j = i + 1\n while j < n:\n if x[i] > x[j]:\n temp = x[i]\n x[i] = x[j]\n x[j] = temp\n j = j + 1\n i = i + 1\n\nprint \"Numbers in ascending order \"\n\nfor a in x:\n print a,\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many numbers ? 4\nEnter the list of 4 numbers\n32 -10 20 5\nNumbers in ascending order \n-10 5 20 32\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7 , Page number: CP-131", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "# Program to search the key value and to print it if the search is successful\n# Variable declaration\n\nn = 6\nx = [6,-2,8,3,13,10]\ns = 3\n\nprint \"How many values in the list ?\",n\nprint \"Enter all values in the list\"\nfor i in x:\n print i,\nprint \nprint \"Enter the key value to be searched :\",s\n\n# loop to search key value in the list\n\nfor i in range(n):\n if s == x[i]:\n print s,\" is available in\",i+1,\"th location\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many values in the list ? 6\nEnter all values in the list\n6 -2 8 3 13 10\nEnter the key value to be searched : 3\n3 is available in 4 th location\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8 , Page number: CP-133", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "# Program to sort n numbers using bubble sort and find number of exchanges and passes\n# Variable declaration\n\nn = 4\nx = [6,-2,8,3]\nexchng = 0\n\nprint \"How many numbers?\",n\nprint \"Enter all the numbers in the list\"\nfor i in x:\n print i,\n\nprint\n\nfor i in range(0,n-1):\n for j in range(0,n-i-1):\n if x[j] > x[j+1]:\n temp = x[j]\n x[j] = x[j+1]\n x[j+1] = temp\n exchng = exchng + 1\n \n\nprint \"The sorted list is\"\nfor i in x:\n print i,\n\nprint \n\nprint \"Sorted in\",n-1,\"passes and\",exchng,\"exchanges\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many numbers? 4\nEnter all the numbers in the list\n6 -2 8 3\nThe sorted list is\n-2 3 6 8\nSorted in 3 passes and 3 exchanges\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9 , Page number: CP-135", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to add two matrices\n# Variable declaration\n\na = [[2,-2],\n [0,4]]\nb = [[6,2],\n [4,-5]]\n\nc = [[0,0],\n [0,0]]\n\nm = 2\nn = 2\n\nprint \"How many rows and columns ?\",m,n\nprint \"Enter A matrix\"\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print \n\nprint \"Enter B matrix\"\nfor i in range(m):\n for j in range(n):\n print b[i][j],\n print \n\n# Loop to add two matrices\n\nfor i in range(m):\n for j in range(n):\n c[i][j] = a[i][j] + b[i][j]\n\n\nprint \"Resultant matrix is\"\nfor i in range(m):\n for j in range(n):\n print c[i][j],\n print ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many rows and columns ? 2 2\nEnter A matrix\n2 -2\n0 4\nEnter B matrix\n6 2\n4 -5\nResultant matrix is\n8 0\n4 -1\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10 , Page number: CP-136", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to multiply two matrices\n# Variable declaration\n\nm = 2\nn = 2\nl = 2\na = [[2,-2],\n [0,4]]\nb = [[6,2],\n [4,-5]]\nc = [[0,0],\n [0,0]]\n\nprint \"Enter order of A matrix :\",m,n\nprint \"Enter A matrix\"\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print \n \nprint \"Enter order of B matrix :\",m,n\nprint \"Enter B matrix\"\nfor i in range(m):\n for j in range(n):\n print b[i][j],\n print \n\n# Loop to multiply two matrices\n# iterate through rowa of A\nfor i in range(m):\n # iterate through columns of B\n for j in range(l):\n c[i][j] = 0\n # iterate through rows of B\n for k in range(n):\n c[i][j] = c[i][j] + a[i][k] * b[k][j]\n\n\nprint \"Resultant matrix is\"\n\nfor i in range(m):\n for j in range(n):\n print c[i][j],\n print \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter order of A matrix : 2 2\nEnter A matrix\n2 -2\n0 4\nEnter order of B matrix : 2 2\nEnter B matrix\n6 2\n4 -5\nResultant matrix is\n4 14\n16 -20\n"}], "metadata": {"scrolled": true, "collapsed": false, "trusted": true}}, {"source": "## Example 11 , Page number: CP-138", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "# Program to find and print the transpose of the matrix\n# Variable declaration\n\nm = 2\nn = 3\na = [[-3,6,0],\n [3,2,8]]\nat = [[0,0],\n [0,0],\n [0,0]]\n\nprint \"Enter order of the matrix :\",m,n\nprint \"Enter the matrix values\"\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print \n\n# Loop to calculate transpose\n\nfor i in range(m):\n for j in range(n):\n at[j][i] = a[i][j]\n\nprint \"The transposed matrix is \"\nfor i in range(n):\n for j in range(m):\n print at[i][j],\n print \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter order of the matrix : 2 3\nEnter the matrix values\n-3 6 0\n3 2 8\nThe transposed matrix is \n-3 3\n6 2\n0 8\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 12 ,Page number: CP-139", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "# Program to check whether a given matrix is symmetric or not\n# Variable declaration\n\nm = 3\na = [[5,3,8],\n [3,1,-7],\n [8,-7,4]]\n\nprint \"Enter order of the square matrix :\",m\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print \n\n# Loop to check whether symmetric or not\n\nfor i in range(m):\n flag = 0\n for j in range(m):\n flag = 0\n if a[i][j] == a[j][i]:\n continue\n else:\n flag = 1\n\nif flag == 0:\n print \"The given matrix is a symmetric matrix\"\nelse:\n print \"The given matrix is not a symmetric matrix\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter order of the square matrix : 3\n5 3 8\n3 1 -7\n8 -7 4\nThe given matrix is a symmetric matrix\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 13 , Page number: CP-141", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to find the trace of a given square matrix\n# Variable dclaration\n\nm = 3\na = [[3,2,-1],\n [4,1,8],\n [6,4,2]]\nsumm = 0\n\nprint \"Enter order of the square matrix :\",m\nprint \"Enter the matrix\"\nfor i in range(m):\n for j in range(m):\n print a[i][j], \n print \n\n# Loop to find trace\nfor i in range(m):\n summ = summ + a[i][i]\n\nprint \"Trace of the matrix =\",summ ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter order of the square matrix : 3\nEnter the matrix\n3 2 -1\n4 1 8\n6 4 2\nTrace of the matrix = 6\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_07_String_Manipulations_in_C_1.ipynb b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_07_String_Manipulations_in_C_1.ipynb
new file mode 100755
index 00000000..9a0df3cb
--- /dev/null
+++ b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_07_String_Manipulations_in_C_1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 07: String Manipulations in C", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-148", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to count the occurence of a particular in a string\n# Variable declaration\n\nst = \"MISSISSIPPI\"\nch = \"S\"\ncount = 0\n\nprint \"Enter the string :\",st\nprint \"Which character to be counted ?\",ch\n\n# Loop to check occurrence of aa character\n\nl = len(st)\n\nfor i in st:\n if i == ch:\n count = count + 1\n\nprint \"The character \" + ch + \" occurs %d times\" % count ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the string : MISSISSIPPI\nWhich character to be counted ? S\nThe character S occurs 4 times\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-149", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to count the number of vowels in a sentence\n# Variable declaration\n\nst = \"This is a book\"\ncount = 0\n\nprint \"Enter the sentence :\"\nprint st\n\n# Loop to count the vowels in the string\n\nfor i in st:\n if i == \"A\":\n count = count + 1\n elif i == \"E\":\n count = count + 1\n elif i == \"I\":\n count = count + 1\n elif i == \"O\":\n count = count + 1\n elif i == \"U\":\n count = count + 1\n elif i == \"a\":\n count = count + 1\n elif i == \"e\":\n count = count + 1\n elif i == \"i\":\n count = count + 1\n elif i == \"o\":\n count = count + 1\n elif i == \"u\":\n count = count + 1\n\nprint \"%d vowels are present in the sentence\" % count\n \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the sentence :\nThis is a book\n5 vowels are present in the sentence\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: CP-150", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to test whether a given string is a palindrome or not\n# Variable declaration\n\nst = \"HYDERABAD\"\nrst = \"\"\ni = 0\nj = len(st) - 1\n\nprint \"Enter the string :\",st\n\n# Palindrome or not \n\nrst = reversed(st)\n\nif list(st) == list(rst):\n print \"%s is a palindrome string \" % st\nelse:\n print \"%s is not a palindrome string \" % st", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the string : HYDERABAD\nHYDERABAD is not a palindrome string \n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-152", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to conctenate two strings\n# Variable declaration\n\nst1 = \"NEW \"\nst2 = \"DELHI\"\n\n# input of two strings to be concatenated\n\nprint \"Enter first string :\",st1\nprint \"Enter second string :\",st2\n\n# concatenation of two strings\nst = st1 + st2\n\nprint \"Resultant string is \",st ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter first string : NEW \nEnter second string : DELHI\nResultant string is NEW DELHI\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-154", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to compare two strings\n# Variable declaration\n\nst1 = \"ALPHA\"\nst2 = \"BETA\"\n\nprint \"Enter string 1:\",st1\nprint \"Enter string 2:\",st2\n\n# compare strings\n\nif (cmp(st1,st2)>0):\n print \"%s \" + st1 + \"is alphabetically greater string\"\nelse:\n print st2 + \" is alphabetically greater string\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter string 1: ALPHA\nEnter string 2: BETA\nBETA is alphabetically greater string\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-155", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to sort an array of names in alphabetical order\n# Variable declaration\n\nn = 4\nnames = [\"DEEPAK\",\"SHERIN\",\"SONIKA\",\"ARUN\"]\n\nprint \"How many names ?\",n\nprint \"Enter the 4 names one by one\"\nfor i in names:\n print i\n\n# Loop to arrange names in alphabetical order\n\nfor i in range(0,n-1):\n for j in range(i+1,n):\n if cmp(names[i],names[j])>0:\n \n temp = names[i]\n names[i] = names[j]\n names[j] = temp\n\nprint \"Names in alphabetical order\"\nfor i in names:\n print i", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many names ? 4\nEnter the 4 names one by one\nDEEPAK\nSHERIN\nSONIKA\nARUN\nNames in alphabetical order\nARUN\nDEEPAK\nSHERIN\nSONIKA\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7 , Page number: CP-157", "cell_type": "markdown", "metadata": {}}, {"execution_count": 13, "cell_type": "code", "source": "# Program to convert a line from lower case to upper case\n# Variable declaretion\n\nimport sys\n\nst = ['l','o','g','i','c','a','l',' ','t','h','i','n','k','i','n','g',' ','i','s',' ','a',' ','m','u','s','t',' ','t','o',' ','l','e','a','r','n',' ','p','r','o','g','r','a','m','m','i','n','g']\n\nprint \"Enter a sentence :\"\nfor i in st:\n print i,\nprint \nprint \"The converted upper case string is\"\n# loop to convert lower case alphabet to upper case text\nfor i in range(len(st)):\n if st[i] >= 'a' and st[i] <= 'z':\n st[i] = chr(ord(st[i])-32)\n\n\n sys.stdout.write(st[i])", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a sentence :\nl o g i c a l t h i n k i n g i s a m u s t t o l e a r n p r o g r a m m i n g\nThe converted upper case string is\nLOGICAL THINKING IS A MUST TO LEARN PROGRAMMING"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9 , Page number: CP-160", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "# Program to read a text and to omit al occurrences of a particular word\n# Variable declartion\n\nst = \"TO ACCESS THE NAME OF THE CITY IN THE LIST\"\ni = 0\nomit = \"THE\"\nl = len(st)\nj = 0\nword = []\nnewst = \"\"\nonesps = \"\"\nprint \"Enter a sentence :\"\nprint st\nprint \"Enter word to omit :\",omit\n\n# loop to omit the given word\n\nfor i in range(l):\n ch = i\n if ch == ' ':\n for j in word:\n j = \" \" \n if j == omit:\n newst = j\n newst = onesps\n j = \" \"\n j = 0\n else:\n j = ch\n j = j + 1\n i = i + 1\n\nprint \"After omiting the word \" + omit\nprint newst\nprint \"Press any key to continue\"\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a sentence :\nTO ACCESS THE NAME OF THE CITY IN THE LIST\nEnter word to omit : THE\nAfter omiting the word THE\n\nPress any key to continue\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10 , Page number: CP-161", "cell_type": "markdown", "metadata": {}}, {"execution_count": 15, "cell_type": "code", "source": "# Program to calculate the amount to be paid for the telegram\n# Variable declaration\n\ncount = 0\nst = \"Congratulations on your success in Examinations.\"\nl = len(st)\n\nprint \"Type the sentence for Telegram\"\nprint st\n\n# loop to count number of words\n\nfor i in range(l):\n if st[i] == '?':\n count = count + 1\n\nif count <= 10:\n amt = 5\nelse:\n amt = 5 + (count - 10) * 1.25\n\nprint \"Amount to be paid for telegram = Rs.%0.2f\" % amt ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Type the sentence for Telegram\nCongratulations on your success in Examinations.\nAmount to be paid for telegram = Rs.5.00\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 11 , Page number: CP-163", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "# Program to count number of lines,words and characters\n# Variable declaration\n\ntxt = \"What is a string? How do you initialize it? Explain with example.$\"\nst = \"\"\ni = 0\nlns = 0\nwds = 0\nchs = 0\n\nprint \"Enter the text, type $ at end.\"\nprint txt\n\n# loop to count lines,words and characters in text\n\nwhile txt[i] != '$':\n # switch case statements\n if txt[i] == ' ':\n wds = wds + 1\n chs = chs + 1\n elif txt[i] == '.':\n wds = wds + 1\n lns = lns + 1\n chs = chs + 1\n elif txt[i] == '?':\n lns = lns + 1\n else: # default\n chs = chs + 1\n\n i = i + 1\n\nprint \"Number of char (incl. blanks) =\",chs\nprint \"Number of words =\",wds\nprint \"Number of lines =\",lns\n\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the text, type $ at end.\nWhat is a string? How do you initialize it? Explain with example.$\nNumber of char (incl. blanks) = 63\nNumber of words = 12\nNumber of lines = 3\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_08_Functins_in_C_1.ipynb b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_08_Functins_in_C_1.ipynb
new file mode 100755
index 00000000..90388fc6
--- /dev/null
+++ b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_08_Functins_in_C_1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 08: Functions in C", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-173", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to write a function to find factorial and use it to find nCr\n# Variable declaration\n\nn = 5\nr = 3\n\nprint \"Enter value to n and r :\",n,r\n\n# function subprogram to find factorial\n\ndef fact(k):\n p = 1\n for i in range(1,k+1):\n p = p * i\n return p\n\n\nncr = fact(n) / (fact(r) * fact(n-r))\n\n\nprint \"Value of nCr =\",ncr", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to n and r : 5 3\nValue of nCr = 10\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-174", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to find the biggest of given three values using function and use it to find total marks of the student\n# Variable declaration\n\nt1 = 62\nt2 = 70\nt3 = 58\na1 = 17\na2 = 21\na3 = 23\n\nprint \"Enter three test scores :\",t1,t2,t3\nprint \"Enter three assignment scores :\",a1,a2,a3\n\n# function to find biggest of three values\n\ndef big(a,b,c):\n if a > b:\n if a > c:\n return a\n else:\n return c\n elif b > c:\n return b\n else:\n return c\n\ntotal = big(t1,t2,t3) + big(a1,a2,a3)\n\nprint \"Total marks =\",total", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter three test scores : 62 70 58\nEnter three assignment scores : 17 21 23\nTotal marks = 93\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: CP-176", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to create a function to compute the cos(x) series upto 15 terms\n# Variable declaration\n\nx = 0\n\nprint \"----------------------------------\"\nprint \" x in degrees cos(x) \"\nprint \"----------------------------------\"\n\n# function for computing cosine function\n\ndef cosine(x):\n s = 0\n i = 0\n term = 1\n x = x * (3.14) / 180\n k = 1\n # loop to find summation of 15 terms\n while k <= 15:\n s = s + term\n term = term * x * x * (-1) / ((i + 1) * (i + 2))\n i = i + 2\n k = k + 1\n return s\n\n\n# calling function\n\nwhile x <= 180:\n print \" %d \" % x,\" %0.2f \"%cosine(x)\n x = x + 30\n\nprint \"-----------------------------------\" ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "----------------------------------\n x in degrees cos(x) \n----------------------------------\n 0 1.00 \n 30 0.87 \n 60 0.50 \n 90 0.00 \n 120 -0.50 \n 150 -0.87 \n 180 -1.00 \n-----------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-177", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to find GCD of two integers\n# Variable declaration\n\na = 45\nb = 27\nc = 81\n\nprint \"Enter three integers :\",a,b,c\n\ndef gcd(x,y):\n if x >= y:\n nr = x\n dr = y\n else:\n nr = y\n dr = x\n r = nr % dr\n while r != 0:\n nr = dr\n dr = r\n r = nr % dr\n\n return dr\n\nd1 = gcd(a,b)\nd2 = gcd(a,c)\nd3 = gcd(b,c)\n\nif d1 == d2:\n if d1 == d3:\n print \"Greatest common divisor is\",d1\n else:\n print \"Greatest common divisor is \",gcd(d1,d3)\nelse:\n print \"Greatest common divisr is\",gcd(d1,d2)\n\n\nprint \"Press any key to continue. . .\" ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter three integers : 45 27 81\nGreatest common divisor is 9\nPress any key to continue. . .\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-178", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to reverse the given integer\n# Variable declaration\n\nn = 2846\n\nprint \"Enter the integer :\",n\n\n# function to reverse an integer\n\ndef reverse(n):\n rn = 0\n while n > 0:\n r = n % 10\n rn = rn * 10 + r\n n = n /10\n return rn\n\n\n# call the function to print the reverse integer\n\nprint n,\"is reversed as \",reverse(n)\nprint \"Press any key to continue. . .\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the integer : 2846\n2846 is reversed as 6482\nPress any key to continue. . .\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-179", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to compare two strings S1 and S2 and return the result 0,1,-1\n# Variable declaration\n\ns1 = \"MUMBAI\"\ns2 = \"MYSORE\"\n\nprint \"Enter the first string :\",s1\nprint \"Enter the second string :\",s2\n\n\n# function to compare the strings\n\ndef compare(s1,s2):\n if cmp(s1,s2) == 0:\n return 0\n if cmp(s1,s2) > 0:\n return 1\n if cmp(s1,s2) < 0:\n return -1\n\n# call the function to print the result\n\nprint \"The result is \", compare(s1,s2)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the first string : MUMBAI\nEnter the second string : MYSORE\nThe result is -1\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7 , Page number: CP-181", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "# Program to find the arithmetic mean of n values using a function\n# Variable declaration\n\nn = 6\nx = [3.1,3.8,3.6,4.0,3.4,3.8]\n\nprint \"How many values ?\",n\nprint \"Enter all values\"\nfor i in x:\n print i,\nprint \n# function to find arithmetic mean\n\ndef amean(x,n):\n s = 0\n for i in range(n):\n s = s + x[i]\n return (s/n)\n\n# call function to print arithmetic mean\n\nprint \"Arithmetic mean = %0.2f\" % amean(x,n)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many values ? 6\nEnter all values\n3.1 3.8 3.6 4.0 3.4 3.8\nArithmetic mean = 3.62\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8 , Page number: CP-182", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "# Program to read a matrix of order m x n and print the sum of all elements using functions\n# Variable declaration\n\nm = 3\nn = 2\na = [[2,3,4],\n [2,0,1]]\n\n\nprint \"How many rows and columns :\",m,n\nprint \"Enter the matrix values\"\nfor i in range(n):\n for j in range(m):\n print a[i][j],\n print \n\n# function to add all elements in the matrix\ndef elem_sum(a,m,n):\n i = 0\n j = 0\n s = 0\n for i in range(n):\n for j in range(m):\n s = s + a[i][j]\n j = j + 1\n i = i + 1 \n return s\n\n# call function to print the result\n\nprint \"Sum of all elements in the matrix =\",\nprint elem_sum(a,m,n)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many rows and columns : 3 2\nEnter the matrix values\n2 3 4\n2 0 1\nSum of all elements in the matrix = 12\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9 , Page number: CP-183", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "# Program to reverse a string\n# Variable declaration\n\nst = \"NEW DELHI\"\nprint \"Enter a string :\",st\ndef reverse(st):\n rst = \"\"\n for i in range(0 ,len(st)):\n rst += st[(len(st) -1) - i]\n return rst\n\nprint st,\"is reversed as \",\nprint reverse(st)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a string : NEW DELHI\nNEW DELHI is reversed as IHLED WEN\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10 , Page number: CP-184", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "# Program to apply binary search to set of N numbers using a function\n# Variable declaration\n\nn = 10\nx = [-3,8,13,19,21,25,26,29,35,42]\ns = 19\n\n\nprint \"How many numbers ?\",n\nprint \"Enter all numbers in the list\"\nfor a in x:\n print a,\nprint \nprint \"Enter the number to be searched :\",s\n\n# function to search the number\n\ndef bi_search(x,n,s):\n flag = 0\n start = 0\n end = n\n while start < end and flag ==0:\n mid = (start + end) / 2\n if x[mid] > s:\n end = mid\n elif x[mid] < s:\n start = mid + 1\n else:\n flag = 1\n return flag\n\n# calling the function\n\nif bi_search(x,n,s):\n print \"The number\",s,\"is present in the list\"\nelse:\n print \"The number\",s,\"is not present in list\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many numbers ? 10\nEnter all numbers in the list\n-3 8 13 19 21 25 26 29 35 42\nEnter the number to be searched : 19\nThe number 19 is present in the list\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 11 , Page number: CP-187", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "# Program to find factorial of a given number using recursive function\n# Variable declaration\n\nn = 5\nr = 3\n\nprint \"Enter the values to n and r :\",n,r\n\n# recursive function to find factorial\n\ndef fact(k):\n if k ==1:\n return 1\n else:\n return (k * fact(k-1))\n\nncr = fact(n)/(fact(r) * fact(n-r))\nprint \"Value of nCr =\",ncr ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the values to n and r : 5 3\nValue of nCr = 10\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 12 , Page number: CP-188", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "# Program to compute the value of x power n using a recursive function\n# Variable declaration\n\nx = 4.20\nn = 3\n\nprint \"Enter value to x :\",x\nprint \"Enter its power :\",n\n\n# recursive function to find x rise to n\n\ndef power(x,n):\n if n == 1:\n return x\n else:\n return (x * power(x,n-1))\n\n\nprint \"%0.2f\" %x,\"raise to \",n,\"is %0.2f\" % power(x,n) ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to x : 4.2\nEnter its power : 3\n4.20 raise to 3 is 74.09\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 13 , Page number: CP-189", "cell_type": "markdown", "metadata": {}}, {"execution_count": 13, "cell_type": "code", "source": "# Program to display first n terms of the fibonacci series using recursive function\n\n# Variable declaration\n\nn = 10\nt1 = 0\nt2 = 1\ni = 0\ncount = 2\n\n# recursive function to print the terms in series\ndef fibo(t1,t2):\n global count\n if (count >= n):\n return\n else:\n t3 = t1 + t2\n print t3,\n count = count + 1\n t1 = t2\n t2 = t3\n return fibo(t1,t2)\n \n\n\nprint \"How many terms to be printed ?\",n\nprint \"The first\",n,\"terms in Fibonacci series are\"\nprint t1,\nprint t2,\n\nfibo(t1,t2)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many terms to be printed ? 10\nThe first 10 terms in Fibonacci series are\n0 1 1 2 3 5 8 13 21 34\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 14 , Page number: CP-196", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "# Program to add two matrices of order m x n and to print the resultant values\n# Variable declaration\n\nm = 2\nn = 2\na = [[2,-2],\n [0,4]]\nb = [[6,2],\n [4,-5]]\nc = [[0,0],\n [0,0]]\n\nprint \"How many rows and columns ?\",m,n\nprint \"Enter A matrix value\"\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print \nprint \"Enter B matrix values\"\nfor i in range(m):\n for j in range(n):\n print b[i][j],\n print \n\n# function to add matrices\ndef matadd():\n for i in range(m):\n for j in range(n):\n c[i][j] = a[i][j] + b[i][j]\n\n\n\n# call function\nmatadd()\nprint \"Resultant matrix is\"\nfor i in range(m):\n for j in range(n):\n print c[i][j],\n print \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many rows and columns ? 2 2\nEnter A matrix value\n2 -2\n0 4\nEnter B matrix values\n6 2\n4 -5\nResultant matrix is\n8 0\n4 -1\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 15 , Page number: CP-197", "cell_type": "markdown", "metadata": {}}, {"execution_count": 15, "cell_type": "code", "source": "# Program to multiply A matrix of order of m x n with B matrix of order n x l and print the resultant matrix\n# Variable declaration\n\na = [[2,-2],\n [0,4]]\nb = [[6,2,],\n [4,-5]]\nc = [[0,0],\n [0,0]]\n\nm = 2\nn = 2\nl = 2\n\nprint \"Enter order of A matrix (m x n) :\",m,n\nprint \"Enter A matrix values\"\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print\n \nprint \"Enter order of B matrix (n x l) :\",n,l\nprint \"Enter B matrix values\"\nfor i in range(m):\n for j in range(n):\n print b[i][j],\n print \n \n\n# function to multiply matrices\n\ndef matmul():\n for i in range(m):\n for j in range(l):\n c[i][j] = 0\n for k in range(n):\n c[i][j] = c[i][j] + a[i][k] * b[k][j]\n return c\n\n# call function\nmatmul()\nprint \"Resultant matix is\"\nfor i in range(m):\n for j in range(n):\n print c[i][j],\n print\n\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter order of A matrix (m x n) : 2 2\nEnter A matrix values\n2 -2\n0 4\nEnter order of B matrix (n x l) : 2 2\nEnter B matrix values\n6 2\n4 -5\nResultant matix is\n4 14\n16 -20\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 16 , Page number: CP-199", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "# Program to transpose a matrix of order m x n\n# Variable declaration\n\na = [[-3,6,0],\n [3,2,8]]\nat = [[0,0],\n [0,0],\n [0,0]]\nm = 2\nn = 3\nch = \"y\"\n\nprint \"How many rows and columns ?\",m,n\nprint \"Enter the matrix values\"\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print \n \n\n# function to transpose a matrix\n\ndef transpose(a,at,m,n):\n for i in range(m):\n for j in range(n):\n at[j][i] = a[i][j]\n return at\n\nwhile ch == 'y' or ch == 'Y' :\n # call function to transpose the matrix\n transpose(a,at,m,n)\n print \"Transpose of the matrix is\"\n for i in range(n):\n for j in range(m):\n print at[i][j],\n print\n ch = \"N\"\n print \"Press y to continue\"\n print \" any other key to stop.\",ch", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many rows and columns ? 2 3\nEnter the matrix values\n-3 6 0\n3 2 8\nTranspose of the matrix is\n-3 3\n6 2\n0 8\nPress y to continue\n any other key to stop. N\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 17 , Page number: CP-200", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "# Program to create a function to sort the elements of an array in ascending order\n# Variable declaration\n\nn = 4\nx = [32,-10,20,5]\n\nprint \"How many numbers ?\",n\nprint \"Enter the list of values\"\nfor a in x:\n print a,\nprint \n\n# function to sort the numbers\ndef sort(x,n):\n for i in range(n-1):\n for j in range(i+1,n):\n if x[i] > x[j]:\n temp = x[i]\n x[i] = x[j]\n x[j] = temp\n return x\n\n# call function to sort the numbers\nsort(x,n)\nprint \"The sorted list is\"\nfor a in x:\n print a,\nprint\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many numbers ? 4\nEnter the list of values\n32 -10 20 5\nThe sorted list is\n-10 5 20 32\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_09_Structures_and_Unions_1.ipynb b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_09_Structures_and_Unions_1.ipynb
new file mode 100755
index 00000000..30accc65
--- /dev/null
+++ b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_09_Structures_and_Unions_1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 09: Structures and Unions", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-211", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to display student details\n# class declaration instead of a structure\n\nclass student:\n rno = 0\n sname = \"\"\n tot = 0\n\n# class object variable\n\nx = student()\nx.rno = 20147\nx.sname = \"PRADEEP\"\nx.tot = 64\n\nprint \"Enter roll number, name and total marks\"\nprint x.rno,x.sname,x.tot\nprint \" Details entered are\"\nprint \"Roll No. :\",x.rno\nprint \"Student name :\",x.sname\nprint \"Total marks :\",x.tot\nprint \"Press any key to continue. . .\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter roll number, name and total marks\n20147 PRADEEP 64\n Details entered are\nRoll No. : 20147\nStudent name : PRADEEP\nTotal marks : 64\nPress any key to continue. . .\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-212", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to input student details and print the marks of a specified student as output\n\n# class declaration for structure\n\nclass student:\n def __init__(self,rno,sname,tot):\n self.rno = rno\n self.sname = sname\n self.tot = tot\n \n# variable declaration\n\nch = \"y\"\nn = 3\n\n# details of n students\nstd = []\nstd.append(student(20201,\"ARUN\",78))\nstd.append(student(20208,\"DEEPAK\",69))\nstd.append(student(20223,\"SUSMITHA\",88))\n\nprint \"How many students ?\",n\nprint \"Roll number ?\",std[0].rno\nprint \"Name ?\",std[0].sname\nprint \"Total marks ?\",std[0].tot\nprint \"Roll number ?\",std[1].rno\nprint \"Name ?\",std[1].sname\nprint \"Total marks ?\",std[1].tot\nprint \"Roll number ?\",std[2].rno\nprint \"Name ?\",std[2].sname\nprint \"Total marks ?\",std[2].tot\nprint \n\n\n# To display marks of the student\nwhile ch == \"y\" or ch == \"Y\":\n temp = 20208\n print \"Enter student roll number to display marks :\",temp\n print \n flag = 0\n #loop to search and display details\n for i in range(3):\n if flag == 0:\n if std[i].rno == temp:\n print \"Marks obtained by \",std[i].rno,std[i].sname\n print \"Total :\",std[i].tot\n flag = 1\n if flag == 0:\n print temp,\" is not present in the list \"\n \n ch = \"n\" \n print \"press y - to continue\"\n print \" any other key to stop.\",ch\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many students ? 3\nRoll number ? 20201\nName ? ARUN\nTotal marks ? 78\nRoll number ? 20208\nName ? DEEPAK\nTotal marks ? 69\nRoll number ? 20223\nName ? SUSMITHA\nTotal marks ? 88\n\nEnter student roll number to display marks : 20208\n\nMarks obtained by 20208 DEEPAK\nTotal : 69\npress y - to continue\n any other key to stop. n\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: CP-214", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to declare a structure for student details and display list of students who obtained more than 75 marks\n\n# class for student structure\n\nclass student:\n def __init__(self,rno,sname,tot):\n self.rno = rno\n self.sname = sname\n self.tot = tot\n\nstd = []\nstd.append(student(30401,\"ANAND\",59))\nstd.append(student(30404,\"NIRMAL\",64))\nstd.append(student(30428,\"ISWARYA\",82))\nstd.append(student(30432,\"VIVEKA\",79))\n\nn = 4\nprint \"How many students ?\",n\nprint \"Roll Number ?\",std[0].rno\nprint \"Name ?\",std[0].sname\nprint \"Total marks ?\",std[0].tot\nprint \"Roll Number ?\",std[1].rno\nprint \"Name ?\",std[1].sname\nprint \"Total marks ?\",std[1].tot\nprint \"Roll Number ?\",std[2].rno\nprint \"Name ?\",std[2].sname\nprint \"Total marks ?\",std[2].tot\nprint \"Roll Number ?\",std[3].rno\nprint \"Name ?\",std[3].sname\nprint \"Total marks ?\",std[3].tot\nprint \n\n\nprint \"----------------------------------------------------\"\nprint \" Roll No. Name Total marks \"\nprint \"----------------------------------------------------\"\nfor i in range(n):\n if std[i].tot >= 75:\n print \" \",std[i].rno,\" \",std[i].sname,\" \",std[i].tot\n\nprint \"----------------------------------------------------\"\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many students ? 4\nRoll Number ? 30401\nName ? ANAND\nTotal marks ? 59\nRoll Number ? 30404\nName ? NIRMAL\nTotal marks ? 64\nRoll Number ? 30428\nName ? ISWARYA\nTotal marks ? 82\nRoll Number ? 30432\nName ? VIVEKA\nTotal marks ? 79\n\n----------------------------------------------------\n Roll No. Name Total marks \n----------------------------------------------------\n 30428 ISWARYA 82\n 30432 VIVEKA 79\n----------------------------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-216", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to store employee information and to compute employee's pay\n\nimport math\n# class declaration for employee\nclass employee:\n def __init__(self,eno,ename,epay,jdate):\n self.eno = eno\n self.ename = ename\n self.epay = epay\n self.jdate = jdate\n\nemploys = []\nemploys.append(employee(20101,\"ASHIKA\",1000,\"31/04/2001\"))\nemploys.append(employee(20182,\"ASHWIN\",6000,\"11/12/1995\"))\nemploys.append(employee(20204,\"PRAVEEN\",3000,\"18/06/1994\"))\n\nn = 3\n\nprint \"Employee No. ?\",employs[0].eno\nprint \"Name ?\",employs[0].ename\nprint \"Existing date ?\",employs[0].epay\nprint \"Joinin date ?\",employs[0].jdate\nprint \nprint \"Press y- to continue any other key to stop. y\"\nprint \"Employee No. ?\",employs[1].eno\nprint \"Name ?\",employs[1].ename\nprint \"Existing date ?\",employs[1].epay\nprint \"Joinin date ?\",employs[1].jdate\nprint\nprint \"Press y- to continue any other key to stop. y\"\nprint \"Employee No. ?\",employs[2].eno\nprint \"Name ?\",employs[2].ename\nprint \"Existing date ?\",employs[2].epay\nprint \"Joinin date ?\",employs[2].jdate\nprint\nprint \"Press y- to continue any other key to stop. N\"\nprint\nprint n,\" records are entered\"\nprint \"Press any key to print the revised salary list\"\nprint \n\n\n\ndef revise(temp):\n if temp <= 2000:\n temp = int(temp + math.ceil(temp * 0.15))\n return temp\n elif temp <= 5000:\n temp = int(temp + temp * 0.10)\n return temp\n else:\n return temp\n\n \n# loop to increment salary\nfor i in range(n):\n employs[i].epay = revise(employs[i].epay)\n\n \n\n\n# loop to print revised salary list\nprint \" Employees Revised Pay List \"\nprint \"---------------------------------------------------------\"\nprint \" S.No. Number Name Joining date Pay \"\nprint \"---------------------------------------------------------\"\n\nfor i in range(n):\n print \" \",i+1,\" \",employs[i].eno,\" \",employs[i].ename,\" \",employs[i].jdate,\" \",employs[i].epay\n\nprint \"---------------------------------------------------------\" \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Employee No. ? 20101\nName ? ASHIKA\nExisting date ? 1000\nJoinin date ? 31/04/2001\n\nPress y- to continue any other key to stop. y\nEmployee No. ? 20182\nName ? ASHWIN\nExisting date ? 6000\nJoinin date ? 11/12/1995\n\nPress y- to continue any other key to stop. y\nEmployee No. ? 20204\nName ? PRAVEEN\nExisting date ? 3000\nJoinin date ? 18/06/1994\n\nPress y- to continue any other key to stop. N\n\n3 records are entered\nPress any key to print the revised salary list\n\n Employees Revised Pay List \n---------------------------------------------------------\n S.No. Number Name Joining date Pay \n---------------------------------------------------------\n 1 20101 ASHIKA 31/04/2001 1150\n 2 20182 ASHWIN 11/12/1995 6000\n 3 20204 PRAVEEN 18/06/1994 3300\n---------------------------------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-219", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to store cricket details and to display a team-wise list with batting average\n\n# class for cricket structure\n\nclass cricket:\n def __init__(self,pname,tname,bavg):\n self.pname = pname\n self.tname = tname\n self.bavg = bavg\n\nn = 6\nprobable = []\nprobable.append(cricket(\"KUMBLE\",\"KARNATAKA\",22))\nprobable.append(cricket(\"KAMBLI\",\"MUMBAI\",39))\nprobable.append(cricket(\"SRIKANTH\",\"TAMILNADU\",52))\nprobable.append(cricket(\"SACHIM\",\"MUMBAI\",69))\nprobable.append(cricket(\"RAHUL\",\"KARNATAKA\",57))\nprobable.append(cricket(\"RAMESH\",\"TAMILNADU\",48))\n\nprint \"How many players ?\",n\nprint\nprint \"Player name ?\",probable[0].pname\nprint \"Which team ?\",probable[0].tname\nprint \"Batting average ?\",probable[0].bavg\nprint \"Player name ?\",probable[1].pname\nprint \"Which team ?\",probable[1].tname\nprint \"Batting average ?\",probable[1].bavg\nprint \"Player name ?\",probable[2].pname\nprint \"Which team ?\",probable[2].tname\nprint \"Batting average ?\",probable[2].bavg\nprint \"Player name ?\",probable[3].pname\nprint \"Which team ?\",probable[3].tname\nprint \"Batting average ?\",probable[3].bavg\nprint \"Player name ?\",probable[4].pname\nprint \"Which team ?\",probable[4].tname\nprint \"Batting average ?\",probable[4].bavg\nprint \"Player name ?\",probable[5].pname\nprint \"Which team ?\",probable[5].tname\nprint \"Batting average ?\",probable[5].bavg\nprint\nprint \nj = 0\nteams = []\nteams.append(probable[0].tname)\nj = j + 1\nfor i in range(n):\n flag = 0\n for k in range(j):\n if flag == 0:\n if probable[i].tname == teams[k]:\n flag = 1\n if flag == 0 :\n teams.append(probable[i].tname)\n j = j + 1\n\n# loop to print team-wise list\n\nfor k in range(3):\n print \" \",teams[k]\n print \"---------------------------------------------\"\n for i in range(n):\n if probable[i].tname == teams[k]:\n print \" \",probable[i].pname,\" \",probable[i].bavg\n print \"---------------------------------------------\" \n\n\n\n\n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many players ? 6\n\nPlayer name ? KUMBLE\nWhich team ? KARNATAKA\nBatting average ? 22\nPlayer name ? KAMBLI\nWhich team ? MUMBAI\nBatting average ? 39\nPlayer name ? SRIKANTH\nWhich team ? TAMILNADU\nBatting average ? 52\nPlayer name ? SACHIM\nWhich team ? MUMBAI\nBatting average ? 69\nPlayer name ? RAHUL\nWhich team ? KARNATAKA\nBatting average ? 57\nPlayer name ? RAMESH\nWhich team ? TAMILNADU\nBatting average ? 48\n\n\n KARNATAKA\n---------------------------------------------\n KUMBLE 22\n RAHUL 57\n---------------------------------------------\n MUMBAI\n---------------------------------------------\n KAMBLI 39\n SACHIM 69\n---------------------------------------------\n TAMILNADU\n---------------------------------------------\n SRIKANTH 52\n RAMESH 48\n---------------------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-235", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to illustrate the use of union using integer,string and float\n\nclass student:\n def __init__(self,roll_no,sname,marks):\n self.roll_no = roll_no\n self.sname = sname\n self.marks = marks\n\nstd = []\nstd.append(student(0,\"AJITH\",0))\nstd.append(student(0,\"RAJU\",0))\nstd.append(student(0,\"VIGNESH\",0))\nstd.append(student(0,\"DIVYA\",0))\n\nch = 2\nprint \"-----------------------------\"\nprint \" Main menu \"\nprint \"-----------------------------\"\nprint \"Press 1 to enter roll numbers\"\nprint \" 2 to enter names \"\nprint \" 3 to enter marks \"\nprint \" 4 to stop \"\nprint \nprint \"Enter your choice :\",ch\n\nn = 4\nprint \"How many students?\",n\nfor i in range(n):\n print \" Student name ? \",std[i].sname\n\nprint\nprint \n# display required list\n# switch case\nif ch == 1: #case 1\n print \"------------------------------\"\n print \" Students roll number list \"\n print \"------------------------------\"\n for i in range(n):\n print std[i].roll_no\n print \"-------------------------------\"\nelif ch == 2: # case 2\n print \"------------------------------\"\n print \" Students name list \"\n print \"------------------------------\"\n for i in range(n):\n print std[i].sname\n print \"-------------------------------\"\nelif ch == 3: # case 3\n print \"------------------------------\"\n print \" Students mark list \"\n print \"------------------------------\"\n for i in range(n):\n print \"Student marks\",std[i].roll_no\n print \"-------------------------------\"\n \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "-----------------------------\n Main menu \n-----------------------------\nPress 1 to enter roll numbers\n 2 to enter names \n 3 to enter marks \n 4 to stop \n\nEnter your choice : 2\nHow many students? 4\n Student name ? AJITH\n Student name ? RAJU\n Student name ? VIGNESH\n Student name ? DIVYA\n\n\n------------------------------\n Students name list \n------------------------------\nAJITH\nRAJU\nVIGNESH\nDIVYA\n-------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_11_Files_1.ipynb b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_11_Files_1.ipynb
new file mode 100755
index 00000000..a198f1a0
--- /dev/null
+++ b/Computer_Programming,_Theory_and_Practice_by_T_Jeyapoovan/Chapter_11_Files_1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 11: Files", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-277", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to create a text file\n\nfp = open(\"sample.txt\",\"w\") # open file in write mode\n\nprint \"Type the text and Press enter key at end.\"\nprint\nprint \"Computer Programming in C language is widely used for Science and Engineering applications\"\n# input data to file\nch = ['Computer ','Programming ','in ','C ','language ','is ','widely ','used ','for ','Science ','and ' ,'Engineering ','applications.']\nfor i in ch:\n fp.write(i)\nfp.close()\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Type the text and Press enter key at end.\n\nComputer Programming in C language is widely used for Science and Engineering applications\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2, Page Number: CP-278 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to read text file and count number of vowels\n\nfp = open(\"sample.txt\",\"r\") # open file in read mode\ncount = 0\nprint \"The Content of the file is:\"\n\nwhile (1): \n ch = fp.read(1)\n if not ch:\n break\n print ch\n # switch statements\n if ch == \"A\" or ch == \"a\": # case 'A' or 'a'\n count = count + 1\n elif ch == \"E\" or ch == \"e\": # case 'E' or 'e'\n count = count + 1\n elif ch == \"I\" or ch == \"i\": # case 'I' or 'i'\n count = count + 1\n elif ch == \"O\" or ch == \"o\": # case 'O' or 'o'\n count = count + 1\n elif ch == \"U\" or ch == \"u\": # case 'U' or 'u'\n count = count + 1\n\n\n\nfp.close() \nprint \"Number of vowels present =\",count \n \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The Content of the file is:\nC\no\nm\np\nu\nt\ne\nr\n \nP\nr\no\ng\nr\na\nm\nm\ni\nn\ng\n \ni\nn\n \nC\n \nl\na\nn\ng\nu\na\ng\ne\n \ni\ns\n \nw\ni\nd\ne\nl\ny\n \nu\ns\ne\nd\n \nf\no\nr\n \nS\nc\ni\ne\nn\nc\ne\n \na\nn\nd\n \nE\nn\ng\ni\nn\ne\ne\nr\ni\nn\ng\n \na\np\np\nl\ni\nc\na\nt\ni\no\nn\ns\n.\nNumber of vowels present = 31\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice/Chapter11.ipynb b/Computer_Programming_Theory_and_Practice/Chapter11.ipynb
deleted file mode 100755
index c046ab93..00000000
--- a/Computer_Programming_Theory_and_Practice/Chapter11.ipynb
+++ /dev/null
@@ -1,62 +0,0 @@
-{
- "metadata": {
- "name": "Chapter11"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 11, Files"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 1, Page Number:CP-277"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "# Program to create a text file\n\nfp = open(\"sample.txt\",\"w\") # open file in write mode\n\nprint \"Type the text and Press enter key at end.\"\nprint\nprint \"Computer Programming in C language is widely used for Science and Engineering applications\"\n# input data to file\nch = ['Computer ','Programming ','in ','C ','language ','is ','widely ','used ','for ','Science ','and ' ,'Engineering ','applications.']\nfor i in ch:\n fp.write(i)\nfp.close()\n ",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Type the text and Press enter key at end.\n\nComputer Programming in C language is widely used for Science and Engineering applications\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2, Page Number:CP-278"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "# Program to read text file and count number of vowels\n\nfp = open(\"sample.txt\",\"r\") # open file in read mode\ncount = 0\nprint \"The Content of the file is:\"\n\nwhile (1): \n ch = fp.read(1)\n if not ch:\n break\n print ch\n # switch statements\n if ch == \"A\" or ch == \"a\": # case 'A' or 'a'\n count = count + 1\n elif ch == \"E\" or ch == \"e\": # case 'E' or 'e'\n count = count + 1\n elif ch == \"I\" or ch == \"i\": # case 'I' or 'i'\n count = count + 1\n elif ch == \"O\" or ch == \"o\": # case 'O' or 'o'\n count = count + 1\n elif ch == \"U\" or ch == \"u\": # case 'U' or 'u'\n count = count + 1\n\n\n\nfp.close() \nprint \"Number of vowels present =\",count \n ",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "The Content of the file is:\nC\no\nm\np\nu\nt\ne\nr\n \nP\nr\no\ng\nr\na\nm\nm\ni\nn\ng\n \ni\nn\n \nC\n \nl\na\nn\ng\nu\na\ng\ne\n \ni\ns\n \nw\ni\nd\ne\nl\ny\n \nu\ns\ne\nd\n \nf\no\nr\n \nS\nc\ni\ne\nn\nc\ne\n \na\nn\nd\n \nE\nn\ng\ni\nn\ne\ne\nr\ni\nn\ng\n \na\np\np\nl\ni\nc\na\nt\ni\no\nn\ns\n.\nNumber of vowels present = 31\n"
- }
- ],
- "prompt_number": 2
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice/Chapter2.ipynb b/Computer_Programming_Theory_and_Practice/Chapter2.ipynb
deleted file mode 100755
index c4bc71ff..00000000
--- a/Computer_Programming_Theory_and_Practice/Chapter2.ipynb
+++ /dev/null
@@ -1,41 +0,0 @@
-{
- "metadata": {
- "name": "Chapter2"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 2, Fundamentals of C language"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3, Page Number: CP-22"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "# variable declaration\n\na = 5\nb = 7\nc = 2\n\n# calculation \n\ny = a + b / c - a % c + 2 * a\n\n# result \n\nprint \"The result is \",y\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "The result is 17\n"
- }
- ],
- "prompt_number": 1
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice/Chapter3.ipynb b/Computer_Programming_Theory_and_Practice/Chapter3.ipynb
deleted file mode 100755
index 04d24871..00000000
--- a/Computer_Programming_Theory_and_Practice/Chapter3.ipynb
+++ /dev/null
@@ -1,293 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:0ff7bb47f00bae9dc5a49237df7011debd17443ba836341d55e8fe830338ade7"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 3: Input/Output Functions and Statements"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-39"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#program to add and find product of two numbers\n",
- "\n",
- "#variable declaration\n",
- "a = 5\n",
- "b = 3\n",
- "\n",
- "# calculation of sum and product \n",
- "\n",
- "summ = a + b\n",
- "product = a * b\n",
- "\n",
- "print a,b\n",
- "print summ,product"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "5 3\n",
- "8 15\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-45"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to convert degree fahrenheit to celcius \n",
- "# variable declaration\n",
- "\n",
- "f = 105.00\n",
- "print \"Degree fahrenheit ? %d\" % f\n",
- "# calculation of degree in celcius \n",
- "\n",
- "c = 5.0/9.0 * (f-32)\n",
- "\n",
- "# result \n",
- "print\n",
- "print \"Degree centigrade =%6.2f\" % c"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Degree fahrenheit ? 105\n",
- "\n",
- "Degree centigrade = 40.56\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-45"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# To find area of a triangle\n",
- "# variable declaration\n",
- "\n",
- "a = 5\n",
- "b = 4\n",
- "c = 6\n",
- "\n",
- "\n",
- "# calculation of area\n",
- "s = float((a+b+c))/2\n",
- "area = (s*(s-a)*(s-b)*(s-c)) ** 0.5\n",
- "\n",
- "# result\n",
- "print \"Enter three sides : %d\" % a,b,c\n",
- "print \n",
- "print \"Area of triangle = %0.2f Sq.units\" % area"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three sides : 5 4 6\n",
- "\n",
- "Area of triangle = 9.92 Sq.units\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-51"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# To print ASCII value of a given character \n",
- "# Variable declaration\n",
- "\n",
- "ch = \"A\"\n",
- "print \"Enter a character : \" , ch\n",
- "\n",
- "# Calculation of ASCII value of a character\n",
- "\n",
- "print \n",
- "print \"ASCII value of \" + ch + \" is\" ,ord(ch)\n",
- "print \"Press any key to stop. . .\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a character : A\n",
- "\n",
- "ASCII value of A is 65\n",
- "Press any key to stop. . .\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-51"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# To print electricity for consumers\n",
- "# Variable declaration\n",
- "\n",
- "sno = \"TMR65358\"\n",
- "pmr = 4305\n",
- "cmr = 4410\n",
- "\n",
- "print \"Enter service number :\" ,sno\n",
- "print \"Previous meter reading ?\",pmr\n",
- "print \"Current meter reading ?\",cmr\n",
- "\n",
- "# Calculation of electricity charges\n",
- "\n",
- "units = cmr - pmr\n",
- "amt = units * 1.50\n",
- "\n",
- "# Result\n",
- "\n",
- "print\n",
- "print \" Electricity Bill\"\n",
- "print \" ----------------\"\n",
- "print \"Service No :\",sno\n",
- "print \"Unit Consumed :\",units\n",
- "print \"Electricity Charges : Rs.%0.2f\" % amt"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter service number : TMR65358\n",
- "Previous meter reading ? 4305\n",
- "Current meter reading ? 4410\n",
- "\n",
- " Electricity Bill\n",
- " ----------------\n",
- "Service No : TMR65358\n",
- "Unit Consumed : 105\n",
- "Electricity Charges : Rs.157.50\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-52"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to swap value of two variables\n",
- "# Variable declaration\n",
- "\n",
- "a = 15\n",
- "b = 250 \n",
- "\n",
- "print \"Enter value to A :\",a\n",
- "print \"Enter value to B :\",b\n",
- "\n",
- "# Swapping\n",
- "\n",
- "temp = a\n",
- "a = b\n",
- "b = temp\n",
- "\n",
- "print \n",
- "print \"Value of A =\",a\n",
- "print \"Value of B =\",b"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to A : 15\n",
- "Enter value to B : 250\n",
- "\n",
- "Value of A = 250\n",
- "Value of B = 15\n"
- ]
- }
- ],
- "prompt_number": 7
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice/Chapter4.ipynb b/Computer_Programming_Theory_and_Practice/Chapter4.ipynb
deleted file mode 100755
index 368164f3..00000000
--- a/Computer_Programming_Theory_and_Practice/Chapter4.ipynb
+++ /dev/null
@@ -1,524 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:c9e723d7feeae217ee8ddaf1b9cf8cfab2d696821fa911ff65107b9da6bec9f0"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 4: Control Statements in C "
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-60"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the biggest of two numbers\n",
- "# Variable declaration\n",
- "\n",
- "a = 5\n",
- "b = 8\n",
- "\n",
- "print \"Enter two numbers : %d\" % a,b\n",
- "\n",
- "# Calculation\n",
- "\n",
- "big = a\n",
- "if (b>big):\n",
- " big = b\n",
- "\n",
- "print \"Biggest number is \",big"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter two numbers : 5 8\n",
- "Biggest number is 8\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-61"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find biggest of three numbers\n",
- "# Variable declaration\n",
- "\n",
- "a = 5\n",
- "b = 13\n",
- "c = 8\n",
- "\n",
- "print \"Enter three numbers : %d\" % a,b,c\n",
- "\n",
- "# Calculate\n",
- "\n",
- "big = a\n",
- "if (b>big):\n",
- " big = b\n",
- "if (c>big):\n",
- " big = c\n",
- "\n",
- "print \"Biggest number is\",big"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three numbers : 5 13 8\n",
- "Biggest number is 13\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-63"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find biggest of three numbers\n",
- "# Variable declaration\n",
- "\n",
- "a = 18\n",
- "b = -5\n",
- "c = 13\n",
- " \n",
- "print \"Enter three numbers : %d\" % a,b,c\n",
- "\n",
- "# Calculation to find biggest number\n",
- "\n",
- "if (a>b):\n",
- " if(a>c):\n",
- " big = a\n",
- " else:\n",
- " big = c\n",
- "else:\n",
- " if(b>c):\n",
- " big = b\n",
- " else:\n",
- " big = c\n",
- "\n",
- "print \"Biggest number is\",big"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three numbers : 18 -5 13\n",
- "Biggest number is 18\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-64"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the value of y \n",
- "# Variable declration\n",
- "\n",
- "x = 0.42\n",
- "n = 5\n",
- "\n",
- "print \"Enter value to x and n :\" , x,n \n",
- "\n",
- "# Calculation\n",
- "\n",
- "if (n==1):\n",
- " y = 1 + x\n",
- "elif (n==2):\n",
- " y = 1 + x / n\n",
- "elif (n==3):\n",
- " y = 1 + (x ** n)\n",
- "else:\n",
- " y = 1 + n * x\n",
- "\n",
- "\n",
- "print \"Value of y(x,n) = %0.2f\" % y"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to x and n : 0.42 5\n",
- "Value of y(x,n) = 3.10\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-66"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the value of y\n",
- "# Variable declaration\n",
- "\n",
- "x = 0.42\n",
- "n = 5\n",
- "\n",
- "\n",
- "print \"Enter value to x and n :\", x,n\n",
- "\n",
- "# Calculation\n",
- "\n",
- "# Switch case statements \n",
- "if n == 1: # case 1\n",
- " y = 1 + x\n",
- "elif n == 2: # case 2\n",
- " y = 1 + x / n\n",
- "elif n == 3: # case 3\n",
- " y = 1 + (x ** n)\n",
- "else: # default\n",
- " y = 1 + n * x\n",
- "\n",
- "print \"Value of y(x,n) = %0.2f\" % y "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to x and n : 0.42 5\n",
- "Value of y(x,n) = 3.10\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-68"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to caculate the commission for sales representatives\n",
- "# Variable declaration\n",
- "\n",
- "sales = 4500\n",
- "\n",
- "print \"Sales amount ? :\" , sales\n",
- "\n",
- "# Calculation of commission\n",
- "\n",
- "if (sales <= 500):\n",
- " comm = 0.05 * sales\n",
- "elif (sales <= 2000):\n",
- " comm = 35 + 0.10 * (sales - 500)\n",
- "elif (sales <= 5000):\n",
- " comm = 185 + 0.12 * (sales - 2000)\n",
- "else:\n",
- " comm = 0.125 * sales\n",
- "\n",
- "\n",
- "print \"Commission Amount Rs.%0.2f\" % comm"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Sales amount ? : 4500\n",
- "Commission Amount Rs.485.00\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-69"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find roots of a quadratic equation\n",
- "# Variable declaration\n",
- "\n",
- "a = 1\n",
- "b = 3\n",
- "c = 2\n",
- "\n",
- "print \"Enter coefficients a, b, and c :\", a,b,c\n",
- "\n",
- "d = b * b - 4 * a * c\n",
- "\n",
- "# Calculation of roots\n",
- "\n",
- "if (d > 0):\n",
- " x1 = (-b + (d ** 0.5)) / (2 * a)\n",
- " x2 = (-b - (d ** 0.5)) / (2 * a)\n",
- " print \"Roots are real and unequal \"\n",
- " print x1,x2\n",
- " \n",
- "\n",
- "elif(d == 0):\n",
- " x = -b / (2 * a)\n",
- " print \"Roots are real and equal\"\n",
- " print \"%6.2f\" % x\n",
- "\n",
- "else:\n",
- " print \"No Real roots, roots are complex\"\n",
- "\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter coefficients a, b, and c : 1 3 2\n",
- "Roots are real and unequal \n",
- "-1.0 -2.0\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8 , Page number: CP-70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print grade\n",
- "# Variable declaration\n",
- "\n",
- "avg_marks = 84\n",
- "\n",
- "print \"Average marks ?\",avg_marks\n",
- "\n",
- "# Calculation of grade\n",
- "\n",
- "if (avg_marks >= 80) and (avg_marks <= 100):\n",
- " print \"Honours\"\n",
- "elif (avg_marks >= 60) and (avg_marks <=79):\n",
- " print \"First Division\"\n",
- "elif (avg_marks >= 50) and (avg_marks <= 59):\n",
- " print \"Second Division\"\n",
- "else:\n",
- " print \"Fail\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Average marks ? 84\n",
- "Honours\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to calculate electirc charges for domestic consumers\n",
- "# Variable declaration\n",
- "\n",
- "units = 348\n",
- "\n",
- "print \"Enter consumed units :\",units\n",
- "\n",
- "# Calculation of electric charges\n",
- "\n",
- "if (units <= 200):\n",
- " amt = 0.5 * units\n",
- "elif (units <= 400):\n",
- " amt = 100 + 0.65 * (units - 200)\n",
- "elif (units <= 600):\n",
- " amt = 230 + 0.8 * (units - 400)\n",
- "else:\n",
- " amt = 425 + 1.25 * (units - 600)\n",
- "print \n",
- "print \"Amount to be paid Rs.%0.2f\" % amt"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter consumed units : 348\n",
- "\n",
- "Amount to be paid Rs.196.20\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-73"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the grade of steel samples\n",
- "# Variable declaration\n",
- "\n",
- "ts = 800\n",
- "rh = 180\n",
- "cc = 3\n",
- "\n",
- "print \"Enter tensile strength :\",ts\n",
- "print \"Enter rockwell hardness :\",rh\n",
- "print \"Enter carbon content :\",cc\n",
- "\n",
- "# Calculation of grade\n",
- "\n",
- "if (ts >= 700):\n",
- " if (rh >= 200):\n",
- " if (cc <= 6):\n",
- " print \"Grade is A\"\n",
- " else:\n",
- " print \"Grade is B\" \n",
- " elif (cc <= 6):\n",
- " print \"Grade is C\"\n",
- " else:\n",
- " print \"Grade is E\" \n",
- "elif (rh >= 200):\n",
- " if (cc <= 6):\n",
- " print \"Grade is D\"\n",
- " else:\n",
- " print \"Grade is E\"\n",
- "elif (cc <= 6):\n",
- " print \"Grade is E\"\n",
- "else:\n",
- " print \"Grade is F\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter tensile strength : 800\n",
- "Enter rockwell hardness : 180\n",
- "Enter carbon content : 3\n",
- "Grade is C\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice/Chapter5.ipynb b/Computer_Programming_Theory_and_Practice/Chapter5.ipynb
deleted file mode 100755
index 52adbd63..00000000
--- a/Computer_Programming_Theory_and_Practice/Chapter5.ipynb
+++ /dev/null
@@ -1,1103 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:1c1423d8954dc10aa9bbb2818169dfeb793cb3bc9435852c4188cde598c54111"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 5: Loop Control Structures in C"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-79"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print natural numbers from 1 to n\n",
- "# Variable decalration\n",
- "\n",
- "n = 15\n",
- "\n",
- "print \"Enter value to n :\",n\n",
- "\n",
- "# Loop to print natural numbers\n",
- "for r in range(15):\n",
- " r = r + 1\n",
- " print r,\n",
- " \n",
- " \n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to n : 15\n",
- "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-80"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the value of y and print a table for values of x\n",
- "# Variable declaration\n",
- "import math\n",
- "x = 1.0\n",
- "print \"------------------------\"\n",
- "print \" x y \"\n",
- "print \"------------------------\"\n",
- "while x <= 3.2:\n",
- " y = 1.36 * ((1 + x + x * x * x) ** 0.5) + ((x) ** (1.0/4)) + math.exp(x)\n",
- " print \" %0.2f \" %x + \" %0.2f\" % y\n",
- " x = x + 0.2"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "------------------------\n",
- " x y \n",
- "------------------------\n",
- " 1.00 6.07\n",
- " 1.20 7.06\n",
- " 1.40 8.23\n",
- " 1.60 9.60\n",
- " 1.80 11.20\n",
- " 2.00 13.09\n",
- " 2.20 15.30\n",
- " 2.40 17.91\n",
- " 2.60 20.99\n",
- " 2.80 24.64\n",
- " 3.00 28.97\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-81"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find factorial of given number\n",
- "# Variable declaration\n",
- "\n",
- "k = 4\n",
- "kfact = 1\n",
- "\n",
- "print \"Enter an integer :\",k\n",
- "\n",
- "# Loop to generate numbers from 1 to n\n",
- "\n",
- "for i in range(1,k + 1):\n",
- " kfact = kfact*i\n",
- "\n",
- " \n",
- "print \"4 factorial is\",kfact "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter an integer : 4\n",
- "4 factorial is 24\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-83"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print sum of the following series\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "s = 0\n",
- "\n",
- "print \"Enter value to N :\",n\n",
- "# Calculation of sum\n",
- "i = 1\n",
- "j = 1\n",
- "\n",
- "for i in range(1,n+1):\n",
- " term = 0\n",
- " for j in range(i+1):\n",
- " term = term + j\n",
- " s = s + term\n",
- "\n",
- "\n",
- "print \"Sum of the series S =\",s "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to N : 4\n",
- "Sum of the series S = 20\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-84"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to compute the values of z based on x and y\n",
- "# Variable declaration\n",
- "\n",
- "x = -1.5\n",
- "y = 0\n",
- "\n",
- "# Loops to generate values of x and y to find z\n",
- "\n",
- "while x <= 1.5:\n",
- " while y <= 3.0:\n",
- " z = 3 * x * x + 2 * y * y * y - 25.5\n",
- " print \"Value of y(\",x,\n",
- " print \",\",y,\n",
- " print \") =\",z\n",
- " y = y + 1.0\n",
- " x = x + 0.5\n",
- " y = 0\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Value of y( -1.5 , 0 ) = -18.75\n",
- "Value of y( -1.5 , 1.0 ) = -16.75\n",
- "Value of y( -1.5 , 2.0 ) = -2.75\n",
- "Value of y( -1.5 , 3.0 ) = 35.25\n",
- "Value of y( -1.0 , 0 ) = -22.5\n",
- "Value of y( -1.0 , 1.0 ) = -20.5\n",
- "Value of y( -1.0 , 2.0 ) = -6.5\n",
- "Value of y( -1.0 , 3.0 ) = 31.5\n",
- "Value of y( -0.5 , 0 ) = -24.75\n",
- "Value of y( -0.5 , 1.0 ) = -22.75\n",
- "Value of y( -0.5 , 2.0 ) = -8.75\n",
- "Value of y( -0.5 , 3.0 ) = 29.25\n",
- "Value of y( 0.0 , 0 ) = -25.5\n",
- "Value of y( 0.0 , 1.0 ) = -23.5\n",
- "Value of y( 0.0 , 2.0 ) = -9.5\n",
- "Value of y( 0.0 , 3.0 ) = 28.5\n",
- "Value of y( 0.5 , 0 ) = -24.75\n",
- "Value of y( 0.5 , 1.0 ) = -22.75\n",
- "Value of y( 0.5 , 2.0 ) = -8.75\n",
- "Value of y( 0.5 , 3.0 ) = 29.25\n",
- "Value of y( 1.0 , 0 ) = -22.5\n",
- "Value of y( 1.0 , 1.0 ) = -20.5\n",
- "Value of y( 1.0 , 2.0 ) = -6.5\n",
- "Value of y( 1.0 , 3.0 ) = 31.5\n",
- "Value of y( 1.5 , 0 ) = -18.75\n",
- "Value of y( 1.5 , 1.0 ) = -16.75\n",
- "Value of y( 1.5 , 2.0 ) = -2.75\n",
- "Value of y( 1.5 , 3.0 ) = 35.25\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-89"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find sum of odd integers between 1 to n\n",
- "# Variable declararion\n",
- "\n",
- "n = 10\n",
- "\n",
- "print \"Enter value to N :\",n\n",
- "\n",
- "s = 0\n",
- "i = 1\n",
- "\n",
- "while (i <= n):\n",
- " s = s + i\n",
- " i = i + 2\n",
- "\n",
- "print \"Sum of odd integers =\",s"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to N : 10\n",
- "Sum of odd integers = 25\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-90"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to generate first 50 positive integers that are divisible by 7\n",
- "# Variable declaration\n",
- "\n",
- "n = 7\n",
- "print \"Integers divisible by 7\"\n",
- "\n",
- "#loop to print numbers divisible by 7\n",
- "for n in range(7,353,7):\n",
- " print n,\n",
- " \n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Integers divisible by 7\n",
- "7 14 21 28 35 42 49 56 63 70 77 84 91 98 105 112 119 126 133 140 147 154 161 168 175 182 189 196 203 210 217 224 231 238 245 252 259 266 273 280 287 294 301 308 315 322 329 336 343 350\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8 , Page number: CP-91"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print integers from 1 to n that are not divisible by 7\n",
- "# Variable declaration\n",
- "\n",
- "n = 20\n",
- "print \"Enter the end value N :\",n\n",
- "\n",
- "# Loop to print numbers that are not divisible by 7\n",
- "\n",
- "print \"Integers not divisible by 7\"\n",
- "for k in range(1,n + 1,1):\n",
- " r = k % 7\n",
- " if (r != 0):\n",
- " print k,"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the end value N : 20\n",
- "Integers not divisible by 7\n",
- "1 2 3 4 5 6 8 9 10 11 12 13 15 16 17 18 19 20\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-92 "
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print sum of digits of an integer\n",
- "# Variable declaration\n",
- "\n",
- "n = 2466\n",
- "\n",
- "print \"Enter a positive integer :\",n\n",
- "\n",
- "q = n\n",
- "s = 0\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " s = s + r\n",
- " q = q / 10\n",
- "\n",
- "\n",
- "print \"Sum of digits =\",s\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a positive integer : 2466\n",
- "Sum of digits = 18\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-93"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to check whether a given number is an armstrong number or not\n",
- "# Variable declaration\n",
- "\n",
- "n = 153\n",
- "q = n\n",
- "s = 0\n",
- "\n",
- "print \"Enter an integer number :\",n\n",
- "\n",
- "# To check armstrong or not\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " s = s + r * r * r\n",
- " q = q / 10\n",
- "\n",
- "if (n == s):\n",
- " print \"%d is an Armstrong number\" % n\n",
- "else:\n",
- " print \"%d is not an Armstrong number\" % n\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter an integer number : 153\n",
- "153 is an Armstrong number\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11 , Page number: CP-94"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to reverse a given integer\n",
- "# Variable declaration\n",
- "\n",
- "n = 18532\n",
- "q = n\n",
- "rn = 0\n",
- "\n",
- "print \"Enter an integer number :\",n\n",
- "# Reversing\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " rn = (rn * 10) + r\n",
- " q = q / 10\n",
- "\n",
- "\n",
- "print \"18532 is reversed as\",rn "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter an integer number : 18532\n",
- "18532 is reversed as 23581\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 12 , Page number: CP-95"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to accept an integer and print digits using words\n",
- "# Variable declaration\n",
- "\n",
- "n = 4352\n",
- "q = n\n",
- "rn = 0\n",
- "\n",
- "print \"Enter an integer number :\",n\n",
- "# converting to digits\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " rn = rn * 10 + r\n",
- " q = q / 10\n",
- "\n",
- "\n",
- "while (rn > 0):\n",
- " r = rn % 10\n",
- " if (r == 1):\n",
- " s = \"One\"\n",
- " print s,\n",
- " elif (r == 2):\n",
- " s = \"Two\"\n",
- " print s,\n",
- " elif (r == 3):\n",
- " s = \"Three\"\n",
- " print s,\n",
- " elif (r == 4):\n",
- " s = \"Four\"\n",
- " print s,\n",
- " elif (r == 5):\n",
- " s = \"Five\"\n",
- " print s,\n",
- " elif (r == 6):\n",
- " s = \"Six\"\n",
- " print s,\n",
- " elif (r == 7):\n",
- " s = \"Seven\"\n",
- " print s,\n",
- " elif (r == 8):\n",
- " s = \"Eight\"\n",
- " print s,\n",
- " elif (r == 9):\n",
- " s = \"Nine\"\n",
- " print s,\n",
- " elif (r == 0):\n",
- " s = \"Zero\"\n",
- " print s,\n",
- " rn = rn / 10\n",
- "\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter an integer number : 4352\n",
- "Four Three Five Two\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 13 , Page number: CP-97"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find whether a number is prime or not\n",
- "# Variable declaration\n",
- "\n",
- "n = 17\n",
- "\n",
- "print \"Enter a positive integer :\",n\n",
- "\n",
- "# prime numbers are greater than 1\n",
- "if n > 1:\n",
- " # check for factors\n",
- " for i in range(2,n):\n",
- " if (n % i) == 0:\n",
- " print(n,\"is not a prime number\")\n",
- " print(i,\"times\",n//i,\"is\",num)\n",
- " break\n",
- " else:\n",
- " print \"%d is a prime number\" % n\n",
- "\n",
- "else:\n",
- " print \"%d is not a prime number\" % n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a positive integer : 17\n",
- "17 is a prime number\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 14 , Page number: CP-98"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to generate Fibonacci series\n",
- "# Variable declaration\n",
- "\n",
- "n = 25\n",
- "n1 = 0\n",
- "n2 = 1\n",
- "\n",
- "print \"Enter the final term of the series :\",n\n",
- "\n",
- "print n1,n2,\n",
- "\n",
- "\n",
- "newterm = n1 + n2\n",
- "\n",
- "# Loop to print fibonacci series\n",
- "while (newterm <= n):\n",
- " print newterm,\n",
- " n1 = n2\n",
- " n2 = newterm\n",
- " newterm = n1 + n2\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the final term of the series : 25\n",
- "0 1 1 2 3 5 8 13 21\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 15 , Page number: CP-99"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to solve the sine series\n",
- "# Variable declaration\n",
- "\n",
- "x = 0.52\n",
- "n = 10\n",
- "s = 0\n",
- "term = x\n",
- "i = 1\n",
- "\n",
- "print \"Enter x in radians :\",x\n",
- "print \"Enter end term power (n):\",n\n",
- "\n",
- "while (i <= n):\n",
- " s = s + term\n",
- " term = (term * x * x *(-1)) / ((i + 1) * (i + 2))\n",
- " i = i + 2\n",
- "\n",
- "print \"Sum of the series = %0.6f\" % s\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter x in radians : 0.52\n",
- "Enter end term power (n): 10\n",
- "Sum of the series = 0.496880\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 16 , Page number: CP-101"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to solve the cosine series\n",
- "# Variable declaration\n",
- "\n",
- "x = 0.52\n",
- "s = 0\n",
- "term = 1\n",
- "i = 0\n",
- "n = 10\n",
- "print \"Enter x in radians :\",x\n",
- "\n",
- "# Calculation of cosine series\n",
- "\n",
- "while (i <= n):\n",
- " s = s + term\n",
- " term = (term * x * x * (-1)) / ((i + 1) * (i + 2))\n",
- " i = i + 2\n",
- "\n",
- "\n",
- "print \"Sum of the series = %0.6f\" % s "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter x in radians : 0.52\n",
- "Sum of the series = 0.867819\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 17 , Page number: CP-102"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "\n",
- "# Program to compute the value of pie\n",
- "# Variable declaration\n",
- "\n",
- "s = 0.0\n",
- "dr = 1\n",
- "sign = 1\n",
- "term = (1.0/dr) * sign\n",
- "while (math.fabs(term) >= 1.0e-4):\n",
- " s = s + term\n",
- " dr = dr + 2\n",
- " sign = sign * -1\n",
- " term = (1.0 / dr) * sign\n",
- "\n",
- "pie = s * 4\n",
- "\n",
- "print \"Value of pie is %.6f\"%pie"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Value of pie is 3.141393\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 18 , Page number: CP-104"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to evaluate the series\n",
- "# Variable declaration\n",
- "\n",
- "n = 15\n",
- "s = 0.00\n",
- "\n",
- "print \"Enter value to N :\",n\n",
- "\n",
- "# Evaluation of series\n",
- "\n",
- "for i in range(1,n + 1,1):\n",
- " s = float(s) + float(1.0 / i)\n",
- " \n",
- "\n",
- "print \"Sum of series = %0.4f\" % s \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to N : 15\n",
- "Sum of series = 3.3182\n"
- ]
- }
- ],
- "prompt_number": 18
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 21 , Page number: CP-108"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print multiplication table\n",
- "# Variable declaration\n",
- "\n",
- "i = 1\n",
- "j = 1\n",
- "\n",
- "# nested loop to print multiplication tables\n",
- "\n",
- "for i in range(1,6):\n",
- " print \"Multiplication table for\",i\n",
- " for j in range(1,11):\n",
- " print \" \",j,\"x\" , i ,\" =\" , j*i\n",
- " print \"Press any key to continue. . .\" "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Multiplication table for 1\n",
- " 1 x 1 = 1\n",
- " 2 x 1 = 2\n",
- " 3 x 1 = 3\n",
- " 4 x 1 = 4\n",
- " 5 x 1 = 5\n",
- " 6 x 1 = 6\n",
- " 7 x 1 = 7\n",
- " 8 x 1 = 8\n",
- " 9 x 1 = 9\n",
- " 10 x 1 = 10\n",
- "Press any key to continue. . .\n",
- "Multiplication table for 2\n",
- " 1 x 2 = 2\n",
- " 2 x 2 = 4\n",
- " 3 x 2 = 6\n",
- " 4 x 2 = 8\n",
- " 5 x 2 = 10\n",
- " 6 x 2 = 12\n",
- " 7 x 2 = 14\n",
- " 8 x 2 = 16\n",
- " 9 x 2 = 18\n",
- " 10 x 2 = 20\n",
- "Press any key to continue. . .\n",
- "Multiplication table for 3\n",
- " 1 x 3 = 3\n",
- " 2 x 3 = 6\n",
- " 3 x 3 = 9\n",
- " 4 x 3 = 12\n",
- " 5 x 3 = 15\n",
- " 6 x 3 = 18\n",
- " 7 x 3 = 21\n",
- " 8 x 3 = 24\n",
- " 9 x 3 = 27\n",
- " 10 x 3 = 30\n",
- "Press any key to continue. . .\n",
- "Multiplication table for 4\n",
- " 1 x 4 = 4\n",
- " 2 x 4 = 8\n",
- " 3 x 4 = 12\n",
- " 4 x 4 = 16\n",
- " 5 x 4 = 20\n",
- " 6 x 4 = 24\n",
- " 7 x 4 = 28\n",
- " 8 x 4 = 32\n",
- " 9 x 4 = 36\n",
- " 10 x 4 = 40\n",
- "Press any key to continue. . .\n",
- "Multiplication table for 5\n",
- " 1 x 5 = 5\n",
- " 2 x 5 = 10\n",
- " 3 x 5 = 15\n",
- " 4 x 5 = 20\n",
- " 5 x 5 = 25\n",
- " 6 x 5 = 30\n",
- " 7 x 5 = 35\n",
- " 8 x 5 = 40\n",
- " 9 x 5 = 45\n",
- " 10 x 5 = 50\n",
- "Press any key to continue. . .\n"
- ]
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 22 , Page number: CP-109"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "\n",
- "# Program to convert a binary number to a decimal number\n",
- "# Variable declaration\n",
- "\n",
- "q = 1101\n",
- "s = 0\n",
- "k = 0\n",
- "\n",
- "print \"Enter the binary number :\",q\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " s = s + r * pow(2,k)\n",
- " q = q / 10\n",
- " k = k + 1\n",
- "\n",
- "\n",
- "print \"The decimal number is :\",s\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the binary number : 1101\n",
- "The decimal number is : 13\n"
- ]
- }
- ],
- "prompt_number": 20
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 23 , Page number: CP-110"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to convert a decimal number to a binary number\n",
- "# Variable declaration\n",
- "\n",
- "n = 28\n",
- "q = n\n",
- "rbi = 0\n",
- "flag = 0\n",
- "k = 0\n",
- "\n",
- "print \"Enter the decimal number :\",n\n",
- "\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 2\n",
- " if (r == 0) and (flag == 0):\n",
- " k = k + 1\n",
- " else:\n",
- " flag = 1\n",
- " rbi = rbi * 10 + r\n",
- " q = q / 2\n",
- " \n",
- "q = rbi\n",
- "bi = 0\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " bi = bi * 10 + r\n",
- " q = q / 10\n",
- " i = 1\n",
- " if (q == 0):\n",
- " while (i <= k):\n",
- " bi = bi * 10\n",
- " i = i + 1\n",
- "\n",
- "\n",
- "print \"The binary number is \",bi "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the decimal number : 28\n",
- "The binary number is 11100\n"
- ]
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice/Chapter6.ipynb b/Computer_Programming_Theory_and_Practice/Chapter6.ipynb
deleted file mode 100755
index 14969fc1..00000000
--- a/Computer_Programming_Theory_and_Practice/Chapter6.ipynb
+++ /dev/null
@@ -1,794 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:aced1a8512bbd1c950b44a0ce98d7bb529f62e617c89b1c73eec08ce49b27311"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 6: Arrays and Subscribed Variables"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-122"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the sum of n numbers using array\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "x = [36,45,52,44,62]\n",
- "\n",
- "print \"How many integers ?\",n\n",
- "print \"Enter the 1th value :\",x[0]\n",
- "print \"Enter the 2th value :\",x[1]\n",
- "print \"Enter the 3th value :\",x[2]\n",
- "print \"Enter the 4th value :\",x[3]\n",
- "print \"Enter the 5th value :\",x[4]\n",
- "\n",
- "summ = 0 \n",
- "\n",
- "# Calculation of sum of numbers\n",
- "for i in x:\n",
- " summ = summ + i\n",
- " \n",
- "\n",
- "print \"Sum of all integers =\",summ\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many integers ? 5\n",
- "Enter the 1th value : 36\n",
- "Enter the 2th value : 45\n",
- "Enter the 3th value : 52\n",
- "Enter the 4th value : 44\n",
- "Enter the 5th value : 62\n",
- "Sum of all integers = 239\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-123"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the biggest of n numbers\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "x = [25,-228,0,185,36]\n",
- "\n",
- "print \"How many numbers ?\",n\n",
- "print \"Enter all those numbers\"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "\n",
- "big = x[0]\n",
- "\n",
- "\n",
- "for i in x:\n",
- " if (i > big):\n",
- " big = i\n",
- "\n",
- "\n",
- "print \"%d is the biggest number\" % big "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers ? 5\n",
- "Enter all those numbers\n",
- "25 -228 0 185 36\n",
- "185 is the biggest number\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: Cp-124"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the arithmetic mean, variance and standard deviation\n",
- "# Variable declaration\n",
- "\n",
- "n = 6\n",
- "x = [3.1,3.8,3.6,4.0,3.4,3.8]\n",
- "summ = 0\n",
- "vsum = 0\n",
- "\n",
- "print \"How many values ?\",n\n",
- "print \"Enter all values in the list \"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "\n",
- "# Loop to find sum of all values\n",
- "\n",
- "for i in x:\n",
- " summ = summ + i\n",
- "\n",
- "xbar = summ / n\n",
- "\n",
- "# Loop to find the numerator vsum to find variance\n",
- "\n",
- "for i in x:\n",
- " vsum = vsum + (i - xbar) * (i - xbar)\n",
- "\n",
- "\n",
- "sigmax = vsum / n\n",
- "sd = sigmax ** 0.5\n",
- "\n",
- "print \"Arithmetic mean = %0.3f\" % xbar\n",
- "print \"Variance = %0.3f \" % sigmax\n",
- "print \"Standard deviation = %0.3f\" % sd"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many values ? 6\n",
- "Enter all values in the list \n",
- "3.1 3.8 3.6 4.0 3.4 3.8\n",
- "Arithmetic mean = 3.617\n",
- "Variance = 0.088 \n",
- "Standard deviation = 0.297\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-126"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to calculate mean of marks and print list of marks greater than mean\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "x = [58,63,68,54,48]\n",
- "summ = 0 # Used summ instead of sum since it was a inbuilt function\n",
- "i = 0\n",
- "\n",
- "print \"How many students ?\",n\n",
- "print \"Enter all the marks \"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "\n",
- "for i in x:\n",
- " summ = summ + i\n",
- "\n",
- "mean = float(summ) / n\n",
- "\n",
- "print \"Mean = %0.2f\" % mean\n",
- "print \"Marks greater than mean :\",\n",
- "\n",
- "i = 0\n",
- "for i in x:\n",
- " if (i > mean):\n",
- " print i,\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many students ? 5\n",
- "Enter all the marks \n",
- "58 63 68 54 48\n",
- "Mean = 58.20\n",
- "Marks greater than mean : 63 68\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-127"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find sum of all positive and negative numbers and to find out which is larger in magnitude\n",
- "# Variable declaration\n",
- "import math\n",
- "\n",
- "n = 6\n",
- "x = [8,-12,-16,12,-9,5]\n",
- "psum = 0\n",
- "nsum = 0\n",
- "\n",
- "print \"How many values ?\",n\n",
- "print \"Enter all values in the list\"\n",
- "for i in x:\n",
- " print i,\n",
- "print \n",
- "\n",
- "# Loop to calculate sum of positive and negative values\n",
- "\n",
- "for i in x:\n",
- " if i > 0:\n",
- " psum = psum + i\n",
- " else:\n",
- " nsum = nsum + i\n",
- "\n",
- "print \"Sum of positive values = %0.2f\" % psum\n",
- "print \"Sum of negative values = %0.2f\" % nsum\n",
- "\n",
- "if (psum > abs(nsum)):\n",
- " print \"Positive sum is greater in magnitude\"\n",
- "else:\n",
- " print \"Negative sum is greater in magnitude\"\n",
- "\n",
- "diff = abs(psum) - abs(nsum)\n",
- "print \"Difference in magnitude = %0.2f\" % abs(diff)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many values ? 6\n",
- "Enter all values in the list\n",
- "8 -12 -16 12 -9 5\n",
- "Sum of positive values = 25.00\n",
- "Sum of negative values = -37.00\n",
- "Negative sum is greater in magnitude\n",
- "Difference in magnitude = 12.00\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-129"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to sort n numbers in ascending order\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "x = [32,-10,20,5]\n",
- "i = 0\n",
- "\n",
- "\n",
- "print \"How many numbers ?\",n\n",
- "print \"Enter the list of 4 numbers\"\n",
- "for a in x:\n",
- " print a,\n",
- "print\n",
- "\n",
- "# Loop to arrange the numbers in ascending order\n",
- "\n",
- "while i < n-1:\n",
- " j = i + 1\n",
- " while j < n:\n",
- " if x[i] > x[j]:\n",
- " temp = x[i]\n",
- " x[i] = x[j]\n",
- " x[j] = temp\n",
- " j = j + 1\n",
- " i = i + 1\n",
- "\n",
- "print \"Numbers in ascending order \"\n",
- "\n",
- "for a in x:\n",
- " print a,\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers ? 4\n",
- "Enter the list of 4 numbers\n",
- "32 -10 20 5\n",
- "Numbers in ascending order \n",
- "-10 5 20 32\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-131"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to search the key value and to print it if the search is successful\n",
- "# Variable declaration\n",
- "\n",
- "n = 6\n",
- "x = [6,-2,8,3,13,10]\n",
- "s = 3\n",
- "\n",
- "print \"How many values in the list ?\",n\n",
- "print \"Enter all values in the list\"\n",
- "for i in x:\n",
- " print i,\n",
- "print \n",
- "print \"Enter the key value to be searched :\",s\n",
- "\n",
- "# loop to search key value in the list\n",
- "\n",
- "for i in range(n):\n",
- " if s == x[i]:\n",
- " print s,\" is available in\",i+1,\"th location\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many values in the list ? 6\n",
- "Enter all values in the list\n",
- "6 -2 8 3 13 10\n",
- "Enter the key value to be searched : 3\n",
- "3 is available in 4 th location\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8 , Page number: CP-133"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to sort n numbers using bubble sort and find number of exchanges and passes\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "x = [6,-2,8,3]\n",
- "exchng = 0\n",
- "\n",
- "print \"How many numbers?\",n\n",
- "print \"Enter all the numbers in the list\"\n",
- "for i in x:\n",
- " print i,\n",
- "\n",
- "print\n",
- "\n",
- "for i in range(0,n-1):\n",
- " for j in range(0,n-i-1):\n",
- " if x[j] > x[j+1]:\n",
- " temp = x[j]\n",
- " x[j] = x[j+1]\n",
- " x[j+1] = temp\n",
- " exchng = exchng + 1\n",
- " \n",
- "\n",
- "print \"The sorted list is\"\n",
- "for i in x:\n",
- " print i,\n",
- "\n",
- "print \n",
- "\n",
- "print \"Sorted in\",n-1,\"passes and\",exchng,\"exchanges\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers? 4\n",
- "Enter all the numbers in the list\n",
- "6 -2 8 3\n",
- "The sorted list is\n",
- "-2 3 6 8\n",
- "Sorted in 3 passes and 3 exchanges\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-135"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to add two matrices\n",
- "# Variable declaration\n",
- "\n",
- "a = [[2,-2],\n",
- " [0,4]]\n",
- "b = [[6,2],\n",
- " [4,-5]]\n",
- "\n",
- "c = [[0,0],\n",
- " [0,0]]\n",
- "\n",
- "m = 2\n",
- "n = 2\n",
- "\n",
- "print \"How many rows and columns ?\",m,n\n",
- "print \"Enter A matrix\"\n",
- "for i in a:\n",
- " print i\n",
- "\n",
- "print \"Enter B matrix\"\n",
- "for j in b:\n",
- " print j\n",
- "\n",
- "# Loop to add two matrices\n",
- "\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " c[i][j] = a[i][j] + b[i][j]\n",
- "\n",
- "\n",
- "print \"Resultant matrix is\"\n",
- "for ci in c:\n",
- " print ci"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many rows and columns ? 2 2\n",
- "Enter A matrix\n",
- "[2, -2]\n",
- "[0, 4]\n",
- "Enter B matrix\n",
- "[6, 2]\n",
- "[4, -5]\n",
- "Resultant matrix is\n",
- "[8, 0]\n",
- "[4, -1]\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-136"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to multiply two matrices\n",
- "# Variable declaration\n",
- "\n",
- "m = 2\n",
- "n = 2\n",
- "l = 2\n",
- "a = [[2,-2],\n",
- " [0,4]]\n",
- "b = [[6,2],\n",
- " [4,-5]]\n",
- "c = [[0,0],\n",
- " [0,0]]\n",
- "\n",
- "print \"Enter order of A matrix :\",m,n\n",
- "print \"Enter A matrix\"\n",
- "for i in a:\n",
- " print i\n",
- "print \"Enter order of B matrix :\",m,n\n",
- "print \"Enter B matrix\"\n",
- "for j in b:\n",
- " print j\n",
- "\n",
- "# Loop to multiply two matrices\n",
- "# iterate through rowa of A\n",
- "for i in range(m):\n",
- " # iterate through columns of B\n",
- " for j in range(l):\n",
- " c[i][j] = 0\n",
- " # iterate through rows of B\n",
- " for k in range(n):\n",
- " c[i][j] = c[i][j] + a[i][k] * b[k][j]\n",
- "\n",
- "\n",
- "print \"Resultant matrix is\"\n",
- "\n",
- "for i in c:\n",
- " print i\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter order of A matrix : 2 2\n",
- "Enter A matrix\n",
- "[2, -2]\n",
- "[0, 4]\n",
- "Enter order of B matrix : 2 2\n",
- "Enter B matrix\n",
- "[6, 2]\n",
- "[4, -5]\n",
- "Resultant matrix is\n",
- "[4, 14]\n",
- "[16, -20]\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11 , Page number: CP-138"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find and print the transpose of the matrix\n",
- "# Variable declaration\n",
- "\n",
- "m = 2\n",
- "n = 3\n",
- "a = [[-3,6,0],\n",
- " [3,2,8]]\n",
- "at = [[0,0],\n",
- " [0,0],\n",
- " [0,0]]\n",
- "\n",
- "print \"Enter order of the matrix :\",m,n\n",
- "print \"Enter the matrix values\"\n",
- "for i in a :\n",
- " print i\n",
- "\n",
- "# Loop to calculate transpose\n",
- "\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " at[j][i] = a[i][j]\n",
- "\n",
- "print \"The transposed matrix is \"\n",
- "for i in at:\n",
- " print i\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter order of the matrix : 2 3\n",
- "Enter the matrix values\n",
- "[-3, 6, 0]\n",
- "[3, 2, 8]\n",
- "The transposed matrix is \n",
- "[-3, 3]\n",
- "[6, 2]\n",
- "[0, 8]\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 12 ,Page number: CP-139"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to check whether a given matrix is symmetric or not\n",
- "# Variable declaration\n",
- "\n",
- "m = 3\n",
- "a = [[5,3,8],\n",
- " [3,1,-7],\n",
- " [8,-7,4]]\n",
- "\n",
- "print \"Enter order of the square matrix :\",m\n",
- "for i in a:\n",
- " print i\n",
- "\n",
- "# Loop to check whether symmetric or not\n",
- "\n",
- "for i in range(m):\n",
- " flag = 0\n",
- " for j in range(m):\n",
- " flag = 0\n",
- " if a[i][j] == a[j][i]:\n",
- " continue\n",
- " else:\n",
- " flag = 1\n",
- "\n",
- "if flag == 0:\n",
- " print \"The given matrix is a symmetric matrix\"\n",
- "else:\n",
- " print \"The given matrix is not a symmetric matrix\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter order of the square matrix : 3\n",
- "[5, 3, 8]\n",
- "[3, 1, -7]\n",
- "[8, -7, 4]\n",
- "The given matrix is a symmetric matrix\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 13 , Page number: CP-141"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the trace of a given square matrix\n",
- "# Variable dclaration\n",
- "\n",
- "m = 3\n",
- "a = [[3,2,-1],\n",
- " [4,1,8],\n",
- " [6,4,2]]\n",
- "summ = 0\n",
- "\n",
- "print \"Enter order of the square matrix :\",m\n",
- "print \"Enter the matrix\"\n",
- "for i in a:\n",
- " print i\n",
- "\n",
- "# Loop to find trace\n",
- "for i in range(m):\n",
- " summ = summ + a[i][i]\n",
- "\n",
- "print \"Trace of the matrix =\",summ "
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice/Chapter7.ipynb b/Computer_Programming_Theory_and_Practice/Chapter7.ipynb
deleted file mode 100755
index 0d79c17f..00000000
--- a/Computer_Programming_Theory_and_Practice/Chapter7.ipynb
+++ /dev/null
@@ -1,557 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:37ae6cc76fe6f4a8cc8dba62582a6a103f99da5c7579d1a782cb95241f542fd8"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-148"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to count the occurence of a particular in a string\n",
- "# Variable declaration\n",
- "\n",
- "st = \"MISSISSIPPI\"\n",
- "ch = \"S\"\n",
- "count = 0\n",
- "\n",
- "print \"Enter the string :\",st\n",
- "print \"Which character to be counted ?\",ch\n",
- "\n",
- "# Loop to check occurrence of aa character\n",
- "\n",
- "l = len(st)\n",
- "\n",
- "for i in st:\n",
- " if i == ch:\n",
- " count = count + 1\n",
- "\n",
- "print \"The character \" + ch + \" occurs %d times\" % count "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the string : MISSISSIPPI\n",
- "Which character to be counted ? S\n",
- "The character S occurs 4 times\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-149"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to count the number of vowels in a sentence\n",
- "# Variable declaration\n",
- "\n",
- "st = \"This is a book\"\n",
- "count = 0\n",
- "\n",
- "print \"Enter the sentence :\"\n",
- "print st\n",
- "\n",
- "# Loop to count the vowels in the string\n",
- "\n",
- "for i in st:\n",
- " if i == \"A\":\n",
- " count = count + 1\n",
- " elif i == \"E\":\n",
- " count = count + 1\n",
- " elif i == \"I\":\n",
- " count = count + 1\n",
- " elif i == \"O\":\n",
- " count = count + 1\n",
- " elif i == \"U\":\n",
- " count = count + 1\n",
- " elif i == \"a\":\n",
- " count = count + 1\n",
- " elif i == \"e\":\n",
- " count = count + 1\n",
- " elif i == \"i\":\n",
- " count = count + 1\n",
- " elif i == \"o\":\n",
- " count = count + 1\n",
- " elif i == \"u\":\n",
- " count = count + 1\n",
- "\n",
- "print \"%d vowels are present in the sentence\" % count\n",
- " \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the sentence :\n",
- "This is a book\n",
- "5 vowels are present in the sentence\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-150"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to test whether a given string is a palindrome or not\n",
- "# Variable declaration\n",
- "\n",
- "st = \"HYDERABAD\"\n",
- "rst = \"\"\n",
- "i = 0\n",
- "j = len(st) - 1\n",
- "\n",
- "print \"Enter the string :\",st\n",
- "\n",
- "# Palindrome or not \n",
- "\n",
- "rst = reversed(st)\n",
- "\n",
- "if list(st) == list(rst):\n",
- " print \"%s is a palindrome string \" % st\n",
- "else:\n",
- " print \"%s is not a palindrome string \" % st"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the string : HYDERABAD\n",
- "HYDERABAD is not a palindrome string \n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-152"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to conctenate two strings\n",
- "# Variable declaration\n",
- "\n",
- "st1 = \"NEW \"\n",
- "st2 = \"DELHI\"\n",
- "\n",
- "# input of two strings to be concatenated\n",
- "\n",
- "print \"Enter first string :\",st1\n",
- "print \"Enter second string :\",st2\n",
- "\n",
- "# concatenation of two strings\n",
- "st = st1 + st2\n",
- "\n",
- "print \"Resultant string is \",st "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter first string : NEW \n",
- "Enter second string : DELHI\n",
- "Resultant string is NEW DELHI\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-154"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to compare two strings\n",
- "# Variable declaration\n",
- "\n",
- "st1 = \"ALPHA\"\n",
- "st2 = \"BETA\"\n",
- "\n",
- "print \"Enter string 1:\",st1\n",
- "print \"Enter string 2:\",st2\n",
- "\n",
- "# compare strings\n",
- "\n",
- "if (cmp(st1,st2)>0):\n",
- " print \"%s \" + st1 + \"is alphabetically greater string\"\n",
- "else:\n",
- " print st2 + \" is alphabetically greater string\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter string 1: ALPHA\n",
- "Enter string 2: BETA\n",
- "BETA is alphabetically greater string\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-155"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to sort an array of names in alphabetical order\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "names = [\"DEEPAK\",\"SHERIN\",\"SONIKA\",\"ARUN\"]\n",
- "\n",
- "print \"How many names ?\",n\n",
- "print \"Enter the 4 names one by one\"\n",
- "for i in names:\n",
- " print i\n",
- "\n",
- "# Loop to arrange names in alphabetical order\n",
- "\n",
- "for i in range(0,n-1):\n",
- " for j in range(i+1,n):\n",
- " if cmp(names[i],names[j])>0:\n",
- " \n",
- " temp = names[i]\n",
- " names[i] = names[j]\n",
- " names[j] = temp\n",
- "\n",
- "print \"Names in alphabetical order\"\n",
- "for i in names:\n",
- " print i"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many names ? 4\n",
- "Enter the 4 names one by one\n",
- "DEEPAK\n",
- "SHERIN\n",
- "SONIKA\n",
- "ARUN\n",
- "Names in alphabetical order\n",
- "ARUN\n",
- "DEEPAK\n",
- "SHERIN\n",
- "SONIKA\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-157"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to convert a line from lower case to upper case\n",
- "# Variable declaretion\n",
- "\n",
- "import sys\n",
- "\n",
- "st = ['l','o','g','i','c','a','l',' ','t','h','i','n','k','i','n','g',' ','i','s',' ','a',' ','m','u','s','t',' ','t','o',' ','l','e','a','r','n',' ','p','r','o','g','r','a','m','m','i','n','g']\n",
- "\n",
- "print \"Enter a sentence :\"\n",
- "for i in st:\n",
- " print i,\n",
- "print \n",
- "print \"The converted upper case string is\"\n",
- "# loop to convert lower case alphabet to upper case text\n",
- "for i in range(len(st)):\n",
- " if st[i] >= 'a' and st[i] <= 'z':\n",
- " st[i] = chr(ord(st[i])-32)\n",
- "\n",
- "\n",
- " sys.stdout.write(st[i])"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a sentence :\n",
- "l o g i c a l t h i n k i n g i s a m u s t t o l e a r n p r o g r a m m i n g\n",
- "The converted upper case string is\n",
- "LOGICAL THINKING IS A MUST TO LEARN PROGRAMMING"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-160"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to read a text and to omit al occurrences of a particular word\n",
- "# Variable declartion\n",
- "\n",
- "st = \"TO ACCESS THE NAME OF THE CITY IN THE LIST\"\n",
- "i = 0\n",
- "omit = \"THE\"\n",
- "l = len(st)\n",
- "j = 0\n",
- "word = []\n",
- "newst = \"\"\n",
- "onesps = \"\"\n",
- "print \"Enter a sentence :\"\n",
- "print st\n",
- "print \"Enter word to omit :\",omit\n",
- "\n",
- "# loop to omit the given word\n",
- "\n",
- "for i in range(l):\n",
- " ch = i\n",
- " if ch == ' ':\n",
- " for j in word:\n",
- " j = \" \" \n",
- " if j == omit:\n",
- " newst = j\n",
- " newst = onesps\n",
- " j = \" \"\n",
- " j = 0\n",
- " else:\n",
- " j = ch\n",
- " j = j + 1\n",
- " i = i + 1\n",
- "\n",
- "print \"After omiting the word \" + omit\n",
- "print newst\n",
- "print \"Press any key to continue\"\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a sentence :\n",
- "TO ACCESS THE NAME OF THE CITY IN THE LIST\n",
- "Enter word to omit : THE\n",
- "After omiting the word THE\n",
- "\n",
- "Press any key to continue\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-161"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to calculate the amount to be paid for the telegram\n",
- "# Variable declaration\n",
- "\n",
- "count = 0\n",
- "st = \"Congratulations on your success in Examinations.\"\n",
- "l = len(st)\n",
- "\n",
- "print \"Type the sentence for Telegram\"\n",
- "print st\n",
- "\n",
- "# loop to count number of words\n",
- "\n",
- "for i in range(l):\n",
- " if st[i] == '?':\n",
- " count = count + 1\n",
- "\n",
- "if count <= 10:\n",
- " amt = 5\n",
- "else:\n",
- " amt = 5 + (count - 10) * 1.25\n",
- "\n",
- "print \"Amount to be paid for telegram = Rs.%0.2f\" % amt "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Type the sentence for Telegram\n",
- "Congratulations on your success in Examinations.\n",
- "Amount to be paid for telegram = Rs.5.00\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11 , Page number: CP-163"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to count number of lines,words and characters\n",
- "# Variable declaration\n",
- "\n",
- "txt = \"What is a string? How do you initialize it? Explain with example.$\"\n",
- "st = \"\"\n",
- "i = 0\n",
- "lns = 0\n",
- "wds = 0\n",
- "chs = 0\n",
- "\n",
- "print \"Enter the text, type $ at end.\"\n",
- "print txt\n",
- "\n",
- "# loop to count lines,words and characters in text\n",
- "\n",
- "while txt[i] != '$':\n",
- " # switch case statements\n",
- " if txt[i] == ' ':\n",
- " wds = wds + 1\n",
- " chs = chs + 1\n",
- " elif txt[i] == '.':\n",
- " wds = wds + 1\n",
- " lns = lns + 1\n",
- " chs = chs + 1\n",
- " elif txt[i] == '?':\n",
- " lns = lns + 1\n",
- " else: # default\n",
- " chs = chs + 1\n",
- "\n",
- " i = i + 1\n",
- "\n",
- "print \"Number of char (incl. blanks) =\",chs\n",
- "print \"Number of words =\",wds\n",
- "print \"Number of lines =\",lns\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the text, type $ at end.\n",
- "What is a string? How do you initialize it? Explain with example.$\n",
- "Number of char (incl. blanks) = 63\n",
- "Number of words = 12\n",
- "Number of lines = 3\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice/Chapter8.ipynb b/Computer_Programming_Theory_and_Practice/Chapter8.ipynb
deleted file mode 100755
index 49edb490..00000000
--- a/Computer_Programming_Theory_and_Practice/Chapter8.ipynb
+++ /dev/null
@@ -1,1027 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:0c7b2e51d9ff140f666ba709dd09beff8baf4fe046109218b6f3ac69ed4bb2fe"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-173"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to write a function to find factorial and use it to find nCr\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "r = 3\n",
- "\n",
- "print \"Enter value to n and r :\",n,r\n",
- "\n",
- "# function subprogram to find factorial\n",
- "\n",
- "def fact(k):\n",
- " p = 1\n",
- " for i in range(1,k+1):\n",
- " p = p * i\n",
- " return p\n",
- "\n",
- "\n",
- "ncr = fact(n) / (fact(r) * fact(n-r))\n",
- "\n",
- "\n",
- "print \"Value of nCr =\",ncr"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to n and r : 5 3\n",
- "Value of nCr = 10\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-174"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the biggest of given three values using function and use it to find total marks of the student\n",
- "# Variable declaration\n",
- "\n",
- "t1 = 62\n",
- "t2 = 70\n",
- "t3 = 58\n",
- "a1 = 17\n",
- "a2 = 21\n",
- "a3 = 23\n",
- "\n",
- "print \"Enter three test scores :\",t1,t2,t3\n",
- "print \"Enter three assignment scores :\",a1,a2,a3\n",
- "\n",
- "# function to find biggest of three values\n",
- "\n",
- "def big(a,b,c):\n",
- " if a > b:\n",
- " if a > c:\n",
- " return a\n",
- " else:\n",
- " return c\n",
- " elif b > c:\n",
- " return b\n",
- " else:\n",
- " return c\n",
- "\n",
- "total = big(t1,t2,t3) + big(a1,a2,a3)\n",
- "\n",
- "print \"Total marks =\",total"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three test scores : 62 70 58\n",
- "Enter three assignment scores : 17 21 23\n",
- "Total marks = 93\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-176"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to create a function to compute the cos(x) series upto 15 terms\n",
- "# Variable declaration\n",
- "\n",
- "x = 0\n",
- "\n",
- "print \"----------------------------------\"\n",
- "print \" x in degrees cos(x) \"\n",
- "print \"----------------------------------\"\n",
- "\n",
- "# function for computing cosine function\n",
- "\n",
- "def cosine(x):\n",
- " s = 0\n",
- " i = 0\n",
- " term = 1\n",
- " x = x * (3.14) / 180\n",
- " k = 1\n",
- " # loop to find summation of 15 terms\n",
- " while k <= 15:\n",
- " s = s + term\n",
- " term = term * x * x * (-1) / ((i + 1) * (i + 2))\n",
- " i = i + 2\n",
- " k = k + 1\n",
- " return s\n",
- "\n",
- "\n",
- "# calling function\n",
- "\n",
- "while x <= 180:\n",
- " print \" %d \" % x,\" %0.2f \"%cosine(x)\n",
- " x = x + 30\n",
- "\n",
- "print \"-----------------------------------\" "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "----------------------------------\n",
- " x in degrees cos(x) \n",
- "----------------------------------\n",
- " 0 1.00 \n",
- " 30 0.87 \n",
- " 60 0.50 \n",
- " 90 0.00 \n",
- " 120 -0.50 \n",
- " 150 -0.87 \n",
- " 180 -1.00 \n",
- "-----------------------------------\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-177"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find GCD of two integers\n",
- "# Variable declaration\n",
- "\n",
- "a = 45\n",
- "b = 27\n",
- "c = 81\n",
- "\n",
- "print \"Enter three integers :\",a,b,c\n",
- "\n",
- "def gcd(x,y):\n",
- " if x >= y:\n",
- " nr = x\n",
- " dr = y\n",
- " else:\n",
- " nr = y\n",
- " dr = x\n",
- " r = nr % dr\n",
- " while r != 0:\n",
- " nr = dr\n",
- " dr = r\n",
- " r = nr % dr\n",
- "\n",
- " return dr\n",
- "\n",
- "d1 = gcd(a,b)\n",
- "d2 = gcd(a,c)\n",
- "d3 = gcd(b,c)\n",
- "\n",
- "if d1 == d2:\n",
- " if d1 == d3:\n",
- " print \"Greatest common divisor is\",d1\n",
- " else:\n",
- " print \"Greatest common divisor is \",gcd(d1,d3)\n",
- "else:\n",
- " print \"Greatest common divisr is\",gcd(d1,d2)\n",
- "\n",
- "\n",
- "print \"Press any key to continue. . .\" "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three integers : 45 27 81\n",
- "Greatest common divisor is 9\n",
- "Press any key to continue. . .\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-178"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to reverse the given integer\n",
- "# Variable declaration\n",
- "\n",
- "n = 2846\n",
- "\n",
- "print \"Enter the integer :\",n\n",
- "\n",
- "# function to reverse an integer\n",
- "\n",
- "def reverse(n):\n",
- " rn = 0\n",
- " while n > 0:\n",
- " r = n % 10\n",
- " rn = rn * 10 + r\n",
- " n = n /10\n",
- " return rn\n",
- "\n",
- "\n",
- "# call the function to print the reverse integer\n",
- "\n",
- "print n,\"is reversed as \",reverse(n)\n",
- "print \"Press any key to continue. . .\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the integer : 2846\n",
- "2846 is reversed as 6482\n",
- "Press any key to continue. . .\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-179"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to compare two strings S1 and S2 and return the result 0,1,-1\n",
- "# Variable declaration\n",
- "\n",
- "s1 = \"MUMBAI\"\n",
- "s2 = \"MYSORE\"\n",
- "\n",
- "print \"Enter the first string :\",s1\n",
- "print \"Enter the second string :\",s2\n",
- "\n",
- "\n",
- "# function to compare the strings\n",
- "\n",
- "def compare(s1,s2):\n",
- " if cmp(s1,s2) == 0:\n",
- " return 0\n",
- " if cmp(s1,s2) > 0:\n",
- " return 1\n",
- " if cmp(s1,s2) < 0:\n",
- " return -1\n",
- "\n",
- "# call the function to print the result\n",
- "\n",
- "print \"The result is \", compare(s1,s2)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the first string : MUMBAI\n",
- "Enter the second string : MYSORE\n",
- "The result is -1\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-181"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the arithmetic mean of n values using a function\n",
- "# Variable declaration\n",
- "\n",
- "n = 6\n",
- "x = [3.1,3.8,3.6,4.0,3.4,3.8]\n",
- "\n",
- "print \"How many values ?\",n\n",
- "print \"Enter all values\"\n",
- "for i in x:\n",
- " print i,\n",
- "print \n",
- "# function to find arithmetic mean\n",
- "\n",
- "def amean(x,n):\n",
- " s = 0\n",
- " for i in range(n):\n",
- " s = s + x[i]\n",
- " return (s/n)\n",
- "\n",
- "# call function to print arithmetic mean\n",
- "\n",
- "print \"Arithmetic mean = %0.2f\" % amean(x,n)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many values ? 6\n",
- "Enter all values\n",
- "3.1 3.8 3.6 4.0 3.4 3.8\n",
- "Arithmetic mean = 3.62\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8 , Page number: CP-182"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to read a matrix of order m x n and print the sum of all elements using functions\n",
- "# Variable declaration\n",
- "\n",
- "m = 3\n",
- "n = 2\n",
- "a = [[2,3,4],\n",
- " [2,0,1]]\n",
- "\n",
- "\n",
- "print \"How many rows and columns :\",m,n\n",
- "print \"Enter the matrix values\"\n",
- "for i in range(n):\n",
- " for j in range(m):\n",
- " print a[i][j],\n",
- " print \n",
- "\n",
- "# function to add all elements in the matrix\n",
- "def elem_sum(a,m,n):\n",
- " i = 0\n",
- " j = 0\n",
- " s = 0\n",
- " for i in range(n):\n",
- " for j in range(m):\n",
- " s = s + a[i][j]\n",
- " j = j + 1\n",
- " i = i + 1 \n",
- " return s\n",
- "\n",
- "# call function to print the result\n",
- "\n",
- "print \"Sum of all elements in the matrix =\",\n",
- "print elem_sum(a,m,n)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many rows and columns : 3 2\n",
- "Enter the matrix values\n",
- "2 3 4\n",
- "2 0 1\n",
- "Sum of all elements in the matrix = 12\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-183"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to reverse a string\n",
- "# Variable declaration\n",
- "\n",
- "st = \"NEW DELHI\"\n",
- "print \"Enter a string :\",st\n",
- "def reverse(st):\n",
- " rst = \"\"\n",
- " for i in range(0 ,len(st)):\n",
- " rst += st[(len(st) -1) - i]\n",
- " return rst\n",
- "\n",
- "print st,\"is reversed as \",\n",
- "print reverse(st)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a string : NEW DELHI\n",
- "NEW DELHI is reversed as IHLED WEN\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-184"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to apply binary search to set of N numbers using a function\n",
- "# Variable declaration\n",
- "\n",
- "n = 10\n",
- "x = [-3,8,13,19,21,25,26,29,35,42]\n",
- "s = 19\n",
- "\n",
- "\n",
- "print \"How many numbers ?\",n\n",
- "print \"Enter all numbers in the list\"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "print \"Enter the number to be searched :\",s\n",
- "\n",
- "# function to search the number\n",
- "\n",
- "def bi_search(x,n,s):\n",
- " flag = 0\n",
- " start = 0\n",
- " end = n\n",
- " while start < end and flag ==0:\n",
- " mid = (start + end) / 2\n",
- " if x[mid] > s:\n",
- " end = mid\n",
- " elif x[mid] < s:\n",
- " start = mid + 1\n",
- " else:\n",
- " flag = 1\n",
- " return flag\n",
- "\n",
- "# calling the function\n",
- "\n",
- "if bi_search(x,n,s):\n",
- " print \"The number\",s,\"is present in the list\"\n",
- "else:\n",
- " print \"The number\",s,\"is not present in list\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers ? 10\n",
- "Enter all numbers in the list\n",
- "-3 8 13 19 21 25 26 29 35 42\n",
- "Enter the number to be searched : 19\n",
- "The number 19 is present in the list\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11 , Page number: CP-187"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find factorial of a given number using recursive function\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "r = 3\n",
- "\n",
- "print \"Enter the values to n and r :\",n,r\n",
- "\n",
- "# recursive function to find factorial\n",
- "\n",
- "def fact(k):\n",
- " if k ==1:\n",
- " return 1\n",
- " else:\n",
- " return (k * fact(k-1))\n",
- "\n",
- "ncr = fact(n)/(fact(r) * fact(n-r))\n",
- "print \"Value of nCr =\",ncr "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the values to n and r : 5 3\n",
- "Value of nCr = 10\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 12 , Page number: CP-188"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to compute the value of x power n using a recursive function\n",
- "# Variable declaration\n",
- "\n",
- "x = 4.20\n",
- "n = 3\n",
- "\n",
- "print \"Enter value to x :\",x\n",
- "print \"Enter its power :\",n\n",
- "\n",
- "# recursive function to find x rise to n\n",
- "\n",
- "def power(x,n):\n",
- " if n == 1:\n",
- " return x\n",
- " else:\n",
- " return (x * power(x,n-1))\n",
- "\n",
- "\n",
- "print \"%0.2f\" %x,\"raise to \",n,\"is %0.2f\" % power(x,n) "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to x : 4.2\n",
- "Enter its power : 3\n",
- "4.20 raise to 3 is 74.09\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 13 , Page number: CP-189"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to display first n terms of the fibonacci series using recursive function\n",
- "\n",
- "# Variable declaration\n",
- "\n",
- "n = 10\n",
- "t1 = 0\n",
- "t2 = 1\n",
- "i = 0\n",
- "count = 2\n",
- "\n",
- "# recursive function to print the terms in series\n",
- "def fibo(t1,t2):\n",
- " global count\n",
- " if (count >= n):\n",
- " return\n",
- " else:\n",
- " t3 = t1 + t2\n",
- " print t3,\n",
- " count = count + 1\n",
- " t1 = t2\n",
- " t2 = t3\n",
- " return fibo(t1,t2)\n",
- " \n",
- "\n",
- "\n",
- "print \"How many terms to be printed ?\",n\n",
- "print \"The first\",n,\"terms in Fibonacci series are\"\n",
- "print t1,\n",
- "print t2,\n",
- "\n",
- "fibo(t1,t2)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many terms to be printed ? 10\n",
- "The first 10 terms in Fibonacci series are\n",
- "0 1 1 2 3 5 8 13 21 34\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 14 , Page number: CP-196"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to add two matrices of order m x n and to print the resultant values\n",
- "# Variable declaration\n",
- "\n",
- "m = 2\n",
- "n = 2\n",
- "a = [[2,-2],\n",
- " [0,4]]\n",
- "b = [[6,2],\n",
- " [4,-5]]\n",
- "c = [[0,0],\n",
- " [0,0]]\n",
- "\n",
- "print \"How many rows and columns ?\",m,n\n",
- "print \"Enter A matrix value\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print a[i][j],\n",
- " print \n",
- "print \"Enter B matrix values\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print b[i][j],\n",
- " print \n",
- "\n",
- "# function to add matrices\n",
- "def matadd():\n",
- " for i in range(m):\n",
- " for j in range(n):\n",
- " c[i][j] = a[i][j] + b[i][j]\n",
- "\n",
- "\n",
- "\n",
- "# call function\n",
- "matadd()\n",
- "print \"Resultant matrix is\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print c[i][j],\n",
- " print \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many rows and columns ? 2 2\n",
- "Enter A matrix value\n",
- "2 -2\n",
- "0 4\n",
- "Enter B matrix values\n",
- "6 2\n",
- "4 -5\n",
- "Resultant matrix is\n",
- "8 0\n",
- "4 -1\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 15 , Page number: CP-197"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to multiply A matrix of order of m x n with B matrix of order n x l and print the resultant matrix\n",
- "# Variable declaration\n",
- "\n",
- "a = [[2,-2],\n",
- " [0,4]]\n",
- "b = [[6,2,],\n",
- " [4,-5]]\n",
- "c = [[0,0],\n",
- " [0,0]]\n",
- "\n",
- "m = 2\n",
- "n = 2\n",
- "l = 2\n",
- "\n",
- "print \"Enter order of A matrix (m x n) :\",m,n\n",
- "print \"Enter A matrix values\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print a[i][j],\n",
- " print\n",
- " \n",
- "print \"Enter order of B matrix (n x l) :\",n,l\n",
- "print \"Enter B matrix values\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print b[i][j],\n",
- " print \n",
- " \n",
- "\n",
- "# function to multiply matrices\n",
- "\n",
- "def matmul():\n",
- " for i in range(m):\n",
- " for j in range(l):\n",
- " c[i][j] = 0\n",
- " for k in range(n):\n",
- " c[i][j] = c[i][j] + a[i][k] * b[k][j]\n",
- " return c\n",
- "\n",
- "# call function\n",
- "matmul()\n",
- "print \"Resultant matix is\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print c[i][j],\n",
- " print\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter order of A matrix (m x n) : 2 2\n",
- "Enter A matrix values\n",
- "2 -2\n",
- "0 4\n",
- "Enter order of B matrix (n x l) : 2 2\n",
- "Enter B matrix values\n",
- "6 2\n",
- "4 -5\n",
- "Resultant matix is\n",
- "4 14\n",
- "16 -20\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 16 , Page number: CP-199"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to transpose a matrix of order m x n\n",
- "# Variable declaration\n",
- "\n",
- "a = [[-3,6,0],\n",
- " [3,2,8]]\n",
- "at = [[0,0],\n",
- " [0,0],\n",
- " [0,0]]\n",
- "m = 2\n",
- "n = 3\n",
- "ch = \"y\"\n",
- "\n",
- "print \"How many rows and columns ?\",m,n\n",
- "print \"Enter the matrix values\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print a[i][j],\n",
- " print \n",
- " \n",
- "\n",
- "# function to transpose a matrix\n",
- "\n",
- "def transpose(a,at,m,n):\n",
- " for i in range(m):\n",
- " for j in range(n):\n",
- " at[j][i] = a[i][j]\n",
- " return at\n",
- "\n",
- "while ch == 'y' or ch == 'Y' :\n",
- " # call function to transpose the matrix\n",
- " transpose(a,at,m,n)\n",
- " print \"Transpose of the matrix is\"\n",
- " for i in range(n):\n",
- " for j in range(m):\n",
- " print at[i][j],\n",
- " print\n",
- " ch = \"N\"\n",
- " print \"Press y to continue\"\n",
- " print \" any other key to stop.\",ch"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many rows and columns ? 2 3\n",
- "Enter the matrix values\n",
- "-3 6 0\n",
- "3 2 8\n",
- "Transpose of the matrix is\n",
- "-3 3\n",
- "6 2\n",
- "0 8\n",
- "Press y to continue\n",
- " any other key to stop. N\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 17 , Page number: CP-200"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to create a function to sort the elements of an array in ascending order\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "x = [32,-10,20,5]\n",
- "\n",
- "print \"How many numbers ?\",n\n",
- "print \"Enter the list of values\"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "\n",
- "# function to sort the numbers\n",
- "def sort(x,n):\n",
- " for i in range(n-1):\n",
- " for j in range(i+1,n):\n",
- " if x[i] > x[j]:\n",
- " temp = x[i]\n",
- " x[i] = x[j]\n",
- " x[j] = temp\n",
- " return x\n",
- "\n",
- "# call function to sort the numbers\n",
- "sort(x,n)\n",
- "print \"The sorted list is\"\n",
- "for a in x:\n",
- " print a,\n",
- "print\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers ? 4\n",
- "Enter the list of values\n",
- "32 -10 20 5\n",
- "The sorted list is\n",
- "-10 5 20 32\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice/Chapter9.ipynb b/Computer_Programming_Theory_and_Practice/Chapter9.ipynb
deleted file mode 100755
index 2113c5af..00000000
--- a/Computer_Programming_Theory_and_Practice/Chapter9.ipynb
+++ /dev/null
@@ -1,624 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:93c2825491a65ebd6dbc85e6208fc8a03cf21f92da06cf2457eda56a011645f1"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-211"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to display student details\n",
- "# class declaration instead of a structure\n",
- "\n",
- "class student:\n",
- " rno = 0\n",
- " sname = \"\"\n",
- " tot = 0\n",
- "\n",
- "# class object variable\n",
- "\n",
- "x = student()\n",
- "x.rno = 20147\n",
- "x.sname = \"PRADEEP\"\n",
- "x.tot = 64\n",
- "\n",
- "print \"Enter roll number, name and total marks\"\n",
- "print x.rno,x.sname,x.tot\n",
- "print \" Details entered are\"\n",
- "print \"Roll No. :\",x.rno\n",
- "print \"Student name :\",x.sname\n",
- "print \"Total marks :\",x.tot\n",
- "print \"Press any key to continue. . .\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter roll number, name and total marks\n",
- "20147 PRADEEP 64\n",
- " Details entered are\n",
- "Roll No. : 20147\n",
- "Student name : PRADEEP\n",
- "Total marks : 64\n",
- "Press any key to continue. . .\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-212"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to input student details and print the marks of a specified student as output\n",
- "\n",
- "# class declaration for structure\n",
- "\n",
- "class student:\n",
- " def __init__(self,rno,sname,tot):\n",
- " self.rno = rno\n",
- " self.sname = sname\n",
- " self.tot = tot\n",
- " \n",
- "# variable declaration\n",
- "\n",
- "ch = \"y\"\n",
- "n = 3\n",
- "\n",
- "# details of n students\n",
- "std = []\n",
- "std.append(student(20201,\"ARUN\",78))\n",
- "std.append(student(20208,\"DEEPAK\",69))\n",
- "std.append(student(20223,\"SUSMITHA\",88))\n",
- "\n",
- "print \"How many students ?\",n\n",
- "print \"Roll number ?\",std[0].rno\n",
- "print \"Name ?\",std[0].sname\n",
- "print \"Total marks ?\",std[0].tot\n",
- "print \"Roll number ?\",std[1].rno\n",
- "print \"Name ?\",std[1].sname\n",
- "print \"Total marks ?\",std[1].tot\n",
- "print \"Roll number ?\",std[2].rno\n",
- "print \"Name ?\",std[2].sname\n",
- "print \"Total marks ?\",std[2].tot\n",
- "print \n",
- "\n",
- "\n",
- "# To display marks of the student\n",
- "while ch == \"y\" or ch == \"Y\":\n",
- " temp = 20208\n",
- " print \"Enter student roll number to display marks :\",temp\n",
- " print \n",
- " flag = 0\n",
- " #loop to search and display details\n",
- " for i in range(3):\n",
- " if flag == 0:\n",
- " if std[i].rno == temp:\n",
- " print \"Marks obtained by \",std[i].rno,std[i].sname\n",
- " print \"Total :\",std[i].tot\n",
- " flag = 1\n",
- " if flag == 0:\n",
- " print temp,\" is not present in the list \"\n",
- " \n",
- " ch = \"n\" \n",
- " print \"press y - to continue\"\n",
- " print \" any other key to stop.\",ch\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many students ? 3\n",
- "Roll number ? 20201\n",
- "Name ? ARUN\n",
- "Total marks ? 78\n",
- "Roll number ? 20208\n",
- "Name ? DEEPAK\n",
- "Total marks ? 69\n",
- "Roll number ? 20223\n",
- "Name ? SUSMITHA\n",
- "Total marks ? 88\n",
- "\n",
- "Enter student roll number to display marks : 20208\n",
- "\n",
- "Marks obtained by 20208 DEEPAK\n",
- "Total : 69\n",
- "press y - to continue\n",
- " any other key to stop. n\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-214"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to declare a structure for student details and display list of students who obtained more than 75 marks\n",
- "\n",
- "# class for student structure\n",
- "\n",
- "class student:\n",
- " def __init__(self,rno,sname,tot):\n",
- " self.rno = rno\n",
- " self.sname = sname\n",
- " self.tot = tot\n",
- "\n",
- "std = []\n",
- "std.append(student(30401,\"ANAND\",59))\n",
- "std.append(student(30404,\"NIRMAL\",64))\n",
- "std.append(student(30428,\"ISWARYA\",82))\n",
- "std.append(student(30432,\"VIVEKA\",79))\n",
- "\n",
- "n = 4\n",
- "print \"How many students ?\",n\n",
- "print \"Roll Number ?\",std[0].rno\n",
- "print \"Name ?\",std[0].sname\n",
- "print \"Total marks ?\",std[0].tot\n",
- "print \"Roll Number ?\",std[1].rno\n",
- "print \"Name ?\",std[1].sname\n",
- "print \"Total marks ?\",std[1].tot\n",
- "print \"Roll Number ?\",std[2].rno\n",
- "print \"Name ?\",std[2].sname\n",
- "print \"Total marks ?\",std[2].tot\n",
- "print \"Roll Number ?\",std[3].rno\n",
- "print \"Name ?\",std[3].sname\n",
- "print \"Total marks ?\",std[3].tot\n",
- "print \n",
- "\n",
- "\n",
- "print \"----------------------------------------------------\"\n",
- "print \" Roll No. Name Total marks \"\n",
- "print \"----------------------------------------------------\"\n",
- "for i in range(n):\n",
- " if std[i].tot >= 75:\n",
- " print \" \",std[i].rno,\" \",std[i].sname,\" \",std[i].tot\n",
- "\n",
- "print \"----------------------------------------------------\"\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many students ? 4\n",
- "Roll Number ? 30401\n",
- "Name ? ANAND\n",
- "Total marks ? 59\n",
- "Roll Number ? 30404\n",
- "Name ? NIRMAL\n",
- "Total marks ? 64\n",
- "Roll Number ? 30428\n",
- "Name ? ISWARYA\n",
- "Total marks ? 82\n",
- "Roll Number ? 30432\n",
- "Name ? VIVEKA\n",
- "Total marks ? 79\n",
- "\n",
- "----------------------------------------------------\n",
- " Roll No. Name Total marks \n",
- "----------------------------------------------------\n",
- " 30428 ISWARYA 82\n",
- " 30432 VIVEKA 79\n",
- "----------------------------------------------------\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-216"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to store employee information and to compute employee's pay\n",
- "\n",
- "import math\n",
- "# class declaration for employee\n",
- "class employee:\n",
- " def __init__(self,eno,ename,epay,jdate):\n",
- " self.eno = eno\n",
- " self.ename = ename\n",
- " self.epay = epay\n",
- " self.jdate = jdate\n",
- "\n",
- "employs = []\n",
- "employs.append(employee(20101,\"ASHIKA\",1000,\"31/04/2001\"))\n",
- "employs.append(employee(20182,\"ASHWIN\",6000,\"11/12/1995\"))\n",
- "employs.append(employee(20204,\"PRAVEEN\",3000,\"18/06/1994\"))\n",
- "\n",
- "n = 3\n",
- "\n",
- "print \"Employee No. ?\",employs[0].eno\n",
- "print \"Name ?\",employs[0].ename\n",
- "print \"Existing date ?\",employs[0].epay\n",
- "print \"Joinin date ?\",employs[0].jdate\n",
- "print \n",
- "print \"Press y- to continue any other key to stop. y\"\n",
- "print \"Employee No. ?\",employs[1].eno\n",
- "print \"Name ?\",employs[1].ename\n",
- "print \"Existing date ?\",employs[1].epay\n",
- "print \"Joinin date ?\",employs[1].jdate\n",
- "print\n",
- "print \"Press y- to continue any other key to stop. y\"\n",
- "print \"Employee No. ?\",employs[2].eno\n",
- "print \"Name ?\",employs[2].ename\n",
- "print \"Existing date ?\",employs[2].epay\n",
- "print \"Joinin date ?\",employs[2].jdate\n",
- "print\n",
- "print \"Press y- to continue any other key to stop. N\"\n",
- "print\n",
- "print n,\" records are entered\"\n",
- "print \"Press any key to print the revised salary list\"\n",
- "print \n",
- "\n",
- "\n",
- "\n",
- "def revise(temp):\n",
- " if temp <= 2000:\n",
- " temp = int(temp + math.ceil(temp * 0.15))\n",
- " return temp\n",
- " elif temp <= 5000:\n",
- " temp = int(temp + temp * 0.10)\n",
- " return temp\n",
- " else:\n",
- " return temp\n",
- "\n",
- " \n",
- "# loop to increment salary\n",
- "for i in range(n):\n",
- " employs[i].epay = revise(employs[i].epay)\n",
- "\n",
- " \n",
- "\n",
- "\n",
- "# loop to print revised salary list\n",
- "print \" Employees Revised Pay List \"\n",
- "print \"---------------------------------------------------------\"\n",
- "print \" S.No. Number Name Joining date Pay \"\n",
- "print \"---------------------------------------------------------\"\n",
- "\n",
- "for i in range(n):\n",
- " print \" \",i+1,\" \",employs[i].eno,\" \",employs[i].ename,\" \",employs[i].jdate,\" \",employs[i].epay\n",
- "\n",
- "print \"---------------------------------------------------------\" \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Employee No. ? 20101\n",
- "Name ? ASHIKA\n",
- "Existing date ? 1000\n",
- "Joinin date ? 31/04/2001\n",
- "\n",
- "Press y- to continue any other key to stop. y\n",
- "Employee No. ? 20182\n",
- "Name ? ASHWIN\n",
- "Existing date ? 6000\n",
- "Joinin date ? 11/12/1995\n",
- "\n",
- "Press y- to continue any other key to stop. y\n",
- "Employee No. ? 20204\n",
- "Name ? PRAVEEN\n",
- "Existing date ? 3000\n",
- "Joinin date ? 18/06/1994\n",
- "\n",
- "Press y- to continue any other key to stop. N\n",
- "\n",
- "3 records are entered\n",
- "Press any key to print the revised salary list\n",
- "\n",
- " Employees Revised Pay List \n",
- "---------------------------------------------------------\n",
- " S.No. Number Name Joining date Pay \n",
- "---------------------------------------------------------\n",
- " 1 20101 ASHIKA 31/04/2001 1150\n",
- " 2 20182 ASHWIN 11/12/1995 6000\n",
- " 3 20204 PRAVEEN 18/06/1994 3300\n",
- "---------------------------------------------------------\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-219"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to store cricket details and to display a team-wise list with batting average\n",
- "\n",
- "# class for cricket structure\n",
- "\n",
- "class cricket:\n",
- " def __init__(self,pname,tname,bavg):\n",
- " self.pname = pname\n",
- " self.tname = tname\n",
- " self.bavg = bavg\n",
- "\n",
- "n = 6\n",
- "probable = []\n",
- "probable.append(cricket(\"KUMBLE\",\"KARNATAKA\",22))\n",
- "probable.append(cricket(\"KAMBLI\",\"MUMBAI\",39))\n",
- "probable.append(cricket(\"SRIKANTH\",\"TAMILNADU\",52))\n",
- "probable.append(cricket(\"SACHIM\",\"MUMBAI\",69))\n",
- "probable.append(cricket(\"RAHUL\",\"KARNATAKA\",57))\n",
- "probable.append(cricket(\"RAMESH\",\"TAMILNADU\",48))\n",
- "\n",
- "print \"How many players ?\",n\n",
- "print\n",
- "print \"Player name ?\",probable[0].pname\n",
- "print \"Which team ?\",probable[0].tname\n",
- "print \"Batting average ?\",probable[0].bavg\n",
- "print \"Player name ?\",probable[1].pname\n",
- "print \"Which team ?\",probable[1].tname\n",
- "print \"Batting average ?\",probable[1].bavg\n",
- "print \"Player name ?\",probable[2].pname\n",
- "print \"Which team ?\",probable[2].tname\n",
- "print \"Batting average ?\",probable[2].bavg\n",
- "print \"Player name ?\",probable[3].pname\n",
- "print \"Which team ?\",probable[3].tname\n",
- "print \"Batting average ?\",probable[3].bavg\n",
- "print \"Player name ?\",probable[4].pname\n",
- "print \"Which team ?\",probable[4].tname\n",
- "print \"Batting average ?\",probable[4].bavg\n",
- "print \"Player name ?\",probable[5].pname\n",
- "print \"Which team ?\",probable[5].tname\n",
- "print \"Batting average ?\",probable[5].bavg\n",
- "print\n",
- "print \n",
- "j = 0\n",
- "teams = []\n",
- "teams.append(probable[0].tname)\n",
- "j = j + 1\n",
- "for i in range(n):\n",
- " flag = 0\n",
- " for k in range(j):\n",
- " if flag == 0:\n",
- " if probable[i].tname == teams[k]:\n",
- " flag = 1\n",
- " if flag == 0 :\n",
- " teams.append(probable[i].tname)\n",
- " j = j + 1\n",
- "\n",
- "# loop to print team-wise list\n",
- "\n",
- "for k in range(3):\n",
- " print \" \",teams[k]\n",
- " print \"---------------------------------------------\"\n",
- " for i in range(n):\n",
- " if probable[i].tname == teams[k]:\n",
- " print \" \",probable[i].pname,\" \",probable[i].bavg\n",
- " print \"---------------------------------------------\" \n",
- "\n",
- "\n",
- "\n",
- "\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many players ? 6\n",
- "\n",
- "Player name ? KUMBLE\n",
- "Which team ? KARNATAKA\n",
- "Batting average ? 22\n",
- "Player name ? KAMBLI\n",
- "Which team ? MUMBAI\n",
- "Batting average ? 39\n",
- "Player name ? SRIKANTH\n",
- "Which team ? TAMILNADU\n",
- "Batting average ? 52\n",
- "Player name ? SACHIM\n",
- "Which team ? MUMBAI\n",
- "Batting average ? 69\n",
- "Player name ? RAHUL\n",
- "Which team ? KARNATAKA\n",
- "Batting average ? 57\n",
- "Player name ? RAMESH\n",
- "Which team ? TAMILNADU\n",
- "Batting average ? 48\n",
- "\n",
- "\n",
- " KARNATAKA\n",
- "---------------------------------------------\n",
- " KUMBLE 22\n",
- " RAHUL 57\n",
- "---------------------------------------------\n",
- " MUMBAI\n",
- "---------------------------------------------\n",
- " KAMBLI 39\n",
- " SACHIM 69\n",
- "---------------------------------------------\n",
- " TAMILNADU\n",
- "---------------------------------------------\n",
- " SRIKANTH 52\n",
- " RAMESH 48\n",
- "---------------------------------------------\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-235"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to illustrate the use of union using integer,string and float\n",
- "\n",
- "class student:\n",
- " def __init__(self,roll_no,sname,marks):\n",
- " self.roll_no = roll_no\n",
- " self.sname = sname\n",
- " self.marks = marks\n",
- "\n",
- "std = []\n",
- "std.append(student(0,\"AJITH\",0))\n",
- "std.append(student(0,\"RAJU\",0))\n",
- "std.append(student(0,\"VIGNESH\",0))\n",
- "std.append(student(0,\"DIVYA\",0))\n",
- "\n",
- "ch = 2\n",
- "print \"-----------------------------\"\n",
- "print \" Main menu \"\n",
- "print \"-----------------------------\"\n",
- "print \"Press 1 to enter roll numbers\"\n",
- "print \" 2 to enter names \"\n",
- "print \" 3 to enter marks \"\n",
- "print \" 4 to stop \"\n",
- "print \n",
- "print \"Enter your choice :\",ch\n",
- "\n",
- "n = 4\n",
- "print \"How many students?\",n\n",
- "for i in range(n):\n",
- " print \" Student name ? \",std[i].sname\n",
- "\n",
- "print\n",
- "print \n",
- "# display required list\n",
- "# switch case\n",
- "if ch == 1: #case 1\n",
- " print \"------------------------------\"\n",
- " print \" Students roll number list \"\n",
- " print \"------------------------------\"\n",
- " for i in range(n):\n",
- " print std[i].roll_no\n",
- " print \"-------------------------------\"\n",
- "elif ch == 2: # case 2\n",
- " print \"------------------------------\"\n",
- " print \" Students name list \"\n",
- " print \"------------------------------\"\n",
- " for i in range(n):\n",
- " print std[i].sname\n",
- " print \"-------------------------------\"\n",
- "elif ch == 3: # case 3\n",
- " print \"------------------------------\"\n",
- " print \" Students mark list \"\n",
- " print \"------------------------------\"\n",
- " for i in range(n):\n",
- " print \"Student marks\",std[i].roll_no\n",
- " print \"-------------------------------\"\n",
- " \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "-----------------------------\n",
- " Main menu \n",
- "-----------------------------\n",
- "Press 1 to enter roll numbers\n",
- " 2 to enter names \n",
- " 3 to enter marks \n",
- " 4 to stop \n",
- "\n",
- "Enter your choice : 2\n",
- "How many students? 4\n",
- " Student name ? AJITH\n",
- " Student name ? RAJU\n",
- " Student name ? VIGNESH\n",
- " Student name ? DIVYA\n",
- "\n",
- "\n",
- "------------------------------\n",
- " Students name list \n",
- "------------------------------\n",
- "AJITH\n",
- "RAJU\n",
- "VIGNESH\n",
- "DIVYA\n",
- "-------------------------------\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice/screenshots/chapter11.png b/Computer_Programming_Theory_and_Practice/screenshots/chapter11.png
deleted file mode 100755
index c5895710..00000000
--- a/Computer_Programming_Theory_and_Practice/screenshots/chapter11.png
+++ /dev/null
Binary files differ
diff --git a/Computer_Programming_Theory_and_Practice/screenshots/chapter2.png b/Computer_Programming_Theory_and_Practice/screenshots/chapter2.png
deleted file mode 100755
index 05fde2b5..00000000
--- a/Computer_Programming_Theory_and_Practice/screenshots/chapter2.png
+++ /dev/null
Binary files differ
diff --git a/Computer_Programming_Theory_and_Practice/screenshots/chapter3.png b/Computer_Programming_Theory_and_Practice/screenshots/chapter3.png
deleted file mode 100755
index 685e290b..00000000
--- a/Computer_Programming_Theory_and_Practice/screenshots/chapter3.png
+++ /dev/null
Binary files differ
diff --git a/Computer_Programming_Theory_and_Practice_/Chapter11.ipynb b/Computer_Programming_Theory_and_Practice_/Chapter11.ipynb
deleted file mode 100755
index c046ab93..00000000
--- a/Computer_Programming_Theory_and_Practice_/Chapter11.ipynb
+++ /dev/null
@@ -1,62 +0,0 @@
-{
- "metadata": {
- "name": "Chapter11"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 11, Files"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 1, Page Number:CP-277"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "# Program to create a text file\n\nfp = open(\"sample.txt\",\"w\") # open file in write mode\n\nprint \"Type the text and Press enter key at end.\"\nprint\nprint \"Computer Programming in C language is widely used for Science and Engineering applications\"\n# input data to file\nch = ['Computer ','Programming ','in ','C ','language ','is ','widely ','used ','for ','Science ','and ' ,'Engineering ','applications.']\nfor i in ch:\n fp.write(i)\nfp.close()\n ",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "Type the text and Press enter key at end.\n\nComputer Programming in C language is widely used for Science and Engineering applications\n"
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 2, Page Number:CP-278"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "# Program to read text file and count number of vowels\n\nfp = open(\"sample.txt\",\"r\") # open file in read mode\ncount = 0\nprint \"The Content of the file is:\"\n\nwhile (1): \n ch = fp.read(1)\n if not ch:\n break\n print ch\n # switch statements\n if ch == \"A\" or ch == \"a\": # case 'A' or 'a'\n count = count + 1\n elif ch == \"E\" or ch == \"e\": # case 'E' or 'e'\n count = count + 1\n elif ch == \"I\" or ch == \"i\": # case 'I' or 'i'\n count = count + 1\n elif ch == \"O\" or ch == \"o\": # case 'O' or 'o'\n count = count + 1\n elif ch == \"U\" or ch == \"u\": # case 'U' or 'u'\n count = count + 1\n\n\n\nfp.close() \nprint \"Number of vowels present =\",count \n ",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "The Content of the file is:\nC\no\nm\np\nu\nt\ne\nr\n \nP\nr\no\ng\nr\na\nm\nm\ni\nn\ng\n \ni\nn\n \nC\n \nl\na\nn\ng\nu\na\ng\ne\n \ni\ns\n \nw\ni\nd\ne\nl\ny\n \nu\ns\ne\nd\n \nf\no\nr\n \nS\nc\ni\ne\nn\nc\ne\n \na\nn\nd\n \nE\nn\ng\ni\nn\ne\ne\nr\ni\nn\ng\n \na\np\np\nl\ni\nc\na\nt\ni\no\nn\ns\n.\nNumber of vowels present = 31\n"
- }
- ],
- "prompt_number": 2
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_/Chapter2.ipynb b/Computer_Programming_Theory_and_Practice_/Chapter2.ipynb
deleted file mode 100755
index c4bc71ff..00000000
--- a/Computer_Programming_Theory_and_Practice_/Chapter2.ipynb
+++ /dev/null
@@ -1,41 +0,0 @@
-{
- "metadata": {
- "name": "Chapter2"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": "Chapter 2, Fundamentals of C language"
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": "Example 3, Page Number: CP-22"
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": "# variable declaration\n\na = 5\nb = 7\nc = 2\n\n# calculation \n\ny = a + b / c - a % c + 2 * a\n\n# result \n\nprint \"The result is \",y\n",
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": "The result is 17\n"
- }
- ],
- "prompt_number": 1
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_/Chapter3.ipynb b/Computer_Programming_Theory_and_Practice_/Chapter3.ipynb
deleted file mode 100755
index 04d24871..00000000
--- a/Computer_Programming_Theory_and_Practice_/Chapter3.ipynb
+++ /dev/null
@@ -1,293 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:0ff7bb47f00bae9dc5a49237df7011debd17443ba836341d55e8fe830338ade7"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 3: Input/Output Functions and Statements"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-39"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#program to add and find product of two numbers\n",
- "\n",
- "#variable declaration\n",
- "a = 5\n",
- "b = 3\n",
- "\n",
- "# calculation of sum and product \n",
- "\n",
- "summ = a + b\n",
- "product = a * b\n",
- "\n",
- "print a,b\n",
- "print summ,product"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "5 3\n",
- "8 15\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-45"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to convert degree fahrenheit to celcius \n",
- "# variable declaration\n",
- "\n",
- "f = 105.00\n",
- "print \"Degree fahrenheit ? %d\" % f\n",
- "# calculation of degree in celcius \n",
- "\n",
- "c = 5.0/9.0 * (f-32)\n",
- "\n",
- "# result \n",
- "print\n",
- "print \"Degree centigrade =%6.2f\" % c"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Degree fahrenheit ? 105\n",
- "\n",
- "Degree centigrade = 40.56\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-45"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# To find area of a triangle\n",
- "# variable declaration\n",
- "\n",
- "a = 5\n",
- "b = 4\n",
- "c = 6\n",
- "\n",
- "\n",
- "# calculation of area\n",
- "s = float((a+b+c))/2\n",
- "area = (s*(s-a)*(s-b)*(s-c)) ** 0.5\n",
- "\n",
- "# result\n",
- "print \"Enter three sides : %d\" % a,b,c\n",
- "print \n",
- "print \"Area of triangle = %0.2f Sq.units\" % area"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three sides : 5 4 6\n",
- "\n",
- "Area of triangle = 9.92 Sq.units\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-51"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# To print ASCII value of a given character \n",
- "# Variable declaration\n",
- "\n",
- "ch = \"A\"\n",
- "print \"Enter a character : \" , ch\n",
- "\n",
- "# Calculation of ASCII value of a character\n",
- "\n",
- "print \n",
- "print \"ASCII value of \" + ch + \" is\" ,ord(ch)\n",
- "print \"Press any key to stop. . .\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a character : A\n",
- "\n",
- "ASCII value of A is 65\n",
- "Press any key to stop. . .\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-51"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# To print electricity for consumers\n",
- "# Variable declaration\n",
- "\n",
- "sno = \"TMR65358\"\n",
- "pmr = 4305\n",
- "cmr = 4410\n",
- "\n",
- "print \"Enter service number :\" ,sno\n",
- "print \"Previous meter reading ?\",pmr\n",
- "print \"Current meter reading ?\",cmr\n",
- "\n",
- "# Calculation of electricity charges\n",
- "\n",
- "units = cmr - pmr\n",
- "amt = units * 1.50\n",
- "\n",
- "# Result\n",
- "\n",
- "print\n",
- "print \" Electricity Bill\"\n",
- "print \" ----------------\"\n",
- "print \"Service No :\",sno\n",
- "print \"Unit Consumed :\",units\n",
- "print \"Electricity Charges : Rs.%0.2f\" % amt"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter service number : TMR65358\n",
- "Previous meter reading ? 4305\n",
- "Current meter reading ? 4410\n",
- "\n",
- " Electricity Bill\n",
- " ----------------\n",
- "Service No : TMR65358\n",
- "Unit Consumed : 105\n",
- "Electricity Charges : Rs.157.50\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-52"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to swap value of two variables\n",
- "# Variable declaration\n",
- "\n",
- "a = 15\n",
- "b = 250 \n",
- "\n",
- "print \"Enter value to A :\",a\n",
- "print \"Enter value to B :\",b\n",
- "\n",
- "# Swapping\n",
- "\n",
- "temp = a\n",
- "a = b\n",
- "b = temp\n",
- "\n",
- "print \n",
- "print \"Value of A =\",a\n",
- "print \"Value of B =\",b"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to A : 15\n",
- "Enter value to B : 250\n",
- "\n",
- "Value of A = 250\n",
- "Value of B = 15\n"
- ]
- }
- ],
- "prompt_number": 7
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_/Chapter4.ipynb b/Computer_Programming_Theory_and_Practice_/Chapter4.ipynb
deleted file mode 100755
index 368164f3..00000000
--- a/Computer_Programming_Theory_and_Practice_/Chapter4.ipynb
+++ /dev/null
@@ -1,524 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:c9e723d7feeae217ee8ddaf1b9cf8cfab2d696821fa911ff65107b9da6bec9f0"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 4: Control Statements in C "
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-60"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the biggest of two numbers\n",
- "# Variable declaration\n",
- "\n",
- "a = 5\n",
- "b = 8\n",
- "\n",
- "print \"Enter two numbers : %d\" % a,b\n",
- "\n",
- "# Calculation\n",
- "\n",
- "big = a\n",
- "if (b>big):\n",
- " big = b\n",
- "\n",
- "print \"Biggest number is \",big"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter two numbers : 5 8\n",
- "Biggest number is 8\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-61"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find biggest of three numbers\n",
- "# Variable declaration\n",
- "\n",
- "a = 5\n",
- "b = 13\n",
- "c = 8\n",
- "\n",
- "print \"Enter three numbers : %d\" % a,b,c\n",
- "\n",
- "# Calculate\n",
- "\n",
- "big = a\n",
- "if (b>big):\n",
- " big = b\n",
- "if (c>big):\n",
- " big = c\n",
- "\n",
- "print \"Biggest number is\",big"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three numbers : 5 13 8\n",
- "Biggest number is 13\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-63"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find biggest of three numbers\n",
- "# Variable declaration\n",
- "\n",
- "a = 18\n",
- "b = -5\n",
- "c = 13\n",
- " \n",
- "print \"Enter three numbers : %d\" % a,b,c\n",
- "\n",
- "# Calculation to find biggest number\n",
- "\n",
- "if (a>b):\n",
- " if(a>c):\n",
- " big = a\n",
- " else:\n",
- " big = c\n",
- "else:\n",
- " if(b>c):\n",
- " big = b\n",
- " else:\n",
- " big = c\n",
- "\n",
- "print \"Biggest number is\",big"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three numbers : 18 -5 13\n",
- "Biggest number is 18\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-64"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the value of y \n",
- "# Variable declration\n",
- "\n",
- "x = 0.42\n",
- "n = 5\n",
- "\n",
- "print \"Enter value to x and n :\" , x,n \n",
- "\n",
- "# Calculation\n",
- "\n",
- "if (n==1):\n",
- " y = 1 + x\n",
- "elif (n==2):\n",
- " y = 1 + x / n\n",
- "elif (n==3):\n",
- " y = 1 + (x ** n)\n",
- "else:\n",
- " y = 1 + n * x\n",
- "\n",
- "\n",
- "print \"Value of y(x,n) = %0.2f\" % y"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to x and n : 0.42 5\n",
- "Value of y(x,n) = 3.10\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-66"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the value of y\n",
- "# Variable declaration\n",
- "\n",
- "x = 0.42\n",
- "n = 5\n",
- "\n",
- "\n",
- "print \"Enter value to x and n :\", x,n\n",
- "\n",
- "# Calculation\n",
- "\n",
- "# Switch case statements \n",
- "if n == 1: # case 1\n",
- " y = 1 + x\n",
- "elif n == 2: # case 2\n",
- " y = 1 + x / n\n",
- "elif n == 3: # case 3\n",
- " y = 1 + (x ** n)\n",
- "else: # default\n",
- " y = 1 + n * x\n",
- "\n",
- "print \"Value of y(x,n) = %0.2f\" % y "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to x and n : 0.42 5\n",
- "Value of y(x,n) = 3.10\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-68"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to caculate the commission for sales representatives\n",
- "# Variable declaration\n",
- "\n",
- "sales = 4500\n",
- "\n",
- "print \"Sales amount ? :\" , sales\n",
- "\n",
- "# Calculation of commission\n",
- "\n",
- "if (sales <= 500):\n",
- " comm = 0.05 * sales\n",
- "elif (sales <= 2000):\n",
- " comm = 35 + 0.10 * (sales - 500)\n",
- "elif (sales <= 5000):\n",
- " comm = 185 + 0.12 * (sales - 2000)\n",
- "else:\n",
- " comm = 0.125 * sales\n",
- "\n",
- "\n",
- "print \"Commission Amount Rs.%0.2f\" % comm"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Sales amount ? : 4500\n",
- "Commission Amount Rs.485.00\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-69"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find roots of a quadratic equation\n",
- "# Variable declaration\n",
- "\n",
- "a = 1\n",
- "b = 3\n",
- "c = 2\n",
- "\n",
- "print \"Enter coefficients a, b, and c :\", a,b,c\n",
- "\n",
- "d = b * b - 4 * a * c\n",
- "\n",
- "# Calculation of roots\n",
- "\n",
- "if (d > 0):\n",
- " x1 = (-b + (d ** 0.5)) / (2 * a)\n",
- " x2 = (-b - (d ** 0.5)) / (2 * a)\n",
- " print \"Roots are real and unequal \"\n",
- " print x1,x2\n",
- " \n",
- "\n",
- "elif(d == 0):\n",
- " x = -b / (2 * a)\n",
- " print \"Roots are real and equal\"\n",
- " print \"%6.2f\" % x\n",
- "\n",
- "else:\n",
- " print \"No Real roots, roots are complex\"\n",
- "\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter coefficients a, b, and c : 1 3 2\n",
- "Roots are real and unequal \n",
- "-1.0 -2.0\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8 , Page number: CP-70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print grade\n",
- "# Variable declaration\n",
- "\n",
- "avg_marks = 84\n",
- "\n",
- "print \"Average marks ?\",avg_marks\n",
- "\n",
- "# Calculation of grade\n",
- "\n",
- "if (avg_marks >= 80) and (avg_marks <= 100):\n",
- " print \"Honours\"\n",
- "elif (avg_marks >= 60) and (avg_marks <=79):\n",
- " print \"First Division\"\n",
- "elif (avg_marks >= 50) and (avg_marks <= 59):\n",
- " print \"Second Division\"\n",
- "else:\n",
- " print \"Fail\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Average marks ? 84\n",
- "Honours\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to calculate electirc charges for domestic consumers\n",
- "# Variable declaration\n",
- "\n",
- "units = 348\n",
- "\n",
- "print \"Enter consumed units :\",units\n",
- "\n",
- "# Calculation of electric charges\n",
- "\n",
- "if (units <= 200):\n",
- " amt = 0.5 * units\n",
- "elif (units <= 400):\n",
- " amt = 100 + 0.65 * (units - 200)\n",
- "elif (units <= 600):\n",
- " amt = 230 + 0.8 * (units - 400)\n",
- "else:\n",
- " amt = 425 + 1.25 * (units - 600)\n",
- "print \n",
- "print \"Amount to be paid Rs.%0.2f\" % amt"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter consumed units : 348\n",
- "\n",
- "Amount to be paid Rs.196.20\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-73"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the grade of steel samples\n",
- "# Variable declaration\n",
- "\n",
- "ts = 800\n",
- "rh = 180\n",
- "cc = 3\n",
- "\n",
- "print \"Enter tensile strength :\",ts\n",
- "print \"Enter rockwell hardness :\",rh\n",
- "print \"Enter carbon content :\",cc\n",
- "\n",
- "# Calculation of grade\n",
- "\n",
- "if (ts >= 700):\n",
- " if (rh >= 200):\n",
- " if (cc <= 6):\n",
- " print \"Grade is A\"\n",
- " else:\n",
- " print \"Grade is B\" \n",
- " elif (cc <= 6):\n",
- " print \"Grade is C\"\n",
- " else:\n",
- " print \"Grade is E\" \n",
- "elif (rh >= 200):\n",
- " if (cc <= 6):\n",
- " print \"Grade is D\"\n",
- " else:\n",
- " print \"Grade is E\"\n",
- "elif (cc <= 6):\n",
- " print \"Grade is E\"\n",
- "else:\n",
- " print \"Grade is F\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter tensile strength : 800\n",
- "Enter rockwell hardness : 180\n",
- "Enter carbon content : 3\n",
- "Grade is C\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_/Chapter5.ipynb b/Computer_Programming_Theory_and_Practice_/Chapter5.ipynb
deleted file mode 100755
index 52adbd63..00000000
--- a/Computer_Programming_Theory_and_Practice_/Chapter5.ipynb
+++ /dev/null
@@ -1,1103 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:1c1423d8954dc10aa9bbb2818169dfeb793cb3bc9435852c4188cde598c54111"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 5: Loop Control Structures in C"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-79"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print natural numbers from 1 to n\n",
- "# Variable decalration\n",
- "\n",
- "n = 15\n",
- "\n",
- "print \"Enter value to n :\",n\n",
- "\n",
- "# Loop to print natural numbers\n",
- "for r in range(15):\n",
- " r = r + 1\n",
- " print r,\n",
- " \n",
- " \n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to n : 15\n",
- "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-80"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the value of y and print a table for values of x\n",
- "# Variable declaration\n",
- "import math\n",
- "x = 1.0\n",
- "print \"------------------------\"\n",
- "print \" x y \"\n",
- "print \"------------------------\"\n",
- "while x <= 3.2:\n",
- " y = 1.36 * ((1 + x + x * x * x) ** 0.5) + ((x) ** (1.0/4)) + math.exp(x)\n",
- " print \" %0.2f \" %x + \" %0.2f\" % y\n",
- " x = x + 0.2"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "------------------------\n",
- " x y \n",
- "------------------------\n",
- " 1.00 6.07\n",
- " 1.20 7.06\n",
- " 1.40 8.23\n",
- " 1.60 9.60\n",
- " 1.80 11.20\n",
- " 2.00 13.09\n",
- " 2.20 15.30\n",
- " 2.40 17.91\n",
- " 2.60 20.99\n",
- " 2.80 24.64\n",
- " 3.00 28.97\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-81"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find factorial of given number\n",
- "# Variable declaration\n",
- "\n",
- "k = 4\n",
- "kfact = 1\n",
- "\n",
- "print \"Enter an integer :\",k\n",
- "\n",
- "# Loop to generate numbers from 1 to n\n",
- "\n",
- "for i in range(1,k + 1):\n",
- " kfact = kfact*i\n",
- "\n",
- " \n",
- "print \"4 factorial is\",kfact "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter an integer : 4\n",
- "4 factorial is 24\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-83"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print sum of the following series\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "s = 0\n",
- "\n",
- "print \"Enter value to N :\",n\n",
- "# Calculation of sum\n",
- "i = 1\n",
- "j = 1\n",
- "\n",
- "for i in range(1,n+1):\n",
- " term = 0\n",
- " for j in range(i+1):\n",
- " term = term + j\n",
- " s = s + term\n",
- "\n",
- "\n",
- "print \"Sum of the series S =\",s "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to N : 4\n",
- "Sum of the series S = 20\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-84"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to compute the values of z based on x and y\n",
- "# Variable declaration\n",
- "\n",
- "x = -1.5\n",
- "y = 0\n",
- "\n",
- "# Loops to generate values of x and y to find z\n",
- "\n",
- "while x <= 1.5:\n",
- " while y <= 3.0:\n",
- " z = 3 * x * x + 2 * y * y * y - 25.5\n",
- " print \"Value of y(\",x,\n",
- " print \",\",y,\n",
- " print \") =\",z\n",
- " y = y + 1.0\n",
- " x = x + 0.5\n",
- " y = 0\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Value of y( -1.5 , 0 ) = -18.75\n",
- "Value of y( -1.5 , 1.0 ) = -16.75\n",
- "Value of y( -1.5 , 2.0 ) = -2.75\n",
- "Value of y( -1.5 , 3.0 ) = 35.25\n",
- "Value of y( -1.0 , 0 ) = -22.5\n",
- "Value of y( -1.0 , 1.0 ) = -20.5\n",
- "Value of y( -1.0 , 2.0 ) = -6.5\n",
- "Value of y( -1.0 , 3.0 ) = 31.5\n",
- "Value of y( -0.5 , 0 ) = -24.75\n",
- "Value of y( -0.5 , 1.0 ) = -22.75\n",
- "Value of y( -0.5 , 2.0 ) = -8.75\n",
- "Value of y( -0.5 , 3.0 ) = 29.25\n",
- "Value of y( 0.0 , 0 ) = -25.5\n",
- "Value of y( 0.0 , 1.0 ) = -23.5\n",
- "Value of y( 0.0 , 2.0 ) = -9.5\n",
- "Value of y( 0.0 , 3.0 ) = 28.5\n",
- "Value of y( 0.5 , 0 ) = -24.75\n",
- "Value of y( 0.5 , 1.0 ) = -22.75\n",
- "Value of y( 0.5 , 2.0 ) = -8.75\n",
- "Value of y( 0.5 , 3.0 ) = 29.25\n",
- "Value of y( 1.0 , 0 ) = -22.5\n",
- "Value of y( 1.0 , 1.0 ) = -20.5\n",
- "Value of y( 1.0 , 2.0 ) = -6.5\n",
- "Value of y( 1.0 , 3.0 ) = 31.5\n",
- "Value of y( 1.5 , 0 ) = -18.75\n",
- "Value of y( 1.5 , 1.0 ) = -16.75\n",
- "Value of y( 1.5 , 2.0 ) = -2.75\n",
- "Value of y( 1.5 , 3.0 ) = 35.25\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-89"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find sum of odd integers between 1 to n\n",
- "# Variable declararion\n",
- "\n",
- "n = 10\n",
- "\n",
- "print \"Enter value to N :\",n\n",
- "\n",
- "s = 0\n",
- "i = 1\n",
- "\n",
- "while (i <= n):\n",
- " s = s + i\n",
- " i = i + 2\n",
- "\n",
- "print \"Sum of odd integers =\",s"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to N : 10\n",
- "Sum of odd integers = 25\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-90"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to generate first 50 positive integers that are divisible by 7\n",
- "# Variable declaration\n",
- "\n",
- "n = 7\n",
- "print \"Integers divisible by 7\"\n",
- "\n",
- "#loop to print numbers divisible by 7\n",
- "for n in range(7,353,7):\n",
- " print n,\n",
- " \n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Integers divisible by 7\n",
- "7 14 21 28 35 42 49 56 63 70 77 84 91 98 105 112 119 126 133 140 147 154 161 168 175 182 189 196 203 210 217 224 231 238 245 252 259 266 273 280 287 294 301 308 315 322 329 336 343 350\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8 , Page number: CP-91"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print integers from 1 to n that are not divisible by 7\n",
- "# Variable declaration\n",
- "\n",
- "n = 20\n",
- "print \"Enter the end value N :\",n\n",
- "\n",
- "# Loop to print numbers that are not divisible by 7\n",
- "\n",
- "print \"Integers not divisible by 7\"\n",
- "for k in range(1,n + 1,1):\n",
- " r = k % 7\n",
- " if (r != 0):\n",
- " print k,"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the end value N : 20\n",
- "Integers not divisible by 7\n",
- "1 2 3 4 5 6 8 9 10 11 12 13 15 16 17 18 19 20\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-92 "
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print sum of digits of an integer\n",
- "# Variable declaration\n",
- "\n",
- "n = 2466\n",
- "\n",
- "print \"Enter a positive integer :\",n\n",
- "\n",
- "q = n\n",
- "s = 0\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " s = s + r\n",
- " q = q / 10\n",
- "\n",
- "\n",
- "print \"Sum of digits =\",s\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a positive integer : 2466\n",
- "Sum of digits = 18\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-93"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to check whether a given number is an armstrong number or not\n",
- "# Variable declaration\n",
- "\n",
- "n = 153\n",
- "q = n\n",
- "s = 0\n",
- "\n",
- "print \"Enter an integer number :\",n\n",
- "\n",
- "# To check armstrong or not\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " s = s + r * r * r\n",
- " q = q / 10\n",
- "\n",
- "if (n == s):\n",
- " print \"%d is an Armstrong number\" % n\n",
- "else:\n",
- " print \"%d is not an Armstrong number\" % n\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter an integer number : 153\n",
- "153 is an Armstrong number\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11 , Page number: CP-94"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to reverse a given integer\n",
- "# Variable declaration\n",
- "\n",
- "n = 18532\n",
- "q = n\n",
- "rn = 0\n",
- "\n",
- "print \"Enter an integer number :\",n\n",
- "# Reversing\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " rn = (rn * 10) + r\n",
- " q = q / 10\n",
- "\n",
- "\n",
- "print \"18532 is reversed as\",rn "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter an integer number : 18532\n",
- "18532 is reversed as 23581\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 12 , Page number: CP-95"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to accept an integer and print digits using words\n",
- "# Variable declaration\n",
- "\n",
- "n = 4352\n",
- "q = n\n",
- "rn = 0\n",
- "\n",
- "print \"Enter an integer number :\",n\n",
- "# converting to digits\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " rn = rn * 10 + r\n",
- " q = q / 10\n",
- "\n",
- "\n",
- "while (rn > 0):\n",
- " r = rn % 10\n",
- " if (r == 1):\n",
- " s = \"One\"\n",
- " print s,\n",
- " elif (r == 2):\n",
- " s = \"Two\"\n",
- " print s,\n",
- " elif (r == 3):\n",
- " s = \"Three\"\n",
- " print s,\n",
- " elif (r == 4):\n",
- " s = \"Four\"\n",
- " print s,\n",
- " elif (r == 5):\n",
- " s = \"Five\"\n",
- " print s,\n",
- " elif (r == 6):\n",
- " s = \"Six\"\n",
- " print s,\n",
- " elif (r == 7):\n",
- " s = \"Seven\"\n",
- " print s,\n",
- " elif (r == 8):\n",
- " s = \"Eight\"\n",
- " print s,\n",
- " elif (r == 9):\n",
- " s = \"Nine\"\n",
- " print s,\n",
- " elif (r == 0):\n",
- " s = \"Zero\"\n",
- " print s,\n",
- " rn = rn / 10\n",
- "\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter an integer number : 4352\n",
- "Four Three Five Two\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 13 , Page number: CP-97"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find whether a number is prime or not\n",
- "# Variable declaration\n",
- "\n",
- "n = 17\n",
- "\n",
- "print \"Enter a positive integer :\",n\n",
- "\n",
- "# prime numbers are greater than 1\n",
- "if n > 1:\n",
- " # check for factors\n",
- " for i in range(2,n):\n",
- " if (n % i) == 0:\n",
- " print(n,\"is not a prime number\")\n",
- " print(i,\"times\",n//i,\"is\",num)\n",
- " break\n",
- " else:\n",
- " print \"%d is a prime number\" % n\n",
- "\n",
- "else:\n",
- " print \"%d is not a prime number\" % n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a positive integer : 17\n",
- "17 is a prime number\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 14 , Page number: CP-98"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to generate Fibonacci series\n",
- "# Variable declaration\n",
- "\n",
- "n = 25\n",
- "n1 = 0\n",
- "n2 = 1\n",
- "\n",
- "print \"Enter the final term of the series :\",n\n",
- "\n",
- "print n1,n2,\n",
- "\n",
- "\n",
- "newterm = n1 + n2\n",
- "\n",
- "# Loop to print fibonacci series\n",
- "while (newterm <= n):\n",
- " print newterm,\n",
- " n1 = n2\n",
- " n2 = newterm\n",
- " newterm = n1 + n2\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the final term of the series : 25\n",
- "0 1 1 2 3 5 8 13 21\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 15 , Page number: CP-99"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to solve the sine series\n",
- "# Variable declaration\n",
- "\n",
- "x = 0.52\n",
- "n = 10\n",
- "s = 0\n",
- "term = x\n",
- "i = 1\n",
- "\n",
- "print \"Enter x in radians :\",x\n",
- "print \"Enter end term power (n):\",n\n",
- "\n",
- "while (i <= n):\n",
- " s = s + term\n",
- " term = (term * x * x *(-1)) / ((i + 1) * (i + 2))\n",
- " i = i + 2\n",
- "\n",
- "print \"Sum of the series = %0.6f\" % s\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter x in radians : 0.52\n",
- "Enter end term power (n): 10\n",
- "Sum of the series = 0.496880\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 16 , Page number: CP-101"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to solve the cosine series\n",
- "# Variable declaration\n",
- "\n",
- "x = 0.52\n",
- "s = 0\n",
- "term = 1\n",
- "i = 0\n",
- "n = 10\n",
- "print \"Enter x in radians :\",x\n",
- "\n",
- "# Calculation of cosine series\n",
- "\n",
- "while (i <= n):\n",
- " s = s + term\n",
- " term = (term * x * x * (-1)) / ((i + 1) * (i + 2))\n",
- " i = i + 2\n",
- "\n",
- "\n",
- "print \"Sum of the series = %0.6f\" % s "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter x in radians : 0.52\n",
- "Sum of the series = 0.867819\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 17 , Page number: CP-102"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "\n",
- "# Program to compute the value of pie\n",
- "# Variable declaration\n",
- "\n",
- "s = 0.0\n",
- "dr = 1\n",
- "sign = 1\n",
- "term = (1.0/dr) * sign\n",
- "while (math.fabs(term) >= 1.0e-4):\n",
- " s = s + term\n",
- " dr = dr + 2\n",
- " sign = sign * -1\n",
- " term = (1.0 / dr) * sign\n",
- "\n",
- "pie = s * 4\n",
- "\n",
- "print \"Value of pie is %.6f\"%pie"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Value of pie is 3.141393\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 18 , Page number: CP-104"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to evaluate the series\n",
- "# Variable declaration\n",
- "\n",
- "n = 15\n",
- "s = 0.00\n",
- "\n",
- "print \"Enter value to N :\",n\n",
- "\n",
- "# Evaluation of series\n",
- "\n",
- "for i in range(1,n + 1,1):\n",
- " s = float(s) + float(1.0 / i)\n",
- " \n",
- "\n",
- "print \"Sum of series = %0.4f\" % s \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to N : 15\n",
- "Sum of series = 3.3182\n"
- ]
- }
- ],
- "prompt_number": 18
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 21 , Page number: CP-108"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to print multiplication table\n",
- "# Variable declaration\n",
- "\n",
- "i = 1\n",
- "j = 1\n",
- "\n",
- "# nested loop to print multiplication tables\n",
- "\n",
- "for i in range(1,6):\n",
- " print \"Multiplication table for\",i\n",
- " for j in range(1,11):\n",
- " print \" \",j,\"x\" , i ,\" =\" , j*i\n",
- " print \"Press any key to continue. . .\" "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Multiplication table for 1\n",
- " 1 x 1 = 1\n",
- " 2 x 1 = 2\n",
- " 3 x 1 = 3\n",
- " 4 x 1 = 4\n",
- " 5 x 1 = 5\n",
- " 6 x 1 = 6\n",
- " 7 x 1 = 7\n",
- " 8 x 1 = 8\n",
- " 9 x 1 = 9\n",
- " 10 x 1 = 10\n",
- "Press any key to continue. . .\n",
- "Multiplication table for 2\n",
- " 1 x 2 = 2\n",
- " 2 x 2 = 4\n",
- " 3 x 2 = 6\n",
- " 4 x 2 = 8\n",
- " 5 x 2 = 10\n",
- " 6 x 2 = 12\n",
- " 7 x 2 = 14\n",
- " 8 x 2 = 16\n",
- " 9 x 2 = 18\n",
- " 10 x 2 = 20\n",
- "Press any key to continue. . .\n",
- "Multiplication table for 3\n",
- " 1 x 3 = 3\n",
- " 2 x 3 = 6\n",
- " 3 x 3 = 9\n",
- " 4 x 3 = 12\n",
- " 5 x 3 = 15\n",
- " 6 x 3 = 18\n",
- " 7 x 3 = 21\n",
- " 8 x 3 = 24\n",
- " 9 x 3 = 27\n",
- " 10 x 3 = 30\n",
- "Press any key to continue. . .\n",
- "Multiplication table for 4\n",
- " 1 x 4 = 4\n",
- " 2 x 4 = 8\n",
- " 3 x 4 = 12\n",
- " 4 x 4 = 16\n",
- " 5 x 4 = 20\n",
- " 6 x 4 = 24\n",
- " 7 x 4 = 28\n",
- " 8 x 4 = 32\n",
- " 9 x 4 = 36\n",
- " 10 x 4 = 40\n",
- "Press any key to continue. . .\n",
- "Multiplication table for 5\n",
- " 1 x 5 = 5\n",
- " 2 x 5 = 10\n",
- " 3 x 5 = 15\n",
- " 4 x 5 = 20\n",
- " 5 x 5 = 25\n",
- " 6 x 5 = 30\n",
- " 7 x 5 = 35\n",
- " 8 x 5 = 40\n",
- " 9 x 5 = 45\n",
- " 10 x 5 = 50\n",
- "Press any key to continue. . .\n"
- ]
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 22 , Page number: CP-109"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "\n",
- "# Program to convert a binary number to a decimal number\n",
- "# Variable declaration\n",
- "\n",
- "q = 1101\n",
- "s = 0\n",
- "k = 0\n",
- "\n",
- "print \"Enter the binary number :\",q\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " s = s + r * pow(2,k)\n",
- " q = q / 10\n",
- " k = k + 1\n",
- "\n",
- "\n",
- "print \"The decimal number is :\",s\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the binary number : 1101\n",
- "The decimal number is : 13\n"
- ]
- }
- ],
- "prompt_number": 20
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 23 , Page number: CP-110"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to convert a decimal number to a binary number\n",
- "# Variable declaration\n",
- "\n",
- "n = 28\n",
- "q = n\n",
- "rbi = 0\n",
- "flag = 0\n",
- "k = 0\n",
- "\n",
- "print \"Enter the decimal number :\",n\n",
- "\n",
- "\n",
- "while (q > 0):\n",
- " r = q % 2\n",
- " if (r == 0) and (flag == 0):\n",
- " k = k + 1\n",
- " else:\n",
- " flag = 1\n",
- " rbi = rbi * 10 + r\n",
- " q = q / 2\n",
- " \n",
- "q = rbi\n",
- "bi = 0\n",
- "while (q > 0):\n",
- " r = q % 10\n",
- " bi = bi * 10 + r\n",
- " q = q / 10\n",
- " i = 1\n",
- " if (q == 0):\n",
- " while (i <= k):\n",
- " bi = bi * 10\n",
- " i = i + 1\n",
- "\n",
- "\n",
- "print \"The binary number is \",bi "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the decimal number : 28\n",
- "The binary number is 11100\n"
- ]
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_/Chapter6.ipynb b/Computer_Programming_Theory_and_Practice_/Chapter6.ipynb
deleted file mode 100755
index 14969fc1..00000000
--- a/Computer_Programming_Theory_and_Practice_/Chapter6.ipynb
+++ /dev/null
@@ -1,794 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:aced1a8512bbd1c950b44a0ce98d7bb529f62e617c89b1c73eec08ce49b27311"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 6: Arrays and Subscribed Variables"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-122"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the sum of n numbers using array\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "x = [36,45,52,44,62]\n",
- "\n",
- "print \"How many integers ?\",n\n",
- "print \"Enter the 1th value :\",x[0]\n",
- "print \"Enter the 2th value :\",x[1]\n",
- "print \"Enter the 3th value :\",x[2]\n",
- "print \"Enter the 4th value :\",x[3]\n",
- "print \"Enter the 5th value :\",x[4]\n",
- "\n",
- "summ = 0 \n",
- "\n",
- "# Calculation of sum of numbers\n",
- "for i in x:\n",
- " summ = summ + i\n",
- " \n",
- "\n",
- "print \"Sum of all integers =\",summ\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many integers ? 5\n",
- "Enter the 1th value : 36\n",
- "Enter the 2th value : 45\n",
- "Enter the 3th value : 52\n",
- "Enter the 4th value : 44\n",
- "Enter the 5th value : 62\n",
- "Sum of all integers = 239\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-123"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the biggest of n numbers\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "x = [25,-228,0,185,36]\n",
- "\n",
- "print \"How many numbers ?\",n\n",
- "print \"Enter all those numbers\"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "\n",
- "big = x[0]\n",
- "\n",
- "\n",
- "for i in x:\n",
- " if (i > big):\n",
- " big = i\n",
- "\n",
- "\n",
- "print \"%d is the biggest number\" % big "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers ? 5\n",
- "Enter all those numbers\n",
- "25 -228 0 185 36\n",
- "185 is the biggest number\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: Cp-124"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the arithmetic mean, variance and standard deviation\n",
- "# Variable declaration\n",
- "\n",
- "n = 6\n",
- "x = [3.1,3.8,3.6,4.0,3.4,3.8]\n",
- "summ = 0\n",
- "vsum = 0\n",
- "\n",
- "print \"How many values ?\",n\n",
- "print \"Enter all values in the list \"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "\n",
- "# Loop to find sum of all values\n",
- "\n",
- "for i in x:\n",
- " summ = summ + i\n",
- "\n",
- "xbar = summ / n\n",
- "\n",
- "# Loop to find the numerator vsum to find variance\n",
- "\n",
- "for i in x:\n",
- " vsum = vsum + (i - xbar) * (i - xbar)\n",
- "\n",
- "\n",
- "sigmax = vsum / n\n",
- "sd = sigmax ** 0.5\n",
- "\n",
- "print \"Arithmetic mean = %0.3f\" % xbar\n",
- "print \"Variance = %0.3f \" % sigmax\n",
- "print \"Standard deviation = %0.3f\" % sd"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many values ? 6\n",
- "Enter all values in the list \n",
- "3.1 3.8 3.6 4.0 3.4 3.8\n",
- "Arithmetic mean = 3.617\n",
- "Variance = 0.088 \n",
- "Standard deviation = 0.297\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-126"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to calculate mean of marks and print list of marks greater than mean\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "x = [58,63,68,54,48]\n",
- "summ = 0 # Used summ instead of sum since it was a inbuilt function\n",
- "i = 0\n",
- "\n",
- "print \"How many students ?\",n\n",
- "print \"Enter all the marks \"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "\n",
- "for i in x:\n",
- " summ = summ + i\n",
- "\n",
- "mean = float(summ) / n\n",
- "\n",
- "print \"Mean = %0.2f\" % mean\n",
- "print \"Marks greater than mean :\",\n",
- "\n",
- "i = 0\n",
- "for i in x:\n",
- " if (i > mean):\n",
- " print i,\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many students ? 5\n",
- "Enter all the marks \n",
- "58 63 68 54 48\n",
- "Mean = 58.20\n",
- "Marks greater than mean : 63 68\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-127"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find sum of all positive and negative numbers and to find out which is larger in magnitude\n",
- "# Variable declaration\n",
- "import math\n",
- "\n",
- "n = 6\n",
- "x = [8,-12,-16,12,-9,5]\n",
- "psum = 0\n",
- "nsum = 0\n",
- "\n",
- "print \"How many values ?\",n\n",
- "print \"Enter all values in the list\"\n",
- "for i in x:\n",
- " print i,\n",
- "print \n",
- "\n",
- "# Loop to calculate sum of positive and negative values\n",
- "\n",
- "for i in x:\n",
- " if i > 0:\n",
- " psum = psum + i\n",
- " else:\n",
- " nsum = nsum + i\n",
- "\n",
- "print \"Sum of positive values = %0.2f\" % psum\n",
- "print \"Sum of negative values = %0.2f\" % nsum\n",
- "\n",
- "if (psum > abs(nsum)):\n",
- " print \"Positive sum is greater in magnitude\"\n",
- "else:\n",
- " print \"Negative sum is greater in magnitude\"\n",
- "\n",
- "diff = abs(psum) - abs(nsum)\n",
- "print \"Difference in magnitude = %0.2f\" % abs(diff)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many values ? 6\n",
- "Enter all values in the list\n",
- "8 -12 -16 12 -9 5\n",
- "Sum of positive values = 25.00\n",
- "Sum of negative values = -37.00\n",
- "Negative sum is greater in magnitude\n",
- "Difference in magnitude = 12.00\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-129"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to sort n numbers in ascending order\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "x = [32,-10,20,5]\n",
- "i = 0\n",
- "\n",
- "\n",
- "print \"How many numbers ?\",n\n",
- "print \"Enter the list of 4 numbers\"\n",
- "for a in x:\n",
- " print a,\n",
- "print\n",
- "\n",
- "# Loop to arrange the numbers in ascending order\n",
- "\n",
- "while i < n-1:\n",
- " j = i + 1\n",
- " while j < n:\n",
- " if x[i] > x[j]:\n",
- " temp = x[i]\n",
- " x[i] = x[j]\n",
- " x[j] = temp\n",
- " j = j + 1\n",
- " i = i + 1\n",
- "\n",
- "print \"Numbers in ascending order \"\n",
- "\n",
- "for a in x:\n",
- " print a,\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers ? 4\n",
- "Enter the list of 4 numbers\n",
- "32 -10 20 5\n",
- "Numbers in ascending order \n",
- "-10 5 20 32\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-131"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to search the key value and to print it if the search is successful\n",
- "# Variable declaration\n",
- "\n",
- "n = 6\n",
- "x = [6,-2,8,3,13,10]\n",
- "s = 3\n",
- "\n",
- "print \"How many values in the list ?\",n\n",
- "print \"Enter all values in the list\"\n",
- "for i in x:\n",
- " print i,\n",
- "print \n",
- "print \"Enter the key value to be searched :\",s\n",
- "\n",
- "# loop to search key value in the list\n",
- "\n",
- "for i in range(n):\n",
- " if s == x[i]:\n",
- " print s,\" is available in\",i+1,\"th location\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many values in the list ? 6\n",
- "Enter all values in the list\n",
- "6 -2 8 3 13 10\n",
- "Enter the key value to be searched : 3\n",
- "3 is available in 4 th location\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8 , Page number: CP-133"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to sort n numbers using bubble sort and find number of exchanges and passes\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "x = [6,-2,8,3]\n",
- "exchng = 0\n",
- "\n",
- "print \"How many numbers?\",n\n",
- "print \"Enter all the numbers in the list\"\n",
- "for i in x:\n",
- " print i,\n",
- "\n",
- "print\n",
- "\n",
- "for i in range(0,n-1):\n",
- " for j in range(0,n-i-1):\n",
- " if x[j] > x[j+1]:\n",
- " temp = x[j]\n",
- " x[j] = x[j+1]\n",
- " x[j+1] = temp\n",
- " exchng = exchng + 1\n",
- " \n",
- "\n",
- "print \"The sorted list is\"\n",
- "for i in x:\n",
- " print i,\n",
- "\n",
- "print \n",
- "\n",
- "print \"Sorted in\",n-1,\"passes and\",exchng,\"exchanges\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers? 4\n",
- "Enter all the numbers in the list\n",
- "6 -2 8 3\n",
- "The sorted list is\n",
- "-2 3 6 8\n",
- "Sorted in 3 passes and 3 exchanges\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-135"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to add two matrices\n",
- "# Variable declaration\n",
- "\n",
- "a = [[2,-2],\n",
- " [0,4]]\n",
- "b = [[6,2],\n",
- " [4,-5]]\n",
- "\n",
- "c = [[0,0],\n",
- " [0,0]]\n",
- "\n",
- "m = 2\n",
- "n = 2\n",
- "\n",
- "print \"How many rows and columns ?\",m,n\n",
- "print \"Enter A matrix\"\n",
- "for i in a:\n",
- " print i\n",
- "\n",
- "print \"Enter B matrix\"\n",
- "for j in b:\n",
- " print j\n",
- "\n",
- "# Loop to add two matrices\n",
- "\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " c[i][j] = a[i][j] + b[i][j]\n",
- "\n",
- "\n",
- "print \"Resultant matrix is\"\n",
- "for ci in c:\n",
- " print ci"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many rows and columns ? 2 2\n",
- "Enter A matrix\n",
- "[2, -2]\n",
- "[0, 4]\n",
- "Enter B matrix\n",
- "[6, 2]\n",
- "[4, -5]\n",
- "Resultant matrix is\n",
- "[8, 0]\n",
- "[4, -1]\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-136"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to multiply two matrices\n",
- "# Variable declaration\n",
- "\n",
- "m = 2\n",
- "n = 2\n",
- "l = 2\n",
- "a = [[2,-2],\n",
- " [0,4]]\n",
- "b = [[6,2],\n",
- " [4,-5]]\n",
- "c = [[0,0],\n",
- " [0,0]]\n",
- "\n",
- "print \"Enter order of A matrix :\",m,n\n",
- "print \"Enter A matrix\"\n",
- "for i in a:\n",
- " print i\n",
- "print \"Enter order of B matrix :\",m,n\n",
- "print \"Enter B matrix\"\n",
- "for j in b:\n",
- " print j\n",
- "\n",
- "# Loop to multiply two matrices\n",
- "# iterate through rowa of A\n",
- "for i in range(m):\n",
- " # iterate through columns of B\n",
- " for j in range(l):\n",
- " c[i][j] = 0\n",
- " # iterate through rows of B\n",
- " for k in range(n):\n",
- " c[i][j] = c[i][j] + a[i][k] * b[k][j]\n",
- "\n",
- "\n",
- "print \"Resultant matrix is\"\n",
- "\n",
- "for i in c:\n",
- " print i\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter order of A matrix : 2 2\n",
- "Enter A matrix\n",
- "[2, -2]\n",
- "[0, 4]\n",
- "Enter order of B matrix : 2 2\n",
- "Enter B matrix\n",
- "[6, 2]\n",
- "[4, -5]\n",
- "Resultant matrix is\n",
- "[4, 14]\n",
- "[16, -20]\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11 , Page number: CP-138"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find and print the transpose of the matrix\n",
- "# Variable declaration\n",
- "\n",
- "m = 2\n",
- "n = 3\n",
- "a = [[-3,6,0],\n",
- " [3,2,8]]\n",
- "at = [[0,0],\n",
- " [0,0],\n",
- " [0,0]]\n",
- "\n",
- "print \"Enter order of the matrix :\",m,n\n",
- "print \"Enter the matrix values\"\n",
- "for i in a :\n",
- " print i\n",
- "\n",
- "# Loop to calculate transpose\n",
- "\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " at[j][i] = a[i][j]\n",
- "\n",
- "print \"The transposed matrix is \"\n",
- "for i in at:\n",
- " print i\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter order of the matrix : 2 3\n",
- "Enter the matrix values\n",
- "[-3, 6, 0]\n",
- "[3, 2, 8]\n",
- "The transposed matrix is \n",
- "[-3, 3]\n",
- "[6, 2]\n",
- "[0, 8]\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 12 ,Page number: CP-139"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to check whether a given matrix is symmetric or not\n",
- "# Variable declaration\n",
- "\n",
- "m = 3\n",
- "a = [[5,3,8],\n",
- " [3,1,-7],\n",
- " [8,-7,4]]\n",
- "\n",
- "print \"Enter order of the square matrix :\",m\n",
- "for i in a:\n",
- " print i\n",
- "\n",
- "# Loop to check whether symmetric or not\n",
- "\n",
- "for i in range(m):\n",
- " flag = 0\n",
- " for j in range(m):\n",
- " flag = 0\n",
- " if a[i][j] == a[j][i]:\n",
- " continue\n",
- " else:\n",
- " flag = 1\n",
- "\n",
- "if flag == 0:\n",
- " print \"The given matrix is a symmetric matrix\"\n",
- "else:\n",
- " print \"The given matrix is not a symmetric matrix\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter order of the square matrix : 3\n",
- "[5, 3, 8]\n",
- "[3, 1, -7]\n",
- "[8, -7, 4]\n",
- "The given matrix is a symmetric matrix\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 13 , Page number: CP-141"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the trace of a given square matrix\n",
- "# Variable dclaration\n",
- "\n",
- "m = 3\n",
- "a = [[3,2,-1],\n",
- " [4,1,8],\n",
- " [6,4,2]]\n",
- "summ = 0\n",
- "\n",
- "print \"Enter order of the square matrix :\",m\n",
- "print \"Enter the matrix\"\n",
- "for i in a:\n",
- " print i\n",
- "\n",
- "# Loop to find trace\n",
- "for i in range(m):\n",
- " summ = summ + a[i][i]\n",
- "\n",
- "print \"Trace of the matrix =\",summ "
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_/Chapter7.ipynb b/Computer_Programming_Theory_and_Practice_/Chapter7.ipynb
deleted file mode 100755
index 0d79c17f..00000000
--- a/Computer_Programming_Theory_and_Practice_/Chapter7.ipynb
+++ /dev/null
@@ -1,557 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:37ae6cc76fe6f4a8cc8dba62582a6a103f99da5c7579d1a782cb95241f542fd8"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-148"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to count the occurence of a particular in a string\n",
- "# Variable declaration\n",
- "\n",
- "st = \"MISSISSIPPI\"\n",
- "ch = \"S\"\n",
- "count = 0\n",
- "\n",
- "print \"Enter the string :\",st\n",
- "print \"Which character to be counted ?\",ch\n",
- "\n",
- "# Loop to check occurrence of aa character\n",
- "\n",
- "l = len(st)\n",
- "\n",
- "for i in st:\n",
- " if i == ch:\n",
- " count = count + 1\n",
- "\n",
- "print \"The character \" + ch + \" occurs %d times\" % count "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the string : MISSISSIPPI\n",
- "Which character to be counted ? S\n",
- "The character S occurs 4 times\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-149"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to count the number of vowels in a sentence\n",
- "# Variable declaration\n",
- "\n",
- "st = \"This is a book\"\n",
- "count = 0\n",
- "\n",
- "print \"Enter the sentence :\"\n",
- "print st\n",
- "\n",
- "# Loop to count the vowels in the string\n",
- "\n",
- "for i in st:\n",
- " if i == \"A\":\n",
- " count = count + 1\n",
- " elif i == \"E\":\n",
- " count = count + 1\n",
- " elif i == \"I\":\n",
- " count = count + 1\n",
- " elif i == \"O\":\n",
- " count = count + 1\n",
- " elif i == \"U\":\n",
- " count = count + 1\n",
- " elif i == \"a\":\n",
- " count = count + 1\n",
- " elif i == \"e\":\n",
- " count = count + 1\n",
- " elif i == \"i\":\n",
- " count = count + 1\n",
- " elif i == \"o\":\n",
- " count = count + 1\n",
- " elif i == \"u\":\n",
- " count = count + 1\n",
- "\n",
- "print \"%d vowels are present in the sentence\" % count\n",
- " \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the sentence :\n",
- "This is a book\n",
- "5 vowels are present in the sentence\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-150"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to test whether a given string is a palindrome or not\n",
- "# Variable declaration\n",
- "\n",
- "st = \"HYDERABAD\"\n",
- "rst = \"\"\n",
- "i = 0\n",
- "j = len(st) - 1\n",
- "\n",
- "print \"Enter the string :\",st\n",
- "\n",
- "# Palindrome or not \n",
- "\n",
- "rst = reversed(st)\n",
- "\n",
- "if list(st) == list(rst):\n",
- " print \"%s is a palindrome string \" % st\n",
- "else:\n",
- " print \"%s is not a palindrome string \" % st"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the string : HYDERABAD\n",
- "HYDERABAD is not a palindrome string \n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-152"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to conctenate two strings\n",
- "# Variable declaration\n",
- "\n",
- "st1 = \"NEW \"\n",
- "st2 = \"DELHI\"\n",
- "\n",
- "# input of two strings to be concatenated\n",
- "\n",
- "print \"Enter first string :\",st1\n",
- "print \"Enter second string :\",st2\n",
- "\n",
- "# concatenation of two strings\n",
- "st = st1 + st2\n",
- "\n",
- "print \"Resultant string is \",st "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter first string : NEW \n",
- "Enter second string : DELHI\n",
- "Resultant string is NEW DELHI\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-154"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to compare two strings\n",
- "# Variable declaration\n",
- "\n",
- "st1 = \"ALPHA\"\n",
- "st2 = \"BETA\"\n",
- "\n",
- "print \"Enter string 1:\",st1\n",
- "print \"Enter string 2:\",st2\n",
- "\n",
- "# compare strings\n",
- "\n",
- "if (cmp(st1,st2)>0):\n",
- " print \"%s \" + st1 + \"is alphabetically greater string\"\n",
- "else:\n",
- " print st2 + \" is alphabetically greater string\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter string 1: ALPHA\n",
- "Enter string 2: BETA\n",
- "BETA is alphabetically greater string\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-155"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to sort an array of names in alphabetical order\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "names = [\"DEEPAK\",\"SHERIN\",\"SONIKA\",\"ARUN\"]\n",
- "\n",
- "print \"How many names ?\",n\n",
- "print \"Enter the 4 names one by one\"\n",
- "for i in names:\n",
- " print i\n",
- "\n",
- "# Loop to arrange names in alphabetical order\n",
- "\n",
- "for i in range(0,n-1):\n",
- " for j in range(i+1,n):\n",
- " if cmp(names[i],names[j])>0:\n",
- " \n",
- " temp = names[i]\n",
- " names[i] = names[j]\n",
- " names[j] = temp\n",
- "\n",
- "print \"Names in alphabetical order\"\n",
- "for i in names:\n",
- " print i"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many names ? 4\n",
- "Enter the 4 names one by one\n",
- "DEEPAK\n",
- "SHERIN\n",
- "SONIKA\n",
- "ARUN\n",
- "Names in alphabetical order\n",
- "ARUN\n",
- "DEEPAK\n",
- "SHERIN\n",
- "SONIKA\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-157"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to convert a line from lower case to upper case\n",
- "# Variable declaretion\n",
- "\n",
- "import sys\n",
- "\n",
- "st = ['l','o','g','i','c','a','l',' ','t','h','i','n','k','i','n','g',' ','i','s',' ','a',' ','m','u','s','t',' ','t','o',' ','l','e','a','r','n',' ','p','r','o','g','r','a','m','m','i','n','g']\n",
- "\n",
- "print \"Enter a sentence :\"\n",
- "for i in st:\n",
- " print i,\n",
- "print \n",
- "print \"The converted upper case string is\"\n",
- "# loop to convert lower case alphabet to upper case text\n",
- "for i in range(len(st)):\n",
- " if st[i] >= 'a' and st[i] <= 'z':\n",
- " st[i] = chr(ord(st[i])-32)\n",
- "\n",
- "\n",
- " sys.stdout.write(st[i])"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a sentence :\n",
- "l o g i c a l t h i n k i n g i s a m u s t t o l e a r n p r o g r a m m i n g\n",
- "The converted upper case string is\n",
- "LOGICAL THINKING IS A MUST TO LEARN PROGRAMMING"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-160"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to read a text and to omit al occurrences of a particular word\n",
- "# Variable declartion\n",
- "\n",
- "st = \"TO ACCESS THE NAME OF THE CITY IN THE LIST\"\n",
- "i = 0\n",
- "omit = \"THE\"\n",
- "l = len(st)\n",
- "j = 0\n",
- "word = []\n",
- "newst = \"\"\n",
- "onesps = \"\"\n",
- "print \"Enter a sentence :\"\n",
- "print st\n",
- "print \"Enter word to omit :\",omit\n",
- "\n",
- "# loop to omit the given word\n",
- "\n",
- "for i in range(l):\n",
- " ch = i\n",
- " if ch == ' ':\n",
- " for j in word:\n",
- " j = \" \" \n",
- " if j == omit:\n",
- " newst = j\n",
- " newst = onesps\n",
- " j = \" \"\n",
- " j = 0\n",
- " else:\n",
- " j = ch\n",
- " j = j + 1\n",
- " i = i + 1\n",
- "\n",
- "print \"After omiting the word \" + omit\n",
- "print newst\n",
- "print \"Press any key to continue\"\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a sentence :\n",
- "TO ACCESS THE NAME OF THE CITY IN THE LIST\n",
- "Enter word to omit : THE\n",
- "After omiting the word THE\n",
- "\n",
- "Press any key to continue\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-161"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to calculate the amount to be paid for the telegram\n",
- "# Variable declaration\n",
- "\n",
- "count = 0\n",
- "st = \"Congratulations on your success in Examinations.\"\n",
- "l = len(st)\n",
- "\n",
- "print \"Type the sentence for Telegram\"\n",
- "print st\n",
- "\n",
- "# loop to count number of words\n",
- "\n",
- "for i in range(l):\n",
- " if st[i] == '?':\n",
- " count = count + 1\n",
- "\n",
- "if count <= 10:\n",
- " amt = 5\n",
- "else:\n",
- " amt = 5 + (count - 10) * 1.25\n",
- "\n",
- "print \"Amount to be paid for telegram = Rs.%0.2f\" % amt "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Type the sentence for Telegram\n",
- "Congratulations on your success in Examinations.\n",
- "Amount to be paid for telegram = Rs.5.00\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11 , Page number: CP-163"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to count number of lines,words and characters\n",
- "# Variable declaration\n",
- "\n",
- "txt = \"What is a string? How do you initialize it? Explain with example.$\"\n",
- "st = \"\"\n",
- "i = 0\n",
- "lns = 0\n",
- "wds = 0\n",
- "chs = 0\n",
- "\n",
- "print \"Enter the text, type $ at end.\"\n",
- "print txt\n",
- "\n",
- "# loop to count lines,words and characters in text\n",
- "\n",
- "while txt[i] != '$':\n",
- " # switch case statements\n",
- " if txt[i] == ' ':\n",
- " wds = wds + 1\n",
- " chs = chs + 1\n",
- " elif txt[i] == '.':\n",
- " wds = wds + 1\n",
- " lns = lns + 1\n",
- " chs = chs + 1\n",
- " elif txt[i] == '?':\n",
- " lns = lns + 1\n",
- " else: # default\n",
- " chs = chs + 1\n",
- "\n",
- " i = i + 1\n",
- "\n",
- "print \"Number of char (incl. blanks) =\",chs\n",
- "print \"Number of words =\",wds\n",
- "print \"Number of lines =\",lns\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the text, type $ at end.\n",
- "What is a string? How do you initialize it? Explain with example.$\n",
- "Number of char (incl. blanks) = 63\n",
- "Number of words = 12\n",
- "Number of lines = 3\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_/Chapter8.ipynb b/Computer_Programming_Theory_and_Practice_/Chapter8.ipynb
deleted file mode 100755
index 49edb490..00000000
--- a/Computer_Programming_Theory_and_Practice_/Chapter8.ipynb
+++ /dev/null
@@ -1,1027 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:0c7b2e51d9ff140f666ba709dd09beff8baf4fe046109218b6f3ac69ed4bb2fe"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-173"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to write a function to find factorial and use it to find nCr\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "r = 3\n",
- "\n",
- "print \"Enter value to n and r :\",n,r\n",
- "\n",
- "# function subprogram to find factorial\n",
- "\n",
- "def fact(k):\n",
- " p = 1\n",
- " for i in range(1,k+1):\n",
- " p = p * i\n",
- " return p\n",
- "\n",
- "\n",
- "ncr = fact(n) / (fact(r) * fact(n-r))\n",
- "\n",
- "\n",
- "print \"Value of nCr =\",ncr"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to n and r : 5 3\n",
- "Value of nCr = 10\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-174"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the biggest of given three values using function and use it to find total marks of the student\n",
- "# Variable declaration\n",
- "\n",
- "t1 = 62\n",
- "t2 = 70\n",
- "t3 = 58\n",
- "a1 = 17\n",
- "a2 = 21\n",
- "a3 = 23\n",
- "\n",
- "print \"Enter three test scores :\",t1,t2,t3\n",
- "print \"Enter three assignment scores :\",a1,a2,a3\n",
- "\n",
- "# function to find biggest of three values\n",
- "\n",
- "def big(a,b,c):\n",
- " if a > b:\n",
- " if a > c:\n",
- " return a\n",
- " else:\n",
- " return c\n",
- " elif b > c:\n",
- " return b\n",
- " else:\n",
- " return c\n",
- "\n",
- "total = big(t1,t2,t3) + big(a1,a2,a3)\n",
- "\n",
- "print \"Total marks =\",total"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three test scores : 62 70 58\n",
- "Enter three assignment scores : 17 21 23\n",
- "Total marks = 93\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-176"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to create a function to compute the cos(x) series upto 15 terms\n",
- "# Variable declaration\n",
- "\n",
- "x = 0\n",
- "\n",
- "print \"----------------------------------\"\n",
- "print \" x in degrees cos(x) \"\n",
- "print \"----------------------------------\"\n",
- "\n",
- "# function for computing cosine function\n",
- "\n",
- "def cosine(x):\n",
- " s = 0\n",
- " i = 0\n",
- " term = 1\n",
- " x = x * (3.14) / 180\n",
- " k = 1\n",
- " # loop to find summation of 15 terms\n",
- " while k <= 15:\n",
- " s = s + term\n",
- " term = term * x * x * (-1) / ((i + 1) * (i + 2))\n",
- " i = i + 2\n",
- " k = k + 1\n",
- " return s\n",
- "\n",
- "\n",
- "# calling function\n",
- "\n",
- "while x <= 180:\n",
- " print \" %d \" % x,\" %0.2f \"%cosine(x)\n",
- " x = x + 30\n",
- "\n",
- "print \"-----------------------------------\" "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "----------------------------------\n",
- " x in degrees cos(x) \n",
- "----------------------------------\n",
- " 0 1.00 \n",
- " 30 0.87 \n",
- " 60 0.50 \n",
- " 90 0.00 \n",
- " 120 -0.50 \n",
- " 150 -0.87 \n",
- " 180 -1.00 \n",
- "-----------------------------------\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-177"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find GCD of two integers\n",
- "# Variable declaration\n",
- "\n",
- "a = 45\n",
- "b = 27\n",
- "c = 81\n",
- "\n",
- "print \"Enter three integers :\",a,b,c\n",
- "\n",
- "def gcd(x,y):\n",
- " if x >= y:\n",
- " nr = x\n",
- " dr = y\n",
- " else:\n",
- " nr = y\n",
- " dr = x\n",
- " r = nr % dr\n",
- " while r != 0:\n",
- " nr = dr\n",
- " dr = r\n",
- " r = nr % dr\n",
- "\n",
- " return dr\n",
- "\n",
- "d1 = gcd(a,b)\n",
- "d2 = gcd(a,c)\n",
- "d3 = gcd(b,c)\n",
- "\n",
- "if d1 == d2:\n",
- " if d1 == d3:\n",
- " print \"Greatest common divisor is\",d1\n",
- " else:\n",
- " print \"Greatest common divisor is \",gcd(d1,d3)\n",
- "else:\n",
- " print \"Greatest common divisr is\",gcd(d1,d2)\n",
- "\n",
- "\n",
- "print \"Press any key to continue. . .\" "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter three integers : 45 27 81\n",
- "Greatest common divisor is 9\n",
- "Press any key to continue. . .\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-178"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to reverse the given integer\n",
- "# Variable declaration\n",
- "\n",
- "n = 2846\n",
- "\n",
- "print \"Enter the integer :\",n\n",
- "\n",
- "# function to reverse an integer\n",
- "\n",
- "def reverse(n):\n",
- " rn = 0\n",
- " while n > 0:\n",
- " r = n % 10\n",
- " rn = rn * 10 + r\n",
- " n = n /10\n",
- " return rn\n",
- "\n",
- "\n",
- "# call the function to print the reverse integer\n",
- "\n",
- "print n,\"is reversed as \",reverse(n)\n",
- "print \"Press any key to continue. . .\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the integer : 2846\n",
- "2846 is reversed as 6482\n",
- "Press any key to continue. . .\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-179"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to compare two strings S1 and S2 and return the result 0,1,-1\n",
- "# Variable declaration\n",
- "\n",
- "s1 = \"MUMBAI\"\n",
- "s2 = \"MYSORE\"\n",
- "\n",
- "print \"Enter the first string :\",s1\n",
- "print \"Enter the second string :\",s2\n",
- "\n",
- "\n",
- "# function to compare the strings\n",
- "\n",
- "def compare(s1,s2):\n",
- " if cmp(s1,s2) == 0:\n",
- " return 0\n",
- " if cmp(s1,s2) > 0:\n",
- " return 1\n",
- " if cmp(s1,s2) < 0:\n",
- " return -1\n",
- "\n",
- "# call the function to print the result\n",
- "\n",
- "print \"The result is \", compare(s1,s2)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the first string : MUMBAI\n",
- "Enter the second string : MYSORE\n",
- "The result is -1\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7 , Page number: CP-181"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find the arithmetic mean of n values using a function\n",
- "# Variable declaration\n",
- "\n",
- "n = 6\n",
- "x = [3.1,3.8,3.6,4.0,3.4,3.8]\n",
- "\n",
- "print \"How many values ?\",n\n",
- "print \"Enter all values\"\n",
- "for i in x:\n",
- " print i,\n",
- "print \n",
- "# function to find arithmetic mean\n",
- "\n",
- "def amean(x,n):\n",
- " s = 0\n",
- " for i in range(n):\n",
- " s = s + x[i]\n",
- " return (s/n)\n",
- "\n",
- "# call function to print arithmetic mean\n",
- "\n",
- "print \"Arithmetic mean = %0.2f\" % amean(x,n)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many values ? 6\n",
- "Enter all values\n",
- "3.1 3.8 3.6 4.0 3.4 3.8\n",
- "Arithmetic mean = 3.62\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8 , Page number: CP-182"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to read a matrix of order m x n and print the sum of all elements using functions\n",
- "# Variable declaration\n",
- "\n",
- "m = 3\n",
- "n = 2\n",
- "a = [[2,3,4],\n",
- " [2,0,1]]\n",
- "\n",
- "\n",
- "print \"How many rows and columns :\",m,n\n",
- "print \"Enter the matrix values\"\n",
- "for i in range(n):\n",
- " for j in range(m):\n",
- " print a[i][j],\n",
- " print \n",
- "\n",
- "# function to add all elements in the matrix\n",
- "def elem_sum(a,m,n):\n",
- " i = 0\n",
- " j = 0\n",
- " s = 0\n",
- " for i in range(n):\n",
- " for j in range(m):\n",
- " s = s + a[i][j]\n",
- " j = j + 1\n",
- " i = i + 1 \n",
- " return s\n",
- "\n",
- "# call function to print the result\n",
- "\n",
- "print \"Sum of all elements in the matrix =\",\n",
- "print elem_sum(a,m,n)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many rows and columns : 3 2\n",
- "Enter the matrix values\n",
- "2 3 4\n",
- "2 0 1\n",
- "Sum of all elements in the matrix = 12\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9 , Page number: CP-183"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to reverse a string\n",
- "# Variable declaration\n",
- "\n",
- "st = \"NEW DELHI\"\n",
- "print \"Enter a string :\",st\n",
- "def reverse(st):\n",
- " rst = \"\"\n",
- " for i in range(0 ,len(st)):\n",
- " rst += st[(len(st) -1) - i]\n",
- " return rst\n",
- "\n",
- "print st,\"is reversed as \",\n",
- "print reverse(st)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a string : NEW DELHI\n",
- "NEW DELHI is reversed as IHLED WEN\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10 , Page number: CP-184"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to apply binary search to set of N numbers using a function\n",
- "# Variable declaration\n",
- "\n",
- "n = 10\n",
- "x = [-3,8,13,19,21,25,26,29,35,42]\n",
- "s = 19\n",
- "\n",
- "\n",
- "print \"How many numbers ?\",n\n",
- "print \"Enter all numbers in the list\"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "print \"Enter the number to be searched :\",s\n",
- "\n",
- "# function to search the number\n",
- "\n",
- "def bi_search(x,n,s):\n",
- " flag = 0\n",
- " start = 0\n",
- " end = n\n",
- " while start < end and flag ==0:\n",
- " mid = (start + end) / 2\n",
- " if x[mid] > s:\n",
- " end = mid\n",
- " elif x[mid] < s:\n",
- " start = mid + 1\n",
- " else:\n",
- " flag = 1\n",
- " return flag\n",
- "\n",
- "# calling the function\n",
- "\n",
- "if bi_search(x,n,s):\n",
- " print \"The number\",s,\"is present in the list\"\n",
- "else:\n",
- " print \"The number\",s,\"is not present in list\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers ? 10\n",
- "Enter all numbers in the list\n",
- "-3 8 13 19 21 25 26 29 35 42\n",
- "Enter the number to be searched : 19\n",
- "The number 19 is present in the list\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11 , Page number: CP-187"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to find factorial of a given number using recursive function\n",
- "# Variable declaration\n",
- "\n",
- "n = 5\n",
- "r = 3\n",
- "\n",
- "print \"Enter the values to n and r :\",n,r\n",
- "\n",
- "# recursive function to find factorial\n",
- "\n",
- "def fact(k):\n",
- " if k ==1:\n",
- " return 1\n",
- " else:\n",
- " return (k * fact(k-1))\n",
- "\n",
- "ncr = fact(n)/(fact(r) * fact(n-r))\n",
- "print \"Value of nCr =\",ncr "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter the values to n and r : 5 3\n",
- "Value of nCr = 10\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 12 , Page number: CP-188"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to compute the value of x power n using a recursive function\n",
- "# Variable declaration\n",
- "\n",
- "x = 4.20\n",
- "n = 3\n",
- "\n",
- "print \"Enter value to x :\",x\n",
- "print \"Enter its power :\",n\n",
- "\n",
- "# recursive function to find x rise to n\n",
- "\n",
- "def power(x,n):\n",
- " if n == 1:\n",
- " return x\n",
- " else:\n",
- " return (x * power(x,n-1))\n",
- "\n",
- "\n",
- "print \"%0.2f\" %x,\"raise to \",n,\"is %0.2f\" % power(x,n) "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter value to x : 4.2\n",
- "Enter its power : 3\n",
- "4.20 raise to 3 is 74.09\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 13 , Page number: CP-189"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to display first n terms of the fibonacci series using recursive function\n",
- "\n",
- "# Variable declaration\n",
- "\n",
- "n = 10\n",
- "t1 = 0\n",
- "t2 = 1\n",
- "i = 0\n",
- "count = 2\n",
- "\n",
- "# recursive function to print the terms in series\n",
- "def fibo(t1,t2):\n",
- " global count\n",
- " if (count >= n):\n",
- " return\n",
- " else:\n",
- " t3 = t1 + t2\n",
- " print t3,\n",
- " count = count + 1\n",
- " t1 = t2\n",
- " t2 = t3\n",
- " return fibo(t1,t2)\n",
- " \n",
- "\n",
- "\n",
- "print \"How many terms to be printed ?\",n\n",
- "print \"The first\",n,\"terms in Fibonacci series are\"\n",
- "print t1,\n",
- "print t2,\n",
- "\n",
- "fibo(t1,t2)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many terms to be printed ? 10\n",
- "The first 10 terms in Fibonacci series are\n",
- "0 1 1 2 3 5 8 13 21 34\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 14 , Page number: CP-196"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to add two matrices of order m x n and to print the resultant values\n",
- "# Variable declaration\n",
- "\n",
- "m = 2\n",
- "n = 2\n",
- "a = [[2,-2],\n",
- " [0,4]]\n",
- "b = [[6,2],\n",
- " [4,-5]]\n",
- "c = [[0,0],\n",
- " [0,0]]\n",
- "\n",
- "print \"How many rows and columns ?\",m,n\n",
- "print \"Enter A matrix value\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print a[i][j],\n",
- " print \n",
- "print \"Enter B matrix values\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print b[i][j],\n",
- " print \n",
- "\n",
- "# function to add matrices\n",
- "def matadd():\n",
- " for i in range(m):\n",
- " for j in range(n):\n",
- " c[i][j] = a[i][j] + b[i][j]\n",
- "\n",
- "\n",
- "\n",
- "# call function\n",
- "matadd()\n",
- "print \"Resultant matrix is\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print c[i][j],\n",
- " print \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many rows and columns ? 2 2\n",
- "Enter A matrix value\n",
- "2 -2\n",
- "0 4\n",
- "Enter B matrix values\n",
- "6 2\n",
- "4 -5\n",
- "Resultant matrix is\n",
- "8 0\n",
- "4 -1\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 15 , Page number: CP-197"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to multiply A matrix of order of m x n with B matrix of order n x l and print the resultant matrix\n",
- "# Variable declaration\n",
- "\n",
- "a = [[2,-2],\n",
- " [0,4]]\n",
- "b = [[6,2,],\n",
- " [4,-5]]\n",
- "c = [[0,0],\n",
- " [0,0]]\n",
- "\n",
- "m = 2\n",
- "n = 2\n",
- "l = 2\n",
- "\n",
- "print \"Enter order of A matrix (m x n) :\",m,n\n",
- "print \"Enter A matrix values\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print a[i][j],\n",
- " print\n",
- " \n",
- "print \"Enter order of B matrix (n x l) :\",n,l\n",
- "print \"Enter B matrix values\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print b[i][j],\n",
- " print \n",
- " \n",
- "\n",
- "# function to multiply matrices\n",
- "\n",
- "def matmul():\n",
- " for i in range(m):\n",
- " for j in range(l):\n",
- " c[i][j] = 0\n",
- " for k in range(n):\n",
- " c[i][j] = c[i][j] + a[i][k] * b[k][j]\n",
- " return c\n",
- "\n",
- "# call function\n",
- "matmul()\n",
- "print \"Resultant matix is\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print c[i][j],\n",
- " print\n",
- "\n",
- "\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter order of A matrix (m x n) : 2 2\n",
- "Enter A matrix values\n",
- "2 -2\n",
- "0 4\n",
- "Enter order of B matrix (n x l) : 2 2\n",
- "Enter B matrix values\n",
- "6 2\n",
- "4 -5\n",
- "Resultant matix is\n",
- "4 14\n",
- "16 -20\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 16 , Page number: CP-199"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to transpose a matrix of order m x n\n",
- "# Variable declaration\n",
- "\n",
- "a = [[-3,6,0],\n",
- " [3,2,8]]\n",
- "at = [[0,0],\n",
- " [0,0],\n",
- " [0,0]]\n",
- "m = 2\n",
- "n = 3\n",
- "ch = \"y\"\n",
- "\n",
- "print \"How many rows and columns ?\",m,n\n",
- "print \"Enter the matrix values\"\n",
- "for i in range(m):\n",
- " for j in range(n):\n",
- " print a[i][j],\n",
- " print \n",
- " \n",
- "\n",
- "# function to transpose a matrix\n",
- "\n",
- "def transpose(a,at,m,n):\n",
- " for i in range(m):\n",
- " for j in range(n):\n",
- " at[j][i] = a[i][j]\n",
- " return at\n",
- "\n",
- "while ch == 'y' or ch == 'Y' :\n",
- " # call function to transpose the matrix\n",
- " transpose(a,at,m,n)\n",
- " print \"Transpose of the matrix is\"\n",
- " for i in range(n):\n",
- " for j in range(m):\n",
- " print at[i][j],\n",
- " print\n",
- " ch = \"N\"\n",
- " print \"Press y to continue\"\n",
- " print \" any other key to stop.\",ch"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many rows and columns ? 2 3\n",
- "Enter the matrix values\n",
- "-3 6 0\n",
- "3 2 8\n",
- "Transpose of the matrix is\n",
- "-3 3\n",
- "6 2\n",
- "0 8\n",
- "Press y to continue\n",
- " any other key to stop. N\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 17 , Page number: CP-200"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to create a function to sort the elements of an array in ascending order\n",
- "# Variable declaration\n",
- "\n",
- "n = 4\n",
- "x = [32,-10,20,5]\n",
- "\n",
- "print \"How many numbers ?\",n\n",
- "print \"Enter the list of values\"\n",
- "for a in x:\n",
- " print a,\n",
- "print \n",
- "\n",
- "# function to sort the numbers\n",
- "def sort(x,n):\n",
- " for i in range(n-1):\n",
- " for j in range(i+1,n):\n",
- " if x[i] > x[j]:\n",
- " temp = x[i]\n",
- " x[i] = x[j]\n",
- " x[j] = temp\n",
- " return x\n",
- "\n",
- "# call function to sort the numbers\n",
- "sort(x,n)\n",
- "print \"The sorted list is\"\n",
- "for a in x:\n",
- " print a,\n",
- "print\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many numbers ? 4\n",
- "Enter the list of values\n",
- "32 -10 20 5\n",
- "The sorted list is\n",
- "-10 5 20 32\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_/Chapter9.ipynb b/Computer_Programming_Theory_and_Practice_/Chapter9.ipynb
deleted file mode 100755
index 2113c5af..00000000
--- a/Computer_Programming_Theory_and_Practice_/Chapter9.ipynb
+++ /dev/null
@@ -1,624 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:93c2825491a65ebd6dbc85e6208fc8a03cf21f92da06cf2457eda56a011645f1"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1 , Page number: CP-211"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to display student details\n",
- "# class declaration instead of a structure\n",
- "\n",
- "class student:\n",
- " rno = 0\n",
- " sname = \"\"\n",
- " tot = 0\n",
- "\n",
- "# class object variable\n",
- "\n",
- "x = student()\n",
- "x.rno = 20147\n",
- "x.sname = \"PRADEEP\"\n",
- "x.tot = 64\n",
- "\n",
- "print \"Enter roll number, name and total marks\"\n",
- "print x.rno,x.sname,x.tot\n",
- "print \" Details entered are\"\n",
- "print \"Roll No. :\",x.rno\n",
- "print \"Student name :\",x.sname\n",
- "print \"Total marks :\",x.tot\n",
- "print \"Press any key to continue. . .\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter roll number, name and total marks\n",
- "20147 PRADEEP 64\n",
- " Details entered are\n",
- "Roll No. : 20147\n",
- "Student name : PRADEEP\n",
- "Total marks : 64\n",
- "Press any key to continue. . .\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2 , Page number: CP-212"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to input student details and print the marks of a specified student as output\n",
- "\n",
- "# class declaration for structure\n",
- "\n",
- "class student:\n",
- " def __init__(self,rno,sname,tot):\n",
- " self.rno = rno\n",
- " self.sname = sname\n",
- " self.tot = tot\n",
- " \n",
- "# variable declaration\n",
- "\n",
- "ch = \"y\"\n",
- "n = 3\n",
- "\n",
- "# details of n students\n",
- "std = []\n",
- "std.append(student(20201,\"ARUN\",78))\n",
- "std.append(student(20208,\"DEEPAK\",69))\n",
- "std.append(student(20223,\"SUSMITHA\",88))\n",
- "\n",
- "print \"How many students ?\",n\n",
- "print \"Roll number ?\",std[0].rno\n",
- "print \"Name ?\",std[0].sname\n",
- "print \"Total marks ?\",std[0].tot\n",
- "print \"Roll number ?\",std[1].rno\n",
- "print \"Name ?\",std[1].sname\n",
- "print \"Total marks ?\",std[1].tot\n",
- "print \"Roll number ?\",std[2].rno\n",
- "print \"Name ?\",std[2].sname\n",
- "print \"Total marks ?\",std[2].tot\n",
- "print \n",
- "\n",
- "\n",
- "# To display marks of the student\n",
- "while ch == \"y\" or ch == \"Y\":\n",
- " temp = 20208\n",
- " print \"Enter student roll number to display marks :\",temp\n",
- " print \n",
- " flag = 0\n",
- " #loop to search and display details\n",
- " for i in range(3):\n",
- " if flag == 0:\n",
- " if std[i].rno == temp:\n",
- " print \"Marks obtained by \",std[i].rno,std[i].sname\n",
- " print \"Total :\",std[i].tot\n",
- " flag = 1\n",
- " if flag == 0:\n",
- " print temp,\" is not present in the list \"\n",
- " \n",
- " ch = \"n\" \n",
- " print \"press y - to continue\"\n",
- " print \" any other key to stop.\",ch\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many students ? 3\n",
- "Roll number ? 20201\n",
- "Name ? ARUN\n",
- "Total marks ? 78\n",
- "Roll number ? 20208\n",
- "Name ? DEEPAK\n",
- "Total marks ? 69\n",
- "Roll number ? 20223\n",
- "Name ? SUSMITHA\n",
- "Total marks ? 88\n",
- "\n",
- "Enter student roll number to display marks : 20208\n",
- "\n",
- "Marks obtained by 20208 DEEPAK\n",
- "Total : 69\n",
- "press y - to continue\n",
- " any other key to stop. n\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3 , Page number: CP-214"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to declare a structure for student details and display list of students who obtained more than 75 marks\n",
- "\n",
- "# class for student structure\n",
- "\n",
- "class student:\n",
- " def __init__(self,rno,sname,tot):\n",
- " self.rno = rno\n",
- " self.sname = sname\n",
- " self.tot = tot\n",
- "\n",
- "std = []\n",
- "std.append(student(30401,\"ANAND\",59))\n",
- "std.append(student(30404,\"NIRMAL\",64))\n",
- "std.append(student(30428,\"ISWARYA\",82))\n",
- "std.append(student(30432,\"VIVEKA\",79))\n",
- "\n",
- "n = 4\n",
- "print \"How many students ?\",n\n",
- "print \"Roll Number ?\",std[0].rno\n",
- "print \"Name ?\",std[0].sname\n",
- "print \"Total marks ?\",std[0].tot\n",
- "print \"Roll Number ?\",std[1].rno\n",
- "print \"Name ?\",std[1].sname\n",
- "print \"Total marks ?\",std[1].tot\n",
- "print \"Roll Number ?\",std[2].rno\n",
- "print \"Name ?\",std[2].sname\n",
- "print \"Total marks ?\",std[2].tot\n",
- "print \"Roll Number ?\",std[3].rno\n",
- "print \"Name ?\",std[3].sname\n",
- "print \"Total marks ?\",std[3].tot\n",
- "print \n",
- "\n",
- "\n",
- "print \"----------------------------------------------------\"\n",
- "print \" Roll No. Name Total marks \"\n",
- "print \"----------------------------------------------------\"\n",
- "for i in range(n):\n",
- " if std[i].tot >= 75:\n",
- " print \" \",std[i].rno,\" \",std[i].sname,\" \",std[i].tot\n",
- "\n",
- "print \"----------------------------------------------------\"\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many students ? 4\n",
- "Roll Number ? 30401\n",
- "Name ? ANAND\n",
- "Total marks ? 59\n",
- "Roll Number ? 30404\n",
- "Name ? NIRMAL\n",
- "Total marks ? 64\n",
- "Roll Number ? 30428\n",
- "Name ? ISWARYA\n",
- "Total marks ? 82\n",
- "Roll Number ? 30432\n",
- "Name ? VIVEKA\n",
- "Total marks ? 79\n",
- "\n",
- "----------------------------------------------------\n",
- " Roll No. Name Total marks \n",
- "----------------------------------------------------\n",
- " 30428 ISWARYA 82\n",
- " 30432 VIVEKA 79\n",
- "----------------------------------------------------\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4 , Page number: CP-216"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to store employee information and to compute employee's pay\n",
- "\n",
- "import math\n",
- "# class declaration for employee\n",
- "class employee:\n",
- " def __init__(self,eno,ename,epay,jdate):\n",
- " self.eno = eno\n",
- " self.ename = ename\n",
- " self.epay = epay\n",
- " self.jdate = jdate\n",
- "\n",
- "employs = []\n",
- "employs.append(employee(20101,\"ASHIKA\",1000,\"31/04/2001\"))\n",
- "employs.append(employee(20182,\"ASHWIN\",6000,\"11/12/1995\"))\n",
- "employs.append(employee(20204,\"PRAVEEN\",3000,\"18/06/1994\"))\n",
- "\n",
- "n = 3\n",
- "\n",
- "print \"Employee No. ?\",employs[0].eno\n",
- "print \"Name ?\",employs[0].ename\n",
- "print \"Existing date ?\",employs[0].epay\n",
- "print \"Joinin date ?\",employs[0].jdate\n",
- "print \n",
- "print \"Press y- to continue any other key to stop. y\"\n",
- "print \"Employee No. ?\",employs[1].eno\n",
- "print \"Name ?\",employs[1].ename\n",
- "print \"Existing date ?\",employs[1].epay\n",
- "print \"Joinin date ?\",employs[1].jdate\n",
- "print\n",
- "print \"Press y- to continue any other key to stop. y\"\n",
- "print \"Employee No. ?\",employs[2].eno\n",
- "print \"Name ?\",employs[2].ename\n",
- "print \"Existing date ?\",employs[2].epay\n",
- "print \"Joinin date ?\",employs[2].jdate\n",
- "print\n",
- "print \"Press y- to continue any other key to stop. N\"\n",
- "print\n",
- "print n,\" records are entered\"\n",
- "print \"Press any key to print the revised salary list\"\n",
- "print \n",
- "\n",
- "\n",
- "\n",
- "def revise(temp):\n",
- " if temp <= 2000:\n",
- " temp = int(temp + math.ceil(temp * 0.15))\n",
- " return temp\n",
- " elif temp <= 5000:\n",
- " temp = int(temp + temp * 0.10)\n",
- " return temp\n",
- " else:\n",
- " return temp\n",
- "\n",
- " \n",
- "# loop to increment salary\n",
- "for i in range(n):\n",
- " employs[i].epay = revise(employs[i].epay)\n",
- "\n",
- " \n",
- "\n",
- "\n",
- "# loop to print revised salary list\n",
- "print \" Employees Revised Pay List \"\n",
- "print \"---------------------------------------------------------\"\n",
- "print \" S.No. Number Name Joining date Pay \"\n",
- "print \"---------------------------------------------------------\"\n",
- "\n",
- "for i in range(n):\n",
- " print \" \",i+1,\" \",employs[i].eno,\" \",employs[i].ename,\" \",employs[i].jdate,\" \",employs[i].epay\n",
- "\n",
- "print \"---------------------------------------------------------\" \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Employee No. ? 20101\n",
- "Name ? ASHIKA\n",
- "Existing date ? 1000\n",
- "Joinin date ? 31/04/2001\n",
- "\n",
- "Press y- to continue any other key to stop. y\n",
- "Employee No. ? 20182\n",
- "Name ? ASHWIN\n",
- "Existing date ? 6000\n",
- "Joinin date ? 11/12/1995\n",
- "\n",
- "Press y- to continue any other key to stop. y\n",
- "Employee No. ? 20204\n",
- "Name ? PRAVEEN\n",
- "Existing date ? 3000\n",
- "Joinin date ? 18/06/1994\n",
- "\n",
- "Press y- to continue any other key to stop. N\n",
- "\n",
- "3 records are entered\n",
- "Press any key to print the revised salary list\n",
- "\n",
- " Employees Revised Pay List \n",
- "---------------------------------------------------------\n",
- " S.No. Number Name Joining date Pay \n",
- "---------------------------------------------------------\n",
- " 1 20101 ASHIKA 31/04/2001 1150\n",
- " 2 20182 ASHWIN 11/12/1995 6000\n",
- " 3 20204 PRAVEEN 18/06/1994 3300\n",
- "---------------------------------------------------------\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5 , Page number: CP-219"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to store cricket details and to display a team-wise list with batting average\n",
- "\n",
- "# class for cricket structure\n",
- "\n",
- "class cricket:\n",
- " def __init__(self,pname,tname,bavg):\n",
- " self.pname = pname\n",
- " self.tname = tname\n",
- " self.bavg = bavg\n",
- "\n",
- "n = 6\n",
- "probable = []\n",
- "probable.append(cricket(\"KUMBLE\",\"KARNATAKA\",22))\n",
- "probable.append(cricket(\"KAMBLI\",\"MUMBAI\",39))\n",
- "probable.append(cricket(\"SRIKANTH\",\"TAMILNADU\",52))\n",
- "probable.append(cricket(\"SACHIM\",\"MUMBAI\",69))\n",
- "probable.append(cricket(\"RAHUL\",\"KARNATAKA\",57))\n",
- "probable.append(cricket(\"RAMESH\",\"TAMILNADU\",48))\n",
- "\n",
- "print \"How many players ?\",n\n",
- "print\n",
- "print \"Player name ?\",probable[0].pname\n",
- "print \"Which team ?\",probable[0].tname\n",
- "print \"Batting average ?\",probable[0].bavg\n",
- "print \"Player name ?\",probable[1].pname\n",
- "print \"Which team ?\",probable[1].tname\n",
- "print \"Batting average ?\",probable[1].bavg\n",
- "print \"Player name ?\",probable[2].pname\n",
- "print \"Which team ?\",probable[2].tname\n",
- "print \"Batting average ?\",probable[2].bavg\n",
- "print \"Player name ?\",probable[3].pname\n",
- "print \"Which team ?\",probable[3].tname\n",
- "print \"Batting average ?\",probable[3].bavg\n",
- "print \"Player name ?\",probable[4].pname\n",
- "print \"Which team ?\",probable[4].tname\n",
- "print \"Batting average ?\",probable[4].bavg\n",
- "print \"Player name ?\",probable[5].pname\n",
- "print \"Which team ?\",probable[5].tname\n",
- "print \"Batting average ?\",probable[5].bavg\n",
- "print\n",
- "print \n",
- "j = 0\n",
- "teams = []\n",
- "teams.append(probable[0].tname)\n",
- "j = j + 1\n",
- "for i in range(n):\n",
- " flag = 0\n",
- " for k in range(j):\n",
- " if flag == 0:\n",
- " if probable[i].tname == teams[k]:\n",
- " flag = 1\n",
- " if flag == 0 :\n",
- " teams.append(probable[i].tname)\n",
- " j = j + 1\n",
- "\n",
- "# loop to print team-wise list\n",
- "\n",
- "for k in range(3):\n",
- " print \" \",teams[k]\n",
- " print \"---------------------------------------------\"\n",
- " for i in range(n):\n",
- " if probable[i].tname == teams[k]:\n",
- " print \" \",probable[i].pname,\" \",probable[i].bavg\n",
- " print \"---------------------------------------------\" \n",
- "\n",
- "\n",
- "\n",
- "\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "How many players ? 6\n",
- "\n",
- "Player name ? KUMBLE\n",
- "Which team ? KARNATAKA\n",
- "Batting average ? 22\n",
- "Player name ? KAMBLI\n",
- "Which team ? MUMBAI\n",
- "Batting average ? 39\n",
- "Player name ? SRIKANTH\n",
- "Which team ? TAMILNADU\n",
- "Batting average ? 52\n",
- "Player name ? SACHIM\n",
- "Which team ? MUMBAI\n",
- "Batting average ? 69\n",
- "Player name ? RAHUL\n",
- "Which team ? KARNATAKA\n",
- "Batting average ? 57\n",
- "Player name ? RAMESH\n",
- "Which team ? TAMILNADU\n",
- "Batting average ? 48\n",
- "\n",
- "\n",
- " KARNATAKA\n",
- "---------------------------------------------\n",
- " KUMBLE 22\n",
- " RAHUL 57\n",
- "---------------------------------------------\n",
- " MUMBAI\n",
- "---------------------------------------------\n",
- " KAMBLI 39\n",
- " SACHIM 69\n",
- "---------------------------------------------\n",
- " TAMILNADU\n",
- "---------------------------------------------\n",
- " SRIKANTH 52\n",
- " RAMESH 48\n",
- "---------------------------------------------\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6 , Page number: CP-235"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Program to illustrate the use of union using integer,string and float\n",
- "\n",
- "class student:\n",
- " def __init__(self,roll_no,sname,marks):\n",
- " self.roll_no = roll_no\n",
- " self.sname = sname\n",
- " self.marks = marks\n",
- "\n",
- "std = []\n",
- "std.append(student(0,\"AJITH\",0))\n",
- "std.append(student(0,\"RAJU\",0))\n",
- "std.append(student(0,\"VIGNESH\",0))\n",
- "std.append(student(0,\"DIVYA\",0))\n",
- "\n",
- "ch = 2\n",
- "print \"-----------------------------\"\n",
- "print \" Main menu \"\n",
- "print \"-----------------------------\"\n",
- "print \"Press 1 to enter roll numbers\"\n",
- "print \" 2 to enter names \"\n",
- "print \" 3 to enter marks \"\n",
- "print \" 4 to stop \"\n",
- "print \n",
- "print \"Enter your choice :\",ch\n",
- "\n",
- "n = 4\n",
- "print \"How many students?\",n\n",
- "for i in range(n):\n",
- " print \" Student name ? \",std[i].sname\n",
- "\n",
- "print\n",
- "print \n",
- "# display required list\n",
- "# switch case\n",
- "if ch == 1: #case 1\n",
- " print \"------------------------------\"\n",
- " print \" Students roll number list \"\n",
- " print \"------------------------------\"\n",
- " for i in range(n):\n",
- " print std[i].roll_no\n",
- " print \"-------------------------------\"\n",
- "elif ch == 2: # case 2\n",
- " print \"------------------------------\"\n",
- " print \" Students name list \"\n",
- " print \"------------------------------\"\n",
- " for i in range(n):\n",
- " print std[i].sname\n",
- " print \"-------------------------------\"\n",
- "elif ch == 3: # case 3\n",
- " print \"------------------------------\"\n",
- " print \" Students mark list \"\n",
- " print \"------------------------------\"\n",
- " for i in range(n):\n",
- " print \"Student marks\",std[i].roll_no\n",
- " print \"-------------------------------\"\n",
- " \n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "-----------------------------\n",
- " Main menu \n",
- "-----------------------------\n",
- "Press 1 to enter roll numbers\n",
- " 2 to enter names \n",
- " 3 to enter marks \n",
- " 4 to stop \n",
- "\n",
- "Enter your choice : 2\n",
- "How many students? 4\n",
- " Student name ? AJITH\n",
- " Student name ? RAJU\n",
- " Student name ? VIGNESH\n",
- " Student name ? DIVYA\n",
- "\n",
- "\n",
- "------------------------------\n",
- " Students name list \n",
- "------------------------------\n",
- "AJITH\n",
- "RAJU\n",
- "VIGNESH\n",
- "DIVYA\n",
- "-------------------------------\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_/screenshots/chapter11.png b/Computer_Programming_Theory_and_Practice_/screenshots/chapter11.png
deleted file mode 100755
index c5895710..00000000
--- a/Computer_Programming_Theory_and_Practice_/screenshots/chapter11.png
+++ /dev/null
Binary files differ
diff --git a/Computer_Programming_Theory_and_Practice_/screenshots/chapter2.png b/Computer_Programming_Theory_and_Practice_/screenshots/chapter2.png
deleted file mode 100755
index 05fde2b5..00000000
--- a/Computer_Programming_Theory_and_Practice_/screenshots/chapter2.png
+++ /dev/null
Binary files differ
diff --git a/Computer_Programming_Theory_and_Practice_/screenshots/chapter3.png b/Computer_Programming_Theory_and_Practice_/screenshots/chapter3.png
deleted file mode 100755
index 685e290b..00000000
--- a/Computer_Programming_Theory_and_Practice_/screenshots/chapter3.png
+++ /dev/null
Binary files differ
diff --git a/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_02_Fundamentals_of_C_language.ipynb b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_02_Fundamentals_of_C_language.ipynb
new file mode 100755
index 00000000..2c500315
--- /dev/null
+++ b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_02_Fundamentals_of_C_language.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 02: Fundamentals of C language", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 3, Page Number: CP-22", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# variable declaration\n\na = 5\nb = 7\nc = 2\n\n# calculation \n\ny = a + b / c - a % c + 2 * a\n\n# result \n\nprint \"The result is \",y\n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The result is 17\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_03_Input_Output_Functions_and_Statements.ipynb b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_03_Input_Output_Functions_and_Statements.ipynb
new file mode 100755
index 00000000..e0941e6f
--- /dev/null
+++ b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_03_Input_Output_Functions_and_Statements.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 03: Input/Output Functions and Statements", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-39", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "#program to add and find product of two numbers\n\n#variable declaration\na = 5\nb = 3\n\n# calculation of sum and product \n\nsumm = a + b\nproduct = a * b\n\nprint a,b\nprint summ,product", "outputs": [{"output_type": "stream", "name": "stdout", "text": "5 3\n8 15\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-45", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to convert degree fahrenheit to celcius \n# variable declaration\n\nf = 105.00\nprint \"Degree fahrenheit ? %d\" % f\n# calculation of degree in celcius \n\nc = 5.0/9.0 * (f-32)\n\n# result \nprint\nprint \"Degree centigrade =%6.2f\" % c", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Degree fahrenheit ? 105\n\nDegree centigrade = 40.56\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: CP-45", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# To find area of a triangle\n# variable declaration\n\na = 5\nb = 4\nc = 6\n\n\n# calculation of area\ns = float((a+b+c))/2\narea = (s*(s-a)*(s-b)*(s-c)) ** 0.5\n\n# result\nprint \"Enter three sides : %d\" % a,b,c\nprint \nprint \"Area of triangle = %0.2f Sq.units\" % area", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter three sides : 5 4 6\n\nArea of triangle = 9.92 Sq.units\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-51", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# To print ASCII value of a given character \n# Variable declaration\n\nch = \"A\"\nprint \"Enter a character : \" , ch\n\n# Calculation of ASCII value of a character\n\nprint \nprint \"ASCII value of \" + ch + \" is\" ,ord(ch)\nprint \"Press any key to stop. . .\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a character : A\n\nASCII value of A is 65\nPress any key to stop. . .\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-51", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# To print electricity for consumers\n# Variable declaration\n\nsno = \"TMR65358\"\npmr = 4305\ncmr = 4410\n\nprint \"Enter service number :\" ,sno\nprint \"Previous meter reading ?\",pmr\nprint \"Current meter reading ?\",cmr\n\n# Calculation of electricity charges\n\nunits = cmr - pmr\namt = units * 1.50\n\n# Result\n\nprint\nprint \" Electricity Bill\"\nprint \" ----------------\"\nprint \"Service No :\",sno\nprint \"Unit Consumed :\",units\nprint \"Electricity Charges : Rs.%0.2f\" % amt", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter service number : TMR65358\nPrevious meter reading ? 4305\nCurrent meter reading ? 4410\n\n Electricity Bill\n ----------------\nService No : TMR65358\nUnit Consumed : 105\nElectricity Charges : Rs.157.50\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-52", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to swap value of two variables\n# Variable declaration\n\na = 15\nb = 250 \n\nprint \"Enter value to A :\",a\nprint \"Enter value to B :\",b\n\n# Swapping\n\ntemp = a\na = b\nb = temp\n\nprint \nprint \"Value of A =\",a\nprint \"Value of B =\",b", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to A : 15\nEnter value to B : 250\n\nValue of A = 250\nValue of B = 15\n"}], "metadata": {"scrolled": true, "collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_04_Control_Statements_in_C.ipynb b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_04_Control_Statements_in_C.ipynb
new file mode 100755
index 00000000..6dcd833e
--- /dev/null
+++ b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_04_Control_Statements_in_C.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 04: Control Statements in C ", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-60", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to find the biggest of two numbers\n# Variable declaration\n\na = 5\nb = 8\n\nprint \"Enter two numbers : %d\" % a,b\n\n# Calculation\n\nbig = a\nif (b>big):\n big = b\n\nprint \"Biggest number is \",big", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter two numbers : 5 8\nBiggest number is 8\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-61", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to find biggest of three numbers\n# Variable declaration\n\na = 5\nb = 13\nc = 8\n\nprint \"Enter three numbers : %d\" % a,b,c\n\n# Calculate\n\nbig = a\nif (b>big):\n big = b\nif (c>big):\n big = c\n\nprint \"Biggest number is\",big", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter three numbers : 5 13 8\nBiggest number is 13\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: CP-63", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to find biggest of three numbers\n# Variable declaration\n\na = 18\nb = -5\nc = 13\n \nprint \"Enter three numbers : %d\" % a,b,c\n\n# Calculation to find biggest number\n\nif (a>b):\n if(a>c):\n big = a\n else:\n big = c\nelse:\n if(b>c):\n big = b\n else:\n big = c\n\nprint \"Biggest number is\",big", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter three numbers : 18 -5 13\nBiggest number is 18\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-64", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to find the value of y \n# Variable declration\n\nx = 0.42\nn = 5\n\nprint \"Enter value to x and n :\" , x,n \n\n# Calculation\n\nif (n==1):\n y = 1 + x\nelif (n==2):\n y = 1 + x / n\nelif (n==3):\n y = 1 + (x ** n)\nelse:\n y = 1 + n * x\n\n\nprint \"Value of y(x,n) = %0.2f\" % y", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to x and n : 0.42 5\nValue of y(x,n) = 3.10\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-66", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to find the value of y\n# Variable declaration\n\nx = 0.42\nn = 5\n\n\nprint \"Enter value to x and n :\", x,n\n\n# Calculation\n\n# Switch case statements \nif n == 1: # case 1\n y = 1 + x\nelif n == 2: # case 2\n y = 1 + x / n\nelif n == 3: # case 3\n y = 1 + (x ** n)\nelse: # default\n y = 1 + n * x\n\nprint \"Value of y(x,n) = %0.2f\" % y ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to x and n : 0.42 5\nValue of y(x,n) = 3.10\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-68", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to caculate the commission for sales representatives\n# Variable declaration\n\nsales = 4500\n\nprint \"Sales amount ? :\" , sales\n\n# Calculation of commission\n\nif (sales <= 500):\n comm = 0.05 * sales\nelif (sales <= 2000):\n comm = 35 + 0.10 * (sales - 500)\nelif (sales <= 5000):\n comm = 185 + 0.12 * (sales - 2000)\nelse:\n comm = 0.125 * sales\n\n\nprint \"Commission Amount Rs.%0.2f\" % comm", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Sales amount ? : 4500\nCommission Amount Rs.485.00\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7 , Page number: CP-69", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "# Program to find roots of a quadratic equation\n# Variable declaration\n\na = 1\nb = 3\nc = 2\n\nprint \"Enter coefficients a, b, and c :\", a,b,c\n\nd = b * b - 4 * a * c\n\n# Calculation of roots\n\nif (d > 0):\n x1 = (-b + (d ** 0.5)) / (2 * a)\n x2 = (-b - (d ** 0.5)) / (2 * a)\n print \"Roots are real and unequal \"\n print x1,x2\n \n\nelif(d == 0):\n x = -b / (2 * a)\n print \"Roots are real and equal\"\n print \"%6.2f\" % x\n\nelse:\n print \"No Real roots, roots are complex\"\n\n\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter coefficients a, b, and c : 1 3 2\nRoots are real and unequal \n-1.0 -2.0\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8 , Page number: CP-70", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "# Program to print grade\n# Variable declaration\n\navg_marks = 84\n\nprint \"Average marks ?\",avg_marks\n\n# Calculation of grade\n\nif (avg_marks >= 80) and (avg_marks <= 100):\n print \"Honours\"\nelif (avg_marks >= 60) and (avg_marks <=79):\n print \"First Division\"\nelif (avg_marks >= 50) and (avg_marks <= 59):\n print \"Second Division\"\nelse:\n print \"Fail\"\n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Average marks ? 84\nHonours\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9 , Page number: CP-70", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "# Program to calculate electirc charges for domestic consumers\n# Variable declaration\n\nunits = 348\n\nprint \"Enter consumed units :\",units\n\n# Calculation of electric charges\n\nif (units <= 200):\n amt = 0.5 * units\nelif (units <= 400):\n amt = 100 + 0.65 * (units - 200)\nelif (units <= 600):\n amt = 230 + 0.8 * (units - 400)\nelse:\n amt = 425 + 1.25 * (units - 600)\nprint \nprint \"Amount to be paid Rs.%0.2f\" % amt", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter consumed units : 348\n\nAmount to be paid Rs.196.20\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10 , Page number: CP-73", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "# Program to find the grade of steel samples\n# Variable declaration\n\nts = 800\nrh = 180\ncc = 3\n\nprint \"Enter tensile strength :\",ts\nprint \"Enter rockwell hardness :\",rh\nprint \"Enter carbon content :\",cc\n\n# Calculation of grade\n\nif (ts >= 700):\n if (rh >= 200):\n if (cc <= 6):\n print \"Grade is A\"\n else:\n print \"Grade is B\" \n elif (cc <= 6):\n print \"Grade is C\"\n else:\n print \"Grade is E\" \nelif (rh >= 200):\n if (cc <= 6):\n print \"Grade is D\"\n else:\n print \"Grade is E\"\nelif (cc <= 6):\n print \"Grade is E\"\nelse:\n print \"Grade is F\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter tensile strength : 800\nEnter rockwell hardness : 180\nEnter carbon content : 3\nGrade is C\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_05_Loop_Control_Structures_In_C.ipynb b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_05_Loop_Control_Structures_In_C.ipynb
new file mode 100755
index 00000000..87019e9b
--- /dev/null
+++ b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_05_Loop_Control_Structures_In_C.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 05: Loop Control Structures in C", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-79", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to print natural numbers from 1 to n\n# Variable decalration\n\nn = 15\n\nprint \"Enter value to n :\",n\n\n# Loop to print natural numbers\nfor r in range(15):\n r = r + 1\n print r,\n \n \n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to n : 15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-80", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to find the value of y and print a table for values of x\n# Variable declaration\nimport math\nx = 1.0\nprint \"------------------------\"\nprint \" x y \"\nprint \"------------------------\"\nwhile x <= 3.2:\n y = 1.36 * ((1 + x + x * x * x) ** 0.5) + ((x) ** (1.0/4)) + math.exp(x)\n print \" %0.2f \" %x + \" %0.2f\" % y\n x = x + 0.2", "outputs": [{"output_type": "stream", "name": "stdout", "text": "------------------------\n x y \n------------------------\n 1.00 6.07\n 1.20 7.06\n 1.40 8.23\n 1.60 9.60\n 1.80 11.20\n 2.00 13.09\n 2.20 15.30\n 2.40 17.91\n 2.60 20.99\n 2.80 24.64\n 3.00 28.97\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: CP-81", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to find factorial of given number\n# Variable declaration\n\nk = 4\nkfact = 1\n\nprint \"Enter an integer :\",k\n\n# Loop to generate numbers from 1 to n\n\nfor i in range(1,k + 1):\n kfact = kfact*i\n\nprint \"4 factorial is\",kfact ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter an integer : 4\n4 factorial is 24\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-83", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to print sum of the following series\n# Variable declaration\n\nn = 4\ns = 0\n\nprint \"Enter value to N :\",n\n# Calculation of sum\ni = 1\nj = 1\n\nfor i in range(1,n+1):\n term = 0\n for j in range(i+1):\n term = term + j\n s = s + term\n\n\nprint \"Sum of the series S =\",s ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to N : 4\nSum of the series S = 20\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-84", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to compute the values of z based on x and y\n# Variable declaration\n\nx = -1.5\ny = 0\n\n# Loops to generate values of x and y to find z\n\nwhile x <= 1.5:\n while y <= 3.0:\n z = 3 * x * x + 2 * y * y * y - 25.5\n print \"Value of y(\",x,\n print \",\",y,\n print \") =\",z\n y = y + 1.0\n x = x + 0.5\n y = 0\n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Value of y( -1.5 , 0 ) = -18.75\nValue of y( -1.5 , 1.0 ) = -16.75\nValue of y( -1.5 , 2.0 ) = -2.75\nValue of y( -1.5 , 3.0 ) = 35.25\nValue of y( -1.0 , 0 ) = -22.5\nValue of y( -1.0 , 1.0 ) = -20.5\nValue of y( -1.0 , 2.0 ) = -6.5\nValue of y( -1.0 , 3.0 ) = 31.5\nValue of y( -0.5 , 0 ) = -24.75\nValue of y( -0.5 , 1.0 ) = -22.75\nValue of y( -0.5 , 2.0 ) = -8.75\nValue of y( -0.5 , 3.0 ) = 29.25\nValue of y( 0.0 , 0 ) = -25.5\nValue of y( 0.0 , 1.0 ) = -23.5\nValue of y( 0.0 , 2.0 ) = -9.5\nValue of y( 0.0 , 3.0 ) = 28.5\nValue of y( 0.5 , 0 ) = -24.75\nValue of y( 0.5 , 1.0 ) = -22.75\nValue of y( 0.5 , 2.0 ) = -8.75\nValue of y( 0.5 , 3.0 ) = 29.25\nValue of y( 1.0 , 0 ) = -22.5\nValue of y( 1.0 , 1.0 ) = -20.5\nValue of y( 1.0 , 2.0 ) = -6.5\nValue of y( 1.0 , 3.0 ) = 31.5\nValue of y( 1.5 , 0 ) = -18.75\nValue of y( 1.5 , 1.0 ) = -16.75\nValue of y( 1.5 , 2.0 ) = -2.75\nValue of y( 1.5 , 3.0 ) = 35.25\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-89", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to find sum of odd integers between 1 to n\n# Variable declararion\n\nn = 10\n\nprint \"Enter value to N :\",n\n\ns = 0\ni = 1\n\nwhile (i <= n):\n s = s + i\n i = i + 2\n\nprint \"Sum of odd integers =\",s", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to N : 10\nSum of odd integers = 25\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7 , Page number: CP-90", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "# Program to generate first 50 positive integers that are divisible by 7\n# Variable declaration\n\nn = 7\nprint \"Integers divisible by 7\"\n\n#loop to print numbers divisible by 7\nfor n in range(7,353,7):\n print n,\n \n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Integers divisible by 7\n7 14 21 28 35 42 49 56 63 70 77 84 91 98 105 112 119 126 133 140 147 154 161 168 175 182 189 196 203 210 217 224 231 238 245 252 259 266 273 280 287 294 301 308 315 322 329 336 343 350\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8 , Page number: CP-91", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "# Program to print integers from 1 to n that are not divisible by 7\n# Variable declaration\n\nn = 20\nprint \"Enter the end value N :\",n\n\n# Loop to print numbers that are not divisible by 7\n\nprint \"Integers not divisible by 7\"\nfor k in range(1,n + 1,1):\n r = k % 7\n if (r != 0):\n print k,", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the end value N : 20\nIntegers not divisible by 7\n1 2 3 4 5 6 8 9 10 11 12 13 15 16 17 18 19 20\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9 , Page number: CP-92 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "# Program to print sum of digits of an integer\n# Variable declaration\n\nn = 2466\n\nprint \"Enter a positive integer :\",n\n\nq = n\ns = 0\n\nwhile (q > 0):\n r = q % 10\n s = s + r\n q = q / 10\n\n\nprint \"Sum of digits =\",s\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a positive integer : 2466\nSum of digits = 18\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10 , Page number: CP-93", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "# Program to check whether a given number is an armstrong number or not\n# Variable declaration\n\nn = 153\nq = n\ns = 0\n\nprint \"Enter an integer number :\",n\n\n# To check armstrong or not\n\nwhile (q > 0):\n r = q % 10\n s = s + r * r * r\n q = q / 10\n\nif (n == s):\n print \"%d is an Armstrong number\" % n\nelse:\n print \"%d is not an Armstrong number\" % n\n\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter an integer number : 153\n153 is an Armstrong number\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 11 , Page number: CP-94", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "# Program to reverse a given integer\n# Variable declaration\n\nn = 18532\nq = n\nrn = 0\n\nprint \"Enter an integer number :\",n\n# Reversing\n\nwhile (q > 0):\n r = q % 10\n rn = (rn * 10) + r\n q = q / 10\n\n\nprint \"18532 is reversed as\",rn ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter an integer number : 18532\n18532 is reversed as 23581\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 12 , Page number: CP-95", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "# Program to accept an integer and print digits using words\n# Variable declaration\n\nn = 4352\nq = n\nrn = 0\n\nprint \"Enter an integer number :\",n\n# converting to digits\n\nwhile (q > 0):\n r = q % 10\n rn = rn * 10 + r\n q = q / 10\n\n\nwhile (rn > 0):\n r = rn % 10\n if (r == 1):\n s = \"One\"\n print s,\n elif (r == 2):\n s = \"Two\"\n print s,\n elif (r == 3):\n s = \"Three\"\n print s,\n elif (r == 4):\n s = \"Four\"\n print s,\n elif (r == 5):\n s = \"Five\"\n print s,\n elif (r == 6):\n s = \"Six\"\n print s,\n elif (r == 7):\n s = \"Seven\"\n print s,\n elif (r == 8):\n s = \"Eight\"\n print s,\n elif (r == 9):\n s = \"Nine\"\n print s,\n elif (r == 0):\n s = \"Zero\"\n print s,\n rn = rn / 10\n\n\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter an integer number : 4352\nFour Three Five Two\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 13 , Page number: CP-97", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to find whether a number is prime or not\n# Variable declaration\n\nn = 17\n\nprint \"Enter a positive integer :\",n\n\n# prime numbers are greater than 1\nif n > 1:\n for i in range(2,n):\n if (n % i) == 0:\n print(n,\"is not a prime number\")\n print(i,\"times\",n//i,\"is\",num)\n break\n else:\n print \"%d is a prime number\" % n\n\nelse:\n print \"%d is not a prime number\" % n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a positive integer : 17\n17 is a prime number\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 14 , Page number: CP-98", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "# Program to generate Fibonacci series\n# Variable declaration\n\nn = 25\nn1 = 0\nn2 = 1\n\nprint \"Enter the final term of the series :\",n\n\nprint n1,n2,\n\n\nnewterm = n1 + n2\n\n# Loop to print fibonacci series\nwhile (newterm <= n):\n print newterm,\n n1 = n2\n n2 = newterm\n newterm = n1 + n2\n\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the final term of the series : 25\n0 1 1 2 3 5 8 13 21\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 15 , Page number: CP-99", "cell_type": "markdown", "metadata": {}}, {"execution_count": 15, "cell_type": "code", "source": "# Program to solve the sine series\n# Variable declaration\n\nx = 0.52\nn = 10\ns = 0\nterm = x\ni = 1\n\nprint \"Enter x in radians :\",x\nprint \"Enter end term power (n):\",n\n\nwhile (i <= n):\n s = s + term\n term = (term * x * x *(-1)) / ((i + 1) * (i + 2))\n i = i + 2\n\nprint \"Sum of the series = %0.6f\" % s\n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter x in radians : 0.52\nEnter end term power (n): 10\nSum of the series = 0.496880\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 16 , Page number: CP-101", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "# Program to solve the cosine series\n# Variable declaration\n\nx = 0.52\ns = 0\nterm = 1\ni = 0\nn = 10\nprint \"Enter x in radians :\",x\n\n# Calculation of cosine series\n\nwhile (i <= n):\n s = s + term\n term = (term * x * x * (-1)) / ((i + 1) * (i + 2))\n i = i + 2\n\n\nprint \"Sum of the series = %0.6f\" % s ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter x in radians : 0.52\nSum of the series = 0.867819\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 17 , Page number: CP-102", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "import math\n\n# Program to compute the value of pie\n# Variable declaration\n\ns = 0.0\ndr = 1\nsign = 1\nterm = (1.0/dr) * sign\nwhile (math.fabs(term) >= 1.0e-4):\n s = s + term\n dr = dr + 2\n sign = sign * -1\n term = (1.0 / dr) * sign\n\npie = s * 4\n\nprint \"Value of pie is %.6f\"%pie", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Value of pie is 3.141393\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 18 , Page number: CP-104", "cell_type": "markdown", "metadata": {}}, {"execution_count": 18, "cell_type": "code", "source": "# Program to evaluate the series\n# Variable declaration\n\nn = 15\ns = 0.00\n\nprint \"Enter value to N :\",n\n\n# Evaluation of series\n\nfor i in range(1,n + 1,1):\n s = float(s) + float(1.0 / i)\n \n\nprint \"Sum of series = %0.4f\" % s \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to N : 15\nSum of series = 3.3182\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 21 , Page number: CP-108", "cell_type": "markdown", "metadata": {}}, {"execution_count": 19, "cell_type": "code", "source": "# Program to print multiplication table\n# Variable declaration\n\ni = 1\nj = 1\n\n# nested loop to print multiplication tables\n\nfor i in range(1,6):\n print \"Multiplication table for\",i\n for j in range(1,11):\n print \" \",j,\"x\" , i ,\" =\" , j*i\n print \"Press any key to continue. . .\" ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Multiplication table for 1\n 1 x 1 = 1\n 2 x 1 = 2\n 3 x 1 = 3\n 4 x 1 = 4\n 5 x 1 = 5\n 6 x 1 = 6\n 7 x 1 = 7\n 8 x 1 = 8\n 9 x 1 = 9\n 10 x 1 = 10\nPress any key to continue. . .\nMultiplication table for 2\n 1 x 2 = 2\n 2 x 2 = 4\n 3 x 2 = 6\n 4 x 2 = 8\n 5 x 2 = 10\n 6 x 2 = 12\n 7 x 2 = 14\n 8 x 2 = 16\n 9 x 2 = 18\n 10 x 2 = 20\nPress any key to continue. . .\nMultiplication table for 3\n 1 x 3 = 3\n 2 x 3 = 6\n 3 x 3 = 9\n 4 x 3 = 12\n 5 x 3 = 15\n 6 x 3 = 18\n 7 x 3 = 21\n 8 x 3 = 24\n 9 x 3 = 27\n 10 x 3 = 30\nPress any key to continue. . .\nMultiplication table for 4\n 1 x 4 = 4\n 2 x 4 = 8\n 3 x 4 = 12\n 4 x 4 = 16\n 5 x 4 = 20\n 6 x 4 = 24\n 7 x 4 = 28\n 8 x 4 = 32\n 9 x 4 = 36\n 10 x 4 = 40\nPress any key to continue. . .\nMultiplication table for 5\n 1 x 5 = 5\n 2 x 5 = 10\n 3 x 5 = 15\n 4 x 5 = 20\n 5 x 5 = 25\n 6 x 5 = 30\n 7 x 5 = 35\n 8 x 5 = 40\n 9 x 5 = 45\n 10 x 5 = 50\nPress any key to continue. . .\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 22 , Page number: CP-109", "cell_type": "markdown", "metadata": {}}, {"execution_count": 20, "cell_type": "code", "source": "import math\n\n# Program to convert a binary number to a decimal number\n# Variable declaration\n\nq = 1101\ns = 0\nk = 0\n\nprint \"Enter the binary number :\",q\nwhile (q > 0):\n r = q % 10\n s = s + r * pow(2,k)\n q = q / 10\n k = k + 1\n\n\nprint \"The decimal number is :\",s\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the binary number : 1101\nThe decimal number is : 13\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 23 , Page number: CP-110", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to convert a decimal number to a binary number\n# Variable declaration\n\nn = 28\nq = n\nrbi = 0\nflag = 0\nk = 0\n\nprint \"Enter the decimal number :\",n\n\n\nwhile (q > 0):\n r = q % 2\n if (r == 0) and (flag == 0):\n k = k + 1\n else:\n flag = 1\n rbi = rbi * 10 + r\n q = q / 2\n\nq = rbi\nbi = 0\nwhile (q > 0):\n r = q % 10\n bi = bi * 10 + r\n q = q / 10\n i = 1\n if (q == 0):\n while (i <= k):\n bi = bi * 10\n i = i + 1\n\n\nprint \"The binary number is \",bi ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the decimal number : 28\nThe binary number is 11100\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_06_Arrays_and_Subscripted_Variables.ipynb b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_06_Arrays_and_Subscripted_Variables.ipynb
new file mode 100755
index 00000000..4d310a43
--- /dev/null
+++ b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_06_Arrays_and_Subscripted_Variables.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 06: Arrays and Subscribed Variables", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-122", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to find the sum of n numbers using array\n# Variable declaration\n\nn = 5\nx = [36,45,52,44,62]\n\nprint \"How many integers ?\",n\nprint \"Enter the 1th value :\",x[0]\nprint \"Enter the 2th value :\",x[1]\nprint \"Enter the 3th value :\",x[2]\nprint \"Enter the 4th value :\",x[3]\nprint \"Enter the 5th value :\",x[4]\n\nsumm = 0 \n\n# Calculation of sum of numbers\nfor i in x:\n summ = summ + i\n \n\nprint \"Sum of all integers =\",summ\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many integers ? 5\nEnter the 1th value : 36\nEnter the 2th value : 45\nEnter the 3th value : 52\nEnter the 4th value : 44\nEnter the 5th value : 62\nSum of all integers = 239\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-123", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to find the biggest of n numbers\n# Variable declaration\n\nn = 5\nx = [25,-228,0,185,36]\n\nprint \"How many numbers ?\",n\nprint \"Enter all those numbers\"\nfor a in x:\n print a,\nprint \n\nbig = x[0]\n\n\nfor i in x:\n if (i > big):\n big = i\n\n\nprint \"%d is the biggest number\" % big ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many numbers ? 5\nEnter all those numbers\n25 -228 0 185 36\n185 is the biggest number\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: Cp-124", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to find the arithmetic mean, variance and standard deviation\n# Variable declaration\n\nn = 6\nx = [3.1,3.8,3.6,4.0,3.4,3.8]\nsumm = 0\nvsum = 0\n\nprint \"How many values ?\",n\nprint \"Enter all values in the list \"\nfor a in x:\n print a,\nprint \n\n# Loop to find sum of all values\n\nfor i in x:\n summ = summ + i\n\nxbar = summ / n\n\n# Loop to find the numerator vsum to find variance\n\nfor i in x:\n vsum = vsum + (i - xbar) * (i - xbar)\n\n\nsigmax = vsum / n\nsd = sigmax ** 0.5\n\nprint \"Arithmetic mean = %0.3f\" % xbar\nprint \"Variance = %0.3f \" % sigmax\nprint \"Standard deviation = %0.3f\" % sd", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many values ? 6\nEnter all values in the list \n3.1 3.8 3.6 4.0 3.4 3.8\nArithmetic mean = 3.617\nVariance = 0.088 \nStandard deviation = 0.297\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-126", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to calculate mean of marks and print list of marks greater than mean\n# Variable declaration\n\nn = 5\nx = [58,63,68,54,48]\nsumm = 0 # Used summ instead of sum since it was a inbuilt function\ni = 0\n\nprint \"How many students ?\",n\nprint \"Enter all the marks \"\nfor a in x:\n print a,\nprint \n\nfor i in x:\n summ = summ + i\n\nmean = float(summ) / n\n\nprint \"Mean = %0.2f\" % mean\nprint \"Marks greater than mean :\",\n\ni = 0\nfor i in x:\n if (i > mean):\n print i,\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many students ? 5\nEnter all the marks \n58 63 68 54 48\nMean = 58.20\nMarks greater than mean : 63 68\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-127", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to find sum of all positive and negative numbers and to find out which is larger in magnitude\n# Variable declaration\nimport math\n\nn = 6\nx = [8,-12,-16,12,-9,5]\npsum = 0\nnsum = 0\n\nprint \"How many values ?\",n\nprint \"Enter all values in the list\"\nfor i in x:\n print i,\nprint \n\n# Loop to calculate sum of positive and negative values\n\nfor i in x:\n if i > 0:\n psum = psum + i\n else:\n nsum = nsum + i\n\nprint \"Sum of positive values = %0.2f\" % psum\nprint \"Sum of negative values = %0.2f\" % nsum\n\nif (psum > abs(nsum)):\n print \"Positive sum is greater in magnitude\"\nelse:\n print \"Negative sum is greater in magnitude\"\n\ndiff = abs(psum) - abs(nsum)\nprint \"Difference in magnitude = %0.2f\" % abs(diff)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many values ? 6\nEnter all values in the list\n8 -12 -16 12 -9 5\nSum of positive values = 25.00\nSum of negative values = -37.00\nNegative sum is greater in magnitude\nDifference in magnitude = 12.00\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-129", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to sort n numbers in ascending order\n# Variable declaration\n\nn = 4\nx = [32,-10,20,5]\ni = 0\n\n\nprint \"How many numbers ?\",n\nprint \"Enter the list of 4 numbers\"\nfor a in x:\n print a,\nprint\n\n# Loop to arrange the numbers in ascending order\n\nwhile i < n-1:\n j = i + 1\n while j < n:\n if x[i] > x[j]:\n temp = x[i]\n x[i] = x[j]\n x[j] = temp\n j = j + 1\n i = i + 1\n\nprint \"Numbers in ascending order \"\n\nfor a in x:\n print a,\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many numbers ? 4\nEnter the list of 4 numbers\n32 -10 20 5\nNumbers in ascending order \n-10 5 20 32\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7 , Page number: CP-131", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "# Program to search the key value and to print it if the search is successful\n# Variable declaration\n\nn = 6\nx = [6,-2,8,3,13,10]\ns = 3\n\nprint \"How many values in the list ?\",n\nprint \"Enter all values in the list\"\nfor i in x:\n print i,\nprint \nprint \"Enter the key value to be searched :\",s\n\n# loop to search key value in the list\n\nfor i in range(n):\n if s == x[i]:\n print s,\" is available in\",i+1,\"th location\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many values in the list ? 6\nEnter all values in the list\n6 -2 8 3 13 10\nEnter the key value to be searched : 3\n3 is available in 4 th location\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8 , Page number: CP-133", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "# Program to sort n numbers using bubble sort and find number of exchanges and passes\n# Variable declaration\n\nn = 4\nx = [6,-2,8,3]\nexchng = 0\n\nprint \"How many numbers?\",n\nprint \"Enter all the numbers in the list\"\nfor i in x:\n print i,\n\nprint\n\nfor i in range(0,n-1):\n for j in range(0,n-i-1):\n if x[j] > x[j+1]:\n temp = x[j]\n x[j] = x[j+1]\n x[j+1] = temp\n exchng = exchng + 1\n \n\nprint \"The sorted list is\"\nfor i in x:\n print i,\n\nprint \n\nprint \"Sorted in\",n-1,\"passes and\",exchng,\"exchanges\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many numbers? 4\nEnter all the numbers in the list\n6 -2 8 3\nThe sorted list is\n-2 3 6 8\nSorted in 3 passes and 3 exchanges\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9 , Page number: CP-135", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to add two matrices\n# Variable declaration\n\na = [[2,-2],\n [0,4]]\nb = [[6,2],\n [4,-5]]\n\nc = [[0,0],\n [0,0]]\n\nm = 2\nn = 2\n\nprint \"How many rows and columns ?\",m,n\nprint \"Enter A matrix\"\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print \n\nprint \"Enter B matrix\"\nfor i in range(m):\n for j in range(n):\n print b[i][j],\n print \n\n# Loop to add two matrices\n\nfor i in range(m):\n for j in range(n):\n c[i][j] = a[i][j] + b[i][j]\n\n\nprint \"Resultant matrix is\"\nfor i in range(m):\n for j in range(n):\n print c[i][j],\n print ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many rows and columns ? 2 2\nEnter A matrix\n2 -2\n0 4\nEnter B matrix\n6 2\n4 -5\nResultant matrix is\n8 0\n4 -1\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10 , Page number: CP-136", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to multiply two matrices\n# Variable declaration\n\nm = 2\nn = 2\nl = 2\na = [[2,-2],\n [0,4]]\nb = [[6,2],\n [4,-5]]\nc = [[0,0],\n [0,0]]\n\nprint \"Enter order of A matrix :\",m,n\nprint \"Enter A matrix\"\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print \n \nprint \"Enter order of B matrix :\",m,n\nprint \"Enter B matrix\"\nfor i in range(m):\n for j in range(n):\n print b[i][j],\n print \n\n# Loop to multiply two matrices\n# iterate through rowa of A\nfor i in range(m):\n # iterate through columns of B\n for j in range(l):\n c[i][j] = 0\n # iterate through rows of B\n for k in range(n):\n c[i][j] = c[i][j] + a[i][k] * b[k][j]\n\n\nprint \"Resultant matrix is\"\n\nfor i in range(m):\n for j in range(n):\n print c[i][j],\n print \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter order of A matrix : 2 2\nEnter A matrix\n2 -2\n0 4\nEnter order of B matrix : 2 2\nEnter B matrix\n6 2\n4 -5\nResultant matrix is\n4 14\n16 -20\n"}], "metadata": {"scrolled": true, "collapsed": false, "trusted": true}}, {"source": "## Example 11 , Page number: CP-138", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "# Program to find and print the transpose of the matrix\n# Variable declaration\n\nm = 2\nn = 3\na = [[-3,6,0],\n [3,2,8]]\nat = [[0,0],\n [0,0],\n [0,0]]\n\nprint \"Enter order of the matrix :\",m,n\nprint \"Enter the matrix values\"\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print \n\n# Loop to calculate transpose\n\nfor i in range(m):\n for j in range(n):\n at[j][i] = a[i][j]\n\nprint \"The transposed matrix is \"\nfor i in range(n):\n for j in range(m):\n print at[i][j],\n print \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter order of the matrix : 2 3\nEnter the matrix values\n-3 6 0\n3 2 8\nThe transposed matrix is \n-3 3\n6 2\n0 8\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 12 ,Page number: CP-139", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "# Program to check whether a given matrix is symmetric or not\n# Variable declaration\n\nm = 3\na = [[5,3,8],\n [3,1,-7],\n [8,-7,4]]\n\nprint \"Enter order of the square matrix :\",m\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print \n\n# Loop to check whether symmetric or not\n\nfor i in range(m):\n flag = 0\n for j in range(m):\n flag = 0\n if a[i][j] == a[j][i]:\n continue\n else:\n flag = 1\n\nif flag == 0:\n print \"The given matrix is a symmetric matrix\"\nelse:\n print \"The given matrix is not a symmetric matrix\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter order of the square matrix : 3\n5 3 8\n3 1 -7\n8 -7 4\nThe given matrix is a symmetric matrix\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 13 , Page number: CP-141", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to find the trace of a given square matrix\n# Variable dclaration\n\nm = 3\na = [[3,2,-1],\n [4,1,8],\n [6,4,2]]\nsumm = 0\n\nprint \"Enter order of the square matrix :\",m\nprint \"Enter the matrix\"\nfor i in range(m):\n for j in range(m):\n print a[i][j], \n print \n\n# Loop to find trace\nfor i in range(m):\n summ = summ + a[i][i]\n\nprint \"Trace of the matrix =\",summ ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter order of the square matrix : 3\nEnter the matrix\n3 2 -1\n4 1 8\n6 4 2\nTrace of the matrix = 6\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_07_String_Manipulations_in_C.ipynb b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_07_String_Manipulations_in_C.ipynb
new file mode 100755
index 00000000..9a0df3cb
--- /dev/null
+++ b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_07_String_Manipulations_in_C.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 07: String Manipulations in C", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-148", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to count the occurence of a particular in a string\n# Variable declaration\n\nst = \"MISSISSIPPI\"\nch = \"S\"\ncount = 0\n\nprint \"Enter the string :\",st\nprint \"Which character to be counted ?\",ch\n\n# Loop to check occurrence of aa character\n\nl = len(st)\n\nfor i in st:\n if i == ch:\n count = count + 1\n\nprint \"The character \" + ch + \" occurs %d times\" % count ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the string : MISSISSIPPI\nWhich character to be counted ? S\nThe character S occurs 4 times\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-149", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to count the number of vowels in a sentence\n# Variable declaration\n\nst = \"This is a book\"\ncount = 0\n\nprint \"Enter the sentence :\"\nprint st\n\n# Loop to count the vowels in the string\n\nfor i in st:\n if i == \"A\":\n count = count + 1\n elif i == \"E\":\n count = count + 1\n elif i == \"I\":\n count = count + 1\n elif i == \"O\":\n count = count + 1\n elif i == \"U\":\n count = count + 1\n elif i == \"a\":\n count = count + 1\n elif i == \"e\":\n count = count + 1\n elif i == \"i\":\n count = count + 1\n elif i == \"o\":\n count = count + 1\n elif i == \"u\":\n count = count + 1\n\nprint \"%d vowels are present in the sentence\" % count\n \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the sentence :\nThis is a book\n5 vowels are present in the sentence\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: CP-150", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to test whether a given string is a palindrome or not\n# Variable declaration\n\nst = \"HYDERABAD\"\nrst = \"\"\ni = 0\nj = len(st) - 1\n\nprint \"Enter the string :\",st\n\n# Palindrome or not \n\nrst = reversed(st)\n\nif list(st) == list(rst):\n print \"%s is a palindrome string \" % st\nelse:\n print \"%s is not a palindrome string \" % st", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the string : HYDERABAD\nHYDERABAD is not a palindrome string \n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-152", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to conctenate two strings\n# Variable declaration\n\nst1 = \"NEW \"\nst2 = \"DELHI\"\n\n# input of two strings to be concatenated\n\nprint \"Enter first string :\",st1\nprint \"Enter second string :\",st2\n\n# concatenation of two strings\nst = st1 + st2\n\nprint \"Resultant string is \",st ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter first string : NEW \nEnter second string : DELHI\nResultant string is NEW DELHI\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-154", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to compare two strings\n# Variable declaration\n\nst1 = \"ALPHA\"\nst2 = \"BETA\"\n\nprint \"Enter string 1:\",st1\nprint \"Enter string 2:\",st2\n\n# compare strings\n\nif (cmp(st1,st2)>0):\n print \"%s \" + st1 + \"is alphabetically greater string\"\nelse:\n print st2 + \" is alphabetically greater string\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter string 1: ALPHA\nEnter string 2: BETA\nBETA is alphabetically greater string\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-155", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to sort an array of names in alphabetical order\n# Variable declaration\n\nn = 4\nnames = [\"DEEPAK\",\"SHERIN\",\"SONIKA\",\"ARUN\"]\n\nprint \"How many names ?\",n\nprint \"Enter the 4 names one by one\"\nfor i in names:\n print i\n\n# Loop to arrange names in alphabetical order\n\nfor i in range(0,n-1):\n for j in range(i+1,n):\n if cmp(names[i],names[j])>0:\n \n temp = names[i]\n names[i] = names[j]\n names[j] = temp\n\nprint \"Names in alphabetical order\"\nfor i in names:\n print i", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many names ? 4\nEnter the 4 names one by one\nDEEPAK\nSHERIN\nSONIKA\nARUN\nNames in alphabetical order\nARUN\nDEEPAK\nSHERIN\nSONIKA\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7 , Page number: CP-157", "cell_type": "markdown", "metadata": {}}, {"execution_count": 13, "cell_type": "code", "source": "# Program to convert a line from lower case to upper case\n# Variable declaretion\n\nimport sys\n\nst = ['l','o','g','i','c','a','l',' ','t','h','i','n','k','i','n','g',' ','i','s',' ','a',' ','m','u','s','t',' ','t','o',' ','l','e','a','r','n',' ','p','r','o','g','r','a','m','m','i','n','g']\n\nprint \"Enter a sentence :\"\nfor i in st:\n print i,\nprint \nprint \"The converted upper case string is\"\n# loop to convert lower case alphabet to upper case text\nfor i in range(len(st)):\n if st[i] >= 'a' and st[i] <= 'z':\n st[i] = chr(ord(st[i])-32)\n\n\n sys.stdout.write(st[i])", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a sentence :\nl o g i c a l t h i n k i n g i s a m u s t t o l e a r n p r o g r a m m i n g\nThe converted upper case string is\nLOGICAL THINKING IS A MUST TO LEARN PROGRAMMING"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9 , Page number: CP-160", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "# Program to read a text and to omit al occurrences of a particular word\n# Variable declartion\n\nst = \"TO ACCESS THE NAME OF THE CITY IN THE LIST\"\ni = 0\nomit = \"THE\"\nl = len(st)\nj = 0\nword = []\nnewst = \"\"\nonesps = \"\"\nprint \"Enter a sentence :\"\nprint st\nprint \"Enter word to omit :\",omit\n\n# loop to omit the given word\n\nfor i in range(l):\n ch = i\n if ch == ' ':\n for j in word:\n j = \" \" \n if j == omit:\n newst = j\n newst = onesps\n j = \" \"\n j = 0\n else:\n j = ch\n j = j + 1\n i = i + 1\n\nprint \"After omiting the word \" + omit\nprint newst\nprint \"Press any key to continue\"\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a sentence :\nTO ACCESS THE NAME OF THE CITY IN THE LIST\nEnter word to omit : THE\nAfter omiting the word THE\n\nPress any key to continue\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10 , Page number: CP-161", "cell_type": "markdown", "metadata": {}}, {"execution_count": 15, "cell_type": "code", "source": "# Program to calculate the amount to be paid for the telegram\n# Variable declaration\n\ncount = 0\nst = \"Congratulations on your success in Examinations.\"\nl = len(st)\n\nprint \"Type the sentence for Telegram\"\nprint st\n\n# loop to count number of words\n\nfor i in range(l):\n if st[i] == '?':\n count = count + 1\n\nif count <= 10:\n amt = 5\nelse:\n amt = 5 + (count - 10) * 1.25\n\nprint \"Amount to be paid for telegram = Rs.%0.2f\" % amt ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Type the sentence for Telegram\nCongratulations on your success in Examinations.\nAmount to be paid for telegram = Rs.5.00\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 11 , Page number: CP-163", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "# Program to count number of lines,words and characters\n# Variable declaration\n\ntxt = \"What is a string? How do you initialize it? Explain with example.$\"\nst = \"\"\ni = 0\nlns = 0\nwds = 0\nchs = 0\n\nprint \"Enter the text, type $ at end.\"\nprint txt\n\n# loop to count lines,words and characters in text\n\nwhile txt[i] != '$':\n # switch case statements\n if txt[i] == ' ':\n wds = wds + 1\n chs = chs + 1\n elif txt[i] == '.':\n wds = wds + 1\n lns = lns + 1\n chs = chs + 1\n elif txt[i] == '?':\n lns = lns + 1\n else: # default\n chs = chs + 1\n\n i = i + 1\n\nprint \"Number of char (incl. blanks) =\",chs\nprint \"Number of words =\",wds\nprint \"Number of lines =\",lns\n\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the text, type $ at end.\nWhat is a string? How do you initialize it? Explain with example.$\nNumber of char (incl. blanks) = 63\nNumber of words = 12\nNumber of lines = 3\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_08_Functins_in_C.ipynb b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_08_Functins_in_C.ipynb
new file mode 100755
index 00000000..90388fc6
--- /dev/null
+++ b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_08_Functins_in_C.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 08: Functions in C", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-173", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to write a function to find factorial and use it to find nCr\n# Variable declaration\n\nn = 5\nr = 3\n\nprint \"Enter value to n and r :\",n,r\n\n# function subprogram to find factorial\n\ndef fact(k):\n p = 1\n for i in range(1,k+1):\n p = p * i\n return p\n\n\nncr = fact(n) / (fact(r) * fact(n-r))\n\n\nprint \"Value of nCr =\",ncr", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to n and r : 5 3\nValue of nCr = 10\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-174", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to find the biggest of given three values using function and use it to find total marks of the student\n# Variable declaration\n\nt1 = 62\nt2 = 70\nt3 = 58\na1 = 17\na2 = 21\na3 = 23\n\nprint \"Enter three test scores :\",t1,t2,t3\nprint \"Enter three assignment scores :\",a1,a2,a3\n\n# function to find biggest of three values\n\ndef big(a,b,c):\n if a > b:\n if a > c:\n return a\n else:\n return c\n elif b > c:\n return b\n else:\n return c\n\ntotal = big(t1,t2,t3) + big(a1,a2,a3)\n\nprint \"Total marks =\",total", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter three test scores : 62 70 58\nEnter three assignment scores : 17 21 23\nTotal marks = 93\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: CP-176", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to create a function to compute the cos(x) series upto 15 terms\n# Variable declaration\n\nx = 0\n\nprint \"----------------------------------\"\nprint \" x in degrees cos(x) \"\nprint \"----------------------------------\"\n\n# function for computing cosine function\n\ndef cosine(x):\n s = 0\n i = 0\n term = 1\n x = x * (3.14) / 180\n k = 1\n # loop to find summation of 15 terms\n while k <= 15:\n s = s + term\n term = term * x * x * (-1) / ((i + 1) * (i + 2))\n i = i + 2\n k = k + 1\n return s\n\n\n# calling function\n\nwhile x <= 180:\n print \" %d \" % x,\" %0.2f \"%cosine(x)\n x = x + 30\n\nprint \"-----------------------------------\" ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "----------------------------------\n x in degrees cos(x) \n----------------------------------\n 0 1.00 \n 30 0.87 \n 60 0.50 \n 90 0.00 \n 120 -0.50 \n 150 -0.87 \n 180 -1.00 \n-----------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-177", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to find GCD of two integers\n# Variable declaration\n\na = 45\nb = 27\nc = 81\n\nprint \"Enter three integers :\",a,b,c\n\ndef gcd(x,y):\n if x >= y:\n nr = x\n dr = y\n else:\n nr = y\n dr = x\n r = nr % dr\n while r != 0:\n nr = dr\n dr = r\n r = nr % dr\n\n return dr\n\nd1 = gcd(a,b)\nd2 = gcd(a,c)\nd3 = gcd(b,c)\n\nif d1 == d2:\n if d1 == d3:\n print \"Greatest common divisor is\",d1\n else:\n print \"Greatest common divisor is \",gcd(d1,d3)\nelse:\n print \"Greatest common divisr is\",gcd(d1,d2)\n\n\nprint \"Press any key to continue. . .\" ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter three integers : 45 27 81\nGreatest common divisor is 9\nPress any key to continue. . .\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-178", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to reverse the given integer\n# Variable declaration\n\nn = 2846\n\nprint \"Enter the integer :\",n\n\n# function to reverse an integer\n\ndef reverse(n):\n rn = 0\n while n > 0:\n r = n % 10\n rn = rn * 10 + r\n n = n /10\n return rn\n\n\n# call the function to print the reverse integer\n\nprint n,\"is reversed as \",reverse(n)\nprint \"Press any key to continue. . .\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the integer : 2846\n2846 is reversed as 6482\nPress any key to continue. . .\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-179", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to compare two strings S1 and S2 and return the result 0,1,-1\n# Variable declaration\n\ns1 = \"MUMBAI\"\ns2 = \"MYSORE\"\n\nprint \"Enter the first string :\",s1\nprint \"Enter the second string :\",s2\n\n\n# function to compare the strings\n\ndef compare(s1,s2):\n if cmp(s1,s2) == 0:\n return 0\n if cmp(s1,s2) > 0:\n return 1\n if cmp(s1,s2) < 0:\n return -1\n\n# call the function to print the result\n\nprint \"The result is \", compare(s1,s2)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the first string : MUMBAI\nEnter the second string : MYSORE\nThe result is -1\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 7 , Page number: CP-181", "cell_type": "markdown", "metadata": {}}, {"execution_count": 7, "cell_type": "code", "source": "# Program to find the arithmetic mean of n values using a function\n# Variable declaration\n\nn = 6\nx = [3.1,3.8,3.6,4.0,3.4,3.8]\n\nprint \"How many values ?\",n\nprint \"Enter all values\"\nfor i in x:\n print i,\nprint \n# function to find arithmetic mean\n\ndef amean(x,n):\n s = 0\n for i in range(n):\n s = s + x[i]\n return (s/n)\n\n# call function to print arithmetic mean\n\nprint \"Arithmetic mean = %0.2f\" % amean(x,n)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many values ? 6\nEnter all values\n3.1 3.8 3.6 4.0 3.4 3.8\nArithmetic mean = 3.62\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 8 , Page number: CP-182", "cell_type": "markdown", "metadata": {}}, {"execution_count": 8, "cell_type": "code", "source": "# Program to read a matrix of order m x n and print the sum of all elements using functions\n# Variable declaration\n\nm = 3\nn = 2\na = [[2,3,4],\n [2,0,1]]\n\n\nprint \"How many rows and columns :\",m,n\nprint \"Enter the matrix values\"\nfor i in range(n):\n for j in range(m):\n print a[i][j],\n print \n\n# function to add all elements in the matrix\ndef elem_sum(a,m,n):\n i = 0\n j = 0\n s = 0\n for i in range(n):\n for j in range(m):\n s = s + a[i][j]\n j = j + 1\n i = i + 1 \n return s\n\n# call function to print the result\n\nprint \"Sum of all elements in the matrix =\",\nprint elem_sum(a,m,n)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many rows and columns : 3 2\nEnter the matrix values\n2 3 4\n2 0 1\nSum of all elements in the matrix = 12\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 9 , Page number: CP-183", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "# Program to reverse a string\n# Variable declaration\n\nst = \"NEW DELHI\"\nprint \"Enter a string :\",st\ndef reverse(st):\n rst = \"\"\n for i in range(0 ,len(st)):\n rst += st[(len(st) -1) - i]\n return rst\n\nprint st,\"is reversed as \",\nprint reverse(st)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter a string : NEW DELHI\nNEW DELHI is reversed as IHLED WEN\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 10 , Page number: CP-184", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "# Program to apply binary search to set of N numbers using a function\n# Variable declaration\n\nn = 10\nx = [-3,8,13,19,21,25,26,29,35,42]\ns = 19\n\n\nprint \"How many numbers ?\",n\nprint \"Enter all numbers in the list\"\nfor a in x:\n print a,\nprint \nprint \"Enter the number to be searched :\",s\n\n# function to search the number\n\ndef bi_search(x,n,s):\n flag = 0\n start = 0\n end = n\n while start < end and flag ==0:\n mid = (start + end) / 2\n if x[mid] > s:\n end = mid\n elif x[mid] < s:\n start = mid + 1\n else:\n flag = 1\n return flag\n\n# calling the function\n\nif bi_search(x,n,s):\n print \"The number\",s,\"is present in the list\"\nelse:\n print \"The number\",s,\"is not present in list\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many numbers ? 10\nEnter all numbers in the list\n-3 8 13 19 21 25 26 29 35 42\nEnter the number to be searched : 19\nThe number 19 is present in the list\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 11 , Page number: CP-187", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "# Program to find factorial of a given number using recursive function\n# Variable declaration\n\nn = 5\nr = 3\n\nprint \"Enter the values to n and r :\",n,r\n\n# recursive function to find factorial\n\ndef fact(k):\n if k ==1:\n return 1\n else:\n return (k * fact(k-1))\n\nncr = fact(n)/(fact(r) * fact(n-r))\nprint \"Value of nCr =\",ncr ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter the values to n and r : 5 3\nValue of nCr = 10\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 12 , Page number: CP-188", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "# Program to compute the value of x power n using a recursive function\n# Variable declaration\n\nx = 4.20\nn = 3\n\nprint \"Enter value to x :\",x\nprint \"Enter its power :\",n\n\n# recursive function to find x rise to n\n\ndef power(x,n):\n if n == 1:\n return x\n else:\n return (x * power(x,n-1))\n\n\nprint \"%0.2f\" %x,\"raise to \",n,\"is %0.2f\" % power(x,n) ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter value to x : 4.2\nEnter its power : 3\n4.20 raise to 3 is 74.09\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 13 , Page number: CP-189", "cell_type": "markdown", "metadata": {}}, {"execution_count": 13, "cell_type": "code", "source": "# Program to display first n terms of the fibonacci series using recursive function\n\n# Variable declaration\n\nn = 10\nt1 = 0\nt2 = 1\ni = 0\ncount = 2\n\n# recursive function to print the terms in series\ndef fibo(t1,t2):\n global count\n if (count >= n):\n return\n else:\n t3 = t1 + t2\n print t3,\n count = count + 1\n t1 = t2\n t2 = t3\n return fibo(t1,t2)\n \n\n\nprint \"How many terms to be printed ?\",n\nprint \"The first\",n,\"terms in Fibonacci series are\"\nprint t1,\nprint t2,\n\nfibo(t1,t2)", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many terms to be printed ? 10\nThe first 10 terms in Fibonacci series are\n0 1 1 2 3 5 8 13 21 34\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 14 , Page number: CP-196", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "# Program to add two matrices of order m x n and to print the resultant values\n# Variable declaration\n\nm = 2\nn = 2\na = [[2,-2],\n [0,4]]\nb = [[6,2],\n [4,-5]]\nc = [[0,0],\n [0,0]]\n\nprint \"How many rows and columns ?\",m,n\nprint \"Enter A matrix value\"\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print \nprint \"Enter B matrix values\"\nfor i in range(m):\n for j in range(n):\n print b[i][j],\n print \n\n# function to add matrices\ndef matadd():\n for i in range(m):\n for j in range(n):\n c[i][j] = a[i][j] + b[i][j]\n\n\n\n# call function\nmatadd()\nprint \"Resultant matrix is\"\nfor i in range(m):\n for j in range(n):\n print c[i][j],\n print \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many rows and columns ? 2 2\nEnter A matrix value\n2 -2\n0 4\nEnter B matrix values\n6 2\n4 -5\nResultant matrix is\n8 0\n4 -1\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 15 , Page number: CP-197", "cell_type": "markdown", "metadata": {}}, {"execution_count": 15, "cell_type": "code", "source": "# Program to multiply A matrix of order of m x n with B matrix of order n x l and print the resultant matrix\n# Variable declaration\n\na = [[2,-2],\n [0,4]]\nb = [[6,2,],\n [4,-5]]\nc = [[0,0],\n [0,0]]\n\nm = 2\nn = 2\nl = 2\n\nprint \"Enter order of A matrix (m x n) :\",m,n\nprint \"Enter A matrix values\"\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print\n \nprint \"Enter order of B matrix (n x l) :\",n,l\nprint \"Enter B matrix values\"\nfor i in range(m):\n for j in range(n):\n print b[i][j],\n print \n \n\n# function to multiply matrices\n\ndef matmul():\n for i in range(m):\n for j in range(l):\n c[i][j] = 0\n for k in range(n):\n c[i][j] = c[i][j] + a[i][k] * b[k][j]\n return c\n\n# call function\nmatmul()\nprint \"Resultant matix is\"\nfor i in range(m):\n for j in range(n):\n print c[i][j],\n print\n\n\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter order of A matrix (m x n) : 2 2\nEnter A matrix values\n2 -2\n0 4\nEnter order of B matrix (n x l) : 2 2\nEnter B matrix values\n6 2\n4 -5\nResultant matix is\n4 14\n16 -20\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 16 , Page number: CP-199", "cell_type": "markdown", "metadata": {}}, {"execution_count": 16, "cell_type": "code", "source": "# Program to transpose a matrix of order m x n\n# Variable declaration\n\na = [[-3,6,0],\n [3,2,8]]\nat = [[0,0],\n [0,0],\n [0,0]]\nm = 2\nn = 3\nch = \"y\"\n\nprint \"How many rows and columns ?\",m,n\nprint \"Enter the matrix values\"\nfor i in range(m):\n for j in range(n):\n print a[i][j],\n print \n \n\n# function to transpose a matrix\n\ndef transpose(a,at,m,n):\n for i in range(m):\n for j in range(n):\n at[j][i] = a[i][j]\n return at\n\nwhile ch == 'y' or ch == 'Y' :\n # call function to transpose the matrix\n transpose(a,at,m,n)\n print \"Transpose of the matrix is\"\n for i in range(n):\n for j in range(m):\n print at[i][j],\n print\n ch = \"N\"\n print \"Press y to continue\"\n print \" any other key to stop.\",ch", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many rows and columns ? 2 3\nEnter the matrix values\n-3 6 0\n3 2 8\nTranspose of the matrix is\n-3 3\n6 2\n0 8\nPress y to continue\n any other key to stop. N\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 17 , Page number: CP-200", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "# Program to create a function to sort the elements of an array in ascending order\n# Variable declaration\n\nn = 4\nx = [32,-10,20,5]\n\nprint \"How many numbers ?\",n\nprint \"Enter the list of values\"\nfor a in x:\n print a,\nprint \n\n# function to sort the numbers\ndef sort(x,n):\n for i in range(n-1):\n for j in range(i+1,n):\n if x[i] > x[j]:\n temp = x[i]\n x[i] = x[j]\n x[j] = temp\n return x\n\n# call function to sort the numbers\nsort(x,n)\nprint \"The sorted list is\"\nfor a in x:\n print a,\nprint\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many numbers ? 4\nEnter the list of values\n32 -10 20 5\nThe sorted list is\n-10 5 20 32\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_09_Structures_and_Unions.ipynb b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_09_Structures_and_Unions.ipynb
new file mode 100755
index 00000000..30accc65
--- /dev/null
+++ b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_09_Structures_and_Unions.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 09: Structures and Unions", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-211", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to display student details\n# class declaration instead of a structure\n\nclass student:\n rno = 0\n sname = \"\"\n tot = 0\n\n# class object variable\n\nx = student()\nx.rno = 20147\nx.sname = \"PRADEEP\"\nx.tot = 64\n\nprint \"Enter roll number, name and total marks\"\nprint x.rno,x.sname,x.tot\nprint \" Details entered are\"\nprint \"Roll No. :\",x.rno\nprint \"Student name :\",x.sname\nprint \"Total marks :\",x.tot\nprint \"Press any key to continue. . .\"", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Enter roll number, name and total marks\n20147 PRADEEP 64\n Details entered are\nRoll No. : 20147\nStudent name : PRADEEP\nTotal marks : 64\nPress any key to continue. . .\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2 , Page number: CP-212", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Program to input student details and print the marks of a specified student as output\n\n# class declaration for structure\n\nclass student:\n def __init__(self,rno,sname,tot):\n self.rno = rno\n self.sname = sname\n self.tot = tot\n \n# variable declaration\n\nch = \"y\"\nn = 3\n\n# details of n students\nstd = []\nstd.append(student(20201,\"ARUN\",78))\nstd.append(student(20208,\"DEEPAK\",69))\nstd.append(student(20223,\"SUSMITHA\",88))\n\nprint \"How many students ?\",n\nprint \"Roll number ?\",std[0].rno\nprint \"Name ?\",std[0].sname\nprint \"Total marks ?\",std[0].tot\nprint \"Roll number ?\",std[1].rno\nprint \"Name ?\",std[1].sname\nprint \"Total marks ?\",std[1].tot\nprint \"Roll number ?\",std[2].rno\nprint \"Name ?\",std[2].sname\nprint \"Total marks ?\",std[2].tot\nprint \n\n\n# To display marks of the student\nwhile ch == \"y\" or ch == \"Y\":\n temp = 20208\n print \"Enter student roll number to display marks :\",temp\n print \n flag = 0\n #loop to search and display details\n for i in range(3):\n if flag == 0:\n if std[i].rno == temp:\n print \"Marks obtained by \",std[i].rno,std[i].sname\n print \"Total :\",std[i].tot\n flag = 1\n if flag == 0:\n print temp,\" is not present in the list \"\n \n ch = \"n\" \n print \"press y - to continue\"\n print \" any other key to stop.\",ch\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many students ? 3\nRoll number ? 20201\nName ? ARUN\nTotal marks ? 78\nRoll number ? 20208\nName ? DEEPAK\nTotal marks ? 69\nRoll number ? 20223\nName ? SUSMITHA\nTotal marks ? 88\n\nEnter student roll number to display marks : 20208\n\nMarks obtained by 20208 DEEPAK\nTotal : 69\npress y - to continue\n any other key to stop. n\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 3 , Page number: CP-214", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to declare a structure for student details and display list of students who obtained more than 75 marks\n\n# class for student structure\n\nclass student:\n def __init__(self,rno,sname,tot):\n self.rno = rno\n self.sname = sname\n self.tot = tot\n\nstd = []\nstd.append(student(30401,\"ANAND\",59))\nstd.append(student(30404,\"NIRMAL\",64))\nstd.append(student(30428,\"ISWARYA\",82))\nstd.append(student(30432,\"VIVEKA\",79))\n\nn = 4\nprint \"How many students ?\",n\nprint \"Roll Number ?\",std[0].rno\nprint \"Name ?\",std[0].sname\nprint \"Total marks ?\",std[0].tot\nprint \"Roll Number ?\",std[1].rno\nprint \"Name ?\",std[1].sname\nprint \"Total marks ?\",std[1].tot\nprint \"Roll Number ?\",std[2].rno\nprint \"Name ?\",std[2].sname\nprint \"Total marks ?\",std[2].tot\nprint \"Roll Number ?\",std[3].rno\nprint \"Name ?\",std[3].sname\nprint \"Total marks ?\",std[3].tot\nprint \n\n\nprint \"----------------------------------------------------\"\nprint \" Roll No. Name Total marks \"\nprint \"----------------------------------------------------\"\nfor i in range(n):\n if std[i].tot >= 75:\n print \" \",std[i].rno,\" \",std[i].sname,\" \",std[i].tot\n\nprint \"----------------------------------------------------\"\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many students ? 4\nRoll Number ? 30401\nName ? ANAND\nTotal marks ? 59\nRoll Number ? 30404\nName ? NIRMAL\nTotal marks ? 64\nRoll Number ? 30428\nName ? ISWARYA\nTotal marks ? 82\nRoll Number ? 30432\nName ? VIVEKA\nTotal marks ? 79\n\n----------------------------------------------------\n Roll No. Name Total marks \n----------------------------------------------------\n 30428 ISWARYA 82\n 30432 VIVEKA 79\n----------------------------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 4 , Page number: CP-216", "cell_type": "markdown", "metadata": {}}, {"execution_count": 5, "cell_type": "code", "source": "# Program to store employee information and to compute employee's pay\n\nimport math\n# class declaration for employee\nclass employee:\n def __init__(self,eno,ename,epay,jdate):\n self.eno = eno\n self.ename = ename\n self.epay = epay\n self.jdate = jdate\n\nemploys = []\nemploys.append(employee(20101,\"ASHIKA\",1000,\"31/04/2001\"))\nemploys.append(employee(20182,\"ASHWIN\",6000,\"11/12/1995\"))\nemploys.append(employee(20204,\"PRAVEEN\",3000,\"18/06/1994\"))\n\nn = 3\n\nprint \"Employee No. ?\",employs[0].eno\nprint \"Name ?\",employs[0].ename\nprint \"Existing date ?\",employs[0].epay\nprint \"Joinin date ?\",employs[0].jdate\nprint \nprint \"Press y- to continue any other key to stop. y\"\nprint \"Employee No. ?\",employs[1].eno\nprint \"Name ?\",employs[1].ename\nprint \"Existing date ?\",employs[1].epay\nprint \"Joinin date ?\",employs[1].jdate\nprint\nprint \"Press y- to continue any other key to stop. y\"\nprint \"Employee No. ?\",employs[2].eno\nprint \"Name ?\",employs[2].ename\nprint \"Existing date ?\",employs[2].epay\nprint \"Joinin date ?\",employs[2].jdate\nprint\nprint \"Press y- to continue any other key to stop. N\"\nprint\nprint n,\" records are entered\"\nprint \"Press any key to print the revised salary list\"\nprint \n\n\n\ndef revise(temp):\n if temp <= 2000:\n temp = int(temp + math.ceil(temp * 0.15))\n return temp\n elif temp <= 5000:\n temp = int(temp + temp * 0.10)\n return temp\n else:\n return temp\n\n \n# loop to increment salary\nfor i in range(n):\n employs[i].epay = revise(employs[i].epay)\n\n \n\n\n# loop to print revised salary list\nprint \" Employees Revised Pay List \"\nprint \"---------------------------------------------------------\"\nprint \" S.No. Number Name Joining date Pay \"\nprint \"---------------------------------------------------------\"\n\nfor i in range(n):\n print \" \",i+1,\" \",employs[i].eno,\" \",employs[i].ename,\" \",employs[i].jdate,\" \",employs[i].epay\n\nprint \"---------------------------------------------------------\" \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Employee No. ? 20101\nName ? ASHIKA\nExisting date ? 1000\nJoinin date ? 31/04/2001\n\nPress y- to continue any other key to stop. y\nEmployee No. ? 20182\nName ? ASHWIN\nExisting date ? 6000\nJoinin date ? 11/12/1995\n\nPress y- to continue any other key to stop. y\nEmployee No. ? 20204\nName ? PRAVEEN\nExisting date ? 3000\nJoinin date ? 18/06/1994\n\nPress y- to continue any other key to stop. N\n\n3 records are entered\nPress any key to print the revised salary list\n\n Employees Revised Pay List \n---------------------------------------------------------\n S.No. Number Name Joining date Pay \n---------------------------------------------------------\n 1 20101 ASHIKA 31/04/2001 1150\n 2 20182 ASHWIN 11/12/1995 6000\n 3 20204 PRAVEEN 18/06/1994 3300\n---------------------------------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 5 , Page number: CP-219", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "# Program to store cricket details and to display a team-wise list with batting average\n\n# class for cricket structure\n\nclass cricket:\n def __init__(self,pname,tname,bavg):\n self.pname = pname\n self.tname = tname\n self.bavg = bavg\n\nn = 6\nprobable = []\nprobable.append(cricket(\"KUMBLE\",\"KARNATAKA\",22))\nprobable.append(cricket(\"KAMBLI\",\"MUMBAI\",39))\nprobable.append(cricket(\"SRIKANTH\",\"TAMILNADU\",52))\nprobable.append(cricket(\"SACHIM\",\"MUMBAI\",69))\nprobable.append(cricket(\"RAHUL\",\"KARNATAKA\",57))\nprobable.append(cricket(\"RAMESH\",\"TAMILNADU\",48))\n\nprint \"How many players ?\",n\nprint\nprint \"Player name ?\",probable[0].pname\nprint \"Which team ?\",probable[0].tname\nprint \"Batting average ?\",probable[0].bavg\nprint \"Player name ?\",probable[1].pname\nprint \"Which team ?\",probable[1].tname\nprint \"Batting average ?\",probable[1].bavg\nprint \"Player name ?\",probable[2].pname\nprint \"Which team ?\",probable[2].tname\nprint \"Batting average ?\",probable[2].bavg\nprint \"Player name ?\",probable[3].pname\nprint \"Which team ?\",probable[3].tname\nprint \"Batting average ?\",probable[3].bavg\nprint \"Player name ?\",probable[4].pname\nprint \"Which team ?\",probable[4].tname\nprint \"Batting average ?\",probable[4].bavg\nprint \"Player name ?\",probable[5].pname\nprint \"Which team ?\",probable[5].tname\nprint \"Batting average ?\",probable[5].bavg\nprint\nprint \nj = 0\nteams = []\nteams.append(probable[0].tname)\nj = j + 1\nfor i in range(n):\n flag = 0\n for k in range(j):\n if flag == 0:\n if probable[i].tname == teams[k]:\n flag = 1\n if flag == 0 :\n teams.append(probable[i].tname)\n j = j + 1\n\n# loop to print team-wise list\n\nfor k in range(3):\n print \" \",teams[k]\n print \"---------------------------------------------\"\n for i in range(n):\n if probable[i].tname == teams[k]:\n print \" \",probable[i].pname,\" \",probable[i].bavg\n print \"---------------------------------------------\" \n\n\n\n\n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "How many players ? 6\n\nPlayer name ? KUMBLE\nWhich team ? KARNATAKA\nBatting average ? 22\nPlayer name ? KAMBLI\nWhich team ? MUMBAI\nBatting average ? 39\nPlayer name ? SRIKANTH\nWhich team ? TAMILNADU\nBatting average ? 52\nPlayer name ? SACHIM\nWhich team ? MUMBAI\nBatting average ? 69\nPlayer name ? RAHUL\nWhich team ? KARNATAKA\nBatting average ? 57\nPlayer name ? RAMESH\nWhich team ? TAMILNADU\nBatting average ? 48\n\n\n KARNATAKA\n---------------------------------------------\n KUMBLE 22\n RAHUL 57\n---------------------------------------------\n MUMBAI\n---------------------------------------------\n KAMBLI 39\n SACHIM 69\n---------------------------------------------\n TAMILNADU\n---------------------------------------------\n SRIKANTH 52\n RAMESH 48\n---------------------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 6 , Page number: CP-235", "cell_type": "markdown", "metadata": {}}, {"execution_count": 6, "cell_type": "code", "source": "# Program to illustrate the use of union using integer,string and float\n\nclass student:\n def __init__(self,roll_no,sname,marks):\n self.roll_no = roll_no\n self.sname = sname\n self.marks = marks\n\nstd = []\nstd.append(student(0,\"AJITH\",0))\nstd.append(student(0,\"RAJU\",0))\nstd.append(student(0,\"VIGNESH\",0))\nstd.append(student(0,\"DIVYA\",0))\n\nch = 2\nprint \"-----------------------------\"\nprint \" Main menu \"\nprint \"-----------------------------\"\nprint \"Press 1 to enter roll numbers\"\nprint \" 2 to enter names \"\nprint \" 3 to enter marks \"\nprint \" 4 to stop \"\nprint \nprint \"Enter your choice :\",ch\n\nn = 4\nprint \"How many students?\",n\nfor i in range(n):\n print \" Student name ? \",std[i].sname\n\nprint\nprint \n# display required list\n# switch case\nif ch == 1: #case 1\n print \"------------------------------\"\n print \" Students roll number list \"\n print \"------------------------------\"\n for i in range(n):\n print std[i].roll_no\n print \"-------------------------------\"\nelif ch == 2: # case 2\n print \"------------------------------\"\n print \" Students name list \"\n print \"------------------------------\"\n for i in range(n):\n print std[i].sname\n print \"-------------------------------\"\nelif ch == 3: # case 3\n print \"------------------------------\"\n print \" Students mark list \"\n print \"------------------------------\"\n for i in range(n):\n print \"Student marks\",std[i].roll_no\n print \"-------------------------------\"\n \n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "-----------------------------\n Main menu \n-----------------------------\nPress 1 to enter roll numbers\n 2 to enter names \n 3 to enter marks \n 4 to stop \n\nEnter your choice : 2\nHow many students? 4\n Student name ? AJITH\n Student name ? RAJU\n Student name ? VIGNESH\n Student name ? DIVYA\n\n\n------------------------------\n Students name list \n------------------------------\nAJITH\nRAJU\nVIGNESH\nDIVYA\n-------------------------------\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_11_Files.ipynb b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_11_Files.ipynb
new file mode 100755
index 00000000..a198f1a0
--- /dev/null
+++ b/Computer_Programming_Theory_and_Practice_by_T_Jeyapoovan/Chapter_11_Files.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 11: Files", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1 , Page number: CP-277", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "# Program to create a text file\n\nfp = open(\"sample.txt\",\"w\") # open file in write mode\n\nprint \"Type the text and Press enter key at end.\"\nprint\nprint \"Computer Programming in C language is widely used for Science and Engineering applications\"\n# input data to file\nch = ['Computer ','Programming ','in ','C ','language ','is ','widely ','used ','for ','Science ','and ' ,'Engineering ','applications.']\nfor i in ch:\n fp.write(i)\nfp.close()\n ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Type the text and Press enter key at end.\n\nComputer Programming in C language is widely used for Science and Engineering applications\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 2, Page Number: CP-278 ", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "# Program to read text file and count number of vowels\n\nfp = open(\"sample.txt\",\"r\") # open file in read mode\ncount = 0\nprint \"The Content of the file is:\"\n\nwhile (1): \n ch = fp.read(1)\n if not ch:\n break\n print ch\n # switch statements\n if ch == \"A\" or ch == \"a\": # case 'A' or 'a'\n count = count + 1\n elif ch == \"E\" or ch == \"e\": # case 'E' or 'e'\n count = count + 1\n elif ch == \"I\" or ch == \"i\": # case 'I' or 'i'\n count = count + 1\n elif ch == \"O\" or ch == \"o\": # case 'O' or 'o'\n count = count + 1\n elif ch == \"U\" or ch == \"u\": # case 'U' or 'u'\n count = count + 1\n\n\n\nfp.close() \nprint \"Number of vowels present =\",count \n \n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The Content of the file is:\nC\no\nm\np\nu\nt\ne\nr\n \nP\nr\no\ng\nr\na\nm\nm\ni\nn\ng\n \ni\nn\n \nC\n \nl\na\nn\ng\nu\na\ng\ne\n \ni\ns\n \nw\ni\nd\ne\nl\ny\n \nu\ns\ne\nd\n \nf\no\nr\n \nS\nc\ni\ne\nn\nc\ne\n \na\nn\nd\n \nE\nn\ng\ni\nn\ne\ne\nr\ni\nn\ng\n \na\np\np\nl\ni\nc\na\nt\ni\no\nn\ns\n.\nNumber of vowels present = 31\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/Electrical_Measurements_Measuring_Instruments/screenshots/chap1.png b/Electrical_Measurements_Measuring_Instruments/screenshots/chap1.png
new file mode 100755
index 00000000..c81ba2c7
--- /dev/null
+++ b/Electrical_Measurements_Measuring_Instruments/screenshots/chap1.png
Binary files differ
diff --git a/Electrical_Measurements_Measuring_Instruments/screenshots/chap2.png b/Electrical_Measurements_Measuring_Instruments/screenshots/chap2.png
new file mode 100755
index 00000000..db977114
--- /dev/null
+++ b/Electrical_Measurements_Measuring_Instruments/screenshots/chap2.png
Binary files differ
diff --git a/Electrical_Measurements_Measuring_Instruments/screenshots/chap4.png b/Electrical_Measurements_Measuring_Instruments/screenshots/chap4.png
new file mode 100755
index 00000000..01cb5618
--- /dev/null
+++ b/Electrical_Measurements_Measuring_Instruments/screenshots/chap4.png
Binary files differ
diff --git a/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter1.ipynb b/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter1.ipynb
new file mode 100755
index 00000000..fdb0119c
--- /dev/null
+++ b/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter1.ipynb
@@ -0,0 +1,548 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 1 - Philosophy of Measurement"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1 - pg 33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "arithmetic mean is (V)= 100.0\n",
+ "average deviation is (V)= 0.084\n",
+ "standard deviation is (V)= 0.1192\n",
+ "probable error is (V)= 0.0804\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Example 1.1:#ARITHEMATIC MEAN,AVERAGE DEVIATION ,STANDARD DEVIATION AND PROBABLE ERROR\n",
+ "#calculate the ARITHEMATIC MEAN,AVERAGE DEVIATION ,STANDARD DEVIATION AND PROBABLE ERROR\n",
+ "#given\n",
+ "import math, numpy\n",
+ "T=numpy.array([99.7,99.8,99.9,100,100.1,100.2,100.3]);#VOLTS\n",
+ "f=numpy.array([2,8,20,40,21,6,3]);#frequency of occurence\n",
+ "q=numpy.array([T[0]*f[0],T[1]*f[1],T[2]*f[2],T[3]*f[3],T[4]*f[4],T[5]*f[5],T[6]*f[6]]);#\n",
+ "#calculations\n",
+ "AM=(q[0]+q[1]+q[2]+q[3]+q[4]+q[5]+q[6])/100;#arithematic mean in mm\n",
+ "qb=numpy.zeros(7)\n",
+ "for i in range(0,7):\n",
+ " qb[i]= T[i]-AM\n",
+ "\n",
+ "Q= numpy.array([qb[0],qb[1],qb[2],qb[3],qb[4],qb[5],qb[6]]);#\n",
+ "AV=(-qb[0]*f[0]-qb[1]*f[1]-qb[2]*f[2]-qb[3]*f[3]+qb[4]*f[4]+qb[5]*f[5]+qb[6]*f[6])/100;#\n",
+ "SD=math.sqrt(((qb[0]**2*f[0])+(qb[1]**2*f[1])+(qb[2]**2*f[2])+(qb[3]**2*f[3])+(qb[4]**2*f[4])+(qb[5]**2*f[5])+(qb[6]**2*f[6]))/100);#standard deviation\n",
+ "r1= 0.6745*SD;#PROBABLE ERROR OF ONE READING\n",
+ "#results\n",
+ "print\"arithmetic mean is (V)=\",AM\n",
+ "print\"average deviation is (V)=\",AV\n",
+ "print\"standard deviation is (V)=\",round(SD,4)\n",
+ "print\"probable error is (V)=\",round(r1,4)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2 - pg 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "when current reading is 5mA\n",
+ "apparent resistance in kilo ohms is 20.0\n",
+ "percentage gross error is 13.33\n",
+ "when current reading is 50mA\n",
+ "apparent resistance in kilo ohms is 2.0\n",
+ "percentage gross error is 1.33\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Example 1.2:#APPRABET RESISTANCE AND PERCENTAGE GROSS ERROR\n",
+ "#calculate the APPARENT RESISTANCE AND PERCENTAGE GROSS ERROR\n",
+ "#given\n",
+ "print\"when current reading is 5mA\"\n",
+ "vr=100.;#voltmeter reading\n",
+ "ir=5.;#mA\n",
+ "#calculations and results\n",
+ "rt=vr/(ir);#in kilo ohms\n",
+ "print\"apparent resistance in kilo ohms is\",rt\n",
+ "vm=150.;#range of voltmeter\n",
+ "s=1.;#kilo ohms per volts sensivity\n",
+ "rv=s*vm;#kilo ohms\n",
+ "rx=((rt*rv)/(rv-rt));#kilo ohms\n",
+ "ge=((rx-rt)/rx)*100;#percentage gross error\n",
+ "print\"percentage gross error is\",round(ge,2)\n",
+ "print\"when current reading is 50mA\"\n",
+ "vr=100.;#voltmeter reading\n",
+ "ir1=50.;#mA\n",
+ "rt1=vr/(ir1);#in kilo ohms\n",
+ "print\"apparent resistance in kilo ohms is\",rt1\n",
+ "vm=150.;#range of voltmeter\n",
+ "s=1;#kilo ohms per volts sensivity\n",
+ "rv=s*vm;#kilo ohms\n",
+ "rx1=((rt1*rv)/(rv-rt1));#kilo ohms\n",
+ "ge1=((rx1-rt1)/rx1)*100;#percentage gross error\n",
+ "print\"percentage gross error is\",round(ge1,2)\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3 - pg 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "limiting error at 150 V is (%)= 5.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Example 1.3:#limiting error\n",
+ "#calculate the limiting error\n",
+ "#given\n",
+ "fs=1.5;#full scale in percentage\n",
+ "vr=500.;#voltmeter reading\n",
+ "#calculations\n",
+ "ea=(fs/100)*vr;#volts\n",
+ "le=150;#limiting error voltage\n",
+ "lep=((ea/le)*100);#limiting error\n",
+ "#results\n",
+ "print \"limiting error at 150 V is (%)=\",lep\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4 - pg 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "arithmetic mean is, (V)= 100.0\n",
+ "average deviation is, (V)= 0.2\n",
+ "standard deviation is, (V)= 0.228\n",
+ "Variance is ,(V)= 0.052\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Example 1.4:#ARITHMETIC MEAN,AVERAGE DEVIATION ,STANDARD DEVIATION AND PROBABLE ERROR\n",
+ "#calculate the ARITHMETIC MEAN,AVERAGE DEVIATION ,STANDARD DEVIATION AND PROBABLE ERROR\n",
+ "#given\n",
+ "import math,numpy\n",
+ "T=numpy.array([99.7,99.8,100,100.2,100.3]);#VOLTS\n",
+ "q=numpy.array([T[0],T[1],T[2],T[3],T[4]]);#\n",
+ "#calculations\n",
+ "AM=(q[0]+q[1]+q[2]+q[3]+q[4])/5;#arithematic mean in mm\n",
+ "qb=numpy.zeros(6)\n",
+ "for i in range(0,5):\n",
+ " qb[i]= T[i]-AM;\n",
+ "\n",
+ "Q= numpy.array([qb[0],qb[1],qb[2],qb[3],qb[4]]);#\n",
+ "AV=(-qb[0]-qb[1]-qb[2]+qb[3]+qb[4])/5;#\n",
+ "SD=math.sqrt(((qb[0]**2)+(qb[1]**2)+(qb[2]**2)+(qb[3]**2)+(qb[4]**2))/5);#standard deviation\n",
+ "V=SD**2;#\n",
+ "#results\n",
+ "print\"arithmetic mean is, (V)=\",AM\n",
+ "print\"average deviation is, (V)=\",AV\n",
+ "print\"standard deviation is, (V)=\",round(SD,3)\n",
+ "print\"Variance is ,(V)=\",V"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5 - pg 36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "power is,(W)= 1344.8\n",
+ "error in power is,(W)= 40.606\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Example 1.5:#error\n",
+ "#calculate the error in power\n",
+ "#given\n",
+ "i=8.2;#in amperes\n",
+ "r=20.;#ohms\n",
+ "nd=100.;#divisions\n",
+ "ra=10.;#range in amperes\n",
+ "d=0.5;#divisions\n",
+ "amcr=1.;#ammemeter constant error\n",
+ "crr=-0.2;#construction error\n",
+ "#calculations\n",
+ "p=i**2*r;#watts\n",
+ "rd1=ra/nd;#reading of one division\n",
+ "per=((d*rd1)/i)*100;#possible ameter rwading error\n",
+ "ter=amcr+per;#total ammeter error\n",
+ "ep=(((2*ter)+crr)/nd)*p;#\n",
+ "#results\n",
+ "print \"power is,(W)=\",p\n",
+ "print \"error in power is,(W)=\",round(ep,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6 - pg 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "arithmetic mean is (V)= 100.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Example 1.6:#ARITHMETIC MEAN\n",
+ "#calculate the arithmetic mean\n",
+ "#given\n",
+ "import numpy\n",
+ "T=numpy.array([99.7,99.8,99.9,100,100.1,100.2,100.3]);#VOLTS\n",
+ "f=numpy.array([2,8,20,40,21,6,3]);#frequency of occurence\n",
+ "#calculations\n",
+ "qb=numpy.zeros(8)\n",
+ "for i in range (0,7):\n",
+ " qb[i]=T[i]-T[5];\n",
+ "\n",
+ "prdtc=(qb[0]*f[0])+(qb[1]*f[1])+(qb[2]*f[2])+(qb[3]*f[3])+(qb[4]*f[4])+(qb[5]*f[5])+(qb[6]*f[6])\n",
+ "am=T[5]+(prdtc/100);#arithemetic mean\n",
+ "#results\n",
+ "print \"arithmetic mean is (V)=\",am\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7 - pg 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "limiting error for power is, (%)= 3.3\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Example 1.7:#limiting error\n",
+ "#calculate the limiting error for power\n",
+ "#given\n",
+ "fse=1.;#full scale deflection\n",
+ "vr=150.;#range in volts\n",
+ "v1=100.;#volts\n",
+ "ve=100.;#range in mA\n",
+ "#calculations\n",
+ "ev=(fse/100)*vr;#voltas\n",
+ "le100=((ev)/v1)*100;#in percentage\n",
+ "ee=(fse/100)*ve;#mA\n",
+ "e1=55;#mA\n",
+ "le50=((ee/e1)*100);#in percentage\n",
+ "ler=le100+le50;#\n",
+ "#results\n",
+ "print \"limiting error for power is, (%)=\",round(ler,1)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8 - pg 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "volume is,(m^3)= 0.216\n",
+ "percentage error in volume is,(%)= 3.0\n",
+ "error in volume is,(m^3)= 0.00648\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 37\n",
+ "#Example 1.8:# error\n",
+ "#calculate the volume, percentage error\n",
+ "#given\n",
+ "fse=1.;#full scale deflection\n",
+ "e=0.60;#meters\n",
+ "#calculations\n",
+ "v=(e)**3;#volume in m^3\n",
+ "ev=3*fse;#error in volume\n",
+ "evv=(ev/100)*v;#\n",
+ "#results\n",
+ "print \"volume is,(m^3)=\",v\n",
+ "print \"percentage error in volume is,(%)=\",ev\n",
+ "print \"error in volume is,(m^3)=\",evv\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9 - pg 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "current in the circuit is,(A)= 2.375\n",
+ "error in current is,(A)= 0.0356\n",
+ "percentage error in current is,(%)= 1.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Example 1.9:#error\n",
+ "#calculate the error in circuit\n",
+ "#given\n",
+ "v=95.;#volts\n",
+ "r=40.;#ohms\n",
+ "evv=0.95;#error in voltage\n",
+ "err=-0.2;#error in resistance\n",
+ "#calculations\n",
+ "i=v/r;#amperes\n",
+ "err1=(err/r)*100;#percentage error \n",
+ "evv1=(evv/v)*100;#percentage error\n",
+ "x=evv1-err1;#\n",
+ "ei=(x/100)*i;#\n",
+ "#results\n",
+ "print \"current in the circuit is,(A)=\",i\n",
+ "print \"error in current is,(A)=\",round(ei,4)\n",
+ "print \"percentage error in current is,(%)=\",x"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10 - pg 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "parralel resistance case\n",
+ "magnitude of resistance in ohms is = 17.391\n",
+ "limiting error in ohms is = 4.348\n",
+ "percentage error (%) = 25.0\n",
+ "series resistance case\n",
+ "magnitude of resistance in ohms is = 170.0\n",
+ "percentage error (%) = 5.0\n",
+ "limiting error in ohms is = 8.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Example 1.10:#MAGNITUDE AND LIMITING ERROR\n",
+ "#calculate the magnitude of resistance and limiting error\n",
+ "#given\n",
+ "print \"parralel resistance case\"\n",
+ "r1=40.;#ohms\n",
+ "er1=5.;#percentage error\n",
+ "r2=80.;#ohms\n",
+ "er2=5.;#percentage error\n",
+ "r3=50.;#ohms\n",
+ "er3=5.;#percentage error\n",
+ "#calculations\n",
+ "rp=((r1*r2*r3)/(r1*r2+r2*r3+r3*r1));#ohms\n",
+ "Y=(r1*r2+r2*r3+r3*r1);#ohms\n",
+ "ex=er1+er2+er3;#percentage error\n",
+ "ey1=er1+er2;#\n",
+ "ey2=er2+er3;#\n",
+ "ey3=er3+er1;#\n",
+ "y=(((r1*r2*ey1)/Y)+((r2*r3*ey2)/Y)+((r3*r1*ey3)/Y));#error\n",
+ "mer=(y+ex)*rp;#\n",
+ "#results\n",
+ "print \"magnitude of resistance in ohms is = \",round(rp,3)\n",
+ "print \"limiting error in ohms is = \",round(mer/100,3)\n",
+ "print \"percentage error (%) = \",(y+ex)\n",
+ "print \"series resistance case\"\n",
+ "rs=r1+r2+r3;#ohms\n",
+ "er=(((r1/rs)*er1)+((r2/rs)*er2)+((r3/rs)*er3));#\n",
+ "mer1=(er/100)*rs;#ohms\n",
+ "print \"magnitude of resistance in ohms is = \",rs\n",
+ "print \"percentage error (%) = \",er\n",
+ "print \"limiting error in ohms is = \",mer1\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11 - pg 39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "magnitude in ohm = 151.0\n",
+ "percentage error when error in both (PS) and (Q) is positive (%) = 0.5\n",
+ "error in ohms when error in both (PS) and (Q) is positive (ohms) = 0.755\n",
+ "percentage error when error in (PS) is positive and (Q) is negative (%) = 1.5\n",
+ "error in ohms when error in (PS) is positive and (Q) is negative (ohms) = 2.265\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Example 1.11:#MAGNITUDE AND LIMITING ERROR\n",
+ "#calculate the magintude of resistance in ohm and error\n",
+ "#given\n",
+ "r1=50;#ohms\n",
+ "er1=0.5;#percentage error\n",
+ "r2=100;#ohms\n",
+ "er2=0.5;#percentage error\n",
+ "r3=75.5;#ohms\n",
+ "er3=0.5;#percentage error\n",
+ "#calculations\n",
+ "x=((r2/r1)*r3);#ohms\n",
+ "eps=er1+er2;#\t\n",
+ "erpsq=eps-er3;#when error in both (PS) and (Q) is positive\n",
+ "erpsq1=eps+er3;#when error in (PS) is positive and (Q) is negetive\n",
+ "oer1=(erpsq/100)*x;#ohms\n",
+ "oer2=(erpsq1/100)*x;#ohms\n",
+ "#results\n",
+ "print \"magnitude in ohm = \",x\n",
+ "print \"percentage error when error in both (PS) and (Q) is positive (%) = \",erpsq\n",
+ "print \"error in ohms when error in both (PS) and (Q) is positive (ohms) = \",oer1\n",
+ "print \"percentage error when error in (PS) is positive and (Q) is negative (%) = \",erpsq1\n",
+ "print \"error in ohms when error in (PS) is positive and (Q) is negative (ohms) = \",oer2\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter2.ipynb b/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter2.ipynb
new file mode 100755
index 00000000..27e9fedf
--- /dev/null
+++ b/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter2.ipynb
@@ -0,0 +1,2381 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 2 - Analog measurement of electrical quantities"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1 - pg 130"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "for Ist method\n",
+ "wattmeter reading is (W)= 804.0\n",
+ "percentage error is high (%) = 0.5\n",
+ "for 2nd method\n",
+ "wattmeter reading (W)= 802.5\n",
+ "percentage error is high (%) = 0.3125\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 130\n",
+ "#Example 2.1:#wattmeter reading and error\n",
+ "#calculate the wattmeter reading\n",
+ "import math,cmath\n",
+ "#given\n",
+ "print \"for Ist method\"\n",
+ "v=50;#volts\n",
+ "i=20;#amperes\n",
+ "pf=0.8;#power factor\n",
+ "pl=v*i*pf;#true power\n",
+ "vc=(50*pf)+1j*v*math.sqrt(1-pf**2);#complex form \n",
+ "ic=i+1j*0;#\n",
+ "r1=0.01;#ohms\n",
+ "#calculations and results\n",
+ "vpl=vc+(i*r1);#voltage across pressure coil\n",
+ "wrlc1=(vpl.real)*(ic.real);#\n",
+ "er=(wrlc1-pl)/(pl);#\n",
+ "print \"wattmeter reading is (W)=\",wrlc1\n",
+ "print \"percentage error is high (%) = \",er*100\n",
+ "print \"for 2nd method\"\n",
+ "r2=1000;#ohms\n",
+ "ic1=ic+(vc/r2);#\n",
+ "wrlc2=(vc.real)*(ic1.real)+(vc.imag)*(ic1.imag);#\n",
+ "er1=(wrlc2-pl)/(pl);#\n",
+ "print \"wattmeter reading (W)=\",wrlc2\n",
+ "print \"percentage error is high (%) = \",er1*100\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2 - pg 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "self inductance (mH) = 2.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 131\n",
+ "#Example 2.2:#self inductance\n",
+ "#calculate the self inductance\n",
+ "#given\n",
+ "c=20.;#pF\n",
+ "rs=10000.;#ohms\n",
+ "#calculations\n",
+ "l=(c*10**-12)*rs**2;#henry\n",
+ "#results\n",
+ "print \"self inductance (mH) = \",l*10**3\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3 - pg 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "percentage error is (%) = 0.39\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 131\n",
+ "#Example 2.3:#percentage error\n",
+ "#calculate the percentage error\n",
+ "#given\n",
+ "import math\n",
+ "v=100;#volts\n",
+ "i=10;#amperes\n",
+ "pf=0.45;#power factor\n",
+ "f=50;#Hz\n",
+ "l=25;#mH\n",
+ "r=4000;#ohms\n",
+ "#calculations\n",
+ "tp=v*i*pf;#true power in watts\n",
+ "b=math.atan((2*math.pi*f*l*10**-3)/r);#phase angle in radians\n",
+ "e=v*i*math.tan(b)*math.sqrt(1-pf**2);#\n",
+ "per=(e*100)/(tp);#\n",
+ "#results\n",
+ "print \"percentage error is (%) = \",round(per,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4 - pg 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "true power in (kW) = 851.3\n",
+ "answer is wrong in the textbook\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 131\n",
+ "#Example 2.4:#true power\n",
+ "#calculate the true power\n",
+ "#given\n",
+ "import math\n",
+ "from math import cos\n",
+ "ph=45.;#degree\n",
+ "th=90.;#radians\n",
+ "dela=-45.;#radians\n",
+ "f=50.;#Hz\n",
+ "l=15.;#mH\n",
+ "r=300.;#ohms\n",
+ "#calculations\n",
+ "b=math.atan((2*math.pi*f*l*10**-3)/r);#in radians\n",
+ "k=((cos(ph/57.3))/(cos(b)*cos(42/57.3)));#\n",
+ "nr=20;#nomianl ratio\n",
+ "e=-0.3;#\n",
+ "er=(e*nr)/100;#\n",
+ "ar1=nr-er;#actual ratio\n",
+ "nr1=100;#nomianl ratio\n",
+ "e1=0.9;#\n",
+ "er1=(e1*nr1)/100;#\n",
+ "ar2=nr1-er1;#actual ratio\n",
+ "p=450;#watts\n",
+ "tp=ar1*ar2*k*p;#\n",
+ "#results\n",
+ "print \"true power in (kW) = \",round(tp*10**-3,1)\n",
+ "print 'answer is wrong in the textbook'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5 - pg 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "torque in Nm when angle is 45 degree (Nm) = 6.68e-06\n",
+ "torque in Nm when angle is 90 degree (Nm) = 9.45e-06\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 132\n",
+ "#Example 2.5:#torque\n",
+ "#calculate the torque required\n",
+ "#given\n",
+ "import math\n",
+ "from math import sin\n",
+ "d=2.5;#diameter in cm\n",
+ "n=500;#turns\n",
+ "b=1.1;#mWb/m**2\n",
+ "v=100;#volts\n",
+ "pf=0.7;#power factor\n",
+ "rp=2000;#ohms\n",
+ "#calculations\n",
+ "x=((math.pi*(d*10**-2)**2*n*b*10**-3*v*pf)/(4*rp));#\n",
+ "ang1=45;#degree\n",
+ "ang2=90;#degree\n",
+ "td1=x*sin(ang1/57.3);#\n",
+ "td2=x*sin(ang2/57.3);#\n",
+ "#results\n",
+ "print \"torque in Nm when angle is 45 degree (Nm) = \",round(td1,8)\n",
+ "print \"torque in Nm when angle is 90 degree (Nm) = \",round(td2,8)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6 - pg 133"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "unknown resistance is (ohm)= 2784.0\n",
+ "answer is wrong in the textbook\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 133\n",
+ "#Example 2.6:#resistance\n",
+ "#calculate the resistance\n",
+ "#given\n",
+ "import math\n",
+ "la=4.78;#henry\n",
+ "ra=298.;#ohms\n",
+ "lb=3.;#henry\n",
+ "rb=190.;#ohms\n",
+ "v=200.;#volts\n",
+ "#calculations\n",
+ "r=((la*100*lb*100*math.pi**2)-(ra*rb))/(rb+ra);#ohm\n",
+ "#results\n",
+ "print \"unknown resistance is (ohm)=\",round(r,0)\n",
+ "print 'answer is wrong in the textbook'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7 - pg 133"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "addition resistance (ohm) = 2750.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 133\n",
+ "#Example 2.7:#resistance\n",
+ "#calculate the addition in resistance\n",
+ "#given\n",
+ "i=20.;#amperes\n",
+ "v=100.;#volts\n",
+ "pf=1;#power factor\n",
+ "rp=5500.;#ohms\n",
+ "th=150.;#angle\n",
+ "wd=20;#watts per degree\n",
+ "#calculations\n",
+ "p=v*i*pf;#watts\n",
+ "kd=((rp*th)/p);#constant\n",
+ "rp1=wd*kd;#in ohms\n",
+ "adr=rp1-rp;#\n",
+ "#results\n",
+ "print \"addition resistance (ohm) = \",adr\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8 - pg 134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance in (ohm) = 120.0\n",
+ "load impedance in (ohm) = 75.0\n",
+ "impedance of combination in (ohm) = 53.57\n",
+ "power absorbed by the load in (W) = 546.6\n",
+ "power factor of the load = 0.4555\n",
+ "total power supply is (W) = 1296.6\n",
+ "total power factor = 0.772\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 134\n",
+ "#Example 2.8:#resistance,impedance,power,power factor ,voltage and power factor\n",
+ "#calculate the total power factor,supply, impedance and resistance\n",
+ "#given\n",
+ "v=300.;#volts\n",
+ "i2=2.5;#amperes\n",
+ "#calculations and results\n",
+ "r=v/i2;#ohms\n",
+ "print \"resistance in (ohm) =\",r\n",
+ "i3=4;#amperes\n",
+ "zl=v/i3;#ohms\n",
+ "print \"load impedance in (ohm) = \",zl\n",
+ "v=300;#volts\n",
+ "i2=2.5;#amperes\n",
+ "r=v/i2;#ohms\n",
+ "i1=5.6;#amperes\n",
+ "z=v/i1;#ohms\n",
+ "print \"impedance of combination in (ohm) = \",round(z,2)\n",
+ "i3=4;#amperes\n",
+ "pl=((i1**2-i2**2-i3**2)*r)/2;#in watts\n",
+ "print \"power absorbed by the load in (W) = \",pl\n",
+ "pl=((i1**2-i2**2-i3**2)*r)/2;#in watts\n",
+ "pfl=((i1**2-i2**2-i3**2)/(2*i2*i3));#power factor\n",
+ "print \"power factor of the load = \",pfl\n",
+ "pr=i2**2*r;#in watts\n",
+ "tps=pl+pr;#in watts\n",
+ "print \"total power supply is (W) = \",tps\n",
+ "tps=pl+pr;#in watts\n",
+ "tpf=tps/(v*i1);#power factor\n",
+ "print \"total power factor = \",round(tpf,3)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9 - pg 135"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "average power to be read by wattmeter is (W) = 127.32\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 135\n",
+ "#Example 2.9:#wattmeter reading\n",
+ "#calculate the average power\n",
+ "import math,scipy\n",
+ "from scipy import integrate\n",
+ "v=24.;#volts\n",
+ "r1=6.;#ohms\n",
+ "vm=100;#volts\n",
+ "t0=0.;#\n",
+ "t1=(1./100);#\n",
+ "f=50.;#Hz\n",
+ "#calculations\n",
+ "i=v/r1;#in amperes\n",
+ "z=2*math.pi*f;#\n",
+ "def fun(t):\n",
+ "\ty=math.sin(z*t)\n",
+ "\treturn y\n",
+ "x=scipy.integrate.quad(fun,t0,(t1/2.));#\n",
+ "p=vm*(1/t1)*i*x[0];#\n",
+ "#results\n",
+ "print \"average power to be read by wattmeter is (W) = \",round(p,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10 - pg 136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "load impedance in (ohm) = 20.0\n",
+ "impedance of combination in (ohm) = 35.0\n",
+ "power absorbed by the load is,(W) = 202.0\n",
+ "power absorbed by the non inductive resistor is,(W) = 300.0\n",
+ "power factor of load is 0.63\n",
+ "power factor of the whole circuit is 0.9\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 136\n",
+ "#Example 2.10:#load impedance and combination impedance\n",
+ "#calculate the power factor and power, load\n",
+ "#given\n",
+ "v3=80.;#volts\n",
+ "i=4.;#amperes\n",
+ "v1=140;#volts\n",
+ "#calculations and results\n",
+ "zl=v3/i;#ohms\n",
+ "z=v1/i;#ohms\n",
+ "print \"load impedance in (ohm) = \",zl\n",
+ "print \"impedance of combination in (ohm) = \",z\n",
+ "v2=75.;#volts (it is given 72 in the textbook)\n",
+ "r=v2/i;#\n",
+ "pl=((v1**2-v2**2-v3**2)/(2*r));#watts\n",
+ "pr=i**2*r;#watts\n",
+ "print \"power absorbed by the load is,(W) = \",pl\n",
+ "print \"power absorbed by the non inductive resistor is,(W) = \",pr\n",
+ "pfl=((v1**2-v2**2-v3**2)/(2*v2*v3));#power factor of the load\n",
+ "tp=pr+pl;#total power in watts\n",
+ "pfc=tp/(v1*i);#power factor\n",
+ "print \"power factor of load is\",round(pfl,2)\n",
+ "print \"power factor of the whole circuit is\",round(pfc,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11 - pg 136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "wattmeter (W1) reading in (kW) = 85.0\n",
+ "wattmeter (W2) reading in (kW) = 215.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 136\n",
+ "#Example 2.11:#wattmeters readings\n",
+ "#calculate the wattmeters readings\n",
+ "import math\n",
+ "from math import sqrt\n",
+ "#given\n",
+ "pf=0.8;#\n",
+ "#calculations\n",
+ "td=(sqrt(1-pf**2))/pf;#\n",
+ "sr=300;#kW\n",
+ "df=(sr/sqrt(3))*td;#\n",
+ "w2=(sr+df)/2;#\n",
+ "w1=sr-w2;#\n",
+ "#results\n",
+ "print \"wattmeter (W1) reading in (kW) = \",round(w1)\n",
+ "print \"wattmeter (W2) reading in (kW) = \",round(w2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12 - pg 137"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "power factor of the system = 0.189\n",
+ "capacitance (micro-F) = 322.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 137\n",
+ "#Example 2.12:#power factor and capacitance\n",
+ "#calculate the capacitance and power factor\n",
+ "import math\n",
+ "from math import atan,sqrt,cos\n",
+ "#given\n",
+ "w1=-2000.;#watts\n",
+ "w2=4000.;#watts\n",
+ "v=400.;#volts\n",
+ "pfn=0.5;#power factor\n",
+ "f=50.;#Hz\n",
+ "#calculations\n",
+ "ph=math.atan((sqrt(3.)*(w2-w1))/(w2+w1)) *57.3;#in degree\n",
+ "pf=cos(ph/57.3);#\n",
+ "w=w1+w2;#total power\n",
+ "vp=(v/sqrt(3));#phase voltage\n",
+ "pp=w/3.;#power per phase\n",
+ "pi=(pp)/(vp*pf);#phase current\n",
+ "pim=vp/pi;#phase impedance\n",
+ "rip=pim*pf;#resistance each phase\n",
+ "rep=(sqrt(pim**2-rip**2));#reactance of each phase\n",
+ "pimb=rip/pfn;#impedance per phase\n",
+ "repn=(sqrt(pimb**2-rip**2));#reactance per phase\n",
+ "cp=rep-repn;#capacitive reactance\n",
+ "c=((1/(2*math.pi*f*cp)));#\n",
+ "#results\n",
+ "print \"power factor of the system = \",round(pf,3)\n",
+ "print \"capacitance (micro-F) = \",round(c*10**6)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13 - pg 138"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "power factor = 0.866\n",
+ "line current is (A)= 83.3\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 138\n",
+ "#Example 2.13:#power factor and line current\n",
+ "#calculate the line current and power factor\n",
+ "#given\n",
+ "import math\n",
+ "x=1;#\n",
+ "w=50;#kW\n",
+ "v=400.;#volts\n",
+ "#calculations\n",
+ "w2=2*x;#\n",
+ "w1=x;#\n",
+ "ph=math.atan((math.sqrt(3)*(w2-w1))/(w2+w1))*57.3;#in degree\n",
+ "pf=math.cos(ph/57.3);#power factor\n",
+ "il=((w/(math.sqrt(3)*v*pf)))*10**3;#in amperes\n",
+ "#results\n",
+ "print \"power factor = \",round(pf,3)\n",
+ "print \"line current is (A)=\",round(il,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14 - pg 138"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "when both readings are positive\n",
+ "power is (W) = 6900.0\n",
+ "power factor (leading) = 0.866\n",
+ "when second readig is negative\n",
+ "power is (W) = 2300.0\n",
+ "power factor (leading) = 0.189\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 138\n",
+ "#Example 2.14:#total power and power factor\n",
+ "#calculate the total power and power factor\n",
+ "#given\n",
+ "import math\n",
+ "print \"when both readings are positive\"\n",
+ "w2=2300.;#watts\n",
+ "w1=4600.;#watts\n",
+ "#calculations and results\n",
+ "p1=w2+w1;#\n",
+ "ph=57.3*math.atan((math.sqrt(3)*(w2-w1))/(w2+w1));#in degree\n",
+ "pf=math.cos(ph/57.3);#power factor\n",
+ "print \"power is (W) = \",p1\n",
+ "print \"power factor (leading) = \",round(pf,3)\n",
+ "print \"when second readig is negative\"\n",
+ "w21=-2300.;#watts\n",
+ "w1=4600.;#watts\n",
+ "p2=w21+w1;#\n",
+ "ph2=57.3*math.atan((math.sqrt(3)*(w21-w1))/(w21+w1));#in degree\n",
+ "pf1=math.cos(ph2/57.3);#power factor\n",
+ "print \"power is (W) = \",p2\n",
+ "print \"power factor (leading) = \",round(pf1,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 15 - pg 139"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "load current in amperes = 5.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 139\n",
+ "#Example 2.15:#load current\n",
+ "#calculate the load current\n",
+ "#given\n",
+ "import math\n",
+ "from math import atan,cos,sqrt\n",
+ "rw=3550.;#reading of wattmeter\n",
+ "rp=806.;#watts\n",
+ "#calculations\n",
+ "ph=atan((sqrt(3)*rp)/rw);#in degree\n",
+ "pf=cos(ph/57.3);#power factor\n",
+ "v=440;#volts\n",
+ "i=((rw)/(sqrt(3)*v*pf));#amperes\n",
+ "#results\n",
+ "print \"load current in amperes = \",round(i)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16 - pg 139"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "error (slow) in percentage = 9.1\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 139\n",
+ "#Example 2.16:#error\n",
+ "#calculate the error percentage\n",
+ "#given\n",
+ "import math\n",
+ "from math import sin\n",
+ "d=87./57.3;#radians\n",
+ "pf=0.5;#\n",
+ "#calculations\n",
+ "n=(1./4)*sin(d-60/57.3);#\n",
+ "nc=(1./4)*pf*sin(d);#\n",
+ "e=((n-nc)/nc)*100;#error\n",
+ "#results\n",
+ "print \"error (slow) in percentage = \",round(-e,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 17 - pg 140"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "error (%) = 1.82\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 140\n",
+ "#Example 2.17:#error\n",
+ "#calculate the error\n",
+ "#given\n",
+ "import math,scipy\n",
+ "from scipy import integrate \n",
+ "i=5;#amperes\n",
+ "t0=0;#\n",
+ "t1=30./60;#\n",
+ "e=0.56;#kWh\n",
+ "v1=220;#volts\n",
+ "#calculations\n",
+ "def function(t):\n",
+ "\ty=5\n",
+ "\treturn y\n",
+ "x=scipy.integrate.quad(function,t0,t1);#\n",
+ "v=(e*10**3)/x[0];#volts\n",
+ "ae=v1*i*t1*10**-3;#actual energy\n",
+ "e=((e-ae)/ae)*100;#error\n",
+ "#results\n",
+ "print \"error (%) = \",round(e,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 18 - pg 140"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "time duration (seconds) = 367.0\n",
+ "limits of accuracy (%) = 0.73\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 140\n",
+ "#Example 2.18:#time and error\n",
+ "#calculate the time duration and limits of accuracy\n",
+ "#given\n",
+ "nd=500.;#dvisions\n",
+ "cr=0.1;#dvisions can read\n",
+ "ie=0.05;#inherent error\n",
+ "tea=0.1;#total error allowable\n",
+ "cr1=0.01;#seconds\n",
+ "cr2=0.1;#seconds\n",
+ "nd1=500/10.;#\n",
+ "#calculations\n",
+ "re=(cr/nd)*100;#reading error\n",
+ "te=re+ie;#total error\n",
+ "per=tea-te;#permissible error\n",
+ "ersw=cr1*100;#error in reading stop watch\n",
+ "erss=cr2*100;#error in stopping and starting\n",
+ "ter=ersw+erss;#total error\n",
+ "t=per/ter;#seconds\n",
+ "er1=(cr/nd1)*100;#new reading error\n",
+ "ie1=((ie*nd)/nd1);#new inherent error\n",
+ "ter1=er1+ie1;#\n",
+ "la=ter1+per;#\n",
+ "#results\n",
+ "print \"time duration (seconds) = \",round(1./t)\n",
+ "print \"limits of accuracy (%) = \",la\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19 - pg 141"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "error (slow) is (%) 1.66\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 141\n",
+ "#Example 2.19:#error\n",
+ "#calculate the error\n",
+ "#given\n",
+ "import math\n",
+ "n=40.;#revolutions\n",
+ "rc=0.12;#registration constant\n",
+ "e2=22000;#volts\n",
+ "e1=110;#volts\n",
+ "i2=500;#amperes\n",
+ "i1=5;#amperes\n",
+ "i=5.25;#amperes\n",
+ "lv=110;#volts\n",
+ "pf=1;#\n",
+ "t=61;#seconds\n",
+ "#calculations\n",
+ "err=n/rc;#energy recorded in kWh is\n",
+ "ae=((math.sqrt(3)*e2*lv*i*i2*pf*t)/(e1*i1*3600))*10**-3;#kWh\n",
+ "e=((err-ae)/ae)*100;#\n",
+ "#results\n",
+ "print \"error (slow) is (%)\",round(-e,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 20 - pg 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "error (fast) in recording (%) = 0.2\n",
+ "limit of error in the meter is 0.07 % or 0.33 % \n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 142\n",
+ "#Example 2.20:#error and limit of error\n",
+ "#calculate the error and limit of error\n",
+ "#given\n",
+ "mc=1200.;#meter constant in rev/kWh\n",
+ "n=40.;#revolutions\n",
+ "tp=99.8;#seconds\n",
+ "v=240;#volts\n",
+ "i=5;#amperes\n",
+ "#calculations\n",
+ "err=n/mc;#energy recorded in kWh\n",
+ "ae=((v*i*tp*10**-3)/3600);#actual energy in kWh\n",
+ "e=((err-ae)/ae)*100;#error\n",
+ "n=500;#divisions\n",
+ "rn=0.1;#dvision reading accuracy\n",
+ "per=((rn/n)*100);#possible error\n",
+ "ie=0.05;#inherent error\n",
+ "per1=(((rn/10)/tp)*100);#possible error\n",
+ "her=((ie/tp)*100);#human error\n",
+ "tpr=per+per1+her+ie;#total possible error\n",
+ "li1=e-tpr;#\n",
+ "li2=e+tpr;#\n",
+ "#results\n",
+ "print \"error (fast) in recording (%) = \",round(e,2)\n",
+ "print \"limit of error in the meter is \",round(li1,2),\"% or \",round(li2,2),\"% \"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 21 - pg 143"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "total monthly bill in Rs 19295.0\n",
+ "power factor is 0.78\n",
+ "load factor is 0.96\n",
+ "average cost per unit (kWh) in paisa is 15.4\n",
+ "total monthly bill and load factor is calculated wrong in the book due to rounding off error\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 143\n",
+ "#Example 2.21:#consumer monthly bill ,power factor and average cost per unit\n",
+ "#calculate the consumer monthly bill ,power factor and average cost per unit\n",
+ "#given\n",
+ "import math\n",
+ "from math import sqrt\n",
+ "kwh=125000.;#\n",
+ "kvarh=100000.;#\n",
+ "kw=180;#\n",
+ "kvar=125;#\n",
+ "d=30.;#days\n",
+ "t=24.;#hours a day\n",
+ "#calculations\n",
+ "kvah=sqrt(kwh**2+kvarh**2);#kVAh\n",
+ "mkva=sqrt(kw**2+kvar**2);#kVA\n",
+ "pkva=15;#rupees\n",
+ "pkvah=0.1;#reupees\n",
+ "tmb=pkva*mkva+pkvah*kvah;#in Rs\n",
+ "pf=kwh/kvah;#power factor\n",
+ "lf=((kwh/(d*t))/kw);#load factor\n",
+ "avcp=tmb/kwh;#in paisa\n",
+ "#results\n",
+ "print \"total monthly bill in Rs\",round(tmb)\n",
+ "print \"power factor is\",round(pf,2)\n",
+ "print \"load factor is\",round(lf,2)\n",
+ "print \"average cost per unit (kWh) in paisa is\",round(avcp*100,1)\n",
+ "print 'total monthly bill and load factor is calculated wrong in the book due to rounding off error'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 22 - pg 143"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "number of revolution per kWh is,(revolutions/kWh)= 3273.0\n",
+ "full load speed r.p.s = 1.0\n",
+ "error (fast) in percentage = 0.84\n",
+ "numberof revolutions is calcultaed wrong in the textbook due to rounding off error\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 143\n",
+ "#Example 2.22:#full load speed and error\n",
+ "#calculate the full load speed and error\n",
+ "#given\n",
+ "v=220.;#volts\n",
+ "n=30.;#revolutions\n",
+ "i=5.;#in amperes\n",
+ "t=59.5;#seconds\n",
+ "#calculations\n",
+ "wrv=((v*i*10**-3)/(3600.));#kWh\n",
+ "mc=((3600.*10**3)/(v*i));#rev/kWh\n",
+ "ec=((v*i*10**-3)/(3600.));#kWh\n",
+ "sfl=mc*ec;#rps\n",
+ "hler=n*ec;#kWh\n",
+ "hlf=(((i/2.)*v*10**-3*t)/(3600.));#kWh\n",
+ "e=(hler-hlf)/hlf;#\n",
+ "#results\n",
+ "print \"number of revolution per kWh is,(revolutions/kWh)=\",round(mc)\n",
+ "print \"full load speed r.p.s = \",sfl\n",
+ "print \"error (fast) in percentage = \",round(e*100,2)\n",
+ "print 'numberof revolutions is calcultaed wrong in the textbook due to rounding off error'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23 - pg 144"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "shunt resistance when current is 10mA (ohm) = 52.63\n",
+ "shunt resistance when current is 75mA (ohm) = 6.71\n",
+ "shunt resistance when current is 100mA (ohm) = 2.004\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 144\n",
+ "#Example 2.23:#shunt resistance \n",
+ "#calculate the shunt resistance \n",
+ "#given\n",
+ "ra=1000.;#armature resistance in ohms\n",
+ "i=10.;#mA\n",
+ "ia=500.;#micro amperes\n",
+ "i1=75;#mA\n",
+ "i3=100;#mA\n",
+ "#calculations\n",
+ "rsh1=((ra)/((i/(ia*10**-3))-1));#in ohms\n",
+ "rsh2=((ra)/((i1/(ia*10**-3))-1));#in ohms\n",
+ "ia3=0.4*ia;#micro amperes\n",
+ "rsh3=((ra)/((i3/(ia3*10**-3))-1));#in ohms\n",
+ "#results\n",
+ "print \"shunt resistance when current is 10mA (ohm) = \",round(rsh1,2)\n",
+ "print \"shunt resistance when current is 75mA (ohm) = \",round(rsh2,2)\n",
+ "print \"shunt resistance when current is 100mA (ohm) = \",round(rsh3,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24 - pg 144"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "shunt resistance in milli ohm is 0.60012\n",
+ "power consumption in shunt is,(W)= 9.37\n",
+ "series resistance in kilo ohm is 24.997\n",
+ "power consumption in the series resistance is,(W)= 15.623\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 144\n",
+ "#Example 2.24:#shunt resistance and series resistance\n",
+ "#calculate the shunt resistance and series resistance\n",
+ "#given\n",
+ "i=125.;#amperes\n",
+ "ia=25.;#armature current in mA\n",
+ "ra=3;#ohms\n",
+ "#calculations\n",
+ "ish=i-(ia*10**-3);#amperes\n",
+ "rsh=((ia*ra)/ish);#milli ohms\n",
+ "pcs=ish**2*rsh*10**-3;#watts\n",
+ "rv=625;#volts\n",
+ "rs=((rv-(ra*ia*10**-3))/(ia*10**-3))*10**-3;#killo ohms\n",
+ "pc=(ia*10**-3)**2*rs*10**3;#watts\n",
+ "#results\n",
+ "print \"shunt resistance in milli ohm is\",round(rsh,5)\n",
+ "print \"power consumption in shunt is,(W)=\",round(pcs,2)\n",
+ "print \"series resistance in kilo ohm is\",rs\n",
+ "print \"power consumption in the series resistance is,(W)=\",round(pc,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 25 - pg 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "when micro meter resistance is 25 ohm\n",
+ "multiplying power for the shunt for a 1250 ohm is 4.02\n",
+ "multiplying power for the shunt for a 2500 ohm is 2.01\n",
+ "when micro meter resistance is 2500 ohm\n",
+ "multiplying power for the shunt for a 1250 ohm is 6.0\n",
+ "multiplying power for the shunt for a 2500 ohm is 3.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 145\n",
+ "#Example 2.25:#mulitplying power\n",
+ "#calculate the mulitplying power in all cases\n",
+ "print \"when micro meter resistance is 25 ohm\"\n",
+ "#given\n",
+ "ra=25.;#ohms\n",
+ "rsh=5000.;#ohms\n",
+ "r1=1250.;#ohms\n",
+ "r2=2500;#ohms\n",
+ "#calculations and results\n",
+ "n=((ra+rsh)/r1);#\n",
+ "n2=((ra+rsh)/r2);#\n",
+ "print \"multiplying power for the shunt for a 1250 ohm is\",n\n",
+ "print \"multiplying power for the shunt for a 2500 ohm is\",n2\n",
+ "print \"when micro meter resistance is 2500 ohm\"\n",
+ "ra1=2500.;#ohms\n",
+ "rsh=5000.;#ohms\n",
+ "r1=1250.;#ohms\n",
+ "n1=((ra1+rsh)/r1);#\n",
+ "r2=2500.;#ohms\n",
+ "n3=((ra1+rsh)/r2);#\n",
+ "print \"multiplying power for the shunt for a 1250 ohm is\",n1\n",
+ "print \"multiplying power for the shunt for a 2500 ohm is\",n3\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 26 - pg 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "voltage is,(V)= 487.0\n",
+ "resistance is ,(k-ohm)= 27.0\n",
+ "resistance is calculated wrong in the textbook due to rounding off error\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 145\n",
+ "#Example 2.26:#resistance\n",
+ "#calculate the resistance\n",
+ "r1=185.;#ohm\n",
+ "r2=205.;#ohm\n",
+ "r3=215.;#ohm\n",
+ "R31=195.;#OHM\n",
+ "r4=200.;#ohm\n",
+ "r5=1100.;#ohm\n",
+ "v1=85.;#V\n",
+ "#calculations\n",
+ "R=r1+r2+r3+r4+R31;#ohm\n",
+ "R1=(R-r4)+((r5*r4)/(r5+r4));#\n",
+ "V=(v1*R1)/round(R1-(R-r4));#V\n",
+ "I=round(V)/R;#A\n",
+ "vd4=I*r4;#V\n",
+ "x=0.5;#% allowable\n",
+ "vd41=(vd4)-(vd4*x)/100;#\n",
+ "rv=((vd41*(R-r4)*r4))/((V*r4)-((R*vd41)));#\n",
+ "#results\n",
+ "print \"voltage is,(V)=\",round(V)\n",
+ "print \"resistance is ,(k-ohm)=\",round(rv*10**-3)\n",
+ "print 'resistance is calculated wrong in the textbook due to rounding off error'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 27 - pg 146"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "(a). The sensitivity of an instrument,S1 = 0.0099\n",
+ "(b). The resistance,R(ohm) = 200.0\n",
+ "The relative sensitivity,S = 0.012\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 146\n",
+ "#Example 2.27: Sensitivity\n",
+ "#calculate the sensitivity and resistance, relative sensitivity\n",
+ "#given data :\n",
+ "I1=0.1;# in mA\n",
+ "R1=50.;# in ohm\n",
+ "I2=10.;# in mA\n",
+ "I3=10.1;# in mA\n",
+ "I5=10;# in mA\n",
+ "V=2;# in Volt\n",
+ "#calculations\n",
+ "I4=I2-I1;\n",
+ "Rsh=I1*R1/(I3-I1);\n",
+ "Im1=Rsh*I4/(R1+Rsh);\n",
+ "S1=(I1-Im1)/(I3-I4);\n",
+ "R=V/(I5*10**-3);\n",
+ "# formula : Im=((I3-Im)*(R-V))/R1;\n",
+ "Im2=(0.8*I3)-8;\n",
+ "Im3=(0.8*I4)-8\n",
+ "S2=(Im2-Im3)/(I3-I4);\n",
+ "S=S1/S2;\n",
+ "#results\n",
+ "print \"(a). The sensitivity of an instrument,S1 = \",round(S1,4)\n",
+ "print \"(b). The resistance,R(ohm) = \",R\n",
+ "print \"The relative sensitivity,S = \",round(S,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 28 - pg 147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Shunt resistance,Rs(ohm) = 0.01\n",
+ "Inductance,Ls(micro-H) = 10.0\n",
+ "Current,Ia1(A) = 4.81\n",
+ "Error,(%)(low) = 3.8\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 147\n",
+ "#Example 2.28: Error\n",
+ "#calculate the Error, shunt resistance and inductance\n",
+ "#given data :\n",
+ "import math\n",
+ "from math import sqrt\n",
+ "La=90*10**-6;# in micro-H\n",
+ "Ra=0.09;# in ohm\n",
+ "I=50;# in A\n",
+ "Ia=5;# in A\n",
+ "f=50;# in Hz\n",
+ "#calculations\n",
+ "LsbyRs=La/Ra;\n",
+ "w=2*math.pi*f;\n",
+ "Rs=Ra/9;\n",
+ "Ls=LsbyRs*Rs*10**6;\n",
+ "Ls1=0;# shunt is non-inductive \n",
+ "Ia1=(Rs*I)/sqrt((Ra+Rs)**2+(w**2*La**2));\n",
+ "Error=((Ia-Ia1)/Ia)*100;\n",
+ "#results\n",
+ "print \"Shunt resistance,Rs(ohm) = \",Rs\n",
+ "print \"Inductance,Ls(micro-H) = \",Ls\n",
+ "print \"Current,Ia1(A) = \",round(Ia1,2)\n",
+ "print \"Error,(%)(low) = \",round(Error,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 29 - pg 148"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "area is (cm^2)= 188.0\n",
+ "error is (%)= 8.11\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 148\n",
+ "#Example 2.29 :area and percentage error\n",
+ "#calculate the area and error\n",
+ "#given data \n",
+ "import math\n",
+ "from math import sqrt\n",
+ "v1=18.;#kV\n",
+ "c1=60.;#pF\n",
+ "v2=2.;#\n",
+ "d=2.5;#cm\n",
+ "#calculations\n",
+ "q=v2*10**3*c1*10**-12;#\n",
+ "cs=q/(v1*10**3);#F\n",
+ "eo=8.854*10**-12;#\n",
+ "a=((cs*d*10**-2)/(eo));#\n",
+ "c2=50;#pf\n",
+ "x=c1-c2;#\n",
+ "stf=((v2*10**3)**2*x*10**-12);#\n",
+ "v=sqrt(stf/(x*10**-12*2))/1000;#kV\n",
+ "c3=c2+(x/2);#pf\n",
+ "x1=c3/(cs*10**12);#\n",
+ "V1=(x1+1)*v#\n",
+ "V=10*sqrt(2);#V\n",
+ "er=((V-V1)/V1)*100;#\n",
+ "#results\n",
+ "print \"area is (cm^2)=\",round(a*10**4)\n",
+ "print \"error is (%)=\",round(er,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 30 - pg 150"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The percentage error in case 1 (%) = -15.25\n",
+ "The percentage error in case 2 (%) = -0.688\n",
+ "The answers are a bit different due to rounding off error in textbook\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 150\n",
+ "#Example 2.30: % Error\n",
+ "#calculate the percentage error \n",
+ "#given data :\n",
+ "Ra=2.;# in ohm\n",
+ "Rsh=0.0004;# constant\n",
+ "alfa=0.004;\n",
+ "t1=288.;# in K\n",
+ "t2=333.;# in K\n",
+ "I=100.;# in A\n",
+ "Rs=50.;# in ohm\n",
+ "#calculations\n",
+ "theta=t2-t1;\n",
+ "Ra1=Ra+(alfa*Ra*theta);\n",
+ "N1=1+(Ra/Rsh);\n",
+ "Ia=I/N1;\n",
+ "N2=1+(Ra1/Rsh);\n",
+ "Ia1=I/N2;\n",
+ "epsilon1=(Ia1-Ia)*100/Ia;\n",
+ "N3=1+((Ra+Rs)/Rsh);\n",
+ "Ia2=I*10**3/N3;\n",
+ "N4=1+((Ra1+Rs)/Rsh);\n",
+ "Ia3=I*10**3/N4;\n",
+ "epsilon2=(Ia3-Ia2)*100/Ia2;\n",
+ "#results\n",
+ "print \"The percentage error in case 1 (%) = \",round(epsilon1,2)\n",
+ "print \"The percentage error in case 2 (%) = \",round(epsilon2,3)\n",
+ "print 'The answers are a bit different due to rounding off error in textbook'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 31 - pg 151"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "electromotive force is (mV)= 24.632\n",
+ "resistance is (ohm)= 105.263\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 151\n",
+ "#Example 2.31: Resistance and electromotive force\n",
+ "#calculate the electromotive force and resistance\n",
+ "#given data :\n",
+ "import numpy\n",
+ "from numpy import linalg\n",
+ "i1=20.;# in mA\n",
+ "i2=400.;# in mA\n",
+ "v1=19.5;# in mV\n",
+ "v2=23.4;# in mV\n",
+ "y=100;#mV\n",
+ "#calculations\n",
+ "i3=i1/i2;\n",
+ "K1=i1/i3;\n",
+ "x1=v1/K1;#\n",
+ "k2=y/i3;#\n",
+ "x2=v2/k2;#\n",
+ "A=numpy.matrix([[1, -x1],[1, -x2]]);\n",
+ "B=numpy.matrix([[v1],[v2]]);#\n",
+ "X=numpy.dot(numpy.linalg.inv(A),B);#\n",
+ "#results\n",
+ "print \"electromotive force is (mV)=\",round(X[0,0],3)\n",
+ "print \"resistance is (ohm)=\",round(X[1,0],3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 32 - pg 151"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Error (%) = 1.4\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 151\n",
+ "#Example 2.32: error\n",
+ "#calculate the error\n",
+ "#given data :\n",
+ "import math\n",
+ "V=20*10**3;# in V\n",
+ "v1=2*10**3;# in V\n",
+ "R=10*10**3;# in ohm\n",
+ "f=50.;# in Hz\n",
+ "#calculations\n",
+ "r=R*v1/V;\n",
+ "w=2*math.pi*f;\n",
+ "C=0.60*10**-6;# in F\n",
+ "v=V/((R/r)*math.sqrt(1+((w**2*C**2*r**2*(R-r)**2)/R**2)));\n",
+ "Error=((v1-v)/v1)*100;\n",
+ "#results\n",
+ "print \"Error (%) = \",round(Error,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 33 - pg 152"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "(i). Flux in the core (mWb) = 0.591\n",
+ "(ii). The actual ratio K = 161.04\n",
+ "(iii). The phase angle (degree) = 0.215\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 152\n",
+ "#Example 2.33: Flux, actual ratio and phase angle\n",
+ "#calculate the Flux, actual ratio and phase angle\n",
+ "#given data :\n",
+ "import math\n",
+ "from math import sin,cos\n",
+ "I=5.;# in A\n",
+ "r1=4.;# in ohm\n",
+ "r2=0.2;# in ohm\n",
+ "Ts=160;# in turns\n",
+ "F=50;# in Hz\n",
+ "I0=6;# in A\n",
+ "theta1=30/57.3;# in radians\n",
+ "#calculations\n",
+ "Es=I*(r1+r2);\n",
+ "fi=Es*10**3/(4.44*Ts*F);\n",
+ "Ie=I0*cos(theta1);# in A\n",
+ "Im=I0*sin(theta1);# in A\n",
+ "dela=0;\n",
+ "K=Ts+(((Ie*cos(dela))+(Im*sin(dela)))/I);\n",
+ "theta=(180/math.pi)*(((Im*cos(dela))-(Ie*sin(dela)))/(Ts*I));\n",
+ "#results\n",
+ "print \"(i). Flux in the core (mWb) = \",round(fi,3)\n",
+ "print \"(ii). The actual ratio K = \",round(K,2)\n",
+ "print \"(iii). The phase angle (degree) = \",round(theta,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34 - pg 152"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 38,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "(a). The ratio error (%) = -0.0436\n",
+ "(b). phase angle is 0.0 degree 3.438 minutes \n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 152\n",
+ "#Example 2.34: The ratio errror and phase angle error\n",
+ "#calculate the ratio error and phase angle\n",
+ "#given data :\n",
+ "import math\n",
+ "from math import sin,cos,sqrt\n",
+ "I=5.;# in A\n",
+ "n=1000./5;# normal ratio\n",
+ "sin_alfa=0.4;\n",
+ "Im=1;# in A\n",
+ "dela=0;\n",
+ "#calculations\n",
+ "cos_alfa=sqrt(1-sin_alfa**2);\n",
+ "I0=Im/cos_alfa;\n",
+ "Ie=I0*sin_alfa;\n",
+ "K=n+(((Ie*cos(dela))+(Im*sin(dela)))/I);\n",
+ "er=(n-K)*100/K;\n",
+ "eph=(180/math.pi)*(((Im*cos(dela))-(Ie*sin(dela)))/(n*I));\n",
+ "x=round(eph);#\n",
+ "y=eph-x;#\n",
+ "#results\n",
+ "print \"(a). The ratio error (%) = \",round(er,4)\n",
+ "print \"(b). phase angle is \",x,\" degree \",round(y*60,3),\" minutes \"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 35 - pg 153"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The ratio error,(%) = -0.744\n",
+ "The phase angle,(degree) = -0.252\n",
+ "The answers are a bit different due to rounding off error in textbook\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 153\n",
+ "#Example 2.35: The ratio errror and phase angle error\n",
+ "#calculate the ratio error and phase angle\n",
+ "#given data :\n",
+ "import math\n",
+ "from math import sin,cos,asin\n",
+ "I=5.;# in A\n",
+ "n=198.;# in turns\n",
+ "L=12.5;#in VA\n",
+ "f=50.;# assume in Hz\n",
+ "Ie=10.;# in A\n",
+ "Im=15.;# in A\n",
+ "l=1.*10**-3;# in H\n",
+ "#calculations\n",
+ "Kn=1000./I;\n",
+ "Zs=L/I**2;\n",
+ "Re=2*math.pi*f*l;# in ohm\n",
+ "dela=asin(Re/Zs)*180/math.pi;\n",
+ "K=n+(((Ie*cos(dela))+(Im*sin(dela)))/I);\n",
+ "Rerror=(Kn-K)*100./K;\n",
+ "eph=(180/math.pi)*(((Im*cos(dela))-(Ie*sin(dela)))/(n*I));\n",
+ "#results\n",
+ "print \"The ratio error,(%) = \",round(Rerror,3)\n",
+ "print \"The phase angle,(degree) = \",round(eph,3)\n",
+ "print 'The answers are a bit different due to rounding off error in textbook'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 36 - pg 154"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "phase angle is -4.7 minutes\n",
+ "load is (VA)= 12.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 154\n",
+ "#Example 2.36: phase angle error load in VA\n",
+ "#calculate the phase angle error load\n",
+ "#given data \n",
+ "import math\n",
+ "from math import sqrt\n",
+ "v1=1000.;#V\n",
+ "v2=100.;#V\n",
+ "xp=65.4;#ohm\n",
+ "rp=97.5;#ohm\n",
+ "pf=0.4;#\n",
+ "im=0.02;#A\n",
+ "Xp=110;#ohm\n",
+ "#calculations\n",
+ "r=v1/v2;#\n",
+ "sd=pf;#\n",
+ "csd=sqrt(1-pf**2);#\n",
+ "ie=im*(pf/csd);#A\n",
+ "th=((ie*xp)-(im*rp))/(r*v2);#rad\n",
+ "thd=th*(180/math.pi);#\n",
+ "iss=(r*((im*rp)-(ie*xp)))/(Xp);\n",
+ "va=iss*v2;#VA\n",
+ "#results\n",
+ "print \"phase angle is \",round(thd*60,1),\"minutes\"\n",
+ "print \"load is (VA)=\",round(va,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 37 - pg 155"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 41,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "flux is (m-Wb)= 0.18\n",
+ "ratio error is (%)= -3.61\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 155\n",
+ "#Example 2.37: flux and current ratio error\n",
+ "#calculate the flux and ratio error\n",
+ "#given\n",
+ "n1=1000.;#A\n",
+ "n2=5.;#A\n",
+ "r=1.6;#ohm\n",
+ "wt=1.5;#watt\n",
+ "f=50;#Hz\n",
+ "cd1=1;#\n",
+ "sd=0;#\n",
+ "#calculations\n",
+ "kn=n1/n2;#\n",
+ "ts=kn;#\n",
+ "es=n2*r;#v\n",
+ "ph=es/(4.44*f*kn);#m Wb\n",
+ "ep=es/kn;#\n",
+ "ie=wt/ep;#A\n",
+ "K=((kn+(ie/n2)));#\n",
+ "re=((kn-K)/K)*100;#\n",
+ "#results\n",
+ "print \"flux is (m-Wb)=\",round(ph*10**3,2)\n",
+ "print \"ratio error is (%)=\",round(re,2)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 38 - pg 155"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "RCF for case (a) = 1.0165\n",
+ "phase error for case (a) (%)= -1.623\n",
+ "phase angle error for case (a) 10.3 minutes\n",
+ "RCF for case (b) = 1.0075\n",
+ "phase error for case (b) (%)= -0.744\n",
+ "phase angle error for case (b)is 51.6 minutes\n",
+ "RCF for case (c) = 0.9925\n",
+ "phase error for case (c) (%)= 0.756\n",
+ "phase angle error for case (c) is 51.6 minutes\n",
+ "RCF for case (d) = 1.00825\n",
+ "phase error for case (d) (%)= -0.82\n",
+ "phase angle error for case (d) is 5.157 minutes\n",
+ "RCF for case (e) = 1.00375\n",
+ "phase error for case (e) (%)= -0.374\n",
+ "phase angle error for case (e) is 25.8 minutes\n",
+ "RCF for case (f) = 0.99625\n",
+ "phase error for case (f) (%)= 0.376\n",
+ "phase angle error for case (f) is 25.8 minutes\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 155\n",
+ "#Example 2.38: RCF ,ratio error and phase angle error\n",
+ "#calculate the ratio error, phase angle error and RCF in all cases\n",
+ "import math\n",
+ "from math import sqrt\n",
+ "#given\n",
+ "vp=2000.;#V\n",
+ "n=20.;#\n",
+ "va1=50.;#\n",
+ "pfl1=0.6;#lagging\n",
+ "va2=25.;#V\n",
+ "ie=0;#\n",
+ "im=0;#\n",
+ "cd1=0.6;#\n",
+ "rs1=0.75;#ohm\n",
+ "rp1=300.;#ohm\n",
+ "xs1=1.5;#ohm\n",
+ "xp1=600.;#ohm\n",
+ "#calculations and results\n",
+ "vs=vp/n;#\n",
+ "iss=va1/vs;#A\n",
+ "iss2=va2/vs;#A\n",
+ "sd1=sqrt(1-cd1**2);#\n",
+ "Rp1=n**2*rs1+rp1;#ohm\n",
+ "Xp1=n**2*xs1+xp1;#ohm\n",
+ "vps1=n+((iss/n)*(Rp1*cd1+Xp1*sd1))/vs;#\n",
+ "RCF1=vps1/n;#\n",
+ "er1=((n-vps1)/vps1)*100;#%\n",
+ "per1=((iss*(Xp1*cd1-Rp1*sd1))/(n**2*vs))*(180/math.pi);#degree\n",
+ "per1a=round(per1);#\n",
+ "x1=per1-per1a;#\n",
+ "print \"RCF for case (a) = \",RCF1\n",
+ "print \"phase error for case (a) (%)=\",round(er1,3)\n",
+ "print \"phase angle error for case (a) \",round(x1*60,1),\" minutes\"\n",
+ "cd11=1;#\n",
+ "sd11=sqrt(1-cd11**2);#\n",
+ "vps2=n+((iss/n)*(Rp1*cd11+Xp1*sd11))/vs;#\n",
+ "RCF2=vps2/n;#\n",
+ "er2=((n-vps2)/vps2)*100;#%\n",
+ "per2=((iss*(Xp1*cd11-Rp1*sd11))/(n**2*vs))*(180/math.pi);#degree\n",
+ "per1a1=round(per2);#\n",
+ "x2=per1-per1a1;#\n",
+ "print \"RCF for case (b) =\",RCF2\n",
+ "print \"phase error for case (b) (%)=\",round(er2,3)\n",
+ "print \"phase angle error for case (b)is \",round(per2*60,1),\" minutes\"\n",
+ "cd12=0.6;#\n",
+ "sd12=-0.8;#\n",
+ "vps3=n+((iss/n)*(Rp1*cd12+Xp1*sd12))/vs;#\n",
+ "RCF3=vps3/n;#\n",
+ "er3=((n-vps3)/vps3)*100;#%\n",
+ "per3=((iss*(Xp1*cd12-Rp1*sd12))/(n**2*vs))*(180/math.pi);#degree\n",
+ "per1a1=round(per2);#\n",
+ "x2=per1-per1a1;#\n",
+ "print \"RCF for case (c) =\",RCF3\n",
+ "print \"phase error for case (c) (%)=\",round(er3,3)\n",
+ "print \"phase angle error for case (c) is \",round(per3*60,1),\" minutes\"\n",
+ "cd13=0.6;#\n",
+ "sd13=0.8;#\n",
+ "vps4=n+((iss2/n)*(Rp1*cd13+Xp1*sd13))/vs;#\n",
+ "RCF4=vps4/n;#\n",
+ "er4=((n-vps4)/vps4)*100;#%\n",
+ "per4=((iss2*(Xp1*cd13-Rp1*sd13))/(n**2*vs))*(180/math.pi);#degree\n",
+ "per1a1=round(per2);#\n",
+ "x2=per1-per1a1;#\n",
+ "print \"RCF for case (d) =\",RCF4\n",
+ "print \"phase error for case (d) (%)=\",round(er4,2)\n",
+ "print \"phase angle error for case (d) is \",round(per4*60,3),\" minutes\"\n",
+ "cd14=1;#\n",
+ "sd14=0;#\n",
+ "vps5=n+((iss2/n)*(Rp1*cd14+Xp1*sd14))/vs;#\n",
+ "RCF5=vps5/n;#\n",
+ "er5=((n-vps5)/vps5)*100;#%\n",
+ "per5=((iss2*(Xp1*cd14-Rp1*sd14))/(n**2*vs))*(180/math.pi);#degree\n",
+ "per1a1=round(per2);#\n",
+ "x2=per1-per1a1;#\n",
+ "print \"RCF for case (e) =\",RCF5\n",
+ "print \"phase error for case (e) (%)=\",round(er5,3)\n",
+ "print \"phase angle error for case (e) is \",round(per5*60,1),\" minutes\"\n",
+ "cd15=0.6;#\n",
+ "sd16=-0.8;#\n",
+ "vps6=n+((iss2/n)*(Rp1*cd15+Xp1*sd16))/vs;#\n",
+ "RCF6=vps6/n;#\n",
+ "er6=((n-vps6)/vps6)*100;#%\n",
+ "per6=((iss2*(Xp1*cd15-Rp1*sd16))/(n**2*vs))*(180/math.pi);#degree\n",
+ "per1a1=round(per2);#\n",
+ "x2=per1-per1a1;#\n",
+ "print \"RCF for case (f) =\",RCF6\n",
+ "print \"phase error for case (f) (%)=\",round(er6,3)\n",
+ "print \"phase angle error for case (f) is \",round(per6*60,1),\" minutes\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 39 - pg 158"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 43,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ratio error (%)= -1.26\n",
+ "RCF = 1.01275\n",
+ "phase angle error (degree)= 0.73\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 158\n",
+ "#Example 2.39: ,ratio error and phase angle error\n",
+ "#calculate the ratio error,RCF and phase angle error\n",
+ "#given\n",
+ "import math\n",
+ "from math import cos, sin\n",
+ "vp=1000.;#V\n",
+ "iss=5.;#A\n",
+ "VA=25.;#\n",
+ "wt=0.25;#W\n",
+ "im=15.;#A\n",
+ "xs=1.;#ohm\n",
+ "rs=5.;#ohm\n",
+ "#calculations\n",
+ "n=vp/iss;#\n",
+ "vs=VA/iss;#\n",
+ "vp=iss/n;#V\n",
+ "ie=wt/vp;#A\n",
+ "dl=math.atan(xs/rs)*57.3;#\n",
+ "dlr=dl*(math.pi/180);#\n",
+ "K=n+((ie*cos(dl/57.3)+im*sin(dl/57.3))/iss);#\n",
+ "re=((n-K)/K)*100;#per\n",
+ "RCF=K/n;#\n",
+ "eph=(180/math.pi)*(((im*cos(dl/57.3))-(ie*sin(dl/57.3)))/(n*iss));\n",
+ "#results\n",
+ "print \"ratio error (%)=\",round(re,2)\n",
+ "print \"RCF =\",round(RCF,5)\n",
+ "print \"phase angle error (degree)=\",round(eph,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 40 - pg 159"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 44,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "true value of voltage is,(V)= 2030.0\n",
+ "true value of current is,(A)= 80.4\n",
+ "true value of power is ,(kW)= 149.4\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 159\n",
+ "#Example 2.40: true value of voltage ,current and power\n",
+ "#calculate the true value of voltage ,current and power\n",
+ "#given\n",
+ "import math\n",
+ "from math import acos,cos\n",
+ "vs=102.;#V\n",
+ "iss=4.;#A\n",
+ "ws=375.;#W\n",
+ "rcf=0.995;#\n",
+ "rcf1=1.005;#\n",
+ "a1=2000.;#\n",
+ "a2=100.;#\n",
+ "#calculations\n",
+ "ph=acos(ws/(iss*vs))*57.3;#degree\n",
+ "ph1=round(ph);#\n",
+ "x=ph-ph1;#\n",
+ "y=x*60;#\n",
+ "angd=y+22+10;#\n",
+ "ang=angd/60.;#\n",
+ "ta=ph1+ang;#\n",
+ "nr=a1/a2;#\n",
+ "avr=rcf*nr;#\n",
+ "pv=avr*vs;#\n",
+ "acr=rcf1*(a2/nr);#\n",
+ "pc=acr*iss*iss;#A\n",
+ "psd=pv*pc*cos(ta/57.3)*10**-3;#\n",
+ "#results\n",
+ "print \"true value of voltage is,(V)=\",round(pv)\n",
+ "print \"true value of current is,(A)=\",pc\n",
+ "print \"true value of power is ,(kW)=\",round(psd,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 41 - pg 160"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 46,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "primary current is,(A)= 498.415\n",
+ "phase error is (radian)= 0.0058\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 160\n",
+ "#Example 2.41:primary current ,phase error \n",
+ "#calculate the primary current ,phase error \n",
+ "#given\n",
+ "import math,cmath\n",
+ "from math import cos,sin\n",
+ "zs=0.433+1j*0.25;#ohm\n",
+ "zs1=0.15+1j*0.0;#ohm\n",
+ "nt=2.;#turns\n",
+ "l1=8.;#\n",
+ "l2=4.;#\n",
+ "tnt=198;#turns\n",
+ "iss=5;#A\n",
+ "#calculations\n",
+ "zs2=zs+zs1;#ohm\n",
+ "zsa=math.sqrt((zs2.real)**2+(zs2.imag)**2);#\n",
+ "zsng=math.atan(zs2.imag/zs2.real);#\n",
+ "ie=l2/nt;#\n",
+ "im=l1/nt;#\n",
+ "K=((tnt/2.)+((ie*cos(zsng))+(im*sin(zsng)))/iss);#\n",
+ "ip=K*iss;#A\n",
+ "th=((im*cos(zsng))-(ie*sin(zsng)))/((tnt/2)*iss);#\n",
+ "#results\n",
+ "print \"primary current is,(A)=\",round(ip,3)\n",
+ "print \"phase error is (radian)=\",round(th,4)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 42 - pg 160"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 47,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ratio error (%)= -1.26\n",
+ "RCF = 1.01275\n",
+ "phase angle error (degree)= 0.73\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 158\n",
+ "#Example 2.39: ,ratio error and phase angle error\n",
+ "#calculate the ratio error,RCF and phase angle error\n",
+ "#given\n",
+ "import math\n",
+ "from math import cos, sin\n",
+ "vp=1000.;#V\n",
+ "iss=5.;#A\n",
+ "VA=25.;#\n",
+ "wt=0.25;#W\n",
+ "im=15.;#A\n",
+ "xs=1.;#ohm\n",
+ "rs=5.;#ohm\n",
+ "#calculations\n",
+ "n=vp/iss;#\n",
+ "vs=VA/iss;#\n",
+ "vp=iss/n;#V\n",
+ "ie=wt/vp;#A\n",
+ "dl=math.atan(xs/rs)*57.3;#\n",
+ "dlr=dl*(math.pi/180);#\n",
+ "K=n+((ie*cos(dl/57.3)+im*sin(dl/57.3))/iss);#\n",
+ "re=((n-K)/K)*100;#per\n",
+ "RCF=K/n;#\n",
+ "eph=(180/math.pi)*(((im*cos(dl/57.3))-(ie*sin(dl/57.3)))/(n*iss));\n",
+ "#results\n",
+ "print \"ratio error (%)=\",round(re,2)\n",
+ "print \"RCF =\",round(RCF,5)\n",
+ "print \"phase angle error (degree)=\",round(eph,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 43 - pg 161"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "current is (mA)= 1.1474\n",
+ "The answer is a bit different due to rounding off error in textbook\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 161\n",
+ "#Example 2.43 :percentage change in current\n",
+ "#calculate the current\n",
+ "#given data\n",
+ "import math,cmath\n",
+ "r=0.5;#kilo ohm\n",
+ "r1=1.;#kilo ohm\n",
+ "f=50.;#Hz\n",
+ "V=1.;#V\n",
+ "#calculations\n",
+ "z1=((1j*r1*r)/(r1+1j*r));#kilo-ohm\n",
+ "z1m=abs(z1);#kilo-ohm\n",
+ "z2=((1j*r1*r)/(r+1j*r1));#kilo-ohm\n",
+ "z2m=abs(z2);#kilo-ohm\n",
+ "tz=z1m+z2m;#kilo-ohm\n",
+ "i=V/tz;#A\n",
+ "v1=i*z1m*10**-3;#V\n",
+ "v2=i*10**-3*z2m;#V\n",
+ "df=f-((f*5)/100);#Hz\n",
+ "rc1=((r*df)/f);#k-ohm\n",
+ "rc2=((r1*df)/f);#k-ohm\n",
+ "z1n=((1j*rc1)/(r1+1j*rc1));#\n",
+ "z1nm=abs(z1n);#k-ohm\n",
+ "z2n=((1j*rc2*r)/(r+1j*rc2));#\n",
+ "z2nm=abs(z2n);#k-ohm\n",
+ "znw=z1nm+z2nm;#k-ohm\n",
+ "inn=V/znw;#\n",
+ "#results\n",
+ "print \"current is (mA)=\",round(inn,4)\n",
+ "print 'The answer is a bit different due to rounding off error in textbook'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 44 - pg 162"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "inductance is (H)= 9.73\n",
+ "frequency is (Hz)= 41.7\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 162\n",
+ "#Example 2.44 :Inductance\n",
+ "#calculate the inductance and frequency\n",
+ "#given data\n",
+ "import math,cmath\n",
+ "c=1.;#micro-F\n",
+ "f1=60.;#Hz\n",
+ "f=50.;#Hz\n",
+ "#calculations\n",
+ "l1=((c*10**6)/(f1**2*(2*math.pi)**2));#\n",
+ "r1=100;#ohm\n",
+ "z1=r1+1j*((2*math.pi*f*l1)-(1/(2*math.pi*f*c*10**-6)));#ohm\n",
+ "c2=1.5;#micro-F\n",
+ "l2=((-z1.imag)+(1/(2*math.pi*c2)))/100;#H\n",
+ "f2=(1/(2*math.pi))*math.sqrt(1/(l2*c2*10**-6));#Hz\n",
+ "#results\n",
+ "print \"inductance is (H)=\",round(l2,2)\n",
+ "print \"frequency is (Hz)=\",round(f2,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 45 - pg 163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 50,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "true value of voltage is,(V)= 2030.0\n",
+ "true value of current is,(A)= 80.4\n",
+ "true value of power is ,(kW)= 149.4\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 159\n",
+ "#Example 2.40: true value of voltage ,current and power\n",
+ "#calculate the true value of voltage ,current and power\n",
+ "#given\n",
+ "import math\n",
+ "from math import acos,cos\n",
+ "vs=102.;#V\n",
+ "iss=4.;#A\n",
+ "ws=375.;#W\n",
+ "rcf=0.995;#\n",
+ "rcf1=1.005;#\n",
+ "a1=2000.;#\n",
+ "a2=100.;#\n",
+ "#calculations\n",
+ "ph=acos(ws/(iss*vs))*57.3;#degree\n",
+ "ph1=round(ph);#\n",
+ "x=ph-ph1;#\n",
+ "y=x*60;#\n",
+ "angd=y+22+10;#\n",
+ "ang=angd/60.;#\n",
+ "ta=ph1+ang;#\n",
+ "nr=a1/a2;#\n",
+ "avr=rcf*nr;#\n",
+ "pv=avr*vs;#\n",
+ "acr=rcf1*(a2/nr);#\n",
+ "pc=acr*iss*iss;#A\n",
+ "psd=pv*pc*cos(ta/57.3)*10**-3;#\n",
+ "#results\n",
+ "print \"true value of voltage is,(V)=\",round(pv)\n",
+ "print \"true value of current is,(A)=\",pc\n",
+ "print \"true value of power is ,(kW)=\",round(psd,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 46 - pg 163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 51,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Series resistance,Rs(ohm) = 8000.0\n",
+ "answer is wrong in the textbook due to rounding off error\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 160\n",
+ "#Example 2.42: Resistance\n",
+ "#calculate the Series resistance\n",
+ "import math\n",
+ "#given data :\n",
+ "f=50.;#/ in Hz\n",
+ "r=2000.;# in ohm\n",
+ "L=0.5;# in H\n",
+ "V=100.;# in V\n",
+ "#calculations\n",
+ "Zm=math.sqrt(r**2+(2*math.pi*f*L));\n",
+ "im=V/Zm;\n",
+ "Rs=(500.-(im*Zm))/im;\n",
+ "#results\n",
+ "print \"Series resistance,Rs(ohm) = \",round(Rs)\n",
+ "print 'answer is wrong in the textbook due to rounding off error'\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter3.ipynb b/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter3.ipynb
new file mode 100755
index 00000000..b28ca570
--- /dev/null
+++ b/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter3.ipynb
@@ -0,0 +1,3283 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 3 - Measurement of parameters"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1 - pg 194"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "(a). True value of unknown resistance Xt(ohm) = 8.13\n",
+ "(b). % error (%) = -1.6\n",
+ " i.e. 1.6 10w\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 194\n",
+ "#Example 3.1: Resistance and percentage error\n",
+ "#calculate the Resistance and percentage error\n",
+ "#given data :\n",
+ "V=3.2;# in V\n",
+ "I=0.4;# in A\n",
+ "Rv=500.;# in ohm\n",
+ "#calculations\n",
+ "Xt=V/(I*(1-(V/(I*Rv))));\n",
+ "Xm=V/I;\n",
+ "Pe=((Xm-Xt)/Xt)*100;\n",
+ "#results\n",
+ "print \"(a). True value of unknown resistance Xt(ohm) = \",round(Xt,2)\n",
+ "print \"(b). % error (%) =\",Pe\n",
+ "print \" i.e.\",-Pe,\"10w\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2 - pg 195"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Measured value of resistance (ohm) = 0.833\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 195\n",
+ "#Example 3.2: Measured value of resistance\n",
+ "#calculate the Measured value of resistance\n",
+ "#given data :\n",
+ "a=1.;# in ohm\n",
+ "b=5.;# in ohm\n",
+ "I=0.1;# in A\n",
+ "#calculations\n",
+ "A=(1/a)+(1/b);\n",
+ "r=1/A;\n",
+ "V=r*I;\n",
+ "Mr=V/I;\n",
+ "#results\n",
+ "print \"Measured value of resistance (ohm) = \",round(Mr,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3 - pg 195"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Resistance of resistor under test X(ohm) = 0.015\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 195\n",
+ "#Example 3.3: Resistor\n",
+ "#calculate the Resistor\n",
+ "#given data :\n",
+ "S=0.02;# in ohm\n",
+ "Vs=0.98;# in V\n",
+ "Vx=0.735;# in V\n",
+ "#calculate\n",
+ "X=(S*Vx)/Vs;\n",
+ "#results\n",
+ "print \"Resistance of resistor under test X(ohm) = \",X\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4 - pg 196"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Resistance of unknown resistor R(ohm) = 0.0411\n",
+ "Current through the resistor I(A) = 10.235\n",
+ "Power loss in the unknown resistance P(W) = 4.31\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 196\n",
+ "#Example 3.4: Resistor,current and power loss\n",
+ "#calculate the Resistor,current and power loss\n",
+ "#given data :\n",
+ "S=0.1;# in ohm\n",
+ "Vs=1.0235;# in V\n",
+ "Vr=0.4211;# in V\n",
+ "#calculations\n",
+ "R=(Vr/Vs)*S;\n",
+ "I=Vs/S;\n",
+ "P=I**2 *R;\n",
+ "#results\n",
+ "print \"Resistance of unknown resistor R(ohm) = \",round(R,4)\n",
+ "print \"Current through the resistor I(A) = \",I\n",
+ "print \"Power loss in the unknown resistance P(W) = \",round(P,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5 - pg 196"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Magnitude of error (micro-ohm) = 0.028129\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 196\n",
+ "#Example 3.5: Magnitude of error\n",
+ "#calculate the Magnitude of error\n",
+ "#given data :\n",
+ "p=100.31;# in ohm\n",
+ "q=200.;# in ohm\n",
+ "P=100.24;# in ohm\n",
+ "Q=200.;# in ohm\n",
+ "S=100.03*10**-6;# in ohm\n",
+ "r=700.*10**-6;# in ohm\n",
+ "Y=50.;# in micro-ohm\n",
+ "#calculations\n",
+ "X=(((P/Q)*S)+(((q*r)/(p+q))*((P/Q)-(p/q))))*10**6;\n",
+ "Error=Y-X;\n",
+ "#results\n",
+ "print \"Magnitude of error (micro-ohm) = \",round(Error,6)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6 - pg 196"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Unknown resistance X(m-ohm) = 1.503\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 196\n",
+ "#Example 3.6: Unknown resistance\n",
+ "#calculate the Unknown resistance\n",
+ "#given data :\n",
+ "p=100.6;# in ohm\n",
+ "q=300.25;# in ohm\n",
+ "P=100.5;# in ohm\n",
+ "Q=300.;# in ohm\n",
+ "S=0.0045;# in ohm\n",
+ "r=0.1;# in ohm\n",
+ "#calculations\n",
+ "X=(((P/Q)*S)+(((q*r)/(p+q+r))*((P/Q)-(p/q))))*10**3;\n",
+ "#results\n",
+ "print \"Unknown resistance X(m-ohm) = \",round(X,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7 - pg 197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "unknown resistance is (Mega-ohm)= 0.4\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 197\n",
+ "#Example 3.7: Unknown resistance\n",
+ "#calculate the Unknown resistance\n",
+ "#given data :\n",
+ "s=0.5;#Mega ohms\n",
+ "g=10.;#killo ohms\n",
+ "d1=41.;#divisions\n",
+ "d2=51.;#divisions\n",
+ "#calculations\n",
+ "r=(((s*10**6)+(g*10**3))*(d1/d2))-(g*10**3);#ohms\n",
+ "#results\n",
+ "print \"unknown resistance is (Mega-ohm)=\",r*10**-6\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8 - pg 197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Unknown resistance R(ohm) = 460.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 197\n",
+ "#Example 3.8: Unknown resistance\n",
+ "#calculate the Unknown resistance\n",
+ "#given data :\n",
+ "P=100.;# in ohm\n",
+ "Q=10.;# in ohm\n",
+ "S=46.;# in ohm\n",
+ "#calculations\n",
+ "R=((P/Q)*S);\n",
+ "#results\n",
+ "print \" Unknown resistance R(ohm) = \",R\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9 - pg 197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "limiting value of resistance is 3154.0 + 0.2 % to 3217.0 ohm\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 197\n",
+ "#Example 3.9: limiting value of unknown resistance\n",
+ "#calculate the limiting value of unknown resistance\n",
+ "#given data :\n",
+ "P=1000.;# in ohm\n",
+ "Q=1000.;# in ohm\n",
+ "S=3154.;# in ohm\n",
+ "dp=0.05;#percentage error\n",
+ "dq=0.05;#percentage error\n",
+ "ds=0.1;#percentage error\n",
+ "#calculations\n",
+ "R=((P/Q)*S);\n",
+ "dr=dp+dq+ds;#percentage error\n",
+ "x=R+((dr*10)*R)/100;#\n",
+ "#results\n",
+ "print \"limiting value of resistance is \",R,\"+\",dr,\"% to \",round(x),\" ohm\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10 - pg 197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "unknown resistance is (Ohm)= 0.3\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 197\n",
+ "#Example 3.10: value of unknown resistance\n",
+ "#calculate the value of unknown resistance\n",
+ "#given data\n",
+ "ra=1200.;#ohms\n",
+ "#calculations\n",
+ "rb=ra/1600;#ohms\n",
+ "r1=800*rb;#ohms\n",
+ "r2=r1/1.25;#ohms\n",
+ "r3=0.5*rb;#ohms\n",
+ "rx=((r2/r1)*r3);#ohms\n",
+ "#results\n",
+ "print \"unknown resistance is (Ohm)=\",rx\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11 - pg 198"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Unknown resistance R(ohm) = 2.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 198\n",
+ "#Example 3.11: Unknown resistance\n",
+ "#calculate the Unknown resistance\n",
+ "#given data :\n",
+ "AB=25.;# in ohm\n",
+ "BC=75.;# in ohm\n",
+ "S=6.;# in ohm\n",
+ "#calculations\n",
+ "R=((AB/BC)*S);\n",
+ "#results\n",
+ "print \"Unknown resistance R(ohm) = \",R\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12 - pg 199"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "In case 1 balance is obtained at 25.0 and 75.0 scale divisions\n",
+ "In case 2 balance is obtained at 5.0 and 95.0 cm\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 199\n",
+ "#Example 3.12: length\n",
+ "#calculate the balance length\n",
+ "#given data\n",
+ "r=0.0250;#ohms\n",
+ "l=100.;#cm\n",
+ "d=100;#divisions\n",
+ "p=10.;#ohms\n",
+ "q=10.;#ohms\n",
+ "r2=1.0125;#ohms\n",
+ "r3=1;#ohms\n",
+ "p1=9.95;#ohms\n",
+ "q1=10.05;#ohms\n",
+ "#calculations\n",
+ "r1=r/l;#ohm/cm\n",
+ "x=p/q;#\n",
+ "l1=((r3+r)-r2)/(2*r1);#cm\n",
+ "l2=100-l1;#cm\n",
+ "x1=p1/q1;#\n",
+ "l11=((p1*(r3+r))-(q1*r2))/((p1*r1)+(q1*r1));#cm\n",
+ "l21=100-round(l11);#cm\n",
+ "#results\n",
+ "print \"In case 1 balance is obtained at \",l1,\" and \",l2,\" scale divisions\"\n",
+ "print \"In case 2 balance is obtained at \",round(l11),\" and \",l21,\" cm\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13 - pg 199"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Insolution resistance R(M-ohm) = 186726.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 199\n",
+ "#Example 3.13: Insolution resistance\n",
+ "#calculate the Insolution resistance\n",
+ "#given data :\n",
+ "import math\n",
+ "V1=125.;# in V\n",
+ "V2=100.;# in V\n",
+ "t=25.;# in sec\n",
+ "C=600*10**-12;# in F\n",
+ "#calculations\n",
+ "R=t*10**-6/(C*math.log(V1/V2));\n",
+ "#results\n",
+ "print \"Insolution resistance R(M-ohm) = \",round(R)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14 - pg 199"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Insolution resistance R(M-ohm) = 5.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 199\n",
+ "#Example 3.14: Insolution resistance of the cable\n",
+ "#calculate the Insolution resistance of the cable\n",
+ "import math\n",
+ "from math import log10\n",
+ "y=10.;#Mega ohms\n",
+ "d=200.;#divisioms\n",
+ "d1=126.;#divisions\n",
+ "d2=100.;#divisions\n",
+ "c=1;#assume\n",
+ "t=30.;#seconds\n",
+ "x=0.4343\n",
+ "#calculations\n",
+ "r=((x*t)/(c*log10(d/d1)));#\n",
+ "rd=((x*t)/(c*log10(d/d2)));#\n",
+ "x=rd/r;#\n",
+ "ro=((y-(10*x))/x);#Mega ohms\n",
+ "#results\n",
+ "print \"Insolution resistance R(M-ohm) = \",round(ro)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 15 - pg 200"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Unknown resistance,R(M-ohm) = 46.98\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 200\n",
+ "#Example 3.15:\n",
+ "#calculate the High resistance\n",
+ "#given data :\n",
+ "import math\n",
+ "V1=500.;# in V\n",
+ "V2=300.;# in V\n",
+ "t=60.;# in sec\n",
+ "C=2.5*10**-6;# in F\n",
+ "#calculations\n",
+ "R=t*10**-6/(C*math.log(V1/V2));\n",
+ "#results\n",
+ "print \"Unknown resistance R(M-ohm) = \",round(R,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16 - pg 200"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Insolution resistance R(M-ohm) = 560.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 200\n",
+ "#Example 3.16: Insolution resistance of the cable\n",
+ "#calculate the Insolution resistance of the cable\n",
+ "US=2.5;#SHUNT\n",
+ "SD=250;#DIVISIONS\n",
+ "sr=350;#scale readomh\n",
+ "sd1=1000;#shunt\n",
+ "r=1;#Mega ohms\n",
+ "#calculations\n",
+ "x=US*SD;#\n",
+ "y=sr*sd1;#\n",
+ "ro=(y/x)*r;#mega ohms\n",
+ "#results\n",
+ "print \"Insolution resistance R(M-ohm) = \",round(ro)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 17 - pg 201"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "As 160000.0 = 160000.0 (Z1*Z4=Z2*Z3) firts condition is satisfied\n",
+ "As 70.0 is not equal to -10.0 (Sum of angles) second condition is not staisfied (so bridge is not balanced) \n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 201\n",
+ "#Example 3.17: Bridhe Balanced\n",
+ "#calculate the Bridhe Balanced condition\n",
+ "z1m=400.;#ohms\n",
+ "z1a=50.;#degree\n",
+ "z2m=200.;#ohms\n",
+ "z2a=40.;#degree\n",
+ "z3m=800.;#ohms\n",
+ "z3a=-50.;#degree\n",
+ "z4m=400.;#ohms\t\n",
+ "z4a=20.;#degree\n",
+ "#calculations\n",
+ "x=z1m*z4m;#ohms\n",
+ "y=z2m*z3m;#ohms\n",
+ "a=z1a+z4a;#degree\n",
+ "b=z2a+z3a;#degree\n",
+ "#results\n",
+ "print \"As \",x,\"=\",y,\" (Z1*Z4=Z2*Z3) firts condition is satisfied\"\n",
+ "print \"As \",a,\"is not equal to\",b,\"(Sum of angles) second condition is not staisfied (so bridge is not balanced) \""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 18 - pg 201"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Resistance R1(ohm) = 31.34\n",
+ "inductance L1(mH) = 47.8\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 201\n",
+ "#Example 3.18:Resistance \n",
+ "#calculate the Resistance and inductance\n",
+ "#given data :\n",
+ "R2=100.;# in ohm\n",
+ "R3=32.7;# in ohm\n",
+ "R4=100.;# in ohm\n",
+ "R=1.36;# in ohm\n",
+ "L=47.8;# in mH\n",
+ "#calculations\n",
+ "R1=(R2*R3/R4)-R;\n",
+ "L1=(R2/R4)*L;\n",
+ "#results\n",
+ "print \"Resistance R1(ohm) = \",R1\n",
+ "print \"inductance L1(mH) = \",L1\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19 - pg 201"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm)= 23.0\n",
+ "inductance is (mH)= 50.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 201\n",
+ "#Example 3.19:Resistance and Inductance\n",
+ "#calculate the Resistance and Inductance\n",
+ "#given data\n",
+ "import math,cmath\n",
+ "f=1;#assume\n",
+ "r1=25;#ohms\n",
+ "i=50.;#MH\n",
+ "x=r1+1j*(2*math.pi*f*(i*10**-3));#\n",
+ "r2=2;#ohms\n",
+ "r=x.real-r2;#ohms\n",
+ "l=x.imag/(2*math.pi*f);#henry\n",
+ "print \"resistance is (ohm)=\",r\n",
+ "print \"inductance is (mH)=\",l*1000.\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 20 - pg 202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Unknown resistance R1(ohm) = 240.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 202\n",
+ "#Example 3.20:Resistance \n",
+ "#calculate the Unknown resistance\n",
+ "#given data :\n",
+ "R2=600.;# in ohm\n",
+ "R3=400.;# in ohm\n",
+ "R4=1000.;# in ohm\n",
+ "#calculations\n",
+ "R1=(R2*R3/R4);\n",
+ "#results\n",
+ "print \"Unknown resistance R1(ohm) = \",R1"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 21 - pg 202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Resistance rx(ohm) = 675.0\n",
+ "Inductance L(mH) = 270.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 202\n",
+ "#Example 3.21:Resistance and inductance\n",
+ "#calculate the Resistance and inductance\n",
+ "#given data :\n",
+ "S=900;# in ohm\n",
+ "P=1.5*10**3;# in ohm\n",
+ "Q=2*10**3;# in ohm\n",
+ "Cs=0.2*10**-6;# in F\n",
+ "#calculations\n",
+ "rx=S*P/Q;\n",
+ "L=P*Cs*S*10**3;\n",
+ "#results\n",
+ "print \"Resistance rx(ohm) = \",rx\n",
+ "print \"Inductance L(mH) = \",L\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 22 - pg 202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Resistance R(ohm) = 1000.0\n",
+ "Inductance L(H) = 2.4\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 202\n",
+ "#Example 3.22:Resistance and inductance\n",
+ "#calculate the Resistance and inductance\n",
+ "#given data :\n",
+ "S=2000.;# in ohm\n",
+ "P=1000.;# in ohm\n",
+ "C=1*10**-6;# in F\n",
+ "r=200;# in ohm\n",
+ "#calculations\n",
+ "Q=S;# in ohm\n",
+ "R=P*Q/S;\n",
+ "L=(C*P/S)*(r*(Q+S)+(Q*S));\n",
+ "#results\n",
+ "print \"Resistance R(ohm) = \",R\n",
+ "print \"Inductance L(H) = \",L\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23 - pg 202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Resistance R1(ohm) = 81.9\n",
+ "inductance L1(H) = 0.0767\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 202\n",
+ "#Example 3.23:Resistance and inductance\n",
+ "#calculate the Resistance and inductance\n",
+ "#given data :\n",
+ "R2=250.;# in ohm\n",
+ "R3=100.;# in ohm\n",
+ "R4=200.;# in ohm\n",
+ "r1=43.1;# in ohm\n",
+ "r=229.7;# in ohm\n",
+ "C=1*10**-6;# in F\n",
+ "#calculations\n",
+ "R1=(R2*R3/R4)-r1;\n",
+ "L1=(C*R3/R4)*(r*(R4+R2)+(R2*R4));\n",
+ "#results\n",
+ "print \"Resistance R1(ohm) = \",R1\n",
+ "print \"inductance L1(H) = \",round(L1,4)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24 - pg 203"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Resistance R1(ohm) = 500.0\n",
+ "inductance L(H) = 1.95\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 203\n",
+ "#Example 3.24:Resistance and inductance\n",
+ "#calculate the Resistance and inductance\n",
+ "#given data :\n",
+ "R2=1000.;# in ohm\n",
+ "R3=500.;# in ohm\n",
+ "R4=1000.;# in ohm\n",
+ "r=100;# in ohm\n",
+ "C=3*10**-6;# in F\n",
+ "#calculations\n",
+ "R1=(R2*R3/R4);\n",
+ "L=(C*R2/R4)*(r*(R4+R3)+(R3*R4));\n",
+ "#results\n",
+ "print \"Resistance R1(ohm) = \",R1\n",
+ "print \"inductance L(H) = \",L\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 25 - pg 203"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Inductance L1(H) = 6.321\n",
+ "Resistance R1(ohm) = 197.491\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 203\n",
+ "#Example 3.25:Resistance and inductance\n",
+ "#calculate the Resistance and inductance\n",
+ "#given data :\n",
+ "import math\n",
+ "R2=1000;# in ohm\n",
+ "R3=16800;# in ohm\n",
+ "R4=833;# in ohm\n",
+ "C4=0.38*10**-6;# in F\n",
+ "f=50;# in Hz\n",
+ "#calculations\n",
+ "w=2*math.pi*f;\n",
+ "L1=(R2*R3*C4)/(1+w**2*C4**2*R4**2);\n",
+ "R1=(R2*R3*R4*w**2*C4**2)/(1+w**2*C4**2*R4**2);\n",
+ "#results\n",
+ "print \"Inductance L1(H) = \",round(L1,3)\n",
+ "print \"Resistance R1(ohm) = \",round(R1,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 26 - pg 204"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Inductance L1(H) = 0.63\n",
+ "Resistance R1(ohm) = 141.1\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 204\n",
+ "#Example 3.26:Resistance and inductance\n",
+ "#calculate the Resistance and inductance\n",
+ "#given data :\n",
+ "import math\n",
+ "R2=2410.;# in ohm\n",
+ "R3=750.;# in ohm\n",
+ "R4=64.9;# in ohm\n",
+ "C4=0.35*10**-6;# in F\n",
+ "f=500.;# in Hz\n",
+ "#calculations\n",
+ "w=2*math.pi*f;\n",
+ "L1=(R2*R3*C4)/(1+w**2*C4**2*R4**2);\n",
+ "R1=(R2*R3*R4*w**2*C4**2)/(1+w**2*C4**2*R4**2);\n",
+ "#results\n",
+ "print \"Inductance L1(H) = \",round(L1,2)\n",
+ "print \"Resistance R1(ohm) = \",round(R1,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 27 - pg 204"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Inductance,L1(H) = 6.32\n",
+ "Resistance,R1(ohm) = 197.0\n",
+ "resistance is calculated wrong in the textbook\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 204\n",
+ "#Example 3.27:Resistance and inductance\n",
+ "#calculate the Resistance and inductance\n",
+ "#given data :\n",
+ "import math\n",
+ "R3=16800.;# in ohm\n",
+ "R2=1000.;# in ohm\n",
+ "R4=833.;# in ohm\n",
+ "C4=0.38*10**-6;# in F\n",
+ "f=50;# in Hz\n",
+ "#calculations\n",
+ "w=2*math.pi*f;\n",
+ "L1=(R2*R3*C4)/(1+w**2*C4**2*R4**2);\n",
+ "R1=(R2*R3*R4*w**2*C4**2)/(1+(w**2*C4**2*R4**2));\n",
+ "#results\n",
+ "print \"Inductance,L1(H) = \",round(L1,2)\n",
+ "print \"Resistance,R1(ohm) = \",round(R1,0)\n",
+ "print 'resistance is calculated wrong in the textbook'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 28 - pg 205"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "inductance is (mH)= 8.34\n",
+ "resistance is (ohm)= 80.65\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 205\n",
+ "#Example 3.28:Resistance and Inductance\n",
+ "#calculate the Resistance and Inductance\n",
+ "r3=100;#ohms\n",
+ "c4=0.1;#micro-farads\n",
+ "r2=834;#ohms\n",
+ "c2=0.124;#micro farads\n",
+ "#calculations\n",
+ "la=r2*r3*c4*10**-3;#mH\n",
+ "r1=(r3)*(c4/c2);#ohms\n",
+ "#results\n",
+ "print \"inductance is (mH)=\",la\n",
+ "print \"resistance is (ohm)=\",round(r1,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 29 - pg 205"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Unknown capacitance C2(micro-F) = 1.0\n",
+ "Phase angle error del1(degree) = 3.6\n",
+ "Phase angle error del2(degree) = 3.6\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 205\n",
+ "#Example 3.29: Phase angle error and Capacitance\n",
+ "#calculate the Phase angle error and Capacitance\n",
+ "#given data :\n",
+ "import math\n",
+ "C1=1*10**-6;# in F\n",
+ "R1=1000.;# in ohm\n",
+ "R2=1000.;# in ohm\n",
+ "f=1000.;# in Hz\n",
+ "r1=10.;# in ohm\n",
+ "R3=2000.;# in ohm\n",
+ "R4=2000.;#/ in ohm\n",
+ "#calculations\n",
+ "C2=C1*R1*10**6/R2;\n",
+ "w=2*math.pi*f;\n",
+ "r2=(R2*(R3+r1)-(R1*R4))/R1;\n",
+ "del1=w*r1*C1*(180/math.pi);\n",
+ "del2=r2*w*C2*10**-6*(180/math.pi);\n",
+ "#results\n",
+ "print \"Unknown capacitance C2(micro-F) = \",C2\n",
+ "print \"Phase angle error del1(degree) = \",del1\n",
+ "print \"Phase angle error del2(degree) = \",del2\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 30 - pg 206"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Series resistance Rs(M-ohm) = 0.5\n",
+ "capacitance is (micro-F)= 309.0\n",
+ "Loss angle del(degree) = 2.779\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 206\n",
+ "#Example 3.30: Series resistance and loss angle\n",
+ "#calculate the Series resistance and loss angle\n",
+ "#given data :\n",
+ "import math\n",
+ "R2=100.;# in ohm\n",
+ "R4=309.;# in ohm\n",
+ "C3=100.*10**-12;# in F\n",
+ "C4=0.5*10**-6;# in F\n",
+ "f=50;# in Hz\n",
+ "#calculations\n",
+ "w=2*math.pi*f;\n",
+ "Rs=C4*R2*10**-6/C3;\n",
+ "Cs=R4*C3*10**12/R2;\n",
+ "dela=math.atan(w*Cs*Rs*10**-6)*57.3;\n",
+ "#results\n",
+ "print \"Series resistance Rs(M-ohm) = \",Rs\n",
+ "print \"capacitance is (micro-F)=\",Cs\n",
+ "print \"Loss angle del(degree) = \",round(dela,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 31 - pg 206"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 83,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Cable capacitance Cs(PF) = 199.0\n",
+ "Parallel loss resistance rs(M-ohm) = 2.43\n",
+ "loss angle is (degree)= 8.11\n",
+ "power loss is = 10000000000\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 206\n",
+ "#Example 3.31: Capacitance, power loss, loss resistance and loss angle\n",
+ "#calculate the Cable Capacitance, power loss, loss resistance and loss angle\n",
+ "#given data :\n",
+ "import math\n",
+ "r2=1500/math.pi;# in ohm\n",
+ "r3=120.;# in ohm\n",
+ "C2=0.95*10**-6;#F\n",
+ "C1=50*10**-12;# F\n",
+ "f=50;\n",
+ "#calculations\n",
+ "Cs=round(C1*r2*10**12/r3);\n",
+ "w=round(2*math.pi*f);\n",
+ "rs=(r3/(w**2*C1*10));\n",
+ "dela=math.atan(100*math.pi*C2*r2)*57.3;#\n",
+ "v=100;#kV\n",
+ "pl=(v*10**3)**2;#\n",
+ "#results\n",
+ "print \"Cable capacitance Cs(PF) = \",Cs\n",
+ "print \"Parallel loss resistance rs(M-ohm) = \",round(rs*10**-6,2)\n",
+ "print \"loss angle is (degree)=\",round(dela,2)\n",
+ "print \"power loss is =\",pl\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 32 - pg 207"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "frequency is (Hz)= 398.0\n",
+ "resistance is (ohm)= 1000.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 207\n",
+ "#Example 3.32:frequency and resistance\n",
+ "#calculate the frequency and resistance\n",
+ "#given data\n",
+ "import math\n",
+ "r1=400.;#ohms\n",
+ "c1=1.;#micro farads\n",
+ "r2=1000.;#ohms\n",
+ "r3=800.;#ohms\n",
+ "c3=0.5;#micro farads\n",
+ "#calculations\n",
+ "f=((1/((2*math.pi)*math.sqrt(r1*r3*c1*10**-6*c3*10**-6))));#Hz\n",
+ "x=((c3/c1)+(r1/r3));#\n",
+ "r4=r2*x;#ohms\n",
+ "#results\n",
+ "print \"frequency is (Hz)=\",round(f)\n",
+ "print \"resistance is (ohm)=\",r4\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 33 - pg 207"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm)= 400.0\n",
+ "frequency is (Hz)= 398.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 207\n",
+ "#Example 3.33:frequency and resistance\n",
+ "#calculate the frequency and resistance\n",
+ "import math\n",
+ "r1=200.;#ohms\n",
+ "c1=1.;#micro farads\n",
+ "r3=400.;#ohms\n",
+ "r4=1000.;#ohms\n",
+ "c2=2.;#micro farads\n",
+ "#calculations\n",
+ "x=((r4/r3)-(c1/c2));#\n",
+ "r2=r1*x;#ohms\n",
+ "f=((1/((2*math.pi)*math.sqrt(r1*r2*c1*10**-6*c2*10**-6))));#Hz\n",
+ "#results\n",
+ "print \"resistance is (ohm)=\",r2\n",
+ "print \"frequency is (Hz)=\",round(f)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 34 - pg 208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "percentage error is (%)= -4.5\n",
+ "voltmeter reading is (V)= 188.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 208\n",
+ "#Example 3.34:percentage error and voltmeter readings\n",
+ "#calculate the percentage error and voltmeter readings\n",
+ "#given data\n",
+ "v=180.;#volts\n",
+ "i=2.;#amperes\n",
+ "rv=2000;#ohms\n",
+ "ra=0.01;#ohms\n",
+ "#calculations\n",
+ "rm2=v/i;#ohms\n",
+ "iv=v/rv;#amperes\n",
+ "ir=i-iv;#amperes\n",
+ "r=v/ir;#ohms\n",
+ "per=((rm2-r)/r)*100;#\n",
+ "vr=i*(ra+r);#volts\n",
+ "#results\n",
+ "print \"percentage error is (%)=\",per\n",
+ "print \"voltmeter reading is (V)=\",round(vr,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 35 - pg 209"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "unknown resistance is (micro-ohm)= 49.97\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 209\n",
+ "#Example 3.35:unknown resistance\n",
+ "#calculate the unknown resistance\n",
+ "#given data\n",
+ "P=100.24;#ohms\n",
+ "Q=200.;#ohms\n",
+ "S=100.03;#ohms\n",
+ "q=200.;#ohms\n",
+ "r=700.;#micro ohms\n",
+ "p=100.31;#ohms\n",
+ "#calculations\n",
+ "x=(P/Q)*S*10**-6;#ohms\n",
+ "y=((q*r*10**-6)/(p+q+(r*10**-6)));#ohms\n",
+ "z=((P/Q)-(p/q));#ohms\n",
+ "R=x+(y*z);#micro ohms\n",
+ "#results\n",
+ "print \"unknown resistance is (micro-ohm)=\",round(R*10**6,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 36 - pg 209"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "deflection of the galvanometer is,(mm)= 27.7\n",
+ "sensivity of bridge is (mm/ohm)= 5.53\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 209\n",
+ "#Example 3.36:\n",
+ "#calculate the deflection of galvanometer and the sensivity\n",
+ "#given\n",
+ "P=1000.;#ohms\n",
+ "Q=100.;#ohms\n",
+ "S=200.;#ohms\n",
+ "R=2005.;#ohms\n",
+ "e=5.;#volts\n",
+ "G=100.;#ohms\n",
+ "si=10.;#mm/micro-ampere\n",
+ "#calculations\n",
+ "R1=((P/Q)*S);#ohms\n",
+ "dr=R-R1;#ohms\n",
+ "eo=e*((R/(R+S))-(P/(P+Q)));#volts\n",
+ "ro=(((R*S)/(R+S))+((P*Q)/(P+Q)));#ohms\n",
+ "ig=eo/(ro+G);#amperes\n",
+ "th=si*(ig*10**6);#mm\n",
+ "sb=th/dr;#mm/ohm\n",
+ "#results\n",
+ "print \"deflection of the galvanometer is,(mm)=\",round(th,1)\n",
+ "print \"sensivity of bridge is (mm/ohm)=\",round(sb,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 37 - pg 209"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (M-ohm)= 4.75\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 209\n",
+ "#Example 3.37: Insolution resistance of the cable\n",
+ "#calculate the resistance\n",
+ "#given data\n",
+ "import math\n",
+ "from math import log\n",
+ "v1=200.;#volts\n",
+ "v2=125.;#volts\n",
+ "t=30.;#seconds\n",
+ "v21=100;#volts\n",
+ "x=10;#mega ohms\n",
+ "#calculations\n",
+ "cr=t/(log(v1/v2));#\n",
+ "cr1=t/(log(v1/v21));#\n",
+ "y=cr1/cr;#\n",
+ "R=((x/y)-x);#mega ohms\n",
+ "#results\n",
+ "print \"resistance is (M-ohm)=\",round(R,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 38 - pg 210"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 41,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm)= 400.0\n",
+ "inductance is (H)= 1.12\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 210\n",
+ "#Example 3.38:resistance and inductance\n",
+ "#calculate the resistance and inductance\n",
+ "r2=400.;#ohms\n",
+ "r3=400.;#ohms\n",
+ "r4=400.;#ohms\n",
+ "r=500.;#ohms\n",
+ "c=2;#micro farads\n",
+ "#calculations\n",
+ "rX=((r2*r3)/r4);#ohms\n",
+ "l=(((c*10**-6*r2)/r4)*((r*(r3+r4))+(r3*r4)));#H\n",
+ "#results\n",
+ "print \"resistance is (ohm)=\",rX\n",
+ "print \"inductance is (H)=\",l\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 39 - pg 211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 43,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "inductance is (H)= 22.45\n",
+ "resistance is (ohm)= 1761.0\n",
+ "resistance is calculated wrong in the textbook\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 211\n",
+ "#Example 3.39:resistance and inductance\n",
+ "#calculate the resistance and inductance\n",
+ "#given data\n",
+ "import math\n",
+ "r2=1000.;#ohms\n",
+ "r3=15000.;#ohms\n",
+ "r4=500.;#ohms\n",
+ "c4=1.59;#micro farads\n",
+ "f=50;#Hz\n",
+ "#calculations\n",
+ "w=2*math.pi*f;#\n",
+ "l=((r2*r3*c4*10**-6)/((1+(w**2*(c4*10**-6)**2*r4**2))));#H\n",
+ "r=((r2*r3*r4*w**2*(c4*10**-6)**2)/((1+(w**2*(c4*10**-6)**2*r4**2))));#ohms\n",
+ "#results\n",
+ "print \"inductance is (H)=\",round(l,2)\n",
+ "print \"resistance is (ohm)=\",round(r,0)\n",
+ "print 'resistance is calculated wrong in the textbook'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 40 - pg 211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 44,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (M-ohm)= 0.01\n",
+ "capacitance is (micro-F) 100.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 211\n",
+ "#Example 3.40:resistance and capacitance\n",
+ "#calculate the resistance and capacitance\n",
+ "#given data\n",
+ "r2=1000.;#ohms\n",
+ "r4=100.;#ohms\n",
+ "c4=0.1;#micro farads\n",
+ "c3=1000.;#pF\n",
+ "#calculations\n",
+ "rs=((c4/(c3*10**-6))*r2);#M-ohm\n",
+ "cs=((r4/r2)*(c3*10**-6));#micro farads\n",
+ "#results\n",
+ "print \"resistance is (M-ohm)=\",rs*10**-7\n",
+ "print \"capacitance is (micro-F)\",cs*10**6\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 41 - pg 211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 45,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "capaciatnce is (micro-F)= 0.0115\n",
+ "resistance is (M-ohm)= 0.96\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 211\n",
+ "#Example 3.41:resistance and capacitance\n",
+ "#calculate the resistance and capacitance\n",
+ "#given data\n",
+ "r1=140.;#ohms\n",
+ "c1=0.0115*10**-6;#F\n",
+ "r2=1000.;#ohms\n",
+ "r4=1000.;#ohms\n",
+ "w=7500.;#\n",
+ "#calculations\n",
+ "x=((1/(w**2*r1*c1)));#\n",
+ "c3=c1;#\n",
+ "r3=x/c3;#\n",
+ "#results\n",
+ "print \"capaciatnce is (micro-F)=\",c3*10**6\n",
+ "print \"resistance is (M-ohm)=\",round(r3*10**-6,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 42 - pg 212"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 46,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Upper and lower limits of X are 302.5 ohm and 197.5 ohm\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 212\n",
+ "#Example 3.42:resistance\n",
+ "#calculate the Upper and lower limits of resistance\n",
+ "dp=0.08;#% error \n",
+ "ds=0.05;#% error\n",
+ "x=250;#ohms\n",
+ "#calculations\n",
+ "dq=dp;#\n",
+ "dx=dp+ds+dq;#% percentage error\n",
+ "dx1=dx*x;#\n",
+ "#results\n",
+ "print \"Upper and lower limits of X are \",x+dx1,\" ohm and \",x-dx1,\" ohm\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 43 - pg 213"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 47,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "unknown resistance is (milli-ohm)= 1.5034\n",
+ "The answer is a bit different from textbook due to rounding off error\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 213\n",
+ "#Example 3.43:resistance\n",
+ "#calculate the unknown resistance\n",
+ "#given data\n",
+ "Q=100.5;#ohms\n",
+ "M=300.;#ohms\n",
+ "S=0.0045;#ohms\n",
+ "r=0.1;#ohms\n",
+ "m=300.25;#micro ohms\n",
+ "q=100.6;#ohms\n",
+ "#calculations\n",
+ "x=(Q/M)*S;#ohms\n",
+ "y=((r*m)/(r+m+q));#ohms\n",
+ "z=((Q/M)-(q/m));#ohms\n",
+ "R=x+(y*z);#milli ohms\n",
+ "#results\n",
+ "print \"unknown resistance is (milli-ohm)=\",round(R*10**3,4)\n",
+ "print 'The answer is a bit different from textbook due to rounding off error'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 44 - pg 213"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "balance current is (micro-A)= 6.6\n",
+ "bridge sensivity is (cm-(ohm/ohm))= 5665.0\n",
+ "sensivity is calculated wrong in the book\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 213\n",
+ "#Example 3.44:balance current and bridge sensivity\n",
+ "#calculate the balance current and bridge sensivity\n",
+ "#given data\n",
+ "P=100.;#ohms\n",
+ "Q=1000.;#ohms\n",
+ "S=857.;#ohms\n",
+ "E=1.5;#volts\n",
+ "rg=50;#ohms\n",
+ "D=100;#M-ohm\n",
+ "#calculations\n",
+ "X=((P/Q)*S);#ohms\n",
+ "dx=1/X;#\n",
+ "a1=((rg+(X*(Q+S))/(X+S)));#ohms\n",
+ "dig=((E*S*X*dx)/((X+S)**2*a1));#\n",
+ "sb=((dig*D*10**6)/dx);#\n",
+ "#results\n",
+ "print \"balance current is (micro-A)=\",round(dig*10**6,1)\n",
+ "print \"bridge sensivity is (cm-(ohm/ohm))=\",round(sb*10**-1)\n",
+ "print 'sensivity is calculated wrong in the book'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 45 - pg 214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "balance current is (micro-A)= 6.6\n",
+ "bridge sensivity is (cm-(ohm/ohm))= 5665.0\n",
+ "sensivity is calculated wrong in the book\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 213\n",
+ "#Example 3.44:balance current and bridge sensivity\n",
+ "#calculate the balance current and bridge sensivity\n",
+ "#given data\n",
+ "P=100.;#ohms\n",
+ "Q=1000.;#ohms\n",
+ "S=857.;#ohms\n",
+ "E=1.5;#volts\n",
+ "rg=50;#ohms\n",
+ "D=100;#M-ohm\n",
+ "#calculations\n",
+ "X=((P/Q)*S);#ohms\n",
+ "dx=1/X;#\n",
+ "a1=((rg+(X*(Q+S))/(X+S)));#ohms\n",
+ "dig=((E*S*X*dx)/((X+S)**2*a1));#\n",
+ "sb=((dig*D*10**6)/dx);#\n",
+ "#results\n",
+ "print \"balance current is (micro-A)=\",round(dig*10**6,1)\n",
+ "print \"bridge sensivity is (cm-(ohm/ohm))=\",round(sb*10**-1)\n",
+ "print 'sensivity is calculated wrong in the book'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 46 - pg 214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 50,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (M-ohm)= 47.28\n",
+ "The answer is a bit different from textbook due to rounding off error\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 214\n",
+ "#Example 3.46:insulation resistance\n",
+ "#calculate the resistance\n",
+ "#given data\n",
+ "import math\n",
+ "from math import log\n",
+ "v=170.;#volts\n",
+ "e=250.;#volts\n",
+ "t=20.;#seconds\n",
+ "v1=110.;#volts\n",
+ "e=250.;#volts\n",
+ "t=20.;#seconds\n",
+ "r1=25.;#M-ohm\n",
+ "r2=70.;#M-ohm\n",
+ "#calculations\n",
+ "cr1=t/(log(e/v));#\n",
+ "cr2=t/(log(e/v1));#\n",
+ "x=cr1/cr2;#\n",
+ "y=((r1*r2)/(r1+r2));#\n",
+ "R=((x*r2*(r1*r2))-(r2*r1*r2))/((r2*(r1+r2))-((r1*r2*x)));#\n",
+ "#results\n",
+ "print \"resistance is (M-ohm)=\",round(R,2)\n",
+ "print 'The answer is a bit different from textbook due to rounding off error'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 47 - pg 215"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 52,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Rp is (M-ohm)= 0.1\n",
+ "Rn is (M-ohm)= 0.3\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 215\n",
+ "#Example 3.47: resistance\n",
+ "#calculate the resistance\n",
+ "#given data\n",
+ "em=500.;#volts\n",
+ "ep=50.;#volts\n",
+ "en=150.;#volts\n",
+ "rv=50.;#k-ohm\n",
+ "#calculations\n",
+ "rp=((em-ep-en)/en)*rv*10**3;#ohm\n",
+ "rn=((em-ep-en)/ep)*rv*10**3;#\n",
+ "#results\n",
+ "print \"Rp is (M-ohm)=\",rp*10**-6\n",
+ "print \"Rn is (M-ohm)=\",rn*10**-6"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 49 - pg 216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 53,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ep is (V)= 11.63\n",
+ "En is (V)= 23.26\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 216\n",
+ "#Example 3.49: readings\n",
+ "#calculate the readings\n",
+ "#given data\n",
+ "rp=1.;#M-ohm\n",
+ "rn=2.;#M-ohm\n",
+ "r=50.;#killo ohms\n",
+ "v=500;#volts\n",
+ "#calculations\n",
+ "x=((rp*10**6)/(r*10**3));#\n",
+ "ep=(v)/((rn*x+(rn+rp)));#volts\n",
+ "en=2*ep;#\n",
+ "#results\n",
+ "print \"Ep is (V)=\",round(ep,2)\n",
+ "print \"En is (V)=\",round(en,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 50 - pg 216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 54,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm)= 240.0\n",
+ "inductance is (H)= 0.12\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 216\n",
+ "#Example 3.50:Resistance and Inductance\n",
+ "#calculate the resistance and inductance\n",
+ "#given data\n",
+ "R2=600.;#OHMS\n",
+ "R4=400.;#OHMS\n",
+ "R3=1000.;#OHMS\n",
+ "C3=0.5;#MICRO-f\n",
+ "#calculations\n",
+ "r=((R2*R4)/R3);#ohms\n",
+ "l=R2*R4*C3*10**-6;#H\n",
+ "#results\n",
+ "print \"resistance is (ohm)=\",r\n",
+ "print \"inductance is (H)=\",l\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 51 - pg 217"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 55,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The maximum (+ve) percentage error in X = 0.253\n",
+ "The maximum (-ve) percentage error in X = -0.2499\n",
+ "Therefore limits of percentage error in X is + 0.253 to -0.2499 \n",
+ "The answers are a bit different from textbook due to rounding off error\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 217\n",
+ "#Example 3.51:Resistance \n",
+ "#calculate the percentage error\n",
+ "#given data\n",
+ "p=100.;#ohms\n",
+ "q=1000.;#ohms\n",
+ "s=518.8;#ohms\n",
+ "ep=0.1;#\n",
+ "eq=0.1;#\n",
+ "es1=0.05;#\n",
+ "es2=0.05;#\n",
+ "es3=0.1;#\n",
+ "es4=0.5;#\n",
+ "tes=0.267;#\n",
+ "ds=0.008;#ohms\n",
+ "#calculations\n",
+ "pes=(tes/s)*100;#\n",
+ "pds=(ds/s)*100;#\n",
+ "ttos1=pes+pds;#\n",
+ "ttos2=-pes+pds;#\n",
+ "m1=ep+eq+ttos1;#\n",
+ "m2=-ep-eq+ttos2;#\n",
+ "#results\n",
+ "print \"The maximum (+ve) percentage error in X =\",round(m1,4)\n",
+ "print \"The maximum (-ve) percentage error in X =\",round(m2,4)\n",
+ "print \"Therefore limits of percentage error in X is +\",round(m1,4),\" to \",round(m2,4),\" \"\n",
+ "print 'The answers are a bit different from textbook due to rounding off error'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 52 - pg 218"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 56,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance (ohms) = 3.65\n",
+ "capacitance (micro-F) = 0.7125\n",
+ "loss angle is 0.0 degree and 4.0 minutes \n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 218\n",
+ "#Example 3.52:loss angle\n",
+ "#calculate the loss angle\n",
+ "#given data\n",
+ "import math\n",
+ "r2=2000.;#ohms\n",
+ "r3=2850.;#ohms\n",
+ "r4=0.4;#ohms\n",
+ "c4=0.5;#micro-F\n",
+ "R4=4.8;#ohms\n",
+ "f=450;#Hz\n",
+ "#calculations\n",
+ "r1=((r2*(R4+r4))/r3);#ohms\n",
+ "c1=((r3*c4)/r2);#micro-F\n",
+ "w=2*math.pi*f;#\n",
+ "d=f*c1*10**-6*r1;#\n",
+ "ad=math.atan(d)*57.3;#\n",
+ "x=round(ad);#\n",
+ "#results\n",
+ "print 'resistance (ohms) = ',round(r1,2)\n",
+ "print 'capacitance (micro-F) = ',c1\n",
+ "print \"loss angle is \",x,\" degree and \",round(ad*60),\" minutes \"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 53 - pg 218"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 57,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "R1 is (M-ohm)= 1.16\n",
+ "R2 is (M-ohm)= 0.58\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 218\n",
+ "#Example 3.53: resistance\n",
+ "#calculate the resistances\n",
+ "#given data\n",
+ "em=500.;#volts\n",
+ "i1=0.8;#mA\n",
+ "r=30;#killo ohms\n",
+ "i2=0.4;#mA\n",
+ "rv=50;#k-ohm\n",
+ "#calculations\n",
+ "ep=i1*r;#volts\n",
+ "en=i2*r;#volts\n",
+ "rp=((em-ep-en)/en)*r*10**3;#ohm\n",
+ "rn=((em-ep-en)/ep)*r*10**3;#\n",
+ "#results\n",
+ "print \"R1 is (M-ohm)=\",rp*10**-6\n",
+ "print \"R2 is (M-ohm)=\",rn*10**-6\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 54 - pg 219"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 58,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm)= 7066.0\n",
+ "capacitance is (micro-F)= 0.717\n",
+ "resistance is wrong in the textbook due to rounding off error\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 219\n",
+ "#Example 3.54: resistance and capacitance\n",
+ "#calculate the resistance and capacitance\n",
+ "#given data\n",
+ "import math\n",
+ "r2=100.;#ohms\n",
+ "r4=1000.;#ohms\n",
+ "r1=50.;#ohms\n",
+ "f=50.;#Hz\n",
+ "l=0.1;#H\n",
+ "#calculations\n",
+ "r3=((r2*r4)/r1)+((r1*r2*r4)/((2*math.pi*f)**2*l**2));#ohms\n",
+ "c3=r1/((2*math.pi*f)**2*l*r3);#F\n",
+ "#results\n",
+ "print \"resistance is (ohm)=\",round(r3)\n",
+ "print \"capacitance is (micro-F)=\",round(c3*10**6,3)\n",
+ "print 'resistance is wrong in the textbook due to rounding off error'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 56 - pg 220"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 59,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm)= 3184.0\n",
+ "inductance is (H)= 21.6\n",
+ "resistance is wrong in the textbook due to rounding off error\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 220\n",
+ "#Example 3.54: resistance and inductance\n",
+ "#calculate the resistance and inductance\n",
+ "#given data\n",
+ "import math\n",
+ "r2=16800.;#ohms\n",
+ "r3=950.;#ohms\n",
+ "r4=1000.;#ohms\n",
+ "f=50.;#Hz\n",
+ "c3=1.57;#micro-F\n",
+ "#calculations\n",
+ "x=((r2*r3*r4*(2*math.pi*f)**2*(c3*10**-6)**2));#\n",
+ "y=(1+(((2*math.pi*f)**2)*(c3*10**-6)**2*r3**2));#\n",
+ "r1=x/y;#ohms\n",
+ "l1=((r2*r4*c3*10**-6)/y);#\n",
+ "print \"resistance is (ohm)=\",round(r1)\n",
+ "print \"inductance is (H)=\",round(l1,1)\n",
+ "print 'resistance is wrong in the textbook due to rounding off error'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 57 - pg 221"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 60,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (k-ohm)= 453.0\n",
+ "capacitance is (p-F)= 281.0\n",
+ "power factor is = 0.04\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 221\n",
+ "#Example 3.57: resistance, capacitance AND POWER FACTOR\n",
+ "#calculate the resistance, capacitance AND POWER FACTOR\n",
+ "#given data\n",
+ "import math\n",
+ "f=50.;#Hz\n",
+ "r2=120.;#ohms\n",
+ "c3=0.4;#micro-F\n",
+ "c4=106.;#pF\n",
+ "r3=318.;#ohms\n",
+ "#calculations\n",
+ "r1=((r2*c3*10**-6)/(c4*10**-12));#ohms\n",
+ "c1=((c4*10**-12*r3)/r2);#pF\n",
+ "pf=((r1)/(math.sqrt(r1**2+(1/(2*math.pi*f*c1)**2))));#\n",
+ "#results\n",
+ "print \"resistance is (k-ohm)=\",round(r1*10**-3)\n",
+ "print \"capacitance is (p-F)=\",round(c1*10**12)\n",
+ "print \"power factor is =\",round(pf,2)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 58 - pg 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 62,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "X is = 3791.175\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 222\n",
+ "#Example 3.58: resistance \n",
+ "#calculate the resistance\n",
+ "#given data\n",
+ "l1=26.;#cm\n",
+ "l2=24.;#cm\n",
+ "l1d=25.8;#cm\n",
+ "l2d=23.5;#cm\n",
+ "s=545.;#ohm\n",
+ "sg=65.;#ohm\n",
+ "#calculations\n",
+ "sd=((s*sg)/(s+sg));#ohm\n",
+ "X=((sd*(l1-l2))-s*(l1d-l2d))/(l1-l2-l1d+l2d);#\n",
+ "#results\n",
+ "print \"X is =\",round(X,3) \n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 59 - pg 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 63,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "capacitance is (micro-F)= 0.2356\n",
+ "resistance is (ohm)= 471.7\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 222\n",
+ "#Example 3.59: capacitance and resistance \n",
+ "#calculate the capacitance and resistance\n",
+ "#given data\n",
+ "e1=5000.;#volts\n",
+ "r1=500.;#ohm\n",
+ "l1=0.18;#H\n",
+ "r2=1000.;#ohm\n",
+ "#calculations\n",
+ "r4=r2;#ohms\n",
+ "x=(r1/(e1**2*l1));#\n",
+ "y=((r2*r2)/(1+((e1**2)*x**2)));#\n",
+ "c3=((l1/y));#F\n",
+ "r3=(x/c3);#\n",
+ "#results\n",
+ "print \"capacitance is (micro-F)=\",round(c3*10**6,4)\n",
+ "print \"resistance is (ohm)=\",round(r3,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 60 - pg 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 64,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "capacitance is (micro-F)= 0.2356\n",
+ "resistance is (ohm)= 471.7\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 222\n",
+ "#Example 3.59: capacitance and resistance \n",
+ "#calculate the capacitance and resistance\n",
+ "#given data\n",
+ "e1=5000.;#volts\n",
+ "r1=500.;#ohm\n",
+ "l1=0.18;#H\n",
+ "r2=1000.;#ohm\n",
+ "#calculations\n",
+ "r4=r2;#ohms\n",
+ "x=(r1/(e1**2*l1));#\n",
+ "y=((r2*r2)/(1+((e1**2)*x**2)));#\n",
+ "c3=((l1/y));#F\n",
+ "r3=(x/c3);#\n",
+ "#results\n",
+ "print \"capacitance is (micro-F)=\",round(c3*10**6,4)\n",
+ "print \"resistance is (ohm)=\",round(r3,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 61 - pg 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 65,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm)= 60.0\n",
+ "inductance is (mH)= 8.1\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 223\n",
+ "#Example 3.61;resistance and inductance\n",
+ "#calculate the resistance and inductance\n",
+ "#given data\n",
+ "p=0;#\n",
+ "r2=10;#ohms\n",
+ "r4=900;#ohms\n",
+ "c3=0.9;#micro-F\n",
+ "c4=0.15;#micro-F\n",
+ "#calculations\n",
+ "r=((r2*c3*10**-6)/(c4*10**-6));#ohms\n",
+ "l=r2*r4*c3*10**-3;#mH\n",
+ "#results\n",
+ "print \"resistance is (ohm)=\",r\n",
+ "print \"inductance is (mH)=\",l\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 62 - pg 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 66,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (M-ohm)= 224.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 223\n",
+ "#Example 3.62;resistance \n",
+ "#calculate the resistance\n",
+ "#given data\n",
+ "d2=350.;#\n",
+ "f2=1000.;#Hz\n",
+ "s=1;#M-ohm\n",
+ "d1=250.;#\n",
+ "f1=2.5;#Hz\n",
+ "l=400.;#/m\n",
+ "l1=1000.;#m\n",
+ "#calculations\n",
+ "X=((d2*f2*s)/(d1*f1));#M-ohm\n",
+ "x=(X*l)/l1;#M-ohm\n",
+ "#results\n",
+ "print \"resistance is (M-ohm)=\",x\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 63 - pg 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 67,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (M-ohm)= 224.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 223\n",
+ "#Example 3.62;resistance \n",
+ "#calculate the resistance\n",
+ "#given data\n",
+ "d2=350.;#\n",
+ "f2=1000.;#Hz\n",
+ "s=1;#M-ohm\n",
+ "d1=250.;#\n",
+ "f1=2.5;#Hz\n",
+ "l=400.;#/m\n",
+ "l1=1000.;#m\n",
+ "#calculations\n",
+ "X=((d2*f2*s)/(d1*f1));#M-ohm\n",
+ "x=(X*l)/l1;#M-ohm\n",
+ "#results\n",
+ "print \"resistance is (M-ohm)=\",x\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 64 - pg 224"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 68,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "permittivity is = 8.91e-11\n",
+ "power factor is = 0.044\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 224\n",
+ "#Example 3.64:permittivity and power factor\n",
+ "#calculate the permittivity and power factor\n",
+ "#given data\n",
+ "import math\n",
+ "r3=350.;#ohms\n",
+ "f=50.;#Hz\n",
+ "r2=250.;#ohms\n",
+ "c3=0.4;#micro-F\n",
+ "c4=100.;#pF\n",
+ "l=5.;#mm\n",
+ "l1=10.;#cm\n",
+ "#calculations\n",
+ "r1=((r2*c3*10**-6)/(c4*10**-12));#ohms\n",
+ "c1=((c4*10**-12)*(r3/r2));#F\n",
+ "e=((c1*l*10**-3)/((math.pi/4)*(l1/100)**2));#\n",
+ "pf=r1*2*math.pi*f*c1;#\n",
+ "#results\n",
+ "print \"permittivity is =\",round(e,13)\n",
+ "print \"power factor is =\",round(pf,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 65 - pg 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 69,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm)= 40.0\n",
+ "capacitance is (micro-F)= 0.833\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 225\n",
+ "#Example 3.65:resistance and capacitance\n",
+ "#calculate the resistance and capacitance\n",
+ "#given data\n",
+ "import math,cmath\n",
+ "rab=2000.;#ohms\n",
+ "f=1;#kHz\n",
+ "cab=0.047;#micro-farad\n",
+ "rbc=1000;#ohms\n",
+ "cbc=0.47;#micro-F\n",
+ "#calculations\n",
+ "cda=0.5;#micro-F\n",
+ "zab=(1/((1/rab)+(1j*2*math.pi*f*10**3*cab*10**-6)));#\n",
+ "zbc=rbc-(1j/(2*math.pi*f*10**3*cbc*10**-6));#\n",
+ "zda=(-1j/(2*math.pi*f*10**3*cda*10**-6));#\n",
+ "zx=(zda*zbc)/zab;#\n",
+ "rx=zx.real;#ohms\n",
+ "cx=-1/(2*math.pi*f*10**3*zx.imag);#\n",
+ "#results\n",
+ "print \"resistance is (ohm)=\",round(rx)\n",
+ "print \"capacitance is (micro-F)=\",round(cx*10**6,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 66 - pg 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 70,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "capacitance is (micro-F)= 0.1\n",
+ "voltage across the detector is (mV)= 4.4\n",
+ "voltage across the detector is (mV)= 7.6\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 225\n",
+ "#Example 3.66:capacitance\n",
+ "#calculate the capacitance and voltage\n",
+ "#given data\n",
+ "import math,cmath\n",
+ "from math import sqrt\n",
+ "zbc=1000;#ohms\n",
+ "f=1;#kHz\n",
+ "cda=0.2*10**-6 ;#micro-F\n",
+ "zab=500.;#ohms\n",
+ "rba=1002;#ohms\n",
+ "v1=10;#volts\n",
+ "#calculations\n",
+ "zda=(-1j/(2*math.pi*f*10**3*cda));#\n",
+ "zcd=(zbc*zda)/zab;#\n",
+ "cx=-1/(2*math.pi*f*10**3*zcd.imag);#\n",
+ "iab=v1/(rba+zab);#amperes\n",
+ "ibc=iab;#amperes\n",
+ "ida=v1*1j*2*math.pi*f*10**3*((cda*cx)/(cda+cx));#amperes\n",
+ "icd=ida;#amperes\n",
+ "vab=(v1*zab)/(rba+zab);#volts\n",
+ "vab1=icd/(1j*2*math.pi*10**3*cda);#volts\n",
+ "vbd=vab1-vab;#volts\n",
+ "iba=v1/(zab-(1j/(2*math.pi*10**3*cda)));#\n",
+ "vba=zab*iba;#\n",
+ "v2=sqrt(vba.real**2+vba.imag**2);#volts\n",
+ "ibc=v1/(rba-(1j/(2*math.pi*10**3*cx)));#\n",
+ "vbc=rba*ibc;#\n",
+ "v3=sqrt(vbc.real**2+vbc.imag**2);#volts\n",
+ "vac=v3-v2;#\n",
+ "#results\n",
+ "print \"capacitance is (micro-F)=\",cx*10**6\n",
+ "print \"voltage across the detector is (mV)=\",round(vbd.real*10**3,1)\n",
+ "print \"voltage across the detector is (mV)=\",round(vac*10**3,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 67 - pg 226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 71,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "frequency is (Hz)= 398.0\n",
+ "resistance is (ohm)= 1171.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 226\n",
+ "#Example 3.67:frequency and resistance\n",
+ "#calculate the frequency and resistance\n",
+ "#given data\n",
+ "import math\n",
+ "rab=800.;#ohm\n",
+ "cab=0.4;#micro-F\n",
+ "rbc=500.;#ohms\n",
+ "cbc=1;#micro-F\n",
+ "rcd=1200.;#ohm\n",
+ "#calculations\n",
+ "x=cab*10**-6*rab;#\n",
+ "y=cbc*10**-6*rbc;#\n",
+ "w=math.sqrt(1/(x*y));#rad/s\n",
+ "f=w/(2*math.pi);#\n",
+ "zab=(rab/((1+(1j*w*cab*10**-6*rab))));#ohms\n",
+ "zbc=rbc+(1/((1+(1j*w*cbc*10**-6*rbc))));#ohms\n",
+ "zda=(zab*rcd)/zbc;#ohms\n",
+ "#results\n",
+ "print \"frequency is (Hz)=\",round(f)\n",
+ "print \"resistance is (ohm)=\",round(zda.real)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 68 - pg 227"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 72,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "in case 1\n",
+ "resistance is (ohm)= 1250.0\n",
+ "inductance is (H)= 0.1875\n",
+ "in case 2\n",
+ "resistance is (ohm)= 1589.64\n",
+ "inductance is (H)= 0.1854\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 227\n",
+ "#Example 3.68: resistance and inductance\n",
+ "#calculate the resistance and inductance\n",
+ "#given data\n",
+ "import math,cmath\n",
+ "cab=0.01;#micro-F\n",
+ "rbc=2.5;#k-ohms\n",
+ "cbc=1;#micro-F\n",
+ "rda=7.5*10**3;#ohm\n",
+ "cda=0.02;#micro-F\n",
+ "w=50*10**3;#Hz\n",
+ "#calculations and results\n",
+ "zab=(-1/(((1j*w*cab*10**-6*1))));#ohms\n",
+ "zbc=rbc*10**3;#ohms\n",
+ "zda=rda+(1/(((1j*w*cda*10**-6))));#ohms\n",
+ "zcd=(zbc*zda)/zab;#\n",
+ "r=-(zcd.real);#ohms\n",
+ "l=-(zcd.imag)/w;#H\n",
+ "print 'in case 1'\n",
+ "print \"resistance is (ohm)=\",round(r)\n",
+ "print \"inductance is (H)=\",l\n",
+ "zda2=zda/(1+(zda*1j*w*100*10**-12));#\n",
+ "zcd=(zbc*zda2)/zab;#\n",
+ "r=-zcd.real;#ohms\n",
+ "l=-(zcd.imag)/w;#H\n",
+ "print 'in case 2'\n",
+ "print \"resistance is (ohm)=\",round(r,2)\n",
+ "print \"inductance is (H)=\",round(l,4)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 69 - pg 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 74,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm)= 27.869\n",
+ "capcitance is (micro-F)= 0.0195\n",
+ "error in R is (%)= 1.815\n",
+ "error in C is (%)= -0.00125\n",
+ "answer is wrong in the textbook for errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 228\n",
+ "#Example 3.69:resistance and capacitance\n",
+ "#calculate the resistance and capacitance\n",
+ "#given data\n",
+ "import math,cmath\n",
+ "zab=521.;#ohms\n",
+ "zbc=1200.;#ohms\n",
+ "rda=12.1;#ohms\n",
+ "f=10.;#kHz\n",
+ "cda=0.045;#micro-F\n",
+ "#calculations and results\n",
+ "zda=rda-(1j/(2*math.pi*f*10**3*cda*10**-6));#\n",
+ "zcd=(zbc*zda)/zab;#\n",
+ "c=1/(2*math.pi*f*10**3*zcd.imag);#\n",
+ "print \"resistance is (ohm)=\",round(zcd.real,3)\n",
+ "print \"capcitance is (micro-F)=\",round(-c*10**6,4)\n",
+ "rab=521;#ohms\n",
+ "lab=2;#micro-H\n",
+ "cab=550;#pF\n",
+ "rbc=1200;#ohms\n",
+ "lbc=5;#micro-H\n",
+ "cbc=250;#pF\n",
+ "rda1=1.5;#m-ohms\n",
+ "cda=0.045;#micro-F\n",
+ "zab1=521;#ohms\n",
+ "zbc1=1200;#ohms\n",
+ "rda1=12.1;#ohms\n",
+ "f1=10;#kHz\n",
+ "cda1=0.045;#micro-F\n",
+ "zab=1/((1/(rab+(1j*2*math.pi*f*10**4*lab*10**-6)))+(1j*2*math.pi*f*10**3*cab*10**-12));#\n",
+ "zbc=1/((1/(rbc+(1j*2*math.pi*f*10**4*lbc*10**-6)))+(1j*2*math.pi*f*10**3*cbc*10**-12));#\n",
+ "zda=rda+((1/((1/rda1*10**-6)+(1j*2*math.pi*f*10**3*cda*10**-6))));#;#\n",
+ "zcd=(zbc*zda)/zab;#\n",
+ "zda1=rda1-(1j/(2*math.pi*f1*10**3*cda1*10**-6));#\n",
+ "zcd1=(zbc1*zda1)/zab1;#\n",
+ "c1=1/(2*math.pi*f*10**3*(zcd1.imag));#\n",
+ "c=1/(2*math.pi*f*10**3*(zcd.imag));#\n",
+ "per=(((zcd1.real)-(zcd.real))/(zcd.real))*100;#\n",
+ "pec=(((zcd1.imag)-(zcd.imag))/(zcd.imag))*100;#\n",
+ "print \"error in R is (%)=\",round(per,3)\n",
+ "print \"error in C is (%)=\",round(pec,5)\n",
+ "print 'answer is wrong in the textbook for errors'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 70 - pg 230"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 75,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm)= 1000.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 230\n",
+ "#Example 3.70:resistance \n",
+ "#calculate the resistance\n",
+ "#given data\n",
+ "import math,cmath\n",
+ "w=5000;#rad/s\n",
+ "cab=0.2;#micro-F\n",
+ "zbc=500.;#ohm\n",
+ "l=0.1;#H\n",
+ "cda=0.4;#micro-F\n",
+ "rcd=50.;#ohm\n",
+ "#calculations\n",
+ "zab=(-1j/(w*cab*10**-6));#ohms\n",
+ "zcd=rcd+1j*w*l;#ohm\n",
+ "izda=-1j/(w*cda*10**-6);#\n",
+ "zda=(zab*zcd)/zbc;#\n",
+ "rs=(zda.real);#ohms\n",
+ "#results\n",
+ "print \"resistance is (ohm)=\",rs\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 71 - pg 230"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 76,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "capacitance is (micro-F)= 0.1\n",
+ "voltage across the detector is (mV)= 4.4\n",
+ "voltage across the detector is (mV)= 7.6\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 225\n",
+ "#Example 3.66:capacitance\n",
+ "#calculate the capacitance and voltage\n",
+ "#given data\n",
+ "import math,cmath\n",
+ "from math import sqrt\n",
+ "zbc=1000;#ohms\n",
+ "f=1;#kHz\n",
+ "cda=0.2*10**-6 ;#micro-F\n",
+ "zab=500.;#ohms\n",
+ "rba=1002;#ohms\n",
+ "v1=10;#volts\n",
+ "#calculations\n",
+ "zda=(-1j/(2*math.pi*f*10**3*cda));#\n",
+ "zcd=(zbc*zda)/zab;#\n",
+ "cx=-1/(2*math.pi*f*10**3*zcd.imag);#\n",
+ "iab=v1/(rba+zab);#amperes\n",
+ "ibc=iab;#amperes\n",
+ "ida=v1*1j*2*math.pi*f*10**3*((cda*cx)/(cda+cx));#amperes\n",
+ "icd=ida;#amperes\n",
+ "vab=(v1*zab)/(rba+zab);#volts\n",
+ "vab1=icd/(1j*2*math.pi*10**3*cda);#volts\n",
+ "vbd=vab1-vab;#volts\n",
+ "iba=v1/(zab-(1j/(2*math.pi*10**3*cda)));#\n",
+ "vba=zab*iba;#\n",
+ "v2=sqrt(vba.real**2+vba.imag**2);#volts\n",
+ "ibc=v1/(rba-(1j/(2*math.pi*10**3*cx)));#\n",
+ "vbc=rba*ibc;#\n",
+ "v3=sqrt(vbc.real**2+vbc.imag**2);#volts\n",
+ "vac=v3-v2;#\n",
+ "#results\n",
+ "print \"capacitance is (micro-F)=\",cx*10**6\n",
+ "print \"voltage across the detector is (mV)=\",round(vbd.real*10**3,1)\n",
+ "print \"voltage across the detector is (mV)=\",round(vac*10**3,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 72 - pg 231"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 77,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "frequency is (Hz)= 398.0\n",
+ "resistance is (ohm)= 1171.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 226\n",
+ "#Example 3.67:frequency and resistance\n",
+ "#calculate the frequency and resistance\n",
+ "#given data\n",
+ "import math\n",
+ "rab=800.;#ohm\n",
+ "cab=0.4;#micro-F\n",
+ "rbc=500.;#ohms\n",
+ "cbc=1;#micro-F\n",
+ "rcd=1200.;#ohm\n",
+ "#calculations\n",
+ "x=cab*10**-6*rab;#\n",
+ "y=cbc*10**-6*rbc;#\n",
+ "w=math.sqrt(1/(x*y));#rad/s\n",
+ "f=w/(2*math.pi);#\n",
+ "zab=(rab/((1+(1j*w*cab*10**-6*rab))));#ohms\n",
+ "zbc=rbc+(1/((1+(1j*w*cbc*10**-6*rbc))));#ohms\n",
+ "zda=(zab*rcd)/zbc;#ohms\n",
+ "#results\n",
+ "print \"frequency is (Hz)=\",round(f)\n",
+ "print \"resistance is (ohm)=\",round(zda.real)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 73 - pg 231"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 78,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "M is (H)= 2.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 231\n",
+ "#Example 3.73: inductance\n",
+ "#calculate the inductance\n",
+ "#given data\n",
+ "l1=4.;#H\n",
+ "r1=1.;#ohm\n",
+ "r2=1.;#ohm\n",
+ "r3=2.;#ohm\n",
+ "l4=2.;#H\n",
+ "r4=2.;#ohm\n",
+ "#calculations\n",
+ "M=((r3*l1)-(r2*l4))/(r2+r3);#H\n",
+ "#results\n",
+ "print \"M is (H)=\",M\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 74 - pg 232"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 79,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm)= 300.0\n",
+ "inductance is (mH)= 0.06\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 232\n",
+ "#Example 3.74:resistance and inductance\n",
+ "#calculate the resistance and inductance\n",
+ "#given data\n",
+ "r2=500.;#ohms\n",
+ "r3=300.;#ohms\n",
+ "r4=500.;#ohms\n",
+ "r=150.;#ohms\n",
+ "c=2.5;#nano farads\n",
+ "#calculations\n",
+ "rX=((r2*r3)/r4);#ohms\n",
+ "l=(((c*10**-9*r3)/r4)*((r*(r2+r4))+(r2*r4)));#H\n",
+ "#results\n",
+ "print \"resistance is (ohm)=\",rX\n",
+ "print \"inductance is (mH)=\",l*100.\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 75 - pg 233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 80,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "current is (A)= 0.326\n",
+ "iron loss is (W)= 0.0935\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 233\n",
+ "#Example 3.75:iron loss\n",
+ "#calculate the current and iron loss\n",
+ "#given data\n",
+ "import math\n",
+ "r2=18.;#ohm\n",
+ "r4=550.;#ohm\n",
+ "r3=1250.;#ohm\n",
+ "c3=0.5;#micro-F\n",
+ "r4=550.;#ohm\n",
+ "r31=1125.;#ohm\n",
+ "c31=3.85;#micro-F\n",
+ "v=50.;#volts\n",
+ "w=4000.;#rad/s\n",
+ "#calculations\n",
+ "r1=(r2*r4)/r3;#ohm\n",
+ "l1=r2*r4*c3*10**-3;#mH\n",
+ "r11=(r2*r4)/r31;#ohm\n",
+ "l11=r2*r4*c31*10**-3;#mH\n",
+ "i1=v/(math.sqrt((r1+r11)**2+(w**2*(l11*10**-3)**2)));#\n",
+ "tl=i1**2*r11;#W\n",
+ "cl=i1**2*r1;#W\n",
+ "il=tl-cl;#\n",
+ "#results\n",
+ "print \"current is (A)=\",round(i1,3)\n",
+ "print \"iron loss is (W)=\",round(il,4)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 77 - pg 235"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 81,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm)= 77.87\n",
+ "capacitance is (micro-F)= 10.152\n",
+ "Rp is (ohm)= 81.03\n",
+ "Cp is (micro-F)= 0.396\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 235\n",
+ "#Example 3.77:parameters\n",
+ "#calculate the required parameters\n",
+ "#given data\n",
+ "import math,cmath\n",
+ "rab=1000.;#ohm\n",
+ "f=1.;#kHz\n",
+ "cab=0.5;#micro-F\n",
+ "rbc=1000.;#ohm\n",
+ "rcd=200.;#ohm\n",
+ "lcd=30.;#mH\n",
+ "#calculations\n",
+ "zab=1/((1/rab)+(1j*2*math.pi*f*10**3*cab*10**-6));#\n",
+ "zbc=rbc-(1j/(2*math.pi*f*10**3*cab*10**-6));#\n",
+ "zcd=rcd+(1j*2*math.pi*f*10**3*lcd*10**-3);#\n",
+ "zda=(zab*zcd)/zbc;#ohm\n",
+ "R=(zda.real);#\n",
+ "cda=1/(2*math.pi*f*10**3*(zda.imag));#\n",
+ "x=math.sqrt((zda.real)**2+(zda.imag)**2);#\n",
+ "x=81.03\n",
+ "rp=x;#ohms\n",
+ "cp=((.2015)*10**3)/(2*math.pi*rp);#\n",
+ "#results\n",
+ "print \"resistance is (ohm)=\",round(R,3)\n",
+ "print \"capacitance is (micro-F)=\",round(-cda*10**6,3)\n",
+ "print \"Rp is (ohm)=\",round(rp,2)\n",
+ "print \"Cp is (micro-F)=\",round(cp,3)\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter4.ipynb b/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter4.ipynb
new file mode 100755
index 00000000..6b8c7b81
--- /dev/null
+++ b/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter4.ipynb
@@ -0,0 +1,751 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 4 - Potentiometers"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1 - pg 256"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Unknown resistor (ohm) = 0.08275\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 256\n",
+ "#Example 4.1: Unknown resistor\n",
+ "#calculate the Unknown resistor\n",
+ "#given data :\n",
+ "Vd=0.83942;# volt-drop in V\n",
+ "emf=23*10**-6;# in V\n",
+ "Vds=1.01575;# volt-drop in V\n",
+ "Rs=0.10014;# in ohm\n",
+ "#calculations\n",
+ "Vdt=Vd-emf;# in V\n",
+ "I=Vds/Rs;\n",
+ "R=Vdt/I;\n",
+ "#results\n",
+ "print \"Unknown resistor (ohm) = \",round(R,5)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2 - pg 257"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "(a). emf of the cell,(V) = 1.42562\n",
+ "(b). % error (high),(%) = 1.98\n",
+ "(c). % error (high),(%) = 1.59\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 257\n",
+ "#Example 4.2: emf and % error \n",
+ "#calculate the emf and % error \n",
+ "#given data :\n",
+ "l=50;# in cm\n",
+ "l1=70;# in cm\n",
+ "l2=65;# in cm\n",
+ "l3=43.5;# in cm\n",
+ "I=0.45;# in A\n",
+ "V=1.0183;# in V\n",
+ "V1=1.35;# in V\n",
+ "R=2;# in ohm\n",
+ "#calculations\n",
+ "Vpl=V/l;# in V/cm\n",
+ "emf=Vpl*l1;\n",
+ "Vr=Vpl*l2;\n",
+ "P_error1=((V1-Vr)/Vr)*100;\n",
+ "Ir=(Vpl*l3)/R;# in A\n",
+ "P_error2=((I-Ir)/Ir)*100;\n",
+ "#results\n",
+ "print \"(a). emf of the cell,(V) = \",emf\n",
+ "print \"(b). % error (high),(%) = \",round(P_error1,2)\n",
+ "print \"(c). % error (high),(%) = \",round(P_error2,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3 - pg 258"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "part a \n",
+ "current is (A)= 0.02\n",
+ "resistance is (ohm)= 100.0\n",
+ "part b\n",
+ "current is (mA)= 7.078\n",
+ "resistance is (k-ohm)= 2035.32\n",
+ "resistance is calculated wrong in the textbook\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 258\n",
+ "#Example 4.3.a: current and resistance\n",
+ "#calculate the current and resistance\n",
+ "#given\n",
+ "import numpy\n",
+ "from numpy import linalg\n",
+ "e1=1.0191;#V\n",
+ "r1=100.;#ohms\n",
+ "l=2;#m\n",
+ "e2=4;#V\n",
+ "#calculations and results\n",
+ "I=l/r1;#A\n",
+ "rh=(e2/I)-r1;#\n",
+ "print 'part a '\n",
+ "print \"current is (A)=\",I\n",
+ "print \"resistance is (ohm)=\",rh\n",
+ "e1=4;#V\n",
+ "e2=1.0191;#V\n",
+ "R1=100;#OHM\n",
+ "R2=49.045;#OHMS\n",
+ "r3=R1-R2;#ohms\n",
+ "rg=50;#ohms\n",
+ "r4=200;#ohms\n",
+ "A=numpy.matrix([[r4, -r3],[-r3, (r4+rg+r3)]]);#\n",
+ "B=numpy.matrix([[e1],[e2]]);#\n",
+ "X=numpy.dot(numpy.linalg.inv(A),B)\n",
+ "I2=X[1,0]*10**3;#\n",
+ "I1=((e1+(r3*10**-5))/r4);#mA\n",
+ "rp=((e2+(r3*I1)-(r4+rg+r3)*10**-5)/10**-5);#\n",
+ "#results\n",
+ "print 'part b'\n",
+ "print \"current is (mA)=\",round(I2,3)\n",
+ "print \"resistance is (k-ohm)=\",round(rp*10**-2,2)\n",
+ "print 'resistance is calculated wrong in the textbook'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4 - pg 259"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "internal resistance,Ri(ohm) = 176.689\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 259\n",
+ "#Example 4.4: Resistance\n",
+ "#calculate the internal resistance\n",
+ "#given data :\n",
+ "emf=1.01892;# in V\n",
+ "R=1;# in M-ohm\n",
+ "V=1.01874;# in V\n",
+ "#calculations\n",
+ "Ic=V/R;\n",
+ "Vd=emf-V;\n",
+ "Ri=Vd/(Ic*10**-6);\n",
+ "#results\n",
+ "print \"internal resistance,Ri(ohm) = \",round(Ri,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5 - pg 259"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Internal resistance,Ri(ohm) = 3.636\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 259\n",
+ "#Example 4.5: Resistance\n",
+ "#calculate the resistance\n",
+ "#given data :\n",
+ "l=65;# in cm\n",
+ "V=0.1;# in V\n",
+ "V1=5.5;# in V\n",
+ "R=20;# in ohm\n",
+ "#calculations\n",
+ "E=V*l;\n",
+ "I=V1/R;\n",
+ "Ri=(E-V1)/I;\n",
+ "#results\n",
+ "print \"Internal resistance,Ri(ohm) = \",round(Ri,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6 - pg 259"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (k-ohm)= 50.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 259\n",
+ "#Example 4.6: Resistance\n",
+ "#calculate the resistance\n",
+ "#given\n",
+ "vr=5.;#V\n",
+ "r=10.;#k-ohm\n",
+ "#calculations\n",
+ "x=vr*r*10**3;#\n",
+ "R=x;#\n",
+ "#results\n",
+ "print \"resistance is (k-ohm)=\",R*10**-3\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7 - pg 260"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The length of slide wire (cm) = 200.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 260\n",
+ "#Example 4.7: Length\n",
+ "#calculate the length of the slide wire\n",
+ "#given data :\n",
+ "l=40.;# in cm\n",
+ "r=0.5;# ion ohm\n",
+ "V=1.2;# in V\n",
+ "V1=6;# in V\n",
+ "#calculations\n",
+ "R=r*l/1;# in ohm\n",
+ "I=V/R;\n",
+ "x=V1/(r*I);\n",
+ "#results\n",
+ "print \"The length of slide wire (cm) = \",x\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8 - pg 260"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance R is (ohm)= 20.0\n",
+ "resistance R1 is (ohm)= 2.0\n",
+ "resistance R2 is (ohm)= 4.0\n",
+ "resistance per cm of slide wire is (ohm/cm)= 0.02\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 260\n",
+ "#Example 4.8: design\n",
+ "#calculate the resistance in all cases\n",
+ "#given\n",
+ "vab=1.;#V\n",
+ "i=50.;#mA\n",
+ "n=10.;#\n",
+ "l=100.;#cm\n",
+ "#calculations\n",
+ "vr=2-vab;#V\n",
+ "R=vr/(i*10**-3);#ohm\n",
+ "R1=(vr/10)/(i*10**-3);#ohm\n",
+ "tr1=n*R1;#ohm\n",
+ "r2=2*R1;#\n",
+ "x=R1/l;#\n",
+ "#results\n",
+ "print \"resistance R is (ohm)=\",R\n",
+ "print \"resistance R1 is (ohm)=\",R1\n",
+ "print \"resistance R2 is (ohm)=\",r2\n",
+ "print \"resistance per cm of slide wire is (ohm/cm)=\",x"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9 - pg 261"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistance is (ohm) = 39.5\n",
+ "resolution of the instrument is (micro-V) = 20.0\n",
+ "error is (micro-V) = 2.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 261\n",
+ "#Example 4.9.a:resistance\n",
+ "#calculate the resistance, resolution and error\n",
+ "#given\n",
+ "st=15.;#steps\n",
+ "r=5.;#ohm\n",
+ "rsw=5.5;#ohm\n",
+ "vr=1.61;#V\n",
+ "e2=1.61;#V\n",
+ "e1=2.40;#V\n",
+ "trn=11.;#turns\n",
+ "dv=100.;#divisions\n",
+ "ig=0.05;#micro-A\n",
+ "vlt=1.1;#V\n",
+ "ir=50.;#ohm\n",
+ "#calculations\n",
+ "tr=(st*r)+rsw;#ohm\n",
+ "i=vr/tr;#A\n",
+ "rh=(e1-e2)/i;#ohm \n",
+ "slwr=rsw/trn;#ohm\n",
+ "vd=slwr*i;#V\n",
+ "vedv=(1/dv)*vd;#\n",
+ "rs=vedv/5;#\n",
+ "em=((ig*ir));#\n",
+ "#results\n",
+ "print \"resistance is (ohm) = \",rh\n",
+ "print \"resolution of the instrument is (micro-V) = \",rs*10**6\n",
+ "print \"error is (micro-V) = \",em\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10 - pg 262"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "power dissipated in the resistor is (mW)= 0.4176\n",
+ "power dissipated in the coil is (mW)= 0.264\n",
+ "power dissipated in the capacitor is (mW)= 0.036\n",
+ "energy stored in the coil is (micro-J)= 0.61\n",
+ "energy stored in capacitor is (micro-J)= 0.42\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 262\n",
+ "#Example 4.10:power dissipated\n",
+ "#calculate the power dissipated and energy stored\n",
+ "#given\n",
+ "import math,cmath\n",
+ "r1=0.6-1j*0.24;#V\n",
+ "r2=0.6+1j*0.4;#V\n",
+ "r3=-0.1-1j*0.4;#V\n",
+ "f=50;#Hx\n",
+ "ir=1000;#ohm\n",
+ "#calculations\n",
+ "i1=r1/ir;#A\n",
+ "pdr=(r1.real*i1.real)+(r1.imag*i1.imag);#W\n",
+ "pdC=(r1.real*i1.real)+(r2.imag*i1.imag);#W\n",
+ "pdc=(r3.real*i1.real)-(r2.imag*i1.imag);#W\n",
+ "imp=(r2/r1)*10**3;#ohm\n",
+ "rc=imp.imag;#ohm\n",
+ "indu=rc/(2*math.pi*f);#H\n",
+ "ersl=(1./2)*(i1.imag**2+i1.real**2)*indu;#joules\n",
+ "admc=(r1*10**-3)/r3;#ohm**-1\n",
+ "C=admc.imag/(2*math.pi*f);#\n",
+ "ersc=(1./2)*(r3.imag**2+r3.real**2)*C;#\n",
+ "#results\n",
+ "print \"power dissipated in the resistor is (mW)=\",pdr*10**3\n",
+ "print \"power dissipated in the coil is (mW)=\",pdC*10**3\n",
+ "print \"power dissipated in the capacitor is (mW)=\",pdc*10**3\n",
+ "print \"energy stored in the coil is (micro-J)=\",round(ersl*10**6,2)\n",
+ "print \"energy stored in capacitor is (micro-J)=\",round(ersc*10**6,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11 - pg 263"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "measuring range of the potentiometer is (V)= 1.9\n",
+ "resolution is (mV)= 0.5\n",
+ "current through the dial is (mA)= 10.0\n",
+ "setting of the rheostat is (ohm)= 410.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 263\n",
+ "#Example 4.11:measuring range,resulution,working current,setting of the rheostat\n",
+ "#calculate the measuring range,resulution,working current,setting of the rheostat\n",
+ "#given\n",
+ "sd=18.;#steps\n",
+ "v1=0.1;#V\n",
+ "dv=100;#divisions\n",
+ "dr=10;#ohm\n",
+ "wbc=6;#V\n",
+ "#calculations\n",
+ "mr=(sd*v1)+v1;#V\n",
+ "rs=(v1/dv)*(1./2);#mV\n",
+ "cdd=v1/dr;#A\n",
+ "rsv=wbc-mr;#V\n",
+ "sh=rsv/cdd;#ohm\n",
+ "#results\n",
+ "print \"measuring range of the potentiometer is (V)=\",mr\n",
+ "print \"resolution is (mV)=\",rs*10**3\n",
+ "print \"current through the dial is (mA)=\",cdd*10**3\n",
+ "print \"setting of the rheostat is (ohm)=\",sh\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12 - pg 263"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "true value of drop across the resistance is (V)= 0.6529\n",
+ "percentage error is (%)= 0.06\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 263\n",
+ "#Example 4.12:voltage and percentage error\n",
+ "#calculate the voltage and percentage error\n",
+ "#given\n",
+ "st=15;#steps\n",
+ "r1=10;#ohm\n",
+ "v1=0.1;#V\n",
+ "r2=10;#ohm\n",
+ "r3=9.9;#ohm\n",
+ "v2=0.0185;#V\n",
+ "v3=1.0185;#V\n",
+ "n=6;#\n",
+ "vg=0.6525;#\n",
+ "#calculations\n",
+ "acr=(r1*r3)+((r2*v2)/v1);#ohm\n",
+ "I=v3/acr;#\n",
+ "acr1=(n*r3)+(r2*0.0525)/v1;#ohm\n",
+ "tvr=I*acr1;#V\n",
+ "er=((tvr-vg)/tvr)*100;#\n",
+ "#results\n",
+ "print \"true value of drop across the resistance is (V)=\",round(tvr,4)\n",
+ "print \"percentage error is (%)=\",round(er,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13 - pg 264"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "reactance is (ohm)= 1.28\n",
+ "inductance of the coil is (mH)= 30.0\n",
+ "The answer is a bit different due to rounding off error in textbook\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 264\n",
+ "#Example 4.13:resistance and reactance\n",
+ "#calculate the resistance and reactance\n",
+ "#given\n",
+ "import math,cmath\n",
+ "from math import sqrt,atan,sin\n",
+ "r1=2.;#ohm\n",
+ "r2=9.;#\n",
+ "vm=85.;#V\n",
+ "va=40.;#degree\n",
+ "vm1=90.;#V\n",
+ "va1=45.;#degree\n",
+ "f=50.;#Hz\n",
+ "#calculations\n",
+ "imp=r1+1j*r2;#ohm\n",
+ "mg=sqrt(r1**2+r2**2);#\n",
+ "th=atan(r2/r1) *57.3;#\n",
+ "ccm=vm/mg;#A\n",
+ "cca=va-th;#degree\n",
+ "impm=vm1/ccm;#ohm\n",
+ "impa=va1-cca;#degree\n",
+ "reac=impm*sin(impa/57.3);#ohm\n",
+ "rc=sqrt(impm**2-reac**2);#ohm\n",
+ "ind=reac/(2*math.pi*f);#\n",
+ "#results\n",
+ "print \"reactance is (ohm)=\",round(rc,2)\n",
+ "print \"inductance of the coil is (mH)=\",math.floor(ind*10**3)\n",
+ "print 'The answer is a bit different due to rounding off error in textbook'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14 - pg 265"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "limit of error in the reading is 48.6 micro-V\n",
+ "deflection of the galvanometer is (mm)= 8.1\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 265\n",
+ "#Example 4.14:limit of error,deflection\n",
+ "#calculate the limit of error and deflection of galvanometer\n",
+ "#given\n",
+ "x=17.5;#mm/micro-A\n",
+ "r1=850.;#ohm\n",
+ "v1=2.;#V\n",
+ "r2=80.;#\n",
+ "v3=1.43;#V\n",
+ "v2=0.1;#V\n",
+ "l=50.;#cm\n",
+ "l1=2.;#mm\n",
+ "fr1=22.784;#\n",
+ "#calculations\n",
+ "lr=r1*(1./x);#micro V\n",
+ "i1=v1/r2;#A\n",
+ "r3=v2/i1;#ohm\n",
+ "r4=v3/i1;#ohm\n",
+ "r5=((l1/10.)/l)*r3;#ohm\n",
+ "fr=r4+r5;#ohm\n",
+ "R=(fr*fr1)/r2;#ohm\n",
+ "e=i1*fr;#V\n",
+ "ig=(e-v3)/(r1+R);#A\n",
+ "dg=ig*x*10**6;#mm\n",
+ "#results\n",
+ "print \"limit of error in the reading is \",round(lr,1),\" micro-V\"\n",
+ "print \"deflection of the galvanometer is (mm)=\",round(dg,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 15 - pg 266"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Current in one direction,I1(mA) = 10.0\n",
+ "Current in another direction,I2(mA) = 10.34\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 266\n",
+ "#Example 4.15: Current \n",
+ "#calculate the Current \n",
+ "#given data :\n",
+ "V1=4.2;# in V\n",
+ "V2=1.43;# in V\n",
+ "r1=21.0;# in ohm\n",
+ "r2=1.;# in ohm\n",
+ "r3=15.;# in ohm\n",
+ "#calculations\n",
+ "I=V1/r1;# in A\n",
+ "R=V2/I;# in ohm\n",
+ "R1=R+r2;\n",
+ "R2=R-r2;\n",
+ "R3=round(R1*(r1-R1)/r1);\n",
+ "R4=R2*(r1-R2)/r1;\n",
+ "e1=R1*I;\n",
+ "e2=R2*I;\n",
+ "I1=(e1-V2)*10**3/(R3+r3);\n",
+ "I2=(V2-e2)*10**3/(R4+r3);\n",
+ "#results\n",
+ "print \"Current in one direction,I1(mA) = \",I1\n",
+ "print \"Current in another direction,I2(mA) = \",round(I2,2)\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter5.ipynb b/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter5.ipynb
new file mode 100755
index 00000000..b328650c
--- /dev/null
+++ b/Electrical_Measurements_Measuring_Instruments_by_K._Shinghal/Chapter5.ipynb
@@ -0,0 +1,769 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 5 - Magnetic measurement"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1 - pg 304"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Capacity of the capacitor (micro-F) = 2.12\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 304\n",
+ "#Example 5.1: Capacity of the capacitor\n",
+ "#calculate the Capacity of the capacitor\n",
+ "#given data :\n",
+ "import math\n",
+ "Ig=0.0001;# in A\n",
+ "T0=3.;# in sec\n",
+ "theta0=200.;\n",
+ "theta=45.;\n",
+ "V=100.;# in V\n",
+ "#calculations\n",
+ "Q=(Ig*T0*theta0)/(theta*2*math.pi);\n",
+ "C=(Q/V)*10**6;\n",
+ "#results\n",
+ "print \"Capacity of the capacitor (micro-F) = \",round(C,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2 - pg 304"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Coulomb sensitivity (mm/micro-C) = 8.89\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 304\n",
+ "#Example 5.2: Coulomb sensitivity\n",
+ "#calculate te Coulomb sensitivity\n",
+ "#given data :\n",
+ "C=1.5*10**-6;# in F\n",
+ "V=15;# in V\n",
+ "d1=20;# in cm\n",
+ "#calculations\n",
+ "Q=C*V;\n",
+ "Sb=(d1/Q)*10**-5;\n",
+ "#resutls\n",
+ "print \"Coulomb sensitivity (mm/micro-C) = \",round(Sb,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3 - pg 305"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Logarithmic increment = 0.2231\n",
+ "undamped frequency is (Hz)= 0.1253\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 305\n",
+ "#Example 5.3: Logarithmic increment\n",
+ "#calculate the Logarithmic increment and frequency\n",
+ "#given data :\n",
+ "import math\n",
+ "theta1=12.5;\n",
+ "theta2=10.;\n",
+ "#calculations\n",
+ "lamda=math.log(theta1/theta2);\n",
+ "x=lamda**2;#\n",
+ "y=x/(math.pi**2-x);#\n",
+ "y1=math.sqrt(y);#\n",
+ "f=0.125;#Hz\n",
+ "fo=f/(math.sqrt(1-y1**2));#Hz\n",
+ "#results\n",
+ "print \"Logarithmic increment = \",round(lamda,4)\n",
+ "print \"undamped frequency is (Hz)=\",round(fo,4)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4 - pg 305"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Flux density B(Wb/m^2) = 55.56\n",
+ "permeability mu(H/m) = 60.0\n",
+ "flux density is calculed wrong in the textbook\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 305\n",
+ "#Example 5.4: Flux density\n",
+ "#calculate the flux density\n",
+ "#given data :\n",
+ "I1=5.;# in A\n",
+ "I2=10.;# in A\n",
+ "N1=100.;# number of turns\n",
+ "N2=200.;#number of turns\n",
+ "l=30*10**-2;# in m\n",
+ "R=200.;# in ohm\n",
+ "theta1=45.;# in degree\n",
+ "theta2=30.;# in degree\n",
+ "As=0.3*10**-4;# in m**2\n",
+ "M=100*10**-3;# in H\n",
+ "#calculations\n",
+ "k=(2*M*I1)/(R*theta1);\n",
+ "H=(N1*I2)/l;\n",
+ "fi=(R*k*theta2)/(2*N2);\n",
+ "B=fi/As;\n",
+ "mu=H/B;\n",
+ "#results\n",
+ "print \"Flux density B(Wb/m^2) = \",round(B,2)\n",
+ "print \"permeability mu(H/m) = \",mu\n",
+ "print 'flux density is calculed wrong in the textbook'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5 - pg 309"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Flux density,B(Wb/m^2) = 1.25\n",
+ "Relative permeability = 521.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 309\n",
+ "#Example 5.5: Flux density and relative permeability\n",
+ "#calculate the Flux density and relative permeability\n",
+ "#given data :\n",
+ "import math\n",
+ "A=5*10**-4;# in m**2\n",
+ "d=25*10**-2;# in m\n",
+ "N1=150;# turns\n",
+ "N2=300;# turns\n",
+ "k=2*10**-6;# coulomb per division\n",
+ "R=2500;# in ohm\n",
+ "I=10;# in A\n",
+ "theta=75;# in division\n",
+ "#calculations\n",
+ "l=math.pi*d;\n",
+ "mu_0=4*math.pi*10**-7;\n",
+ "B=(k*theta*R)/(2*N2*A);\n",
+ "H=(N1*I)/l;\n",
+ "mu_r=(B/(mu_0*H));\n",
+ "#results\n",
+ "print \"Flux density,B(Wb/m^2) = \",B\n",
+ "print \"Relative permeability = \",round(mu_r)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6 - pg 308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "In case of total flux is (Wb)= 0.027\n",
+ "In case of useful flux is (Wb)= 0.0228\n",
+ "leakage coefficient is = 1.185\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 308\n",
+ "#Example 5.6 #flux per pole and leakage cofficient\n",
+ "#calculate the flux per pole and leakage cofficient\n",
+ "#given data:\n",
+ "k=0.15;#micro-C\n",
+ "th=120.;#divisions\n",
+ "th1=135.;#divisions\n",
+ "r=4500.;#ohm\n",
+ "n=3.;#turns\n",
+ "#calculations\n",
+ "ft=(k*10**-6*th*r)/n;#Wb\n",
+ "n1=4;#\n",
+ "ft1=(k*10**-6*th1*r)/n1;#Wb\n",
+ "lk=ft/ft1;#\n",
+ "#results\n",
+ "print \"In case of total flux is (Wb)=\",ft\n",
+ "print \"In case of useful flux is (Wb)=\",round(ft1,4)\n",
+ "print \"leakage coefficient is =\",round(lk,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7 - pg 308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "relative permeability = 30.7\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 308\n",
+ "#Example 5.7 #relative permeability\n",
+ "#calculate the relative permeability\n",
+ "#given data\n",
+ "import math\n",
+ "n1=320.;#turns\n",
+ "n2=250.;#turns\n",
+ "i=10.;#A\n",
+ "l=32.;#cm\n",
+ "fl=2.5*10**-4;#Wb\n",
+ "sd=100;#\n",
+ "sd1=270;#/\n",
+ "#calculations\n",
+ "N=(n1*i)/(l*10**-2);#AT/m\n",
+ "k=(fl*i)/sd;#\n",
+ "mo=4*math.pi*10**-7;#\n",
+ "A=0.35;#cm**2\n",
+ "ur=((k*sd1)/(2*mo*N*A*10**-4*n2));#\n",
+ "#results\n",
+ "print \"relative permeability =\",round(ur,1)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8 - pg 309"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The shunt resistance S(ohm) = 0.0127\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 309\n",
+ "#Example 5.7 # Shunt resistance\n",
+ "#calculate the shunt resistance\n",
+ "#given data :\n",
+ "N=800.;# turns\n",
+ "I=10.;# in A\n",
+ "reluctance=150000;# in AT per Wb\n",
+ "K=.15*10**-3;# in Wb turns/ division\n",
+ "rs=0.025;# in ohm\n",
+ "Ns=1;\n",
+ "theta=120;#divisions\n",
+ "#calculations\n",
+ "fi=(N*I)/reluctance;\n",
+ "S=(K*rs*theta)/((fi*Ns)-(K*theta));\n",
+ "#results\n",
+ "print \"The shunt resistance S(ohm) = \",round(S,4)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9 - pg 310"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The magnetic potential difference between two points,(AT) = 697.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 310\n",
+ "#Example 5.9 # Magnetic pole difference\n",
+ "#calculate the Magnetic pole difference\n",
+ "#given data :\n",
+ "N=150.;# turns\n",
+ "I=1.2;# in A\n",
+ "theta=300.;# divisions\n",
+ "t=155.;#change in mmf in division\n",
+ "#calculations\n",
+ "mmf=N*I;\n",
+ "r=2*mmf;# du to reversal\n",
+ "K=360/t;\n",
+ "M=(K*theta);\n",
+ "#results\n",
+ "print \"The magnetic potential difference between two points,(AT) = \",round(M)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10 - pg 310"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "relative permeability = 521.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 310\n",
+ "#Example 5.10 #relative permeability\n",
+ "#calculate the relative permeability\n",
+ "#given data\n",
+ "import math\n",
+ "n1=600.;#turns\n",
+ "i=3.;#A\n",
+ "d=30.;#cm\n",
+ "ass=6.;#cm^2;#\n",
+ "t1=500.;#turns\n",
+ "r=250.;#ohms\n",
+ "k=3000.;#micro-C\n",
+ "#calculations\n",
+ "H=(n1*i)/(math.pi*d*10**-2);#\n",
+ "mo=4*math.pi*10**-7;#\n",
+ "x=mo*H;#\n",
+ "y=ass*10**-4*x;#\n",
+ "z=t1*y;#\n",
+ "z1=2*z;#\n",
+ "it=z1/r;#\n",
+ "ur=(k*10**-6)/it;#\n",
+ "#results\n",
+ "print \"relative permeability =\",round(ur)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11 - pg 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Fluxmeter deflection (degree) = 76.4\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 311\n",
+ "#Example 5.11 # Fluxmeter deflection\n",
+ "#calculate the Fluxmeter deflection\n",
+ "#given data :\n",
+ "import math\n",
+ "l=5*10**-2;# in m\n",
+ "N=40;# turns\n",
+ "B=5*10**-3;# in Wb/m**2\n",
+ "b=1.5*10**-2;# in m\n",
+ "cs=2*10**-4;# in m**2\n",
+ "B1=0.05;# in Wb/m**2\n",
+ "#calculations\n",
+ "fi=B1*cs;\n",
+ "del_fi=2*fi;\n",
+ "theta=(del_fi*10)/(N*B*l*b);\n",
+ "#results\n",
+ "print \"Fluxmeter deflection (degree) = \",round((theta*(180/math.pi)),1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12 - pg 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Hysteresis current component of the loss (W)= 266.7\n",
+ "Eddy current component of the loss (W)= 158.3\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 311\n",
+ "#Example 5.12 #hysteresis and eddy current components\n",
+ "#calculate the hysteresis and eddy current components\n",
+ "#given data\n",
+ "import numpy\n",
+ "w1=132.;#W\n",
+ "f1=20.;#Hz\n",
+ "w2=425.;#W\n",
+ "f2=50.;#Hz\n",
+ "#calculations\n",
+ "x=w1/f1;#\n",
+ "y=w2/f2;#\n",
+ "A=numpy.matrix([[1, f1],[1, f2]]);#\n",
+ "B=numpy.matrix([[x],[y]]);#\n",
+ "X=numpy.dot(numpy.linalg.inv(A),B);#\n",
+ "Wh=X[0,0]*f2;#W\n",
+ "We=X[1,0]*f2**2;#W\n",
+ "#results\n",
+ "print \"Hysteresis current component of the loss (W)=\",round(Wh,1)\n",
+ "print \"Eddy current component of the loss (W)=\",round(We,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13 - pg 312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "hysteresis loss is (W)= 22.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 312\n",
+ "#Example 5.13 #hysteresis loss\n",
+ "#calculate the hysteresis loss\n",
+ "#given data\n",
+ "Hx=125.;#AT/m\n",
+ "ah=200.;#cm**2\n",
+ "ba=0.15;#Wb/m**2\n",
+ "lo=50;#loos\n",
+ "kg=8.5*10**3;#kg/m**3\n",
+ "#calculations\n",
+ "le=ah*Hx*ba;#J/m**3\n",
+ "po=lo*le;#W/m**3\n",
+ "lkg=po/kg;#watt\n",
+ "#results\n",
+ "print \"hysteresis loss is (W)=\",round(lkg)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14 - pg 312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The flux density B(Wb/m^2) = 0.121\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 312\n",
+ "#Example 5.14 # flux density\n",
+ "#calculate the flux density\n",
+ "#given data :\n",
+ "R=200+50.;# in ohm\n",
+ "k=100*10**-6;# in coulomb\n",
+ "theta=80.;# divisions\n",
+ "A=55*10**-4;# in m**2\n",
+ "N=1500;# turns\n",
+ "#calculations\n",
+ "B=(R*k*theta)/(2*A*N);\n",
+ "#results\n",
+ "print \"The flux density B(Wb/m^2) = \",round(B,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 15 - pg 313"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "loss is (W)= 0.617\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 313\n",
+ "#Example 5.15 #loss\n",
+ "#calculate the loss\n",
+ "#given data\n",
+ "f=50.;#Hz\n",
+ "k=2.3*10**-2;#\n",
+ "x=1.7;#\n",
+ "wi=0.6;#W\n",
+ "bm=0.5;#Wb/m**2\n",
+ "f1=20;#Hz\n",
+ "bm1=1;#\n",
+ "#calculations\n",
+ "kd=((wi-(k*bm**x*f))/(bm**2*f**2));#\n",
+ "wi1=((k*bm1**x*f1)+(kd*bm1**2*f1**2));#\n",
+ "#results\n",
+ "print \"loss is (W)=\",round(wi1,3)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16 - pg 313"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "magnetic flux is (Wb/m^2)= 0.714\n",
+ "flux density is (AT/m^2)= 400.0\n",
+ "relative permeability is = 1421.03\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 313\n",
+ "#Example 5.16 #MAGNETIC FORCE ,FLUX DENSITY AND RELATIVE PERMEABILITY\n",
+ "#calculate the MAGNETIC FORCE ,FLUX DENSITY AND RELATIVE PERMEABILITY\n",
+ "#given data\n",
+ "import math\n",
+ "k=1;#micro-C\n",
+ "th=100.;#turns\n",
+ "r=5000.;#ohm\n",
+ "n2=350.;#turns\n",
+ "ass=10.;#cm**2\n",
+ "n1=100.;#turns\n",
+ "i=4.;#A\n",
+ "l=100.;#cm\n",
+ "#calculations\n",
+ "b=((k*th*r*10**-6)/(2*n2*ass*10**-4));#Wb/m**2\n",
+ "H=(n1*i)/(l*10**-2);#AT/m**2\n",
+ "mo=4*math.pi*10**-7;#\n",
+ "ur=b/(mo*H);#\n",
+ "#results\n",
+ "print \"magnetic flux is (Wb/m^2)=\",round(b,3)\n",
+ "print \"flux density is (AT/m^2)=\",H\n",
+ "print \"relative permeability is =\",round(ur,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 17 - pg 314"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Constant is (Wb-turn/scale-div)= 1.005e-07\n"
+ ]
+ }
+ ],
+ "source": [
+ "#pg 314\n",
+ "#Example 5.17 # fluxmeter\n",
+ "#calculate the Constant of fluxmeter\n",
+ "#given data :\n",
+ "import math\n",
+ "N1=800.;# turns\n",
+ "I=5;# in A\n",
+ "l=1;# in m\n",
+ "A=5*10**-4;# in m**2\n",
+ "N=500;# turns\n",
+ "theta=25.;# divisions\n",
+ "#calculations\n",
+ "H=(N1*I)/l;\n",
+ "B=(4*math.pi*10**-7*H);\n",
+ "fi=B*A*10**8;\n",
+ "K=((2*N*fi*10**-8)/(theta));\n",
+ "#results\n",
+ "print \"Constant is (Wb-turn/scale-div)=\",round(K*10**-3,10)\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Electrical_Power-i_/screenshots/Chapter5_Transmission_Efficiendy.png b/Electrical_Power-i_/screenshots/Chapter5_Transmission_Efficiendy.png
new file mode 100755
index 00000000..2e1ee63b
--- /dev/null
+++ b/Electrical_Power-i_/screenshots/Chapter5_Transmission_Efficiendy.png
Binary files differ
diff --git a/Electrical_Power-i_/screenshots/Chapter7_MinPotential.png b/Electrical_Power-i_/screenshots/Chapter7_MinPotential.png
new file mode 100755
index 00000000..6a25a318
--- /dev/null
+++ b/Electrical_Power-i_/screenshots/Chapter7_MinPotential.png
Binary files differ
diff --git a/Electrical_Power-i_/screenshots/Chapter9_Reactance.png b/Electrical_Power-i_/screenshots/Chapter9_Reactance.png
new file mode 100755
index 00000000..f0663e1d
--- /dev/null
+++ b/Electrical_Power-i_/screenshots/Chapter9_Reactance.png
Binary files differ
diff --git a/Electrical_Power-i__by_M.L._Anand/Chapter1.ipynb b/Electrical_Power-i__by_M.L._Anand/Chapter1.ipynb
new file mode 100755
index 00000000..edab587f
--- /dev/null
+++ b/Electrical_Power-i__by_M.L._Anand/Chapter1.ipynb
@@ -0,0 +1,198 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "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": [
+ "Exa 1.1 - page 13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given data : \n",
+ "R=4 #in ohm\n",
+ "XL=3 #in ohm\n",
+ "VL=400 #in volt\n",
+ "Vph=VL/sqrt(3) #in volt\n",
+ "Zph=sqrt(R**2+XL**2) #in ohm\n",
+ "Iph=Vph/Zph #in Ampere\n",
+ "#In star connected IL=Iph\n",
+ "IL=Iph #in Ampere\n",
+ "print \"Line Current = %0.1f A\" %IL\n",
+ "cosfi=R/Zph #unitless\n",
+ "PowerConsumed=sqrt(3)*VL*IL*cosfi #in watts\n",
+ "print \"Total power consumed by the load = %.f Watts\" %PowerConsumed "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Line Current = 46.2 A\n",
+ "Total power consumed by the load = 25600 Watts\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.2 - page 14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given data : \n",
+ "VL=440 #in volt\n",
+ "IL=10 #in Ampere\n",
+ "#In star connected :\n",
+ "print \"In star connected :\" \n",
+ "Iph=IL #in Ampere\n",
+ "Vph=VL/sqrt(3) #in volt\n",
+ "Rph=Vph/Iph #in ohm\n",
+ "print \"Value of each resistor = %.1f ohm\" %Rph\n",
+ "#In delta connected :\n",
+ "print \"In delta connected :\"\n",
+ "Iph=IL/sqrt(3) #in Ampere\n",
+ "Vph=Iph*Rph #in volt\n",
+ "print \"Voltage in delta connection = %.2f volt\" %Vph"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In star connected :\n",
+ "Value of each resistor = 25.4 ohm\n",
+ "In delta connected :\n",
+ "Voltage in delta connection = 146.67 volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.3 - page 15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi\n",
+ "#Given Data :\n",
+ "R=16 #in ohm\n",
+ "L=38.2 #in mH\n",
+ "L=38.2*10**-3 #in H\n",
+ "VL=400 #in volt\n",
+ "f=50 #in Hz\n",
+ "XL=2*pi*f*L #in ohm\n",
+ "Zph=sqrt(R**2+XL**2) #in ohm\n",
+ "#In star connected :\n",
+ "Vph=VL/sqrt(3) #in volt\n",
+ "Iph=Vph/Zph #in Ampere\n",
+ "IL=Iph #in Ampere\n",
+ "print \"Line Current = %0.2f A\" %IL\n",
+ "cosfi=R/Zph #unitless\n",
+ "print \"Power factor = %.1f\" %cosfi\n",
+ "P=sqrt(3)*VL*IL*cosfi #in watts\n",
+ "P/=10**3 # kW\n",
+ "print \"Total power consumed by the load = %0.3f kW\" %P"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Line Current = 11.55 A\n",
+ "Power factor = 0.8\n",
+ "Total power consumed by the load = 6.400 kW\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 1.4 - page 15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given Data :\n",
+ "R=15 #in ohm\n",
+ "X=40 #in ohm\n",
+ "VL=440 #in volt\n",
+ "#In delta connection : \n",
+ "Vph=VL #in volt\n",
+ "Zph=sqrt(R**2+X**2) #in ohm\n",
+ "Iph=Vph/Zph #in Ampere\n",
+ "print \"Phase Current = %0.1f A\" %Iph\n",
+ "IL=Iph*sqrt(3) #in Ampere\n",
+ "print \"Line Current = %0.2f A\" %IL"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Phase Current = 10.3 A\n",
+ "Line Current = 17.84 A\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/Electrical_Power-i__by_M.L._Anand/Chapter10.ipynb b/Electrical_Power-i__by_M.L._Anand/Chapter10.ipynb
new file mode 100755
index 00000000..a6dd1247
--- /dev/null
+++ b/Electrical_Power-i__by_M.L._Anand/Chapter10.ipynb
@@ -0,0 +1,786 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter10 - Power factor improvement"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.1 - page 268"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "Load=500 #in KW\n",
+ "cosfi_1=0.75 #powerfactor\n",
+ "x=40 #in Rs/year/KVA\n",
+ "x1=60 #cost of PF improvement equipment in Rs./KVAR\n",
+ "i=12 #in % per annum\n",
+ "y=x1*i/100 #in Rs.\n",
+ "cosfi_2=0.98 #unitless\n",
+ "KVA1=Load/cosfi_1 #in KVA(at 0.75 pf)\n",
+ "KVA2=Load/cosfi_2 #in KVA(at 0.98 pf)\n",
+ "AnnualSaving=x*(KVA1-KVA2) #in Rs.\n",
+ "fi_1=np.arccos(cosfi_1)*180/np.pi #in degree\n",
+ "tanfi_1=np.tan(fi_1*np.pi/180) #unitless\n",
+ "Pr1=Load*tanfi_1 #in KVAR\n",
+ "fi_2=np.arccos(cosfi_2)*180/np.pi #in degree\n",
+ "tanfi_2=np.tan(fi_2*np.pi/180) #unitless\n",
+ "Pr2=Load*tanfi_2 #in KVAR\n",
+ "Rating=Pr1-Pr2 #in KVAR\n",
+ "AnnualExpenditure=y*Rating #in Rs.\n",
+ "NetSaving=AnnualSaving-AnnualExpenditure #in Rs./year\n",
+ "print \"Net saving per year = %0.2f Rs.\" %NetSaving\n",
+ "# Answer in the textbook is not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Net saving per year = 3882.50 Rs.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.2 - page 270"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "Eta=85 #in %\n",
+ "P=30 #in HP\n",
+ "P1=P*0.7355*Eta/100 #in KW\n",
+ "cosfi_1=0.8 #powerfactor\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) #unitless\n",
+ "Pr=P1*tanfi_1 #in KVAR\n",
+ "#Let active power P2 : Total Active power = P1+P2\n",
+ "cosfi=0.9 #overall powerfactor\n",
+ "tanfi=np.tan(np.arccos(cosfi)) #unitless\n",
+ "#Pr1=tanfi*(P1+P2) #in KVAR\n",
+ "#Putting Pr=Pr1\n",
+ "P2=(Pr-P1*tanfi)/tanfi #in KW\n",
+ "print \"Rating of the heater = %0.2f KW\" %P2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rating of the heater = 10.29 KW\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.3 - page 270"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "Im=50 #in Ampere\n",
+ "f=50 #in Hz\n",
+ "V=400 #in volts\n",
+ "cosfi_1=0.6 #powerfactor\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) #unitless\n",
+ "Ia=Im*cosfi_1 #in Ampere\n",
+ "Ir1=Ia*tanfi_1 #in Ampere\n",
+ "#Let the capaitor of C farads be connected to improve pf i.e., 0.9(lag) \n",
+ "cosfi_2=0.9 #powerfactor\n",
+ "tanfi_2=np.tan(np.arccos(cosfi_2)) #unitless\n",
+ "Ir2=Ia*tanfi_2 #in Ampere\n",
+ "Ic=Ir1-Ir2 #in Ampere\n",
+ "C=Ic/(2*np.pi*f*V) #in farads\n",
+ "print \"Capacity of condenser = %0.1f uF\" %(C*10**6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacity of condenser = 202.7 uF\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.4 - page 271"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "Im=10 #in Ampere\n",
+ "f=50 #in Hz\n",
+ "V=240 #in volts\n",
+ "cosfi_1=0.707 #powerfactor\n",
+ "sinfi_1=np.sin(np.arccos(cosfi_1)) #unitless\n",
+ "Ir1=Im*sinfi_1 #in Ampere\n",
+ "cosfi_2=1 #powerfactor\n",
+ "Ir2=0 #in A(as cosfi_2=1)\n",
+ "Ic=Ir1-Ir2 #in Ampere\n",
+ "C=Ic/(2*np.pi*f*V) #in farads\n",
+ "print \"Capacity of condenser = %0.2f uF\" %(C*10**6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacity of condenser = 93.80 uF\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.5 - page 272"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "Im=30 #in Ampere\n",
+ "f=50 #in Hz\n",
+ "V=200 #in volts\n",
+ "cosfi_1=0.8 #powerfactor\n",
+ "Ia=Im*cosfi_1 #in Ampere\n",
+ "cosfi_2=1 #powerfactor\n",
+ "Ir2=0 #in A(as cosfi_2=1)\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) #unitless\n",
+ "Ir1=Ia*tanfi_1 #in Ampere\n",
+ "Ic=Ir1-Ir2 #in Ampere\n",
+ "C=Ic/(2*np.pi*f*V) #in farads\n",
+ "print \"Capacity of condenser = %0.1f uF\" %(C*10**6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacity of condenser = 286.5 uF\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.6 - page 272"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "Im=30 #in Ampere\n",
+ "f=50 #in Hz\n",
+ "V=200 #in volts\n",
+ "cosfi_1=0.7 #powerfactor\n",
+ "Ia=Im*cosfi_1 #in Ampere\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) #unitless\n",
+ "Ir1=Ia*tanfi_1 #in Ampere\n",
+ "cosfi_2=0.85 #powerfactor\n",
+ "tanfi_2=np.tan(np.arccos(cosfi_2)) #unitless\n",
+ "Ir2=Ia*tanfi_2 #in Ampere\n",
+ "Ic=Ir1-Ir2 #in Ampere\n",
+ "C=Ic/(2*np.pi*f*V) #in farads\n",
+ "print \"Capacity of condenser = %0.2f uF\" %(C*10**6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacity of condenser = 133.84 uF\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.7 - page 273"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "#(i)\n",
+ "IMO=200 #in HP(Induction Motor output)\n",
+ "IMO=IMO*0.7355 #in KW(Induction Motor output)\n",
+ "LagEff=90 #in %\n",
+ "LagEff=90/100 #in fraction\n",
+ "MotorIn=IMO/(LagEff) #in KW\n",
+ "cosfi_1=0.75 #powerfactor\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) #unitless\n",
+ "Pr1=MotorIn*tanfi_1 #in KVAR\n",
+ "#(ii)\n",
+ "P2=300 #in KW\n",
+ "cosfi_2=0.5 #unitless\n",
+ "tanfi_2=np.tan(np.arccos(cosfi_2)) #unitless\n",
+ "Pr2=P2*tanfi_2 #in KVAR\n",
+ "#(iii)\n",
+ "P3=200 #in KW\n",
+ "cosfi_3=1 #unitless\n",
+ "tanfi_3=0 #unitless\n",
+ "Pr3=0 #in KVAR\n",
+ "#(iv)\n",
+ "PsynMotor=500 #in KW\n",
+ "Eff=93 #in %\n",
+ "Eff=93/100 #in fration\n",
+ "Input=PsynMotor/Eff #in KW\n",
+ "Pa=MotorIn+P2+P3+PsynMotor #in KW\n",
+ "P1=Pr1+Pr2+Pr3 #in KVAR\n",
+ "cosfi=1 #unitless\n",
+ "tanfi=0 #unitless\n",
+ "Pr=Pa*tanfi #in KVAR\n",
+ "Prm=Pr-P1 #in KVAR\n",
+ "tanfi_m=Prm/Input\n",
+ "cosfi_m=np.cos(np.arctan(tanfi_m)) #unitless\n",
+ "print \"P.F. of the motor = %0.4f lead\" %cosfi_m\n",
+ "#Note : Answer in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "P.F. of the motor = 0.6294 lead\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.8 - page 274"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "f=50 #in Hz\n",
+ "V=400 #in volts\n",
+ "MotorOut=20 #in HP(Motor output)\n",
+ "MotorOut=MotorOut*735.5 #in Watts(Induction Motor output)\n",
+ "CorrectPF=0.85 #in fraction\n",
+ "MotorIn=MotorOut/(CorrectPF*1000) #in KW\n",
+ "cosfi_1=0.7071 #powerfactor\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) #unitless\n",
+ "Pr1=MotorIn*tanfi_1 #in KVAR\n",
+ "cosfi_2=0.85 #unitless\n",
+ "tanfi_2=np.tan(np.arccos(cosfi_2)) #unitless\n",
+ "Pr2=Pr1*tanfi_2 #in KVAR\n",
+ "Prc=Pr1-Pr2 #in KVAR\n",
+ "Prc_ph=Prc/3 #in KVAR\n",
+ "C=Prc_ph*10**3/(2*np.pi*f*V**2)\n",
+ "print \"Rating of each capacitor per phase = %0.2f uF\" %(C*10**6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rating of each capacitor per phase = 43.64 uF\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.9 - page 275"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "Pa=500 #in KW\n",
+ "cosfi_1=0.7071 #powerfactor\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) #unitless\n",
+ "Pr1=Pa*tanfi_1 #in KVAR\n",
+ "Pm=100 #in KW\n",
+ "P=Pa+Pm #in KW\n",
+ "cosfi_2=0.95 #unitless\n",
+ "tanfi_2=np.tan(np.arccos(cosfi_2)) #unitless\n",
+ "Pr=P*tanfi_2 #in KVAR\n",
+ "Prm=Pr-Pr1 #in KVAR\n",
+ "Pam=np.sqrt(Pm**2+Prm**2)\n",
+ "PFsynMotor=Pm/Pam #leading PF\n",
+ "print \"P.F. of synchronous motor = %0.4f lead\" %(PFsynMotor)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "P.F. of synchronous motor = 0.3136 lead\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.10 - page 275"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "P=1500 #in KW\n",
+ "cosfi_1=0.75 #powerfactor\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) #unitless\n",
+ "Pr1=P*tanfi_1 #in KVAR\n",
+ "Pm=150 #in KW\n",
+ "P=P+Pm #in KW\n",
+ "cosfi_2=0.9 #unitless\n",
+ "tanfi_2=np.tan(np.arccos(cosfi_2)) #unitless\n",
+ "Pr=P*tanfi_2 #in KVAR\n",
+ "Prm=Pr-Pr1 #in KVAR\n",
+ "Pam=np.sqrt(Pm**2+Prm**2)\n",
+ "cosfi=Pm/Pam #leading PF\n",
+ "print \"P.F. of synchronous motor = %0.4f lead\" %cosfi"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "P.F. of synchronous motor = 0.2753 lead\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.11 - page 276"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "Load=100 #in KW\n",
+ "LoadPF=0.75 #powerfactor\n",
+ "x=100 #in Rs/KVA\n",
+ "y=600*(10/100) #in Rs.\n",
+ "cosfi_2=np.sqrt(1-(y/x)**2)\n",
+ "print \"P.F. = %0.1f lag\" %(cosfi_2)\n",
+ "MaxDemand1=Load/LoadPF #in KW(at 0.75 load power factor)\n",
+ "MaxDemand2=Load/cosfi_2 #in KW(at cosfi_2 power factor)\n",
+ "AnnSaving=(MaxDemand1-MaxDemand2)*x #in Rs.\n",
+ "cosfi_1=0.75 #powerfactor\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) #unitless\n",
+ "tanfi_2=np.tan(np.arccos(cosfi_2)) #unitless\n",
+ "KVAR1=Load*tanfi_1 #in KVAR\n",
+ "KVAR2=Load*cosfi_2 #in KVAR\n",
+ "Rating=KVAR1-KVAR2 #in KVAR\n",
+ "AnnualExpenditure=y*Rating #in Rs.\n",
+ "AnnualSaving=AnnSaving-AnnualExpenditure #in Rs.\n",
+ "print \"Annual Savings = %0.1f Rs.\" %AnnualSaving"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "P.F. = 0.8 lag\n",
+ "Annual Savings = 341.8 Rs.\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.12 - page 277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "#(i)\n",
+ "PHeater=50 #in KW\n",
+ "cosfi_1=1 #unitless\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) #unitless\n",
+ "Pr1=PHeater*tanfi_1 #in KVAR\n",
+ "#(ii)\n",
+ "cosfi_2=0.7 #unitless\n",
+ "P2=200*735.5/(1000*0.8) #in KW\n",
+ "tanfi_2=np.tan(np.arccos(cosfi_2)) #unitless\n",
+ "Pr2=P2*tanfi_2 #in KVAR\n",
+ "#(iii)\n",
+ "cosfi=0.9 #unitless New PF\n",
+ "P3=200*735.5/(1000*cosfi) #in KW\n",
+ "TotalActivePower=PHeater+P2+P3 #in KW\n",
+ "TotalReactivePower=Pr1+Pr2 #in KW\n",
+ "tanfi=np.tan(np.arccos(cosfi)) #unitless\n",
+ "TotalPr=TotalActivePower*tanfi #in KVAR\n",
+ "Pnn=TotalPr-TotalReactivePower #in KVAR(ReactivePower of motor)\n",
+ "tanfi_mu=Pnn/P3 #unitless\n",
+ "cosfi_mu=np.cos(np.arctan(tanfi_mu)) \n",
+ "print \"PF of the synchronous motor = %0.2f\" %cosfi_mu \n",
+ "#Note : Answer in the book is wrong due to accuracy. My ans is 0.9996 if calculate upto 4 decimal place."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "PF of the synchronous motor = 1.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.13 - page 277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "x=60 #in Rs./KVA\n",
+ "x1=100 #in Rs/KVAR(cost of phase advancing equipment)\n",
+ "InterestCepriciation=x1*10/100 #in Rs.\n",
+ "y=10 #in Rs./KVAR\n",
+ "cosfi_2=np.sqrt(1-(y/x)**2) #unitless\n",
+ "print \"Most Ecomnomical PF = %0.3f lag\" %cosfi_2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Most Ecomnomical PF = 0.986 lag\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.14 - page 278"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "f=50 #in Hz\n",
+ "V=240 #in Volts\n",
+ "#(i)\n",
+ "Imoter=20 #in Ampere\n",
+ "cosfi_1=0.75 #unitless\n",
+ "ReacComponent1=Imoter*np.sqrt(1-cosfi_1**2) #in Ampere\n",
+ "#(ii)\n",
+ "cosfi_2=0.9 #unitless\n",
+ "P2=200*735.5/(1000*0.8) #in KW\n",
+ "ReacComponent2=Imoter*np.sqrt(1-cosfi_2**2) #in Ampere\n",
+ "Ic=ReacComponent1-ReacComponent2 #in Ampere(Leading reactive component)\n",
+ "C=Ic/(2*np.pi*f*V) #in Farads\n",
+ "print \"Capacitance of the capacitor = %0.2f uF\" %(round(C*10**6))\n",
+ "#Power of the motor=5 KW\n",
+ "P=5 #in KW\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) \n",
+ "tanfi_2=np.tan(np.arccos(cosfi_2)) \n",
+ "LeadingKVAR=P*(tanfi_1-tanfi_2) #in KVAR\n",
+ "print \"Leading KVAR supplied by the capactor = %0.2f KVAR\" %(round(LeadingKVAR))\n",
+ "print \"KVAR supplied per phase = %0.2f KVAR\" %(LeadingKVAR/3) \n",
+ "#Note : Answer in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacitance of the capacitor = 60.00 uF\n",
+ "Leading KVAR supplied by the capactor = 2.00 KVAR\n",
+ "KVAR supplied per phase = 0.66 KVAR\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.15 - page 279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "f=50 #in Hz\n",
+ "V=240 #in Volts\n",
+ "TotalLoad=200+80 #in KW\n",
+ "cosfi_1=0.8 #unitless\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) \n",
+ "cosfi_2=0.9 #unitless\n",
+ "tanfi_2=np.tan(np.arccos(cosfi_2)) \n",
+ "#(i)\n",
+ "OA=200 #in KW\n",
+ "OD=280 #in KW\n",
+ "CM=OA*tanfi_1-OD*tanfi_2 #in KVAR\n",
+ "print \"(i) Leading KVAR supplied by the motor = %0.1f KVAR\" %CM\n",
+ "#(ii)\n",
+ "BM=80 #in KW\n",
+ "CM=15.6 #in KW\n",
+ "KVA_Rating=np.sqrt(BM**2+CM**2) #in KVA\n",
+ "print \"(ii) KVA rating = %0.1f KVA\" %(KVA_Rating)\n",
+ "#(iii)\n",
+ "BC=KVA_Rating #in KW\n",
+ "cosfi_m=BM/BC #unitless\n",
+ "print \"(iii) P.F. Of the motor = %0.2f \"%cosfi_m \n",
+ "#Note : Answer of (i) part is wrong in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Leading KVAR supplied by the motor = 14.4 KVAR\n",
+ "(ii) KVA rating = 81.5 KVA\n",
+ "(iii) P.F. Of the motor = 0.98 \n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.16 - page 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "x=80 #in Rs./KVA\n",
+ "x1=100 #in Rs/KVAR(cost of phase advancing equipment)\n",
+ "i=12 #in %\n",
+ "y=(i/100)*150 #in Rs./KVAR\n",
+ "cosfi_2=np.sqrt(1-(y/x)**2) #unitless\n",
+ "print \"Most Ecomnomical PF = %0.2f lag\" %cosfi_2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Most Ecomnomical PF = 0.97 lag\n"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 10.17 - page 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "P=300 #in KW\n",
+ "cosfi_1=0.7 #unitless\n",
+ "tanfi_1=np.tan(np.arccos(cosfi_1)) \n",
+ "y=13 #in Rs./KVAR\n",
+ "x=130 #in Rs./KVA\n",
+ "cosfi_2=np.sqrt(1-(y/x)**2) #unitless\n",
+ "print \"(i) Most Ecomnomical PF = %0.3f\"%cosfi_2\n",
+ "tanfi_2=np.tan(np.arccos(cosfi_2)) \n",
+ "#(ii)\n",
+ "LeadingKVAR=P*(tanfi_1-tanfi_2) #in KVAR\n",
+ "AnnSavingMD=x*(P/cosfi_1-P/cosfi_2) #in Rs.\n",
+ "AnnExpenditure=y*LeadingKVAR #in Rs.\n",
+ "NetSaving=AnnSavingMD-AnnExpenditure #in Rs.\n",
+ "print \"(ii) Net Saving = %0.2f Rs.\" %NetSaving\n",
+ "#Note : Answer in the book is not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Most Ecomnomical PF = 0.995\n",
+ "(ii) Net Saving = 12930.98 Rs.\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/Electrical_Power-i__by_M.L._Anand/Chapter11.ipynb b/Electrical_Power-i__by_M.L._Anand/Chapter11.ipynb
new file mode 100755
index 00000000..71d12924
--- /dev/null
+++ b/Electrical_Power-i__by_M.L._Anand/Chapter11.ipynb
@@ -0,0 +1,459 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter11 - Various types of tariffs"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 11.1 - page 290"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "E=438000 #in kWh(Energy consumed per year)\n",
+ "pf=0.8 #unitless\n",
+ "cosfi=pf #unitless\n",
+ "LoadFactor=40 #in %\n",
+ "#tarrif=Rs. 75/year/kw of max demand plus 3 paise per unit per reactive KVA\n",
+ "h=8760 #no. of years in a year\n",
+ "AvgLoad=E/h #kw\n",
+ "MaxLoad=AvgLoad/(LoadFactor/100) #in kw\n",
+ "MaxLoad_KVA=MaxLoad/pf #in KVA\n",
+ "tanfi=np.tan(np.arccos(cosfi)) #unitless\n",
+ "ReactiveKVAR=h*tanfi*AvgLoad #in KVA\n",
+ "AnnualBill=75*MaxLoad+(3/100)*E+(1.5/100)*ReactiveKVAR #in Rs.\n",
+ "CostPerUnit=AnnualBill/E #in Rs.\n",
+ "CostPerUnit=CostPerUnit*100 #in Paisa\n",
+ "print \"Cost per unit = %0.3f Paisa\" %CostPerUnit"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Cost per unit = 6.265 Paisa\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 11.2 - page 291"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "#tarrif=Rs. 275/year/KVA of max demand plus 35 paise per unit\n",
+ "C1=275 #in Rs.year/KVA\n",
+ "C2=35 #in paisa/unit\n",
+ "LoadFactor=30 #in %/year\n",
+ "LoadFactor=30/100 #in fraction\n",
+ "#Let MaxDemand = x KW\n",
+ "#Case (i) PF=1\n",
+ "cosfi=1 #unitless\n",
+ "AnnualBillBYx=C1/cosfi+(C2/100)*LoadFactor*24*365 #in Rs.(Here 24*365 is for No. of hours in a year)\n",
+ "AnnualBill=AnnualBillBYx*100/(LoadFactor*24*365) #in paisa/unit\n",
+ "print \"Cost per unit(at unity power factor) = %0.2f paisa\" %AnnualBill\n",
+ "#Case (i) PF=0.8\n",
+ "cosfi=0.8 #unitless\n",
+ "AnnualBillBYx=C1/cosfi+(C2/100)*LoadFactor*24*365 #in Rs.(Here 24*365 is for No. of hours in a year)\n",
+ "AnnualBill=AnnualBillBYx*100/(LoadFactor*24*365) #in paisa/unit\n",
+ "print \"Cost per unit(at 0.8 power factor) = %0.2f paisa\" %AnnualBill"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Cost per unit(at unity power factor) = 45.46 paisa\n",
+ "Cost per unit(at 0.8 power factor) = 48.08 paisa\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 11.3 - page 292"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "FixedLoad=200 #in kW\n",
+ "PF=0.8 #unitless\n",
+ "cosfi=PF #unitless\n",
+ "h=10 #in hours/day\n",
+ "d=300 #in days\n",
+ "Time=h*d #in hours\n",
+ "Energy=FixedLoad*Time #in kwh/year\n",
+ "# (i) tarrif=Rs. 100/KVA/Annum plus 20 paise per kwh\n",
+ "C1=100 #in Rs.year/KVA\n",
+ "C2=20 #in paisa/kwh\n",
+ "KVA=FixedLoad/cosfi #in KVA\n",
+ "AnnualBill=KVA*C1+(C2/100)*Energy #in Rs.\n",
+ "print \" Case (i) Annual Payment = %0.f Rs.\" %AnnualBill\n",
+ "# (ii) tarrif=Rs. 100/KW/Annum plus 20 paise per kwh plus 2 paise/KVARH\n",
+ "C1=100 #in Rs./year/KW\n",
+ "C2=20 #in paisa/kwh\n",
+ "C3=2 #in paisa/KVARH\n",
+ "tanfi=np.tan(np.arccos(cosfi)) #unitless\n",
+ "ReactiveKVARH=FixedLoad*tanfi*Time #in KVARH\n",
+ "AnnualBill=C1*FixedLoad+(C2/100)*Energy+(C3/100)*ReactiveKVARH #in Rs.\n",
+ "print \" Case (ii) Annual Payment = %0.f Rs.\" %AnnualBill"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Case (i) Annual Payment = 145000 Rs.\n",
+ " Case (ii) Annual Payment = 149000 Rs.\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 11.4 - page 293"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "Energy=180000 #in kwh\n",
+ "LoadFactor=45 #in %/year\n",
+ "LoadFactor=45/100 #in fraction\n",
+ "#Charges=Rs. 50/KW/Annum plus 8 paise per unit\n",
+ "C1=50 #in Rs.year/KW\n",
+ "C2=8 #in paisa/unit\n",
+ "h=365*24 #no. of hours per year\n",
+ "AvgLoad=Energy/h #in KW\n",
+ "MaxLoad=AvgLoad/LoadFactor #in KW\n",
+ "FixCharges=MaxLoad*C1 #in Rs.\n",
+ "PlusCharges=(C2/100)*Energy #in rs.\n",
+ "TotalTarrif=FixCharges+PlusCharges #in Rs.\n",
+ "print \"Total Annual electricity charges = %0.2f Rs.\" %TotalTarrif"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total Annual electricity charges = 16683.11 Rs.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 11.5 - page 293"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "Energy=25*10**6 #in kwh\n",
+ "MaxDemand=1600 #in KW\n",
+ "#(i) Rs. 70/KW max demand plus 2 paise per kwh\n",
+ "C1=70 #in Rs.year/KW\n",
+ "C2=2 #in paisa/unit\n",
+ "AnnualCost=MaxDemand*C1+(C2/100)*Energy #in Rs.\n",
+ "print \"Case (i) Annual cost of energy = %0.f Rs.\" %AnnualCost\n",
+ "#(ii) Annual cost at a flat rate of 5p/kwh\n",
+ "C=5 #in paisa/kwh\n",
+ "AnnualCost=(C/100)*Energy #in Rs.\n",
+ "print \"Case (ii) Annual cost of energy = %0.f Rs.\" %AnnualCost"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Case (i) Annual cost of energy = 612000 Rs.\n",
+ "Case (ii) Annual cost of energy = 1250000 Rs.\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 11.6 - page 293"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "MaxDemand=20 #in KW\n",
+ "#(i) Rs. 180/KW/annum max demand plus 15 paise per unit\n",
+ "#(ii) Flat rate tarrif 40 paise/unit\n",
+ "C1=180 #in Rs.year/KW\n",
+ "C2=15 #in paisa/unit\n",
+ "#AnnualBill1=C1*MaxDemand+(C2/100)*x x is the energy consumed\n",
+ "C=40 #in paisa/unit\n",
+ "#AnnualBill2=(C/100)*x x is the energy consumed\n",
+ "#Puting two bills equal gives :\n",
+ "x=C1*MaxDemand/((C/100)-(C2/100)) #in kwh\n",
+ "print \"No. of units to be consumed is %d or %d kwh\" %(x,x)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No. of units to be consumed is 14400 or 14400 kwh\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 11.7 - page 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "MaxDemand=500 #in KW\n",
+ "LoadFactor=70 #in %/year\n",
+ "LoadFactor=70/100 #in fraction\n",
+ "cosfi=0.8 #unitless\n",
+ "#(i) Rs. 80/KVA of max demand\n",
+ "#(ii) Running chargeare 5 paise/kwh\n",
+ "C1=80 #in Rs./KVA\n",
+ "C2=5 #in paisa/kwh\n",
+ "AvgLoad=MaxDemand*LoadFactor #in KW\n",
+ "h=365*24 #no. of hours per year\n",
+ "Energy=AvgLoad*h #in kwh\n",
+ "MaxDemandKVA=MaxDemand/cosfi #in KVA\n",
+ "AnnualBill=MaxDemandKVA*C1+(C2/100)*Energy #in RS\n",
+ "print \"Annual bill of consumer = %0.f Rs.\" %AnnualBill"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Annual bill of consumer = 203300 Rs.\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 11.8 - page 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "MD=100 #in KW\n",
+ "LF=60 #in %/year\n",
+ "LF=60/100 #in fraction\n",
+ "#Tarrif Rs. 100/KW of max demand and Rs. 1/kwh\n",
+ "C1=100 #in Rs./KW\n",
+ "C2=1 #in Rs./kwh\n",
+ "h=365*24*12 #no. of hours\n",
+ "UnitsConsumed=MD*LF*h #in kwh/year\n",
+ "AnnualCharges=C1*MD+C2*UnitsConsumed #in RS\n",
+ "print \"Overall Annual chrges = %0.f Rs.\" %AnnualCharges"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Overall Annual chrges = 6317200 Rs.\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 11.9 - page 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "MD=250 #in KW\n",
+ "PF=0.8 #power factor\n",
+ "cosfi=PF #unitless\n",
+ "Energy=50000 #in units/annum\n",
+ "#Tarrif Rs. 50/KVA of max demand and 0.25paisa/unit\n",
+ "C1=50 #in Rs./KW\n",
+ "C2=0.25 #in Paise/kwh\n",
+ "MDKVA=MD/cosfi #in KVA\n",
+ "AnnualBill1=C1*MDKVA+C2*Energy #in RS\n",
+ "print \"Annuall bill of industry = %0.f Rs.\" %AnnualBill1\n",
+ "#Note : If consumer raised the PF to unity.\n",
+ "PF=1 #power factor\n",
+ "cosfi=PF #unitless\n",
+ "MDKVA=MD/cosfi #in KVA\n",
+ "AnnualBill2=C1*MDKVA+C2*Energy #in RS\n",
+ "print \"Saving by consumer in the bill = %0.f Rs.\"%(AnnualBill1-AnnualBill2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Annuall bill of industry = 28125 Rs.\n",
+ "Saving by consumer in the bill = 3125 Rs.\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 11.10 - page 295"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "#Given Data :\n",
+ "MD=10 #in KW\n",
+ "Energy=50000 #in kwh/year(Annual consumption)\n",
+ "#(i) Rs. 100/KW/year max demand plus Rs. 0.20 paise per unit\n",
+ "#(ii) Simple tarrif 0.30 Rs./unit\n",
+ "C1=100 #in Rs.year/KW\n",
+ "C2=0.20 #in Rs. /unit\n",
+ "#Case (i)\n",
+ "AnnualBill1=C1*MD+C2*Energy #in Rs.\n",
+ "print \"Case(i) Annual Bill of tarrif 1 = %0.f Rs.\" %AnnualBill1\n",
+ "C=0.30 #in Rs. /unit\n",
+ "AnnualBill2=C*Energy #in Rs.\n",
+ "print \"Case(ii) Annual Bill of tarrif 2 = %0.f Rs.\" %AnnualBill2\n",
+ "print \"He must choose the first tarrif.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Case(i) Annual Bill of tarrif 1 = 11000 Rs.\n",
+ "Case(ii) Annual Bill of tarrif 2 = 15000 Rs.\n",
+ "He must choose the first tarrif.\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/Electrical_Power-i__by_M.L._Anand/Chapter2.ipynb b/Electrical_Power-i__by_M.L._Anand/Chapter2.ipynb
new file mode 100755
index 00000000..4d0e3eeb
--- /dev/null
+++ b/Electrical_Power-i__by_M.L._Anand/Chapter2.ipynb
@@ -0,0 +1,626 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter 2, Layout of transmission systems"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.1 : page 32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import symbols\n",
+ "from __future__ import division\n",
+ "a=symbols('a')\n",
+ "#Given Data :\n",
+ "CableCost=20+400*a #in Rs./meter (a=cross section in cm**2)\n",
+ "Cable_cost=(20+400*a)*1000 #in Rs./km\n",
+ "l=1 #in Km\n",
+ "P=1 #in MW\n",
+ "V=11 #in KV\n",
+ "cosfi=0.8 #powerfactor\n",
+ "h=3000 #hours\n",
+ "i=10 #in %\n",
+ "E_cost=15 #in paisa/kwh\n",
+ "rho=1.75*10**-6 #sp. resistance in ohm-cm\n",
+ "C1=CableCost*1000 #in Rs./km\n",
+ "R=rho*l*10**3/(a*10**-2) #in ohm\n",
+ "Ifl=(P*10**6)/(V*10**3*cosfi) #in Ampere\n",
+ "Ploss=2*Ifl**2*R #in Watts\n",
+ "Annual_cost=Ploss*10**-3*h*E_cost/100 #in Rs.\n",
+ "AnnualCost2=400*10**3*a*i/100 #in Rs.\n",
+ "annually_energy_lost = 40000/a # Rs.\n",
+ "#comparing Annual_cost = AnnualCost2\n",
+ "a=Annual_cost/AnnualCost2*a**2\n",
+ "print \"Most economical cross section area, a = \",round(a,4), \"cm2 \""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Most economical cross section area, a = 0.0508 cm2 \n"
+ ]
+ }
+ ],
+ "prompt_number": 245
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.2 : page 33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt\n",
+ "#Given Data :\n",
+ "Pt=30*10**6 #in watt\n",
+ "V=220*10**3 #in volt\n",
+ "l=275*10**3 #in meter\n",
+ "R=0.173 #in ohm/km\n",
+ "Eta=90 #in %\n",
+ "density=8.9 #copper density\n",
+ "Loss=100-Eta #in %\n",
+ "cosfi=0.8 #powerfactor\n",
+ "print \"3-phase 3 wire :\"\n",
+ "IL=Pt/(sqrt(3)*V*cosfi) #in Ampere\n",
+ "LineLosses=(Loss/100)*Pt #in watts\n",
+ "rho=R*10**-4/(1*10**3) #in ohm-meter\n",
+ "a=3*IL**2*rho*l/(LineLosses) #in m**2\n",
+ "Volume=3*a*l #in m**3\n",
+ "Cu_weight=Volume*density #in Tones\n",
+ "print \"Weight of copper = %0.f Tones\" %Cu_weight\n",
+ "print \"Single phase 2 wire :\"\n",
+ "IL=Pt/(V*cosfi) #in Ampere\n",
+ "a=2*IL**2*rho*l/(LineLosses) #in m**2\n",
+ "Volume=2*a*l #in m**3\n",
+ "Cu_weight=Volume*density #in Tones\n",
+ "print \"Weight of copper = %0.1f Tones\" %Cu_weight\n",
+ "#Note : answer is not accurate in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3-phase 3 wire :\n",
+ "Weight of copper = 338 Tones\n",
+ "Single phase 2 wire :\n",
+ "Weight of copper = 451.1 Tones\n"
+ ]
+ }
+ ],
+ "prompt_number": 246
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.3 : page 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import symbols\n",
+ "from __future__ import division\n",
+ "from math import sqrt\n",
+ "a=symbols('a')\n",
+ "#Given Data :\n",
+ "l=1 #in Km\n",
+ "l=l*10**5 #in cm\n",
+ "I=200 #in Ampere\n",
+ "CableCost=50*a #in Rs./meter (a=cross section in cm**2)\n",
+ "E_cost=5 #in paisa/kwh\n",
+ "i=10 #in %\n",
+ "rho=1.72*10**-6 #resistivity in ohm-cm\n",
+ "R=rho*l/a #in ohm\n",
+ "Eloss=2*I**2*R*24*365/1000 #in kwh\n",
+ "AnnualCost2=(E_cost/100)*2*I**2*rho*l*24*365/1000/a #in Rs.\n",
+ "C1=CableCost*1000 #in Rs./km\n",
+ "AnnualCharges=C1*i/100 #in Rs.\n",
+ "a=sqrt(AnnualCost2/AnnualCharges*a**2) # cm2\n",
+ "print \"Most economical cross section area a = %0.3f cm2\" %a"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Most economical cross section area a = 1.098 cm2\n"
+ ]
+ }
+ ],
+ "prompt_number": 247
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.4 : page 36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import symbols\n",
+ "from __future__ import division\n",
+ "from math import sqrt\n",
+ "a=symbols('a')\n",
+ "#Given Data : \n",
+ "l=4*10**5 #in cm\n",
+ "VL=30 #in KV\n",
+ "LineCost=40000*a+7500 #in Rs/km\n",
+ "i=8 #in %\n",
+ "E_cost=4 #in paisa/kwh\n",
+ "rho=1.72*10**-6 #in ohm-cm\n",
+ "R=rho*l/a #in ohm\n",
+ "P1=3*10**6 #in watt\n",
+ "h1=10 #in hours\n",
+ "cosfi1=0.8#unitless\n",
+ "I1=P1/(sqrt(3)*VL*10**3*cosfi1) #in Ampere\n",
+ "P2=1.5*10**6 #in watt\n",
+ "h2=6 #in hours\n",
+ "cosfi2=0.9#unitless\n",
+ "I2=P2/(sqrt(3)*VL*10**3*cosfi2) #in Ampere\\\n",
+ "P3=0.5*10**6 #in watt\n",
+ "h3=8 #in hours\n",
+ "cosfi3=0.9 #unitless\n",
+ "I3=P3/(sqrt(3)*VL*10**3*cosfi3) #in Ampere\n",
+ "Etot=3*(I1**2*h1+I2**2*h2+I3**2*h3)*R*365/1000 #in kwh\n",
+ "Ccost_line=40000*a*4 #in Rs.\n",
+ "AnnualCharges=Ccost_line*i/100 #in Rs.\n",
+ "AnnualCost2=(E_cost/100)*Etot #in Rs.\n",
+ "a=sqrt(AnnualCost2/AnnualCharges*a**2) # cm2\n",
+ "print \"Most economical cross section area a = %0.2f cm2\" %a"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Most economical cross section area a = 0.37 cm2\n"
+ ]
+ }
+ ],
+ "prompt_number": 248
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.5 : page 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import symbols\n",
+ "from __future__ import division\n",
+ "from math import sqrt\n",
+ "a, l=symbols('a l')\n",
+ "#Given Data :\n",
+ "P=5*10**6 #in watt\n",
+ "VL=33*10**3 #in volt\n",
+ "cosfi=0.8#unitless\n",
+ "LineCost=31250*a+4000 #in Rs/km\n",
+ "rho=10**-6 #in ohm-cm\n",
+ "i=8 #in %\n",
+ "E_cost=4 #in paisa/kwh\n",
+ "IL=P/(sqrt(3)*VL*cosfi) #in Ampere\n",
+ "Line_length=l*10**5 #in cm\n",
+ "R=rho*l*10**5/a #in ohm\n",
+ "E_lost=3*IL**2*R*365/1000 #in kwh\n",
+ "Ccost_line=31250*a*l #in Rs.\n",
+ "AnnualCharges=Ccost_line*i/100 #in Rs.\n",
+ "a=sqrt(E_lost/AnnualCharges*a**2)\n",
+ "print \"Most economical cross section area a = %0.2f cm2\" %a"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Most economical cross section area a = 0.72 cm2\n"
+ ]
+ }
+ ],
+ "prompt_number": 249
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.6 : page 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given Data :\n",
+ "P=50*10**6 #in watt\n",
+ "VL=220*10**3 #in volt\n",
+ "cosfi=0.8#unitless\n",
+ "Eta=90 #in %\n",
+ "l=200*10**3 #in meter\n",
+ "rho=1.75*10**-8 #in ohm-cm\n",
+ "W=P*(100-Eta)/100 #in Wats(Line losses)\n",
+ "#Part (i) : 3 phase 3 wire with Cu condutor\n",
+ "gravity=8.9 #specific gravity\n",
+ "IL=P/(sqrt(3)*VL*cosfi) #in Ampere\n",
+ "a=3*IL**2*rho*l/W #in m**2\n",
+ "Vol3=3*a*l #volume of 3 lines(in m**3)\n",
+ "CuWeight=Vol3*gravity #in Tones\n",
+ "print \"Weight of copper = %0.2f Tones\" %CuWeight \n",
+ "#Part (ii) : When Al conductor is used.\n",
+ "gravity=2.7 #specific gravity\n",
+ "rho=3*10**-8 #in ohm-meter\n",
+ "a=3*IL**2*rho*(l/W) #in m**2\n",
+ "Vol=3*a*l #volume of 3 lines(in m**3)\n",
+ "AlWeight=Vol*gravity #in Tones\n",
+ "print \"Weight of Alluminium = %0.3f Tones\" %AlWeight "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Weight of copper = 301.69 Tones\n",
+ "Weight of Alluminium = 156.896 Tones\n"
+ ]
+ }
+ ],
+ "prompt_number": 250
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.7 : page 39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import symbols\n",
+ "from __future__ import division\n",
+ "from math import sqrt\n",
+ "P2, V, cosfi, R = symbols('P2 V cosfi R')\n",
+ "#Given Data :\n",
+ "Vcon=V #in volt\n",
+ "pf=cosfi #unitless\n",
+ "Rcon=R #in ohm\n",
+ "P1=15*10**6 #in watt\n",
+ "I1=P1/(V*cosfi) #in Ampere\n",
+ "W1=2*I1**2*Rcon #in Wats(Line losses)\n",
+ "Lloss_percent=W1/P1*100 #in % eqn(1)\n",
+ "\n",
+ "I2=P2/(V*cosfi*sqrt(3)) #in Ampere\n",
+ "W2=3*I2**2*Rcon #in Wats(Line losses)\n",
+ "Lloss_percent=W2/P2*100 #in % eqn(2)\n",
+ "# Equating eqn(1) & eqn(2)\n",
+ "P2=W1/P1*100/W2/100*P2**2 # W\n",
+ "P2/=10**6 # MW\n",
+ "print \"3 phase load = %0.f MW \" %P2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3 phase load = 30 MW \n"
+ ]
+ }
+ ],
+ "prompt_number": 251
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.8 : page 40"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given Data :\n",
+ "from sympy import symbols\n",
+ "P, V, rho, l, a = symbols('P V rho l a')\n",
+ "I=P/V #in Ampere\n",
+ "R=rho*l/a\n",
+ "a=2*I**2*2*rho*l/W\n",
+ "K=a*V**2\n",
+ "#(i) When V=220 volts\n",
+ "V1=220 #in volts\n",
+ "vol1=K/V1**2\n",
+ "#(ii) When V=500 volts\n",
+ "V2=500 #in volts\\\n",
+ "vol2=K/V2**2\n",
+ "saving=(vol1-vol2)/vol1*100 # in % \n",
+ "print \"Saving in copper =\",round(saving,2),\"%\"\n",
+ "# Answer not accurate in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Saving in copper = 80.64 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 252
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.9 : page 41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given Data :\n",
+ "P=30*10**6 #in watts\n",
+ "V=220*10**3 #in Volt\n",
+ "l=250*10**3 #in meter\n",
+ "Eta=85 #in %\n",
+ "rho=3*10**-8 #in ohm-meter\n",
+ "cosfi=0.8 #power factor\n",
+ "W=P*(100-Eta)/100 #in watts\n",
+ "I=P/(sqrt(3)*V*cosfi) #in Ampere\n",
+ "a=3*I**2*rho*l/W #in m**2\n",
+ "Volume=3*a*l #in m**3\n",
+ "print \"Volume of the conductor material = %0.1f m3\" %Volume\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Volume of the conductor material = 36.3 m3\n"
+ ]
+ }
+ ],
+ "prompt_number": 253
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.10 : page 42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given Data :\n",
+ "P=20*10**6 #in VA\n",
+ "cosfi=0.75 #power factor\n",
+ "P=20*10**6*cosfi #in watts\n",
+ "V=33*10**3 #in Volt\n",
+ "l=20*10**3 #in meter\n",
+ "Eta=85 #in %\n",
+ "rho=3*10**-8 #in ohm-meter\n",
+ "W=P*(100-Eta)/100 #in watts\n",
+ "#For single phase system :\n",
+ "I=P/(V*cosfi) #in Ampere\n",
+ "a1=2*I**2*rho*l/W #in m**2\n",
+ "V1=2*a1*l #in m**3\n",
+ "print \"For single phase system :\\nVolume of the conductor material = %0.3f m3\" %(V1)\n",
+ "#For 3 phase 3 wire system :\n",
+ "I=P/(sqrt(3)*V*cosfi) #in Ampere\n",
+ "a2=3*I**2*rho*l/W #in m**2\n",
+ "V2=3*a2*l #in m**3\n",
+ "print \"For three phase 3-wire system :\\nVolume of the conductor material = %0.2f m3\" %V2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For single phase system :\n",
+ "Volume of the conductor material = 7.836 m3\n",
+ "For three phase 3-wire system :\n",
+ "Volume of the conductor material = 5.88 m3\n"
+ ]
+ }
+ ],
+ "prompt_number": 254
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.11 : page 43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import symbols\n",
+ "from __future__ import division\n",
+ "from math import sqrt\n",
+ "a=symbols('a')#Given Data :\n",
+ "l=1*10**3 #in meter\n",
+ "rho=1.85*10**-6 #in ohm-cm\n",
+ "R=rho*l*100/a #in ohm\n",
+ "IL=300 #in Ampere\n",
+ "Rate=10 #in Rs/kwh\n",
+ "Eloss=2*IL**2*R*365*24/1000 #in kwh\n",
+ "CableCost=100*a #in Rs/meter : a=cross sectional area(in cm**2)\n",
+ "i=10 #in %\n",
+ "AnnualCost=Eloss/Rate #in Rs\n",
+ "Ccost=100*a*l #in Rs\n",
+ "Ccost=Ccost*i/100 # with effet of depreciation\n",
+ "#a=sqrt(29170.8/10000)\n",
+ "a=sqrt(AnnualCost/Ccost*a**2) # cm2\n",
+ "print \"Most economical cross section = %0.3f cm2\" %a"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Most economical cross section = 1.708 cm2\n"
+ ]
+ }
+ ],
+ "prompt_number": 255
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.12 : page 44 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import symbols\n",
+ "pf, Vcon, Rcon = symbols('cosfi V R')\n",
+ "#Given Data :\n",
+ "#Part (i) : single phase system\n",
+ "P1=5*10**6 #in watt\n",
+ "I1=P1/(Vcon*pf) #in Ampere\n",
+ "W1=2*I1**2*Rcon #in Watts(Line losses)\n",
+ "Lloss_percent=W1/P1*100 #in % eqn(1)\n",
+ "#Part (ii) : 3 phase 3 wire system\n",
+ "P2 = symbols('P2') # MW\n",
+ "I2=P2/(Vcon*pf*sqrt(3)) #in Ampere\n",
+ "W2=3*I2**2*Rcon #in Watts(Line losses)\n",
+ "Lloss_percent=W2/P2*100 #in % eqn(2)\n",
+ "# Equating two eqn\n",
+ "P2=(W1/P1*100)/(W2*100)*P2**2\n",
+ "P2/=10**6 # MW\n",
+ "print \"3 phase load = %0.f MW \" %P2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3 phase load = 10 MW \n"
+ ]
+ }
+ ],
+ "prompt_number": 256
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 2.13 : page 45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#Given Data :\n",
+ "from sympy import symbols\n",
+ "P, V, rho, l, a = symbols('P V rho l a')\n",
+ "I=P/V #in Ampere\n",
+ "R=rho*l/a\n",
+ "a=2*I**2*2*rho*l/W\n",
+ "K=a*V**2\n",
+ "#(i) When V=200 volts\n",
+ "V1=200 #in volts\n",
+ "vol1=K/V1**2\n",
+ "#(ii) When V=600 volts\n",
+ "V2=600 #in volts\\\n",
+ "vol2=K/V2**2\n",
+ "saving=(vol1-vol2)/vol1*100 # in % \n",
+ "print \"Saving in copper =\",math.floor(saving),\"%\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Saving in copper = 88.0 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 257
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/Electrical_Power-i__by_M.L._Anand/Chapter3.ipynb b/Electrical_Power-i__by_M.L._Anand/Chapter3.ipynb
new file mode 100755
index 00000000..3d8b23b2
--- /dev/null
+++ b/Electrical_Power-i__by_M.L._Anand/Chapter3.ipynb
@@ -0,0 +1,501 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3, Constructional Mechanical Features of line"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.1 : page 70"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given Data :\n",
+ "m=1/10 #unitless\n",
+ "EL=66 #in KV\n",
+ "E=EL/sqrt(3) #in KV\n",
+ "#Formula : E=E1+(11/10)*E1+(131/100)*E1+(1651/1000)*E1=(5061/1000)*E1\n",
+ "E1=E*(1000/5061) #in KV\n",
+ "print \"E1 = %0.2f KV\" %E1 \n",
+ "E2=E1*(11/10) #in KV\n",
+ "print \"E2 = %0.3f KV\" %E2\n",
+ "E3=E1*(131/100) #in KV\n",
+ "print \"E3 = %0.2f KV\" %E3\n",
+ "E4=E1*(1651/1000) #in KV\n",
+ "print \"E4 = %0.2f KV\" %E4\n",
+ "Eta=(E/(4*E4))*100 #in %\n",
+ "print \"String Efficiency = %0.1f %%\" %Eta"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "E1 = 7.53 KV\n",
+ "E2 = 8.282 KV\n",
+ "E3 = 9.86 KV\n",
+ "E4 = 12.43 KV\n",
+ "String Efficiency = 76.6 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.2 : page 71"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given Data :\n",
+ "W=0.85 #in Kg/meter\n",
+ "L=250 #in meter\n",
+ "Ww=1.4 #in Kg\n",
+ "SafetyFactor=5 #unitless\n",
+ "UTS=10128 #Ultimate tensile strength in Kg\n",
+ "T=UTS/SafetyFactor #in Kg\n",
+ "Wi=0 #there is no ice\n",
+ "Wr=sqrt((W+Wi)**2+Ww**2) #in Kg\n",
+ "S=Wr*L**2/(8*T) #in meter\n",
+ "Sv=(W/Wr)*S #in meter\n",
+ "print \"Horizontal sag = %0.3f m\" %S\n",
+ "print \"Vertical sag = %0.3f m\" %Sv "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Horizontal sag = 6.317 m\n",
+ "Vertical sag = 3.278 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.3 : page 72"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given Data :\n",
+ "L=150 #in meter\n",
+ "A=2 #in cm**2(cross sectional area)\n",
+ "US=5000 #in Kg/cm**2(ultimate strength)\n",
+ "g=8.9 #specific gravity\n",
+ "Ww=1.5 #in Kg/m(wind pressure)\n",
+ "SafetyFactor=5 #unitless\n",
+ "B_strength=2*US #in Kg\n",
+ "T=B_strength/SafetyFactor #in Kg\n",
+ "Volume=A*100 #in cm**2\n",
+ "Wc=1.78 #in Kg/m\n",
+ "Wr=sqrt(Wc**2+Ww**2) #in Kg\n",
+ "Sag=Wr*L**2/(8*T) #in meter\n",
+ "print \"Sag = %0.2f m\" % Sag "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sag = 3.27 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.4 : page 73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi\n",
+ "#Given Data :\n",
+ "L=160 #in meter\n",
+ "d=0.95 #in cm\n",
+ "A=pi*d**2/4 #in cm**2(cross sectional area)\n",
+ "US=4250 #in Kg/cm**2(ultimate strength)\n",
+ "g=8.9 #specific gravity\n",
+ "Ww=1.5 #in Kg/m(wind pressure)\n",
+ "SafetyFactor=5 #unitless\n",
+ "B_strength=2*US #in Kg\n",
+ "T=B_strength/SafetyFactor #in Kg\n",
+ "Volume=A*100 #in cm**2\n",
+ "Wc=1.78 #in Kg/m\n",
+ "Wr=sqrt(Wc**2+Ww**2) #in Kg\n",
+ "Sag=Wr*L**2/(8*T) #in meter\n",
+ "print \"Sag = %.f m\" % Sag \n",
+ "#Note : Answer in the book is not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sag = 4 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.5 : page 73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given Data :\n",
+ "m=75-45 #in meter\n",
+ "L=300 #in meter\n",
+ "T=2500 #in Kg\n",
+ "w=0.9 #in kg/meter\n",
+ "x=L/2-T*m/(w*L) #in meters\n",
+ "print \"x = %0.2f m\" %x\n",
+ "x=L/2-x #in meter\n",
+ "print \"Centre point P from O is %0.2f m\" %(x) \n",
+ "y=w*x**2/(2*T) #in meter\n",
+ "print \"Height of point P, y= %0.2f m\" %y\n",
+ "x=L/2-T*m/(w*L) #in meters\n",
+ "z=w*(L-x)**2/(2*T) #in meters\n",
+ "print \"Height of B above O is, z = %0.2f m\" %z \n",
+ "print \"The mid point of the line is \",(z-y),\" meter below point B, i.e., \",(75-(z-y)),\" meter above water level.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x = -127.78 m\n",
+ "Centre point P from O is 277.78 m\n",
+ "Height of point P, y= 13.89 m\n",
+ "Height of B above O is, z = 32.94 m\n",
+ "The mid point of the line is 19.05 meter below point B, i.e., 55.95 meter above water level.\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.6 : page 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given Data :\n",
+ "L=60 #in meter\n",
+ "S=25*10**-2 #in meter\n",
+ "A=61.36 #in mm**2(cross sectional area)\n",
+ "W=0.5445 #in Kg/m\n",
+ "UTS=42.20 #in Kg/mm**2\n",
+ "T=W*L**2/(8*S) #in Kg\n",
+ "B_strength=UTS*A #in Kg\n",
+ "SafetyFactor=B_strength/T #unitless\n",
+ "print \"Factor of safety =\", round(SafetyFactor,2) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Factor of safety = 2.64\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.7 : page 75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given Data :\n",
+ "L=220 #in meter\n",
+ "W=0.604 #in Kg/m\n",
+ "T_strength=5758 #in Kg\n",
+ "SafetyFactor=2 #unitless\n",
+ "T=T_strength/SafetyFactor #in Kg\n",
+ "S=W*L**2/(8*T) #in meter\n",
+ "print \"Sag = %0.2f m \" %S "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sag = 1.27 m \n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.8 : page 75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given Data :\n",
+ "W=850/1000 #in Kg/m\n",
+ "US=7950 #in kg\n",
+ "L=275 #in meter\n",
+ "h=8 #in meter(ground clearance)\n",
+ "SafetyFactor=2 #unitless\n",
+ "T=US/SafetyFactor #in Kg\n",
+ "S=W*L**2/(8*T) #in meter\n",
+ "H=h+S #in meter\n",
+ "print \"Height above the ground = %0.2f m \" %H"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Height above the ground = 10.02 m \n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.9 : page 76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import floor\n",
+ "#Given Data :\n",
+ "m=1/9 #unitless\n",
+ "EL=33 #in K\n",
+ "EbyE1=1+(1+m)+(1+3*m+m**2) #assumed\n",
+ "E=EL/sqrt(3) #in KV\n",
+ "E1=E/EbyE1 #in KV\n",
+ "print \"E1 = %0.2f kV\" %E1\n",
+ "E2=(1+m)*E1 #in KV\n",
+ "print \"E2 = %0.2f kV\" %E2 \n",
+ "E3=(1+3*m+m**2)*E1 #in KV\n",
+ "print \"E3 = %0.2f kV\" %E3 \n",
+ "E=E1+E2+E3 #in KV\n",
+ "Eff=E/(3*E3) \n",
+ "Eff*=100 # %\n",
+ "print \"String Efficiency = %.f %%\" %floor(Eff)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "E1 = 5.51 kV\n",
+ "E2 = 6.12 kV\n",
+ "E3 = 7.42 kV\n",
+ "String Efficiency = 85 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.10 : page 77"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given Data :\n",
+ "#Applying KCL we get I1+i1=I2+ix and I2+i2=I3+iy\n",
+ "#On solving we get : 1*2*E1=1*1*E2+0*1*E3 and 0*2*E1=-1*2*E2+1*3*E3 \n",
+ "E1byE=1/(1+(154/155)+(166/155)) #assumed\n",
+ "E2byE=(154/155)*E1byE #assumed\n",
+ "E3byE=(166/155)*E1byE #assumed\n",
+ "Eff=1/((3*(166/155)*E1byE))\n",
+ "Eff*=100 # %\n",
+ "print \"String Efficiency = %.f %%\" %Eff "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "String Efficiency = 95 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.11 - page : 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given Data :\n",
+ "L=200 #in meter\n",
+ "W=684/1000 #in Kg/m\n",
+ "T=1450 #in Kg\n",
+ "S=W*L**2/(8*T) #in meter\n",
+ "print \"Sag = %0.2f m\" %S"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sag = 2.36 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 3.12 : page 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt\n",
+ "#Given Data :\n",
+ "L=220 #in meter\n",
+ "T=586 #in Kg\n",
+ "Wc=0.62 #in Kg\n",
+ "Ww=39.2*0.94/100 #in Kg\n",
+ "Wr=sqrt(Wc**2+Ww**2) #in Kg\n",
+ "cos_theta=Wc/Wr #unitless\n",
+ "Sv=Wr*L**2*cos_theta/(8*T) #in meter\n",
+ "print \"Vertical Sag = %0.2f m\" %Sv \n",
+ "# Answer is not accurate in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vertical Sag = 6.40 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/Electrical_Power-i__by_M.L._Anand/Chapter4.ipynb b/Electrical_Power-i__by_M.L._Anand/Chapter4.ipynb
new file mode 100755
index 00000000..66eb3e2e
--- /dev/null
+++ b/Electrical_Power-i__by_M.L._Anand/Chapter4.ipynb
@@ -0,0 +1,602 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4, Electrical Features of lines - 1"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.1 : page 104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log, pi\n",
+ "import math\n",
+ "#Given Data :\n",
+ "r=1.213/2 #in cm\n",
+ "f=60 #in Hz\n",
+ "ds=0.77888*r #in cm\n",
+ "spacing=1.25 #in meter\n",
+ "L=4*10**-7*log(spacing*100/ds) #in H/m\n",
+ "L*=1000 # in H/km\n",
+ "print \"Inductance = %0.2e H/km\" %L\n",
+ "XL=2*pi*f*L #in ohm/km\n",
+ "XL*=60 # ohm per 60 km\n",
+ "print \"Inductive reactance for 60 km line = %0.1f ohm\" %XL"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inductance = 2.23e-03 H/km\n",
+ "Inductive reactance for 60 km line = 50.5 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 105
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.2 : page 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import log\n",
+ "#Given Data : \n",
+ "l=20 # km (length of line)\n",
+ "d=2.8*100 #in cm(spacing)\n",
+ "r=0.5*1.5 #in cm\n",
+ "ds=0.77888*r #in cm\n",
+ "L=0.2*log(d/ds) #in H/m/phase\n",
+ "L*=l # mH for 20km line\n",
+ "print \"Inductance per phase for a 20 km line = %0.2f mH\" %L"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inductance per phase for a 20 km line = 24.69 mH\n"
+ ]
+ }
+ ],
+ "prompt_number": 106
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.3 : page 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import log\n",
+ "#Given Data :\n",
+ "a=1.5 #in cm**2\n",
+ "d=8 #in meter(spacing)\n",
+ "r=39.8/2 #in mm\n",
+ "l=1*10**5 #in cm\n",
+ "rho=1.73*10**-6 #in ohm-cm\n",
+ "R=rho*l/a #in ohm/km\n",
+ "print \"Resistance of line = %0.4f ohms/km\" %R\n",
+ "ds=0.77888*r #in cm\n",
+ "L=0.2*log(d/(ds*10**-3)) #in mH/km/phase\n",
+ "print \"Inductance per phase for a 1 km line = %0.3f mH/km\" %L"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance of line = 0.1153 ohms/km\n",
+ "Inductance per phase for a 1 km line = 1.249 mH/km\n"
+ ]
+ }
+ ],
+ "prompt_number": 107
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.4 : page 106"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given Data :\n",
+ "Cs=1/3 #in uF\n",
+ "Cc=(0.6-Cs)/2 #in uF\n",
+ "#Part (a) :\n",
+ "C1=(3/2)*Cc+(1/2)*Cs #in uF(between any two conductor)\n",
+ "print \"Capacitance between any two conductor = %0.3f uF\" %C1\n",
+ "#Part (b) :\n",
+ "C2=2*Cc+2*Cs/3\n",
+ "print \"Capacitance between any shorted conductors = %0.3f uF\" %C2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacitance between any two conductor = 0.367 uF\n",
+ "Capacitance between any shorted conductors = 0.489 uF\n"
+ ]
+ }
+ ],
+ "prompt_number": 108
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.5 : page 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given Data :\n",
+ "d1=3 #in meter\n",
+ "d2=3 #in meter\n",
+ "d3=d1+d2 #in meter\n",
+ "d=378 #in cm\n",
+ "dia=2.5 #in cm\n",
+ "r=dia/2 #in cm\n",
+ "epsilon_o=8.854*10**-12 #constnt\n",
+ "L=(0.5+2*log10(d/r))*10**-7 #in H/m\n",
+ "L*=60*1000*1000 # mH per 60 km\n",
+ "print \"Inductance for 60 km line %0.2f mH\" %L\n",
+ "C=2*pi*epsilon_o/log(d/r) #in F/m\n",
+ "C*=60*10**3*10**6 # uF per 60 km line\n",
+ "print \"Capacitnce for 60 km line = %0.4f uF\" %C\n",
+ "# Answer is not accurate in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inductance for 60 km line 32.77 mH\n",
+ "Capacitnce for 60 km line = 0.5844 uF\n"
+ ]
+ }
+ ],
+ "prompt_number": 109
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.6 : page 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log10\n",
+ "#Given Data : \n",
+ "dinner=6 #in meter\n",
+ "douter=12 #in meter\n",
+ "d=(dinner**2*douter)**(1/3) #in meter\n",
+ "r=2.8 #in meter\n",
+ "ds=0.7788*r #in cm\n",
+ "L=2*log10(d*100/ds) #in mH/phase/km\n",
+ "L*=100 # mH per 100 km\n",
+ "print \"Inductance for 100 km line %0.f mH\" %L"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inductance for 100 km line 508 mH\n"
+ ]
+ }
+ ],
+ "prompt_number": 110
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.7 : page 108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import log\n",
+ "#Given Data :\n",
+ "dia=5 #in mm\n",
+ "d=1.5 #in meter(spacing)\n",
+ "r=dia/2 #in mm\n",
+ "r=r*10**-3 #in meter\n",
+ "epsilon_o=8.854*10**-12 #constnt\n",
+ "C=pi*epsilon_o/log(d/r) #in Farad per meter\n",
+ "C*=50*1000 # F per 50km line\n",
+ "print \"Capacitance for 50 km line = %0.2e F\" %C\n",
+ "#Note : answer is not accurate in the book. "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacitance for 50 km line = 2.17e-07 F\n"
+ ]
+ }
+ ],
+ "prompt_number": 111
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.8 : page 108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import log\n",
+ "#Given Data :\n",
+ "d=300 #in cm(spacing)\n",
+ "r=1 #in cm\n",
+ "#Formula : L=10**-7*[mu_r+4*log10(d/r)] #in H/m\n",
+ "#Part (i) : mu_r=1\n",
+ "mu_r=1 #constant\n",
+ "L=10**-4*(mu_r+4*log(d/r)) #in H/m\n",
+ "L*=1000 # mh per km\n",
+ "print \"Loop inductance per km for copper %0.2f mH\" %L\n",
+ "#Part (ii) : mu_r=100\n",
+ "mu_r=100 #constant\n",
+ "L=10**-4*(mu_r+4*log(d/r)) #in H/m\n",
+ "L*=1000 # mH per km\n",
+ "print \"Loop inductance per km for steel = %0.2f mH\" %L\n",
+ "# Answer not calculated completely and calculation mistake."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Loop inductance per km for copper 2.38 mH\n",
+ "Loop inductance per km for steel = 12.28 mH\n"
+ ]
+ }
+ ],
+ "prompt_number": 112
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.9 : page 109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import log\n",
+ "#Given Data :\n",
+ "d1=100 #in cm(spacing)\n",
+ "d2=100 #in cm(spacing)\n",
+ "d3=100 #in cm\n",
+ "r=1 #in cm\n",
+ "L=10**-7*(0.5+2*log((d1*d2*d3)**(1/3)/r)) #in H/m\n",
+ "L=L*1000*1000 #in mH/km\n",
+ "print \"Inductance per km = %0.2f mH\" %L\n",
+ "#Note : Answer in the book is wrong due to calculation mistake.\n",
+ "#Note : In the last line it should be multiply by 10**6 to convert from H/m to mH/km instead of 10**8."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inductance per km = 0.97 mH\n"
+ ]
+ }
+ ],
+ "prompt_number": 113
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.10 : page 109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log\n",
+ "#Given Data : \n",
+ "d1=2 #in cm\n",
+ "d2=2.5 #in cm\n",
+ "d3=4.5 #in cm\n",
+ "r=1.24/2 #in cm\n",
+ "L=10**-7*(0.5+2*log((d1*d2*d3)**(1/3)/r)) #in H/m\n",
+ "L=L*1000*1000 #in mH/km\n",
+ "print \"Inductance per km per phase = %0.2f mH\" %L\n",
+ "#Note : Answer in the book is wrong(calculation mistake)."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inductance per km per phase = 0.35 mH\n"
+ ]
+ }
+ ],
+ "prompt_number": 114
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.11 : page 110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log\n",
+ "#Given Data :\n",
+ "r=0.75*10 #in mm\n",
+ "d=1.5*10**3 #in mm\n",
+ "ds=0.7788*r #in mm\n",
+ "L=4*10**-7*log(d/ds) #in H/m\n",
+ "L=L*10**6 #in mH/km\n",
+ "print \"Inductance of line = %0.2f mH/km\" %L"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inductance of line = 2.22 mH/km\n"
+ ]
+ }
+ ],
+ "prompt_number": 115
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.12 : page 110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log\n",
+ "#Given Data :\n",
+ "d1=4*100 #in cm\n",
+ "d2=5*100 #in cm\n",
+ "d3=6*100 #in cm\n",
+ "r=1 #in cm\n",
+ "ds=0.7788*r #in cm\n",
+ "L=(0.2*log((d1*d2*d3)**(1/3)/ds)) #in mH\n",
+ "L*=10**3 # uH\n",
+ "print \"Inductance per km = %0.2f uH\" %L\n",
+ "#Note : answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inductance per km = 1290.20 uH\n"
+ ]
+ }
+ ],
+ "prompt_number": 116
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.13 : page 110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log\n",
+ "#Given Data :\n",
+ "d=300 #in cm(spacing)\n",
+ "r=1 #in cm\n",
+ "epsilon_o=8.854*10**-12 #constnt\n",
+ "C=pi*epsilon_o/log(d/r) #in Farad per meter\n",
+ "C*=30*1000*10**6 # uF per 30k km line\n",
+ "print \"Capacitance for 30 km line = %0.2f uF\" %C"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacitance for 30 km line = 0.15 uF\n"
+ ]
+ }
+ ],
+ "prompt_number": 117
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.14 : page 111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log\n",
+ "#Given Data :\n",
+ "d=2.5*100 #in cm(spacing)\n",
+ "r=2/2 #in cm\n",
+ "epsilon_o=8.854*10**-12 #constnt\n",
+ "C=2*pi*epsilon_o/log(d/r) #in Farad per meter\n",
+ "C*=10*1000*10**6 # uF per 10 km line\n",
+ "print \"Capacitance for 10 km line = %0.2f uF\" %C\n",
+ "#Note : answer given in the book is wrong but calculated is right."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacitance for 10 km line = 0.10 uF\n"
+ ]
+ }
+ ],
+ "prompt_number": 119
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 4.15 : page 111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given Data :\n",
+ "VL=33 #in KV\n",
+ "f=50 #in hz\n",
+ "d1=4 #in meter\n",
+ "d2=4 #in meter\n",
+ "d3=8 #in meter\n",
+ "d=(d1*d2*d3)**(1/3) #in meter\n",
+ "epsilon_o=8.854*10**-12 #constnt\n",
+ "d=d*100 #in cm\n",
+ "r=0.62 #in cm\n",
+ "C=2*pi*epsilon_o/log(d/r) #in Farad per meter\n",
+ "C*=50*1000*10**6 # uF per m line\n",
+ "print \"Capacitance for 50 km line %0.3f uF\" %C\n",
+ "Vp=VL/sqrt(3) #in KV\n",
+ "Vp=Vp*10**3 #in volt\n",
+ "Ic=2*pi*f*(C*10**-6)*Vp #in Ampere\n",
+ "print \"The charging current = %0.2f Ampere\" %Ic"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacitance for 50 km line 0.415 uF\n",
+ "The charging current = 2.48 Ampere\n"
+ ]
+ }
+ ],
+ "prompt_number": 120
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/Electrical_Power-i__by_M.L._Anand/Chapter5.ipynb b/Electrical_Power-i__by_M.L._Anand/Chapter5.ipynb
new file mode 100755
index 00000000..aadf45e9
--- /dev/null
+++ b/Electrical_Power-i__by_M.L._Anand/Chapter5.ipynb
@@ -0,0 +1,630 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5, Electrical features of lines-2"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.1 : page 128"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "from __future__ import division\n",
+ "#Given Data :\n",
+ "Load=100 #in MW\n",
+ "V=380 #in KV\n",
+ "d=100 #in km\n",
+ "rho=0.045 #in ohm/cm**2/km\n",
+ "w=0.01 #in kg/cm**3\n",
+ "Eff=90 #in %\n",
+ "IL=Load*10**6/(sqrt(3)*V*10**3) #in Ampere\n",
+ "P_loss=Load*(100-Eff)/100 #in MW\n",
+ "P_loss=P_loss*10**6 #in Watt\n",
+ "P_loss=P_loss/3 #in watt/conductor\n",
+ "R_con=P_loss/IL**2 #in ohm/conductor\n",
+ "#R_con=R_con/d #in ohm/conductor/km\n",
+ "a=rho*d/R_con #in cm**2\n",
+ "vol=a*d #in cm**3\n",
+ "W_cu=vol*w #in Kg\n",
+ "W_cu*=100*10**3*3 # kg per 100 km \n",
+ "print \"Weight of Cu for 3 conductors of 100 km length %0.f Kg\" %W_cu\n",
+ "#Note : answer in the book is not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Weight of Cu for 3 conductors of 100 km length 9349 Kg\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.2 : page 129"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "from __future__ import division\n",
+ "#Given Data : \n",
+ "R=2 #in ohm\n",
+ "X=6 #in ohm\n",
+ "P=10000*10**3 #in watts\n",
+ "cos_fir=0.8 #unitless\n",
+ "VR=22*10**3 #in volt\n",
+ "I=P/(sqrt(3)*VR*cos_fir) #in Ampere\n",
+ "VR_phase=VR/sqrt(3) #in volt\n",
+ "Vs=sqrt((VR_phase*cos_fir+I*R)**2+(VR_phase*sqrt(1-cos_fir**2)+I*X)**2) \n",
+ "print \"Sending end voltage Vs(phase) %0.2f V\" %Vs\n",
+ "R=((Vs-VR_phase)/VR_phase)*100 # %\n",
+ "print \"Regulation = %0.2f %%\" %R\n",
+ "# Ans in the textbook is not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sending end voltage Vs(phase) 14455.83 V\n",
+ "Regulation = 13.81 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.3 : page 129"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "from __future__ import division\n",
+ "#Given Data : \n",
+ "l=10*10**3 #in meter\n",
+ "P_del=4000 #in KVA\n",
+ "cos_fir=0.9 #unitless\n",
+ "VL=11*10**3 #in volt\n",
+ "R=0.2*10 #in ohm/phase/10km\n",
+ "X=0.3*10 #in ohm/phase/10km\n",
+ "I=P_del*10**3/(sqrt(3)*VL) #in Ampere\n",
+ "VR_phase=VL/sqrt(3) #in volt\n",
+ "Vs=sqrt((VR_phase*cos_fir+I*R)**2+(VR_phase*sqrt(1-cos_fir**2)+I*X)**2) # V\n",
+ "Vs*=sqrt(3)/1000 # kV\n",
+ "print \"Sending end voltage Vs(line) %0.4f KV\" %Vs \n",
+ "Reg=((Vs-VL/1000)/VL*1000)*100 # %\n",
+ "print \"Regulation = %0.3f %%\" %Reg \n",
+ "Losses3line=3*I**2*R #in watt\n",
+ "P_rec=P_del*cos_fir #in KW\n",
+ "Pin=P_rec+Losses3line/1000 #in KW\n",
+ "ETA=P_rec/Pin #unitless\n",
+ "ETA*=100 # %\n",
+ "print \"Transmission Efficiency = %0.3f %%\" %ETA\n",
+ "cos_fis=(VR_phase*cos_fir+I*R)/(Vs*1000/sqrt(3)) #unitless\n",
+ "print \"Sending end PF = %0.4f lag\" %cos_fis "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sending end voltage Vs(line) 12.1483 KV\n",
+ "Regulation = 10.439 %\n",
+ "Transmission Efficiency = 93.157 %\n",
+ "Sending end PF = 0.8748 lag\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.4 : page 130"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "from __future__ import division\n",
+ "#Given Data :\n",
+ "l=15*10**3 #in meter\n",
+ "Pt=10000 #in kW\n",
+ "cos_fir=0.8 #unitless\n",
+ "VL=33*10**3 #in volt\n",
+ "R=0.2*15 #in ohm/phase/15km\n",
+ "X=0.4*15 #in ohm/phase/15km\n",
+ "I=Pt*10**3/(sqrt(3)*VL*cos_fir) #in Ampere\n",
+ "VR_phase=VL/sqrt(3) #in volt\n",
+ "Vs=sqrt((VR_phase*cos_fir+I*R)**2+(VR_phase*sqrt(1-cos_fir**2)-I*X)**2) \n",
+ "Vs*=sqrt(3)/1000 # \n",
+ "print \"Sending end voltage Vs(line) = %0.3f KV \" %Vs\n",
+ "Vs=sqrt((VR_phase*cos_fir+I*R)**2+(VR_phase*sqrt(1-cos_fir**2)-I*X)**2) \n",
+ "cos_fis=(VR_phase*cos_fir+I*R)/Vs #unitless\n",
+ "print \"Sending end PF = %0.4f leading \" %cos_fis\n",
+ "Reg=((Vs-VR_phase)/VR_phase)*100 # %\n",
+ "print \"Regulation = %0.3f %%\" %Reg"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sending end voltage Vs(line) = 32.641 KV \n",
+ "Sending end PF = 0.8436 leading \n",
+ "Regulation = -1.087 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.5 : page 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import array, sqrt, roots, poly\n",
+ "import cmath\n",
+ "from sympy import symbols\n",
+ "VR=symbols('VR')\n",
+ "#Given Data :\n",
+ "Vs_line=33*10**3 #in volt\n",
+ "cos_fir=0.8 #unitless\n",
+ "P_KVA=6000 #in KVA\n",
+ "P_KW=P_KVA*cos_fir #in KW\n",
+ "cos_fir=0.8 #unitless\n",
+ "impedence=complex(2,6) #in ohm/phase\n",
+ "R=impedence.real #in ohm\n",
+ "X=impedence.imag #in ohm\n",
+ "Vs_phase=Vs_line/sqrt(3) #in volt\n",
+ "##\n",
+ "I=P_KVA*10**3/sqrt(3)/VR\n",
+ "Vs = VR+I*R*cos_fir+I*X*sin_fir\n",
+ "#polynomial p = [1 -Vs_phase P_KVA*10**3*R*cos_fir/sqrt(3)+P_KVA*10**3*X*sin_fir/sqrt(3)]\n",
+ "sin_fir=sqrt(1-cos_fir**2) \n",
+ "p=poly((1,-Vs_phase,P_KVA*R*cos_fir/sqrt(3)+P_KVA*X*sin_fir/sqrt(3)) )\n",
+ "VR=roots(p) # Calculating roots of the polynomial\n",
+ "VR=VR[1] #(root calculated using -ve sign is discarded in shreedharacharya method)\n",
+ "VR_line=VR*sqrt(3) #in volt\n",
+ "print \"(i) Line voltage at receiving end = %0.2f KV\" %(VR_line/1000)\n",
+ "Regulation=((Vs_line-VR_line)/VR_line)*100 #unitless\n",
+ "print \"(ii) Regulation = %0.2f %%\" %Regulation\n",
+ "I=P_KVA*10**3/(sqrt(3)*VR_line)\n",
+ "#I=P*10**3/(sqrt(3)*VR_line) #in Ampere\n",
+ "TotalLoss=3*I**2*R #in watt\n",
+ "Pout=P_KVA*cos_fir #in KW\n",
+ "Pin=Pout+TotalLoss/1000 #in KW\n",
+ "ETA=Pout/Pin #unitless\n",
+ "print \"(iii) Transmission Efficiency = %0.2f %%\" %(ETA*100)\n",
+ "#NOTE : Answer wrong : Accuracy efficiency in textbook'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Line voltage at receiving end = 31.20 KV\n",
+ "(ii) Regulation = 5.77 %\n",
+ "(iii) Transmission Efficiency = 98.48 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.6 - page 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "from __future__ import division\n",
+ "#Given Data :\n",
+ "P_del=10000*10**3 #in Watts\n",
+ "cos_fir=0.8 #unitless\n",
+ "R=0.95 #in ohm/km\n",
+ "VR=132*10**3 #in volt\n",
+ "IL=P_del/(sqrt(3)*VR*cos_fir) #in Ampere\n",
+ "#TotalLosses=3*I**2*R and should be equal to (7.5/100)*P_del #in watt\n",
+ "l=(7.5/100)*P_del/(3*IL**2*R) #in km\n",
+ "print \"Distance = %0.2f km \" %l"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Distance = 88.04 km \n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.7 - page 133"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given Data :\n",
+ "I=180 #in Ampere\n",
+ "cos_fir=0.8 #unitless\n",
+ "R=0.7 #in ohm/phase\n",
+ "X=1.2 #in ohm/phase\n",
+ "ETA=90 #in %\n",
+ "Pdev_BY_VR=3*I*cos_fir #in KW\n",
+ "Psending_BY_VR=Pdev_BY_VR/(ETA/100) #in kW\n",
+ "Losses=3*I**2*R #in watt\n",
+ "VR=Losses/(Psending_BY_VR-Pdev_BY_VR) #in volt\n",
+ "Vs=sqrt((VR*cos_fir+I*R)**2+(VR*sqrt(1-cos_fir**2)+I*X)**2) \n",
+ "print \"Sending end voltage Vs(line) = %0.2f Volts\" %(Vs*sqrt(3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sending end voltage Vs(line) = 2859.21 Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.8 - page 134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log, sqrt, pi\n",
+ "#Given Data :\n",
+ "d=1*100 #in cm\n",
+ "dia=1 #in cm\n",
+ "r=dia/2 #in cm\n",
+ "Length=20 #in km\n",
+ "V=33 #in KV\n",
+ "P=10 #in MW\n",
+ "cosfi=0.8 #unitless\n",
+ "f=50 #in Hz\n",
+ "R=0.19 #in ohm/km/phase\n",
+ "#Part (i) :\n",
+ "L=2*10**-7*log(d/r) #in H/m\n",
+ "L20=L*Length*10**3 #in H\n",
+ "XL=2*pi*f*L20 #in ohm\n",
+ "R20=R*Length #in ohm\n",
+ "Z=sqrt(R20**2+XL**2) #in ohm\n",
+ "IR=P*10**3/(sqrt(3)*V*cosfi)\n",
+ "Losses=3*IR**2*R20 #in watt\n",
+ "ETA=P/(P+Losses/10**6) #unitless\n",
+ "print \"(i) Efficiency of line = %0.2f %%\" %(ETA*100)\n",
+ "#Part (ii) :\n",
+ "VR=V*1000/sqrt(3) #in volt\n",
+ "Vs=((VR*cosfi+IR*R20)+(VR*sqrt(1-cosfi**2)+IR*XL)) \n",
+ "print \"(ii) Regulation = %0.2f %% \" %(((Vs-VR)/VR)*100) \n",
+ "#Note : Answer in the book is wrong. In second last line of the solution in the book 16079+12885 is taken as 20605 instead of 28964. "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Efficiency of line = 94.83 %\n",
+ "(ii) Regulation = 52.00 % \n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.9 : page 134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given Data : \n",
+ "R=2.5 #in ohm\n",
+ "X=4.33 #in ohm\n",
+ "I=120 #in Ampere\n",
+ "Vr=3300 #in volt\n",
+ "cos_fir=0.8 #unitless\n",
+ "Vs=Vr+I*R*cos_fir+I*X*sqrt(1-cos_fir**2) #in volt\n",
+ "print \"Sending end voltage = %0.2f Volts\" %Vs"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sending end voltage = 3851.76 Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.10 - page 135"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given Data :\n",
+ "Pt=4000*10**3 #in watt(power to be transmitted)\n",
+ "VR=11000 #in volt\n",
+ "cos_fir=0.9 #unitless\n",
+ "R=1 #in ohm\n",
+ "X=2.5 #in ohm\n",
+ "I=Pt/VR #in Ampere\n",
+ "Vs=VR+I*R*cos_fir+I*X*sqrt(1-cos_fir**2) #in volt\n",
+ "print \"(i) Sending end voltage = %0.2f Volts\" %Vs\n",
+ "Reg=(Vs-VR)*100/VR #in %\n",
+ "print \"(ii) Regulation = %0.3f %%\" %Reg\n",
+ "cos_fis=(VR*cos_fir+I*R)/Vs #unitless\n",
+ "print \"(iii) Sending end pf = %0.3f lag \" %(cos_fis)\n",
+ "losses=I**2*R #in watts\n",
+ "Pr=Pt*cos_fir #in wats(Receiving end power)\n",
+ "Psend=Pr+losses #in watts\n",
+ "Eff=Pr*100/Psend #unitless\n",
+ "print \"(iv) Transmission efficiency = %0.2f %%\" %(Eff)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Sending end voltage = 11723.54 Volts\n",
+ "(ii) Regulation = 6.578 %\n",
+ "(iii) Sending end pf = 0.875 lag \n",
+ "(iv) Transmission efficiency = 96.46 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.11 - page 136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "from __future__ import division\n",
+ "#Given Data :\n",
+ "L=20 #in Km(length of the line)\n",
+ "Pdev=3000*10**3 #in watt(power delivered)\n",
+ "cos_fir=0.8 #unitless\n",
+ "VR=11*1000 #in volt\n",
+ "R=0.15*L #in ohm\n",
+ "X=0.4*L #in ohm\n",
+ "I=Pdev/VR #in Ampere\n",
+ "Vs=VR+I*R*cos_fir-I*X*sqrt(1-cos_fir**2) #in volt\n",
+ "print \"(i) Sending end voltage = %0.2f Volts\" %Vs\n",
+ "Reg=(VR-Vs)*100/VR #in %\n",
+ "print \"(ii) Regulation = %0.2f %% \"%Reg \n",
+ "cos_fis=(VR*cos_fir+I*R)/Vs #unitless\n",
+ "print \"(iii) Sending end pf = %0.3f lag\" %cos_fis\n",
+ "losses=I**2*R #in watts\n",
+ "Pr=Pdev*cos_fir #in wats(Receiving end power)\n",
+ "Psend=Pr+losses #in watts\n",
+ "Eff=Pr*100/Psend #unitless\n",
+ "print \"(iv) Transmission efficiency = %0.2f %%\" %(Eff)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Sending end voltage = 10345.45 Volts\n",
+ "(ii) Regulation = 5.95 % \n",
+ "(iii) Sending end pf = 0.930 lag\n",
+ "(iv) Transmission efficiency = 91.49 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.12 - page 137"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "from __future__ import division\n",
+ "#Given Data :\n",
+ "R=2 #in ohm\n",
+ "X=3 #in ohm\n",
+ "VR=10*1000 #in volt\n",
+ "P=1000*10**3 #in watt(power delivered)\n",
+ "cos_fir=0.8 #unitless\n",
+ "I=P/(VR*cos_fir) #in Ampere\n",
+ "Vs=sqrt((VR*cos_fir+I*R)**2+(VR*sqrt(1-cos_fir**2)+I*X)**2) #in volt\n",
+ "Reg=(Vs-VR)*100/VR #in %\n",
+ "print \"(i) Regulation = %0.2f %%\" %Reg \n",
+ "losses=I**2*R #in watts\n",
+ "Pr=P*cos_fir #in wats(Receiving end power)\n",
+ "Psend=Pr+losses #in watts\n",
+ "Eff=Pr*100/Psend #unitless\n",
+ "print \"(ii) Transmission efficiency = %0.2f %% \" %(Eff)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Regulation = 4.26 %\n",
+ "(ii) Transmission efficiency = 96.24 % \n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 5.13 - page 137"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "from __future__ import division\n",
+ "#Given Data :\n",
+ "R=1.5 #in ohm\n",
+ "X=4 #in ohm\n",
+ "VR=11*1000 #in volt\n",
+ "VRphase=VR/sqrt(3) #in volt/phase\n",
+ "P=6000 #in KVA(power delivered)\n",
+ "cos_fir=0.8 #unitless\n",
+ "I=P*1000/(3*VRphase) #in Ampere\n",
+ "Vs=VRphase+cos_fir*I*R+sqrt(1-cos_fir**2)*I*X #in volt\n",
+ "Vs=Vs*sqrt(3) #in volt(not phase)\n",
+ "Reg=(Vs-VR)*100/VR #in %\n",
+ "print \"(i) Regulation = %0.1f %%\" %Reg\n",
+ "losses=3*I**2*R/1000 #in Kw\n",
+ "Pr=P*cos_fir #in wats(Receiving end power)\n",
+ "Psend=Pr+losses #in watts\n",
+ "Eff=Pr*100/Psend #unitless\n",
+ "print \"Transmission efficiency = %0.1f %%\" %Eff"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Regulation = 17.9 %\n",
+ "Transmission efficiency = 91.5 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 52
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/Electrical_Power-i__by_M.L._Anand/Chapter7.ipynb b/Electrical_Power-i__by_M.L._Anand/Chapter7.ipynb
new file mode 100755
index 00000000..71496b0e
--- /dev/null
+++ b/Electrical_Power-i__by_M.L._Anand/Chapter7.ipynb
@@ -0,0 +1,814 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter7 - Distribution systems"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.1 - page 174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import cmath\n",
+ "#Given data : \n",
+ "l=1 #in km\n",
+ "I=100 #in Ampere\n",
+ "cosfi=0.8 #Power factor(lag) unitless\n",
+ "VC=200 #in volt\n",
+ "IL=60 #in Ampere\n",
+ "cosfi_load=0.9 #Power factor(lag) unitless\n",
+ "R=0.6 #in ohm\n",
+ "XL=0.08 #in ohm\n",
+ "IC=I*complex(0.8,-0.6) #in Ampere\n",
+ "z=complex(0.06,0.08)/2 #in ohm\n",
+ "VD_BC=z*IC #in volt\n",
+ "VB=VC+VD_BC #in volt\n",
+ "IB=IL*complex(0.9,-0.4357)+IC #in Ampere\n",
+ "VD_AB=z*IB #in volt\n",
+ "VD_AB=round(VD_AB.real,2)+round(VD_AB.imag,2)*1J\n",
+ "print \"V.D. from sending end to mid point =\" ,VD_AB,\"Volt\"\n",
+ "print \"V.D. from mid point to the far end =\",VD_BC,\"Volt\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "V.D. from sending end to mid point = (7.47+2.78j) Volt\n",
+ "V.D. from mid point to the far end = (4.8+1.4j) Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.2 - page 175"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from sympy import symbols\n",
+ "#Given data : \n",
+ "l=500 #in meter\n",
+ "i=1 #in Ampere/meter\n",
+ "IL1=200;IL2=150;IL3=50;IL4=100 #in Ampere\n",
+ "l1=100;l2=200;l3=300;l4=400 #in meter\n",
+ "r=0.1 #in ohm/km\n",
+ "Vd=250 #in volt\n",
+ "I=symbols('I')\n",
+ "Drop_AC=100*(r/10**3)*(I-i*l1/2) \n",
+ "Drop_CD=I \n",
+ "Drop_DE=100*r*(I-550)-I*100/2 \n",
+ "Drop_EF=100*r*(I-700-I*100/2) \n",
+ "Drop_FB=100*r*(I-900-I*100/2) \n",
+ "VD_tot=0.05*I-27 #in volts\n",
+ "#both ends are fed with same voltage,\n",
+ "#VD_tot should be equal to zero.\"\n",
+ "I=27/0.05 #in Ampere\n",
+ "print \"Curent = %0.2f Ampere\" %I\n",
+ "Drop_AD=(0.01*I-0.5)+(0.01*I-3.5) \n",
+ "print \"Value at minimum potential at D = %0.2f V\" %(Vd-Drop_AD)\n",
+ "#Note : Ans in the book is wrong as 27/0.05 gives 540 instead of 54."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Curent = 540.00 Ampere\n",
+ "Value at minimum potential at D = 243.20 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.3 - page 176"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "l=250 #in meter\n",
+ "VA=230 #in volt\n",
+ "VB=232 #in volt\n",
+ "r=0.5 #in ohm/km\n",
+ "r=0.5/10**3 #in ohm/m\n",
+ "RAC=r*50*2 #in ohm\n",
+ "RCD=RAC;RDE=RAC;REF=RAC;RFB=RAC #in ohm\n",
+ "#VA-VB=VAC+VCD+VDE+VEF+VFB #in volt\n",
+ "Ia=(VA-VB+15)/(5*RAC) #Ampere\n",
+ "IAC=Ia;ICD=IAC-20;IDE=IAC-60;IED=-IDE;IEF=IAC-100;IFE=-IEF;IFB=IAC-120;IBF=-IFB #in Ampere\n",
+ "print \"IAC = %0.f A\" %IAC\n",
+ "print \"ICD = %0.f A\" %ICD\n",
+ "print \"IDE = %0.f A\" %IDE\n",
+ "print \"IED = %0.f A\" %IED\n",
+ "print \"IEF = %0.f A\" %IEF\n",
+ "print \"IFE = %0.f A\" %IFE\n",
+ "print \"IFB = %0.f A\" %IFB\n",
+ "print \"IBF = %0.f A\" %IBF\n",
+ "VAC=IAC*RAC #in volt\n",
+ "VCD=ICD*RCD #in volt\n",
+ "VD=VA-VAC-VCD #in volt\n",
+ "print \"The minimum potential = %0.1f Volt\" %(VD)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "IAC = 52 A\n",
+ "ICD = 32 A\n",
+ "IDE = -8 A\n",
+ "IED = 8 A\n",
+ "IEF = -48 A\n",
+ "IFE = 48 A\n",
+ "IFB = -68 A\n",
+ "IBF = 68 A\n",
+ "The minimum potential = 225.8 Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.4 - page 177"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "VA=235 #in volt\n",
+ "VB=236 #in volt\n",
+ "l=200 #in meter\n",
+ "IL1=20;IL2=40;IL3=25;IL4=30 #in Ampere\n",
+ "l1=50;l2=75;l3=100;l4=50 #in meter\n",
+ "r=0.4 #in ohm/km\n",
+ "r=0.4/10**3 #in ohm/m\n",
+ "RAC=r*l1*2 #in ohm\n",
+ "RCD=r*(l2-l1)*2*RAC;RDE=r*(l2-l1)*2*RAC;REF=r*l1*2*RAC;RFB=r*l1*2*RAC #in ohm\n",
+ "#VA-VB=VAC+VCD+VDE+VEF+VFB #in volt\n",
+ "IA=(VA-VB+9.6)/(0.16) #in Ampere\n",
+ "IAC=IA;ICD=IA-IL1;IDE=IA-IL1-IL2;IEF=IA-IL1-IL2-IL3;IFB=IA-IL1-IL2-IL3-IL4 #in Ampere\n",
+ "print \"IAC = %0.2f A\" %IAC\n",
+ "print \"ICD = %0.2f A\" %ICD\n",
+ "print \"IED = %0.2f A\" %(-IDE)\n",
+ "print \"IFE = %0.2f A\" %-IEF\n",
+ "print \"IFB = %0.2f A\" %-IFB\n",
+ "VAC=IAC*RAC #in volt\n",
+ "VCD=ICD*RCD #in volt\n",
+ "VD=VA-VAC-VCD #in volt\n",
+ "print \"The minimum potential = %0.3f Volt\" %VD\n",
+ "# Answer wrong in the textbook due to accuracy."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "IAC = 53.75 A\n",
+ "ICD = 33.75 A\n",
+ "IED = 6.25 A\n",
+ "IFE = 31.25 A\n",
+ "IFB = 61.25 A\n",
+ "The minimum potential = 232.823 Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.5 - page 179"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "VA=400 #in volt\n",
+ "r=0.03 #in ohm/km\n",
+ "r=0.03/1000 #in ohm/m\n",
+ "RAB=r*500*2 #in ohm\n",
+ "RBC=r*300*2 #in ohm\n",
+ "RAB=r*700*2 #in ohm\n",
+ "RAB=r*500*2 #in ohm\n",
+ "#VA-VB=VAC+VCD+VDE+VEF+VFB #in volt\n",
+ "IA=(17.4)/(0.09) #in Ampere\n",
+ "VAB=(RAB)*IA #in volt\n",
+ "VB=VA-VAB #in volt\n",
+ "print \"Voltage at B = %0.2f Volts\" %VB\n",
+ "VBC=(RBC)*(IA-150) #in volt\n",
+ "VC=VB-VBC #in volt\n",
+ "print \"Voltage at C = %0.2f Volts\" %VC\n",
+ "IBC=IA-150 #in A\n",
+ "print \"Current in section BC = %0.2f A \"%IBC \n",
+ "#Note : Answer of VB is wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage at B = 394.20 Volts\n",
+ "Voltage at C = 393.42 Volts\n",
+ "Current in section BC = 43.33 A \n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.6 - page 180"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "VA=240 #in volt\n",
+ "MAxVDrop=VA*5/100 #in volt\n",
+ "rho=2.87*10**-6 #in ohm-cm \n",
+ "#VAB+VBC+VCA=0 #in volt\n",
+ "IA=(3200)/(26) #in Ampere\n",
+ "IAB=IA #in Ampere\n",
+ "IBC=IA-100 #in Ampere\n",
+ "#Allowed voltage drop: IAB*RAB+IBC*RBC=12\n",
+ "R=12/(1015.26) #in ohm\n",
+ "RAB=R*300*2/100 #in ohm\n",
+ "RBC=R*600*2/100 #in ohm\n",
+ "RCA=R*400*2/100 #in ohm\n",
+ "#formula : R=rho*l/a\n",
+ "a=rho*(100*100)/R #in cm**2\n",
+ "print \"Cross section area = %0.2f cm2 \" %a"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Cross section area = 2.43 cm2 \n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.7 - page 182"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given data : \n",
+ "R=0.2 #in ohm/km\n",
+ "X=0.1 #in ohm/km\n",
+ "ZAM=((R+X*1J)/1000)*200 #in ohm\n",
+ "ZMB=((R+X*1J)/1000)*100 #in ohm\n",
+ "I1=100*(0.707-0.707*1J) #in A\n",
+ "I2=200*(0.8-0.6*1J) #in A\n",
+ "IAM=I1+I2 #in Ampere\n",
+ "VAM=ZAM*IAM #in volts\n",
+ "VMB=ZMB*I2 #in volts\n",
+ "VAB=VAM+VMB #in volts\n",
+ "magVAB=sqrt(VAB.real**2+VAB.imag**2) \n",
+ "print \"Total voltage drop = %0.2f Volts\" %magVAB"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total voltage drop = 17.85 Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.8 - page 183"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, sin, pi, arctan, arccos, cos\n",
+ "import cmath\n",
+ "#Given data : \n",
+ "VB=200 #in volts\n",
+ "R=0.2 #in ohm/km\n",
+ "X=0.3 #in ohm/km\n",
+ "I=100 #in Ampere\n",
+ "ZAB=(R+X*1J) #in ohm\n",
+ "ZMB=ZAB/2 #in ohm\n",
+ "ZAM=ZMB #in ohm\n",
+ "cosfi_1=0.6 #unitless\n",
+ "cosfi_2=0.8 #unitless\n",
+ "IMB=I*(cosfi_2-cosfi_1*1J) #in A\n",
+ "I2=IMB #in Ampere\n",
+ "VMB=IMB*ZMB #in volts\n",
+ "VM=VB+VMB #in volts\n",
+ "print \"Voltage at M = %.2f\u2220%.2f\u00b0\" %(abs(VM),cmath.phase(VM)*180/pi)\n",
+ "#print('Sending end voltage , V_S = %.2f\u2220%.2f\u00b0 kV/phase' %(abs(V_S*10**-3),cmath.phase(V_S)*180/math.pi))\n",
+ "fi=arctan(VM.imag/VM.real)*180/pi #in degree\n",
+ "fi_1=arccos(cosfi_1)*180/pi #in degree\n",
+ "fi_VBandI1=fi_1-fi #in degree\n",
+ "I1=I*(cos(fi_VBandI1*pi/180)-sin(fi_VBandI1*pi/180))*1J #in Ampere\n",
+ "IAM=I1+I2 #inA Ampere\n",
+ "VAM=ZAM*IAM #in volts\n",
+ "VA=VM+VAM #in volts\n",
+ "magVA=sqrt(VA.real**2+VA.imag**2) \n",
+ "print \"Voltage at A, standing end voltage = %0.2f Volts\" %magVA\n",
+ "#Answer wrong in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage at M = 217.08\u22201.58\u00b0\n",
+ "Voltage at A, standing end voltage = 236.65 Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 63
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.9 - page 184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "l=500 #in meter\n",
+ "VA=200 #in volt\n",
+ "MAxVDrop=6 #in % of declared voltage \n",
+ "rho=0.014 #in ohm/m \n",
+ "#VD in the distributor=53*10**3*r\n",
+ "AllowedVD=VA*(6/100) #in volts\n",
+ "r=AllowedVD*10**6/(53*10**3) #in ohm/meter\n",
+ "#formula : R=rho*l/a\n",
+ "a=rho*(2*l)/r #in m**2\n",
+ "print \"Cross section area = %0.2f m2 \" %(a)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Cross section area = 0.06 m2 \n"
+ ]
+ }
+ ],
+ "prompt_number": 64
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.10 - page 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "l=300 #in meter\n",
+ "I=0.75 #in A/m\n",
+ "R=0.00018 #in ohm/m\n",
+ "x=200 #in meter\n",
+ "Vs=250 #in volt\n",
+ "VD=I*R*(l*x-x**2/2) #in volt\n",
+ "V_A=Vs-VD #in volt(Voltage at 200m from end A)\n",
+ "print \"Voltage as 200m from supply end A = %0.1f Volts\" %V_A"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage as 200m from supply end A = 244.6 Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 66
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.11 - page 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "l=600 #in meter\n",
+ "VA=440 #in volt\n",
+ "VB=400 #in volt\n",
+ "R=0.01 #in ohm/100m\n",
+ "RAC=(R/100)*300 #in ohm\n",
+ "RCD=(R/100)*300 #in ohm\n",
+ "RDE=(R/100)*100 #in ohm\n",
+ "REF=(R/100)*200 #in ohm\n",
+ "RFB=(R/100)*300 #in ohm\n",
+ "#VA-VB=VAC+VCD+VDE+VEF+VFB #in volt\n",
+ "IA=(VA-VB+42.5)/(0.12) #in Ampere\n",
+ "IAC=IA;ICD=IA-100;IDE=IA-300;IFE=IA-550;IFB=IA-850 #in Ampere\n",
+ "print \"Current fed at A, IA = %0.1f A \"%IAC \n",
+ "print \"Current fed at B, IB = %0.1f A \"%-IFB"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current fed at A, IA = 687.5 A \n",
+ "Current fed at B, IB = 162.5 A \n"
+ ]
+ }
+ ],
+ "prompt_number": 69
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.12 - page 187"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "VA=220 #in volt\n",
+ "VB=200 #in volt\n",
+ "R=0.1 #in ohm/km\n",
+ "I=1 #in A/m\n",
+ "l=500 #in meter\n",
+ "R=2*R/1000 #in ohm/m\n",
+ "x=(VA-VB)/(I*R*l)+l/2 #in meter\n",
+ "Vmin=VA-I*R*x**2/2 #in volts\n",
+ "print \"Value of minimum potential = %0.2f V \"%Vmin \n",
+ "IA=I*x #in A\n",
+ "print \"Current supplied from end A = %0.f A \" %IA \n",
+ "IB=I*(l-x) #in A\n",
+ "print \"Current supplied from end B = %0.f A\"%IB"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of minimum potential = 199.75 V \n",
+ "Current supplied from end A = 450 A \n",
+ "Current supplied from end B = 50 A\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.13 - page 187"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "VL=240 #in volt\n",
+ "Router=0.2 #in ohm\n",
+ "I1=VL/5 #in Ampere\n",
+ "I2=VL/6 #in Ampere\n",
+ "Ineutral=I1-I2 #in Ampere\n",
+ "#Applying KVL on +ve side\n",
+ "V1=VL+I1*0.2+8*0.4 #in volt\n",
+ "print \"Voltage at +ve side = %0.1f V\" %V1\n",
+ "#Applying KVL on +ve side\n",
+ "V2=VL-(8*0.4)+I2*0.2 #in volt\n",
+ "print \"Voltage at -ve side = %0.1f V\" %V2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage at +ve side = 252.8 V\n",
+ "Voltage at -ve side = 244.8 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.14 - page 188"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "#Applying KVL on +ve side\n",
+ "V1=200-(600*0.015)-(100)*0.03 #in volt\n",
+ "print \"Voltage at +ve side = %0.f V\" %V1\n",
+ "#Applying KVL on -ve side\n",
+ "V2=200-(-100*0.03)-500*0.0015 #in volt\n",
+ "print \"Voltage at -ve side = %0.1f V\" %V2\n",
+ "#Note : answer of 2nd part is wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage at +ve side = 188 V\n",
+ "Voltage at -ve side = 202.2 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.15 - page 189"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import symbols\n",
+ "x=symbols('x')\n",
+ "#Given data : \n",
+ "#VD in section AC from RHS: \n",
+ "VD1=(40+x)*0.02+0.17*x\n",
+ "#VD in section AC from LHS: \n",
+ "VD2=(350-x)*0.015+(150-x)*0.03\n",
+ "#Equating two VDs we get\n",
+ "#x*0.02+0.17*x+0.015*x+x*0.03=350*0.015+150*0.03-40*0.02\n",
+ "x=(350*0.015+150*0.03-40*0.02)/0.082 #in A\n",
+ "VB=500-(x+40)*0.02 #in volts\n",
+ "print \"Potential at point B = %0.2f V\" %VB\n",
+ "VC=VB-(x*0.017) #in volts\n",
+ "print \"Potential at point C = %0.2f V\" %VC\n",
+ "VD=500-(350-x)*0.015 #in volts\n",
+ "print \"Potential at point D = %0.2f V\" %VD\n",
+ "#Note : Answer of 3rd part is given wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Potential at point B = 497.02 V\n",
+ "Potential at point C = 495.16 V\n",
+ "Potential at point D = 496.39 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.16 - page 190"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import symbols\n",
+ "x=symbols('x')\n",
+ "#Given data : \n",
+ "#Applying KVL in loop AFEDA: \n",
+ "p1=((0.016*x)+0.09*(x-30)+0.14*(x-17)-0.1*y) #eqn(1) \n",
+ "#Applying KVL in loop ADCBA: \n",
+ "p2=(0.1*y-0.12*(95-x-y)-.01*(145-x-y)-0.008*(165-x-y)) #eqn(2)\n",
+ "#Equating two equtions we get\n",
+ "#3.9*x-125=97.75-0.75*x\n",
+ "x=(97.75+125)/(3.9+0.75) #in A\n",
+ "y=97.75-0.75*x #in A\n",
+ "print \"x = %0.f A\" %x \n",
+ "print \"y = %0.2f A\"%y \n",
+ "print \"Point of minimum ppotential is E.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x = 48 A\n",
+ "y = 61.82 A\n",
+ "Point of minimum ppotential is E.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.17 - page 190"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "V=200 #in volt\n",
+ "I=1 #in A/m\n",
+ "R=2*0.05/1000 #in ohm/m\n",
+ "l=1*1000 #in meter\n",
+ "IT=I*l #in Ampere\n",
+ "RT=R*l #in ohm\n",
+ "VD=IT*RT/8 #in volt\n",
+ "Vmin=V-VD #in volt\n",
+ "print \"Minimum potential occurs at mid point. It is %0.2f V\" %Vmin"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Minimum potential occurs at mid point. It is 187.50 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.19 - page 191"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "VB=400 #in volt\n",
+ "ZAC=0.04+0.08*1J #in ohm\n",
+ "ZCB=0.08+1J*0.12 #in ohm\n",
+ "I1=60*(0.8-1J*0.6) \n",
+ "I2=120*(0.8-1J*0.6) \n",
+ "VCB=I2*ZCB #in Volt\n",
+ "VAC=(I1+I2)*ZAC #in volt\n",
+ "VC=VB+I2*ZCB #in Volt\n",
+ "print \"Voltage at C =\",VC,\"Volt\"\n",
+ "VA=VC+(I1+I2)*ZAC #in volt\n",
+ "print \"Voltage at A =\",VA,\"Volt\"\n",
+ "#Answer not accurate in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage at C = (416.32+5.76j) Volt\n",
+ "Voltage at A = (430.72+12.96j) Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/Electrical_Power-i__by_M.L._Anand/Chapter8.ipynb b/Electrical_Power-i__by_M.L._Anand/Chapter8.ipynb
new file mode 100755
index 00000000..b2ca03f6
--- /dev/null
+++ b/Electrical_Power-i__by_M.L._Anand/Chapter8.ipynb
@@ -0,0 +1,364 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter8 - Underground cables and faults"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.1 - page 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import exp, pi\n",
+ "#given data\n",
+ "R=500 #in Mohm/Km\n",
+ "R=R*10**6 #in ohm\n",
+ "r1=2.5/2 #in cm\n",
+ "r1=r1*10**-2 #in meter\n",
+ "rho=4.5*10**16 #in ohm/cm\n",
+ "rho=rho*10**-2 #in ohm/m\n",
+ "l=1 #in Km\n",
+ "l=l*1000 #in meter\n",
+ "#Formula : R=(rho/(2*pi*l))*log(r2/r1)\n",
+ "r2=(exp(R/(rho/(2*pi*l))))*r1 #in meter\n",
+ "thickness=r2-r1 #in meter\n",
+ "thickness=thickness*100 #in cm\n",
+ "print \"Thickness of Insulation = %0.3f cm\" %thickness\n",
+ "# Answer in the textbook is wrong due to accuracy."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Thickness of Insulation = 0.009 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.2 - page 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log10\n",
+ "#given data\n",
+ "d=1 #in cm\n",
+ "d=d*10**-2 #in meter\n",
+ "D=1.8 #in cm\n",
+ "D=D*10**-2 #in meter\n",
+ "epsilon_r=4 #permittivity of insulation\n",
+ "C=0.024*epsilon_r/log10(D/d) #in uF/Km\n",
+ "print \"Capacitance/km of the fibre = %0.3f uF\" %C"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacitance/km of the fibre = 0.376 uF\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.3 - page 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log\n",
+ "#given data\n",
+ "V=33 #in KV\n",
+ "d=1 #in cm\n",
+ "D=4 #in cm\n",
+ "#Part (a) :\n",
+ "gmax=2*V/(d*log(D/d)) #in KV/cm\n",
+ "print \"Maximum Stress = %0.1f KV/cm\" %gmax\n",
+ "#Part (b) :\n",
+ "gmin=2*V/(D*log(D/d)) #in KV/cm\n",
+ "print \"Minimum Stress = %0.0f KV/cm\" %round(gmin)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum Stress = 47.6 KV/cm\n",
+ "Minimum Stress = 12 KV/cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.4 - page 224"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt\n",
+ "#given data\n",
+ "Vrms=66 #in KV\n",
+ "gmax=40 #in KV/cm\n",
+ "V=sqrt(2)*Vrms #in Volt\n",
+ "#Part (a) : \n",
+ "d=2*V/gmax #in cm\n",
+ "print \"The most economical diameter = %0.3f cm\" %d\n",
+ "#Part (b) : \n",
+ "PeakVoltage=sqrt(2)*Vrms/sqrt(3) #in Volt\n",
+ "V=PeakVoltage #in Volt\n",
+ "d=2*V/gmax #in cm\n",
+ "print \"The most economical diameter for 3 phase system = %0.1f m\" %d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The most economical diameter = 4.667 cm\n",
+ "The most economical diameter for 3 phase system = 2.7 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.5 - page 224"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from math import sqrt\n",
+ "#given data\n",
+ "d=2 #in cm\n",
+ "D=2.5*2 #in cm\n",
+ "d1=(5/4)*d #in cm\n",
+ "d2=(5/3)*d #in cm\n",
+ "gmax=40 #in KV/cm\n",
+ "PeakVoltage=(gmax/2)*(d*log(d1/d)+d1*log(d2/d1)+d2*log(D/d2)) #in KV\n",
+ "print \"The safe Working Potential = %0.1f KV\" %(PeakVoltage/sqrt(2))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The safe Working Potential = 35.6 KV\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.6 - page 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import pi, sqrt\n",
+ "#given data\n",
+ "CN=0.4 #in uF\n",
+ "V=33 #in KV\n",
+ "VP=V/sqrt(3) #in KV\n",
+ "f=25 #in Hz\n",
+ "#Capacitance between 2 cores for 15 Km length\n",
+ "CN_1=15*CN #in uF\n",
+ "#Capacitance of each core to neutral\n",
+ "CN=2*CN_1 #in uF\n",
+ "#Charging current per phase\n",
+ "I=2*pi*f*VP*1000*CN*10**-6 #in Ampere\n",
+ "print \"Charging current per phase = %0.2f A\" %round(I)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Charging current per phase = 36.00 A\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.7 - page 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import pi, sqrt\n",
+ "#given data\n",
+ "l=10 #in Km\n",
+ "C=0.3 #in uF\n",
+ "V=22 #in KV\n",
+ "VP=V/sqrt(3) #in KV\n",
+ "VP=VP*1000 #in Volt\n",
+ "f=50 #in Hz\n",
+ "Capacitance=C*l #in uF\n",
+ "CN=2*Capacitance #in uF\n",
+ "KVA_Taken=3*VP*2*pi*f*VP*CN*10/1000 #in KVA\n",
+ "print \"KVA taken by the 10 Km cable = %0.3e KVA\" %KVA_Taken"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "KVA taken by the 10 Km cable = 9.123e+09 KVA\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.8 - page 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given data\n",
+ "P=10 #in Ohm\n",
+ "Q=80 #in Ohm\n",
+ "S2=3400 #in Ohm\n",
+ "S1=2400 #in Ohm\n",
+ "X=P*(S2-S1)/(P+Q) #in Ohm\n",
+ "LoopResistance=P*S2/Q #in Ohm\n",
+ "ResistancePerKm=LoopResistance/10 #in Ohm\n",
+ "Distance=X/ResistancePerKm #in Km\n",
+ "print \"Distance of fault from testing end = %0.3f Km\" %Distance"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Distance of fault from testing end = 2.614 Km\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exa 8.9 - page 226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given data\n",
+ "Resistance=1.6 #in ohm/Km\n",
+ "l=1000 #in meter\n",
+ "PbyQ=3 #unitless\n",
+ "PplusQbyQ=4 #unitless\n",
+ "LoopResistance=(Resistance/1000)*2*l #in Ohm\n",
+ "X=(1/PplusQbyQ)*LoopResistance #in Ohm\n",
+ "Distance=X/(Resistance/1000) #in meter\n",
+ "print \"Distance of Fault from testing end = %0.2f meters\" %Distance"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Distance of Fault from testing end = 500.00 meters\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/Electrical_Power-i__by_M.L._Anand/Chapter9.ipynb b/Electrical_Power-i__by_M.L._Anand/Chapter9.ipynb
new file mode 100755
index 00000000..4eac07db
--- /dev/null
+++ b/Electrical_Power-i__by_M.L._Anand/Chapter9.ipynb
@@ -0,0 +1,58 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter9 - Substations and earthing"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 9.1 - page 252"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import pi\n",
+ "#Given Data :\n",
+ "V=250 #in volt\n",
+ "f=50 #in Hz\n",
+ "l=300 #in km\n",
+ "C_earth=0.03 #in uF\n",
+ "C=l*C_earth*10**-6 #in F\n",
+ "XL=1/(3*2*pi*f*C) #in ohm\n",
+ "print \"Reactance required for the Peterson coil = %.f ohm\" %XL"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reactance required for the Peterson coil = 118 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/Electrical_Power_System/README.txt b/Electrical_Power_System/README.txt
new file mode 100755
index 00000000..ebabefbd
--- /dev/null
+++ b/Electrical_Power_System/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Shriniwas Sabban
+Course: be
+College/Institute/Organization: university of pune
+Department/Designation: Electronics Department
+Book Title: Electrical Power System
+Author: C.L. Wadhwa
+Publisher: New Age International
+Year of publication: 2010
+Isbn: 9788122428391
+Edition: 6 \ No newline at end of file
diff --git a/Elements_Of_Heat_Transfer/README.txt b/Elements_Of_Heat_Transfer/README.txt
new file mode 100755
index 00000000..473cf24e
--- /dev/null
+++ b/Elements_Of_Heat_Transfer/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Parth Thakkar
+Course: mscit
+College/Institute/Organization: Freelancer
+Department/Designation: Developer
+Book Title: Elements Of Heat Transfer
+Author: M. Jacob And G. A. Hawkins
+Publisher: John Wiley & Sons, New York
+Year of publication: 1957
+Isbn: 9780471437253
+Edition: 3 \ No newline at end of file
diff --git a/Elements_of_Mechanical_Engineering/README.txt b/Elements_of_Mechanical_Engineering/README.txt
new file mode 100755
index 00000000..db7fb47e
--- /dev/null
+++ b/Elements_of_Mechanical_Engineering/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Jatin Patel
+Course: bca
+College/Institute/Organization: Freelancing work
+Department/Designation: Freelancer
+Book Title: Elements of Mechanical Engineering
+Author: N. M. Bhatt and J. R. Mehta
+Publisher: Mahajan Publishing, Ahmedabad
+Year of publication: 2012
+Isbn: 978-93-81256-35-0
+Edition: 6 \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis/README.txt b/Elements_of_Power_System_Analysis/README.txt
new file mode 100755
index 00000000..5624ed61
--- /dev/null
+++ b/Elements_of_Power_System_Analysis/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Mayur Sabban
+Course: be
+College/Institute/Organization: Vishwakarma Institute of Technology Pune
+Department/Designation: Computer Engg
+Book Title: Elements of Power System Analysis
+Author: W.D. Stevenson, Jr.
+Publisher: McGraw Hill.
+Year of publication: 1982
+Isbn: 0070665842
+Edition: 4 \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis/screenshots/Chapter2.png b/Elements_of_Power_System_Analysis/screenshots/Chapter2.png
new file mode 100755
index 00000000..35ed83ff
--- /dev/null
+++ b/Elements_of_Power_System_Analysis/screenshots/Chapter2.png
Binary files differ
diff --git a/Elements_of_Power_System_Analysis/screenshots/Chapter2_1.png b/Elements_of_Power_System_Analysis/screenshots/Chapter2_1.png
new file mode 100755
index 00000000..35ed83ff
--- /dev/null
+++ b/Elements_of_Power_System_Analysis/screenshots/Chapter2_1.png
Binary files differ
diff --git a/Elements_of_Power_System_Analysis/screenshots/Chapter3.png b/Elements_of_Power_System_Analysis/screenshots/Chapter3.png
new file mode 100755
index 00000000..2b06320d
--- /dev/null
+++ b/Elements_of_Power_System_Analysis/screenshots/Chapter3.png
Binary files differ
diff --git a/Elements_of_Power_System_Analysis/screenshots/Chapter3_1.png b/Elements_of_Power_System_Analysis/screenshots/Chapter3_1.png
new file mode 100755
index 00000000..2b06320d
--- /dev/null
+++ b/Elements_of_Power_System_Analysis/screenshots/Chapter3_1.png
Binary files differ
diff --git a/Elements_of_Power_System_Analysis/screenshots/Chapter4.png b/Elements_of_Power_System_Analysis/screenshots/Chapter4.png
new file mode 100755
index 00000000..03c7adf4
--- /dev/null
+++ b/Elements_of_Power_System_Analysis/screenshots/Chapter4.png
Binary files differ
diff --git a/Elements_of_Power_System_Analysis/screenshots/Chapter4_1.png b/Elements_of_Power_System_Analysis/screenshots/Chapter4_1.png
new file mode 100755
index 00000000..03c7adf4
--- /dev/null
+++ b/Elements_of_Power_System_Analysis/screenshots/Chapter4_1.png
Binary files differ
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo02.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo02.ipynb
new file mode 100755
index 00000000..660f7921
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo02.ipynb
@@ -0,0 +1,411 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 02 : Basic Concepts"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1, Page No 21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy\n",
+ "#initialisation of variables\n",
+ "E1=complex(100,0)\n",
+ "E2=complex(86.6,50)\n",
+ "Z=complex(5)\n",
+ "X=5.0\n",
+ "print(\" Value of voltage source one designated as a machine 1 = {0:.5f}+{1:.5f}i v\".format(E1.real, E1.imag))\n",
+ "print(\" Value of voltage source two designated as a machine 2 = {0:.5f}+{1:.5f}i v\".format(E2.real, E2.imag))\n",
+ "print(\" Impedance connected = %.4f ohms \" %abs(Z))\n",
+ "\n",
+ "\n",
+ "#Calculation Of Current\n",
+ "I=(E1-E2)/Z\n",
+ "print(\" Current through the impedance = {0:.5f}+{1:.5f}i A\".format(I.real, I.imag))\n",
+ "\n",
+ "#Calculations\n",
+ "#Calculation Of Power\n",
+ "M1=E1*numpy.conj(I)\n",
+ "print('Machine one Power = %.2f' %M1)\n",
+ "M2=E2*numpy.conj(I)\n",
+ "print('Machine Two Power = %.2f' %M2)\n",
+ "\n",
+ "\n",
+ "#Calculation Of Reactive Power Required By Inductive Reactance\n",
+ "RP=(abs(I))**2*X\n",
+ "print(\" Reactive power required by inductive reactance i.e, impedance = %.4f VAR \" %RP)\n",
+ "print(\" Machine 1 consumes energy at the rate of %.4f W \" %abs(M1.real))\n",
+ "print(\" Machine 2 generates energy at the rate of %.4f W \" %abs(M2.real))\n",
+ "print(\" Machine 1 supplies reactive power at the rate of %.4f VAR \" %(M1.imag))\n",
+ "print(\" Machine 2 supplies reactive power at the rate of %.4f VAR \" %abs(M2.imag))\n",
+ "print(\" Reactive power required by inductive reactance i.e, impedance = Sum of reactive power supplied by machine 1 + reactive power supplied by machine 2 = %.4f VAR \"%RP)\n",
+ "print('Real Power consumed by impedance is Zero')\n",
+ "print('The real power generated by machine two is transferred to machine one')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of voltage source one designated as a machine 1 = 100.00000+0.00000i v\n",
+ " Value of voltage source two designated as a machine 2 = 86.60000+50.00000i v\n",
+ " Impedance connected = 5.0000 ohms \n",
+ " Current through the impedance = 2.68000+-10.00000i A\n",
+ "Machine one Power = 268.00\n",
+ "Machine Two Power = -267.91\n",
+ " Reactive power required by inductive reactance i.e, impedance = 535.9120 VAR \n",
+ " Machine 1 consumes energy at the rate of 268.0000 W \n",
+ " Machine 2 generates energy at the rate of 267.9120 W \n",
+ " Machine 1 supplies reactive power at the rate of 1000.0000 VAR \n",
+ " Machine 2 supplies reactive power at the rate of 1000.0000 VAR \n",
+ " Reactive power required by inductive reactance i.e, impedance = Sum of reactive power supplied by machine 1 + reactive power supplied by machine 2 = 535.9120 VAR \n",
+ "Real Power consumed by impedance is Zero\n",
+ "The real power generated by machine two is transferred to machine one\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2 Page No 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Vab = 173.2*complex(math.cos(0),math.sin(0))\n",
+ "Vbc = 173.2*complex(math.cos(240*math.pi/180),math.sin(240*math.pi/180))\n",
+ "Vca = 173.2*complex(math.cos(120*math.pi/180),math.sin(120*math.pi/180))\n",
+ "print('The given line-line voltages are')\n",
+ "\n",
+ "\n",
+ "#'/_' this symbol has been used to show angle\n",
+ "print( \"Vab= {0:.2f}\".format(abs(Vab.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vab.imag,Vab.real))*180/math.pi))\n",
+ "print( \"Vbc= {0:.2f}\".format(abs(Vbc)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vbc.imag,Vbc.real))))\n",
+ "print( \"Vca= {0:.2f}\".format(abs(Vca)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vca.imag,Vca.real))))\n",
+ "\n",
+ "#Calculation of line-neutral voltage\n",
+ "Van = (Vab/math.sqrt(3)/complex(0.866,0.5))\n",
+ "Vbn = (Vbc/math.sqrt(3)/complex(0.866,0.5))\n",
+ "Vcn = (Vca/math.sqrt(3)/complex(0.866,0.5))\n",
+ "print('The line-neutral voltages are')\n",
+ "print( \"Van= {0:.2f}\".format(abs(Van.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Van.imag,Van.real))*180/math.pi))\n",
+ "print( \"Vbn= {0:.2f}\".format(abs(Vbn)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vbn.imag,Vbn.real))))\n",
+ "print( \"Vcn= {0:.2f}\".format(abs(Vcn)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vcn.imag,Vcn.real))))\n",
+ "ZL = 10*complex(math.cos(20*math.pi/180),math.sin(20*math.pi/180))\n",
+ "\n",
+ "print( \"Load Impedance ZL = {0:.2f}\".format(abs(ZL)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(ZL.imag,ZL.real))))\n",
+ "\n",
+ "#Calculation of line-neutral current\n",
+ "Ian = Van / ZL\n",
+ "Ibn = Vbn / ZL\n",
+ "Icn = Vcn / ZL\n",
+ "\n",
+ "#Results\n",
+ "print('The resulting current in each phase')\n",
+ "print( \"Ian= {0:.2f}\".format(abs(Ian.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Ian.imag,Ian.real))*180/math.pi))\n",
+ "print( \"Ibn= {0:.2f}\".format(abs(Ibn)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vbn.imag,Vbn.real))))\n",
+ "print( \"Icn= {0:.2f}\".format(abs(Icn)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Icn.imag,Icn.real))))\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The given line-line voltages are\n",
+ "Vab= 173.20\n",
+ "Angle = 0.00 v \n",
+ "Vbc= 173.20\n",
+ "Angle = -120.00 v \n",
+ "Vca= 173.20\n",
+ "Angle = 120.00 v \n",
+ "The line-neutral voltages are\n",
+ "Van= 86.60\n",
+ "Angle = -1718.92 v \n",
+ "Vbn= 100.00\n",
+ "Angle = -150.00 v \n",
+ "Vcn= 100.00\n",
+ "Angle = 90.00 v \n",
+ "Load Impedance ZL = 10.00\n",
+ "Angle = 20.00 v \n",
+ "The resulting current in each phase\n",
+ "Ian= 6.43\n",
+ "Angle = -2864.83 v \n",
+ "Ibn= 10.00\n",
+ "Angle = -150.00 v \n",
+ "Icn= 10.00\n",
+ "Angle = 70.00 v \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3, Page No 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Vll = 4.4e3\n",
+ "Vln=Vll /math.sqrt(3)\n",
+ "Zline=1.4*complex(math.cos(75* math.pi/180),math.sin(75*math.pi/180))\n",
+ "Van = Vln*complex(math.cos(0),math.sin(0))\n",
+ "Zload = 20*complex(math.cos(30*math.pi/180),math.sin(30*math.pi/180))\n",
+ "print(\" Given line-line voltage = %.4f V \" %Vll)\n",
+ "print(\" Line-neutral voltage = %.4f V \" %Vln)\n",
+ "\n",
+ "\n",
+ "#'/_' this symbol has been used to specify angle\n",
+ "\n",
+ "print( \"Impedance of the load = {0:.2f}\".format(abs(Zload.real)))\n",
+ "print(\"Angle = %.2f ohms \" %(math.degrees(math.atan2(Zload.imag,Zload.real))))\n",
+ "print( \"Impedance of the line = {0:.2f}\".format(abs(Zline.real)))\n",
+ "print(\"Angle = %.2f ohms \" %(math.degrees(math.atan2(Zline.imag,Zline.real))))\n",
+ "\n",
+ "#Calculation of phase current\n",
+ "Ian = Van / Zload\n",
+ "print( \"Van = {0:.2f}\".format(abs(Van.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Van.imag,Van.real))))\n",
+ "print( \"Ian = {0:.2f}\".format(abs(Ian.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Ian.imag,Ian.real))))\n",
+ "\n",
+ "#Calculation of line-neutral voltage at the substation\n",
+ "Vltn = Van + Ian * Zline\n",
+ "\n",
+ "\n",
+ "#Magnitude of the voltage at the substation bus\n",
+ "magVl = math.sqrt(3) * abs(Vltn)\n",
+ "\n",
+ "#Results\n",
+ "print( \"The line to neutral voltage at the substation = {0:.2f} \".format(abs(Vltn.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vltn.imag,Vltn.real))))\n",
+ "print(\" The magnitude of the voltage at the substation bus = %.4f V\" %magVl)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Given line-line voltage = 4400.0000 V \n",
+ " Line-neutral voltage = 2540.3412 V \n",
+ "Impedance of the load = 17.32\n",
+ "Angle = 30.00 ohms \n",
+ "Impedance of the line = 0.36\n",
+ "Angle = 75.00 ohms \n",
+ "Van = 2540.34\n",
+ "Angle = 0.00 v \n",
+ "Ian = 110.00\n",
+ "Angle = -30.00 v \n",
+ "The line to neutral voltage at the substation = 2666.08 \n",
+ "Angle = 2.70 v \n",
+ " The magnitude of the voltage at the substation bus = 4622.9218 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4, Page No 32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Vll = 4.4e3\n",
+ "Zline = 1.4*complex(math.cos(75*math.pi/180),math.sin(75*math.pi/180))\n",
+ "Zload = 20*complex(math.cos(30*math.pi/180),math.sin(30*math.pi/180))\n",
+ "Vbase = Vll\n",
+ "Ibase = 127\n",
+ "Zbase = (Vbase / math.sqrt(3)) / Ibase \n",
+ "\n",
+ "#Calculations\n",
+ "#Displaying the given values and the base values\n",
+ "print(\" Given line-line voltage = %.4f V \" %Vll)\n",
+ "print( \"Impedance of the load = {0:.2f}\".format(abs(Zload.real)))\n",
+ "print(\"Angle = %.2f ohms \" %(math.degrees(math.atan2(Zload.imag,Zload.real))))\n",
+ "print( \"Impedance of the line = {0:.2f}\".format(abs(Zline.real)))\n",
+ "print(\"Angle = %.2f ohms \" %(math.degrees(math.atan2(Zline.imag,Zline.real))))\n",
+ "print(\" Base Voltage = %.4f V \" %Vbase)\n",
+ "print(\" Base Current = %.4f V \" %Ibase)\n",
+ "print(\" Base Impedance = %.4f V \" %Zbase)\n",
+ "Van = (Vll/math.sqrt(3))*complex(math.cos(0),math.sin(0))\n",
+ "Ian = Van / Zload\n",
+ "print( \"Van = {0:.2f}\".format(abs(Van.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Van.imag,Van.real))))\n",
+ "print( \"Ian = {0:.2f}\".format(abs(Ian.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Ian.imag,Ian.real))))\n",
+ "\n",
+ "#Calculation of per-unit quantities\n",
+ "V_pu = Vll / Vbase\n",
+ "I_pu = Ian / Ibase\n",
+ "Zline_pu = Zline / Zbase\n",
+ "Zload_pu = Zload / Zbase\n",
+ "Van_pu = V_pu + I_pu * Zline_pu\n",
+ "print('Per-unit Quantities')\n",
+ "print( \"Per Unit line-line voltage = {0:.2f}\".format(abs(V_pu.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_pu.imag,V_pu.real))))\n",
+ "print( \"Per Unit line-neutral current = {0:.2f}\".format(abs(I_pu.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(I_pu.imag,I_pu.real))))\n",
+ "print( \"Per Unit line-neutral voltage = {0:.2f}\".format(abs(V_pu.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Van_pu.imag,Van_pu.real))))\n",
+ "print( \"Per Unit line impedance = {0:.2f}\".format(abs(Zline_pu.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Zline_pu.imag,Zline_pu.real))))\n",
+ "print( \"Per Unit load impedance = {0:.2f}\".format(abs(Zload_pu.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Zload_pu.imag,Zload_pu.real))))\n",
+ "\n",
+ "\n",
+ "#Calculation of line-neutral and line-line voltage\n",
+ "Vln = abs(Van_pu) * Vll / math.sqrt(3)\n",
+ "VLL = abs(Van_pu) * Vll\n",
+ "\n",
+ "#Results\n",
+ "print( \"The line to neutral voltage at the substation , VLN = {0:.2f}\".format(abs(Vln.real)))\n",
+ "print(\"Angle = %.2f V \" %(math.degrees(math.atan2(Vln.imag,Vln.real))))\n",
+ "print(\" The magnitude of the voltage at the substation bus , VLL= %.4f V\" %VLL)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Given line-line voltage = 4400.0000 V \n",
+ "Impedance of the load = 17.32\n",
+ "Angle = 30.00 ohms \n",
+ "Impedance of the line = 0.36\n",
+ "Angle = 75.00 ohms \n",
+ " Base Voltage = 4400.0000 V \n",
+ " Base Current = 127.0000 V \n",
+ " Base Impedance = 20.0027 V \n",
+ "Van = 2540.34\n",
+ "Angle = 0.00 v \n",
+ "Ian = 110.00\n",
+ "Angle = -30.00 v \n",
+ "Per-unit Quantities\n",
+ "Per Unit line-line voltage = 1.00\n",
+ "Angle = 0.00 per unit \n",
+ "Per Unit line-neutral current = 0.87\n",
+ "Angle = -30.00 per unit \n",
+ "Per Unit line-neutral voltage = 1.00\n",
+ "Angle = 2.70 per unit \n",
+ "Per Unit line impedance = 0.02\n",
+ "Angle = 75.00 per unit \n",
+ "Per Unit load impedance = 0.87\n",
+ "Angle = 30.00 per unit \n",
+ "The line to neutral voltage at the substation , VLN = 2669.05\n",
+ "Angle = 0.00 V \n",
+ " The magnitude of the voltage at the substation bus , VLL= 4622.9218 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5 Page No 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "\n",
+ "pu_Z_given = 0.25\n",
+ "base_kV_given = 18\n",
+ "base_kV_new = 20.0\n",
+ "base_kVA_new = 100.0\n",
+ "base_kVA_given = 500.0\n",
+ "\n",
+ "#Calculations\n",
+ "X11=(pu_Z_given * (base_kV_given/base_kV_new)**2 * (base_kVA_new/base_kVA_given))\n",
+ "\n",
+ "#Results\n",
+ "print('Per-Unit Znew = per-unit Zgiven * (base kVgiven/base kVnew)**2 * (base kVAnew/base kVAgiven)')\n",
+ "print(' = 0.25 * (18/20)**2 * (100/500)')\n",
+ "print(\" Per-Unit Znew = %.4f per unit\" %X11)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Per-Unit Znew = per-unit Zgiven * (base kVgiven/base kVnew)**2 * (base kVAnew/base kVAgiven)\n",
+ " = 0.25 * (18/20)**2 * (100/500)\n",
+ " Per-Unit Znew = 0.0405 per unit\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo02_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo02_1.ipynb
new file mode 100755
index 00000000..660f7921
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo02_1.ipynb
@@ -0,0 +1,411 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 02 : Basic Concepts"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1, Page No 21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy\n",
+ "#initialisation of variables\n",
+ "E1=complex(100,0)\n",
+ "E2=complex(86.6,50)\n",
+ "Z=complex(5)\n",
+ "X=5.0\n",
+ "print(\" Value of voltage source one designated as a machine 1 = {0:.5f}+{1:.5f}i v\".format(E1.real, E1.imag))\n",
+ "print(\" Value of voltage source two designated as a machine 2 = {0:.5f}+{1:.5f}i v\".format(E2.real, E2.imag))\n",
+ "print(\" Impedance connected = %.4f ohms \" %abs(Z))\n",
+ "\n",
+ "\n",
+ "#Calculation Of Current\n",
+ "I=(E1-E2)/Z\n",
+ "print(\" Current through the impedance = {0:.5f}+{1:.5f}i A\".format(I.real, I.imag))\n",
+ "\n",
+ "#Calculations\n",
+ "#Calculation Of Power\n",
+ "M1=E1*numpy.conj(I)\n",
+ "print('Machine one Power = %.2f' %M1)\n",
+ "M2=E2*numpy.conj(I)\n",
+ "print('Machine Two Power = %.2f' %M2)\n",
+ "\n",
+ "\n",
+ "#Calculation Of Reactive Power Required By Inductive Reactance\n",
+ "RP=(abs(I))**2*X\n",
+ "print(\" Reactive power required by inductive reactance i.e, impedance = %.4f VAR \" %RP)\n",
+ "print(\" Machine 1 consumes energy at the rate of %.4f W \" %abs(M1.real))\n",
+ "print(\" Machine 2 generates energy at the rate of %.4f W \" %abs(M2.real))\n",
+ "print(\" Machine 1 supplies reactive power at the rate of %.4f VAR \" %(M1.imag))\n",
+ "print(\" Machine 2 supplies reactive power at the rate of %.4f VAR \" %abs(M2.imag))\n",
+ "print(\" Reactive power required by inductive reactance i.e, impedance = Sum of reactive power supplied by machine 1 + reactive power supplied by machine 2 = %.4f VAR \"%RP)\n",
+ "print('Real Power consumed by impedance is Zero')\n",
+ "print('The real power generated by machine two is transferred to machine one')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Value of voltage source one designated as a machine 1 = 100.00000+0.00000i v\n",
+ " Value of voltage source two designated as a machine 2 = 86.60000+50.00000i v\n",
+ " Impedance connected = 5.0000 ohms \n",
+ " Current through the impedance = 2.68000+-10.00000i A\n",
+ "Machine one Power = 268.00\n",
+ "Machine Two Power = -267.91\n",
+ " Reactive power required by inductive reactance i.e, impedance = 535.9120 VAR \n",
+ " Machine 1 consumes energy at the rate of 268.0000 W \n",
+ " Machine 2 generates energy at the rate of 267.9120 W \n",
+ " Machine 1 supplies reactive power at the rate of 1000.0000 VAR \n",
+ " Machine 2 supplies reactive power at the rate of 1000.0000 VAR \n",
+ " Reactive power required by inductive reactance i.e, impedance = Sum of reactive power supplied by machine 1 + reactive power supplied by machine 2 = 535.9120 VAR \n",
+ "Real Power consumed by impedance is Zero\n",
+ "The real power generated by machine two is transferred to machine one\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2 Page No 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Vab = 173.2*complex(math.cos(0),math.sin(0))\n",
+ "Vbc = 173.2*complex(math.cos(240*math.pi/180),math.sin(240*math.pi/180))\n",
+ "Vca = 173.2*complex(math.cos(120*math.pi/180),math.sin(120*math.pi/180))\n",
+ "print('The given line-line voltages are')\n",
+ "\n",
+ "\n",
+ "#'/_' this symbol has been used to show angle\n",
+ "print( \"Vab= {0:.2f}\".format(abs(Vab.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vab.imag,Vab.real))*180/math.pi))\n",
+ "print( \"Vbc= {0:.2f}\".format(abs(Vbc)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vbc.imag,Vbc.real))))\n",
+ "print( \"Vca= {0:.2f}\".format(abs(Vca)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vca.imag,Vca.real))))\n",
+ "\n",
+ "#Calculation of line-neutral voltage\n",
+ "Van = (Vab/math.sqrt(3)/complex(0.866,0.5))\n",
+ "Vbn = (Vbc/math.sqrt(3)/complex(0.866,0.5))\n",
+ "Vcn = (Vca/math.sqrt(3)/complex(0.866,0.5))\n",
+ "print('The line-neutral voltages are')\n",
+ "print( \"Van= {0:.2f}\".format(abs(Van.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Van.imag,Van.real))*180/math.pi))\n",
+ "print( \"Vbn= {0:.2f}\".format(abs(Vbn)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vbn.imag,Vbn.real))))\n",
+ "print( \"Vcn= {0:.2f}\".format(abs(Vcn)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vcn.imag,Vcn.real))))\n",
+ "ZL = 10*complex(math.cos(20*math.pi/180),math.sin(20*math.pi/180))\n",
+ "\n",
+ "print( \"Load Impedance ZL = {0:.2f}\".format(abs(ZL)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(ZL.imag,ZL.real))))\n",
+ "\n",
+ "#Calculation of line-neutral current\n",
+ "Ian = Van / ZL\n",
+ "Ibn = Vbn / ZL\n",
+ "Icn = Vcn / ZL\n",
+ "\n",
+ "#Results\n",
+ "print('The resulting current in each phase')\n",
+ "print( \"Ian= {0:.2f}\".format(abs(Ian.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Ian.imag,Ian.real))*180/math.pi))\n",
+ "print( \"Ibn= {0:.2f}\".format(abs(Ibn)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vbn.imag,Vbn.real))))\n",
+ "print( \"Icn= {0:.2f}\".format(abs(Icn)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Icn.imag,Icn.real))))\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The given line-line voltages are\n",
+ "Vab= 173.20\n",
+ "Angle = 0.00 v \n",
+ "Vbc= 173.20\n",
+ "Angle = -120.00 v \n",
+ "Vca= 173.20\n",
+ "Angle = 120.00 v \n",
+ "The line-neutral voltages are\n",
+ "Van= 86.60\n",
+ "Angle = -1718.92 v \n",
+ "Vbn= 100.00\n",
+ "Angle = -150.00 v \n",
+ "Vcn= 100.00\n",
+ "Angle = 90.00 v \n",
+ "Load Impedance ZL = 10.00\n",
+ "Angle = 20.00 v \n",
+ "The resulting current in each phase\n",
+ "Ian= 6.43\n",
+ "Angle = -2864.83 v \n",
+ "Ibn= 10.00\n",
+ "Angle = -150.00 v \n",
+ "Icn= 10.00\n",
+ "Angle = 70.00 v \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3, Page No 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Vll = 4.4e3\n",
+ "Vln=Vll /math.sqrt(3)\n",
+ "Zline=1.4*complex(math.cos(75* math.pi/180),math.sin(75*math.pi/180))\n",
+ "Van = Vln*complex(math.cos(0),math.sin(0))\n",
+ "Zload = 20*complex(math.cos(30*math.pi/180),math.sin(30*math.pi/180))\n",
+ "print(\" Given line-line voltage = %.4f V \" %Vll)\n",
+ "print(\" Line-neutral voltage = %.4f V \" %Vln)\n",
+ "\n",
+ "\n",
+ "#'/_' this symbol has been used to specify angle\n",
+ "\n",
+ "print( \"Impedance of the load = {0:.2f}\".format(abs(Zload.real)))\n",
+ "print(\"Angle = %.2f ohms \" %(math.degrees(math.atan2(Zload.imag,Zload.real))))\n",
+ "print( \"Impedance of the line = {0:.2f}\".format(abs(Zline.real)))\n",
+ "print(\"Angle = %.2f ohms \" %(math.degrees(math.atan2(Zline.imag,Zline.real))))\n",
+ "\n",
+ "#Calculation of phase current\n",
+ "Ian = Van / Zload\n",
+ "print( \"Van = {0:.2f}\".format(abs(Van.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Van.imag,Van.real))))\n",
+ "print( \"Ian = {0:.2f}\".format(abs(Ian.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Ian.imag,Ian.real))))\n",
+ "\n",
+ "#Calculation of line-neutral voltage at the substation\n",
+ "Vltn = Van + Ian * Zline\n",
+ "\n",
+ "\n",
+ "#Magnitude of the voltage at the substation bus\n",
+ "magVl = math.sqrt(3) * abs(Vltn)\n",
+ "\n",
+ "#Results\n",
+ "print( \"The line to neutral voltage at the substation = {0:.2f} \".format(abs(Vltn.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Vltn.imag,Vltn.real))))\n",
+ "print(\" The magnitude of the voltage at the substation bus = %.4f V\" %magVl)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Given line-line voltage = 4400.0000 V \n",
+ " Line-neutral voltage = 2540.3412 V \n",
+ "Impedance of the load = 17.32\n",
+ "Angle = 30.00 ohms \n",
+ "Impedance of the line = 0.36\n",
+ "Angle = 75.00 ohms \n",
+ "Van = 2540.34\n",
+ "Angle = 0.00 v \n",
+ "Ian = 110.00\n",
+ "Angle = -30.00 v \n",
+ "The line to neutral voltage at the substation = 2666.08 \n",
+ "Angle = 2.70 v \n",
+ " The magnitude of the voltage at the substation bus = 4622.9218 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4, Page No 32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Vll = 4.4e3\n",
+ "Zline = 1.4*complex(math.cos(75*math.pi/180),math.sin(75*math.pi/180))\n",
+ "Zload = 20*complex(math.cos(30*math.pi/180),math.sin(30*math.pi/180))\n",
+ "Vbase = Vll\n",
+ "Ibase = 127\n",
+ "Zbase = (Vbase / math.sqrt(3)) / Ibase \n",
+ "\n",
+ "#Calculations\n",
+ "#Displaying the given values and the base values\n",
+ "print(\" Given line-line voltage = %.4f V \" %Vll)\n",
+ "print( \"Impedance of the load = {0:.2f}\".format(abs(Zload.real)))\n",
+ "print(\"Angle = %.2f ohms \" %(math.degrees(math.atan2(Zload.imag,Zload.real))))\n",
+ "print( \"Impedance of the line = {0:.2f}\".format(abs(Zline.real)))\n",
+ "print(\"Angle = %.2f ohms \" %(math.degrees(math.atan2(Zline.imag,Zline.real))))\n",
+ "print(\" Base Voltage = %.4f V \" %Vbase)\n",
+ "print(\" Base Current = %.4f V \" %Ibase)\n",
+ "print(\" Base Impedance = %.4f V \" %Zbase)\n",
+ "Van = (Vll/math.sqrt(3))*complex(math.cos(0),math.sin(0))\n",
+ "Ian = Van / Zload\n",
+ "print( \"Van = {0:.2f}\".format(abs(Van.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Van.imag,Van.real))))\n",
+ "print( \"Ian = {0:.2f}\".format(abs(Ian.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Ian.imag,Ian.real))))\n",
+ "\n",
+ "#Calculation of per-unit quantities\n",
+ "V_pu = Vll / Vbase\n",
+ "I_pu = Ian / Ibase\n",
+ "Zline_pu = Zline / Zbase\n",
+ "Zload_pu = Zload / Zbase\n",
+ "Van_pu = V_pu + I_pu * Zline_pu\n",
+ "print('Per-unit Quantities')\n",
+ "print( \"Per Unit line-line voltage = {0:.2f}\".format(abs(V_pu.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_pu.imag,V_pu.real))))\n",
+ "print( \"Per Unit line-neutral current = {0:.2f}\".format(abs(I_pu.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(I_pu.imag,I_pu.real))))\n",
+ "print( \"Per Unit line-neutral voltage = {0:.2f}\".format(abs(V_pu.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Van_pu.imag,Van_pu.real))))\n",
+ "print( \"Per Unit line impedance = {0:.2f}\".format(abs(Zline_pu.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Zline_pu.imag,Zline_pu.real))))\n",
+ "print( \"Per Unit load impedance = {0:.2f}\".format(abs(Zload_pu.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Zload_pu.imag,Zload_pu.real))))\n",
+ "\n",
+ "\n",
+ "#Calculation of line-neutral and line-line voltage\n",
+ "Vln = abs(Van_pu) * Vll / math.sqrt(3)\n",
+ "VLL = abs(Van_pu) * Vll\n",
+ "\n",
+ "#Results\n",
+ "print( \"The line to neutral voltage at the substation , VLN = {0:.2f}\".format(abs(Vln.real)))\n",
+ "print(\"Angle = %.2f V \" %(math.degrees(math.atan2(Vln.imag,Vln.real))))\n",
+ "print(\" The magnitude of the voltage at the substation bus , VLL= %.4f V\" %VLL)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Given line-line voltage = 4400.0000 V \n",
+ "Impedance of the load = 17.32\n",
+ "Angle = 30.00 ohms \n",
+ "Impedance of the line = 0.36\n",
+ "Angle = 75.00 ohms \n",
+ " Base Voltage = 4400.0000 V \n",
+ " Base Current = 127.0000 V \n",
+ " Base Impedance = 20.0027 V \n",
+ "Van = 2540.34\n",
+ "Angle = 0.00 v \n",
+ "Ian = 110.00\n",
+ "Angle = -30.00 v \n",
+ "Per-unit Quantities\n",
+ "Per Unit line-line voltage = 1.00\n",
+ "Angle = 0.00 per unit \n",
+ "Per Unit line-neutral current = 0.87\n",
+ "Angle = -30.00 per unit \n",
+ "Per Unit line-neutral voltage = 1.00\n",
+ "Angle = 2.70 per unit \n",
+ "Per Unit line impedance = 0.02\n",
+ "Angle = 75.00 per unit \n",
+ "Per Unit load impedance = 0.87\n",
+ "Angle = 30.00 per unit \n",
+ "The line to neutral voltage at the substation , VLN = 2669.05\n",
+ "Angle = 0.00 V \n",
+ " The magnitude of the voltage at the substation bus , VLL= 4622.9218 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5 Page No 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "\n",
+ "pu_Z_given = 0.25\n",
+ "base_kV_given = 18\n",
+ "base_kV_new = 20.0\n",
+ "base_kVA_new = 100.0\n",
+ "base_kVA_given = 500.0\n",
+ "\n",
+ "#Calculations\n",
+ "X11=(pu_Z_given * (base_kV_given/base_kV_new)**2 * (base_kVA_new/base_kVA_given))\n",
+ "\n",
+ "#Results\n",
+ "print('Per-Unit Znew = per-unit Zgiven * (base kVgiven/base kVnew)**2 * (base kVAnew/base kVAgiven)')\n",
+ "print(' = 0.25 * (18/20)**2 * (100/500)')\n",
+ "print(\" Per-Unit Znew = %.4f per unit\" %X11)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Per-Unit Znew = per-unit Zgiven * (base kVgiven/base kVnew)**2 * (base kVAnew/base kVAgiven)\n",
+ " = 0.25 * (18/20)**2 * (100/500)\n",
+ " Per-Unit Znew = 0.0405 per unit\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo03.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo03.ipynb
new file mode 100755
index 00000000..f1537709
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo03.ipynb
@@ -0,0 +1,393 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 03 : Series Impedance Of Transmission Lines"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1, Page No 42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "R_dc = 0.01558 \t\t#in ohm per 1000 ft at 20 degree Celsius\n",
+ "R_ac = 0.0956 \t\t#in ohm per mi at 50 degree Celsius\n",
+ "A = 1113000 \t\t#in cmil\n",
+ "l = 1000.0\t\t\t#in ft\n",
+ "p = 17 \t\t\t\t# $p$(rho) = 2.83e-8 ohm.m = 17 ohm.cmil per ft\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "#Verification of dc resistance\n",
+ "R_0_1 = p*l*1.02/A \t\t\t\t\t#1.02 is to account for 2\\% increase in spiraling\n",
+ "print(\" The dc resistance at 20 degree Celsius = %f ohm per 1000 ft\" %R_0_1)\n",
+ "T = 228.0\t\t\t#in degree Celsius\n",
+ "t1 = 50.0\t\t\t#in degree Celsius\n",
+ "t2 = 20.0\t\t\t#in degree Celsius\n",
+ "\n",
+ "#to obtain dc resistance at 50 degree celsius\n",
+ "R0 = R_0_1 * (T + t1)/(T + t2)\n",
+ "\n",
+ "print(\" The dc resistance at 50 degree Celsius = %f ohm per 1000 ft \" %R0)\n",
+ "\n",
+ "R = R_ac / 5.280e3 \t\t\t\t#to convert ohm per mi to ohm per ft,ac resistance\n",
+ "R_0 = R0 / 1000.0 \t\t\t\t#to convert ohm per 1000 ft to ohm per ft,dc resistance\n",
+ "\n",
+ "#Results\n",
+ "# to calculate ratio of ac to dc resistance\n",
+ "print(\" Ratio of ac to dc resistance = %.3f \" %(R / R_0))\n",
+ "print(\" Skin effect causes a %.1f increase in resistance.\"%(((R/R_0)-1)*100))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The dc resistance at 20 degree Celsius = 0.015580 ohm per 1000 ft\n",
+ " The dc resistance at 50 degree Celsius = 0.017464 ohm per 1000 ft \n",
+ " Ratio of ac to dc resistance = 1.037 \n",
+ " Skin effect causes a 3.7 increase in resistance.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.2, Page No 55"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "r_x = 0.25e-2\t\t\t#radius of circuit in m,composed of 3 wires a,b,c\n",
+ "r_y = 0.50e-2\t\t\t#radius of return circuit in m,composed of 2 wires d,e\n",
+ "d_c = 9.0\t\t\t\t#distance between the two circuits\n",
+ "d_w = 6.0\t\t\t\t#distance between wires of same circuit\n",
+ "\n",
+ "#Calculations\n",
+ "#To find GMD between sides X and Y\n",
+ "D_ad = d_c\n",
+ "D_be = D_ad\n",
+ "D_ae = math.sqrt(d_w**2+d_c**2)\n",
+ "D_bd = D_ae\n",
+ "D_ce = D_ae\n",
+ "D_cd = math.sqrt(d_c**2+(2*d_w)**2)\n",
+ "#GMD is given by\n",
+ "D_m = (D_ad * D_ae * D_bd * D_be * D_cd * D_ce)**(1.0/6)\n",
+ "print(\" The GMD between the sides X and Y = %.3f m \" %D_m)\n",
+ "\n",
+ "#To find GMR for the side X\n",
+ "D_aa = r_x * 0.7788#multiplication by 0.7788 to adjust the radiuss \n",
+ " #in order to account for internal flux\n",
+ "D_ab = d_w\n",
+ "D_ac = 2 * d_w\n",
+ "D_ba = d_w\n",
+ "D_bb = D_aa\n",
+ "D_bc = D_ab\n",
+ "D_ca = D_ac\n",
+ "D_cb = D_ab\n",
+ "D_cc = D_aa\n",
+ "\n",
+ "#GMR for side X\n",
+ "D_s_x = (D_aa * D_ab * D_ac * D_ba * D_bb * D_bc * D_ca * D_cb * D_cc)**(1/9)\n",
+ "print(\" The GMR for side X = %.3f m \" %D_s_x)\n",
+ "\n",
+ "#To find GMR for the side Y\n",
+ "D_dd = r_y * 0.7788\n",
+ "D_de = d_w\n",
+ "D_ee = D_dd\n",
+ "D_ed = D_de\n",
+ "\n",
+ "#GMR for side Y\n",
+ "D_s_y = (D_dd * D_de * D_ee * D_ed)**(1/4)\n",
+ "print(\" The GMR for side Y = %.3f m \" %D_s_y)\n",
+ "\n",
+ "#Inductance\n",
+ "L_x = 2e-7 *math.log(D_m / D_s_x)\n",
+ "L_y = 2e-7 *math.log(D_m / D_s_y)\n",
+ "L = L_x + L_y\n",
+ "\n",
+ "#Results\n",
+ "print(\" Inductance of side X = %.3fe-7 H/m \" %(L_x*10**7))\n",
+ "print(\" Inductance of side Y = %.3fe-7 H/m \" %(L_y*10**7))\n",
+ "print(\" Inductance of Complete line = %.3fe-7 H/m\" %(L*10**7))\n",
+ "print(\" = %.2f mH/mi \" %(L*1609e3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The GMD between the sides X and Y = 10.743 m \n",
+ " The GMR for side X = 1.000 m \n",
+ " The GMR for side Y = 1.000 m \n",
+ " Inductance of side X = 4.749e-7 H/m \n",
+ " Inductance of side Y = 4.749e-7 H/m \n",
+ " Inductance of Complete line = 9.497e-7 H/m\n",
+ " = 1.53 mH/mi \n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3, Page No 57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "f = 60.0\t #in Hz\n",
+ "D_m = 20.0\t #in ft\n",
+ "\n",
+ "#Inductive Reactance with D_s known\n",
+ "D_s = 0.0217\t\t\t #in ft from Table A(appendix).1\n",
+ "X_L = 2.022e-3*f*math.log(D_m/D_s)\n",
+ "print('With GMR known')\n",
+ "print(\"Inductive Reactance for one conductor,XL = %.3f ohm/mi \" %X_L)\n",
+ "\n",
+ "#Calculations\n",
+ "#Inductive Reactance with D_s not known\n",
+ "print('With GMR not known')\n",
+ "X_a = 0.465 \t\t\t#inductive reactance at 1 ft spacingin ohm per mi from Table A.1\n",
+ "X_d = 0.3635 \t\t\t#inductive reactance spacing factor in ohm per mi from Table A.1\n",
+ "\n",
+ "#Results\n",
+ "print(\" Inductive reactance of one conductor = %.4f ohm/mi \" %(X_a + X_d))\n",
+ "print('Since conductors composing the two lines are identical')\n",
+ "XL = 2 * (X_a + X_d)\n",
+ "print(\" Inductive reactance,XL = %.3f ohm/mi \" %(XL))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "With GMR known\n",
+ "Inductive Reactance for one conductor,XL = 0.828 ohm/mi \n",
+ "With GMR not known\n",
+ " Inductive reactance of one conductor = 0.8285 ohm/mi \n",
+ "Since conductors composing the two lines are identical\n",
+ " Inductive reactance,XL = 1.657 ohm/mi \n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.4 Page No 60"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "#Given Values\n",
+ "D_12 = 20.0\n",
+ "D_23 = D_12\n",
+ "D_31 = 38.0\n",
+ "#in ft\n",
+ "f=60.0\t#frequency in Hz\n",
+ "#From Table A.1\n",
+ "D_s = 0.0373\t#in ft\n",
+ "X_a = 0.399\t\t#inductive reactance at 1 ft spacing in ohm/mi\n",
+ "X_d = 0.389\t\t#inductive reactance spacing factor in ohm/mi for 24.8ft\n",
+ "\n",
+ "#Calculations\n",
+ "D_eq =(D_12*D_23*D_31)**(1.0/3)\n",
+ "L = 2e-7 * math.log(D_eq/D_s)*10**7\n",
+ "X_L=2*math.pi*f*L*10**-7*1609.0\t\t#multiplication by 1609 to convert to ohm/mi\n",
+ "\n",
+ "#Results\n",
+ "print(\"Inductance = %.4fe-7 H/m \" %L)\n",
+ "print(\"Inductive reactance = %.4f ohm/mi/phase\" %X_L)\n",
+ "X_L1 = X_a + X_d\n",
+ "print(\"Inductive reactance from Xa and Xd = %.4f ohm/mi/phase \" %X_L1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inductance = 12.9969e-7 H/m \n",
+ "Inductive reactance = 0.7884 ohm/mi/phase\n",
+ "Inductive reactance from Xa and Xd = 0.7880 ohm/mi/phase \n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.5, Page No 62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "d = 0.45\t\t#in m\n",
+ "l = 160.0\t \t#in km\n",
+ "d_12 = 8.0\n",
+ "d_23 = 8.0\n",
+ "d_31 = 16\t#in m\n",
+ "f = 60#in Hz\n",
+ "P = 100#in MVA\n",
+ "V = 345#in kV\n",
+ "#From Table A1\n",
+ "D_s = 0.0466#in ft\n",
+ "\n",
+ "#Calculations\n",
+ "D_b_s = math.sqrt(D_s * 0.3048 * d)#multiplicqation by 0.3048 is to convert D_s\n",
+ "#from ft to m\n",
+ "D_eq=(d_12*d_23*d_31)**(1/3)\n",
+ "X_L=2*math.pi*f*2e-7*10**3*math.log(D_eq/D_b_s)\t\t#10^3 to get ohm/km\n",
+ "#To find per unit series reactance\n",
+ "Z = V**2/P\t\t\t#Base Impedance\n",
+ "X = X_L*l/Z\t\t\t#per unit series reactance\n",
+ "\n",
+ "#Results\n",
+ "print(\" Inductive reactance = %.3f ohm/km/phase \" %X_L)\n",
+ "print(\" Base Impedance = %.0f ohm \" %Z)\n",
+ "print(\" Per unit series resistance of the line = %.3f per unit \" %X)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Inductive reactance = 0.190 ohm/km/phase \n",
+ " Base Impedance = 1190 ohm \n",
+ " Per unit series resistance of the line = 0.026 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.6, Page No 152"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "f = 60.0\t#in Hz\n",
+ "\n",
+ "#From Table A.1\n",
+ "D_s = 0.0229 #in ft\n",
+ "#Distances from given figure 3.15\n",
+ "d_a_c = 18.0\n",
+ "d_c_a = d_a_c\n",
+ "d_b_b = 21.0\n",
+ "d = 10.0\t\t#distance between conductors\n",
+ "d_a_b = math.sqrt(d**2 + (d_b_b - 19.5)**2)\n",
+ "d_a_b1 = math.sqrt(d**2 + (d_b_b - 1.5)**2)\n",
+ "d_aa1_actual = math.sqrt((d * 2)**2 + d_a_c**2)\n",
+ "d_bb1_actual = d_b_b\n",
+ "d_cc1_actual = d_aa1_actual\n",
+ "d_aa1_pos = math.sqrt(d_aa1_actual * D_s)\n",
+ "d_bb1_pos = math.sqrt(d_bb1_actual * D_s)\n",
+ "d_cc1_pos = math.sqrt(d_cc1_actual * D_s)\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "#GMD's between phases\n",
+ "D_p_ab = ((d_a_b * d_a_b1)**(2*1.0/4))#in ft\n",
+ "D_p_bc = D_p_ab\n",
+ "D_p_ca = (((d*2) * d_c_a)**(2*1.0/4))#in ft\n",
+ "D_eq = (D_p_ab * D_p_bc * D_p_ca)**(1.0/3)#in ft\n",
+ "print(\" Equivalent GMD = %.1f ft \"%D_eq)\n",
+ "\n",
+ "#GMR\n",
+ "D_p_s = (d_aa1_pos * d_bb1_pos * d_cc1_pos)**(1.0/3)\n",
+ "print(\" GMR = %.3f ft \" %D_p_s)\n",
+ "\n",
+ "#Inductance\n",
+ "L = 2e-7*math.log(D_eq/D_p_s)\n",
+ "X_L = 2*math.pi*f*L*1609\t\t\t#multiplication by 1609 is to convert to ohm/mi\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print(\" The Inductive reactance = %.3f ohm/mi/phase \" %X_L)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Equivalent GMD = 16.1 ft \n",
+ " GMR = 0.753 ft \n",
+ " The Inductive reactance = 0.372 ohm/mi/phase \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo03_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo03_1.ipynb
new file mode 100755
index 00000000..f1537709
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo03_1.ipynb
@@ -0,0 +1,393 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 03 : Series Impedance Of Transmission Lines"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1, Page No 42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "R_dc = 0.01558 \t\t#in ohm per 1000 ft at 20 degree Celsius\n",
+ "R_ac = 0.0956 \t\t#in ohm per mi at 50 degree Celsius\n",
+ "A = 1113000 \t\t#in cmil\n",
+ "l = 1000.0\t\t\t#in ft\n",
+ "p = 17 \t\t\t\t# $p$(rho) = 2.83e-8 ohm.m = 17 ohm.cmil per ft\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "#Verification of dc resistance\n",
+ "R_0_1 = p*l*1.02/A \t\t\t\t\t#1.02 is to account for 2\\% increase in spiraling\n",
+ "print(\" The dc resistance at 20 degree Celsius = %f ohm per 1000 ft\" %R_0_1)\n",
+ "T = 228.0\t\t\t#in degree Celsius\n",
+ "t1 = 50.0\t\t\t#in degree Celsius\n",
+ "t2 = 20.0\t\t\t#in degree Celsius\n",
+ "\n",
+ "#to obtain dc resistance at 50 degree celsius\n",
+ "R0 = R_0_1 * (T + t1)/(T + t2)\n",
+ "\n",
+ "print(\" The dc resistance at 50 degree Celsius = %f ohm per 1000 ft \" %R0)\n",
+ "\n",
+ "R = R_ac / 5.280e3 \t\t\t\t#to convert ohm per mi to ohm per ft,ac resistance\n",
+ "R_0 = R0 / 1000.0 \t\t\t\t#to convert ohm per 1000 ft to ohm per ft,dc resistance\n",
+ "\n",
+ "#Results\n",
+ "# to calculate ratio of ac to dc resistance\n",
+ "print(\" Ratio of ac to dc resistance = %.3f \" %(R / R_0))\n",
+ "print(\" Skin effect causes a %.1f increase in resistance.\"%(((R/R_0)-1)*100))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The dc resistance at 20 degree Celsius = 0.015580 ohm per 1000 ft\n",
+ " The dc resistance at 50 degree Celsius = 0.017464 ohm per 1000 ft \n",
+ " Ratio of ac to dc resistance = 1.037 \n",
+ " Skin effect causes a 3.7 increase in resistance.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.2, Page No 55"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "r_x = 0.25e-2\t\t\t#radius of circuit in m,composed of 3 wires a,b,c\n",
+ "r_y = 0.50e-2\t\t\t#radius of return circuit in m,composed of 2 wires d,e\n",
+ "d_c = 9.0\t\t\t\t#distance between the two circuits\n",
+ "d_w = 6.0\t\t\t\t#distance between wires of same circuit\n",
+ "\n",
+ "#Calculations\n",
+ "#To find GMD between sides X and Y\n",
+ "D_ad = d_c\n",
+ "D_be = D_ad\n",
+ "D_ae = math.sqrt(d_w**2+d_c**2)\n",
+ "D_bd = D_ae\n",
+ "D_ce = D_ae\n",
+ "D_cd = math.sqrt(d_c**2+(2*d_w)**2)\n",
+ "#GMD is given by\n",
+ "D_m = (D_ad * D_ae * D_bd * D_be * D_cd * D_ce)**(1.0/6)\n",
+ "print(\" The GMD between the sides X and Y = %.3f m \" %D_m)\n",
+ "\n",
+ "#To find GMR for the side X\n",
+ "D_aa = r_x * 0.7788#multiplication by 0.7788 to adjust the radiuss \n",
+ " #in order to account for internal flux\n",
+ "D_ab = d_w\n",
+ "D_ac = 2 * d_w\n",
+ "D_ba = d_w\n",
+ "D_bb = D_aa\n",
+ "D_bc = D_ab\n",
+ "D_ca = D_ac\n",
+ "D_cb = D_ab\n",
+ "D_cc = D_aa\n",
+ "\n",
+ "#GMR for side X\n",
+ "D_s_x = (D_aa * D_ab * D_ac * D_ba * D_bb * D_bc * D_ca * D_cb * D_cc)**(1/9)\n",
+ "print(\" The GMR for side X = %.3f m \" %D_s_x)\n",
+ "\n",
+ "#To find GMR for the side Y\n",
+ "D_dd = r_y * 0.7788\n",
+ "D_de = d_w\n",
+ "D_ee = D_dd\n",
+ "D_ed = D_de\n",
+ "\n",
+ "#GMR for side Y\n",
+ "D_s_y = (D_dd * D_de * D_ee * D_ed)**(1/4)\n",
+ "print(\" The GMR for side Y = %.3f m \" %D_s_y)\n",
+ "\n",
+ "#Inductance\n",
+ "L_x = 2e-7 *math.log(D_m / D_s_x)\n",
+ "L_y = 2e-7 *math.log(D_m / D_s_y)\n",
+ "L = L_x + L_y\n",
+ "\n",
+ "#Results\n",
+ "print(\" Inductance of side X = %.3fe-7 H/m \" %(L_x*10**7))\n",
+ "print(\" Inductance of side Y = %.3fe-7 H/m \" %(L_y*10**7))\n",
+ "print(\" Inductance of Complete line = %.3fe-7 H/m\" %(L*10**7))\n",
+ "print(\" = %.2f mH/mi \" %(L*1609e3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The GMD between the sides X and Y = 10.743 m \n",
+ " The GMR for side X = 1.000 m \n",
+ " The GMR for side Y = 1.000 m \n",
+ " Inductance of side X = 4.749e-7 H/m \n",
+ " Inductance of side Y = 4.749e-7 H/m \n",
+ " Inductance of Complete line = 9.497e-7 H/m\n",
+ " = 1.53 mH/mi \n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3, Page No 57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "f = 60.0\t #in Hz\n",
+ "D_m = 20.0\t #in ft\n",
+ "\n",
+ "#Inductive Reactance with D_s known\n",
+ "D_s = 0.0217\t\t\t #in ft from Table A(appendix).1\n",
+ "X_L = 2.022e-3*f*math.log(D_m/D_s)\n",
+ "print('With GMR known')\n",
+ "print(\"Inductive Reactance for one conductor,XL = %.3f ohm/mi \" %X_L)\n",
+ "\n",
+ "#Calculations\n",
+ "#Inductive Reactance with D_s not known\n",
+ "print('With GMR not known')\n",
+ "X_a = 0.465 \t\t\t#inductive reactance at 1 ft spacingin ohm per mi from Table A.1\n",
+ "X_d = 0.3635 \t\t\t#inductive reactance spacing factor in ohm per mi from Table A.1\n",
+ "\n",
+ "#Results\n",
+ "print(\" Inductive reactance of one conductor = %.4f ohm/mi \" %(X_a + X_d))\n",
+ "print('Since conductors composing the two lines are identical')\n",
+ "XL = 2 * (X_a + X_d)\n",
+ "print(\" Inductive reactance,XL = %.3f ohm/mi \" %(XL))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "With GMR known\n",
+ "Inductive Reactance for one conductor,XL = 0.828 ohm/mi \n",
+ "With GMR not known\n",
+ " Inductive reactance of one conductor = 0.8285 ohm/mi \n",
+ "Since conductors composing the two lines are identical\n",
+ " Inductive reactance,XL = 1.657 ohm/mi \n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.4 Page No 60"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "#Given Values\n",
+ "D_12 = 20.0\n",
+ "D_23 = D_12\n",
+ "D_31 = 38.0\n",
+ "#in ft\n",
+ "f=60.0\t#frequency in Hz\n",
+ "#From Table A.1\n",
+ "D_s = 0.0373\t#in ft\n",
+ "X_a = 0.399\t\t#inductive reactance at 1 ft spacing in ohm/mi\n",
+ "X_d = 0.389\t\t#inductive reactance spacing factor in ohm/mi for 24.8ft\n",
+ "\n",
+ "#Calculations\n",
+ "D_eq =(D_12*D_23*D_31)**(1.0/3)\n",
+ "L = 2e-7 * math.log(D_eq/D_s)*10**7\n",
+ "X_L=2*math.pi*f*L*10**-7*1609.0\t\t#multiplication by 1609 to convert to ohm/mi\n",
+ "\n",
+ "#Results\n",
+ "print(\"Inductance = %.4fe-7 H/m \" %L)\n",
+ "print(\"Inductive reactance = %.4f ohm/mi/phase\" %X_L)\n",
+ "X_L1 = X_a + X_d\n",
+ "print(\"Inductive reactance from Xa and Xd = %.4f ohm/mi/phase \" %X_L1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inductance = 12.9969e-7 H/m \n",
+ "Inductive reactance = 0.7884 ohm/mi/phase\n",
+ "Inductive reactance from Xa and Xd = 0.7880 ohm/mi/phase \n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.5, Page No 62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "d = 0.45\t\t#in m\n",
+ "l = 160.0\t \t#in km\n",
+ "d_12 = 8.0\n",
+ "d_23 = 8.0\n",
+ "d_31 = 16\t#in m\n",
+ "f = 60#in Hz\n",
+ "P = 100#in MVA\n",
+ "V = 345#in kV\n",
+ "#From Table A1\n",
+ "D_s = 0.0466#in ft\n",
+ "\n",
+ "#Calculations\n",
+ "D_b_s = math.sqrt(D_s * 0.3048 * d)#multiplicqation by 0.3048 is to convert D_s\n",
+ "#from ft to m\n",
+ "D_eq=(d_12*d_23*d_31)**(1/3)\n",
+ "X_L=2*math.pi*f*2e-7*10**3*math.log(D_eq/D_b_s)\t\t#10^3 to get ohm/km\n",
+ "#To find per unit series reactance\n",
+ "Z = V**2/P\t\t\t#Base Impedance\n",
+ "X = X_L*l/Z\t\t\t#per unit series reactance\n",
+ "\n",
+ "#Results\n",
+ "print(\" Inductive reactance = %.3f ohm/km/phase \" %X_L)\n",
+ "print(\" Base Impedance = %.0f ohm \" %Z)\n",
+ "print(\" Per unit series resistance of the line = %.3f per unit \" %X)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Inductive reactance = 0.190 ohm/km/phase \n",
+ " Base Impedance = 1190 ohm \n",
+ " Per unit series resistance of the line = 0.026 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.6, Page No 152"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "f = 60.0\t#in Hz\n",
+ "\n",
+ "#From Table A.1\n",
+ "D_s = 0.0229 #in ft\n",
+ "#Distances from given figure 3.15\n",
+ "d_a_c = 18.0\n",
+ "d_c_a = d_a_c\n",
+ "d_b_b = 21.0\n",
+ "d = 10.0\t\t#distance between conductors\n",
+ "d_a_b = math.sqrt(d**2 + (d_b_b - 19.5)**2)\n",
+ "d_a_b1 = math.sqrt(d**2 + (d_b_b - 1.5)**2)\n",
+ "d_aa1_actual = math.sqrt((d * 2)**2 + d_a_c**2)\n",
+ "d_bb1_actual = d_b_b\n",
+ "d_cc1_actual = d_aa1_actual\n",
+ "d_aa1_pos = math.sqrt(d_aa1_actual * D_s)\n",
+ "d_bb1_pos = math.sqrt(d_bb1_actual * D_s)\n",
+ "d_cc1_pos = math.sqrt(d_cc1_actual * D_s)\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "#GMD's between phases\n",
+ "D_p_ab = ((d_a_b * d_a_b1)**(2*1.0/4))#in ft\n",
+ "D_p_bc = D_p_ab\n",
+ "D_p_ca = (((d*2) * d_c_a)**(2*1.0/4))#in ft\n",
+ "D_eq = (D_p_ab * D_p_bc * D_p_ca)**(1.0/3)#in ft\n",
+ "print(\" Equivalent GMD = %.1f ft \"%D_eq)\n",
+ "\n",
+ "#GMR\n",
+ "D_p_s = (d_aa1_pos * d_bb1_pos * d_cc1_pos)**(1.0/3)\n",
+ "print(\" GMR = %.3f ft \" %D_p_s)\n",
+ "\n",
+ "#Inductance\n",
+ "L = 2e-7*math.log(D_eq/D_p_s)\n",
+ "X_L = 2*math.pi*f*L*1609\t\t\t#multiplication by 1609 is to convert to ohm/mi\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print(\" The Inductive reactance = %.3f ohm/mi/phase \" %X_L)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Equivalent GMD = 16.1 ft \n",
+ " GMR = 0.753 ft \n",
+ " The Inductive reactance = 0.372 ohm/mi/phase \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo04.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo04.ipynb
new file mode 100755
index 00000000..ed8e34c8
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo04.ipynb
@@ -0,0 +1,257 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 04 : Capacitance Of Transmission Lines"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1, Page No 75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "D = 20.0 #in ft\n",
+ "f = 60.0 #in Hz\n",
+ "\n",
+ "#From Table A.1 and A.3\n",
+ "d = 0.642 \t\t\t#in inches\n",
+ "X_a = 0.1074e6 \t\t#in ohm-mi\n",
+ "X_d = 0.0889e6 \t\t#in ohm-mi\n",
+ "\n",
+ "#finding radius\n",
+ "r = d/(2*12) \t\t#divided by 12 convert in to ft\n",
+ "\n",
+ "#Calculations\n",
+ "print('Calculations using conductor spacing and radius')\n",
+ "X_c = 1.779 * math.log(D/r)/f\n",
+ "B_c = 1 / X_c\n",
+ "print(\" Capactive reatance = %.4fe6 ohm mi to neutral \" %X_c)\n",
+ "print(\" Capactive susceptance = %.4fe-6 mho/mi to neutral \" %B_c)\n",
+ "\n",
+ "#calculations using capacitive reactance at 1-ft spacing and spacing factor\n",
+ "print('Calculations using capacitive reactance at 1-ft spacing and spacing factor')\n",
+ "X_c1 = X_a + X_d\n",
+ "print(\" Capactive reatance = %.4fe6 ohm mi per conductor \" %(X_c1/10**6))\n",
+ "X_c11 = 2 * X_c1\n",
+ "B_c1 = 1 / X_c11\n",
+ "\n",
+ "#Results\n",
+ "print(\" Line-to-line capactive reatance = %.4fe6 ohm mi \" %(X_c11/10**6))\n",
+ "print(\" Line-to-line capactive susceptance = %.4fe-6 mho mi \" %(B_c1*10**6))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Calculations using conductor spacing and radius\n",
+ " Capactive reatance = 0.1962e6 ohm mi to neutral \n",
+ " Capactive susceptance = 5.0970e-6 mho/mi to neutral \n",
+ "Calculations using capacitive reactance at 1-ft spacing and spacing factor\n",
+ " Capactive reatance = 0.1963e6 ohm mi per conductor \n",
+ " Line-to-line capactive reatance = 0.3926e6 ohm mi \n",
+ " Line-to-line capactive susceptance = 2.5471e-6 mho mi \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2, Page No 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "D_12 = 20.0\t\t\t#in ft\n",
+ "D_23 = D_12\n",
+ "D_31 = 38.0\t\t\t#in ft\n",
+ "f = 60.0\t\t\t#in Hz\n",
+ "V = 220e3\t\t\t#in volts\n",
+ "l = 175\t\t\t\t#in mi\n",
+ "k = 8.85e-12\t\t#permittivity in F/m\n",
+ "#From tables A.1 and A.3\n",
+ "d = 1.108#in inches\n",
+ "X_a1 = 0.0912e6#in ohm mi\n",
+ "X_d1 = 0.0952e6#in ohm mi\n",
+ "\n",
+ "#Calculations\n",
+ "r = d / ( 2 * 12)#division by 12 to convert in to ft\n",
+ "D_eq = (D_12*D_23*D_31)**(1.0/3)\n",
+ "C_n = (2*math.pi*k)/math.log(D_eq/r)\n",
+ "X_c = 1.0/(2*math.pi*f*C_n*1609)\t\t#division by 1609 to convert to ohm mi\n",
+ "\n",
+ "print(\" Capacitance = %.4fe-12 F/m \" %(C_n*1e12))\n",
+ "print(\" Capacitive reactance = %.4fe6 ohm mi \" %(X_c/1e6))\n",
+ "\n",
+ "#Calculations From tables\n",
+ "X_c1 = X_a1 + X_d1\n",
+ "print('Using capacitive reactance at 1-ft spacing and spacing factor')\n",
+ "print(\" Capacitive reactance = %.4fe6 ohm mi \" %(X_c1/1e6))\n",
+ "X_c_l = X_c1/l\t\t\t#Capacitive reactance for 175mi\n",
+ "I_chg = 2*math.pi*f*V*C_n*1609/math.sqrt(3.0)\n",
+ "I_chg_l = I_chg * l\n",
+ "Q =math.sqrt(3)*V*I_chg_l\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print('For a lenght of 175mi')\n",
+ "print(\" Capacitive reactance = %.4f ohm to neutral \" %X_c_l)\n",
+ "print(\" Charging current per mile = %.3f A/mi \" %I_chg)\n",
+ "print('For a lenght of 175mi')\n",
+ "print(\" Charging current = %.0f A \" %I_chg_l)\n",
+ "print(\" Total charging megavolt-amperes = %.1f Mvar \" %(Q/1e6))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Capacitance = 8.8472e-12 F/m \n",
+ " Capacitive reactance = 0.1863e6 ohm mi \n",
+ "Using capacitive reactance at 1-ft spacing and spacing factor\n",
+ " Capacitive reactance = 0.1864e6 ohm mi \n",
+ "For a lenght of 175mi\n",
+ " Capacitive reactance = 1065.1429 ohm to neutral \n",
+ " Charging current per mile = 0.682 A/mi \n",
+ "For a lenght of 175mi\n",
+ " Charging current = 119 A \n",
+ " Total charging megavolt-amperes = 45.5 Mvar \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3, Page No 85"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "d = 0.45 #in m\n",
+ "k = 8.85e-12 #in F/m\n",
+ "D_ab = 8 #in m\n",
+ "D_bc = D_ab\n",
+ "D_ca = 16 #in m\n",
+ "f = 60 #in Hz\n",
+ "\n",
+ "#From tables\n",
+ "D = 1.382 #in inches\n",
+ "\n",
+ "#Calculations\n",
+ "r = D*0.3048/(2.0*12) #divison by 12 to convert in to ft\n",
+ " #multiplication by 0.3048 to convert ft to m\n",
+ "D_b_sC = math.sqrt( r * d)\n",
+ "D_eq = (D_ab * D_bc * D_ca)**(1/3)\n",
+ "C_m = 2* math.pi*k/math.log(D_eq / D_b_sC)\n",
+ "X_c = 1e-3/(2*math.pi*f*C_m) #1e-3 #to convert m to km\n",
+ "\n",
+ "#Results\n",
+ "print(\" Capacitance = %.3fe-12 F/m \" %(C_m * 1e12))\n",
+ "print(\" Capacitive reactance = %.4fe6 ohm km per phase to neutral\" %(X_c/1e6))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Capacitance = 22.972e-12 F/m \n",
+ " Capacitive reactance = 0.1155e6 ohm km per phase to neutral\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4 Page No 85"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "f = 60.0\t\t#in Hz\n",
+ "k = 8.85e-12\t#in F/m\n",
+ "D_eq = 16.1\t\t#in ft\n",
+ "D_a_a1 = 26.9\n",
+ "D_b_b1 = 21.0\n",
+ "D_c_c1 = D_a_a1 #in ft\n",
+ "\n",
+ "#From Table A.1\n",
+ "d = 0.680#in inches\n",
+ "\n",
+ "#calculations\n",
+ "r = d /(2*12)\n",
+ "D_p_sC = (math.sqrt(D_a_a1 * r) * math.sqrt(D_b_b1 * r) * math.sqrt(D_c_c1 * r))**(1.0/3)\n",
+ "C_n = 2 * math.pi * k / math.log(D_eq / D_p_sC)\n",
+ "B_c = 2 * math.pi * f * C_n * 1609.0\t#1609 to convert from m to mi\n",
+ "\n",
+ "#Results\n",
+ "print(\"printprint Capacitance = %.3fe-12 F/m printprint\" %(C_n*1e12))\n",
+ "print(\"printprint Capacitive susceptance = %.2fe-6 mho per mi per phase to neutral\" %(B_c*1e6))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "printprint Capacitance = 18.812e-12 F/m printprint\n",
+ "printprint Capacitive susceptance = 11.41e-6 mho per mi per phase to neutral\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo04_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo04_1.ipynb
new file mode 100755
index 00000000..ed8e34c8
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo04_1.ipynb
@@ -0,0 +1,257 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 04 : Capacitance Of Transmission Lines"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1, Page No 75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "D = 20.0 #in ft\n",
+ "f = 60.0 #in Hz\n",
+ "\n",
+ "#From Table A.1 and A.3\n",
+ "d = 0.642 \t\t\t#in inches\n",
+ "X_a = 0.1074e6 \t\t#in ohm-mi\n",
+ "X_d = 0.0889e6 \t\t#in ohm-mi\n",
+ "\n",
+ "#finding radius\n",
+ "r = d/(2*12) \t\t#divided by 12 convert in to ft\n",
+ "\n",
+ "#Calculations\n",
+ "print('Calculations using conductor spacing and radius')\n",
+ "X_c = 1.779 * math.log(D/r)/f\n",
+ "B_c = 1 / X_c\n",
+ "print(\" Capactive reatance = %.4fe6 ohm mi to neutral \" %X_c)\n",
+ "print(\" Capactive susceptance = %.4fe-6 mho/mi to neutral \" %B_c)\n",
+ "\n",
+ "#calculations using capacitive reactance at 1-ft spacing and spacing factor\n",
+ "print('Calculations using capacitive reactance at 1-ft spacing and spacing factor')\n",
+ "X_c1 = X_a + X_d\n",
+ "print(\" Capactive reatance = %.4fe6 ohm mi per conductor \" %(X_c1/10**6))\n",
+ "X_c11 = 2 * X_c1\n",
+ "B_c1 = 1 / X_c11\n",
+ "\n",
+ "#Results\n",
+ "print(\" Line-to-line capactive reatance = %.4fe6 ohm mi \" %(X_c11/10**6))\n",
+ "print(\" Line-to-line capactive susceptance = %.4fe-6 mho mi \" %(B_c1*10**6))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Calculations using conductor spacing and radius\n",
+ " Capactive reatance = 0.1962e6 ohm mi to neutral \n",
+ " Capactive susceptance = 5.0970e-6 mho/mi to neutral \n",
+ "Calculations using capacitive reactance at 1-ft spacing and spacing factor\n",
+ " Capactive reatance = 0.1963e6 ohm mi per conductor \n",
+ " Line-to-line capactive reatance = 0.3926e6 ohm mi \n",
+ " Line-to-line capactive susceptance = 2.5471e-6 mho mi \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2, Page No 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "D_12 = 20.0\t\t\t#in ft\n",
+ "D_23 = D_12\n",
+ "D_31 = 38.0\t\t\t#in ft\n",
+ "f = 60.0\t\t\t#in Hz\n",
+ "V = 220e3\t\t\t#in volts\n",
+ "l = 175\t\t\t\t#in mi\n",
+ "k = 8.85e-12\t\t#permittivity in F/m\n",
+ "#From tables A.1 and A.3\n",
+ "d = 1.108#in inches\n",
+ "X_a1 = 0.0912e6#in ohm mi\n",
+ "X_d1 = 0.0952e6#in ohm mi\n",
+ "\n",
+ "#Calculations\n",
+ "r = d / ( 2 * 12)#division by 12 to convert in to ft\n",
+ "D_eq = (D_12*D_23*D_31)**(1.0/3)\n",
+ "C_n = (2*math.pi*k)/math.log(D_eq/r)\n",
+ "X_c = 1.0/(2*math.pi*f*C_n*1609)\t\t#division by 1609 to convert to ohm mi\n",
+ "\n",
+ "print(\" Capacitance = %.4fe-12 F/m \" %(C_n*1e12))\n",
+ "print(\" Capacitive reactance = %.4fe6 ohm mi \" %(X_c/1e6))\n",
+ "\n",
+ "#Calculations From tables\n",
+ "X_c1 = X_a1 + X_d1\n",
+ "print('Using capacitive reactance at 1-ft spacing and spacing factor')\n",
+ "print(\" Capacitive reactance = %.4fe6 ohm mi \" %(X_c1/1e6))\n",
+ "X_c_l = X_c1/l\t\t\t#Capacitive reactance for 175mi\n",
+ "I_chg = 2*math.pi*f*V*C_n*1609/math.sqrt(3.0)\n",
+ "I_chg_l = I_chg * l\n",
+ "Q =math.sqrt(3)*V*I_chg_l\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print('For a lenght of 175mi')\n",
+ "print(\" Capacitive reactance = %.4f ohm to neutral \" %X_c_l)\n",
+ "print(\" Charging current per mile = %.3f A/mi \" %I_chg)\n",
+ "print('For a lenght of 175mi')\n",
+ "print(\" Charging current = %.0f A \" %I_chg_l)\n",
+ "print(\" Total charging megavolt-amperes = %.1f Mvar \" %(Q/1e6))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Capacitance = 8.8472e-12 F/m \n",
+ " Capacitive reactance = 0.1863e6 ohm mi \n",
+ "Using capacitive reactance at 1-ft spacing and spacing factor\n",
+ " Capacitive reactance = 0.1864e6 ohm mi \n",
+ "For a lenght of 175mi\n",
+ " Capacitive reactance = 1065.1429 ohm to neutral \n",
+ " Charging current per mile = 0.682 A/mi \n",
+ "For a lenght of 175mi\n",
+ " Charging current = 119 A \n",
+ " Total charging megavolt-amperes = 45.5 Mvar \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3, Page No 85"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "d = 0.45 #in m\n",
+ "k = 8.85e-12 #in F/m\n",
+ "D_ab = 8 #in m\n",
+ "D_bc = D_ab\n",
+ "D_ca = 16 #in m\n",
+ "f = 60 #in Hz\n",
+ "\n",
+ "#From tables\n",
+ "D = 1.382 #in inches\n",
+ "\n",
+ "#Calculations\n",
+ "r = D*0.3048/(2.0*12) #divison by 12 to convert in to ft\n",
+ " #multiplication by 0.3048 to convert ft to m\n",
+ "D_b_sC = math.sqrt( r * d)\n",
+ "D_eq = (D_ab * D_bc * D_ca)**(1/3)\n",
+ "C_m = 2* math.pi*k/math.log(D_eq / D_b_sC)\n",
+ "X_c = 1e-3/(2*math.pi*f*C_m) #1e-3 #to convert m to km\n",
+ "\n",
+ "#Results\n",
+ "print(\" Capacitance = %.3fe-12 F/m \" %(C_m * 1e12))\n",
+ "print(\" Capacitive reactance = %.4fe6 ohm km per phase to neutral\" %(X_c/1e6))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Capacitance = 22.972e-12 F/m \n",
+ " Capacitive reactance = 0.1155e6 ohm km per phase to neutral\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4 Page No 85"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "f = 60.0\t\t#in Hz\n",
+ "k = 8.85e-12\t#in F/m\n",
+ "D_eq = 16.1\t\t#in ft\n",
+ "D_a_a1 = 26.9\n",
+ "D_b_b1 = 21.0\n",
+ "D_c_c1 = D_a_a1 #in ft\n",
+ "\n",
+ "#From Table A.1\n",
+ "d = 0.680#in inches\n",
+ "\n",
+ "#calculations\n",
+ "r = d /(2*12)\n",
+ "D_p_sC = (math.sqrt(D_a_a1 * r) * math.sqrt(D_b_b1 * r) * math.sqrt(D_c_c1 * r))**(1.0/3)\n",
+ "C_n = 2 * math.pi * k / math.log(D_eq / D_p_sC)\n",
+ "B_c = 2 * math.pi * f * C_n * 1609.0\t#1609 to convert from m to mi\n",
+ "\n",
+ "#Results\n",
+ "print(\"printprint Capacitance = %.3fe-12 F/m printprint\" %(C_n*1e12))\n",
+ "print(\"printprint Capacitive susceptance = %.2fe-6 mho per mi per phase to neutral\" %(B_c*1e6))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "printprint Capacitance = 18.812e-12 F/m printprint\n",
+ "printprint Capacitive susceptance = 11.41e-6 mho per mi per phase to neutral\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo05.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo05.ipynb
new file mode 100755
index 00000000..c282663f
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo05.ipynb
@@ -0,0 +1,428 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 05 : Current And Voltage Relations On A Transmission Line"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.1, Page No 101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "D_12 = 23.8 \n",
+ "D_23 = 23.8 \n",
+ "D_31 = 47.6 #in ft\n",
+ "l = 230.0 #in mi\n",
+ "f = 60 #in Hz\n",
+ "P = 125e6 #in W\n",
+ "V = 215e3 #in V\n",
+ "\n",
+ "#Calculations\n",
+ "D_eq = (D_12 * D_23 * D_31)**(1.0/3)\n",
+ "\n",
+ "#From Table A.1 and A.2 for 30ft Rook\n",
+ "#z = R + i(Xa + Xd)\n",
+ "z = complex(0.1603,(0.415+0.4127))\n",
+ "\n",
+ "#From Table A.1 and A.3 for 30ft Rook\n",
+ "y = complex(1e-6 / ( 0.0950 + 0.1008))\n",
+ "\n",
+ "#Calculations\n",
+ "yl = 0.0455806 + complex(0.4750793)\n",
+ "Z_c = 404.43706 - complex(38.802997)\n",
+ "V_r = V / math.sqrt(3)\n",
+ "I_r = P / (math.sqrt(3)*V)\n",
+ "print(\" Sending end voltage= {0:.2f}+{1:.2f}i\".format(yl.real, yl.imag))\n",
+ "\n",
+ "math.cosh_yl = math.cosh(yl.real) * math.cos(yl.imag) + complex(math.sinh(yl.real)) * math.sin(yl.imag)\n",
+ "math.sinh_yl = math.sinh(yl.real) * math.cos(yl.imag) + complex(math.cosh(yl.real)) * math.sin(yl.imag)\n",
+ "\n",
+ "V_s = V_r * math.cosh_yl + I_r * Z_c * math.sinh_yl\n",
+ "I_s = I_r * math.cosh_yl + V_r * math.sinh_yl / Z_c\n",
+ "print( \"Sending end voltage = {0:.2f}\".format(abs(V_s.real)))\n",
+ "print(\"Angle = %.2f V \" %(math.degrees(math.atan2(V_s.imag,V_s.real))))\n",
+ "print( \"Sending end voltage = {0:.2f}\".format(abs(I_s.real)))\n",
+ "print(\"Angle = %.2f V \" %(math.degrees(math.atan2(I_s.imag,I_s.real))))\n",
+ "\n",
+ "Line_voltage = math.sqrt(3) * abs(V_s) / 1000.0 \n",
+ "Line_current = abs(I_s)\n",
+ "Power_factor = math.cos(math.atan2(V_s.imag,V_s.real) - math.atan2(I_s.imag,I_s.real))\n",
+ "Power = math.sqrt(3) * Line_voltage * Line_current * Power_factor\n",
+ "\n",
+ "#Results\n",
+ "print(\" Sending end line voltage = %.1f kV \" %Line_voltage)\n",
+ "print(\" Sending end line current = %.1f A \" %Line_current)\n",
+ "print(\" Sending end power = %.0f kW \" %Power)\n",
+ "\n",
+ "voltage_regulation = (((abs(V_s)/abs(math.cosh_yl)) - V_r)/V_r)*100\n",
+ "print(\" Voltage Regulation = %.1f percent \" %voltage_regulation)\n",
+ "B = 0.0020656\n",
+ "y1 = 2 * math.pi / B\n",
+ "Velocity = f * y1\n",
+ "print(\" Wavelength = %.0f mi \" %y1)\n",
+ "print(\" Velocity = %.0f mi/s \" %Velocity)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Sending end voltage= 0.52+0.00i\n",
+ "Sending end voltage = 208167.01\n",
+ "Angle = 0.00 V \n",
+ "Sending end voltage = 567.06\n",
+ "Angle = 0.00 V \n",
+ " Sending end line voltage = 360.6 kV \n",
+ " Sending end line current = 567.1 A \n",
+ " Sending end power = 354129 kW \n",
+ " Voltage Regulation = 47.3 percent \n",
+ " Wavelength = 3042 mi \n",
+ " Velocity = 182509 mi/s \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2, Page No 103"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "l = 230.0 #in mi\n",
+ "f = 60.0 #in Hz\n",
+ "P = 125e6 #in W\n",
+ "V = 215e3 #in V\n",
+ "\n",
+ "#From Table A.1 and A.2 for 30ft Rook\n",
+ "#z = R + i(Xa + Xd)\n",
+ "z = 0.1603 + complex(0.415+0.4127)\n",
+ "\n",
+ "#From Table A.1 and A.3 for 30ft Rook\n",
+ "y = complex(1e-6 / ( 0.0950 + 0.1008))\n",
+ "\n",
+ "#Calculations\n",
+ "yl = 0.0455806 + complex(0.4750793)\n",
+ "Z_c = 404.43706 - complex(38.802997)\n",
+ "V_r = V / math.sqrt(3)\n",
+ "I_r = P / (math.sqrt(3)*V)\n",
+ "\n",
+ "math.cosh_yl = math.cosh(yl.real) * math.cos(yl.imag) + complex(math.sinh(yl.real)) * math.sin(yl.imag)\n",
+ "math.sinh_yl = math.sinh(yl.real) * math.cos(yl.imag) + complex(math.cosh(yl.real)) * math.sin(yl.imag)\n",
+ "\n",
+ "#Per Unit calculations\n",
+ "Base_impedance = V**2 / P\n",
+ "Base_current = P / (math.sqrt(3)*V)\n",
+ "Z_c_pu = Z_c / Base_impedance\n",
+ "V_r_pu = (V / math.sqrt(3)) / (V / math.sqrt(3))\n",
+ "I_r_pu = (P / (math.sqrt(3)*V)) / Base_current\n",
+ "\n",
+ "V_s_pu = V_r_pu * math.cosh_yl + I_r_pu * Z_c_pu * math.sinh_yl\n",
+ "I_s_pu = I_r_pu * math.cosh_yl + V_r_pu * math.sinh_yl / Z_c_pu\n",
+ "\n",
+ "Line_voltage = abs(V_s_pu)*V / 1000\n",
+ "Line_current = abs(I_s_pu)*Base_current\n",
+ "\n",
+ "#Results\n",
+ "print(\" Sending end line voltage = %.1f V \" %Line_voltage)\n",
+ "print(\" Sending end line current = %.1f A \" %Line_current)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Sending end line voltage = 360.6 V \n",
+ " Sending end line current = 567.1 A \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.3, Page No 106"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "l = 230 #in mi\n",
+ "f = 60 #in Hz\n",
+ "P = 125e6 #in W\n",
+ "V = 215e3 #in V\n",
+ "\n",
+ "#From Table A.1 and A.2 for 30ft Rook\n",
+ "#z = R + complex(Xa + Xd)\n",
+ "z = 0.1603 + complex(0.415+0.4127)\n",
+ "\n",
+ "#From Table A.1 and A.3 for 30ft Rook\n",
+ "y = complex(1e-6 / ( 0.0950 + 0.1008))\n",
+ "\n",
+ "#Calculations\n",
+ "yl = 0.0455806 + complex(0.4750793)\n",
+ "Z_c = 404.43706 - complex(38.802997)\n",
+ "cosh_yl = math.cosh(yl.real) * math.cos(yl.imag) + complex(math.sinh(yl.real)) * math.sin(yl.imag)\n",
+ "sinh_yl = math.sinh(yl.real) * math.cos(yl.imag) + complex(math.cosh(yl.real)) * math.sin(yl.imag)\n",
+ "\n",
+ "#Equivalent pi circuit\n",
+ "Z1 = Z_c * sinh_yl\n",
+ "Y1_2 = (cosh_yl - 1)/(Z_c * sinh_yl)\n",
+ "\n",
+ "#Results\n",
+ "print('Equivalent PI circuit')\n",
+ "print( \"Total series impedance of the line = {0:.2f}\".format(abs(Z1.real)))\n",
+ "print(\"Angle = %.2f ohm in series arm \" %(math.degrees(math.atan2(Z1.imag,Z1.real))))\n",
+ "print( \"Total Shunt admittance of the line = {0:.2f}\".format(abs(Y1_2.real)))\n",
+ "print(\"Angle = %.2f ohm in each shunt arm \" %(math.degrees(math.atan2(Y1_2.imag,Y1_2.real))))\n",
+ "\n",
+ "\n",
+ "#Nominal pi Circuit\n",
+ "Z = l * z\n",
+ "Y_2 = y * l/2\n",
+ "\n",
+ "print('Nominal PI circuit')\n",
+ "print( \"Total series impedance of the line = {0:.2f}\".format(abs(Z.real)))\n",
+ "print(\"Angle = %.2f ohm in series arm \" %(math.degrees(math.atan2(Z.imag,Z.real))))\n",
+ "print( \"Total Shunt admittance of the line = {0:.2f}\".format(abs(Y_2.real)))\n",
+ "print(\"Angle = %.2f ohm in each shunt arm \" %(math.degrees(math.atan2(Y_2.imag,Y_2.real))))\n",
+ "\n",
+ "zp = ((abs(Z)-abs(Z1))/abs(Z1))*100\n",
+ "yp = ((abs(Y_2)-abs(Y1_2))/abs(Y1_2))*100\n",
+ "\n",
+ "print(\" Line impedace of the series arm of the nominal pi exceeds that of equivalent pi by %.1f percent \" %zp)\n",
+ "print(\" Conductance of the shunt arms of the nominal pi is %.0f percent less than that of equivalent pi \" %abs(yp))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Equivalent PI circuit\n",
+ "Total series impedance of the line = 199.09\n",
+ "Angle = 0.00 ohm in series arm \n",
+ "Total Shunt admittance of the line = 0.00\n",
+ "Angle = 0.00 ohm in each shunt arm \n",
+ "Nominal PI circuit\n",
+ "Total series impedance of the line = 227.24\n",
+ "Angle = 0.00 ohm in series arm \n",
+ "Total Shunt admittance of the line = 0.00\n",
+ "Angle = 0.00 ohm in each shunt arm \n",
+ " Line impedace of the series arm of the nominal pi exceeds that of equivalent pi by 14.1 percent \n",
+ " Conductance of the shunt arms of the nominal pi is 16 percent less than that of equivalent pi \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4 Page No 111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "l = 230.0 #in mi\n",
+ "f = 60.0 #in Hz\n",
+ "P = 125e6 #in W\n",
+ "V = 215e3 #in V\n",
+ "\n",
+ "#From Table A.1 and A.2 for 30ft Rook\n",
+ "#z = R + i(Xa + Xd)\n",
+ "z = 0.1603 + complex(0.415+0.4127)\n",
+ "\n",
+ "#From Table A.1 and A.3 for 30ft Rook\n",
+ "y =complex(1e-6 / ( 0.0950 + 0.1008))\n",
+ "\n",
+ "#Calculations\n",
+ "yl = 0.0455806 + complex(0.4750793)\n",
+ "Z_c = 404.43706 - complex(38.802997)\n",
+ "\n",
+ "cosh_yl = math.cosh(yl.real) * math.cos(yl.imag) + complex(math.sinh(yl.real)) * math.sin(yl.imag)\n",
+ "sinh_yl = math.sinh(yl.real)*math.cos(yl.imag) + complex(math.cosh(yl.real)) * math.sin(yl.imag)\n",
+ "\n",
+ "#Equivalent pi circuit\n",
+ "Z1 = Z_c * sinh_yl\n",
+ "Y1_2 = (math.cosh_yl - 1)/(Z_c * sinh_yl)\n",
+ "A = cosh_yl\n",
+ "D = cosh_yl\n",
+ "B = Z1\n",
+ "C = sinh_yl / Z_c\n",
+ "\n",
+ "print('For an uncompensated line')\n",
+ "print( \"A = D = {0:.2f}\".format(abs(A.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(A.imag,A.real))*180/math.pi))\n",
+ "print( \"B = {0:.2f}\".format(abs(B.real)))\n",
+ "print(\"Angle = %.2f ohm \" %(math.degrees(math.atan2(B.imag,B.real))*180/math.pi))\n",
+ "print( \"C = {0:.2f}\".format(abs(C.real)))\n",
+ "print(\"Angle = %.2f ohm \" %(math.degrees(math.atan2(C.imag,C.real))*180/math.pi))\n",
+ "\n",
+ "#For a series compensation factor of 70%\n",
+ "cf = 0.7\n",
+ "B1 = Z1 - complex(cf) * l * (0.415 + 0.4127) #X_a = 0.415 ohm/mi,X_d = 0.4127 in\n",
+ "A1 = B1 * Y1_2 + 1\n",
+ "C1 = 2 * Y1_2 + B1 * (Y1_2)**2\n",
+ "\n",
+ "#Results\n",
+ "print('For a series compensation factor of 70%')\n",
+ "print( \"A = D = {0:.2f}\".format(abs(A1.real)))\n",
+ "print(\"Angle = %.2f \" %(math.degrees(math.atan2(A1.imag,A1.real))))\n",
+ "print( \"B = {0:.2f}\".format(abs(B1.real)))\n",
+ "print(\"Angle = %.2f ohm \" %(math.degrees(math.atan2(B1.imag,B1.real))))\n",
+ "print( \"C = {0:.2f}\".format(abs(C1.real)))\n",
+ "print(\"Angle = %.2f ohm \" %(math.degrees(math.atan2(C1.imag,C1.real))))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For an uncompensated line\n",
+ "A = D = 1.14\n",
+ "Angle = 0.00 v \n",
+ "B = 199.09\n",
+ "Angle = 0.00 ohm \n",
+ "C = 0.00\n",
+ "Angle = 0.00 ohm \n",
+ "For a series compensation factor of 70%\n",
+ "A = D = 1.05\n",
+ "Angle = 0.00 \n",
+ "B = 65.83\n",
+ "Angle = 0.00 ohm \n",
+ "C = 0.00\n",
+ "Angle = 0.00 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5, Page No 112"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "l = 230.0 #in mi\n",
+ "f = 60.0 #in Hz\n",
+ "P = 125e6 #in W\n",
+ "V = 215e3 #in V\n",
+ "\n",
+ "#From Table A.1 and A.2 for 30ft Rook\n",
+ "#z = R + i(Xa + Xd)\n",
+ "z = 0.1603 + complex(0.415+0.4127)\n",
+ "\n",
+ "#From Table A.1 and A.3 for 30ft Rook\n",
+ "y = complex(1e-6 / ( 0.0950 + 0.1008))\n",
+ "\n",
+ "#Calculations\n",
+ "yl = 0.0455806 + complex(0.4750793)\n",
+ "Z_c = 404.43706 - complex(38.802997)\n",
+ "V_r = V / math.sqrt(3)\n",
+ "I_r = P / (math.sqrt(3)*V)\n",
+ "\n",
+ "cosh_yl = math.cosh(yl.real) * math.cos(yl.imag) + complex(math.sinh(yl.real)) * math.sin(yl.imag)\n",
+ "sinh_yl = math.sinh(yl.real) * math.cos(yl.imag) + complex(math.cosh(yl.real)) * math.sin(yl.imag)\n",
+ "\n",
+ "V_s = V_r * cosh_yl + I_r * Z_c * sinh_yl\n",
+ "I_s = I_r * cosh_yl + V_r * sinh_yl / Z_c\n",
+ "\n",
+ "#Equivalent pi circuit\n",
+ "Z1 = Z_c * sinh_yl\n",
+ "Y1_2 = (cosh_yl - 1)/(Z_c * sinh_yl)\n",
+ "\n",
+ "#Total capacitive Susceptance\n",
+ "B_c = complex(y) * l\n",
+ "\n",
+ "#For 70% Compensation\n",
+ "cf = 0.7\n",
+ "B_L = - B_c * 0.7\n",
+ "\n",
+ "#From appendix\n",
+ "A = 1\n",
+ "D = 1\n",
+ "B = 0\n",
+ "C = -complex(B_L)\n",
+ "\n",
+ "\n",
+ "#From Table A.6 for combining two networks in series\n",
+ "A_eq = cosh_yl + Z1 * C\n",
+ "voltage_regulation = ((abs(V_s)/abs(A_eq))-V_r)*100.0/V_r\n",
+ "print(\" Voltage regulation in percent \")\n",
+ "print(voltage_regulation)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Voltage regulation in percent \n",
+ "28.7687144089\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo05_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo05_1.ipynb
new file mode 100755
index 00000000..c282663f
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo05_1.ipynb
@@ -0,0 +1,428 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 05 : Current And Voltage Relations On A Transmission Line"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.1, Page No 101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "D_12 = 23.8 \n",
+ "D_23 = 23.8 \n",
+ "D_31 = 47.6 #in ft\n",
+ "l = 230.0 #in mi\n",
+ "f = 60 #in Hz\n",
+ "P = 125e6 #in W\n",
+ "V = 215e3 #in V\n",
+ "\n",
+ "#Calculations\n",
+ "D_eq = (D_12 * D_23 * D_31)**(1.0/3)\n",
+ "\n",
+ "#From Table A.1 and A.2 for 30ft Rook\n",
+ "#z = R + i(Xa + Xd)\n",
+ "z = complex(0.1603,(0.415+0.4127))\n",
+ "\n",
+ "#From Table A.1 and A.3 for 30ft Rook\n",
+ "y = complex(1e-6 / ( 0.0950 + 0.1008))\n",
+ "\n",
+ "#Calculations\n",
+ "yl = 0.0455806 + complex(0.4750793)\n",
+ "Z_c = 404.43706 - complex(38.802997)\n",
+ "V_r = V / math.sqrt(3)\n",
+ "I_r = P / (math.sqrt(3)*V)\n",
+ "print(\" Sending end voltage= {0:.2f}+{1:.2f}i\".format(yl.real, yl.imag))\n",
+ "\n",
+ "math.cosh_yl = math.cosh(yl.real) * math.cos(yl.imag) + complex(math.sinh(yl.real)) * math.sin(yl.imag)\n",
+ "math.sinh_yl = math.sinh(yl.real) * math.cos(yl.imag) + complex(math.cosh(yl.real)) * math.sin(yl.imag)\n",
+ "\n",
+ "V_s = V_r * math.cosh_yl + I_r * Z_c * math.sinh_yl\n",
+ "I_s = I_r * math.cosh_yl + V_r * math.sinh_yl / Z_c\n",
+ "print( \"Sending end voltage = {0:.2f}\".format(abs(V_s.real)))\n",
+ "print(\"Angle = %.2f V \" %(math.degrees(math.atan2(V_s.imag,V_s.real))))\n",
+ "print( \"Sending end voltage = {0:.2f}\".format(abs(I_s.real)))\n",
+ "print(\"Angle = %.2f V \" %(math.degrees(math.atan2(I_s.imag,I_s.real))))\n",
+ "\n",
+ "Line_voltage = math.sqrt(3) * abs(V_s) / 1000.0 \n",
+ "Line_current = abs(I_s)\n",
+ "Power_factor = math.cos(math.atan2(V_s.imag,V_s.real) - math.atan2(I_s.imag,I_s.real))\n",
+ "Power = math.sqrt(3) * Line_voltage * Line_current * Power_factor\n",
+ "\n",
+ "#Results\n",
+ "print(\" Sending end line voltage = %.1f kV \" %Line_voltage)\n",
+ "print(\" Sending end line current = %.1f A \" %Line_current)\n",
+ "print(\" Sending end power = %.0f kW \" %Power)\n",
+ "\n",
+ "voltage_regulation = (((abs(V_s)/abs(math.cosh_yl)) - V_r)/V_r)*100\n",
+ "print(\" Voltage Regulation = %.1f percent \" %voltage_regulation)\n",
+ "B = 0.0020656\n",
+ "y1 = 2 * math.pi / B\n",
+ "Velocity = f * y1\n",
+ "print(\" Wavelength = %.0f mi \" %y1)\n",
+ "print(\" Velocity = %.0f mi/s \" %Velocity)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Sending end voltage= 0.52+0.00i\n",
+ "Sending end voltage = 208167.01\n",
+ "Angle = 0.00 V \n",
+ "Sending end voltage = 567.06\n",
+ "Angle = 0.00 V \n",
+ " Sending end line voltage = 360.6 kV \n",
+ " Sending end line current = 567.1 A \n",
+ " Sending end power = 354129 kW \n",
+ " Voltage Regulation = 47.3 percent \n",
+ " Wavelength = 3042 mi \n",
+ " Velocity = 182509 mi/s \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2, Page No 103"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "l = 230.0 #in mi\n",
+ "f = 60.0 #in Hz\n",
+ "P = 125e6 #in W\n",
+ "V = 215e3 #in V\n",
+ "\n",
+ "#From Table A.1 and A.2 for 30ft Rook\n",
+ "#z = R + i(Xa + Xd)\n",
+ "z = 0.1603 + complex(0.415+0.4127)\n",
+ "\n",
+ "#From Table A.1 and A.3 for 30ft Rook\n",
+ "y = complex(1e-6 / ( 0.0950 + 0.1008))\n",
+ "\n",
+ "#Calculations\n",
+ "yl = 0.0455806 + complex(0.4750793)\n",
+ "Z_c = 404.43706 - complex(38.802997)\n",
+ "V_r = V / math.sqrt(3)\n",
+ "I_r = P / (math.sqrt(3)*V)\n",
+ "\n",
+ "math.cosh_yl = math.cosh(yl.real) * math.cos(yl.imag) + complex(math.sinh(yl.real)) * math.sin(yl.imag)\n",
+ "math.sinh_yl = math.sinh(yl.real) * math.cos(yl.imag) + complex(math.cosh(yl.real)) * math.sin(yl.imag)\n",
+ "\n",
+ "#Per Unit calculations\n",
+ "Base_impedance = V**2 / P\n",
+ "Base_current = P / (math.sqrt(3)*V)\n",
+ "Z_c_pu = Z_c / Base_impedance\n",
+ "V_r_pu = (V / math.sqrt(3)) / (V / math.sqrt(3))\n",
+ "I_r_pu = (P / (math.sqrt(3)*V)) / Base_current\n",
+ "\n",
+ "V_s_pu = V_r_pu * math.cosh_yl + I_r_pu * Z_c_pu * math.sinh_yl\n",
+ "I_s_pu = I_r_pu * math.cosh_yl + V_r_pu * math.sinh_yl / Z_c_pu\n",
+ "\n",
+ "Line_voltage = abs(V_s_pu)*V / 1000\n",
+ "Line_current = abs(I_s_pu)*Base_current\n",
+ "\n",
+ "#Results\n",
+ "print(\" Sending end line voltage = %.1f V \" %Line_voltage)\n",
+ "print(\" Sending end line current = %.1f A \" %Line_current)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Sending end line voltage = 360.6 V \n",
+ " Sending end line current = 567.1 A \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.3, Page No 106"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "l = 230 #in mi\n",
+ "f = 60 #in Hz\n",
+ "P = 125e6 #in W\n",
+ "V = 215e3 #in V\n",
+ "\n",
+ "#From Table A.1 and A.2 for 30ft Rook\n",
+ "#z = R + complex(Xa + Xd)\n",
+ "z = 0.1603 + complex(0.415+0.4127)\n",
+ "\n",
+ "#From Table A.1 and A.3 for 30ft Rook\n",
+ "y = complex(1e-6 / ( 0.0950 + 0.1008))\n",
+ "\n",
+ "#Calculations\n",
+ "yl = 0.0455806 + complex(0.4750793)\n",
+ "Z_c = 404.43706 - complex(38.802997)\n",
+ "cosh_yl = math.cosh(yl.real) * math.cos(yl.imag) + complex(math.sinh(yl.real)) * math.sin(yl.imag)\n",
+ "sinh_yl = math.sinh(yl.real) * math.cos(yl.imag) + complex(math.cosh(yl.real)) * math.sin(yl.imag)\n",
+ "\n",
+ "#Equivalent pi circuit\n",
+ "Z1 = Z_c * sinh_yl\n",
+ "Y1_2 = (cosh_yl - 1)/(Z_c * sinh_yl)\n",
+ "\n",
+ "#Results\n",
+ "print('Equivalent PI circuit')\n",
+ "print( \"Total series impedance of the line = {0:.2f}\".format(abs(Z1.real)))\n",
+ "print(\"Angle = %.2f ohm in series arm \" %(math.degrees(math.atan2(Z1.imag,Z1.real))))\n",
+ "print( \"Total Shunt admittance of the line = {0:.2f}\".format(abs(Y1_2.real)))\n",
+ "print(\"Angle = %.2f ohm in each shunt arm \" %(math.degrees(math.atan2(Y1_2.imag,Y1_2.real))))\n",
+ "\n",
+ "\n",
+ "#Nominal pi Circuit\n",
+ "Z = l * z\n",
+ "Y_2 = y * l/2\n",
+ "\n",
+ "print('Nominal PI circuit')\n",
+ "print( \"Total series impedance of the line = {0:.2f}\".format(abs(Z.real)))\n",
+ "print(\"Angle = %.2f ohm in series arm \" %(math.degrees(math.atan2(Z.imag,Z.real))))\n",
+ "print( \"Total Shunt admittance of the line = {0:.2f}\".format(abs(Y_2.real)))\n",
+ "print(\"Angle = %.2f ohm in each shunt arm \" %(math.degrees(math.atan2(Y_2.imag,Y_2.real))))\n",
+ "\n",
+ "zp = ((abs(Z)-abs(Z1))/abs(Z1))*100\n",
+ "yp = ((abs(Y_2)-abs(Y1_2))/abs(Y1_2))*100\n",
+ "\n",
+ "print(\" Line impedace of the series arm of the nominal pi exceeds that of equivalent pi by %.1f percent \" %zp)\n",
+ "print(\" Conductance of the shunt arms of the nominal pi is %.0f percent less than that of equivalent pi \" %abs(yp))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Equivalent PI circuit\n",
+ "Total series impedance of the line = 199.09\n",
+ "Angle = 0.00 ohm in series arm \n",
+ "Total Shunt admittance of the line = 0.00\n",
+ "Angle = 0.00 ohm in each shunt arm \n",
+ "Nominal PI circuit\n",
+ "Total series impedance of the line = 227.24\n",
+ "Angle = 0.00 ohm in series arm \n",
+ "Total Shunt admittance of the line = 0.00\n",
+ "Angle = 0.00 ohm in each shunt arm \n",
+ " Line impedace of the series arm of the nominal pi exceeds that of equivalent pi by 14.1 percent \n",
+ " Conductance of the shunt arms of the nominal pi is 16 percent less than that of equivalent pi \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4 Page No 111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "l = 230.0 #in mi\n",
+ "f = 60.0 #in Hz\n",
+ "P = 125e6 #in W\n",
+ "V = 215e3 #in V\n",
+ "\n",
+ "#From Table A.1 and A.2 for 30ft Rook\n",
+ "#z = R + i(Xa + Xd)\n",
+ "z = 0.1603 + complex(0.415+0.4127)\n",
+ "\n",
+ "#From Table A.1 and A.3 for 30ft Rook\n",
+ "y =complex(1e-6 / ( 0.0950 + 0.1008))\n",
+ "\n",
+ "#Calculations\n",
+ "yl = 0.0455806 + complex(0.4750793)\n",
+ "Z_c = 404.43706 - complex(38.802997)\n",
+ "\n",
+ "cosh_yl = math.cosh(yl.real) * math.cos(yl.imag) + complex(math.sinh(yl.real)) * math.sin(yl.imag)\n",
+ "sinh_yl = math.sinh(yl.real)*math.cos(yl.imag) + complex(math.cosh(yl.real)) * math.sin(yl.imag)\n",
+ "\n",
+ "#Equivalent pi circuit\n",
+ "Z1 = Z_c * sinh_yl\n",
+ "Y1_2 = (math.cosh_yl - 1)/(Z_c * sinh_yl)\n",
+ "A = cosh_yl\n",
+ "D = cosh_yl\n",
+ "B = Z1\n",
+ "C = sinh_yl / Z_c\n",
+ "\n",
+ "print('For an uncompensated line')\n",
+ "print( \"A = D = {0:.2f}\".format(abs(A.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(A.imag,A.real))*180/math.pi))\n",
+ "print( \"B = {0:.2f}\".format(abs(B.real)))\n",
+ "print(\"Angle = %.2f ohm \" %(math.degrees(math.atan2(B.imag,B.real))*180/math.pi))\n",
+ "print( \"C = {0:.2f}\".format(abs(C.real)))\n",
+ "print(\"Angle = %.2f ohm \" %(math.degrees(math.atan2(C.imag,C.real))*180/math.pi))\n",
+ "\n",
+ "#For a series compensation factor of 70%\n",
+ "cf = 0.7\n",
+ "B1 = Z1 - complex(cf) * l * (0.415 + 0.4127) #X_a = 0.415 ohm/mi,X_d = 0.4127 in\n",
+ "A1 = B1 * Y1_2 + 1\n",
+ "C1 = 2 * Y1_2 + B1 * (Y1_2)**2\n",
+ "\n",
+ "#Results\n",
+ "print('For a series compensation factor of 70%')\n",
+ "print( \"A = D = {0:.2f}\".format(abs(A1.real)))\n",
+ "print(\"Angle = %.2f \" %(math.degrees(math.atan2(A1.imag,A1.real))))\n",
+ "print( \"B = {0:.2f}\".format(abs(B1.real)))\n",
+ "print(\"Angle = %.2f ohm \" %(math.degrees(math.atan2(B1.imag,B1.real))))\n",
+ "print( \"C = {0:.2f}\".format(abs(C1.real)))\n",
+ "print(\"Angle = %.2f ohm \" %(math.degrees(math.atan2(C1.imag,C1.real))))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For an uncompensated line\n",
+ "A = D = 1.14\n",
+ "Angle = 0.00 v \n",
+ "B = 199.09\n",
+ "Angle = 0.00 ohm \n",
+ "C = 0.00\n",
+ "Angle = 0.00 ohm \n",
+ "For a series compensation factor of 70%\n",
+ "A = D = 1.05\n",
+ "Angle = 0.00 \n",
+ "B = 65.83\n",
+ "Angle = 0.00 ohm \n",
+ "C = 0.00\n",
+ "Angle = 0.00 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5, Page No 112"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "l = 230.0 #in mi\n",
+ "f = 60.0 #in Hz\n",
+ "P = 125e6 #in W\n",
+ "V = 215e3 #in V\n",
+ "\n",
+ "#From Table A.1 and A.2 for 30ft Rook\n",
+ "#z = R + i(Xa + Xd)\n",
+ "z = 0.1603 + complex(0.415+0.4127)\n",
+ "\n",
+ "#From Table A.1 and A.3 for 30ft Rook\n",
+ "y = complex(1e-6 / ( 0.0950 + 0.1008))\n",
+ "\n",
+ "#Calculations\n",
+ "yl = 0.0455806 + complex(0.4750793)\n",
+ "Z_c = 404.43706 - complex(38.802997)\n",
+ "V_r = V / math.sqrt(3)\n",
+ "I_r = P / (math.sqrt(3)*V)\n",
+ "\n",
+ "cosh_yl = math.cosh(yl.real) * math.cos(yl.imag) + complex(math.sinh(yl.real)) * math.sin(yl.imag)\n",
+ "sinh_yl = math.sinh(yl.real) * math.cos(yl.imag) + complex(math.cosh(yl.real)) * math.sin(yl.imag)\n",
+ "\n",
+ "V_s = V_r * cosh_yl + I_r * Z_c * sinh_yl\n",
+ "I_s = I_r * cosh_yl + V_r * sinh_yl / Z_c\n",
+ "\n",
+ "#Equivalent pi circuit\n",
+ "Z1 = Z_c * sinh_yl\n",
+ "Y1_2 = (cosh_yl - 1)/(Z_c * sinh_yl)\n",
+ "\n",
+ "#Total capacitive Susceptance\n",
+ "B_c = complex(y) * l\n",
+ "\n",
+ "#For 70% Compensation\n",
+ "cf = 0.7\n",
+ "B_L = - B_c * 0.7\n",
+ "\n",
+ "#From appendix\n",
+ "A = 1\n",
+ "D = 1\n",
+ "B = 0\n",
+ "C = -complex(B_L)\n",
+ "\n",
+ "\n",
+ "#From Table A.6 for combining two networks in series\n",
+ "A_eq = cosh_yl + Z1 * C\n",
+ "voltage_regulation = ((abs(V_s)/abs(A_eq))-V_r)*100.0/V_r\n",
+ "print(\" Voltage regulation in percent \")\n",
+ "print(voltage_regulation)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Voltage regulation in percent \n",
+ "28.7687144089\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo06.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo06.ipynb
new file mode 100755
index 00000000..c78060a7
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo06.ipynb
@@ -0,0 +1,1199 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 06 : System Modelling"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1, Page No 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "N_1 = 2000.0\n",
+ "N_2 = 500.0\n",
+ "V_1 = 1200.0*complex(math.cos(0),math.sin(0))\n",
+ "I_1 = 5*complex(math.cos(-30*math.pi/180),math.sin(-30*math.pi/180))\n",
+ "\n",
+ "#Calculations\n",
+ "a = N_1 / N_2\n",
+ "V_2 = V_1/a\n",
+ "I_2 = a * I_1\n",
+ "Z_2 = V_2 / I_2\n",
+ "Z1_2 = Z_2 * a**2\n",
+ "\n",
+ "#Results\n",
+ "print( \"V_2 = {0:.2f}\".format(abs(V_2.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(V_2.imag,V_2.real))))\n",
+ "print( \"I_2 = {0:.2f}\".format(abs(I_2.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_2.imag,I_2.real))))\n",
+ "print( \"Z_2 = {0:.2f}\".format(abs(Z_2.real)))\n",
+ "print(\"Angle = %.2f ohm \" %(math.degrees(math.atan2(Z_2.imag,Z_2.real))))\n",
+ "print( \"Z1_2 = {0:.2f}\".format(abs(I_2.real)))\n",
+ "print(\"Angle = %.2f ohm \" %(math.degrees(math.atan2(Z1_2.imag,Z1_2.real))))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "V_2 = 300.00\n",
+ "Angle = 0.00 v \n",
+ "I_2 = 17.32\n",
+ "Angle = -30.00 A \n",
+ "Z_2 = 12.99\n",
+ "Angle = 30.00 ohm \n",
+ "Z1_2 = 17.32\n",
+ "Angle = 30.00 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2, Page No 144"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "N_1 = 2000.0\n",
+ "N_2 = 500.0\n",
+ "V_1 = 1200*complex(math.cos(0),math.sin(0))\n",
+ "r1 = 2\n",
+ "r2 = 0.125\n",
+ "x1 = 8\n",
+ "x2 = 0.5\n",
+ "Z_2 = 12\n",
+ "\n",
+ "#Calculations\n",
+ "a = N_1 / N_2\n",
+ "R1 = r1 + a**2 * r2\n",
+ "X1 = x1 + a**2 * x2\n",
+ "Z1_2 = Z_2 * a**2\n",
+ "\n",
+ "I_1 = V_1 /(Z1_2+ complex(R1,X1))\n",
+ "V_2 = I_1 * Z1_2 / a\n",
+ "voltage_regulation = ((V_1/4)-abs(V_2))*100.0/V_2\n",
+ "\n",
+ "print( \"I_1 = {0:.2f}\".format(abs(I_1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_1.imag,I_1.real))))\n",
+ "print( \"V_2 = {0:.2f}\".format(abs(V_2.real)))\n",
+ "print(\"Angle = %.2f V \" %(math.degrees(math.atan2(V_2.imag,V_2.real))))\n",
+ "print( \"Voltage Regulation ={0:.5f}+{1:.5f}i\".format(voltage_regulation.real, voltage_regulation.imag))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I_1 = 6.08\n",
+ "Angle = -4.67 A \n",
+ "V_2 = 291.93\n",
+ "Angle = -4.67 V \n",
+ "Voltage Regulation =2.41487+0.19713i\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3, Page No 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P = 30e3\n",
+ "V_lt = 120.0\n",
+ "V_ht = 240.0\n",
+ "\n",
+ "#Calculations\n",
+ "I_1 = P / V_lt\n",
+ "I_2 = P / V_ht\n",
+ "V_2 = V_lt + V_ht\n",
+ "I_in = I_1 + I_2\n",
+ "input_kva = I_in * V_lt / 1e3\n",
+ "output_kva = I_2 * V_2 / 1e3\n",
+ "\n",
+ "#Results\n",
+ "print(\" Input kVA = %.0f kVA \" %input_kva)\n",
+ "print(\" Output kVA = %.0f kVA \" %output_kva)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Input kVA = 45 kVA \n",
+ " Output kVA = 45 kVA \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.4 Page No 147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V_lt = 110.0\n",
+ "V_ht = 440.0\n",
+ "P = 2.5e3\n",
+ "x_lt = 0.06\n",
+ "\n",
+ "#Calculations\n",
+ "print('Viewed from low-tension side')\n",
+ "lt_base_impedance = (V_lt)**2 / P\n",
+ "print(\" Leakage reactance from low-tension side = %.2f ohm\" %x_lt)\n",
+ "print(\" Low-tension base impedance = %.2f ohmn\" %lt_base_impedance)\n",
+ "X_lt_pu = x_lt / lt_base_impedance\n",
+ "print(\" Leakage reactance in per unit from Low-tension side = %.4f per unit \" %X_lt_pu)\n",
+ "print('Viewed from high-tension side')\n",
+ "x_ht = x_lt * (V_ht / V_lt)**2\n",
+ "ht_base_impedance = (V_ht)**2 / P\n",
+ "\n",
+ "#Results\n",
+ "print(\" Leakage reactance from high-tension side = %.2f ohm\" %x_ht)\n",
+ "print(\" High-tension base impedance = %.2f ohmn\" %ht_base_impedance)\n",
+ "X_ht_pu = x_ht / ht_base_impedance\n",
+ "print(\" Leakage reactance in per unit from Low-tension side = %.4f per unit \" %X_ht_pu)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Viewed from low-tension side\n",
+ " Leakage reactance from low-tension side = 0.06 ohm\n",
+ " Low-tension base impedance = 4.84 ohmn\n",
+ " Leakage reactance in per unit from Low-tension side = 0.0124 per unit \n",
+ "Viewed from high-tension side\n",
+ " Leakage reactance from high-tension side = 0.96 ohm\n",
+ " High-tension base impedance = 77.44 ohmn\n",
+ " Leakage reactance in per unit from Low-tension side = 0.0124 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.5, Page No 147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P_AB = 10e6\n",
+ "V_AB_lt = 13.8e3\n",
+ "V_AB_ht = 138e3\n",
+ "x_AB = complex(0.1)\n",
+ "P_BC = 10e6\n",
+ "V_BC_lt = 69e3\n",
+ "V_BC_ht = 138e3\n",
+ "x_BC = complex(0.08)\n",
+ "P_base_B = 10e6\n",
+ "V_base_B = 138e3\n",
+ "Z_L = 300\n",
+ "V_load = 66e3\n",
+ "\n",
+ "#Calculations\n",
+ "V_base_A = (V_AB_lt/V_AB_ht)*V_base_B\n",
+ "V_base_C = (V_BC_lt/V_BC_ht)*V_base_B\n",
+ "base_impedance_C = (V_base_C)**2 / P_BC\n",
+ "Z_L_pu = Z_L / base_impedance_C\n",
+ "\n",
+ "#impedance diagram is shown in the xcos file\n",
+ "V_load_pu = V_load / V_base_C\n",
+ "I_L_pu = V_load_pu / Z_L_pu\n",
+ "voltage_input = (I_L_pu * (x_AB + x_BC)) + V_load_pu\n",
+ "voltage_regulation = (abs(voltage_input)-abs(V_load_pu))*100/abs(V_load_pu)\n",
+ "\n",
+ "#Results\n",
+ "print(\" Voltage regulation = %.2f percent \" %voltage_regulation)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Voltage regulation = 28.57 percent \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6, Page No 151"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P = 25e6\n",
+ "V_ht = 38.1e3\n",
+ "V_lt = 3.81e3\n",
+ "R_l = 0.6\n",
+ "P_ht_base = 75e6\n",
+ "V_ht_base = 66e3\n",
+ "\n",
+ "#Calculations\n",
+ "#Low-tension side base ratings\n",
+ "print('Low-tension side')\n",
+ "P_lt_base = P_ht_base\n",
+ "V_lt_base = (V_lt/(V_ht*math.sqrt(3)))*V_ht_base\n",
+ "print(\" Base for low tension side is %.0f MVA,%.2f kV\" %(P_lt_base/1e6,V_lt_base/1e3))\n",
+ "Z_lt_base = (V_lt_base)**2/P_lt_base\n",
+ "R_lt_l_base = R_l / Z_lt_base\n",
+ "print(\" Base impedance for the low-tension side = %.2f ohm\" %Z_lt_base)\n",
+ "print(\" Per unit impedance of load on the low-tension side = %.2f per unit \" %R_lt_l_base)\n",
+ "\n",
+ "#Results\n",
+ "print('High-tension side')\n",
+ "R_l_ht = R_l * ((V_ht*math.sqrt(3))/V_lt)**2\n",
+ "Z_ht_base = (V_ht_base)**2 / P_ht_base\n",
+ "R_ht_l_base = R_l_ht / Z_ht_base\n",
+ "print(\" Base impedance for the high-tension side = %.2f ohm\" %Z_ht_base)\n",
+ "print(\" Per unit impedance of load on the high-tension side = %.2f per unit\" %R_ht_l_base)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Low-tension side\n",
+ " Base for low tension side is 75 MVA,3.81 kV\n",
+ " Base impedance for the low-tension side = 0.19 ohm\n",
+ " Per unit impedance of load on the low-tension side = 3.10 per unit \n",
+ "High-tension side\n",
+ " Base impedance for the high-tension side = 58.08 ohm\n",
+ " Per unit impedance of load on the high-tension side = 3.10 per unit\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7 Page No 152"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "z = 0.121\n",
+ "P = 400e6\n",
+ "V_ht = 220e3\n",
+ "V_lt = 22e3\n",
+ "V_ht_base = 230e3\n",
+ "P_ht_base = 100e6\n",
+ "\n",
+ "#Calculations\n",
+ "z_pu = z * P / (V_lt)**2\n",
+ "\n",
+ "#Results\n",
+ "print(\" On its own base the transformer reactance = %.2f per unit\" %z_pu)\n",
+ "z_new_pu=(z_pu * (V_ht/P_ht_base)**2 * (P_ht_base/P))\n",
+ "print(\" On the chosen base the reactance = %.4f per unit\" %z_new_pu)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " On its own base the transformer reactance = 0.10 per unit\n",
+ " On the chosen base the reactance = 0.0000 per unit\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7, Page No 154"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Z_ps = complex(0.07)\n",
+ "P_ps_base = 15e6\n",
+ "V_ps_base = 66e3\n",
+ "\n",
+ "Z_pt = complex(0.09)\n",
+ "P_pt_base = 15e6\n",
+ "V_pt_base = 66e3\n",
+ "Z_st = complex(0.08)\n",
+ "P_st_base = 10e6\n",
+ "V_st_base = 13.2e3\n",
+ "\n",
+ "#Calculations\n",
+ "Z_st_new = Z_st * P_ps_base / P_st_base\n",
+ "Z_p = (Z_ps + Z_pt - Z_st_new)/2\n",
+ "Z_s = (Z_ps - Z_pt + Z_st_new)/2\n",
+ "Z_t = (-Z_ps + Z_pt + Z_st_new)/2\n",
+ "\n",
+ "#Results\n",
+ "print( \"Z_p in per unit = {0:.5f}i\".format(Z_p.real))\n",
+ "print( \"Z_s in per unit = {0:.5f}i\".format(Z_s.real))\n",
+ "print( \"Z_t in per unit = {0:.5f}i\".format(Z_t.real))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Z_p in per unit = 0.02000i\n",
+ "Z_s in per unit = 0.05000i\n",
+ "Z_t in per unit = 0.07000i\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.9 Page No 155"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Z_ps = complex(0.07)\n",
+ "P_ps_base = 15e6\n",
+ "V_ps_base = 66e3\n",
+ "P_r_load = 5e6\n",
+ "V_r_load = 2.3e3\n",
+ "P_m = 7.5e6\n",
+ "V_m = 13.2e3\n",
+ "R_l = 1\n",
+ "X_11 = 0.20\n",
+ "\n",
+ "Z_pt = complex(0.09)\n",
+ "P_pt_base = 15e6\n",
+ "V_pt_base = 66e3\n",
+ "\n",
+ "Z_st = complex(0.08)\n",
+ "P_st_base = 10e6\n",
+ "V_st_base = 13.2e3\n",
+ "\n",
+ "#Calculations\n",
+ "Z_st_new = Z_st * P_ps_base / P_st_base\n",
+ "Z_p = (Z_ps + Z_pt - Z_st_new)/2\n",
+ "Z_s = (Z_ps - Z_pt + Z_st_new)/2\n",
+ "Z_t = (-Z_ps + Z_pt + Z_st_new)/2\n",
+ "\n",
+ "R_pu = R_l * P_ps_base / P_r_load\n",
+ "X11_pu = X_11 * P_ps_base / P_m\n",
+ "\n",
+ "#Results\n",
+ "print(\" On a base of 15MVA,2.3kV load resistance = %.1f per unit\" %R_pu)\n",
+ "print(\" Reactance of the motor at a base of 15MVA,13.2kV = %.2f per unit\" %X11_pu)\n",
+ "\n",
+ "#Reactance diagram is drawn in the xcos file\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " On a base of 15MVA,2.3kV load resistance = 3.0 per unit\n",
+ " Reactance of the motor at a base of 15MVA,13.2kV = 0.40 per unit\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.10 Page No 159"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "\n",
+ "def pucalc(pu_Z_given,base_kV_given,base_kV_new,base_kVA_new,base_kVA_given):\n",
+ " X11=(pu_Z_given * (base_kV_given/base_kV_new)**2 * (base_kVA_new/base_kVA_given))\n",
+ " return X11\n",
+ "\n",
+ "\n",
+ "P_g = 300e6\n",
+ "V_g = 20e3\n",
+ "X11_g = 0.20\n",
+ "l = 64\n",
+ "V_m = 13.2e3\n",
+ "P_m1 = 200e6\n",
+ "P_m2 = 100e6\n",
+ "X11_m = 0.20\n",
+ "T1_P = 350e6\n",
+ "T1_vht = 230e3\n",
+ "T1_vlt = 20e3\n",
+ "x_T1 = 0.10\n",
+ "T2_1_P = 100e6\n",
+ "T2_1_vht = 127e3\n",
+ "T2_1_vlt = 13.2e3\n",
+ "x_T2 = 0.10\n",
+ "x_line = 0.5\t\t#ohm per km\n",
+ "V_base = V_g\n",
+ "P_base = P_g\n",
+ "\n",
+ "#Calculations\n",
+ "T2_P = 3*T2_1_P\n",
+ "T2_vht = math.sqrt(3)*T2_1_vht\n",
+ "T2_vlt = T2_1_vlt\n",
+ "V_base_line = (T1_vht/T1_vlt)*V_base\n",
+ "V_base_m = V_base_line * (T2_vlt/T2_vht)\n",
+ "x_T1_base = x_T1 * (P_base/T1_P)\n",
+ "x_T2_base = x_T2 * (T2_vlt/V_base_m)\n",
+ "z_line_base = (V_base_line)**2/P_base\n",
+ "x_line_pu = x_line * l / z_line_base\n",
+ "X11_m1_pu = pucalc(X11_m,V_m,V_base_m,P_base,P_m1)\n",
+ "X11_m2_pu = pucalc(X11_m,V_m,V_base_m,P_base,P_m2)\n",
+ "\n",
+ "#Results\n",
+ "#Reactance diagram is given in xcos file\n",
+ "print('Base Voltages in different parts of circuit')\n",
+ "print(\" Generator voltage = %.0f kV\" %(V_g/1e3))\n",
+ "print(\" Line voltage = %.0f kV\" %(V_base_line/1e3))\n",
+ "print(\" Motor voltage = %.1f kV \" %(V_base_m/1e3))\n",
+ "\n",
+ "print('Base reactance in different parts of circuit')\n",
+ "print(\" Transformer 1 reactance = %.4f per unit\" %x_T1_base)\n",
+ "print(\" Transformer 2 reactance = %.4f per unit\" %x_T2_base)\n",
+ "print(\" Line reactance = %.4f per unit\" %x_line_pu)\n",
+ "print(\" Motor 1 reactance = %.4f per unit\" %X11_m1_pu)\n",
+ "print(\" Motor 2 reactance = %.4f per unit\" %X11_m2_pu)\n",
+ "#impedance diagram is shown in the xcos file\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base Voltages in different parts of circuit\n",
+ " Generator voltage = 20 kV\n",
+ " Line voltage = 230 kV\n",
+ " Motor voltage = 13.8 kV \n",
+ "Base reactance in different parts of circuit\n",
+ " Transformer 1 reactance = 0.0857 per unit\n",
+ " Transformer 2 reactance = 0.0956 per unit\n",
+ " Line reactance = 0.1815 per unit\n",
+ " Motor 1 reactance = 0.2744 per unit\n",
+ " Motor 2 reactance = 0.5488 per unit\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.11 Page No 160"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P_g = 300e6\n",
+ "V_g = 20e3\n",
+ "X11_g = 0.20\n",
+ "l = 64\n",
+ "V_m = 13.2e3\n",
+ "P_m1 = 120e6\n",
+ "P_m2 = 60e6\n",
+ "X11_m = 0.20\n",
+ "T1_P = 350e6\n",
+ "T1_vht = 230e3\n",
+ "T1_vlt = 20e3\n",
+ "x_T1 = 0.10\n",
+ "T2_1_P = 100e6\n",
+ "T2_1_vht = 127e3\n",
+ "T2_1_vlt = 13.2e3\n",
+ "x_T2 = 0.10\n",
+ "x_line = 0.5#onhm per km\n",
+ "V_base = V_g\n",
+ "P_base = P_g\n",
+ "\n",
+ "#Calculations\n",
+ "T2_P = 3*T2_1_P\n",
+ "T2_vht = math.sqrt(3)*T2_1_vht\n",
+ "T2_vlt = T2_1_vlt\n",
+ "V_base_line = (T1_vht/T1_vlt)*V_base\n",
+ "V_base_m = V_base_line * (T2_vlt/T2_vht)\n",
+ "x_T1_base = x_T1 * (P_base/T1_P)\n",
+ "x_T2_base = x_T2 * (T2_vlt/V_base_m)\n",
+ "z_line_base = (V_base_line)**2/P_base\n",
+ "x_line_pu = x_line * l / z_line_base\n",
+ "P = P_m1 + P_m2\n",
+ "P_pu = P / P_base\n",
+ "V = V_m / V_base_m\n",
+ "I = P_pu / V\n",
+ "Vg = V + I * (complex(x_T1_base) + complex(x_T2_base) + complex(x_line_pu))\n",
+ "V_terminal = abs(Vg) * V_g\n",
+ "\n",
+ "#Results\n",
+ "print(\" The generator terminal voltage = %.2f kV\" %(V_terminal / 1e3))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The generator terminal voltage = 23.68 kV\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.17, Page No 176"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialisation of variables\n",
+ "\n",
+ "V_s=math.sqrt(2)*230 #V\n",
+ "L=15*10**-6 #H\n",
+ "I=V_s/L #I=(di/dt)_max\n",
+ "R_s=10 #ohm\n",
+ "v=I*R_s #v=(dv/dt)_max\n",
+ "\n",
+ "#Calculations\n",
+ "f=50 #Hz\n",
+ "X_L=L*2*math.pi*f\n",
+ "R=2\n",
+ "I_max=V_s/(R+X_L) \n",
+ "FF=math.pi/math.sqrt(2)\n",
+ "I_TAV1=I_max/FF \n",
+ "FF=3.98184\n",
+ "I_TAV2=I_max/FF \n",
+ "\n",
+ "\n",
+ "#RESULTS\n",
+ "print(\"(di/dt)_max=%.3f A/usec\" %(I/10**6))\n",
+ "print(\"\\n(dv/dt)_max=%.2f V/usec\" %(v/10**6))\n",
+ "print(\"\\nI_rms=%.3f A\" %I_max)\n",
+ "print(\"when conduction angle=90\")\n",
+ "print(\"I_TAV=%.3f A\" %I_TAV1)\n",
+ "print(\"when conduction angle=30\")\n",
+ "print(\"I_TAV=%.3f A\" %I_TAV2)\n",
+ "print(\"\\nvoltage rating=%.3f V\" %(2.75*V_s)) #rating is taken 2.75 times of peak working voltage unlike 2.5 to 3 times as mentioned int book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(di/dt)_max=21.685 A/usec\n",
+ "\n",
+ "(dv/dt)_max=216.85 V/usec\n",
+ "\n",
+ "I_rms=162.252 A\n",
+ "when conduction angle=90\n",
+ "I_TAV=73.039 A\n",
+ "when conduction angle=30\n",
+ "I_TAV=40.748 A\n",
+ "\n",
+ "voltage rating=894.490 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.19, Page No 186"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "\n",
+ "T_jm=125\n",
+ "th_jc=.15 #degC/W\n",
+ "th_cs=0.075 #degC/W\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "dT=54 #dT=T_s-T_a\n",
+ "P_av=120\n",
+ "th_sa=dT/P_av\n",
+ "T_a=40 #ambient temp\n",
+ "P_av=(T_jm-T_a)/(th_sa+th_jc+th_cs)\n",
+ "if (P_av-120)<1 :\n",
+ " print(\"selection of heat sink is satisfactory\")\n",
+ "\n",
+ "dT=58 #dT=T_s-T_a\n",
+ "P_av=120\n",
+ "th_sa=dT/P_av\n",
+ "T_a=40 #ambient temp\n",
+ "P_av=(T_jm-T_a)/(th_sa+th_jc+th_cs)\n",
+ "if (P_av-120)<1 :\n",
+ " print(\"selection of heat sink is satisfactory\")\n",
+ "\n",
+ "V_m=math.sqrt(2)*230\n",
+ "R=2\n",
+ "I_TAV=V_m/(R*math.pi)\n",
+ "P_av=90\n",
+ "th_sa=(T_jm-T_a)/P_av-(th_jc+th_cs)\n",
+ "dT=P_av*th_sa\n",
+ "print(\"for heat sink\") \n",
+ "print(\"T_s-T_a=%.2f degC\" %dT) \n",
+ "print(\"\\nP_av=%.0f W\" %P_av)\n",
+ "P=(V_m/2)**2/R\n",
+ "eff=P/(P+P_av) \n",
+ "print(\"\\nckt efficiency=%.3f pu\" %eff)\n",
+ "a=60 #delay angle\n",
+ "I_TAV=(V_m/(2*math.pi*R))*(1+math.cos(math.radians(a)))\n",
+ "print(\"\\nI_TAV=%.2f A\" %I_TAV)\n",
+ "dT=46\n",
+ "T_s=dT+T_a\n",
+ "T_c=T_s+P_av*th_cs \n",
+ "T_j=T_c+P_av*th_jc \n",
+ "\n",
+ "#Results\n",
+ "print(\"\\ncase temp=%.2f degC\" %T_c)\n",
+ "print(\"\\njunction temp=%.2f degC\" %T_j)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "for heat sink\n",
+ "T_s-T_a=-20.25 degC\n",
+ "\n",
+ "P_av=90 W\n",
+ "\n",
+ "ckt efficiency=0.993 pu\n",
+ "\n",
+ "I_TAV=38.83 A\n",
+ "\n",
+ "case temp=92.75 degC\n",
+ "\n",
+ "junction temp=106.25 degC\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.20, Page No 187"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "T_j=125.0 #degC\n",
+ "T_s=70.0 #degC\n",
+ "th_jc=.16 #degC/W\n",
+ "th_cs=.08 #degC/W\n",
+ "\n",
+ "#Calculations\n",
+ "P_av1=(T_j-T_s)/(th_jc+th_cs) \n",
+ "\n",
+ "T_s=60 #degC\n",
+ "P_av2=(T_j-T_s)/(th_jc+th_cs) \n",
+ "inc=(math.sqrt(P_av2)-math.sqrt(P_av1))*100/math.sqrt(P_av1) \n",
+ "\n",
+ "#Results\n",
+ "print(\"Total avg power loss in thristor sink combination=%.2f W\" %P_av1)\n",
+ "print(\"Percentage inc in rating=%.2f\" %inc)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total avg power loss in thristor sink combination=229.17 W\n",
+ "Percentage inc in rating=8.71\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.21, Page No 197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "\n",
+ "R=25000.0\n",
+ "I_l1=.021 #I_l=leakage current\n",
+ "I_l2=.025\n",
+ "I_l3=.018\n",
+ "I_l4=.016\n",
+ " #V1=(I-I_l1)*R\n",
+ " #V2=(I-I_l2)*R\n",
+ " #V3=(I-I_l3)*R\n",
+ " #V4=(I-I_l4)*R\n",
+ " #V=V1+V2+V3+V4\n",
+ " \n",
+ "#Calculations\n",
+ "V=10000.0\n",
+ "I_l=I_l1+I_l2+I_l3+I_l4\n",
+ " #after solving\n",
+ "I=((V/R)+I_l)/4\n",
+ "R_c=40.0\n",
+ "V1=(I-I_l1)*R \n",
+ "\n",
+ "#Resluts\n",
+ "print(\"voltage across SCR1=%.0f V\" %V1)\n",
+ "V2=(I-I_l2)*R \n",
+ "print(\"\\nvoltage across SCR2=%.0f V\" %V2)\n",
+ "V3=(I-I_l3)*R \n",
+ "print(\"\\nvoltage across SCR3=%.0f V\" %V3)\n",
+ "V4=(I-I_l4)*R \n",
+ "print(\"\\nvoltage across SCR4=%.0f V\" %V4)\n",
+ "\n",
+ "I1=V1/R_c \n",
+ "print(\"\\ndischarge current through SCR1=%.3f A\" %I1)\n",
+ "I2=V2/R_c \n",
+ "print(\"\\ndischarge current through SCR2=%.3f A\" %I2)\n",
+ "I3=V3/R_c \n",
+ "print(\"\\ndischarge current through SCR3=%.3f A\" %I3)\n",
+ "I4=V4/R_c \n",
+ "print(\"\\ndischarge current through SCR4=%.3f A\" %I4)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "voltage across SCR1=2475 V\n",
+ "\n",
+ "voltage across SCR2=2375 V\n",
+ "\n",
+ "voltage across SCR3=2550 V\n",
+ "\n",
+ "voltage across SCR4=2600 V\n",
+ "\n",
+ "discharge current through SCR1=61.875 A\n",
+ "\n",
+ "discharge current through SCR2=59.375 A\n",
+ "\n",
+ "discharge current through SCR3=63.750 A\n",
+ "\n",
+ "discharge current through SCR4=65.000 A\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.22, Page No 198"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V_r=1000 #rating of SCR\n",
+ "I_r=200 #rating of SCR\n",
+ "V_s=6000 #rating of String\n",
+ "I_s=1000 #rating of String\n",
+ "\n",
+ "#Calculations\n",
+ "print(\"when DRF=.1\")\n",
+ "DRF=.1\n",
+ "n_s=V_s/(V_r*(1-DRF)) \n",
+ "print(\"number of series units=%.0f\" %math.ceil(n_s))\n",
+ "n_p=I_s/(I_r*(1-DRF)) \n",
+ "print(\"\\nnumber of parrallel units=%.0f\" %math.ceil(n_p))\n",
+ "print(\"when DRF=.2\")\n",
+ "DRF=.2\n",
+ "\n",
+ "#Results\n",
+ "n_s=V_s/(V_r*(1-DRF)) \n",
+ "print(\"number of series units=%.0f\" %math.ceil(n_s))\n",
+ "n_p=I_s/(I_r*(1-DRF)) \n",
+ "print(\"\\nnumber of parrallel units=%.0f\" %math.ceil(n_p))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "when DRF=.1\n",
+ "number of series units=7\n",
+ "\n",
+ "number of parrallel units=6\n",
+ "when DRF=.2\n",
+ "number of series units=8\n",
+ "\n",
+ "number of parrallel units=7\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.23, Page No 198"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V1=1.6 #on state voltage drop of SCR1\n",
+ "V2=1.2 #on state voltage drop of SCR2\n",
+ "I1=250.0 #current rating of SCR1\n",
+ "I2=350.0 #current rating of SCR2\n",
+ "\n",
+ "#Calculations\n",
+ "R1=V1/I1\n",
+ "R2=V2/I2\n",
+ "I=600.0 #current to be shared\n",
+ " #for SCR1 % I*(R1+R)/(total resistance)=k*I1 (1)\n",
+ " #for SCR2 % I*(R2+R)/(total resistance)=k*I2 (2)\n",
+ " #(1)/(2)\n",
+ "R=(R2*I2-R1*I1)/(I1-I2)\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print(\"RSequired value of resistance=%.3f ohm\" %R)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "RSequired value of resistance=0.004 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.25, Page No 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "f=2000.0 #Hz\n",
+ "C=0.04*10**-6\n",
+ "n=.72\n",
+ "\n",
+ "#Calculations\n",
+ "R=1/(f*C*math.log(1/(1-n))) \n",
+ "V_p=18\n",
+ "V_BB=V_p/n\n",
+ "R2=10**4/(n*V_BB) \n",
+ "I=4.2*10**-3 #leakage current\n",
+ "R_BB=5000\n",
+ "R1=(V_BB/I)-R2-R_BB\n",
+ "\n",
+ "#Results\n",
+ "print(\"R=%.2f kilo-ohm\" %(R/1000))\n",
+ "print(\"\\nR2=%.2f ohm\" %R2)\n",
+ "print(\"\\nR1=%.0f ohm\" %R1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "R=9.82 kilo-ohm\n",
+ "\n",
+ "R2=555.56 ohm\n",
+ "\n",
+ "R1=397 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.26, Page No 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "\n",
+ "V_p=18.0\n",
+ "n=.72\n",
+ "V_BB=V_p/n\n",
+ "I_p=.6*10**-3\n",
+ "I_v=2.5*10**-3\n",
+ "V_v=1\n",
+ "\n",
+ "#Calculations\n",
+ "R_max=V_BB*(1-n)/I_p \n",
+ "print(\"R_max=%.2f kilo-ohm\" %(R_max/1000))\n",
+ "R_min=(V_BB-V_v)/I_v \n",
+ "print(\"\\nR_min=%.2f kilo-ohm\" %(R_min/1000))\n",
+ "\n",
+ "C=.04*10**-6\n",
+ "f_min=1/(R_max*C*math.log(1/(1-n))) \n",
+ "print(\"\\nf_min=%.3f kHz\" %(f_min/1000))\n",
+ "f_max=1/(R_min*C*math.log(1/(1-n))) \n",
+ "print(\"\\nf_max=%.2f kHz\" %(f_max/1000))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "R_max=11.67 kilo-ohm\n",
+ "\n",
+ "R_min=9.60 kilo-ohm\n",
+ "\n",
+ "f_min=1.683 kHz\n",
+ "\n",
+ "f_max=2.05 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.27, Page No 231"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "R1=1000.0\n",
+ "C=.5*10**-6\n",
+ "f=50.0\n",
+ "w=2*math.pi*f\n",
+ "V_s=230.0\n",
+ "X_c=1.0/(w*C)\n",
+ "v_c=30.0\n",
+ "R=0\n",
+ "\n",
+ "#Calculations\n",
+ "a = 227.2 #magnitude of V_c\n",
+ "b = 8.93 #argument of V_c\n",
+ "a1 = 14.3\n",
+ "Z=math.sqrt((R+R1)**2+X_c**2)\n",
+ "phi=math.degrees(math.atan(X_c/(R+R1)))\n",
+ "v_c=30\n",
+ "a1=math.sin(math.radians(v_c/(sqrt(2.0)*a)))+b\n",
+ "R=25000.0\n",
+ "a=54.7 #magnitude of V_c\n",
+ "b=76.24 #argument of V_c\n",
+ "#a2=76.24\n",
+ "Z=math.sqrt((R+R1)**2+X_c**2)\n",
+ "phi=math.degrees(math.atan(X_c/(R+R1)))\n",
+ "v_c=30.0\n",
+ "a2=math.degrees(math.asin(v_c/(math.sqrt(2)*a)))+b\n",
+ "\n",
+ "#Results\n",
+ "print(\"min angle=%.1f deg\" %a1)\n",
+ "print(\"Max angle=%.2f deg\" %a2)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "NameError",
+ "evalue": "name 'sqrt' is not defined",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m<ipython-input-20-cf37d8d6ab2c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 17\u001b[0m \u001b[0mphi\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdegrees\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0matan\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX_c\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mR\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mR1\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 18\u001b[0m \u001b[0mv_c\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m30\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 19\u001b[1;33m \u001b[0ma1\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mradians\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mv_c\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msqrt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2.0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 20\u001b[0m \u001b[0mR\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m25000.0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 21\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m54.7\u001b[0m \u001b[1;31m#magnitude of V_c\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mNameError\u001b[0m: name 'sqrt' is not defined"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo06_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo06_1.ipynb
new file mode 100755
index 00000000..d1efd868
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo06_1.ipynb
@@ -0,0 +1,660 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 06 : System Modelling"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1, Page No 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "N_1 = 2000.0\n",
+ "N_2 = 500.0\n",
+ "V_1 = 1200.0*complex(math.cos(0),math.sin(0))\n",
+ "I_1 = 5*complex(math.cos(-30*math.pi/180),math.sin(-30*math.pi/180))\n",
+ "\n",
+ "#Calculations\n",
+ "a = N_1 / N_2\n",
+ "V_2 = V_1/a\n",
+ "I_2 = a * I_1\n",
+ "Z_2 = V_2 / I_2\n",
+ "Z1_2 = Z_2 * a**2\n",
+ "\n",
+ "#Results\n",
+ "print( \"V_2 = {0:.2f}\".format(abs(V_2.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(V_2.imag,V_2.real))))\n",
+ "print( \"I_2 = {0:.2f}\".format(abs(I_2.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_2.imag,I_2.real))))\n",
+ "print( \"Z_2 = {0:.2f}\".format(abs(Z_2.real)))\n",
+ "print(\"Angle = %.2f ohm \" %(math.degrees(math.atan2(Z_2.imag,Z_2.real))))\n",
+ "print( \"Z1_2 = {0:.2f}\".format(abs(I_2.real)))\n",
+ "print(\"Angle = %.2f ohm \" %(math.degrees(math.atan2(Z1_2.imag,Z1_2.real))))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "V_2 = 300.00\n",
+ "Angle = 0.00 v \n",
+ "I_2 = 17.32\n",
+ "Angle = -30.00 A \n",
+ "Z_2 = 12.99\n",
+ "Angle = 30.00 ohm \n",
+ "Z1_2 = 17.32\n",
+ "Angle = 30.00 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2, Page No 144"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "N_1 = 2000.0\n",
+ "N_2 = 500.0\n",
+ "V_1 = 1200*complex(math.cos(0),math.sin(0))\n",
+ "r1 = 2\n",
+ "r2 = 0.125\n",
+ "x1 = 8\n",
+ "x2 = 0.5\n",
+ "Z_2 = 12\n",
+ "\n",
+ "#Calculations\n",
+ "a = N_1 / N_2\n",
+ "R1 = r1 + a**2 * r2\n",
+ "X1 = x1 + a**2 * x2\n",
+ "Z1_2 = Z_2 * a**2\n",
+ "\n",
+ "I_1 = V_1 /(Z1_2+ complex(R1,X1))\n",
+ "V_2 = I_1 * Z1_2 / a\n",
+ "voltage_regulation = ((V_1/4)-abs(V_2))*100.0/V_2\n",
+ "\n",
+ "print( \"I_1 = {0:.2f}\".format(abs(I_1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_1.imag,I_1.real))))\n",
+ "print( \"V_2 = {0:.2f}\".format(abs(V_2.real)))\n",
+ "print(\"Angle = %.2f V \" %(math.degrees(math.atan2(V_2.imag,V_2.real))))\n",
+ "print( \"Voltage Regulation ={0:.5f}+{1:.5f}i\".format(voltage_regulation.real, voltage_regulation.imag))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I_1 = 6.08\n",
+ "Angle = -4.67 A \n",
+ "V_2 = 291.93\n",
+ "Angle = -4.67 V \n",
+ "Voltage Regulation =2.41487+0.19713i\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3, Page No 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P = 30e3\n",
+ "V_lt = 120.0\n",
+ "V_ht = 240.0\n",
+ "\n",
+ "#Calculations\n",
+ "I_1 = P / V_lt\n",
+ "I_2 = P / V_ht\n",
+ "V_2 = V_lt + V_ht\n",
+ "I_in = I_1 + I_2\n",
+ "input_kva = I_in * V_lt / 1e3\n",
+ "output_kva = I_2 * V_2 / 1e3\n",
+ "\n",
+ "#Results\n",
+ "print(\" Input kVA = %.0f kVA \" %input_kva)\n",
+ "print(\" Output kVA = %.0f kVA \" %output_kva)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Input kVA = 45 kVA \n",
+ " Output kVA = 45 kVA \n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.4 Page No 147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V_lt = 110.0\n",
+ "V_ht = 440.0\n",
+ "P = 2.5e3\n",
+ "x_lt = 0.06\n",
+ "\n",
+ "#Calculations\n",
+ "print('Viewed from low-tension side')\n",
+ "lt_base_impedance = (V_lt)**2 / P\n",
+ "print(\" Leakage reactance from low-tension side = %.2f ohm\" %x_lt)\n",
+ "print(\" Low-tension base impedance = %.2f ohmn\" %lt_base_impedance)\n",
+ "X_lt_pu = x_lt / lt_base_impedance\n",
+ "print(\" Leakage reactance in per unit from Low-tension side = %.4f per unit \" %X_lt_pu)\n",
+ "print('Viewed from high-tension side')\n",
+ "x_ht = x_lt * (V_ht / V_lt)**2\n",
+ "ht_base_impedance = (V_ht)**2 / P\n",
+ "\n",
+ "#Results\n",
+ "print(\" Leakage reactance from high-tension side = %.2f ohm\" %x_ht)\n",
+ "print(\" High-tension base impedance = %.2f ohmn\" %ht_base_impedance)\n",
+ "X_ht_pu = x_ht / ht_base_impedance\n",
+ "print(\" Leakage reactance in per unit from Low-tension side = %.4f per unit \" %X_ht_pu)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Viewed from low-tension side\n",
+ " Leakage reactance from low-tension side = 0.06 ohm\n",
+ " Low-tension base impedance = 4.84 ohmn\n",
+ " Leakage reactance in per unit from Low-tension side = 0.0124 per unit \n",
+ "Viewed from high-tension side\n",
+ " Leakage reactance from high-tension side = 0.96 ohm\n",
+ " High-tension base impedance = 77.44 ohmn\n",
+ " Leakage reactance in per unit from Low-tension side = 0.0124 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.5, Page No 147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P_AB = 10e6\n",
+ "V_AB_lt = 13.8e3\n",
+ "V_AB_ht = 138e3\n",
+ "x_AB = complex(0.1)\n",
+ "P_BC = 10e6\n",
+ "V_BC_lt = 69e3\n",
+ "V_BC_ht = 138e3\n",
+ "x_BC = complex(0.08)\n",
+ "P_base_B = 10e6\n",
+ "V_base_B = 138e3\n",
+ "Z_L = 300\n",
+ "V_load = 66e3\n",
+ "\n",
+ "#Calculations\n",
+ "V_base_A = (V_AB_lt/V_AB_ht)*V_base_B\n",
+ "V_base_C = (V_BC_lt/V_BC_ht)*V_base_B\n",
+ "base_impedance_C = (V_base_C)**2 / P_BC\n",
+ "Z_L_pu = Z_L / base_impedance_C\n",
+ "\n",
+ "#impedance diagram is shown in the xcos file\n",
+ "V_load_pu = V_load / V_base_C\n",
+ "I_L_pu = V_load_pu / Z_L_pu\n",
+ "voltage_input = (I_L_pu * (x_AB + x_BC)) + V_load_pu\n",
+ "voltage_regulation = (abs(voltage_input)-abs(V_load_pu))*100/abs(V_load_pu)\n",
+ "\n",
+ "#Results\n",
+ "print(\" Voltage regulation = %.2f percent \" %voltage_regulation)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Voltage regulation = 28.57 percent \n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6, Page No 151"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P = 25e6\n",
+ "V_ht = 38.1e3\n",
+ "V_lt = 3.81e3\n",
+ "R_l = 0.6\n",
+ "P_ht_base = 75e6\n",
+ "V_ht_base = 66e3\n",
+ "\n",
+ "#Calculations\n",
+ "#Low-tension side base ratings\n",
+ "print('Low-tension side')\n",
+ "P_lt_base = P_ht_base\n",
+ "V_lt_base = (V_lt/(V_ht*math.sqrt(3)))*V_ht_base\n",
+ "print(\" Base for low tension side is %.0f MVA,%.2f kV\" %(P_lt_base/1e6,V_lt_base/1e3))\n",
+ "Z_lt_base = (V_lt_base)**2/P_lt_base\n",
+ "R_lt_l_base = R_l / Z_lt_base\n",
+ "print(\" Base impedance for the low-tension side = %.2f ohm\" %Z_lt_base)\n",
+ "print(\" Per unit impedance of load on the low-tension side = %.2f per unit \" %R_lt_l_base)\n",
+ "\n",
+ "#Results\n",
+ "print('High-tension side')\n",
+ "R_l_ht = R_l * ((V_ht*math.sqrt(3))/V_lt)**2\n",
+ "Z_ht_base = (V_ht_base)**2 / P_ht_base\n",
+ "R_ht_l_base = R_l_ht / Z_ht_base\n",
+ "print(\" Base impedance for the high-tension side = %.2f ohm\" %Z_ht_base)\n",
+ "print(\" Per unit impedance of load on the high-tension side = %.2f per unit\" %R_ht_l_base)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Low-tension side\n",
+ " Base for low tension side is 75 MVA,3.81 kV\n",
+ " Base impedance for the low-tension side = 0.19 ohm\n",
+ " Per unit impedance of load on the low-tension side = 3.10 per unit \n",
+ "High-tension side\n",
+ " Base impedance for the high-tension side = 58.08 ohm\n",
+ " Per unit impedance of load on the high-tension side = 3.10 per unit\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7 Page No 152"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "z = 0.121\n",
+ "P = 400e6\n",
+ "V_ht = 220e3\n",
+ "V_lt = 22e3\n",
+ "V_ht_base = 230e3\n",
+ "P_ht_base = 100e6\n",
+ "\n",
+ "#Calculations\n",
+ "z_pu = z * P / (V_lt)**2\n",
+ "\n",
+ "#Results\n",
+ "print(\" On its own base the transformer reactance = %.2f per unit\" %z_pu)\n",
+ "z_new_pu=(z_pu * (V_ht/P_ht_base)**2 * (P_ht_base/P))\n",
+ "print(\" On the chosen base the reactance = %.4f per unit\" %z_new_pu)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " On its own base the transformer reactance = 0.10 per unit\n",
+ " On the chosen base the reactance = 0.0000 per unit\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7, Page No 154"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Z_ps = complex(0.07)\n",
+ "P_ps_base = 15e6\n",
+ "V_ps_base = 66e3\n",
+ "\n",
+ "Z_pt = complex(0.09)\n",
+ "P_pt_base = 15e6\n",
+ "V_pt_base = 66e3\n",
+ "Z_st = complex(0.08)\n",
+ "P_st_base = 10e6\n",
+ "V_st_base = 13.2e3\n",
+ "\n",
+ "#Calculations\n",
+ "Z_st_new = Z_st * P_ps_base / P_st_base\n",
+ "Z_p = (Z_ps + Z_pt - Z_st_new)/2\n",
+ "Z_s = (Z_ps - Z_pt + Z_st_new)/2\n",
+ "Z_t = (-Z_ps + Z_pt + Z_st_new)/2\n",
+ "\n",
+ "#Results\n",
+ "print( \"Z_p in per unit = {0:.5f}i\".format(Z_p.real))\n",
+ "print( \"Z_s in per unit = {0:.5f}i\".format(Z_s.real))\n",
+ "print( \"Z_t in per unit = {0:.5f}i\".format(Z_t.real))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Z_p in per unit = 0.02000i\n",
+ "Z_s in per unit = 0.05000i\n",
+ "Z_t in per unit = 0.07000i\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.9 Page No 155"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Z_ps = complex(0.07)\n",
+ "P_ps_base = 15e6\n",
+ "V_ps_base = 66e3\n",
+ "P_r_load = 5e6\n",
+ "V_r_load = 2.3e3\n",
+ "P_m = 7.5e6\n",
+ "V_m = 13.2e3\n",
+ "R_l = 1\n",
+ "X_11 = 0.20\n",
+ "\n",
+ "Z_pt = complex(0.09)\n",
+ "P_pt_base = 15e6\n",
+ "V_pt_base = 66e3\n",
+ "\n",
+ "Z_st = complex(0.08)\n",
+ "P_st_base = 10e6\n",
+ "V_st_base = 13.2e3\n",
+ "\n",
+ "#Calculations\n",
+ "Z_st_new = Z_st * P_ps_base / P_st_base\n",
+ "Z_p = (Z_ps + Z_pt - Z_st_new)/2\n",
+ "Z_s = (Z_ps - Z_pt + Z_st_new)/2\n",
+ "Z_t = (-Z_ps + Z_pt + Z_st_new)/2\n",
+ "\n",
+ "R_pu = R_l * P_ps_base / P_r_load\n",
+ "X11_pu = X_11 * P_ps_base / P_m\n",
+ "\n",
+ "#Results\n",
+ "print(\" On a base of 15MVA,2.3kV load resistance = %.1f per unit\" %R_pu)\n",
+ "print(\" Reactance of the motor at a base of 15MVA,13.2kV = %.2f per unit\" %X11_pu)\n",
+ "\n",
+ "#Reactance diagram is drawn in the xcos file\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " On a base of 15MVA,2.3kV load resistance = 3.0 per unit\n",
+ " Reactance of the motor at a base of 15MVA,13.2kV = 0.40 per unit\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.10 Page No 159"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "\n",
+ "def pucalc(pu_Z_given,base_kV_given,base_kV_new,base_kVA_new,base_kVA_given):\n",
+ " X11=(pu_Z_given * (base_kV_given/base_kV_new)**2 * (base_kVA_new/base_kVA_given))\n",
+ " return X11\n",
+ "\n",
+ "\n",
+ "P_g = 300e6\n",
+ "V_g = 20e3\n",
+ "X11_g = 0.20\n",
+ "l = 64\n",
+ "V_m = 13.2e3\n",
+ "P_m1 = 200e6\n",
+ "P_m2 = 100e6\n",
+ "X11_m = 0.20\n",
+ "T1_P = 350e6\n",
+ "T1_vht = 230e3\n",
+ "T1_vlt = 20e3\n",
+ "x_T1 = 0.10\n",
+ "T2_1_P = 100e6\n",
+ "T2_1_vht = 127e3\n",
+ "T2_1_vlt = 13.2e3\n",
+ "x_T2 = 0.10\n",
+ "x_line = 0.5\t\t#ohm per km\n",
+ "V_base = V_g\n",
+ "P_base = P_g\n",
+ "\n",
+ "#Calculations\n",
+ "T2_P = 3*T2_1_P\n",
+ "T2_vht = math.sqrt(3)*T2_1_vht\n",
+ "T2_vlt = T2_1_vlt\n",
+ "V_base_line = (T1_vht/T1_vlt)*V_base\n",
+ "V_base_m = V_base_line * (T2_vlt/T2_vht)\n",
+ "x_T1_base = x_T1 * (P_base/T1_P)\n",
+ "x_T2_base = x_T2 * (T2_vlt/V_base_m)\n",
+ "z_line_base = (V_base_line)**2/P_base\n",
+ "x_line_pu = x_line * l / z_line_base\n",
+ "X11_m1_pu = pucalc(X11_m,V_m,V_base_m,P_base,P_m1)\n",
+ "X11_m2_pu = pucalc(X11_m,V_m,V_base_m,P_base,P_m2)\n",
+ "\n",
+ "#Results\n",
+ "#Reactance diagram is given in xcos file\n",
+ "print('Base Voltages in different parts of circuit')\n",
+ "print(\" Generator voltage = %.0f kV\" %(V_g/1e3))\n",
+ "print(\" Line voltage = %.0f kV\" %(V_base_line/1e3))\n",
+ "print(\" Motor voltage = %.1f kV \" %(V_base_m/1e3))\n",
+ "\n",
+ "print('Base reactance in different parts of circuit')\n",
+ "print(\" Transformer 1 reactance = %.4f per unit\" %x_T1_base)\n",
+ "print(\" Transformer 2 reactance = %.4f per unit\" %x_T2_base)\n",
+ "print(\" Line reactance = %.4f per unit\" %x_line_pu)\n",
+ "print(\" Motor 1 reactance = %.4f per unit\" %X11_m1_pu)\n",
+ "print(\" Motor 2 reactance = %.4f per unit\" %X11_m2_pu)\n",
+ "#impedance diagram is shown in the xcos file\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base Voltages in different parts of circuit\n",
+ " Generator voltage = 20 kV\n",
+ " Line voltage = 230 kV\n",
+ " Motor voltage = 13.8 kV \n",
+ "Base reactance in different parts of circuit\n",
+ " Transformer 1 reactance = 0.0857 per unit\n",
+ " Transformer 2 reactance = 0.0956 per unit\n",
+ " Line reactance = 0.1815 per unit\n",
+ " Motor 1 reactance = 0.2744 per unit\n",
+ " Motor 2 reactance = 0.5488 per unit\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.11 Page No 160"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P_g = 300e6\n",
+ "V_g = 20e3\n",
+ "X11_g = 0.20\n",
+ "l = 64\n",
+ "V_m = 13.2e3\n",
+ "P_m1 = 120e6\n",
+ "P_m2 = 60e6\n",
+ "X11_m = 0.20\n",
+ "T1_P = 350e6\n",
+ "T1_vht = 230e3\n",
+ "T1_vlt = 20e3\n",
+ "x_T1 = 0.10\n",
+ "T2_1_P = 100e6\n",
+ "T2_1_vht = 127e3\n",
+ "T2_1_vlt = 13.2e3\n",
+ "x_T2 = 0.10\n",
+ "x_line = 0.5#onhm per km\n",
+ "V_base = V_g\n",
+ "P_base = P_g\n",
+ "\n",
+ "#Calculations\n",
+ "T2_P = 3*T2_1_P\n",
+ "T2_vht = math.sqrt(3)*T2_1_vht\n",
+ "T2_vlt = T2_1_vlt\n",
+ "V_base_line = (T1_vht/T1_vlt)*V_base\n",
+ "V_base_m = V_base_line * (T2_vlt/T2_vht)\n",
+ "x_T1_base = x_T1 * (P_base/T1_P)\n",
+ "x_T2_base = x_T2 * (T2_vlt/V_base_m)\n",
+ "z_line_base = (V_base_line)**2/P_base\n",
+ "x_line_pu = x_line * l / z_line_base\n",
+ "P = P_m1 + P_m2\n",
+ "P_pu = P / P_base\n",
+ "V = V_m / V_base_m\n",
+ "I = P_pu / V\n",
+ "Vg = V + I * (complex(x_T1_base) + complex(x_T2_base) + complex(x_line_pu))\n",
+ "V_terminal = abs(Vg) * V_g\n",
+ "\n",
+ "#Results\n",
+ "print(\" The generator terminal voltage = %.2f kV\" %(V_terminal / 1e3))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The generator terminal voltage = 23.68 kV\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo07.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo07.ipynb
new file mode 100755
index 00000000..76fb395e
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo07.ipynb
@@ -0,0 +1,386 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 07 : Network Calculations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1, Page No 170"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "#Voltage Sources\n",
+ "Ea = 1.5\n",
+ "Eb = 1.5*complex(math.cos(-36.87 * math.pi / 180),math.sin(-36.87 * math.pi / 180))\n",
+ "Ec = 1.5\n",
+ "#admittances\n",
+ "Ya = -complex(0.8)\n",
+ "Yb = Ya\n",
+ "Yc= Ya\n",
+ "Yd = -complex(5)\n",
+ "Ye = -complex(8)\n",
+ "Yf = -complex(4)\n",
+ "Yg = -complex(2.5)\n",
+ "Yh = Yd\n",
+ "\n",
+ "#Calculations\n",
+ "#current sourcs\n",
+ "I1 = Ea * Ya\n",
+ "I2 = Eb * Yb\n",
+ "I3 = I1\n",
+ "I4 = 0\n",
+ "print('Current Sources are')\n",
+ "print(\" I1 = - j%.2f per unit\" %(-I1.imag))\n",
+ "print(\" I2 = %.2f - j%.2f per unit\" %(I2.real,-I2.imag))\n",
+ "print(\" I3 = - j%.2f per unit \" %(-I3.imag))\n",
+ "#Self-admittances\n",
+ "Y11 = Yd + Yf + Ya\n",
+ "Y22 = Yh + Yg + Yb\n",
+ "Y33 = Ye + Yc + Yg + Yf\n",
+ "Y44 = Yd + Ye + Yh\n",
+ "print('Self-admittances are')\n",
+ "print(\" Y11 = - j%.2f per unit\" %(-Y11.imag))\n",
+ "print(\" Y22 = - j%.2f per unit\" %(-Y22.imag))\n",
+ "print(\" Y33 = - j%.2f per unit\" %(-Y33.imag))\n",
+ "print(\" Y44 = - j%.2f per unit\" %(-Y44.imag))\n",
+ "#Mutual-admittances\n",
+ "Y12 = 0;Y21 = Y12\n",
+ "Y13 = -Yf;Y31 = Y13\n",
+ "Y14 = -Yd;Y41 = Y14\n",
+ "Y23 = -Yg;Y32 = Y23\n",
+ "Y24 = -Yh;Y42 = Y24;\n",
+ "Y34 = -Ye;Y43 = Y34\n",
+ "print('Mutual admittances are')\n",
+ "print(\" Y12 = - j%.2f per unit\" %(-Y12.imag))\n",
+ "print(\" Y13 = - j%.2f per unit\" %(-Y13.imag))\n",
+ "print(\" Y14 = - j%.2f per unit\" %(-Y14.imag))\n",
+ "print(\" Y23 = - j%.2f per unit\" %(-Y23.imag))\n",
+ "print(\" Y24 = - j%.2f per unit\" %(-Y24.imag))\n",
+ "print(\" Y34 = - j%.2f per unit\" %(-Y34.imag))\n",
+ "#Matrix Form\n",
+ "I = [I1.real,I2.imag,I3.real,I4.imag]\n",
+ "Y = [[Y11.real,Y12.real,Y13.real,Y14.real],\n",
+ " [Y21.real,Y22.real,Y23.real,Y24.real],\n",
+ " [Y31.real,Y32.real,Y33.real,Y34.real],\n",
+ " [Y41.real,Y42.real,Y43.real,Y44.real]]\n",
+ "print('Current Vector =')\n",
+ "for i in range(0, 4):\n",
+ " print(\"I= %.2f\" %I[i])\n",
+ "\t\n",
+ "print('Bus admittance matrix =')\n",
+ "for x in range(0, 4):\n",
+ " for y in range(0, 4):\n",
+ " print(\"Y[%.0f][%.0f]= %.2f\" %(x,y,Y[x][y]))\n",
+ " print(\"\\n\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current Sources are\n",
+ " I1 = - j0.00 per unit\n",
+ " I2 = -0.96 - j-0.72 per unit\n",
+ " I3 = - j0.00 per unit \n",
+ "Self-admittances are\n",
+ " Y11 = - j0.00 per unit\n",
+ " Y22 = - j0.00 per unit\n",
+ " Y33 = - j0.00 per unit\n",
+ " Y44 = - j0.00 per unit\n",
+ "Mutual admittances are\n",
+ " Y12 = - j0.00 per unit\n",
+ " Y13 = - j-0.00 per unit\n",
+ " Y14 = - j-0.00 per unit\n",
+ " Y23 = - j-0.00 per unit\n",
+ " Y24 = - j-0.00 per unit\n",
+ " Y34 = - j-0.00 per unit\n",
+ "Current Vector =\n",
+ "I= -1.20\n",
+ "I= 0.72\n",
+ "I= -1.20\n",
+ "I= 0.00\n",
+ "Bus admittance matrix =\n",
+ "Y[0][0]= -9.80\n",
+ "Y[0][1]= 0.00\n",
+ "Y[0][2]= 4.00\n",
+ "Y[0][3]= 5.00\n",
+ "\n",
+ "\n",
+ "Y[1][0]= 0.00\n",
+ "Y[1][1]= -8.30\n",
+ "Y[1][2]= 2.50\n",
+ "Y[1][3]= 5.00\n",
+ "\n",
+ "\n",
+ "Y[2][0]= 4.00\n",
+ "Y[2][1]= 2.50\n",
+ "Y[2][2]= -15.30\n",
+ "Y[2][3]= 8.00\n",
+ "\n",
+ "\n",
+ "Y[3][0]= 5.00\n",
+ "Y[3][1]= 5.00\n",
+ "Y[3][2]= 8.00\n",
+ "Y[3][3]= -18.00\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2, Page No 171"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy\n",
+ "#initialisation of variables\n",
+ "#Voltage Sources\n",
+ "Ea = 1.5\n",
+ "Eb = 1.5*complex(math.cos(-36.87*math.pi/180),math.sin(-36.87 * math.pi / 180))\n",
+ "Ec = 1.5;\n",
+ "#admittances\n",
+ "Ya = complex(-0.8)\n",
+ "Yb = Ya\n",
+ "Yc= Ya\n",
+ "Yd = complex(-5)\n",
+ "Ye = complex(-8)\n",
+ "Yf = complex(-4)\n",
+ "Yg = complex(-2.5)\n",
+ "Yh = Yd\n",
+ "\n",
+ "#Calculations\n",
+ "#current sourcs\n",
+ "I1 = Ea * Ya\n",
+ "I2 = Eb * Yb\n",
+ "I3 = I1\n",
+ "I4 = 0\n",
+ "#Self-admittances\n",
+ "Y11 = Yd + Yf + Ya\n",
+ "Y22 = Yh + Yg + Yb\n",
+ "Y33 = Ye + Yc + Yg + Yf\n",
+ "Y44 = Yd + Ye + Yh\n",
+ "#Mutual-admittances\n",
+ "Y12 = 0\n",
+ "Y21 = Y12\n",
+ "Y13 = -Yf\n",
+ "Y31 = Y13\n",
+ "Y14 = -Yd\n",
+ "Y41 = Y14\n",
+ "Y23 = -Yg\n",
+ "Y32 = Y23\n",
+ "Y24 = -Yh\n",
+ "Y42 = Y24\n",
+ "Y34 = -Ye\n",
+ "Y43 = Y34\n",
+ "#Matrix Form\n",
+ "I = [I1,I2,I3,I4]\n",
+ "Y = [[Y11,Y12,Y13,Y14],[Y21,Y22,Y23,Y24],[Y31,Y32,Y33,Y34],[Y41,Y42,Y43,Y44]]\n",
+ "V = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]\n",
+ "for x in range(0, 4):\n",
+ " for y in range(0, 4):\n",
+ " if I[x].imag > 0 :\n",
+ " V[x][y]=Y[x][y]/I[x]\n",
+ " else:\n",
+ " V[x][y]=0\n",
+ "\n",
+ "#Results\n",
+ "print('Node Voltages V1,V2,V3 and V4 in per unit is')\n",
+ "for x in range(0, 4):\n",
+ " for y in range(0, 4):\n",
+ " print(\"V[%.0f][%.0f]= %.2f -%.2fi\" %(x,y,V[x][y].imag,V[x][y].real))\n",
+ " print(\"\\n\")\n",
+ "\n",
+ "print('In polar form')\n",
+ "print( \"V1 = {0:.2f}\".format(abs(V[0][0].real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(V[0][0].imag,V[0][0].real))*180/math.pi))\n",
+ "print( \"V2 = {0:.2f}\".format(abs(V[1][1].real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(V[1][1].imag,V[1][1].real))*180/math.pi))\n",
+ "print( \"V2 = {0:.2f}\".format(abs(V[2][2].real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(V[2][2].imag,V[2][2].real))*180/math.pi))\n",
+ "print( \"V2 = {0:.2f}\".format(abs(V[3][3].real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(V[3][3].imag,V[3][3].real))*180/math.pi))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Node Voltages V1,V2,V3 and V4 in per unit is\n",
+ "V[0][0]= 0.00 -0.00i\n",
+ "V[0][1]= 0.00 -0.00i\n",
+ "V[0][2]= 0.00 -0.00i\n",
+ "V[0][3]= 0.00 -0.00i\n",
+ "\n",
+ "\n",
+ "V[1][0]= -0.00 --0.00i\n",
+ "V[1][1]= 4.15 -5.53i\n",
+ "V[1][2]= -1.25 --1.67i\n",
+ "V[1][3]= -2.50 --3.33i\n",
+ "\n",
+ "\n",
+ "V[2][0]= 0.00 -0.00i\n",
+ "V[2][1]= 0.00 -0.00i\n",
+ "V[2][2]= 0.00 -0.00i\n",
+ "V[2][3]= 0.00 -0.00i\n",
+ "\n",
+ "\n",
+ "V[3][0]= 0.00 -0.00i\n",
+ "V[3][1]= 0.00 -0.00i\n",
+ "V[3][2]= 0.00 -0.00i\n",
+ "V[3][3]= 0.00 -0.00i\n",
+ "\n",
+ "\n",
+ "In polar form\n",
+ "V1 = 0.00\n",
+ "Angle = 0.00 v \n",
+ "V2 = 5.53\n",
+ "Angle = 2112.50 v \n",
+ "V2 = 0.00\n",
+ "Angle = 0.00 v \n",
+ "V2 = 0.00\n",
+ "Angle = 0.00 v \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3, Page No 177"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Ea = 1.5\n",
+ "Eb = 1.5*complex(math.cos(-36.87 *math.pi / 180),math.sin(-36.87 * math.pi / 180))\n",
+ "Ec = 1.5\n",
+ "#admittances\n",
+ "Ya = -complex(0.8)\n",
+ "Yb = Ya\n",
+ "Yc= Ya\n",
+ "Yd = -complex(5)\n",
+ "Ye = -complex(8)\n",
+ "Yf = -complex(4)\n",
+ "Yg = -complex(2.5)\n",
+ "Yh = Yd\n",
+ "#Self-admittances\n",
+ "Y11 = Yd + Yf + Ya\n",
+ "Y22 = Yh + Yg + Yb\n",
+ "Y33 = Ye + Yg + Yf\n",
+ "Y44 = Yd + Ye + Yh\n",
+ "#Mutual-admittances\n",
+ "Y12 = 0\n",
+ "Y21 = Y12\n",
+ "Y13 = -Yf\n",
+ "Y31 = Y13\n",
+ "Y14 = -Yd\n",
+ "Y41 = Y14\n",
+ "Y23 = -Yg\n",
+ "Y32 = Y23\n",
+ "Y24 = -Yh\n",
+ "Y42 = Y24\n",
+ "Y34 = -Ye\n",
+ "Y43 = Y34\n",
+ "\n",
+ "#Calculations\n",
+ "#Bus Impedance Matrix\n",
+ "Y = [[Y11,Y12,Y13,Y14],[Y21,Y22,Y23,Y24],[Y31,Y32,Y33,Y34],[Y41,Y42,Y43,Y44]]\n",
+ "K = [[Y[0][0],Y[0][1]],[Y[1][0],Y[1][1]]]\n",
+ "L = [[Y[0][2],Y[0][3]],[Y[1][2],Y[1][3]]]\n",
+ "L_T = [[Y[2][0],Y[2][1]],[Y[3][0],Y[3][1]]]\n",
+ "M = [[Y[2][2],Y[2][3]],[Y[3][2],Y[3][3]]]\n",
+ "Ybus = [[0,0],[0,0]]\n",
+ "M_1 = [[complex(0.0913706),complex(0.0406091)],[complex(0.0406091),complex(0.0736041)]]\n",
+ "LMT = [[complex(-4.9263959),complex(-4.0736041)],[complex(-4.0736041),complex(-3.4263959)]]\n",
+ "for x in range(0, 2):\n",
+ " for y in range(0, 2):\n",
+ " Ybus[x][y]=K[x][y]-LMT[x][y] \n",
+ "Y_12 = - Ybus[0][1]\n",
+ "Y_10 = Ybus[0][0] - Y_12\n",
+ "Y_20 = Y_10\n",
+ "print(\" Admittance between buses 1 and 2 = - j%.4f per unit\" %(-Y_12.imag))\n",
+ "print(\" Admittance between buse 1 and reference bus = - j%.4f per unit\" %(-Y_10.imag))\n",
+ "print(\" Admittance between buse 2 and reference bus = - j%.4f per unit\" %(-Y_20.imag))\n",
+ "Z = 1/Y_12 + 1/Y_10 + 1/Y_20\n",
+ "I = (Ea-Eb) / Z\n",
+ "print( \"I = {0:.2f}\".format(abs(I.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(I.imag,I.real))))\n",
+ "I1=complex(0.3278120,0.1092710)\n",
+ "Pa = Ea * I1\n",
+ "\n",
+ "#Resluts\n",
+ "print(\" Power out of source ''a'' = %.3f + j%.3f per unit \" %(Pa.real,Pa.imag))\n",
+ "Pb = Eb * I1\n",
+ "print(\" Power out of source ''b'' = %.3f - j%.3f per unit \" %(Pb.real,-Pb.imag))\n",
+ "Var = (abs(I))**2 * (Z.imag)\n",
+ "print(\" Reactie voltamperes in circuit equivalent = %.3f per unit \" %Var)\n",
+ "V_1 = Ea - I/Y_10\n",
+ "print(\" Voltage at node 1 = %.3f - j%.3f per unit \" %(V_1.real,-V_1.imag))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Admittance between buses 1 and 2 = - j0.0000 per unit\n",
+ " Admittance between buse 1 and reference bus = - j-0.0000 per unit\n",
+ " Admittance between buse 2 and reference bus = - j-0.0000 per unit\n",
+ "I = 0.11\n",
+ "Angle = -108.44 v \n",
+ " Power out of source ''a'' = 0.492 + j0.164 per unit \n",
+ " Power out of source ''b'' = 0.492 - j0.164 per unit \n",
+ " Reactie voltamperes in circuit equivalent = -0.000 per unit \n",
+ " Voltage at node 1 = 1.363 - j0.410 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo07_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo07_1.ipynb
new file mode 100755
index 00000000..76fb395e
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo07_1.ipynb
@@ -0,0 +1,386 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 07 : Network Calculations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1, Page No 170"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "#Voltage Sources\n",
+ "Ea = 1.5\n",
+ "Eb = 1.5*complex(math.cos(-36.87 * math.pi / 180),math.sin(-36.87 * math.pi / 180))\n",
+ "Ec = 1.5\n",
+ "#admittances\n",
+ "Ya = -complex(0.8)\n",
+ "Yb = Ya\n",
+ "Yc= Ya\n",
+ "Yd = -complex(5)\n",
+ "Ye = -complex(8)\n",
+ "Yf = -complex(4)\n",
+ "Yg = -complex(2.5)\n",
+ "Yh = Yd\n",
+ "\n",
+ "#Calculations\n",
+ "#current sourcs\n",
+ "I1 = Ea * Ya\n",
+ "I2 = Eb * Yb\n",
+ "I3 = I1\n",
+ "I4 = 0\n",
+ "print('Current Sources are')\n",
+ "print(\" I1 = - j%.2f per unit\" %(-I1.imag))\n",
+ "print(\" I2 = %.2f - j%.2f per unit\" %(I2.real,-I2.imag))\n",
+ "print(\" I3 = - j%.2f per unit \" %(-I3.imag))\n",
+ "#Self-admittances\n",
+ "Y11 = Yd + Yf + Ya\n",
+ "Y22 = Yh + Yg + Yb\n",
+ "Y33 = Ye + Yc + Yg + Yf\n",
+ "Y44 = Yd + Ye + Yh\n",
+ "print('Self-admittances are')\n",
+ "print(\" Y11 = - j%.2f per unit\" %(-Y11.imag))\n",
+ "print(\" Y22 = - j%.2f per unit\" %(-Y22.imag))\n",
+ "print(\" Y33 = - j%.2f per unit\" %(-Y33.imag))\n",
+ "print(\" Y44 = - j%.2f per unit\" %(-Y44.imag))\n",
+ "#Mutual-admittances\n",
+ "Y12 = 0;Y21 = Y12\n",
+ "Y13 = -Yf;Y31 = Y13\n",
+ "Y14 = -Yd;Y41 = Y14\n",
+ "Y23 = -Yg;Y32 = Y23\n",
+ "Y24 = -Yh;Y42 = Y24;\n",
+ "Y34 = -Ye;Y43 = Y34\n",
+ "print('Mutual admittances are')\n",
+ "print(\" Y12 = - j%.2f per unit\" %(-Y12.imag))\n",
+ "print(\" Y13 = - j%.2f per unit\" %(-Y13.imag))\n",
+ "print(\" Y14 = - j%.2f per unit\" %(-Y14.imag))\n",
+ "print(\" Y23 = - j%.2f per unit\" %(-Y23.imag))\n",
+ "print(\" Y24 = - j%.2f per unit\" %(-Y24.imag))\n",
+ "print(\" Y34 = - j%.2f per unit\" %(-Y34.imag))\n",
+ "#Matrix Form\n",
+ "I = [I1.real,I2.imag,I3.real,I4.imag]\n",
+ "Y = [[Y11.real,Y12.real,Y13.real,Y14.real],\n",
+ " [Y21.real,Y22.real,Y23.real,Y24.real],\n",
+ " [Y31.real,Y32.real,Y33.real,Y34.real],\n",
+ " [Y41.real,Y42.real,Y43.real,Y44.real]]\n",
+ "print('Current Vector =')\n",
+ "for i in range(0, 4):\n",
+ " print(\"I= %.2f\" %I[i])\n",
+ "\t\n",
+ "print('Bus admittance matrix =')\n",
+ "for x in range(0, 4):\n",
+ " for y in range(0, 4):\n",
+ " print(\"Y[%.0f][%.0f]= %.2f\" %(x,y,Y[x][y]))\n",
+ " print(\"\\n\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current Sources are\n",
+ " I1 = - j0.00 per unit\n",
+ " I2 = -0.96 - j-0.72 per unit\n",
+ " I3 = - j0.00 per unit \n",
+ "Self-admittances are\n",
+ " Y11 = - j0.00 per unit\n",
+ " Y22 = - j0.00 per unit\n",
+ " Y33 = - j0.00 per unit\n",
+ " Y44 = - j0.00 per unit\n",
+ "Mutual admittances are\n",
+ " Y12 = - j0.00 per unit\n",
+ " Y13 = - j-0.00 per unit\n",
+ " Y14 = - j-0.00 per unit\n",
+ " Y23 = - j-0.00 per unit\n",
+ " Y24 = - j-0.00 per unit\n",
+ " Y34 = - j-0.00 per unit\n",
+ "Current Vector =\n",
+ "I= -1.20\n",
+ "I= 0.72\n",
+ "I= -1.20\n",
+ "I= 0.00\n",
+ "Bus admittance matrix =\n",
+ "Y[0][0]= -9.80\n",
+ "Y[0][1]= 0.00\n",
+ "Y[0][2]= 4.00\n",
+ "Y[0][3]= 5.00\n",
+ "\n",
+ "\n",
+ "Y[1][0]= 0.00\n",
+ "Y[1][1]= -8.30\n",
+ "Y[1][2]= 2.50\n",
+ "Y[1][3]= 5.00\n",
+ "\n",
+ "\n",
+ "Y[2][0]= 4.00\n",
+ "Y[2][1]= 2.50\n",
+ "Y[2][2]= -15.30\n",
+ "Y[2][3]= 8.00\n",
+ "\n",
+ "\n",
+ "Y[3][0]= 5.00\n",
+ "Y[3][1]= 5.00\n",
+ "Y[3][2]= 8.00\n",
+ "Y[3][3]= -18.00\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2, Page No 171"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy\n",
+ "#initialisation of variables\n",
+ "#Voltage Sources\n",
+ "Ea = 1.5\n",
+ "Eb = 1.5*complex(math.cos(-36.87*math.pi/180),math.sin(-36.87 * math.pi / 180))\n",
+ "Ec = 1.5;\n",
+ "#admittances\n",
+ "Ya = complex(-0.8)\n",
+ "Yb = Ya\n",
+ "Yc= Ya\n",
+ "Yd = complex(-5)\n",
+ "Ye = complex(-8)\n",
+ "Yf = complex(-4)\n",
+ "Yg = complex(-2.5)\n",
+ "Yh = Yd\n",
+ "\n",
+ "#Calculations\n",
+ "#current sourcs\n",
+ "I1 = Ea * Ya\n",
+ "I2 = Eb * Yb\n",
+ "I3 = I1\n",
+ "I4 = 0\n",
+ "#Self-admittances\n",
+ "Y11 = Yd + Yf + Ya\n",
+ "Y22 = Yh + Yg + Yb\n",
+ "Y33 = Ye + Yc + Yg + Yf\n",
+ "Y44 = Yd + Ye + Yh\n",
+ "#Mutual-admittances\n",
+ "Y12 = 0\n",
+ "Y21 = Y12\n",
+ "Y13 = -Yf\n",
+ "Y31 = Y13\n",
+ "Y14 = -Yd\n",
+ "Y41 = Y14\n",
+ "Y23 = -Yg\n",
+ "Y32 = Y23\n",
+ "Y24 = -Yh\n",
+ "Y42 = Y24\n",
+ "Y34 = -Ye\n",
+ "Y43 = Y34\n",
+ "#Matrix Form\n",
+ "I = [I1,I2,I3,I4]\n",
+ "Y = [[Y11,Y12,Y13,Y14],[Y21,Y22,Y23,Y24],[Y31,Y32,Y33,Y34],[Y41,Y42,Y43,Y44]]\n",
+ "V = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]\n",
+ "for x in range(0, 4):\n",
+ " for y in range(0, 4):\n",
+ " if I[x].imag > 0 :\n",
+ " V[x][y]=Y[x][y]/I[x]\n",
+ " else:\n",
+ " V[x][y]=0\n",
+ "\n",
+ "#Results\n",
+ "print('Node Voltages V1,V2,V3 and V4 in per unit is')\n",
+ "for x in range(0, 4):\n",
+ " for y in range(0, 4):\n",
+ " print(\"V[%.0f][%.0f]= %.2f -%.2fi\" %(x,y,V[x][y].imag,V[x][y].real))\n",
+ " print(\"\\n\")\n",
+ "\n",
+ "print('In polar form')\n",
+ "print( \"V1 = {0:.2f}\".format(abs(V[0][0].real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(V[0][0].imag,V[0][0].real))*180/math.pi))\n",
+ "print( \"V2 = {0:.2f}\".format(abs(V[1][1].real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(V[1][1].imag,V[1][1].real))*180/math.pi))\n",
+ "print( \"V2 = {0:.2f}\".format(abs(V[2][2].real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(V[2][2].imag,V[2][2].real))*180/math.pi))\n",
+ "print( \"V2 = {0:.2f}\".format(abs(V[3][3].real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(V[3][3].imag,V[3][3].real))*180/math.pi))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Node Voltages V1,V2,V3 and V4 in per unit is\n",
+ "V[0][0]= 0.00 -0.00i\n",
+ "V[0][1]= 0.00 -0.00i\n",
+ "V[0][2]= 0.00 -0.00i\n",
+ "V[0][3]= 0.00 -0.00i\n",
+ "\n",
+ "\n",
+ "V[1][0]= -0.00 --0.00i\n",
+ "V[1][1]= 4.15 -5.53i\n",
+ "V[1][2]= -1.25 --1.67i\n",
+ "V[1][3]= -2.50 --3.33i\n",
+ "\n",
+ "\n",
+ "V[2][0]= 0.00 -0.00i\n",
+ "V[2][1]= 0.00 -0.00i\n",
+ "V[2][2]= 0.00 -0.00i\n",
+ "V[2][3]= 0.00 -0.00i\n",
+ "\n",
+ "\n",
+ "V[3][0]= 0.00 -0.00i\n",
+ "V[3][1]= 0.00 -0.00i\n",
+ "V[3][2]= 0.00 -0.00i\n",
+ "V[3][3]= 0.00 -0.00i\n",
+ "\n",
+ "\n",
+ "In polar form\n",
+ "V1 = 0.00\n",
+ "Angle = 0.00 v \n",
+ "V2 = 5.53\n",
+ "Angle = 2112.50 v \n",
+ "V2 = 0.00\n",
+ "Angle = 0.00 v \n",
+ "V2 = 0.00\n",
+ "Angle = 0.00 v \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3, Page No 177"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Ea = 1.5\n",
+ "Eb = 1.5*complex(math.cos(-36.87 *math.pi / 180),math.sin(-36.87 * math.pi / 180))\n",
+ "Ec = 1.5\n",
+ "#admittances\n",
+ "Ya = -complex(0.8)\n",
+ "Yb = Ya\n",
+ "Yc= Ya\n",
+ "Yd = -complex(5)\n",
+ "Ye = -complex(8)\n",
+ "Yf = -complex(4)\n",
+ "Yg = -complex(2.5)\n",
+ "Yh = Yd\n",
+ "#Self-admittances\n",
+ "Y11 = Yd + Yf + Ya\n",
+ "Y22 = Yh + Yg + Yb\n",
+ "Y33 = Ye + Yg + Yf\n",
+ "Y44 = Yd + Ye + Yh\n",
+ "#Mutual-admittances\n",
+ "Y12 = 0\n",
+ "Y21 = Y12\n",
+ "Y13 = -Yf\n",
+ "Y31 = Y13\n",
+ "Y14 = -Yd\n",
+ "Y41 = Y14\n",
+ "Y23 = -Yg\n",
+ "Y32 = Y23\n",
+ "Y24 = -Yh\n",
+ "Y42 = Y24\n",
+ "Y34 = -Ye\n",
+ "Y43 = Y34\n",
+ "\n",
+ "#Calculations\n",
+ "#Bus Impedance Matrix\n",
+ "Y = [[Y11,Y12,Y13,Y14],[Y21,Y22,Y23,Y24],[Y31,Y32,Y33,Y34],[Y41,Y42,Y43,Y44]]\n",
+ "K = [[Y[0][0],Y[0][1]],[Y[1][0],Y[1][1]]]\n",
+ "L = [[Y[0][2],Y[0][3]],[Y[1][2],Y[1][3]]]\n",
+ "L_T = [[Y[2][0],Y[2][1]],[Y[3][0],Y[3][1]]]\n",
+ "M = [[Y[2][2],Y[2][3]],[Y[3][2],Y[3][3]]]\n",
+ "Ybus = [[0,0],[0,0]]\n",
+ "M_1 = [[complex(0.0913706),complex(0.0406091)],[complex(0.0406091),complex(0.0736041)]]\n",
+ "LMT = [[complex(-4.9263959),complex(-4.0736041)],[complex(-4.0736041),complex(-3.4263959)]]\n",
+ "for x in range(0, 2):\n",
+ " for y in range(0, 2):\n",
+ " Ybus[x][y]=K[x][y]-LMT[x][y] \n",
+ "Y_12 = - Ybus[0][1]\n",
+ "Y_10 = Ybus[0][0] - Y_12\n",
+ "Y_20 = Y_10\n",
+ "print(\" Admittance between buses 1 and 2 = - j%.4f per unit\" %(-Y_12.imag))\n",
+ "print(\" Admittance between buse 1 and reference bus = - j%.4f per unit\" %(-Y_10.imag))\n",
+ "print(\" Admittance between buse 2 and reference bus = - j%.4f per unit\" %(-Y_20.imag))\n",
+ "Z = 1/Y_12 + 1/Y_10 + 1/Y_20\n",
+ "I = (Ea-Eb) / Z\n",
+ "print( \"I = {0:.2f}\".format(abs(I.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(I.imag,I.real))))\n",
+ "I1=complex(0.3278120,0.1092710)\n",
+ "Pa = Ea * I1\n",
+ "\n",
+ "#Resluts\n",
+ "print(\" Power out of source ''a'' = %.3f + j%.3f per unit \" %(Pa.real,Pa.imag))\n",
+ "Pb = Eb * I1\n",
+ "print(\" Power out of source ''b'' = %.3f - j%.3f per unit \" %(Pb.real,-Pb.imag))\n",
+ "Var = (abs(I))**2 * (Z.imag)\n",
+ "print(\" Reactie voltamperes in circuit equivalent = %.3f per unit \" %Var)\n",
+ "V_1 = Ea - I/Y_10\n",
+ "print(\" Voltage at node 1 = %.3f - j%.3f per unit \" %(V_1.real,-V_1.imag))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Admittance between buses 1 and 2 = - j0.0000 per unit\n",
+ " Admittance between buse 1 and reference bus = - j-0.0000 per unit\n",
+ " Admittance between buse 2 and reference bus = - j-0.0000 per unit\n",
+ "I = 0.11\n",
+ "Angle = -108.44 v \n",
+ " Power out of source ''a'' = 0.492 + j0.164 per unit \n",
+ " Power out of source ''b'' = 0.492 - j0.164 per unit \n",
+ " Reactie voltamperes in circuit equivalent = -0.000 per unit \n",
+ " Voltage at node 1 = 1.363 - j0.410 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo08.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo08.ipynb
new file mode 100755
index 00000000..78378c7d
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo08.ipynb
@@ -0,0 +1,348 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 08 : Load Flow Solutions And Control"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.1, Page No 200"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P = 100e6\n",
+ "V = 138e3\n",
+ "#From Table 8.1\n",
+ "R_12 = 0.042\n",
+ "R_15 = 0.031\n",
+ "R_23 = 0.031\n",
+ "R_34 = 0.084\n",
+ "R_25 = 0.053\n",
+ "R_45 = 0.063\n",
+ "X_12 = 0.168\n",
+ "X_15 = 0.126\n",
+ "X_23 = 0.126\n",
+ "X_34 = 0.336\n",
+ "X_25 = 0.210\n",
+ "X_45 = 0.252\n",
+ "#From Table 8.2\n",
+ "V1 = 1.04\n",
+ "V2 = 1\n",
+ "V3 = 1.02\n",
+ "V4 = 1\n",
+ "V5 = 1\n",
+ "P_2 = 115e6\n",
+ "\n",
+ "#Calculation\n",
+ "Y_21=- 1/complex(R_12,X_12)\n",
+ "print( \"Y21 = {0:.2f}\".format(abs(Y_21.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Y_21.imag,Y_21.real))*180/math.pi))\n",
+ "Y_23=-1/complex(R_23,X_23)\n",
+ "print( \"Y23 = {0:.2f}\".format(abs(Y_23.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Y_23.imag,Y_23.real))*180/math.pi))\n",
+ "\n",
+ "Y_21mag = abs(Y_21)\n",
+ "Y_21ang = math.degrees(math.atan2(Y_21.imag,Y_21.real))\n",
+ "Y_23mag = abs(Y_23)\n",
+ "Y_23ang = math.degrees(math.atan2(Y_23.imag,Y_23.real))\n",
+ "Y_22 = - Y_21 - Y_23\n",
+ "Y_24 = 0\n",
+ "Y_25 = 0\n",
+ "P0_2calc = (V2 * V1 * Y_21mag * math.cos(Y_21ang)) - (V2 * V2 * Y_21mag * math.cos(Y_21ang)) - (V2 * V2 * Y_23mag * math.cos(Y_23ang)) + (V2 * V3 * Y_23mag * math.cos(Y_23ang))\n",
+ "P_2scheduled = - P_2 / P\n",
+ "print(\" Scheduled power into the network at bus 2 is %.2f per unit\" %P_2scheduled)\n",
+ "delta_P0_2 = P_2scheduled - P0_2calc\n",
+ "delP_2_3 = - V2 * V3 * Y_23mag * math.sin(Y_23ang)\n",
+ "\n",
+ "#Results\n",
+ "print(\"Difference between calculated value and scheduled value = %.4f per unit\" %delta_P0_2)\n",
+ "print(\"The value of the second element in the first row of the Jacobian = %.4f per unit \" %delP_2_3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Y21 = 1.40\n",
+ "Angle = 5960.84 v \n",
+ "Y23 = 1.84\n",
+ "Angle = 5948.57 v \n",
+ " Scheduled power into the network at bus 2 is -1.15 per unit\n",
+ "Difference between calculated value and scheduled value = -0.7817 per unit\n",
+ "The value of the second element in the first row of the Jacobian = 1.1708 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2, Page No 210"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Zth = complex(0.2)\n",
+ "Xg = complex(1)\n",
+ "Vt = 0.97\n",
+ "I = complex(0.8,-0.2)\n",
+ "Vt_b =1\n",
+ "\n",
+ "#Calculations\n",
+ "#a\n",
+ "S = Vt * I\n",
+ "Eg = Vt + Xg * I\n",
+ "print(\" P = %.3f per unit \\n Q = %.3f per unit\" %(S.real,S.imag))\n",
+ "print( \"Eg = {0:.2f}\".format(abs(Eg.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Eg.imag,Eg.real))))\n",
+ "\n",
+ "#b\n",
+ "Eth = Vt - Zth * I\n",
+ "delta = math.degrees(math.asin(S.real*abs(Zth)/(abs(Eth)* Vt_b)))\n",
+ "print( \"Eth = {0:.2f}\".format(abs(Eth.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Eth.imag,Eth.real))))\n",
+ "\n",
+ "#Results\n",
+ "print(\" Phase angle of Vt = %.2f \" %(delta))\n",
+ "ang = (math.degrees(math.atan2(Eth.imag,Eth.real))+ delta)\n",
+ "Vt_b1 = Vt_b*complex(math.cos(ang*math.pi/180),math.sin(ang*math.pi/180))\n",
+ "I_b = (Vt_b1 - Eth) / Zth\n",
+ "print( \"I_b = {0:.2f}\".format(abs(I_b.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(I_b.imag,I_b.real))))\n",
+ "Eg_b = Vt_b1 + Xg * I_b\n",
+ "S_b = Vt_b1 * I_b\n",
+ "print(\" P = %.3f per unit \\nQ = %.3f per unit\" %(S.real,S.imag))\n",
+ "print( \"Eg = {0:.2f}\".format(abs(Eg.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Eg.imag,Eg.real))))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " P = 0.776 per unit \n",
+ " Q = -0.194 per unit\n",
+ "Eg = 1.77\n",
+ "Angle = -6.45 per unit \n",
+ "Eth = 0.81\n",
+ "Angle = 2.83 per unit \n",
+ " Phase angle of Vt = 11.03 \n",
+ "I_b = 0.80\n",
+ "Angle = 51.12 per unit \n",
+ " P = 0.776 per unit \n",
+ "Q = -0.194 per unit\n",
+ "Eg = 1.77\n",
+ "Angle = -6.45 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3, Page No 218"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Z = complex(0.8,0.6)\n",
+ "V2 = 1\n",
+ "Z_Ta = complex(0.1)\n",
+ "Z_Tb = complex(0.1)\n",
+ "a=1.05\n",
+ "I2 = - V2 / Z\n",
+ "Y21_Ta = - 1/Z_Ta\n",
+ "Y22_Ta = 1/Z_Ta\n",
+ "\n",
+ "#Calculations\n",
+ "print('For transformer Ta Y21 and Y22 in per unit is')\n",
+ "print(Y21_Ta)\n",
+ "print(Y22_Ta)\n",
+ "Y21_Tb = - (1/Z_Ta) / a\n",
+ "Y22_Tb = (1/Z_Ta) / a**2\n",
+ "print('For transformer Tb Y21 and Y22 in per unit is')\n",
+ "print(Y21_Tb)\n",
+ "print(Y22_Tb)\n",
+ "Y21 = Y21_Ta + Y21_Tb\n",
+ "Y22 = Y22_Ta + Y22_Tb\n",
+ "print('For the two transformers in parallel')\n",
+ "print('Y21 in per unit')\n",
+ "print(Y21)\n",
+ "print('Y22 in per unit')\n",
+ "print(Y22)\n",
+ "V1 = (I2 - Y22 * V2) / Y21\n",
+ "print('V1 in per unit')\n",
+ "print(V1)\n",
+ "V_1_2 = V1 - V2\n",
+ "print('Difference between V1 and V2 in per unit')\n",
+ "print(V_1_2)\n",
+ "I_Ta = V_1_2 * Y22_Ta\n",
+ "I_Tb_a1 = -I2 - I_Ta\n",
+ "S_Ta = V2 * I_Ta\n",
+ "S_Tb = V2 * I_Tb_a1\n",
+ "\n",
+ "#Results\n",
+ "print('Complex power transmitted from the two transformers to the load')\n",
+ "print('From transformer Ta in per unit')\n",
+ "print(S_Ta)\n",
+ "print('From transformer Tb in per unit')\n",
+ "print(S_Tb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For transformer Ta Y21 and Y22 in per unit is\n",
+ "(-10+0j)\n",
+ "(10+0j)\n",
+ "For transformer Tb Y21 and Y22 in per unit is\n",
+ "(-9.52380952381+0j)\n",
+ "(9.07029478458+0j)\n",
+ "For the two transformers in parallel\n",
+ "Y21 in per unit\n",
+ "(-19.5238095238+0j)\n",
+ "Y22 in per unit\n",
+ "(19.0702947846+0j)\n",
+ "V1 in per unit\n",
+ "(1.01774680604-0.0307317073171j)\n",
+ "Difference between V1 and V2 in per unit\n",
+ "(0.0177468060395-0.0307317073171j)\n",
+ "Complex power transmitted from the two transformers to the load\n",
+ "From transformer Ta in per unit\n",
+ "(0.177468060395-0.307317073171j)\n",
+ "From transformer Tb in per unit\n",
+ "(0.622531939605-0.292682926829j)\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4 Page No 221"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Z = complex(0.8,0.6)\n",
+ "V2 = 1\n",
+ "Z_Ta = complex(0.1)\n",
+ "Z_Tb = complex(0.1)\n",
+ "Z1_Tb = complex(0.1)\n",
+ "Z2_Tb = complex(0.1)\n",
+ "a=1*complex(math.cos(3*math.pi/180),math.sin(3*math.pi/180))\n",
+ "I2 = - V2 / Z\n",
+ "Y21_Ta = - 1/Z_Ta\n",
+ "Y22_Ta = 1/Z_Ta\n",
+ "Y21_Tb = Y21_Ta/a\n",
+ "Y22_Tb = Y22_Ta/(abs(a))**2\n",
+ "print( \"Y21 = {0:.2f}\".format(abs(Y21.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Y21.imag,Y21.real))*180/math.pi))\n",
+ "print(\" Y21 = \" )\n",
+ "print(abs(Y22_Tb))\n",
+ "Y21 = Y21_Ta + Y21_Tb\n",
+ "Y22 = Y22_Ta + Y22_Tb\n",
+ "print('For the two transformers in parallel')\n",
+ "print(Y21,'Y21 in per unit')\n",
+ "print(Y22,'Y21 in per unit')\n",
+ "V1 = (I2 - Y22 * V2) / Y21\n",
+ "print(V1,'V1 in per unit =')\n",
+ "V_1_2 = V1 - V2\n",
+ "print(V_1_2,'Difference between V1 and V2 in per unit')\n",
+ "I_Ta = V_1_2 * Y22_Ta\n",
+ "I_Tb_a1 = -I2 - I_Ta\n",
+ "S_Ta = V2 * I_Ta\n",
+ "S_Tb = V2 * I_Tb_a1\n",
+ "print('Complex power transmitted from the two transformers to the load')\n",
+ "print(S_Ta,'From transformer Ta in per unit')\n",
+ "print(S_Tb,'From transformer Tb in per unit')\n",
+ "V = a - V2\n",
+ "I = I2/2\n",
+ "I_circ = V / (Z1_Tb + Z2_Tb)\n",
+ "I_Ta_1 = - I - I_circ\n",
+ "I_Tb_1 = -I + I_circ\n",
+ "S_Ta_1 = V2 * I_Ta_1\n",
+ "S_Tb_1 = V2 * I_Tb_1\n",
+ "print('Complex power transmitted from the two transformers to the load')\n",
+ "print(S_Ta_1,'From transformer Ta in per unit')\n",
+ "print(S_Tb_1,'From transformer Tb in per unit')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Y21 = 19.52\n",
+ "Angle = 10313.24 per unit \n",
+ " Y21 = \n",
+ "10.0\n",
+ "For the two transformers in parallel\n",
+ "((-19.98629534754574+0.5233595624294384j), 'Y21 in per unit')\n",
+ "((19.999999999999996+0j), 'Y21 in per unit')\n",
+ "((1.0407855776470751-0.002766641568045591j), 'V1 in per unit =')\n",
+ "((0.04078557764707513-0.002766641568045591j), 'Difference between V1 and V2 in per unit')\n",
+ "Complex power transmitted from the two transformers to the load\n",
+ "((0.40785577647075133-0.027666415680455907j), 'From transformer Ta in per unit')\n",
+ "((0.3921442235292487-0.572333584319544j), 'From transformer Tb in per unit')\n",
+ "Complex power transmitted from the two transformers to the load\n",
+ "((0.40685232622713086-0.5616797812147191j), 'From transformer Ta in per unit')\n",
+ "((0.3931476737728692-0.0383202187852808j), 'From transformer Tb in per unit')\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo08_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo08_1.ipynb
new file mode 100755
index 00000000..78378c7d
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo08_1.ipynb
@@ -0,0 +1,348 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 08 : Load Flow Solutions And Control"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.1, Page No 200"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P = 100e6\n",
+ "V = 138e3\n",
+ "#From Table 8.1\n",
+ "R_12 = 0.042\n",
+ "R_15 = 0.031\n",
+ "R_23 = 0.031\n",
+ "R_34 = 0.084\n",
+ "R_25 = 0.053\n",
+ "R_45 = 0.063\n",
+ "X_12 = 0.168\n",
+ "X_15 = 0.126\n",
+ "X_23 = 0.126\n",
+ "X_34 = 0.336\n",
+ "X_25 = 0.210\n",
+ "X_45 = 0.252\n",
+ "#From Table 8.2\n",
+ "V1 = 1.04\n",
+ "V2 = 1\n",
+ "V3 = 1.02\n",
+ "V4 = 1\n",
+ "V5 = 1\n",
+ "P_2 = 115e6\n",
+ "\n",
+ "#Calculation\n",
+ "Y_21=- 1/complex(R_12,X_12)\n",
+ "print( \"Y21 = {0:.2f}\".format(abs(Y_21.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Y_21.imag,Y_21.real))*180/math.pi))\n",
+ "Y_23=-1/complex(R_23,X_23)\n",
+ "print( \"Y23 = {0:.2f}\".format(abs(Y_23.real)))\n",
+ "print(\"Angle = %.2f v \" %(math.degrees(math.atan2(Y_23.imag,Y_23.real))*180/math.pi))\n",
+ "\n",
+ "Y_21mag = abs(Y_21)\n",
+ "Y_21ang = math.degrees(math.atan2(Y_21.imag,Y_21.real))\n",
+ "Y_23mag = abs(Y_23)\n",
+ "Y_23ang = math.degrees(math.atan2(Y_23.imag,Y_23.real))\n",
+ "Y_22 = - Y_21 - Y_23\n",
+ "Y_24 = 0\n",
+ "Y_25 = 0\n",
+ "P0_2calc = (V2 * V1 * Y_21mag * math.cos(Y_21ang)) - (V2 * V2 * Y_21mag * math.cos(Y_21ang)) - (V2 * V2 * Y_23mag * math.cos(Y_23ang)) + (V2 * V3 * Y_23mag * math.cos(Y_23ang))\n",
+ "P_2scheduled = - P_2 / P\n",
+ "print(\" Scheduled power into the network at bus 2 is %.2f per unit\" %P_2scheduled)\n",
+ "delta_P0_2 = P_2scheduled - P0_2calc\n",
+ "delP_2_3 = - V2 * V3 * Y_23mag * math.sin(Y_23ang)\n",
+ "\n",
+ "#Results\n",
+ "print(\"Difference between calculated value and scheduled value = %.4f per unit\" %delta_P0_2)\n",
+ "print(\"The value of the second element in the first row of the Jacobian = %.4f per unit \" %delP_2_3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Y21 = 1.40\n",
+ "Angle = 5960.84 v \n",
+ "Y23 = 1.84\n",
+ "Angle = 5948.57 v \n",
+ " Scheduled power into the network at bus 2 is -1.15 per unit\n",
+ "Difference between calculated value and scheduled value = -0.7817 per unit\n",
+ "The value of the second element in the first row of the Jacobian = 1.1708 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2, Page No 210"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Zth = complex(0.2)\n",
+ "Xg = complex(1)\n",
+ "Vt = 0.97\n",
+ "I = complex(0.8,-0.2)\n",
+ "Vt_b =1\n",
+ "\n",
+ "#Calculations\n",
+ "#a\n",
+ "S = Vt * I\n",
+ "Eg = Vt + Xg * I\n",
+ "print(\" P = %.3f per unit \\n Q = %.3f per unit\" %(S.real,S.imag))\n",
+ "print( \"Eg = {0:.2f}\".format(abs(Eg.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Eg.imag,Eg.real))))\n",
+ "\n",
+ "#b\n",
+ "Eth = Vt - Zth * I\n",
+ "delta = math.degrees(math.asin(S.real*abs(Zth)/(abs(Eth)* Vt_b)))\n",
+ "print( \"Eth = {0:.2f}\".format(abs(Eth.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Eth.imag,Eth.real))))\n",
+ "\n",
+ "#Results\n",
+ "print(\" Phase angle of Vt = %.2f \" %(delta))\n",
+ "ang = (math.degrees(math.atan2(Eth.imag,Eth.real))+ delta)\n",
+ "Vt_b1 = Vt_b*complex(math.cos(ang*math.pi/180),math.sin(ang*math.pi/180))\n",
+ "I_b = (Vt_b1 - Eth) / Zth\n",
+ "print( \"I_b = {0:.2f}\".format(abs(I_b.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(I_b.imag,I_b.real))))\n",
+ "Eg_b = Vt_b1 + Xg * I_b\n",
+ "S_b = Vt_b1 * I_b\n",
+ "print(\" P = %.3f per unit \\nQ = %.3f per unit\" %(S.real,S.imag))\n",
+ "print( \"Eg = {0:.2f}\".format(abs(Eg.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Eg.imag,Eg.real))))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " P = 0.776 per unit \n",
+ " Q = -0.194 per unit\n",
+ "Eg = 1.77\n",
+ "Angle = -6.45 per unit \n",
+ "Eth = 0.81\n",
+ "Angle = 2.83 per unit \n",
+ " Phase angle of Vt = 11.03 \n",
+ "I_b = 0.80\n",
+ "Angle = 51.12 per unit \n",
+ " P = 0.776 per unit \n",
+ "Q = -0.194 per unit\n",
+ "Eg = 1.77\n",
+ "Angle = -6.45 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3, Page No 218"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Z = complex(0.8,0.6)\n",
+ "V2 = 1\n",
+ "Z_Ta = complex(0.1)\n",
+ "Z_Tb = complex(0.1)\n",
+ "a=1.05\n",
+ "I2 = - V2 / Z\n",
+ "Y21_Ta = - 1/Z_Ta\n",
+ "Y22_Ta = 1/Z_Ta\n",
+ "\n",
+ "#Calculations\n",
+ "print('For transformer Ta Y21 and Y22 in per unit is')\n",
+ "print(Y21_Ta)\n",
+ "print(Y22_Ta)\n",
+ "Y21_Tb = - (1/Z_Ta) / a\n",
+ "Y22_Tb = (1/Z_Ta) / a**2\n",
+ "print('For transformer Tb Y21 and Y22 in per unit is')\n",
+ "print(Y21_Tb)\n",
+ "print(Y22_Tb)\n",
+ "Y21 = Y21_Ta + Y21_Tb\n",
+ "Y22 = Y22_Ta + Y22_Tb\n",
+ "print('For the two transformers in parallel')\n",
+ "print('Y21 in per unit')\n",
+ "print(Y21)\n",
+ "print('Y22 in per unit')\n",
+ "print(Y22)\n",
+ "V1 = (I2 - Y22 * V2) / Y21\n",
+ "print('V1 in per unit')\n",
+ "print(V1)\n",
+ "V_1_2 = V1 - V2\n",
+ "print('Difference between V1 and V2 in per unit')\n",
+ "print(V_1_2)\n",
+ "I_Ta = V_1_2 * Y22_Ta\n",
+ "I_Tb_a1 = -I2 - I_Ta\n",
+ "S_Ta = V2 * I_Ta\n",
+ "S_Tb = V2 * I_Tb_a1\n",
+ "\n",
+ "#Results\n",
+ "print('Complex power transmitted from the two transformers to the load')\n",
+ "print('From transformer Ta in per unit')\n",
+ "print(S_Ta)\n",
+ "print('From transformer Tb in per unit')\n",
+ "print(S_Tb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For transformer Ta Y21 and Y22 in per unit is\n",
+ "(-10+0j)\n",
+ "(10+0j)\n",
+ "For transformer Tb Y21 and Y22 in per unit is\n",
+ "(-9.52380952381+0j)\n",
+ "(9.07029478458+0j)\n",
+ "For the two transformers in parallel\n",
+ "Y21 in per unit\n",
+ "(-19.5238095238+0j)\n",
+ "Y22 in per unit\n",
+ "(19.0702947846+0j)\n",
+ "V1 in per unit\n",
+ "(1.01774680604-0.0307317073171j)\n",
+ "Difference between V1 and V2 in per unit\n",
+ "(0.0177468060395-0.0307317073171j)\n",
+ "Complex power transmitted from the two transformers to the load\n",
+ "From transformer Ta in per unit\n",
+ "(0.177468060395-0.307317073171j)\n",
+ "From transformer Tb in per unit\n",
+ "(0.622531939605-0.292682926829j)\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4 Page No 221"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Z = complex(0.8,0.6)\n",
+ "V2 = 1\n",
+ "Z_Ta = complex(0.1)\n",
+ "Z_Tb = complex(0.1)\n",
+ "Z1_Tb = complex(0.1)\n",
+ "Z2_Tb = complex(0.1)\n",
+ "a=1*complex(math.cos(3*math.pi/180),math.sin(3*math.pi/180))\n",
+ "I2 = - V2 / Z\n",
+ "Y21_Ta = - 1/Z_Ta\n",
+ "Y22_Ta = 1/Z_Ta\n",
+ "Y21_Tb = Y21_Ta/a\n",
+ "Y22_Tb = Y22_Ta/(abs(a))**2\n",
+ "print( \"Y21 = {0:.2f}\".format(abs(Y21.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Y21.imag,Y21.real))*180/math.pi))\n",
+ "print(\" Y21 = \" )\n",
+ "print(abs(Y22_Tb))\n",
+ "Y21 = Y21_Ta + Y21_Tb\n",
+ "Y22 = Y22_Ta + Y22_Tb\n",
+ "print('For the two transformers in parallel')\n",
+ "print(Y21,'Y21 in per unit')\n",
+ "print(Y22,'Y21 in per unit')\n",
+ "V1 = (I2 - Y22 * V2) / Y21\n",
+ "print(V1,'V1 in per unit =')\n",
+ "V_1_2 = V1 - V2\n",
+ "print(V_1_2,'Difference between V1 and V2 in per unit')\n",
+ "I_Ta = V_1_2 * Y22_Ta\n",
+ "I_Tb_a1 = -I2 - I_Ta\n",
+ "S_Ta = V2 * I_Ta\n",
+ "S_Tb = V2 * I_Tb_a1\n",
+ "print('Complex power transmitted from the two transformers to the load')\n",
+ "print(S_Ta,'From transformer Ta in per unit')\n",
+ "print(S_Tb,'From transformer Tb in per unit')\n",
+ "V = a - V2\n",
+ "I = I2/2\n",
+ "I_circ = V / (Z1_Tb + Z2_Tb)\n",
+ "I_Ta_1 = - I - I_circ\n",
+ "I_Tb_1 = -I + I_circ\n",
+ "S_Ta_1 = V2 * I_Ta_1\n",
+ "S_Tb_1 = V2 * I_Tb_1\n",
+ "print('Complex power transmitted from the two transformers to the load')\n",
+ "print(S_Ta_1,'From transformer Ta in per unit')\n",
+ "print(S_Tb_1,'From transformer Tb in per unit')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Y21 = 19.52\n",
+ "Angle = 10313.24 per unit \n",
+ " Y21 = \n",
+ "10.0\n",
+ "For the two transformers in parallel\n",
+ "((-19.98629534754574+0.5233595624294384j), 'Y21 in per unit')\n",
+ "((19.999999999999996+0j), 'Y21 in per unit')\n",
+ "((1.0407855776470751-0.002766641568045591j), 'V1 in per unit =')\n",
+ "((0.04078557764707513-0.002766641568045591j), 'Difference between V1 and V2 in per unit')\n",
+ "Complex power transmitted from the two transformers to the load\n",
+ "((0.40785577647075133-0.027666415680455907j), 'From transformer Ta in per unit')\n",
+ "((0.3921442235292487-0.572333584319544j), 'From transformer Tb in per unit')\n",
+ "Complex power transmitted from the two transformers to the load\n",
+ "((0.40685232622713086-0.5616797812147191j), 'From transformer Ta in per unit')\n",
+ "((0.3931476737728692-0.0383202187852808j), 'From transformer Tb in per unit')\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo09.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo09.ipynb
new file mode 100755
index 00000000..725e5a21
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo09.ipynb
@@ -0,0 +1,196 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 09 : Economic Operation Of Power Systems"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3, Page No 236"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "I1 = 1.0\n",
+ "I2 = 0.8\n",
+ "V3 = 1.0\n",
+ "pf1 =1.0\n",
+ "pf2 = pf1\n",
+ "pf3 = pf1\n",
+ "\n",
+ "#Calculations\n",
+ "Za = complex(0.04,0.16)\n",
+ "Ra = Za.real\n",
+ "Zb = complex(0.03,0.12)\n",
+ "Rb = Zb.real\n",
+ "Zc = complex(0.02,0.08)\n",
+ "Rc = Zc.real\n",
+ "V1 = V3 + I1 * Za\n",
+ "print(V1,'Voltage at bus 1,V1 in per unit')\n",
+ "V2 = V3 + I2 * Zb\n",
+ "\n",
+ "#Results\n",
+ "print(V2,'Voltage at bus 2,V2 in per unit')\n",
+ "print('Transmission Loss Co-efficients')\n",
+ "B11 = (Ra + Rc) / (abs(V1) * pf1)**2\n",
+ "print('B11 in per unit = %.2f' %B11)\n",
+ "B12 = Rc / (abs(V1) * abs(V2) * pf1 * pf2)\n",
+ "print('B12 in per unit = %.2f' %B12)\n",
+ "B22 = (Rb + Rc) / (abs(V2) * pf2)**2\n",
+ "print('B22 in per unit = %.2f' %B22)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "((1.04+0.16j), 'Voltage at bus 1,V1 in per unit')\n",
+ "((1.024+0.096j), 'Voltage at bus 2,V2 in per unit')\n",
+ "Transmission Loss Co-efficients\n",
+ "B11 in per unit = 0.05\n",
+ "B12 in per unit = 0.02\n",
+ "B22 in per unit = 0.05\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4, Page No 237"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "I1 = 1.0\n",
+ "I2 = 0.8\n",
+ "V3 = 1.0\n",
+ "pf1 =1.0\n",
+ "pf2 = pf1\n",
+ "pf3 = pf1\n",
+ "\n",
+ "#Calculations\n",
+ "Za = complex(0.04,0.16)\n",
+ "Ra = Za.real\n",
+ "Zb = complex(0.03,0.12)\n",
+ "Rb = Zb.real\n",
+ "Zc = complex(0.02 ,0.08)\n",
+ "Rc = Zc.real\n",
+ "V1 = V3 + I1 * Za\n",
+ "V2 = V3 + I2 * Zb\n",
+ "B11 = (Ra + Rc) / (abs(V1) * pf1)**2\n",
+ "B12 = Rc / (abs(V1) * abs(V2) * pf1 * pf2)\n",
+ "B22 = (Rb + Rc) / (abs(V2) * pf2)**2\n",
+ "P1 = (I1.real * V1.real)\n",
+ "\n",
+ "#Results\n",
+ "print('P1 in per unit = %.2f' %P1)\n",
+ "P2 = (I2.real * V2.real)\n",
+ "print('P2 in per unit = %.2f' %P2)\n",
+ "PL = (P1)**2 * B11 + 2 * P1 * P2 * B12 + (P2)**2 * B22\n",
+ "print('Loss calculated using loss coefficients in per unit is = %.2f' %PL)\n",
+ "PL_I2R = I1**2 * Ra + (I1+I2)**2 * Rc + I2**2 * Rb\n",
+ "print('Loss calculated using current and resistance in per unit is = %.2f' %PL_I2R)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "P1 in per unit = 1.04\n",
+ "P2 in per unit = 0.82\n",
+ "Loss calculated using loss coefficients in per unit is = 0.12\n",
+ "Loss calculated using current and resistance in per unit is = 0.12\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5, Page No 240"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "l = 12.5\n",
+ "dF_dP = [[0.01,8,0.5],[0.015,9,0.5]]\n",
+ "B22 = 0\n",
+ "B12 = 0 #since all the load is at plant 2\n",
+ "P1_trans = 200\n",
+ "PL_trans = 16\n",
+ "\n",
+ "#Calculations\n",
+ "B11 = PL_trans / P1_trans**2\n",
+ "print(\" Penalty factors are \\n L1 = 1 / (1 - %fP1) \\n L2 = 1\" %(2*B11))\n",
+ "P1 = (l - dF_dP[0][1]) / (2*B11 * l + dF_dP[0][0])\n",
+ "P2 = (l - dF_dP[1][1]) / dF_dP[1][0]\n",
+ "PL = B11 * P1**2\n",
+ "Pr = P1 + P2 - PL\n",
+ "\n",
+ "#Results\n",
+ "print(\"Required generation from plant \\n P1 = %.0fMW \\n P2 = %.0fMW\" %(P1,P2))\n",
+ "print(\"Power loss in transmisison is %.0fMW\" %(PL))\n",
+ "print(\"The delivered load is %.0fMW\" %Pr)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Penalty factors are \n",
+ " L1 = 1 / (1 - 0.000000P1) \n",
+ " L2 = 1\n",
+ "Required generation from plant \n",
+ " P1 = 450MW \n",
+ " P2 = 233MW\n",
+ "Power loss in transmisison is 0MW\n",
+ "The delivered load is 683MW\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo09_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo09_1.ipynb
new file mode 100755
index 00000000..725e5a21
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo09_1.ipynb
@@ -0,0 +1,196 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 09 : Economic Operation Of Power Systems"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3, Page No 236"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "I1 = 1.0\n",
+ "I2 = 0.8\n",
+ "V3 = 1.0\n",
+ "pf1 =1.0\n",
+ "pf2 = pf1\n",
+ "pf3 = pf1\n",
+ "\n",
+ "#Calculations\n",
+ "Za = complex(0.04,0.16)\n",
+ "Ra = Za.real\n",
+ "Zb = complex(0.03,0.12)\n",
+ "Rb = Zb.real\n",
+ "Zc = complex(0.02,0.08)\n",
+ "Rc = Zc.real\n",
+ "V1 = V3 + I1 * Za\n",
+ "print(V1,'Voltage at bus 1,V1 in per unit')\n",
+ "V2 = V3 + I2 * Zb\n",
+ "\n",
+ "#Results\n",
+ "print(V2,'Voltage at bus 2,V2 in per unit')\n",
+ "print('Transmission Loss Co-efficients')\n",
+ "B11 = (Ra + Rc) / (abs(V1) * pf1)**2\n",
+ "print('B11 in per unit = %.2f' %B11)\n",
+ "B12 = Rc / (abs(V1) * abs(V2) * pf1 * pf2)\n",
+ "print('B12 in per unit = %.2f' %B12)\n",
+ "B22 = (Rb + Rc) / (abs(V2) * pf2)**2\n",
+ "print('B22 in per unit = %.2f' %B22)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "((1.04+0.16j), 'Voltage at bus 1,V1 in per unit')\n",
+ "((1.024+0.096j), 'Voltage at bus 2,V2 in per unit')\n",
+ "Transmission Loss Co-efficients\n",
+ "B11 in per unit = 0.05\n",
+ "B12 in per unit = 0.02\n",
+ "B22 in per unit = 0.05\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4, Page No 237"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "I1 = 1.0\n",
+ "I2 = 0.8\n",
+ "V3 = 1.0\n",
+ "pf1 =1.0\n",
+ "pf2 = pf1\n",
+ "pf3 = pf1\n",
+ "\n",
+ "#Calculations\n",
+ "Za = complex(0.04,0.16)\n",
+ "Ra = Za.real\n",
+ "Zb = complex(0.03,0.12)\n",
+ "Rb = Zb.real\n",
+ "Zc = complex(0.02 ,0.08)\n",
+ "Rc = Zc.real\n",
+ "V1 = V3 + I1 * Za\n",
+ "V2 = V3 + I2 * Zb\n",
+ "B11 = (Ra + Rc) / (abs(V1) * pf1)**2\n",
+ "B12 = Rc / (abs(V1) * abs(V2) * pf1 * pf2)\n",
+ "B22 = (Rb + Rc) / (abs(V2) * pf2)**2\n",
+ "P1 = (I1.real * V1.real)\n",
+ "\n",
+ "#Results\n",
+ "print('P1 in per unit = %.2f' %P1)\n",
+ "P2 = (I2.real * V2.real)\n",
+ "print('P2 in per unit = %.2f' %P2)\n",
+ "PL = (P1)**2 * B11 + 2 * P1 * P2 * B12 + (P2)**2 * B22\n",
+ "print('Loss calculated using loss coefficients in per unit is = %.2f' %PL)\n",
+ "PL_I2R = I1**2 * Ra + (I1+I2)**2 * Rc + I2**2 * Rb\n",
+ "print('Loss calculated using current and resistance in per unit is = %.2f' %PL_I2R)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "P1 in per unit = 1.04\n",
+ "P2 in per unit = 0.82\n",
+ "Loss calculated using loss coefficients in per unit is = 0.12\n",
+ "Loss calculated using current and resistance in per unit is = 0.12\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5, Page No 240"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "l = 12.5\n",
+ "dF_dP = [[0.01,8,0.5],[0.015,9,0.5]]\n",
+ "B22 = 0\n",
+ "B12 = 0 #since all the load is at plant 2\n",
+ "P1_trans = 200\n",
+ "PL_trans = 16\n",
+ "\n",
+ "#Calculations\n",
+ "B11 = PL_trans / P1_trans**2\n",
+ "print(\" Penalty factors are \\n L1 = 1 / (1 - %fP1) \\n L2 = 1\" %(2*B11))\n",
+ "P1 = (l - dF_dP[0][1]) / (2*B11 * l + dF_dP[0][0])\n",
+ "P2 = (l - dF_dP[1][1]) / dF_dP[1][0]\n",
+ "PL = B11 * P1**2\n",
+ "Pr = P1 + P2 - PL\n",
+ "\n",
+ "#Results\n",
+ "print(\"Required generation from plant \\n P1 = %.0fMW \\n P2 = %.0fMW\" %(P1,P2))\n",
+ "print(\"Power loss in transmisison is %.0fMW\" %(PL))\n",
+ "print(\"The delivered load is %.0fMW\" %Pr)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Penalty factors are \n",
+ " L1 = 1 / (1 - 0.000000P1) \n",
+ " L2 = 1\n",
+ "Required generation from plant \n",
+ " P1 = 450MW \n",
+ " P2 = 233MW\n",
+ "Power loss in transmisison is 0MW\n",
+ "The delivered load is 683MW\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo10.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo10.ipynb
new file mode 100755
index 00000000..95f3242b
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo10.ipynb
@@ -0,0 +1,416 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10 : Symmetrical Three Phase Faults"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.1, Page No 253"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P_g1 = 50e6\n",
+ "V_g1 = 13.8e3\n",
+ "P_g2 = 25e6\n",
+ "V_g2 = 13.8e3\n",
+ "P_t = 75e6\n",
+ "V_t_lt = 13.8e3\n",
+ "V_t_ht = 69e3\n",
+ "X11_g = 0.25\n",
+ "X11_t = 0.10\n",
+ "Vbase = 69e3\n",
+ "Pbase = 75e6\n",
+ "Vbase_lt = 13.8e3\n",
+ "V_ht = 66e3\n",
+ "\n",
+ "def pucalc(pu_Z_given,base_kV_given,base_kV_new,base_kVA_new,base_kVA_given):\n",
+ " X11=(pu_Z_given * (base_kV_given/base_kV_new)**2 * (base_kVA_new/base_kVA_given));\n",
+ " return X11 \n",
+ "\n",
+ "#Calculations\n",
+ "X11_d_g1 = pucalc(X11_g,V_t_lt,Vbase_lt,Pbase,P_g1)\n",
+ "X11_d_g2 = pucalc(X11_g,V_t_lt,Vbase_lt,Pbase,P_g2)\n",
+ "E_g1 = V_ht / Vbase\n",
+ "E_g2 = V_ht / Vbase\n",
+ "print('For Generator 1')\n",
+ "print(\"Xd11 = %.3f per unit \\n Eg1 = %.3f per unit \\n\" %(X11_d_g1,E_g1))\n",
+ "print('For Generator 2')\n",
+ "print(\"Xd11 = %.3f per unit \\n Eg2 = %.3f per unit \\n\" %(X11_d_g2,E_g2))\n",
+ "X_g12 = (X11_d_g1 * X11_d_g2) / (X11_d_g1 + X11_d_g2)\n",
+ "I11 = E_g1 / (complex(X_g12 + X11_t))\n",
+ "print('Subtransient current in the short circuit in per unit is= {0:.2f}+{1:.2f}i'.format(I11.real, I11.imag))\n",
+ "Vdt = I11 * complex(X11_t)\n",
+ "print('Voltage on the delta side of the transformer in per unit is')\n",
+ "print(Vdt)\n",
+ "I11_g1 = (E_g1 - Vdt) / complex(X11_d_g1)\n",
+ "I11_g2 = (E_g2 - Vdt) / complex(X11_d_g2)\n",
+ "print('Subtransient current in generator 1 and 2 in per unit respectively')\n",
+ "print(I11_g1)\n",
+ "print(I11_g2)\n",
+ "Ibase = Pbase / (math.sqrt(3) * Vbase_lt)\n",
+ "I11_1 = abs(I11_g1) * Ibase\n",
+ "I11_2 = abs(I11_g2) * Ibase\n",
+ "\n",
+ "#Results\n",
+ "print('Subtransient current in generator 1 and 2 in Amperes respectively')\n",
+ "print(I11_1)\n",
+ "print(I11_2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For Generator 1\n",
+ "Xd11 = 0.375 per unit \n",
+ " Eg1 = 0.957 per unit \n",
+ "\n",
+ "For Generator 2\n",
+ "Xd11 = 0.750 per unit \n",
+ " Eg2 = 0.957 per unit \n",
+ "\n",
+ "Subtransient current in the short circuit in per unit is= 2.73+0.00i\n",
+ "Voltage on the delta side of the transformer in per unit is\n",
+ "(0.273291925466+0j)\n",
+ "Subtransient current in generator 1 and 2 in per unit respectively\n",
+ "(1.82194616977+0j)\n",
+ "(0.910973084886+0j)\n",
+ "Subtransient current in generator 1 and 2 in Amperes respectively\n",
+ "5716.85386721\n",
+ "2858.42693361\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.2, Page No 256"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Pgm = 30e6\n",
+ "Vgm = 13.2e3\n",
+ "Xgm = 0.20\n",
+ "Xl = 0.10\n",
+ "Pm = 20e6\n",
+ "pfm = 0.8\n",
+ "Vt_m = 12.8e3\n",
+ "Pbase = Pgm\n",
+ "Vbase = Vgm\n",
+ "\n",
+ "#Calculations\n",
+ "Vf = Vt_m / Vbase\n",
+ "Ibase = Pbase / (math.sqrt(3) * Vbase)\n",
+ "I_L = (Pm / (pfm * math.sqrt(3) * Vt_m)) * complex(math.cos(36.9 * math.pi/180),math.sin(36.9 * math.pi / 180)) / Ibase\n",
+ "print('Line Current in per unit is = {0:.2f}+{1:.2f}i'.format(I_L.real, I_L.imag))\n",
+ "Vt_g = Vf + complex(Xl) * I_L\n",
+ "E11_g = Vt_g + complex(Xgm) * I_L\n",
+ "I11_g = E11_g / complex(Xgm + Xl)\n",
+ "I11_gA = Ibase * I11_g\n",
+ "print('Fault current in the generator side in per unit = {0:.2f}+{1:.2f}i'.format(I11_g.real, I11_g.imag))\n",
+ "print('Fault current in the generator side in A= {0:.2f}+{1:.2f}i'.format(I11_gA.real, I11_gA.imag))\n",
+ "E11_m = Vf -complex(Xgm) * I_L\n",
+ "I11_m = E11_m / complex(Xgm)\n",
+ "I11_mA = Ibase * I11_m\n",
+ "print('Fault current in the motor side in per unit = {0:.2f}+{1:.2f}i'.format(I11_m.real, I11_m.imag))\n",
+ "print('Fault current in the motor side in A= {0:.2f}+{1:.2f}i'.format(I11_mA.real, I11_mA.imag))\n",
+ "If = I11_g + I11_m\n",
+ "If_Ib = If * Ibase\n",
+ "\n",
+ "#Results\n",
+ "print('Toatl Fault current in per unit %If=%.2f')\n",
+ "print('Total Fault current in A= {0:.2f}+{1:.2f}i'.format(If_Ib.real, If_Ib.imag))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Line Current in per unit is = 0.69+0.52i\n",
+ "Fault current in the generator side in per unit = 3.92+0.52i\n",
+ "Fault current in the generator side in A= 5143.08+677.06i\n",
+ "Fault current in the motor side in per unit = 4.16+-0.52i\n",
+ "Fault current in the motor side in A= 5460.23+-677.06i\n",
+ "Toatl Fault current in per unit %If=%.2f\n",
+ "Total Fault current in A= 10603.31+-0.00i\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.3, Page No 259"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Pgm = 30e6\n",
+ "Vgm = 13.2e3\n",
+ "Xgm = 0.20\n",
+ "Xl = 0.10\n",
+ "Pm = 20e6\n",
+ "pfm = 0.8\n",
+ "Vt_m = 12.8e3\n",
+ "Pbase = Pgm\n",
+ "Vbase = Vgm\n",
+ "\n",
+ "#Calculations\n",
+ "Vf = Vt_m / Vbase\n",
+ "Ibase = Pbase / (math.sqrt(3) * Vbase)\n",
+ "I_L = (Pm / (pfm * math.sqrt(3) * Vt_m)) * complex(math.cos(36.9 * math.pi/180),math.sin(36.9 * math.pi / 180)) / Ibase\n",
+ "Zth = (complex(Xgm+Xl) * (complex(Xgm))) / (complex(Xgm+Xl) + (complex(Xgm)))\n",
+ "print('Zth in per unit = {0:.2f}+{1:.2f}i'.format(Zth.real, Zth.imag))\n",
+ "I11_f = Vf / Zth\n",
+ "print('Subtransient fault current in per unit = {0:.2f}+{1:.2f}i'.format(I11_f.real, I11_f.imag))\n",
+ "If_g = I11_f * complex(Xgm) / (complex(Xgm+Xl) + complex(Xgm))\n",
+ "If_m = I11_f * (complex(Xgm + Xl)) / (complex(Xgm+Xl) + (complex(Xgm)))\n",
+ "I11_g = I_L + If_g \n",
+ "\n",
+ "#Results\n",
+ "print('Subtransient fault current in generator side in per unit = {0:.2f}+{1:.2f}i'.format(I11_g.real, I11_g.imag))\n",
+ "I11_m = If_m - I_L \n",
+ "print('Subtransient fault current in motor side in per unit = {0:.2f}+{1:.2f}i'.format(I11_m.real, I11_m.imag))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Zth in per unit = 0.12+0.00i\n",
+ "Subtransient fault current in per unit = 8.08+0.00i\n",
+ "Subtransient fault current in generator side in per unit = 3.92+0.52i\n",
+ "Subtransient fault current in motor side in per unit = 4.16+-0.52i\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.4 Page No 265"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Pg1 = 270e6\n",
+ "Pg3 = 225e6\n",
+ "Pbase = 100e6\n",
+ "V = 1\n",
+ "X = 0.3\n",
+ "Xg_b1 = X * Pbase /Pg1\n",
+ "Xg_b3 = X * Pbase /Pg3\n",
+ "y10 = 1 / complex(Xg_b1)\n",
+ "y30 = 1 / complex(Xg_b3)\n",
+ "y12 = 1 / complex(0.168)\n",
+ "y15 = 1 / complex(0.126)\n",
+ "y23 = 1 / complex(0.126)\n",
+ "y34 = 1 / complex(0.336)\n",
+ "y35 = 1 / complex(0.210)\n",
+ "y45 = 1 / complex(0.252)\n",
+ "#Ybus by inspection\n",
+ "Ybus = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]\n",
+ "Ybus[0][0] = y10 + y12 + y15\n",
+ "Ybus[1][1] = y12 + y23\n",
+ "Ybus[3][2] = y30 + y23 + y35 + y34\n",
+ "Ybus[3][3] = y34 + y45\n",
+ "Ybus[4][4] = y45 + y15 + y35\n",
+ "Ybus[0][1] = -y12\n",
+ "Ybus[1][0] = Ybus[0][1]\n",
+ "Ybus[0][2] = 0\n",
+ "Ybus[0][3] =0\n",
+ "Ybus[1][2] = -y23\n",
+ "Ybus[2][1] = Ybus[1][2]\n",
+ "Ybus[1][4] = 0\n",
+ "Ybus[1][3] =0\n",
+ "Ybus[2][3] = -y34\n",
+ "Ybus[3][2] = Ybus[2][3]\n",
+ "Ybus[2][0] = 0\n",
+ "Ybus[3][4] = -y45\n",
+ "Ybus[4][3] = Ybus[3][4]\n",
+ "Ybus[3][0] = 0\n",
+ "Ybus[3][1] = 0\n",
+ "Ybus[0][4] = -y15\n",
+ "Ybus[4][0] = Ybus[0][4]\n",
+ "Ybus[4][1] = 0\n",
+ "Ybus[2][4] = -y35\n",
+ "Ybus[4][2] = Ybus[2][4]\n",
+ "print('Ybus=')\n",
+ "print(Ybus)\n",
+ "I11 = V / Ybus[3][3]\n",
+ "print(I11,' The subtransient current in a three-phase fault on bus 4 in per unit is ')\n",
+ "V3 = V - I11 * Ybus[3][2]\n",
+ "V5 = V - I11 * Ybus[3][4]\n",
+ "print('Voltages at bus 3 and 5 repectively in per unit = {0:.2f}+{1:.2f}i'.format(V3.real, V3.imag))\n",
+ "print('and {0:.2f}+{1:.2f}i'.format(V5.real, V5.imag))\n",
+ "\n",
+ "I3 = V3 * y34\n",
+ "I5 = V5 * y45\n",
+ "\n",
+ "#Results\n",
+ "print('Currents to fault from bus 3 in per unit = {0:.2f}+{1:.2f}i'.format(I3.real, I3.imag))\n",
+ "print(I5,'Currents to fault from bus 5 in per unit')\n",
+ "print('Currents to fault from bus 5 in per unit = {0:.2f}+{1:.2f}i'.format(I5.real, I5.imag))\n",
+ "print('Total current to fault in per unit = {0:.2f}+{1:.2f}i'.format((I3.real+I5.real),(I3.imag+I5.imag)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ybus=\n",
+ "[[(22.88888888888889+0j), (-5.952380952380952-0j), 0, 0, (-7.936507936507937-0j)], [(-5.952380952380952-0j), (13.88888888888889+0j), (-7.936507936507937-0j), 0, 0], [0, (-7.936507936507937-0j), 0, (-2.976190476190476-0j), (-4.761904761904762-0j)], [0, 0, (-2.976190476190476-0j), (6.944444444444445+0j), (-3.9682539682539684-0j)], [(-7.936507936507937-0j), 0, (-4.761904761904762-0j), (-3.9682539682539684-0j), (16.666666666666668+0j)]]\n",
+ "((0.144+0j), '\\n The subtransient current in a three-phase fault on bus 4 in per unit is \\n')\n",
+ "Voltages at bus 3 and 5 repectively in per unit = 1.43+0.00i\n",
+ "and 1.57+0.00i\n",
+ "Currents to fault from bus 3 in per unit = 4.25+0.00i\n",
+ "((6.235827664399093+0j), 'Currents to fault from bus 5 in per unit')\n",
+ "Currents to fault from bus 5 in per unit = 6.24+0.00i\n",
+ "Total current to fault in per unit = 10.49+0.00i\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.5, Page No 268"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Pg = 25e6\n",
+ "Vg = 13.8e3\n",
+ "X11_dg = 0.15\n",
+ "X11_dm = 0.20\n",
+ "Pmbase = 5e6\n",
+ "Vbasem = 6.9e3\n",
+ "P_tr = 25e6\n",
+ "V_ht = 13.8e3\n",
+ "V_lt = 6.9e3\n",
+ "X_tr = 0.10\n",
+ "Vbus_m = 6.9e3\n",
+ "\n",
+ "#Calculations\n",
+ "#the subtransient current in the fault\n",
+ "X11_dm1 = X11_dm * (P_tr / Pmbase)\n",
+ "Vf = 1.0\n",
+ "Xeqm = 1.0/(4*X11_dm1)\n",
+ "Xeq_trg = X11_dg + X_tr\n",
+ "Zth = Xeqm * Xeq_trg / (Xeqm + Xeq_trg)\n",
+ "I11_f = Vf / complex(Zth)\n",
+ "Ibase_vbus = P_tr / (math.sqrt(3) * Vbus_m)\n",
+ "I11_f_a = abs(I11_f) * Ibase_vbus\n",
+ "print(\" Fault current in per unit = -j%.0f \" %abs(I11_f.real))\n",
+ "print(\" Fault current in amperes = %.0f \" %I11_f_a)\n",
+ "#the subtransient current in breaker A\n",
+ "Ig_f = I11_f * Xeq_trg / (Xeqm + Xeq_trg)\n",
+ "Im_f = 0.25 * (I11_f - Ig_f)\n",
+ "I11_pu = Ig_f + 3 * Im_f\n",
+ "I11_a = I11_pu * Ibase_vbus\n",
+ "print(\" Subtransient current through breaker A in per unit is -j%.0f \" %abs(I11_pu))\n",
+ "print(\" Subtransient current through breaker A in amperes is %.0f \" %abs(I11_a))\n",
+ "#Symmetrical short-circuit interrupting current in the fault and in breaker A\n",
+ "X11_dm2 = 1.5 * X11_dm1\n",
+ "Xeqm1 = X11_dm2 / 4\n",
+ "Zth_c = (Xeqm1 * Xeq_trg) / (Xeqm1 + Xeq_trg)\n",
+ "Ig_f1 = Vf * Xeqm1 / (Zth_c * (Xeqm1 + Xeq_trg))\n",
+ "Im_f1 = (Vf * Xeq_trg) / (4 * Zth_c * (Xeqm1 + Xeq_trg))\n",
+ "I11_1pu = Ig_f1 + 3 * Im_f1\n",
+ "I11_1a = I11_1pu * Ibase_vbus\n",
+ "print('Symmetrical Short circuit current to be interrupted in A = %0.2f' %I11_1a)\n",
+ "I11_pu_cb = Ig_f1 + 4 * Im_f1\n",
+ "I11_a_cb = I11_pu_cb * Ibase_vbus\n",
+ "print('The short circuit current rating of breakers must be atleast(in amperes) = %0.2f' %I11_a_cb)\n",
+ "Vcb = 15.5e3\n",
+ "I_ic = 8900\n",
+ "k = 2.67\n",
+ "Iic = I_ic * k\n",
+ "Icb = Vcb * I_ic / Vbus_m\n",
+ "\n",
+ "#Results\n",
+ "print(\"The required capability of %.0f A is well below 80 percent of %.0f A\\n and the breaker is suitable with respect to the short-circuit current\" %(abs(I11_a_cb),abs(Icb)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Fault current in per unit = -j8 \n",
+ " Fault current in amperes = 16735 \n",
+ " Subtransient current through breaker A in per unit is -j7 \n",
+ " Subtransient current through breaker A in amperes is 14643 \n",
+ "Symmetrical Short circuit current to be interrupted in A = 12551.09\n",
+ "The short circuit current rating of breakers must be atleast(in amperes) = 13945.66\n",
+ "The required capability of 13946 A is well below 80 percent of 19993 A\n",
+ " and the breaker is suitable with respect to the short-circuit current\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo10_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo10_1.ipynb
new file mode 100755
index 00000000..95f3242b
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo10_1.ipynb
@@ -0,0 +1,416 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10 : Symmetrical Three Phase Faults"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.1, Page No 253"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P_g1 = 50e6\n",
+ "V_g1 = 13.8e3\n",
+ "P_g2 = 25e6\n",
+ "V_g2 = 13.8e3\n",
+ "P_t = 75e6\n",
+ "V_t_lt = 13.8e3\n",
+ "V_t_ht = 69e3\n",
+ "X11_g = 0.25\n",
+ "X11_t = 0.10\n",
+ "Vbase = 69e3\n",
+ "Pbase = 75e6\n",
+ "Vbase_lt = 13.8e3\n",
+ "V_ht = 66e3\n",
+ "\n",
+ "def pucalc(pu_Z_given,base_kV_given,base_kV_new,base_kVA_new,base_kVA_given):\n",
+ " X11=(pu_Z_given * (base_kV_given/base_kV_new)**2 * (base_kVA_new/base_kVA_given));\n",
+ " return X11 \n",
+ "\n",
+ "#Calculations\n",
+ "X11_d_g1 = pucalc(X11_g,V_t_lt,Vbase_lt,Pbase,P_g1)\n",
+ "X11_d_g2 = pucalc(X11_g,V_t_lt,Vbase_lt,Pbase,P_g2)\n",
+ "E_g1 = V_ht / Vbase\n",
+ "E_g2 = V_ht / Vbase\n",
+ "print('For Generator 1')\n",
+ "print(\"Xd11 = %.3f per unit \\n Eg1 = %.3f per unit \\n\" %(X11_d_g1,E_g1))\n",
+ "print('For Generator 2')\n",
+ "print(\"Xd11 = %.3f per unit \\n Eg2 = %.3f per unit \\n\" %(X11_d_g2,E_g2))\n",
+ "X_g12 = (X11_d_g1 * X11_d_g2) / (X11_d_g1 + X11_d_g2)\n",
+ "I11 = E_g1 / (complex(X_g12 + X11_t))\n",
+ "print('Subtransient current in the short circuit in per unit is= {0:.2f}+{1:.2f}i'.format(I11.real, I11.imag))\n",
+ "Vdt = I11 * complex(X11_t)\n",
+ "print('Voltage on the delta side of the transformer in per unit is')\n",
+ "print(Vdt)\n",
+ "I11_g1 = (E_g1 - Vdt) / complex(X11_d_g1)\n",
+ "I11_g2 = (E_g2 - Vdt) / complex(X11_d_g2)\n",
+ "print('Subtransient current in generator 1 and 2 in per unit respectively')\n",
+ "print(I11_g1)\n",
+ "print(I11_g2)\n",
+ "Ibase = Pbase / (math.sqrt(3) * Vbase_lt)\n",
+ "I11_1 = abs(I11_g1) * Ibase\n",
+ "I11_2 = abs(I11_g2) * Ibase\n",
+ "\n",
+ "#Results\n",
+ "print('Subtransient current in generator 1 and 2 in Amperes respectively')\n",
+ "print(I11_1)\n",
+ "print(I11_2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For Generator 1\n",
+ "Xd11 = 0.375 per unit \n",
+ " Eg1 = 0.957 per unit \n",
+ "\n",
+ "For Generator 2\n",
+ "Xd11 = 0.750 per unit \n",
+ " Eg2 = 0.957 per unit \n",
+ "\n",
+ "Subtransient current in the short circuit in per unit is= 2.73+0.00i\n",
+ "Voltage on the delta side of the transformer in per unit is\n",
+ "(0.273291925466+0j)\n",
+ "Subtransient current in generator 1 and 2 in per unit respectively\n",
+ "(1.82194616977+0j)\n",
+ "(0.910973084886+0j)\n",
+ "Subtransient current in generator 1 and 2 in Amperes respectively\n",
+ "5716.85386721\n",
+ "2858.42693361\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.2, Page No 256"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Pgm = 30e6\n",
+ "Vgm = 13.2e3\n",
+ "Xgm = 0.20\n",
+ "Xl = 0.10\n",
+ "Pm = 20e6\n",
+ "pfm = 0.8\n",
+ "Vt_m = 12.8e3\n",
+ "Pbase = Pgm\n",
+ "Vbase = Vgm\n",
+ "\n",
+ "#Calculations\n",
+ "Vf = Vt_m / Vbase\n",
+ "Ibase = Pbase / (math.sqrt(3) * Vbase)\n",
+ "I_L = (Pm / (pfm * math.sqrt(3) * Vt_m)) * complex(math.cos(36.9 * math.pi/180),math.sin(36.9 * math.pi / 180)) / Ibase\n",
+ "print('Line Current in per unit is = {0:.2f}+{1:.2f}i'.format(I_L.real, I_L.imag))\n",
+ "Vt_g = Vf + complex(Xl) * I_L\n",
+ "E11_g = Vt_g + complex(Xgm) * I_L\n",
+ "I11_g = E11_g / complex(Xgm + Xl)\n",
+ "I11_gA = Ibase * I11_g\n",
+ "print('Fault current in the generator side in per unit = {0:.2f}+{1:.2f}i'.format(I11_g.real, I11_g.imag))\n",
+ "print('Fault current in the generator side in A= {0:.2f}+{1:.2f}i'.format(I11_gA.real, I11_gA.imag))\n",
+ "E11_m = Vf -complex(Xgm) * I_L\n",
+ "I11_m = E11_m / complex(Xgm)\n",
+ "I11_mA = Ibase * I11_m\n",
+ "print('Fault current in the motor side in per unit = {0:.2f}+{1:.2f}i'.format(I11_m.real, I11_m.imag))\n",
+ "print('Fault current in the motor side in A= {0:.2f}+{1:.2f}i'.format(I11_mA.real, I11_mA.imag))\n",
+ "If = I11_g + I11_m\n",
+ "If_Ib = If * Ibase\n",
+ "\n",
+ "#Results\n",
+ "print('Toatl Fault current in per unit %If=%.2f')\n",
+ "print('Total Fault current in A= {0:.2f}+{1:.2f}i'.format(If_Ib.real, If_Ib.imag))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Line Current in per unit is = 0.69+0.52i\n",
+ "Fault current in the generator side in per unit = 3.92+0.52i\n",
+ "Fault current in the generator side in A= 5143.08+677.06i\n",
+ "Fault current in the motor side in per unit = 4.16+-0.52i\n",
+ "Fault current in the motor side in A= 5460.23+-677.06i\n",
+ "Toatl Fault current in per unit %If=%.2f\n",
+ "Total Fault current in A= 10603.31+-0.00i\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.3, Page No 259"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Pgm = 30e6\n",
+ "Vgm = 13.2e3\n",
+ "Xgm = 0.20\n",
+ "Xl = 0.10\n",
+ "Pm = 20e6\n",
+ "pfm = 0.8\n",
+ "Vt_m = 12.8e3\n",
+ "Pbase = Pgm\n",
+ "Vbase = Vgm\n",
+ "\n",
+ "#Calculations\n",
+ "Vf = Vt_m / Vbase\n",
+ "Ibase = Pbase / (math.sqrt(3) * Vbase)\n",
+ "I_L = (Pm / (pfm * math.sqrt(3) * Vt_m)) * complex(math.cos(36.9 * math.pi/180),math.sin(36.9 * math.pi / 180)) / Ibase\n",
+ "Zth = (complex(Xgm+Xl) * (complex(Xgm))) / (complex(Xgm+Xl) + (complex(Xgm)))\n",
+ "print('Zth in per unit = {0:.2f}+{1:.2f}i'.format(Zth.real, Zth.imag))\n",
+ "I11_f = Vf / Zth\n",
+ "print('Subtransient fault current in per unit = {0:.2f}+{1:.2f}i'.format(I11_f.real, I11_f.imag))\n",
+ "If_g = I11_f * complex(Xgm) / (complex(Xgm+Xl) + complex(Xgm))\n",
+ "If_m = I11_f * (complex(Xgm + Xl)) / (complex(Xgm+Xl) + (complex(Xgm)))\n",
+ "I11_g = I_L + If_g \n",
+ "\n",
+ "#Results\n",
+ "print('Subtransient fault current in generator side in per unit = {0:.2f}+{1:.2f}i'.format(I11_g.real, I11_g.imag))\n",
+ "I11_m = If_m - I_L \n",
+ "print('Subtransient fault current in motor side in per unit = {0:.2f}+{1:.2f}i'.format(I11_m.real, I11_m.imag))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Zth in per unit = 0.12+0.00i\n",
+ "Subtransient fault current in per unit = 8.08+0.00i\n",
+ "Subtransient fault current in generator side in per unit = 3.92+0.52i\n",
+ "Subtransient fault current in motor side in per unit = 4.16+-0.52i\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.4 Page No 265"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Pg1 = 270e6\n",
+ "Pg3 = 225e6\n",
+ "Pbase = 100e6\n",
+ "V = 1\n",
+ "X = 0.3\n",
+ "Xg_b1 = X * Pbase /Pg1\n",
+ "Xg_b3 = X * Pbase /Pg3\n",
+ "y10 = 1 / complex(Xg_b1)\n",
+ "y30 = 1 / complex(Xg_b3)\n",
+ "y12 = 1 / complex(0.168)\n",
+ "y15 = 1 / complex(0.126)\n",
+ "y23 = 1 / complex(0.126)\n",
+ "y34 = 1 / complex(0.336)\n",
+ "y35 = 1 / complex(0.210)\n",
+ "y45 = 1 / complex(0.252)\n",
+ "#Ybus by inspection\n",
+ "Ybus = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]\n",
+ "Ybus[0][0] = y10 + y12 + y15\n",
+ "Ybus[1][1] = y12 + y23\n",
+ "Ybus[3][2] = y30 + y23 + y35 + y34\n",
+ "Ybus[3][3] = y34 + y45\n",
+ "Ybus[4][4] = y45 + y15 + y35\n",
+ "Ybus[0][1] = -y12\n",
+ "Ybus[1][0] = Ybus[0][1]\n",
+ "Ybus[0][2] = 0\n",
+ "Ybus[0][3] =0\n",
+ "Ybus[1][2] = -y23\n",
+ "Ybus[2][1] = Ybus[1][2]\n",
+ "Ybus[1][4] = 0\n",
+ "Ybus[1][3] =0\n",
+ "Ybus[2][3] = -y34\n",
+ "Ybus[3][2] = Ybus[2][3]\n",
+ "Ybus[2][0] = 0\n",
+ "Ybus[3][4] = -y45\n",
+ "Ybus[4][3] = Ybus[3][4]\n",
+ "Ybus[3][0] = 0\n",
+ "Ybus[3][1] = 0\n",
+ "Ybus[0][4] = -y15\n",
+ "Ybus[4][0] = Ybus[0][4]\n",
+ "Ybus[4][1] = 0\n",
+ "Ybus[2][4] = -y35\n",
+ "Ybus[4][2] = Ybus[2][4]\n",
+ "print('Ybus=')\n",
+ "print(Ybus)\n",
+ "I11 = V / Ybus[3][3]\n",
+ "print(I11,' The subtransient current in a three-phase fault on bus 4 in per unit is ')\n",
+ "V3 = V - I11 * Ybus[3][2]\n",
+ "V5 = V - I11 * Ybus[3][4]\n",
+ "print('Voltages at bus 3 and 5 repectively in per unit = {0:.2f}+{1:.2f}i'.format(V3.real, V3.imag))\n",
+ "print('and {0:.2f}+{1:.2f}i'.format(V5.real, V5.imag))\n",
+ "\n",
+ "I3 = V3 * y34\n",
+ "I5 = V5 * y45\n",
+ "\n",
+ "#Results\n",
+ "print('Currents to fault from bus 3 in per unit = {0:.2f}+{1:.2f}i'.format(I3.real, I3.imag))\n",
+ "print(I5,'Currents to fault from bus 5 in per unit')\n",
+ "print('Currents to fault from bus 5 in per unit = {0:.2f}+{1:.2f}i'.format(I5.real, I5.imag))\n",
+ "print('Total current to fault in per unit = {0:.2f}+{1:.2f}i'.format((I3.real+I5.real),(I3.imag+I5.imag)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ybus=\n",
+ "[[(22.88888888888889+0j), (-5.952380952380952-0j), 0, 0, (-7.936507936507937-0j)], [(-5.952380952380952-0j), (13.88888888888889+0j), (-7.936507936507937-0j), 0, 0], [0, (-7.936507936507937-0j), 0, (-2.976190476190476-0j), (-4.761904761904762-0j)], [0, 0, (-2.976190476190476-0j), (6.944444444444445+0j), (-3.9682539682539684-0j)], [(-7.936507936507937-0j), 0, (-4.761904761904762-0j), (-3.9682539682539684-0j), (16.666666666666668+0j)]]\n",
+ "((0.144+0j), '\\n The subtransient current in a three-phase fault on bus 4 in per unit is \\n')\n",
+ "Voltages at bus 3 and 5 repectively in per unit = 1.43+0.00i\n",
+ "and 1.57+0.00i\n",
+ "Currents to fault from bus 3 in per unit = 4.25+0.00i\n",
+ "((6.235827664399093+0j), 'Currents to fault from bus 5 in per unit')\n",
+ "Currents to fault from bus 5 in per unit = 6.24+0.00i\n",
+ "Total current to fault in per unit = 10.49+0.00i\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.5, Page No 268"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Pg = 25e6\n",
+ "Vg = 13.8e3\n",
+ "X11_dg = 0.15\n",
+ "X11_dm = 0.20\n",
+ "Pmbase = 5e6\n",
+ "Vbasem = 6.9e3\n",
+ "P_tr = 25e6\n",
+ "V_ht = 13.8e3\n",
+ "V_lt = 6.9e3\n",
+ "X_tr = 0.10\n",
+ "Vbus_m = 6.9e3\n",
+ "\n",
+ "#Calculations\n",
+ "#the subtransient current in the fault\n",
+ "X11_dm1 = X11_dm * (P_tr / Pmbase)\n",
+ "Vf = 1.0\n",
+ "Xeqm = 1.0/(4*X11_dm1)\n",
+ "Xeq_trg = X11_dg + X_tr\n",
+ "Zth = Xeqm * Xeq_trg / (Xeqm + Xeq_trg)\n",
+ "I11_f = Vf / complex(Zth)\n",
+ "Ibase_vbus = P_tr / (math.sqrt(3) * Vbus_m)\n",
+ "I11_f_a = abs(I11_f) * Ibase_vbus\n",
+ "print(\" Fault current in per unit = -j%.0f \" %abs(I11_f.real))\n",
+ "print(\" Fault current in amperes = %.0f \" %I11_f_a)\n",
+ "#the subtransient current in breaker A\n",
+ "Ig_f = I11_f * Xeq_trg / (Xeqm + Xeq_trg)\n",
+ "Im_f = 0.25 * (I11_f - Ig_f)\n",
+ "I11_pu = Ig_f + 3 * Im_f\n",
+ "I11_a = I11_pu * Ibase_vbus\n",
+ "print(\" Subtransient current through breaker A in per unit is -j%.0f \" %abs(I11_pu))\n",
+ "print(\" Subtransient current through breaker A in amperes is %.0f \" %abs(I11_a))\n",
+ "#Symmetrical short-circuit interrupting current in the fault and in breaker A\n",
+ "X11_dm2 = 1.5 * X11_dm1\n",
+ "Xeqm1 = X11_dm2 / 4\n",
+ "Zth_c = (Xeqm1 * Xeq_trg) / (Xeqm1 + Xeq_trg)\n",
+ "Ig_f1 = Vf * Xeqm1 / (Zth_c * (Xeqm1 + Xeq_trg))\n",
+ "Im_f1 = (Vf * Xeq_trg) / (4 * Zth_c * (Xeqm1 + Xeq_trg))\n",
+ "I11_1pu = Ig_f1 + 3 * Im_f1\n",
+ "I11_1a = I11_1pu * Ibase_vbus\n",
+ "print('Symmetrical Short circuit current to be interrupted in A = %0.2f' %I11_1a)\n",
+ "I11_pu_cb = Ig_f1 + 4 * Im_f1\n",
+ "I11_a_cb = I11_pu_cb * Ibase_vbus\n",
+ "print('The short circuit current rating of breakers must be atleast(in amperes) = %0.2f' %I11_a_cb)\n",
+ "Vcb = 15.5e3\n",
+ "I_ic = 8900\n",
+ "k = 2.67\n",
+ "Iic = I_ic * k\n",
+ "Icb = Vcb * I_ic / Vbus_m\n",
+ "\n",
+ "#Results\n",
+ "print(\"The required capability of %.0f A is well below 80 percent of %.0f A\\n and the breaker is suitable with respect to the short-circuit current\" %(abs(I11_a_cb),abs(Icb)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Fault current in per unit = -j8 \n",
+ " Fault current in amperes = 16735 \n",
+ " Subtransient current through breaker A in per unit is -j7 \n",
+ " Subtransient current through breaker A in amperes is 14643 \n",
+ "Symmetrical Short circuit current to be interrupted in A = 12551.09\n",
+ "The short circuit current rating of breakers must be atleast(in amperes) = 13945.66\n",
+ "The required capability of 13946 A is well below 80 percent of 19993 A\n",
+ " and the breaker is suitable with respect to the short-circuit current\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo11.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo11.ipynb
new file mode 100755
index 00000000..6f47cd70
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo11.ipynb
@@ -0,0 +1,321 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11 : Symmetrical Components"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.1, Page No 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "I_a = 10 *complex(math.cos(0),math.sin(0))\n",
+ "I_b = 10 *complex(math.cos(180 * math.pi / 180),math.sin(180 * math.pi / 180))\n",
+ "I_c = 0\n",
+ "a = 1.0 * complex(math.cos(120.0 * math.pi / 180),math.sin(120 * math.pi / 180))\n",
+ "\n",
+ "#Calculations\n",
+ "#Phase 'a'\n",
+ "print('Phase a')\n",
+ "I_a0=(1.0/3)*(I_a+I_b+I_c)\n",
+ "I_a1=(1.0/3)*(I_a+a*I_b+a**2*I_c)\n",
+ "I_a2=(1.0/3)*(I_a+a**2*I_b+a*I_c)\n",
+ "print( \"I_a0 = {0:.2f}\".format(abs(I_a0.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_a0.imag,I_a0.real))))\n",
+ "print( \"I_a1 = {0:.2f}\".format(abs(I_a1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_a1.imag,I_a1.real))))\n",
+ "print( \"I_a2 = {0:.2f}\".format(abs(I_a2.real)))\n",
+ "print(\"Angle = %.2f A\\n \" %(math.degrees(math.atan2(I_a2.imag,I_a2.real))))\n",
+ "\n",
+ "#Phase 'b'\n",
+ "print('Phase b')\n",
+ "I_b0 = I_a0\n",
+ "I_b1=a**2*I_a1\n",
+ "I_b2=a*I_a2\n",
+ "\n",
+ "#Results\n",
+ "print( \"I_b0 = {0:.2f}\".format(abs(I_b0.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_b0.imag,I_b0.real))))\n",
+ "print( \"I_b1 = {0:.2f}\".format(abs(I_b1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_b1.imag,I_b1.real))))\n",
+ "print( \"I_b2 = {0:.2f}\".format(abs(I_b2.real)))\n",
+ "print(\"Angle = %.2f A\\n \" %(math.degrees(math.atan2(I_b2.imag,I_b2.real))))\n",
+ "\n",
+ "#Phase 'c'\n",
+ "print('Phase c')\n",
+ "I_c0=I_a0\n",
+ "I_c1=a*I_a1\n",
+ "I_c2=a**2*I_a2\n",
+ "\n",
+ "#Results\n",
+ "print( \"I_c0 = {0:.2f}\".format(abs(I_c0.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_c0.imag,I_c0.real))))\n",
+ "print( \"I_c1 = {0:.2f}\".format(abs(I_c1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_c1.imag,I_c1.real))))\n",
+ "print( \"I_c2 = {0:.2f}\".format(abs(I_c2.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_c2.imag,I_c2.real))))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Phase a\n",
+ "I_a0 = 0.00\n",
+ "Angle = 90.00 A \n",
+ "I_a1 = 5.00\n",
+ "Angle = -30.00 A \n",
+ "I_a2 = 5.00\n",
+ "Angle = 30.00 A\n",
+ " \n",
+ "Phase b\n",
+ "I_b0 = 0.00\n",
+ "Angle = 90.00 A \n",
+ "I_b1 = 5.00\n",
+ "Angle = -150.00 A \n",
+ "I_b2 = 5.00\n",
+ "Angle = 150.00 A\n",
+ " \n",
+ "Phase c\n",
+ "I_c0 = 0.00\n",
+ "Angle = 90.00 A \n",
+ "I_c1 = 0.00\n",
+ "Angle = 90.00 A \n",
+ "I_c2 = 0.00\n",
+ "Angle = -90.00 A \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.2, Page No 285"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V_ab = 0.8 * complex(math.cos(82.8 * math.pi /180),math.sin(82.8 * math.pi / 180))\n",
+ "V_bc = 1.2 * complex(math.cos(-41.4 * math.pi /180),math.sin(-41.4 * math.pi / 180))\n",
+ "V_ca = 1 * complex(math.cos(180 * math.pi /180),math.sin(180 * math.pi / 180))\n",
+ "a = 1 * complex(math.cos(120 * math.pi / 180),math.sin(120 * math.pi / 180))\n",
+ "\n",
+ "#Symmetrical components of line voltage\n",
+ "#math.since neutral connection is absent zero sequence components are absent\n",
+ "V_ab1=(1.0/3)*(V_ab+a*V_bc+a**2*V_ca)\n",
+ "V_ab2=(1.0/3)*(V_ab+a**2*V_bc+a*V_ca)\n",
+ "\n",
+ "V_a1 = V_ab1 * complex(math.cos(-30 * math.pi / 180),math.sin(-30 * math.pi / 180))\n",
+ "V_a2 = V_ab2 * complex(math.cos(30 * math.pi / 180),math.sin(30 * math.pi / 180))\n",
+ "\n",
+ "r = 1 * complex(math.cos(0),math.sin(0))\n",
+ "\n",
+ "I_a1 = V_a1 / r\n",
+ "I_a2 = V_a2 / r\n",
+ "\n",
+ "V_A1 = -1 *complex(V_a1) \n",
+ "V_A2 = complex(V_a2) \n",
+ "V_A = V_A1 + V_A2\n",
+ "\n",
+ "V_B1 = a**2 * V_A1\n",
+ "V_B2 = a * V_A2\n",
+ "V_B = V_B1 + V_B2\n",
+ "\n",
+ "V_C1 = a * V_A1\n",
+ "V_C2 = a**2 * V_A2\n",
+ "V_C = V_C1 + V_C2\n",
+ "\n",
+ "V_AB = V_A - V_B\n",
+ "V_BC = V_B - V_C\n",
+ "V_CA = V_C - V_A\n",
+ "\n",
+ "I_A = V_A / r\n",
+ "I_B = V_B / r\n",
+ "I_C = V_C / r\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print('Line-neutral voltages')\n",
+ "print( \"V_AB = {0:.2f}\".format(abs(V_AB.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_AB.imag,V_AB.real))))\n",
+ "print( \"V_BC = {0:.2f}\".format(abs(V_BC.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_BC.imag,V_BC.real))))\n",
+ "print( \"V_CA = {0:.2f}\".format(abs(V_CA.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_CA.imag,V_CA.real))))\n",
+ "\n",
+ "\n",
+ "print('Line-line voltages')\n",
+ "print( \"V_AB = {0:.2f}\".format(abs(V_AB.real)/math.sqrt(3)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_AB.imag,V_AB.real))))\n",
+ "print( \"V_BC = {0:.2f}\".format(abs(V_BC.real)/math.sqrt(3)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_BC.imag,V_BC.real))))\n",
+ "print( \"V_CA = {0:.2f}\".format(abs(V_CA.real)/math.sqrt(3)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_CA.imag,V_CA.real))))\n",
+ "\n",
+ "\n",
+ "print('Line currents')\n",
+ "print( \"I_A = {0:.2f}\".format(abs(I_A.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(I_A.imag,I_A.real))))\n",
+ "print( \"I_B = {0:.2f}\".format(abs(I_B.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(I_B.imag,I_B.real))))\n",
+ "print( \"I_C = {0:.2f}\".format(abs(I_C.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(I_C.imag,I_C.real))))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Line-neutral voltages\n",
+ "V_AB = 0.79\n",
+ "Angle = -112.67 per unit \n",
+ "V_BC = 0.79\n",
+ "Angle = 125.81 per unit \n",
+ "V_CA = 1.59\n",
+ "Angle = 26.74 per unit \n",
+ "Line-line voltages\n",
+ "V_AB = 0.46\n",
+ "Angle = -112.67 per unit \n",
+ "V_BC = 0.46\n",
+ "Angle = 125.81 per unit \n",
+ "V_CA = 0.92\n",
+ "Angle = 26.74 per unit \n",
+ "Line currents\n",
+ "I_A = 0.79\n",
+ "Angle = -131.41 per unit \n",
+ "I_B = 0.00\n",
+ "Angle = 90.00 per unit \n",
+ "I_C = 0.79\n",
+ "Angle = -7.19 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.4, Page No 301"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "\n",
+ "def pucalc(pu_Z_given,base_kV_given,base_kV_new,base_kVA_new,base_kVA_given):\n",
+ " X11=(pu_Z_given * (base_kV_given/base_kV_new)**2 * (base_kVA_new/base_kVA_given))\n",
+ " return X11\n",
+ "\n",
+ "#Given\n",
+ "P_g = 300e6\n",
+ "V_g = 20e3\n",
+ "X11_g = 0.20\n",
+ "l = 64\n",
+ "V_m = 13.2e3\n",
+ "P_m1 = 200e6\n",
+ "P_m2 = 100e6\n",
+ "X11_m = 0.20\n",
+ "T1_P = 350e6\n",
+ "T1_vht = 230e3\n",
+ "T1_vlt = 20e3\n",
+ "x_T1 = 0.10\n",
+ "T2_1_P = 100e6\n",
+ "T2_1_vht = 127e3\n",
+ "T2_1_vlt = 13.2e3\n",
+ "x_T2 = 0.10\n",
+ "x_line = 0.5#ohm per km\n",
+ "V_base = V_g\n",
+ "P_base = P_g\n",
+ "x0 = 0.05\n",
+ "x_cl = 0.4\n",
+ "x0_line = 1.5#ohm per km\n",
+ "\n",
+ "#Calculations\n",
+ "T2_P = 3*T2_1_P\n",
+ "T2_vht = math.sqrt(3)*T2_1_vht\n",
+ "T2_vlt = T2_1_vlt\n",
+ "V_base_line = (T1_vht/T1_vlt)*V_base\n",
+ "V_base_m = V_base_line * (T2_vlt/T2_vht)\n",
+ "z_line_base = (V_base_line)**2/P_base\n",
+ "x_line_pu = x_line * l / z_line_base\n",
+ "x0_g = x0\n",
+ "x0_m1 = pucalc(x0,V_m,V_base_m,P_base,P_m1)\n",
+ "x0_m2 = pucalc(x0,V_m,V_base_m,P_base,P_m2)\n",
+ "Z_g = (V_g**2) / P_base\n",
+ "Z_m = (V_base_m)**2 / P_base\n",
+ "Zn_g = 3 * x_cl / Z_g\n",
+ "Zn_m = 3 * x_cl / Z_m\n",
+ "X_0 = x0_line * l / z_line_base\n",
+ "\n",
+ "#Results\n",
+ "print(\" Generator X0 = %.2f per unit\" %x0_g)\n",
+ "print(\" Motor 1 X0 = %.4f per unit\" %x0_m1)\n",
+ "print(\" Motor 2 X0 = %.4f per unit\" %x0_m2)\n",
+ "print(\" Generator base impedance = %.3f per unit\" %Z_g)\n",
+ "print(\" Motor base impedance = %.3f per unit\" %Z_m)\n",
+ "print(\" In generator 3Zn = %.3f per unit\" %Zn_g)\n",
+ "print(\" In motor 3Zn = %.3f per unit\" %Zn_m)\n",
+ "print(\" Transmission line X0 = %.4f per unit\" %X_0)\n",
+ "#zero-sequence diagram is shown in xcos file"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Generator X0 = 0.05 per unit\n",
+ " Motor 1 X0 = 0.0686 per unit\n",
+ " Motor 2 X0 = 0.1372 per unit\n",
+ " Generator base impedance = 1.333 per unit\n",
+ " Motor base impedance = 0.635 per unit\n",
+ " In generator 3Zn = 0.900 per unit\n",
+ " In motor 3Zn = 1.890 per unit\n",
+ " Transmission line X0 = 0.5444 per unit\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo11_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo11_1.ipynb
new file mode 100755
index 00000000..6f47cd70
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo11_1.ipynb
@@ -0,0 +1,321 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11 : Symmetrical Components"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.1, Page No 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "I_a = 10 *complex(math.cos(0),math.sin(0))\n",
+ "I_b = 10 *complex(math.cos(180 * math.pi / 180),math.sin(180 * math.pi / 180))\n",
+ "I_c = 0\n",
+ "a = 1.0 * complex(math.cos(120.0 * math.pi / 180),math.sin(120 * math.pi / 180))\n",
+ "\n",
+ "#Calculations\n",
+ "#Phase 'a'\n",
+ "print('Phase a')\n",
+ "I_a0=(1.0/3)*(I_a+I_b+I_c)\n",
+ "I_a1=(1.0/3)*(I_a+a*I_b+a**2*I_c)\n",
+ "I_a2=(1.0/3)*(I_a+a**2*I_b+a*I_c)\n",
+ "print( \"I_a0 = {0:.2f}\".format(abs(I_a0.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_a0.imag,I_a0.real))))\n",
+ "print( \"I_a1 = {0:.2f}\".format(abs(I_a1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_a1.imag,I_a1.real))))\n",
+ "print( \"I_a2 = {0:.2f}\".format(abs(I_a2.real)))\n",
+ "print(\"Angle = %.2f A\\n \" %(math.degrees(math.atan2(I_a2.imag,I_a2.real))))\n",
+ "\n",
+ "#Phase 'b'\n",
+ "print('Phase b')\n",
+ "I_b0 = I_a0\n",
+ "I_b1=a**2*I_a1\n",
+ "I_b2=a*I_a2\n",
+ "\n",
+ "#Results\n",
+ "print( \"I_b0 = {0:.2f}\".format(abs(I_b0.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_b0.imag,I_b0.real))))\n",
+ "print( \"I_b1 = {0:.2f}\".format(abs(I_b1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_b1.imag,I_b1.real))))\n",
+ "print( \"I_b2 = {0:.2f}\".format(abs(I_b2.real)))\n",
+ "print(\"Angle = %.2f A\\n \" %(math.degrees(math.atan2(I_b2.imag,I_b2.real))))\n",
+ "\n",
+ "#Phase 'c'\n",
+ "print('Phase c')\n",
+ "I_c0=I_a0\n",
+ "I_c1=a*I_a1\n",
+ "I_c2=a**2*I_a2\n",
+ "\n",
+ "#Results\n",
+ "print( \"I_c0 = {0:.2f}\".format(abs(I_c0.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_c0.imag,I_c0.real))))\n",
+ "print( \"I_c1 = {0:.2f}\".format(abs(I_c1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_c1.imag,I_c1.real))))\n",
+ "print( \"I_c2 = {0:.2f}\".format(abs(I_c2.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(I_c2.imag,I_c2.real))))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Phase a\n",
+ "I_a0 = 0.00\n",
+ "Angle = 90.00 A \n",
+ "I_a1 = 5.00\n",
+ "Angle = -30.00 A \n",
+ "I_a2 = 5.00\n",
+ "Angle = 30.00 A\n",
+ " \n",
+ "Phase b\n",
+ "I_b0 = 0.00\n",
+ "Angle = 90.00 A \n",
+ "I_b1 = 5.00\n",
+ "Angle = -150.00 A \n",
+ "I_b2 = 5.00\n",
+ "Angle = 150.00 A\n",
+ " \n",
+ "Phase c\n",
+ "I_c0 = 0.00\n",
+ "Angle = 90.00 A \n",
+ "I_c1 = 0.00\n",
+ "Angle = 90.00 A \n",
+ "I_c2 = 0.00\n",
+ "Angle = -90.00 A \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.2, Page No 285"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V_ab = 0.8 * complex(math.cos(82.8 * math.pi /180),math.sin(82.8 * math.pi / 180))\n",
+ "V_bc = 1.2 * complex(math.cos(-41.4 * math.pi /180),math.sin(-41.4 * math.pi / 180))\n",
+ "V_ca = 1 * complex(math.cos(180 * math.pi /180),math.sin(180 * math.pi / 180))\n",
+ "a = 1 * complex(math.cos(120 * math.pi / 180),math.sin(120 * math.pi / 180))\n",
+ "\n",
+ "#Symmetrical components of line voltage\n",
+ "#math.since neutral connection is absent zero sequence components are absent\n",
+ "V_ab1=(1.0/3)*(V_ab+a*V_bc+a**2*V_ca)\n",
+ "V_ab2=(1.0/3)*(V_ab+a**2*V_bc+a*V_ca)\n",
+ "\n",
+ "V_a1 = V_ab1 * complex(math.cos(-30 * math.pi / 180),math.sin(-30 * math.pi / 180))\n",
+ "V_a2 = V_ab2 * complex(math.cos(30 * math.pi / 180),math.sin(30 * math.pi / 180))\n",
+ "\n",
+ "r = 1 * complex(math.cos(0),math.sin(0))\n",
+ "\n",
+ "I_a1 = V_a1 / r\n",
+ "I_a2 = V_a2 / r\n",
+ "\n",
+ "V_A1 = -1 *complex(V_a1) \n",
+ "V_A2 = complex(V_a2) \n",
+ "V_A = V_A1 + V_A2\n",
+ "\n",
+ "V_B1 = a**2 * V_A1\n",
+ "V_B2 = a * V_A2\n",
+ "V_B = V_B1 + V_B2\n",
+ "\n",
+ "V_C1 = a * V_A1\n",
+ "V_C2 = a**2 * V_A2\n",
+ "V_C = V_C1 + V_C2\n",
+ "\n",
+ "V_AB = V_A - V_B\n",
+ "V_BC = V_B - V_C\n",
+ "V_CA = V_C - V_A\n",
+ "\n",
+ "I_A = V_A / r\n",
+ "I_B = V_B / r\n",
+ "I_C = V_C / r\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print('Line-neutral voltages')\n",
+ "print( \"V_AB = {0:.2f}\".format(abs(V_AB.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_AB.imag,V_AB.real))))\n",
+ "print( \"V_BC = {0:.2f}\".format(abs(V_BC.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_BC.imag,V_BC.real))))\n",
+ "print( \"V_CA = {0:.2f}\".format(abs(V_CA.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_CA.imag,V_CA.real))))\n",
+ "\n",
+ "\n",
+ "print('Line-line voltages')\n",
+ "print( \"V_AB = {0:.2f}\".format(abs(V_AB.real)/math.sqrt(3)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_AB.imag,V_AB.real))))\n",
+ "print( \"V_BC = {0:.2f}\".format(abs(V_BC.real)/math.sqrt(3)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_BC.imag,V_BC.real))))\n",
+ "print( \"V_CA = {0:.2f}\".format(abs(V_CA.real)/math.sqrt(3)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(V_CA.imag,V_CA.real))))\n",
+ "\n",
+ "\n",
+ "print('Line currents')\n",
+ "print( \"I_A = {0:.2f}\".format(abs(I_A.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(I_A.imag,I_A.real))))\n",
+ "print( \"I_B = {0:.2f}\".format(abs(I_B.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(I_B.imag,I_B.real))))\n",
+ "print( \"I_C = {0:.2f}\".format(abs(I_C.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(I_C.imag,I_C.real))))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Line-neutral voltages\n",
+ "V_AB = 0.79\n",
+ "Angle = -112.67 per unit \n",
+ "V_BC = 0.79\n",
+ "Angle = 125.81 per unit \n",
+ "V_CA = 1.59\n",
+ "Angle = 26.74 per unit \n",
+ "Line-line voltages\n",
+ "V_AB = 0.46\n",
+ "Angle = -112.67 per unit \n",
+ "V_BC = 0.46\n",
+ "Angle = 125.81 per unit \n",
+ "V_CA = 0.92\n",
+ "Angle = 26.74 per unit \n",
+ "Line currents\n",
+ "I_A = 0.79\n",
+ "Angle = -131.41 per unit \n",
+ "I_B = 0.00\n",
+ "Angle = 90.00 per unit \n",
+ "I_C = 0.79\n",
+ "Angle = -7.19 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.4, Page No 301"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "\n",
+ "def pucalc(pu_Z_given,base_kV_given,base_kV_new,base_kVA_new,base_kVA_given):\n",
+ " X11=(pu_Z_given * (base_kV_given/base_kV_new)**2 * (base_kVA_new/base_kVA_given))\n",
+ " return X11\n",
+ "\n",
+ "#Given\n",
+ "P_g = 300e6\n",
+ "V_g = 20e3\n",
+ "X11_g = 0.20\n",
+ "l = 64\n",
+ "V_m = 13.2e3\n",
+ "P_m1 = 200e6\n",
+ "P_m2 = 100e6\n",
+ "X11_m = 0.20\n",
+ "T1_P = 350e6\n",
+ "T1_vht = 230e3\n",
+ "T1_vlt = 20e3\n",
+ "x_T1 = 0.10\n",
+ "T2_1_P = 100e6\n",
+ "T2_1_vht = 127e3\n",
+ "T2_1_vlt = 13.2e3\n",
+ "x_T2 = 0.10\n",
+ "x_line = 0.5#ohm per km\n",
+ "V_base = V_g\n",
+ "P_base = P_g\n",
+ "x0 = 0.05\n",
+ "x_cl = 0.4\n",
+ "x0_line = 1.5#ohm per km\n",
+ "\n",
+ "#Calculations\n",
+ "T2_P = 3*T2_1_P\n",
+ "T2_vht = math.sqrt(3)*T2_1_vht\n",
+ "T2_vlt = T2_1_vlt\n",
+ "V_base_line = (T1_vht/T1_vlt)*V_base\n",
+ "V_base_m = V_base_line * (T2_vlt/T2_vht)\n",
+ "z_line_base = (V_base_line)**2/P_base\n",
+ "x_line_pu = x_line * l / z_line_base\n",
+ "x0_g = x0\n",
+ "x0_m1 = pucalc(x0,V_m,V_base_m,P_base,P_m1)\n",
+ "x0_m2 = pucalc(x0,V_m,V_base_m,P_base,P_m2)\n",
+ "Z_g = (V_g**2) / P_base\n",
+ "Z_m = (V_base_m)**2 / P_base\n",
+ "Zn_g = 3 * x_cl / Z_g\n",
+ "Zn_m = 3 * x_cl / Z_m\n",
+ "X_0 = x0_line * l / z_line_base\n",
+ "\n",
+ "#Results\n",
+ "print(\" Generator X0 = %.2f per unit\" %x0_g)\n",
+ "print(\" Motor 1 X0 = %.4f per unit\" %x0_m1)\n",
+ "print(\" Motor 2 X0 = %.4f per unit\" %x0_m2)\n",
+ "print(\" Generator base impedance = %.3f per unit\" %Z_g)\n",
+ "print(\" Motor base impedance = %.3f per unit\" %Z_m)\n",
+ "print(\" In generator 3Zn = %.3f per unit\" %Zn_g)\n",
+ "print(\" In motor 3Zn = %.3f per unit\" %Zn_m)\n",
+ "print(\" Transmission line X0 = %.4f per unit\" %X_0)\n",
+ "#zero-sequence diagram is shown in xcos file"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Generator X0 = 0.05 per unit\n",
+ " Motor 1 X0 = 0.0686 per unit\n",
+ " Motor 2 X0 = 0.1372 per unit\n",
+ " Generator base impedance = 1.333 per unit\n",
+ " Motor base impedance = 0.635 per unit\n",
+ " In generator 3Zn = 0.900 per unit\n",
+ " In motor 3Zn = 1.890 per unit\n",
+ " Transmission line X0 = 0.5444 per unit\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo12.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo12.ipynb
new file mode 100755
index 00000000..24e7be7d
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo12.ipynb
@@ -0,0 +1,592 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12 : Unsymmetrical Faults"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.1, Page No 308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P = 20e6\n",
+ "V = 13.8e3\n",
+ "P_b = 20e6\n",
+ "V_b = 13.8e3\n",
+ "Z1 = complex(0.25)\n",
+ "Z2 = complex(0.35)\n",
+ "Z0 = complex(0.10)\n",
+ "a = 1 * complex(math.cos(120*math.pi / 180),math.sin(120 * math.pi / 180))\n",
+ "\n",
+ "#Calculations\n",
+ "Ea = V / V_b\n",
+ "Ia1 = Ea / (Z0 + Z1 + Z2)\n",
+ "Ia2 = Ia1\n",
+ "Ia0 = Ia1\n",
+ "Ia = 3 * Ia1\n",
+ "I_b = P / (math.sqrt(3) * V)\n",
+ "Ia_1 = Ia * I_b\n",
+ "print(\" Base Current = %f A\" %I_b)\n",
+ "print(\" Subtransient current in line a = -j%.0f A \" %abs(Ia_1.imag))\n",
+ "#Symmetrical Components of voltage from point a to ground\n",
+ "Va1 = Ea - Ia1 * Z1\n",
+ "Va2 = -Ia2 * Z2\n",
+ "Va0 = -Ia0 * Z0\n",
+ "print('Symmetrical Components of voltage from point a to ground')\n",
+ "print( \"Va1= {0:.5f}+{1:.5f}i per unit\".format(Va1.real, Va1.imag))\n",
+ "print( \"Va2= {0:.5f}+{1:.5f}i per unit\".format(Va2.real, Va2.imag))\n",
+ "print( \"Va0= {0:.5f}+{1:.5f}i per unit\".format(Va0.real, Va0.imag))\n",
+ "\n",
+ "#Line to ground voltages\n",
+ "Va = Va0 + Va1 + Va2\n",
+ "Vb = Va0 + Va1 * a**2 + Va2 * a\n",
+ "Vc = Va0 + Va2 * a**2 + Va1 * a\n",
+ "\n",
+ "#Results\n",
+ "print('Line to ground voltages')\n",
+ "print( \"Va = {0:.2f}\".format(abs(Va.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Va.imag,Va.real))))\n",
+ "print( \"Vb = {0:.2f}\".format(abs(Vb.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vb.imag,Vb.real))))\n",
+ "print( \"Vc = {0:.2f}\".format(abs(Vc.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vc.imag,Vc.real))))\n",
+ "\n",
+ "#Line to line voltages in per-unit are\n",
+ "Vab = Va - Vb\n",
+ "Vbc = Vb - Vc\n",
+ "Vca = Vc - Va\n",
+ "print('Line to line voltages in per-unit are')\n",
+ "print( \"Vab = {0:.2f}\".format(abs(Vab.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vab.imag,Vab.real))))\n",
+ "print( \"Vbc = {0:.2f}\".format(abs(Vbc.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vbc.imag,Vbc.real))))\n",
+ "print( \"Vca = {0:.2f}\".format(abs(Vca.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vca.imag,Vca.real))))\n",
+ "#Line to line voltages in volts\n",
+ "Vab_1 = Vab * V / math.sqrt(3)\n",
+ "Vbc_1 = Vbc * V / math.sqrt(3)\n",
+ "Vca_1 = Vca * V / math.sqrt(3)\n",
+ "print('Line to line voltages in volts')\n",
+ "print( \"Vab = {0:.2f}\".format(abs(Vab_1.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vab_1.imag,Vab_1.real))))\n",
+ "print( \"Vbc = {0:.2f}\".format(abs(Vbc_1.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vbc_1.imag,Vbc_1.real))))\n",
+ "print( \"Vca = {0:.2f}\".format(abs(Vca_1.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vca_1.imag,Vca_1.real))))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Base Current = 836.739521 A\n",
+ " Subtransient current in line a = -j0 A \n",
+ "Symmetrical Components of voltage from point a to ground\n",
+ "Va1= 0.64286+0.00000i per unit\n",
+ "Va2= -0.50000+-0.00000i per unit\n",
+ "Va0= -0.14286+-0.00000i per unit\n",
+ "Line to ground voltages\n",
+ "Va = 0.00\n",
+ "Angle = 180.00 per unit \n",
+ "Vb = 0.21\n",
+ "Angle = -102.22 per unit \n",
+ "Vc = 0.21\n",
+ "Angle = 102.22 per unit \n",
+ "Line to line voltages in per-unit are\n",
+ "Vab = 0.21\n",
+ "Angle = 77.78 per unit \n",
+ "Vbc = 0.00\n",
+ "Angle = -90.00 per unit \n",
+ "Vca = 0.21\n",
+ "Angle = 102.22 per unit \n",
+ "Line to line voltages in volts\n",
+ "Vab = 1707.31\n",
+ "Angle = 77.78 per unit \n",
+ "Vbc = 0.00\n",
+ "Angle = -90.00 per unit \n",
+ "Vca = 1707.31\n",
+ "Angle = 102.22 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.2, Page No 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P = 20e6\n",
+ "V = 13.8e3\n",
+ "P_b = 20e6\n",
+ "V_b = 13.8e3\n",
+ "Z1 = complex(0.25)\n",
+ "Z2 = complex(0.35)\n",
+ "Z0 = complex(0.10)\n",
+ "a = 1 * complex(math.cos(120 * math.pi / 180),math.sin(120 * math.pi / 180))\n",
+ "#Calculations\n",
+ "Ea = V / V_b\n",
+ "Ia1 = Ea / (Z1 + Z2)\n",
+ "Ia2 = - Ia1\n",
+ "Ia0 = 0\n",
+ "Ia = Ia1 + Ia2 + Ia0\n",
+ "Ib = a**2 * Ia1 + a*Ia2 + Ia0\n",
+ "Ic = -Ib\n",
+ "I_b = P / (math.sqrt(3) * V)\n",
+ "print( \"Base Current = {0:.2f}+{1:.2f}i A\".format(I_b.real, I_b.imag))\n",
+ "Ia_1 = Ia * I_b\n",
+ "Ib_1 = Ib * I_b\n",
+ "Ic_1 = Ic * I_b\n",
+ "print(\" Subtransient current in line a = {0:.2f}+{1:.2f}i A\".format(Ia_1.real, Ia_1.imag))\n",
+ "print( \"Subtransient current in line b = {0:.2f}\".format(abs(Ib_1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(Ib_1.imag,Ib_1.real))))\n",
+ "print( \"Subtransient current in line c = = {0:.2f}\".format(abs(Ic_1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(Ic_1.imag,Ic_1.real))))\n",
+ "\n",
+ "##Symmetrical Components of voltage from point a to ground\n",
+ "Va1 = Ea - Ia1 * Z1\n",
+ "Va2 = Va1\n",
+ "Va0 = 0\n",
+ "print('Symmetrical Components of voltage from point a to ground')\n",
+ "print( \"Va1= {0:.5f}+{1:.5f}i per unit\".format(Va1.real, Va1.imag))\n",
+ "print( \"Va2= {0:.5f}+{1:.5f}i per unit\".format(Va2.real, Va2.imag))\n",
+ "print( \"Va0= {0:.5f}+{1:.5f}i per unit\".format(Va0.real, Va0.imag))\n",
+ "\n",
+ "#Line to ground voltages\n",
+ "Va = Va0 + Va1 + Va2\n",
+ "Vb = Va0 + Va1 * a**2 + Va2 * a\n",
+ "Vc = Vb\n",
+ "print('Line to ground voltages')\n",
+ "print( \"Va = {0:.2f}\".format(abs(Va.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Va.imag,Va.real))))\n",
+ "print( \"Vb= {0:.5f}+{1:.5f}i per unit\".format(Vb.real, Vb.imag))\n",
+ "\n",
+ "#Line to line voltages in per-unit are\n",
+ "Vab = Va - Vb\n",
+ "Vbc = Vb - Vc\n",
+ "Vca = Vc - Va\n",
+ "\n",
+ "#Results\n",
+ "print('Line to line voltages in per-unit are')\n",
+ "print( \"Vab = {0:.2f}\".format(abs(Vab.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vab.imag,Vab.real))))\n",
+ "print( \"Vbc= {0:.5f}+{1:.5f}i per unit\".format(Vbc.real, Vbc.imag))\n",
+ "print( \"Vca = {0:.2f}\".format(abs(Vca.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vca.imag,Vca.real))))\n",
+ "\n",
+ "#Line to line voltages in volts\n",
+ "Vab_1 = Vab * V / math.sqrt(3)\n",
+ "Vbc_1 = Vbc * V / math.sqrt(3)\n",
+ "Vca_1 = Vca * V / math.sqrt(3)\n",
+ "print('Line to line voltages in volts')\n",
+ "print( \"Vab = {0:.2f}\".format(abs(Vab_1.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vab_1.imag,Vab_1.real))))\n",
+ "print( \"Vbc= {0:.5f}+{1:.5f}i per unit\".format(Vbc_1.real, Vbc_1.imag))\n",
+ "print( \"Vca = {0:.2f}\".format(abs(Vca_1.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vca_1.imag,Vca_1.real))))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base Current = 836.74+0.00i A\n",
+ " Subtransient current in line a = 0.00+0.00i A\n",
+ "Subtransient current in line b = 0.00\n",
+ "Angle = -90.00 A \n",
+ "Subtransient current in line c = = 0.00\n",
+ "Angle = 90.00 A \n",
+ "Symmetrical Components of voltage from point a to ground\n",
+ "Va1= 0.58333+0.00000i per unit\n",
+ "Va2= 0.58333+0.00000i per unit\n",
+ "Va0= 0.00000+0.00000i per unit\n",
+ "Line to ground voltages\n",
+ "Va = 1.17\n",
+ "Angle = 0.00 per unit \n",
+ "Vb= -0.58333+0.00000i per unit\n",
+ "Line to line voltages in per-unit are\n",
+ "Vab = 1.75\n",
+ "Angle = -0.00 per unit \n",
+ "Vbc= 0.00000+0.00000i per unit\n",
+ "Vca = 1.75\n",
+ "Angle = 180.00 per unit \n",
+ "Line to line voltages in volts\n",
+ "Vab = 13943.01\n",
+ "Angle = -0.00 per unit \n",
+ "Vbc= 0.00000+0.00000i per unit\n",
+ "Vca = 13943.01\n",
+ "Angle = 180.00 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.3, Page No 314"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P = 20e6\n",
+ "V = 13.8e3\n",
+ "P_b = 20e6\n",
+ "V_b = 13.8e3\n",
+ "Z1 = complex(0.25)\n",
+ "Z2 = complex(0.35)\n",
+ "Z0 = complex(0.10)\n",
+ "a = 1 * complex(math.cos(120 * math.pi / 180), math.sin(120 * math.pi/180))\n",
+ "\n",
+ "#Calculations\n",
+ "Ea = V / V_b\n",
+ "Ia1 = Ea / (Z1 + (Z2*Z0)/(Z2+Z0))\n",
+ "I_b = P / (math.sqrt(3) * V)\n",
+ "Va1 = Ea - Ia1 * Z1\n",
+ "Va2 = Va1Va0 = Va1\n",
+ "Ia2 = - Va2 / Z2\n",
+ "Ia0 = - Va0 / Z0\n",
+ "Ia = Ia1 + Ia2 + Ia0\n",
+ "Ib = a**2*Ia1 + a*Ia2 + Ia0\n",
+ "Ic = a*Ia1 + a**2*Ia2 + Ia0\n",
+ "In = 3 * Ia0\n",
+ "Va = Va1 + Va2 + Va0\n",
+ "Vb = 0\n",
+ "Vc = 0\n",
+ "print('Line to ground voltages')\n",
+ "print( \"Va = {0:.2f}\".format(abs(Va.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Va.imag,Va.real))))\n",
+ "print( \"Vb= {0:.5f}+{1:.5f}i per unit\".format(Vb.real, Vb.imag))\n",
+ "Vab = Va - Vb\n",
+ "Vbc = Vb - Vc\n",
+ "Vca = Vc - Va\n",
+ "print('Line to line voltages in per-unit are')\n",
+ "\n",
+ "print( \"Vab= {0:.2f}+{1:.2f}i per unit\".format(Vab.real, Vab.imag))\n",
+ "print( \"Vbc= {0:.2f}+{1:.2f}i per unit\".format(Vbc.real, Vbc.imag))\n",
+ "print( \"Vca= {0:.2f}+{1:.2f}i per unit\".format(Vca.real, Vca.imag))\n",
+ "I_a1 = I_b * Ia\n",
+ "I_b1 = I_b * Ib\n",
+ "I_c1 = I_b * Ic\n",
+ "I_n1 = I_b * In\n",
+ "\n",
+ "#Results\n",
+ "print( \"Base Current = {0:.2f}+{1:.2f}i per unit\".format(I_b.real, I_b.imag))\n",
+ "print(\" Subtransient current in line a = {0:.2f}+{1:.2f}i A\".format(Ia_1.real, Ia_1.imag))\n",
+ "print( \"Subtransient current in line b = {0:.2f}\".format(abs(Ib_1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(Ib_1.imag,Ib_1.real))))\n",
+ "print( \"Subtransient current in line c = = {0:.2f}\".format(abs(Ic_1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(Ic_1.imag,Ic_1.real))))\n",
+ "print( \"Subtransient current in line c = = {0:.2f}\".format(abs(Ic_1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(Ic_1.imag,Ic_1.real))))\n",
+ "\n",
+ "Vab_1 = Vab * V / math.sqrt(3)\n",
+ "Vbc_1 = Vbc * V / math.sqrt(3)\n",
+ "Vca_1 = Vca * V / math.sqrt(3)\n",
+ "print('Line to line voltages in volts')\n",
+ "print( \"Vab = {0:.2f}\".format(abs(Vab.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vab.imag,Vab.real))))\n",
+ "print( \"Vbc= {0:.5f}+{1:.5f}i per unit\".format(Vbc.real, Vbc.imag))\n",
+ "print( \"Vca = {0:.2f}\".format(abs(Vca.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vca.imag,Vca.real))))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Line to ground voltages\n",
+ "Va = 0.47\n",
+ "Angle = 0.00 per unit \n",
+ "Vb= 0.00000+0.00000i per unit\n",
+ "Line to line voltages in per-unit are\n",
+ "Vab= 0.47+0.00i per unit\n",
+ "Vbc= 0.00+0.00i per unit\n",
+ "Vca= -0.47+0.00i per unit\n",
+ "Base Current = 836.74+0.00i per unit\n",
+ " Subtransient current in line a = 0.00+0.00i A\n",
+ "Subtransient current in line b = 0.00\n",
+ "Angle = -90.00 A \n",
+ "Subtransient current in line c = = 0.00\n",
+ "Angle = 90.00 A \n",
+ "Subtransient current in line c = = 0.00\n",
+ "Angle = 90.00 A \n",
+ "Line to line voltages in volts\n",
+ "Vab = 0.47\n",
+ "Angle = 0.00 per unit \n",
+ "Vbc= 0.00000+0.00000i per unit\n",
+ "Vca = 0.47\n",
+ "Angle = 180.00 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.4 Page No 321"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V_bus1 = 4.16e3\n",
+ "V_bus_2 = 600\n",
+ "Vm = 600\n",
+ "n_m = 0.895\n",
+ "Pop_m = 6000\n",
+ "X11_m = 0.2\n",
+ "X_2_m = 0.20\n",
+ "X_0_m = 0.04\n",
+ "X_n_m= 0.02\n",
+ "Vtr_ht = math.sqrt(3) * 2400\n",
+ "Vtr_lt = 600\n",
+ "Ptr =3 * 2500e3\n",
+ "X11_tr = 0.10\n",
+ "Pg = 7500e3\n",
+ "Vg = 4.16e3\n",
+ "X11_g = 0.10\n",
+ "X_2_g = 0.10\n",
+ "X_0_g = 0.05\n",
+ "X_n_g = 0.05\n",
+ "#At the time of fault\n",
+ "Pload = 5000\n",
+ "pf_load = 0.85\n",
+ "n_load = 0.88\n",
+ "Vbase_sysbus = Vg\n",
+ "Pbase_sysbus = Pg\n",
+ "Vbase_m = Vtr_lt\n",
+ "Pbase_m = Ptr\n",
+ "\n",
+ "#Calculations\n",
+ "Pin_m =(Pop_m * 0.746) * 1e3/ n_m\n",
+ "print(\" Input Rating of the math.single equivalent motor = %.0f kVA \" %Pin_m)\n",
+ "X11_m_new = X11_m * Pbase_m / Pin_m\n",
+ "X_2_m_new = X_2_m * Pbase_m / Pin_m\n",
+ "X_0_m_new = X_0_m * Pbase_m / Pin_m\n",
+ "X_n_m_new = 3 * X_n_m * Pbase_m / Pin_m\n",
+ "print('For Motor')\n",
+ "print(\"X11 = %.1f per unit X_2 = %.1f per unit X_0 = %0.2f per unit 3X_n = %.2f per unit\" %(X11_m_new,X_2_m_new,X_0_m_new,X_n_m_new))\n",
+ "print(\" The equivalent generator reactance from neutral to ground in the zero-sequence network = %.2f per unit\" %(3*X_0_g))\n",
+ "\n",
+ "Vf = 1 * complex(math.cos(0),math.sin(0))\n",
+ "Ibase_m = Pbase_m / (math.sqrt(3) * Vbase_m)\n",
+ "print(\" Base current in motor circuit = {0:.2f}+{1:.2f}i\".format(Ibase_m.real, Ibase_m.imag))\n",
+ "Iactual_m = 746 * Pload / (n_load * math.sqrt(3) * Vbase_m * pf_load)\n",
+ "magIa = Iactual_m / Ibase_m\n",
+ "angleIa = - math.acos(0.85)\n",
+ "Ia_prefault = magIa * complex(math.cos(angleIa),math.sin(angleIa))\n",
+ "print(\" Prefault current through line a = %.3f - j%.3f per unit\" %((Ia_prefault.real),abs(Ia_prefault.imag)))\n",
+ "Eg_11 = 1\n",
+ "Em_11 = 1\n",
+ "Z1 = ((complex(X11_g) + complex(X_2_g)) * (complex(X11_m_new))) / (complex((X11_g + X_2_g),X11_m_new))\n",
+ "Z2 = Z1Z0 = 3 * complex(X_0_g)\n",
+ "print(\" Z1 = j%.2f per unit Z2 = j%.2f per unit Z0 = j%.2f per unit\" %(abs(Z1.real),abs(Z2.real),abs(Z0.real)))\n",
+ "Ia1 = Vf / (Z1 + Z2 + Z0)\n",
+ "Ia2 = Ia1Ia0 = Ia1\n",
+ "Ia_fault = 3 * Ia0\n",
+ "print(\" Current Ia in fault = -j%.3f per unit \" %abs(Ia_fault.real))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Input Rating of the math.single equivalent motor = 5001117 kVA \n",
+ "For Motor\n",
+ "X11 = 0.3 per unit X_2 = 0.3 per unit X_0 = 0.06 per unit 3X_n = 0.09 per unit\n",
+ " The equivalent generator reactance from neutral to ground in the zero-sequence network = 0.15 per unit\n",
+ " Base current in motor circuit = 7216.88+0.00i\n",
+ " Prefault current through line a = 0.565 - j0.350 per unit\n",
+ " Z1 = j0.09 per unit Z2 = j0.15 per unit Z0 = j0.10 per unit\n",
+ " Current Ia in fault = -j0.000 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.5, Page No 329"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V_bus1 = 4.16e3\n",
+ "V_bus_2 = 600\n",
+ "Vm = 600\n",
+ "n_m = 0.895\n",
+ "Pop_m = 6000\n",
+ "X11_m = complex(0.2)\n",
+ "X_2_m = complex(0.20)\n",
+ "X_0_m = complex(0.04)\n",
+ "X_n_m= complex(0.02)\n",
+ "Vtr_ht = math.sqrt(3) * 2400\n",
+ "Vtr_lt = 600\n",
+ "Ptr =3 * 2500e3\n",
+ "X11_tr = complex(0.10)\n",
+ "Pg = 7500e3\n",
+ "Vg = 4.16e3\n",
+ "X11_g = complex(0.10)\n",
+ "X_2_g = complex(0.10)\n",
+ "X_0_g = complex(0.05)\n",
+ "X_n_g = complex(0.05)\n",
+ "#At the time of fault\n",
+ "Pload = 5000\n",
+ "pf_load = 0.85\n",
+ "n_load = 0.88\n",
+ "Vbase_sysbus = Vg\n",
+ "Pbase_sysbus = Pg\n",
+ "Vbase_m = Vtr_lt\n",
+ "Pbase_m = Ptr\n",
+ "Pin_m =(Pop_m * 0.746) * 1e3/ n_m\n",
+ "X11_m_new = X11_m * Pbase_m / Pin_m\n",
+ "X_2_m_new = X_2_m * Pbase_m / Pin_m\n",
+ "X_0_m_new = X_0_m * Pbase_m / Pin_m\n",
+ "X_n_m_new = 3 * X_n_m * Pbase_m / Pin_m\n",
+ "X_n_g_new = 3 * X_n_g\n",
+ "Y1 =[[0,0],[0,0]]\n",
+ "Y2 =[[0,0],[0,0]]\n",
+ "Y0 =[[0,0],[0,0]]\n",
+ "Y1[0][0] = 1.0/X11_g + 1/X11_m_new\n",
+ "Y2[0][0] = Y1[0][0]\n",
+ "Y1[0][1] = - 1 / X11_g\n",
+ "Y2[0][1] = Y1[0][1]\n",
+ "Y1[1][1] = 1/X11_g + 1/X_2_g\n",
+ "Y2[1][1] = Y1[1][1]\n",
+ "Y1[1][0] = Y1[0][1]\n",
+ "Y2[1][0] = Y2[0][1]\n",
+ "Y0[0][0] = 1.0/ X_n_g_new\n",
+ "Y0[1][1] = 1.0/X11_m + 1/X_2_g\n",
+ "print('Y_bus1 = Y_bus2 = ')\n",
+ "print(Y2)\n",
+ "print('Y_bus0 = ')\n",
+ "print(Y0) \n",
+ "Z0 =[[complex(0.15),0],[0,complex(0,0.0666667)]]\n",
+ "Z2 =[[complex(0.1199893),complex(0.0599946)],[complex(0.0599946),complex(0.0799973)]]\n",
+ "Z1 =[[complex(0.1199893),complex(0.0599946)],[complex(0.0599946),complex(0.0799973) ]]\n",
+ "print('Z_bus1 = Z_bus2 = ')\n",
+ "print(Z1)\n",
+ "print('Z_bus0 = ')\n",
+ "print(Z0)\n",
+ "Vf = 1 * complex(math.cos(0),math.sin(0))\n",
+ "If_bus1 = 3 * Vf / (Z1[0][0] + Z2[0][0] + Z0[0][0])\n",
+ "print('The current in fault on bus 1 in per unit is')\n",
+ "print(If_bus1)\n",
+ "If_bus2 = 3 * Vf / (Z1[1][1] + Z2[1][1] + Z0[1][1])\n",
+ "print('The current in fault on bus 2 in per unit is')\n",
+ "print(If_bus2)\n",
+ "Ia_1 =If_bus1 / 3\n",
+ "Ia_2 = Ia_1\n",
+ "Ia_0 = Ia_1\n",
+ "Va1 = Vf - (Z1[1][0] * Ia_1)\n",
+ "Va2 = - Ia_2 * Z2[1][0]\n",
+ "Va0 = - Ia_0 * Z0[1][0]\n",
+ "print('Sequence components of phase A in the order Va1,Va2,Va0 in per unit are')\n",
+ "print(Va1)\n",
+ "print(Va2)\n",
+ "print(Va0)\n",
+ "VA1 = -complex(Va1)\n",
+ "VA2 = complex(Va2)\n",
+ "VA = VA1 + VA2\n",
+ "a = 1 * complex(math.cos(120 * math.pi / 180),math.sin(120 * math.pi / 180))\n",
+ "VB = a**2 * VA1 + a * VA2\n",
+ "VC = a * VA1 + a**2 * VA2\n",
+ "print('Currents in phases in the order VA,VB,VC in per unit are')\n",
+ "print(VA)\n",
+ "print(VB)\n",
+ "print(VC)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Y_bus1 = Y_bus2 = \n",
+ "[[(13.334078212290503+0j), (-10+0j)], [(-10+0j), (20+0j)]]\n",
+ "Y_bus0 = \n",
+ "[[(6.666666666666666+0j), 0], [0, (15+0j)]]\n",
+ "Z_bus1 = Z_bus2 = \n",
+ "[[(0.1199893+0j), (0.0599946+0j)], [(0.0599946+0j), (0.0799973+0j)]]\n",
+ "Z_bus0 = \n",
+ "[[(0.15+0j), 0], [0, 0.0666667j]]\n",
+ "The current in fault on bus 1 in per unit is\n",
+ "(7.6927298062+0j)\n",
+ "The current in fault on bus 2 in per unit is\n",
+ "(15.9767086779-6.65718995778j)\n",
+ "Sequence components of phase A in the order Va1,Va2,Va0 in per unit are\n",
+ "(0.84615925079+0j)\n",
+ "(-0.15384074921-0j)\n",
+ "-0j\n",
+ "Currents in phases in the order VA,VB,VC in per unit are\n",
+ "(-1-0j)\n",
+ "(0.5+0.599565409878j)\n",
+ "(0.5-0.599565409878j)\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo12_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo12_1.ipynb
new file mode 100755
index 00000000..24e7be7d
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo12_1.ipynb
@@ -0,0 +1,592 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12 : Unsymmetrical Faults"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.1, Page No 308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P = 20e6\n",
+ "V = 13.8e3\n",
+ "P_b = 20e6\n",
+ "V_b = 13.8e3\n",
+ "Z1 = complex(0.25)\n",
+ "Z2 = complex(0.35)\n",
+ "Z0 = complex(0.10)\n",
+ "a = 1 * complex(math.cos(120*math.pi / 180),math.sin(120 * math.pi / 180))\n",
+ "\n",
+ "#Calculations\n",
+ "Ea = V / V_b\n",
+ "Ia1 = Ea / (Z0 + Z1 + Z2)\n",
+ "Ia2 = Ia1\n",
+ "Ia0 = Ia1\n",
+ "Ia = 3 * Ia1\n",
+ "I_b = P / (math.sqrt(3) * V)\n",
+ "Ia_1 = Ia * I_b\n",
+ "print(\" Base Current = %f A\" %I_b)\n",
+ "print(\" Subtransient current in line a = -j%.0f A \" %abs(Ia_1.imag))\n",
+ "#Symmetrical Components of voltage from point a to ground\n",
+ "Va1 = Ea - Ia1 * Z1\n",
+ "Va2 = -Ia2 * Z2\n",
+ "Va0 = -Ia0 * Z0\n",
+ "print('Symmetrical Components of voltage from point a to ground')\n",
+ "print( \"Va1= {0:.5f}+{1:.5f}i per unit\".format(Va1.real, Va1.imag))\n",
+ "print( \"Va2= {0:.5f}+{1:.5f}i per unit\".format(Va2.real, Va2.imag))\n",
+ "print( \"Va0= {0:.5f}+{1:.5f}i per unit\".format(Va0.real, Va0.imag))\n",
+ "\n",
+ "#Line to ground voltages\n",
+ "Va = Va0 + Va1 + Va2\n",
+ "Vb = Va0 + Va1 * a**2 + Va2 * a\n",
+ "Vc = Va0 + Va2 * a**2 + Va1 * a\n",
+ "\n",
+ "#Results\n",
+ "print('Line to ground voltages')\n",
+ "print( \"Va = {0:.2f}\".format(abs(Va.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Va.imag,Va.real))))\n",
+ "print( \"Vb = {0:.2f}\".format(abs(Vb.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vb.imag,Vb.real))))\n",
+ "print( \"Vc = {0:.2f}\".format(abs(Vc.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vc.imag,Vc.real))))\n",
+ "\n",
+ "#Line to line voltages in per-unit are\n",
+ "Vab = Va - Vb\n",
+ "Vbc = Vb - Vc\n",
+ "Vca = Vc - Va\n",
+ "print('Line to line voltages in per-unit are')\n",
+ "print( \"Vab = {0:.2f}\".format(abs(Vab.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vab.imag,Vab.real))))\n",
+ "print( \"Vbc = {0:.2f}\".format(abs(Vbc.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vbc.imag,Vbc.real))))\n",
+ "print( \"Vca = {0:.2f}\".format(abs(Vca.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vca.imag,Vca.real))))\n",
+ "#Line to line voltages in volts\n",
+ "Vab_1 = Vab * V / math.sqrt(3)\n",
+ "Vbc_1 = Vbc * V / math.sqrt(3)\n",
+ "Vca_1 = Vca * V / math.sqrt(3)\n",
+ "print('Line to line voltages in volts')\n",
+ "print( \"Vab = {0:.2f}\".format(abs(Vab_1.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vab_1.imag,Vab_1.real))))\n",
+ "print( \"Vbc = {0:.2f}\".format(abs(Vbc_1.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vbc_1.imag,Vbc_1.real))))\n",
+ "print( \"Vca = {0:.2f}\".format(abs(Vca_1.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vca_1.imag,Vca_1.real))))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Base Current = 836.739521 A\n",
+ " Subtransient current in line a = -j0 A \n",
+ "Symmetrical Components of voltage from point a to ground\n",
+ "Va1= 0.64286+0.00000i per unit\n",
+ "Va2= -0.50000+-0.00000i per unit\n",
+ "Va0= -0.14286+-0.00000i per unit\n",
+ "Line to ground voltages\n",
+ "Va = 0.00\n",
+ "Angle = 180.00 per unit \n",
+ "Vb = 0.21\n",
+ "Angle = -102.22 per unit \n",
+ "Vc = 0.21\n",
+ "Angle = 102.22 per unit \n",
+ "Line to line voltages in per-unit are\n",
+ "Vab = 0.21\n",
+ "Angle = 77.78 per unit \n",
+ "Vbc = 0.00\n",
+ "Angle = -90.00 per unit \n",
+ "Vca = 0.21\n",
+ "Angle = 102.22 per unit \n",
+ "Line to line voltages in volts\n",
+ "Vab = 1707.31\n",
+ "Angle = 77.78 per unit \n",
+ "Vbc = 0.00\n",
+ "Angle = -90.00 per unit \n",
+ "Vca = 1707.31\n",
+ "Angle = 102.22 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.2, Page No 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P = 20e6\n",
+ "V = 13.8e3\n",
+ "P_b = 20e6\n",
+ "V_b = 13.8e3\n",
+ "Z1 = complex(0.25)\n",
+ "Z2 = complex(0.35)\n",
+ "Z0 = complex(0.10)\n",
+ "a = 1 * complex(math.cos(120 * math.pi / 180),math.sin(120 * math.pi / 180))\n",
+ "#Calculations\n",
+ "Ea = V / V_b\n",
+ "Ia1 = Ea / (Z1 + Z2)\n",
+ "Ia2 = - Ia1\n",
+ "Ia0 = 0\n",
+ "Ia = Ia1 + Ia2 + Ia0\n",
+ "Ib = a**2 * Ia1 + a*Ia2 + Ia0\n",
+ "Ic = -Ib\n",
+ "I_b = P / (math.sqrt(3) * V)\n",
+ "print( \"Base Current = {0:.2f}+{1:.2f}i A\".format(I_b.real, I_b.imag))\n",
+ "Ia_1 = Ia * I_b\n",
+ "Ib_1 = Ib * I_b\n",
+ "Ic_1 = Ic * I_b\n",
+ "print(\" Subtransient current in line a = {0:.2f}+{1:.2f}i A\".format(Ia_1.real, Ia_1.imag))\n",
+ "print( \"Subtransient current in line b = {0:.2f}\".format(abs(Ib_1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(Ib_1.imag,Ib_1.real))))\n",
+ "print( \"Subtransient current in line c = = {0:.2f}\".format(abs(Ic_1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(Ic_1.imag,Ic_1.real))))\n",
+ "\n",
+ "##Symmetrical Components of voltage from point a to ground\n",
+ "Va1 = Ea - Ia1 * Z1\n",
+ "Va2 = Va1\n",
+ "Va0 = 0\n",
+ "print('Symmetrical Components of voltage from point a to ground')\n",
+ "print( \"Va1= {0:.5f}+{1:.5f}i per unit\".format(Va1.real, Va1.imag))\n",
+ "print( \"Va2= {0:.5f}+{1:.5f}i per unit\".format(Va2.real, Va2.imag))\n",
+ "print( \"Va0= {0:.5f}+{1:.5f}i per unit\".format(Va0.real, Va0.imag))\n",
+ "\n",
+ "#Line to ground voltages\n",
+ "Va = Va0 + Va1 + Va2\n",
+ "Vb = Va0 + Va1 * a**2 + Va2 * a\n",
+ "Vc = Vb\n",
+ "print('Line to ground voltages')\n",
+ "print( \"Va = {0:.2f}\".format(abs(Va.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Va.imag,Va.real))))\n",
+ "print( \"Vb= {0:.5f}+{1:.5f}i per unit\".format(Vb.real, Vb.imag))\n",
+ "\n",
+ "#Line to line voltages in per-unit are\n",
+ "Vab = Va - Vb\n",
+ "Vbc = Vb - Vc\n",
+ "Vca = Vc - Va\n",
+ "\n",
+ "#Results\n",
+ "print('Line to line voltages in per-unit are')\n",
+ "print( \"Vab = {0:.2f}\".format(abs(Vab.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vab.imag,Vab.real))))\n",
+ "print( \"Vbc= {0:.5f}+{1:.5f}i per unit\".format(Vbc.real, Vbc.imag))\n",
+ "print( \"Vca = {0:.2f}\".format(abs(Vca.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vca.imag,Vca.real))))\n",
+ "\n",
+ "#Line to line voltages in volts\n",
+ "Vab_1 = Vab * V / math.sqrt(3)\n",
+ "Vbc_1 = Vbc * V / math.sqrt(3)\n",
+ "Vca_1 = Vca * V / math.sqrt(3)\n",
+ "print('Line to line voltages in volts')\n",
+ "print( \"Vab = {0:.2f}\".format(abs(Vab_1.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vab_1.imag,Vab_1.real))))\n",
+ "print( \"Vbc= {0:.5f}+{1:.5f}i per unit\".format(Vbc_1.real, Vbc_1.imag))\n",
+ "print( \"Vca = {0:.2f}\".format(abs(Vca_1.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vca_1.imag,Vca_1.real))))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base Current = 836.74+0.00i A\n",
+ " Subtransient current in line a = 0.00+0.00i A\n",
+ "Subtransient current in line b = 0.00\n",
+ "Angle = -90.00 A \n",
+ "Subtransient current in line c = = 0.00\n",
+ "Angle = 90.00 A \n",
+ "Symmetrical Components of voltage from point a to ground\n",
+ "Va1= 0.58333+0.00000i per unit\n",
+ "Va2= 0.58333+0.00000i per unit\n",
+ "Va0= 0.00000+0.00000i per unit\n",
+ "Line to ground voltages\n",
+ "Va = 1.17\n",
+ "Angle = 0.00 per unit \n",
+ "Vb= -0.58333+0.00000i per unit\n",
+ "Line to line voltages in per-unit are\n",
+ "Vab = 1.75\n",
+ "Angle = -0.00 per unit \n",
+ "Vbc= 0.00000+0.00000i per unit\n",
+ "Vca = 1.75\n",
+ "Angle = 180.00 per unit \n",
+ "Line to line voltages in volts\n",
+ "Vab = 13943.01\n",
+ "Angle = -0.00 per unit \n",
+ "Vbc= 0.00000+0.00000i per unit\n",
+ "Vca = 13943.01\n",
+ "Angle = 180.00 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.3, Page No 314"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P = 20e6\n",
+ "V = 13.8e3\n",
+ "P_b = 20e6\n",
+ "V_b = 13.8e3\n",
+ "Z1 = complex(0.25)\n",
+ "Z2 = complex(0.35)\n",
+ "Z0 = complex(0.10)\n",
+ "a = 1 * complex(math.cos(120 * math.pi / 180), math.sin(120 * math.pi/180))\n",
+ "\n",
+ "#Calculations\n",
+ "Ea = V / V_b\n",
+ "Ia1 = Ea / (Z1 + (Z2*Z0)/(Z2+Z0))\n",
+ "I_b = P / (math.sqrt(3) * V)\n",
+ "Va1 = Ea - Ia1 * Z1\n",
+ "Va2 = Va1Va0 = Va1\n",
+ "Ia2 = - Va2 / Z2\n",
+ "Ia0 = - Va0 / Z0\n",
+ "Ia = Ia1 + Ia2 + Ia0\n",
+ "Ib = a**2*Ia1 + a*Ia2 + Ia0\n",
+ "Ic = a*Ia1 + a**2*Ia2 + Ia0\n",
+ "In = 3 * Ia0\n",
+ "Va = Va1 + Va2 + Va0\n",
+ "Vb = 0\n",
+ "Vc = 0\n",
+ "print('Line to ground voltages')\n",
+ "print( \"Va = {0:.2f}\".format(abs(Va.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Va.imag,Va.real))))\n",
+ "print( \"Vb= {0:.5f}+{1:.5f}i per unit\".format(Vb.real, Vb.imag))\n",
+ "Vab = Va - Vb\n",
+ "Vbc = Vb - Vc\n",
+ "Vca = Vc - Va\n",
+ "print('Line to line voltages in per-unit are')\n",
+ "\n",
+ "print( \"Vab= {0:.2f}+{1:.2f}i per unit\".format(Vab.real, Vab.imag))\n",
+ "print( \"Vbc= {0:.2f}+{1:.2f}i per unit\".format(Vbc.real, Vbc.imag))\n",
+ "print( \"Vca= {0:.2f}+{1:.2f}i per unit\".format(Vca.real, Vca.imag))\n",
+ "I_a1 = I_b * Ia\n",
+ "I_b1 = I_b * Ib\n",
+ "I_c1 = I_b * Ic\n",
+ "I_n1 = I_b * In\n",
+ "\n",
+ "#Results\n",
+ "print( \"Base Current = {0:.2f}+{1:.2f}i per unit\".format(I_b.real, I_b.imag))\n",
+ "print(\" Subtransient current in line a = {0:.2f}+{1:.2f}i A\".format(Ia_1.real, Ia_1.imag))\n",
+ "print( \"Subtransient current in line b = {0:.2f}\".format(abs(Ib_1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(Ib_1.imag,Ib_1.real))))\n",
+ "print( \"Subtransient current in line c = = {0:.2f}\".format(abs(Ic_1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(Ic_1.imag,Ic_1.real))))\n",
+ "print( \"Subtransient current in line c = = {0:.2f}\".format(abs(Ic_1.real)))\n",
+ "print(\"Angle = %.2f A \" %(math.degrees(math.atan2(Ic_1.imag,Ic_1.real))))\n",
+ "\n",
+ "Vab_1 = Vab * V / math.sqrt(3)\n",
+ "Vbc_1 = Vbc * V / math.sqrt(3)\n",
+ "Vca_1 = Vca * V / math.sqrt(3)\n",
+ "print('Line to line voltages in volts')\n",
+ "print( \"Vab = {0:.2f}\".format(abs(Vab.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vab.imag,Vab.real))))\n",
+ "print( \"Vbc= {0:.5f}+{1:.5f}i per unit\".format(Vbc.real, Vbc.imag))\n",
+ "print( \"Vca = {0:.2f}\".format(abs(Vca.real)))\n",
+ "print(\"Angle = %.2f per unit \" %(math.degrees(math.atan2(Vca.imag,Vca.real))))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Line to ground voltages\n",
+ "Va = 0.47\n",
+ "Angle = 0.00 per unit \n",
+ "Vb= 0.00000+0.00000i per unit\n",
+ "Line to line voltages in per-unit are\n",
+ "Vab= 0.47+0.00i per unit\n",
+ "Vbc= 0.00+0.00i per unit\n",
+ "Vca= -0.47+0.00i per unit\n",
+ "Base Current = 836.74+0.00i per unit\n",
+ " Subtransient current in line a = 0.00+0.00i A\n",
+ "Subtransient current in line b = 0.00\n",
+ "Angle = -90.00 A \n",
+ "Subtransient current in line c = = 0.00\n",
+ "Angle = 90.00 A \n",
+ "Subtransient current in line c = = 0.00\n",
+ "Angle = 90.00 A \n",
+ "Line to line voltages in volts\n",
+ "Vab = 0.47\n",
+ "Angle = 0.00 per unit \n",
+ "Vbc= 0.00000+0.00000i per unit\n",
+ "Vca = 0.47\n",
+ "Angle = 180.00 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.4 Page No 321"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V_bus1 = 4.16e3\n",
+ "V_bus_2 = 600\n",
+ "Vm = 600\n",
+ "n_m = 0.895\n",
+ "Pop_m = 6000\n",
+ "X11_m = 0.2\n",
+ "X_2_m = 0.20\n",
+ "X_0_m = 0.04\n",
+ "X_n_m= 0.02\n",
+ "Vtr_ht = math.sqrt(3) * 2400\n",
+ "Vtr_lt = 600\n",
+ "Ptr =3 * 2500e3\n",
+ "X11_tr = 0.10\n",
+ "Pg = 7500e3\n",
+ "Vg = 4.16e3\n",
+ "X11_g = 0.10\n",
+ "X_2_g = 0.10\n",
+ "X_0_g = 0.05\n",
+ "X_n_g = 0.05\n",
+ "#At the time of fault\n",
+ "Pload = 5000\n",
+ "pf_load = 0.85\n",
+ "n_load = 0.88\n",
+ "Vbase_sysbus = Vg\n",
+ "Pbase_sysbus = Pg\n",
+ "Vbase_m = Vtr_lt\n",
+ "Pbase_m = Ptr\n",
+ "\n",
+ "#Calculations\n",
+ "Pin_m =(Pop_m * 0.746) * 1e3/ n_m\n",
+ "print(\" Input Rating of the math.single equivalent motor = %.0f kVA \" %Pin_m)\n",
+ "X11_m_new = X11_m * Pbase_m / Pin_m\n",
+ "X_2_m_new = X_2_m * Pbase_m / Pin_m\n",
+ "X_0_m_new = X_0_m * Pbase_m / Pin_m\n",
+ "X_n_m_new = 3 * X_n_m * Pbase_m / Pin_m\n",
+ "print('For Motor')\n",
+ "print(\"X11 = %.1f per unit X_2 = %.1f per unit X_0 = %0.2f per unit 3X_n = %.2f per unit\" %(X11_m_new,X_2_m_new,X_0_m_new,X_n_m_new))\n",
+ "print(\" The equivalent generator reactance from neutral to ground in the zero-sequence network = %.2f per unit\" %(3*X_0_g))\n",
+ "\n",
+ "Vf = 1 * complex(math.cos(0),math.sin(0))\n",
+ "Ibase_m = Pbase_m / (math.sqrt(3) * Vbase_m)\n",
+ "print(\" Base current in motor circuit = {0:.2f}+{1:.2f}i\".format(Ibase_m.real, Ibase_m.imag))\n",
+ "Iactual_m = 746 * Pload / (n_load * math.sqrt(3) * Vbase_m * pf_load)\n",
+ "magIa = Iactual_m / Ibase_m\n",
+ "angleIa = - math.acos(0.85)\n",
+ "Ia_prefault = magIa * complex(math.cos(angleIa),math.sin(angleIa))\n",
+ "print(\" Prefault current through line a = %.3f - j%.3f per unit\" %((Ia_prefault.real),abs(Ia_prefault.imag)))\n",
+ "Eg_11 = 1\n",
+ "Em_11 = 1\n",
+ "Z1 = ((complex(X11_g) + complex(X_2_g)) * (complex(X11_m_new))) / (complex((X11_g + X_2_g),X11_m_new))\n",
+ "Z2 = Z1Z0 = 3 * complex(X_0_g)\n",
+ "print(\" Z1 = j%.2f per unit Z2 = j%.2f per unit Z0 = j%.2f per unit\" %(abs(Z1.real),abs(Z2.real),abs(Z0.real)))\n",
+ "Ia1 = Vf / (Z1 + Z2 + Z0)\n",
+ "Ia2 = Ia1Ia0 = Ia1\n",
+ "Ia_fault = 3 * Ia0\n",
+ "print(\" Current Ia in fault = -j%.3f per unit \" %abs(Ia_fault.real))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Input Rating of the math.single equivalent motor = 5001117 kVA \n",
+ "For Motor\n",
+ "X11 = 0.3 per unit X_2 = 0.3 per unit X_0 = 0.06 per unit 3X_n = 0.09 per unit\n",
+ " The equivalent generator reactance from neutral to ground in the zero-sequence network = 0.15 per unit\n",
+ " Base current in motor circuit = 7216.88+0.00i\n",
+ " Prefault current through line a = 0.565 - j0.350 per unit\n",
+ " Z1 = j0.09 per unit Z2 = j0.15 per unit Z0 = j0.10 per unit\n",
+ " Current Ia in fault = -j0.000 per unit \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.5, Page No 329"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V_bus1 = 4.16e3\n",
+ "V_bus_2 = 600\n",
+ "Vm = 600\n",
+ "n_m = 0.895\n",
+ "Pop_m = 6000\n",
+ "X11_m = complex(0.2)\n",
+ "X_2_m = complex(0.20)\n",
+ "X_0_m = complex(0.04)\n",
+ "X_n_m= complex(0.02)\n",
+ "Vtr_ht = math.sqrt(3) * 2400\n",
+ "Vtr_lt = 600\n",
+ "Ptr =3 * 2500e3\n",
+ "X11_tr = complex(0.10)\n",
+ "Pg = 7500e3\n",
+ "Vg = 4.16e3\n",
+ "X11_g = complex(0.10)\n",
+ "X_2_g = complex(0.10)\n",
+ "X_0_g = complex(0.05)\n",
+ "X_n_g = complex(0.05)\n",
+ "#At the time of fault\n",
+ "Pload = 5000\n",
+ "pf_load = 0.85\n",
+ "n_load = 0.88\n",
+ "Vbase_sysbus = Vg\n",
+ "Pbase_sysbus = Pg\n",
+ "Vbase_m = Vtr_lt\n",
+ "Pbase_m = Ptr\n",
+ "Pin_m =(Pop_m * 0.746) * 1e3/ n_m\n",
+ "X11_m_new = X11_m * Pbase_m / Pin_m\n",
+ "X_2_m_new = X_2_m * Pbase_m / Pin_m\n",
+ "X_0_m_new = X_0_m * Pbase_m / Pin_m\n",
+ "X_n_m_new = 3 * X_n_m * Pbase_m / Pin_m\n",
+ "X_n_g_new = 3 * X_n_g\n",
+ "Y1 =[[0,0],[0,0]]\n",
+ "Y2 =[[0,0],[0,0]]\n",
+ "Y0 =[[0,0],[0,0]]\n",
+ "Y1[0][0] = 1.0/X11_g + 1/X11_m_new\n",
+ "Y2[0][0] = Y1[0][0]\n",
+ "Y1[0][1] = - 1 / X11_g\n",
+ "Y2[0][1] = Y1[0][1]\n",
+ "Y1[1][1] = 1/X11_g + 1/X_2_g\n",
+ "Y2[1][1] = Y1[1][1]\n",
+ "Y1[1][0] = Y1[0][1]\n",
+ "Y2[1][0] = Y2[0][1]\n",
+ "Y0[0][0] = 1.0/ X_n_g_new\n",
+ "Y0[1][1] = 1.0/X11_m + 1/X_2_g\n",
+ "print('Y_bus1 = Y_bus2 = ')\n",
+ "print(Y2)\n",
+ "print('Y_bus0 = ')\n",
+ "print(Y0) \n",
+ "Z0 =[[complex(0.15),0],[0,complex(0,0.0666667)]]\n",
+ "Z2 =[[complex(0.1199893),complex(0.0599946)],[complex(0.0599946),complex(0.0799973)]]\n",
+ "Z1 =[[complex(0.1199893),complex(0.0599946)],[complex(0.0599946),complex(0.0799973) ]]\n",
+ "print('Z_bus1 = Z_bus2 = ')\n",
+ "print(Z1)\n",
+ "print('Z_bus0 = ')\n",
+ "print(Z0)\n",
+ "Vf = 1 * complex(math.cos(0),math.sin(0))\n",
+ "If_bus1 = 3 * Vf / (Z1[0][0] + Z2[0][0] + Z0[0][0])\n",
+ "print('The current in fault on bus 1 in per unit is')\n",
+ "print(If_bus1)\n",
+ "If_bus2 = 3 * Vf / (Z1[1][1] + Z2[1][1] + Z0[1][1])\n",
+ "print('The current in fault on bus 2 in per unit is')\n",
+ "print(If_bus2)\n",
+ "Ia_1 =If_bus1 / 3\n",
+ "Ia_2 = Ia_1\n",
+ "Ia_0 = Ia_1\n",
+ "Va1 = Vf - (Z1[1][0] * Ia_1)\n",
+ "Va2 = - Ia_2 * Z2[1][0]\n",
+ "Va0 = - Ia_0 * Z0[1][0]\n",
+ "print('Sequence components of phase A in the order Va1,Va2,Va0 in per unit are')\n",
+ "print(Va1)\n",
+ "print(Va2)\n",
+ "print(Va0)\n",
+ "VA1 = -complex(Va1)\n",
+ "VA2 = complex(Va2)\n",
+ "VA = VA1 + VA2\n",
+ "a = 1 * complex(math.cos(120 * math.pi / 180),math.sin(120 * math.pi / 180))\n",
+ "VB = a**2 * VA1 + a * VA2\n",
+ "VC = a * VA1 + a**2 * VA2\n",
+ "print('Currents in phases in the order VA,VB,VC in per unit are')\n",
+ "print(VA)\n",
+ "print(VB)\n",
+ "print(VC)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Y_bus1 = Y_bus2 = \n",
+ "[[(13.334078212290503+0j), (-10+0j)], [(-10+0j), (20+0j)]]\n",
+ "Y_bus0 = \n",
+ "[[(6.666666666666666+0j), 0], [0, (15+0j)]]\n",
+ "Z_bus1 = Z_bus2 = \n",
+ "[[(0.1199893+0j), (0.0599946+0j)], [(0.0599946+0j), (0.0799973+0j)]]\n",
+ "Z_bus0 = \n",
+ "[[(0.15+0j), 0], [0, 0.0666667j]]\n",
+ "The current in fault on bus 1 in per unit is\n",
+ "(7.6927298062+0j)\n",
+ "The current in fault on bus 2 in per unit is\n",
+ "(15.9767086779-6.65718995778j)\n",
+ "Sequence components of phase A in the order Va1,Va2,Va0 in per unit are\n",
+ "(0.84615925079+0j)\n",
+ "(-0.15384074921-0j)\n",
+ "-0j\n",
+ "Currents in phases in the order VA,VB,VC in per unit are\n",
+ "(-1-0j)\n",
+ "(0.5+0.599565409878j)\n",
+ "(0.5-0.599565409878j)\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo13.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo13.ipynb
new file mode 100755
index 00000000..0ecd6b7a
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo13.ipynb
@@ -0,0 +1,426 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13 : System Protection"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.1, Page No 341"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Chapter 13\n",
+ "#Example 13.1\n",
+ "#Page 341\n",
+ "print('Solution to this problem can be got by theory from Section 13.2 in the textbook')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Solution to this problem can be got by theory from Section 13.2 in the textbook\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.2, Page No 355"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V = 13.8e3\n",
+ "Z_tr = complex(5)\n",
+ "Z_tr_eq = Z_tr / 2#since two reactances of equal value are in parallel\n",
+ "Z1 = complex(9.6)\n",
+ "Z2 = complex(6.4)\n",
+ "Z3 = complex(8.0)\n",
+ "Z4 = complex(12.8)\n",
+ "m = math.sqrt(3)/2\t\t\t#to obtain line-to-line fault from a three-phase fault current\n",
+ "#At bus 5\n",
+ "#Max. Current\n",
+ "\n",
+ "#Calculations\n",
+ "If_b5_max = (V/math.sqrt(3))/(Z_tr_eq + Z1 + Z2 + Z3 + Z4)\n",
+ "print(If_b5_max,'Maximum fault current at bus 5 in A')\n",
+ "#Min. Current\n",
+ "If_b5_min = (V/math.sqrt(3)) * m / (Z_tr + Z1 + Z2 + Z3 + Z4)\n",
+ "print(If_b5_min,'Minimum fault current at bus 5 in A')\n",
+ "#At bus 4\n",
+ "#Max. Current\n",
+ "If_b4_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1 + Z2 + Z3)\n",
+ "print(If_b4_max,'Maximum fault current at bus 4 in A')\n",
+ "#Min. Current\n",
+ "If_b4_min = (V/math.sqrt(3)) * m / (Z_tr + Z1 + Z2 + Z3)\n",
+ "print(If_b4_min,'Minimum fault current at bus 4 in A')\n",
+ "#At bus 3\n",
+ "#Max. Current\n",
+ "If_b3_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1 + Z2)\n",
+ "print(If_b3_max,'Maximum fault current at bus 3 in A')\n",
+ "#Min. Current\n",
+ "If_b3_min = (V/math.sqrt(3)) * m / (Z_tr + Z1 + Z2)\n",
+ "print(If_b3_min,'Minimum fault current at bus 3 in A')\n",
+ "#At bus 2\n",
+ "#Max. Current\n",
+ "If_b2_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1)\n",
+ "print(If_b2_max,'Maximum fault current at bus 2 in A')\n",
+ "#Min. Current\n",
+ "If_b2_min = (V/math.sqrt(3)) * m / (Z_tr + Z1)\n",
+ "print(If_b2_min,'Minimum fault current at bus 2 in A')\n",
+ "#At bus 2\n",
+ "#Max. Current\n",
+ "If_b1_max = (V/math.sqrt(3)) / (Z_tr_eq)\n",
+ "print(If_b1_max,'Maximum fault current at bus 1 in A')\n",
+ "#Min. Current\n",
+ "If_b1_min = (V/math.sqrt(3)) * m / (Z_tr)\n",
+ "print(If_b1_min,'Minimum fault current at bus 1 in A')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "((202.73368231086098+0j), 'Maximum fault current at bus 5 in A')\n",
+ "((165.07177033492823+0j), 'Minimum fault current at bus 5 in A')\n",
+ "((300.657876030824+0j), 'Maximum fault current at bus 4 in A')\n",
+ "((237.93103448275863+0j), 'Minimum fault current at bus 4 in A')\n",
+ "((430.6720926928019+0j), 'Maximum fault current at bus 3 in A')\n",
+ "((328.57142857142856+0j), 'Minimum fault current at bus 3 in A')\n",
+ "((658.4655962658543+0j), 'Maximum fault current at bus 2 in A')\n",
+ "((472.60273972602744+0j), 'Minimum fault current at bus 2 in A')\n",
+ "((3186.9734859267346+0j), 'Maximum fault current at bus 1 in A')\n",
+ "((1380+0j), 'Minimum fault current at bus 1 in A')\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.3, Page No 357"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "#This problem contains many assumptions and values are taken from Figure 13.7 in page 348 after intial calculations,it is done in order to select equipment of the available rated value in the market to meet the required conditions.So only the required calculations are shown and final answer after the required changes are printlayed.\n",
+ "V = 13.8e3\n",
+ "Z_tr = complex(5)\n",
+ "Z_tr_eq = Z_tr / 2\t\t#since two reactances of equal value are in parallel\n",
+ "Z1 = complex(9.6)\n",
+ "Z2 = complex(6.4)\n",
+ "Z3 = complex(8.0)\n",
+ "Z4 = complex(12.8)\n",
+ "m = math.sqrt(3) / 2\t\t#to obtain line-to-line fault from a three-phase fault current\n",
+ "If_b5_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1 + Z2 + Z3 + Z4)\n",
+ "If_b5_min = (V/math.sqrt(3)) * m / (Z_tr + Z1 + Z2 + Z3 + Z4)\n",
+ "If_b4_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1 + Z2 + Z3)\n",
+ "If_b4_min = (V/math.sqrt(3)) * m / (Z_tr + Z1 + Z2 + Z3)\n",
+ "If_b3_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1 + Z2)\n",
+ "If_b3_min = (V/math.sqrt(3)) * m / (Z_tr + Z1 + Z2)\n",
+ "If_b2_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1)\n",
+ "If_b2_min = (V/math.sqrt(3)) * m / (Z_tr + Z1)\n",
+ "If_b1_max = (V/math.sqrt(3)) / (Z_tr_eq)\n",
+ "If_b1_min = (V/math.sqrt(3)) * m / (Z_tr)\n",
+ "#Settings for relay R4\n",
+ "R4_I_1_p = If_b5_min /3\n",
+ "print('One third of minimum fault current in A')\n",
+ "print(abs(R4_I_1_p))\n",
+ "R4_I_p = R4_I_1_p * 5 /55\n",
+ "print('For CT ratio 50/5 resulting relay current in A will be')\n",
+ "print(abs(R4_I_p))\n",
+ "print('Settings for relay R4')\n",
+ "print('CT ratio = 50:5')\n",
+ "print('Pick up setting in A = 5')\n",
+ "print('Time-dial setting = 1/2')\n",
+ "#Settings for relay R3\n",
+ "R3_I_p = If_b4_max * 5 / 50\n",
+ "print('The relay current of both R3 and R4 for higest fault current seen by R4')\n",
+ "print(abs(R3_I_p))\n",
+ "R4_t_op = 0.135\n",
+ "print('Operating time for R4 with time dial setting 1/2 in sec is')\n",
+ "print(R4_t_op)\n",
+ "t=0.3\n",
+ "R3_t_op = R4_t_op + t\n",
+ "print('Required operating time of relay R3')\n",
+ "print(R3_t_op)\n",
+ "print('Settings for relay R3')\n",
+ "print('CT ratio = 50:5')\n",
+ "print('Pick up setting in A = 5')\n",
+ "print('Time-dial setting = 2')\n",
+ "#Settings for relay R2\n",
+ "R2_I_p = (1.0/3) * If_b4_min * (5.0/100)\n",
+ "print('Pickup setting in A')\n",
+ "print(abs(R2_I_p))\n",
+ "R3_I_1_p = If_b3_max * (5.0/50) * (1.0/5)\n",
+ "print('Reatio of relay current to picup setting in A for max fault current through R3')\n",
+ "print(abs(R3_I_1_p))\n",
+ "R3_t_op = 0.31\n",
+ "R2_t_op = R3_t_op + t\n",
+ "print('Operating time of R2 in sec')\n",
+ "print(R2_t_op)\n",
+ "R2_I_1_p = If_b3_max * (5.0/100) * (1.0/4)\n",
+ "print('For backing up R3 the ratio of relay current to pickup setting of R2 in A')\n",
+ "print(abs(R2_I_1_p))\n",
+ "print('Settings for relay R2')\n",
+ "print('CT ratio = 100:5')\n",
+ "print('Pick up setting in A = 4')\n",
+ "print('Time-dial setting = 2.6')\n",
+ "#Settings for relay R1\n",
+ "R1_I_p = If_b3_min * (1.0/3) * (5.0/100)\n",
+ "#taking tap as 5.0\n",
+ "R2_1_I_1_op = If_b2_max * (5.0/50) * (1.0/5)\n",
+ "#Operating time will come to 0.33s\n",
+ "R1_t_op = 0.33+t\n",
+ "R1_1_I_1_op = If_b2_max * (5.0/100) * (1.0/5)\n",
+ "\n",
+ "#Results\n",
+ "print('Settings for relay R1')\n",
+ "print('CT ratio = 100:5')\n",
+ "print('Pick up setting in A = 5')\n",
+ "print('Time-dial setting = 2.9')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "One third of minimum fault current in A\n",
+ "55.023923445\n",
+ "For CT ratio 50/5 resulting relay current in A will be\n",
+ "5.00217485863\n",
+ "Settings for relay R4\n",
+ "CT ratio = 50:5\n",
+ "Pick up setting in A = 5\n",
+ "Time-dial setting = 1/2\n",
+ "The relay current of both R3 and R4 for higest fault current seen by R4\n",
+ "30.0657876031\n",
+ "Operating time for R4 with time dial setting 1/2 in sec is\n",
+ "0.135\n",
+ "Required operating time of relay R3\n",
+ "0.435\n",
+ "Settings for relay R3\n",
+ "CT ratio = 50:5\n",
+ "Pick up setting in A = 5\n",
+ "Time-dial setting = 2\n",
+ "Pickup setting in A\n",
+ "3.96551724138\n",
+ "Reatio of relay current to picup setting in A for max fault current through R3\n",
+ "8.61344185386\n",
+ "Operating time of R2 in sec\n",
+ "0.61\n",
+ "For backing up R3 the ratio of relay current to pickup setting of R2 in A\n",
+ "5.38340115866\n",
+ "Settings for relay R2\n",
+ "CT ratio = 100:5\n",
+ "Pick up setting in A = 4\n",
+ "Time-dial setting = 2.6\n",
+ "Settings for relay R1\n",
+ "CT ratio = 100:5\n",
+ "Pick up setting in A = 5\n",
+ "Time-dial setting = 2.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.4 Page No 363"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "l_12 = 64\n",
+ "l_23 = 64\n",
+ "l_24 = 96\t\t#in km\n",
+ "l_12m = 40\n",
+ "l_23m = 40\n",
+ "l_24m = 60\n",
+ "z = complex(0.05 ,0.5)\n",
+ "Pmax = 50e6\n",
+ "V = 138e3\n",
+ "pf = 0.8\n",
+ "cvt = 67\n",
+ "\n",
+ "#Calculations\n",
+ "Z_12 = z * l_12\n",
+ "Z_23 = z * l_23\n",
+ "Z_24 = z * l_24\n",
+ "print('The positive sequnce impedances of the three line in ohms in the order line 1-2,line 2-3,line 2-4 are')\n",
+ "print(Z_12)\n",
+ "print(Z_23)\n",
+ "print(Z_24)\n",
+ "Il_max = Pmax / (math.sqrt(3) * V)\n",
+ "print('Maximum load current in A')\n",
+ "print(Il_max)\n",
+ "Vn = V/ math.sqrt(3)\n",
+ "print('System Voltage to neutral')\n",
+ "print(Vn)\n",
+ "ratio_cvt = Vn / cvt\n",
+ "print('cvt ratio = 1089.1/1')\n",
+ "b1_factor = l_12m / ratio_cvt\n",
+ "Z_r12 = Z_12 * b1_factor\n",
+ "Z_r23 = Z_23 * b1_factor\n",
+ "Z_r24 = Z_24 * b1_factor\n",
+ "print('The impedance of the lines as seen by R12 in ohms in the order line 1-2,line 2-3,line 2-4 are')\n",
+ "print(Z_r12)\n",
+ "print(Z_r23)\n",
+ "print(Z_r24)\n",
+ "Zload = (cvt * complex(pf,math.sqrt(1-pf**2))) / (Il_max * (5.0/200))\n",
+ "print('Impedance of load current')\n",
+ "print(Zload)\n",
+ "zone1 = 0.8 * Z_r12\n",
+ "print('Setting of zone one on secondary in ohms')\n",
+ "print(zone1)\n",
+ "zone2 = 1.2 * Z_r23\n",
+ "print('Setting of zone two on secondary in ohms')\n",
+ "print(zone2)\n",
+ "zone3 = Z_r23 + 1.2 * Z_r24\n",
+ "print('Setting of zone three on secondary in ohms')\n",
+ "print(zone3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The positive sequnce impedances of the three line in ohms in the order line 1-2,line 2-3,line 2-4 are\n",
+ "(3.2+32j)\n",
+ "(3.2+32j)\n",
+ "(4.8+48j)\n",
+ "Maximum load current in A\n",
+ "209.184880141\n",
+ "System Voltage to neutral\n",
+ "79674.3371482\n",
+ "cvt ratio = 1089.1/1\n",
+ "The impedance of the lines as seen by R12 in ohms in the order line 1-2,line 2-3,line 2-4 are\n",
+ "(0.107638171925+1.07638171925j)\n",
+ "(0.107638171925+1.07638171925j)\n",
+ "(0.161457257888+1.61457257888j)\n",
+ "Impedance of load current\n",
+ "(10.2493067307+7.68698004806j)\n",
+ "Setting of zone one on secondary in ohms\n",
+ "(0.0861105375404+0.861105375404j)\n",
+ "Setting of zone two on secondary in ohms\n",
+ "(0.129165806311+1.29165806311j)\n",
+ "Setting of zone three on secondary in ohms\n",
+ "(0.301386881391+3.01386881391j)\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.5, Page No 368"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V_ht = 345e3\n",
+ "V_lt = 34.5e3\n",
+ "P = 50e6\n",
+ "P_short_term = 60e6\n",
+ "\n",
+ "#Calculations\n",
+ "I_ht = P_short_term / (math.sqrt(3) * V_ht)\n",
+ "I_lt = P_short_term / (math.sqrt(3) * V_lt)\n",
+ "print('Under maximum load the currents on 345-kV and 34.5-kV side of the transformer respectively in A = %.2f %.2f' %(I_ht,I_lt))\n",
+ "#CT ratio on the 34.5kV side 1000/5\n",
+ "I_r_lt = I_lt * 5 / 1000\n",
+ "print('Current flowing through the differential relay from 34.5-kV side = %.2f' %I_r_lt)\n",
+ "I_balance = 5.0\n",
+ "I_lt_sec_ct = I_balance / math.sqrt(3)\n",
+ "print('To balance the above current each of the secondary windings of the delta connected CTs should have a current(in A) of = %.2f' %I_lt_sec_ct)\n",
+ "ct_sec = I_ht / I_lt_sec_ct\n",
+ "print('CT ratios in secondary for the above currents = %.2f' %ct_sec)\n",
+ "I_ht_sec_ct = I_ht * 5 / 200\n",
+ "\n",
+ "#Results\n",
+ "print('CT secondary currents for ratio 200/5 on the secondary side of 345-kV will be = %.2f' %I_ht_sec_ct)\n",
+ "I_line_ctr = I_ht_sec_ct * math.sqrt(3)\n",
+ "print('Line currents from CTs to differential relays = %.2f' %I_line_ctr)\n",
+ "turns_ratio = I_r_lt / I_line_ctr\n",
+ "print('Required turns ratio for the three auxillary CTs uses is = %.2f' %turns_ratio)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Under maximum load the currents on 345-kV and 34.5-kV side of the transformer respectively in A = 100.41 1004.09\n",
+ "Current flowing through the differential relay from 34.5-kV side = 5.02\n",
+ "To balance the above current each of the secondary windings of the delta connected CTs should have a current(in A) of = 2.89\n",
+ "CT ratios in secondary for the above currents = 34.78\n",
+ "CT secondary currents for ratio 200/5 on the secondary side of 345-kV will be = 2.51\n",
+ "Line currents from CTs to differential relays = 4.35\n",
+ "Required turns ratio for the three auxillary CTs uses is = 1.15\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo13_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo13_1.ipynb
new file mode 100755
index 00000000..0ecd6b7a
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo13_1.ipynb
@@ -0,0 +1,426 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13 : System Protection"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.1, Page No 341"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Chapter 13\n",
+ "#Example 13.1\n",
+ "#Page 341\n",
+ "print('Solution to this problem can be got by theory from Section 13.2 in the textbook')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Solution to this problem can be got by theory from Section 13.2 in the textbook\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.2, Page No 355"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V = 13.8e3\n",
+ "Z_tr = complex(5)\n",
+ "Z_tr_eq = Z_tr / 2#since two reactances of equal value are in parallel\n",
+ "Z1 = complex(9.6)\n",
+ "Z2 = complex(6.4)\n",
+ "Z3 = complex(8.0)\n",
+ "Z4 = complex(12.8)\n",
+ "m = math.sqrt(3)/2\t\t\t#to obtain line-to-line fault from a three-phase fault current\n",
+ "#At bus 5\n",
+ "#Max. Current\n",
+ "\n",
+ "#Calculations\n",
+ "If_b5_max = (V/math.sqrt(3))/(Z_tr_eq + Z1 + Z2 + Z3 + Z4)\n",
+ "print(If_b5_max,'Maximum fault current at bus 5 in A')\n",
+ "#Min. Current\n",
+ "If_b5_min = (V/math.sqrt(3)) * m / (Z_tr + Z1 + Z2 + Z3 + Z4)\n",
+ "print(If_b5_min,'Minimum fault current at bus 5 in A')\n",
+ "#At bus 4\n",
+ "#Max. Current\n",
+ "If_b4_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1 + Z2 + Z3)\n",
+ "print(If_b4_max,'Maximum fault current at bus 4 in A')\n",
+ "#Min. Current\n",
+ "If_b4_min = (V/math.sqrt(3)) * m / (Z_tr + Z1 + Z2 + Z3)\n",
+ "print(If_b4_min,'Minimum fault current at bus 4 in A')\n",
+ "#At bus 3\n",
+ "#Max. Current\n",
+ "If_b3_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1 + Z2)\n",
+ "print(If_b3_max,'Maximum fault current at bus 3 in A')\n",
+ "#Min. Current\n",
+ "If_b3_min = (V/math.sqrt(3)) * m / (Z_tr + Z1 + Z2)\n",
+ "print(If_b3_min,'Minimum fault current at bus 3 in A')\n",
+ "#At bus 2\n",
+ "#Max. Current\n",
+ "If_b2_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1)\n",
+ "print(If_b2_max,'Maximum fault current at bus 2 in A')\n",
+ "#Min. Current\n",
+ "If_b2_min = (V/math.sqrt(3)) * m / (Z_tr + Z1)\n",
+ "print(If_b2_min,'Minimum fault current at bus 2 in A')\n",
+ "#At bus 2\n",
+ "#Max. Current\n",
+ "If_b1_max = (V/math.sqrt(3)) / (Z_tr_eq)\n",
+ "print(If_b1_max,'Maximum fault current at bus 1 in A')\n",
+ "#Min. Current\n",
+ "If_b1_min = (V/math.sqrt(3)) * m / (Z_tr)\n",
+ "print(If_b1_min,'Minimum fault current at bus 1 in A')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "((202.73368231086098+0j), 'Maximum fault current at bus 5 in A')\n",
+ "((165.07177033492823+0j), 'Minimum fault current at bus 5 in A')\n",
+ "((300.657876030824+0j), 'Maximum fault current at bus 4 in A')\n",
+ "((237.93103448275863+0j), 'Minimum fault current at bus 4 in A')\n",
+ "((430.6720926928019+0j), 'Maximum fault current at bus 3 in A')\n",
+ "((328.57142857142856+0j), 'Minimum fault current at bus 3 in A')\n",
+ "((658.4655962658543+0j), 'Maximum fault current at bus 2 in A')\n",
+ "((472.60273972602744+0j), 'Minimum fault current at bus 2 in A')\n",
+ "((3186.9734859267346+0j), 'Maximum fault current at bus 1 in A')\n",
+ "((1380+0j), 'Minimum fault current at bus 1 in A')\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.3, Page No 357"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "#This problem contains many assumptions and values are taken from Figure 13.7 in page 348 after intial calculations,it is done in order to select equipment of the available rated value in the market to meet the required conditions.So only the required calculations are shown and final answer after the required changes are printlayed.\n",
+ "V = 13.8e3\n",
+ "Z_tr = complex(5)\n",
+ "Z_tr_eq = Z_tr / 2\t\t#since two reactances of equal value are in parallel\n",
+ "Z1 = complex(9.6)\n",
+ "Z2 = complex(6.4)\n",
+ "Z3 = complex(8.0)\n",
+ "Z4 = complex(12.8)\n",
+ "m = math.sqrt(3) / 2\t\t#to obtain line-to-line fault from a three-phase fault current\n",
+ "If_b5_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1 + Z2 + Z3 + Z4)\n",
+ "If_b5_min = (V/math.sqrt(3)) * m / (Z_tr + Z1 + Z2 + Z3 + Z4)\n",
+ "If_b4_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1 + Z2 + Z3)\n",
+ "If_b4_min = (V/math.sqrt(3)) * m / (Z_tr + Z1 + Z2 + Z3)\n",
+ "If_b3_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1 + Z2)\n",
+ "If_b3_min = (V/math.sqrt(3)) * m / (Z_tr + Z1 + Z2)\n",
+ "If_b2_max = (V/math.sqrt(3)) / (Z_tr_eq + Z1)\n",
+ "If_b2_min = (V/math.sqrt(3)) * m / (Z_tr + Z1)\n",
+ "If_b1_max = (V/math.sqrt(3)) / (Z_tr_eq)\n",
+ "If_b1_min = (V/math.sqrt(3)) * m / (Z_tr)\n",
+ "#Settings for relay R4\n",
+ "R4_I_1_p = If_b5_min /3\n",
+ "print('One third of minimum fault current in A')\n",
+ "print(abs(R4_I_1_p))\n",
+ "R4_I_p = R4_I_1_p * 5 /55\n",
+ "print('For CT ratio 50/5 resulting relay current in A will be')\n",
+ "print(abs(R4_I_p))\n",
+ "print('Settings for relay R4')\n",
+ "print('CT ratio = 50:5')\n",
+ "print('Pick up setting in A = 5')\n",
+ "print('Time-dial setting = 1/2')\n",
+ "#Settings for relay R3\n",
+ "R3_I_p = If_b4_max * 5 / 50\n",
+ "print('The relay current of both R3 and R4 for higest fault current seen by R4')\n",
+ "print(abs(R3_I_p))\n",
+ "R4_t_op = 0.135\n",
+ "print('Operating time for R4 with time dial setting 1/2 in sec is')\n",
+ "print(R4_t_op)\n",
+ "t=0.3\n",
+ "R3_t_op = R4_t_op + t\n",
+ "print('Required operating time of relay R3')\n",
+ "print(R3_t_op)\n",
+ "print('Settings for relay R3')\n",
+ "print('CT ratio = 50:5')\n",
+ "print('Pick up setting in A = 5')\n",
+ "print('Time-dial setting = 2')\n",
+ "#Settings for relay R2\n",
+ "R2_I_p = (1.0/3) * If_b4_min * (5.0/100)\n",
+ "print('Pickup setting in A')\n",
+ "print(abs(R2_I_p))\n",
+ "R3_I_1_p = If_b3_max * (5.0/50) * (1.0/5)\n",
+ "print('Reatio of relay current to picup setting in A for max fault current through R3')\n",
+ "print(abs(R3_I_1_p))\n",
+ "R3_t_op = 0.31\n",
+ "R2_t_op = R3_t_op + t\n",
+ "print('Operating time of R2 in sec')\n",
+ "print(R2_t_op)\n",
+ "R2_I_1_p = If_b3_max * (5.0/100) * (1.0/4)\n",
+ "print('For backing up R3 the ratio of relay current to pickup setting of R2 in A')\n",
+ "print(abs(R2_I_1_p))\n",
+ "print('Settings for relay R2')\n",
+ "print('CT ratio = 100:5')\n",
+ "print('Pick up setting in A = 4')\n",
+ "print('Time-dial setting = 2.6')\n",
+ "#Settings for relay R1\n",
+ "R1_I_p = If_b3_min * (1.0/3) * (5.0/100)\n",
+ "#taking tap as 5.0\n",
+ "R2_1_I_1_op = If_b2_max * (5.0/50) * (1.0/5)\n",
+ "#Operating time will come to 0.33s\n",
+ "R1_t_op = 0.33+t\n",
+ "R1_1_I_1_op = If_b2_max * (5.0/100) * (1.0/5)\n",
+ "\n",
+ "#Results\n",
+ "print('Settings for relay R1')\n",
+ "print('CT ratio = 100:5')\n",
+ "print('Pick up setting in A = 5')\n",
+ "print('Time-dial setting = 2.9')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "One third of minimum fault current in A\n",
+ "55.023923445\n",
+ "For CT ratio 50/5 resulting relay current in A will be\n",
+ "5.00217485863\n",
+ "Settings for relay R4\n",
+ "CT ratio = 50:5\n",
+ "Pick up setting in A = 5\n",
+ "Time-dial setting = 1/2\n",
+ "The relay current of both R3 and R4 for higest fault current seen by R4\n",
+ "30.0657876031\n",
+ "Operating time for R4 with time dial setting 1/2 in sec is\n",
+ "0.135\n",
+ "Required operating time of relay R3\n",
+ "0.435\n",
+ "Settings for relay R3\n",
+ "CT ratio = 50:5\n",
+ "Pick up setting in A = 5\n",
+ "Time-dial setting = 2\n",
+ "Pickup setting in A\n",
+ "3.96551724138\n",
+ "Reatio of relay current to picup setting in A for max fault current through R3\n",
+ "8.61344185386\n",
+ "Operating time of R2 in sec\n",
+ "0.61\n",
+ "For backing up R3 the ratio of relay current to pickup setting of R2 in A\n",
+ "5.38340115866\n",
+ "Settings for relay R2\n",
+ "CT ratio = 100:5\n",
+ "Pick up setting in A = 4\n",
+ "Time-dial setting = 2.6\n",
+ "Settings for relay R1\n",
+ "CT ratio = 100:5\n",
+ "Pick up setting in A = 5\n",
+ "Time-dial setting = 2.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.4 Page No 363"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "l_12 = 64\n",
+ "l_23 = 64\n",
+ "l_24 = 96\t\t#in km\n",
+ "l_12m = 40\n",
+ "l_23m = 40\n",
+ "l_24m = 60\n",
+ "z = complex(0.05 ,0.5)\n",
+ "Pmax = 50e6\n",
+ "V = 138e3\n",
+ "pf = 0.8\n",
+ "cvt = 67\n",
+ "\n",
+ "#Calculations\n",
+ "Z_12 = z * l_12\n",
+ "Z_23 = z * l_23\n",
+ "Z_24 = z * l_24\n",
+ "print('The positive sequnce impedances of the three line in ohms in the order line 1-2,line 2-3,line 2-4 are')\n",
+ "print(Z_12)\n",
+ "print(Z_23)\n",
+ "print(Z_24)\n",
+ "Il_max = Pmax / (math.sqrt(3) * V)\n",
+ "print('Maximum load current in A')\n",
+ "print(Il_max)\n",
+ "Vn = V/ math.sqrt(3)\n",
+ "print('System Voltage to neutral')\n",
+ "print(Vn)\n",
+ "ratio_cvt = Vn / cvt\n",
+ "print('cvt ratio = 1089.1/1')\n",
+ "b1_factor = l_12m / ratio_cvt\n",
+ "Z_r12 = Z_12 * b1_factor\n",
+ "Z_r23 = Z_23 * b1_factor\n",
+ "Z_r24 = Z_24 * b1_factor\n",
+ "print('The impedance of the lines as seen by R12 in ohms in the order line 1-2,line 2-3,line 2-4 are')\n",
+ "print(Z_r12)\n",
+ "print(Z_r23)\n",
+ "print(Z_r24)\n",
+ "Zload = (cvt * complex(pf,math.sqrt(1-pf**2))) / (Il_max * (5.0/200))\n",
+ "print('Impedance of load current')\n",
+ "print(Zload)\n",
+ "zone1 = 0.8 * Z_r12\n",
+ "print('Setting of zone one on secondary in ohms')\n",
+ "print(zone1)\n",
+ "zone2 = 1.2 * Z_r23\n",
+ "print('Setting of zone two on secondary in ohms')\n",
+ "print(zone2)\n",
+ "zone3 = Z_r23 + 1.2 * Z_r24\n",
+ "print('Setting of zone three on secondary in ohms')\n",
+ "print(zone3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The positive sequnce impedances of the three line in ohms in the order line 1-2,line 2-3,line 2-4 are\n",
+ "(3.2+32j)\n",
+ "(3.2+32j)\n",
+ "(4.8+48j)\n",
+ "Maximum load current in A\n",
+ "209.184880141\n",
+ "System Voltage to neutral\n",
+ "79674.3371482\n",
+ "cvt ratio = 1089.1/1\n",
+ "The impedance of the lines as seen by R12 in ohms in the order line 1-2,line 2-3,line 2-4 are\n",
+ "(0.107638171925+1.07638171925j)\n",
+ "(0.107638171925+1.07638171925j)\n",
+ "(0.161457257888+1.61457257888j)\n",
+ "Impedance of load current\n",
+ "(10.2493067307+7.68698004806j)\n",
+ "Setting of zone one on secondary in ohms\n",
+ "(0.0861105375404+0.861105375404j)\n",
+ "Setting of zone two on secondary in ohms\n",
+ "(0.129165806311+1.29165806311j)\n",
+ "Setting of zone three on secondary in ohms\n",
+ "(0.301386881391+3.01386881391j)\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.5, Page No 368"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "V_ht = 345e3\n",
+ "V_lt = 34.5e3\n",
+ "P = 50e6\n",
+ "P_short_term = 60e6\n",
+ "\n",
+ "#Calculations\n",
+ "I_ht = P_short_term / (math.sqrt(3) * V_ht)\n",
+ "I_lt = P_short_term / (math.sqrt(3) * V_lt)\n",
+ "print('Under maximum load the currents on 345-kV and 34.5-kV side of the transformer respectively in A = %.2f %.2f' %(I_ht,I_lt))\n",
+ "#CT ratio on the 34.5kV side 1000/5\n",
+ "I_r_lt = I_lt * 5 / 1000\n",
+ "print('Current flowing through the differential relay from 34.5-kV side = %.2f' %I_r_lt)\n",
+ "I_balance = 5.0\n",
+ "I_lt_sec_ct = I_balance / math.sqrt(3)\n",
+ "print('To balance the above current each of the secondary windings of the delta connected CTs should have a current(in A) of = %.2f' %I_lt_sec_ct)\n",
+ "ct_sec = I_ht / I_lt_sec_ct\n",
+ "print('CT ratios in secondary for the above currents = %.2f' %ct_sec)\n",
+ "I_ht_sec_ct = I_ht * 5 / 200\n",
+ "\n",
+ "#Results\n",
+ "print('CT secondary currents for ratio 200/5 on the secondary side of 345-kV will be = %.2f' %I_ht_sec_ct)\n",
+ "I_line_ctr = I_ht_sec_ct * math.sqrt(3)\n",
+ "print('Line currents from CTs to differential relays = %.2f' %I_line_ctr)\n",
+ "turns_ratio = I_r_lt / I_line_ctr\n",
+ "print('Required turns ratio for the three auxillary CTs uses is = %.2f' %turns_ratio)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Under maximum load the currents on 345-kV and 34.5-kV side of the transformer respectively in A = 100.41 1004.09\n",
+ "Current flowing through the differential relay from 34.5-kV side = 5.02\n",
+ "To balance the above current each of the secondary windings of the delta connected CTs should have a current(in A) of = 2.89\n",
+ "CT ratios in secondary for the above currents = 34.78\n",
+ "CT secondary currents for ratio 200/5 on the secondary side of 345-kV will be = 2.51\n",
+ "Line currents from CTs to differential relays = 4.35\n",
+ "Required turns ratio for the three auxillary CTs uses is = 1.15\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo14.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo14.ipynb
new file mode 100755
index 00000000..59439b8a
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo14.ipynb
@@ -0,0 +1,428 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 14 : Power System Stability"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.1, Page No 380"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "WR2 = 5.82\n",
+ "Smach = 1333\n",
+ "n = 1800\n",
+ "\n",
+ "#Calculations\n",
+ "ft_lb = 746 / 550.0\n",
+ "w = 2 * math.pi * n / 60\n",
+ "H = ft_lb * WR2 * w**2 / (2 * 32.2 * Smach)\n",
+ "\n",
+ "#Results\n",
+ "print('The inertia constant in MJ/MVA is = %.2f' %H)\n",
+ "print('Converting H to a 100-MVA system base,units in MJ/MVA = %.2f' %(H * Smach / 100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The inertia constant in MJ/MVA is = 3.27\n",
+ "Converting H to a 100-MVA system base,units in MJ/MVA = 43.55\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.2, Page No 181"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P1 = 500.0\n",
+ "pf1 = 0.85\n",
+ "V1 = 20.0\n",
+ "n1 = 3600\n",
+ "P2 = 1333.0\n",
+ "pf2 = 0.9\n",
+ "V2 = 22.0\n",
+ "n2 = 1800.0\n",
+ "Pbase = 100\n",
+ "H1 = 4.8\n",
+ "H2 = 3.27\n",
+ "\n",
+ "#Calculations\n",
+ "KE = H1 * P1 + H2 * P2\n",
+ "\n",
+ "#Results\n",
+ "print('The total kinetic energy of rotation of the two machines in MJ is = %.2f' %KE)\n",
+ "print('The inertia constant for the equivalent machine on 100-MVA base in MJ/MVA is = %.2f' %(KE/Pbase))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The total kinetic energy of rotation of the two machines in MJ is = 6758.91\n",
+ "The inertia constant for the equivalent machine on 100-MVA base in MJ/MVA is = 67.59\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.3, Page No 386"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Pm =1\n",
+ "Vt = 1.0\n",
+ "V_ib = 1.0\n",
+ "X1_g =0.2\n",
+ "X1_t = 0.1\n",
+ "X1_l1 = 0.4\n",
+ "X1_l2 = 0.4\n",
+ "\n",
+ "#Calculations\n",
+ "X = X1_t + X1_l1 /2\n",
+ "a = math.asin(Pm*X/(Vt*V_ib))*180/math.pi\n",
+ "Vt1 = Vt*complex(math.cos(a * math.pi / 180),math.sin(a * math.pi / 180))\n",
+ "I = (Vt1 - V_ib) / complex(X)\n",
+ "E1 = Vt1 + complex(X1_g * I)\n",
+ "X1 = X1_g + X1_t + X1_l1 /2\n",
+ "Pmax = abs(E1) * V_ib / X1\n",
+ "\n",
+ "#Results\n",
+ "print('The terminal voltage after considering the angle is,in per unit= {0:.2f}+{1:.2f}i'.format(Vt1.real, Vt1.imag))\n",
+ "print('The output current from the generator in per unit is= {0:.2f}+{1:.2f}i'.format(I.real, I.imag))\n",
+ "print('The transient internal voltage in per unit= {0:.2f}+{1:.2f}i'.format(E1.real, E1.imag))\n",
+ "print('Power angle equation is')\n",
+ "print(\"\\n Pe = %.2f * sin(delta) \\n where delta is the machine rotor angle wrt to the infinite bus\" %Pmax)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The terminal voltage after considering the angle is,in per unit= 0.95+0.30i\n",
+ "The output current from the generator in per unit is= -0.15+1.00i\n",
+ "The transient internal voltage in per unit= 0.92+0.50i\n",
+ "Power angle equation is\n",
+ "\n",
+ " Pe = 2.10 * sin(delta) \n",
+ " where delta is the machine rotor angle wrt to the infinite bus\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.4 Page No 388"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "H = 5.0\n",
+ "Pm =1.0\n",
+ "Vt = 1.0\n",
+ "V_ib = 1.0\n",
+ "X1_g =0.2\n",
+ "X1_t = 0.1\n",
+ "X1_l1 = 0.4\n",
+ "X1_l2 = 0.4\n",
+ "X = X1_t + X1_l1 /2\n",
+ "a = math.asin(Pm * X / (Vt * V_ib)) * 180 / math.pi\n",
+ "Vt1 = Vt*complex(math.cos(a * math.pi / 180),math.sin(a * math.pi / 180))\n",
+ "I = (Vt1 - V_ib) / complex(X)\n",
+ "E1 = Vt1 + complex(X1_g * I)\n",
+ "y10 = complex(3.33)\n",
+ "y32 = complex(2.5)\n",
+ "y30 = complex(5)\n",
+ "y20 = complex(5)\n",
+ "Ybus = [[0,0,0],[0,0,0],[0,0,0]]\n",
+ "\n",
+ "#Calculations\n",
+ "Ybus[0][0] = -y10\n",
+ "Ybus[0][1] =0\n",
+ "Ybus[0][2] = y10\n",
+ "Ybus[1][0] = Ybus[0][1]\n",
+ "Ybus[1][1] = -(y32 + y30)\n",
+ "Ybus[1][2] = y32\n",
+ "Ybus[2][0] = Ybus[0][2]\n",
+ "Ybus[2][1] = Ybus[1][2]\n",
+ "Ybus[2][2] = -(y10 + y32 + y30)\n",
+ "print('Ybus formed by inspection is')\n",
+ "print(Ybus)\n",
+ "\n",
+ "Ybus_new = [[0,0],[0,0]]\n",
+ "for c in range(0, 2):\n",
+ " for d in range(0, 2):\n",
+ " Ybus_new[c][d] = Ybus[c][d] - ((Ybus[c][2]*Ybus[2][d]) / Ybus[2][2])\n",
+ " \n",
+ "print('Ybus formed after elimination of Bus 3')\n",
+ "print(Ybus_new)\n",
+ "Pmax = abs(E1) * V_ib * abs(Ybus_new[0][1])\n",
+ "delta = 28.44\n",
+ "Pa = Pm - Pmax * math.sin(delta * math.pi / 180)\n",
+ "b = 180 * Pa / H\n",
+ "#Results\n",
+ "print('The power abgle equation is')\n",
+ "print(\" Pe = %.3f * sin(delta) \\n where delta is the machine rotor angle wrt to the infinite bus\" %Pmax)\n",
+ "print('The swing equation is')\n",
+ "print(\"(%.2f/180f) * d(delta)^2/dt^2 = %.2f - %.2fsin(delta) \\n\" %(H,Pm,Pmax))\n",
+ "print(\" Intial Accelerating power is %.3f per unit \\n\" %(Pa))\n",
+ "print(\" Initial acceleration is %.2f*f \\n where f is the system frequency\" %(b))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ybus formed by inspection is\n",
+ "[[(-3.33-0j), 0, (3.33+0j)], [0, (-7.5-0j), (2.5+0j)], [(3.33+0j), (2.5+0j), (-10.83-0j)]]\n",
+ "Ybus formed after elimination of Bus 3\n",
+ "[[(-2.306094182825485+0j), (0.7686980609418281+0j)], [(0.7686980609418281+0j), (-6.922899353647276+0j)]]\n",
+ "The power abgle equation is\n",
+ " Pe = 0.807 * sin(delta) \n",
+ " where delta is the machine rotor angle wrt to the infinite bus\n",
+ "The swing equation is\n",
+ "(5.00/180f) * d(delta)^2/dt^2 = 1.00 - 0.81sin(delta) \n",
+ "\n",
+ " Intial Accelerating power is 0.616 per unit \n",
+ "\n",
+ " Initial acceleration is 22.16*f \n",
+ " where f is the system frequency\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.5, Page No 389"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "H = 5\n",
+ "Pm =1\n",
+ "Vt = 1\n",
+ "V_ib = 1\n",
+ "X1_g =0.2\n",
+ "X1_t = 0.1\n",
+ "X1_l1 = 0.4\n",
+ "X1_l2 = 0.4\n",
+ "\n",
+ "#Calculations\n",
+ "X = X1_t + X1_l1 /2\n",
+ "a = math.asin(Pm * X / (Vt * V_ib)) * 180 / math.pi\n",
+ "Vt1 = Vt * complex(math.cos(a * math.pi / 180),math.sin(a * math.pi / 180))\n",
+ "I = (Vt1 - V_ib) / complex(X)\n",
+ "E1 = Vt1 + complex(X1_g * I)\n",
+ "y12 = 1 / complex((X1_g + X1_t + X1_l1))\n",
+ "Y12 = -y12\n",
+ "Pe = abs(E1) * V_ib * abs(Y12)\n",
+ "\n",
+ "#Results\n",
+ "print('The power abgle equation is')\n",
+ "print(\" Pe = %.3f * sin(delta) \\n where delta is the machine rotor angle wrt to the infinite bus\" %Pe)\n",
+ "print('The swing equation is')\n",
+ "print(\" (%.2f/180f) * d(delta)^2/dt^2 = %.2f - %.2fsin(delta) \\n\" %(H,Pm,Pe))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The power abgle equation is\n",
+ " Pe = 1.500 * sin(delta) \n",
+ " where delta is the machine rotor angle wrt to the infinite bus\n",
+ "The swing equation is\n",
+ " (5.00/180f) * d(delta)^2/dt^2 = 1.00 - 1.50sin(delta) \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.6, Page No 392"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "delta = 28.44\n",
+ "H = 5\n",
+ "ws = 377\n",
+ "Pm =1\n",
+ "Vt = 1.0\n",
+ "V_ib = 1\n",
+ "X1_g =0.2\n",
+ "X1_t = 0.1\n",
+ "X1_l1 = 0.4\n",
+ "X1_l2 = 0.4\n",
+ "\n",
+ "#Calculations\n",
+ "X = X1_t + X1_l1 /2\n",
+ "a = math.asin(Pm * X / (Vt * V_ib)) * 180 / math.pi\n",
+ "Vt1 = Vt * complex(math.cos(a * math.pi / 180),math.sin(a * math.pi / 180))\n",
+ "I = (Vt1 - V_ib) / complex(X)\n",
+ "E1 = Vt1 + complex(X1_g * I)\n",
+ "X1 = X1_g + X1_t + X1_l1 /2\n",
+ "Pmax = abs(E1) * V_ib / X1\n",
+ "Sp = Pmax * math.cos(delta * math.pi / 180)\n",
+ "wn = math.sqrt(ws * Sp / (2 * H))\n",
+ "fn = wn / (2 * math.pi)\n",
+ "T = 1 / fn\n",
+ "\n",
+ "#Results\n",
+ "print(\"The angular frequency of oscillation is %.3f elec rad/s \" %wn)\n",
+ "print(\"The corresponding frquency of oscillation is %.2f Hz \" %fn)\n",
+ "print(\"The period of oscillation is %.3f s\" %T)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The angular frequency of oscillation is 8.343 elec rad/s \n",
+ "The corresponding frquency of oscillation is 1.33 Hz \n",
+ "The period of oscillation is 0.753 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.7 Page No 392"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "delta = 28.44\n",
+ "H = 5\n",
+ "ws = 377\n",
+ "Pm =1\n",
+ "Vt = 1\n",
+ "V_ib = 1\n",
+ "X1_g =0.2\n",
+ "X1_t = 0.1\n",
+ "X1_l1 = 0.4\n",
+ "X1_l2 = 0.4\n",
+ "\n",
+ "#Calculations\n",
+ "X = X1_t + X1_l1 /2\n",
+ "a = math.asin(Pm * X / (Vt * V_ib)) * 180 / math.pi\n",
+ "Vt1 = Vt * complex(math.cos(a * math.pi / 180),math.sin(a * math.pi / 180))\n",
+ "I = (Vt1 - V_ib) / complex(X)\n",
+ "E1 = Vt1 + complex(X1_g * I)\n",
+ "X1 = X1_g + X1_t + X1_l1 /2\n",
+ "Pmax = abs(E1) * V_ib / X1\n",
+ "delta_rad = delta * math.pi / 180\n",
+ "delta_cr = math.acos((math.pi - 2 * delta_rad) * math.sin(delta_rad) - math.cos(delta_rad))\n",
+ "t_cr = math.sqrt(4 * H * (delta_cr - delta_rad) / (ws * Pm))\n",
+ "\n",
+ "#Results\n",
+ "print(\"Critical clearing angle = %.3f elec rad \" %(delta_cr))\n",
+ "print(\"Critical clearing angle for the system = %.3f s\" %(t_cr))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical clearing angle = 1.426 elec rad \n",
+ "Critical clearing angle for the system = 0.222 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo14_1.ipynb b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo14_1.ipynb
new file mode 100755
index 00000000..59439b8a
--- /dev/null
+++ b/Elements_of_Power_System_Analysis_by_W.D._Stevenson,_Jr./ChapterNo14_1.ipynb
@@ -0,0 +1,428 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 14 : Power System Stability"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.1, Page No 380"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "WR2 = 5.82\n",
+ "Smach = 1333\n",
+ "n = 1800\n",
+ "\n",
+ "#Calculations\n",
+ "ft_lb = 746 / 550.0\n",
+ "w = 2 * math.pi * n / 60\n",
+ "H = ft_lb * WR2 * w**2 / (2 * 32.2 * Smach)\n",
+ "\n",
+ "#Results\n",
+ "print('The inertia constant in MJ/MVA is = %.2f' %H)\n",
+ "print('Converting H to a 100-MVA system base,units in MJ/MVA = %.2f' %(H * Smach / 100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The inertia constant in MJ/MVA is = 3.27\n",
+ "Converting H to a 100-MVA system base,units in MJ/MVA = 43.55\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.2, Page No 181"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "P1 = 500.0\n",
+ "pf1 = 0.85\n",
+ "V1 = 20.0\n",
+ "n1 = 3600\n",
+ "P2 = 1333.0\n",
+ "pf2 = 0.9\n",
+ "V2 = 22.0\n",
+ "n2 = 1800.0\n",
+ "Pbase = 100\n",
+ "H1 = 4.8\n",
+ "H2 = 3.27\n",
+ "\n",
+ "#Calculations\n",
+ "KE = H1 * P1 + H2 * P2\n",
+ "\n",
+ "#Results\n",
+ "print('The total kinetic energy of rotation of the two machines in MJ is = %.2f' %KE)\n",
+ "print('The inertia constant for the equivalent machine on 100-MVA base in MJ/MVA is = %.2f' %(KE/Pbase))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The total kinetic energy of rotation of the two machines in MJ is = 6758.91\n",
+ "The inertia constant for the equivalent machine on 100-MVA base in MJ/MVA is = 67.59\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.3, Page No 386"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "Pm =1\n",
+ "Vt = 1.0\n",
+ "V_ib = 1.0\n",
+ "X1_g =0.2\n",
+ "X1_t = 0.1\n",
+ "X1_l1 = 0.4\n",
+ "X1_l2 = 0.4\n",
+ "\n",
+ "#Calculations\n",
+ "X = X1_t + X1_l1 /2\n",
+ "a = math.asin(Pm*X/(Vt*V_ib))*180/math.pi\n",
+ "Vt1 = Vt*complex(math.cos(a * math.pi / 180),math.sin(a * math.pi / 180))\n",
+ "I = (Vt1 - V_ib) / complex(X)\n",
+ "E1 = Vt1 + complex(X1_g * I)\n",
+ "X1 = X1_g + X1_t + X1_l1 /2\n",
+ "Pmax = abs(E1) * V_ib / X1\n",
+ "\n",
+ "#Results\n",
+ "print('The terminal voltage after considering the angle is,in per unit= {0:.2f}+{1:.2f}i'.format(Vt1.real, Vt1.imag))\n",
+ "print('The output current from the generator in per unit is= {0:.2f}+{1:.2f}i'.format(I.real, I.imag))\n",
+ "print('The transient internal voltage in per unit= {0:.2f}+{1:.2f}i'.format(E1.real, E1.imag))\n",
+ "print('Power angle equation is')\n",
+ "print(\"\\n Pe = %.2f * sin(delta) \\n where delta is the machine rotor angle wrt to the infinite bus\" %Pmax)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The terminal voltage after considering the angle is,in per unit= 0.95+0.30i\n",
+ "The output current from the generator in per unit is= -0.15+1.00i\n",
+ "The transient internal voltage in per unit= 0.92+0.50i\n",
+ "Power angle equation is\n",
+ "\n",
+ " Pe = 2.10 * sin(delta) \n",
+ " where delta is the machine rotor angle wrt to the infinite bus\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.4 Page No 388"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "H = 5.0\n",
+ "Pm =1.0\n",
+ "Vt = 1.0\n",
+ "V_ib = 1.0\n",
+ "X1_g =0.2\n",
+ "X1_t = 0.1\n",
+ "X1_l1 = 0.4\n",
+ "X1_l2 = 0.4\n",
+ "X = X1_t + X1_l1 /2\n",
+ "a = math.asin(Pm * X / (Vt * V_ib)) * 180 / math.pi\n",
+ "Vt1 = Vt*complex(math.cos(a * math.pi / 180),math.sin(a * math.pi / 180))\n",
+ "I = (Vt1 - V_ib) / complex(X)\n",
+ "E1 = Vt1 + complex(X1_g * I)\n",
+ "y10 = complex(3.33)\n",
+ "y32 = complex(2.5)\n",
+ "y30 = complex(5)\n",
+ "y20 = complex(5)\n",
+ "Ybus = [[0,0,0],[0,0,0],[0,0,0]]\n",
+ "\n",
+ "#Calculations\n",
+ "Ybus[0][0] = -y10\n",
+ "Ybus[0][1] =0\n",
+ "Ybus[0][2] = y10\n",
+ "Ybus[1][0] = Ybus[0][1]\n",
+ "Ybus[1][1] = -(y32 + y30)\n",
+ "Ybus[1][2] = y32\n",
+ "Ybus[2][0] = Ybus[0][2]\n",
+ "Ybus[2][1] = Ybus[1][2]\n",
+ "Ybus[2][2] = -(y10 + y32 + y30)\n",
+ "print('Ybus formed by inspection is')\n",
+ "print(Ybus)\n",
+ "\n",
+ "Ybus_new = [[0,0],[0,0]]\n",
+ "for c in range(0, 2):\n",
+ " for d in range(0, 2):\n",
+ " Ybus_new[c][d] = Ybus[c][d] - ((Ybus[c][2]*Ybus[2][d]) / Ybus[2][2])\n",
+ " \n",
+ "print('Ybus formed after elimination of Bus 3')\n",
+ "print(Ybus_new)\n",
+ "Pmax = abs(E1) * V_ib * abs(Ybus_new[0][1])\n",
+ "delta = 28.44\n",
+ "Pa = Pm - Pmax * math.sin(delta * math.pi / 180)\n",
+ "b = 180 * Pa / H\n",
+ "#Results\n",
+ "print('The power abgle equation is')\n",
+ "print(\" Pe = %.3f * sin(delta) \\n where delta is the machine rotor angle wrt to the infinite bus\" %Pmax)\n",
+ "print('The swing equation is')\n",
+ "print(\"(%.2f/180f) * d(delta)^2/dt^2 = %.2f - %.2fsin(delta) \\n\" %(H,Pm,Pmax))\n",
+ "print(\" Intial Accelerating power is %.3f per unit \\n\" %(Pa))\n",
+ "print(\" Initial acceleration is %.2f*f \\n where f is the system frequency\" %(b))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ybus formed by inspection is\n",
+ "[[(-3.33-0j), 0, (3.33+0j)], [0, (-7.5-0j), (2.5+0j)], [(3.33+0j), (2.5+0j), (-10.83-0j)]]\n",
+ "Ybus formed after elimination of Bus 3\n",
+ "[[(-2.306094182825485+0j), (0.7686980609418281+0j)], [(0.7686980609418281+0j), (-6.922899353647276+0j)]]\n",
+ "The power abgle equation is\n",
+ " Pe = 0.807 * sin(delta) \n",
+ " where delta is the machine rotor angle wrt to the infinite bus\n",
+ "The swing equation is\n",
+ "(5.00/180f) * d(delta)^2/dt^2 = 1.00 - 0.81sin(delta) \n",
+ "\n",
+ " Intial Accelerating power is 0.616 per unit \n",
+ "\n",
+ " Initial acceleration is 22.16*f \n",
+ " where f is the system frequency\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.5, Page No 389"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "H = 5\n",
+ "Pm =1\n",
+ "Vt = 1\n",
+ "V_ib = 1\n",
+ "X1_g =0.2\n",
+ "X1_t = 0.1\n",
+ "X1_l1 = 0.4\n",
+ "X1_l2 = 0.4\n",
+ "\n",
+ "#Calculations\n",
+ "X = X1_t + X1_l1 /2\n",
+ "a = math.asin(Pm * X / (Vt * V_ib)) * 180 / math.pi\n",
+ "Vt1 = Vt * complex(math.cos(a * math.pi / 180),math.sin(a * math.pi / 180))\n",
+ "I = (Vt1 - V_ib) / complex(X)\n",
+ "E1 = Vt1 + complex(X1_g * I)\n",
+ "y12 = 1 / complex((X1_g + X1_t + X1_l1))\n",
+ "Y12 = -y12\n",
+ "Pe = abs(E1) * V_ib * abs(Y12)\n",
+ "\n",
+ "#Results\n",
+ "print('The power abgle equation is')\n",
+ "print(\" Pe = %.3f * sin(delta) \\n where delta is the machine rotor angle wrt to the infinite bus\" %Pe)\n",
+ "print('The swing equation is')\n",
+ "print(\" (%.2f/180f) * d(delta)^2/dt^2 = %.2f - %.2fsin(delta) \\n\" %(H,Pm,Pe))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The power abgle equation is\n",
+ " Pe = 1.500 * sin(delta) \n",
+ " where delta is the machine rotor angle wrt to the infinite bus\n",
+ "The swing equation is\n",
+ " (5.00/180f) * d(delta)^2/dt^2 = 1.00 - 1.50sin(delta) \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.6, Page No 392"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "delta = 28.44\n",
+ "H = 5\n",
+ "ws = 377\n",
+ "Pm =1\n",
+ "Vt = 1.0\n",
+ "V_ib = 1\n",
+ "X1_g =0.2\n",
+ "X1_t = 0.1\n",
+ "X1_l1 = 0.4\n",
+ "X1_l2 = 0.4\n",
+ "\n",
+ "#Calculations\n",
+ "X = X1_t + X1_l1 /2\n",
+ "a = math.asin(Pm * X / (Vt * V_ib)) * 180 / math.pi\n",
+ "Vt1 = Vt * complex(math.cos(a * math.pi / 180),math.sin(a * math.pi / 180))\n",
+ "I = (Vt1 - V_ib) / complex(X)\n",
+ "E1 = Vt1 + complex(X1_g * I)\n",
+ "X1 = X1_g + X1_t + X1_l1 /2\n",
+ "Pmax = abs(E1) * V_ib / X1\n",
+ "Sp = Pmax * math.cos(delta * math.pi / 180)\n",
+ "wn = math.sqrt(ws * Sp / (2 * H))\n",
+ "fn = wn / (2 * math.pi)\n",
+ "T = 1 / fn\n",
+ "\n",
+ "#Results\n",
+ "print(\"The angular frequency of oscillation is %.3f elec rad/s \" %wn)\n",
+ "print(\"The corresponding frquency of oscillation is %.2f Hz \" %fn)\n",
+ "print(\"The period of oscillation is %.3f s\" %T)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The angular frequency of oscillation is 8.343 elec rad/s \n",
+ "The corresponding frquency of oscillation is 1.33 Hz \n",
+ "The period of oscillation is 0.753 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.7 Page No 392"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#initialisation of variables\n",
+ "delta = 28.44\n",
+ "H = 5\n",
+ "ws = 377\n",
+ "Pm =1\n",
+ "Vt = 1\n",
+ "V_ib = 1\n",
+ "X1_g =0.2\n",
+ "X1_t = 0.1\n",
+ "X1_l1 = 0.4\n",
+ "X1_l2 = 0.4\n",
+ "\n",
+ "#Calculations\n",
+ "X = X1_t + X1_l1 /2\n",
+ "a = math.asin(Pm * X / (Vt * V_ib)) * 180 / math.pi\n",
+ "Vt1 = Vt * complex(math.cos(a * math.pi / 180),math.sin(a * math.pi / 180))\n",
+ "I = (Vt1 - V_ib) / complex(X)\n",
+ "E1 = Vt1 + complex(X1_g * I)\n",
+ "X1 = X1_g + X1_t + X1_l1 /2\n",
+ "Pmax = abs(E1) * V_ib / X1\n",
+ "delta_rad = delta * math.pi / 180\n",
+ "delta_cr = math.acos((math.pi - 2 * delta_rad) * math.sin(delta_rad) - math.cos(delta_rad))\n",
+ "t_cr = math.sqrt(4 * H * (delta_cr - delta_rad) / (ws * Pm))\n",
+ "\n",
+ "#Results\n",
+ "print(\"Critical clearing angle = %.3f elec rad \" %(delta_cr))\n",
+ "print(\"Critical clearing angle for the system = %.3f s\" %(t_cr))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical clearing angle = 1.426 elec rad \n",
+ "Critical clearing angle for the system = 0.222 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/Chapter1.ipynb b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/Chapter1.ipynb
index 93534790..93534790 100755
--- a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/Chapter1.ipynb
+++ b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/Chapter1.ipynb
diff --git a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/Chapter2.ipynb b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/Chapter2.ipynb
index 73a9ca5d..73a9ca5d 100755
--- a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/Chapter2.ipynb
+++ b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/Chapter2.ipynb
diff --git a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/Chapter3.ipynb b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/Chapter3.ipynb
index 024540f1..024540f1 100755
--- a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/Chapter3.ipynb
+++ b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/Chapter3.ipynb
diff --git a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/Chapter4.ipynb b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/Chapter4.ipynb
index 819fca74..819fca74 100755
--- a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/Chapter4.ipynb
+++ b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/Chapter4.ipynb
diff --git a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/screenshots/Screenshot1.png b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot1.png
index ff7899d1..ff7899d1 100755
--- a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/screenshots/Screenshot1.png
+++ b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot1.png
Binary files differ
diff --git a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/screenshots/Screenshot2.png b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot2.png
index 9f4171d1..9f4171d1 100755
--- a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/screenshots/Screenshot2.png
+++ b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot2.png
Binary files differ
diff --git a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/screenshots/Screenshot3.png b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot3.png
index bc2fe5aa..bc2fe5aa 100755
--- a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering/screenshots/Screenshot3.png
+++ b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot3.png
Binary files differ
diff --git a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot_(1).png b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot_(1).png
new file mode 100755
index 00000000..ff7899d1
--- /dev/null
+++ b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot_(1).png
Binary files differ
diff --git a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot_(2).png b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot_(2).png
new file mode 100755
index 00000000..9f4171d1
--- /dev/null
+++ b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot_(2).png
Binary files differ
diff --git a/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot_(3).png b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot_(3).png
new file mode 100755
index 00000000..bc2fe5aa
--- /dev/null
+++ b/Engineering_Basics_:_Electrical_,_Electronics_and_Computer_Engineering_by_T._Thyagarajan/screenshots/Screenshot_(3).png
Binary files differ
diff --git a/Engineering_Mechanics/screenshots/bending_moment_diagram_.png b/Engineering_Mechanics/screenshots/bending_moment_diagram_.png
new file mode 100755
index 00000000..b2fe11de
--- /dev/null
+++ b/Engineering_Mechanics/screenshots/bending_moment_diagram_.png
Binary files differ
diff --git a/Engineering_Mechanics/screenshots/shear_force_diagram_.png b/Engineering_Mechanics/screenshots/shear_force_diagram_.png
new file mode 100755
index 00000000..00bf60e4
--- /dev/null
+++ b/Engineering_Mechanics/screenshots/shear_force_diagram_.png
Binary files differ
diff --git a/Engineering_Mechanics/screenshots/shear_force_diagram_1.png b/Engineering_Mechanics/screenshots/shear_force_diagram_1.png
new file mode 100755
index 00000000..a193dcf3
--- /dev/null
+++ b/Engineering_Mechanics/screenshots/shear_force_diagram_1.png
Binary files differ
diff --git a/Engineering_Mechanics_by_Tayal_A.K./appendix.ipynb b/Engineering_Mechanics_by_Tayal_A.K./appendix.ipynb
new file mode 100755
index 00000000..cf97f900
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./appendix.ipynb
@@ -0,0 +1,1002 @@
+{
+ "metadata": {
+ "name": "appendix.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Appendix"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-1,Page No:638"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "#Initilization of variables\n",
+ "\n",
+ "P=[-5,2,14] #Point co-ordinates\n",
+ "\n",
+ "#Calculations\n",
+ "r=(P[0]**2+P[1]**2+P[2]**2)**0.5 #Magnitude of the poistion vector\n",
+ "\n",
+ "#Direction cosines\n",
+ "l=P[0]/r \n",
+ "m=P[1]/r\n",
+ "n=P[2]/r\n",
+ "\n",
+ "\n",
+ "#Unit Vector calculations\n",
+ "\n",
+ "r_unit=[l,m,n]\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The unit vector in the direction of r is \",round(r_unit[0],2),\"i +\",round(r_unit[1],3),\"j +\",round(r_unit[2],3),\"k\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The unit vector in the direction of r is -0.33 i + 0.133 j + 0.933 k\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-2,Page No:639"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilizatin of variable\n",
+ "F=10 #N\n",
+ "P_1=[2,4,3] \n",
+ "P_2=[1,-5,2]\n",
+ "\n",
+ "#Calculations\n",
+ "d_x=P_2[0]-P_1[0] \n",
+ "d_y=P_2[1]-P_1[1]\n",
+ "d_z=P_2[2]-P_1[2]\n",
+ "d=(d_x**2+d_y**2+d_z**2)**0.5\n",
+ "Fx=(F/d)*d_x #N\n",
+ "Fy=(F/d)*d_y #N\n",
+ "Fz=(F/d)*d_z #N\n",
+ "#Direction cosines\n",
+ "l=Fx/F\n",
+ "m=Fy/F\n",
+ "n=Fz/F\n",
+ "#Angles\n",
+ "theta_x=arccos(l)*(180/pi) #degrees\n",
+ "theta_y=arccos(m)*(180/pi) #degrees\n",
+ "theta_z=arccos(n)*(180/pi) #degrees\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print\"The force in vector notation is \",round(Fx,1),\"i \",round(Fy,2),\"j \",round(Fz,1),\"k\"\n",
+ "print\"Thetax=\",round(theta_x,1),\" degrees\",\"\", \"Thetay=\",round(theta_y,2),\"degrees\",\"\", \"Thetaz=\",round(theta_z,1), \"degrees\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The force in vector notation is -1.1 i + -9.88 j + -1.1 k\n",
+ "Thetax= 96.3 degrees Thetay= 171.07 degrees Thetaz= 96.3 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-3,Page No:640"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initiliation of variables\n",
+ "T=2500 #N\n",
+ "\n",
+ "#Co-ordinates\n",
+ "Q=[40,0,-30]\n",
+ "P=[0,80,0]\n",
+ "\n",
+ "#Calculations\n",
+ "mag_QP=sqrt((P[0]-Q[0])**2+(P[1]-Q[1])**2+(P[2]-Q[2])**2) #Magnitude\n",
+ "QP=[(P[0]-Q[0]),(P[1]-Q[1]),(P[2]-Q[2])] \n",
+ "F=(T*mag_QP**-1)*QP #N\n",
+ "thetax=arccos(F[0]/T)*(180/pi) #degrees\n",
+ "thetay=arccos(F[1]/T)*(180/pi) #degrees\n",
+ "thetaz=arccos(F[2]/T)*(180/pi) #degrees\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print\"The force vector is \",round(F[0]),\"i +\",round(F[1]),\"j +\",round(F[2]),\"k\"\n",
+ "\n",
+ "#Answer in the textbook is printed as 1600 which is incorrect\n",
+ "print\"The angles are thetax=\",round(thetax,1),\"degrees\",\"\",\"thetay=\",round(thetay),\" degrees\",\"\",\" thetaz=\",round(thetaz,1),\" degrees\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The force vector is -40.0 i + 80.0 j + 30.0 k\n",
+ "The angles are thetax= 180.0 degrees thetay= 90.0 degrees thetaz= 90.0 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-4,Page No:642"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initilization of variables\n",
+ "\n",
+ "A=[2,-1,1]\n",
+ "B=[1,1,2]\n",
+ "C=[3,-2,4]\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "R=[A[0]+B[0]+C[0],A[1]+B[1]+C[1],A[2]+B[2]+C[2]] #Resultant\n",
+ "R1=[R[0],R[1],R[2]]\n",
+ "mag=sqrt(R[0]**2+R[1]**2+R[2]**2)\n",
+ "\n",
+ "#Unit vector\n",
+ "U=R1/mag \n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print\"The unit vector is \",round(U[0],3),\"i\",round(U[1],3),\"j +\",round(U[2],2),\"k\"\n",
+ "#Answer for k part is incorrect in the textbook\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The unit vector is 0.636 i -0.212 j + 0.74 k\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-5,Page No:642"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initilization of variables\n",
+ "A=[2,-6,-3]\n",
+ "B=[4,3,-1] \n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "AdotB=A[0]*B[0]+A[1]*B[1]+A[2]*B[2] \n",
+ "magA=sqrt(A[0]**2+A[1]**2+A[2]**2) \n",
+ "magB=sqrt(B[0]**2+B[1]**2+B[2]**2)\n",
+ "theta=arccos(AdotB/(magA*magB))*(180/pi) #degrees\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print\"The product of both the vectors is \",round(AdotB)\n",
+ "print\"The angle between them is \",round(theta,1),\"degrees\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The product of both the vectors is -7.0\n",
+ "The angle between them is 101.3 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-6,Page No:643"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initilization of variables\n",
+ "\n",
+ "A=[4,-3,1]\n",
+ "P=[2,3,-1]\n",
+ "Q=[-2,-4,3]\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "B=[Q[0]-P[0],Q[1]-P[1],Q[2]-P[2]]\n",
+ "AdotB=A[0]*B[0]+A[1]*B[1]+A[2]*B[2]\n",
+ "magB=sqrt(B[0]**2+B[1]**2+B[2]**2)\n",
+ "A_costheta=AdotB/magB\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print\"The value of A_costheta is \",round(A_costheta)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The value of A_costheta is 1.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-7,Page No:643"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "F=[5,10,-15]\n",
+ "a=[1,0,3]\n",
+ "b=[3,-1,-6]\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "d=[b[0]-a[0],b[1]-a[1],b[2]-a[2]]\n",
+ "\n",
+ "Work_done=(F[0]*d[0])+(F[1]*d[1])+(F[2]*d[2])\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print\"The work done is \",round(Work_done)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The work done is 135.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-8,Page No:644"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initilization of variables\n",
+ "A=[2,-6,-3]\n",
+ "B=[4,3,-1]\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "AcrossB=[(A[1]*B[2]-B[1]*A[2]),A[2]*B[0]-A[0]*B[2],A[0]*B[1]-A[1]*B[0]]\n",
+ "mag=sqrt(AcrossB[0]**2+AcrossB[1]**2+AcrossB[2]**2)\n",
+ "n=AcrossB/mag\n",
+ "magA=(A[0]**2+A[1]**2+A[2]**2)**0.5\n",
+ "magB=(B[0]**2+B[1]**2+B[2]**2)**0.5\n",
+ "theta=arcsin(mag/(magA*magB))*(180/pi)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print\"The cross prcoduct of the two vectors is \",AcrossB[0],\"i\",AcrossB[1],\"j\",AcrossB[2],\"k\"\n",
+ "print\"The angle between the two is \",round(theta,1),\"degrees\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The cross prcoduct of the two vectors is 15 i -10 j 30 k\n",
+ "The angle between the two is 78.7 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-9,Page No:645"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilizatin of variable\n",
+ "omega=2 # rad/second\n",
+ "A=[0,1,2] \n",
+ "B=[1,3,-2]\n",
+ "P=[3,6,4]\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "# Point co-ordinates of axis of rotation is \n",
+ "S=[1,2,-4]\n",
+ "R=sqrt(S[0]**2+S[1]**2+S[2]**2) # magnitude of position vector\n",
+ "# Unit vector calculations along axis of rotation\n",
+ "R_unit=S/R\n",
+ "w=omega*R_unit\n",
+ "# Position vector calculations\n",
+ "r=(P[0]-A[0])+(P[1]-A[1])+(P[2]-A[2])\n",
+ "v=w*r\n",
+ "# Magnitude of v \n",
+ "v_mag=sqrt(v[0]**2+v[1]**2+v[2]**2)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print\"The linear velocity of point P is \",round(v_mag)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The linear velocity of point P is 20.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-10,Page No:647"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialization\n",
+ "\n",
+ "O=[-2,3,5]\n",
+ "F=[4,4,-1]\n",
+ "P=[1,-2,4]\n",
+ "Q=[5,2,3]\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "r1=[P[0]-O[0],P[1]-O[1],P[2]-O[2]]\n",
+ "\n",
+ "moment=[(r1[1]*F[2]-r1[2]*F[1]),(r1[2]*F[0]-r1[0]*F[2]),(r1[0]*F[1]-r1[1]*F[0])] #momentum\n",
+ "\n",
+ "r2=[Q[0]-O[0],Q[1]-O[1],Q[2]-O[2]]\n",
+ "\n",
+ "moment1=[(r2[1]*F[2]-r2[2]*F[1]),(r2[2]*F[0]-r2[0]*F[2]),(r2[0]*F[1]-r2[1]*F[0])]#momentum\n",
+ "\n",
+ "#result\n",
+ "\n",
+ "print\"The moment about point O is \",round(moment[0],3),\"i\",round(moment[1],3),\"j +\",round(moment[2],3),\"k\"\n",
+ "print\"The moment about point O is \",round(moment1[0],3),\"i\",round(moment1[1],3),\"j +\",round(moment1[2],3),\"k\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The moment about point O is 9.0 i -1.0 j + 32.0 k\n",
+ "The moment about point O is 9.0 i -1.0 j + 32.0 k\n"
+ ]
+ }
+ ],
+ "prompt_number": 62
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-11,Page No:647"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialization\n",
+ "\n",
+ "F=[3,2,-4]\n",
+ "P=[1,-1,2]\n",
+ "O=[2,-1,3]\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "r=[P[0]-O[0],P[1]-O[1],P[2]-O[2]]\n",
+ "\n",
+ "M=[(r[1]*F[2]-r[2]*F[1]),(r[2]*F[0]-r[0]*F[2]),(r[0]*F[1]-r[1]*F[0])]\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print\"The moment of force about point O is \",round(M[0]),\"i\",round(M[1]),\"j +\",round(M[2]),\"k\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The moment of force about point O is 2.0 i -7.0 j + -2.0 k\n"
+ ]
+ }
+ ],
+ "prompt_number": 64
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-12,Page No:648"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initiaization\n",
+ "\n",
+ "A=[4,-1,7]\n",
+ "O=[1,-3,2]\n",
+ "V=[9,6,-2]\n",
+ "\n",
+ "#Clalculation\n",
+ "\n",
+ "mag_v=sqrt(V[0]**2+V[1]**2+V[2]**2)\n",
+ "\n",
+ "F=[(22/mag_v)*V[0],(22/mag_v)*V[1],(22/mag_v)*V[2]]\n",
+ "\n",
+ "r=[A[0]-O[0],A[1]-O[1],A[2]-O[2]]\n",
+ "\n",
+ "M=[r[1]*F[2]-F[1]*r[2],r[0]*F[2]-r[2]*F[0],r[0]*F[1]-r[1]*F[0]]\n",
+ "\n",
+ "#result\n",
+ "\n",
+ "print\"\",round(M[0]),\"i\",\"+\",round(M[1]),\"j\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " -68.0 i + -102.0 j\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-13,Page No:648"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialization\n",
+ "\n",
+ "F=[50,-80,30]\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "#unit vector in u direction\n",
+ "u=[cos(30*(pi/180)),cos(60*(pi/180)),cos(90*(pi/180))]\n",
+ "#unit vector in v direction\n",
+ "v=[1*cos(120*(pi/180)),1*cos(30*(pi/180)),1*cos(90*(pi/180))]\n",
+ "#unit vector in w direction\n",
+ "w=[1*cos(90*(pi/180)),1*cos(90*(pi/180)),1*cos(0*(pi/180))]\n",
+ "\n",
+ "#component of force F\n",
+ "\n",
+ "U=F[0]*u[0]+F[1]*u[1]+F[2]*u[2] #component force along u\n",
+ "V=F[0]*v[0]+F[1]*v[1]+F[2]*v[2] #component force along v\n",
+ "W=F[0]*w[0]+F[1]*w[1]+F[2]*w[2] #component force along w\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print\"the component force along u is \",round(U,1)\n",
+ "print\"the component force along v is \",round(V,2)\n",
+ "print\"the component force along w is \",round(W,1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the component force along u is 3.3\n",
+ "the component force along v is -94.28\n",
+ "the component force along w is 30.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 90
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-14,Page No:649"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialization\n",
+ "\n",
+ "\n",
+ "F_v=100 #N\n",
+ "A=[0,0,0]\n",
+ "B=[0.5,0,0]\n",
+ "C=[0.5,0,1]\n",
+ "D=[0,0,1]\n",
+ "E=[0,0.5,0]\n",
+ "F=[0.5,0.5,0]\n",
+ "G=[0.5,0.5,1]\n",
+ "H=[0,0.5,1]\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "F_vec=F_v/sqrt((F[0]-C[0])**2+(F[1]-C[1])**2+(F[2]-C[2])**2)\n",
+ "F_x=(F[0]-C[0])*F_vec\n",
+ "F_y=(F[1]-C[1])*F_vec\n",
+ "F_z=(F[2]-C[2])*F_vec\n",
+ "\n",
+ "F=[F_x,F_y,F_z]\n",
+ "\n",
+ "#moment about point E\n",
+ "\n",
+ "#taking position vector r directed from E on force F\n",
+ "r_ec=[C[0]-E[0],C[1]-E[1],C[2]-E[2]]\n",
+ "\n",
+ "#M_e=r_ec*F\n",
+ "\n",
+ "M_e=[(r_ec[1]*F[2]-r_ec[2]*F[1]),(r_ec[0]*F[2]-r_ec[2]*F[0]),(r_ec[0]*F[1]-r_ec[1]*F[0])]\n",
+ "\n",
+ "#unit vector in direction AE is n_ae\n",
+ "\n",
+ "n_ae=[0,1,0]\n",
+ "\n",
+ "#moment about axis AE\n",
+ "#M_ae=M_e*n_ae\n",
+ "\n",
+ "M_ae=[M_e[0]*n_ae[0],M_e[1]*n_ae[1],M_e[2]*n_ae[2]] \n",
+ "\n",
+ "#result\n",
+ "\n",
+ "print\"moment of force about E is \",round(M_e[0]),\"i\",round(M_e[1]),\"j +\",round(M_e[2]),\"k\" #answer given in book is wrong \n",
+ "print\"moment of force about axis AE is \",round(M_ae[0]),\"i\",round(M_ae[1]),\"j +\",round(M_ae[2]),\"k\" #answer given in book is wrong "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "moment of force about E is 0.0 i -45.0 j + 22.0 k\n",
+ "moment of force about axis AE is 0.0 i -45.0 j + 0.0 k\n"
+ ]
+ }
+ ],
+ "prompt_number": 103
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-15,Page No:652"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialization\n",
+ "F_1=5 #kN\n",
+ "F_2=7.5 #kN\n",
+ "F_3=10 #kN\n",
+ "A=[0,0,0]\n",
+ "E=[0,1,0]\n",
+ "D=[0,0,2]\n",
+ "F=[3,1,0]\n",
+ "G=[3,1,2]\n",
+ "H=[0,1,2]\n",
+ "#calculation\n",
+ "\n",
+ "F1=[F_1*3**-1*(F[0]-E[0]),F_1/3*(F[1]-E[1]),F_1/3*(F[2]-E[2])] #5/sqrt(9)=5/3\n",
+ "F2=[F_2*(H[0]),F_2*-H[1],F_2*0] #force is only acting in the y direction\n",
+ "F3=[F_3/3.6*(G[0]-E[0]),F_3/3.6*(G[1]-E[1]),F_3/3.6*(G[2]-E[2])] #10/sqrt(13)=10/3.6\n",
+ "\n",
+ "#resultant force R\n",
+ "\n",
+ "#R=F1+F2+F3\n",
+ "R=[F1[0]+F2[0]+F3[0],F1[1]+F2[1]+F3[1],F1[2]+F2[2]+F3[2]]\n",
+ "\n",
+ "#resultant force along axis AE\n",
+ "\n",
+ "r_ae=[E[0]-A[0],E[1]-A[1],E[2]-A[2]]\n",
+ "\n",
+ "r_ad=[D[0]-A[0],D[1]-A[1],D[2]-A[2]]\n",
+ "\n",
+ "#moments of force about A\n",
+ "\n",
+ "#M_ra=r_ae*F1+r_ae*F2+r_ae*F3\n",
+ "\n",
+ "M_ra1=[(r_ae[1]*F1[2]-r_ae[2]*F1[1]),(r_ae[0]*F1[2]-r_ae[2]*F1[0]),(r_ae[0]*F1[1]-r_ae[1]*F1[0])] #r_ae*F1\n",
+ "M_ra2=[(r_ad[1]*F2[2]-r_ad[2]*F2[1]),(r_ad[0]*F2[2]-r_ad[2]*F2[0]),(r_ad[0]*F2[1]-r_ad[1]*F2[0])] #r_ae*F2\n",
+ "M_ra3=[(r_ae[1]*F3[2]-r_ae[2]*F3[1]),(r_ae[0]*F3[2]-r_ae[2]*F3[0]),(r_ae[0]*F3[1]-r_ae[1]*F3[0])] #r_ae*F3\n",
+ "\n",
+ "M_ra=[M_ra1[0]+M_ra2[0]+M_ra3[0],M_ra1[1]+M_ra2[1]+M_ra3[1],M_ra1[2]+M_ra2[2]+M_ra3[2]]\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"resultant force R\",round(R[0],2),\"i\",round(R[1],2),\"j +\",round(R[2],2),\"k\"\n",
+ "print\"moments of all forces about A\",round(M_ra[0],3),\"i +\",round(M_ra[1]),\"j\",round(M_ra[2],3),\"k\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resultant force R 13.33 i -7.5 j + 5.56 k\n",
+ "moments of all forces about A 20.556 i + 0.0 j -13.333 k\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-16,Page No:654"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialization\n",
+ "\n",
+ "F=20 #kN\n",
+ "M_x=76 #kNm\n",
+ "M_y=82 #kNm\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "#Force shifted to P by distance x\n",
+ "x=M_x*F**-1\n",
+ "\n",
+ "#Force shifted to P by distance z\n",
+ "z=M_y*F**-1\n",
+ "\n",
+ "#result\n",
+ "\n",
+ "print\"the force shifted to P by distance x\",round(x,2),\"m\"\n",
+ "print\"the force shited to P by distance y\",round(z,2),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the force shifted to P by distance x 3.8 m\n",
+ "the force shited to P by distance y 4.1 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 109
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-17,Page No:655"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#initialization\n",
+ "\n",
+ "A=[0,4.5,0]\n",
+ "B=[2.8,0,0]\n",
+ "C=[0,0,-2.4]\n",
+ "D=[-2.6,0,1.8]\n",
+ "\n",
+ "#calculations\n",
+ "\n",
+ "#tension in cable AB\n",
+ "x=(B[0]**2+A[1]**2)**0.5\n",
+ "T_ab=[(B[0]-A[0])/x,(B[1]-A[1])/x,(B[2]-A[2])/x]\n",
+ "\n",
+ "#tension in cable AC\n",
+ "y=(C[2]**2+A[1]**2)**0.5\n",
+ "T_ac=[(C[0]-A[0])/y,(C[1]-A[1])/y,(C[2]-A[2])/y]\n",
+ "\n",
+ "#tension in cable AD\n",
+ "z=(D[0]**2+D[2]**2+A[1]**2)**0.5\n",
+ "T_ad=[[(D[0]-A[0])/z,(D[1]-A[1])/z,(D[2]-A[2])/z]]\n",
+ "\n",
+ "#weight acting vertically downwards \n",
+ "W=[0*5000,1*5000,0*5000]\n",
+ "\n",
+ "#Solving using equations of equlibrium\n",
+ "import math\n",
+ "import numpy as np\n",
+ "A=np.array([[0.528,-0.473,0],[0,-0.327,0.47],[0.85,0.818,0.88]])\n",
+ "B=np.array([0,0,5000])\n",
+ "C=np.linalg.solve(A,B)\n",
+ "\n",
+ "#result\n",
+ "print \"T_AB =\",round(C[0],1),\"N\",\"T_AD =\",round(C[1]),\"N\",\"T_AC\",round(C[2],1),\"N\" \n",
+ "#answer varies due to decimal accuracy in python\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "T_AB = 2043.7 N T_AD = 2281.0 N T_AC 1587.2 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-18,Page No:656"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "P=5 # kN\n",
+ "Q=3 # kN\n",
+ "C=5 # kNm # couple\n",
+ "# ref fig.20 # Notations have been assumed\n",
+ "z1=1.5 # m\n",
+ "z2=0.625 # m\n",
+ "z3=0.5 # m\n",
+ "x1=3.5 # m\n",
+ "x2=0.625 # m\n",
+ "# Calculations\n",
+ "# sum M_x=0\n",
+ "R_A=((P*z2)+(Q*z3)+C)*z1**-1 # kN\n",
+ "# M_z=0\n",
+ "R_C=((Q*x1)+(P*x2))*x1**-1 # kN\n",
+ "# sum F_y=0\n",
+ "R_B=P+Q-R_A-R_C # kN\n",
+ "# Results\n",
+ "\n",
+ "print\"The reactions are: \",round(R_A,3),\"kN\",round(R_C,3),\"kN\",round(R_B,2),\"kN\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reactions are: 6.417 kN 3.893 kN -2.31 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 26.26-19,Page No:657"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "\n",
+ "# Initilization of variables\n",
+ "F=2 # kN\n",
+ "W=1 # kN\n",
+ "# Co-ordinates as matrices\n",
+ "A=[0,0,0]\n",
+ "C=[0,0,1.2]\n",
+ "B=[0,0,2.5]\n",
+ "D=[-1,1,0]\n",
+ "E=[1,1,0]\n",
+ "F=[0,0,1]\n",
+ "G=[0,0,2]\n",
+ "# Force vector\n",
+ "f=[0,-2,0]\n",
+ "# Weight vector\n",
+ "w=[0,-1,0]\n",
+ "# Calculations\n",
+ "# we have 5 unknowns: A_x,A_y,A_z,T_FE & T_GD\n",
+ "# we define and solve eqn's 1,2,3,4&5 using matrix as,\n",
+ "P=np.array([[1,0,0,0.58,-0.41],[0,1,0,0.58,0.41],[0,0,1,-0.58,-0.82],[0,0,0,0.58,0.82],[0,0,0,0.58,-0.82]])\n",
+ "Q=np.array([0,3,0,6.25,0])\n",
+ "X=np.linalg.solve(P,Q)\n",
+ "\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The components of reaction at A are: A_x=\",round(X[0],2),\" kN \",\" A_y=\",round(X[1],2),\" kN \",\"and A_z=\",round(X[2],2),\" kN\"\n",
+ "print\"The tensions in the cable are: T_FE=\",round(X[3],2),\" kN \",\"and T_GD=\",round(X[4],1), \"kN \"\n",
+ "# The solution in the textbook is incorrect and yeilds singularity in matrix calculation.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The components of reaction at A are: A_x= -1.56 kN A_y= -1.69 kN and A_z= 6.25 kN\n",
+ "The tensions in the cable are: T_FE= 5.39 kN and T_GD= 3.8 kN \n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter02.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter02.ipynb
new file mode 100755
index 00000000..eba2a295
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter02.ipynb
@@ -0,0 +1,792 @@
+{
+ "metadata": {
+ "name": "chapter2.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2:Concurrent Forces in A Plane"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-1, Page No:10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "P=50 #N\n",
+ "Q=100 #N\n",
+ "beta=150 #degree # angle between P & the horizontal\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "R=(P**2+Q**2-(2*P*Q*cos(beta*(pi/180))))**0.5 # using the Trignometric solution\n",
+ "Alpha=(arcsin(((sin(beta*(pi/180))*Q)/R)))*(180/pi)+15 #Angle in degrees\n",
+ "\n",
+ "#Result\n",
+ "print \"The magnitude of resultant is\",round(R,2),\"N\"\n",
+ "print \"The direction of resultant is\",round(Alpha,2),\"degrees\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-2,Page No:16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "P=50 #N\n",
+ "Q=100 #N\n",
+ "beta=15 #degree # angle between P& the horizontal\n",
+ "theta=45 #degree # angle between the resultant (R) & the horizontal\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "Rx=P*cos(beta*(pi/180))+Q*cos(theta*(pi/180)) #N\n",
+ "Ry=P*sin(beta*(pi/180))+Q*sin(theta*(pi/180)) #N\n",
+ "R=((Rx**2)+(Ry**2))**0.5 #N\n",
+ "alpha=arctan(Ry/Rx)*(180/pi) #degree\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The magnitude of the resultant is \",round(R,2),\"N\"\n",
+ "print\"The ange of the resultant with x-axis is\",round(alpha,2),\"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The magnitude of the resultant is 145.47 N\n",
+ "The ange of the resultant with x-axis is 35.1 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-4,Page No:19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "Tac=3.5 #kN\n",
+ "Tbc=3.5 #kN\n",
+ "alpha=20 #degree #angle made by Tac with -ve X axis\n",
+ "beta=50 #degree #angle made by Tbc with +ve X axis\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "theta=(arctan(((Tac*sin(alpha*(pi/180)))+(Tbc*sin(beta*(pi/180))))/((Tac*cos(alpha*(pi/180)))-(Tbc*cos(beta*(pi/180))))))*(180/pi) #degree\n",
+ "P=Tac*(cos(alpha*(pi/180))-cos(beta*(pi/180)))/(cos(theta*(pi/180))) #kN # from eq'n 1\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The maximum force that can be applied is \",round(P,1),\"kN\"\n",
+ "print\"The direction of applied force is \",round(theta,2),\"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum force that can be applied is 4.0 kN\n",
+ "The direction of applied force is 75.0 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-8,Page No:25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "lAB=0.4 #m\n",
+ "lBC=0.3 #m\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "alpha=arctan(lAB/lBC)*(180/pi) #degree\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The angle which the force should make with the horizontal to keep the edge AB of the body vertical is \",round(alpha,2),\"degrees\" #here alpha=theta"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The angle which the force should make with the horizontal to keep the edge AB of the body vertical is 53.13 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-9,Page No:28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "F=1000 #N\n",
+ "lAB=0.5 #m\n",
+ "lDC=0.25 #m #length of the perpendicular drawn from point C to AB\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "lAC=((0.3)**2+(0.25)**2)**0.5 #m\n",
+ "lBC=((0.20)**2+(0.25)**2)**0.5 #m\n",
+ "Sac=(lAC*F)/(lAB) #N #by law of concurrent forces\n",
+ "Sbc=(lBC*F)/(lAB) #N #by law of concurrent forces\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The axial force in the bar AC(by aw of concurrent forces) is \",round(Sac),\"N\" #the answer in textbook is wrong by 1 N \n",
+ "print\"The axial force in the bar BC(by aw of concurrent forces) is \",round(Sbc),\"N\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The axial force in the bar AC(by aw of concurrent forces) is 781.0 N\n",
+ "The axial force in the bar BC(by aw of concurrent forces) is 640.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-10,Page No:30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#Initilization of variables\n",
+ "\n",
+ "F3=500 #N\n",
+ "alpha=60 #degree #angle made by F3 with F2\n",
+ "beta=40 #degree #angle made by F1 with F3\n",
+ "theta=80 #degree #angle made by F1 with F2\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "# Solving by using law of sines\n",
+ "\n",
+ "F1=(F3*sin(alpha*(pi/180))/sin(theta*(pi/180))) #N #by law of sines\n",
+ "F2=(F3*sin(beta*(pi/180))/sin(theta*(pi/180))) #N #by law of sines\n",
+ "\n",
+ "#Resuts\n",
+ "\n",
+ "print\"The force F1 is \",round(F1,1),\"N\"\n",
+ "print\"The force F2 is \",round(F2,1),\"N\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The force F1 is 439.7 N\n",
+ "The force F2 is 326.4 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-11,Page No:31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "P=5000 #N\n",
+ "lAB=5 #m\n",
+ "lOB=1.443 # m\n",
+ "alpha=30 #degree #angle made by force P with the beam\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "theta=arctan(lOB/lAB)*(180/pi) #degree # eq'n 1\n",
+ "Xa=(P*cos(alpha*(pi/180))) #N #using eq'n 4\n",
+ "Ya=Xa*tan(theta*(pi/180)) #N #from eq'n 3 & 4\n",
+ "Rb=(P*sin(alpha*(pi/180)))-Ya # N # substuting value of Ya in eq'n 5\n",
+ "Ra=((Xa**2)+(Ya**2))**0.5 #N\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The reaction at support A is \",round(Ra,1),\"N\"\n",
+ "print\"The reaction at support B is \",round(Rb),\"N\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction at support A is 4506.8 N\n",
+ "The reaction at support B is 1250.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-12,Page No:32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "W=1000 #N\n",
+ "OD=0.4 #m\n",
+ "AD=0.3 #m\n",
+ "AO=0.5 #m #AO=sqrt((0.4)^2+(0.3)^2)\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "Ra=W*AO/OD #N\n",
+ "Rc=W*AD/OD #N\n",
+ "alpha=arctan(OD/AD)*(180/pi) #degree\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The reaction at support A is \",round(Ra),\"N\" # answer in textbook is wrong by 50 N\n",
+ "print\"The reaction at support B is \",round(Rc),\"N\"\n",
+ "print\"The angle that Rc makes with horizontal \",round(alpha,1),\"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction at support A is 1250.0 N\n",
+ "The reaction at support B is 750.0 N\n",
+ "The angle that Rc makes with horizontal 53.1 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-13,Page No:33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "W=2500 #N #This load acts at point B and C.\n",
+ "alpha=30 #degree # angle made by T1 with +ve y-axis & T2 with +ve x-axis\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "T2=W-(((cos(alpha*(pi/180)))**2/(sin(alpha*(pi/180))))-(sin(alpha*(pi/180)))) # N # substuting eq'n 1 in 2\n",
+ "T1=(T2*cos(30*(pi/180)))/(sin(30*(pi/180))) #N # using eq'n 1\n",
+ "T3=T2 #N # By equilibrium eq'n at point C(sumFx=0)\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"Tension in portion AB is \",round(T1),\"N\" #due to decimal variance the answer varies by 2.0 N\n",
+ "print\"Tension in portion BC is \",round(T2),\"N\" #due to decimal variance the answer varies by 1.0 N\n",
+ "print\"Tension in portion CD is \",round(T3),\"N\" #due to decimal variance the answer varies by 1.0 N"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tension in portion AB is 4328.0 N\n",
+ "Tension in portion BC is 2499.0 N\n",
+ "Tension in portion CD is 2499.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 55
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-15,Page No:35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "d=0.6 #m #diameter of the wheel\n",
+ "r=0.3 #m #radius of the wheel\n",
+ "W=1000 #N #weight of the wheel\n",
+ "h=0.15 #m #height of rectangular block\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "theta=arctan(((h)**0.5)/((d-h)**0.5))\n",
+ "P=(W*tan(theta)) #N # dividing eq'n 1 & 2\n",
+ "\n",
+ "#Resuts\n",
+ "\n",
+ "print\"The force P so that the wheel is just to roll over the block is \",round(P),\"N\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The force P so that the wheel is just to roll over the block is 577.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 56
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-16,Page No:36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "Soa=1000 #N (tension)\n",
+ "alpha=45 #degree #where alpha=(360/8)\n",
+ "theta=67.5 #degree #angle made by bar AO with AB &AH\n",
+ "\n",
+ "#Calcultions\n",
+ "\n",
+ "Sab=Soa*(sin(theta*(pi/180))/sin(alpha*(pi/180))) # N # Using law of sines\n",
+ "Sah=Sab #N\n",
+ "Sob=(Sab*sin((180-2*(theta))*(pi/180)))/sin(theta*(pi/180)) #N\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The axial force in the bar AB is \",round(Sab,1),\"N\" #Compression\n",
+ "print\"The axial force in the bar OB is \",round(Sob),\"N\" #Tension"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The axial force in the bar AB is 1306.6 N\n",
+ "The axial force in the bar OB is 1000.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 60
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-17,Page No:37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "W=500 #N #weight of cylinder\n",
+ "alpha=25 #degree #angle made by OA with horizontal\n",
+ "beta=65 #degree #angle made by OB with horizontal\n",
+ "theta=90 #degree # theta=(alpha+beta)\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "Ra=(W*sin(beta*(pi/180)))/sin(theta*(pi/180)) #N #from equilibrium eq'n\n",
+ "Rb=(W*sin(alpha*(pi/180)))/sin(theta*(pi/180)) #N #from equilibrium eqn's\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The reaction at A is \",round(Ra,1),\"N\"\n",
+ "print\"The reaction at B is \",round(Rb,1),\"N\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction at A is 453.2 N\n",
+ "The reaction at B is 211.3 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 62
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-18,Page No:38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "Wa=1000 #N #weight of sphere A\n",
+ "Wb=400 #N #weight of sphere B\n",
+ "Ra=0.09 #m #radius of sphere A\n",
+ "Rb=0.05 #m #radius of sphere B\n",
+ "theta=33.86 #degree #angle made by Rq with Wb\n",
+ "alpha=60 #degree #angle made by Rl with horizontal\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "Rq=Wb/cos(theta*(pi/180)) #N #using sum Fy=0 for sphere B\n",
+ "Rp=Rq*sin(theta*(pi/180)) #N #using sum Fx=0 for sphere B\n",
+ "Rl=(Rq*sin(theta*(pi/180)))/sin(alpha*(pi/180)) #N #using sum Fx=0 for sphere A\n",
+ "Rn=((Wa)+(Rq*cos(theta*(pi/180)))-(Rl*cos(alpha*(pi/180)))) #N\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The reaction at point P is \",round(Rp,1),\"N\"\n",
+ "print\"The reaction at point L is \",round(Rl),\"N\"\n",
+ "print\"The reaction at point N is \",round(Rn,1),\"N\" # the answer in textbook is wrong by 3.2 N"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction at point P is 268.4 N\n",
+ "The reaction at point L is 310.0 N\n",
+ "The reaction at point N is 1245.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 65
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-19,Page No:39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "P=50 #N\n",
+ "Q=100 #N\n",
+ "alpha=30 #degree #angle made by Rq with +ve Y-axis\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "theta_r=arctan((P*((cos(alpha*(pi/180)))/(sin(alpha*(pi/180))))-Q*tan(alpha*(pi/180)))/(P+Q)) #radians\n",
+ "theta=theta_r*(180/pi)\n",
+ "T=Q/(cos(theta*(pi/180))*(cos(alpha*(pi/180)))/(sin(alpha*(pi/180)))-sin(theta*(pi/180))) #N\n",
+ "\n",
+ "#Results\n",
+ "print\"The tension in the string is \",round(T,1),\"N\"\n",
+ "print\"The angle wich the string makes with the horizontal when the system is in equilibrium is \",round(theta,1),\"degrees\" \n",
+ "#Note:The decimal accuracy in python causes discrepancy in answers"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The tension in the string is 66.1 N\n",
+ "The angle wich the string makes with the horizontal when the system is in equilibrium is 10.9 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-20,Page No:41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "theta1=50.5 #degree #is the angle made between BC & and BE\n",
+ "theta2=36.87 #degree #is te angle ade between BA &BE \n",
+ "g=9.81 #m/s^2\n",
+ "Wa=15*g #N\n",
+ "Wb=40*g #N\n",
+ "Wc=20*g #N\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "R2=Wc/(sin(theta1*(pi/180))) #N #from F.B.D of cylinder C(sum Fy=0)\n",
+ "R4=(Wb+R2*sin(theta1*(pi/180)))/sin(theta2*(pi/180)) #N #from F.B.D of cylinder B(sum Fy=0)\n",
+ "R6=R4*cos(theta2*(pi/180)) #N #from F.B.D of cylinder A(sum Fx=0)\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The reaction between the cylinder A and the wall of the channel is \",round(R6,2),\"N\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction between the cylinder A and the wall of the channel is 784.8 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 70
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-21,Page No:50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilazation of variables\n",
+ "\n",
+ "F=1000 #N\n",
+ "theta=30 #degree #angle made by the force with the beam AB\n",
+ "Lab=3 #m\n",
+ "Lae=2 #m\n",
+ "Lce=1 #m\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "Re=(F*Lab*sin(theta*(pi/180)))/Lae #N #Taking moment at A\n",
+ "Rd=(Re*Lce)/(Lab*sin(theta*(pi/180))) #N #Taking moment about C\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The reaction at D due to force of 1000 N acting at B is \",round(Rd,2),\"N\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction at D due to force of 1000 N acting at B is 500.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 71
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-23,Page No:51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "W=1000 #N\n",
+ "r=0.30 #m #radius of the wheel\n",
+ "h=0.15 #m #height of the obstacle\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "theta=arcsin(1)*(180/pi) #degree #P is mini when sin(theta)=1 from eq'n of P\n",
+ "Pmini=(W*((2*r*h)-(h**2))**0.5)/(r*sin(theta*(pi/180))) #N\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The least force required to just turn the wheel over the block is \",round(Pmini),\"N\"\n",
+ "print\"The angle wich should be made by Pmini with AC is \",round(theta,2),\"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The least force required to just turn the wheel over the block is 866.0 N\n",
+ "The angle wich should be made by Pmini with AC is 90.0 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter03.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter03.ipynb
new file mode 100755
index 00000000..cdcc5a68
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter03.ipynb
@@ -0,0 +1,598 @@
+{
+ "metadata": {
+ "name": "chapter3.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3 : Parallel Forces In A Plane"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3-1,Page No:64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "W=1000 #N\n",
+ "Lab=1 #m\n",
+ "Lac=0.6 #m\n",
+ "theta=60 #degree #angle made by the beam with the horizontal\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "Q=(W*Lac*cos(theta*(pi/180)))/(Lab*cos(theta*(pi/180))) #N # from eq'n 2\n",
+ "P=W-Q #N # from eq'n 1\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The load taken by man P is \",round(P),\"N\"\n",
+ "print\"The load taken by man Q is \",round(Q),\"N\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The load taken by man P is 400.0 N\n",
+ "The load taken by man Q is 600.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3-2,Page No:64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "F=1000 #N\n",
+ "Lab=1 #m\n",
+ "Lbc=0.25 #m\n",
+ "Lac=1.25 #m\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "Rb=(F*Lac)/Lab #N # from eq'n 2\n",
+ "Ra=Rb-F #N # fom eq'n 1\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The reaction (downwards)at support A is \",round(Ra),\"N\"\n",
+ "print\"The reaction (upwards)at support B is \",round(Rb),\"N\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction (downwards)at support A is 250.0 N\n",
+ "The reaction (upwards)at support B is 1250.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3-3,Page No:65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Inilitization of variables\n",
+ "\n",
+ "Lab=12 #m\n",
+ "Mc=40 #kN-m \n",
+ "Md=10 #kN-m\n",
+ "Me=20 #kN-m\n",
+ "Fe=20 #kN #force acting at point E\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "Xa=-(Fe) #kN #take sum Fx=0\n",
+ "a=Me+Md-Mc #N #take moment at A\n",
+ "Rb=a*(Lab)**-1\n",
+ "Ya=-Rb #N #take sum Fy=0\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The vertical reaction (upwards) at A is \",round(Ya,3),\"kN\"\n",
+ "print\"The horizontal reaction (towards A) is \",round(Xa,2),\"kN\"\n",
+ "print\"The reaction (downwards) at B is \",round(Rb,3),\"kN\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The vertical reaction (upwards) at A is 0.833 kN\n",
+ "The horizontal reaction (towards A) is -20.0 kN\n",
+ "The reaction (downwards) at B is -0.833 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3-5,Page No:66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "W=1000 #N\n",
+ "Lad=7.5 #m\n",
+ "Lae=1.5 #m\n",
+ "La1=3.75 #m #distance of 1st 1000N load from pt A\n",
+ "La2=5 #m #distance of 2nd 1000N load from pt A\n",
+ "La3=6 #m # distance of 3rd 1000N load from pt A\n",
+ "\n",
+ "# Calculations (part1)\n",
+ "\n",
+ "#using matrix to solve the given eqn's 1 & 2\n",
+ "\n",
+ "A=np.array([[1 ,-2.5],[3.5 ,-5]])\n",
+ "B=np.array([1000,7250])\n",
+ "C=np.linalg.solve(A,B)\n",
+ "\n",
+ "#Resuts\n",
+ "\n",
+ "print\"The reaction at F i.e Rf is \",round(C[0]),\"N\"\n",
+ "print\"The reaction at D i.e Rd is \",round(C[1]),\"N\"\n",
+ "\n",
+ "#Calculations (part 2)\n",
+ "#Consider combined F.B.D of beams AB,BC &CD. Take moment at A\n",
+ "\n",
+ "Re=((W*La1)+(W*La2)+(W*La3)+(C[1]*Lad)-(C[0]*La3))/Lae #N\n",
+ "Ra=C[1]-Re-C[0]+(3*W) #N #Taking sum of forces in Y direction\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The reaction at pt E i.e Re is \",round(Re),\"N\"\n",
+ "print\"The reaction at pt A i.e Ra is \",round(Ra),\"N\" #acting vertically downwards"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction at F i.e Rf is 3500.0 N\n",
+ "The reaction at D i.e Rd is 1000.0 N\n",
+ "The reaction at pt E i.e Re is 833.0 N\n",
+ "The reaction at pt A i.e Ra is -333.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3-7,Page No:69"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "Ws=2 #kN #weight of scooter\n",
+ "Wd=0.5 #kN #weight of driver\n",
+ "Lab=1 #m\n",
+ "Led=0.8 #m\n",
+ "Leg=0.1 #m\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "Rc=((2*Leg)+(Wd*Led))/Lab #kN #take moment at E\n",
+ "Ra=(2+Wd-Rc)/2 #kN # as Ra=Rb,(Ra+Rb=2*Ra)\n",
+ "Rb=Ra # kN\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The reaction at wheel A is \",round(Ra,2),\"kN\"\n",
+ "print\"The reaction at wheel B is \",round(Rb,2),\"kN\"\n",
+ "print\"The reaction at wheel C is \",round(Rc,2),\"kN\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction at wheel A is 0.95 kN\n",
+ "The reaction at wheel B is 0.95 kN\n",
+ "The reaction at wheel C is 0.6 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3-8,Page No:69"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "W1=15 #N #up\n",
+ "W2=60 #N #down\n",
+ "W3=10 #N #up\n",
+ "W4=25 #N #down\n",
+ "Lab=1.2 #m\n",
+ "Lac=0.4 #m\n",
+ "Lcd=0.3 #m\n",
+ "Ldb=0.5 #m\n",
+ "Lad=0.7 #m\n",
+ "Leb=0.417 #m #Leb=Lab-x\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "#(a) A single force\n",
+ "\n",
+ "Ry=W1-W2+W3-W4 #N #take sum Fy=0\n",
+ "x=((-W2*Lac)+(W3*Lad)-(W4*Lab))/(Ry) #m\n",
+ "\n",
+ "#(b) Single force moment at A\n",
+ "\n",
+ "Ma=(Ry*x) #N-m\n",
+ "\n",
+ "# Single force moment at B\n",
+ "\n",
+ "Mb=W2*Leb #N-m\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The reaction for single force (a) is \",round(Ry,2),\"N\"\n",
+ "print\"The distance of Ry from A is \",round(x,3),\"m\"\n",
+ "print\"The moment at A is \",round(Ma,2),\"N-m\"\n",
+ "print\"The moment at B is \",round(Mb,2),\"N-m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction for single force (a) is -60.0 N\n",
+ "The distance of Ry from A is 0.783 m\n",
+ "The moment at A is -47.0 N-m\n",
+ "The moment at B is 25.02 N-m\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3-9,Page No:71"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "Ra=5000 #N\n",
+ "Ma=10000 #Nm\n",
+ "alpha=60 #degree #angle made by T1 with the pole\n",
+ "beta=45 #degree #angle made by T2 with the pole\n",
+ "theta=30 #degree #angle made by T3 with the pole\n",
+ "Lab=6 #m\n",
+ "Lac=1.5 #m\n",
+ "Lcb=4.5 #m\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "T3=Ma/(4.5*sin(theta*(pi/180))) #N #take moment at B\n",
+ "\n",
+ "# Now we use matrix to solve eqn's 1 & 2 simultaneously,\n",
+ "\n",
+ "A=np.array([[-0.707, 0.866],[0.707, 0.5]])\n",
+ "B=np.array([2222.2,8848.8])\n",
+ "C=np.linalg.solve(A,B)\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"Tension in wire 1 i.e T1 is \",round(C[1],1),\"N\" #answer may vary due to decimal variance\n",
+ "print\"Tension in wire 2 i.e T2 is \",round(C[0],1),\"N\"\n",
+ "print\"Tension in wire 3 i.e T3 is \",round(T3,1),\"N\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tension in wire 1 i.e T1 is 8104.7 N\n",
+ "Tension in wire 2 i.e T2 is 6784.2 N\n",
+ "Tension in wire 3 i.e T3 is 4444.4 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3-10,Page No:76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "w=2000 #N/m\n",
+ "Lab=3 #m\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "W=w*Lab/2 #N# Area under the curve\n",
+ "Lac=(0.6666)*Lab #m#centroid of the triangular load system\n",
+ "Rb=(W*Lac)/Lab #N #sum of moment at A\n",
+ "Ra=W-Rb #N\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The resultant of the distibuted load lies at \",round(Lac),\"m\"\n",
+ "print\"The reaction at support A is \",round(Ra),\"N\"\n",
+ "print\"The reaction at support B is \",round(Rb),\"N\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The resultant of the distibuted load lies at 2.0 m\n",
+ "The reaction at support A is 1000.0 N\n",
+ "The reaction at support B is 2000.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3-12,Page No:78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "w1=1.5 #kN/m # intensity of varying load at the starting point of the beam\n",
+ "w2=4.5 #kN/m # intensity of varying load at the end of the beam\n",
+ "l=6 #m # ength of the beam\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The varying load distribution is divided into a rectangle and a right angled triangle\n",
+ "\n",
+ "W1=w1*l #kN # where W1 is the area of the load diagram(rectangle ABED)\n",
+ "x1=l/2 #m # centroid of the rectangular load system\n",
+ "W2=(w2-w1)*l/2 #kN # where W1 is the area of the load diagram(triangle DCE)\n",
+ "x2=2*l/3 #m # centroid of the triangular load system\n",
+ "W=W1+W2 #kN # W is the resultant\n",
+ "x=((W1*x1)+(W2*x2))/W #m # where x is the distance where the resultant lies\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The resultant of the distributed load system is \",round(W),\"kN\"\n",
+ "print\"The line of action of the resulting load is \",round(x,1),\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The resultant of the distributed load system is 18.0 kN\n",
+ "The line of action of the resulting load is 3.5 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3-13,Page No:78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initiization of variables\n",
+ "\n",
+ "W1=10 #kN #point load acting at D\n",
+ "W2=20 #kN # point load acting at C at an angle of 30 degree\n",
+ "W3=5 #kN/m # intensity of udl acting on span EB of 4m\n",
+ "W4=10 #kN/m # intensity of varying load acting on span BC of 3m\n",
+ "M=25 #kN-m # moment acting at E\n",
+ "theta=30 #degree # angle made by 20 kN load with the beam\n",
+ "Lad=2 #m\n",
+ "Leb=4 #m\n",
+ "Laf=6 #m #distance between the resultant of W3 & point A\n",
+ "Lac=11 #m\n",
+ "Lag=9 #m #distance between the resultant of W4 and point A\n",
+ "Lbc=3 #m\n",
+ "Lab=8 #m\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "Xa=20*cos(theta*(pi/180)) #kN # sum Fx=0\n",
+ "Rb=((W1*Lad)+(-M)+(W3*Leb*Laf)+(W2*sin(theta*(pi/180))*Lac)+((W4*Lbc*Lag)/2))/Lab #kN # taking moment at A\n",
+ "Ya=W1+(W2*sin(theta*(pi/180)))+(W3*Leb)+(W4*Lbc/2)-Rb #kN # sum Fy=0\n",
+ "Ra=(Xa**2+Ya**2)**0.5 #kN # resultant at A\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The horizontal reaction at A i.e Xa is \",round(Xa,2),\"kN\"\n",
+ "print\"The vertical reaction at A i.e Ya is \",round(Ya),\"kN\"\n",
+ "print\"The reaction at A i.e Ra is \",round(Ra),\"kN\"\n",
+ "print\"The reaction at B i.e Rb is \",round(Rb),\"kN\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The horizontal reaction at A i.e Xa is 17.32 kN\n",
+ "The vertical reaction at A i.e Ya is 10.0 kN\n",
+ "The reaction at A i.e Ra is 20.0 kN\n",
+ "The reaction at B i.e Rb is 45.0 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3-14,Page No:79"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "h=4 #m #height of the dam wall\n",
+ "rho_w=1000 # kg/m^3 # density of water\n",
+ "rho_c=2400 # kg/m^3 # density of concrete\n",
+ "g=9.81 # m/s^2\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "P=(rho_w*g*h**2)/2 # The resultant force due to water pressure per unit length of the dam\n",
+ "x=(0.6666)*h #m # distance at which the resutant of the triangular load acts \n",
+ "b=((2*P*h)/(3*h*rho_c*g))**0.5 # m # eq'n required to find the minimum width of the dam\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The minimum width which is to be provided to the dam to prevent overturning about point B is \",round(b,3),\"m\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum width which is to be provided to the dam to prevent overturning about point B is 1.491 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter04.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter04.ipynb
new file mode 100755
index 00000000..e5d35c61
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter04.ipynb
@@ -0,0 +1,138 @@
+{
+ "metadata": {
+ "name": "chapter4.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4 : Centroid , Centre Of Mass And Centre Of Gravity"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4-8,Page No:100"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "b1=20 #cm # width of top flange\n",
+ "t1=5 #cm # thickness of top flange\n",
+ "b2=5 #cm # width of web\n",
+ "t2=15 #cm # thickness or height of the web\n",
+ "b3=30 #cm # width of bottom flange\n",
+ "t3=5 #cm # thickness of bottom flange\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "A1=b1*t1 #cm^2 # area of bottom flange\n",
+ "A2=b2*t2 #cm^2 # area of the web\n",
+ "A3=b3*t3 #cm^2 # area of top flange\n",
+ "y1=t3+t2+(t1*0.5) #cm # y co-ordinate of the centroid of top flange\n",
+ "y2=t3+(t2*0.5) #cm # y co-ordinate of the centroid of the web\n",
+ "y3=t3*0.5 #cm # y co-ordinate of the centroid of the bottom flange\n",
+ "y_c=((A1*y1)+(A2*y2)+(A3*y3))/(A1+A2+A3) #cm # where y_c is the centroid of the un-symmetrycal I-section\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The centroid of the un equal I-section is \",round(y_c,2),\"cm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The centroid of the un equal I-section is 10.96 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4-9,Page No:101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "# The given section is Z-section which is un-symmetrycal about both the axis\n",
+ "\n",
+ "b1=20 #cm # width of bottom flange \n",
+ "t1=5 #cm # thickness of the bottom flange\n",
+ "b2=2.5 #cm # thickness of the web of the flange\n",
+ "t2=15 #cm # depth of the web\n",
+ "b3=10 #cm # width of the top flange\n",
+ "t3=2.5 #cm # thickness of the top flange\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Respective areas\n",
+ "\n",
+ "A1=b1*t1 # cm^2 # area of the bottom flange\n",
+ "A2=b2*t2 # cm^2 # area of the web\n",
+ "A3=b3*t3 # cm^2 # area of the top-flange\n",
+ "\n",
+ "# first we calculate the x co-ordinate of the centroid\n",
+ "\n",
+ "x1=b3-b2+(b1*0.5) #cm # for the bottom flange\n",
+ "x2=b3-(b2*0.5) #cm # for the web\n",
+ "x3=b3*0.5 #cm # for the top flange\n",
+ "x_c=((A1*x1)+(A2*x2)+(A3*x3))/(A1+A2+A3) #cm\n",
+ "\n",
+ "# secondly we calculate the y co-ordinate of the centroid\n",
+ "\n",
+ "y1=t1*0.5 #cm # for the bottom flange\n",
+ "y2=t1+(t2*0.5) #cm # for the web\n",
+ "y3=t1+t2+(t3*0.5) #cm # for the top flange\n",
+ "y_c=((A1*y1)+(A2*y2)+(A3*y3))/(A1+A2+A3) # cm\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The centroid of the cross-sectional area of a Z-section about x-axis is \",round(x_c,2),\"cm\"\n",
+ "print\"The centroid of the cross-sectional area of a Z-section about y-axis is \",round(y_c,2),\"cm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The centroid of the cross-sectional area of a Z-section about x-axis is 13.56 cm\n",
+ "The centroid of the cross-sectional area of a Z-section about y-axis is 7.69 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter05.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter05.ipynb
new file mode 100755
index 00000000..efb681de
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter05.ipynb
@@ -0,0 +1,285 @@
+{
+ "metadata": {
+ "name": "chapter5.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5: General Case Of Forces In Plane"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5-2,Page No:111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Inilization of variables\n",
+ "\n",
+ "W=2000 #N\n",
+ "Lab=2 #m #length of the member from the vertical to the 1st load of 2000 N\n",
+ "Lac=5 #m #length of the member from the vertical to the 2nd load of 2000 N\n",
+ "Lpq=3.5 #m\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "Rq=((W*Lab)+(W*Lac))/Lpq #N #take moment abt. pt P\n",
+ "Xp=Rq #N #sum Fx=0\n",
+ "Yp=2*W #N #sum Fy=0\n",
+ "Rp=(Xp**2+Yp**2)**0.5 #N\n",
+ "\n",
+ "#Resuts\n",
+ "\n",
+ "print\"The reaction at P is \",round(Rp,1),\"N\"\n",
+ "print\"The reaction at Q is \",round(Rq),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction at P is 5656.9 N\n",
+ "The reaction at Q is 4000.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5-3,Page No:112"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "#Initilization of vaiables\n",
+ "\n",
+ "W=25 #N # self weight of the ladder\n",
+ "M=75 #N # weight of the man standing o the ladder\n",
+ "theta=63.43 #degree # angle which the ladder makes with the horizontal\n",
+ "alpha=30 #degree # angle made by the string with the horizontal\n",
+ "Loa=2 #m # spacing between the wall and the ladder\n",
+ "Lob=4 #m #length from the horizontal to the top of the ladder touching the wall(vertical)\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "#Using matrix to solve the simultaneous eqn's 3 & 4\n",
+ "\n",
+ "A=np.array([[2 ,-4],[1, -0.577]])\n",
+ "B=np.array([100,100])\n",
+ "C=np.linalg.solve(A,B)\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The reaction at A i.e Ra is \",round(C[0],2),\"N\"\n",
+ "print\"The reaction at B i.e Rb is \",round(C[1],2),\"N\"\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "T=C[1]/cos(alpha*(pi/180)) #N # from (eqn 1)\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The required tension in the string is \",round(T,2),\"N\"\n",
+ "\n",
+ "#answer may vary due to decimal variance"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction at A i.e Ra is 120.27 N\n",
+ "The reaction at B i.e Rb is 35.14 N\n",
+ "The required tension in the string is 40.57 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5-4,Page No:113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "W=100 #N\n",
+ "theta=60 #degree #angle made by the ladder with the horizontal\n",
+ "alpha=30 #degree #angle made by the ladder with the vertical wall\n",
+ "Lob=4 #m # length from the horizontal to the top of the ladder touching the wall(vertical)\n",
+ "Lcd=2 #m # length from the horizontal to the centre of the ladder where the man stands\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "Lab=Lob*(1/cos(alpha*(pi/180))) #m #length of the ladder\n",
+ "Lad=Lcd*tan(alpha*(pi/180)) #m\n",
+ "Rb=(W*Lad)/Lab #N #take moment at A\n",
+ "Xa=Rb*sin(theta*(pi/180)) #N # From eq'n 1\n",
+ "Ya=W+Rb*cos(theta*(pi/180)) #N #From eq'n 2\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The reaction at B i.e Rb is \",round(Rb),\"N\"\n",
+ "print\"The horizontal reaction at A i.e Xa is \",round(Xa,2),\"N\"\n",
+ "print\"The vertical reaction at A i.e Ya is \",round(Ya,1),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction at B i.e Rb is 25.0 N\n",
+ "The horizontal reaction at A i.e Xa is 21.65 N\n",
+ "The vertical reaction at A i.e Ya is 112.5 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5-5,Page No:114"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "W=100 #N #self weight of the man\n",
+ "alpha=30 #degree # angle made by the ladder with the wall\n",
+ "Lob=4 #m # length from the horizontal to the top of the ladder touching the wall(vertical)\n",
+ "Lcd=2 #m\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "# using the equiblirium equations\n",
+ "\n",
+ "Ya=W #N # From eq'n 2\n",
+ "Lad=Lcd*tan(alpha*(pi/180)) #m #Lad is the distance fom pt A to the point where the line from the cg intersects the horizontal\n",
+ "Rb=(W*Lad)/Lob #N # Taking sum of moment abt A\n",
+ "Xa=Rb #N # From eq'n 1\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The horizontal reaction at A i.e Xa is \",round(Xa,2),\"N\"\n",
+ "print\"The vertical reaction at A i.e Ya is \",round(Ya),\"N\"\n",
+ "print\"The reaction at B i.e Rb is \",round(Rb,2),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The horizontal reaction at A i.e Xa is 28.87 N\n",
+ "The vertical reaction at A i.e Ya is 100.0 N\n",
+ "The reaction at B i.e Rb is 28.87 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5-6,Page No:115"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "d=0.09 #m #diametre of the right circular cylinder\n",
+ "h=0.12 #m #height of the cyinder\n",
+ "W=10 #N # self weight of the bar\n",
+ "l=0.24 #m #length of the bar\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "theta=arctan(h/d)*(180/pi) # angle which the bar makes with the horizontal\n",
+ "Lad=(d**2+h**2)**0.5 #m # Lad is the length of the bar from point A to point B\n",
+ "Rd=(W*h*cos(theta*(pi/180)))/Lad #N # Taking moment at A\n",
+ "Xa=Rd*sin(theta*(pi/180)) #N # sum Fx=0.... From eq'n 1\n",
+ "Ya=W-(Rd*cos(theta*(pi/180))) #N # sum Fy=0..... From eq'n 2\n",
+ "Ra=(Xa**2+Ya**2)**0.5 #resultant of Xa & Ya\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print\"The horizontal reaction at A i.e Xa is \",round(Xa,2),\"N\"\n",
+ "print\"The vertical reaction at A i.e Ya is \",round(Ya,2),\"N\"\n",
+ "print\"Therefore the reaction at A i.e Ra is \",round(Ra,2),\"N\"\n",
+ "print\"The reaction at D i.e Rd is \",round(Rd,2),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The horizontal reaction at A i.e Xa is 3.84 N\n",
+ "The vertical reaction at A i.e Ya is 7.12 N\n",
+ "Therefore the reaction at A i.e Ra is 8.09 N\n",
+ "The reaction at D i.e Rd is 4.8 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter06.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter06.ipynb
new file mode 100755
index 00000000..a0feab39
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter06.ipynb
@@ -0,0 +1,279 @@
+{
+ "metadata": {
+ "name": "chapter6.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Friction"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6-1,Page No:126"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "m=5 #kg # mass of the bock\n",
+ "g=9.81 # m/s^2 # acceleration due to gravity\n",
+ "theta=15 # degree # angle made by the forces (P1 & P2) with the horizontal of the block\n",
+ "mu=0.4 #coefficient of static friction\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "# Case 1. Where P1 is the force required to just pull the bock\n",
+ "\n",
+ "# Solving eqn's 1 & 2 using matrix\n",
+ "A=np.array([[cos(theta*(pi/180)), -mu],[sin(theta*(pi/180)), 1]])\n",
+ "B=np.array([0,(m*g)])\n",
+ "C=np.linalg.solve(A,B)\n",
+ "\n",
+ "# Calculations \n",
+ "\n",
+ "# Case 2. Where P2 is the force required to push the block\n",
+ "\n",
+ "# Solving eqn's 1 & 2 using matrix\n",
+ "P=np.array([[-cos(theta*(pi/180)), mu],[-sin(theta*(pi/180)) ,1]])\n",
+ "Q=np.array([0,(m*g)])\n",
+ "R=np.linalg.solve(P,Q)\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The required pull force P1 is \",round(C[0],2),\"N\" #answer in textbook is wrong\n",
+ "print\"The required push force P2 is \",round(R[0]),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The required pull force P1 is 18.35 N\n",
+ "The required push force P2 is 23.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6-4,Page No:129"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W1=50 # N # weight of the first block\n",
+ "W2=50 # N # weight of the second block\n",
+ "mu_1=0.3 # coefficient of friction between the inclined plane and W1\n",
+ "mu_2=0.2 # coefficient of friction between the inclined plane and W2\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# On adding eq'ns 1&3 and substuting the values of N1 & N2 from eqn's 2&4 in this and on solving for alpha we get,\n",
+ "\n",
+ "alpha=(arctan(((mu_1*W1)+(mu_2*W2))/(W1+W2)))*(180/pi) # degrees\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The inclination of the plane is \",round(alpha),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The inclination of the plane is 14.0 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6-7,Page No:133"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "M=2000 # kg # mass of the car\n",
+ "mu=0.3 # coefficient of static friction between the tyre and the road\n",
+ "g=9.81 # m/s^2 # acc. due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Divide eqn 1 by eqn 2, We get\n",
+ "theta=arctan(mu)*(180/pi) #degree\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The angle of inclination is \",round(theta,1),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The angle of inclination is 16.7 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6-9,Page No:135"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "\n",
+ "# Initilization of variabes\n",
+ "\n",
+ "Wa=1000 #N # weight of block A\n",
+ "Wb=500 #N # weight of block B\n",
+ "theta=15 # degree # angle of the wedge\n",
+ "mu=0.2 # coefficient of friction between the surfaces in contact\n",
+ "phi=7.5 # degrees # used in case 2\n",
+ "\n",
+ "# Caculations \n",
+ "\n",
+ "# CASE (a)\n",
+ "\n",
+ "# consider the equilibrium of upper block A\n",
+ "# rearranging eq'ns 1 &2 and solving them using matrix for N1 & N2\n",
+ "A=np.array([[1 ,-0.4522],[-0.2 ,0.914]])\n",
+ "B=np.array([0,1000])\n",
+ "C=np.linalg.solve(A,B)\n",
+ "\n",
+ "# Now consider the equilibrium of lower block B\n",
+ "# From eq'n 4\n",
+ "N3=Wb+(C[1]*cos(theta*(pi/180)))-(mu*C[1]*sin(theta*(pi/180))) #N\n",
+ "# Now from eq'n 3\n",
+ "P=(mu*N3)+(mu*C[1]*cos(theta*(pi/180)))+(C[1]*sin(theta*(pi/180))) # N\n",
+ "\n",
+ "# CASE (b)\n",
+ "\n",
+ "# The eq'n for required coefficient for the wedge to be self locking is,\n",
+ "mu_req=(theta*pi)/360 # multiplying with (pi/180) to convert it into radians\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The minimum horizontal force (P) which should be applied to raise the block is \",round(P),\"N\"\n",
+ "print\"The required coefficient for the wedge to be self locking is \",round(mu_req,4) #answer in textbook is wrong\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum horizontal force (P) which should be applied to raise the block is 871.0 N\n",
+ "The required coefficient for the wedge to be self locking is 0.1309\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6-13.Page No:141"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "P=100 #N # force acting at 0.2 m from A\n",
+ "Q=200 #N # force acting at any distance x from B\n",
+ "l=1 #m # length of the bar\n",
+ "theta=45 #degree #angle made by the normal reaction at A&B with horizontal\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "#solving eqn's 1 & 2 using matrix for Ra & Rb,\n",
+ "A=np.array([[1, -1],[sin(theta*(pi/180)) ,sin(theta*(pi/180))]])\n",
+ "B=np.array([0,(P+Q)])\n",
+ "C=np.linalg.solve(A,B)\n",
+ "\n",
+ "# Now take moment about B\n",
+ "x=((C[0]*l*sin(theta*(pi/180)))-(P*(l-0.2)))/200 #m # here 0.2 is the distance where 100 N load lies from A\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The minimum value of x at which the load Q=200 N may be applied before slipping impends is \",round(x,2),\"m\" \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum value of x at which the load Q=200 N may be applied before slipping impends is 0.35 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter07.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter07.ipynb
new file mode 100755
index 00000000..aae60e42
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter07.ipynb
@@ -0,0 +1,551 @@
+{
+ "metadata": {
+ "name": "chapter7.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Application Of Friction"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7-1,Page No:152"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "d1=24 # cm # diameter of larger pulley\n",
+ "d2=12 # cm # diameter of smaller pulley\n",
+ "d=30 #cm # seperation betweem 1st & the 2nd pulley\n",
+ "pie=3.14\n",
+ "\n",
+ "# Calcuations\n",
+ "\n",
+ "r1=d1*0.5 #cm # radius of 1st pulley #1/2=0.5\n",
+ "r2=d2*0.5 #cm # radius of 2nd pulley #1/2=0.5\n",
+ "theta=(arcsin((r1-r2)/d))*(180/pi) #degrees \n",
+ "\n",
+ "# Angle of lap\n",
+ "beta_1=180+(2*theta) #degree # for larger pulley\n",
+ "beta_2=180-(2*theta) #degree # for smaller pulley\n",
+ "L=pie*(r1+r2)+(2*d)+((r1-r2)**(2/d)) #cm # Length of the belt\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The angle of lap for the larger pulley is \",round(beta_1,2),\"degree\"\n",
+ "print\"he angle of lap for the smaller pulley is \",round(beta_2,2),\"degree\"\n",
+ "print\"he length of pulley required is \",round(L,2),\"cm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The angle of lap for the larger pulley is 203.07 degree\n",
+ "he angle of lap for the smaller pulley is 156.93 degree\n",
+ "he length of pulley required is 117.52 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7-2,Page No:153"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "d1=0.6 #m # diameter of larger pulley\n",
+ "d2=0.3 #m diameter of smaller pulley\n",
+ "d=3.5 #m #separation between the pulleys\n",
+ "pie=3.14\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "r1=d1*0.5 #m # radius of larger pulley #1/2=0.5\n",
+ "r2=d2*0.5 #m # radius of smaller pulley #1/2=0.5\n",
+ "theta=arcsin((r1+r2)/d)*(180/pi) #degree\n",
+ "\n",
+ "# Angle of lap for both the pulleys is same, i.e\n",
+ "\n",
+ "beta=180+(2*theta) # degree\n",
+ "L=((pie*(r1+r2))+(2*d)+(((r1+r2)**2)/d)) #cm # Length of the belt\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The angle of lap for the pulley is \",round(beta,1),\"degree\"\n",
+ "print\"The length of pulley required is \",round(L,3),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The angle of lap for the pulley is 194.8 degree\n",
+ "The length of pulley required is 8.471 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7-4,Page No:161"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W1=1000 #N\n",
+ "mu=0.25 #coefficient of friction\n",
+ "pie=3.14\n",
+ "beta=pie\n",
+ "T1=W1 # Tension in the 1st belt carrying W1\n",
+ "e=2.718 #constant\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "T2=T1/(e**(mu*beta)) #N # Tension in the 2nd belt\n",
+ "W2=T2 #N\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The minimum weight W2 to keep W1 in equilibrium is \",round(W2),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum weight W2 to keep W1 in equilibrium is 456.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7-5,Page No:162"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "mu=0.5 # coefficient of friction between the belt and the wheel\n",
+ "W=100 #N\n",
+ "theta=45 #degree\n",
+ "e=2.718\n",
+ "Lac=0.75 #m # ength of the lever\n",
+ "Lab=0.25 #m\n",
+ "Lbc=0.50 #m\n",
+ "r=0.25 #m\n",
+ "pie=3.14 # constant\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "beta=((180+theta)*pie)/180 # radian # angle of lap\n",
+ "\n",
+ "# from eq'n 2\n",
+ "T1=(W*Lbc)/Lab #N \n",
+ "T2=T1/(e**(mu*beta)) #N # from eq'n 1\n",
+ "\n",
+ "# consider the F.B.D of the pulley and take moment about its center, we get Braking Moment (M)\n",
+ "M=r*(T1-T2) #N-m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The braking moment (M) exerted by the vertical weight W is \",round(M,2),\"N-m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The braking moment (M) exerted by the vertical weight W is 42.97 N-m\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7-6,Page No:163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initiization of variables\n",
+ "\n",
+ "W= 1000 #N # or 1kN\n",
+ "mu=0.3 # coefficient of friction between the rope and the cylinder\n",
+ "e=2.718 # constant\n",
+ "pie=3.14 # constant\n",
+ "alpha=90 # degree # since 2*alpha=180 egree\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "beta=2*pie*3 # radian # for 3 turn of the rope\n",
+ "\n",
+ "# Here T1 is the larger tension in that section of the rope which is about to slip\n",
+ "T1=W #N\n",
+ "F=W/e**(mu*(1/(sin(alpha*(pi/180))))*(beta)) #N # Here T2=F\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The force required to suport the weight of 1000 N i.e 1kN is \",round(F,1),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The force required to suport the weight of 1000 N i.e 1kN is 3.5 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7-7,Page No:163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "Pw=50 #kW\n",
+ "T_max=1500 #N\n",
+ "v=10 # m/s # velocity of rope\n",
+ "w=4 # N/m # weight of rope\n",
+ "mu=0.2 # coefficient of friction \n",
+ "g=9.81 # m/s^2 # acceleration due to gravity\n",
+ "e=2.718 # constant\n",
+ "pie=3.14 # constant\n",
+ "alpha=30 # degree # since 2*alpha=60 \n",
+ "\n",
+ "# Calcuations\n",
+ "\n",
+ "beta=pie # radian # angle of lap\n",
+ "T_e=(w*v**2)/g # N # where T_e is the centrifugal tension\n",
+ "T1=(T_max)-(T_e) #N\n",
+ "T2=T1/(e**(mu*(1/sin(alpha*(pi/180)))*(beta))) #N # From eq'n T1/T2=e^(mu*cosec(alpha)*beta)\n",
+ "P=(T1-T2)*v*(10**-3) #kW # power transmitted by a single rope\n",
+ "N=Pw/P # Number of ropes required\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The number of ropes required to transmit 50 kW is \",round(N),\"Nos\"\n",
+ "# approx no of ropes is 5\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The number of ropes required to transmit 50 kW is 5.0 Nos\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7-8,Page No:164"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "d1=0.45 #m # diameter of larger pulley\n",
+ "d2=0.20 #m # diameter of smaller pulley\n",
+ "d=1.95 #m # separation between the pulley's\n",
+ "T_max=1000 #N # or 1kN which is the maximum permissible tension\n",
+ "mu=0.20 # coefficient of friction\n",
+ "N=100 # r.p.m # speed of larger pulley\n",
+ "e=2.718 # constant\n",
+ "pie=3.14 # constant\n",
+ "T_e=0 #N # as the data for calculating T_e is not given we assume T_e=0\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "r1=d1*0.5 #m # radius of larger pulley #1/2=0.5\n",
+ "r2=d2*0.5 #m # radius of smaller pulley #1/2=0.5\n",
+ "theta=arcsin((r1+r2)/d)*(180/pi) # degree\n",
+ "\n",
+ "# for cross drive the angle of lap for both the pulleys is same\n",
+ "beta=(180+(2*(theta)))*(pi/180) #radian\n",
+ "T1=T_max-T_e #N\n",
+ "T2=T1/(e**(mu*(beta))) #N # from formulae, T1/T2=e^(mu*beta)\n",
+ "v=((2*pie)*N*r1)/60 # m/s # where v=velocity of belt which is given as, v=wr=2*pie*N*r/60\n",
+ "P=(T1-T2)*v*(10**-3) #kW # Power\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The power transmitted by the cross belt drive is \",round(P,1),\"kW\"\n",
+ "# the approx answer is 1.3 kW The answer given in the book (i.e 1.81kW) is wrong.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The power transmitted by the cross belt drive is 1.2 kW\n"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7-9,Page No:165"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variabes\n",
+ "\n",
+ "b=0.1 #m #width of the belt\n",
+ "t=0.008 #m #thickness of the belt\n",
+ "v=26.67 # m/s # belt speed\n",
+ "pie=3.14 # constant\n",
+ "beta=165 # radian # angle of lap for the smaller belt\n",
+ "mu=0.3 # coefficient of friction\n",
+ "sigma_max=2 # MN/m^2 # maximum permissible stress in the belt\n",
+ "m=0.9 # kg/m # mass of the belt\n",
+ "g=9.81 # m/s^2\n",
+ "e=2.718 # constant\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "A=b*t # m^2 # cross-sectional area of the belt\n",
+ "T_e=m*v**2 # N # where T_e is the Centrifugal tension\n",
+ "T_max=(sigma_max)*(A)*(10**6) # N # maximum tension in the belt\n",
+ "T1=(T_max)-(T_e) # N \n",
+ "T2=T1/(e**((mu*pie*beta)/180)) #N # from formulae T1/T2=e^(mu*beta)\n",
+ "P=(T1-T2)*v*(10**-3) #kW # Power transmitted\n",
+ "T_o=(T1+T2)/2 # N # Initial tension\n",
+ "\n",
+ "# Now calculations to transmit maximum power\n",
+ "\n",
+ "Te=T_max/3 # N # max tension\n",
+ "u=(T_max/(3*m))**0.5 # m/s # belt speed for max power\n",
+ "T_1=T_max-Te # N # T1 for case 2\n",
+ "T_2=T_1/(e**((mu*pie*beta)/180)) # N \n",
+ "P_max=(T_1-T_2)*u*(10**-3) # kW # Max power transmitted\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The initial power transmitted is \",round(P,2),\"kW\"\n",
+ "print\"The initial tension in the belt is \",round(T_o,1),\"N\"\n",
+ "print\"The maximum power that can be transmitted is \",round(P_max,2),\"kW\" # the answer is approx 15.017kW wheres the answer 14.99kW given in book is wrong \n",
+ "print\"The maximum power is transmitted at a belt speed of \",round(u,2),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The initial power transmitted is 14.8 kW\n",
+ "The initial tension in the belt is 682.3 N\n",
+ "The maximum power that can be transmitted is 15.02 kW\n",
+ "The maximum power is transmitted at a belt speed of 24.34 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 54
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7-10,Page No:169"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "p=0.0125 # m # pitch of screw\n",
+ "d=0.1 #m # diameter of the screw\n",
+ "r=0.05 #m # radius of the screw\n",
+ "l=0.5 #m # length of the lever\n",
+ "W=50 #kN # load on the lever\n",
+ "mu=0.20 # coefficient of friction \n",
+ "pie=3.14 #constant\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "theta=arctan(p/(2*pie*r))*(180/pi) #degree # theta is the Helix angle\n",
+ "phi=arctan(mu)*(180/pi) # degree # phi is the angle of friction\n",
+ "\n",
+ "# Taking the leverage due to handle into account,force F1 required is,\n",
+ "F1=(W*(tan(theta*(pi/180)+phi*(pi/180))))*(r/l) #kN\n",
+ "\n",
+ "# To lower the load\n",
+ "F2=(W*(tan(theta*(pi/180)-phi*(pi/180))))*(r/l) #kN # -ve sign of F2 indicates force required is in opposite sense\n",
+ "E=(tan(theta*(pi/180))/tan(theta*(pi/180)+phi*(pi/180)))*100 # % # here E=eata=efficiency in %\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The force required (i.e F1) to raise the weight is \",round(F1,3),\"kN\" #due to decimal variance answer varies by 0.004kN \n",
+ "print\"The force required (i.e F2) to lower the weight is \",round(F2,3),\"kN\"\n",
+ "print\"The efficiency of the jack is \",round(E,2),\"percent\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The force required (i.e F1) to raise the weight is 1.209 kN\n",
+ "The force required (i.e F2) to lower the weight is -0.795 kN\n",
+ "The efficiency of the jack is 16.47 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 58
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7-11,Page No:172"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variabes\n",
+ "\n",
+ "P=20000 #N #Weight of the shaft\n",
+ "D=0.30 #m #diameter of the shaft\n",
+ "R=0.15 #m #radius of the shaft\n",
+ "mu=0.12 # coefficient of friction\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Friction torque T is given by formulae,\n",
+ "T=(0.666)*P*R*mu #N-m #2/3=0.666\n",
+ "M=T #N-m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The frictional torque is \",round(M),\"N-m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The frictional torque is 240.0 N-m\n"
+ ]
+ }
+ ],
+ "prompt_number": 61
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter08.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter08.ipynb
new file mode 100755
index 00000000..666bcf43
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter08.ipynb
@@ -0,0 +1,311 @@
+{
+ "metadata": {
+ "name": "chapter8.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: Simple Lifting Machines"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.8-1,Page No:179"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "VR=6 # Velocity ratio\n",
+ "P=20 #N # Effort\n",
+ "W=100 #N # Load lifted\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "#(a)\n",
+ "\n",
+ "P_actual=P #N\n",
+ "W_actual=W #N\n",
+ "MA=W/P # where, MA= Mechanical advantage\n",
+ "E=(0.833)*100 #% # Where MA/VR=0.833 and E= efficiency\n",
+ "\n",
+ "#(b)\n",
+ "# Now ideal effort required is,\n",
+ "P_ideal=W*VR**-1 #N\n",
+ "# Effort loss in friction is, (Le)\n",
+ "Le=P_actual-P_ideal #N # Effort loss in friction\n",
+ "\n",
+ "#(c)\n",
+ "# Ideal load lifted is,(W_ideal)\n",
+ "W_ideal=P*VR #N \n",
+ "# Frictional load/resistance,\n",
+ "F=W_ideal-W_actual # N\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The efficiency of the machine is \",round(E,3),\"percent\"\n",
+ "print\"(b) The effort loss in friction of the machine is \",round(Le,2),\"N\"\n",
+ "print\"(c) The Frictional load of the machine is \",round(F),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The efficiency of the machine is 83.3 percent\n",
+ "(b) The effort loss in friction of the machine is 3.33 N\n",
+ "(c) The Frictional load of the machine is 20.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.8-2, Page No:180"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import matplotlib.pyplot as plt\n",
+ "%matplotlib inline\n",
+ "\n",
+ "# Initilization of variables\n",
+ "V_r=20 # Velocity ratio\n",
+ "# Values from the table # Variables have been assumed\n",
+ "# Values of W in N\n",
+ "W=[30 ,40 ,50 ,60 ,70 ,80 ,90 ,100]\n",
+ "# P in N\n",
+ "P=[7 ,8.5 ,10 ,11.5 ,13.5 ,14.5 ,16 ,17.5]\n",
+ "M_A=[W[0]*P[0]**-1 ,W[1]*P[1]**-1 ,W[2]*P[2]**-1 ,W[3]*P[3]**-1 ,W[4]*P[4]**-1 ,W[5]*P[5]**-1 ,W[6]*P[6]**-1 ,W[7]*P[7]**-1]\n",
+ "# Efficiency (n)\n",
+ "n=[(V_r**-1)*M_A[0] ,(V_r**-1)*M_A[1] ,(V_r**-1)*M_A[2] ,(V_r**-1)*M_A[3], (V_r**-1)*M_A[4] ,(V_r**-1)*M_A[5] ,(V_r**-1)*M_A[6] ,(V_r**-1)*M_A[7]]*100 # %\n",
+ "# Calculations\n",
+ "# Part (a)- Realtionship between W & P\n",
+ "# Here part a cannot be solved as it has variables which cannot be defined in Scilab. Ref.textbook for the solution\n",
+ "# Part (b)- Graph between W & efficiency n(eta)\n",
+ "x=[0 ,W[0] ,W[1] ,W[2] ,W[3] ,W[4] ,W[5] ,W[6] ,W[7]] # values for W # N\n",
+ "y=[0 ,n[0] ,n[1] ,n[2] ,n[3] ,n[4] ,n[5] ,n[6] ,n[7]] # values for efficiency n (eta) # %\n",
+ "d=transpose(x)\n",
+ "plt.plot(d,y)\n",
+ "plt.show()\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The graph is the solution\"\n",
+ "# The value of m is found by drawing straight line on the graph and by taking its slope. Ref textbook for the solution\n",
+ "# The curve of the graph may differ from textbook because of the graphical calculation.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x4fe1370>"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The graph is the solution\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.8-3,Page No:184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initialization of variables\n",
+ "\n",
+ "W_actual=1360 #N #Load lifted\n",
+ "P_actual=100 #N # Effort\n",
+ "n=4 # no of pulleys\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# for 1st system of pulleys having 4 movable pulleys, Velocity ratio is\n",
+ "VR=2**(n) # Velocity Ratio\n",
+ "\n",
+ "# If the machine were to be ideal(frictionless)\n",
+ "MA=VR # Here, M.A= mechanical advantage \n",
+ "\n",
+ "# For a load of 1360 N, ideal effort required is\n",
+ "P_ideal=W_actual/VR #N\n",
+ "\n",
+ "# Effort loss in friction is,\n",
+ "P_friction=P_actual-P_ideal #N\n",
+ "\n",
+ "# For a effort of 100 N, ideal load lifted is,\n",
+ "W_ideal=VR*100 #N \n",
+ "\n",
+ "# Load lost in friction is,\n",
+ "W_friction=W_ideal-W_actual # N \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The effort wasted in friction is \",round(P_friction,2),\"N\"\n",
+ "print\"(b) The load wasted in friction is \",round(W_friction,2),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The effort wasted in friction is 15.0 N\n",
+ "(b) The load wasted in friction is 240.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.8-4,Page No:185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W=1000 #N # Load to be lifted\n",
+ "n=5 # no. of pulleys\n",
+ "E=75 #% # Efficiency\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Velocity Ratio is given as,\n",
+ "VR=n \n",
+ "\n",
+ "# Mechanical Advantage (MA) is,\n",
+ "MA=(E*0.01)*VR # from formulae, Efficiency=E=MA/VR\n",
+ "P=W/MA #N # Effort required\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The effort required to lift the load of 1000 N is \",round(P,2),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The effort required to lift the load of 1000 N is 266.67 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.8-5,Page No:191 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W=2000 #N # Load to be raised\n",
+ "l=0.70 #m # length of the handle\n",
+ "d=0.05 #m # diameter of the screw\n",
+ "p=0.01 #m # pitch of the screw\n",
+ "mu=0.15 # coefficient of friction at the screw thread\n",
+ "pie=3.14 #constant\n",
+ "E=1 # efficiency\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "phi=arctan(mu)*(180/pi) #degree\n",
+ "theta=arctan(p/(pie*d))*(180/pi) #degree # where theta is the Helix angle\n",
+ "\n",
+ "# Force required at the circumference of the screw is,\n",
+ "P=W*tan(theta*(pi/180)+phi*(pi/180)) # N //\n",
+ "\n",
+ "# Force required at the end of the handle is,\n",
+ "F=(P*(d*0.5))/l #N # as d/2=d*0.5\n",
+ "\n",
+ "# Force required (Ideal case)\n",
+ "VR=2*pie*l/p\n",
+ "MA=E*VR # from formulae E=M.A/V,R\n",
+ "P_ideal=W/MA #N # From formulae, M.A=W/P\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The force required at the end of the handle is \",round(F,2),\"N\"\n",
+ "print\"The force required if the screw jack is considered to be an ideal machine is \",round(P_ideal,2),\"N\" \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The force required at the end of the handle is 15.41 N\n",
+ "The force required if the screw jack is considered to be an ideal machine is 4.55 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter09.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter09.ipynb
new file mode 100755
index 00000000..736fe4f5
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter09.ipynb
@@ -0,0 +1,669 @@
+{
+ "metadata": {
+ "name": "chapter9.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Analysis Of Plane Trusses And Frames"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9-1,Page No:198"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W1=2000 #N # load at joint D of the truss\n",
+ "W2=4000 #N # load at joint E of the truss\n",
+ "Lac=6 #m # length of the tie\n",
+ "Lab=3 #m\n",
+ "Lbc=3 #m\n",
+ "theta=60 #degree # interior angles of the truss\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Here A is simply supported & B is roller support. Now the SUPPORT REACTIONS are given as,\n",
+ "Rc=((W1*(Lab*0.5))+(W2*(Lab+(Lbc*0.5))))/Lac #N # Taking moment at A\n",
+ "Ra=W1+W2-Rc #N # Take sum Fy=0\n",
+ "\n",
+ "# ANALYSIS OF TRUSS BY METHOD OF JOINT\n",
+ "# ASSUMPTION- we consider the,(1) Forces moving towards each other as +ve i.e TENSILE (T) & (2) Forces moving away from each other as -ve i.e COMPRESSIVE (C)\n",
+ "\n",
+ "# (1) JOINT A\n",
+ "Fad=Ra/(sin(theta*(pi/180))) #N #(C) # Using eq'n 2\n",
+ "Fab=Fad*cos(theta*(pi/180)) #N # (T) # Using eq'n 1\n",
+ "\n",
+ "# (2) JOINT C\n",
+ "Fce=Rc/(sin(theta*(pi/180))) #N # (C) # Using eq'n 4\n",
+ "Fcb=Fce*cos(theta*(pi/180)) #N # (T) # Using eq'n 3\n",
+ "\n",
+ "# (3) JOINT D\n",
+ "Fdb=((Fad*sin(theta*(pi/180)))-(W1))/sin(theta*(pi/180)) #N # (T) # Using eq'n 6\n",
+ "Fde=(Fdb*cos(theta*(pi/180)))+(Fad*cos(theta*(pi/180))) #N # (C) # Using eq'n 5\n",
+ "\n",
+ "# (4) JOINT E\n",
+ "Feb=((Fce*cos(theta*(pi/180)))-(Fde))/cos(theta*(pi/180)) #N # (C) # Using eq'n 7\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The Axial Force in member AD (Fad) is \",round(Fad),\"N\"\n",
+ "print\"The Axial Force in member AB (Fab) is \",round(Fab),\"N\"\n",
+ "print\"The Axial Force in member CE (Fce) is \",round(Fce),\"N\"\n",
+ "print\"The Axial Force in member CB (Fcb) is \",round(Fcb,1),\"N\"\n",
+ "print\"The Axial Force in member DB (Fdb) is \",round(Fdb),\"N\"\n",
+ "print\"The Axial Force in member DE (Fde)is \",round(Fde),\"N\"\n",
+ "print\"The Axial Force in member EB (Feb) is \",round(Feb),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Axial Force in member AD (Fad) is 2887.0 N\n",
+ "The Axial Force in member AB (Fab) is 1443.0 N\n",
+ "The Axial Force in member CE (Fce) is 4041.0 N\n",
+ "The Axial Force in member CB (Fcb) is 2020.7 N\n",
+ "The Axial Force in member DB (Fdb) is 577.0 N\n",
+ "The Axial Force in member DE (Fde)is 1732.0 N\n",
+ "The Axial Force in member EB (Feb) is 577.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9-2,Page No:201"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W1=2000 #N (or 2 kN)# load at joint D of the truss\n",
+ "W2=4000 #N (or 4 kN)# load at joint E of the truss\n",
+ "Lac=6 #m # length of the tie\n",
+ "Lab=3 #m\n",
+ "Lbc=3 #m\n",
+ "theta=60 #degree # interior angles of the truss\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Here A is simply supported & B is roller support. Now the SUPPORT REACTIONS are given as,\n",
+ "Rc=((W1*(Lab*0.5))+(W2*(Lab+(Lbc*0.5))))/Lac #N # Taking moment at A\n",
+ "Ra=W1+W2-Rc #N # Take sum Fy=0\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Calculating the axial forces in the respective members by METHOD OF SECTION\n",
+ "# A section is drawn passing through member DE such that it cuts the respective member. Now consider the equilibrium of the left hand portion of the truss. The three unknown forces are Fde, Fdb, & Fab\n",
+ "# Take moment about B\n",
+ "Fde=((3*Ra)-(W1*Lab*sin(30*(pi/180))))/(3*cos(30*(pi/180))) #N # (T)\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The axial force in the member DE (Fde)is \",round(Fde),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The axial force in the member DE (Fde)is 1732.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9-3,Page No:202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W=1 #kN # load on the truss at joint D\n",
+ "theta=45 #degree # angle made by the members AC & BD with the horizontal\n",
+ "Lab=1 #m \n",
+ "Lcd=1 #m # here Lcd= the distance from B to the line of extension drawn from 1kN force on the horizontal\n",
+ "\n",
+ "# Calculations \n",
+ "\n",
+ "# (1) JOINT E\n",
+ "# Here the joint E is in equilibrium under two forces Fec & Fed which are non-collinear. Hence they must be 0. i.e Fec=Fed=0 \n",
+ "Fec=0\n",
+ "Fed=0\n",
+ "\n",
+ "# (2) JOINT D\n",
+ "Fdb=W/sin(theta*(pi/180)) # kN # (C)# sum Fy=0\n",
+ "Fdc=Fdb*cos(theta*(pi/180)) # kN # (T) # sum Fx=0\n",
+ "\n",
+ "# (3) JOINT C\n",
+ "Fca=Fdc/sin(theta*(pi/180)) # kN # (T) # sum Fx=0\n",
+ "Fcb=-(Fca*sin(theta*(pi/180))) # kN # (C) # sum Fy=0\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The axial force in the member DC (Fdc) is \",round(Fdc),\"kN\"\n",
+ "print\"The axial force in the member DB (Fdb) is \",round(Fdb),\"kN\"\n",
+ "print\"The axial force in the member CA (Fca) is \",round(Fca,2),\"kN\" #squareroot of 2 =1.41\n",
+ "print\"The axial force in the member CB (Fcb) is \",round(Fcb),\"kN\"\n",
+ "print\"The axial force in the member EC (Fec) is \",round(Fec),\"kN\"\n",
+ "print\"The axial force in the member ED (Fed) is \",round(Fed),\"kN\"\n",
+ "# Here -ve sign indicates COMPRESSIVE force & +ve indicates TENSILE force\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The axial force in the member DC (Fdc) is 1.0 kN\n",
+ "The axial force in the member DB (Fdb) is 1.0 kN\n",
+ "The axial force in the member CA (Fca) is 1.41 kN\n",
+ "The axial force in the member CB (Fcb) is -1.0 kN\n",
+ "The axial force in the member EC (Fec) is 0.0 kN\n",
+ "The axial force in the member ED (Fed) is 0.0 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9-5,Page No:206"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W1=1000 #N # Load acting at the end pannels and the ridge\n",
+ "W2=2000 #N # Load acting at the intermidiate pannels\n",
+ "Laf=1 #m\n",
+ "Lgf=1 #m\n",
+ "Lag=2 #m\n",
+ "Lbg=1 #m\n",
+ "Lab=3 #m\n",
+ "theta=30 #degree # angle made by the principal rafter with the tie beam\n",
+ "beta=60 #degree # angle made by the slings (i.e members CF & CG) with the tie beam\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# consider the equilibrium of the entire truss as a F.B.D\n",
+ "Xa=2*(W1*sin(theta*(pi/180)))+(W2*sin(theta*(pi/180))) #N # sum Fx=0\n",
+ "Rb=((W2*Laf*cos(theta*(pi/180)))+(W1*Lag*cos(theta*(pi/180))))/Lab # N # Moment at A=0\n",
+ "Ya=2*(W1*cos(theta*(pi/180)))+(W2*cos(theta*(pi/180)))-(Rb) #N # sum Fy=0\n",
+ "\n",
+ "# Now pass a section through the truss such that it cuts the members CE,CG & FG. Now consider the equilibrium of the right hand side of the truss\n",
+ "\n",
+ "# Take moment about C\n",
+ "Ffg=(Rb*(Lbg+0.5))/(0.5*tan(beta*(pi/180))) # N # (T) # Here 0.5 is the half distance of Lgf\n",
+ "\n",
+ "# Take moment about G\n",
+ "Fce=(-Rb*Lbg)/(Lbg*sin(theta*(pi/180))) # N # (C)\n",
+ "\n",
+ "# Take moment about B\n",
+ "Fcg=0/(Lbg*sin(beta*(pi/180))) # N\n",
+ "\n",
+ "# Results \n",
+ "\n",
+ "print\"The axial force in the member FG (Ffg) is \",round(Ffg),\"N\"\n",
+ "print\"The axial force in the member CE (Fce) is \",round(Fce),\"N\"\n",
+ "print\"The axial force in the member CG (Fcg) is \",round(Fcg),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The axial force in the member FG (Ffg) is 2000.0 N\n",
+ "The axial force in the member CE (Fce) is -2309.0 N\n",
+ "The axial force in the member CG (Fcg) is 0.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9-6,Page No:208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W1=100 #N # load acting at pt. C vertically\n",
+ "W2=50 #N # load acting at point B horizontaly\n",
+ "L=2 #m # length of each bar in the hexagonal truss\n",
+ "theta=60 #degree # internal angle of the truss\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# We calculate the values of different members of the truss\n",
+ "HG=L*sin(theta*(pi/180))\n",
+ "AF=L\n",
+ "\n",
+ "# Support A is hinged whereas support F is a roller support. Firstly we find the support reactios as follows,\n",
+ "Rf=(W2*HG)/AF #N # moment at F\n",
+ "Xa=W2 #N # sum Fx=0\n",
+ "Ya=W1-Rf #N # sum Fy=0\n",
+ "\n",
+ "# Now pass a section through the truss cutting the members CD,GD,GE & GF and consider equilibrium of right hand portion of the truss\n",
+ "Fcd=(Rf*(L/2))/(L*sin(theta*(pi/180))) # N (C) # Taking moment about G\n",
+ "\n",
+ "# Now pass a scetion pq cutting the members CB,GB & GA\n",
+ "Fga=((Rf*(L+(L/2)))-(W1*(L/2)))/(L*sin(theta*(pi/180))) # N (T) # Taking moment about B\n",
+ "\n",
+ "# take moment about G\n",
+ "Fcb=((W1*(L/2))+(Rf*(L/2)))/(L*sin(theta*(pi/180))) # N (C)\n",
+ "Fgb=(Fcb*cos(theta*(pi/180)))-(Fga*cos(theta*(pi/180))) # N (T) # sum Fx=0\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The axial force in the member CD (Fcd) is \",round(Fcd),\"N\"\n",
+ "print\"The axial force in the member GB (Fgb) is \",round(Fgb,2),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The axial force in the member CD (Fcd) is 25.0 N\n",
+ "The axial force in the member GB (Fgb) is 32.74 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9-10,Page No:214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W=24 # kN # Load acting at pt C\n",
+ "Laf=12 # m # length of the tie beam\n",
+ "l=4 # m# length of each member in the tie\n",
+ "h=3 # m # height of the slings\n",
+ "Lae=8 # m\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "s=((l**2)+(h**2))**0.5 # m # sloping length \n",
+ "\n",
+ "# From triangle BCD,\n",
+ "theta=arccos(h/s)*(180/pi)\n",
+ "\n",
+ "# SUPPORT REACTIONS\n",
+ "Rf=(W*l)/Laf # kN # take moment at A\n",
+ "Ra=W-Rf # kN # sum Fy=0\n",
+ "\n",
+ "# now pass a sectio mn through the truss and consider te equilibrium of the left hand portion \n",
+ "Fce=(Ra*l)*h**-1 # kN (T) # Take moment at B\n",
+ "\n",
+ "Fbd=((W*l)-(Ra*Lae))*h**-1 # kN (C) # take moment at E\n",
+ "\n",
+ "Fbe=(Ra-W)*(cos(theta*(pi/180)))**-1 # kN\n",
+ "\n",
+ "Fbd2=(-Ra*l)*h**-1 # kN # take moment at C\n",
+ "\n",
+ "Fce2= ((Ra*Lae)-(W*l))*h**-1# kN (T) # take moment at D\n",
+ "\n",
+ "Fcd=(W-Ra)*(cos(theta*(pi/180)))**-1 # kN (T) # sum Fy=0\n",
+ "\n",
+ "# Resuts\n",
+ "\n",
+ "print\"(1) The axial force in the bar CE (Fce) is \",round(Fce,2),\"kN\" \n",
+ "print\"(2) The axial force in the bar BD (Fbd) is \",round(Fbd,3),\"kN\"#answer in textbook is wrong \n",
+ "print\"(3) The axial force in the bar BE (Fbe) is \",round(Fbe,2),\"kN\" \n",
+ "print\"(4) The axial force in the bar CE (Fce) is \",round(Fce2,2),\"kN\"#answer in textbook is wrong \n",
+ "print\"(5) The axial force in the bar BD (Fbd) is \",round(Fbd2,3),\"kN\" \n",
+ "print\"(6) The axial force in the bar CD (Fcd) is \",round(Fcd,2),\"kN\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) The axial force in the bar CE (Fce) is 21.33 kN\n",
+ "(2) The axial force in the bar BD (Fbd) is -10.667 kN\n",
+ "(3) The axial force in the bar BE (Fbe) is -13.33 kN\n",
+ "(4) The axial force in the bar CE (Fce) is 10.67 kN\n",
+ "(5) The axial force in the bar BD (Fbd) is -21.333 kN\n",
+ "(6) The axial force in the bar CD (Fcd) is 13.33 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9-12,Page No:224"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W1=4 # kN # load acting at a distance of 5 m from C\n",
+ "W2=3 # kN # load acting at a distance of 7.5 m from C\n",
+ "L=30 #m # distance AB\n",
+ "L1=15 # dist AC\n",
+ "L2=15 #m #dist BC\n",
+ "l1=10 #m # distance between A and 4 kN load\n",
+ "l2=22.5 #m # distance between A and 3 kN load\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# (1) Reactions\n",
+ "Yb=((W1*l1)+(W2*l2))/L # kN # Take moment at A\n",
+ "Ya=W1+W2-Yb # kN # sum Fy=0\n",
+ "\n",
+ "# Xa=Xb........(eq'n 1) // sum Fx=0\n",
+ "# (2) Dismember\n",
+ "# Member AC. Consider equilibrium of member AC\n",
+ "# Xa=Xc ... Consider thus as eq'n 2 // sum Fx=0\n",
+ "Yc=W1-Ya # kN # sum Fy=0\n",
+ "# Take moment about A\n",
+ "Xc=((W1*l1)-(Yc*L1))/L1 # kN \n",
+ "\n",
+ "# now from eq'n 1 & 2\n",
+ "Xa=Xc # kN\n",
+ "Xb=Xa # kN\n",
+ "\n",
+ "# The components of reactions at A & B are,\n",
+ "Ra=(Xa**2+Ya**2)**0.5 # kN\n",
+ "Rb=(Xb**2+Yb**2)**0.5 # kN\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The reaction at A ( Ra) is \",round(Ra,2),\"kN\"\n",
+ "print\"The reaction at B ( Rb) is \",round(Rb,2),\"kN\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction at A ( Ra) is 4.0 kN\n",
+ "The reaction at B ( Rb) is 4.14 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9-13,Page No:225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W1=2 # kN # load acting at a distance of 1m from point A\n",
+ "W2=1 # kN # load acting at a distance of 1m from point B\n",
+ "theta=30 # degree\n",
+ "L=4 # m # length of the tie beam\n",
+ "l=1 #m # length of each member in the tie\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# (a) Reactions\n",
+ "Yb=((W1*l)+(W2*3*l))*L**-1 # kN # Taking moment about A\n",
+ "Ya=W1+W2-Yb # kN # sum Fy=0\n",
+ "\n",
+ "# (b) Dismember\n",
+ "# MEMBER AB\n",
+ "# Xa=Xb........ (eq'n 1) # sum Fx=0\n",
+ "# MEMBER AC\n",
+ "# Xa=Xc.........(eq'n 2) # sum Fx=0\n",
+ "Yc=W1-Ya # kN # sum Fy=0\n",
+ "# Taking moment about A\n",
+ "Xc=((W1*l)-(Yc*2*l))*(2*tan(theta*(pi/180)))**-1 # kN\n",
+ "# From eq'n 1 & 2\n",
+ "Xa=Xc # kN\n",
+ "Xb=Xa # kN\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The force in tie bar AB is \",round(Xb,3),\"kN\" #due to decimal variance answer varies by 0.44kN\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The force in tie bar AB is 1.299 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9-14,Page No:226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W=1000 # N \n",
+ "r=0.25 # radius of pulley at E \n",
+ "Lab=2 #m\n",
+ "Lad=1 # m\n",
+ "Lbd=1 # m \n",
+ "Ldc=0.75 # m\n",
+ "l1=0.5 #m # c/c distance between bar AB and point E\n",
+ "l2=1.25 # m # dist between rigid support and the weight\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# (a) Reactions\n",
+ "Xa=W # N # sum Fx=0\n",
+ "Yb=((W*l1)+(W*l2))/Lab # N # Take moment about A\n",
+ "Ya=W-Yb # N # sum Fy=0\n",
+ "\n",
+ "# Dismember\n",
+ "# MEMBER ADB\n",
+ "# consider triangle BCD to find theta, where s= length of bar BC, \n",
+ "s=(Lbd**2+Ldc**2)**0.5 # m\n",
+ "theta=arccos(Lbd/s)*(180/pi) # degree\n",
+ "\n",
+ "# equilibrium eq'n of member ADB\n",
+ "Yd=(Ya*Lab)/Lad # take moment about B\n",
+ "Fbc=(Yb+Ya-Yd)/sin(theta*(pi/180)) # N # sum Fy=0\n",
+ "Xd=(Fbc*cos(theta*(pi/180)))+(Xa) # N # sum Fx=0\n",
+ "\n",
+ "# PIN D\n",
+ "Rd=(Xd**2+Yd**2)**0.5 # N # shear force on the pin\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The compressive force in bar BC (Fbc) is \",round(Fbc),\"N\"\n",
+ "print\"The shear force on the pin is \",round(Rd,1),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The compressive force in bar BC (Fbc) is 1250.0 N\n",
+ "The shear force on the pin is 2015.6 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9-15,Page No:229"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initiliztion of variables\n",
+ "\n",
+ "P=5000 # N\n",
+ "theta=45 # degree # angle made by Rd & Re with the horizontal\n",
+ "Lab=3 # m\n",
+ "Lac=3 # m\n",
+ "Lbd=2 # m\n",
+ "Lce=2 # m\n",
+ "l=1.5 # m # dist of load P from B\n",
+ "\n",
+ "# Calculations (BEAM AB )\n",
+ "# Consider the equilibrium of beams \n",
+ "# We are using matrix to solve the simultaneous eqn's \n",
+ "A=[(Lbd*sin(theta*(pi/180))) Lab;(Lce*sin(theta*(pi/180))) -Lac]\n",
+ "B=[(P*l) 0]\n",
+ "C=B*inv(A)\n",
+ "# Calculations (BEAM AC)\n",
+ "Re=C(1) # N (C) # from eq'n 1\n",
+ "Ya=(Re*Lce*sin(theta*(pi/180)))/Lac # N #from eq'n 7\n",
+ "Xa=C(1)*cos(theta*(pi/180)) # N # from eq'n 2\n",
+ "Ra=(Xa^2+Ya^2)**0.5 # N (C)\n",
+ "Yb=P-Ya-(C(1)*sin(theta*(pi/180))) # N (C) # eq'n 3\n",
+ "Yc=Ya-(Re*sin(theta*(pi/180))) # N (T)\n",
+ "\n",
+ "# Results \n",
+ "\n",
+ "print\"(1) The value of axial force (Rd) in bar 2 is \",round(C(1)),\"N\"\n",
+ "print\"(2) The value of axial force (Re) in bar 3 is \",round(Re),\"N\"\n",
+ "print\"(3) The value of axial force (Yb) in bar 1 is \",round(Yb),\"N\"\n",
+ "print\"(4) The value of axial force (Yc) in bar 4 is \",round(Yc),\"N\"\n",
+ "# here consider Yc as +ve coz the assumed direction of the force was compressive which is to be reversed\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "SyntaxError",
+ "evalue": "invalid syntax (<ipython-input-52-17797782c115>, line 16)",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;36m File \u001b[1;32m\"<ipython-input-52-17797782c115>\"\u001b[1;36m, line \u001b[1;32m16\u001b[0m\n\u001b[1;33m A=[(Lbd*sin(theta*(pi/180))) Lab;(Lce*sin(theta*(pi/180))) -Lac]\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
+ ]
+ }
+ ],
+ "prompt_number": 52
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter10.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter10.ipynb
new file mode 100755
index 00000000..3563e562
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter10.ipynb
@@ -0,0 +1,378 @@
+{
+ "metadata": {
+ "name": "chapter10.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10: Uniform Flexible Suspension Cables"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.10-1,Page No:238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W1=400 # N # vertical load at pt C\n",
+ "W2=600 # N # vertical load at pt D\n",
+ "W3=400 # N # vertical load at pt E\n",
+ "l=2 # m # l= Lac=Lcd=Lde=Leb\n",
+ "h=2.25 # m # distance of the cable from top\n",
+ "L=2 # m # dist of A from top\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Solving eqn's 1&2 using MATRIX for Xb & Yb\n",
+ "A=np.array([[-L ,4*l],[-h, 2*l]])\n",
+ "B=np.array([((W1*l)+(W2*2*l)+(W1*3*l)),(W1*l)])\n",
+ "C=np.linalg.solve(A,B)\n",
+ "\n",
+ "# Now consider the F.B.D of BE, Take moment at E\n",
+ "y_e=(C[1]*l)/C[0] # m / here y_e is the distance between E and the top\n",
+ "theta_1=arctan(y_e/l)*(180/pi) # degree # where theta_1 is the angle between BE and the horizontal\n",
+ "T_BE=C[0]/cos(theta_1*(pi/180)) # N (T_BE=T_max)\n",
+ "\n",
+ "# Now consider the F.B.D of portion BEDC\n",
+ "# Take moment at C\n",
+ "y_c=((C[1]*6)-(W3*4)-(W2*2))/(C[0]) # m\n",
+ "theta_4=arctan(((y_c)-(l))/(l))*(180/pi) # degree\n",
+ "T_CA=C[0]/cos(theta_4*(pi/180)) # N # Tension in CA\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(i) The horizontal reaction at B (Xb) is \",round(C[0]),\"N\"\n",
+ "print\"(i) The vertical reaction at B (Yb) is \",round(C[1]),\"N\"\n",
+ "print\"(ii) The sag at point E (y_e) is \",round(y_e,3),\"m\"\n",
+ "print\"(iii) The tension in portion CA (T_CA) is \",round(T_CA,1),\"N\"\n",
+ "print\"(iv) The max tension in the cable (T_max) is \",round(T_BE,1),\"N\" #answer varies due to decimal variance\n",
+ "print\"(iv) The max slope (theta_1) in the cable is \",round(theta_1,1),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) The horizontal reaction at B (Xb) is 1600.0 N\n",
+ "(i) The vertical reaction at B (Yb) is 1100.0 N\n",
+ "(ii) The sag at point E (y_e) is 1.375 m\n",
+ "(iii) The tension in portion CA (T_CA) is 1627.9 N\n",
+ "(iv) The max tension in the cable (T_max) is 1941.6 N\n",
+ "(iv) The max slope (theta_1) in the cable is 34.5 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.10-2,Page No:241"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initiization of variables\n",
+ "\n",
+ "W1=100 # N # Pt load at C\n",
+ "W2=150 # N # Pt load at D\n",
+ "W3=200 # N # Pt load at E\n",
+ "l=1 # m # l=Lac=Lcd=Lde=Leb\n",
+ "h=2 # m # dist between Rb & top\n",
+ "Xa=200 # N\n",
+ "Xb=200 # N\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# consider the F.B.D of entire cable\n",
+ "# Take moment at A\n",
+ "Yb=((W1*l)+(W2*2*l)+(W3*3*l)-(Xb*h))/(4*l) # N\n",
+ "Ya=W1+W2+W3-Yb # N # sum Fy=0\n",
+ "# Now consider the F.B.D of AC\n",
+ "\n",
+ "# Take moment at C,\n",
+ "y_c=(Ya*l)/Xa # m\n",
+ "theta_1=arctan(y_c/l)*(180/pi) # degree\n",
+ "T_AC=Xa/cos(theta_1*(pi/180)) # N # T_AC*cosd(theta_1)=horizontal component of tension in the cable\n",
+ "# here, T_AC=T_max\n",
+ "T_max=(Xa**2+Ya**2)**0.5 # N\n",
+ "T_AC=T_max\n",
+ "\n",
+ "# Now consider the F.B.D of portion ACD\n",
+ "y_d=((Ya*2*l)-(W1*l))/(Xa) # m # taking moment at D\n",
+ "theta_2=arctan(((y_d)-(y_c))/(l))*(180/pi) # degree\n",
+ "T_CD=Xa/(cos(theta_2*(pi/180))) # N \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(i) The component of support reaction at A (Ya) is \",round(Ya),\"N\"\n",
+ "print\"(i) The component of support reaction at B (Yb) is \",round(Yb),\"N\"\n",
+ "print\"(ii) The tension in portion AC (T_AC) of the cable is \",round(T_AC,1),\"N\"\n",
+ "print\"(ii) The tension in portion CD (T_CD) of the cable is \",round(T_CD,1),\"N\"\n",
+ "print\"(iii) The max tension in the cable is \",round(T_max,1),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) The component of support reaction at A (Ya) is 300.0 N\n",
+ "(i) The component of support reaction at B (Yb) is 150.0 N\n",
+ "(ii) The tension in portion AC (T_AC) of the cable is 360.6 N\n",
+ "(ii) The tension in portion CD (T_CD) of the cable is 282.8 N\n",
+ "(iii) The max tension in the cable is 360.6 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.10-3,Page No:246"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "w=75 # kg/m # mass per unit length of thw pipe\n",
+ "l=20 # m # dist between A & B\n",
+ "g=9.81 #m/s^2 # acc due to gravity\n",
+ "y=2 # m # position of C below B\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Let x_b be the distance of point C from B \n",
+ "# In eq'n x_b^2+32*x_b-320=0\n",
+ "a=1\n",
+ "b=32\n",
+ "c=-320\n",
+ "x_b=(-b+(b**2-(4*a*c))**0.5)/(2*a) # m # we get x_b by equating eqn's 1&2\n",
+ "\n",
+ "# Now tension T_0\n",
+ "T_0=((w*g*x_b**2)/(2*y))*(10**-3) #kN # from eq'n 1\n",
+ "\n",
+ "# Now the max tension occurs at point A,hence x is given as,\n",
+ "x=20-x_b # m\n",
+ "w_x=w*g*x*10**(-3) # kN \n",
+ "T_max=((T_0)**2+(w_x)**2)**0.5 # kN # Maximum Tension\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The lowest point C which is situated at a distance (x_b) from support B is \",round(x_b),\"m\"\n",
+ "print\"The maximum tension (T_max) in the cable is \",round(T_max,2),\"kN\"\n",
+ "print\"The minimum tension (T_0) in the cable is \",round(T_0,2),\"kN\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The lowest point C which is situated at a distance (x_b) from support B is 8.0 m\n",
+ "The maximum tension (T_max) in the cable is 14.71 kN\n",
+ "The minimum tension (T_0) in the cable is 11.77 kN\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.10-4,Page No:247"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "m=0.5 # kg/m # mass of the cable per unit length\n",
+ "g=9.81 # m/s^2\n",
+ "x=30#/ m # length AB\n",
+ "y=0.5 # m # dist between C & the horizontal\n",
+ "x_b=15 # m # dist of horizontal from C to B\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "w=m*g # N/m # weight of the cable per unit length\n",
+ "T_0=(w*x_b**2)/(2*y) # N # From eq'n 1\n",
+ "T_B=((T_0)**2+(w*x*0.5)**2)**0.5 # N # Tension in the cable at point B\n",
+ "W=T_B # N # As pulley is frictionless the tension in the pulley on each side is same,so W=T_B\n",
+ "\n",
+ "\n",
+ "# Slope of the cable at B,\n",
+ "theta=arccos(T_0/T_B)*(180/pi) # degree\n",
+ "\n",
+ "# Now length of the cable between C & B is,\n",
+ "S_cb =x_b*(1+((2/3)*(y/x_b)*0.5)) # m\n",
+ "\n",
+ "\n",
+ "# Now total length of the cable AB is,\n",
+ "S_ab=2*S_cb # m \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(i) The magnitude of load W is \",round(W),\"N\"\n",
+ "print\"(ii) The angle of the cable with the horizontal at B is \",round(theta,1),\"degree\"\n",
+ "print\"(iii) The total length of the cable AB is \",round(S_ab),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) The magnitude of load W is 1106.0 N\n",
+ "(ii) The angle of the cable with the horizontal at B is 3.8 degree\n",
+ "(iii) The total length of the cable AB is 30.0 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 116
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.10-5,Page No:249"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "x=30 # m # distance between two electric poles\n",
+ "Tmax=400 # N # Max Pull or tension\n",
+ "w=3 # N/m # weight per unit length of the cable\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The cable is assumed to be parabolic in shape, its eq'n is y=w*x^2/2*T_0.....(eq'n 1). Substuting the co-ordinates of point B (l/2,h), where h is the sag in the cable.This gives, T_0=(w*(l/2)^2)/(2*h)=wl^2/8*h\n",
+ "# Now the maximum pull or tension occurs at B,\n",
+ "T_B=Tmax # N \n",
+ "# Hence T_B=Tmax=sqrt(T_0^2+(w*l/2)^2). On simplyfyingthis eq'n we get, \n",
+ "h=(x**2)**0.5/((16*(((Tmax*2)**2/(w*x)**2)))+(1))**0.5 # m \n",
+ "\n",
+ "# Results \n",
+ "\n",
+ "print\"The smallest value of the sag in the cable is \",round(h,3),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The smallest value of the sag in the cable is 0.843 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 72
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.10-6,Page No:252"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "l=200 # m # length of the cable\n",
+ "m=1000 # kg # mass of the cable\n",
+ "S=50 # m # sag in the cable\n",
+ "s=l/2 # m\n",
+ "g=9.81 # m/s^2\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "w=(m*g)/l # N/m # mass per unit length of the cable\n",
+ "# Substuting the values s=l/2 & y=c+S in eq'n 1 to get the value of c,\n",
+ "c=7500/100 # m \n",
+ "Tmax=((w*c)**2+(w*s)**2)**0.5 # N # Maximum Tension\n",
+ "# To determine the span (2*x) let us use the eq'n of catenary, y=c*cosh(x/c), where y=c+50. On simplyfying we get y/c=cosh(x/c), here let y/c=A\n",
+ "y=c+50\n",
+ "\n",
+ "A=1.666 \n",
+ "x=c*(arccosh(A))*(pi/180)# m \n",
+ "L=2*x*(180/pi) # m # where L= span\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The horizontal distance between the supports and the max Tension (L) is \",round(L),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The horizontal distance between the supports and the max Tension (L) is 165.0 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 114
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter11.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter11.ipynb
new file mode 100755
index 00000000..825638b6
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter11.ipynb
@@ -0,0 +1,22 @@
+{
+ "metadata": {
+ "name": "chapter11.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11:Graphical Analysis:Coplanar Forces and Trusses"
+ ]
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter12.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter12.ipynb
new file mode 100755
index 00000000..9f1a8645
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter12.ipynb
@@ -0,0 +1,411 @@
+{
+ "metadata": {
+ "name": "chapter12.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12: Moment Of Inertia"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.12-7,Page No:285"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "A= 50 # cm^2 # area of the shaded portion\n",
+ "J_A=22.5*10**2 # cm^4 # polar moment of inertia of the shaded portion\n",
+ "d=6 # cm\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "J_c=J_A-(A*d**2) \n",
+ "\n",
+ "# substuting the value of I_x from eq'n 2 in eq'n 1 we get,\n",
+ "I_y=J_c*0.333 # cm^4 # M.O.I about Y-axis # 1/3=0.333\n",
+ "\n",
+ "# Now from eq'n 2,\n",
+ "I_x=2*I_y # cm^4 # M.O.I about X-axis\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The centroidal moment of inertia about X-axis (I_x) is \",round(I_x),\"cm^4\"\n",
+ "print\"The centroidal moment of inertia about Y-axis (I_y) is \",round(I_y),\"cm^4\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The centroidal moment of inertia about X-axis (I_x) is 300.0 cm^4\n",
+ "The centroidal moment of inertia about Y-axis (I_y) is 150.0 cm^4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.12-8,Page No:288"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "b=20 # cm # width of the pate\n",
+ "d=30 # cm # depth of the plate\n",
+ "r=15 # cm # radius of the circular hole\n",
+ "h=20 # cm # distance between the centre of the circle & the x-axis\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# (a) Location of the centroid of the composite area\n",
+ "\n",
+ "A_1=b*d # cm^2 # area of the plate\n",
+ "y_1=d/2 # cm # y-coordinate of the centroid\n",
+ "A_2=(pi*r**2)/4 # cm^2 # area of the circle removed (negative)\n",
+ "y_2=h # cm # y-coordinate of the centroid\n",
+ "y_c=((A_1*y_1)-(A_2*y_2))/(A_1-A_2) # cm # from the bottom edge\n",
+ "\n",
+ "# (b) Moment of Inertia of the composite area about the centroidal x-axis\n",
+ "\n",
+ "# Area (A_1) M.I of area A_1 about x-axis\n",
+ "I_x1=(b*(d**3))/12 # cm^4\n",
+ "\n",
+ "# M.I of the area A_1 about the centroidal x-axis of the composite area (By parallel-axis theorem)\n",
+ "OC_1=15 # cm # from the bottom edge\n",
+ "OC_2=20 # cm\n",
+ "OC=12.9 # cm # from the bottom edge\n",
+ "d_1=OC_1-OC # cm\n",
+ "d_2=OC_2-OC # cm \n",
+ "I_X1=(I_x1)+(A_1*d_1**2) # cm^4\n",
+ "\n",
+ "# Area(A_2) M.I of area A_2 about x-axis\n",
+ "I_x2=(pi*r**4)/64 # cm^2\n",
+ "\n",
+ "#M.I of the area A_2 about the centroidal x-axis of the composite area (By parallel-axis theorem)\n",
+ "I_X2=(I_x2)+(A_2*d_2**2) # cm^4\n",
+ "\n",
+ "# COMPOSITE AREA:M.O.I of the composite area about the centroidal x-axis\n",
+ "I_x=(I_X1)-(I_X2) # cm^4\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The M.O.I of the composite area about the centroidal x-axis is \",round(I_x),\"cm^4\" \n",
+ "#due to decimal variance answer varies by 1cm^4 from textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The M.O.I of the composite area about the centroidal x-axis is 36253.0 cm^4\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.12-9,Page No:289"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "b1=80 # mm # width of the flange pate\n",
+ "d1=20 # mm # depth of the flange plate\n",
+ "b2=40 # mm # width/thickness of the web\n",
+ "d2=60 # mm # depth of the web\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# (a) Location of the centroid of the composite area\n",
+ "A_1=b1*d1 # mm^2 # area of the flange plate\n",
+ "y_1=d2+(d1/2) # mm # y-coordinate of the centroid\n",
+ "A_2=b2*d2 # mm^2 # area of the web\n",
+ "y_2=d2/2 # mm # y-coordinate of the centroid\n",
+ "y_c=((A_1*y_1)+(A_2*y_2))/(A_1+A_2) # mm # from the bottom edge\n",
+ "\n",
+ "# (b) Moment of Inertia of the composite area about the centroidal x-axis\n",
+ "\n",
+ "# Area (A_1) M.I of area A_1 about x-axis\n",
+ "I_x1=(b1*(d1**3))/12 # mm^4\n",
+ "# M.I of the area A_1 about the centroidal x-axis of the composite area (By parallel-axis theorem)\n",
+ "OC_1=70 # mm # from the bottom edge\n",
+ "OC_2=30 # mm # from the bottom edge\n",
+ "OC=y_c # mm # from the bottom edge\n",
+ "d_1=(d2-y_c)+(d1/2) # mm\n",
+ "d_2=y_c-OC_2 # mm \n",
+ "I_X1=(I_x1)+(A_1*d_1**2) # mm^4\n",
+ "\n",
+ "# Area(A_2) M.I of area A_2 about x-axis\n",
+ "I_x2=(b2*d2**3)/12 # mm^4\n",
+ "# M.I of the area A_2 about the centroidal x-axis of the composite area (By parallel-axis theorem)\n",
+ "I_X2=(I_x2)+(A_2*d_2**2) # mm^4\n",
+ "# COMPOSITE AREA:M.O.I of the composite area about the centroidal x-axis\n",
+ "I_x=(I_X1)+(I_X2) # mm^4\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The M.O.I of the composite area about the centroidal x-axis is \",round(I_x),\"mm^4\"\n",
+ "# NOTE: The answer given in the text book is 2.31*10^3 insted of 2.31*10^6.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The M.O.I of the composite area about the centroidal x-axis is 2309333.0 mm^4\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.12-10,Page No:291"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "b1=120 # mm # width of the flange pate of L-section\n",
+ "d1=20 # mm # depth of the flange plate\n",
+ "b2=20 # mm # width/thickness of the web\n",
+ "d2=130 # mm # depth of the web\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# (a) Location of the centroid of the composite area\n",
+ "A_1=b1*d1 # mm^2 # area of the flange plate\n",
+ "A_2=b2*d2 # mm^2 # area of the web\n",
+ "y_1=d2+(d1/2) # mm # y-coordinate of the centroid\n",
+ "y_2=d2/2 # mm # y-coordinate of the centroid\n",
+ "x_1=60 # mm # x-coordinate of the centroid\n",
+ "x_2=110 # mm # x-coordinate of the centroid\n",
+ "y_c=((A_1*y_1)+(A_2*y_2))/(A_1+A_2) # mm # from the bottom edge\n",
+ "x_c=((A_1*x_1)+(A_2*x_2))/(A_1+A_2) # mm # from the bottom edge\n",
+ "\n",
+ "# (b) Moment of Inertia of the composite area about the centroidal x-axis\n",
+ "\n",
+ "# Area (A_1) M.I of area A_1 about x-axis\n",
+ "I_x1=(b1*(d1**3))/12 # mm^4\n",
+ "# M.I of the area A_1 about the centroidal x-axis of the composite area (By parallel-axis theorem)\n",
+ "OC_1=d2+(d1/2) # mm # from the bottom edge\n",
+ "OC_2=d2/2 # mm # from the bottom edge\n",
+ "OC=y_c # mm # from the bottom edge\n",
+ "d_1=(d2-y_c)+(d1/2) # mm\n",
+ "d_2=y_c-OC_2 # mm \n",
+ "I_X1=(I_x1)+(A_1*d_1**2) # mm^4\n",
+ "\n",
+ "# Area(A_2) M.I of area A_2 about x-axis\n",
+ "I_x2=(b2*d2**3)/12 # mm^4\n",
+ "\n",
+ "# M.I of the area A_2 about the centroidal x-axis of the composite area (By parallel-axis theorem)\n",
+ "I_X2=(I_x2)+(A_2*d_2**2) # mm^4\n",
+ "# COMPOSITE AREA:M.O.I of the composite area about the centroidal x-axis\n",
+ "I_x=(I_X1)+(I_X2) # mm^4\n",
+ "\n",
+ "# (c) Moment of Inertia of the composite area about the centroidal y-axis\n",
+ "\n",
+ "# Area (A_1) M.I of area A_1 about y-axis\n",
+ "I_y1=(d1*(b1**3))/12 # mm^4\n",
+ "# M.I of the area A_1 about the centroidal y-axis of the composite area (By parallel-axis theorem)\n",
+ "d_3=x_c-(b1/2) # mm # distance between c &c1 along x axis\n",
+ "I_Y1=(I_y1)+(A_1*d_3**2) # mm^4\n",
+ "\n",
+ "# Area(A_2) M.I of area A_2 about y-axis\n",
+ "I_y2=(d2*b2**3)/12 # mm^4\n",
+ "\n",
+ "# M.I of the area A_2 about the centroidal y-axis of the composite area (By parallel-axis theorem)\n",
+ "d_4=b1-x_c-(b2/2) # mm # distance between c &c2 along x axis\n",
+ "I_Y2=(I_y2)+(A_2*d_4**2) # mm^4\n",
+ "# COMPOSITE AREA:M.O.I of the composite area about the centroidal y-axis\n",
+ "I_y=(I_Y1)+(I_Y2) # mm^4\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The M.O.I of the composite area about the centroidal x-axis is \",round(I_x),\"mm^4\"\n",
+ "print\"The M.O.I of the composite area about the centroidal Y-axis is \",round(I_y),\"mm^4\"\n",
+ "# NOTE: The answer for I_x given in text book is 0.76*10^6 insted of 10.76*10^6\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The M.O.I of the composite area about the centroidal x-axis is 10761666.0 mm^4\n",
+ "The M.O.I of the composite area about the centroidal Y-axis is 6086666.0 mm^4\n"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.12-14,Page No:299"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "b=1 # cm # smaller side of the L-section\n",
+ "h=4 # cm # larger side of the L-section\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# (A) RECTANGLE A_1: Using the paralel axis theorem\n",
+ "Ixy=0\n",
+ "I_xy1=(Ixy)+((h*b)*(b*0.5)*(h*0.5)) # cm**4\n",
+ "\n",
+ "# (B) RECTANGLE A_2: Using the paralel axis theorem\n",
+ "I_xy2=(Ixy)+((b*(h-1))*(1+(1.5))*(b*0.5)) # cm**4\n",
+ "\n",
+ "# Product of inertia of the total area\n",
+ "I_xy=I_xy1+I_xy2 # cm**4\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The Product of inertia of the L-section is \",round(I_xy,2),\"cm^4\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Product of inertia of the L-section is 7.75 cm^4\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.12-15,Page No:300"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "I_x=1548 # cm^4 # M.O.I of the Z-section about X-axis\n",
+ "I_y=2668 # cm^4 # M.O.I of the Z-section about Y-axis\n",
+ "b=12 # cm # width of flange of the Z-section\n",
+ "d=3 # cm # depth of flange of the Z-section\n",
+ "t=2 # cm # thickness of the web of the Z-section\n",
+ "h=6 # cm # depth of the web of the Z-section\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "A_1=b*d # cm^2 # area of top flange\n",
+ "x_1=-5 # cm # distance of the centroid from X-axis for top flange\n",
+ "y_1=4.5 # cm # distance of the centroid from Y-axis for top flange\n",
+ "A_2=t*h # cm^2 # area of web\n",
+ "x_2=0 # cm # distance of the centroid from X-axis for the web\n",
+ "y_2=0 # cm # distance of the centroid from Y-axis for the web\n",
+ "A_3=b*d # cm^2 # area of bottom flange\n",
+ "x_3=5 # cm # distance of the centroid from X-axis for top flange\n",
+ "y_3=-4.5 # cm # distance of the centroid from Y-axis for top flange\n",
+ "\n",
+ "# Product of Inertia of the total area is,\n",
+ "I_xy=((A_1*x_1*y_1)+(A_3*x_3*y_3)) # cm^4\n",
+ "# The direction of the principal axes is,\n",
+ "theta_m=(arctan((2*I_xy)/(I_y-I_x))*(180/pi))/2 # degree\n",
+ "# Principa M.O.I\n",
+ "I_max=((I_x+I_y)/2)+((((I_x-I_y)/2)**2+(I_xy)**2)**0.5) # cm**4\n",
+ "I_mini=((I_x+I_y)/2)-((((I_x-I_y)/2)**2+(I_xy)**2)**0.5) # cm**4\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The principal axes of the section about O is \",round(theta_m,2),\"degree\"\n",
+ "print\"The Maximum value of principal M.O.I is \",round(I_max),\"cm^4\"\n",
+ "print\"The Minimum value of principal M.O.I is \",round(I_mini),\"cm^4\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The principal axes of the section about O is -35.47 degree\n",
+ "The Maximum value of principal M.O.I is 3822.0 cm^4\n",
+ "The Minimum value of principal M.O.I is 394.0 cm^4\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter13.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter13.ipynb
new file mode 100755
index 00000000..690eeb8a
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter13.ipynb
@@ -0,0 +1,121 @@
+{
+ "metadata": {
+ "name": "chapter13.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13: Principle Of Virtual Work"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.13-1,Page No:312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W=1000 # N # weight to be raised\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# From the Principle of virtual work,\n",
+ "P=W/2 # N\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The value of force (i.e P) that can hold the system in equilibrium is \",round(P),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of force (i.e P) that can hold the system in equilibrium is 500.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.13-7,Page No:317"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "P=1000 # N # Force acting at the hinge of the 1st square\n",
+ "Q=1000 # N # Force acting at the hinge of the 2nd square\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Chosing the co-ordinate system with originat A, we can write,\n",
+ "theta=45 # degree\n",
+ "\n",
+ "# Forces that do work are P,Q & X_B. Applying the principle of virtual work & Simplyfying and solving for X_B,\n",
+ "X_B=((2*P)*0.166666)*(cos(theta*(pi/180))/sin(theta*(pi/180))) # N # as 1/6=0.166666\n",
+ "\n",
+ "# Now give a virtual angular displacement to the whole frame about end A such that line AB turns by an angle delta_phi.\n",
+ "\n",
+ "# The force doing work are P,Q&Y_B.Applying the principle of virtual work & Simplyfying this eq'n and solving for Y_B,\n",
+ "Y_B=((3*Q)+P)*0.166666 # N # as 1/6=0.166666\n",
+ "\n",
+ "# Simply by removing the support at A & replacing it by the reactions X_A & Y_A we can obtain,\n",
+ "X_A=X_B # N\n",
+ "Y_A=P+Q-Y_B # N\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The Horizontal component of reaction at A (X_A) is \",round(X_A,1),\"N\"\n",
+ "print\"The Vertical component of reaction at A (Y_A) is \",round(Y_A,1),\"N\"\n",
+ "print\"The Horizontal component of reaction at B (X_B) is \",round(X_B,1),\"N\"\n",
+ "print\"The Vertical component of reaction at B (Y_B) is \",round(Y_B,1),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Horizontal component of reaction at A (X_A) is 333.3 N\n",
+ "The Vertical component of reaction at A (Y_A) is 1333.3 N\n",
+ "The Horizontal component of reaction at B (X_B) is 333.3 N\n",
+ "The Vertical component of reaction at B (Y_B) is 666.7 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter14.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter14.ipynb
new file mode 100755
index 00000000..41eaaa76
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter14.ipynb
@@ -0,0 +1,1056 @@
+{
+ "metadata": {
+ "name": "chapter14.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 14: Rectilinear Motion Of A Particle"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-3,Page No:335"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "a_T=0.18 # m/s^2 # acc of trolley\n",
+ "# Calculations\n",
+ "a_B=-a_T*3**-1 # m/s^2 # from eq'n 4\n",
+ "t=4 # seconds\n",
+ "v_T=a_T*t # m/s # velocity of trolley after 4 seconds\n",
+ "v_B=-v_T*3**-1 # m/s # from eq'n 3\n",
+ "S_T=(0.5)*a_T*t**2 # m # distance moved by trolley in 4 sec\n",
+ "S_B=-S_T*3**-1 # m # from eq'n 2\n",
+ "# Results\n",
+ "\n",
+ "print\"The acceleration of block B is \",round(a_B,2),\"m/s^2\"\n",
+ "print\"The velocity of trolley & the block after 4 sec is \",round(v_T,2),\"m/s\",\"&\",round(v_B,2),\"m/s\"\n",
+ "print\"The distance moved by the trolley & the block is \",round(S_T,2),\"m\",\"&\",round(S_B,2),\"m\"\n",
+ "# The -ve sign indicates that the velocity or the distance travelled is in opposite direction.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The acceleration of block B is -0.06 m/s^2\n",
+ "The velocity of trolley & the block after 4 sec is 0.72 m/s & -0.24 m/s\n",
+ "The distance moved by the trolley & the block is 1.44 m & -0.48 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-4,Page No:338"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initiliztion of variables\n",
+ "\n",
+ "v_B=12 # cm/s # velocity of block B\n",
+ "u=0\n",
+ "s=24 # cm # distance travelled by bock B\n",
+ "t=5 # seconds\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "a_B=v_B**2/(2*s) # cm/s^2 # using eq'n v^2-u^2=28*a*s for block B. Here u=0\n",
+ "a_A=(1.5)*a_B # cm/s^2 # from eq'n 4 # Here a_A is negative which means acceleration is in opposite direction. However we consider +ve values for further calculations\n",
+ "v_A=u+(a_A*t) # m/s # using eq'n v=u+(a*t)\n",
+ "S_A=(u*t)+((0.5)*a_A*t**2) # m # using eq'n S=(u*t)+((1/2)*a*t^2)\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The acceleration of block A (a_A) is \",round(a_A,1),\"cm/s^2\"\n",
+ "print\"The acceleration of block B (a_B) is \",round(a_B),\"cm/s^2\"\n",
+ "print\"The velocity of block A (v_A) after 5 seconds is \",round(v_A,1),\"m/s\"\n",
+ "print\"The position of block A (S_A) after 5 seconds is \",round(S_A,2),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The acceleration of block A (a_A) is 4.5 cm/s^2\n",
+ "The acceleration of block B (a_B) is 3.0 cm/s^2\n",
+ "The velocity of block A (v_A) after 5 seconds is 22.5 m/s\n",
+ "The position of block A (S_A) after 5 seconds is 56.25 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-5,Page No:340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "u=72*1000*60**-2 # km/hr # speed of the vehicle\n",
+ "s=300 # m # distance where the light is turning is red\n",
+ "t=20 # s # traffic light timed to remain red\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Now to find the acceleration we use the eq'n s=u*t+(1/2)*a*t^2\n",
+ "a=(((s)-(u*t))*2)*t**-2 # m/s^2 (Deceleration) \n",
+ "v=(u+(a*t))*(60*60*0.001) # km/hr # here we multiply with (60*60)/1000 to convert m/s to km/hr\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The required uniform acceleration of the car is \",round(a,2),\"m/s^2\"\n",
+ "print\"(b) The speed at which the motorist crosses the traffic light is \",round(v),\"km/hr\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The required uniform acceleration of the car is -0.5 m/s^2\n",
+ "(b) The speed at which the motorist crosses the traffic light is 36.0 km/hr\n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-6,Page No:340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "S=50 # m # height of the tower\n",
+ "v=25 # m/s # velocity at which the stone is thrown up from the foot of the tower\n",
+ "g=9.81 # m/s^2 # acc due to graity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The equation of time for the two stones to cross each other is given as,\n",
+ "t=S/v # seconds\n",
+ "S_1=(0.5)*g*t**2 # m # from the top\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The time (t) at which the two stones cross each other is \",round(t),\"seconds\"\n",
+ "print\"The two stones cross each other (from top) at a distance of \",round(S_1,1),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The time (t) at which the two stones cross each other is 2.0 seconds\n",
+ "The two stones cross each other (from top) at a distance of 19.6 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-7,Page No:341"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Intilization of variables\n",
+ "\n",
+ "acc=0.5 # m/s^2 # acceleration of the elevator\n",
+ "s=25 # m # distance travelled by the elevator from the top\n",
+ "u=0 # m/s\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Using eq'n the eq'n v^2-u^2=2*a*s, solving for v we get,\n",
+ "v=sqrt((2*acc*s)+(u^2)) # m/s \n",
+ "# Now solving eq'n 1 & 2 for t we get, (4.655*t^2)-(5*t)+(25)=0\n",
+ "# Find the roots of the eq'n using the eq'n,t=(-b+sqrt(b^2-(4*a*c)))/(2*a).In this eq'n the values of a,b & c are,\n",
+ "a=4.655\n",
+ "b=-5\n",
+ "c=-25\n",
+ "t=(-b+((b**2)-(4*a*c))**0.5)/(2*a) # seconds\n",
+ "\n",
+ "# Let S_1 be the distance travelled by the elevator after it travels 25 m from top when the stone hits the elevator,This disance S_1 is given as,\n",
+ "S_1=(v*t)+((1/2)*acc*t**2) # m\n",
+ "\n",
+ "# Let S be the total dist from top when the stone hits the elevator,\n",
+ "S=S_1+s # m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The time taken by the stone to hit the elevator is \",round(t,3),\"second\"\n",
+ "print\"The distance (S)travelled by the elevator at the time of impact is \",round(S,2),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The time taken by the stone to hit the elevator is 2.916 second\n",
+ "The distance (S)travelled by the elevator at the time of impact is 40.15 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-9,Page No:343"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "v=60 # km/hr # velocity of the train\n",
+ "d1=15 # km # Distance travelled by the local train from the velocity-time graph (here d1= Area OED)\n",
+ "d2=12 # km # from the velocity-time graph (here d2= Area OABB')\n",
+ "d3=3 # km # from the velocity-time graph (here d3= Area BB'C)\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "t_1=d2*v**-1 # hr # time of travel for first 12 kms\n",
+ "t_2=(2*d3)*v**-1 # hr # time of for next 3 kms\n",
+ "\n",
+ "# Total time of travel for passenger train is given by eq'n\n",
+ "t=t_1+t_2 # hr\n",
+ "\n",
+ "# Now time of travel of the local train (let it be T) is given as,\n",
+ "T=2*t # hr\n",
+ "V_max=2*d1/T # km/hr\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The maximum speed of the local train is \",round(V_max),\"km/hr\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum speed of the local train is 50.0 km/hr\n"
+ ]
+ }
+ ],
+ "prompt_number": 65
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-10,Page No:345"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "a=10 # m/s^2 # acceleration of the particle\n",
+ "S_5th=50 # m # distance travelled by the particle during the 5th second\n",
+ "t=5 # seconds\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The distance travelled by the particle in time t is given by, S=(u*t)+(1/2)*a*t^2.....(consider this as eq'n 1)\n",
+ "# Here, The distance travelled by the particle in the 5th second=The distance travelled in 5 seconds - The distance travelled in 4 seconds..... (consider eq'n 2)\n",
+ "# Using eq'n 1: S_(0-5)=(5*u)+(1/2)*10*5^2 = 5*u+125.....(consider eq'n 3)\n",
+ "# again, S_(0-4)=(4*u)+(1/2)*10*4^2 = 4*u+80....(consider eq'n 4)\n",
+ "\n",
+ "# Now,put eq'n 3&4 in eq'n 2 and solve for u. We get, 50=[(5*u+125)-(4*u+80)] i.e 50=u+45\n",
+ "u=(S_5th)-45 # m/s\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The initial velocity of the particle is \",round(u),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The initial velocity of the particle is 5.0 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 66
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-11,Page No:345"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "# Conditions given are\n",
+ "t=1 # s\n",
+ "x=14.75 # m\n",
+ "v=6.33 # m/s\n",
+ "# Calculations\n",
+ "# We use expression 1,2 & 3 to find distance,velocity & acceleration of the particle after 2 sec\n",
+ "T=2 # sec\n",
+ "X=(T**4*12**-1)-(T**3*3**-1)+(T**2)+(5*T)+9 # m # eq'n 3\n",
+ "V=(T**3*3**-1)-(T**2)+(2*T)+5 # m/s \n",
+ "a=(T**2)-(2*T)+2 # m/s^2\n",
+ "# Results\n",
+ "\n",
+ "print\"The distance travelled by the particle is \",round(X,2),\"m\"\n",
+ "print\"The velocity of the particle is \",round(V,2),\"m/s\"\n",
+ "print\"The acceleration of the particle is \",round(a),\"m/s^2\"\n",
+ "# The answer may vary due to decimal point error\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The distance travelled by the particle is 21.67 m\n",
+ "The velocity of the particle is 7.67 m/s\n",
+ "The acceleration of the particle is 2.0 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-12,Page No:346"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Calculations\n",
+ "# From eq'n 2 it is clear that velocity of the particle becomes zero at t=3 sec\n",
+ "t=3 # sec .. from eq'n 2\n",
+ "# Position of particle at t=3 sec\n",
+ "x=(t**3)-(3*t**2)-(9*t)+12 # m # from eq'n 1\n",
+ "# Acc of particle at t=3 sec\n",
+ "a=6*(t-1) # m/s^2 # from eq'n 3\n",
+ "# Results\n",
+ "\n",
+ "print\"The time at which the velocity of the particle becomes zero is \",round(t),\"sec\"\n",
+ "print\"The position of the partice at t=3 sec is \",round(x),\"m\"\n",
+ "print\"The acceleration of the particle is \",round(a),\"m/s^2\"\n",
+ "# Ref textbook for the graphs\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The time at which the velocity of the particle becomes zero is 3.0 sec\n",
+ "The position of the partice at t=3 sec is -15.0 m\n",
+ "The acceleration of the particle is 12.0 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-15,Page No:354"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "F=250 # N # Force acting on a body\n",
+ "m=100 # kg # mass of the body\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Using the eq'n of motion\n",
+ "a=F*m**-1 # m/s^2 \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The acceleration of the body is \",round(a,2),\"m/s^2\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The acceleration of the body is 2.5 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 70
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-16,Page No:354"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "a=1 # m/s^2 # downward/upward acceleration of the elevator\n",
+ "W=500 # N # Weight of man\n",
+ "g=9.81 # m/s^2 # acceleration due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# (a) Downward Motion \n",
+ "R_1=W*(1-(a/g)) # N # (Assume pressure as R_1)\n",
+ "\n",
+ "# (b) Upward Motion\n",
+ "R_2=W*(1+(a/g)) # N # (Assume pressure as R_2)\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The pressure transmitted to the floor by the man for Downward motion of the elevator is \",round(R_1),\"N\"\n",
+ "print\"(b) The pressure transmitted to the floor by the man for Upward motion of the elevator is \",round(R_2,2),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The pressure transmitted to the floor by the man for Downward motion of the elevator is 449.0 N\n",
+ "(b) The pressure transmitted to the floor by the man for Upward motion of the elevator is 550.97 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 72
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-17,Page no:355"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W=5000 # N # Total weight of the elevator\n",
+ "u=0 # m/s\n",
+ "v=2 # m/s # velocity of the elevator\n",
+ "s=2 # m # distance traveled by the elevator\n",
+ "t=2 # seconds # time to stop the lift\n",
+ "w=600 # N # weight of the man\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Acceleration acquired by the elevator after travelling 2 m is given by,\n",
+ "a=(((v**2-u**2)**0.5/2)) # m/s^2\n",
+ "\n",
+ "# (a) Let T be the the tension in the cable which is given by eq'n,\n",
+ "T=W*(1+(a/g)) # N\n",
+ "\n",
+ "# (b) Motion of man\n",
+ "# Let R be the pressure experinced by the man.Then from the Eq'n of motion of man pressure is given as,\n",
+ "R=w*(1-(a/g)) # N \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The Tensile force in the cable is \",round(T,1),\"N\"\n",
+ "print\"(b) The pressure transmitted to the floor by the man is \",round(R,1),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The Tensile force in the cable is 5509.7 N\n",
+ "(b) The pressure transmitted to the floor by the man is 538.8 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 83
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-18,Page No:355"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "M_1=10 # kg # mass of the 1st block\n",
+ "M_2=5 # kg # mass of the 2nd block\n",
+ "mu=0.25 # coefficient of friction between the blocks and the surface\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "a=g*(M_2-(mu*M_1))/(M_1+M_2) # m/s^2 # from eq'n 5\n",
+ "T=M_1*M_2*g*(1+mu)/(M_1+M_2) # N # from eq'n 6\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The acceleration of the masses is \",round(a,3),\"m/s^2\"\n",
+ "print\"The tension in the string is \",round(T,3),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The acceleration of the masses is 1.635 m/s^2\n",
+ "The tension in the string is 40.875 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 85
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-19,Page No:357"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "M_1=150 # kg # mass of the 1st block\n",
+ "M_2=100 # kg # mass of the 2nd block\n",
+ "mu=0.2 # coefficient of friction between the blocks and the inclined plane\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "theta=45 # degree # inclination of the surface\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# substuting the value of eq'n 3 in eq'n 1 & solving for T,we get value of T as,\n",
+ "T=((M_1*M_2*g)*(sin(theta*(pi/180))+2-(mu*cos(theta*(pi/180)))))/((4*M_1)+(M_2)) # N\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The tension in the string during the motion of the system is \",round(T,1),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The tension in the string during the motion of the system is 539.3 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 87
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-20,Page No:358"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "M_1=5 # kg # mass of the 1st block\n",
+ "theta_1=30 # degree # inclination of the 1st plane\n",
+ "M_2=10 # kg # mass of the 2nd block\n",
+ "theta_2=60 # degree # inclination of the 2nd plane\n",
+ "mu=0.33 # coefficient of friction between the blocks and the inclined plane\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# solving eq'n 1 & 2 for a we get,\n",
+ "a=((((M_2*(sin(theta_2*(pi/180))-(mu*cos(theta_2*(pi/180)))))-(M_1*(sin(theta_1*(pi/180))+(mu*cos(theta_1*(pi/180)))))))*g)/(M_1+M_2) # m/s^2\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The acceleration of the masses is \",round(a,3),\"m/s^2\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The acceleration of the masses is 2.015 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 89
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-21,Page No:359"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "S=5 # m # distance between block A&B\n",
+ "mu_A=0.2 # coefficient of friction between the block A and the inclined plane\n",
+ "mu_B=0.1 # coefficient of friction between the block B and the inclined plane\n",
+ "theta=20 # degree # inclination of the pane\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculatio#\n",
+ "\n",
+ "# EQUATION OF MOTION OF BLOCK A:\n",
+ "# Let a_A & a_B be the acceleration of block A & B.\n",
+ "a_A=(g*sin(theta*(pi/180)))-(mu_A*g*cos(theta*(pi/180))) # m/s^2 # from eq'n 1 & eq'n 2\n",
+ "\n",
+ "# EQUATION OF MOTION OF BLOCK B:\n",
+ "a_B=g*((sin(theta*(pi/180)))-(mu_B*cos(theta*(pi/180)))) # m/s^2 # from eq'n 3 & Rb\n",
+ "\n",
+ "# Now the eq'n for time of collision of the blocks is given as,\n",
+ "t=((S*2)/(a_B-a_A))**0.5 # seconds \n",
+ "S_A=(0.5)*a_A*t**2 # m # distance travelled by block A\n",
+ "S_B=(0.5)*a_B*t**2 # m # distance travelled by block B\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The time before collision is \",round(t,2),\"seconds\"\n",
+ "print\"The distance travelled by block A before collision is \",round(S_A,2),\"m\"\n",
+ "print\"The distance travelled by block B before collision is \",round(S_B,2),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The time before collision is 3.29 seconds\n",
+ "The distance travelled by block A before collision is 8.2 m\n",
+ "The distance travelled by block B before collision is 13.2 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 96
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-22,Page No:361"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "P=50 # N # Weight of the car\n",
+ "Q=100 # N # Weight of the rectangular block\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "b=25 # cm # width of the rectangular block\n",
+ "d=50 # cm # depth of the block\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "a=(Q*g)/(4*P+2*Q) # m/s^2 # from eq'n 4\n",
+ "W=(Q*(P+Q))/(4*P+Q) # N # from eq'n 6\n",
+ "\n",
+ "# Resuts\n",
+ "\n",
+ "print\"The maximum value of weight (W) by which the car can be accelerated is \",round(W),\"N\"\n",
+ "print\"The acceleration is \",round(a,2),\"m/s^2\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum value of weight (W) by which the car can be accelerated is 50.0 N\n",
+ "The acceleration is 2.45 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 99
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-23,Page No:363"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "P=40 # N # weight on puley r_1\n",
+ "Q=60 # N # weight on pulley r_2\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The eq'n for acceleration of pulley Pi.e a_p is,\n",
+ "a_p=(2*P-Q)*(4*P+Q)**-1*2*g # m/s^2\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The downward acceleration of P is \",round(a_p,3),\"m/s^2\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The downward acceleration of P is 1.784 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 112
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-24,Page No:364"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "M=15 # kg # mass of the wedge\n",
+ "m=6 # kg # mass of the block\n",
+ "theta=30 # degree # angle of the wedge\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "a_A=((m*g*cos(theta*(pi/180))*sin(theta*(pi/180)))/((M)+(m*(sin(theta*(pi/180)))**2)))/(g) # g # By eliminating R_1 from eq'n 1&3.\n",
+ "\n",
+ "# Here, assume a_r is the acceleration of block B relative to wedge A which is given by substuting a_A in eq'n 2\n",
+ "\n",
+ "a_r=(((g*sin(theta*(pi/180)))*(m+M))/((M)+(m*(sin(theta*(pi/180)))**2)))/(g) # g\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The acceleration of the wedge is \",round(a_A,3),\"g\"\n",
+ "print\"(b) The acceleration of the bock relative to the wedge is \",round(a_r,3),\"g\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The acceleration of the wedge is 0.157 g\n",
+ "(b) The acceleration of the bock relative to the wedge is 0.636 g\n"
+ ]
+ }
+ ],
+ "prompt_number": 114
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-25,Page No:366"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "P=30 # N # weight on pulley A\n",
+ "Q=20 # N # weight on pulley B\n",
+ "R=10 # N # weight on puey B\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Solving eqn's 6 & 7 using matrix for a & a_1, we get\n",
+ "A=np.array([[70 ,-40],[-10, 30]])\n",
+ "B=np.array([10,-10])\n",
+ "C=np.linalg.solve(A,B)\n",
+ "\n",
+ "# Acceleration of P is given as,\n",
+ "P=C[0] # m/s^2\n",
+ "# Acceleration of Q is given as,\n",
+ "Q=C[1]-C[0] # m/s^2\n",
+ "# Acceleration of R is given as,\n",
+ "R=-(C[1]+C[0]) # m/s^2 # as R is taken to be +ve\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The acceleration of P is \",round(P,2),\"g\"\n",
+ "print\"The acceleration of Q is \",round(Q,2),\"g\"\n",
+ "print\"The acceleration of R is \",round(R,2),\"g\"\n",
+ "# Here the -ve sign indicates deceleration or backward/downward acceleation.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The acceleration of P is -0.06 g\n",
+ "The acceleration of Q is -0.29 g\n",
+ "The acceleration of R is 0.41 g\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.14-30,Page No:372"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W=1 # kg/m # weight of the bar\n",
+ "L_AB=0.6 # m # length of segment AB\n",
+ "L_BC=0.30 # m # length of segment BC\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider the respective F.B.D.\n",
+ "theta_1=arctan(5/12)*(180/pi) # slope of bar AB # here theta_1= atan(theta)\n",
+ "theta_2=arcsin(5/13)*(180/pi) # theta_2=asin(theta)\n",
+ "theta_3=arccos(12/13)*(180/pi) # theta_3=acos(theta)\n",
+ "M_AB=L_AB*W # kg acting at D # Mass of segment AB\n",
+ "M_BC=L_BC*W # kg acting at E # Mass of segment BC\n",
+ "\n",
+ "# The various forces acting on the bar are:\n",
+ "\n",
+ "# Writing the eqn's of dynamic equilibrium\n",
+ "Y_A=(L_AB*g)+(L_BC*g) # N # sum F_y=0\n",
+ "\n",
+ "# Using moment eq'n Sum M_A=0:Here,in this eq'n the values are as follows,\n",
+ "AF=L_BC*cos(theta_3) \n",
+ "DF=L_BC*sin(theta_2)\n",
+ "AH=(L_AB*cos(theta_3))+((L_BC/2)*sin(theta_2))\n",
+ "IG=(L_AB*sin(theta_2)-((L_BC/2)*cos(theta_3)))\n",
+ "\n",
+ "# On simplifying and solving moment eq'n we get a as,\n",
+ "a=(g*(L_AB*(DF)+L_BC*(IG)))*(L_AB*(AF)+L_BC*(AH))**-1\n",
+ "#a=(2*L_AB*L_BC*g*sin(theta_2))-(L_BC*g*(L_BC/2)*cos(theta_3))/((2*L_AB*L_BC*cos(theta_3*(pi/180)))+(L_BC*(L_BC/2)*sin(theta_2*(pi/180)))) # m/s^2\n",
+ "X_A=0.9*a #N # from eq'n of dynamic equilibrium\n",
+ "R_A=(X_A**2+Y_A**2)**0.5 # N # Resultant of R_A\n",
+ "alpha=arctan(Y_A/X_A)*(180/pi) # degree\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The acceleration is \",round(a,4),\"m/s^2\"\n",
+ "print\"The reaction at A (R_A) is \",round(R_A,3),\"N\"\n",
+ "print\"The angle made by the resultant is \",round(alpha,2),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The acceleration is -1.2263 m/s^2\n",
+ "The reaction at A (R_A) is 8.898 N\n",
+ "The angle made by the resultant is -82.87 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter15.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter15.ipynb
new file mode 100755
index 00000000..db992973
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter15.ipynb
@@ -0,0 +1,775 @@
+{
+ "metadata": {
+ "name": "chapter15.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 15: Curvilinear Motion Of A Particle"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-2,Page No:386"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "r=200 # m # radius of the curved road\n",
+ "v_1=72*1000*3600**-1 # m/s # initial speed of the car\n",
+ "v_2=36*1000*3600**-1 # m/s # speed of the car after 10 seconds\n",
+ "t=10 # seconds\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "A_n=v_1**2/r # m/s^2 # normal component of acceleration\n",
+ "A_t=0 # since dv/dt=0 # tangential component of acceeration\n",
+ "delv=v_1-v_2\n",
+ "delt=t-0\n",
+ "a_t=delv/delt # m/s^2 # tangential component of deceleration after the brakes are applied\n",
+ "a_n=v_1**2/r # m/s^2 # normal component of deceleration after the brakes are applied\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The normal component of acceleration is \",round(A_n),\"m/s^2\"\n",
+ "print\"The tangential component of acceleration is \",round(A_t),\"m/s^2\"\n",
+ "print\"The normal component of deceleration is \",round(a_n),\"m/s^2\"\n",
+ "print\"The tangential component of deceleration is \",round(a_t),\"m/s^2\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The normal component of acceleration is 2.0 m/s^2\n",
+ "The tangential component of acceleration is 0.0 m/s^2\n",
+ "The normal component of deceleration is 2.0 m/s^2\n",
+ "The tangential component of deceleration is 1.0 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-3,Page No:387"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Iintilization of variables\n",
+ "\n",
+ "r=250 # m # radius of the curved road\n",
+ "a_t=0.6 # m/s^2 # tangential acceleration\n",
+ "a=0.75 # m/s^2 # total acceleration attained by the car\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "a_n=(a**2-a_t**2)**0.5 # m/s^2\n",
+ "v=sqrt(a_n*r) # m/s\n",
+ "\n",
+ "# Using v=u+a*t\n",
+ "u=0\n",
+ "t=v/a_t # seconds\n",
+ "\n",
+ "# Now using v^2-u^2=2*a*s\n",
+ "s=v**2/(2*a_t) # m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The distance traveled by the car is \",round(s,2),\"m\"\n",
+ "print\"The time for which the car travels is \",round(t,2),\"seconds\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The distance traveled by the car is 93.75 m\n",
+ "The time for which the car travels is 17.68 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-5,Page No:388"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "v=10 # m/s # speed of the car\n",
+ "r=200 # m # radius of the road\n",
+ "t=15 # seconds\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "omega=(v*r**-1) # radian/seconds # angular velocity of the car\n",
+ "\n",
+ "# Velocity in x & y direction is given by eq'n\n",
+ "v_x=omega*r*sin(omega*t) # m/s # value of v_x is -ve but we consider it to be +ve for calculations\n",
+ "v_y=omega*r*cos(omega*t) # m/s\n",
+ "\n",
+ "# Acceleration in x & y direction is given by\n",
+ "a_x=(omega**2)*r*cos(omega*t) # m/s^2 # value of a_x is -ve but we consider it to be +ve for calculations\n",
+ "a_y=(omega**2)*r*sin(omega*t) # m/s^2 # value of a_y is -ve but we consider it to be +ve for calculations\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The component of velocity in X direction (v_x) is \",round(v_x,2),\"m/s\"\n",
+ "print\"The component of velocity in Y direction (v_y) is \",round(v_y,2),\"m/s\"\n",
+ "print\"The component of acceleration in X direction (a_x) is \",round(a_x,3),\"m/s^2\"\n",
+ "print\"The component of acceleration in Y direction (a_y) is \",round(a_y,3),\"m/s^2\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The component of velocity in X direction (v_x) is 6.82 m/s\n",
+ "The component of velocity in Y direction (v_y) is 7.32 m/s\n",
+ "The component of acceleration in X direction (a_x) is 0.366 m/s^2\n",
+ "The component of acceleration in Y direction (a_y) is 0.341 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-6,Page No:392"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "t=1 # seconds\n",
+ "pi=3.14\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# From the equations of r and theta given we find 1st & 2nd derative and substitute t=1sec Here we consider the 1st derative as r_1 & theta_1 and so on...\n",
+ "r=(1.25*t**2)-(0.9*t**3) # m\n",
+ "r_1=(1.25*(2*t))-(0.9*(3*t**2)) # m/s\n",
+ "r_2=2.5-(0.9*3*(2*t)) # m/s^2\n",
+ "theta=(pi/2)*(4*t-3*t**2) # radian\n",
+ "theta_1=(pi/2)*(4-(6*t)) # rad/second\n",
+ "theta_2=(pi/2)*(0-(6*t)) # rad/second^2\n",
+ "\n",
+ "# Velocity of collar P\n",
+ "v_r=r_1 # m/s\n",
+ "v_theta=r*theta_1 # m/s\n",
+ "v=(v_r**2+v_theta**2)**0.5 # m/s\n",
+ "alpha=arctan(v_theta/v_r) # degree\n",
+ "\n",
+ "# Acceleration of the collar P\n",
+ "a_r=r_2-(r*theta_1**2) # m/s^2\n",
+ "a_theta=(r*theta_2)+(2*r_1*theta_1) # m/s^2\n",
+ "a=(a_r**2+a_theta**2)**0.5 # m/s^2\n",
+ "beta=arctan(a_theta/a_r) # degree\n",
+ "\n",
+ "# Acceleration of collar P relative to the rod. Let it be a_relative\n",
+ "a_relative=r_2 # m/s^2 # towards O\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "print\"The velocity of the collar is \",round(v,3),\"m/s\"\n",
+ "print\"The accelaration of the collar is \",round(a,3),\"m/s^2\"\n",
+ "print\"The acceleration of the collar relative to the rod is \",round(a_relative,1),\"m/s^2\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity of the collar is 1.117 m/s\n",
+ "The accelaration of the collar is 6.671 m/s^2\n",
+ "The acceleration of the collar relative to the rod is -2.9 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-7,Page No:394"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Consider the eq'ns of motion from the book\n",
+ "# The notations have been changed for the derivatives of r & theta\n",
+ "# (1) At t=0 s\n",
+ "theta_0=0\n",
+ "theta_1=2*pi # rad/s\n",
+ "theta_2=0\n",
+ "r_0=0\n",
+ "r_1=10 # cm/s\n",
+ "r_2=0\n",
+ "# At t=0.3 s\n",
+ "t=0.3 # sec\n",
+ "theta=2*pi*t # rad\n",
+ "theta1=2*pi # rad/s\n",
+ "theta2=0\n",
+ "r=10*t # cm\n",
+ "r1=10 # cm/s\n",
+ "r2=0\n",
+ "# (i) \n",
+ "#Velocity\n",
+ "v_r=r_1 # cm/s\n",
+ "v_theta=r_0*theta_1\n",
+ "v=sqrt(v_r**2+v_theta**2) # cm/s\n",
+ "# Acceleration\n",
+ "a_r=r_2-(r_0*theta_1**2) # cm/s^2\n",
+ "a_theta=(r_0*theta_2)+(2*r_1*theta_1) # cm/s^2\n",
+ "a=sqrt(a_r**2+a_theta**2) # cm/s^2\n",
+ "# (ii)\n",
+ "# Velocity\n",
+ "V_R=r1 # cm/s\n",
+ "V_theta=r*theta1 # cm/s\n",
+ "V=sqrt(V_R**2+V_theta**2) # cm/s\n",
+ "# Acceleration\n",
+ "A_r=r2-(r*theta1**2) # cm/s^2\n",
+ "A_theta=(r*theta2)+(2*r1*theta1) # cm/s^2\n",
+ "A=sqrt(A_r**2+A_theta**2) # cm/s^2\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity and the acceleration of the partice at t=0 s is \",round(v),\"cm/s\",\"&\",round(a,1),\"cm/s^2\"\n",
+ "print\"The velocity and the acceleration of the partice at t=0.3 s is \",round(V,2),\"cm/s\",\"&\",round(A,2),\"cm/s^2\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity and the acceleration of the partice at t=0 s is 10.0 cm/s & 125.7 cm/s^2\n",
+ "The velocity and the acceleration of the partice at t=0.3 s is 21.34 cm/s & 172.68 cm/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-9,Page No:404"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Calculations\n",
+ "# Tension in the wire before it is cut\n",
+ "T_ab=1/((2.747*0.643)+(0.766)) # From eqn's 1 & 2..Here T_ab is multiplied with W (i.e weight of small ball) \n",
+ "T_AB=cos(40*(pi/180)) # Tension in the wire after the wire is cut. Again T_AB is multiplied with W.\n",
+ "# Results\n",
+ "\n",
+ "print\"The tension in the wire before and after it is cut is respectively \",round(T_ab,3),\"W\",\"&\",round(T_AB,3),\"W\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The tension in the wire before and after it is cut is respectively 0.395 W & 0.766 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-10,Page No:405"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W_A=120 # N # Weight of block A\n",
+ "W_B=80 # N # Weight of block B\n",
+ "mu_a=0.4 # coefficient of friction under block A\n",
+ "n=40 # r.p.m # rotation of frame\n",
+ "r_a=1.2 # m # distance from block A to the axis of rotation\n",
+ "r_b=1.6 # m # distance from block A to the axis of rotation\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "pi=3.14 # constant\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider the F.B.D of block A.\n",
+ "N=W_A # N # Sum F_y=0\n",
+ "\n",
+ "# Now here, a_n=omega^2*r\n",
+ "omega=(2*pi*n)*60**-1 # rad/sec\n",
+ "a_n=(omega**2)*r_a # m/s^2\n",
+ "\n",
+ "# sum F_x=0 gives the eq'n of T as,\n",
+ "T=((W_A*g**-1)*a_n)-(mu_a*N) # N \n",
+ "\n",
+ "# Now consider the F.B.D of block B\n",
+ "A_n=(omega**2)*r_b # m/s^2\n",
+ "N_1=(W_B*g**-1)*A_n # N # sum F_x=0\n",
+ "mu=(T-W_B)*N_1**-1 \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The coefficient of friction of block B is \",round(mu,3) \n",
+ "#answer may vary due to decimal variance in python\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The coefficient of friction of block B is 0.565\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-12,Page No:408"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "W=10000 # N # Weight of the locomotive\n",
+ "# Calculations\n",
+ "# Consider the various derivations given in the textbook\n",
+ "R_max=W*20**-1 # N # eq'n for max reaction\n",
+ "# The position of occurence of maximum thrust cannot be defined here. Refer textbook for the answer\n",
+ "# Results\n",
+ "\n",
+ "print\"The maximum lateral thrust is \",round(R_max),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum lateral thrust is 500.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-13,Page No:411"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "W=10 #N # Weight of the ball\n",
+ "# Calculations\n",
+ "# consider the eq'n derived to find the reaction, given as\n",
+ "R=W*(1+((2*pi**2)*9**-1)) # N \n",
+ "# Results\n",
+ "\n",
+ "print\"The value of the reaction is \",round(R,1),\"N\"\n",
+ "#answer may vary due to decimal variance\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of the reaction is 31.9 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-15,Page No:412"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "P=50 # N # Weight of ball P\n",
+ "Q=50 # N # Weight of ball Q\n",
+ "R=100 # N # Weight of the governing device\n",
+ "l=0.3 # m # length of each side\n",
+ "theta=30 # degree\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "pi=3.14 # constant\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider the respective F.B.D\n",
+ "r=l*sin(theta*(pi/180)) # m # Radius of circe\n",
+ "# On solving eqn's 1,2 &3 we get the value of v as,\n",
+ "v=(((Q+R)*g*r)/(3**0.5*Q))**0.5 # m/s \n",
+ "# But the eq'n v=omega*r we get the value of N as,\n",
+ "N=(60*v)/(2*pi*r) # r.p.m \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The speed of rotation is \",round(N,1),\"r.p.m\"\n",
+ "# NOTE: In the text book (A.K. Tayal) this sum is numbered as 'EXAMPLE 15.14' which is incorrect.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The speed of rotation is 101.7 r.p.m\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-16,Page No:414"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "Q=20 # N # Weight of the governor device\n",
+ "W=10 # N # Weight of the fly balls\n",
+ "theta=30 # degree # angle between the vertical shaft and the axis AB\n",
+ "l=0.2 # m # length of the shaft\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "pi=3.14 # constant\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider the respective F.B.D\n",
+ "# Radius of the circle is given as,\n",
+ "r=Q*sin(theta*(pi/180))*(10**-2) # m \n",
+ "\n",
+ "# Solving eq'n 1 & 2 for v. The eq'n for v is given as,\n",
+ "v=(((W*l*0.5)+(0.05*Q))/((W*0.2*(3)**0.5)/(2*g*r)))**0.5 # m/s\n",
+ "\n",
+ "# But, v=r*omega=2*pi*N*r/60. From this eq'n we get N as,\n",
+ "N=(v*60)/(2*pi*r) # r.p.m.\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The speed of the fly-balls is \",round(N,1),\"r.p.m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The speed of the fly-balls is 101.7 r.p.m\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-18,Page No:421 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "r=50 # m # radius of the road\n",
+ "mu=0.15 # coefficient of friction between the wheels and the road\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The eq'n fo max speed of the vehicle without skidding is \n",
+ "v=(mu*g*r)**0.5 # m/s\n",
+ "\n",
+ "# The angle theta made with the vertical while negotiating the corner is \n",
+ "theta=arctan(v**2/(g*r))*(180/pi) # degree\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The maximum speed with which the vehicle can travel is \",round(v,2),\"m/s\"\n",
+ "print\"The angle made with the vertical is \",round(theta,2),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum speed with which the vehicle can travel is 8.58 m/s\n",
+ "The angle made with the vertical is 8.54 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-19,Page No:422"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "v=100*1000*3600**-1 # m/s # or 100 km/hr\n",
+ "r=250 # m # radius of the road\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The angle of banking is given by eq'n,\n",
+ "theta=arctan((v**2)/(g*r))*(180/pi) # degree \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The angle of banking of the track is \",round(theta,2),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The angle of banking of the track is 17.47 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-20,Page No:422"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W=10000 # N # Weight of the car\n",
+ "r=100 # m # radius of the road\n",
+ "v=10 # m/s # speed of the car\n",
+ "h=1 # m # height of the C.G of the car above the ground\n",
+ "b=1.5 # m # distance between the wheels\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The reactions at the wheels are given by te eq'ns:\n",
+ "R_A=(W/2)*(1-((v**2*h)/(g*r*b))) # N # Reaction at A\n",
+ "R_B=(W/2)*(1+((v**2*h)/(g*r*b))) # N # Reaction at B\n",
+ "\n",
+ "# The eq'n for max speed to avoid overturning on level ground is,\n",
+ "v_max=((g*r*(b/2))/(h))**0.5 # m/s\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The reaction at Wheel A (R_A) is \",round(R_A,1),\"N\"\n",
+ "print\"The reaction at Wheel B (R_B) is \",round(R_B,1),\"N\"\n",
+ "print\"The maximum speed at which the vehicle can travel without the fear of overturning is \",round(v_max,2),\"m/s\" \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reaction at Wheel A (R_A) is 4660.2 N\n",
+ "The reaction at Wheel B (R_B) is 5339.8 N\n",
+ "The maximum speed at which the vehicle can travel without the fear of overturning is 27.12 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 45
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15-21,Page No:423"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W=1 # N # Weight of the bob\n",
+ "theta=8 # degree # angle made by the bob with the vertical\n",
+ "r=100 # m # radius of the curve\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# from eq'n 1 & 2 we get v as,\n",
+ "v=((g*r*tan(theta*(pi/180)))**0.5)*3600*1000**-1 # km/hr \n",
+ "T=W/cos(theta*(pi/180)) # N # from eq'n 2\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The speed of the cariage is \",round(v,2),\"km/hr\"\n",
+ "print\"The tension in the chord is \",round(T,2),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The speed of the cariage is 42.26 km/hr\n",
+ "The tension in the chord is 1.01 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter16.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter16.ipynb
new file mode 100755
index 00000000..7bd00420
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter16.ipynb
@@ -0,0 +1,471 @@
+{
+ "metadata": {
+ "name": "chapter16.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16: Kinetics Of A Particle : Work And Energy"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.16-1,Page No:432"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "k=1000 # N/m # stiffness of spring\n",
+ "x_1=0.1 # m # distance upto which the spring is stretched\n",
+ "x_2=0.2 # m \n",
+ "x_0=0 # initial position of spring\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Work required to stretch the spring by 10 cm from undeformed position is given as,\n",
+ "U_10=-(k/2)*(x_1**2-x_0**2) # N-m \n",
+ "# Work required to stretch from 10 cm to 20 cm is,\n",
+ "U=-(0.5)*k*(x_2**2-x_1**2) # N-m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The work of the spring force is \",round(U_10),\"N-m\"\n",
+ "print\"The work required to stretch the spring by 20 cm is \",round(U),\"N-m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The work of the spring force is -5.0 N-m\n",
+ "The work required to stretch the spring by 20 cm is -15.0 N-m\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.16-3,Page No:436"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "M_A=100 # kg # mass of block A\n",
+ "M_B=150 # kg # mass of block B\n",
+ "mu=0.2 # coefficient of friction between the blocks and the surface\n",
+ "x=1 # m # distance by which block A moves\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider the respective F.B.D\n",
+ "# Applying the principle of work and energy to the system of blocks A&B and on simplifying we get the value of v as,\n",
+ "v=(((-mu*M_A*g)+(M_B*g))/(125))**0.5 # m/s \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity of block A is \",round(v,2),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity of block A is 3.19 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.16-4,Page No:440"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "M=500*10**3 # kg # mass of the train\n",
+ "u=0 # m/s # initial speed\n",
+ "v=90*1000*3600**-1 # m/s # final speed\n",
+ "t=50 # seconds\n",
+ "F_r=15*10**3 # N # Frictioal resistance to motion\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Acceleration is given as,\n",
+ "a=v*t**-1 # m/s^2\n",
+ "# The total force required to accelerate the train is,\n",
+ "F=M*a # N\n",
+ "# The maximum power required is at, t=50s & v=25 m/s\n",
+ "P=(F+F_r)*v*(10**-6) # MW\n",
+ "# At any time after 50 seconds, the force required only to overcome the frictional resistance of 15*10^3 N is,\n",
+ "P_req=F_r*v*(10**-3) # kW\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The maximum power required is \",round(P,3),\"MW\"\n",
+ "print\"(b) The power required to maintain a speed of 90 km/hr is \",round(P_req,2),\"kW\" \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The maximum power required is 6.625 MW\n",
+ "(b) The power required to maintain a speed of 90 km/hr is 375.0 kW\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.16-5,Page No:440"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W=50 # N # Weight suspended on spring\n",
+ "k=10 # N/cm # stiffness of the spring\n",
+ "x_2=15 # cm # measured extensions\n",
+ "h=10 # cm # height for position 2\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider the required F.B.D.\n",
+ "\n",
+ "# POSITION 1: The force exerted by the spring is,\n",
+ "F_1=W # N\n",
+ "\n",
+ "# Extension of spring from undeformed position is x_1,\n",
+ "x_1=F_1/k # cm\n",
+ "\n",
+ "# POSITION 2: When pulled by 10 cm to the floor. P.E of weight is,\n",
+ "P_E_g=-W*h # N-cm # (P_E_g= P_E_gravity)\n",
+ "\n",
+ "# P.E of the spring with respect to position 1\n",
+ "P_E_s=(0.5)*k*(x_2**2-x_1**2) # N-cm # (P_E_s= P_E_ spring)\n",
+ "\n",
+ "# Total P.E of the system with respect to position 1\n",
+ "P_E_t=P_E_g+P_E_s # N-cm # (P_E_t= P_E_total)\n",
+ "\n",
+ "# Total energy of the system,\n",
+ "E_2=P_E_t # N-cm\n",
+ "\n",
+ "# Total energy of the system in position 3 w.r.t position 1 is:\n",
+ "x=-(100)**0.5 # cm\n",
+ "x=+(100)**0.5 # cm\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The potential energy of the system is \",round(E_2),\"N-cm\"\n",
+ "print\"The maximum height above the floor that the weight W will attain after release is \",round(x),\"cm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The potential energy of the system is 500.0 N-cm\n",
+ "The maximum height above the floor that the weight W will attain after release is 10.0 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.16-6,Page No:442"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "m=5 # kg # mass of the ball\n",
+ "k=500 # N/m # stiffness of the spring\n",
+ "h=10 # cm # height of drop\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider the respective F.B.D.\n",
+ "# In eq'n 1 substitute the respective values and simplify it further. In this eq'n of 2nd degree a=1 b=-0.1962 & c=-0.01962. Thus the roots of the eq'n is given as,\n",
+ "a=1 \n",
+ "b=-0.1962\n",
+ "c=-0.01962\n",
+ "delta=((-b+(((b**2)-(4*a*c))**0.5))/(2*a))*(10**2) # cm # We consider the +ve value of delta\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The maximum deflection of the spring is \",round(delta,2),\"cm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum deflection of the spring is 26.91 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.16-7,Page No:444"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "m=5 # kg # mass of the ball\n",
+ "k=500 # N/m # stiffness of the spring\n",
+ "h=0.1 # m # height of vertical fall\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider the respective F.B.D\n",
+ "# On equating the total energies at position 1 & 2 we get eq'n of delta as,\n",
+ "delta=((2*m*g*h)/(k))**0.5 # m \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The maximum compression of the spring is \",round(delta,3),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum compression of the spring is 0.14 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.16-9,Page No:445"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "m=5 # kg # mass of the collar\n",
+ "k=500 # N/m # stiffness of the spring\n",
+ "AB=0.15 # m # Refer the F.B.D for AB\n",
+ "AC=0.2 # m # Refer the F.B.D for AC\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider the respective F.B.D\n",
+ "\n",
+ "# POSITION 1: \n",
+ "P_E_1=m*g*(AB)+0 \n",
+ "K_E_1=0\n",
+ "E_1=P_E_1+K_E_1 #\n",
+ "\n",
+ "# POSITION 2 : Length of the spring in position 2\n",
+ "CB=(AB**2+AC**2)**0.5 # m \n",
+ "# x is the extension in the spring\n",
+ "x=CB-AC # m\n",
+ "# On substuting and Equating equations of total energies for position1 & position 2 we get the value of v as,\n",
+ "v=(((E_1-((0.5)*k*x**2))*2)/m)**0.5 # m/s\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity of the collar will be \",round(v,2),\"m/s\"\n",
+ "# The answer given in the text book (v=16.4 m/s) is wrong.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity of the collar will be 1.64 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.16-10,Page No:446"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "m=5 # kg # mass of the block\n",
+ "theta=30 # degree # inclination of the plane\n",
+ "x=0.5 # m # distance travelled by the block\n",
+ "k=1500 # N/m # stiffness of the spring\n",
+ "mu=0.2 # coefficient of friction between the block and the surface\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider the F.B.D of the block\n",
+ "# Applying the principle of work and energy between the positions 1 & 2 and on further simplification we get the generic eq'n for delta as, 750*delta^2-16.03*delta-8.015=0. From this eq'n e have values of a.b & c as,\n",
+ "a=750\n",
+ "b=-16.03\n",
+ "c=-8.015\n",
+ "# Thus the roots of the eq'n are given as,\n",
+ "delta=(-b+((b**2-(4*a*c))**0.5))/(2*a) # m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The maximum compression of the spring is \",round(delta,3),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The maximum compression of the spring is 0.115 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.16-11,Page No:448"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "M=10 # kg # Here M=M_1=M_2\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider the respective F.B.D\n",
+ "# Applying the principle of conservation of energy and by equating the total energies at position 1 & position 2 we get v as,\n",
+ "v=((M*g*4)/(25))**0.5 # m/s\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity of mass M_2 is \",round(v,2),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity of mass M_2 is 3.96 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter17.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter17.ipynb
new file mode 100755
index 00000000..5049e924
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter17.ipynb
@@ -0,0 +1,342 @@
+{
+ "metadata": {
+ "name": "chapter17.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 17: Kinetics Of A Particle : Impulse And Momentum"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17.17-1,Page no:460"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "m=0.1 # kg # mass of ball\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider the respective F.B.D.\n",
+ "\n",
+ "# For component eq'n in x-direction\n",
+ "delta_t=0.015 # seconds # time for which the ball &the bat are in contact\n",
+ "v_x_1=-25 # m/s \n",
+ "v_x_2=40*cos(40*(pi/180)) # m/s\n",
+ "F_x_average=((m*(v_x_2))-(m*(v_x_1)))/(delta_t) # N\n",
+ "\n",
+ "# For component eq'n in y-direction\n",
+ "delta_t=0.015 # sceonds\n",
+ "v_y_1=0 # m/s\n",
+ "v_y_2=40*sin(40*(pi/180)) # m/s\n",
+ "F_y_average=((m*v_y_2)-(m*(v_y_1)))/(delta_t) # N\n",
+ "F_average=(F_x_average**2+F_y_average**2)**0.5 # N\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The average impules force exerted by the bat on the ball is \",round(F_average,1),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average impules force exerted by the bat on the ball is 408.6 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Examplle 17.17-2,Page No:461"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initiliation of variables\n",
+ "\n",
+ "m_g=3000 # kg # mass of the gun\n",
+ "m_s=50 # kg # mass of the shell\n",
+ "v_s=300 # m/s # initial velocity of shell\n",
+ "s=0.6 # m # distance at which the gun is brought to rest\n",
+ "v=0 # m/s # initial velocity of gun\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# On equating eq'n 1 & eq'n 2 we get v_g as,\n",
+ "v_g=(m_s*v_s)/(-m_g) # m/s\n",
+ "\n",
+ "# Using v^2-u^2=2*a*s to find acceleration,\n",
+ "a=(v**2-v_g**2)/(2*s) # m/s^2\n",
+ "\n",
+ "# Force required to stop the gun,\n",
+ "F=m_g*-a # N # here we make a +ve to find the Force\n",
+ "\n",
+ "# Time required to stop the gun, using v=u+a*t:\n",
+ "t=(-v_g)/(-a) # seconds # we take -a to consider +ve value of acceleration\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The recoil velocity of gun is \",round(v_g),\"m/s\"\n",
+ "print\"The Force required to stop the gun is \",round(F),\"N\" # Answer in textbook 62400 is wrong as a=20.833\n",
+ "print\"The time required to stop the gun is \",round(t,2),\"seconds\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The recoil velocity of gun is -5.0 m/s\n",
+ "The Force required to stop the gun is 62500.0 N\n",
+ "The time required to stop the gun is 0.24 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17.17-3,Page No:462"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "m_m=50 # kg # mass of man\n",
+ "m_b=250 # kg # mass of boat\n",
+ "s=5 # m # length of the boat\n",
+ "v_r=1 # m/s # here v_r=v_(m/b)= relative velocity of man with respect to boat\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Velocity of man is given by, v_m=(-v_r)+v_b\n",
+ "\n",
+ "# Final momentum of the man and the boat=m_m*v_m+m_b*v_b. From this eq'n v_b is given as\n",
+ "v_b=(m_m*v_r)*(m_m+m_b)**-1 # m/s # this is the absolute velocity of the boat\n",
+ "\n",
+ "# Time taken by man to move to the other end of the boat is,\n",
+ "t=s/v_r # seconds\n",
+ "\n",
+ "# The distance travelled by the boat in the same time is,\n",
+ "s_b=v_b*t # m to right from O\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The velocity of boat as observed from the ground is \",round(v_b,3),\"m/s\"\n",
+ "print\"(b) The distance by which the boat gets shifted is \",round(s_b,3),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The velocity of boat as observed from the ground is 0.167 m/s\n",
+ "(b) The distance by which the boat gets shifted is 0.833 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17.17-5,Page No:464"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "M=250 # kg # mass of the boat\n",
+ "M_1=50 # kg # mass of the man\n",
+ "M_2=75 # kg # mass of the man\n",
+ "v=4 # m/s # relative velocity of man w.r.t boat\n",
+ "\n",
+ "# Calculations \n",
+ "\n",
+ "# (a)\n",
+ "# Let the increase in the velocity or the final velocity of the boat when TWO MEN DIVE SIMULTANEOUSLY is given by eq'n,\n",
+ "deltaV_1=((M_1+M_2)*v)*(M+(M_1+M_2))**-1 # m/s\n",
+ "\n",
+ "# (b) # The increase in the velocity or the final velocity of the boat when man of 75 kg dives 1st followed by man of 50 kg\n",
+ "# Man of 75 kg dives first, So let the final velocity is given as\n",
+ "deltaV_75=(M_2*v)*((M+M_1)+M_2)**-1 # m/s\n",
+ "# Now let the man of 50 kg jumps next, Here\n",
+ "deltaV_50=(M_1*v)*(M+M_1)**-1 # m/s\n",
+ "# Let final velocity of boat is,\n",
+ "deltaV_2=0+deltaV_75+deltaV_50 # m/s\n",
+ "\n",
+ "# (c) \n",
+ "# The man of 50 kg jumps first,\n",
+ "delV_50=(M_1*v)*((M+M_2)+(M_1))**-1 # m/s\n",
+ "# the man of 75 kg jumps next,\n",
+ "delV_75=(M_2*v)*(M+M_2)**-1 # m/s\n",
+ "# Final velocity of boat is,\n",
+ "deltaV_3=0+delV_50+delV_75 # m/s\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The Final velocity of boat when two men dive simultaneously is \",round(deltaV_1,2),\"m/s\"\n",
+ "print\"(b) The Final velocity of boat when the man of 75 kg dives first and 50 kg dives second is \",round(deltaV_2,3),\"m/s\"\n",
+ "print\"(c) The Final velocity of boat when the man of 50kg dives first followed by the man of 75 kg is \",round(deltaV_3,3),\"m/s\" \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The Final velocity of boat when two men dive simultaneously is 1.33 m/s\n",
+ "(b) The Final velocity of boat when the man of 75 kg dives first and 50 kg dives second is 1.467 m/s\n",
+ "(c) The Final velocity of boat when the man of 50kg dives first followed by the man of 75 kg is 1.456 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17.17-6,Page No:466"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "m_m=70 # kg # mass of man\n",
+ "m_c=35 # kg # mass of canoe\n",
+ "m=25*1000**-1 # kg # mass of bullet\n",
+ "m_wb=2.25 # kg # mass of wodden block\n",
+ "V_b=5 # m/s # velocity of block\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Considering Initial Momentum of bullet=Final momentum of bullet & the block we have,Velocity of bullet (v) is given by eq'n,\n",
+ "v=(V_b*(m_wb+m))/(m) # m/s \n",
+ "\n",
+ "# Considering, Momentum of the bullet=Momentum of the canoe & the man,the velocity on canoe is given by eq'n\n",
+ "V=(m*v)*(m_m+m_c)**-1 # m/s\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity of the canoe is \",round(V,3),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity of the canoe is 0.108 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17.17-8,Page no:470"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "m=2 # kg # mass of the particle\n",
+ "v_0=20 # m/s # speed of rotation of the mass attached to the string\n",
+ "r_0=1 # m # radius of the circle along which the particle is rotated\n",
+ "r_1=r_0*0.5 # m\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# here, equating (H_0)_1=(H_0)_2 i.e (m*v_0)*r_0=(m*v_1)*r_1 (here, r_1=r_0/2). On solving we get v_1 as,\n",
+ "v_1=2*v_0 # m/s\n",
+ "# Tension is given by eq'n,\n",
+ "T=(m*v_1**2)/r_1 # N\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The new speed of the particle is \",round(v_1),\"m/s\"\n",
+ "print\"The tension in the string is \",round(T),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The new speed of the particle is 40.0 m/s\n",
+ "The tension in the string is 6400.0 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter18.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter18.ipynb
new file mode 100755
index 00000000..696a0479
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter18.ipynb
@@ -0,0 +1,620 @@
+{
+ "metadata": {
+ "name": "chapter18.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 18: Impact:Collision Of Elastic Bodies"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.18-1,Page No:474"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "\n",
+ "# Initilization of variables\n",
+ "m_a=1 # kg # mass of the ball A\n",
+ "v_a=2 # m/s # velocity of ball A\n",
+ "m_b=2 # kg # mass of ball B\n",
+ "v_b=0 # m/s # ball B at rest\n",
+ "e=1/2 # coefficient of restitution\n",
+ "\n",
+ "# Calculations\n",
+ "# Solving eqn's 1 & 2 using matrix for v'_a & v'_b,\n",
+ "A=np.array([[1 ,2],[-1 ,1]])\n",
+ "B=np.array([2,1])\n",
+ "C=np.linalg.solve(A,B)\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity of ball A after impact is \",round(C[0]),\"m/s\"\n",
+ "print\"The velocity of ball B after impact is \",round(C[1]),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity of ball A after impact is 0.0 m/s\n",
+ "The velocity of ball B after impact is 1.0 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.18-2,Page No:480"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "\n",
+ "# Initilization of variables\n",
+ "m_a=2 # kg # mass of ball A\n",
+ "m_b=6 # kg # mass of ball B\n",
+ "m_c=12 # kg # mass of ball C\n",
+ "v_a=12 # m/s # velocity of ball A\n",
+ "v_b=4 # m/s # velocity of ball B\n",
+ "v_c=2 # m/s # velocity of ball C\n",
+ "e=1 # coefficient of restitution for perfectly elastic body\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# (A)\n",
+ "# Solving eq'n 1 & 2 using matrix for v'_a & v'_b,\n",
+ "A=np.array([[2 ,6],[-1, 1]])\n",
+ "B=np.array([48,8])\n",
+ "C=np.linalg.solve(A,B)\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# (B)\n",
+ "# Solving eq'ns 3 & 4 simultaneously using matrix for v'_b & v'_c\n",
+ "P=np.array([[1 ,2],[-1, 1]])\n",
+ "Q=np.array([12,6])\n",
+ "R=np.linalg.solve(P,Q)\n",
+ "\n",
+ "# Results (A&B)\n",
+ "\n",
+ "print\"The velocity of ball A after impact on ball B is \",round(C[0]),\"m/s\" # here the ball of mass 2 kg is bought to rest\n",
+ "print\"The velocity of ball B after getting impacted by ball A is \",round(C[1]),\"m/s\"\n",
+ "print\"The final velocity of ball B is \",round(R[0]),\"m/s\" # here the ball of mass 6 kg is bought to rest\n",
+ "print\"The velocity of ball C after getting impacted by ball B is \",round(R[1]),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity of ball A after impact on ball B is 0.0 m/s\n",
+ "The velocity of ball B after getting impacted by ball A is 8.0 m/s\n",
+ "The final velocity of ball B is 0.0 m/s\n",
+ "The velocity of ball C after getting impacted by ball B is 6.0 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.18-3,Page No:481"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "h_1=9 # m # height of first bounce\n",
+ "h_2=6 # m # height of second bounce\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# From eq'n (5) we have, Coefficient of restitution between the glass and the floor is,\n",
+ "e=(h_2*h_1**-1)**0.5\n",
+ "# From eq'n 3 we get height of drop as,\n",
+ "h=h_1/e**2 # m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The ball was dropped from a height of \",round(h,1),\"m\"\n",
+ "print\"The coefficient of restitution between the glass and the floor is \",round(e,1)\n",
+ "# Here we use h`=h_1 & h``=h_2 because h` & h`` could not be defined in Scilab.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The ball was dropped from a height of 13.5 m\n",
+ "The coefficient of restitution between the glass and the floor is 0.8\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.18-4,Page No:484"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "e=0.90 # coefficient o restitution\n",
+ "v_a=10 # m/s # velocity of ball A\n",
+ "v_b=15 # m/s # velocity of ball B\n",
+ "alpha_1=30 # degree # angle made by v_a with horizontal\n",
+ "alpha_2=60 # degree # angle made by v_b with horizontal\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The components of initial velocity of ball A:\n",
+ "v_a_x=v_a*cos(alpha_1*(pi/180)) # m/s\n",
+ "v_a_y=v_a*sin(alpha_1*(pi/180)) # m/s\n",
+ "\n",
+ "# The components of initial velocity of ball B:\n",
+ "v_b_x=-v_b*cos(alpha_2*(pi/180)) # m/s\n",
+ "v_b_y=v_b*sin(alpha_2*(pi/180)) # m/s\n",
+ "\n",
+ "# From eq'n 1 & 2 we get,\n",
+ "v_ay=v_a_y # m/s # Here, v_ay=(v'_a)_y\n",
+ "v_by=v_b_y # m/s # Here, v_by=(v'_b)_y\n",
+ "\n",
+ "# On adding eq'n 3 & 4 we get,\n",
+ "v_bx=((v_a_x+v_b_x)+(-e*(v_b_x-v_a_x)))*0.5 # m/s # Here. v_bx=(v'_b)_x\n",
+ "\n",
+ "# On substuting the value of v'_b_x in eq'n 3 we get,\n",
+ "v_ax=(v_a_x+v_b_x)-(v_bx) # m/s # here, v_ax=(v'_a)_x\n",
+ "\n",
+ "# Now the eq'n for resultant velocities of balls A & B after impact are,\n",
+ "v_A=(v_ax**2+v_ay**2)**0.5 # m/s\n",
+ "v_B=(v_bx**2+v_by**2)**0.5 # m/s\n",
+ "\n",
+ "# The direction of the ball after Impact is,\n",
+ "theta_1=arctan(-(v_ay/v_ax))*(180/pi) # degree\n",
+ "theta_2=arctan(v_by/v_bx)*(180/pi) # degree\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity of ball A after impact is \",round(v_A,2),\"m/s\"\n",
+ "print\"The velocity of ball B after impact is \",round(v_B,2),\"m/s\"\n",
+ "print\"The direction of ball A after impact is \",round(theta_1,2),\"degree\"\n",
+ "print\"The direction of ball B after impact is \",round(theta_2,2),\"degree\"\n",
+ "# Her we use, (1) v'_a & v'_b as v_A & v_B.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity of ball A after impact is 8.35 m/s\n",
+ "The velocity of ball B after impact is 15.18 m/s\n",
+ "The direction of ball A after impact is 36.77 degree\n",
+ "The direction of ball B after impact is 58.85 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.18-5,Page No:485"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initiization of variables\n",
+ "theta=30 # degrees # ange made by the ball against the wall\n",
+ "e=0.50\n",
+ "# Calculations\n",
+ "# The notations have been changed\n",
+ "# Resolving the velocity v as,\n",
+ "v_x=cos(theta*(pi/180))\n",
+ "v_y=sin(theta*(pi/180))\n",
+ "V_y=v_y\n",
+ "# from coefficient of restitution reation\n",
+ "V_x=-e*v_x\n",
+ "# Resultant velocity\n",
+ "V=sqrt(V_x**2+V_y**2)\n",
+ "theta=arctan(V_y*(-V_x)**-1)*(180/pi) # taking +ve value for V_x\n",
+ "# NOTE: Here all the terms are multiplied with velocity i.e (v).\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity of the ball is \",round(V,3),\"v\"\n",
+ "print\"The direction of the ball is \",round(theta,1),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity of the ball is 0.661 v\n",
+ "The direction of the ball is 49.1 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.18-6,Page No:488"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "\n",
+ "# Initilization of variables\n",
+ "e=0.8 # coefficient of restitution\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calcuations\n",
+ "\n",
+ "# Squaring eqn's 1 &2 and Solving eqn's 1 & 2 using matrix for the value of h\n",
+ "A=np.array([[-1 ,(2*g)],[-1 ,-(1.28*g)]])\n",
+ "B=np.array([0.945**2,(-0.4*9.81)])\n",
+ "C=np.linalg.solve(A,B) # m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The height from which the ball A should be released is \",round(C[1],3),\"m\"\n",
+ "# The answer given in the book i.e 0.104 is wrong.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The height from which the ball A should be released is 0.15 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.18-7,Page No:490"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "theta_a=60 # degree # angle made by sphere A with the verticle\n",
+ "e=1 # coefficient of restitution for elastic impact\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# theta_b is given by the eq'n cosd*theta_b=0.875, hence theta_b is,\n",
+ "theta_b=arccos(0.875)*(180/pi) # degree\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The angle through which the sphere B will swing after the impact is \",round(theta_b,2),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The angle through which the sphere B will swing after the impact is 28.96 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.18-8,Page No:491"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "m_a=0.01 # kg # mass of bullet A\n",
+ "v_a=100 # m/s # velocity of bullet A\n",
+ "m_b=1 # kg # mass of the bob\n",
+ "v_b=0 # m/s # velocity of the bob\n",
+ "l=1 # m # length of the pendulum\n",
+ "v_r=-20 # m/s # velocity at which the bullet rebounds the surface of the bob # here the notation for v'_a is shown by v_r\n",
+ "v_e=20 # m/s # velocity at which the bullet escapes through the surface of the bob # here the notation for v_a is shown by v_e\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Momentum of the bullet & the bob before impact is,\n",
+ "M=(m_a*v_a)+(m_b*v_b) # kg.m/s......(eq'n 1)\n",
+ "\n",
+ "# The common velocity v_c ( we use v_c insted of v' for notation of common velocity) is given by equating eq'n 1 & eq'n 2 as,\n",
+ "\n",
+ "# (a) When the bullet gets embedded into the bob\n",
+ "v_c=M/(m_a+m_b) # m/s\n",
+ "# The height h to which the bob rises is given by eq'n 3 as,\n",
+ "h_1=(0.5)*(v_c**2/g) # m\n",
+ "# The angle (theta_1) by which the bob swings corresponding to the value of height h_1 is,\n",
+ "theta_1=arccos((l-h_1)/l)*(180/pi) # degree\n",
+ "\n",
+ "# (b) When the bullet rebounds from the surface of the bob\n",
+ "# The velocity of the bob after the rebound of the bullet from its surface is given by equating eq'n 1 & eq'n 4 as,\n",
+ "v_bob_rebound=M-(m_a*v_r) # m/s # here v_bob_rebound=v'_b\n",
+ "# The equation for the height which the bob attains after impact is,\n",
+ "h_2=(v_bob_rebound**2)/(2*g) # m\n",
+ "# The corresponding angle of swing \n",
+ "theta_2=arccos((l-h_2)/l)*(180/pi) # degree\n",
+ "\n",
+ "# (c) When the bullet pierces and escapes through the bob\n",
+ "# From eq'n 1 & 5 the velocity attained by the bob after impact is given as,\n",
+ "v_b_escape=M-(m_a*v_e) # m/s # here we use, v_b_escape insted of v'_b\n",
+ "# The equation for the height which the bob attains after impact is,\n",
+ "h_3=(v_b_escape**2)/(2*g) # m\n",
+ "# The corresponding angle of swing \n",
+ "theta_3=arccos((l-h_3)/(l))*(180/pi) # degree\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The maximum angle through which the pendulum swings when the bullet gets embeded into the bob is \",round(theta_1,1),\"degree\"\n",
+ "print\"(b) The maximum angle through which the pendulum swings when the bullet rebounds from the surface of the bob is \",round(theta_2,2),\"degree\"\n",
+ "print\"(c) The maximum angle through which the pendulum swings when the bullet escapes from other end of the bob the bob is \",round(theta_3,1),\"degree\"\n",
+ "# IN THIS SUM WE HAVE USED DIFFERENT NOTATIONS CONSIDERING DIFFERENT CASES BECAUSE IN THE TEXT BOOK WE HAD 3 VARIABLES WITH SAME NOTATION BUT WITH A DIFFERENT VALUE WHICH COULD NOT BE EXECUTED INTO SCILAB.\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The maximum angle through which the pendulum swings when the bullet gets embeded into the bob is 18.2 degree\n",
+ "(b) The maximum angle through which the pendulum swings when the bullet rebounds from the surface of the bob is 22.09 degree\n",
+ "(c) The maximum angle through which the pendulum swings when the bullet escapes from other end of the bob the bob is 14.7 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.18-9,Page No:493"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W_a=50 # N # falling weight\n",
+ "W_b=50 # N # weight on which W_a falls\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "m_a=W_a/g # kg # mass of W_a\n",
+ "m_b=W_b/g # kg # mass of W_b\n",
+ "k=2*10**3 # N/m # stiffness of spring\n",
+ "h=0.075 # m # height through which W_a falls\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "# The velocity of weight W_a just before the impact and after falling from a height of h is given from the eq'n, ( Principle of conservation of energy)\n",
+ "v_a=(2*g*h)**0.5 # m/s\n",
+ "\n",
+ "# Let the mutual velocity after the impact be v_m (i.e v_m=v'), (by principle of conservation of momentum)\n",
+ "v_m=(m_a*v_a)/(m_a+m_b) # m/s\n",
+ "\n",
+ "# Initial compression of the spring due to weight W_b is given by,\n",
+ "delta_st=(W_b/k)*(10**2) # cm\n",
+ "\n",
+ "# Let the total compression of the spring be delta_t, Then delta_t is found by finding the roots from the eq'n........ delta_t^2-0.1*delta_t-0.000003=0. In this eq'n let,\n",
+ "a=1\n",
+ "b=-0.1\n",
+ "c=-0.000003\n",
+ "delta_t=((-b+((b**2-(4*a*c))**0.5))/2*a)*(10**2) # cm # we consider the -ve value\n",
+ "delta=delta_t-delta_st # cm\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The compression of the spring over and above caused by the static action of weight W_a is \",round(delta),\"cm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The compression of the spring over and above caused by the static action of weight W_a is 10.0 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.18-10,Page No:494"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "v_a=600 # m/s # velocity of the bullet before impact\n",
+ "v_b=0 # m/s # velocity of the block before impact\n",
+ "w_b=0.25 # N # weight of the bullet\n",
+ "w_wb=50 # N # weight of wodden block\n",
+ "mu=0.5 # coefficient of friction between the floor and the block\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "m_a=w_b/g # kg # mass of the bullet\n",
+ "m_b=w_wb/g # kg # mass of the block\n",
+ "\n",
+ "# Let the common velocity be v_c which is given by eq'n (Principle of conservation of momentum)\n",
+ "v_c=(w_b*v_a)/(w_wb+w_b) # m/s\n",
+ "\n",
+ "# Let the distance through which the block is displaced be s, Then s is given by eq'n\n",
+ "s=v_c**2/(2*g*mu) # m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The distance through which the block is displaced from its initial position is \",round(s,2),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The distance through which the block is displaced from its initial position is 0.91 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18.18-11,Page No:495"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "M=750 # kg # mass of hammer\n",
+ "m=200 # kg # mass of the pile\n",
+ "h=1.2 # m # height of fall of the hammer\n",
+ "delta=0.1 # m # distance upto which the pile is driven into the ground\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Caculations\n",
+ "\n",
+ "# The resistance to penetration to the pile is given by eq'n,\n",
+ "R=(((M+m)*g)+((M**2*g*h)/((M+m)*delta)))*(10**-3) # kN \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The resistance to penetration to the pile is \",round(R),\"KN\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The resistance to penetration to the pile is 79.0 KN\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter19.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter19.ipynb
new file mode 100755
index 00000000..ca13c8e8
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter19.ipynb
@@ -0,0 +1,262 @@
+{
+ "metadata": {
+ "name": "chapter19.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 19: Relative Motion"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 19.19-1,Page no:503"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "v_t=10 # m/s # velocity of the train\n",
+ "v_s=5 # m/s # velocity of the stone\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Let v_r be the relative velocity, which is given as, (from triangle law)\n",
+ "v_r=(v_t**2+v_s**2)**0.5 # m/s\n",
+ "# The direction ofthe stone is,\n",
+ "theta=arctan(v_s*v_t**-1)*(180/pi) # degree\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity at which the stone appears to hit the person travelling in the train is \",round(v_r,1),\"m\"\n",
+ "print\"The direction of the stone is \",round(theta,2),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity at which the stone appears to hit the person travelling in the train is 11.2 m\n",
+ "The direction of the stone is 26.57 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 19.19-2,Page No:504"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "v_A=5 # m/s # speed of ship A\n",
+ "v_B=2.5 # m/s # speed of ship B\n",
+ "theta=135 # degree # angle between the two ships\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Here,\n",
+ "OA=v_A # m/s\n",
+ "OB=v_B # m/s\n",
+ "\n",
+ "# The magnitude of relative velocity is given by cosine law as,\n",
+ "AB=((OA**2)+(OB**2)-(2*OA*OB*cos(theta*(pi/180))))**0.5 # m/s\n",
+ "\n",
+ "# where AB gives the relative velocity of ship B with respect to ship A\n",
+ "# Applying sine law to find the direction, Let alpha be the direction of the reative velocity, then\n",
+ "alpha=arcsin((OB*sin(theta*(pi/180)))/(AB))*(180/pi) # degree\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The magnitude of relative velocity of ship B with respect to ship A is \",round(AB,2),\"m/s\"\n",
+ "print\"The direction of the relative velocity is \",round(alpha,2),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The magnitude of relative velocity of ship B with respect to ship A is 6.99 m/s\n",
+ "The direction of the relative velocity is 14.64 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 19.19-3,Page No:505"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import numpy as np\n",
+ "# Initilization of variables\n",
+ "\n",
+ "v_c=20 # km/hr # speed at which the cyclist is riding to west\n",
+ "theta_1=45 # degree # angle made by rain with the cyclist when he rides at 20 km/hr\n",
+ "V_c=12 # km/hr # changed speed\n",
+ "theta_2=30 # degree # changed angle when the cyclist rides at 12 km/hr\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Solving eq'ns 1 & 2 simultaneously to get the values of components(v_R_x & v_R_y) of absolute velocity v_R. We use matrix to solve eqn's 1 & 2.\n",
+ "A=np.array([[1 ,1],[1, 0.577]])\n",
+ "B=np.array([20,12])\n",
+ "C=np.linalg.solve(A,B) # km/hr\n",
+ "\n",
+ "# The X component of relative velocity (v_R_x) is C(1)\n",
+ "# The Y component of relative velocity (v_R_y) is C(2)\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Relative velocity (v_R) is given as,\n",
+ "v_R=((C[0])**2+(C[1])**2)**0.5 # km/hr\n",
+ "# And the direction of absolute velocity of rain is theta, is given as\n",
+ "theta=arctan(C[1]/C[0])*(180/pi) # degree\n",
+ "\n",
+ "# Results \n",
+ "\n",
+ "print\"The magnitude of absolute velocity is \",round(v_R,2),\"km/hr\"\n",
+ "print\"The direction of absolute velocity is \",round(theta,1),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The magnitude of absolute velocity is 18.94 km/hr\n",
+ "The direction of absolute velocity is 86.7 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 19.19-4,Page No:508"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initiization of variables\n",
+ "\n",
+ "a=1 # m/s^2 # acceleration of car A\n",
+ "u_B=36*1000*3600**-1 # m/s # velocity of car B\n",
+ "u=0 # m/s # initial velocity of car A\n",
+ "d=32.5 # m # position of car A from north of crossing\n",
+ "t=5 # seconds\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# CAR A: Absolute motion using eq'n v=u+at we have,\n",
+ "v=u+(a*t) # m/s\n",
+ "# Now distance travelled by car A after 5 seconds is given by, s_A=u*t+(1/2)*a*t^2\n",
+ "s_A=(u*t)+((0.5)*a*t**2)\n",
+ "# Now, let the position of car A after 5 seconds be y_A\n",
+ "y_A=d-s_A # m # \n",
+ "\n",
+ "# CAR B:\n",
+ "# let a_B be the acceleration of car B\n",
+ "a_B=0 # m/s\n",
+ "# Now position of car B is s_B\n",
+ "s_B=(u_B*t)+((0.5)*a_B*t**2) # m\n",
+ "x_B=s_B # m\n",
+ "\n",
+ "# Let the Relative position of car A with respect to car B be BA & its direction be theta, then from fig. 19.9(b)\n",
+ "OA=y_A\n",
+ "OB=x_B\n",
+ "BA=(OA**2+OB**2)**0.5 # m\n",
+ "theta=arctan(OA/OB)*(180/pi) # degree\n",
+ "\n",
+ "# Let the relative velocity of car A w.r.t. the car B be v_AB & the angle be phi. Then from fig 19.9(c). Consider small alphabets\n",
+ "oa=v\n",
+ "ob=u_B\n",
+ "v_AB=(oa**2+ob**2)**0.5 # m/s\n",
+ "phi=arctan(oa/ob)*(180/pi) # degree\n",
+ "\n",
+ "# Let the relative acceleration of car A w.r.t. car B be a_A/B.Then,\n",
+ "a_AB=a-a_B # m/s^2\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The relative position of car A relative to car B is \",round(BA,1),\"m\"\n",
+ "print\"The direction of car A w.r.t car B is \",round(theta,1),\"degree\"\n",
+ "print\"The velocity of car A relative to car B is \",round(v_AB,1),\"m/s\"\n",
+ "print\"The direction of car A w.r.t (for relative velocity)is \",round(phi,1),\"degree\"\n",
+ "print\"The acceleration of car A relative to car B is \",round(a_AB,1),\"m/s^2\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The relative position of car A relative to car B is 53.9 m\n",
+ "The direction of car A w.r.t car B is 21.8 degree\n",
+ "The velocity of car A relative to car B is 11.2 m/s\n",
+ "The direction of car A w.r.t (for relative velocity)is 26.6 degree\n",
+ "The acceleration of car A relative to car B is 1.0 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter20.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter20.ipynb
new file mode 100755
index 00000000..7b30b675
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter20.ipynb
@@ -0,0 +1,546 @@
+{
+ "metadata": {
+ "name": "chapter20.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 20: Motion Of Projectile"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 20.20-1,Page No:518"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initilization of variables\n",
+ "\n",
+ "v_o=500 # m/s # velocity of the projectile\n",
+ "alpha=30 # angle at which the projectile is fired\n",
+ "t=30 # seconds\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "v_x=v_o*cos(alpha*(pi/180)) # m/s # Initial velocity in the horizontal direction\n",
+ "v_y=v_o*sin(alpha*(pi/180)) # m/s # Initial velocity in the vertical direction\n",
+ "\n",
+ "# MOTION IN HORIZONTA DIRECTION:\n",
+ "V_x=v_x # m/s # V_x=Horizontal velocity after 30 seconds\n",
+ "\n",
+ "# MOTION IN VERTICAL DIRECTION: # using the eq'n v=u+a*t\n",
+ "V_y=v_y-(g*t) # m/s # -ve sign denotes downward motion\n",
+ "\n",
+ "# Let the Resultant velocity be v_R. It is given as,\n",
+ "v_R=((V_x)**2+(-V_y)**2)**0.5# m/s\n",
+ "theta=arctan((-V_y)/V_x)*(180/pi) # degree # direction of the projectile\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity of the projectile is \",round(v_R,2),\"m/s\" # The answer of velocity is wrong in the text book.\n",
+ "print\"The direction of the projectile is \",round(theta,2),\"degree\" # -ve value of theta indicates that the direction is in downward direction\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity of the projectile is 435.27 m/s\n",
+ "The direction of the projectile is 5.84 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 20.20-2,Page no:519"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "v_A=10 # m/s # velocity of body A\n",
+ "alpha_A=60 # degree # direction of body A\n",
+ "alpha_B=45 # degree # direction of body B\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# (a) The velocity (v_B) for the same range is given by eq'n;\n",
+ "v_B=((v_A**2*sin(2*alpha_A*(pi/180)))/(sin(2*alpha_B*(pi/180))))**0.5 # m/s\n",
+ "\n",
+ "# (b) Now velocity v_B for the same maximum height is given as,\n",
+ "v_b=((v_A**2)*((sin(alpha_A*(pi/180)))**2/(sin(alpha_B*(pi/180)))**2))**0.5 # m/s\n",
+ "\n",
+ "# (c) Now the velocity (v) for the equal time of flight is;\n",
+ "v=(v_A*sin(alpha_A*(pi/180)))/(sin(alpha_B*(pi/180))) # m/s\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The velocity of body B for horizontal range is \",round(v_B,1),\"m/s\"\n",
+ "print\"(b) The velocity of body B for the maximum height is \",round(v_b,2),\"m/s\"\n",
+ "print\"(c) The velocity of body B for equal time of flight is \",round(v,2),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The velocity of body B for horizontal range is 9.3 m/s\n",
+ "(b) The velocity of body B for the maximum height is 12.25 m/s\n",
+ "(c) The velocity of body B for equal time of flight is 12.25 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 20.20-3,Page No:520 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "y=3.6 # m # height of the wall\n",
+ "x_1=4.8 # m # position of the boy w.r.t the wall\n",
+ "x_2=3.6 # m # distance from the wall where the ball hits the ground\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The range of the projectile is r, given as,\n",
+ "r=x_1+x_2 # m\n",
+ "\n",
+ "# Let the angle of the projection be alpha, which is derived and given as,\n",
+ "alpha=arctan((y)/(x_1-(x_1**2/r)))*(180/pi) # degree\n",
+ "\n",
+ "# Now substuting the value of alpha in eq'n 3 we get the least velocity (v_o) as;\n",
+ "v_o=((g*r)/(sin(2*alpha*(pi/180))))**0.5 # m/s\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The least velocity with which the ball can be thrown is \",round(v_o,2),\"m/s\"\n",
+ "print\"The angle of projection for the same is \",round(alpha,1),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The least velocity with which the ball can be thrown is 9.78 m/s\n",
+ "The angle of projection for the same is 60.3 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 20.20-5,Page No:523 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "v_o=400 # m/s # initial velocity of each gun\n",
+ "r=5000 # m # range of each of the guns\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "p=180 # degree \n",
+ "pi=3.14\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# now from eq'n 1\n",
+ "theta_1=(arcsin(r*g/v_o**2)*(180/pi))/2 # degree # angle at which the 1st gun is fired\n",
+ "\n",
+ "# from eq'n 3\n",
+ "theta_2=(p-2*theta_1)/2 # degree \n",
+ "\n",
+ "# For 1st & 2nd gun, s is\n",
+ "s=r # m\n",
+ "\n",
+ "# For 1st gun \n",
+ "v_x=v_o*cos(theta_1*(pi/180)) # m/s\n",
+ "\n",
+ "# Now the time of flight for 1st gun is t_1, which is given by relation,\n",
+ "t_1=s*(v_x)**-1 # seconds\n",
+ "\n",
+ "# For 2nd gun\n",
+ "V_x=v_o*cos(theta_2*(pi/180))\n",
+ "\n",
+ "# Now the time of flight for 2nd gun is t_2\n",
+ "t_2=s/V_x # seconds\n",
+ "\n",
+ "# Let the time difference between the two hits be delta.T. Then,\n",
+ "T=t_2-t_1 # seconds\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The time difference between the two hits is \",round(T,2),\"seconds\" #answer varies by 0.6 sec due to decimal variance\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The time difference between the two hits is 67.5 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 99
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 20.20-6,Page No:524"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "h=2000 # m/ height of the plane\n",
+ "v=540*1000*3600**-1 # m/s # velocity of the plane\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "pi=3.14\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Time t required to travel down a height 2000 m is given by eq'n,\n",
+ "u=0 # m/s # initial velocity\n",
+ "t=(2*h/g)**0.5 # seconds\n",
+ "\n",
+ "# Now let s be the horizonta distance travelled by the bomb in time t seconds, then\n",
+ "s= v*t # m\n",
+ "\n",
+ "# angle is given as theta,\n",
+ "theta=arctan(h/s)*(180/pi) # degree\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The pilot should release the bomb from a distance of \",round(s),\"m\" #the answer varies by 1m due to decimal variance\n",
+ "print\"The angle at which the target would appear is \",round(theta,1),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The pilot should release the bomb from a distance of 3029.0 m\n",
+ "The angle at which the target would appear is 33.5 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 70
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 20.20-7,Page No:525"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "theta=30 # degree # angle at which the bullet is fired\n",
+ "s=-50 # position of target below hill\n",
+ "v=100 # m/s # velocity at which the bullet if fired\n",
+ "g=9.81 # m/s^2 \n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "v_x=v*cos(theta*(pi/180)) # m/s # Initial velocity in horizontal direction\n",
+ "v_y=v*sin(theta*(pi/180)) # m/s # Initial velocity in vertical direction\n",
+ "\n",
+ "# (a) Max height attained by the bullet\n",
+ "h=v_y**2/(2*g) # m\n",
+ "\n",
+ "# (b)Let the vertical Velocity with which the bullet will hit the target be V_y. Then,\n",
+ "V_y=((2*-9.81*s)+(v_y)**2)**0.5 # m/s # the value of V_y is +ve & -ve\n",
+ "\n",
+ "# Let V be the velocity with wich it hits the target\n",
+ "V=((v_x)**2+(V_y)**2)**0.5 # m/s\n",
+ "\n",
+ "# (c) The time required to hit the target\n",
+ "a=g # m/s^2\n",
+ "t=(v_y-(-V_y))/a # seconds\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The maximum height to which the bullet will rise above the soldier is \",round(h,1),\"m\"\n",
+ "print\"(b) The velocity with which the bullet will hit the target is \",round(V,1),\"m/s\"\n",
+ "print\"(c) The time required to hit the target is \",round(t,1),\"seconds\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The maximum height to which the bullet will rise above the soldier is 127.3 m\n",
+ "(b) The velocity with which the bullet will hit the target is 104.8 m/s\n",
+ "(c) The time required to hit the target is 11.1 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 72
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 20.20-8,Page No:527"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W=30 # N # Weight of the hammer\n",
+ "theta=30 # degree # ref fig.20.12\n",
+ "mu=0.18 # coefficient of friction\n",
+ "s=10 # m # distance travelled by the hammer # fig 20.12\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The acceleration of the hammer is given as,\n",
+ "a=g*((sin(theta*(pi/180)))-(mu*cos(theta*(pi/180)))) # m/s^2\n",
+ "\n",
+ "# The velocity of the hammer at point B is,\n",
+ "v=(2*a*s)**0.5 # m/s\n",
+ "\n",
+ "# Let the initial velocity of the hammer in horizontal direction be v_x & v_y in vertical direction, Then,\n",
+ "v_x=v*cos(theta*(pi/180)) # m/s\n",
+ "v_y=v*sin(theta*(pi/180)) # m/s\n",
+ "\n",
+ "# MOTION IN VERTICAL DIRECTION\n",
+ "# Now, let time required to travel vertical distance (i.e BB'=S=5 m) is given by finding the roots of the second degree eq'n as,\n",
+ "# From the eq'n 4.9*t^2+4.1*t-5=0,\n",
+ "a=4.9\n",
+ "b=4.1\n",
+ "c=-5\n",
+ "\n",
+ "# The roots of the eq'n are,\n",
+ "t=((-b)+((b**2-(4*a*c))**0.5))/(2*a)\n",
+ "\n",
+ "# MOTION IN HORIZONTAL DIRECTION\n",
+ "# Let the horizotal distance travelled by the hammer in time t be s_x.Then,\n",
+ "s_x=v_x*cos(theta*(pi/180))*t # m\n",
+ "x=1+s_x # m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The distance x where the hammer hits the round is \",round(x,2),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The distance x where the hammer hits the round is 5.16 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 101
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 20.20-9,Page no:528"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "s=1000 # m # distance OB (ref fig.20.13)\n",
+ "h=19.6 # m # height of shell from ground\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# MOTION OF ENTIRE SHELL FROM O to A.\n",
+ "v_y=(2*(g)*h)**0.5 # m/s # initial velocity of shell in vertical direction\n",
+ "t=v_y/g # seconds # time taken by the entire shell to reach point A\n",
+ "v_x=s/t # m/s # velocity of shell in vertical direction\n",
+ "\n",
+ "# VELOCITIES OF THE TWO PARTS OF THE SHELL AFTER BURSTING AT A:\n",
+ "\n",
+ "# Let v_x2 be the horizontal velocity of 1st & the 2nd part after bursting which is given as,\n",
+ "v_x2=v_x*2 # m/s\n",
+ "\n",
+ "# Now distance BC travelled by part 2 is\n",
+ "BC=v_x2*t # m\n",
+ "\n",
+ "# Distance from firing point OC\n",
+ "OC=s+BC # m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The velocity of shell just before bursting is \",round(v_x),\"m/s\"\n",
+ "print\"(b) The velocity of first part immediately before the shell burst is \",round(v_x),\"m/s\"\n",
+ "print\"(c) The velocity of second part immediately after the shell burst is \",round(v_x2,1),\"m/s\"\n",
+ "print\"(b) The distance between the firing point & the point where the second part of the shell hit the ground is \",round(OC),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The velocity of shell just before bursting is 500.0 m/s\n",
+ "(b) The velocity of first part immediately before the shell burst is 500.0 m/s\n",
+ "(c) The velocity of second part immediately after the shell burst is 1000.5 m/s\n",
+ "(b) The distance between the firing point & the point where the second part of the shell hit the ground is 3000.0 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 106
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 20.20-10,Page No:530"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "v_o=200 # m/s # initial velocity\n",
+ "theta=60 # degree # angle of the incline\n",
+ "y=5 # rise of incline\n",
+ "x=12 # length of incline\n",
+ "g=9.81 # m/s^2 # acc due to gravity\n",
+ "\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The angle of the inclined plane with respect to horizontal\n",
+ "beta=arctan(y*x**-1)*(180/pi) # degree\n",
+ "\n",
+ "# The angle of projection with respect to horizontal\n",
+ "alpha=90-theta # degree\n",
+ "\n",
+ "# Range is given by eq'n (ref. fig.20.14)\n",
+ "AB=(2*v_o**2*(sin((alpha-beta)*(pi/180)))*cos(alpha*(pi/180)))/(g*(cos(beta*(pi/180)))**2) # m\n",
+ "\n",
+ "# Range AC when the short is fired down the plane\n",
+ "AC=(2*v_o**2*(sin((alpha+beta)*(pi/180)))*cos(alpha*(pi/180)))/(g*(cos(beta*(pi/180)))**2) # m\n",
+ "BC=AB+AC # m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The range covered (i.e BC) is \",round(BC),\"m\" #due to decimal variancce answer varies by 1m\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The range covered (i.e BC) is 7649.0 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 138
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter21.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter21.ipynb
new file mode 100755
index 00000000..c58e0b47
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter21.ipynb
@@ -0,0 +1,658 @@
+{
+ "metadata": {
+ "name": "chapter21.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 21: Kinematics Of Rigid Body"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21.21-1,Page No:536"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "N=1800 # r.p.m # Speed of the shaft\n",
+ "t=5 # seconds # time taken to attain the rated speed # case (a)\n",
+ "T=90 # seconds # time taken by the unit to come to rest # case (b)\n",
+ "pi=3.14 # constant\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "omega=(2*pi*N)/(60)\n",
+ "\n",
+ "# (a)\n",
+ "# we take alpha_1,theta_1 & n_1 for case (a)\n",
+ "alpha_1=omega/t # rad/s^2 #\n",
+ "theta_1=(omega**2)/(2*alpha_1) # radian\n",
+ "# Let n_1 be the number of revolutions turned,\n",
+ "n_1=theta_1*(1/(2*pi))\n",
+ "\n",
+ "# (b)\n",
+ "# similarly we take alpha_1,theta_1 & n_1 for case (b)\n",
+ "alpha_2=(omega/T) # rad/s^2 # However here alpha_2 is -ve\n",
+ "theta_2=(omega**2)/(2*alpha_2) # radians\n",
+ "# Let n_2 be the number of revolutions turned,\n",
+ "n_2=theta_2*(1/(2*pi))\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The no of revolutions the unit turns to attain the rated speed is \",round(n_1)\n",
+ "print\"(b) The no of revolutions the unit turns to come to rest is \",round(n_2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The no of revolutions the unit turns to attain the rated speed is 75.0\n",
+ "(b) The no of revolutions the unit turns to come to rest is 1350.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21.21-2,Page No:540"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "r=1 # m # radius of the cylinder\n",
+ "v_c=20 # m/s # velocity of the cylinder at its centre\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The velocity of point E is given by using the triangle law as,\n",
+ "v_e=(2)**0.5*v_c # m/s \n",
+ "\n",
+ "# Similarly the velocity at point F is given as,\n",
+ "v_f=2*v_c # m/s \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity of point E is \",round(v_e,2),\"m/s\"\n",
+ "print\"The velocity of point F is \",round(v_f),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity of point E is 28.28 m/s\n",
+ "The velocity of point F is 40.0 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21.21-3,Page No:541"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of Variables\n",
+ "\n",
+ "v_1=3 # m/s # uniform speed of the belt at top\n",
+ "v_2=2 # m/s # uniform speed of the belt at the bottom\n",
+ "r=0.4 # m # radius of the roller\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# equating eq'ns 2 & 4 and solving for v_c & theta' (angular velocity). We use matrix to solve the eqn's\n",
+ "A=[1 r;1 -r]\n",
+ "B=[v_1;v_2]\n",
+ "C=inv(A)*B\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The linear velocity (v_c) at point C is \",round(C(1)),\"m/s\"\n",
+ "print\"The angular velocity at point C is \" round(C(2)),\"radian/second\"\n",
+ "# NOTE: The answer of angular velocity is incorrect in the book\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "SyntaxError",
+ "evalue": "invalid syntax (<ipython-input-4-f6df08d07dba>, line 12)",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;36m File \u001b[1;32m\"<ipython-input-4-f6df08d07dba>\"\u001b[1;36m, line \u001b[1;32m12\u001b[0m\n\u001b[1;33m A=[1 r;1 -r]\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21.21-4,Page No:542"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of Variables\n",
+ "\n",
+ "l=1 # m # length of bar AB\n",
+ "v_a=5 # m/s # velocity of A\n",
+ "theta=30 # degree # angle made by the bar with the horizontal\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# From the vector diagram linear velocity of end B is given as,\n",
+ "v_b=v_a/tan(theta*(pi/180)) # m/s \n",
+ "\n",
+ "# Now let the relative velocity be v_ba which is given as,\n",
+ "v_ba=v_a/sin(theta*(pi/180)) # m/s\n",
+ "\n",
+ "# Now let the angular velocity of the bar be theta_a which is given as,\n",
+ "theta_a=(v_ba)/l # radian/second\n",
+ "\n",
+ "# Velocity of point A\n",
+ "v_a=(0.5)*theta_a # m/s\n",
+ "\n",
+ "# Magnitude of velocity at point C is,\n",
+ "v_c=v_a # m/s # from the vector diagram\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The angular velocity of the bar is \",round(theta_a),\"radian/second\"\n",
+ "print\"(b) The velocity of end B is \",round(v_b,2),\"m/s\"\n",
+ "print\"(c) The velocity of mid point C is \",round(v_c),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The angular velocity of the bar is 10.0 radian/second\n",
+ "(b) The velocity of end B is 8.67 m/s\n",
+ "(c) The velocity of mid point C is 5.0 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21.21-5,Page No:544"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of Variables\n",
+ "\n",
+ "r=0.12 # m # length of the crank\n",
+ "l=0.6 # m # length of the connecting rod\n",
+ "N=300 # r.p.m # angular velocity of the crank\n",
+ "theta=30 # degree # angle made by the crank with the horizontal\n",
+ "pi=3.14\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Now let the angle between the connecting rod and the horizontal rod be phi\n",
+ "phi=arcsin(r*sin(theta*(pi/180))/(l))*(180/pi) # degree\n",
+ "\n",
+ "# Now let the angular velocity of crank OA be omega_oa, which is given by eq'n\n",
+ "omega_oa=(2*pi*N)/(60) # radian/second\n",
+ "\n",
+ "# Linear velocity at A is given as,\n",
+ "v_a=r*omega_oa # m/s\n",
+ "\n",
+ "# Now using the sine rule linear velocity at B can be given as,\n",
+ "v_b=v_a*sin(35.7*(pi/180))/sin(84.3*(pi/180)) # m/s\n",
+ "\n",
+ "# Similarly the relative velocity (assume v_ba) is given as,\n",
+ "v_ba=v_a*sin(60*(pi/180))/sin(84.3*(pi/180))\n",
+ "\n",
+ "# Angular velocity (omega_ab) is given as,\n",
+ "omega_ab=v_ba/l # radian/second\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The angular velocity of the connecting rod is \",round(omega_ab,2),\"radian/second\"\n",
+ "print\"(b) The velocity of the piston when the crank makes an angle of 30 degree is \",round(v_b,2),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The angular velocity of the connecting rod is 5.46 radian/second\n",
+ "(b) The velocity of the piston when the crank makes an angle of 30 degree is 2.21 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21.21-6,Page No:548"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initiization of variables\n",
+ "\n",
+ "r=1 # m # radius of the cylinder\n",
+ "v_c=20 # m/s # velocity at the centre\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Angular velocity is given as,\n",
+ "omega=v_c/r # radian/second\n",
+ "\n",
+ "# Velocity at point D is\n",
+ "v_d=omega*(2)**0.5*r # m/s # from eq'n 1\n",
+ "\n",
+ "# Now, the velocity at point E is,\n",
+ "v_e=omega*2*r # m/s \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity at point D is \",round(v_d,2),\"m/s\"\n",
+ "print\"The velocity at point E is \",round(v_e),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity at point D is 28.28 m/s\n",
+ "The velocity at point E is 40.0 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21.21-7,Page No:548"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of Variables\n",
+ "\n",
+ "r=5 # cm # radius of the roller\n",
+ "AB=0.1 # m\n",
+ "v_a=3 # m/s # velocity at A\n",
+ "v_b=2 # m/s # velocity at B\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Solving eqn's 1 & 2 using matrix for IA & IB we get,\n",
+ "A=[-2 3;1 1]\n",
+ "B=[0;AB]\n",
+ "C=inv(A)*B\n",
+ "d1=C(2)*10**2 # cm # assume d1 for case 1\n",
+ "\n",
+ "# Similary solving eqn's 3 & 4 again for IA & IB we get,\n",
+ "P=[-v_b v_a;1 -1]\n",
+ "Q=[0;AB]\n",
+ "R=inv(P)*Q\n",
+ "d2=R(2)*10**2 # cm # assume d2 for case 2\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The distance d when the bars move in the opposite directions are \",round(d1),\"cm\"\n",
+ "print\"The distance d when the bars move in the same directions are \",round(d2),\"cm\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "SyntaxError",
+ "evalue": "invalid syntax (<ipython-input-21-6e389b1a0870>, line 13)",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;36m File \u001b[1;32m\"<ipython-input-21-6e389b1a0870>\"\u001b[1;36m, line \u001b[1;32m13\u001b[0m\n\u001b[1;33m A=[-2 3;1 1]\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21.21-8,Page No:550"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of Variables\n",
+ "\n",
+ "v_c=1 # m/s # velocity t the centre\n",
+ "r1=0.1 # m \n",
+ "r2=0.20 # m\n",
+ "EB=0.1 # m\n",
+ "EA=0.3 # m\n",
+ "ED=(r1**2+r2**2)**0.5 # m\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# angular velocity is given as,\n",
+ "omega=v_c/r1 # radian/seconds\n",
+ "\n",
+ "# Velocit at point B\n",
+ "v_b=omega*EB # m/s \n",
+ "\n",
+ "# Velocity at point A\n",
+ "v_a=omega*EA # m/s\n",
+ "\n",
+ "# Velocity at point D\n",
+ "v_d=omega*ED # m/s\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity at point A is \",round(v_a),\"m/s\"\n",
+ "print\"The velocity at point B is \",round(v_b),\"m/s\"\n",
+ "print\"The velocity at point D is \",round(v_d,2),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity at point A is 3.0 m/s\n",
+ "The velocity at point B is 1.0 m/s\n",
+ "The velocity at point D is 2.24 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21.21-9,Page No:551"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "l=1 # m # length of bar AB\n",
+ "v_a=5 # m/s # velocity at A\n",
+ "theta=30 # degree # angle made by the bar with the horizontal\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "IA=l*sin(theta*(pi/180)) # m\n",
+ "IB=l*cos(theta*(pi/180)) # m\n",
+ "IC=0.5 # m # from triangle IAC\n",
+ "\n",
+ "# Angular veocity is given as,\n",
+ "omega=v_a/(IA) # radian/second\n",
+ "v_b=omega*IB # m/s\n",
+ "v_c=omega*IC # m/s\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity at point B is \",round(v_b,2),\"m/s\"\n",
+ "print\"The velocity at point C is \",round(v_c),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity at point B is 8.67 m/s\n",
+ "The velocity at point C is 5.0 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21.21-11,Page No:552"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "v_a=2 # m/s # velocity at end A\n",
+ "r=0.05 # m # radius of the disc\n",
+ "alpha=30 # degree # angle made by the bar with the horizontal\n",
+ "\n",
+ "# Calculations \n",
+ "\n",
+ "# Soving eqn's 1 & 2 and substuting eqn 1 in it we get eq'n for omega as,\n",
+ "omega=(v_a*(sin(alpha*(pi/180)))**2)/(r*cos(alpha*(pi/180))) # radian/second\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The anguar veocity of the bar is \",round(omega,2),\"radian/second\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The anguar veocity of the bar is 11.53 radian/second\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21.21-12,Page No:553"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "l=0.6 # m \n",
+ "r=0.12 # m \n",
+ "theta=30 # degree # angle made by OA with the horizontal\n",
+ "phi=5.7 # degree # from EX 21.5\n",
+ "N=300\n",
+ "pi=3.14\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Let the angular velocity of the connecting rod be (omega_ab) which is given from eqn's 1 & 4 as,\n",
+ "omega_oa=(2*pi*N)/(60) # radian/ second\n",
+ "\n",
+ "# Now,in triangle IBO.\n",
+ "IB=(l*cos(phi*(pi/180))*tan(theta*(pi/180)))+(r*sin(theta*(pi/180))) # m\n",
+ "IA=(l*cos(phi*(pi/180)))/(cos(theta*(pi/180))) # m\n",
+ "\n",
+ "# from eq'n 5\n",
+ "v_b=(r*omega_oa*IB)/(IA) # m/s\n",
+ "\n",
+ "# From eq'n 6\n",
+ "omega_ab=(r*omega_oa)/(IA) # radian/second\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The velocity at B is \",round(v_b,2),\"m/s\"\n",
+ "print\"The angular velocity of the connecting rod is \",round(omega_ab,2),\"radian/second\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The velocity at B is 2.21 m/s\n",
+ "The angular velocity of the connecting rod is 5.47 radian/second\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21.21-13,Page No:555"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "omega_ab=5 # rad/s # angular veocity of the bar\n",
+ "AB=0.20 # m\n",
+ "BC=0.15 # m\n",
+ "CD=0.3 # m\n",
+ "theta=30 # degree # where theta= angle made by AB with the horizontal\n",
+ "alpha=60 # degree # where alpha=angle made by CD with the horizontal\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Consider triangle BIC\n",
+ "IB=sin(alpha*(pi/180))*BC*1 # m\n",
+ "IC=sin(theta*(pi/180))*BC*1 # m\n",
+ "v_b=omega_ab*AB # m/s\n",
+ "\n",
+ "# let the angular velocity of the bar BC be omega_bc\n",
+ "omega_bc=v_b/IB # radian/second\n",
+ "v_c=omega_bc*IC # m/s\n",
+ "\n",
+ "# let the angular velocity of bar DC be omega_dc\n",
+ "omega_dc=v_c/CD # radian/second\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The angular velocity of bar BC is \",round(omega_bc,3),\"rad/s\"\n",
+ "print\"The angular velocity of bar CD is \",round(omega_dc,2),\"rad/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The angular velocity of bar BC is 7.7 rad/s\n",
+ "The angular velocity of bar CD is 1.92 rad/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter22.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter22.ipynb
new file mode 100755
index 00000000..c5908132
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter22.ipynb
@@ -0,0 +1,282 @@
+{
+ "metadata": {
+ "name": "chapter22.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 22: Kinetics Of Rigid Body:Force And Acceleration"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 22.22-1,Page No:562"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "N=1500 # r.p.m\n",
+ "r=0.5 # m # radius of the disc\n",
+ "m=300 # N # weight of the disc\n",
+ "t=120 # seconds # time in which the disc comes to rest\n",
+ "omega=0 \n",
+ "pi=3.14 \n",
+ "g=9.81 # m/s^2\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "omega_0=(2*pi*N)*0.01666 # rad/s #1/60=0.01666\n",
+ "\n",
+ "# angular deceleration is given as,\n",
+ "alpha=-(omega_0/t) # radian/second^2\n",
+ "theta=(omega_0**2)/(2*(-alpha)) # radian\n",
+ "\n",
+ "# Let n be the no of revolutions taken by the disc before it comes to rest, then\n",
+ "n=theta/(2*pi)\n",
+ "\n",
+ "# Now,\n",
+ "I_G=((0.5)*m*r**2)/g\n",
+ "\n",
+ "# The frictional torque is given as,\n",
+ "M=I_G*alpha # N-m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The no of revolutions executed by the disc before coming to rest is \",round(n,2)\n",
+ "print\"(b) The frictional torque is \",round(M),\"N-m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The no of revolutions executed by the disc before coming to rest is 1499.4\n",
+ "(b) The frictional torque is -5.0 N-m\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 22.22-2,Page No:563"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "s=1 # m\n",
+ "mu=0.192 # coefficient of static friction\n",
+ "g=9.81 # m/s^2\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The maximum angle of the inclined plane is given as,\n",
+ "theta=arctan(3*mu)*(180/pi) # degree\n",
+ "a=(2/3)*g*sin(theta*(pi/180)) # m/s^2 # by solving eq'n 4\n",
+ "v=(2*a*s)**0.5 # m/s\n",
+ "\n",
+ "# Let the acceleration at the centre be A which is given as,\n",
+ "A=g*sin(theta*(pi/180)) # m/s^2 # from eq'n 1\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The acceleration at the centre is \",round(A,3),\"m/s^2\"\n",
+ "print\"(b) The maximum angle of the inclined plane is \",round(theta),\"degree\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The acceleration at the centre is 4.896 m/s^2\n",
+ "(b) The maximum angle of the inclined plane is 30.0 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 22.22-5,Page No:568"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "W_a=25 # N \n",
+ "W_b=25 # N \n",
+ "W=200 # N # weight of the pulley\n",
+ "i_g=0.2 # m # radius of gyration\n",
+ "g=9.81 # m/s^2\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Solving eqn's 1 & 2 for acceleration of weight A (assume a)\n",
+ "a=(0.15*W_a*g)/(((W*i_g**2)/(0.45))+(0.45*W_a)+((0.6*W_b)/(3))) # m/s^2\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The acceleration of weight A is \",round(a,2),\"m/s^2\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The acceleration of weight A is 1.08 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 22.22-8,Page No:571"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "r_1=0.075 # m\n",
+ "r_2=0.15 # m\n",
+ "P=50 # N\n",
+ "W=100 # N\n",
+ "i_g=0.05 # m\n",
+ "theta=30 # degree\n",
+ "g=9.81 # m/s^2\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The eq'n for acceleration of the pool is given by solving eqn's 1,2 &3 as,\n",
+ "a=(50*g*(r_2*cos(theta*(pi/180))-r_1))/(100*((i_g**2/r_2)+r_2)) # m/s^2\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The acceleration of the pool is \",round(a,2),\"m/s^2\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The acceleration of the pool is 1.62 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 22.22-10,Page No:574"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "L=1 # m # length of rod AB\n",
+ "m=10 # kg # mass of the rod\n",
+ "g=9.81 \n",
+ "theta=30 # degree\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# solving eq'n 4 for omega we get,\n",
+ "omega=(2*16.82*sin(theta*(pi/180)))**0.5 # rad/s\n",
+ "\n",
+ "# Now solving eq'ns 1 &3 for alpha we get,\n",
+ "alpha=(1.714)*g*cos(theta*(pi/180)) # rad/s\n",
+ "\n",
+ "# Components of reaction are given as,\n",
+ "R_t=((m*g*cos(theta*(pi/180)))-((m*alpha*L)/4)) # N\n",
+ "R_n=((m*omega**2*L)/4)+(m*g*sin(theta*(pi/180))) # N\n",
+ "R=(R_t**2+R_n**2)**0.5 # N \n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The angular velocity of the rod is \",round(omega,2),\"rad/sec\"\n",
+ "print\"(b) The reaction at the hinge is \",round(R,1),\"N\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The angular velocity of the rod is 4.1 rad/sec\n",
+ "(b) The reaction at the hinge is 103.2 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter23.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter23.ipynb
new file mode 100755
index 00000000..e2d06a9e
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter23.ipynb
@@ -0,0 +1,74 @@
+{
+ "metadata": {
+ "name": "chapter23.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 23: Kinetics Of Rigid Body:Work And Energy"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 23.23-2,Page No:586"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "m=600 # kg # mass of the roller\n",
+ "r=0.25 # m # radius of the roller\n",
+ "P=850 # N # Force\n",
+ "v=3 # m/s # velocity to be acquired\n",
+ "theta=30 # degree # angle made by v with the force P\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The distance required to be rolled is given by equating the Work done between positions 1 & 2 as,\n",
+ "x=((0.75)*m*v**2)/(P*cos(theta*(pi/180))) # m\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The distance required to be rolled is \",round(x,1),\"m\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The distance required to be rolled is 5.5 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter24.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter24.ipynb
new file mode 100755
index 00000000..9fcc267a
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter24.ipynb
@@ -0,0 +1,349 @@
+{
+ "metadata": {
+ "name": "chapter24.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 24: Mechanical Vibrations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 24.24-1,Page No:596"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "f=0.1666666 # oscillations/second\n",
+ "x=8 # cm # distance from the mean position\n",
+ "pi=3.14\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "omega=2*pi*f\n",
+ "\n",
+ "# Amplitude is given by eq'n \n",
+ "r=sqrt((25*x**2)/16) # cm\n",
+ "\n",
+ "# Maximum acceleration is given as,\n",
+ "a_max=(pi/3)**2*10 # cm/s^2\n",
+ "\n",
+ "# Velocity when it is at a dist of 5 cm (assume s=5 cm) is given by\n",
+ "s=5 # cm\n",
+ "v=omega*(r**2-s**2)**0.5 # cm/s\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The amplitude of oscillation is \",round(r,2),\"cm\"\n",
+ "print\"(b) The maximum acceleration is \",round(a_max,2),\"cm/s^2\"\n",
+ "print\"(c) The velocity of the particle at 5 cm from mean position is \",round(v,2),\"cm/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The amplitude of oscillation is 10.0 cm\n",
+ "(b) The maximum acceleration is 10.96 cm/s^2\n",
+ "(c) The velocity of the particle at 5 cm from mean position is 9.06 cm/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 24.24-2,Page No:597"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "x_1=0.1 # m # assume the distance of the particle from mean position as (x_1 & x_2)\n",
+ "x_2=0.2# m \n",
+ "\n",
+ "# assume velocities as v_1 & v_2\n",
+ "\n",
+ "v_1=1.2 # m/s\n",
+ "v_2=0.8 # m/s\n",
+ "pi=3.14\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# The amplitude of oscillations is given by dividing eq'n 1 by 2 as,\n",
+ "r=(0.064)**0.5 # m\n",
+ "omega=v_1*((r**2-x_1**2)**0.5) # radians/second\n",
+ "t=(2*pi)/omega # seconds\n",
+ "v_max=r*omega # m/s\n",
+ "\n",
+ "# let the max acceleration be a which is given as,\n",
+ "a=r*omega**2 # m/s^2\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The amplitude of oscillations is \",round(r,3),\"m\"\n",
+ "print\"(b) The time period of oscillations is \",round(t,2),\"seconds\"\n",
+ "print\"(c) The maximum velocity is \",round(v_max,2),\"m/s\"\n",
+ "print\"(d) The maximum acceleration is \",round(a,2),\"m/s^2\"\n",
+ "# NOTE: the value of t is incorrect in the text book\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The amplitude of oscillations is 0.253 m\n",
+ "(b) The time period of oscillations is 1.22 seconds\n",
+ "(c) The maximum velocity is 1.31 m/s\n",
+ "(d) The maximum acceleration is 6.75 m/s^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Exammple 24.24-5,Page No:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variabes\n",
+ "\n",
+ "W=50 # N # weight\n",
+ "x_0=0.075 # m # amplitude\n",
+ "f=1 # oscillation/sec # frequency\n",
+ "pi=3.14\n",
+ "g=9.81 \n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "omega=2*pi*f\n",
+ "K=(((2*pi)**2*W)/g)*(10**-2) # N/cm\n",
+ "\n",
+ "# let the total extension of the string be delta which is given as,\n",
+ "delta=(W/K)+(x_0*10**2) # cm\n",
+ "T=K*delta # N # Max Tension\n",
+ "v=omega*x_0 #m/s # max velocity\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"(a) The stiffness of the spring is \",round(K,2),\"N/cm\"\n",
+ "print\"(b) The maximum Tension in the spring is \",round(T,2),\"N\"\n",
+ "print\"(c) The maximum velocity is \",round(v,2),\"m/s\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) The stiffness of the spring is 2.01 N/cm\n",
+ "(b) The maximum Tension in the spring is 65.08 N\n",
+ "(c) The maximum velocity is 0.47 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 24.24-10,Page No:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "l=1 # m # length of the simple pendulum\n",
+ "g=9.81 # m/s^2\n",
+ "pi=3.14\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Let t_s be the time period when the elevator is stationary\n",
+ "t_s=2*pi*(l/g)**0.5 #/ seconds\n",
+ "\n",
+ "# Let t_u be the time period when the elevator moves upwards. Then from eqn 1\n",
+ "t_u=2*pi*((l)/(g+(g/10)))**0.5 # seconds\n",
+ "\n",
+ "# Let t_d be the time period when the elevator moves downwards.\n",
+ "t_d=2*pi*(l/(g-(g/10)))**0.5 # seconds\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The time period of oscillation of the pendulum for upward acc of the elevator is \",round(t_u,2),\"seconds\"\n",
+ "print\"The time period of oscillation of the pendulum for downward acc of the elevator is \",round(t_d,2),\"seconds\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The time period of oscillation of the pendulum for upward acc of the elevator is 1.91 seconds\n",
+ "The time period of oscillation of the pendulum for downward acc of the elevator is 2.11 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 24.24-11,Page No:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "t=1 # second # time period of the simple pendulum\n",
+ "g=9.81 # m/s^2\n",
+ "pi=3.14\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# Length of pendulum is given as,\n",
+ "l=(t/(2*pi)**2)*g # m\n",
+ "\n",
+ "# Let t_u be the time period when the elevator moves upwards. Then the time period is given as,\n",
+ "t_u=2*pi*((l)/(g+(g/10)))**0.5 # seconds\n",
+ "\n",
+ "# Let t_d be the time period when the elevator moves downwards.\n",
+ "t_d=2*pi*(l/(g-(g/10)))**0.5 # seconds\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The time period of oscillation of the pendulum for upward acc of the elevator is \",round(t_u,2),\"seconds\"\n",
+ "print\"The time period of oscillation of the pendulum for downward acc of the elevator is \",round(t_d,2),\"seconds\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The time period of oscillation of the pendulum for upward acc of the elevator is 0.95 seconds\n",
+ "The time period of oscillation of the pendulum for downward acc of the elevator is 1.05 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 24.24-12,Page No:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "m=15 # kg # mass of the disc\n",
+ "D=0.3 # m # diameter of the disc\n",
+ "R=0.15 # m # radius\n",
+ "l=1 # m # length of the shaft\n",
+ "d=0.01 # m # diameter of the shaft\n",
+ "G=30*10**9 # N-m^2 # modulus of rigidity\n",
+ "pi=3.14\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# M.I of the disc about the axis of rotation is given as,\n",
+ "I=(m*R**2)*0.5 # kg-m^2\n",
+ "\n",
+ "# Stiffness of the shaft\n",
+ "k_t=(pi*d**4*G)/(32*l) # N-m/radian\n",
+ "t=2*pi*(I/k_t)**0.5 # seconds\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The time period of oscillations of the disc is \",round(t,2),\"seconds\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The time period of oscillations of the disc is 0.48 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 24
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Mechanics_by_Tayal_A.K./chapter25.ipynb b/Engineering_Mechanics_by_Tayal_A.K./chapter25.ipynb
new file mode 100755
index 00000000..c424f5bc
--- /dev/null
+++ b/Engineering_Mechanics_by_Tayal_A.K./chapter25.ipynb
@@ -0,0 +1,217 @@
+{
+ "metadata": {
+ "name": "chapter25.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 25 :Shear Force And Bending Moment"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 25.25-5,Page No:628"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import matplotlib.pyplot as plt\n",
+ "%matplotlib inline\n",
+ "\n",
+ "# Initilization of variables\n",
+ "L_AB=3 # m # length of the beam\n",
+ "L_AC=1 # m\n",
+ "L_BC=2 # m\n",
+ "M_C=12 # kNm # clockwise moment at C\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# REACTIONS\n",
+ "R_B=M_C/L_AB # kN # moment at A\n",
+ "R_A=-M_C/L_AB # kN # moment at B\n",
+ "\n",
+ "# S.F\n",
+ "F_A=R_A # kN \n",
+ "F_B=R_A # kN\n",
+ "\n",
+ "# B.M\n",
+ "M_A=0 # kNm\n",
+ "M_C1=R_A*L_AC # kNm # M_C1 is the BM just before C\n",
+ "M_C2=(R_A*L_AC)+M_C # kNm # M_C2 is the BM just after C\n",
+ "M_B=0 # kNm\n",
+ "\n",
+ "# Plotting SFD & BMD\n",
+ "x=[0, 0.99, 1, 3]\n",
+ "y=[-4, -4, -4, -4]\n",
+ "a=[0, 0.99, 1, 3]\n",
+ "b=[0, -4, 8, 0]\n",
+ "g=[0,0,0,0]\n",
+ "d=transpose(x)\n",
+ "e=transpose(b)\n",
+ "plt.plot(d,y)\n",
+ "plt.show()\n",
+ "plt.plot(a,e,a,g)\n",
+ "plt.show()\n",
+ "\n",
+ "# Results\n",
+ "print \"The graphs are the solutions\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\nRQAAAABJRU5ErkJggg==\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x5b828b0>"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\nS1OnStu32zcMA2CWiNWCNP7nP/+pa665Rm3btpUk7dq1S1lZWSovL1enTp0abZuTk6OdyX5MDwCE\nTPfu3bVjx45mf12LQv1Ul1xyidavX68LLrjA7UsBAFzw5KK1CMNXAAgET5o6ACAYPPvxkhUrVig3\nN1c9evTQnDlzHLe599571aNHDxUWFqqiosKrt06JpvYvFoupffv2KioqUlFRkX7961/7sMqWmTBh\ngjp37qw+ffrE3cbkY9fU/pl87KqqqjRo0CD16tVLvXv31rx58xy3M/X4JbJ/Jh+/48ePq7i4WH37\n9lV+fr4efvhhx+2adfwsD5w4ccLq3r279emnn1rV1dVWYWGhtXXr1kbbLFu2zBo2bJhlWZZVVlZm\nFRcXe/HWKZHI/q1atcq6/vrrfVqhO3//+9+tDRs2WL1793b8vMnHzrKa3j+Tj93evXutiooKy7Is\n6/Dhw1bPnj1Dde4lsn8mHz/Lsqwvv/zSsizLqqmpsYqLi601a9Y0+nxzj58nTb28vFw5OTm6+OKL\n1aZNG40dO1ZLly5ttM2f//xnlZaWSpKKi4t18OBB7WvuTb59ksj+SeZe1nnFFVfo/PPPj/t5k4+d\n1PT+SeYeuy5duqhv376SpMzMTOXl5WnPKY+8Mvn4JbJ/krnHT1LDVYTV1dWqra097YKT5h4/T0J9\n9+7d6tq1a8Ofs7OztXv37ia32bVrlxdvn3SJ7F8kEtH777+vwsJCDR8+XFu3bk31MpPG5GOXiLAc\nu8rKSlVUVKi4uLjRx8Ny/OLtn+nHr66uTn379lXnzp01aNAg5efnN/p8c4+fJz9ekujVL6f+a2rK\nVTOJrLNfv36qqqpS27Zt9Ze//EUjR47Uxx9/nILVpYapxy4RYTh2R44c0ZgxYzR37lxlZmae9nnT\nj9+Z9s/049eqVSt99NFHOnTokIYOHapYLKZoNNpom+YcP0+aelZWlqqqqhr+XFVVpezs7DNuU/8D\nSyZIZP/OO++8hv9GDRs2TDU1NaG5c6XJxy4Rph+7mpoajR49WuPHj9fIkSNP+7zpx6+p/TP9+NVr\n3769rr32Wq1bt67Rx5t7/DwJ9QEDBmj79u2qrKxUdXW1Fi1apBEjRjTaZsSIEVqwYIEkqaysTB06\ndFDnzp29ePukS2T/9u3b1/CvaXl5uSzLCs0PY5l87BJh8rGzLEsTJ05Ufn6+7rvvPsdtTD5+ieyf\nycfvwIEDOvi/26MeO3ZMK1euVFFRUaNtmnv8PBm/ZGRk6KmnntLQoUNVW1uriRMnKi8vT88995wk\n6a677tLw4cO1fPly5eTkqF27dpo/f74Xb50SiezfkiVL9OyzzyojI0Nt27bVa6+95vOqE3fzzTdr\n9erVOnDggLp27aoZM2aopqZGkvnHTmp6/0w+dmvXrtXChQtVUFDQEAazZs3Sf/7zH0nmH79E9s/k\n47d3716Vlpaqrq5OdXV1uvXWW3XNNde4yk5++AgAQoRn2wBAiBDqABAihDoAhAihDgAhQqgDQIgQ\n6gAQIoQ6AIQIoQ4AIfL/2SSvyxXhJiEAAAAASUVORK5CYII=\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x5c897b0>"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The graphs are the solutions\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 25.25-7,Page No:631"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import matplotlib.pyplot as plt\n",
+ "%matplotlib inline\n",
+ "import numpy as np\n",
+ "\n",
+ "# Initilization of variables\n",
+ "\n",
+ "L_AD=8 # m # length of the beam\n",
+ "L_AB=2 # m \n",
+ "L_BC=4 # m\n",
+ "L_CD=2 # m\n",
+ "UDL=1 # kN/m\n",
+ "P=2 # kN # point load at A\n",
+ "\n",
+ "# Calculations\n",
+ "\n",
+ "# REACTIONS\n",
+ "\n",
+ "# solving eqn's 1&2 using matrix to get R_B & R_C as,\n",
+ "\n",
+ "A=np.array([[1, 1],[ 1, 3]])\n",
+ "B=np.array([8,15])\n",
+ "C=np.linalg.solve(A,B)\n",
+ "\n",
+ "# SHEAR FORCE\n",
+ "\n",
+ "# the term F with suffixes 1 & 2 indicates SF just to left and right \n",
+ "F_A=-P # kN\n",
+ "F_B1=-P # kN\n",
+ "F_B2=-P+C[0] # kN\n",
+ "F_C1=-P+C[0]-(UDL*L_BC) # kN\n",
+ "F_C2=-P+C[0]-(UDL*L_BC)+C[1] # kN\n",
+ "F_D=0\n",
+ "\n",
+ "# BENDING MOMENT\n",
+ "\n",
+ "# the term F with suffixes 1 & 2 indicates BM just to left and right\n",
+ "M_A=0 # kNm\n",
+ "M_B=(-P*L_CD) # kNm\n",
+ "M_C=(-P*(L_AB+L_BC))+(C[0]*L_BC)-(UDL*L_BC*(L_BC/2)) # kNm\n",
+ "M_D=0 # kNm\n",
+ "\n",
+ "# LOCATION OF MAXIMUM BM\n",
+ "\n",
+ "# Max BM occurs at E at a distance of 2.5 m from B i.e x=L_AE=4.5 m from free end A. Thus max BM is given by taking moment at B\n",
+ "L_AE=4.5 # m # given\n",
+ "M_E=(-2*L_AE)+(4.5*(L_AE-2))-((1/2)*(L_AE-2)**2) # kNm\n",
+ "\n",
+ "#Plotting\n",
+ "x_p=linspace(2,6,40)\n",
+ "M_p=-2*+4.5*(x_p-2)-((x_p-2)**2)*0.5\n",
+ "\n",
+ "# PLOTTING SFD & BMD\n",
+ "x=[0,1.99,2,4.5,5.99,6,8]\n",
+ "y=[-2,-2,2.5,0,-1.5,2,0]\n",
+ "z=[0,0,0,0,0,0,0]\n",
+ "a=[0,2,4.5,6,8]\n",
+ "b=[0,-4,-0.875,-2,0]\n",
+ "g=[0,0,0,0,0]\n",
+ "d=transpose(x)\n",
+ "plt.plot(d,y,x,z)\n",
+ "plt.show()\n",
+ "e=transpose(b)\n",
+ "plt.plot(a,e,a,g)\n",
+ "plt.show()\n",
+ "\n",
+ "\n",
+ "# Results\n",
+ "\n",
+ "print\"The graphs are the solutions\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\nRU5ErkJggg==\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x5b10e30>"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\n/T/kZq6+7dkZ0AAAAABJRU5ErkJggg==\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x5baadb0>"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The graphs are the solutions\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics/Chapter11_1.ipynb b/Engineering_Physics/Chapter11_1.ipynb
deleted file mode 100755
index 39762859..00000000
--- a/Engineering_Physics/Chapter11_1.ipynb
+++ /dev/null
@@ -1,620 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:1d5f4970753c62d94a2bd202867cc0f79046f1baac4b1a42721a5ae6844ad5f4"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "11: Nuclear Radiations and Detectors"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.1, Page number 227"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "r0=1.2; #radius(fm)\n",
- "A=7; #mass number \n",
- "\n",
- "#Calculation \n",
- "r=r0*A**(1/3);\t #radius of Li(fm) \n",
- "\n",
- "#Result\n",
- "print \"The radius of Li is\",round(r,4),\"fm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The radius of Li is 2.2955 fm\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.2, Page number 227"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "M=235.043945; #atomic mass of uranium(u)\n",
- "Z=92; #atomic number of uranium\n",
- "mp=1.007825; #mass of proton(kg)\n",
- "N=143; #no.of neutrons\n",
- "mn=1.008665; #mass of neutron(kg)\n",
- "A=235; #number of nucleons\n",
- "\n",
- "#Calculation \n",
- "B=(((Z*mp)+(N*mn)-(M))/A)*931.5; #Binding energy(MeV)\n",
- "\n",
- "#Result\n",
- "print \"The binding energy per nucleon is\",round(B,3),\"MeV\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The binding energy per nucleon is 7.591 MeV\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.3, Page number 227"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#After removing one neutron from Ca(A=43;Z=20) it becomes Ca(A=42;Z=20)\n",
- "M=41.958622; #mass of Ca(A=42;Z=20)(kg)\n",
- "mn=1.008665; #mass of neutron(kg)\n",
- "E=42.95877; #mass of Ca(A=43;Z=20)(kg)\n",
- "\n",
- "#Calculation \n",
- "C=M+mn;\n",
- "D=C-E;\n",
- "B=D*931.5; #Binding energy of neutron(MeV)\n",
- "\n",
- "#Result\n",
- "print \"The binding energy of neutron is\",round(B,4),\"MeV\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The binding energy of neutron is 7.9336 MeV\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.4, Page number 227"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "mBe=9.012182; #Atomic mass of beryllium(u)\n",
- "mHe=4.002603; #Atomic mass of helium\n",
- "mn=1.008665; #mass of neutron(kg)\n",
- "mC=12.000000; #Atomic mass of carbon\n",
- "\n",
- "#Calculation \n",
- "Q=(mBe+mHe-mn-mC)*931.5 #energy balance of the reaction(MeV)\n",
- "\n",
- "#Result\n",
- "print \"The Q-value is\",round(Q,1),\"MeV\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The Q-value is 5.7 MeV\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.5, Page number 227"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "mLi=7.016004; #mass of Lithium(A=7)(u)\n",
- "mH=1.007825; #mass of Hydrogen(A=1)(u)\n",
- "mHe=4.002603; #mass of helium(A=4)(u)\n",
- "p=0.5; #energy of proton(MeV)\n",
- "\n",
- "#Calculation \n",
- "Q=(mLi+mH-2*(mHe))*931.5 #energy balance of the reaction(MeV)\n",
- "#The energy of 2 alpha particles is equal to the Q-value + energy of proton.\n",
- "Ealpha=(Q+p)/2; #energy of each alpha particle(MeV)\n",
- "\n",
- "#Result\n",
- "print \"The Q-value of the reaction is\",round(Q,2),\"MeV\"\n",
- "print \"The energy of each alpha particle is\",round(Ealpha,3),\"MeV\"\n",
- "print \"answer for energy in the book varies due to rounding off errors\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The Q-value of the reaction is 17.35 MeV\n",
- "The energy of each alpha particle is 8.924 MeV\n",
- "answer for energy in the book varies due to rounding off errors\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.6, Page number 228"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "wt=1000; #weight(gm)\n",
- "A=235; #mass number of uranium\n",
- "N=(6.02*10**23/A)*wt; #no.of nuclei in 1kg of uranium\n",
- "Q=208; #energy-balance of the reaction\n",
- "\n",
- "#Calculation \n",
- "E=N*Q; #Energy released(MeV)\n",
- "#1MeV=4.45*10^-20kWh\n",
- "E=E*4.45*10**-20;\n",
- "\n",
- "#Result\n",
- "print \"The energy released is\",round(E/10**7,3),\"*10**7 kWh\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The energy released is 2.371 *10**7 kWh\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.7, Page number 228"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "wt=5000; #weight(gm)\n",
- "A=235; #mass number of uranium\n",
- "Ef=208; #Energy released per fission(MeV)\n",
- "\n",
- "#Calculation \n",
- "N=(6.02*10**23/A)*wt; #number of nuclei in 5 Kg\n",
- "E=N*Ef; #Energy(MeV)\n",
- "E=E*1.6*10**-13; #Energy(J)\n",
- "T=24*60*60; #time\n",
- "P=E/T; #power(MW)\n",
- "\n",
- "#Result\n",
- "print \"The power output of a nuclear reactor is\",round(P/10**6),\"MW\"\n",
- "print \"answer given in the book is wrong\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The power output of a nuclear reactor is 4934.0 MW\n",
- "answer given in the book is wrong\n"
- ]
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.8, Page number 228"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "A=235; #mass number of uranium\n",
- "p=1000; #amount of electric power produced(MW)\n",
- "e=0.32; #energy conversion efficiency of the plant\n",
- "f=200; #fission energy per event(MeV)\n",
- "\n",
- "#Calculation \n",
- "I=p/e; #Input nuclear energy(MW)\n",
- "TE=I*(10**6)*3600*24*365; #total energy(J)\n",
- "EF=f*(10**6)*1.6*10**-19; #Energy released per fission event(J)\n",
- "N=TE/EF; #Number of nuclei required\n",
- "M=N*A/(6.02*10**23); #corresponding mass(g)\n",
- "\n",
- "#Result\n",
- "print \"The amount of uranium required is\",round(M*10**-3,1),\"kg\"\n",
- "print \"answer in the book varies due to rounding off errors\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The amount of uranium required is 1202.2 kg\n",
- "answer in the book varies due to rounding off errors\n"
- ]
- }
- ],
- "prompt_number": 22
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.9, Page number 229"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "q=1.6*10**-19; #charge of the particle(c)\n",
- "B=1; #magnetic field(T)\n",
- "m=1.67*10**-27; #mass of proton(kg)\n",
- "r=0.5; #radius(m)\n",
- "\n",
- "#Calculation \n",
- "omega=(q*B)/m; #angular frequency(radian/s)\n",
- "v=(omega/(2*math.pi))*10**-8; #frequency(MHz)\n",
- "s=omega*r; #speed of proton(m/s)\n",
- "K=(m*(s**2))*(1/2)*6.27*10**12; #kinetic energy of protons emerging from cyclotron(MeV)\n",
- "\n",
- "#Result\n",
- "print \"The frequency of oscillator to accelerate protons is\",round(omega/10**8,2),\"*10**8 radian/s\"\n",
- "print \"The speed of proton is\",round(s/10**7,1),\"*10**7 m/s\"\n",
- "print \"The kinetic energy of protons emerging from the cyclotron is\",int(K),\"MeV\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The frequency of oscillator to accelerate protons is 0.96 *10**8 radian/s\n",
- "The speed of proton is 4.8 *10**7 m/s\n",
- "The kinetic energy of protons emerging from the cyclotron is 12 MeV\n"
- ]
- }
- ],
- "prompt_number": 28
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.10, Page number 229"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "rho=1.83*10**17; #average density of carbon nucleus(kg/m^3)\n",
- "m=12; #mass(u)\n",
- "e=1.66*10**-27;\n",
- "\n",
- "#Calculation \n",
- "r=(m*e/((4/3)*math.pi*rho))**(1/3)*10**15; #radius(fm)\n",
- "\n",
- "#Result\n",
- "print \"The radius is\",round(r,2),\"fm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The radius is 2.96 fm\n"
- ]
- }
- ],
- "prompt_number": 30
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.11, Page number 229"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "q=1.6*10**-19; #charge of the particle(c)\n",
- "B=5; #magnetic field(T)\n",
- "m=9.1*10**-31; #mass of electron(kg)\n",
- "\n",
- "#Calculation \n",
- "v=(q*B)/(2*math.pi*m); #cyclotron frequency(Hz)\n",
- "\n",
- "#Result\n",
- "print \"cyclotron frequency of electron is\",round(v/10**11,1),\"*10**11 Hz\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "cyclotron frequency of electron is 1.4 *10**11 Hz\n"
- ]
- }
- ],
- "prompt_number": 32
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.12, Page number 229"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "k=1.5; #maximum kinetic energy(MeV)\n",
- "m=1.67*10**-27; #mass of proton(kg)\n",
- "q=1.6*10**-19; #charge of particle(c)\n",
- "r=0.35; #radius(m)\n",
- "\n",
- "#Calculation \n",
- "B=math.sqrt(k*10**6*q*2*m)/(q*r); #magnetic field(T)\n",
- "\n",
- "#Result\n",
- "print \"The mgnetic field is\",round(B,1),\"T\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The mgnetic field is 0.5 T\n"
- ]
- }
- ],
- "prompt_number": 34
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.13, Page number 229"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "m=1.67*10**-27; #mass of proton(kg)\n",
- "q=1.6*10**-19; #charge of particle(q)\n",
- "v=25; #cyclotron frequency(MHz)\n",
- "\n",
- "#Calculation \n",
- "B=(v*10**6*2*math.pi*m)/q; #magnetic field(T)\n",
- "\n",
- "#Result\n",
- "print \"The required magnetic field is\",round(B,4),\"T\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The required magnetic field is 1.6395 T\n"
- ]
- }
- ],
- "prompt_number": 37
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 11.14, Page number 229"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "v=20; #cyclotron frequency(MHz)\n",
- "B=1.3; #magnetic field(T)\n",
- "\n",
- "#Calculation \n",
- "d=2*math.pi*v*10**6/B; #charge to mass ratio of proton(C/kg)\n",
- "\n",
- "#Result\n",
- "print \"charge to mass ratio of proton is\",round(d/10**6,2),\"*10**6 C/kg\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "charge to mass ratio of proton is 96.66 *10**6 C/kg\n"
- ]
- }
- ],
- "prompt_number": 39
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/Chapter13_1.ipynb b/Engineering_Physics/Chapter13_1.ipynb
deleted file mode 100755
index 83323d13..00000000
--- a/Engineering_Physics/Chapter13_1.ipynb
+++ /dev/null
@@ -1,386 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:46a82c7fe1b65af7ee26b9fa38521b26c61cee31bc75dd5001fe45442416739c"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "13: Optical Fibre"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 13.1, Page number 250"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "n1=1.49; #refractive index of core\n",
- "n2=1.46; #refractive index of cladding\n",
- "\n",
- "#Calculation \n",
- "NA=math.sqrt((n1**2)-(n2**2)); #Numerical aperture\n",
- "\n",
- "#Result\n",
- "print \"The numerical aperture is\",round(NA,1)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The numerical aperture is 0.3\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 13.2, Page number 250"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "NA=0.5; #numerical aperture of fibre \n",
- "n0=1; #refractive index of the medium(air)\n",
- "\n",
- "#Calculation \n",
- "i=math.asin(NA/n0); #acceptance angle(radian)\n",
- "i=i*180/math.pi; #angle(degrees)\n",
- "\n",
- "#Result\n",
- "print \"The acceptance angle is\",i,\"degrees\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The acceptance angle is 30.0 degrees\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 13.3, Page number 250"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "NA=0.25; #numerical apperture\n",
- "lamda=0.75; #wavelength(micro m)\n",
- "a=25; #core radius(micro m)\n",
- "\n",
- "#Calculation \n",
- "f=(2*math.pi*a*NA)/lamda; #normalised frequency\n",
- "Ng=(f**2)/2; #number of guided modes\n",
- "\n",
- "#Result\n",
- "print \"The number of guided modes is\",int(Ng)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The number of guided modes is 1370\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 13.4, Page number 250"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "pi=100; #mean optical power launched(micro m)\n",
- "po=5; #mean optical power at fibre output(micro W)\n",
- "l=6; #length(km)\n",
- "\n",
- "#Calculation \n",
- "S=10*math.log10(pi/po); #signal attenuation(dB)\n",
- "Sk=S/l; #signal attenuation(dB/km)\n",
- "\n",
- "#Result\n",
- "print \"The signal attenuation is\",round(Sk,3),\"dB/km\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The signal attenuation is 2.168 dB/km\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 13.5, Page number 250"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "ns=2.89; #sum of refractive indices of core & cladding\n",
- "nd=0.03; #difference of refractive indices of core & cladding\n",
- "\n",
- "#Calculation \n",
- "NA=math.sqrt(ns*nd); #numerical apperture\n",
- "\n",
- "#Result\n",
- "print \"The numerical apperture for the optical fibre is\",round(NA,2)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The numerical apperture for the optical fibre is 0.29\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 13.6, Page number 250"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "NA=0.28; #numerical aperture\n",
- "a=30; #core radius(micro m)\n",
- "lamda=0.8; #wavelength(micro m)\n",
- "\n",
- "#Calculation \n",
- "f=(2*math.pi*a*NA)/lamda; #normalised frequency\n",
- "Ng=f**2/2; #number of guided modes\n",
- "\n",
- "#Result\n",
- "print \"The number of guided modes is\",int(Ng)\n",
- "print \"answer in the book varies due to rounding off errors\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The number of guided modes is 2176\n",
- "answer in the book varies due to rounding off errors\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 13.7, Page number 250"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "S=2; #signal attenuation(dB/km)\n",
- "l=1; #length(km)\n",
- "p0=20; #mean optical power at fibre output(micro W)\n",
- "\n",
- "#Calculation \n",
- "pi=p0*10**(S/10); #mean optical power launched into fibre(micro W)\n",
- "\n",
- "#Result\n",
- "print \"The mean optical power launched into a fibre is\",round(pi,1),\"micro W\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The mean optical power launched into a fibre is 31.7 micro W\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 13.8, Page number 251"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "S=2.3; #Signal attenuation(dB/km)\n",
- "l=4; #length(km)\n",
- "\n",
- "#Calculation \n",
- "S=S*l; #signal attenuation for 4km in dB\n",
- "P=10**(S/10); #ratio of mean optical power\n",
- "\n",
- "#Result\n",
- "print \"ratio of mean optical power is\",round(P,1)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "ratio of mean optical power is 8.3\n"
- ]
- }
- ],
- "prompt_number": 18
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 13.9, Page number 251"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "op=1/4; #ratio\n",
- "\n",
- "#Calculation \n",
- "#S=10*log(pi/po)\n",
- "S=10*math.log10(1/op); #signal attenuation(dB)\n",
- "\n",
- "#Result\n",
- "print \"Signal attenuation is\",int(S),\"dB\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Signal attenuation is 6 dB\n"
- ]
- }
- ],
- "prompt_number": 20
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/Chapter1_1.ipynb b/Engineering_Physics/Chapter1_1.ipynb
deleted file mode 100755
index e69de29b..00000000
--- a/Engineering_Physics/Chapter1_1.ipynb
+++ /dev/null
diff --git a/Engineering_Physics/Chapter2_1.ipynb b/Engineering_Physics/Chapter2_1.ipynb
deleted file mode 100755
index b527497e..00000000
--- a/Engineering_Physics/Chapter2_1.ipynb
+++ /dev/null
@@ -1,431 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:ad2a8335720a8ceacd5db30334fb790c6a4c8fa5b69e23fcad6e232d80ed69c2"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "2: Crystal Structure"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 2.1, Page number 29"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "d=6.5*10**3; #density of silver bromide(Kg/m**3)\n",
- "m=187.8; #molecular weight of silver bromide\n",
- "\n",
- "#Calculation\n",
- "M=(4*m)/(6.022*10**26); #mass of ion in unit cell(kg)\n",
- "#d=mass of ions in unit cell/volume of unit cell\n",
- "a=((M/d)**(1/3))*10**10; #lattice parameter(Angstrom)\n",
- "\n",
- "#Result\n",
- "print \"The lattice parameter is\",round(a,2),\"Angstrom\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The lattice parameter is 5.77 Angstrom\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 2.2, Page number 29"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "r=2.3; #atomic radius(Angstrom)\n",
- "\n",
- "#Calculation\n",
- "a=(4*r)/math.sqrt(3); \n",
- "fv=((a)**3-(2*(4/3)*math.pi*r**3))*10**-30; #free volume(m**3)\n",
- "\n",
- "#Result\n",
- "print \"The free volume per unit cell is\",round(fv*10**30,1),\"*10**-30 m**3\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The free volume per unit cell is 47.9 *10**-30 m**3\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 2.3, Page number 29"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "k=8.625*10**-5; #Boltzmann constant(eV/K)\n",
- "#n1000/n500=ln[n1000/n500]=Ev/1000k\n",
- "Ev=1.08; #average energy required to create a vacancy(eV)\n",
- "\n",
- "#Calculation\n",
- "N=math.exp(Ev/(1000*k)); #ratio of vacancies\n",
- "\n",
- "#Result\n",
- "print \"The ratio of vacancies is\",round(N/10**5,1),\"*10**5\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The ratio of vacancies is 2.7 *10**5\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 2.4, Page number 29"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#n500=N*exp(-Ev/500k)\n",
- "k=8.625*10**-5; #Boltzmann constant(eV/K)\n",
- "Ev=0.95; #average energy required to create a vacancy\n",
- "\n",
- "#Calculation\n",
- "n=math.exp(-Ev/(500*k)); #n500/N\n",
- "\n",
- "#Result\n",
- "print \"The ratio of number of vacancies to the number of atoms is\",round(n*10**10,1),\"*10**-10\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The ratio of number of vacancies to the number of atoms is 2.7 *10**-10\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 2.5, Page number 30"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "h=1;\n",
- "k=1;\n",
- "l=1;\n",
- "#d(hkl)=a/sqrt(h^2+k^2+l^2) where \"a\" is the lattice parameter\n",
- "r=0.18; #atomic radius(nm)\n",
- "\n",
- "#Calculation\n",
- "d111=(2*math.sqrt(2)*r)/math.sqrt((h**2)+(k**2)+(l**2)); #spacing(nm)\n",
- "\n",
- "#Result\n",
- "print \"The spacing of (111) planes in a monoatomic structure is\",round(d111,2),\"nm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The spacing of (111) planes in a monoatomic structure is 0.29 nm\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 2.6, Page number 30"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "M=200; #atomic weight \n",
- "a=5; #lattice parameter(angstrom)\n",
- "Na=6.022*(10**26);\n",
- "\n",
- "#Calculation\n",
- "rho=(2*M)/(Na*(a*10**-10)**3); #density of the structure(kg/m**3)\n",
- "\n",
- "#Result\n",
- "print \"The density of the bcc structure is\",round(rho/10**3,2),\"*10**3 kg/m**3\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The density of the bcc structure is 5.31 *10**3 kg/m**3\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 2.7, Page number 30"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#Free volume=a^3-[(4/3)*pi*r^3];for sc,a=2r\n",
- "#Therefore free volume =(2r)^3-[(4/3)*pi*r^3]\n",
- "fv=30.48*10**-30; #free volume per unit cell(m**3)\n",
- "\n",
- "#Calculation\n",
- "r=(fv/(8-(4/3)*math.pi))**(1/3)*(10**10); #atomic radius(angstrom) \n",
- "\n",
- "#Result\n",
- "print \"The atomic radius is\",round(r),\"Angstrom\" "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The atomic radius is 2.0 Angstrom\n"
- ]
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 2.8, Page number 30"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#free volume=a^3-[2*(4/3)*pi*r^3]\n",
- "#for bcc a=4r/3^(1/3)\n",
- "fv=61.72*(10**-30); #free volume(m**3)\n",
- "\n",
- "#Calculation\n",
- "a=-(fv/(1-math.pi*math.sqrt(3))/8)**1/3*10**31; #lattice parameter(angstrom)\n",
- "\n",
- "#Result\n",
- "print \"The lattice parameter is\",round(a,2),\"Angstrom\"\n",
- "print \"answer in the book varies due to rounding off errors\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The lattice parameter is 5.79 Angstrom\n",
- "answer in the book varies due to rounding off errors\n"
- ]
- }
- ],
- "prompt_number": 24
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 2.9, Page number 30"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "rho=9000; #density(kg/m**3)\n",
- "w=65; #atomic weight\n",
- "v=1; #volume(m**3)\n",
- "a=1.4; #average number of free electrons per atom\n",
- "\n",
- "#Calculation\n",
- "n=(rho*v)/(w/(6.022*10**26)); #number of atoms\n",
- "rhoe=n*a; #density of free electrons per atom(electrons/m**3)\n",
- "\n",
- "#Result\n",
- "print \"The density of free electrons is\",round(rhoe/10**29,3),\"*10**29 electrons/m**3\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The density of free electrons is 1.167 *10**29 electrons/m**3\n"
- ]
- }
- ],
- "prompt_number": 26
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 2.10, Page number 31"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "h=1;\n",
- "k=0;\n",
- "l=1;\n",
- "d101=0.5; #spacing of (101) plane\n",
- "\n",
- "#Calculation\n",
- "#d101=a/sqrt((h^2)+(k^2)+(l^2))\n",
- "a=d101*math.sqrt(2) #lattice parameter(Angstrom)\n",
- "\n",
- "#Result\n",
- "print \"The lattice parameter is\",round(a,1),\"Angstrom\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The lattice parameter is 0.7 Angstrom\n"
- ]
- }
- ],
- "prompt_number": 28
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/Chapter4_1.ipynb b/Engineering_Physics/Chapter4_1.ipynb
deleted file mode 100755
index f4145c55..00000000
--- a/Engineering_Physics/Chapter4_1.ipynb
+++ /dev/null
@@ -1,553 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:e9b50f0b4ca0520935774156fedb1fdaaf2b2fd5241b8184a650d42b25d657cd"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "4: Interference"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.1, Page number 69"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "i=40; #angle of incidence(degrees)\n",
- "mew=1.2; #refractive index\n",
- "t=0.23; #thickness of the film(micro m)\n",
- "\n",
- "#Calculation\n",
- "i=i*math.pi/180; #angle of incidence(radian)\n",
- "r=math.asin(math.sin(i)/mew); #angle of refraction(radian)\n",
- "lambda1=(2*mew*t*math.cos(r))*10**3; #wavelength absent(nm) \n",
- "lambda2=lambda1/2;\n",
- "\n",
- "#Result\n",
- "print \"The wavelength absent is\",round(lambda1,1),\"nm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The wavelength absent is 466.1 nm\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.2, Page number 69"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "lambda1=400*10**-9; #wavelength 1(m)\n",
- "lambda2=600*10**-9; #wavelength 2(m)\n",
- "#2*t=n*lambda\n",
- "n=150; \n",
- "\n",
- "#Calculation \n",
- "t=((n*lambda2)/2)*10**6; #thickness of the air film(micro meter)\n",
- "\n",
- "#Result\n",
- "print \"The thickness of the air film is\",t,\"micro m\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The thickness of the air film is 45.0 micro m\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.3, Page number 70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "lamda=600*10**-9; #wavelength(m)\n",
- "mew=2;\n",
- "theta=0.025; #wedge-angle(degrees)\n",
- "\n",
- "#Calculation \n",
- "theta=theta*math.pi/180; #wedge-angle(radian)\n",
- "x=(lamda/(2*mew*math.sin(theta)))*10**2; #bandwidth(cm)\n",
- "\n",
- "#Result\n",
- "print \"The bandwidth is\",round(x,3),\"cm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The bandwidth is 0.034 cm\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.4, Page number 70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "xair=0.15; #bandwidth of air(cm)\n",
- "xliq=0.115; #bandwidth of liquid(cm)\n",
- "mewair=1; #refractive index of air\n",
- "\n",
- "#Calculation \n",
- "mewliq=(xair*mewair)/xliq; #refractive index of liquid\n",
- "\n",
- "#Result\n",
- "print \"The refractive index of liquid is\",round(mewliq,1)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The refractive index of liquid is 1.3\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.5, Page number 70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "n=9;\n",
- "lamda=589*10**-9; #wavelength of light used(m)\n",
- "R=0.95; #radius of curvature of lens(m)\n",
- "mew=1;\n",
- "\n",
- "#Calculation \n",
- "D=(math.sqrt((4*n*lamda*R)/mew))*10**2; #diameter of the ninth dark ring(m)\n",
- "\n",
- "#Result\n",
- "print \"The diameter of the ninth dark ring is\",round(D,2),\"cm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The diameter of the ninth dark ring is 0.45 cm\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.6, Page number 70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "x=0.055; #distance in fringe shift(mm)\n",
- "n=200; #number of fringes\n",
- "\n",
- "#Calculation \n",
- "lamda=((2*x)/n)*10**6; #wavelength(nm)\n",
- "\n",
- "#Result\n",
- "print \"The wavelength of light used is\",lamda,\"nm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The wavelength of light used is 550.0 nm\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.7, Page number 70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "n=50; #number of fringes\n",
- "lamda=500*10**-9; #wavelength of light used(m)\n",
- "mew=1.5; #refractive index of the plate\n",
- "\n",
- "#Calculation \n",
- "t=((n*lamda)/(2*(mew-1)))*10**6; #thickness of the plate(micro meter)\n",
- "\n",
- "#Result\n",
- "print \"The thickness of the plate is\",t,\"micro m\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The thickness of the plate is 25.0 micro m\n"
- ]
- }
- ],
- "prompt_number": 20
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.8, Page number 70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "lamda=550*10**-9; #wavelength(m)\n",
- "mew=1.38; #refractive index\n",
- "\n",
- "#Calculation \n",
- "t=(lamda/(4*mew))*10**9; #thickness(nm)\n",
- "\n",
- "#Result\n",
- "print \"The minimum thickness of the plate for normal incidence of light is\",round(t,3),\"nm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The minimum thickness of the plate for normal incidence of light is 99.638 nm\n"
- ]
- }
- ],
- "prompt_number": 23
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.9, Page number 70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "i=35; #angle of incidence(degrees)\n",
- "mew=1.4; #refractive index\n",
- "n=50; \n",
- "lamda=459*10**-9; #wavelength(m)\n",
- "\n",
- "#Calculation \n",
- "i=i*math.pi/180; #angle of incidence(radian)\n",
- "r=math.asin(math.sin(i)/mew); #angle of refraction(radian)\n",
- "#2*mew*cos(r)=n*lambda\n",
- "#n(459)=(n+1)450\n",
- "t=(n*lamda/(2*mew*math.cos(r)))*10**6; #thickness of the film(micro meter)\n",
- "\n",
- "#Result\n",
- "print \"The thickness of the film is\",round(t,3),\"micro m\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The thickness of the film is 8.985 micro m\n"
- ]
- }
- ],
- "prompt_number": 26
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.10, Page number 71"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "lamda=500*10**-9; #wavelength(m)\n",
- "x=0.07; #observed band width(cm)\n",
- "mew=1; #refractive index\n",
- "\n",
- "#Calculation \n",
- "theta=(math.asin(lamda/(2*mew*x)))*10**2; #wedge angle(radian)\n",
- "theta=theta*180/math.pi; #wedge angle(degrees)\n",
- "\n",
- "#Result\n",
- "print \"The wedge angle is\",round(theta,2),\"degrees\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The wedge angle is 0.02 degrees\n"
- ]
- }
- ],
- "prompt_number": 31
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.11, Page number 71"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "dair=0.42; #diameter of certain rings(cm)\n",
- "dliq=0.38; #diameter of rings when liquid is introduced(cm)\n",
- "\n",
- "#Calculation \n",
- "mew=dair**2/dliq**2; #refractive index of liquid\n",
- "\n",
- "#Result\n",
- "print \"The refravtive index of liquid is\",round(mew,2)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The refravtive index of liquid is 1.22\n"
- ]
- }
- ],
- "prompt_number": 33
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.12, Page number 71"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "m=8; #eigth ring\n",
- "n=3; #third ring\n",
- "dm=0.4; #diameter of the eigth ring(cm)\n",
- "dn=0.2; #diameter of the third ring(cm)\n",
- "R=101; #Radius of curvature(cm)\n",
- "\n",
- "#Calculation \n",
- "lamda=(((dm**2)-(dn**2))/(4*R*(m-n))); #wavelength of light(cm) \n",
- "\n",
- "#Result\n",
- "print \"The wavelength of light used is\",round(lamda*10**5,4),\"*10**-5 cm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The wavelength of light used is 5.9406 *10**-5 cm\n"
- ]
- }
- ],
- "prompt_number": 39
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 4.13, Page number 71"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "mew=1.38; #refractive index of magnesium floride\n",
- "t=175; #thickness of coating of magnesium fluoride(nm)\n",
- "\n",
- "#Calculation \n",
- "lamda=4*t*mew; #wavelength(nm)\n",
- "\n",
- "#Result\n",
- "print \"The wavelength which has high transmission is\",lamda,\"nm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The wavelength which has high transmission is 966.0 nm\n"
- ]
- }
- ],
- "prompt_number": 41
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/Chapter5_1.ipynb b/Engineering_Physics/Chapter5_1.ipynb
deleted file mode 100755
index d125b365..00000000
--- a/Engineering_Physics/Chapter5_1.ipynb
+++ /dev/null
@@ -1,469 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:f4c05fd79d4d56cbd4b08f847aeb0bba767b388c9bbe1bea8066d97e3ac78212"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "5: Diffraction"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 5.1, Page number 86"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "n=1;\n",
- "lamda=600*10**-9; #wavelength(m)\n",
- "theta=35; #angle at which first minimum falls(degrees)\n",
- "\n",
- "#Calculation \n",
- "theta=theta*math.pi/180; #angle at which first minimum falls(radian)\n",
- "d=((n*lamda)/math.sin(theta))*10**6; #width of the slit(micro m)\n",
- "\n",
- "#Result\n",
- "print \"The width of the slit is\",round(d,2),\"micro m\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The width of the slit is 1.05 micro m\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 5.2, Page number 86"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "D=0.95; #distance of the screen from the slit(m)\n",
- "lamda=589*10**-9; #wavelength(m)\n",
- "d=0.5*10**-3; #width of the slit(m)\n",
- "\n",
- "#Calculation \n",
- "y=((2*D*lamda)/d)*10**3; #width of a central band(mm)\n",
- "\n",
- "#Result\n",
- "print \"The width of the central band is\",round(y,2),\"mm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The width of the central band is 2.24 mm\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 5.3, Page number 86"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "D=1.1; #distance of the screen from the slit(m)\n",
- "lamda=589*10**-9; #wavelength(m)\n",
- "y=4.5*10**-3; #distance of first minimum on either side of central maximum(m)\n",
- "\n",
- "#Calculation \n",
- "d=((D*lamda)/y)*10**3 #slit width(mm)\n",
- "\n",
- "#Result\n",
- "print \"The slit width is\",round(d,3),\"mm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The slit width is 0.144 mm\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 5.4, Page number 86"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "n=4;\n",
- "lamda=589.6*10**-9; #wavelength(m)\n",
- "D=0.95; #distance of the screen from the slit(m)\n",
- "w=0.28*10**-3; #width of the slit(m)\n",
- "\n",
- "#Calculation \n",
- "d=((n*lamda*D)/w)*10**3; #distance between centres(mm)\n",
- "\n",
- "#Result\n",
- "print \"The distance between centres of central maximum and the fourth dark fringe is\",int(d),\"mm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The distance between centres of central maximum and the fourth dark fringe is 8 mm\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 5.5, Page number 86"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "s=5*math.pi/2; #secondary maximum\n",
- "\n",
- "#Calculation \n",
- "I=(math.sin(s)/s)**2; #I2/I0\n",
- "\n",
- "#Result\n",
- "print \"Ratio of intensities of central & second secondary maximum is\",round(I,3)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Ratio of intensities of central & second secondary maximum is 0.016\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 5.6, Page number 86"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "lamda=450*10**-9; #wavelength(m)\n",
- "n=2;\n",
- "dlambda=1*10**-9; #difference in wavelength(m)\n",
- "\n",
- "#Calculation \n",
- "N=lamda/(n*dlambda); #minimum number of lines per cm \n",
- "\n",
- "#Result\n",
- "print \"The minimum number of lines per cm is\",N/2"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The minimum number of lines per cm is 112.5\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 5.7, Page number 86"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "n=1;\n",
- "lamda=650*10**-9; #wavelength(m)\n",
- "d=2*10**-6; #width of the slit(m)\n",
- "\n",
- "#Calculation \n",
- "theta=math.asin((n*lamda)/d); #angle at which first minimum will be observed(radian)\n",
- "theta=theta*180/math.pi; #angle at which first minimum will be observed(degrees)\n",
- "\n",
- "#Result\n",
- "print \"The angle at which first minimum will be observed is\",round(theta,3),\"degrees\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The angle at which first minimum will be observed is 18.966 degrees\n"
- ]
- }
- ],
- "prompt_number": 22
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 5.8, Page number 87"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "lamda=600*10**-9; #wavelength(m)\n",
- "y=2*10**-3; #width of the central band(m)\n",
- "D=1; #distance of the screen from the slit(m)\n",
- "\n",
- "#Calculation \n",
- "d=((2*D*lamda)/y)*10**3; #slit width(mm)\n",
- "\n",
- "#Result\n",
- "print \"The slit width is\",d,\"mm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The slit width is 0.6 mm\n"
- ]
- }
- ],
- "prompt_number": 24
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 5.9, Page number 87"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "y=6*10**-3; #first minimum is observed(m)\n",
- "d=90*10**-6; #slit width(m)\n",
- "D=0.98; #distance of the screen from the slit(m)\n",
- "\n",
- "#Calculation \n",
- "lamda=((y*d)/D)*10**9; #wavelength(nm)\n",
- "\n",
- "#Result\n",
- "print \"The wavelength of light used is\",int(lamda),\"nm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The wavelength of light used is 551 nm\n"
- ]
- }
- ],
- "prompt_number": 27
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 5.10, Page number 87"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "n=1;\n",
- "lambda1=450*10**-9; #wavelength of first spectral line(m)\n",
- "d=1/5000; #number of lines\n",
- "\n",
- "#Calculation \n",
- "theta1=math.asin((n*lambda1)/d); \n",
- "theta1=round(theta1*10**2*180/math.pi);\n",
- "theta2=theta1+2.97;\n",
- "theta2=theta2*math.pi/180;\n",
- "lambda2=d*math.sin(theta2)/n; #wavelength of second spectral line(nm)\n",
- "\n",
- "#Result\n",
- "print \"The wavelength of second spectral line is\",int(lambda2*10**7),\"nm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The wavelength of second spectral line is 550 nm\n"
- ]
- }
- ],
- "prompt_number": 41
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 5.11, Page number 87"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "n=3;\n",
- "lamda=700*10**-9; #wavelength(m)\n",
- "theta=90; #angle(degrees)\n",
- "\n",
- "#Calculation \n",
- "theta=theta*math.pi/180; #angle(radian)\n",
- "d=n*lamda/math.sin(theta); #grating element(m)\n",
- "\n",
- "#Result\n",
- "print \"The minimum grating element required to observe the entire third order spectrum is\",d*10**6,\"*10**-6 m\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The minimum grating element required to observe the entire third order spectrum is 2.1 *10**-6 m\n"
- ]
- }
- ],
- "prompt_number": 45
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/Chapter6_1.ipynb b/Engineering_Physics/Chapter6_1.ipynb
deleted file mode 100755
index 271f7718..00000000
--- a/Engineering_Physics/Chapter6_1.ipynb
+++ /dev/null
@@ -1,437 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:015049a6d28a54143e382d872ce51260f52be159a8159c04fe93d876c0cea685"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "6: Polarisation"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 6.1, Page number 108"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "mew=1.63; #refractive index of the glass plate\n",
- "\n",
- "#Calculation \n",
- "#tan ip=mew\n",
- "ip=math.atan(mew); #ip=polarising angle(radian)\n",
- "ip=ip*180/math.pi; #ip=polarising angle(degrees)\n",
- "#ip+r=90\n",
- "r=90-ip; #angle of refraction(degrees)\n",
- "rd=int(r); #angle(degrees)\n",
- "rm=round(60*(r-rd)); #angle(minutes)\n",
- "\n",
- "#Result\n",
- "print \"The angle of refraction is\",rd,\"degrees\",rm,\"minutes\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The angle of refraction is 31 degrees 32.0 minutes\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 6.2, Page number 108"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#I=I0(cos^2(teta))\n",
- "theta=50; #angle made between two principle planes(degrees)\n",
- "\n",
- "#Calculation \n",
- "theta=theta*math.pi/180; #angle(radian)\n",
- "I=(math.cos(theta))**2; #incident unpolarized light\n",
- "#percentage of incident unpolarised light is (I/I0)*100 where I0 is incident polarised light\n",
- "p=I*100; #percentage of incident unpolarized light(%)\n",
- "\n",
- "#Result\n",
- "print \"The percentage of incident unpolarized light is\",int(p),\"%\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The percentage of incident unpolarized light is 41 %\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 6.3, Page number 108"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#I=I0*cos^2(teta)\n",
- "#cos^2(teta)=I/I0\n",
- "a=0.08; #a=I/I0;where I=incident unpolarized light & I0=incident polarized light\n",
- "\n",
- "#Calculation \n",
- "theta=math.acos(math.sqrt(a)); #angle between planes of transmission of analyser and polariser(radian)\n",
- "theta=theta*180/math.pi; #angle(degrees)\n",
- "thetad=int(theta); #angle(degrees)\n",
- "thetam=round(60*(theta-thetad)); #angle(minutes)\n",
- "\n",
- "#Result\n",
- "print \"The angle between the planes of transmission of analyser & polariser is +(or)- \",thetad,\"degrees\",thetam,\"minutes\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The angle between the planes of transmission of analyser & polariser is +(or)- 73 degrees 34.0 minutes\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 6.4, Page number 108"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#IE=A^2(cos^2(teta));IO=A^2(sin^2(teta))\n",
- "#I0/IE=tan^2(teta)\n",
- "theta=40; #angle made between incident beam & optic axis(degrees)\n",
- "\n",
- "#Calculation \n",
- "theta=theta*math.pi/180; #angle(radian)\n",
- "a=math.tan(theta)**2; #I0/IE\n",
- "\n",
- "#Result\n",
- "print \"I0/IE=\",round(a,1)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "I0/IE= 0.7\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 6.5, Page number 108"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "lamda=589; #wavelength of light(nm)\n",
- "mew0=1.54; #refractive index for ordinary wave\n",
- "mewE=1.55; #refractive index for extraordinary wave\n",
- "\n",
- "#Calculation \n",
- "t=lamda/(4*(mewE-mew0))*10**-3; #thickness(micro m)\n",
- "\n",
- "#Result\n",
- "print \"The thickness of a quarter-wave plate is\",t,\"micro m\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The thickness of a quarter-wave plate is 14.725 micro m\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 6.6, Page number 109"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "ip=52; #angle of polarization(degrees)\n",
- "\n",
- "#Calculation \n",
- "ip=ip*math.pi/180; #angle(radian)\n",
- "mew=math.tan(ip); #refractive index of the material surface\n",
- "\n",
- "#Result\n",
- "print \"The refractive index of the material surface is\",round(mew,2)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The refractive index of the material surface is 1.28\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 6.7, Page number 109"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "r=33; #angle of refraction(degrees)\n",
- "\n",
- "#Calculation \n",
- "ip=90-r; #polarising angle(degrees)\n",
- "ip=ip*math.pi/180; #angle(radian)\n",
- "mew=math.tan(ip); #refractive index of quartz\n",
- "\n",
- "#Result\n",
- "print \"The refractive index of quartz is\",round(mew,2)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The refractive index of quartz is 1.54\n"
- ]
- }
- ],
- "prompt_number": 18
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 6.8, Page number 109"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#IE=A^2*cos^2(teta);IO=A^2*sin^2(teta)\n",
- "#I0/IE=tan^2(teta)=0.65\n",
- "a=0.65; #ratio of intensities of ordinary & extraordinary light\n",
- "\n",
- "#Calculation \n",
- "theta=math.atan(math.sqrt(a)); #angle made by plane of vibration of the incident light with optic axis(radian)\n",
- "theta=theta*180/math.pi; #angle(degrees)\n",
- "thetad=int(theta); #angle(degrees)\n",
- "thetam=int(60*(theta-thetad));\n",
- "\n",
- "#Result\n",
- "print \"The angle made by the plane of vibration of incident light with the optic axis is\",thetad,\"degrees\",thetam,\"minutes\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The angle made by the plane of vibration of incident light with the optic axis is 38 degrees 52 minutes\n"
- ]
- }
- ],
- "prompt_number": 20
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 6.9, Page number 109"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "mew0=1.544; #refractive index of ordinary waves\n",
- "mewE=1.553; #refractive index of extraordinary waves\n",
- "lamda=550; #wavelength(nm) \n",
- "t=9;\n",
- "\n",
- "#Calculation \n",
- "delta=((2*180)/(lamda*(10**-9)))*(mewE-mew0)*t*(10**-6); #phase difference(degrees)\n",
- "\n",
- "#Result\n",
- "print \"The phase difference between O and E rays is\",int(delta),\"degrees\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The phase difference between O and E rays is 53 degrees\n"
- ]
- }
- ],
- "prompt_number": 23
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 6.10, Page number 109"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "delta=50; #phase difference(degrees)\n",
- "mewE=1.544; #refractive index of extraordinary waves\n",
- "mew0=1.553; #refractive index of ordinary waves\n",
- "t=8; #thickness(nm)\n",
- "\n",
- "#Calculation \n",
- "lamda=((2*180)/delta)*(mew0-mewE)*t*10**-6*10**9; #wavelength of light incident(nm)\n",
- "\n",
- "#Result\n",
- "print \"The wavelength of light incident is\",lamda,\"nm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The wavelength of light incident is 518.4 nm\n"
- ]
- }
- ],
- "prompt_number": 25
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/Chapter7_1.ipynb b/Engineering_Physics/Chapter7_1.ipynb
deleted file mode 100755
index 36caeba7..00000000
--- a/Engineering_Physics/Chapter7_1.ipynb
+++ /dev/null
@@ -1,582 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:604dfd31225e3c2fe12afc104ed18461bd1bcabd558389f5cc69df386ba9091d"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "7: Motion of a charged particle"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.1, Page number 132"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "e=1.6*10**-19; #charge of the electron(c)\n",
- "V=18; #potential difference(kV)\n",
- "m=9.1*10**-31; #mass of the electron(kg)\n",
- "\n",
- "#Calculation \n",
- "K=e*V*10**3; #Kinetic energy(J)\n",
- "v=math.sqrt((2*e*V*10**3)/m); #speed of electron(m/s)\n",
- "\n",
- "#Result\n",
- "print \"The kinetic energy of electron is\",K*10**16,\"*10**-16 J\"\n",
- "print \"Speed of the electron is\",round(v/10**7,3),\"*10**7 m/s\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The kinetic energy of electron is 28.8 *10**-16 J\n",
- "Speed of the electron is 7.956 *10**7 m/s\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.2, Page number 133"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "m=9.1*10**-31; #mass of electron(kg)\n",
- "vx=4*10**6; #velocity along x-axis(m/s)\n",
- "E=1500; #electric field strength(N/C)\n",
- "l=0.07; #length in y-axis(m)\n",
- "q=1.6*10**-19; #charge of electron(c)\n",
- "\n",
- "#Calculation \n",
- "y=(-q*E*(l**2))/(2*m*(vx**2))*10**2; #vertical displacement of electron(cm)\n",
- "\n",
- "#Result\n",
- "print \"The vertical displacement of electron when it leaves the electric field is\",round(y,3),\"cm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The vertical displacement of electron when it leaves the electric field is -4.038 cm\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.3, Page number 133"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "u=5*10**5; #velocity(m/s)\n",
- "m=1.67*10**-27; #mass of proton(kg)\n",
- "q=1.6*10**-19;\n",
- "E=500; #electric field(N/C)\n",
- "theta=42; #angle(degrees)\n",
- "\n",
- "#Calculation \n",
- "theta=theta*math.pi/180; #angle(radian)\n",
- "t=((u*m*math.sin(theta))/(q*E))*10**6; #time required for the proton(micro s)\n",
- "\n",
- "#Result\n",
- "print \"The time required for the proton is\",round(t,2),\"micro s\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The time required for the proton is 6.98 micro s\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.4, Page number 133"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "m=1.67*10**-27; #mass of proton(kg)\n",
- "q=1.6*10**-19;\n",
- "B=0.36; #magnetic field(T)\n",
- "R=0.2; #radius(m)\n",
- "\n",
- "#Calculation \n",
- "v=(q*B*R)/m; #orbital speed of proton(m/s)\n",
- "\n",
- "#Result\n",
- "print \"The orbital speed of proton is\",round(v/10**6,1),\"*10**6 m/s\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The orbital speed of proton is 6.9 *10**6 m/s\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.5, Page number 133"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "v=2*10**6; #speed(m/s)\n",
- "theta=30; #angle at which proton enters at the origin of coordinate system(degrees)\n",
- "B=0.3; #magnetic field(T)\n",
- "m=1.67*10**-27; #mass of proton(kg)\n",
- "q=1.6*10**-19;\n",
- "\n",
- "#Calculation \n",
- "theta=theta*math.pi/180; #angle(radian)\n",
- "vp=v*math.sin(theta); #v(perpendicular component)\n",
- "vpa=v*math.cos(theta); #v(parallel component)\n",
- "p=(vpa*2*math.pi*m)/(q*B); #pitch of the helix described by the proton\n",
- "R=((m*vp)/(q*B))*10**2; #radius of the trajectory\n",
- "\n",
- "#Result\n",
- "print \"the pitch of the helix is\",round(p,2),\"m\"\n",
- "print \"the radius of trajectory is\",round(R,2),\"cm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the pitch of the helix is 0.38 m\n",
- "the radius of trajectory is 3.48 cm\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.6, Page number 133"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "V=25; #deflecting voltage(V)\n",
- "l=0.03; #length of deflecting planes(m)\n",
- "d=0.75; #distance between 2 deflecting plates(cm)\n",
- "Va=800; #final anode voltage(V)\n",
- "D=0.2; #distance between the screen and the plates(m)\n",
- "e=1.6*10**-19;\n",
- "m=9.1*10**-31; #mass of electron(kg)\n",
- "\n",
- "#Calculation \n",
- "y=(((V*l)/(2*d*Va))*(D+(l/2)))*10**4; #displacement produced(cm)\n",
- "a=((V*l)/(2*d*Va))*10**2;\n",
- "alpha=math.atan(a); #angle made by the beam with the axis(radian)\n",
- "alpha1=alpha*180/math.pi; #angle(degrees)\n",
- "v=((math.sqrt((2*e*Va)/m))/math.cos(alpha)); #velocity of electron(v)\n",
- "\n",
- "#Result\n",
- "print \"the displacement produced is\",round(y,2),\"cm\"\n",
- "print \"the angle made by the beam with the axis is\",round(alpha1,2),\"degrees\"\n",
- "print \"velocity of electrons is\",round(v/10**7,2),\"*10**7 m/s\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the displacement produced is 1.34 cm\n",
- "the angle made by the beam with the axis is 3.58 degrees\n",
- "velocity of electrons is 1.68 *10**7 m/s\n"
- ]
- }
- ],
- "prompt_number": 18
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.7, Page number 134"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "e=1.6*10**-19;\n",
- "B=5*10**-5; #magnetic field(Wb/m**2)\n",
- "l=0.04; #length of magnetic field along the axis(m)\n",
- "m=9.1*10**-31; #mass of electron(kg)\n",
- "D=0.25; #distance of the screen from the field(m)\n",
- "Va=600; #final anode voltage(V)\n",
- "\n",
- "#Calculation \n",
- "y=(((e*B*l)/m)*math.sqrt(m/(2*e*Va))*(D+(l/2)))*10**2; #displacement of the electron(cm)\n",
- "\n",
- "#Result\n",
- "print \"the displacement of the electron beam spot on the screen is\",round(y,2),\"cm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the displacement of the electron beam spot on the screen is 0.65 cm\n"
- ]
- }
- ],
- "prompt_number": 20
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.8, Page number 134"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "E=2.5*10**4; #electric field(V/m)\n",
- "B=0.18; #magnetic field(T)\n",
- "B1=0.22; #magnetic field in the main chamber(T)\n",
- "m2=13; #mass number of carbon(kg)\n",
- "m1=12; #mass number of carbon(kg)\n",
- "e=1.6*10**-9;\n",
- "q=1.67*10**-27;\n",
- "\n",
- "#Calculation \n",
- "v=E/B; #velocity of particles(m/s)\n",
- "s=((2*v*(m2-m1)*q)/(e*B1))*10**12; #seperation on photographic plate(cm)\n",
- "\n",
- "#Result\n",
- "print \"the seperation on photographic plate is\",round(s,3),\"cm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the seperation on photographic plate is 1.318 cm\n"
- ]
- }
- ],
- "prompt_number": 22
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.9, Page number 134"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "v=5.6*10**6; #speed of the electron(m/s)\n",
- "m=9.1*10**-31; #mass of electron(kg)\n",
- "e=1.6*10**-19;\n",
- "s=0.03; #distance travelled(m)\n",
- "\n",
- "#Calculation \n",
- "E=(m*(v)**2)/(2*e*s); #intensity of electric field(N/C)\n",
- "\n",
- "#Result\n",
- "print \"The intensity of electric field is\",round(E),\"N/C\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The intensity of electric field is 2973.0 N/C\n"
- ]
- }
- ],
- "prompt_number": 24
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.10, Page number 134"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "v=5*10**7;\n",
- "B=0.4; #magnetic field(T)\n",
- "r=0.711*10**-3; #radius of the circle(m)\n",
- "\n",
- "#Calculation \n",
- "Q=v/(B*r); #charge to mass ratio(C/kg)\n",
- "\n",
- "#Result\n",
- "print \"The charge to mass ratio is\",round(Q/10**10,2),\"*10**10 C/kg\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The charge to mass ratio is 17.58 *10**10 C/kg\n"
- ]
- }
- ],
- "prompt_number": 27
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.11, Page number 135"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "m=9.1*10**-31; #mass of electron(kg)\n",
- "v=3*10**7; #speed of electron(m/s)\n",
- "R=0.05; #radius of the circle(m)\n",
- "q=1.6*10**-31;\n",
- "\n",
- "#Calculation \n",
- "B=((m*v)/(q*R))*10**-9; #magnetic field(mT)\n",
- "\n",
- "#Result\n",
- "print \"The magnetic field to bend a beam is\",round(B,1),\"mT\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The magnetic field to bend a beam is 3.4 mT\n"
- ]
- }
- ],
- "prompt_number": 29
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.12, Page number 135"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "m=9.1*10**-31; #mass of electron(kg)\n",
- "q=1.6*10**-19;\n",
- "t=8*10**-9; #time(ns)\n",
- "\n",
- "#Calculation \n",
- "B=(2*math.pi*m*500)/(q*t); #magnetic field(T)\n",
- "\n",
- "#Result\n",
- "print \"The magnetic field is\",round(B,2),\"T\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The magnetic field is 2.23 T\n"
- ]
- }
- ],
- "prompt_number": 31
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 7.13, Page number 135"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "v=9.15*10**7; #cyclotron frequency of proton(Hz)\n",
- "m=1.67*10**-27; #mass of proton(kg)\n",
- "q=1.6*10**-19;\n",
- "\n",
- "#Calculation \n",
- "B=(2*math.pi*v*m)/q; #magnetic field(T)\n",
- "\n",
- "#Result\n",
- "print \"The magnetic field is\",int(B),\"T\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The magnetic field is 6 T\n"
- ]
- }
- ],
- "prompt_number": 33
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/Chapter8_1.ipynb b/Engineering_Physics/Chapter8_1.ipynb
deleted file mode 100755
index b3ec194e..00000000
--- a/Engineering_Physics/Chapter8_1.ipynb
+++ /dev/null
@@ -1,360 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:a95b407b682939fdad30498a4e63981a88538f3262f7c6d2067bc16aa9ba5b35"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "8: Magnetic materials and Spectroscopy"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 8.1, Page number 153"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "mew=0.9*10**-23; #magnetic dipole moment(J/T)\n",
- "B=0.72; #magnetic field applied(T)\n",
- "k=1.38*10**-23; #boltzmann constant\n",
- "\n",
- "#Calculation \n",
- "T=(2*mew*B)/(3*k); #temperature(K)\n",
- "\n",
- "#Result\n",
- "print \"The temperature is\",round(T,2),\"K\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The temperature is 0.31 K\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 8.2, Page number 153"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#(C=mew0*M*T)/B.\n",
- "#Therefore M=(C*B)/(mew0*T)\n",
- "C=2*10**-3; #C is curies constant(K)\n",
- "B=0.4; #applied magnetic field(T)\n",
- "mew0=4*math.pi*10**-7;\n",
- "T=300; #temperature(K)\n",
- "\n",
- "#Calculation \n",
- "M=(C*B)/(mew0*T); #magnetisation(A/m)\n",
- "\n",
- "#Result\n",
- "print \"magnetisation is\",round(M,2),\"A/m\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "magnetisation is 2.12 A/m\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 8.3, Page number 153"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "e=1.6*10**-19;\n",
- "B=0.35; #magnetic field(T)\n",
- "lamda=500*10**-9; #wavelength(m)\n",
- "m=9.1*10**-31;\n",
- "c=3*10**8; #speed of light \n",
- "\n",
- "#Calculation \n",
- "deltalambda=(e*B*(lamda)**2)/(4*(math.pi)*m*c*10**-9); #Zeeman shift in wave length(nm)\n",
- "\n",
- "#Result\n",
- "print \"Zeeman shift in wave length is\",round(deltalambda,5),\"nm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Zeeman shift in wave length is 0.00408 nm\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 8.4, Page number 154"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#T=(C*B)/(mew0*B)\n",
- "C=2.1*10**-3; #C is curie's constant(K)\n",
- "B=0.38; #magnetic field(T)\n",
- "mew0=4*math.pi*10**-7; #molecular magnetic moment\n",
- "M=2.15; #magnetisation(A/m)\n",
- "\n",
- "#Calculation \n",
- "T=(C*B)/(mew0*M); #temperature(K)\n",
- "\n",
- "#Result\n",
- "print \"Temperature is\",round(T,1),\"K\"\n",
- "print \"answer in the book varies due to rounding off errors\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Temperature is 295.4 K\n",
- "answer in the book varies due to rounding off errors\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 8.5, Page number 154"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#(M1*T1)=(M2*T2).Therefore M2=(M1*T1)/T2\n",
- "M1=2; #Initial magnetisation(A/m)\n",
- "T1=305; #Initial temperature(K)\n",
- "T2=321;\t\t #final temperature(K)\t\n",
- "\n",
- "#Calculation \n",
- "M2=(M1*T1)/T2; #magnetisation at 321K(A/m)\n",
- "\n",
- "#Result\n",
- "print \"Magnetisation at 321 K is\",round(M2,1),\"A/m\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Magnetisation at 321 K is 1.9 A/m\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 8.6, Page number 154"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "mew0=4*math.pi*10**-7; #molecular magnetic moment\n",
- "M=4; #magnetisation(A/m)\n",
- "T=310; #temperature(K)\n",
- "C=1.9*10**-3; #Curie's constant(K)\n",
- "\n",
- "#Calculation \n",
- "B=(mew0*M*T)/C; #magnetic field(T)\n",
- "\n",
- "#Result\n",
- "print \"Magnetic field is\",round(B,2),\"T\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Magnetic field is 0.82 T\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 8.7, Page number 154"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#e/m is gyromagnetic ratio.\n",
- "deltalambda=0.01*10**-9; #Zeeman shift(m)\n",
- "c=3*10**8; #speed of light in vacuum(m/s)\n",
- "lamda=600*10**-9; #wavelength(m)\n",
- "e=1.6*10**-19;\n",
- "m=9.1*10**-31;\n",
- "\n",
- "#Calculation \n",
- "B=(deltalambda*4*math.pi*m*c)/(e*(lamda)**2); #uniform magnetic field(T)\n",
- "\n",
- "#Result\n",
- "print \"Magnetic field is\",round(B,4),\"T\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Magnetic field is 0.5956 T\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 8.8, Page number 154"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "deltalambda=0.01*10**-9; #Zeeman shift(m)\n",
- "c=3*10**8; #speed of light in vacuum(m/s)\n",
- "B=0.78; #magnetic field(T)\n",
- "lamda=550*10**-9; #wavelength(m)\n",
- "\n",
- "#Calculation \n",
- "Y=(deltalambda*4*math.pi*3*10**8)/(B*(lamda)**2); #e/m ratio(C/kg)\n",
- "\n",
- "#Result\n",
- "print \"e/m ratio is\",round(Y/10**11,1),\"*10**11 C/kg\"\n",
- "print \"answer in the book varies due to rounding off errors\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "e/m ratio is 1.6 *10**11 C/kg\n",
- "answer in the book varies due to rounding off errors\n"
- ]
- }
- ],
- "prompt_number": 21
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/Chapter9_1.ipynb b/Engineering_Physics/Chapter9_1.ipynb
deleted file mode 100755
index 29c8edee..00000000
--- a/Engineering_Physics/Chapter9_1.ipynb
+++ /dev/null
@@ -1,576 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:495ac96015f20ad80c50d2c1722e924721169f0ca7b7ca56739c5ef92f3f2a43"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "9: Quantum Theory"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.1, Page number 171"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "r=0.05; #radius of the wire(mm)\n",
- "l=4; #length of the wire(cm)\n",
- "e=1;\n",
- "T=3000; #temperature(K)\n",
- "s=5.6703*10**-8; #stefan's constant \n",
- "\n",
- "#Calculation \n",
- "A=2*math.pi*r*l*10**-5; #area(m**2)\n",
- "p=s*T**4*A*e; #power radiated by the filament(W)\n",
- "\n",
- "#Result\n",
- "print \"The power radiated by the filament is\",round(p,2),\"W\"\n",
- "print \"answer given in the book is wrong\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The power radiated by the filament is 57.72 W\n",
- "answer given in the book is wrong\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.2, Page number 171"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "h=6.626*10**-34; #plancks constant\n",
- "c=3*10**8; #speed of light(m/s)\n",
- "lamda=550; #wavelength(nm)\n",
- "\n",
- "#Calculation \n",
- "E=(h*c)/(lamda*10**-9); #energy of photon(J)\n",
- "Es=0.1/E; #number of photons(per square cm per second)\n",
- "\n",
- "#Result\n",
- "print \"The number of photons are\",round(Es/10**17,2),\"*10**17 per square cm per second\"\n",
- "print \"answer in the book varies due to rounding off errors\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The number of photons are 2.77 *10**17 per square cm per second\n",
- "answer in the book varies due to rounding off errors\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.3, Page number 171"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "h=6.626*10**-34; #plancks constant\n",
- "c=3*10**8; #speed of light(m/s)\n",
- "lamda=300*10**-9; #wavelength(m)\n",
- "e=1.6*10**-19;\n",
- "phi=2.2; #work function(eV)\n",
- "\n",
- "#Calculation \n",
- "E=(h*c)/lamda; #energy of photon(J)\n",
- "Kmax=(E-(phi*e))/e; #maximum kinetic energy(eV)\n",
- "\n",
- "#Result\n",
- "print \"The maximum kinetic energy is\",round(Kmax,2),\"eV\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The maximum kinetic energy is 1.94 eV\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.4, Page number 172"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "h=6.626*10**-34; #plancks constant\n",
- "c=3*10**8; #speed of light(m/s)\n",
- "lamda=175*10**-9; #wavelength of light(m)\n",
- "w=5; #work function of nickel(eV)\n",
- "\n",
- "#Calculation \n",
- "E=(h*c)/(lamda*1.6*10**-19); #Energy of 200 nm photon(eV)\n",
- "#From photoelectric equation E-w is the potential difference\n",
- "p=E-w; #potential difference required to stop the fastest electron(eV)\n",
- "\n",
- "#Result\n",
- "print \"The potential difference that should be applied is\",round(p,1),\"V\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The potential difference that should be applied is 2.1 V\n"
- ]
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.5, Page number 172"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "h=6.626*10**-34; #plancks constant\n",
- "c=3*10**8; #speed of light(m/s)\n",
- "e=1.6*10**-19;\n",
- "V=50; #accelerating voltage(kV)\n",
- "\n",
- "#Calculation \n",
- "lambdamin=((h*c)/(e*V*10**3))*10**9; #shortest wavelength of X-rays(nm)\n",
- "\n",
- "#Result\n",
- "print \"The shortest wavelength of X-rays is\",round(lambdamin,4),\"nm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The shortest wavelength of X-rays is 0.0248 nm\n"
- ]
- }
- ],
- "prompt_number": 23
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.6, Page number 172"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "lambda1=0.708; #wavelength of a certain line in an X-ray spectrum(angstrom)\n",
- "Z1=42; #atomic number\n",
- "Z2=24;\n",
- "a=1; #screening constant\n",
- "\n",
- "#Calculation \n",
- "lambda2=(lambda1*(Z1-a)**2)/((Z2-a)**2); #wavelength of same line(angstrom)\n",
- "\n",
- "#Result\n",
- "print \"The wavelength of same line is\",round(lambda2,2),\"angstrom\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The wavelength of same line is 2.25 angstrom\n"
- ]
- }
- ],
- "prompt_number": 25
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.7, Page number 172"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#From Bragg's law 2*d*sin(teta)=n*lambda\n",
- "n=1;\n",
- "lamda=0.32; #wavelength(nm)\n",
- "theta=28; #angle at which first order Bragg's reflection is observed(degrees)\n",
- "\n",
- "#Calculation \n",
- "theta=theta*math.pi/180; #angle(radian)\n",
- "d=lamda/(2*math.sin(theta)); #distance between atomic planes(nm)\n",
- "\n",
- "#Result\n",
- "print \"The distance between atomic planes is\",round(d,2),\"nm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The distance between atomic planes is 0.34 nm\n"
- ]
- }
- ],
- "prompt_number": 28
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.8, Page number 172"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "h=6.626*10**-34; #plancks constant\n",
- "theta=50; #angle(degrees)\n",
- "m=9.1*10**-31; #mass of electron(kg)\n",
- "c=3*10**8; #speed of light(m/s)\n",
- "\n",
- "#Calculation \n",
- "theta=theta*math.pi/180; #angle(radian)\n",
- "deltalambda=(h/(m*c))*(1-math.cos(theta))*10**12; \n",
- "lambdafin=2.5; #wavelength of scattered X-rays\n",
- "lambdainit=lambdafin-deltalambda; #wavelength of X-rays in the incident beam(pm)\n",
- "\n",
- "#Result\n",
- "print \"The wavelength of X-rays in the incident beam is\",round(lambdainit,2),\"pm\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The wavelength of X-rays in the incident beam is 1.63 pm\n"
- ]
- }
- ],
- "prompt_number": 30
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.9, Page number 172"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "h=6.626*10**-34; #plancks constant\n",
- "c=3*10**8; #speed of light(m/s)\n",
- "lamda=500*10**-9; #wavelength of laser(m)\n",
- "t=20*10**-3; #time(s)\n",
- "N=2.52*10**16; #number of photons in a 20ms pulse\n",
- "\n",
- "#Calculation \n",
- "E=(h*c)/lamda; #Energy of 500 nm photon(J)\n",
- "p=E*N/t; #power of the laser(W)\n",
- "\n",
- "#Result\n",
- "print \"The power of the laser is\",round(p,1),\"W\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The power of the laser is 0.5 W\n"
- ]
- }
- ],
- "prompt_number": 34
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.10, Page number 173"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "h=6.626*10**-34; #plancks constant\n",
- "c=3*10**8; #speed of light(m/s)\n",
- "lamda=350*10**-9; #threshold wavelength(m)\n",
- "e=1.6*10**-19;\n",
- "\n",
- "#Calculation \n",
- "W=h*c/(lamda*e); #work function of the surface(eV)\n",
- "\n",
- "#Result\n",
- "print \"The work function of the surface is\",round(W,2),\"eV\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The work function of the surface is 3.55 eV\n"
- ]
- }
- ],
- "prompt_number": 40
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.11, Page number 173"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "h=6.626*10**-34; #plancks constant\n",
- "c=3*10**8; #speed of light(m/s)\n",
- "e=1.6*10**-19;\n",
- "lambdamin=0.02*10**-9; #minimum wavelength(m)\n",
- "\n",
- "#Calculation \n",
- "V=(h*c/(lambdamin*e))*10**-3; #accelerating voltage(kV)\n",
- "\n",
- "#Result\n",
- "print \"The accelerating voltage needed to produce minimum wavelength is\",round(V,4),\"kV\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The accelerating voltage needed to produce minimum wavelength is 62.1187 kV\n"
- ]
- }
- ],
- "prompt_number": 42
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.12, Page number 173"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "#According to Bragg's eq.2*d*sin(teta)=n*lambda\n",
- "n=2; #since second order Bragg's eq.\n",
- "d=5; #since d=5(lambda)\n",
- "lamda=1;\n",
- "\n",
- "#Calculation \n",
- "a=(n*lamda)/(2*5*lamda);\n",
- "theta=math.asin(a); #angle of second order Braggs reflection(radian)\n",
- "theta=theta*180/math.pi; #angle(degrees)\n",
- "\n",
- "#Result\n",
- "print \"The angle of second order Braggs reflection is\",round(theta,2),\"degrees\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The angle of second order Braggs reflection is 11.54 degrees\n"
- ]
- }
- ],
- "prompt_number": 45
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example number 9.13, Page number 173"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#importing modules\n",
- "import math\n",
- "from __future__ import division\n",
- "\n",
- "#Variable declaration\n",
- "h=6.626*10**-34; #plancks constant\n",
- "c=3*10**8; #speed of light(m/s)\n",
- "lamda=0.03; #wavelength(nm)\n",
- "p=80/100;\n",
- "\n",
- "#Calculation \n",
- "E=(h*c)/(lamda*10**-9); #energy of photon(J) \n",
- "TE=E/p; #Total energy.E=80% of TE(J)\n",
- "TE=TE*(10**-3)/e; #Total energy(keV)\n",
- "\n",
- "#Result\n",
- "print \"The electron must have been accelerated through a potential difference of\",round(TE,3),\"kV\" "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "The electron must have been accelerated through a potential difference of 51.766 kV\n"
- ]
- }
- ],
- "prompt_number": 49
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/README.txt b/Engineering_Physics/README.txt
deleted file mode 100755
index 98363f45..00000000
--- a/Engineering_Physics/README.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-Contributed By: SINDHU ARROJU
-Course: btech
-College/Institute/Organization: JNTUH
-Department/Designation: Computer Science
-Book Title: Engineering Physics
-Author: P. V. Naik
-Publisher: Pearson Education(Singapore)
-Year of publication: 2004
-Isbn: 8129705206
-Edition: 1 \ No newline at end of file
diff --git a/Engineering_Physics/chapter1.ipynb b/Engineering_Physics/chapter1.ipynb
deleted file mode 100755
index 69791eee..00000000
--- a/Engineering_Physics/chapter1.ipynb
+++ /dev/null
@@ -1,862 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:0e6e83846c51774a2df15d43a35bd12afc7130920f3c7a5b4cb2d5a70d8dae4a"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter1:RELATIVISTIC MECHANICS"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.1:pg-12"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# example 1\n",
- "import math\n",
- "#to calculate length of the bar measured by the ststionary observer\n",
- "lo =1 #length in metre\n",
- "v=0.75*3*10**8 #speed (m/s)\n",
- "c=3*10**8 #light speed(m/s)\n",
- "l=lo*math.sqrt(1-(v**2/c**2))\n",
- "print \"\\n the length of bar in is\",round(l,2),\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "\n",
- " the length of bar in is 0.66 m\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.2:pg-12"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# example 2\n",
- "import math\n",
- "#to calculate velocity of rocket \n",
- "#lo be the length at rest \n",
- "l=99.0/100 #length is 99 per cent of its length at rest is l=(99/100)lo\n",
- "c=3*10**8 #light speed(m/s)\n",
- "v=c*math.sqrt(1-l**2) #formula is v=c math.sqrt(1-(l/lo)**2)\n",
- "print\" the velocity of rocket is v=\",\"{:.2e}\".format(v),\"m/s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- " the velocity of rocket is v= 4.23e+07 m/s\n"
- ]
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.4:pg-13"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to percentage contraction of a rod\n",
- "c=3.0*10**8 #light speed(m/s)\n",
- "v=0.8*c #velocity(m/s)\n",
- "#let lo be the length of the rod in the frame in which it is at rest\n",
- "#s' is the frame which is moving with a speed 0.8c in a direction making an angle 60 with x-axis\n",
- "#components of lo along perpendicular to the direction of motion are lo cos60 and lo sin60 respectively\n",
- "l1=math.cos(math.pi/3)*math.sqrt(1-(v/c)**2) #length of the rod alond the direction of motion =lo math.cos(pi/3)math.sqrt(1-(v/c)**2)\n",
- "l2=math.sin(math.pi/3) #length of the rod perpendicular to the direction of motion =lo sin60\n",
- "l=math.sqrt(l1**2+l2**2) # length of the moving rod\n",
- "per=(1-l)*100/1\n",
- "print \"percentage contraction of a rod is\",round(per,2),\"%\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "percentage contraction of a rod is 8.35 %\n"
- ]
- }
- ],
- "prompt_number": 23
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.7:pg-14"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# example 7\n",
- "import math\n",
- "#to calculate velocity of the circular lamina \n",
- "c=3*10**8 #light speed (m/s)\n",
- "#R'=R/2 (radius)\n",
- "#R'=R math.sqrt(1-(v/c)**2)\n",
- "v=(math.sqrt(3)/2)*c \n",
- "print \"velocity of the circular lamina relative to frame s is v=\",v,\"m/s\"\n",
- "#answer is given in terms of c in the textbook\n",
- "\n",
- "\n",
- "\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "velocity of the circular lamina relative to frame s is v= 259807621.135 m/s\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.8:pg-17"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# example 8\n",
- "import math\n",
- "#to calculate speed of the clock\n",
- "#clock should record l=59 minutes for each hour recorded by clocks stationary with respect to the observer\n",
- "l=59.0 \n",
- "lo=60\n",
- "c=3*10**8 #light speed (m/s)\n",
- "v=math.sqrt(c**2*(1-l**2/lo**2))\n",
- "print \"speed of the clock is v =\",\"{:.2e}\".format(v),\"m/s\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "speed of the clock is v = 5.45e+07 m/s\n"
- ]
- }
- ],
- "prompt_number": 31
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.9:pg-17"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate distance travelled by the beam \n",
- "deltat0=2.5*10**-8 #proper half life of pi mesons in (s)\n",
- "c=3*10**8 #light speed (m/s)\n",
- "v=0.8*c #mesons velocity (m/s)\n",
- "deltat=deltat0/math.sqrt(1-(v/c)**2) #half life (s)\n",
- "#No=initial flux ,N=flux after time t\n",
- "#N=N0 e**(-t/T)\n",
- "#N=N0/e**2 (given)=No e(-t/T)\n",
- "#t=2 deltat\n",
- "d=2*deltat*v #d=vt\n",
- "print \"distance travelled by the beam is d=\",d,\"m\" \n",
- "#answer is given in the textbook=19.96 m\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "distance travelled by the beam is d= 20.0 m\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.10:pg-17"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate distance travelled by the particle \n",
- "deltat0=2*10**-8 #proper half life to of the particle in (s) \n",
- "c=3*10**8 #light speed (m/s)\n",
- "v=0.96*c #speed of the particle (m/s)\n",
- "deltat=(deltat0)/(math.sqrt(1-(v/c)**2)) #half life in the laboratory frame t in (s) \n",
- "#t=deltat (flux of the beam falls to (1/2) times initial flux)\n",
- "d=v*deltat #d=vt\n",
- "print \"distance travelled by the particle in this time is d=\",d,\"m\"\n",
- "#answer is given wrong in the textbook =20.45 m\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "distance travelled by the particle in this time is d= 20.5714285714 m\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.11:pg-18"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate speed\n",
- "deltat0=1440 #proper time interval measured by an observer moving with the clock (min)\n",
- "deltat=1444 #time interval measured by a stationary observer (min)\n",
- "c=3*10**8 #light speed (m/s)\n",
- "v=c*math.sqrt(1-(deltat0/deltat)**2)\n",
- "print \" moving clock appears to lose 4min in 24 hours from the stationary observer is v=\",\"{:.1e}\".format(v),\"m/s\"\n",
- "#answer is given wrong in the book =2.32*10**7 m/s\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- " moving clock appears to lose 4min in 24 hours from the stationary observer is v= 3.0e+08 m/s\n"
- ]
- }
- ],
- "prompt_number": 33
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.12:pg-18"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate velocity of beta particle\n",
- "c=3*10**8 #light velocity(m/s)\n",
- "u1=0.9*c #velocity of the beta particle relative to the atom in the direction of motion\n",
- "v=0.25*c #velocity of the radioactive atom relative to an experimenter\n",
- "u=(u1+v)/(1+u1*v/c**2) \n",
- "print \" velocity of the beta particle as observed by the experimenter is u=\",\"{:.3e}\".format(u),\"m/s\"\n",
- "#answer is given in terms of c in the book =0.94c\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- " velocity of the beta particle as observed by the experimenter is u= 2.816e+08 m/s\n"
- ]
- }
- ],
- "prompt_number": 34
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.13:pg-18"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate velocity\n",
- "c=3*10**8 # light velocity\n",
- "v=0.75*c #speed of A\n",
- "ux=-0.85*c #speed of B\n",
- "ux1=(ux-v)/(1-ux*v/c**2)\n",
- "print\"\\n the velocity of B with respect to A (m/s) is\",\"{:.3e}\".format(ux1),\"m/s\"\n",
- "#answer is given in terms of c in the book=-0.9771c\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "\n",
- " the velocity of B with respect to A (m/s) is -2.931e+08 m/s\n"
- ]
- }
- ],
- "prompt_number": 36
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.14:pg-19"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate velocity in the laboratory frame\n",
- "c=3*10**8 #light speed (m/s)\n",
- "v=0.8*c #velocity relative to laboratory along positive direction of x-axis\n",
- "#given that u'=3 i+4 j+12 k (m/s)\n",
- "ux1=3 #in (m/s)\n",
- "uy1=4 #in (m/s)\n",
- "uz1=12 #in (m/s)\n",
- "ux=(ux1+v)/(1+v*ux1/c**2)\n",
- "uy=(uy1*math.sqrt(1-(v/c)**2))/(1+v*ux1/c**2)\n",
- "uz=(uz1*math.sqrt(1-(v/c)**2))/(1+v*ux1/c**2)\n",
- "print \"u=ux i+uy j+uz k\"\n",
- "print \"where\"\n",
- "print \"ux=\", \"{:.1e}\".format(ux),\"m/s\"\n",
- "print \"uy=\",round(uy,1),\"m/s\"\n",
- "print \"uz=\",round(uz,1),\"m/s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "u=ux i+uy j+uz k\n",
- "where\n",
- "ux= 2.4e+08 m/s\n",
- "uy= 2.4 m/s\n",
- "uz= 7.2 m/s\n"
- ]
- }
- ],
- "prompt_number": 41
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.17:pg-21"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "# to calculate velocity of the particle\n",
- "c=3.0*10**8 #light speed (m/s)\n",
- "v=0.4*c #velocity of frame s' relative to s along axis x\n",
- "ux=0.8*c*(1.0/2) #component of velocity u(=0.8 c) of the particle along x axis ux=0.8 c cos60\n",
- "uy=0.8*c*sin (math.pi/3) #component of the velocity u of the particle along y axis \n",
- "ux1=(ux-v)/(1-ux*v/c**2)\n",
- "uy1=uy*math.sqrt(1-(v/c)**2)/(1-(ux*v/c**2))\n",
- "print \"resultant velocity as observed by a person in frame s1 is u1=ux1 i+uy1 j\"\n",
- "print \"where\"\n",
- "print \"ux1=\",ux1,\"m/s\"\n",
- "print \"uy1=\",\"{:.1e}\".format(uy1),\"m/s\"\n",
- "#answer is given in terms of c in the book i.e. uy1=0.756c m/s\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "resultant velocity as observed by a person in frame s1 is u1=ux1 i+uy1 j\n",
- "where\n",
- "ux1= 0.0 m/s\n",
- "uy1= 2.3e+08 m/s\n"
- ]
- }
- ],
- "prompt_number": 48
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.18:pg-25"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate mass, momentum,total energy,kinetic energy\n",
- "c=3*10**8 #light speed (m/s)\n",
- "v=c/sqrt (2) #velocity (m/s)\n",
- "#let mo be the rest mass of the particle \n",
- "#relativistic mass m of the particle is m=mo/math.sqrt(1-(v/c)**2)\n",
- "m=1/sqrt (1-v**2/c**2) #in kg\n",
- "print \"mass m=\",round(m,2),\" mo\"\n",
- "#momentum p of the particle is p=mv\n",
- "p=m*v #in kg-m/s\n",
- "print \"momentum p=\",\"{:.1e}\".format(p),\" mo\"\n",
- "#total energy E of the particle\n",
- "E=m*c**2 #in J\n",
- "print \"energy E=\",\"{:.3e}\".format(E,3),\" mo\"\n",
- "#kinetic energy K=E-mo c**2\n",
- "K=E-c**2 #in J\n",
- "print \"kinetic energy K=\",\"{:.3e}\".format(K),\" mo\"\n",
- "#answer is given in terms of m0 and c in the book\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "mass m= 1.41 mo\n",
- "momentum p= 3.0e+08 mo\n",
- "energy E= 1.273e+17 mo\n",
- "kinetic energy K= 3.728e+16 mo\n"
- ]
- }
- ],
- "prompt_number": 56
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.19:pg-26"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate velocity of the parcticle \n",
- "c=3*10**8 #light speed(m/s)\n",
- "# we know that E(energy)=mc**2\n",
- "# mo=rest mass\n",
- "#E=3 moc**2=mc**2 or m=3 mo (given that total energy of the particle is thrice its rest energy) \n",
- "m=3.0 # relativistic mass \n",
- "#formula is v=c math.sqrt(1-(mo/m)**2)\n",
- "v=math.sqrt(c**2*(1-(1/m)**2))\n",
- "print \"velocity of the particle is v=\",\"{:.3e}\".format(v),\"m/s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "velocity of the particle is v= 2.828e+08 m/s\n"
- ]
- }
- ],
- "prompt_number": 57
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.20:pg-26"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate mass(m),speed(v) of an electron\n",
- "K=1.5*10**6*1.6*10**-19 #kinetic energy(J)\n",
- "m0=9.11*10**-31 #rest mass of an electron(kg)\n",
- "c=3*10**8 # velocity of light in vacuum(m/s)\n",
- "m=(K/c**2)+m0 #relativistic kinetic energy(k=(m-mo)c**2)\n",
- "print \"mass is m=\",\"{:.2e}\".format(m),\"kg \"\n",
- "v=c*math.sqrt(1-m0**2/m**2)\n",
- "print \"speed of an electron is v=\",\"{:.1e}\".format(v),\"m/s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "mass is m= 3.58e-30 kg \n",
- "speed of an electron is v= 2.9e+08 m/s\n"
- ]
- }
- ],
- "prompt_number": 59
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.21:pg-27"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate work to be done \n",
- "E=0.5*10**6 #rest energy of electron (MeV) E=m0*c**2\n",
- "v1=0.6*3*10**8 #speed of electron in (m/s)\n",
- "v2=0.8*3*10**8\n",
- "c=3.0*10**8 #speed of light in (m/s)\n",
- "K1=E*((1.0/math.sqrt(1-v1**2/c**2))-1) #kinetic energy in (eV)\n",
- "K2=E*((1.0/math.sqrt(1-v2**2/c**2))-1)\n",
- "w=(K2-K1)*1.6*10**-19\n",
- "print \"amount of work to be done is w=\",\"{:.1e}\".format(w),\"J\"\n",
- "\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "amount of work to be done is w= 3.3e-14 J\n"
- ]
- }
- ],
- "prompt_number": 64
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.22:pg-27"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate speed\n",
- "c=3*10**8 #light speed (m/s)\n",
- "m=2.25 #mass m of a body be 2.25 times its rest mass mo i.e. m=2.25m0\n",
- "#formula is v=c math.sqrt(1-(m0/m)**2)\n",
- "v=c*math.sqrt(1-(1/m)**2)\n",
- "print \" speed is v=\",\"{:.3e}\".format(v),\"m/s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- " speed is v= 2.687e+08 m/s\n"
- ]
- }
- ],
- "prompt_number": 67
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.23:pg-27"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate speed of the rocket\n",
- "m0=50.0 #weight of man on the earth(kg)\n",
- "m=50.5 #weight of man in rocket ship (kg)\n",
- "c=3*10**8 #speed of light(m/s)\n",
- "v=c*math.sqrt(1-m0**2/m**2)\n",
- "print \"speed of the rocket is v=\",\"{:.2e}\".format(v),\"m/s\" \n",
- "#to calculate speed of electron\n",
- "m0=9.11*10**-31 #mass of electron =rest mass of proton\n",
- "m=1.67*10**-27\n",
- "v=c*math.sqrt(1-m0**2/m**2)\n",
- "print \"speed of an electron is v=\",\"{:.2e}\".format(v),\"m/s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "speed of the rocket is v= 4.21e+07 m/s\n",
- "speed of an electron is v= 3.00e+08 m/s\n"
- ]
- }
- ],
- "prompt_number": 71
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.24:pg-28"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate velocity\n",
- "c=3*10**8 #light speed (m/s)\n",
- "#K(kinetic energy)=(m-mo(rest mass))c**2\n",
- "#it can also be written as mc**2=K+m0c**2\n",
- "#given that K=2m0c**2(rest mass energy)\n",
- "#m=3m0\n",
- "m=3.0 #relativistic mass\n",
- "#formula is v=c math.sqrt(1-(m0/m)**2)\n",
- "v=c*math.sqrt(1-(1/m)**2)\n",
- "print \"velocity of a body is v=\",\"{:.3e}\".format(v),\"m/s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "velocity of a body is v= 2.828e+08 m/s\n"
- ]
- }
- ],
- "prompt_number": 73
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.25:pg-28"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate kinetic energy ,momentum of electron\n",
- "m0=9.11*10**-31 #its rest mass (kg)\n",
- "c=3*10**8 #light velocity in (m/s)\n",
- "m=11*m0 #mass of moving electron is 11 times its rest mass\n",
- "K=(m-m0)*c**2/(1.6*10**-19) # kinetic energy\n",
- "print \"kinetic energy is K=\",\"{:.2e}\".format(K),\"eV\" \n",
- "v=c*math.sqrt(1-(m0/m)**2) #velocity(m/s)\n",
- "p=m*v #momentum\n",
- "print \"momentum is p=\",\"{:.2e}\".format(p),\"kg m/s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "kinetic energy is K= 5.12e+06 eV\n",
- "momentum is p= 2.99e-21 kg m/s\n"
- ]
- }
- ],
- "prompt_number": 74
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.26:pg-29\n",
- " "
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate proton gain in mass\n",
- "c=3*10**8 #light speed(m/s)\n",
- "K=500*10**6*1.6*10**-19 #kinetic energy (J)\n",
- "deltam=K/c**2\n",
- "print \"proton gain in mass is delm=\",\"{:.2e}\".format(deltam),\"kg\"\n",
- "#answer is given wrong in the book=8.89*10**28 kg\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- " proton gain in mass is delm= 8.89e-28 kg\n"
- ]
- }
- ],
- "prompt_number": 76
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex1.27:pg-29"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate speed of 0.1MeV electron\n",
- "E=0.512*10**6 #rest mass energy E=m0*c**2\n",
- "c=3*10**8 #velocity of light (m/s)\n",
- "K=0.1*10**6 #kinetic energy (MeV)\n",
- "v=c*math.sqrt(1-(E/(K+E))**2) \n",
- "print \"speed of electron is v=\",\"{:.3e}\".format(v),\"m/s\" \n",
- "#to calculate mass and speed of 2MeV electron\n",
- "E=2*10**6*1.6*10**-19 #in (J)\n",
- "m=E/c**2 \n",
- "print \"mass is m=\",\"{:.2e}\".format(m),\"kg\"\n",
- "m0=9.11*10**-31 #electron mass (kg)\n",
- "v=c*math.sqrt(1-m0**2/m**2)\n",
- "print \"speed is v=\",\"{:.2e}\".format(v),\"m/s\"\n",
- "\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "speed of electron is v= 1.643e+08 m/s\n",
- "mass is m= 3.56e-30 kg\n",
- "speed is v= 2.90e+08 m/s\n"
- ]
- }
- ],
- "prompt_number": 78
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/chapter10.ipynb b/Engineering_Physics/chapter10.ipynb
deleted file mode 100755
index 2fc444d1..00000000
--- a/Engineering_Physics/chapter10.ipynb
+++ /dev/null
@@ -1,293 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:a79be9375f475037255b00d45fe0971e7606cfc4e70e2a086d7c77b20c6b87d7"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter10:MAGNETIC PROPERTIES OF MATERIALS"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex10.1:pg-288"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate permeability and susceptibility of the bar\n",
- "phi=2.4*10**-5 #magnetic flux in weber\n",
- "A=0.2*10**-4 #cross sectional area in m**2\n",
- "B=phi/A #magnetic induction in N/Am\n",
- "H=1200 #magnetising field in A/m\n",
- "mu=B/H\n",
- "print \"permeability is mu=\",\"{:.2e}\".format(mu),\"N/A**2\"\n",
- "muo=4*math.pi*10**-7 \n",
- "chim=(mu/muo)-1\n",
- "print \"susceptibility is chim=\",round(chim,2),\"unitless\"\n",
- "#the answer is given wrong in the book (round off error) chim=737\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "permeability is mu= 1.00e-03 N/A**2\n",
- "susceptibility is chim= 794.77 unitless\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex10.2:pg-289"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate current should be sent through the solenoid\n",
- "l=.10 #length in m\n",
- "N=50 #number of turns\n",
- "H=5*10**3 #magnetising field in A/m\n",
- "i=H*l/N \n",
- "print \"current is i=\",i,\"A\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "current is i= 10.0 A\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex10.3:pg-289"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate magnetic moment of the rod\n",
- "#formula is B=muo*(H+I)\n",
- "#where H=ni\n",
- "n=500.0 #number of turns in turns/m\n",
- "i=0.5 #current passed through the solenoid in A\n",
- "mur=1200.0 #relative permeability\n",
- "I=(mur-1)*n*i #intensity of magnetisation in A/m\n",
- "V=10**-3 #volume in m**3\n",
- "M=I*V\n",
- "print \"the magnetic moment of the rod is M=\",round(M),\"A-m**2\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the magnetic moment of the rod is M= 300.0 A-m**2\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex10.4:pg-290"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate flux density,magnetic intensity,permeability of iron\n",
- "phi=2.0*10**-6 #flux in the ring in weber\n",
- "A=10**-4 #cross-sectional area in m**2\n",
- "B=phi/A \n",
- "print \"flux density is B=\",\"{:.2e}\".format(B),\"weber/m**2\"\n",
- "N=200.0 #number of turns\n",
- "i=0.30 #current flows in the windings in A\n",
- "l=0.2 #length in m\n",
- "H=N*i/l\n",
- "print \"magnetic intensity is H=\",H,\"A-turn/m\"\n",
- "mu=B/H\n",
- "print \"permeability is mu=\",round(mu,6),\"weber/A-m\"\n",
- "muo=4*math.pi*10**-7 \n",
- "mur=mu/muo\n",
- "print \"relative permeability is mur=\",round(mur,2),\"unitless\"\n",
- "\n",
- "#the answer for H in the book is wrong\n",
- "#the answer for mu in book is wrong due to wrong H\n",
- "#the answer in book for mur is wrong due to \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "flux density is B= 2.00e-02 weber/m**2\n",
- "magnetic intensity is H= 300.0 A-turn/m\n",
- "permeability is mu= 6.7e-05 weber/A-m\n",
- "relative permeability is mur= 53.05 unitless\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex10.5:pg-294"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate number of ampere turns\n",
- "l=0.5 #length in m\n",
- "mu=6.5*10**-3 #permeability of iron in henry/m\n",
- "A=2*10**-4 #area of cross-section in m**-4\n",
- "R=l/(mu*A) #reluctance in A-turns/weber\n",
- "flux=4*10**-4 #in weber\n",
- "mmf=flux*R\n",
- "print \"the number of ampere turns is mmf=\",round(mmf,1),\"ampere-turns\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the number of ampere turns is mmf= 153.8 ampere-turns\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex10.6:pg-294"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate relative permeability of the medium\n",
- "phi=1.5*10**-3 #magnetic flux in weber\n",
- "l=math.pi*50*10**-2 #length in m\n",
- "A=10*10**-4 #area of cross-section\n",
- "N=1000 #number of turns\n",
- "i=5 #current in A\n",
- "muo=4*math.pi*10**-7\n",
- "#phi(magnetic flux)=m.m.f/reluctance\n",
- "#phi=N*i*muo*mur*A/l\n",
- "#we get,\n",
- "mur=phi*l/(N*i*A*muo)\n",
- "print \"relative permeability of the medium is mur=\",mur,\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "relative permeability of the medium is mur= 375.0 unitless\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex10.7:pg-295"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate magnetising current\n",
- "#formula is phi(magnetic flux)=m.m.f/reluctance\n",
- "#phi=N*i*mu*A/l--------eq(1)\n",
- "#phi=BA------------eq(2)\n",
- "B=0.20 #magnetic flux density in weber/m**2\n",
- "l=1 #average length of the circuit in m \n",
- "N=100 #number of turns\n",
- "mu=7.3*10**-3 #in h.m\n",
- "#from eq(1)and eq(2),we get\n",
- "i=B*l/(N*mu)\n",
- "print \"magnetising current is i=\",round(i,3),\"A\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "magnetising current is i= 0.274 A\n"
- ]
- }
- ],
- "prompt_number": 10
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/chapter11.ipynb b/Engineering_Physics/chapter11.ipynb
deleted file mode 100755
index ffad9cdd..00000000
--- a/Engineering_Physics/chapter11.ipynb
+++ /dev/null
@@ -1,60 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:63e794f26755ea447faa48915f48af2a1824429b5991c82dc73f1b261af07c7e"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter11:ULTRASONICS"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex11.1:pg-303"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate fundemental frequency\n",
- "Y=7.9*10**10 #Young modulus for quartz in Nm**-2\n",
- "rho=2.65*10**3 #density of quartz in kg/m**3\n",
- "#the velocity of longitudinal wave is given by\n",
- "v=math.sqrt(Y/rho) #in m/s\n",
- "#for fundamental mode of vibration ,thickness is given by lamda/2\n",
- "lamda=2*0.001 #wavelength in m\n",
- "nu=v/lamda\n",
- "print \"the fundamental frequency is nu=\",round(nu,2),\"Hz\"\n",
- "#answer is given wrong in the book ,nu=2730 Hz\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the fundamental frequency is nu= 2729987.21 Hz\n"
- ]
- }
- ],
- "prompt_number": 2
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/chapter12.ipynb b/Engineering_Physics/chapter12.ipynb
deleted file mode 100755
index 35c30635..00000000
--- a/Engineering_Physics/chapter12.ipynb
+++ /dev/null
@@ -1,550 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:024efb73c06fed2399cd64a4d2a669b874446e3757757251d146f1996aec28e9"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter12:ELECTROMAGNETICS"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.1:pg-322"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate electric flux\n",
- "#electric flux through a surface is phi=vector(E)*vector(s)\n",
- "#where vector E=2i+4j+7k,vector s=10j\n",
- "E=4 #E=4j\n",
- "s=10 #s=10j\n",
- "phi=E*s\n",
- "print \"electric flux is phi=\",phi,\"units\"\n",
- "#to calculate flux coming out of any face of the cube\n",
- "q=1 #charge in coulomb\n",
- "epsilon0=8.85*10**-12 #permittivity in free space in coul**2/N-m**2\n",
- "phi1=q/(6*epsilon0)\n",
- "print \"flux coming out of any face of the cube is phi1=\",\"{:.2e}\".format(phi1),\"N-m**2/coul**2\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "electric flux is phi= 40 units\n",
- "flux coming out of any face of the cube is phi1= 1.88e+10 N-m**2/coul**2\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.2:pg-322"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate electric field at a point from centre of the shell\n",
- "q=0.2*10**-6 #charge\n",
- "r=3 #radius\n",
- "epsilon0=8.85*10**-12\n",
- "E=q/(4*math.pi*epsilon0*r**2)\n",
- "print \"electric field at a point from centre of the shell is E=\",round(E),\"N/coulomb\"\n",
- "#to calculate electric field at a point just outside the shell\n",
- "R=0.25 #radius\n",
- "E=q/(4*math.pi*epsilon0*R**2)\n",
- "print \"electric field at a point just outside the shell is E=\",\"{:.2e}\".format(E),\"N/coulomb\"\n",
- "#to calculate the electric field at a point inside the shell\n",
- "#when the point is situated inside the spherical shell,the electric field is zero\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "electric field at a point from centre of the shell is E= 200.0 N/coulomb\n",
- "electric field at a point just outside the shell is E= 2.88e+04 N/coulomb\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.3:pg-323"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate electric field at a point on earth vertically below the wire\n",
- "lamda=10**-4 #wavelength in coulomb/m\n",
- "r=4 #radius in m\n",
- "epsilon0=8.854*10**-12\n",
- "E=2*lamda/(4*math.pi*epsilon0*r)\n",
- "print \"electric field at a point on earth vertically below the wire is E=\",\"{:.1e}\".format(E),\"N/coulomb\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "electric field at a point on earth vertically below the wire is E= 4.5e+05 N/coulomb\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.4:pg-323"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate separation between those equipotential surfaces \n",
- "V=5 #potential difference\n",
- "epsilon0=8.85*10**-12 #permittivity of free space\n",
- "sigma=1*10**-7 #in c/m**2\n",
- "#electric field due to an infinite sheet of surface charge density is given by E=sigma/(2*epsilon0) eq(1)\n",
- "#E=V/d eq(2)\n",
- "#from eq(1) and eq(2),we get \n",
- "d=(2*epsilon0*V)/sigma\n",
- "print \"separation between those equipotential surfaces is d=\",\"{:.2e}\".format(d),\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "separation between those equipotential surfaces is d= 8.85e-04 m\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.5:pg-324"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate force per unit area\n",
- "#force of attraction per unit area is given by F=(epsilon0*E**2)/2 eq(1)\n",
- "#E=V/d eq(2)\n",
- "epsilon0=8.85*10**-12 #permittivity of free space\n",
- "d=1*10**-3 #distance\n",
- "V=100 #potential difference in volts\n",
- "#from eq(1) and eq(2),we get\n",
- "F=(epsilon0*V**2)/(2*d**2)\n",
- "print \"force per unit area is F=\",\"{:.2e}\".format(F),\"N/m**2\"\n",
- "#answer is given incorrect in the book ,F=4.425*10**-12\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "force per unit area is F= 4.42e-02 N/m**2\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.6:pg-324"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate charge\n",
- "#let charge be q coulomb ,then the surface density of charge i.e. sigma=q/(4*math.pi*r**2)..............eq(1)\n",
- "#outward pull per unit area =sigma**2/(2*epsilon0)............eq(2)\n",
- "#put eq(1) in eq(2),we get q**2/(4*math.pi*r**2)**2*(2*epsilon0)..............eq(3)\n",
- "#pressure due to surface tension =4*T/r............eq(4)\n",
- "T=27\n",
- "r=1.5*10**-2\n",
- "epsilon0=8.85*10**-12\n",
- "#equate eq(3) and eq(4),we get\n",
- "q=math.sqrt(4*T*((4*math.pi*r**2)**2)*2*epsilon0/r)\n",
- "print \"charge is q=\",\"{:.3e}\".format(q),\"coulomb\"\n",
- "#answer is given wrong in the book,square of 4*math.pi*r**2 is not taken in the solution.\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "charge is q= 1.009e-06 coulomb\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.7:pg-325"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate increase in radius \n",
- "q=4.8*10**-8 #charge in coulomb\n",
- "r=10*10**-2 #radius in m\n",
- "epsilon0=8.85*10**-12 #C**2/N-m**2\n",
- "P=10**5 #N/m**2\n",
- "dr=(q**2)/(96*((math.pi)**2)*(r**3)*epsilon0*P)\n",
- "print \"increase in radius is dr=\",\"{:.2e}\".format(dr),\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "increase in radius is dr= 2.75e-09 m\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.8:pg-340"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#in page no.340,numbering is done wrongly,it should be like ex-8,ex-9,ex-10,ex-11,ex-12,ex-13,ex-14\n",
- "import math\n",
- "#to calculate average values of intensities of electric and magnetic fields of radiation\n",
- "#energy of lamp=1000 J/s\n",
- "#area illuminated =4*math.pi*r**2=16*math.pi m**2\n",
- "#energy radiated per unit area per second =1000/16*math.pi\n",
- "#from poynting theorem |s|=|E*H|=E*H eq(1)\n",
- "s=1000/(16*math.pi)\n",
- "muo=4*math.pi*10**-7 #permeability of free space\n",
- "epsilon0=8.85*10**-12 #permittivity in free space\n",
- "#E/H=math.sqrt(muo/epsilon0) eq(2)\n",
- "#from eq(1) and eq(2),we get\n",
- "E=math.sqrt(s*math.sqrt(muo/epsilon0))\n",
- "H=s/E\n",
- "print \"average value of intensity of electric fields of radiation is E=\",round(E,2),\"V/m\"\n",
- "print \"average value of intensity of magnetic fields of radiation is H=\",round(H,2),\"ampere-turn/m\"\n",
- "#answer is given wrong in the book E=48.87 V/m,solution of magnetic fields is not given in the book .\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "average value of intensity of electric fields of radiation is E= 86.58 V/m\n",
- "average value of intensity of magnetic fields of radiation is H= 0.23 ampere-turn/m\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.9:pg-340"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate amplitudes of electric and magnetic fields of radiation\n",
- "#energy received by an electromagnetic wave per sec per unit area is given by poynting vector |s|=|E*H|=E*H*sin 90 (becoz E is perpendicular to H)\n",
- "#it is given that energy received by earth's surface is\n",
- "s=1400.0 #|s|=2 cal min**-1 cm**-2\n",
- "muo=4.0*math.pi*10**-7 #permittivity of free space\n",
- "epsilon0=8.85*10**-12 #permeability of free space\n",
- "#E*H=1400 eq(1)\n",
- "#E/H=math.sqrt(muo/epsilon0) eq(2)\n",
- "#from eq(1) and eq(2) ,we get\n",
- "E=math.sqrt(s*math.sqrt(muo/epsilon0))\n",
- "#from eq(1) ,we get\n",
- "H=1400.0/E\n",
- "Eo=E*math.sqrt(2) # at distance 2 m\n",
- "Ho=H*math.sqrt(2) # at distance 2 m\n",
- "print \"amplitude of electric field is Eo=\",int(Eo),\"V/m\"\n",
- "print \"amplitude of magnetic field is Ho=\",round(Ho,3),\"amp-turn/m\"\n",
- "\n",
- "# The answers in the textbook are slightly different due to approximation\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "amplitude of electric field is Eo= 1027 V/m\n",
- "amplitude of magnetic field is Ho= 2.726 amp-turn/m\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.10:pg-341"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# no value to be found out , only equation to be written hence skipped following the TBC guidelines"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [],
- "prompt_number": 29
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.11:pg-341"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate skin depth \n",
- "f=10**8 #frequency\n",
- "sigma=3*10.0**7 #conductivity of the medium\n",
- "muo=4*math.pi*10**-7 #permeability of free space\n",
- "Del=math.sqrt(2/(2*math.pi*f*sigma*muo))\n",
- "print \"skin depth is Del=\",\"{:.1e}\".format(Del),\"cm\"\n",
- "\n",
- "# answer in book is wrong"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- " skin depth is Del= 9.2e-06 cm\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.12:pg-341"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate frequency \n",
- "muo=4*math.pi*10**-7 #permeability of free space\n",
- "sigma=4.3 # in mhos/m\n",
- "Del=0.1 #skin depth in m\n",
- "f=2/(2*math.pi*muo*Del**2)\n",
- "print \"frequency is f=\",\"{:.2e}\".format(f),\"Hz\"\n",
- "#value of frequency is given incorrect in the book \n",
- "#show that for frequencies less than 10**8 ,it can be considered as good conductor\n",
- "epsilon=80*8.854*10**-12\n",
- "f=10**8 #frequency in Hz\n",
- "sigma=4.3\n",
- "#formula is sigma/(omega*epsilon)>4.3/(2*math.pi*10**8*80*epsilon)\n",
- "sigma1=sigma/(2*math.pi*f*epsilon) #where sigma1=sigma/(omega*epsilon)\n",
- "print \"sigma1=\",round(sigma1,2),\"unitless\"\n",
- "#the ocean water to be good conductor ,the value of sigma/(omega*epsilon) should be greater than 1\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "frequency is f= 2.53e+07 Hz\n",
- "sigma1= 9.66 unitless\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.13:pg-342"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to show that for frequency <10**9 Hz ,a sample of silicon will act like a good conductor\n",
- "sigma=200 #in mhos/m\n",
- "omega=2*math.pi*10**9 \n",
- "epsilon0=8.85*10**-12 #permittivity in free space\n",
- "epsilon=12*epsilon0 \n",
- "sigma1=sigma/(omega*epsilon) #sigma1=sigma/(omega*epsilon)\n",
- "print \"sigma1=\",round(sigma1),\"unitless\"\n",
- "#if sigma/(omega*epsilon) is greater than 1 , silicon is a good conductor at frequency <10**9 Hz\n",
- "#to calculate penetration depth\n",
- "f=10**6 #frequency in Hz\n",
- "muo=4*math.pi*10**-7 #permeability of free space\n",
- "sigma=200\n",
- "Del=math.sqrt(2/(2*math.pi*f*muo*sigma))\n",
- "print \"penetration depth is del=\",round(Del*100,1),\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "sigma1= 300.0 unitless\n",
- "penetration depth is del= 3.6 m\n"
- ]
- }
- ],
- "prompt_number": 25
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex12.14:pg-343"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate conduction current and displacement current densities \n",
- "sigma=10**-3 #conductivity in mhos/m\n",
- "E=4*10**-6 #where E=4*10**-6*math.sin(9*10**9t) v/m\n",
- "J=sigma*E\n",
- "print \"conduction current density is J=\",J,\"math.sin(9*10**9t) A/m\"\n",
- "epsilon0=8.85*10**-12 #permittivity in free space\n",
- "epsilonr=2.45 #relative permittivity\n",
- "#formula is epsilon0*epsilonr*(delE/delt)\n",
- "#delE/delt=4*10**-6*9*10**9*math.cos(9*10**9*t)\n",
- "Jd=epsilon0*epsilonr*4*10**-6*9*10**9\n",
- "print \"displacement current density is Jd=\",round(Jd,8),\"math.cos(9*10**9*t) A/m**2\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "conduction current density is J= 4e-09 math.sin(9*10**9t) A/m\n",
- "displacement current density is Jd= 7.8e-07 math.cos(9*10**9*t) A/m**2\n"
- ]
- }
- ],
- "prompt_number": 23
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/chapter13.ipynb b/Engineering_Physics/chapter13.ipynb
deleted file mode 100755
index 5c4d543b..00000000
--- a/Engineering_Physics/chapter13.ipynb
+++ /dev/null
@@ -1,101 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:54e553aa602b5b46f788e4b29d82727b714210cbc37d72a1b8625b974bd8b58b"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter13:SUPERCONDUCTIVITY"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "\n",
- "Ex13.1:pg-357"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#example 1\n",
- "#to calculate value of Temperature\n",
- "import math\n",
- "Bc=105.0*10**3 #magnetic field in amp/m\n",
- "Bo=150.0*10**3 #critical field of the metal in amp/m \n",
- "Tc=9.2 #critical temperature of the metal in K\n",
- "T=Tc*math.sqrt(1-(Bc/Bo))#temperature\n",
- "print\"\\n the value of temperature is\",round(T,3),\"K\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "\n",
- " the value of temperature is 5.039 K\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex13.2:pg-357"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#example 2\n",
- "#to calculate temperature\n",
- "import math\n",
- "Tc=7.18 #critical temperature in K\n",
- "Bc=4.5*10**3 #critical field in A/m\n",
- "Bo=6.5*10**3 #critical magnetic field in A/m\n",
- "T=Tc*math.sqrt(1-(Bc/Bo))# temperature\n",
- "print\"\\n the temperature is\",round(T,2),\"K\"\n",
- "#to calculate critical current density at that temperature\n",
- "r=1*10**-3 #diameter of the wire in mm\n",
- "TJc=(Bc*2*math.pi*r)/(math.pi*r**2)# critical current density\n",
- "print\"\\n the critical current density at that temperature is\",\"{:.1e}\".format(TJc),\"A/m^2\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "\n",
- " the temperature is 3.98 K\n",
- "\n",
- " the critical current density at that temperature is 9.0e+06 A/m^2\n"
- ]
- }
- ],
- "prompt_number": 2
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/chapter2.ipynb b/Engineering_Physics/chapter2.ipynb
deleted file mode 100755
index 8c10ecf8..00000000
--- a/Engineering_Physics/chapter2.ipynb
+++ /dev/null
@@ -1,1113 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:2b54094513f6b50d68fe3b6c91cd7d7cafc36254b75abea2a0d6c88b266fd509"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter2:INTERFERENCE"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.2:pg-41"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate ratio of intensity\n",
- "#I1/I2=1/25\n",
- "#formula is a1/a2=math.sqrt(I1/I2)=1/5\n",
- "a2=5 #a2=5*a1\n",
- "a1=1\n",
- "I=((1+5)**2)/((1-5)**2)\n",
- "print \"ratio of intensity at the maxima and minima in the interference pattern is Imax/Imin=((a1+a2)**2)/((a1-a2)**2)=\",((a1+a2)**2)/((a1-a2)**2),\"unitless\"\n",
- "#answer is given in terms of ratio\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "ratio of intensity at the maxima and minima in the interference pattern is Imax/Imin=((a1+a2)**2)/((a1-a2)**2)= 2 unitless\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.3:pg-42"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate ratio of intensity at this point to that at the centre of a bright fringe\n",
- "#the intensity at any pont is I=a1**2+a2**2+2*a1*a2*cos del\n",
- "#let a1=a2=a\n",
- "#phase difference del is 0\n",
- "#then I0=a**2+a**2+2*a*a*cos 0\n",
- "#we get I0=4a**2\n",
- "I0=4 #intensity\n",
- "#path difference is lemda/8\n",
- "#phase difference =2*math.pi/lemda*path difference=math.pi/4\n",
- "#I1=a**2+a**2+2a*a*cos math.pi/4\n",
- "#I1=3.414a**2\n",
- "I1=3.414\n",
- "intensity=I1/I0\n",
- "print \" ratio of intensity =\",intensity,\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- " ratio of intensity = 0.8535 unitless\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.4:pg-42"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate ratio of maximum intensity to minimum intensity\n",
- "#formula is I1/I2=a1**2/a2**2=100/1\n",
- "#a1/a2=10/1\n",
- "a1=10 #a1=10*a2\n",
- "a2=1\n",
- "print \"the ratio of maximum intensity to minmum intensity in the interference pattern Imax/Imin=((a1+a2)**2)/((a1-a2)**2)=\",((a1+a2)**2)/((a1-a2)**2),\"unitless\" \n",
- "#answer is given in terms of ratio in the book\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the ratio of maximum intensity to minmum intensity in the interference pattern Imax/Imin=((a1+a2)**2)/((a1-a2)**2)= 1 unitless\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.5:pg-43"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate relative intensities\n",
- "#Imax/Imin=(a1+a2)**2/(a1-a2)**2+105/95\n",
- "#(a1+a2)/(a1-a2)=1.051\n",
- "#we get a1/a2=40 \n",
- "a1=40 #a1=40*a2\n",
- "a2=1\n",
- "print \"the ratio of the intensities of interfering sources is I1/I2=a1**2/a2**2=\",a1**2/a2**2,\"unitless\"\n",
- "#answer is given in terms of ratio in the book\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the ratio of the intensities of interfering sources is I1/I2=a1**2/a2**2= 1600 unitless\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.7:pg-52"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate distance between the two coherent sources\n",
- "lamda=5890*10**-10 #wavelength in m\n",
- "omega=9.424*10**-4 #width of the fringes in m\n",
- "D=.80 #distance in m\n",
- "twod=D*lamda/omega\n",
- "print \"the distance between two coherent sources is twod=\",twod,\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the distance between two coherent sources is twod= 0.0005 m\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.8:pg-53"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate fringe width \n",
- "mu=1.5 #refractive index (unitless)\n",
- "alpha=math.pi/180 #refracting angle in radian\n",
- "Y1=20*10**-2 #distance between the source and the biprism in m\n",
- "Y2=80*10**-2 #distance in m\n",
- "D=Y1+Y2 # distance in m\n",
- "lamda=6900*10**-10 #wavelength in m\n",
- "twod=2*(mu-1)*alpha*Y1 \n",
- "omega=D*lamda/twod\n",
- "print \"the fringe width is omega=\",round(omega,7),\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the fringe width is omega= 0.0001977 m\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.9:pg-53"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength of light\n",
- "omega=(1.888*10**-2)/20 #in (m)\n",
- "D=1.20 #distance of eye piece from the source in m\n",
- "twod=0.00075 #distance between two virtual sources in m\n",
- "lamda=(omega*twod/D)/(10e-11)\n",
- "print \"the wavelength of light is lamda=\",lamda,\"Angstrom\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the wavelength of light is lamda= 5900.0 Angstrom\n"
- ]
- }
- ],
- "prompt_number": 44
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.10:pg-54"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate thickness of glass plate\n",
- "n=3\n",
- "mu=1.5 #refractive index (unitless)\n",
- "lamda=5450*10**-10 #wavelength in m\n",
- "t=n*lamda/(mu-1)\n",
- "print \"the thickness of glass plate is t=\",t,\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the thickness of glass plate is t= 3.27e-06 m\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.11:pg-54"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate refractive index of the sheet\n",
- "t=6.3*10**-6 #thickness of thin sheet of transparent material in m\n",
- "lamda=5460*10**-10 #wavelength in m\n",
- "n=6\n",
- "mu=(n*lamda/t)+1\n",
- "print \"the refractive index of the sheet is mu=\",mu,\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the refractive index of the sheet is mu= 1.52 unitless\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.12:pg-54"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate refractive index of mica\n",
- "t=1.2*10**-8 #thickness of thin sheet of mica in m\n",
- "n=1 \n",
- "lamda=6*10**-7 #wavelength in m\n",
- "mu=(n*lamda/t)+1\n",
- "print \"the refractive index of mica is mu=\",mu,\"unitless\"\n",
- "#answer is given wrong in the book=1.50\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the refractive index of mica is mu= 51.0 unitless\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.13:pg-54"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate intensity\n",
- "mu=1.5 #refractive index(unitless)\n",
- "t=1.5*10**-6 #thickness of thin glass plate in m\n",
- "pathdifference=(mu-1)*t # in m\n",
- "lamda=5*10**-7 #wavelength in m\n",
- "#del=2*math.pi*pathdifference/lamda\n",
- "#del=3*math.pi\n",
- "a1=1\n",
- " #where a1=a2=a\n",
- "a2=1\n",
- "#formula is I=a1**2+a2**2+2*a1*a2*cos del\n",
- "# where cos 3math.pi=-1\n",
- "I=a1**2+a2**2+2*a1*a2*(-1) \n",
- "print \"the intensity at the centre of the screen is I=\",I,\"unitless\" \n",
- "#to calculate lateral shift\n",
- "D=1 #distance in m\n",
- "twod=5*10**-4 #distance between two slits in m\n",
- "mu=1.5 #refractive index (unitless)\n",
- "t=1.5*10**-6 #thickness of thin glass plate in m\n",
- "x0=D*(mu-1)*t/twod\n",
- "print \"the lateral shift of the central maximum is x0=\",x0,\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the intensity at the centre of the screen is I= 0 unitless\n",
- "the lateral shift of the central maximum is x0= 0.0015 m\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.14:pg-55"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate spacing between the slits\n",
- "lamda=6*10**-5 #wavelength in cm\n",
- "omegatheta=0.1*math.pi/180 #angular width of a fringe in radians\n",
- "twod=lamda/omegatheta\n",
- "print \"the spacing between the slits is twod=\",\"{:.2e}\".format(twod),\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the spacing between the slits is twod= 3.44e-02 cm\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.15:pg-55"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate distance of the third bright fringe on the screen from the central maximum \n",
- "lamda=6.5*10**-5 #wavelength in cm\n",
- "twod=0.2 #distance between the slits in cm\n",
- "D=120 #distance between the plane of the slits and the screen in cm\n",
- "n=3 \n",
- "X3=D*n*lamda/twod\n",
- "print \"the distance of the third bright fringe from the central maximum is X3=\",X3,\"cm\"\n",
- "#to calculate the least distance from the central maximum \n",
- "lamda1=6.5*10**-5 #wavelength in cm\n",
- "lamda2=5.2*10**-5 #wavelength in cm\n",
- "#Xn=Dnlamda1/2d=D(n+1)lamda2/2d\n",
- "#we get,\n",
- "n=lamda2/(lamda1-lamda2)\n",
- "print \"n=\",n,\"unitless\"\n",
- "Xn=D*n*lamda1/twod\n",
- "print \"the distance from the central maximum when the bright fringes due to both wavelengths coincide is Xn=\",Xn,\"cm\"\n",
- " \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the distance of the third bright fringe from the central maximum is X3= 0.117 cm\n",
- "n= 4.0 unitless\n",
- "the distance from the central maximum when the bright fringes due to both wavelengths coincide is Xn= 0.156 cm\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.16:pg-56"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate refractive index \n",
- "D=10 #distance in cm\n",
- "twod=0.2 #distance detween the slits in cm\n",
- "t=0.05 #thickness of transparent plate in cm\n",
- "deltaX=0.5 #in cm\n",
- "mu=(deltaX*twod/(D*t))+1\n",
- "print \"the refractive index of the transparent plate is mu=\",mu,\"unitless\"\n",
- "#to calculate order\n",
- "n=10 \n",
- "lamda=7000*10**-8 #wavelength in cm\n",
- "#path difference =n*lamda\n",
- "n1=n*lamda/(5000*10**-8) \n",
- "print \"the order will be visible is n1=\",n1,\"unitless\"\n",
- "#to calculate distance between the two coherent sources\n",
- "D=100 #distance in m \n",
- "lamda=6000*10**-8 #wavelength in cm\n",
- "omega=0.05 #distance between two consecutive bright fringes on the screen in cm\n",
- "twod=D*lamda/omega\n",
- "print \"the distance between the coherent sources is twod=\",twod,\"cm\"\n",
- "#to calculate wavelength\n",
- "Xn=1 #distance of fourth bright fringe from the central fringe in cm\n",
- "twod=0.02 #distance between the two coherent sources in cm\n",
- "n=4 \n",
- "D=100 #distance in cm \n",
- "lamda=Xn*twod/(n*D)\n",
- "print \"the wavelength of light is lamda=\",lamda,\"cm\"\n",
- "#to calculate wavelength\n",
- "#position of nth bright fringe from the centre of the central fringe is Xn=D*n*lamda/2d----eq(1)\n",
- "#fringe width umega=D*lamda/2d---------------------eq(2)\n",
- "#from eq(1) and eq(2) we get, Xn=n*omega\n",
- "#for 11th bright fringe X11=11*omega\n",
- "#position for nth dark fringe Xn'=(2n+1)D*lamda/4d\n",
- "#X4'=(7/2)*omega\n",
- "#distance between 11th and 4th dark fringe =0.8835 cm\n",
- "#we get \n",
- "omega=0.1178 #in cm\n",
- "twod=0.05 #distance between slis in cm\n",
- "D=100 # distance in cm\n",
- "lamda=omega*twod/D \n",
- "print \"the wavelength of light is lamda=\",lamda,\"cm\"\n",
- "#to calculate changed fringe width\n",
- "#X10-X0=10*omega\n",
- "#given that X10-X0=14.73-12.34=2.39mm \n",
- "omega=0.239 #in mm\n",
- "lamda=6000 #wavelength in angstrom\n",
- "lamda1=5000 #lamda'=5000 angstrom\n",
- "omega1=omega*lamda1/lamda\n",
- "print \"the changed fringe width is omega1=\",omega1,\"mm\"\n",
- "#to calculate thickness of mica sheet\n",
- "n=3\n",
- "mu=1.6 #refractive index(unitless)\n",
- "lamda=5.89*10**-5 #wavelength in cm\n",
- "t=n*lamda/(mu-1)\n",
- "print \"the thickness of mica sheet is t=\",t,\"cm\"\n",
- "#answer of thickness is given wrong in the book =0.002945 cm\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the refractive index of the transparent plate is mu= 1.2 unitless\n",
- "the order will be visible is n1= 14.0 unitless\n",
- "the distance between the coherent sources is twod= 0.12 cm\n",
- "the wavelength of light is lamda= 5e-05 cm\n",
- "the wavelength of light is lamda= 5.89e-05 cm\n",
- "the changed fringe width is omega1= 0.199166666667 mm\n",
- "the thickness of mica sheet is t= 0.0002945 cm\n"
- ]
- }
- ],
- "prompt_number": 18
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.17:pg-75"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate the smallest thickness of the plate\n",
- "mu=1.5 #refractive index(unitless)\n",
- "r=60*math.pi/180 #angle of refraction in radians\n",
- "lamda=5890*10**-10 #wavelength in m\n",
- "n=1\n",
- "#formula is t=n*lamda/(2*mu*cosr) where cosr=0.5\n",
- "t=n*lamda/(2*mu*0.5)\n",
- "print \"the smallest thickness of the plate which will appear dark by reflection is t=\",\"{:.3e}\".format(t),\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the smallest thickness of the plate which will appear dark by reflection is t= 3.927e-07 m\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.18:pg-75"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate least thickness of the film\n",
- "lamda=5893*10**-10#wavelength in m\n",
- "r=0 #in degree\n",
- "mu=1.42 #refractive index\n",
- "n=1\n",
- "#the formula is t=n*lamda/(2*mu*cosr), where cos0=1\n",
- "t=n*lamda/(2*mu*1)\n",
- "print \"the least thickness of the film that will appear black is t=\",t,\"m\"\n",
- "t=(2*n-1)*lamda/(2*mu*1*2)\n",
- "print \"the least thickness of the film that will appear bright is t=\",t,\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the least thickness of the film that will appear black is t= 2.075e-07 m\n",
- "the least thickness of the film that will appear bright is t= 1.0375e-07 m\n"
- ]
- }
- ],
- "prompt_number": 20
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.19:pg-76"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate thickness of the film\n",
- "lamda1=6.1*10**-7 #wavelength in m\n",
- "lamda2=6*10**-7 # wavelength in m\n",
- "#the two dark consecutive fringes are overlapping for the wavelength lamda1 and lamda2 respectively\n",
- "#then, n*lamda1=(n+1)*lamda2\n",
- "#we get,\n",
- "n=lamda2/(lamda1-lamda2)\n",
- "sini=4.0/5\n",
- "mu=4.0/3\n",
- "#formula is mu=sini/sinr\n",
- "sinr=0.6\n",
- "cosr=math.sqrt(1-(sinr)**2)\n",
- "t=n*lamda1/(2*mu*cosr)\n",
- "print \"the thickness of the film is t=\",\"{:.2e}\".format(t),\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the thickness of the film is t= 1.72e-05 m\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.20:pg-77"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate thickness of the film\n",
- "mu=1.33 #refractive index of soap film (unitless)\n",
- "i=45*math.pi/180\n",
- "#the formula is mu=sini/sinr \n",
- "sinr=0.5317 \n",
- "cosr=math.sqrt(1-(sinr)**2)\n",
- "#for destructive interference\n",
- "lamda=5890*10**-10 #wavelength in m\n",
- "n=1\n",
- "t=n*lamda/(2*mu*cosr)\n",
- "print \"the thickness of the film is t=\",\"{:.3e}\".format(t),\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the thickness of the film is t= 2.614e-07 m\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.21:pg-77"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate angle of the wedge\n",
- "lamda=6000*10**-10 #wavelength in m\n",
- "mu=1.4 #refractive index in unitless\n",
- "omega=2*10.0**-3 #distance in m\n",
- "theta=lamda/(2*mu*omega)\n",
- "print \"the angle of the wedge is theta =\",\"{:.2e}\".format(theta),\"radians\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the angle of the wedge is theta = 1.07e-04 radians\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.22:pg-77"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength of light \n",
- "theta=10*22.0/(7*60*60*180.0) #angle of wedge in radians\n",
- "omega=5*10.0**-2 #distance between the successive fringes in m\n",
- "mu=1.4 #refractive index\n",
- "lamda=2.0*mu*theta*omega/(10e-10)\n",
- "print \"the wavelength of light is lamda=\",round(lamda),\"Angstrom\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the wavelength of light is lamda= 6790.0 Angstrom\n"
- ]
- }
- ],
- "prompt_number": 23
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.23:pg-78"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength of the light\n",
- "D15=0.590*10**-2 #diamater of 15th ring in m\n",
- "D5=0.336*10**-2 #diameter of 5th ring in m\n",
- "p=1 # in m\n",
- "R=1 #radius of plano convex lens in m\n",
- "#formula is lamda=Dn+p**2-Dn**2/4pR\n",
- "lamda=((D15**2)-(D5**2))/(4*p*R)/(10e-10)\n",
- "print \"the wavelength of the monochromatic light is lamda=\",int(lamda),\"Angstrom\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the wavelength of the monochromatic light is lamda= 5880 Angstrom\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.24:pg-78"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate refractive index of the liquid\n",
- "n=6\n",
- "lamda=6000*10**-10 #wavelength in m\n",
- "R=1 #radius of curvature of the curved surface in m\n",
- "Dn=3.1*10**-3 #diameter of 6th bright ring in m\n",
- "mu=2*(2*n-1)*lamda*R/Dn**2\n",
- "print \"the refractive index of the liquid is mu=\",round(mu,3),\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the refractive index of the liquid is mu= 1.374 unitless\n"
- ]
- }
- ],
- "prompt_number": 28
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.25:pg-78"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate radius of curvature\n",
- "lamda=5900*10**-10 #wavelength in m\n",
- "n=10\n",
- "Dn=5*10**-3 # diameter of 10th dark ring in m\n",
- "R=Dn**2/(4*n*lamda)\n",
- "print \"the radius of curvature of the lens is R=\",round(R,3),\"m\"\n",
- "#to calculate thichness\n",
- "t=n*lamda/2\n",
- "print \"the thickness of the air film is t=\",t,\"m\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the radius of curvature of the lens is R= 1.059 m\n",
- "the thickness of the air film is t= 2.95e-06 m\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.26:pg-79"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate the distance from the apex of the wedge at which the maximum due to the two wavelengths first coincide\n",
- "#condition for maxima for normal incidence air film is 2t=(2n+1)lamda/2\n",
- "#let nth order maximum due to lamda1 coincides with (n+1)th order maximum due to lamda2 \n",
- "#we get , n=(3lamda2-lamda1)/2(lamda1-lamda2)\n",
- "# we also get, 2t=lamda1*lamda2/(lamda1-lamda2)\n",
- "#t=X*theta\n",
- "lamda1=5896.0*10**-8 #wavelength in cm\n",
- "lamda2=5890.0*10**-8 #wavelength in cm\n",
- "theta=0.3*math.pi/180 #angle of wedge\n",
- "X=lamda1*lamda2/(2*(lamda1-lamda2)*theta)\n",
- "print \"the distance from the apex of the wedge is X=\",round(X,3),\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the distance from the apex of the wedge is X= 5.527 cm\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.27:pg-80"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate radius of curvature \n",
- "n=10.0\n",
- "Dn=0.50 #diameter of 10th ring in cm\n",
- "lamda=6000*10**-8 #wavelength in cm\n",
- "R=Dn**2/(4*n*lamda)\n",
- "print \"the radius of curvature of the lens is R=\",R,\"cm\"\n",
- "#answer is given wrong in the book =106 cm\n",
- "#to calculate thickness of the film\n",
- "t=Dn**2/(8*R)\n",
- "print \"the thickness of the film is t=\",\"{:.1e}\".format(t),\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the radius of curvature of the lens is R= 104.166666667 cm\n",
- "the thickness of the film is t= 3.0e-04 cm\n"
- ]
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.28:pg-80"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate diameter\n",
- "#the difference of (n+p)th and nth dark ring is Dn+p**2-Dn**2=4nRlamda\n",
- "N=12 #where N=n+p\n",
- "n=4\n",
- "D12=0.7 #diameter of 12th dark ring in cm\n",
- "D4=0.4 #diameter of 4th dark ring in cm\n",
- "#D12**2-D4**2=4pRlamda where p=8 ----eq(1)\n",
- "#D20**2-D4**2=4pRlamda where p=16 -----eq(2)\n",
- "#divide eq(2) by eq(1) ,we get\n",
- "D20=math.sqrt((2*D12**2)-D4**2)\n",
- "print \"the diameter of 20th dark ring is D20=\",round(D20,2),\"cm\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the diameter of 20th dark ring is D20= 0.91 cm\n"
- ]
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.29:pg-80"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate diameter \n",
- "lamda1=6*10**-5 #wavelength in cm\n",
- "lamda2=4.5*10**-5 #wavelength in cm\n",
- "R=90 #radius of curvature of the curved surface in cm\n",
- "#Dn**2=4nRlamda1 -------eq(1)\n",
- "#Dn+1**2=4(n+1)Rlamda2-------eq(2)\n",
- "#the nth dark ring due to lamda1 coincides with (n+1)th dark ring due to lamda2\n",
- "#from eq(1) and eq(2)-4nRlamda1=4(n+1)Rlamda2\n",
- "# we get,\n",
- "n=lamda2/(lamda1-lamda2)\n",
- "Dn=math.sqrt(4*n*R*lamda1)\n",
- "print \"the diameter of nth dark ring for lamda1 is Dn=\",round(Dn,3),\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the diameter of nth dark ring for lamda1 is Dn= 0.255 cm\n"
- ]
- }
- ],
- "prompt_number": 22
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex2.30:pg-81"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate the difference of square of diameters for nth and (n+p)th ring when light of wavelength lamda is changed to lamda'\n",
- "lamda=6*10**-5 #wavelength in cm\n",
- "lamda1=4.5*10**-5 #wavelength in cm\n",
- "#Let D=(D**2-Dn**2)=0.125 cm**2 \n",
- "D=0.125\n",
- "#formula is D'(n+p)**2-D'n**2=lamda'*(D(n+p)**2-Dn**2)/lamda\n",
- "print \"the difference of square of diameters is D1(n+p)**2-D1n**2=(lamda1*D)/lamda=\",(lamda1*D)/lamda,\"cm**2\"\n",
- "#to calculate difference of square of diamaters when liqquid of refractive index mu' is introduced\n",
- "mu=1 #refractive index (unitless)\n",
- "mu1=1.33 # mu'=1.33\n",
- "#formula is D'(n+p)**2-D'n**2=(mu/mu')*(D(n+p)**2-Dn**2)\n",
- "print \"the difference of square of diameters is D1(n+p)**2-D1n**2=(mu*D)/mu1=\",round((mu*D)/mu1,3),\"cm**2\"\n",
- "#to calculate difference of square of diameters when radius of curvature of convex surface of the plano convex lens is doubled\n",
- "R1=2 #radius of curvature is R'=2R\n",
- "R=1\n",
- "#formula is D'(n+p)**2-D'n**2=(R'/R)*(D(n+p)**2-Dn**2)\n",
- "print \"the difference of square of diameters is D1(n+p)**2-D1n**2=(R1*D)/R=\",round((R1*D)/R,2),\"cm**2\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the difference of square of diameters is D1(n+p)**2-D1n**2=(lamda1*D)/lamda= 0.09375 cm**2\n",
- "the difference of square of diameters is D1(n+p)**2-D1n**2=(mu*D)/mu1= 0.094 cm**2\n",
- "the difference of square of diameters is D1(n+p)**2-D1n**2=(R1*D)/R= 0.25 cm**2\n"
- ]
- }
- ],
- "prompt_number": 27
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/chapter3.ipynb b/Engineering_Physics/chapter3.ipynb
deleted file mode 100755
index 1c763114..00000000
--- a/Engineering_Physics/chapter3.ipynb
+++ /dev/null
@@ -1,1365 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:f8c5b92f0cb0a1787021af8dd46e58ab42d75991e4d7ba39c4a4693a16608b3e"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter3:DIFFRACTION"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.1:pg-97"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate angular width and linear width \n",
- "lamda=6*10**-5\n",
- "e=0.01 #width of slit in cm\n",
- "#position of minima is given by\n",
- "sintheta=lamda/e #sintheta=m*lamda/e ,where m=1,2,3,......\n",
- "print \"sintheta=\",sintheta,\" m\"\n",
- "#since theta is very small,so sintheta is approximately equal to theta\n",
- "theta=sintheta\n",
- "theta1=2*theta\n",
- "print \"total angular width of central maximum is theta1=\",theta1,\" m radians \"\n",
- "d=100 #distance in cm\n",
- "Y=theta*d\n",
- "Y1=2*Y\n",
- "print \"linear width of central maximum on the screen is Y1=\",Y1,\" m cm\"\n",
- "print \"values of m =1,2,3,............ gives the directions of first, second .............minima\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "sintheta= 0.006 m\n",
- "total angular width of central maximum is theta1= 0.012 m radians \n",
- "linear width of central maximum on the screen is Y1= 1.2 m cm\n",
- "values of m =1,2,3,............ gives the directions of first, second .............minima\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.2:pg-97"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength of light\n",
- "#in a diffraction pattern due to single slit, minima is given by e*sintheta=m*lamda\n",
- "#since theta is very small, sintheta is approximately equal to theta\n",
- "#theta=Y/d\n",
- "e=0.014 #width of slit in cm\n",
- "d=200 #distance in cm\n",
- "m=2 \n",
- "Y=1.6 #in cm\n",
- "lamda=Y*e/(d*m)\n",
- "print \"wavelength of light is lamda=\",lamda,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "wavelength of light is lamda= 5.6e-05 cm\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.3:pg-98"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate width of slit\n",
- "#direction of minima in fraunhofer diffraction due to single slit is given by math.pi/lamda*e*siuntheta=+m*math.pi,where m=1,2,3\n",
- "#angular spread of the central maximum on either side of the incident light is sintheta=lamda/e,where m=1,position of first minima\n",
- "lamda=5000*10**-8\n",
- "e=lamda/math.sin(math.pi/6)\n",
- "print \"width of slit is e=\",e,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "width of slit is e= 0.0001 cm\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.4:pg-98"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength of incident light\n",
- "#direction of minima is given by e*sintheta=+m*lamda\n",
- "#for first minima m=1,i.e. e*sintheta=lamda,sintheta is approximately equal to theta,then we can write it as e*theta=lamda ...........eq(1)\n",
- "#theta=Y/d........................eq(2) \n",
- "e=0.02 #in cm\n",
- "Y=0.5 #position of first minima from the central maxima in cm\n",
- "d=200 #distance of screen from the slit in cm\n",
- "#from eq(1) and eq(2),we get\n",
- "lamda=e*Y/d\n",
- "print \"wavelength of incident light is lamda=\",lamda,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "wavelength of incident light is lamda= 5e-05 cm\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.6:pg-99"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate values of lamda1 and lamda2\n",
- "#in fraunhofer diffraction pattern ,the direction of minima is given by e*sintheta=+m*lamda,where m=1,2,.......\n",
- "#direction of fourth minima (m=4) for wavelength lamda1 is given by e*sintheta1=4*lamda1..........eq(1)\n",
- "#similarly, e*sintheta2=5*lamda2..........eq(2)\n",
- "#from eq(1) and eq(2),we get e*sintheta=4*lamda1=5*lamda2....eq(3)\n",
- "y=0.5 #in cm\n",
- "f=100 #in cm\n",
- "theta=y/f #in radian\n",
- "sintheta=theta #theta is very small\n",
- "e=0.05 #width of slit in cm\n",
- "lamda1=e*sintheta/4\n",
- "print \"lamda1=\",lamda1,\"cm\"\n",
- "#from eq(3) we get,\n",
- "lamda2=4*lamda1/5\n",
- "print \"lamda2=\",lamda2,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "lamda1= 6.25e-05 cm\n",
- "lamda2= 5e-05 cm\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.7:pg-100"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate half angular width \n",
- "e=1.2*10**-4 #width of slit in cm\n",
- "y=6*10**-5 #wavelength of monochromatic light in cm\n",
- "theta=y/e\n",
- "print \"half angular width of central bright maxima is theta=\",theta,\"radian\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "half angular width of central bright maxima is theta= 0.5 radian\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.8:pg-100"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate angle\n",
- "lamda=6000.0*10**-8 #wavelength of light in cm\n",
- "e=0.03 #width of slit in cm\n",
- "#e*sintheta=m*lamda,where m=1\n",
- "theta=math.degrees(math.asin(lamda/e)) \n",
- "print \"angle at which the first dark band are formed in the fraunhofer diffraction pattern is theta=\",round(theta,4),\"degree\"\n",
- "theta1=math.degrees(math.sin(3*lamda/(2*e)))\n",
- "print \"angle at which the next bright band are formed in the fraunhofer diffraction pattern is theta1=\",round(theta1,4),\"degree\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "angle at which the first dark band are formed in the fraunhofer diffraction pattern is theta= 0.1146 degree\n",
- "angle at which the next bright band are formed in the fraunhofer diffraction pattern is theta1= 0.1719 degree\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.9:pg-101"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate distances of first dark band and of next bright band on either side of the central maximum\n",
- "#formula is e*sintheta=m*lamda,where m=1\n",
- "lamda=5890.0*10**-8 #wavelength of light in cm\n",
- "e=0.03 #width of slit in cm\n",
- "sintheta=lamda/e \n",
- "theta=sintheta #becoz theta is very small,so sintheta is approximately equal to theta\n",
- "f=50.0\n",
- "y=f*theta\n",
- "print \"linear distance of first minimum from the central maximum is y=\",y,\"cm\"\n",
- "sintheta1=3*lamda/(2*e)\n",
- "theta1=sintheta1\n",
- "y1=f*theta1\n",
- "print \"linear distance of first secondary maxima is y1=\",y1,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "linear distance of first minimum from the central maximum is y= 0.0981666666667 cm\n",
- "linear distance of first secondary maxima is y1= 0.14725 cm\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.10:pg-105"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength of light and missing orders\n",
- "omega=0.25 #fringe width in cm\n",
- "D=170 #distance in cm\n",
- "twod=0.04 # distance in cm\n",
- "lamda=omega*twod/D\n",
- "print \"wavelength of light is lamda=\",lamda,\"cm\"\n",
- "e=0.08 #width of slit in mm\n",
- "d=0.4 #in mm\n",
- "m=1\n",
- "n=m*(e+d)/e \n",
- "print \"missing order is n=\",n,\"unitless\"\n",
- "#we can also find order for m=2,3,....\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "wavelength of light is lamda= 5.88235294118e-05 cm\n",
- "missing order is n= 6.0 unitless\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.11:pg-112"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength\n",
- "n=2.0 #order of spectrum\n",
- "theta=math.pi/6 #in radians\n",
- "E=1.0/5000 #let (e+d)=E\n",
- "lamda=E*math.sin(math.pi/6)/n\n",
- "print \"the wavelength of the spectral line is lamda=\",lamda,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the wavelength of the spectral line is lamda= 5e-05 cm\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.12:pg-112"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate difference in deviations \n",
- "lamda=5*10**-5 #wavelength of light in cm\n",
- "eplusd=1/6000.0 #where eplusd=e+d\n",
- "theta1=math.degrees(math.asin(lamda/eplusd)) #for first order spectrum\n",
- "theta3=math.degrees(math.asin(3*lamda/eplusd)) #for second order spectrum\n",
- "difference=theta3-theta1\n",
- "print \"difference in deviations in first and third order spectra is difference =\",round(difference,1),\"degree\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "difference in deviations in first and third order spectra is difference = 46.7 degree\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.13:pg-112"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate orders\n",
- "#let E=(e+d) \n",
- "#formula is (e+d)*sin thita=n*lamda\n",
- "#for maximum order to be possible thita=90 degree\n",
- "#sin theta=1\n",
- "E=2.54/2620 #in cm\n",
- "lamda=5*10**-5 #wavelength of the incident light in cm\n",
- "n=E/lamda\n",
- "print \"the orders will be visible is n=\",n,\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the orders will be visible is n= 19.3893129771 unitless\n"
- ]
- }
- ],
- "prompt_number": 18
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.14:pg-113"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate number of lines in the grating\n",
- "#theta1=theta2=30 degree\n",
- "#sin theta1=sin theta2=1/2\n",
- "lamda1=6*10**-5 \n",
- " #wavelength in cm\n",
- "lamda2=4.5*10**-5\n",
- "#let (e+d)=E \n",
- "#formula is (e+d)*sin theta1=n*lamda1----------eq(1)\n",
- "#(e+d)*sin theta2=(n+1)*lamda2----------eq(2)\n",
- "#we get,\n",
- "n=lamda2/(lamda1-lamda2) #order of spectrum\n",
- "E=n*lamda1/math.sin(math.pi/6)\n",
- "number=1/E\n",
- "print \"number of lines is number=\",number,\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "number of lines is number= 2777.77777778 unitless\n"
- ]
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.15:pg-113"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate order when visible light of wavelength in the range 4000 to 7500 angstrom\n",
- "#let E=(e+d)\n",
- "E=1.0/4000 #in cm\n",
- "lamda1=4*10**-5 \n",
- " #wavelength in cm\n",
- "lamda2=7.5*10**-5\n",
- "n1=E*math.sin(math.pi/2)/lamda1\n",
- "n2=E*math.sin(math.pi/2)/lamda2\n",
- "print \"order when wavelength of 4000 angstrom is n1=\",n1,\"unitless\"\n",
- "print \"order when wavelength of 7500 angstrom is n2=\",n2,\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "order when wavelength of 4000 angstrom is n1= 6.25 unitless\n",
- "order when wavelength of 7500 angstrom is n2= 3.33333333333 unitless\n"
- ]
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.17:pg-114"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate angle of diffraction \n",
- "n=1 #order\n",
- "lamda=5000*10**-8 #wavelength of light in cm\n",
- "eplusd=1/5000.0 # in cm\n",
- "theta=math.degrees(math.asin(n*lamda/(eplusd)))\n",
- "minu=(theta-int(theta))*60 # minute\n",
- "print \"angle of diffraction for maximum intensity in the first order is theta=\",int(theta),\"degree\",round(minu),\"minutes\" \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "angle of diffraction for maximum intensity in the first order is theta= 14 degree 29.0 minutes\n"
- ]
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.18:pg-115"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate number of lines in one centimeter of the grating\n",
- "#let E=(e+d)\n",
- "#formula for grating equation for principal maxima is (e+d)*sin theta=n*lamda\n",
- "n=2 #order of spectrum\n",
- "lamda=5*10**-5 #wavelength in cm\n",
- "E=n*lamda/math.sin(math.pi/6)\n",
- "number=1/E\n",
- "print \"number of lines is number=\",number,\"unitless\"\n",
- "#answer is given wrong in the book ,number of lines=1000\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "number of lines is number= 5000.0 unitless\n"
- ]
- }
- ],
- "prompt_number": 23
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.19:pg-115"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate which spectral line in 5th order will overlap with 4th order line of 5890 angstrom\n",
- "#the grating equation for principal maxima is (e+d)*sin theta =n*lamda\n",
- "n1=5 \n",
- " #order of spectrum \n",
- "n2=4\n",
- "lamda2=5890*10**-8 #wavelength of 4th order spectrum in cm\n",
- "#(e+d)*sin theta=5*lamda-------------eq(1)\n",
- "#(e+d)*sin theta=4*5890*10**-8-----------------eq(2)\n",
- "#from eq(1) and eq(2) ,we get\n",
- "lamda1=n2*lamda2/n1\n",
- "print \"wavelength of 5th order spectrum is lamda1=\",lamda1,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "wavelength of 5th order spectrum is lamda1= 4.712e-05 cm\n"
- ]
- }
- ],
- "prompt_number": 24
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.20:pg-115"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate grating element\n",
- "#grating equation for principal maxima is given by (e+d)*sintheta=n*lamda\n",
- "#let nth order spectrum for yellow line (lamda=6000 angstrom) coincide with (n+1)th order spectrum for blue line (lamda=4800 angstrom) \n",
- "#(e+d)*sintheta=n*6000*10**-8..eq(1)\n",
- "#(e+d)*sintheta=(n+1)*4800*10**-8.....eq(2)\n",
- "#from eq(1) and eq(2),we get n=4\n",
- "n=4\n",
- "lamda=6000*10**-8 #wavelength in cm\n",
- "sintheta=3.0/4 \n",
- "eplusd=n*lamda/sintheta\n",
- "print \"grating element is eplusd=\",eplusd,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "grating element is eplusd= 0.00032 cm\n"
- ]
- }
- ],
- "prompt_number": 26
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.21:pg-116"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate angle of diffraction for third order spectrum and absent spectra if any\n",
- "n=3\n",
- "lamda=6000*10**-8\n",
- "eplusd=1/200.0\n",
- "theta=math.degrees(math.asin(n*lamda/eplusd))\n",
- "minu=(theta-int(theta))*60 # minute\n",
- "print \"angle of refraction is theta=\",int(theta),\"degree\",round(minu),\"minutes\"\n",
- "d=0.0025\n",
- "e=eplusd-d #width of wire in cm\n",
- "m=1\n",
- "n=eplusd*m/e\n",
- "print \"order of absent spectrum is n=\",n,\"unitless\"\n",
- "print \"here,m=1 is considered because the higher values of m result the order of absent spectrum more than the given order 3\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "angle of refraction is theta= 2 degree 4.0 minutes\n",
- "order of absent spectrum is n= 2.0 unitless\n",
- "here,m=1 is considered because the higher values of m result the order of absent spectrum more than the given order 3\n"
- ]
- }
- ],
- "prompt_number": 24
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.22:pg-116"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate difference in the two wavelengths\n",
- "#grating equation for principal maxima is (e+d)*sintheta=n*lamda...............eq(1)\n",
- "#differentiate both sides ,we get dtheta=n*dlamda/((e+d)*costheta)...........eq(2)\n",
- "lamda=5000 #mean value of wavelengths in angstrom\n",
- "cottheta=1.732 #cot30degree=1.732\n",
- "dtheta=0.01 #in radian\n",
- "#put the value of n from eq(2),we can write eq(2) \n",
- "dlamda=lamda*dtheta*cottheta\n",
- "print \"difference in two wavelengths is dlamda=\",dlamda,\"angstrom\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "difference in two wavelengths is dlamda= 86.6 angstrom\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.23:pg-117"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate dispersive power \n",
- "#differentiate grating equation ,we get dtheta/dlamda=n/((e+d)*costheta)\n",
- "n=2 #order \n",
- "eplusd=1/4000.0\n",
- "lamda=5000.0*10**-8 #wavelength in cm\n",
- "sintheta=n*lamda/(eplusd)\n",
- "costheta=math.sqrt(1-(sintheta)**2)\n",
- "dtheta=n/((eplusd)*costheta) #where dispersive power dtheta/dlamda=dtheta\n",
- "print \"dispersive power of grating in the second order spectrum is dtheta=\",int(dtheta),\"unitless\"\n",
- "\n",
- "# answer is slightly different due to approximation\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "dispersive power of grating in the second order spectrum is dtheta= 8728 unitless\n"
- ]
- }
- ],
- "prompt_number": 27
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.24:pg-117"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate orders\n",
- "eplusd=1/4000.0\n",
- "lamda1=5*10.0**-5 #wavelengh in cm\n",
- "lamda2=7.5*10**-5\n",
- "nmax1=eplusd/lamda1\n",
- "nmax2=eplusd/lamda2\n",
- "print \"orders will be observed by a grating ,if it is illuminated by light of wavelength of 5000 angstrom is nmax1=\",nmax1,\"unitless \"\n",
- "print \"orders will be observed ,if it is illuminated by light of wavelength of 7500 angstrom is nmax2=\",round(nmax2,1),\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "orders will be observed by a grating ,if it is illuminated by light of wavelength of 5000 angstrom is nmax1= 5.0 unitless \n",
- "orders will be observed ,if it is illuminated by light of wavelength of 7500 angstrom is nmax2= 3.3 unitless\n"
- ]
- }
- ],
- "prompt_number": 30
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.25:pg-118"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate difference in wavelengths of two lines\n",
- "#let E=(e+d)=1/5000\n",
- "#we get\n",
- "E=2*10**-4 #in cm\n",
- "n=2 #order of spectrum\n",
- "lamda=5893*10**-8 #wavelength in cm\n",
- "#dtheta=2.5'=(2.5/60)*(3.14/180),we get\n",
- "dtheta=7.27*10**-4 #in radian\n",
- "dlamda=math.sqrt(((E/n)**2)-lamda**2)*dtheta\n",
- "print \"the difference in wavelengths of two lines is dlamda=\",dlamda,\"cm\" \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the difference in wavelengths of two lines is dlamda= 5.87353693335e-08 cm\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.26:pg-123"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate aperture of the objective of a telescope\n",
- "lamda=6*10**-5 #wavelength of light in cm\n",
- "dtheta=4.88*10**-6 # in radians\n",
- "a=1.22*lamda/dtheta\n",
- "print \"the aperture of the objective of a telescope is a=\",a,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the aperture of the objective of a telescope is a= 15.0 cm\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.27:pg-123"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate separation of two points on the moon\n",
- "lamda=5.5*10**-5 #wavelength of light in cm\n",
- "a=500 #diameter in cm\n",
- "dtheta=1.22*lamda/a #limit of resolution of telescope in radians\n",
- "R=3.8*10**8 #distance between earth and moon in m\n",
- "X=R*dtheta\n",
- "print \"the separation of two points on the moon is X=\",X,\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the separation of two points on the moon is X= 50.996 m\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.28:pg-124"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate numerical aperture of the objective\n",
- "lamda=5.461*10**-5 #wavelength in cm\n",
- "S=5.55*10**-5 #distance in cm\n",
- "NA=1.22*lamda/(2*S)\n",
- "print \"the numerical aperture of the objective is NA=\",NA,\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the numerical aperture of the objective is NA= 0.600218018018 unitless\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.29:pg-124"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate resolving power of microscope\n",
- "NA=0.12 #numerical aperture\n",
- "lamda=6*10**-5 #wavelength of light in cm\n",
- "RP=2*NA/lamda #RP=resolving power\n",
- "print \"the resolving power of microscope is RP=\",RP,\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the resolving power of microscope is RP= 4000.0 unitless\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.30:pg-124"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate maximum resolving power\n",
- "lamda=5*10**-5 #wavelength of light in cm\n",
- "N=40000 #total number of lines on grating\n",
- "#(e+d)=12.5*10**-5 cm\n",
- "#formula is nmax=(e+d)/lamda\n",
- "#we get\n",
- "nmax=2 #order of spectrum\n",
- "RP=nmax*N #RP=resolving power\n",
- "print \"the maximum resolving power is RP=\",RP,\"unitless\" \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the maximum resolving power is RP= 80000 unitless\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.31:pg-124"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate minimum number of lines in a grating\n",
- "lamda1=5890 \n",
- " #wavelengh in angstrom\n",
- "lamda2=5896\n",
- "dlamda=6 #smallest wavelength difference in angstrom\n",
- "n=2 #order of spectrum \n",
- "lamda=(lamda1+lamda2)/2 #average wavelength in angstrom\n",
- "RP=lamda/dlamda #RP=resolving power\n",
- "N=RP/n\n",
- "print \"minimum number of lines in a grating is N=\",N,\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "minimum number of lines in a grating is N= 491 unitless\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.32:pg-125"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#will the telescope be able to observe the wiremesh\n",
- "a=3 #aperture in cm\n",
- "lamda=5.5*10**-5 #wavelength of light in cm\n",
- "#limit of resolution of telescope is given by\n",
- "theta=1.22*lamda/a\n",
- "#alpha=spacing of wire-mesh/distance of objective from wire-mesh\n",
- "alpha=0.2/(80*10**2)\n",
- "print \"theta=\",theta,\"radian\"\n",
- "print \"alpha=\",alpha,\"radian\"\n",
- "print \"if alpha>theta then telescope will be able to observe the wire-mesh\"\n",
- "#value of alpha is given wrong in the book 2.25*10**-5 radian\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "theta= 2.23666666667e-05 radian\n",
- "alpha= 2.5e-05 radian\n",
- "if alpha>theta then telescope will be able to observe the wire-mesh\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.33:pg-125"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#distance between the centres of images of two stars\n",
- "lamda=5500*10**-8 #wavelength of light in cm\n",
- "f=4*10**2 #focal length of telescope objective in cm\n",
- "a=0.01*10**2 #diameter in cm\n",
- "X=1.22*lamda*f/a\n",
- "print \"distance between the centres of images of two stars is X=\",X,\"cm \"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "distance between the centres of images of two stars is X= 0.02684 cm \n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.34:pg-126"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate diameter of a telescope \n",
- "lamda=5.0*10**-5 #wavelength in cm\n",
- "theta=(math.pi/180)*(1.0/1000) #in radians\n",
- "a=1.22*lamda/theta\n",
- "print \"the diameter of a telescope is a=\",a,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the diameter of a telescope is a= 3.4950425503 cm\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.35:pg-126"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate smallest angle between two stars\n",
- "lamda=5*10**-5 #wavelength in cm\n",
- "a=100*2.54 #diameter in cm\n",
- "theta=1.22*lamda/a\n",
- "print \"the smallest angle between two stars is thita=\",theta,\"radians\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the smallest angle between two stars is thita= 2.40157480315e-07 radians\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.36:pg-126"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate limit of resolution of the telescope\n",
- "lamda=5890*10**-8 #wavelength in cm\n",
- "a=1 #diameter in cm\n",
- "theta=1.22*lamda/a\n",
- "print \"the limit of resolution of the telescope is theta=\",theta,\"radians \"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the limit of resolution of the telescope is theta= 7.1858e-05 radians \n"
- ]
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.37:pg-126"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate resolving limit of microscope\n",
- "lamda=5.5*10**-5 #wavelengh in cm\n",
- "theta=math.pi/6 #in radians\n",
- "s=1.22*lamda/(2*math.sin(math.pi/6))\n",
- "print \"resolving limit of microscope is s=\",s,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "resolving limit of microscope is s= 6.71e-05 cm\n"
- ]
- }
- ],
- "prompt_number": 20
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.38:pg-127"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate resolving power of grating \n",
- "N=15000 #total number of lines on grating\n",
- "lamda=6*10**-5 #wavelength in cm\n",
- "n=2 #order of spectrum\n",
- "RP=n*N\n",
- "print \"resolving power is RP =\",RP,\"unitless\"\n",
- "#to calculate smallest wavelength difference that can be resolved with a light of wavelength 6000angstrom in the second order\n",
- "dlamda=lamda/(n*N)\n",
- "print \"smallest wavelength difference dlamda=\",dlamda,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "resolving power is RP = 30000 unitless\n",
- "smallest wavelength difference dlamda= 2e-09 cm\n"
- ]
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex3.39:pg-127"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate resolving power in the second order\n",
- "N=6*10**4 #N=total number of lines on grating\n",
- "n=2 #order of spectrum\n",
- "RP=n*N #RP=resoling power\n",
- "print \"the resolving power is RP=\",RP,\"unitless\"\n",
- "#to calculate smallest wavelength\n",
- "lamda=6000*10**-8 #wavelength in cm\n",
- "n=3 #order of spectrum\n",
- "dlamda=lamda/(n*N)\n",
- "print \"smallest wavelength that can be resolved in the third order in 6000angstrom wavelength region is dlamda=\",dlamda,\"cm\" \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the resolving power is RP= 120000 unitless\n",
- "smallest wavelength that can be resolved in the third order in 6000angstrom wavelength region is dlamda= 3.33333333333e-10 cm\n"
- ]
- }
- ],
- "prompt_number": 18
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/chapter4.ipynb b/Engineering_Physics/chapter4.ipynb
deleted file mode 100755
index 3e350b0f..00000000
--- a/Engineering_Physics/chapter4.ipynb
+++ /dev/null
@@ -1,541 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:7c369c2593aa95d4aac8153f9063553bb327aa743223d1fff41c98aa45d77ebe"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter4:POLARISATION"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.1:pg-147"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "# compare the intensities of ordinary and extraordinary rays\n",
- "#intensity of ordinary rays is given by Io=a**2 *(sin theta)**2\n",
- "#where theta=30 degree\n",
- "#we get Io=a**2/4\n",
- "Io=1.0/4\n",
- "#intensity of extraordinary ray is given by IE=(a*cos theta)**2\n",
- "#we get IE=3*a**2/4\n",
- "IE=3.0/4\n",
- "I=IE/Io\n",
- "print \"the intensities of ordinary and extraordinary rays is I=\",I,\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the intensities of ordinary and extraordinary rays is I= 3.0 unitless\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.2:pg-147"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate angle of refraction\n",
- "#according to brewster's law mu=tan ip\n",
- "mu=1.732 #refractive index\n",
- "ip=math.degrees(math.atan(mu)) #polarising angle in degree\n",
- "r=90-ip\n",
- "print \"angle of refraction of ray is r=\",round(r),\"degree\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "angle of refraction of ray is r= 30.0 degree\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.3:pg-147"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate polarising angle and angle of refraction\n",
- "mu=1.345 #refractive index, mu=1/sinc=1/sin48degree=1/0.7431 \n",
- "ip=math.degrees(math.atan(mu))\n",
- "r=90-ip\n",
- "print \"polarising angle is ip=\",round(ip,3),\"degree\"\n",
- "print \"angle of refraction is r=\",round(r,3),\"degree\" \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "polarising angle is ip= 53.369 degree\n",
- "angle of refraction is r= 36.631 degree\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.4:pg-147"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate thickness of a half wave plate of quartz\n",
- "lamda=5*10**-5 #wavelength in cm\n",
- "mue=1.553 \n",
- " #refractive index (unitless)\n",
- "muo=1.544\n",
- "#for a half plate of positive crystal\n",
- "t=lamda/(2*(mue-muo))\n",
- "print \"thickness of a half wave plate of quartz is t=\",\"{:.2e}\".format(t),\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "thickness of a half wave plate of quartz is t= 2.78e-03 cm\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.5:pg-148"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate thickness of quarter wave plate\n",
- "lamda=5.890*10**-5 #wavelength of light in cm\n",
- "mue=1.553\n",
- " #refractive index\n",
- "muo=1.544\n",
- "t=lamda/(4*(mue-muo)) \n",
- "print \"thickness of quarter wave plate is t=\",\"{:.3e}\".format(t),\"cm\" \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "thickness of quarter wave plate is t= 1.636e-03 cm\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.6:pg-148"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate thickness of a doubly refracting plate\n",
- "lamda=5.890*10**-5 #wavelength in cm\n",
- "muo=1.53 \n",
- " #refractive index\n",
- "mue=1.54\n",
- "t=lamda/(4*(mue-muo))\n",
- "print \"thickness of a plate is t=\",\"{:.2e}\".format(t),\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "thickness of a plate is t= 1.47e-03 cm\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.7:pg-152"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate angle of rotation\n",
- "alpha=66 #specific rotation of cane sugar in degree\n",
- "c=15.0/100 #concentration of the solution in gm/cc\n",
- "l=20 #length of tube in cm\n",
- "theta=alpha*l*c/10\n",
- "print \"the angle of rotation of the plane of polarisation is theta=\",theta,\"degree\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the angle of rotation of the plane of polarisation is theta= 19.8 degree\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.8:pg-153"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate specific rotation \n",
- "theta=26.4 #in degree\n",
- "l=20 #length in cm\n",
- "c=0.2 #gm/cm**3\n",
- "alpha=10*theta/(l*c)\n",
- "print \"the specific rotation is alpha=\",alpha,\"degree\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the specific rotation is alpha= 66.0 degree\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.9:pg-153"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate strength of solution\n",
- "theta=11 #degree\n",
- "l=20.0 #length in cm\n",
- "alpha=66 #specific rotation of sugar in degree\n",
- "c=10*theta/(l*alpha)\n",
- "print \"strength of solution is c=\",round(c,4),\"gm/cm**3\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "strength of solution is c= 0.0833 gm/cm**3\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.10:pg-153"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate difference in the refractive indices\n",
- "#specific rotation is theta/d=29.73 degree/mm\n",
- "theta=29.73 #where theta=theta/d\n",
- "lamda=5.086*10**-4 #wavelength in mm\n",
- "#optical rotation is given by theta=math.pi*d*(mul-mur)/lamda\n",
- "#where mul and mur are refractive indices for anti-clockwise and clockwise polarised lights\n",
- "mu=theta*lamda/180 #where mu=mul-mur\n",
- "print \"difference in refractive indices is mu=\",\"{:.1e}\".format(mu),\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "difference in refractive indices is mu= 8.4e-05 unitless\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.11:pg-153"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate optical rotation\n",
- "#let theta' be the optical rotation by a solution of strength c' in a tube of length l' then\n",
- "#we get 10*theta'/l'*c'=10*theta/l*c\n",
- "c=1.0/3 #it is given that solution is 1/3 of its previous concentration i.e. c'/c=1/3,where c=c'/c\n",
- "l1=30 #where l1=l'\n",
- " #length in cm \n",
- "l=20.0\n",
- "theta=13 #degree\n",
- "#formula is theta'=l'*c'*theta/(l*c)\n",
- "theta1=l1*c*theta/l\n",
- "print \"optical rotation is theta1=\",theta1,\"degree\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "optical rotation is theta1= 6.5 degree\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.12:pg-154"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate specific rotation\n",
- "theta=52.8 #optical rotation in degree\n",
- "l=20.0 #length of the solution in cm\n",
- "c=20/50.0 #concentration of the solution in gm/cc\n",
- "alpha=10*theta/(l*c)\n",
- "print \"the specific rotation is alpha=\",alpha,\"degree\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the specific rotation is alpha= 66.0 degree\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.13:pg-154"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate length \n",
- "l=40 #length in cm\n",
- "c=5.0/100 #concentration in percentage\n",
- "theta1=35 #optical rotation in degree ,where theta1=theta'\n",
- "c1=10.0/100 #concentration in % ,where c1=c'\n",
- "theta=20\n",
- "#formula of specific rotation is alpha=10*theta/l*c\n",
- "l1=l*c*theta1/(c1*theta)\n",
- "print \"length is l1=\",l1,\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "length is l1= 35.0 cm\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.14:pg-155"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate rotation of plane of polarisation of light\n",
- "mur=1.53914\n",
- " #refractive index\n",
- "mul=1.53920\n",
- "lamda=6.5*10**-5 #wavelength in cm\n",
- "d=0.02 #distance in cm\n",
- "thetaR=180*(mul-mur)*d/lamda\n",
- "print \"rotation of plane of polarisation of light is thetaR=\",round(thetaR,3),\"degree\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "rotation of plane of polarisation of light is thetaR= 3.323 degree\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex4.15:pg-155"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate % purity of the sugar sample\n",
- "theta=9.9 #optical rotation in degree\n",
- "alpha=66 #specific roation of pure sugar solution in dm**-1(gm/cc)**-1\n",
- "l=20 #length of tube in cm\n",
- "c=10*theta/(l*alpha) #concentration of solution in gm/c.c\n",
- "#it is given that 80 gm of impure sugar is dissolved in a litre of water\n",
- "per=(c*100*10**3)/80 #here c is in gm/litre\n",
- "print \"percentage of the sugar sample is per=\",per,\"%\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "percentage of the sugar sample is per= 93.75 %\n"
- ]
- }
- ],
- "prompt_number": 17
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/chapter5.ipynb b/Engineering_Physics/chapter5.ipynb
deleted file mode 100755
index bf9aee93..00000000
--- a/Engineering_Physics/chapter5.ipynb
+++ /dev/null
@@ -1,177 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:141e2987b2be679ae1fc9e807cf81c12805438f836d3be09701fc88866bf9bb5"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter5:LASERS"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex5.1:pg-164"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate area of the spot on the moon\n",
- "lamda=6*10**-7 #wavelength in m\n",
- "d=2 #diameter in m\n",
- "dtheta=lamda/d #angular spread in radian\n",
- "D=4*10**8 #distance of the moon\n",
- "A=(D*dtheta)**2\n",
- "print \"the areal spread is A=\",\"{:.2e}\".format(A),\"m**2\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the areal spread is A= 1.44e+04 m**2\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex5.2:pg-164"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate angular spread of the beam\n",
- "lamda=8*10**-7 #wavelength in m\n",
- "d=5*10**-3 #aperture in m\n",
- "dtheta=lamda/d \n",
- "print \"the angular spread of the beam is dtheta=\",\"{:.1e}\".format(dtheta),\"radian\"\n",
- "#to calculate the areal spread when it reaches the moon\n",
- "D=4*10**8 #distance of the moon in m\n",
- "A=(D*dtheta)**2\n",
- "print \"the areal spread is A=\",\"{:.3e}\".format(A),\"m**2\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the angular spread of the beam is dtheta= 1.6e-04 radian\n",
- "the areal spread is A= 4.096e+09 m**2\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex5.3:pg-165"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate number of oscillations corresponding to the coherence length\n",
- "L=2.945*10**-2 #coherence length in m\n",
- "lamda=5890*10**-10 #wavelength of sodium light in m\n",
- "n=L/lamda\n",
- "print \"the number of oscillations is n=\",\"{:.1e}\".format(n),\"unitless\"\n",
- "#to calculate coherence time\n",
- "c=3*10**8 #light speed in m\n",
- "Time=L/c #coherence time\n",
- "print \"the coherence Time=\",\"{:.2e}\".format(Time),\"s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the number of oscillations is n= 5.0e+04 unitless\n",
- "the coherence Time= 9.82e-11 s\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex5.4:pg-165"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate area and intensity of the image\n",
- "lamda=7200*10**-10 #wavelength in m\n",
- "d=5*10**-3 #aperture in m\n",
- "dtheta=lamda/d #angular spread in radian \n",
- "f=0.1 #focal length in m\n",
- "arealspread=(dtheta*f)**2\n",
- "print \"areal spread =\",\"{:.3e}\".format(arealspread),\"m**2\"\n",
- "power=50*10**-3\n",
- "I=power/arealspread\n",
- "print \"intensity of the image is I=\",\"{:.3e}\".format(I),\"watts/m**2\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "areal spread = 2.074e-10 m**2\n",
- "intensity of the image is I= 2.411e+08 watts/m**2\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/chapter6.ipynb b/Engineering_Physics/chapter6.ipynb
deleted file mode 100755
index 26000b31..00000000
--- a/Engineering_Physics/chapter6.ipynb
+++ /dev/null
@@ -1,230 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:7bd6880823e892a54fce1336eeffd037b53706d16df72c924dbe7c27da815476"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter6:FIBER OPTICS AND HOLOGRAPHY"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex6.1:pg-189"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate critical angle for core-cladding interface\n",
- "n1=1.5\n",
- "n2=1.45\n",
- "thetac=math.degrees(math.asin(n2/n1))\n",
- "theta1=90-thetac\n",
- "\n",
- "print \"critical angle for core-cladding interface is theta1=\",round(theta1),\"degree\"\n",
- "#to calculate acceptance angle in air for fibre and corresponding angle of obliquences\n",
- "na=1\n",
- "thetaa=math.degrees(math.asin(n1*0.26/na))\n",
- "\n",
- "print \"acceptance angle thetaa=\",round(thetaa),\"degree\"\n",
- "#to calculate numerical aperture\n",
- "NA=((n1+n2)*(n1-n2))**(1/2.0)\n",
- "print \"numerical aperture of fibre is NA=\",round(NA,4),\"unitless\"\n",
- "#to calculate % of light\n",
- "per=(NA)**2*100\n",
- "print \"light collected is per=\",round(per,2),\"%\"\n",
- "\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "critical angle for core-cladding interface is theta1= 15.0 degree\n",
- "acceptance angle thetaa= 23.0 degree\n",
- "numerical aperture of fibre is NA= 0.3841 unitless\n",
- "light collected is per= 14.75 %\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex6.2:pg-190"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate numerical aperture\n",
- "Del=0.02 #relative refractive index difference between the core and the cladding of the fibre i.e. del=(n1-n2)/n1\n",
- "n1=1.46 #refractive index of core of W-step index fibre \n",
- "n2=n1-Del*n1\n",
- "NA=((n1+n2)*(n1-n2))**(1/2.0)\n",
- "print \"numerical aperture is NA=\",round(NA,2),\"unitless\"\n",
- "#to calculate critical angle at the core cladding interface within the fibre\n",
- "thetac=math.degrees(math.asin(n2/n1))\n",
- "print \"thetac=\",int(thetac),\"degree\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "numerical aperture is NA= 0.29 unitless\n",
- "thetac= 78 degree\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex6.3:pg-190"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate refractive index of the cladding\n",
- "a=35.0*10**-6 #core diameter in micrometre\n",
- "#formula is del=(n1-n2)/n1\n",
- "#we get\n",
- "Del=1.5/100 \n",
- "n1=1.46 #refractive index of the fibre \n",
- "lamda=0.85*10**-6 #wavelength in micrometer\n",
- "n2=n1-Del*n1\n",
- "print \"refractive index is n2=\",round(n2,3),\"unitless\"\n",
- "#to calculate normalised frequency V number of the fibre\n",
- "V=round((2*math.pi*a*n1*0.173)/lamda,1)\n",
- "print \"normalised frequency V number of the fibre is V=\",V,\"unitless\"\n",
- "#to calculate total number of guided modes in the fibre\n",
- "M=(V**2)/2.0\n",
- "print \"total number of guided modes in the fibre is M=\",int(M),\"modes\"\n",
- "\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "refractive index is n2= 1.438 unitless\n",
- "normalised frequency V number of the fibre is V= 65.3 unitless\n",
- "total number of guided modes in the fibre is M= 2132 modes\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex6.4:pg-191"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate cut-off wavelength of the fibre\n",
- "#(2*del)**(1/2)=(2*(n1-n2)/n1)**(1/2)=(0.005)**(1/2)=0.071\n",
- "a=5*10**-6 #radius in micrometre\n",
- "n1=1.46 #core refractive index in micrometre\n",
- "Vc=2.405 #cut-off value of V parametre for single mode operation\n",
- "#formula is LAMBDAc=(2*math.pi*a*n1*(2*del)**(1/2))/Vc \n",
- "lamdac=(2*math.pi*a*n1*0.071)/Vc\n",
- "print \"cut-off wavelength is LAMBDAc=\",round(lamdac/1e-6,2),\"micrometre\"\n",
- "\n",
- "# answer is slightly different due to approximation in book\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "cut-off wavelength is LAMBDAc= 1.35 micrometre\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex6.5:pg-191"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate maximum and minimum value of phase constant\n",
- "lamda=0.8*10**-6 #wavelength in micrometre\n",
- "n1=1.6*10**-6 \n",
- " #refractive indices in micrometre\n",
- "n2=1.44*10**-6\n",
- "maximum=(2*math.pi*n1)/lamda\n",
- "minimum=(2*math.pi*n2)/lamda\n",
- "print \"maximum value of phase constant is maximum=\",round(maximum,3),\"radian/micrometre\"\n",
- "print \"minimum value of phase constant is minimum=\",round(minimum,2),\"radian/micrometre\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "maximum value of phase constant is maximum= 12.566 radian/micrometre\n",
- "minimum value of phase constant is minimum= 11.31 radian/micrometre\n"
- ]
- }
- ],
- "prompt_number": 6
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/chapter7.ipynb b/Engineering_Physics/chapter7.ipynb
deleted file mode 100755
index b30ad5a1..00000000
--- a/Engineering_Physics/chapter7.ipynb
+++ /dev/null
@@ -1,912 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:43ad060be6803a5e6c90770bf46ae3612188f9380f800bb70a03161cb97405cb"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Chapter7:WAVE MECHANICS"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.1:pg-200"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate de Broglie wavelength \n",
- "v=1.5*10**7 #velocity of proton =(1/20)*velocity of light i.e.3*10**8 in m/s\n",
- "m=1.67*10**-27 #mass of the proton in kg\n",
- "h=6.6*10**-34 #plank's constant \n",
- "lamda=h/(m*v)\n",
- "print \"the de Broglie wavelength is lamda=\",\"{:.3e}\".format(lamda),\"m\" \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the de Broglie wavelength is lamda= 2.635e-14 m\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.2:pg-200"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate de Broglie wavelength\n",
- "#mo*c**2=1.507*10**-10/1.6*10**-19=941.87 Mev\n",
- "#since 12.8 Mev is very small compared to rest mass energy hence relavistic consideration may be ignored\n",
- "m=1.67*10**-27 #mass in kg\n",
- "h=6.62*10**-34 #plank's constant\n",
- "E=12.8*10**6 #energy in Mev\n",
- "lamda=h/math.sqrt(2*m*E*1.6*10**-19)/(1e-10)\n",
- "print \"the de Broglie wavelength is lamda=\",round(lamda,5),\"angstrom\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the de Broglie wavelength is lamda= 8e-05 angstrom\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.4:pg-201"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength\n",
- "h=6.6*10**-34 #plank's constant\n",
- "m=9.1*10**-31 #mass of electron in kg\n",
- "E=1.25*10**3 #pottential difference keV\n",
- "lamda=h/math.sqrt(2*m*E*1.6*10**-19)\n",
- "print \"the wavelength is lamda=\",\"{:.2e}\".format(lamda),\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the wavelength is lamda= 3.46e-11 m\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.5:pg-201"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate kinetic energy of an electron \n",
- "h=6.63*10**-34 #plank's constant\n",
- "mo=9.1*10**-31 #rest mass of an electron in kg\n",
- "lamda=5896*10**-10 #wavelength in angstrom\n",
- "K=(h**2)/(2*mo*(lamda**2)*1.6*10**-19) \n",
- "print \"kinetic energy of an electron is K=\",\"{:.2e}\".format(K),\"eV\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "kinetic energy of an electron is K= 4.34e-06 eV\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.6:pg-202"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate the wavelength of an electron of kinetic energy\n",
- "mo=9.1*10**-31 #mass of an electron in kg\n",
- "c=3*10**8 #speed of light in m/s \n",
- "K=1*10**6#kinetic energy in eV\n",
- "h=6.62*10**-34 #planck's constant in J-s\n",
- "#E=moc**2=81.9*10**-15/1.6*10**-19 eV=0.51MeV\n",
- "E=0.51*10**6\n",
- "lamda=(h*c)/(math.sqrt(K*(K+2*E))*1.6*10**-19)\n",
- "print \"wavelength of an electron of kinetic energy is lamda=\",round(lamda,14),\"m\"\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "wavelength of an electron of kinetic energy is lamda= 8.7e-13 m\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.7:pg-203"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate de Broglie wavelength\n",
- "V=100 #potential difference in volts\n",
- "lamda=12.25/math.sqrt(V)\n",
- "print \"de Broglie wavelength of any electron is lamda=\",lamda,\"angstrom\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "de Broglie wavelength of any electron is lamda= 1.225 angstrom\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.9:pg-203"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate energy of the neutron\n",
- "h=6.60*10**-34 #plank's constant in J/s\n",
- "m=1.674*10**-27 #mass of the neutron in kg\n",
- "lamda=10**-10 #de Broglie wavelength in m\n",
- "E=(h**2)/(2*m*(lamda**2)*1.6*10**-19)\n",
- "print \"energy of the neutron is E=\",\"{:.2e}\".format(E),\"eV\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "energy of the neutron is E= 8.13e-02 eV\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.10:pg-204"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength\n",
- "h=6.6*10**-34 #plank's constant in J/sec\n",
- "m=9.1*10**-31 #mass of electron in kg\n",
- "c=3*10**8 #light speed in m/s\n",
- "lamda=h/(m*c)/(1e-10) # in angstrom\n",
- "print \"wavelength of quantum of radiant energy is lamda=\",round(lamda,4),\"angstrom\"\n",
- "#to calculate number of photons \n",
- "power=12 #power emitted by the lamp =150*(8/100) in watts\n",
- "E=12.0 #energy emitted per second\n",
- "lamda=4500*10.0**-10\n",
- "energy=(h*c)/lamda #energy contained in one photon in J\n",
- "number=E/energy\n",
- "print \"number of photons emitted per sec is number=\",round(number,-16),\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "wavelength of quantum of radiant energy is lamda= 0.0242 angstrom\n",
- "number of photons emitted per sec is number= 2.727e+19 unitless\n"
- ]
- }
- ],
- "prompt_number": 22
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.11:pg-209"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate uncertainity in position\n",
- "#actual formula is (delx)min*(delp)max=h/2*math.pi-------------eq(1)\n",
- "#(delp)max=p(momentum of the electron)\n",
- "#mv=mov/math.sqrt(1-(v/c)**2)---------------------eq(2)\n",
- "mo=9*10**-31 #mass of an electron in m/s\n",
- "c=3*10**8 #light speed in m/s\n",
- "v=3*10**7 #velocity in m/s \n",
- "h=6.6*10**-34 #plank's constant in J/s\n",
- "#from eq(1) and eq(2),we get\n",
- "delxmin=(h*math.sqrt(1-(v/c)**2))/(2*math.pi*mo*v)\n",
- "print \"smallest possible uncertainity in the position of an electron is delxmin=\",round(delxmin/1e-10,4),\"angstrom\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "smallest possible uncertainity in the position of an electron is delxmin= 0.0389 angstrom\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.12:pg-209"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate minimum uncertainity in the velocity\n",
- "delxmax=10**-8 #maximum uncertainity in position in m\n",
- "h=6.626*10**-34 #planck's constant\n",
- "delpmin=h/(2*math.pi*delxmax) #minimum uncertainity in momentum in kg-m/s**2 \n",
- "m=9*10**-31 #mass of an electron in kg\n",
- "delvmin=delpmin/m\n",
- "print \"minimum uncertainity in the velocity is delvmin=\",\"{:.2e}\".format(delvmin),\"m/s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "minimum uncertainity in the velocity is delvmin= 1.17e+04 m/s\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.13:pg-209"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate uncertainity in the momentum of the parcticle \n",
- "h=6.626*10**-34 #planck's constant J-s\n",
- "delx=0.01*10**-2 #uncertainity in position in m\n",
- "delp=h/(2*math.pi*delx)\n",
- "print \"uncertainity in the momentum of the parcticle is delp=\",\"{:.2e}\".format(delp),\"kg-m/s**2\"\n",
- "#to calculate uncertainity in the velocity of an electron\n",
- "m=9*10**-31 #mass of an electron in kg\n",
- "delx=5*10**-10 \n",
- "delv=h/(2*math.pi*m*delx)\n",
- "print \"uncertainity in the velocity of an electron is delv=\",\"{:.3e}\".format(delv),\"m/s\"\n",
- "#to calculate uncertainity in the velocity of alpha particle \n",
- "m=4*1.67*10**-27 #mass of alpha particle in kg\n",
- "delx=5*10**-10\n",
- "delv=h/(2*math.pi*m*delx)\n",
- "print \"uncertainity in the velocity of an electron is delv=\",round(delv,2),\"m/s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "uncertainity in the momentum of the parcticle is delp= 1.05e-30 kg-m/s**2\n",
- "uncertainity in the velocity of an electron is delv= 2.343e+05 m/s\n",
- "uncertainity in the velocity of an electron is delv= 31.57 m/s\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.14:pg-210"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate uncertainity in position\n",
- "m=9.11*10**-31 #mass of electron in kg\n",
- "delv=40 #uncertainity in velocity in m/s\n",
- "h=6.6*10**-34 #plank's constant \n",
- "delx=h/(2*math.pi*m*delv)\n",
- "print \"uncertainity in the position of the electron is delx=\",\"{:.2e}\".format(delx),\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "uncertainity in the position of the electron is delx= 2.88e-06 m\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.15:pg-210"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate uncertainity in frequency\n",
- "#delE*delt=h/2*math.pi----eq(1)\n",
- "#delE=h*delv-----------eq(2)\n",
- "delt=10**-8 #uncertainity in time in s\n",
- "#from eq(1) and eq(2),we get\n",
- "delnu=1/(2*math.pi*delt)\n",
- "print \"minimum uncertainity in the frequency of the photon is delv=\",\"{:.3e}\".format(delnu),\"sec**-1\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "minimum uncertainity in the frequency of the photon is delv= 1.592e+07 sec**-1\n"
- ]
- }
- ],
- "prompt_number": 17
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.16:pg-211"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate uncertainity in the energy\n",
- "h=6.63*10**-34 #plank's constant in J-s\n",
- "delt=2.5*10**-14 #uncertainity in time in s\n",
- "delE=h/(2*math.pi*delt*1.6*10**-19)\n",
- "print \"minimum error with which the energy of the state can be measured is delE=\",round(delE,3),\"ev\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "minimum error with which the energy of the state can be measured is delE= 0.026 ev\n"
- ]
- }
- ],
- "prompt_number": 18
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.17:pg-211"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate time required for the atomic system \n",
- "#delE=h*c*dellamda/lamda**2 -----eq(1)\n",
- "#delE*delt=h/2*math.pi----------eq(2)\n",
- "dellamda=10**-14\n",
- "c=3*10**8\n",
- "lamda=6*10**-7\n",
- "#from eq(1)and eq(2),we get\n",
- "delt=(lamda**2)/(2*math.pi*c*dellamda)\n",
- "print \"time required for the atomic system to retain rotational energy is delt=\",\"{:.1e}\".format(delt),\"s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "time required for the atomic system to retain rotational energy is delt= 1.9e-08 s\n"
- ]
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.18:pg-211"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate minimum uncertainity in the momentum \n",
- "delxmax=5*10**-14 #uncertainity in position in m\n",
- "h=6.626*10**-34 #plank's constant in Js\n",
- "delpmin=h/(2*math.pi*delxmax)\n",
- "print \"minimum uncertainity in the momentum of the nucleon is delpmin=\",\"{:.2e}\".format(delpmin),\"kg m/s\"\n",
- "m=1.675*10**-27 #mass in kg\n",
- "Emin=(delpmin**2)/(2*m*1.6*10**-19)\n",
- "print \"minimum kinetic energy of the nucleon is Emin=\",round(Emin,2),\"eV\"\n",
- "#the answer is given wrong in the book Emin=0.039 eV\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "minimum uncertainity in the momentum of the nucleon is delpmin= 2.11e-21 kg m/s\n",
- "minimum kinetic energy of the nucleon is Emin= 8299.24 eV\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.19:pg-212"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate uncertainity in velocity\n",
- "delx=1.1*10**-8 #uncertainity in velocity in m\n",
- "h=6.626*10**-34 #plank's constant\n",
- "m=9.1*10**-31 #mass of electron in kg\n",
- "delv=h/(2*math.pi*m*delx)\n",
- "print \"minimum uncertainity in velocity is delv=\",\"{:.2e}\".format(delv),\"m/s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "minimum uncertainity in velocity is delv= 1.05e+04 m/s\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.20:pg-212"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate uncertainity in frequency\n",
- "delt=10**-8 #uncertainity in time\n",
- "delnu=1/(2*math.pi*delt) \n",
- "print \"minimum uncertainity in the frequency of a photon is delnu=\",\"{:.2e}\".format(delnu),\"sec**-1\"\n",
- "#to use the uncertainity principle to place a lower limit on the energy an electron must have if it is to be part of a nucleus\n",
- "delx=5*10**-15 #uncertainity in position\n",
- "delp=h/(2*2*math.pi*delx) #uncertainbity in momentum\n",
- "c=3*10**8 #/speed of light in m/s\n",
- "E=delp*c\n",
- "print \"energy of an electron is E=\",\"{:.2e}\".format(E),\"J\"\n",
- "\n",
- "# the answer is slightlty different due to approximation in textboook\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "minimum uncertainity in the frequency of a photon is delnu= 1.59e+07 sec**-1\n",
- "energy of an electron is E= 3.16e-12 J\n"
- ]
- }
- ],
- "prompt_number": 15
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.22:pg-223"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate probability of finding the particle\n",
- "a=25*10**-10#width in angstrom \n",
- "#wave function of the particle is chi(x)=math.sqrt(2/a)*math.sin(n*math.pi*x/a),for the particle in the least energy state n=1\n",
- "chix=math.sqrt(2/a)*math.sin(math.pi*(a/2)/a)\n",
- "delx=5*10**-10 #interval in angstrom\n",
- "P=delx*chix**2\n",
- "print \"probability of finding the particle is P=\",P,\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "probability of finding the particle is P= 0.4 unitless\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.24:pg-224"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate energy of an electron\n",
- "n=1 #least energy of the particle \n",
- "h=6.63*10**-34 #planck's constant in Js\n",
- "m=9.11*10**-31 #mass of electron in kg\n",
- "a=10**-10 #width in angstrom\n",
- "E=(n**2)*(h**2)/(8*m*(1.602*10**-19)*a**2)\n",
- "print \"energy of an electron moving in one dimension in an infinitely high potential box is E=\",round(E,2),\"eV\"\n",
- "#the answer is given wrong in the book E=5.68 eV\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "energy of an electron moving in one dimension in an infinitely high potential box is E= 37.65 eV\n"
- ]
- }
- ],
- "prompt_number": 16
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.26:pg-225"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate probability\n",
- "x1=0.45 #x1=0.45*L\n",
- "x2=0.55 #x2=0.55*L\n",
- "n=1 #for ground state \n",
- "#formula is P=integrate('(2/L)*math.sin(n*math.pi*x)**2),'x',x1,x2)\n",
- "from scipy.integrate import quad\n",
- "def integrand(x):\n",
- " return 2*(math.sin(n*math.pi*x)**2)\n",
- "P1 ,er=quad(integrand,x1,x2)\n",
- "\n",
- "print \"P1=\",round(P1,3),\"unitless\"\n",
- "probability1=P1*100\n",
- "print \"probability for the ground states is probability1 =\",round(probability1,1),\"%\"\n",
- "n=2 #for first excited state\n",
- "P2, er=quad(integrand,x1,x2)\n",
- "print \"P2=\",round(P2,4),\"unitless\"\n",
- "probability2=P2*100 \n",
- "print \"probability for first excited states is probability2=\",round(probability2,2),\"%\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "P1= 0.198 unitless\n",
- "probability for the ground states is probability1 = 19.8 %\n",
- "P2= 0.0065 unitless\n",
- "probability for first excited states is probability2= 0.65 %\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.28:pg-226"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate energy of a neutron\n",
- "#consider nucleus as a cubical box of size 10**-14m\n",
- "#x=y=z=a=10**-14=l\n",
- "#for neutron to be in the lowest energy state nx=ny=nz=1\n",
- "#formula is E=(math.pi**2*h**2/8*math.pi**2*m)*((nx/lx)**2+(ny/ly)**2+(nz/lz)**2)\n",
- "h=6.626*10**-34 #planck's constant in Js\n",
- "m=1.6*10**-27 #mass in kg\n",
- "l=10**-14 #in m\n",
- "E=(math.pi**2)*(h**2)*3/(4*(math.pi**2)*2*m*(1.6*10**-19)*l**2)\n",
- "print \"lowest energy of a neutron is E=\",round(E/(1e6),2),\"MeV\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "lowest energy of a neutron is E= 6.43 MeV\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.29:pg-226"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate zero point energy of a linear harmonic oscillator\n",
- "h=6.63*10**-34 #planck's constant in Js\n",
- "nu=50 #frequency in Hz\n",
- "zeropointenergy=(h*nu)/2\n",
- "print \"zeropointenergy=\",\"{:.2e}\".format(zeropointenergy),\"J\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "zeropointenergy= 1.66e-32 J\n"
- ]
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.30:pg-226"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate zero point energy\n",
- "nu=1 #frequency in Hz\n",
- "h=6.63*10**-34 #planck's constant in Js\n",
- "zeropointenergy=(h*nu)/2\n",
- "print \"zeropointenergy=\",zeropointenergy,\"J\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "zeropointenergy= 3.315e-34 J\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex7.31:pg-226"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate frequency of vibration\n",
- "En=0.1*1.6*10**-19 #energy of a linear harmonic oscillator in eV\n",
- "n=3.0 #third excited state\n",
- "h=6.63*10**-34 #planck's constant\n",
- "nu=En/((n+(1/2.0))*h)\n",
- "print \"the frequency of vibration is nu=\",round(nu,-9),\"Hz\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the frequency of vibration is nu= 6.895e+12 Hz\n"
- ]
- }
- ],
- "prompt_number": 16
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/chapter8.ipynb b/Engineering_Physics/chapter8.ipynb
deleted file mode 100755
index 106ed7f9..00000000
--- a/Engineering_Physics/chapter8.ipynb
+++ /dev/null
@@ -1,620 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:2b8beebd2e19262e31711f6c9b2785f35ddc221da552f5b3fe2ed984a495062e"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter8:X-RAY"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.1:pg-240"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate value of planck's constant\n",
- "e=1.6*10**-19 #in C\n",
- "V=100*10**3 #voltage in KV\n",
- "c=3*10**8 #light speed in m/s\n",
- "lamdamin=12.35*10**-12 #wavelength in m\n",
- "h=e*V*lamdamin/c\n",
- "print \"the value of plancks constant is h=\",\"{:.2e}\".format(h),\"J-s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the value of plancks constant is h= 6.59e-34 J-s\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.2:pg-240"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate maximum frequency\n",
- "h=6.6*10**-34 #planck's constant in J-s\n",
- "c=3.0*10**8 #light speed in m/s\n",
- "Ve=50000 #accelerating potential in V\n",
- "lamdamin=h*c/Ve #wavelength in m\n",
- "numax=c/lamdamin\n",
- "print \"maximum frequency present in the radiation from an X-ray tube is numax=\",\"{:.2e}\".format(numax),\"Hz\"\n",
- "#answer is given in thec book is incorrect =1.2*10**19 Hz\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "maximum frequency present in the radiation from an X-ray tube is numax= 7.58e+37 Hz\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.3:pg-240"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate number of electrons \n",
- "I=2*10**-3 #current in mA\n",
- "e=1.6*10**-19 \n",
- "n=I/e\n",
- "print \"number of electrons striking the target per second is n=\",n,\"unitless\"\n",
- "#to calculate speed\n",
- "m=9.1*10**-31 #mass of electron in kg\n",
- "V=12.4*10**3 #potential difference in V\n",
- "v=math.sqrt(2*V*e/m)\n",
- "print \"the speed with which electrons strike the target is v=\",\"{:.1e}\".format(v),\"m/s\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "number of electrons striking the target per second is n= 1.25e+16 unitless\n",
- "the speed with which electrons strike the target is v= 6.6e+07 m/s\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.4:pg-240"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength\n",
- "n=2 #second order for longest wavelength\n",
- "d=2.82*10**-10 # spacing in angstrom\n",
- "sintheta=1 \n",
- "lamdamax=2*d*sintheta/n\n",
- "print \"the longest wavelength that can be analysed by a rock salt crystal is lamdamax=\",lamdamax,\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the longest wavelength that can be analysed by a rock salt crystal is lamdamax= 2.82e-10 m\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.5:pg-241"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate spacing of the crystal\n",
- "h=6.62*10**-34 #planck's constant in J-s\n",
- "m=9.1*10**-31 #mass of electron in kg\n",
- "V=344 #voltage in V\n",
- "e=1.6*10**-19\n",
- "lamda=h/math.sqrt(2*m*e*V) #wavelength in m\n",
- "#according to Bragg's law\n",
- "n=1\n",
- "#formula is 2*d*sintheta=n*lamda\n",
- "d=n*lamda/(2*math.sin(math.pi/6))\n",
- "print \"the spacing of the crystal is d=\",round(d/1e-10,2),\"angstrom\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the spacing of the crystal is d= 0.66 angstrom\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.6:pg-241"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength of Kalpha line for an atom\n",
- "R=1.1*10**5\n",
- "z=92\n",
- "#Ka line is emitted when electron jumps from l shell(n2=2) to k shell(n1=1)\n",
- "#formula is 1/alphaa=R*(z-b)*((1/n1**2)-(1/n2)**2)\n",
- "alphaa=4/(3*R*(z-1)**2)\n",
- "print \"wavelength of Kalpha line for an atom is alphaa=\",\"{:.3e}\".format(alphaa),\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "wavelength of Kalpha line for an atom is alphaa= 1.464e-09 cm\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.7:pg-241"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate thickness\n",
- "#mass absorption coefficient mum of an absorber is related with linear absorption coefficient mu and density of the material rho is given by\n",
- "#mu=rho*mum=2.7*0.6=1.62 cm**-1\n",
- "mu=1.62\n",
- "#if initial intensity Io of the X-ray beam is reduced to I in traversing a distance x in absorber I=Io*e**-mu*x\n",
- "#where I/Io=20\n",
- "#put above values in the below equation , we get\n",
- "x=(2.3026*(math.log(20)/math.log(10)))/1.62\n",
- "print \"thickness is x=\",round(x,2),\"cm\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "thickness is x= 1.85 cm\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.8:pg-242"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate atomic number of the element\n",
- "#equation for balmer series in hydrogen spectrum is 1/lamda=R*((1/2**2)-(1/n**2))\n",
- "#for series limit n=infinity ,R=4/lamdainfinity i.e. R=4/364.6nm\n",
- "#X-ray wavelength of K series is 1/lamda=R*(z-1)**2*((1/1**2)-(1/n**2))\n",
- "lamda=0.1*10**-9\n",
- "R=4/(364.6*10**-9)\n",
- "#for n=infinity ,minimum wavelength of k series is given by\n",
- "z=math.sqrt(1/(lamda*R))+1\n",
- "print \"atomic number is z=\",int(z),\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "atomic number is z= 31 unitless\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.9:pg-242"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength\n",
- "d=1.87*10**-10 #spacing in angstrom\n",
- "n=2 \n",
- "#formula is lamda=2*d*sintheta/n\n",
- "lamda=2*d*math.sin(math.pi/6)/n\n",
- "print \"the wavelength of X-rays is lamda=\",round(lamda/1e-10,3),\"angstrom\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the wavelength of X-rays is lamda= 0.935 angstrom\n"
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.10:pg-242"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength of second X-ray beam\n",
- "#from bragg's law\n",
- "#lamda=(d*math.sin(math.pi/3))/n eq(1)\n",
- "#it is given that,theta=60,n=3,lamda=1.97 angstrom\n",
- "#from eq(1) we get,2*d*sin60degree=3*0.97 eq(2)\n",
- "#let lamda' be the second X-ray beam \n",
- "#we get 2*d'*sin theta'=n'*lamda' eq(3)\n",
- "#from eq(2) and eq(3),we get\n",
- "lamda1=math.sin(math.pi/6)*3*0.97/math.sin(math.pi/3) #where lamda1=lamda'\n",
- "print \"wavelength of X-ray is lamda1=\",round(lamda1,2),\"angstrom\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "wavelength of X-ray is lamda1= 1.68 angstrom\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.11:pg-243"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength\n",
- "d=2.82*10**-10 #spacing in m\n",
- "n=1 \n",
- "lamda=2*d*math.sin(10*math.pi/180)/n\n",
- "print \"wavelength of X-ray is lamda=\",round(lamda/1e-10,3),\"angstrom\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "wavelength of X-ray is lamda= 0.979 angstrom\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.12:pg-243"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#deduce possible spacing of the set of planes\n",
- "#for first order , 2*d*sintheta1=1*lamda...eq(1)\n",
- "#for second order ,2*d*sintheta2=2*lamda..eq(2)\n",
- "#for third order, 2*d*sintheta3=3*lamda......eq(3)\n",
- "#for fourth order, 2*d*sintheta4=4*lamda..............eq(4)\n",
- "#divide eq(2) by eq(1),we get sintheta2=2*sintheta1\n",
- "#similarly,sintheta3=3*sintheta1,sintheta4=4*sintheta1\n",
- "lamda=1.32*10**-10\n",
- "sintheta1=0.1650\n",
- "d1=lamda/(2*sintheta1)#for first order n=1,d1=d/n\n",
- "d2=lamda/(2*2*sintheta1) #for second order n=2,d2=d/n\n",
- "d3=lamda/(2*3*sintheta1) #for third order n=3,d3=d/n\n",
- "d4=lamda/(2*4*sintheta1) #for fourth order n=4,d4=d/n\n",
- "print \"d1=\",d1,\"m\"\n",
- "print \"d2=\",d2,\"m\"\n",
- "print \"d3=\",round(d3,2),\"m\"\n",
- "print \"d4=\",d4,\"m\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "d1= 4e-10 m\n",
- "d2= 2e-10 m\n",
- "d3= 0.0 m\n",
- "d4= 1e-10 m\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.13:pg-248"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate compton shift and wavelength\n",
- "h=6.63*10**-34 #planck's constant in J-s\n",
- "m0=9.11*10**-31 #mass of electron\n",
- "c=3*10**8 #light speed in m/s\n",
- "dellamda=h*(1-(1/math.sqrt(2)))/(m0*c)\n",
- "lamda0=2*10**-10\n",
- "lamda=dellamda+lamda0\n",
- "print \"compton shift is dellamda=\",round(dellamda/1e-10,4),\"angstrom\"\n",
- "print \"wavelength of the scattered X-rays is lamda=\",round(lamda/1e-10,4),\"angstrom\"\n",
- "#to calculate fraction of energy lost by the photon in the collision\n",
- "#energy lost =E0-E/E0=(hc/lamda0)-(hc/lamda)/(ha/lamda0)\n",
- "#we get,\n",
- "energylost=dellamda/lamda\n",
- "print \"energylost =\",round(energylost,5),\"unitless\" \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "compton shift is dellamda= 0.0071 angstrom\n",
- "wavelength of the scattered X-rays is lamda= 2.0071 angstrom\n",
- "energylost = 0.00354 unitless\n"
- ]
- }
- ],
- "prompt_number": 18
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.14:pg-249"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength and energy\n",
- "#formula is lamda'-lamda=h*(1-cos phi)/(m0*c),where phi=90 degree, lamda'=2lamda ---------------eq(1)\n",
- "#dellamda=2lamda-lamda=lamda ----------------------------eq(2)\n",
- "h=6.62*10**-34 #planck's constant\n",
- "c=3*10**8 #light speed in m.s\n",
- "m0=9*10**-31 #mass of electron in kg\n",
- "#from eq(1) and eq(2) ,we get\n",
- "lamda=h/(m0*c)\n",
- "print \"wavelength is lamda=\",round(lamda/1e-10,4),\"angstrom\"\n",
- "E=h*c/lamda\n",
- "print \"energy of the incident photon is E=\",E,\"J\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "wavelength is lamda= 0.0245 angstrom\n",
- "energy of the incident photon is E= 8.1e-14 J\n"
- ]
- }
- ],
- "prompt_number": 19
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.15:pg-249"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength of radiation and direction of emission\n",
- "h=6.6*10**-34 #planck's constant in J-s\n",
- "c=3*10**8 #speed of light in m/s\n",
- "energy=510*10**3 #energy of photon in eV\n",
- "lamda=h*c/(energy*1.6*10**-19)\n",
- "mo=9.1*10**-31 #mass of electron in Kg\n",
- "lamda1=lamda+h*(1-math.cos(math.pi/2))/(mo*c)\n",
- "print \"wavelength of radiation is lamda1=\",\"{:.2e}\".format(lamda1),\"m\"\n",
- "theta=math.degrees(math.atan(lamda*math.sin(math.pi/2)/(lamda1-lamda*math.cos(math.pi/2))))\n",
- "print\"direction of emission of electron is theta=\",round(theta,2),\"degree\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "wavelength of radiation is lamda1= 4.84e-12 m\n",
- "direction of emission of electron is theta= 26.61 degree\n"
- ]
- }
- ],
- "prompt_number": 21
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex8.16:pg-249"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate wavelength of two X-rays\n",
- "h=6.6*10**-34 #planck's constant in J-s\n",
- "c=3.0*10.0**8 #light speed in m/s\n",
- "mo=9.1*10**-31 #mass of electron in kg\n",
- "lamda=10.0*10**-12 #wavelength in pm\n",
- "lamda1=lamda+((h/(mo*c))*(1-(1/math.sqrt(2))))\n",
- "print \"wavelength of two X-rays is lamda1=\",round(lamda1*(1e12),1),\"picometer\"\n",
- "#to calculate maximum wavelength\n",
- "lamda2=lamda+((2*h)/(mo*c))\n",
- "print \"maximum wavelength present in the scattered X-rays is lamda2=\",round(lamda2*(1e12),2),\"picometer\"\n",
- "#to calculate maximum kinetic energy \n",
- "Kmax=(h*c)*((1/lamda)-(1/lamda2))/(1.6*10**-19)\n",
- "print \"maximum kinetic energy of the recoil electrons is Kmax=\",round(Kmax/1000.0,1),\"KeV\"\n",
- "\n",
- "# the answer is slightly different due to approximation\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "wavelength of two X-rays is lamda1= 10.7 picometer\n",
- "maximum wavelength present in the scattered X-rays is lamda2= 14.84 picometer\n",
- "maximum kinetic energy of the recoil electrons is Kmax= 40.3 KeV\n"
- ]
- }
- ],
- "prompt_number": 6
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/chapter9.ipynb b/Engineering_Physics/chapter9.ipynb
deleted file mode 100755
index d92ff5fa..00000000
--- a/Engineering_Physics/chapter9.ipynb
+++ /dev/null
@@ -1,130 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:5dfcc3b8a36b2e69e76da78cbe3cbbcd618d029b3ed8c322ee0560bc514169c3"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter9:DIELECTRIC PROPERTIESOF MATERIALS"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex9.1:pg-269"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate dielectric constant of the liquid\n",
- "#capacitance of the air filled dielectric Cair=Q/Vo-----------eq(1)\n",
- "#when dielectric is filled between the plates ,Cliquid=Q/V\n",
- "#then Cliquid=epsilonr*Q/Vo------eq(2)\n",
- "Vo=60\n",
- " #voltage in volts\n",
- "V=30\n",
- "#from eq(1) and eq(2),we get\n",
- "epsilon0=Vo/V\n",
- "print \"the dielectric constant of the liquid is epsilon0=\",epsilon0,\"unitless\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the dielectric constant of the liquid is epsilon0= 2 unitless\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex9.2:pg-269"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate charge on the capacitance\n",
- "epsilon0=8.854*10**-12 #permittivity\n",
- "epsilonr=6 #relative permittivity\n",
- "V=100 #voltage in volts\n",
- "d=1.5*10**-3 #distance in m\n",
- "A=4*10**-4#area in m**2\n",
- "Q=epsilon0*epsilonr*A*V/d\n",
- "print \"the charge on the capacitance is Q=\",\"{:.2e}\".format(Q),\"Coulomb\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the charge on the capacitance is Q= 1.42e-09 Coulomb\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Ex9.3:pg-269"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import math\n",
- "#to calculate voltage\n",
- "A=6.50*10**-4 #area in m**2\n",
- "Q=2*10**-10 #charge in C\n",
- "d=4*10**-3 #plate separation in m\n",
- "epsilon0=8.854*10**-12\n",
- "epsilonr=3.5 #dielectric constant\n",
- "V=Q*d/(epsilon0*epsilonr*A)\n",
- "print \"the resultant voltage across the capacitor is V=\",round(V,1),\"volt\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "the resultant voltage across the capacitor is V= 39.7 volt\n"
- ]
- }
- ],
- "prompt_number": 2
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file
diff --git a/Engineering_Physics/screenshots/1.png b/Engineering_Physics/screenshots/1.png
deleted file mode 100755
index 4282275d..00000000
--- a/Engineering_Physics/screenshots/1.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/11.png b/Engineering_Physics/screenshots/11.png
deleted file mode 100755
index 0fc56fcd..00000000
--- a/Engineering_Physics/screenshots/11.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/1_converted.png b/Engineering_Physics/screenshots/1_converted.png
deleted file mode 100755
index 6f902c6e..00000000
--- a/Engineering_Physics/screenshots/1_converted.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/2.png b/Engineering_Physics/screenshots/2.png
deleted file mode 100755
index 9e1e8cf6..00000000
--- a/Engineering_Physics/screenshots/2.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/22.png b/Engineering_Physics/screenshots/22.png
deleted file mode 100755
index 3a440c46..00000000
--- a/Engineering_Physics/screenshots/22.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/2_converted.png b/Engineering_Physics/screenshots/2_converted.png
deleted file mode 100755
index 5b3697bc..00000000
--- a/Engineering_Physics/screenshots/2_converted.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/3.png b/Engineering_Physics/screenshots/3.png
deleted file mode 100755
index 662e6b45..00000000
--- a/Engineering_Physics/screenshots/3.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/33.png b/Engineering_Physics/screenshots/33.png
deleted file mode 100755
index fc148b77..00000000
--- a/Engineering_Physics/screenshots/33.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/3_converted.png b/Engineering_Physics/screenshots/3_converted.png
deleted file mode 100755
index 47f7a27c..00000000
--- a/Engineering_Physics/screenshots/3_converted.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/U3.png b/Engineering_Physics/screenshots/U3.png
deleted file mode 100755
index fc148b77..00000000
--- a/Engineering_Physics/screenshots/U3.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/Untitled.png b/Engineering_Physics/screenshots/Untitled.png
deleted file mode 100755
index ef585cf3..00000000
--- a/Engineering_Physics/screenshots/Untitled.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/Untitled2.png b/Engineering_Physics/screenshots/Untitled2.png
deleted file mode 100755
index 3a440c46..00000000
--- a/Engineering_Physics/screenshots/Untitled2.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/area_of_the_spot_on_the_moon.png b/Engineering_Physics/screenshots/area_of_the_spot_on_the_moon.png
deleted file mode 100755
index d72ce215..00000000
--- a/Engineering_Physics/screenshots/area_of_the_spot_on_the_moon.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/electric_flux.png b/Engineering_Physics/screenshots/electric_flux.png
deleted file mode 100755
index ba949261..00000000
--- a/Engineering_Physics/screenshots/electric_flux.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics/screenshots/velocity_of_rocket.png b/Engineering_Physics/screenshots/velocity_of_rocket.png
deleted file mode 100755
index d86b5e4c..00000000
--- a/Engineering_Physics/screenshots/velocity_of_rocket.png
+++ /dev/null
Binary files differ
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter1.ipynb b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter1.ipynb
new file mode 100755
index 00000000..7df93df9
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter1.ipynb
@@ -0,0 +1,705 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e55f587b2da98ead68f73bb2b4d29bef91aa67eb577c460fb9dcaab92acc4339"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Ultrasonics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.1, Page number 20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the depth of a submerged submarine\n",
+ "\n",
+ "#Variable declaration\n",
+ "v = 1440; #velocity of ultrasonic waves(m/s)\n",
+ "t = 0.33; #time elapsed(s)\n",
+ "\n",
+ "#Calculation\n",
+ "d = v*t; #distance travelled(m)\n",
+ "d1 = d/2; #depth of submarine(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"depth of the submerged submarine is\",d1, \"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "depth of the submerged submarine is 237.6 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.2, Page number 21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the natural frequency \n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "l = 40; #length of iron rod(mm)\n",
+ "E = 115*10**9; #Young's modulus(N/m**2)\n",
+ "rho = 7.25*10**3; #density of pure iron(kg/m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "l = l*10**-3; #length of iron rod(m)\n",
+ "new = (1/(2*l))*math.sqrt(E/rho); #natural frequency of the rod(Hz)\n",
+ "new = new*10**-3; #natural frequency of the rod(kHz)\n",
+ "new=math.ceil(new*10**3)/10**3; #rounding off to 3 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"depth of the submerged submarine is\",new, \"kHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "depth of the submerged submarine is 49.785 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.3, Page number 21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the fundamental frequency \n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "l = 1; #length of quartz crystal(mm)\n",
+ "E = 7.9*10**10; #Young's modulus(N/m**2)\n",
+ "rho = 2650; #density(kg/m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "l = l*10**-3; #length of iron rod(m)\n",
+ "new = (1/(2*l))*math.sqrt(E/rho); #natural frequency of the rod(Hz)\n",
+ "new = new*10**-6; \n",
+ "new=math.ceil(new*10**2)/10**2; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"fundamental frequency of crystal is\",new, \"*10**6 Hz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "fundamental frequency of crystal is 2.73 *10**6 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.4, Page number 22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the velocity of waves\n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "d = 0.55; #distance between 2 constructive antinodes(mm)\n",
+ "new = 1.5; #frequency of crystal(MHz)\n",
+ " \n",
+ "#Calculation\n",
+ "new = new*10**6; #frequency of crystal(Hz)\n",
+ "d = d*10**-3; #distance between 2 constructive antinodes(m)\n",
+ "#distance between 2 antinodes is given by lamda/2\n",
+ "lamda = 2*d; #wavelength of ultrasonic waves(m)\n",
+ "v = new*lamda; #velocity of waves(m/s)\n",
+ "\n",
+ "#Result\n",
+ "print \"velocity of waves is\",int(v), \"m/s\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "velocity of waves is 1650 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.5, Page number 22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the natural frequency\n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "l = 50; #length of rod(mm)\n",
+ "E = 11.5*10**10; #Young's modulus(N/m**2)\n",
+ "rho = 7250; #density(kg/m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "l = l*10**-3; #length of iron rod(m)\n",
+ "new = (1/(2*l))*math.sqrt(E/rho); #natural frequency of the rod(Hz)\n",
+ "new = new*10**-3; #natural frequency of the rod(kHz)\n",
+ "new = math.ceil(new*10**2)/10**2; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"natural frequency of rod is\",new, \"kHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "natural frequency of rod is 39.83 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.6, Page number 22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the frequency\n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "l = 2; #length of crystal(mm)\n",
+ "E = 7.9*10**10; #Young's modulus(N/m**2)\n",
+ "rho = 2650; #density(kg/m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "l = l*10**-3; #length of iron rod(m)\n",
+ "new = (1/(2*l))*math.sqrt(E/rho); #natural frequency of the rod(Hz)\n",
+ "new = new*10**-6; #natural frequency of the rod(MHz)\n",
+ "new=math.ceil(new*10**3)/10**3; #rounding off to 3 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"frequency of crystal is\",new, \"MHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "frequency of crystal is 1.365 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.7, Page number 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the frequency\n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "l = 3; #length of crystal(mm)\n",
+ "E = 8*10**10; #Young's modulus(N/m**2)\n",
+ "rho = 2500; #density(kg/m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "l = l*10**-3; #length of iron rod(m)\n",
+ "new = (1/(2*l))*math.sqrt(E/rho); #natural frequency of the rod(Hz)\n",
+ "new = new*10**-3; #natural frequency of the rod(kHz) \n",
+ "new=math.ceil(new*10**2)/10**2; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"frequency of crystal is\",new, \"kHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "frequency of crystal is 942.81 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.8, Page number 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the frequency\n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "l = 1.5; #length of crystal(mm)\n",
+ "E = 7.9*10**10; #Young's modulus(N/m**2)\n",
+ "rho = 2650; #density(kg/m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "l = l*10**-3; #length of iron rod(m)\n",
+ "new = (1/(2*l))*math.sqrt(E/rho); #natural frequency of the rod(Hz)\n",
+ "new = new*10**-6; #natural frequency of the rod(MHz) \n",
+ "new=math.ceil(new*10**2)/10**2; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"frequency of crystal is\",new, \"MHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "frequency of crystal is 1.82 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.9, Page number 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the depth of the sea\n",
+ "\n",
+ "#Variable declaration\n",
+ "v = 1440; #velocity of ultrasonic waves(m/s)\n",
+ "t = 0.95; #time elapsed(s)\n",
+ "\n",
+ "#Calculation\n",
+ "d = v*t; #distance travelled(m)\n",
+ "d1 = d/2; #depth of sea(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"depth of the submerged submarine is\",int(d1), \"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "depth of the submerged submarine is 684 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.10, Page number 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the depth of a submerged submarine\n",
+ "\n",
+ "#Variable declaration\n",
+ "v = 1440; #velocity of ultrasonic waves(m/s)\n",
+ "t = 0.83; #time elapsed(s)\n",
+ "\n",
+ "#Calculation\n",
+ "d = v*t; #distance travelled(m)\n",
+ "d1 = d/2; #depth of submarine(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"depth of the submerged submarine is\",d1, \"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "depth of the submerged submarine is 597.6 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.11, Page number 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the reverberation time of hall\n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "aS = 1050; #total absorption inside hall(Sabine)\n",
+ "V = 9000; #volume of cinema hall(m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "T = 0.165*V/aS; #reverberation time of hall(s)\n",
+ "T = math.ceil(T*10**4)/10**4; #rounding off to 4 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"reverberation time of the hall is\",T, \"s\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "reverberation time of the hall is 1.4143 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.12, Page number 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the area of interior surface\n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "a = 0.65; #average absorption coefficient(Sabine/m**2)\n",
+ "V = 13500; #volume of auditorium(m**3)\n",
+ "T = 1.2; #reverberation time of hall(s)\n",
+ "\n",
+ "#Calculation\n",
+ "S = 0.165*V/(a*T); #reverberation time of hall(s)\n",
+ "S = math.ceil(S*10)/10; #rounding off to 1 decimal\n",
+ "\n",
+ "#Result\n",
+ "print \"total area of interior surface is\",S, \"m**2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total area of interior surface is 2855.8 m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.13, Page number 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the new reverberation time of hall\n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "V = 15000; #volume of cinema hall(m**3)\n",
+ "T1 = 1.3; #initial reverberation time of hall(s)\n",
+ "a1S1 = 300; #number of chairs placed\n",
+ "\n",
+ "#Calculation\n",
+ "aS = 0.165*V/T1; #total absorption of hall\n",
+ "T2 = (0.165*V)/(aS+a1S1); #reverberation time of hall after adding chairs(s)\n",
+ "T2 = math.ceil(T2*10**4)/10**4; #rounding off to 4 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"reverberation time of the hall after adding chairs is\",T2, \"s\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "reverberation time of the hall after adding chairs is 1.1231 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.14, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the depth of a submerged submarine\n",
+ "\n",
+ "#Variable declaration\n",
+ "v = 1440; #velocity of ultrasonic waves(m/s)\n",
+ "t = 0.5; #time elapsed(s)\n",
+ "\n",
+ "#Calculation\n",
+ "d = v*t; #distance travelled(m)\n",
+ "d1 = d/2; #depth of submarine(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"depth of the submerged submarine is\",int(d1), \"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "depth of the submerged submarine is 360 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.15, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the velocity of waves\n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "d = 0.4; #distance between 2 constructive antinodes(mm)\n",
+ "new = 1.5; #frequency of crystal(MHz)\n",
+ " \n",
+ "#Calculation\n",
+ "new = new*10**6; #frequency of crystal(Hz)\n",
+ "d = d*10**-3; #distance between 2 constructive antinodes(m)\n",
+ "#distance between 2 antinodes is given by lamda/2\n",
+ "lamda = 2*d; #wavelength of ultrasonic waves(m)\n",
+ "v = new*lamda; #velocity of waves(m/s)\n",
+ "\n",
+ "#Result\n",
+ "print \"velocity of waves is\",int(v), \"m/s\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "velocity of waves is 1200 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.16, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the natural frequency \n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "l = 40; #length of iron rod(mm)\n",
+ "E = 11.5*10**10; #Young's modulus(N/m**2)\n",
+ "rho = 7250; #density of pure iron(kg/m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "l = l*10**-3; #length of iron rod(m)\n",
+ "new = (1/(2*l))*math.sqrt(E/rho); #natural frequency of the rod(Hz)\n",
+ "new = new*10**-3; #natural frequency of the rod(kHz)\n",
+ "new=math.ceil(new*10**3)/10**3; #rounding off to 3 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"depth of the submerged submarine is\",new, \"kHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "depth of the submerged submarine is 49.785 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter10.ipynb b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter10.ipynb
new file mode 100755
index 00000000..e90b7dfe
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter10.ipynb
@@ -0,0 +1,70 @@
+{
+ "metadata": {
+ "name": "Chapter10"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Dielectric Materials"
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 10.1, Page number 289"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the electronic polarizability of He atoms\n\n#importing modules\nimport math\n\n#Variable declaration\nepsilon_r = 1.0000684; #dielectric constant\nN = 2.7*10**25; #number of atoms(per m**3)\nepsilon0 = 8.85*10**-12; #permittivity of free space\n\n#Calculation\nalpha_e = epsilon0*(epsilon_r-1)/N; #electronic polarizability(Fm**2)\n\n#Result\nprint \"electronic polarizability is\",alpha_e,\"Fm**2\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "electronic polarizability is 2.242e-41 Fm**2\n"
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 10.2, Page number 290"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the electronic polarizability of Argon gas\n\n#importing modules\nimport math\n\n#Variable declaration\nepsilon_r = 1.0024; #relative permittivity\nN = 2.7*10**25; #number of atoms(per m**3)\nepsilon0 = 8.85*10**-12; #permittivity of free space\n\n#Calculation\nalpha_e = epsilon0*(epsilon_r-1)/N; #electronic polarizability(Fm**2)\n\n#Result\nprint \"electronic polarizability is\",alpha_e,\"Fm**2\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "electronic polarizability is 7.86666666667e-40 Fm**2\n"
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter2.ipynb b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter2.ipynb
new file mode 100755
index 00000000..a5d2bc97
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter2.ipynb
@@ -0,0 +1,175 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:ac80f9dfe1725f11a5d4ce0fbda5ffed825d99c680f116629e5e3fcb8b69c198"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Lasers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.1, Page number 52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the relative population \n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda = 590; #wavelength(nm)\n",
+ "h = 6.625*10**-34; #planck's constant\n",
+ "c = 3*10**8; #velocity of light(m/s)\n",
+ "k = 1.38*10**-23; #boltzmann's constant\n",
+ "T = 523; #temperature(Kelvin)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda = lamda*10**-9; #wavelength(m) \n",
+ "#n1byn2 = math.exp(-(E2-E1)/(k*T))\n",
+ "#but E2-E1 = h*new and new = c/lamda\n",
+ "#therefore n1byn2 = math.exp(-h*c/(lamda*k*T))\n",
+ "n1byn2 = math.exp(-h*c/(lamda*k*T));\n",
+ "\n",
+ "#Result\n",
+ "print \"relative population of Na atoms is\",n1byn2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "relative population of Na atoms is 5.36748316686e-21\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.2, Page number 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the ratio of stimulated to spontaneous emission \n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda = 590; #wavelength(nm)\n",
+ "h = 6.625*10**-34; #planck's constant\n",
+ "c = 3*10**8; #velocity of light(m/s)\n",
+ "k = 1.38*10**-23; #boltzmann's constant\n",
+ "T = 523; #temperature(Kelvin)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda = lamda*10**-9; #wavelength(m) \n",
+ "#n21dashbyn21 = 1/(math.exp(h*new/(k*T))-1)\n",
+ "#but new = c/lamda\n",
+ "#therefore n21dashbyn21 = 1/(math.exp(h*c/(lamda*k*T))-1)\n",
+ "A = math.exp(h*c/(lamda*k*T))-1;\n",
+ "n21dashbyn21 = 1/A; \n",
+ "\n",
+ "#Result\n",
+ "print \"ratio of stimulated to spontaneous emission is\",n21dashbyn21\n",
+ "print \"answer given in the book is wrong\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ratio of stimulated to spontaneous emission is 5.36748316686e-21\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.3, Page number 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To calculate the number of photons emitted \n",
+ "\n",
+ "#importing modules\n",
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda = 632.8; #wavelength of laser(nm)\n",
+ "h = 6.625*10**-34; #planck's constant\n",
+ "c = 3*10**8; #velocity of light(m/s)\n",
+ "p = 3.147; #output power(mW)\n",
+ "\n",
+ "#Calculation\n",
+ "p = p*10**-3; #output power(W)\n",
+ "lamda = lamda*10**-9; #wavelength(m) \n",
+ "new = c/lamda; #frequency(Hz)\n",
+ "E = h*new; #energy of each photon(J)\n",
+ "Em = p*60; #energy emitted per minute(J/min)\n",
+ "N = Em/E; #number of photons emitted per second\n",
+ "\n",
+ "#Result\n",
+ "print \"number of photons emitted per second is\",N"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of photons emitted per second is 6.01183879245e+17\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter3.ipynb b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter3.ipynb
new file mode 100755
index 00000000..4f695418
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter3.ipynb
@@ -0,0 +1,91 @@
+{
+ "metadata": {
+ "name": "Chapter3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Fibre Optics and Applications"
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 3.1, Page number 84"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the numerical aperture, critical angle,acceptance angle\n\n#importing modules\nimport math\n\n#Variable declaration\nn1 = 1.5; #refractive index of core\nn2 = 1.47; #refractive index of cladding\nn0 = 1; #refractive index of air\na = 180/math.pi; #conversion factor of radian to degree\n\n#Calculation\nNA = math.sqrt((n1**2)-(n2**2)); #numerical aperture\nNA=math.ceil(NA*10)/10; #rounding off to 1 decimal\nalpha_m = math.asin(NA/n0); #acceptance angle(radian)\nalpha_m = alpha_m*a; #acceptance angle(degrees)\nalpha_m=math.ceil(alpha_m*10**2)/10**2; #rounding off to 2 decimals\nphi_m = math.asin(NA/n1); #phase angle(radian)\nphi_m = phi_m*a; #phase angle(degrees)\nphi_m=math.ceil(phi_m*10**2)/10**2; #rounding off to 2 decimals\ntheta_c = math.asin(n2/n1); #critical angle(radian)\ntheta_c = theta_c*a; #critical angle(degrees)\ntheta_c=math.ceil(theta_c*10**3)/10**3; #rounding off to 3 decimals\n\n#Result\nprint \"numerical aperture is\",NA\nprint \"acceptance angle is\",alpha_m,\"degrees\"\nprint \"phase angle is\",phi_m,\"degrees\"\nprint \"critical angle is\",theta_c,\"degrees\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "numerical aperture is 0.3\nacceptance angle is 17.46 degrees\nphase angle is 11.54 degrees\ncritical angle is 78.522 degrees\n"
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 3.2, Page number 85"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the pulse broadening \n\n#importing modules\nimport math\n\n#Variable declaration\nn1 = 1.5; #refractive index of core\nn2 = 1.47; #refractive index of cladding\nc = 3*10**8; #velocity of light(m/sec)\n\n#Calculation\ndeltatbyL = (n1/n2)*((n1-n2)/c);\n\n#Result\nprint \"pulse broadening per unit length is\",deltatbyL,\"s/m\"\n",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "pulse broadening per unit length is 1.02040816327e-10 s/m\n"
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 3.3, Page number 85"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the minimum and maximum number of total internal reflections\n\n#importing modules\nimport math\n\n#Variable declaration\nphi_m = 11.54; #phase angle(degrees)\na = 0.5*10**-4;\nx = math.pi/180; #conversion factor from degrees to radians\n\n#Calculation\nphi_m = phi_m*x; #phase angle(radian)\nL = a/math.tan(phi_m); #length(m)\nn = 1/(2*L); #total number of internal reflections(m-1)\n\n#Result\nprint \"rays travelling with alpha = 0 suffer no reflection. therefore minimum number of reflections per metre is 0.\"\nprint \"for rays travelling with alpha = alpha_m, the total number of internal reflections for 1m is\",int(n),\"m-1\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "rays travelling with alpha = 0 suffer no reflection. therefore minimum number of reflections per metre is 0.\nfor rays travelling with alpha = alpha_m, the total number of internal reflections for 1m is 2041 m-1\n"
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter4.ipynb b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter4.ipynb
new file mode 100755
index 00000000..79f4bf10
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter4.ipynb
@@ -0,0 +1,217 @@
+{
+ "metadata": {
+ "name": "Chapter4"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Quantum Physics"
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 4.1, Page number 117"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the energy and momentum of photon\n\n#importing modules\nimport math\n\n#Variable declaration\nc = 3*10**8; #velocity of light(m/sec)\nh = 6.62*10**-34; #planck's constant\nlamda = 1.2; #wavelength of photon(Angstrom)\ne = 1.6*10**-19; #conversion factor from J to eV\n\n#Calculation\nlamda = lamda*10**-10; #wavelength of photon(m)\nE = (h*c)/(lamda*e); #energy of photon(eV)\nE=math.ceil(E*10)/10; #rounding off to 1 decimal\np = h/lamda; #momentum of photon(kg m/s)\n\n#Result\nprint \"energy of the photon is\",E,\"eV\"\nprint \"momentum of the photon is\",p,\"kg m/s\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "energy of the photon is 10343.8 eV\nmomentum of the photon is 5.51666666667e-24 kg m/s\n"
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 4.2, Page number 117"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the number of photons emitted \n\n#importing modules\nimport math\n\n#Variable declaration\nh = 6.625*10**-34; #planck's constant\nnew = 900; #frequency(kHz)\nE1 = 10; #power radiated(kW)\n\n#Calculation\nE1 = E1*10**3; #power radiated(W)\nnew = new*10**3; #frequency(Hz)\nE = h*new; #energy of photon(J)\nN = E1/E; #number of photons emitted \n\n#Result\nprint \"number of photons emitted per second is\",N",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "number of photons emitted per second is 1.67714884696e+31\n"
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 4.3, Page number 118"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the number of photons emitted \n\n#importing modules\nimport math\n\n#Variable declaration\nc = 3*10**8; #velocity of light(m/sec)\nh = 6.63*10**-34; #planck's constant\nlamda = 5893; #wavelength of photon(Angstrom)\nE1 = 100; #power of lamp(W) \n\n#Calculation\nlamda = lamda*10**-10; #wavelength of photon(m)\nE = h*c/lamda; #energy of photon(J)\nN = E1/E; #number of photons emitted \n\n#Result\nprint \"number of photons emitted per second is\",N\nprint \"answer given in the book is wrong\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "number of photons emitted per second is 2.96279537456e+20\nanswer given in the book is wrong\n"
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 4.4, Page number 118"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the wavelength of scattered radiation\n\n#importing modules\nimport math\n\n#Variable declaration\nc = 3*10**8; #velocity of light(m/sec)\nh = 6.6*10**-34; #planck's constant\nm0 = 9.1*10**-31; #mass of photon(kg)\ntheta = 30; #viewing angle(degrees)\nlamda = 2.8*10**-10; #wavelength of photon(m)\n\n#Calculation\nx = math.pi/180; #conversion factor from degrees to radians\ntheta = theta*x; #viewing angle(radian) \nlamda_dash = (2*h*(math.sin(theta/2))**2/(m0*c))+lamda; #wavelength of scattered radiation(m)\nlamda_dash = lamda_dash*10**10; #wavelength of scattered radiation(Angstrom)\nlamda_dash=math.ceil(lamda_dash*10**5)/10**5; #rounding off to 5 decimals\n\n#Result\nprint \"wavelength of scattered radiation is\",lamda_dash,\"Angstrom\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "wavelength of scattered radiation is 2.80324 Angstrom\n"
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 4.5, Page number 119"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the deBroglie wavelength\n\n#importing modules\nimport math\n\n#Variable declaration\nh = 6.6*10**-34; #planck's constant\nm = 0.040; #mass of bullet(kg)\nv = 1; #speed of bullet(km/s)\n\n#Calculation\nv = v*10**3; #speed of bullet(m/s)\np = m*v; #momemtun of bullet(kg m/s)\nlamda = h/p; #deBroglie wavelength(m)\nlamda = lamda*10**10; #deBroglie wavelength(Angstrom)\n\n#Result\nprint \"deBroglie wavelength is\",lamda,\"Angstrom\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "deBroglie wavelength is 1.65e-25 Angstrom\n"
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 4.6, Page number 119"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the energy of particle\n\n#importing modules\nimport math\n\n#Variable declaration\nn = 1; #lowest energy state\na = 0.1; #width of box(nm)\nh = 6.625*10**-34; #planck's constant\ne = 1.602*10**-19; #conversion factor from J to eV\nm = 9.11*10**-31; #mass of particle(kg)\n\n#Calculation\na = a*10**-9; #width of box(m)\nE = (n**2)*(h**2)/(8*m*(a**2)); #energy of particle(J)\nE_eV = E/e; #energy of particle(eV)\nE_eV=math.ceil(E_eV*10)/10; #rounding off to 1 decimal\n\n#Result\nprint \"energy of particle is\",E,\"J or\",E_eV,\"eV\" ",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "energy of particle is 6.02231407794e-18 J or 37.6 eV\n"
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 4.7, Page number 120"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the minimum energy of an electron\n\n#importing modules\nimport math\n\n#Variable declaration\nn = 1; #lowest energy state\na = 4; #width of well(nm)\nh = 6.625*10**-34; #planck's constant\ne = 1.6025*10**-19; #conversion factor from J to eV\nm = 9.11*10**-31; #mass of electron(kg)\n\n#Calculation\na = a*10**-9; #width of box(m)\nE = (n**2)*(h**2)/(8*m*(a**2)); #energy of particle(J)\nE_eV = E/e; #energy of particle(eV)\nE_eV=math.ceil(E_eV*10**4)/10**4; #rounding off to 4 decimals\n\n#Result\nprint \"minimum energy of electron is\",E,\"J or\",E_eV,\"eV\" ",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "minimum energy of electron is 3.76394629871e-21 J or 0.0235 eV\n"
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 4.8, Page number 120"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the energy required to excite the electron\n\n#importing modules\nimport math\n\n#Variable declaration\nn1 = 1; #lowest energy state\nn2 = 6; #for 6th excited state\na = 0.1; #width of box(nm)\nh = 6.625*10**-34; #planck's constant\ne = 1.602*10**-19; #conversion factor from J to eV\nm = 9.11*10**-31; #mass of electron(kg)\n\n#Calculation\na = a*10**-9; #width of box(m)\nE1 = (n1**2)*(h**2)/(8*m*(a**2)); #energy of electron in ground state(J)\nE6 = (n2**2)*(h**2)/(8*m*(a**2)); #energy of electron in excited state(J)\nE = E6-E1; #energy required to excite the electron(J)\nE_eV = E/e; #energy required to excite the electron(eV)\nE_eV=math.ceil(E_eV*10)/10; #rounding off to 1 decimal\n\n#Result\nprint \"energy required to excite the electron is\",E,\"J or\",E_eV,\"eV\" \nprint \"answer for energy in eV given in the book is wrong\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "energy required to excite the electron is 2.10780992728e-16 J or 1315.8 eV\nanswer for energy in eV given in the book is wrong\n"
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 4.9, Page number 121"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the change in wavelength\n\n#importing modules\nimport math\n\n#Variable declaration\nh = 6.625*10**-34; #planck's constant\nc = 3*10**8; #velocity of light(m/sec)\nm0 = 9.11*10**-31; #rest mass of electron(kg)\nphi = 90; #angle of scattering(degrees)\nx = math.pi/180; #conversion factor from degrees to radians\n\n#Calculation\nphi = phi*x; ##angle of scattering(radian)\ndelta_lamda = h*(1-math.cos(phi))/(m0*c); #change in wavelength(m)\n\n#Result\nprint \"change in wavelength of X-ray photon is\",delta_lamda,\"m\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "change in wavelength of X-ray photon is 2.42407610684e-12 m\n"
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter5.ipynb b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter5.ipynb
new file mode 100755
index 00000000..57b4a5f8
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter5.ipynb
@@ -0,0 +1,175 @@
+{
+ "metadata": {
+ "name": "Chapter5"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Crystal Physics"
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 5.1, Page number 149"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the Miller indices\n\n#Calculation\n#The plane has intercepts a,2b,3c along 3 crystal axes\n#lattice points are r = pa+qb+sc\n#therefore p = 1 q = 2 s = 3\n#miller indices are [1/p,1/q,1/s]\n\n#Result\nprint \"lattice points are p = 1 q = 2 s = 3\"\nprint \"miller indices are [1/p,1/q,1/s] or [1,1/2,1/3] or [6,3,2]\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "lattice points are p = 1 q = 2 s = 3\nmiller indices are [1/p,1/q,1/s] or [1,1/2,1/3] or [6,3,2]\n"
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 5.2, Page number 150"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the density of Si\n\n#importing modules\nimport math\n\n#Variable declaration\nn = 8; #number of atoms per cell\na = 5.43*10**-8; #lattice constant(cm)\nw = 28.1; #atomic weight(gm)\nN = 6.02*10**23; #avagadro number\n\n#Calculation\nac = n/(a**3); #atomic concentration(atoms/cm**3)\nd = ac*w/N; #density of Si(g/cm**3)\nd=math.ceil(d*10**3)/10**3; #rounding off to 3 decimals\n\n#Result\nprint \"density of Si is\",d,\"g/cm**3\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "density of Si is 2.333 g/cm**3\n"
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 5.3, Page number 151"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the surface density of atoms\n\n#importing modules\nimport math\nfrom __future__ import division\n\n#Variable declaration\na = 5; #lattice constant(Angstrom)\n\n#Calculation\na = a*10**-10; #lattice constant(m)\n#to calculate the planar concentration, only equilateral triangular region is considered of length a*math.sqrt(2) and height a*math.sqrt(3/2)\nl = a*math.sqrt(2); #length of face diagonal(m)\nh = a*math.sqrt(3/2); #height of triangle(m)\nA = l*h/2; #area of shaded portion(m**2)\n#every atom at the corner contributes 1/6 to this area.\nn111 = (3/6)*(1/A); #planar concentration(atoms/m**2)\n\n#Result\nprint \"surface density of atoms is\",n111,\"atoms/m**2\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "surface density of atoms is 2.30940107676e+18 atoms/m**2\n"
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 5.4, Page number 152"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the spacing of planes\n\n#importing modules\nimport math\n\n#Variable declaration\na = 4.049; #lattice constant(Angstrom)\nh = 2;\nk = 2;\nl = 0; #miller indices of(2 2 0)\n\n#Calculation\nd = a/math.sqrt(h**2+k**2+l**2); #spacing of planes(Angstrom)\nd=math.ceil(d*10**3)/10**3; #rounding off to 3 decimals\n\n#Result\nprint \"spacing of planes is\",d,\"Angstrom\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "spacing of planes is 1.432 Angstrom\n"
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 5.5, Page number 152"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the size of unit cell\n\n#importing modules\nimport math\n\n#Variable declaration\nd110 = 2.03; #distance between planes(Angstrom)\nh = 1;\nk = 1;\nl = 0; #miller indices of(1 1 0)\n\n#Calculation\na = d110*math.sqrt(h**2+k**2+l**2); #size of unit cell(Angstrom)\na=math.ceil(a*10**3)/10**3; #rounding off to 3 decimals\n\n#Result\nprint \"size of unit cell is\",a,\"Angstrom\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "size of unit cell is 2.871 Angstrom\n"
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 5.6, Page number 152"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the spacing of planes\n\n#importing modules\nimport math\n\n#Variable declaration\na = 5.64; #lattice constant(Angstrom)\nh1 = 1;\nk1 = 0;\nl1 = 0; #miller indices of(1 0 0)\nh2 = 1;\nk2 = 1;\nl2 = 0; #miller indices of(1 1 0)\nh3 = 1;\nk3 = 1;\nl3 = 1; #miller indices of(1 1 1)\n\n#Calculation\nd100 = a/math.sqrt(h1**2+k1**2+l1**2); #spacing of planes[100](Angstrom)\nd110 = a/math.sqrt(h2**2+k2**2+l2**2); #spacing of planes[110](Angstrom)\nd111 = a/math.sqrt(h3**2+k3**2+l3**2); #spacing of planes[111](Angstrom)\nd111=math.ceil(d111*10**2)/10**2; #rounding off to 2 decimals\n\n#Result\nprint \"spacing of plane [100] is\",d100,\"Angstrom\"\nprint \"spacing of plane [110] is\",round(d110),\"Angstrom\"\nprint \"spacing of plane [111] is\",d111,\"Angstrom\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "spacing of plane [100] is 5.64 Angstrom\nspacing of plane [110] is 4.0 Angstrom\nspacing of plane [111] is 3.26 Angstrom\n"
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 5.7, Page number 153"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the volume of unit cell\n\n#importing modules\nimport math\n\n#Variable declaration\nr = 1.605; #radius of atom(Angstrom)\n\n\n#Calculation\nr = r*10**-10; #radius of atom(m)\na = 2*r; #size of unit cell(m)\nc = a*math.sqrt(8/3);\nV = 3*math.sqrt(3)*a**2*c/2; #volume of unit cell(m**3)\n\n#Result\nprint \"volume of unit cell is\",V,\"m**3\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "volume of unit cell is 1.40330266432e-28 m**3\n"
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter6.ipynb b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter6.ipynb
new file mode 100755
index 00000000..33260c42
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter6.ipynb
@@ -0,0 +1,364 @@
+{
+ "metadata": {
+ "name": "Chapter6"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Conducting Materials"
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.1, Page number 170"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the Fermi energy\n\n#importing modules\nimport math\n\n#Variable declaration\nm = 9.1*10**-31; #mass of electron\nvf = 1*10**6; #Fermi velocity(m/s)\ne = 1.6*10**-19; #conversion factor from J to eV\n\n#Calculation\nEF = m*(vf**2)/(2*e); #Fermi energy(eV)\nEF=math.ceil(EF*10**2)/10**2; #rounding off to 2 decimals\n\n#Result\nprint \"Fermi energy is\",EF,\"eV\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Fermi energy is 2.85 eV\n"
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.2, Page number 170"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the Fermi energy\n\n#importing modules\nimport math\n\n#Variable declaration\nEF0 = 7.04; #Fermi energy at 0K(eV)\nT = 300; #temperature(K)\nk = 1.38*10**-23; #boltzmann constant\ne = 1.6*10**-19; #conversion factor from J to eV\n\n#Calculation\nEF = EF0*(1-(((math.pi**2)/12)*(k*T/(EF0*e))**2)); #Fermi energy(eV)\nEF=math.ceil(EF*10**5)/10**5; #rounding off to 5 decimals\n\n#Result\nprint \"Fermi energy is\",EF,\"eV\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Fermi energy is 7.03993 eV\n"
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.3, Page number 171"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the conductivity\n\n#importing modules\nimport math\n\n#Variable declaration\nd = 2.7*10**3; #density of Al(kg/m**3)\nMat = 27; #atomic weight of Al\ntow = 10**-14; #relaxation time(sec)\nNa = 6.022*10**23; #avagadro constant\na = 3*10**3; #number of free electrons per atom\ne = 1.6*10**-19; #charge of electron\nme = 9.1*10**-31; #mass of electron\n\n#Calculation\nn = d*Na*a/Mat; #concentration of atoms(per m**3)\nsigma = n*e**2*tow/me; #conductivity(ohm m)\nsigma = sigma*10**-7;\nsigma=math.ceil(sigma*10**4)/10**4; #rounding off to 4 decimals\n\n#Result\nprint \"conductivity of Al is\",sigma,\"*10**7 ohm m\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "conductivity of Al is 5.0824 *10**7 ohm m\n"
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.4, Page number 171"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the Lorentz number\n\n#importing modules\nimport math\n\n#Variable declaration\nsigma = 5.87*10**7; #electrical conductivity(per ohm m)\nK = 390; #thermal conductivity(W/mK)\nT = 20; #temperature(C)\n\n#Calculation\nT = T+273; #temperature(K)\nL = K/(sigma*T); #Lorentz number(W ohm/K**2)\n\n#Result\nprint \"Lorentz number is\",L,\"W ohm/K**2\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Lorentz number is 2.26756051189e-08 W ohm/K**2\n"
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.5, Page number 172"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the electrical conductivity\n\n#importing modules\nimport math\n\n#Variable declaration\nd = 8900; #density of Cu(kg/m**3)\nMat = 63.5; #atomic weight of Cu\ntow = 10**-14; #relaxation time(sec)\nNa = 6.022*10**23; #avagadro constant\na = 1*10**3; #number of free electrons per atom\ne = 1.6*10**-19; #charge of electron\nme = 9.1*10**-31; #mass of electron\n\n#Calculation\nn = d*Na*a/Mat; #concentration of atoms(per m**3)\nsigma = n*e**2*tow/me; #electrical conductivity(ohm m)\nsigma = sigma*10**-7;\nsigma=math.ceil(sigma*10**4)/10**4; #rounding off to 4 decimals\n\n#Result\nprint \"electrical conductivity is\",sigma,\"*10**7 ohm m\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "electrical conductivity is 2.3745 *10**7 ohm m\n"
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.6, Page number 172"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the relaxation time, mobility of electrons, average drift, velocity and mean free path\n\n#importing modules\nimport math\n\n#Variable declaration\nrho = 1.54*10**-8; #resistivity(ohm m)\nEF = 5.5; #fermi energy(eV)\nme = 9.1*10**-31; #mass of electron\nepsilon = 100;\ne = 1.6*10**-19; #charge of electron\nn = 5.8*10**28; #concentration of electrons(per m**3)\n\n#Calculation\ntow = me/(rho*n*e**2); #relaxation time(sec)\nmew = e*tow/me; #mobility of electrons(m**2/Vs)\nmew = mew*10**3;\nvd = e*tow*epsilon/me; #drift velocity(m/s)\nvd=math.ceil(vd*10)/10; #rounding off to 1 decimal\nEF = EF*e; #fermi energy((J)\nvF = math.sqrt(2*EF/me); #fermi velocity(m/s)\nvf = vF*10**-6;\nvf=math.ceil(vf*10**3)/10**3; #rounding off to 3 decimals\nlamda_m = vF*tow; #mean free path(m)\n\n#Result\nprint \"relaxation time of electrons is\",tow,\"sec\"\nprint \"mobility of electrons is\",mew,\"*10**-3 m**2/Vs\"\nprint \"drift velocity of electrons is\",vd,\"m/s\"\nprint \"drift velocity given in the book is wrong\"\nprint \"fermi velocity of electrons is\",vf,\"*10**6 m/s\"\nprint \"mean free path is\",lamda_m,\"m\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "relaxation time of electrons is 3.97972178683e-14 sec\nmobility of electrons is 6.9973130318 *10**-3 m**2/Vs\ndrift velocity of electrons is 0.7 m/s\ndrift velocity given in the book is wrong\nfermi velocity of electrons is 1.391 *10**6 m/s\nmean free path is 5.53462691011e-08 m\n"
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.7, Page number 174"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the thermal conductivity\n\n#importing modules\nimport math\n\n#Variable declaration\nrho = 1.72*10**-8; #electrical resistivity(ohm m)\nL = 2.26*10**-8; #Lorentz number(ohm W/K**2)\nT = 27; #temperature(C)\n\n#Calculation\nT = T+273; #temperature(K)\nK = L*T/rho; #thermal conductivity(W/mK)\n\n#Result\nprint \"thermal conductivity is\",int(K),\"W/mK\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "thermal conductivity is 394 W/mK\n"
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.8, Page number 174"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the Lorentz number\n\n#importing modules\nimport math\n\n#Variable declaration\nsigma = 5.87*10**7; #electrical conductivity(per ohm m)\nK = 390; #thermal conductivity(W/mK)\nT = 20; #temperature(C)\n\n#Calculation\nT = T+273; #temperature(K)\nL = K/(sigma*T); #Lorentz number(W ohm/K**2)\n\n#Result\nprint \"Lorentz number is\",L,\"W ohm/K**2\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Lorentz number is 2.26756051189e-08 W ohm/K**2\n"
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.9, Page number 174"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the value of F(E)\n\n#importing modules\nimport math\n\n#Variable declaration\nE_EF = 0.01; #energy(eV)\ne = 1.6*10**-19; #conversion factor from eV to J\nT = 200; #temperature(K)\nk = 1.38*10**-23; #boltzmann constant(J/K)\n\n#Calculation\nE_EF = E_EF*e; #energy(J)\nA = E_EF/(k*T);\nFofE = 1/(1+(math.exp(A))); #value of F(E)\nFofE=math.ceil(FofE*10**2)/10**2; #rounding off to 2 decimals\n\n#Result\nprint \"value of F(E) is\",FofE",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "value of F(E) is 0.36\n"
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.10, Page number 175"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the electrical conductivity\n\n#importing modules\nimport math\n\n#Variable declaration\nlamda = 4*10**-8; #mean free path(m)\nn = 8.4*10**28; #density(per m**3)\nvthbar = 1.6*10**6; #average thermal velocity(m/s)\ne = 1.6*10**-19; #charge of electron(c)\nm = 9.11*10**-31; #mass of electron\n\n#Calculation\nsigma = n*e**2*lamda/(m*vthbar); #electrical conductivity(ohm-1 m-1)\nsigma = sigma*10**-7;\nsigma=math.ceil(sigma*100)/100; #rounding off to 2 decimals\n\n#Result\nprint \"electrical conductivity is\",sigma,\"*10**7 ohm-1 m-1\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "electrical conductivity is 5.91 *10**7 ohm-1 m-1\n"
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.11, Page number 176"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the electrical,thermal conductivity and Lorentz number\n\n#importing modules\nimport math\n\n#Variable declaration\ntow = 10**-14; #relaxation time(sec)\nT = 300; #temperature(K)\nn = 6*10**28; #electron concentration(per m**3)\ne = 1.6*10**-19; #charge of electron(c)\nme = 9.1*10**-31; #mass of electron\nk = 1.38*10**-23; #boltzmann constant(J/K)\n\n#Calculation\nsigma = n*e**2*tow/me; #electrical conductivity(ohm-1 m-1)\nsigmaa = sigma*10**-7;\nsigmaa=math.ceil(sigmaa*100)/100; #rounding off to 2 decimals\nK = 3*n*(k**2)*tow*T/(2*me); #thermal conductivity(W/mK)\nK=math.ceil(K*10)/10; #rounding off to 1 decimal\nL = K/(sigma*T); #Lorentz number(W ohm/K**2)\n\n#Result\nprint \"electrical conductivity is\",sigmaa,\"*10**7 ohm-1 m-1\"\nprint \"thermal conductivity is\",K,\"W/mK\"\nprint \"Lorentz number is\",L,\"W ohm/K**2\"\nprint \"answer for thermal conductivity and Lorentz number given in the book are wrong\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "electrical conductivity is 1.69 *10**7 ohm-1 m-1\nthermal conductivity is 56.6 W/mK\nLorentz number is 1.11775173611e-08 W ohm/K**2\nanswer for thermal conductivity and Lorentz number given in the book are wrong\n"
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.12, Page number 177"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the relaxation time\n\n#importing modules\nimport math\n\n#Variable declaration\nn = 5.8*10**28; #electron concentration(per m**3)\ne = 1.6*10**-19; #charge of electron(c)\nm = 9.1*10**-31; #mass of electron\nrho = 1.54*10**-8; #resistivity of metal(ohm m)\n\n#Calculation\ntow = m/(n*rho*e**2); #relaxation time(sec)\n\n#Result\nprint \"relaxation time is\",tow,\"sec\"\nprint \"answer given in the book is wrong\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "relaxation time is 3.97972178683e-14 sec\nanswer given in the book is wrong\n"
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.13, Page number 177"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the relaxation time, mobility of electrons, drift velocity \n\n#importing modules\nimport math\n\n#Variable declaration\nrho = 1.54*10**-8; #resistivity(ohm m)\nE = 1; #electric field(V/cm)\nme = 9.1*10**-31; #mass of electron\ne = 1.6*10**-19; #charge of electron\nn = 5.8*10**28; #concentration of electrons(per m**3)\n\n#Calculation\nE = E*10**2; #electric field(V/m)\ntow = me/(rho*n*e**2); #relaxation time(sec)\nvd = e*E*tow/me; #drift velocity(m/s)\nvd=math.ceil(vd*10)/10; #rounding off to 1 decimal\nmew = vd/E; #mobility of electrons(m**2/Vs)\nmew = mew*10**2;\n\n#Result\nprint \"relaxation time of electrons is\",tow,\"sec\"\nprint \"drift velocity of electrons is\",vd,\"m/s\"\nprint \"mobility of electrons is\",mew,\"*10**-2 m**2/Vs\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "relaxation time of electrons is 3.97972178683e-14 sec\ndrift velocity of electrons is 0.7 m/s\nmobility of electrons is 0.7 *10**-2 m**2/Vs\n"
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.14, Page number 178"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the drift velocity \n\n#importing modules\nimport math\n\n#Variable declaration\nT = 300; #temperature(K)\nl = 2; #length of wire(m)\nR = 0.02; #resistance(ohm)\nI = 15; #current(amp)\nmew = 4.3*10**-3; #mobility(m**2/Vs)\n\n#Calculation\nV = I*R; #voltage drop(V)\nE = V/l; #electric field(V/m)\nvd = mew*E; #drift velocity(m/s)\nvd = vd*10**3;\nvd=math.ceil(vd*100)/100; #rounding off to 2 decimals\n\n#Result\nprint \"drift velocity of electrons is\",vd,\"*10**-3 m/s\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "drift velocity of electrons is 0.65 *10**-3 m/s\n"
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.15, Page number 179"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the Fermi energy and Fermi temperature\n\n#importing modules\nimport math\n\n#Variable declaration\nvf = 0.86*10**6; #fermi velocity(m/s)\nm = 9.1*10**-31; #mass of electron(kg)\ne = 1.6*10**-19; #charge of electron(C)\nk = 1.38*10**-23; #boltzmann constant\n\n#Calculation\nEF = m*vf**2/(2*e); #fermi energy(eV)\nEF=math.ceil(EF*100)/100; #rounding off to 2 decimals\nTF = EF*e/k; #fermi temperature(K)\n\n#Result\nprint \"Fermi energy is\",EF,\"eV\"\nprint \"Fermi temperature is\",int(TF),\"K\"\nprint \"answer for fermi temperature given in the book is wrong due to rounding off the value of EF\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Fermi energy is 2.11 eV\nFermi temperature is 24463 K\nanswer for fermi temperature given in the book is wrong due to rounding off the value of EF\n"
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 6.16, Page number 179"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the Fermi velocity\n\n#importing modules\nimport math\n\n#Variable declaration\nTF = 2460; #fermi temperature(K)\nm = 9.11*10**-31; #mass of electron(kg)\nk = 1.38*10**-23; #boltzmann constant\n\n#Calculation\nvF = math.sqrt(2*k*TF/m); #fermi velocity(m/s)\nvF = vF*10**-5;\nvF=math.ceil(vF*10**3)/10**3; #rounding off to 3 decimals\n\n#Result\nprint \"Fermi velocity is\",vF,\"*10**5 m/s\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Fermi velocity is 2.731 *10**5 m/s\n"
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter7.ipynb b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter7.ipynb
new file mode 100755
index 00000000..4981fbf4
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter7.ipynb
@@ -0,0 +1,485 @@
+{
+ "metadata": {
+ "name": "Chapter7",
+ "signature": "sha256:043709ddd748250fcd3232cc251c6d71d665f281189e172a4c8d9b59233bdcee"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Semiconducting Materials"
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.1, Page number 208"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the approximate donor binding energy\n\n#importing modules\nimport math\n\n#Variable declaration\nme = 9.11*10**-31; #mass of electron(kg)\nepsilon_r = 13.2; \nepsilon0 = 8.85*10**-12;\nh = 6.63*10**-34;\ne = 1.6*10**-19; #charge of electron(C)\n\n#Calculation\nm_nc = 0.067*me;\nE = m_nc*e**4/(8*(epsilon0*epsilon_r*h)**2); #energy(J)\nE = E/e; #energy(eV)\nE = math.ceil(E*10**5)/10**5; #rounding off to 5 decimals\nE_meV = E*10**3; #energy(meV)\n\n#Result\nprint \"donor binding energy is\",E,\"eV or\",E_meV,\"meV\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "donor binding energy is 0.00521 eV or 5.21 meV\n"
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.2, Page number 208"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the equilibrium hole concentration\n\n#importing modules\nimport math\nimport numpy as np\n\n#Variable declaration\nNd = 10**16; #donor concentration(atoms/cm**3)\nni = 1.5*10**10; #concentration(per cm**3)\nT = 300; #temperature(K)\nkT = 0.0259;\n\n#Calculation\nn0 = Nd; #for Nd>>ni, assume n0=Nd\np0 = ni**2/n0; #equilibrium hole concentration(per cm**3)\np0 = p0*10**-4;\nEF_Ei = kT*np.log(n0/ni);\nEF_Ei = math.ceil(EF_Ei*10**4)/10**4; #rounding off to 4 decimals\n\n\n#Result\nprint \"equilibrium hole concentration is\",p0,\"*10**4 per cm**3\"\nprint \"value of EF-Ei is\",EF_Ei,\"eV\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "equilibrium hole concentration is 2.25 *10**4 per cm**3\nvalue of EF-Ei is 0.3474 eV\n"
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.3, Page number 209"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the resistivity of sample\n\n#importing modules\nimport math\n\n#Variable declaration\ne = 1.6*10**-19; #charge of electron(C)\nNd = 10**14; #donor density(atoms/cm**3)\nmew_n = 3900;\n\n#Calculation\nn = Nd;\nsigma = n*e*mew_n; #conductivity(ohm-1 cm-1)\nrho = 1/sigma; #resistivity(ohm cm)\nrho = math.ceil(rho*100)/100; #rounding off to 2 decimals\n\n\n#Result\nprint \"resistivity of sample is\",rho,\"ohm cm\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "resistivity of sample is 16.03 ohm cm\n"
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.4, Page number 209"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the resistivity, Hall coefficient and Hall voltage\n\n#importing modules\nimport math\n\n#Variable declaration\ne = 1.6*10**-19; #charge of electron(C)\nn0 = 5*10**16; #donor density(atoms/cm**3)\nmew_0 = 800;\nIx = 2; #current(mA)\nBz = 5*10**-5;\nd = 200; #thickness(micrometre)\n\n#Calculation\nIx = Ix*10**-3; #current(A)\nd = d*10**-4; #thickness(m)\nsigma = e*n0*mew_0; #conductivity(ohm-1 cm-1)\nrho = 1/sigma; #resistivity(ohm cm)\nrho = math.ceil(rho*10**4)/10**4; #rounding off to 4 decimals\nRH = -1/(e*n0); #Hall coefficient(cm**3/C)\nVH = Ix*Bz*RH/d; #Hall voltage(V)\nVH = VH*10**5;\n\n\n#Result\nprint \"resistivity of sample is\",rho,\"ohm cm\"\nprint \"Hall coefficient is\",RH,\"cm**3/C\"\nprint \"Hall voltage is\",VH,\"*10**-5 V\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "resistivity of sample is 0.1563 ohm cm\nHall coefficient is -125.0 cm**3/C\nHall voltage is -62.5 *10**-5 V\n"
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.5, Page number 210"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the intrinsic carrier concentration, intrinsic conductivity and resistivity\n\n#importing modules\nimport math\nfrom __future__ import division\n\n#Variable declaration\nT = 300; #temperature(K)\nmew_n = 0.4; #electron mobility(m**2/Vs)\nmew_p = 0.2; #hole mobility(m**2/Vs)\nEg = 0.7; #band gap(eV)\nme = 9.11*10**-31; #mass of electron(kg)\nk = 1.38*10**-23; #boltzmann constant\nT = 300; #temperature(K)\nh = 6.625*10**-34;\nkT = 0.0259;\ne = 1.6*10**-19; #charge of electron(C)\n\n#Calculation\nmn_star = 0.55*me; #electron effective mass(kg)\nmp_star = 0.37*me; #hole effective mass(kg)\na = (2*math.pi*k*T/(h**2))**(3/2);\nb = (mn_star*mp_star)**(3/4);\nc = math.exp(-Eg/(2*kT));\nni = 2*a*b*c; #intrinsic concentration(per m**3)\nsigma = ni*e*(mew_n+mew_p); #intrinsic conductivity(per ohm m)\nsigma = math.ceil(sigma*10**4)/10**4; #rounding off to 4 decimals\nrho = 1/sigma; #intrinsic resistivity(ohm m)\nrho = math.ceil(rho*10**4)/10**4; #rounding off to 4 decimals\n\n#Result\nprint \"intrinsic concentration is\",ni,\"per m**3\"\nprint \"intrinsic conductivity is\",sigma,\"per ohm m\"\nprint \"intrinsic resistivity is\",rho,\"ohm m\"\nprint \"answers given in the book are wrong\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "intrinsic concentration is 1.02825111151e+19 per m**3\nintrinsic conductivity is 0.9872 per ohm m\nintrinsic resistivity is 1.013 ohm m\nanswers given in the book are wrong\n"
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.6, Page number 211"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the Fermi energy\n\n#importing modules\nimport math\nimport numpy as np\nfrom __future__ import division\n\n#Variable declaration\nNd = 10**16; #donor concentration(per cm**3)\nni = 1.45*10**10; #concentration(per cm**3)\nkT = 0.0259;\n\n#Calculation\n#ni = Nc*math.exp(-(Ec-Ei)/kT)\n#Nd = Nc*(math.exp(-(Ec-Efd)/kT)\n#dividing Nd/ni we get \nEFd_Ei = kT*np.log(Nd/ni);\nEFd_Ei = math.ceil(EFd_Ei*10**4)/10**4; #rounding off to 4 decimals\n\n#Result\nprint \"Fermi energy is\",EFd_Ei,\"eV\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Fermi energy is 0.3482 eV\n"
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.7, Page number 211"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the resistance\n\n#The given information in the question is not sufficient to solve the entire problem. And the problem is completely wrong in the book",
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.8, Page number 212"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the forbidden energy gap\n\n#importing modules\nimport math\nimport numpy as np\nfrom __future__ import division\n\n#Variable declaration\nT = 300; #temperature(K)\nmew_n = 0.36; #electron mobility(m**2/Vs)\nmew_p = 0.17; #hole mobility(m**2/Vs)\nrho = 2.12; #resistivity(ohm m)\nme = 9.11*10**-31; #mass of electron(kg)\nkT = 0.0259;\nh = 6.625*10**-34;\nk = 1.38*10**-23; #boltzmann constant\ne = 1.6*10**-19; #charge of electron(C)\n\n#Calculation\nmn_star = 0.55*me; #electron effective mass(kg)\nmp_star = 0.37*me; #hole effective mass(kg)\nsigma = 1/rho; #conductivity(per ohm m)\nsigma = math.ceil(sigma*10**3)/10**3; #rounding off to 3 decimals\nni = sigma/(e*(mew_n+mew_p)); #concentration of electrons(per m**3)\na = (2*math.pi*kT/(h**2))**(3/2);\nNc = 2*a*(mn_star**(3/2)); \nNv = 2*a*(mp_star**(3/2)); \nb = (Nc*Nv)**(1/2);\nEg = 2*kT*np.log(b/ni);\n\n#Result\nprint \"forbidden energy gap is\",Eg,\"eV\"\nprint \"answer given in the book is wrong\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "forbidden energy gap is 4.09465494989 eV\nanswer given in the book is wrong\n"
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.9, Page number 213"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the conductivity\n\n#importing modules\nimport math\n\n#Variable declaration\nni = 2.4*10**19; #concentration(per m**3)\nmew_n = 0.39; #electron mobility(m**2/Vs)\nmew_p = 0.19; #hole mobility(m**2/Vs)\ne = 1.6*10**-19; #charge of electron(C)\n\n#Calculation\nsigma = ni*e*(mew_n+mew_p); #conductivity(per ohm m)\nsigma = math.ceil(sigma*10**3)/10**3; #rounding off to 3 decimals\n\n#Result\nprint \"conductivity of sample is\",sigma,\"ohm-1 m-1\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "conductivity of sample is 2.228 ohm-1 m-1\n"
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.10, Page number 214"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the new position of Fermi level\n\n#importing modules\nimport math\nfrom __future__ import division\n\n#Variable declaration\nEc = 0.3; #initial position(eV)\nT1 = 300; #initial temperature(K)\nT2 = 330; #increased temperature\n\n#Calculation\n#Ec/T1 = Ec_EF330/T2\nEc_EF330 = Ec*T2/T1; #new position of Fermi level(eV)\n\n#Result\nprint \"new position of Fermi level is\",Ec_EF330,\"eV\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "new position of Fermi level is 0.33 eV\n"
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.11, Page number 214"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the concentration in conduction band\n\n#importing modules\nimport math\nfrom __future__ import division\n\n#Variable declaration\nk = 1.38*10**-23; #boltzmann constant\nT = 300; #temperature(K)\nme = 9.1*10**-31; #mass of electron(kg)\nh = 6.63*10**-34; #planck's constant\nEc_Ev = 1.1; #energy gap(eV)\ne = 1.6*10**-19; #charge of electron(C)\n\n#Calculation\nme_star = 0.31*me;\nA = (2*math.pi*k*T*me_star/(h**2))**(3/2);\nB = math.exp(-(Ec_Ev*e)/(2*k*T));\nni = A*B; #concentration in conduction band(per m**3)\n\n#Result\nprint \"intrinsic electron concentration is\",ni,\"per m**3\"\nprint \"answer given in the book is wrong\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "intrinsic electron concentration is 1.26605935487e+15 per m**3\nanswer given in the book is wrong\n"
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.12, Page number 214"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the drift mobility of electrons\n\n#importing modules\nimport math\n\n#Variable declaration\nRH = 0.55*10**-10; #Hall coefficient(m**3/As)\nsigma = 5.9*10**7; #conductivity(ohm-1 m-1)\n\n#Calculation\nmew = RH*sigma; #drift mobility(m**2/Vs)\nmew = mew*10**3;\nmew = math.ceil(mew*10**2)/10**2; #rounding off to 2 decimals\n\n#Result\nprint \"drift mobility of electrons is\",mew,\"*10**-3 m**2/Vs\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "drift mobility of electrons is 3.25 *10**-3 m**2/Vs\n"
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.13, Page number 215"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the concentration and average number of electrons\n\n#importing modules\nimport math\nfrom __future__ import division\n\n#Variable declaration\nA = 6.022*10**23; #avagadro constant\nd = 8.96*10**-9; #density(kg/m**3)\nn = 9.932*10**14; #no. of free electrons per atom\nsigma = 5.9*10**7; #conductivity(ohm-1 m-1)\ne = 1.6*10**-19; #electron charge(C)\nmew = 3.2*10**-3; #drift mobility(m**2/Vs)\nw = 63.5; #atomic weight of Cu(kg)\n\n#Calculation\nni = sigma/(mew*e); #conductivity(per m**3)\nN = A*d*n/w; #concentration of free electrons in pure Cu\nAN = ni/N; #average number of electrons contributed per Cu atom\n\n#Result\nprint \"concentration of free electrons in pure Cu is\",N,\"per m**3\"\nprint \"average number of electrons contributed per Cu atom is\",int(AN)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "concentration of free electrons in pure Cu is 8.43940339906e+28 per m**3\naverage number of electrons contributed per Cu atom is 1\n"
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.14, Page number 215"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the charge carrier density and electron mobility\n\n#importing modules\nimport math\nfrom __future__ import division\n\n#Variable declaration\nRH = 3.66*10**-11; #hall coefficient(m**3/As)\ne = 1.6*10**-19; #electron charge(C)\nsigma = 112*10**7; #conductivity(ohm-1 m-1)\n\n#Calculation\nn = 1/(e*RH); #charge carrier density(per m**3)\nmew_n = sigma/(n*e); #electron mobility(m**2/As)\nmew_n = math.ceil(mew_n*10**3)/10**3; #rounding off to 3 decimals\n\n#Result\nprint \"charge carrier density is\",n,\"per m**3\"\nprint \"electron mobility is\",mew_n,\"m**2/As\"\nprint \"answers given in the book are wrong\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "charge carrier density is 1.70765027322e+29 per m**3\nelectron mobility is 0.041 m**2/As\nanswers given in the book are wrong\n"
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.15, Page number 216"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the magnitude of Hall voltage\n\n#importing modules\nimport math\nfrom __future__ import division\n\n#Variable declaration\ne = 1.6*10**-19; #electron charge(C)\nB = 1.5; #magnetic field(T)\nI = 50; #current(Amp)\nn = 8.4*10**28; #free electron concentration(per m**3)\nd = 0.2; #thickness of slab(cm)\n\n#Calculation\nd = d*10**-2; #thickness of slab(m)\nVH = B*I/(n*e*d); #hall voltage(V)\n\n#Result\nprint \"magnitude of Hall voltage is\",VH,\"V\"\nprint \"answer given in the book is wrong\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "magnitude of Hall voltage is 2.79017857143e-06 V\nanswer given in the book is wrong\n"
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.16, Page number 216"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the resistance of intrinsic Ge rod\n\n#importing modules\nimport math\nfrom __future__ import division\n\n#Variable declaration\ne = 1.6*10**-19; #electron charge(C)\nn = 2.5*10**19; #free electron concentration(per m**3)\nmew_n = 0.39; #electron mobility(m**2/Vs)\nmew_p = 0.19; #hole mobility(m**2/Vs)\nL = 1; #length(cm)\nw = 1; #width(mm)\nt = 1; #thickness(mm)\n\n#Calculation\nL = L*10**-2; #length(m)\nw = w*10**-3; #width(m)\nt = t*10**-3; #thickness(m)\nA = w*t; #area(m**2)\nsigma = n*e*(mew_n+mew_p); #conductivity(ohm-1 m-1)\nR = L/(sigma*A); #resistance(ohm)\n\n#Result\nprint \"resistance of intrinsic Ge rod is\",int(R),\"ohm\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "resistance of intrinsic Ge rod is 4310 ohm\n"
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.17, Page number 216"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To determine the position of Fermi level\n\n#importing modules\nimport math\nimport numpy as np\nfrom __future__ import division\n\n#Variable declaration\ne = 1.6*10**-19; #electron charge(C)\nEg = 1.12; #band gap(eV)\nme = 1;\nmn_star = 0.12*me; #electron mobility(m**2/Vs)\nmp_star = 0.28*me; #hole mobility(m**2/Vs)\nk = 1.38*10**-23; #boltzmann constant\nT = 300; #temperature\n\n#Calculation\na = mp_star/mn_star;\nEF = (Eg/2)+((3*k*T/(4*e))*np.log(a));\nEF = math.ceil(EF*10**3)/10**3; #rounding off to 3 decimals\n\n#Result\nprint \"position of Fermi level is\",EF,\"eV\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "position of Fermi level is 0.577 eV\n"
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.18, Page number 217"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the electrical conductivity\n\n#importing modules\nimport math\n\n#Variable declaration\ne = 1.6*10**-19; #electron charge(C)\nni = 1.5*10**16; #intrinsic carrier density(per m**3)\nmew_n = 0.13; #electron mobility(m**2/Vs)\nmew_p = 0.05; #hole mobility(m**2/Vs)\n\n#Calculation\nsigma = ni*e*(mew_n+mew_p); #electrical conductivity\nsigma = sigma*10**4;\n\n#Result\nprint \"electrical conductivity is\",sigma,\"*10**-4 ohm-1 m-1\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "electrical conductivity is 4.32 *10**-4 ohm-1 m-1\n"
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.19, Page number 217"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the intrinsic resistivity\n\n#importing modules\nimport math\nfrom __future__ import division\n\n#Variable declaration\ne = 1.6*10**-19; #electron charge(C)\nni = 2.15*10**-13; #intrinsic carrier density(per cm**3)\nmew_n = 3900; #electron mobility(cm**2/Vs)\nmew_p = 1900; #hole mobility(cm**2/Vs)\n\n#Calculation\nsigmai = ni*e*(mew_n+mew_p); #electrical conductivity(ohm-1 cm-1)\nrhoi = 1/sigmai; #intrinsic resistivity(ohm cm)\n\n#Result\nprint \"intrinsic resistivity is\",rhoi,\"ohm cm\"\nprint \"answer given in the book is wrong\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "intrinsic resistivity is 5.01202886929e+27 ohm cm\nanswer given in the book is wrong\n"
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.20, Page number 217"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the electrical conductivity\n\n#importing modules\nimport math\n\n#Variable declaration\ne = 1.6*10**-19; #electron charge(C)\nni = 2.1*10**19; #intrinsic carrier density(per m**3)\nmew_n = 0.4; #electron mobility(m**2/Vs)\nmew_p = 0.2; #hole mobility(m**2/Vs)\n\n#Calculation\nsigma = ni*e*(mew_n+mew_p); #electrical conductivity\n\n#Result\nprint \"intrinsic resistivity is\",sigma,\"ohm-1 m-1\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "intrinsic resistivity is 2.016 ohm-1 m-1\n"
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.21, Page number 218"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the Hall coefficient and electron mobility\n\n#importing modules\nimport math\n\n#Variable declaration\ne = 1.6*10**-19; #electron charge(C)\nV = 1.35; #voltage supply(V)\nI = 5; #current(mA)\nb = 5; #breadth(mm)\nd = 1; #thickness(mm)\nL = 1; #length(cm)\nH = 0.45; #magnetic field(Wb/m**2)\nVy =20; #Hall voltage(mV)\n\n#Calculation\nVy = Vy*10**-3; #Hall voltage(V)\nL = L*10**-2; #length(m)\nd = d*10**-3; #thickness(m)\nb = b*10**-3; #breadth(m)\nI = I*10**-3; #current(A)\nR = V/I; #resistance(ohm)\nA = b*d; #area(m**2)\nrho = R*A/L; #resistivity(ohm m)\nEy = Vy/d; #Hall field(V/m)\nJx = I/A; \na = Ey/(H*Jx); #current density(m**3/C).Here a is 1/ne \nRH = a; #Hall coefficient(m**3/C)\nRH = math.ceil(RH*10**4)/10**4; #rounding off to 4 decimals\nmew_n = RH/rho; #electron mobility(m**2/Vs)\nmew_n = math.ceil(mew_n*10**2)/10**2; #rounding off to 2 decimals\n\n#Result\nprint \"Hall coefficient is\",RH,\"m**3/C\"\nprint \"electron mobility is\",mew_n,\"m**2/Vs\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Hall coefficient is 0.0445 m**3/C\nelectron mobility is 0.33 m**2/Vs\n"
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 7.22, Page number 219"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the Hall potential difference\n\n#importing modules\nimport math\n\n#Variable declaration\ne = 1.6*10**-19; #electron charge(C)\nIx = 200; #current(A)\nBz = 1.5; #magnetic field(Wb/m**2)\np = 8.4*10**28; #electron concentration(per m**3)\nd = 1; #thickness(mm)\n\n#Calculation\nd = d*10**-3; #thickness(m)\nVH = Ix*Bz/(e*p*d); #Hall potential(V)\nVH = VH*10**6; #Hall potential(micro V)\n\n#Result\nprint \"Hall potential is\",int(VH),\"micro V\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Hall potential is 22 micro V\n"
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter8.ipynb b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter8.ipynb
new file mode 100755
index 00000000..00903a6d
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter8.ipynb
@@ -0,0 +1,133 @@
+{
+ "metadata": {
+ "name": "Chapter8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Magnetic Materials"
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 8.1, Page number 238"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the magnitude and direction of magnetic moment\n\n#importing modules\nimport math\n\n#Variable declaration\nI = 12; #current(Ampere)\nA = 7.5*10**-4 #area of loop(m**2)\n\n#Calculation\nM = I*A; #magnetic moment(Am**2)\nM = M*10**3;\n\n#Result\nprint \"magnetic moment is\",M,\"*10**-3 Am**2\"\nprint \"M is directed away from the observer and is perpendicular to the plane of the loop\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "magnetic moment is 9.0 *10**-3 Am**2\nM is directed away from the observer and is perpendicular to the plane of the loop\n"
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 8.2, Page number 238"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the magnetic moment\n\n#importing modules\nimport math\n\n#Variable declaration\nr = 0.5; #radius of orbit(Angstrom)\ne = 1.6*10**-19; #charge of electron(C)\nnew = 10**16; #frequency(rps)\n\n#Calculation\nr = r*10**-10; #radius of orbit(m)\nI = e*new; #current(Ampere)\nA = math.pi*r**2; #area enclosed(m**2)\nM = I*A; #magnetic moment(Am**2)\n\n#Result\nprint \"magnetic moment is\",M,\"Am**2\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "magnetic moment is 1.25663706144e-23 Am**2\n"
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 8.3, Page number 239"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the magnetic susceptibility\n\n#importing modules\nimport math\n\n#Variable declaration\nmew_r = 5000; #relative permeability\n\n#Calculation\nchi_m = mew_r-1; #magnetic susceptibility\n\n#Result\nprint \"magnetic susceptibility is\",chi_m",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "magnetic susceptibility is 4999\n"
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 8.4, Page number 239"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the permeability\n\n#importing modules\nimport math\n\n#Variable declaration\nH = 1800; #magnetic field(A/m)\nphi = 3*10**-5; #magnetic flux(Wb)\nA = 0.2; #cross sectional area(cm**2)\n\n#Calculation\nA = A*10**-4; #cross sectional area(m**2)\nB = phi/A; #magnetic flux density(Wb/m**2)\nmew = B/H; #permeability(H/m)\nmew = mew*10**4;\nmew=math.ceil(mew*100)/100; #rounding off to 2 decimals\n\n#Result\nprint \"permeability is\",mew,\"*10**-4 H/m\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "permeability is 8.34 *10**-4 H/m\n"
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 8.5, Page number 239"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the magnetic moment\n\n#importing modules\nimport math\n\n#Variable declaration\nB = 0.65; #magnetic induction(Wb/m**2)\nrho = 8906; #density(kg/m**3)\nM = 58.7; #atomic weight\nmew0 = 4*math.pi*10**-7;\nmb = 9.27*10**-24;\nNa = 6.023*10**26; #avagadro constant\n\n#Calculation\nN = rho*Na/M; #number of atoms per unit volume(atoms/m**3)\nmew_r = B/(N*mew0); #relative permeability(A/m**2)\nM = mew_r/mb; #magnetic moment in mew_B \nM=math.ceil(M*10**3)/10**3; #rounding off to 3 decimals\n\n#Result\nprint \"magnetic moment is\",M,\"mew_B\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "magnetic moment is 0.611 mew_B\n"
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter9.ipynb b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter9.ipynb
new file mode 100755
index 00000000..3a5ba4c1
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/Chapter9.ipynb
@@ -0,0 +1,70 @@
+{
+ "metadata": {
+ "name": "Chapter9"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Superconducting Materials"
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 9.1, Page number 255"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the critical magnetic field intensity\n\n#importing modules\nimport math\n\n#Variable declaration\nH0 = 6.5*10**4; #magnetic field intensity(A/m)\nT = 4.2; #temperature(K)\nTc = 7.18; #critical temperature(K)\n\n#Calculation\nHc = H0*(1-((T**2)/(Tc**2))); #critical magnetic field intensity(A/m)\nHc = Hc*10**-4;\nHc=math.ceil(Hc*10**3)/10**3; #rounding off to 3 decimals\n\n#Result\nprint \"critical magnetic field intensity is\",Hc,\"*10**4 A/m\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "critical magnetic field intensity is 4.276 *10**4 A/m\n"
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 9.2, Page number 255"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#To calculate the isotopic mass\n\n#importing modules\nimport math\n\n#Variable declaration\nTc1 = 4.185; #critical temperature for M1(K)\nTc2 = 4.133; #critical temperature for M2(K)\nM1 = 199.5; #isotopic mass\nalpha = 0.5;\n\n#Calculation\nA = math.pow(M1,alpha)*Tc1/Tc2;\nM2 = math.pow(A,1/alpha); #isotopic mass\nM2=math.ceil(M2*10**3)/10**3; #rounding off to 3 decimals\n\n#Result\nprint \"isotopic mass is\",M2\nprint \"answer given in the book is wrong\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "isotopic mass is 204.552\nanswer given in the book is wrong\n"
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/screenshots/screen1.png b/Engineering_Physics_by_Bhattacharya_Bhaskaran/screenshots/screen1.png
new file mode 100755
index 00000000..cccb5c17
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/screenshots/screen1.png
Binary files differ
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/screenshots/screen2.png b/Engineering_Physics_by_Bhattacharya_Bhaskaran/screenshots/screen2.png
new file mode 100755
index 00000000..23204984
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/screenshots/screen2.png
Binary files differ
diff --git a/Engineering_Physics_by_Bhattacharya_Bhaskaran/screenshots/screen3.png b/Engineering_Physics_by_Bhattacharya_Bhaskaran/screenshots/screen3.png
new file mode 100755
index 00000000..25a9f874
--- /dev/null
+++ b/Engineering_Physics_by_Bhattacharya_Bhaskaran/screenshots/screen3.png
Binary files differ
diff --git a/Engineering_Physics/Chapter1.ipynb b/Engineering_Physics_by_PV_Naik/Chapter1.ipynb
index aec285c1..aec285c1 100755
--- a/Engineering_Physics/Chapter1.ipynb
+++ b/Engineering_Physics_by_PV_Naik/Chapter1.ipynb
diff --git a/Engineering_Physics/Chapter10.ipynb b/Engineering_Physics_by_PV_Naik/Chapter10.ipynb
index 7a9d784a..7a9d784a 100755
--- a/Engineering_Physics/Chapter10.ipynb
+++ b/Engineering_Physics_by_PV_Naik/Chapter10.ipynb
diff --git a/Engineering_Physics/Chapter11.ipynb b/Engineering_Physics_by_PV_Naik/Chapter11.ipynb
index 39762859..39762859 100755
--- a/Engineering_Physics/Chapter11.ipynb
+++ b/Engineering_Physics_by_PV_Naik/Chapter11.ipynb
diff --git a/Engineering_Physics/Chapter13.ipynb b/Engineering_Physics_by_PV_Naik/Chapter13.ipynb
index 83323d13..83323d13 100755
--- a/Engineering_Physics/Chapter13.ipynb
+++ b/Engineering_Physics_by_PV_Naik/Chapter13.ipynb
diff --git a/Engineering_Physics/Chapter2.ipynb b/Engineering_Physics_by_PV_Naik/Chapter2.ipynb
index b527497e..b527497e 100755
--- a/Engineering_Physics/Chapter2.ipynb
+++ b/Engineering_Physics_by_PV_Naik/Chapter2.ipynb
diff --git a/Engineering_Physics/Chapter4.ipynb b/Engineering_Physics_by_PV_Naik/Chapter4.ipynb
index f4145c55..f4145c55 100755
--- a/Engineering_Physics/Chapter4.ipynb
+++ b/Engineering_Physics_by_PV_Naik/Chapter4.ipynb
diff --git a/Engineering_Physics/Chapter5.ipynb b/Engineering_Physics_by_PV_Naik/Chapter5.ipynb
index d125b365..d125b365 100755
--- a/Engineering_Physics/Chapter5.ipynb
+++ b/Engineering_Physics_by_PV_Naik/Chapter5.ipynb
diff --git a/Engineering_Physics/Chapter6.ipynb b/Engineering_Physics_by_PV_Naik/Chapter6.ipynb
index 271f7718..271f7718 100755
--- a/Engineering_Physics/Chapter6.ipynb
+++ b/Engineering_Physics_by_PV_Naik/Chapter6.ipynb
diff --git a/Engineering_Physics/Chapter7.ipynb b/Engineering_Physics_by_PV_Naik/Chapter7.ipynb
index 36caeba7..36caeba7 100755
--- a/Engineering_Physics/Chapter7.ipynb
+++ b/Engineering_Physics_by_PV_Naik/Chapter7.ipynb
diff --git a/Engineering_Physics/Chapter8.ipynb b/Engineering_Physics_by_PV_Naik/Chapter8.ipynb
index b3ec194e..b3ec194e 100755
--- a/Engineering_Physics/Chapter8.ipynb
+++ b/Engineering_Physics_by_PV_Naik/Chapter8.ipynb
diff --git a/Engineering_Physics/Chapter9.ipynb b/Engineering_Physics_by_PV_Naik/Chapter9.ipynb
index 29c8edee..29c8edee 100755
--- a/Engineering_Physics/Chapter9.ipynb
+++ b/Engineering_Physics_by_PV_Naik/Chapter9.ipynb
diff --git a/Engineering_Physics_by_PV_Naik/screenshots/chapter1.png b/Engineering_Physics_by_PV_Naik/screenshots/chapter1.png
new file mode 100755
index 00000000..a1439bda
--- /dev/null
+++ b/Engineering_Physics_by_PV_Naik/screenshots/chapter1.png
Binary files differ
diff --git a/Engineering_Physics_by_PV_Naik/screenshots/chapter11.png b/Engineering_Physics_by_PV_Naik/screenshots/chapter11.png
new file mode 100755
index 00000000..fd1ee9f2
--- /dev/null
+++ b/Engineering_Physics_by_PV_Naik/screenshots/chapter11.png
Binary files differ
diff --git a/Engineering_Physics_by_PV_Naik/screenshots/chapter5.png b/Engineering_Physics_by_PV_Naik/screenshots/chapter5.png
new file mode 100755
index 00000000..72b99b17
--- /dev/null
+++ b/Engineering_Physics_by_PV_Naik/screenshots/chapter5.png
Binary files differ
diff --git a/Engineering_Physics_by_Rajendran/Chapter1.ipynb b/Engineering_Physics_by_Rajendran/Chapter1.ipynb
new file mode 100755
index 00000000..3f1a5138
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter1.ipynb
@@ -0,0 +1,492 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:be338ef971644a9f5f4678fb763a92b7fd97bf3ce5a24c5818759072b8dab2d8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "1: Elasticity"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.1, Page number 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "L=3; #length of wire(m)\n",
+ "A=6.25*10**-5; #cross sectional area(m**2)\n",
+ "delta_L=3*10**-3; #increase in length(m)\n",
+ "F=1.2*10**3; #force(N)\n",
+ "\n",
+ "#Calculation\n",
+ "Y=F*L/(A*delta_L); #young's modulus(N/m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"young's modulus is \",Y/10**10,\"*10**10 N/m**2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "young's modulus is 1.92 *10**10 N/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.2, Page number 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Y=2*10**11; #young's modulus(N/m**2)\n",
+ "L=2.75; #length of wire(m)\n",
+ "d=1*10**-3; #diameter(m)\n",
+ "M=1; #applied load(kg)\n",
+ "g=9.8; #acceleration due to gravity(N)\n",
+ "\n",
+ "#Calculation\n",
+ "T=M*g; #tension(N)\n",
+ "delta_L=T*L/(math.pi*(d/2)**2*Y); #increase in length of wire(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"increase in length of wire is\",round(delta_L*10**4,5),\"*10**-4 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "increase in length of wire is 1.71569 *10**-4 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.3, Page number 31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "F=0.3; #force(N)\n",
+ "d=5*10**-3; #displacement(m)\n",
+ "L=6*10**-2; #length of solid(m)\n",
+ "B=6*10**-2; #breadth of solid(m)\n",
+ "h=2*10**-2; #height of solid(m)\n",
+ "\n",
+ "#Calculation\n",
+ "s=F/(L*B); #shear stress(N/m**2)\n",
+ "theta=d/h; #shear strain\n",
+ "rm=s/theta; #rigidity modulus(N/m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"shear stress is\",round(s,2),\"N/m**2\"\n",
+ "print \"shear strain is\",theta\n",
+ "print \"rigidity modulus is\",round(rm,2),\"N/m**2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "shear stress is 83.33 N/m**2\n",
+ "shear strain is 0.25\n",
+ "rigidity modulus is 333.33 N/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.4, Page number 32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=2.5*10**10; #rigidity modulus(N/m**2)\n",
+ "L=30*10**-2; #thickness(m)\n",
+ "A=12*10**-4; #surface area(m**2)\n",
+ "delta_L=1.5*10**-2; #displacement(m)\n",
+ "\n",
+ "#Calculation\n",
+ "F=n*A*delta_L/L; #shearing force(N)\n",
+ "\n",
+ "#Result\n",
+ "print \"shearing force is\",F/10**6,\"*10**6 N\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "shearing force is 1.5 *10**6 N\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.6, Page number 33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Y=7.25*10**10; #young's modulus of silver(N/m**2)\n",
+ "K=11*10**10; #bulk modulus of silver(N/m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "sigma=(3*K-Y)/(6*K); #poisson's ratio\n",
+ "\n",
+ "#Result\n",
+ "print \"poisson's ratio is\",round(sigma,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "poisson's ratio is 0.39\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.7, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "L=3; #length of Cu wire(m)\n",
+ "Y=12.5*10**10; #young's modulus(N/m**2)\n",
+ "r=5*10**-4; #radius of wire(m)\n",
+ "sigma=0.26; #poisson's ratio\n",
+ "m=10; #load(kg)\n",
+ "g=9.8; #acceleration due to gravity(N)\n",
+ "\n",
+ "#Calculation\n",
+ "delta_L=m*g*L/(math.pi*r**2*Y); #extension produced(m)\n",
+ "ls=sigma*delta_L/3; #lateral strain\n",
+ "dd=ls*r*2; #decrease in diameter(m) \n",
+ "\n",
+ "#Result\n",
+ "print \"extension produced is\",round(delta_L*10**3,2),\"*10**-3 m\"\n",
+ "print \"lateral compression produced is\",round(dd*10**7,3),\"*10**-7 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "extension produced is 2.99 *10**-3 m\n",
+ "lateral compression produced is 2.595 *10**-7 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.8, Page number 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "L=1; #length of wire(m)\n",
+ "d=1*10**-3; #diameter of wire(m)\n",
+ "n=2.8*10**10; #rigidity modulus of wire(N/m**2)\n",
+ "theta=math.pi/2; #angle of twisting(radian)\n",
+ "\n",
+ "#Calculation\n",
+ "C=math.pi**2*n*(d/2)**4/(4*L); #couple to be applied(Nm)\n",
+ "\n",
+ "#Result\n",
+ "print \"couple to be applied is\",round(C*10**3,5),\"*10**-3 Nm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "couple to be applied is 4.31795 *10**-3 Nm\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.9, Page number 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "d=0.82*10**-3; #diameter of wire(m)\n",
+ "delta_L=1*10**-3; #length of elongation produced(m)\n",
+ "m=0.33; #load(kg)\n",
+ "g=9.8; #acceleration due to gravity(N)\n",
+ "n=2.2529*10**9; #rigidity modulus of wire(N/m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "Y=m*g/(math.pi*(d/2)**2*delta_L); #young's modulus(N/m**2)\n",
+ "sigma=(Y/(2*n))-1; #poisson's ratio\n",
+ "\n",
+ "#Result\n",
+ "print \"poisson's ratio is\",round(sigma,3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "poisson's ratio is 0.359\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.10, Page number 36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "p1=1.01*10**5; #atmospheric pressure(N/m**2)\n",
+ "K=16*10**10; #bulk modulus(N/m**2)\n",
+ "p2=10**2; #increased pressure(N/m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "dP=p1-p2; #change in pressure(N/m**2)\n",
+ "dV=dP/K; #fractional change of volume\n",
+ "\n",
+ "#Result\n",
+ "print \"change in volume of steel bar is\",round(dV*10**7,1),\"*10**-7 V m**3\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "change in volume of steel bar is 6.3 *10**-7 V m**3\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.11, Page number 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Y=1.013*10**10; #young's modulus of bar(N/m**2)\n",
+ "b=2*10**-2; #breadth of bar(m)\n",
+ "l=1; #length of bar(m)\n",
+ "d=1*10**-2; #depth of bar(m)\n",
+ "m=2; #load(kg)\n",
+ "g=9.8; #acceleration due to gravity(N)\n",
+ "\n",
+ "#Calculation\n",
+ "y=m*g*l**3/(4*Y*b*d**3); #depression produced in bar(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"depression produced in bar is\",round(y,6),\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "depression produced in bar is 0.024186 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.12, Page number 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "r=1.2*10**-2; #radius of cantilever(m)\n",
+ "l=1.5; #length of cantilever(m)\n",
+ "Y=19.5*10**10; #young's modulus(N/m**2)\n",
+ "m=2; #load(kg)\n",
+ "g=9.8; #acceleration due to gravity(N)\n",
+ "\n",
+ "#Calculation\n",
+ "y=4*m*g*l**3/(3*Y*math.pi*(r**4)); #depression produced in cantilever(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"depression produced in cantilever is\",round(y*10**3,3),\"*10**-3 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "depression produced in cantilever is 6.943 *10**-3 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter11.ipynb b/Engineering_Physics_by_Rajendran/Chapter11.ipynb
new file mode 100755
index 00000000..3f04726e
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter11.ipynb
@@ -0,0 +1,288 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c3dcf79a03b4887493b03eb7567c9289353e41ba9f42b1e11e4742e5d995690d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "11: Laser"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 11.1, Page number 33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda=590*10**-9; #wavelength of sodium D line(m)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "c=3*10**8; #velocity of light(m/s)\n",
+ "e=1.602*10**-19; #charge of electron(eV)\n",
+ "\n",
+ "#Calculation\n",
+ "E=h*c/lamda; #energy of 1st excited state(J)\n",
+ "E=E/e; #energy of 1st excited state(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"energy of 1st excited state is\",round(E,1),\"eV\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "energy of 1st excited state is 2.1 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 11.2, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=250+273; #temperature(K)\n",
+ "lamda=590*10**-9; #wavelength of sodium D line(m)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "c=3*10**8; #velocity of light(m/s)\n",
+ "k=1.38*10**-23; #boltzmann constant\n",
+ "\n",
+ "#Calculation\n",
+ "a=h*c/(k*T*lamda);\n",
+ "N2byN1=math.exp(-a); #ratio between atoms in 1st excited state and ground state\n",
+ "\n",
+ "#Result\n",
+ "print \"ratio between atoms in 1st excited state and ground state is\",round(N2byN1*10**21,2),\"*10**-21\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ratio between atoms in 1st excited state and ground state is 5.33 *10**-21\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 11.3, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=250+273; #temperature(K)\n",
+ "lamda=590*10**-9; #wavelength of sodium D line(m)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "c=3*10**8; #velocity of light(m/s)\n",
+ "k=1.38*10**-23; #boltzmann constant\n",
+ "\n",
+ "#Calculation\n",
+ "a=h*c/(k*T*lamda);\n",
+ "N2byN1=1/(math.exp(a)-1); #ratio between stimulated emission and spontaneous emission\n",
+ "\n",
+ "#Result\n",
+ "print \"ratio between stimulated emission and spontaneous emission is\",round(N2byN1*10**21,4),\"*10**-21\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ratio between stimulated emission and spontaneous emission is 5.3298 *10**-21\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 11.4, Page number 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n0=1.76; #refractive index of ruby rod\n",
+ "new0=4.3*10**14; #frequency(Hz)\n",
+ "deltav0=1.5*10**11; #doppler broadening(Hz)\n",
+ "c=3*10**8; #velocity of light(m/s)\n",
+ "tow21=4.3*10**-3; #lifetime of spontaneous emission(s)\n",
+ "tow_photon=6*10**-9; #lifetime of photon(s)\n",
+ "\n",
+ "#Calculation\n",
+ "a=4*math.pi**2*new0**2*n0**3/(c**3);\n",
+ "N2_N1=a*tow21*deltav0/tow_photon; #difference between excited state and ground state population(per m**3)\n",
+ "\n",
+ "#Result\n",
+ "print \"difference between excited state and ground state population is\",round(N2_N1*10**-23,3),\"*10**23 per m**3\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "difference between excited state and ground state population is 1.584 *10**23 per m**3\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 11.5, Page number 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300; #temperature(K)\n",
+ "lamda=5000*10**-10; #wavelength of light(m)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "c=3*10**8; #velocity of light(m/s)\n",
+ "k=1.38*10**-23; #boltzmann constant\n",
+ "\n",
+ "#Calculation\n",
+ "a=h*c/(k*T*lamda);\n",
+ "N2byN1=1/(math.exp(a)-1); #ratio between stimulated emission and spontaneous emission\n",
+ "\n",
+ "#Result\n",
+ "print \"ratio between stimulated emission and spontaneous emission is\",round(N2byN1*10**42),\"*10**-42\"\n",
+ "print \"answer varies due to rounding off errors\"\n",
+ "print \"spontaneous emission is more predominant than that of stimulated emission. for stimulating emission, N2>>N1. therefore there is no amplification possibility\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ratio between stimulated emission and spontaneous emission is 2.0 *10**-42\n",
+ "answer varies due to rounding off errors\n",
+ "spontaneous emission is more predominant than that of stimulated emission. for stimulating emission, N2>>N1. therefore there is no amplification possibility\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 11.6, Page number 36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda=632.8*10**-9; #wavelength of laser beam(m)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "c=3*10**8; #velocity of light(m/s)\n",
+ "P=2.3*10**-3; #output power(W)\n",
+ "\n",
+ "#Calculation\n",
+ "new=c/lamda; #frequency of photon(Hz)\n",
+ "E=h*new; #energy of photon(J)\n",
+ "El=P*60; #energy emitted by laser(J/min)\n",
+ "n=El/E; #number of photons emitted(photons/min)\n",
+ "\n",
+ "#Result\n",
+ "print \"number of photons emitted is\",round(n*10**-17,3),\"*10**17 photons/min\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of photons emitted is 4.393 *10**17 photons/min\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter12.ipynb b/Engineering_Physics_by_Rajendran/Chapter12.ipynb
new file mode 100755
index 00000000..b909b231
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter12.ipynb
@@ -0,0 +1,123 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:608ce4833ab64488375d1cbc1e6cf701004b5459a3cd8764d294e881ba488e96"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "12: Fibre Optics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 12.1, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "NA=0.16; #numerical aperture of fibre\n",
+ "n1=1.45; #refractive index of core\n",
+ "d=90*10**-6; #diameter of core(m)\n",
+ "n0=1; #refractive index of air\n",
+ "lamda=0.9*10**-6; #wavelength(m)\n",
+ "\n",
+ "#Calculation\n",
+ "n2=math.sqrt((n1**2)-(NA**2)); #refractive index of cladding\n",
+ "phi=math.asin(NA/n0); #acceptance angle(radian)\n",
+ "phi=phi*180/math.pi; #acceptance angle(degrees)\n",
+ "phid=int(phi); #acceptance angle(degrees)\n",
+ "t=60*(phi-phid); \n",
+ "phim=int(t); #acceptance angle(minutes)\n",
+ "phis=60*(t-phim); #acceptance angle(seconds)\n",
+ "N=4.9*(d*NA/lamda)**2; #number of nodes propagating through fibre\n",
+ "Nstep=N/2; #number of nodes propagating through graded index fibre\n",
+ "\n",
+ "#Result\n",
+ "print \"refractive index of cladding is\",round(n2,3)\n",
+ "print \"acceptance angle is\",phid,\"degrees\",phim,\"minutes\",round(phis,2),\"seconds\"\n",
+ "print \"number of nodes propagating through fibre is\",N\n",
+ "print \"number of nodes propagating through graded index fibre is\",int(Nstep)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "refractive index of cladding is 1.441\n",
+ "acceptance angle is 9 degrees 12 minutes 24.83 seconds\n",
+ "number of nodes propagating through fibre is 1254.4\n",
+ "number of nodes propagating through graded index fibre is 627\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 12.2, Page number 27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda=1*10**-6; #wavelength of light(m)\n",
+ "n1=1.45; #refractive index of core\n",
+ "n2=1.448; #refractive index of cladding\n",
+ "d=6*10**-6; #diameter of core(m)\n",
+ "\n",
+ "#Calculation\n",
+ "NA=math.sqrt((n1**2)-(n2**2)); #numerical aperture\n",
+ "N=4.9*(d*NA/lamda)**2; #number of nodes propagating through fibre\n",
+ "\n",
+ "#Result\n",
+ "print \"number of nodes allowed to propagate through fibre is\",int(N)\n",
+ "print \"it is a single mode fibre\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of nodes allowed to propagate through fibre is 1\n",
+ "it is a single mode fibre\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter13.ipynb b/Engineering_Physics_by_Rajendran/Chapter13.ipynb
new file mode 100755
index 00000000..27d1caad
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter13.ipynb
@@ -0,0 +1,210 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7f366d2ca1671042b1f87ae7b598f1c0353e6f5b6feadb85488043da7746af76"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "13: Crystal Structure"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 13.2, Page number 20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "rho=9.6*10**2; #density of Na(kg/m**3)\n",
+ "aw=23; #atomic weight\n",
+ "n=2; #number of atoms in a unit cell\n",
+ "N=6.022*10**26;\n",
+ "\n",
+ "#Calculation\n",
+ "a3=n*aw/(N*rho);\n",
+ "a=a3**(1/3); #lattice constant of Na(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"lattice constant of Na is\",round(a*10**10,1),\"angstrom\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "lattice constant of Na is 4.3 angstrom\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 13.3, Page number 20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "rho=4*10**3; #density of CsCl(kg/m**3)\n",
+ "aw1=132.9; #atomic weight of Cs\n",
+ "aw2=35.5; #atomic weight of Cl\n",
+ "a=4.12*10**-10; #lattice constant(m)\n",
+ "n=1; #number of atoms in a unit cell\n",
+ "\n",
+ "#Calculation\n",
+ "m=rho*(a**3); #mass of CsCl unit cell(kg)\n",
+ "N=n*(aw1+aw2)/m; #avagadro constant(per kg mole)\n",
+ "\n",
+ "#Result\n",
+ "print \"avagadro constant is\",round(N/10**26,4),\"*10**26 per kg mole\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "avagadro constant is 6.0199 *10**26 per kg mole\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 13.8, Page number 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=4.12*10**-10; #lattice constant(m)\n",
+ "h1=1;\n",
+ "k1=1;\n",
+ "l1=1; #for (111) plane\n",
+ "h2=1;\n",
+ "k2=1;\n",
+ "l2=2; #for (112) plane\n",
+ "h3=1;\n",
+ "k3=2;\n",
+ "l3=3; #for (123) plane\n",
+ "\n",
+ "#Calculation\n",
+ "d111=a/math.sqrt(h1**2+k1**2+l1**2); #lattice spacing for plane (111)(m)\n",
+ "d112=a/math.sqrt(h2**2+k2**2+l2**2); #lattice spacing for plane (112)(m)\n",
+ "d123=a/math.sqrt(h3**2+k3**2+l3**2); #lattice spacing for plane (123)(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"lattice spacing for plane (111) is\",round(d111*10**10,4),\"*10**-10 m\"\n",
+ "print \"lattice spacing for plane (112) is\",round(d112*10**10,3),\"*10**-10 m\"\n",
+ "print \"lattice spacing for plane (123) is\",round(d123*10**10,4),\"*10**-10 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "lattice spacing for plane (111) is 2.3787 *10**-10 m\n",
+ "lattice spacing for plane (112) is 1.682 *10**-10 m\n",
+ "lattice spacing for plane (123) is 1.1011 *10**-10 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 13.9, Page number 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=1; #assume\n",
+ "h1=1;\n",
+ "k1=0;\n",
+ "l1=0; #for (100) plane\n",
+ "h2=1;\n",
+ "k2=1;\n",
+ "l2=0; #for (110) plane\n",
+ "h3=1;\n",
+ "k3=1;\n",
+ "l3=1; #for (111) plane\n",
+ "\n",
+ "#Calculation\n",
+ "d100=a/math.sqrt(h1**2+k1**2+l1**2); #lattice spacing for plane (100)\n",
+ "d110=a/math.sqrt(h2**2+k2**2+l2**2); #lattice spacing for plane (110)\n",
+ "d111=a/math.sqrt(h3**2+k3**2+l3**2); #lattice spacing for plane (111)\n",
+ "\n",
+ "#Result\n",
+ "print \"ratio of lattice spacing is d100:d110:d111=\",d100,\":\",round(d110,2),\":\",round(d111,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ratio of lattice spacing is d100:d110:d111= 1.0 : 0.71 : 0.58\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter14.ipynb b/Engineering_Physics_by_Rajendran/Chapter14.ipynb
new file mode 100755
index 00000000..b3653caa
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter14.ipynb
@@ -0,0 +1,340 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:ea49c9c54a7abfea63e3838cff940d23d5976ae6af1b86c7e497f10ce35239cd"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "14: Waves and Particles"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 14.1, Page number 17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "V=150; #potential difference(V)\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "m=9.1*10**-31; #mass of electron(kg)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "\n",
+ "#Calculation\n",
+ "lamda=h/math.sqrt(2*m*e*V); #de broglie wavelength of electron(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"de broglie wavelength of electron is\",round(lamda*10**10,5),\"*10**-10 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "de broglie wavelength of electron is 1.00256 *10**-10 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 14.2, Page number 17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "E=0.025; #energy of electron(MeV)\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "m=9.1*10**-31; #mass of electron(kg)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "\n",
+ "#Calculation\n",
+ "E=E*10**6*e; #energy of electron(J)\n",
+ "v=math.sqrt(2*E/m); #velocity of electron(m/s)\n",
+ "lamda=h/(m*v); #de broglie wavelength(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"de broglie wavelength is\",round(lamda*10**10,5),\"angstrom\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "de broglie wavelength is 0.07766 angstrom\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 14.3, Page number 18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "E=1; #kinetic energy of electron(MeV)\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "m=9.1*10**-31; #mass of electron(kg)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "\n",
+ "#Calculation\n",
+ "E=E*10**6*e; #energy of electron(J)\n",
+ "v=math.sqrt(2*E/m); #velocity of electron(m/s)\n",
+ "lamda=h/(m*v); #de broglie wavelength of electron(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"de broglie wavelength of electron is\",round(lamda*10**10,5),\"angstrom\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "de broglie wavelength of electron is 0.01228 angstrom\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 14.4, Page number 18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "V=100; #potential difference(V)\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "m=9.1*10**-31; #mass of electron(kg)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "c=3*10**8; #velocity of light(m/s)\n",
+ "\n",
+ "#Calculation\n",
+ "v=math.sqrt(2*e*V/m); #velocity of electron(m/s)\n",
+ "u=c**2/v; #phase velocity of electron(m/s)\n",
+ "lamda=h/(m*v); #de broglie wavelength of electron(m)\n",
+ "p=m*v; #momentum of electron(kg m/s)\n",
+ "vbar=1/lamda; #wave number of electron wave(per m)\n",
+ "\n",
+ "#Result\n",
+ "print \"velocity of electron is\",round(v/10**6,5),\"*10**6 m/s\"\n",
+ "print \"phase velocity of electron is\",round(u/10**10,4),\"*10**10 m/s\"\n",
+ "print \"de broglie wavelength of electron is\",round(lamda*10**10,3),\"angstrom\"\n",
+ "print \"momentum of electron is\",round(p*10**24,3),\"*10**-24 kg m/s\"\n",
+ "print \"wave number of electron wave is\",round(vbar/10**9,3),\"*10**9 per m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "velocity of electron is 5.92999 *10**6 m/s\n",
+ "phase velocity of electron is 1.5177 *10**10 m/s\n",
+ "de broglie wavelength of electron is 1.228 angstrom\n",
+ "momentum of electron is 5.396 *10**-24 kg m/s\n",
+ "wave number of electron wave is 8.144 *10**9 per m\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 14.5, Page number 19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "deltax=10**-14; #radius of nucleus(m)\n",
+ "m=1.67*10**-27; #mass of proton(kg)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "\n",
+ "#Calculation\n",
+ "deltap=h/(2*math.pi*deltax); #uncertainity in momentum of proton(kg m/s)\n",
+ "KE=deltap**2/(2*m); #minimum kinetic energy of proton(J)\n",
+ "KE=KE/(e*10**6); #minimum kinetic energy of proton(MeV)\n",
+ "\n",
+ "#Result\n",
+ "print \"uncertainity in momentum of proton is\",round(deltap*10**20,4),\"*10**-20 kg m/s\"\n",
+ "print \"minimum kinetic energy of proton is\",round(KE,3),\"MeV\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "uncertainity in momentum of proton is 1.0546 *10**-20 kg m/s\n",
+ "minimum kinetic energy of proton is 0.208 MeV\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 14.6, Page number 20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "deltax=0.1*10**-10; #uncertainity in position of electron(m)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "\n",
+ "#Calculation\n",
+ "deltap=h/(2*math.pi*deltax); #uncertainity in momentum of electron(kg m/s)\n",
+ "\n",
+ "#Result\n",
+ "print \"uncertainity in momentum of electron is\",round(deltap*10**23,4),\"*10**-23 kg m/s\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "uncertainity in momentum of electron is 1.0546 *10**-23 kg m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 14.7, Page number 20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "m=9.1*10**-31; #mass of electron(kg)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "a=1*10**-10; #width of potential wall(m)\n",
+ "n1=1; \n",
+ "n2=2;\n",
+ "n3=3;\n",
+ "e=6.24*10**18; #conversion factor from J to eV\n",
+ "\n",
+ "#Calculation\n",
+ "En=(h**2)/(8*m*(a**2)); #energy of electron(J)\n",
+ "E1=En*n1**2; #energy of 1st excited state(J)\n",
+ "E1=E1*e; #energy of 1st excited state(eV)\n",
+ "E2=En*n2**2; #energy of 2nd excited state(J)\n",
+ "E2=E2*e; #energy of 2nd excited state(eV)\n",
+ "E3=En*n3**2; #energy of 3rd excited state(J)\n",
+ "E3=E3*e; #energy of 3rd excited state(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"first 3 permitted energy levels of electron are\",round(E1,2),\"eV\",round(E2,2),\"eV and\",round(E3,2),\"eV\"\n",
+ "print \"answers given in the book vary due to rounding off errors\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "first 3 permitted energy levels of electron are 37.63 eV 150.53 eV and 338.69 eV\n",
+ "answers given in the book vary due to rounding off errors\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter16.ipynb b/Engineering_Physics_by_Rajendran/Chapter16.ipynb
new file mode 100755
index 00000000..fd70504a
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter16.ipynb
@@ -0,0 +1,213 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:0a8e4e4ffe1102aa0e8d709fa097c42aa3e09b9945c321059b30f1ddc8f4e107"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "16: Electron theory of solids"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 16.1, Page number 10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "sigma=5.87*10**7; #electrical conductivity of Cu(per ohm m)\n",
+ "K=390; #thermal conductivity(W/mK)\n",
+ "T=20+273; #temperature(K)\n",
+ "\n",
+ "#Calculation\n",
+ "L=K/(sigma*T); #Lorentz number(W ohm/K**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"Lorentz number is\",round(L*10**8,4),\"*10**-8 W ohm/K**2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Lorentz number is 2.2676 *10**-8 W ohm/K**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 16.2, Page number 11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "tow_r=10**-14; #relaxation time(s)\n",
+ "T=300; #temperature(K)\n",
+ "kB=1.38*10**-23; #boltzmann constant\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "m=9.1*10**-31; #mass of electron(kg)\n",
+ "n=6*10**28; #electron concentration(per m**3)\n",
+ "\n",
+ "#Calculation\t\n",
+ "sigma=n*e**2*tow_r/m; #electrical conductivity(per ohm m)\n",
+ "K=n*math.pi**2*kB**2*T*tow_r/(3*m); #thermal conductivity(W/mK)\n",
+ "L=K/(sigma*T); #Lorentz number(W ohm/K**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"electrical conductivity is\",round(sigma/10**7,4),\"*10**7 per ohm m\"\n",
+ "print \"thermal conductivity is\",round(K,4),\"W/mK\"\n",
+ "print \"Lorentz number is\",round(L*10**8,4),\"*10**-8 W ohm/K**2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "electrical conductivity is 1.6879 *10**7 per ohm m\n",
+ "thermal conductivity is 123.9275 W/mK\n",
+ "Lorentz number is 2.4474 *10**-8 W ohm/K**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 16.3, Page number 11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "tow_r=10**-14; #relaxation time(s)\n",
+ "rho=8900; #density of Cu(kg/m**3)\n",
+ "aw=63.5; #atomic weight of Cu\n",
+ "N=6.022*10**23; #avagadro constant\n",
+ "f=1*10**3; #number of free electrons per atom\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "m=9.1*10**-31; #mass of electron(kg)\n",
+ "\n",
+ "#Calculation\t\n",
+ "n=N*rho*f/aw; #electron concentration(per m**3)\n",
+ "sigma=n*e**2*tow_r/m; #electrical conductivity(per ohm m)\n",
+ "\n",
+ "#Result\n",
+ "print \"electrical conductivity is\",round(sigma/10**7,3),\"*10**7 per ohm m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "electrical conductivity is 2.374 *10**7 per ohm m\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 16.4, Page number 12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "rho=1.54*10**-8; #resistivity(ohm m)\n",
+ "EF=5.5; #fermi energy(eV)\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "m=9.1*10**-31; #mass of electron(kg)\n",
+ "E=100;\n",
+ "n=5.8*10**28; #electron concentration(per m**3)\n",
+ "\n",
+ "#Calculation\t\n",
+ "tow_r=m/(rho*n*e**2); #relaxation time(s)\n",
+ "mew=e*tow_r/m; #mobility of electrons(m**2/Vs)\n",
+ "v=e*tow_r*E/m; #drift velocity(m/s)\n",
+ "EF=EF*e; #fermi energy(J)\n",
+ "vF=math.sqrt(2*EF/m); #fermi velocity(m/s)\n",
+ "lamda=vF*tow_r; #mean free path(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"relaxation time is\",round(tow_r*10**14,2),\"*10**-14 s\"\n",
+ "print \"mobility of electrons is\",round(mew*10**3,3),\"*10**-3 m**2/Vs\"\n",
+ "print \"drift velocity is\",round(v,4),\"m/s\"\n",
+ "print \"fermi velocity is\",round(vF/10**6,2),\"*10**6 m/s\"\n",
+ "print \"mean free path is\",round(lamda*10**8,2),\"*10**-8 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "relaxation time is 3.98 *10**-14 s\n",
+ "mobility of electrons is 6.997 *10**-3 m**2/Vs\n",
+ "drift velocity is 0.6997 m/s\n",
+ "fermi velocity is 1.39 *10**6 m/s\n",
+ "mean free path is 5.53 *10**-8 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter17.ipynb b/Engineering_Physics_by_Rajendran/Chapter17.ipynb
new file mode 100755
index 00000000..7f40976f
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter17.ipynb
@@ -0,0 +1,214 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:fde95e6d9c736121aaabaa0d5609f06ddf07df078e4e974cfe128a5769da216f"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "17: Statistics and band theory of solids"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 17.1, Page number 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "rhoCu=8.96*10**3; #density of Cu(kg/m**3)\n",
+ "awCu=63.55; #atomic weight of Cu\n",
+ "nfCu=1*10**3; #number of free electrons per Cu atom\n",
+ "rhoZn=7.14*10**3; #density of Zn(kg/m**3)\n",
+ "awZn=65.38; #atomic weight of Zn\n",
+ "nfZn=2*10**3; #number of free electrons per Zn atom\n",
+ "rhoAl=2.7*10**3; #density of Al(kg/m**3)\n",
+ "awAl=27; #atomic weight of Al\n",
+ "nfAl=3*10**3; #number of free electrons per Al atom\n",
+ "N=6.022*10**23; #avagadro constant\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "me=9.1*10**-31; #mass of electron(kg)\n",
+ "e=1.6*10**-19; #electron charge(c)\n",
+ "\n",
+ "#Calculation\n",
+ "nCu=rhoCu*N*nfCu/awCu; #concentration of electrons in Cu(per m**3)\n",
+ "EF0Cu=(h**2/(8*me))*(3*nCu/math.pi)**(2/3); #fermi energy of Cu at 0K(J)\n",
+ "EF0Cu=EF0Cu/e; #fermi energy of Cu at 0K(eV)\n",
+ "nZn=rhoZn*N*nfZn/awZn; #concentration of electrons in Zn(per m**3)\n",
+ "EF0Zn=(h**2/(8*me))*(3*nZn/math.pi)**(2/3); #fermi energy of Zn at 0K(J)\n",
+ "EF0Zn=EF0Zn/e; #fermi energy of Zn at 0K(eV)\n",
+ "nAl=rhoAl*N*nfAl/awAl; #concentration of electrons in Al(per m**3)\n",
+ "EF0Al=(h**2/(8*me))*(3*nAl/math.pi)**(2/3); #fermi energy of Al at 0K(J)\n",
+ "EF0Al=EF0Al/e; #fermi energy of Al at 0K(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"fermi energy of Cu at 0K is\",round(EF0Cu,4),\"eV\"\n",
+ "print \"fermi energy of Zn at 0K is\",round(EF0Zn,2),\"eV\"\n",
+ "print \"fermi energy of Al at 0K is\",round(EF0Al,2),\"eV\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "fermi energy of Cu at 0K is 7.0608 eV\n",
+ "fermi energy of Zn at 0K is 9.45 eV\n",
+ "fermi energy of Al at 0K is 11.68 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 17.2, Page number 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "nCu=8.4905*10**28; #concentration of electrons in Cu(per m**3)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "me=9.1*10**-31; #mass of electron(kg)\n",
+ "gama=6.82*10**27;\n",
+ "\n",
+ "#Calculation\n",
+ "EF0=(h**2/(8*me))*(3*nCu/math.pi)**(2/3); #fermi energy of Cu at 0K(J)\n",
+ "EF=EF0/e; #fermi energy of Cu at 0K(eV)\n",
+ "DE=(gama/2)*math.sqrt(EF); #density of states for Cu at fermi level(per m**3)\n",
+ "\n",
+ "#Result\n",
+ "print \"density of states for Cu at fermi level is\",int(DE/10**27),\"*10**27 per m**3\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "density of states for Cu at fermi level is 9 *10**27 per m**3\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 17.3, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "rhoNi=69*10**-9; #resistivity of Ni(ohm m)\n",
+ "rhoCr=129*10**-9; #resistivity of Cr(ohm m)\n",
+ "rho=1120*10**-9; #resistivity(ohm m) \n",
+ "X=0.8; \n",
+ "\n",
+ "#Calculation\n",
+ "C=rho/(X*(1-X)); #Nordheim's coefficient(ohm m)\n",
+ "\n",
+ "#Result\n",
+ "print \"Nordheim's coefficient is\",C,\"ohm m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Nordheim's coefficient is 7e-06 ohm m\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 17.4, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "rho=2.7*10**3; #density of Al(kg/m**3)\n",
+ "M=27; #atomic weight of Al \n",
+ "tow_r=10**-14; #relaxation time(s)\n",
+ "e=1.6*10**-19; #charge of electron(c) \n",
+ "NA=6.022*10**23; #avagadro constant\n",
+ "m=9.1*10**-31; #mass of electron(kg)\n",
+ "f=3*10**3; #number of free electrons per atom\n",
+ "\n",
+ "#Calculation\n",
+ "n=rho*NA*f/M; #number of electrons available per m**3\n",
+ "sigma=n*e**2*tow_r/m; #conductivity of Al(ohm m) \n",
+ "\n",
+ "#Result\n",
+ "print \"conductivity of Al is\",round(sigma/10**7,4),\"*10**7 ohm m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "conductivity of Al is 5.0823 *10**7 ohm m\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter18.ipynb b/Engineering_Physics_by_Rajendran/Chapter18.ipynb
new file mode 100755
index 00000000..25c14fca
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter18.ipynb
@@ -0,0 +1,582 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:b2d7b45e6d7157611952afeb132c76e4391a2a303ceb4704e095dc42c36f50c3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "18: Transport properties of semiconductors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 18.1, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300; #temperature(K)\n",
+ "mew_e=0.4; #electron mobility(m**2/Vs)\n",
+ "mew_h=0.2; #hole mobility(m**2/Vs)\n",
+ "Eg=0.7; #band gap(eV)\n",
+ "m0=9.1*10**-31; #mass of electron(kg)\n",
+ "mestar=0.55*m0; #electron effective mass(kg)\n",
+ "mhstar=0.37*m0; #hole effective mass(kg)\n",
+ "k=1.38*10**-23; #boltzmann constant\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "\n",
+ "#Calculation\n",
+ "a=(2*math.pi*k*T/(h**2))**(3/2);\n",
+ "Eg=Eg*e; #band gap(J)\n",
+ "b=-Eg/(k*T); \n",
+ "ni=2*a*((mhstar*mestar)**(3/4))*math.exp(b); #intrinsic concentration(per m**3)\n",
+ "sigma=ni*e*(mew_e+mew_h); #intrinsic conductivity(per ohm m)\n",
+ "rho=1/sigma; #intrinsic resistivity(ohm m)\n",
+ "\n",
+ "#Result\n",
+ "print \"intrinsic concentration is\",round(ni/10**13,3),\"*10**13 per m**3\"\n",
+ "print \"intrinsic conductivity is\",round(sigma*10**6,3),\"*10**-6 per ohm m\"\n",
+ "print \"intrinsic resistivity is\",round(rho/10**6,2),\"*10**6 ohm m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "intrinsic concentration is 1.352 *10**13 per m**3\n",
+ "intrinsic conductivity is 1.298 *10**-6 per ohm m\n",
+ "intrinsic resistivity is 0.77 *10**6 ohm m\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 18.2, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300; #temperature(K)\n",
+ "k=1.38*10**-23; #boltzmann constant\n",
+ "Nd=10**16; #donor concentration(per cm**3)\n",
+ "ni=1.45*10**10; #intrinsic concentration(per cm**3)\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "\n",
+ "#Calculation\n",
+ "Efd_Efi=k*T*math.log(Nd/ni); #fermi energy(J)\n",
+ "Efd_Efi=Efd_Efi/e; #fermi energy(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"fermi energy is\",round(Efd_Efi,3),\"eV\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "fermi energy is 0.348 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 18.3, Page number 27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mew_e=1.35; #electron mobility(m**2/Vs)\n",
+ "mew_h=0.45; #hole mobility(m**2/Vs)\n",
+ "ni=1.45*10**13; #intrinsic concentration(per m**3)\n",
+ "NSi=5*10**28; #atomic concentration(per m**3)\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "LbyA=1; #Si crystal(cm**3)\n",
+ "\n",
+ "#Calculation\n",
+ "sigmai=ni*e*(mew_e+mew_h); #intrinsic conductivity(per ohm m)\n",
+ "rho=1/sigmai; #intrinsic resistivity(ohm m)\n",
+ "LbyA=LbyA*10**2; #Si crystal(m**3)\n",
+ "R1=rho*LbyA; #resistance(ohm)\n",
+ "Nd=NSi/10**9; #donor concentration(per m**3)\n",
+ "p=(ni**2)/Nd; #hole concentration(per m**3)\n",
+ "sigma=Nd*e*mew_e; #conductivity(per ohm m)\n",
+ "R2=(1/sigma)*100; #resistance(ohm) \n",
+ "\n",
+ "#Result\n",
+ "print \"resistance of 1cm**3 pure Si crystal is\",round(R1/10**7,2),\"*10**7 ohm\"\n",
+ "print \"resistance when crystal is doped with arsenic is\",round(R2,2),\"ohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resistance of 1cm**3 pure Si crystal is 2.39 *10**7 ohm\n",
+ "resistance when crystal is doped with arsenic is 9.26 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 18.4, Page number 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300; #temperature(K)\n",
+ "rho=2.12; #resistivity(ohm m)\n",
+ "mew_e=0.36; #electron mobility(m**2/Vs)\n",
+ "mew_h=0.17; #hole mobility(m**2/Vs)\n",
+ "mestar=0.5*m0; #electron effective mass(kg)\n",
+ "mhstar=0.37*m0; #hole effective mass(kg)\n",
+ "m0=9.1*10**-31; #mass of electron(kg)\n",
+ "k=1.38*10**-23; #boltzmann constant\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "\n",
+ "#Calculation\n",
+ "sigma=1/rho; #conductivity(per ohm m)\n",
+ "ni=sigma/(e*(mew_e+mew_h)); #intrinsic concentration(per m**3)\n",
+ "a=(2*math.pi*k*T/(h**2))**(3/2);\n",
+ "NC=2*a*(mestar**(3/2));\n",
+ "NV=2*a*(mhstar**(3/2));\n",
+ "b=(NC*NV)**(1/2);\n",
+ "Eg=2*k*T*math.log(b/ni); #energy gap of semiconductor(J)\n",
+ "Eg=Eg/e; #energy gap of semiconductor(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"energy gap of semiconductor is\",round(Eg,3),\"eV\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "energy gap of semiconductor is 0.727 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 18.5, Page number 29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "mew_e=0.39; #electron mobility(m**2/Vs)\n",
+ "mew_h=0.19; #hole mobility(m**2/Vs)\n",
+ "ni=2.4*10**19; #intrinsic concentration(per m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "sigmai=ni*e*(mew_e+mew_h); #conductivity of Ge(per Wm)\n",
+ "\n",
+ "#Result\n",
+ "print \"conductivity of Ge is\",round(sigmai,3),\"per Wm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "conductivity of Ge is 2.227 per Wm\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 18.6, Page number 29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "EC_EF300=-0.3; #position of fermi level(eV)\n",
+ "T1=300; #temperature(K)\n",
+ "T2=330; #temperature(K)\n",
+ "k=1.38*10**-23; #boltzmann constant\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "\n",
+ "#Calculation\n",
+ "EC_EF330=-EC_EF300*T2/T1; #new position of fermi level(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"new position of fermi level is\",EC_EF330,\"eV\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "new position of fermi level is 0.33 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 18.7, Page number 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "T1=20; #temperature(C)\n",
+ "T2=40; #temperature(C)\n",
+ "Eg=0.72; #energy gap(eV)\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "k=1.38*10**-23; #boltzmann constant\n",
+ "sigmai20=2; #conductivity(per ohm m)\n",
+ "\n",
+ "#Calculation\n",
+ "T1=T1+273; #temperature(K)\n",
+ "T2=T2+273; #temperature(K)\n",
+ "Eg=Eg*e; #energy gap(J)\n",
+ "a=(T2/T1)**(3/2);\n",
+ "b=Eg/(2*k);\n",
+ "c=(1/T1)-(1/T2);\n",
+ "ni40byni20=a*math.exp(b*c); #ratio of intrinsic concentration\n",
+ "sigmai40=sigmai20*ni40byni20; #conductivity at 40C(per ohm m)\n",
+ "\n",
+ "#Result\n",
+ "print \"conductivity at 40C is\",round(sigmai40,3),\"per ohm m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "conductivity at 40C is 5.487 per ohm m\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 18.8, Page number 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "k=1.38*10**-23; #boltzmann constant\n",
+ "T=300; #temperature(K)\n",
+ "m0=9.1*10**-31; #mass of electron(kg)\n",
+ "Eg=1.1; #energy gap(eV)\n",
+ "mestar=0.31*m0; #effective mass of electron(kg)\n",
+ "\n",
+ "#Calculation\n",
+ "Eg=Eg*e; #energy gap(J)\n",
+ "a=(2*math.pi*k*T*mestar/(h**2))**(3/2);\n",
+ "b=-Eg/(2*k*T); \n",
+ "ni=2*a*math.exp(b); #intrinsic concentration(per m**3)\n",
+ "\n",
+ "#Result\n",
+ "print \"intrinsic concentration is\",round(ni/10**15,4),\"*10**15 per m**3\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "intrinsic concentration is 2.5367 *10**15 per m**3\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 18.9, Page number 31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "RH=-0.55*10**-10; #hall coefficient(m**3/As)\n",
+ "sigma=5.9*10**7; #conductivity(per ohm m)\n",
+ "\n",
+ "#Calculation\n",
+ "mewd=-RH*sigma; #drift mobility(m**2/Vs)\n",
+ "\n",
+ "#Result\n",
+ "print \"drift mobility is\",round(mewd*10**3,1),\"*10**-3 m**2/Vs\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "drift mobility is 3.2 *10**-3 m**2/Vs\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 18.10, Page number 31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "sigma=5.9*10**7; #conductivity(per ohm m)\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "mew=3.2*10**-3; #drift velocity(m**2/Vs)\n",
+ "N=6.022*10**23; #avagadro number\n",
+ "ne=8900*10**3; #number of free electrons per atom\n",
+ "w=63.5; #atomic weight of Cu(kg)\n",
+ "\n",
+ "#Calculation\n",
+ "ni=sigma/(e*mew); #intrinsic concentration(per m**3)\n",
+ "n=N*ne/w; #concentration of free electrons(per m**3)\n",
+ "a=ni/n; #average number of electrons\n",
+ "\n",
+ "#Result\n",
+ "print \"intrinsic concentration is\",round(ni/10**29,2),\"*10**29 per m**3\"\n",
+ "print \"concentration of free electrons is\",round(n/10**28,2),\"*10**28 per m**3\"\n",
+ "print \"average number of electrons is\",int(a)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "intrinsic concentration is 1.15 *10**29 per m**3\n",
+ "concentration of free electrons is 8.44 *10**28 per m**3\n",
+ "average number of electrons is 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 18.11, Page number 32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "RH=3.66*10**-11; #hall coefficient(m**3/As)\n",
+ "sigma=112*10**7; #conductivity(per ohm m)\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "\n",
+ "#Calculation\n",
+ "n=3*math.pi/(8*RH*e); #concentration of electrons(per m**3)\n",
+ "mew_e=sigma/(n*e); #electron mobility(m**2/Vs)\n",
+ "\n",
+ "#Result\n",
+ "print \"concentration of electrons is\",round(n/10**29,1),\"*10**29 per m**3\"\n",
+ "print \"electron mobility is\",round(mew_e,3),\"m**2/Vs\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "concentration of electrons is 2.0 *10**29 per m**3\n",
+ "electron mobility is 0.035 m**2/Vs\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 18.12, Page number 33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "i=50; #current(A)\n",
+ "B=1.5; #magnetic field(T)\n",
+ "n=8.4*10**28; #concentration of electrons(per m**3)\n",
+ "t=0.5; #thickness(cm)\n",
+ "w=2; #width of slab(cm)\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "\n",
+ "#Calculation\n",
+ "w=w*10**-2; #width of slab(m)\n",
+ "VH=B*i/(n*e*w); #hall voltage(V)\n",
+ "\n",
+ "#Result\n",
+ "print \"hall voltage is\",round(VH*10**7,2),\"*10**-7 V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "hall voltage is 2.79 *10**-7 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter2.ipynb b/Engineering_Physics_by_Rajendran/Chapter2.ipynb
new file mode 100755
index 00000000..417da87c
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter2.ipynb
@@ -0,0 +1,153 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:ba867fe9fbc8067f0691ccade40c2ad894318b7fde36802aa91fc404852bb7c8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "2: Viscosity"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.1, Page number 11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "eta=8.9*10**-4; #coefficient of viscosity of water(Ns/m**2)\n",
+ "a=0.054*10**-2; #radius of capillary tube(m)\n",
+ "l=56*10**-2; #length of capillary tube(m)\n",
+ "h=34*10**-4; #height of pressure head(m)\n",
+ "t=5*60; #time of flow(s)\n",
+ "g=9.8;\n",
+ "rho=10**3; #density of water(kg/m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "V=math.pi*h*g*rho*(a**4)/(8*eta*l); #volume of water in 1 sec(m**3)\n",
+ "V5=V*t; #volme of water flowing in 5 minutes(m**3)\n",
+ "m=V5*rho; #mass of water flowing in 5 minutes(kg)\n",
+ "\n",
+ "#Result\n",
+ "print \"mass of water flowing in 5 minutes is\",round(m*10**3,4),\"g\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "mass of water flowing in 5 minutes is 0.6697 g\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.2, Page number 12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "t1=6; #time taken by water(s)\n",
+ "t2=3.6; #time taken by alcohol(s)\n",
+ "rho1=10**3; #density of water(kg/m**3)\n",
+ "rho2=800; #density of alcohol(kg/m**3)\n",
+ "eta1=8.9*10**-4; #viscosity of water(Ns/m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "eta2=t2*rho2*eta1/(t1*rho1); #viscosity of alcohol(Ns/m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"viscosity of alcohol is\",eta2*10**4,\"*10**-4 Ns/m**2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "viscosity of alcohol is 4.272 *10**-4 Ns/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.3, Page number 12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "sigma=1.26*10**-3; #density of medium(kg/m**3)\n",
+ "eta=2*10**-5; #viscosity of medium(Ns/m**2)\n",
+ "r=0.2*10**-2; #radius of body(m)\n",
+ "rho=8*10**-3; #density of body(kg/m**3)\n",
+ "g=9.8;\n",
+ "\n",
+ "#Calculation\n",
+ "v=2*(r**2)*(rho-sigma)*g/(9*eta); #terminal velocity(m/s)\n",
+ "\n",
+ "#Result\n",
+ "print \"terminal velocity is\",round(v*10**3,4),\"*10**-3 m/s\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "terminal velocity is 2.9356 *10**-3 m/s\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter20.ipynb b/Engineering_Physics_by_Rajendran/Chapter20.ipynb
new file mode 100755
index 00000000..b3801c22
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter20.ipynb
@@ -0,0 +1,155 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e20abe68023c39c2fa0cfc7eae20109c8c692466fb3387d83d01339972209a5e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "20: Magnetic materials"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 20.1, Page number 39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "M=2300; #magnetisation(A/m)\n",
+ "B=0.00314; #flux density(Wb/m**2)\n",
+ "mew0=4*math.pi*10**-7;\n",
+ "\n",
+ "#Calculation\n",
+ "H=(B/mew0)-M; #magnetizing force(A/m)\n",
+ "mew_r=(M/H)+1; #relative permeability\n",
+ "\n",
+ "#Result\n",
+ "print \"magnetizing force is\",round(H,4),\"A/m\"\n",
+ "print \"relative permeability is\",round(mew_r,5)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "magnetizing force is 198.7326 A/m\n",
+ "relative permeability is 12.57334\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 20.2, Page number 40"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "H=10**4; #magnetic field intensity(A/m)\n",
+ "chi=3.7*10**-3; #susceptibility\n",
+ "mew0=4*math.pi*10**-7;\n",
+ "\n",
+ "#Calculation\n",
+ "M=chi*H; #magnetisation(A/m)\n",
+ "B=mew0*(M+H); #flux density(Wb/m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"magnetisation is\",M,\"A/m\"\n",
+ "print \"flux density is\",round(B*10**2,2),\"*10**-2 Wb/m**2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "magnetisation is 37.0 A/m\n",
+ "flux density is 1.26 *10**-2 Wb/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 20.3, Page number 41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=2.5*10**-10; #interatomic spacing(m)\n",
+ "M=1.8*10**6; #magnetisation(A/m)\n",
+ "n=2; #number of atoms present in unit cell\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "m=9.1*10**-31; #mass of electron(kg)\n",
+ "h=6.625*10**-34; #planck's constant\n",
+ "\n",
+ "#Calculation\n",
+ "nv=n/(a**3); #number of atoms present per unit volume(per m**3)\n",
+ "Ma=M/nv; #magnetisation produced per atom(A/m**2)\n",
+ "beta=e*h/(4*math.pi*m); #bohr magneton(A/m**2)\n",
+ "Ma=Ma/beta; #magnetisation produced per atom(bohr magneton)\n",
+ "\n",
+ "#Result\n",
+ "print \"average magnetisation produced per atom is\",round(Ma,3),\"bohr magneton\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "average magnetisation produced per atom is 1.517 bohr magneton\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter21.ipynb b/Engineering_Physics_by_Rajendran/Chapter21.ipynb
new file mode 100755
index 00000000..c91130dc
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter21.ipynb
@@ -0,0 +1,278 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:dd76b185872085137646ef650e27e3207f4aa1a0d590f7c3a0d53ab66156e953"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "21: Dielectric Materials"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 21.1, Page number 27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=0.629*10**-9; #lattice parameter(m)\n",
+ "alphaeK=1.26*10**-40; #electronic polarizability for K+(F/m**2)\n",
+ "alphaeCl=3.408*10**-40; #electronic polarizability for Cl-(F/m**2)\n",
+ "n=4; #number of atoms\n",
+ "epsilon0=8.854*10**-12;\n",
+ "\n",
+ "#Calculation\n",
+ "alphae=alphaeK+alphaeCl; #electronic polarizability for KCl(F/m**2)\n",
+ "N=n/(a**3); #number of dipoles(atoms/m**3)\n",
+ "epsilonr=(N*alphae/epsilon0)+1; #dielectric constant of KCl\n",
+ "\n",
+ "#Result\n",
+ "print \"dielectric constant of KCl is\",round(epsilonr,4)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dielectric constant of KCl is 1.8474\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 21.2, Page number 27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "R=0.12*10**-9; #atomic radius of Se(m)\n",
+ "epsilon0=8.854*10**-12;\n",
+ "\n",
+ "#Calculation\n",
+ "alphae=4*math.pi*epsilon0*(R**3); #electronic polarizability of isolated Se(F/m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"electronic polarizability of isolated Se is\",round(alphae*10**40,4),\"*10**-40 F/m**2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "electronic polarizability of isolated Se is 1.9226 *10**-40 F/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 21.3, Page number 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "alphae=0.35*10**-40; #electronic polarizability(F/m**2)\n",
+ "N=2.7*10**25; #number of atoms(atoms/m**3)\n",
+ "epsilon0=8.854*10**-12;\n",
+ "\n",
+ "#Calculation\n",
+ "a=N*alphae/(3*epsilon0);\n",
+ "epsilonr=(1+(2*a))/(1-a); #dielectric constant of Ne\n",
+ "\n",
+ "#Result\n",
+ "print \"dielectric constant of Ne is\",round(epsilonr,9)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dielectric constant of Ne is 1.000106735\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 21.4, Page number 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "R=0.384*10**-9; #radius of Ar(m)\n",
+ "N=2.7*10**25; #number of atoms(atoms/m**3)\n",
+ "epsilon0=8.854*10**-12;\n",
+ "\n",
+ "#Calculation\n",
+ "alphae=4*math.pi*epsilon0*(R**3); #electronic polarizability of Ar(F/m**2)\n",
+ "a=N*alphae/(3*epsilon0);\n",
+ "epsilonr=(1+(2*a))/(1-a); #dielectric constant of Ar\n",
+ "\n",
+ "#Result\n",
+ "print \"dielectric constant of Ar is\",epsilonr\n",
+ "print \"answer given in the book is wrong\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dielectric constant of Ar is 1.01933559019\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 21.5, Page number 29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "C=2*10**-6; #capacitance(F)\n",
+ "epsilonr=80; #permitivity of dielectric\n",
+ "V=1*10**3; #applied voltage(V)\n",
+ "\n",
+ "#Calculation\n",
+ "E1=(1/2)*C*V**2; #energy stored in capacitor(J)\n",
+ "C0=C/epsilonr; #capacitance when dielectric is removed(F)\n",
+ "E2=(1/2)*C0*V**2; #energy stored in capacitor with vacuum as dielectric(J)\n",
+ "E=1-E2; #energy stored in capacitor in polarizing the dielectric(J)\n",
+ "\n",
+ "#Result\n",
+ "print \"energy stored in capacitor is\",E1,\"J\"\n",
+ "print \"energy stored in capacitor in polarizing the dielectric is\",E,\"J\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "energy stored in capacitor is 1.0 J\n",
+ "energy stored in capacitor in polarizing the dielectric is 0.9875 J\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 21.6, Page number 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "N=5*10**28; #number of atoms(per m**3)\n",
+ "alpha=2*10**-40; #polarizability(Fm**2)\n",
+ "epsilon0=8.854*10**-12;\n",
+ "\n",
+ "#Calculation\n",
+ "P=N*alpha;\n",
+ "a=1-(P/(3*epsilon0));\n",
+ "EibyE=1/a; #ratio of internal field to applied field\n",
+ "\n",
+ "#Result\n",
+ "print \"ratio of internal field to applied field is\",round(EibyE,4)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ratio of internal field to applied field is 1.6038\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter4.ipynb b/Engineering_Physics_by_Rajendran/Chapter4.ipynb
new file mode 100755
index 00000000..be4a2831
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter4.ipynb
@@ -0,0 +1,451 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3f5941b661a8515cae38219efa7050e771c862dd351401d57b16c57806506e2a"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "4: Acoustics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.1, Page number 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "I1=10**-12; #intensity(W/m**2)\n",
+ "I2=0.1; #intensity of sound(W/m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "beta=10*np.log10(I2/I1); #intensity level(dB) \n",
+ "\n",
+ "#Result\n",
+ "print \"intensity level is\",beta,\"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "intensity level is 110.0 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.2, Page number 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "I1=10**-12; #intensity(W/m**2)\n",
+ "I2=10**-4; #intensity of sound(W/m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "beta=10*np.log10(I2/I1); #relative sound intensity(dB) \n",
+ "\n",
+ "#Result\n",
+ "print \"relative sound intensity is\",beta,\"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "relative sound intensity is 80.0 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.3, Page number 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "I2byI1=2; #intensity ratio\n",
+ "\n",
+ "#Calculation\n",
+ "beta=10*np.log10(I2byI1); #increase in sound intensity level(dB) \n",
+ "\n",
+ "#Result\n",
+ "print \"increase in sound intensity level is\",round(beta,2),\"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "increase in sound intensity level is 3.01 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.4, Page number 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "P=3.14; #power radiated(W)\n",
+ "r=10; #radius(m)\n",
+ "I11=100; #intensity(W/m**2)\n",
+ "I12=1; #intensity(W/m**2)\n",
+ "I13=10**-12; #intensity(W/m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "I2=P/(4*math.pi*r**2); #intensity of sound(W/m**2)\n",
+ "beta1=10*np.log10(I2/I11); #relative intensity(dB) \n",
+ "beta2=10*np.log10(I2/I12); #relative intensity(dB) \n",
+ "beta3=10*np.log10(I2/I13); #relative intensity(dB) \n",
+ "\n",
+ "#Result\n",
+ "print \"relative intensity with respect to 100W/m**2 is\",round(beta1,4),\"dB\"\n",
+ "print \"relative intensity with respect to 1W/m**2 is\",round(beta2,4),\"dB\"\n",
+ "print \"relative intensity with respect to 10**-12W/m**2 is\",round(beta3,3),\"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "relative intensity with respect to 100W/m**2 is -46.0228 dB\n",
+ "relative intensity with respect to 1W/m**2 is -26.0228 dB\n",
+ "relative intensity with respect to 10**-12W/m**2 is 93.977 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.5, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "P=1.5; #power radiated(J/s)\n",
+ "r=20; #radius(m)\n",
+ "I1=10**-12; #intensity level of sound(W/m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "I2=P/(4*math.pi*r**2); #intensity of sound(W/m**2)\n",
+ "beta=10*np.log10(I2/I1); #intensity level(dB) \n",
+ "\n",
+ "#Result\n",
+ "print \"intensity level of sound is\",round(beta,1),\"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "intensity level of sound is 84.7 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.6, Page number 27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "beta1=80; #intensity level of sound(dB)\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print \" \""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.7, Page number 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "V=1500; #volume of hall(m**3)\n",
+ "sigma_a1s=100; #absorption of sound by hall(sabine)\n",
+ "sigma_a2s=100; #absorption of sound by audience(sabine)\n",
+ "\n",
+ "#Calculation\n",
+ "A=sigma_a1s+sigma_a2s; #total absorption(sabine)\n",
+ "t1=0.16*V/sigma_a1s; #reverberation time of hall when room is empty(s)\n",
+ "t2=0.16*V/(sigma_a1s+sigma_a2s); #reverberation time of hall when room is filled(s)\n",
+ "t=t1-t2; #change in reverberation time(s)\n",
+ "\n",
+ "#Result\n",
+ "print \"when the room is filled, reverberation time is reduced to\",t,\"s\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "when the room is filled, reverberation time is reduced to 1.2 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.8, Page number 28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "V=1000; #volume of hall(m**3)\n",
+ "T=2; #reverberation time(s)\n",
+ "s=350; #area of sound absorbing surface(m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "alpha=0.16*V/(T*s); #average absorption coefficient\n",
+ "\n",
+ "#Result\n",
+ "print \"average absorption coefficient is\",round(alpha,5)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "average absorption coefficient is 0.22857\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.9, Page number 29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "V=2400; #volume of hall(m**3)\n",
+ "a1=500; #area of plaster ceiling(m**2)\n",
+ "s1=0.02; #coefficient of absorption of plaster ceiling\n",
+ "a2=600; #area of plaster walls(m**2)\n",
+ "s2=0.03; #coefficient of absorption of plaster walls\n",
+ "a3=500; #area of wood floor(m**2)\n",
+ "s3=0.06; #coefficient of absorption of wood floor\n",
+ "a4=20; #area of wood doors(m**2)\n",
+ "s4=0.06; #coefficient of absorption of wood doors\n",
+ "a5=400; #area of cushion seats(m**2)\n",
+ "s5=0.01; #coefficient of absorption of cushion seats\n",
+ "a6=200; #area of cane seats(m**2)\n",
+ "s6=0.01; #coefficient of absorption of cane seats \n",
+ "s=0.45; #absorption of each member(sabine)\n",
+ "\n",
+ "#Calculation\n",
+ "sigma_asE=(a1*s1)+(a2*s2)+(a3*s3)+(a4*s4)+(a5*s5)+(a6*s6); #total absorption when hall is empty(sabine)\n",
+ "TE=0.16*V/sigma_asE; #reverberation time when hall is empty(s)\n",
+ "sigma_asF=(a1*s1)+(a2*s2)+(a3*s3)+(a4*s4)+(a5*s)+(a6*s); #total absorption when hall is filled(sabine)\n",
+ "TF=0.16*V/sigma_asF; #reverberation time when hall is filled(s)\n",
+ "\n",
+ "#Result\n",
+ "print \"reverberation time when hall is empty is\",round(TE,4),\"s\"\n",
+ "print \"reverberation time when hall is filled is\",round(TF,3),\"s\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "reverberation time when hall is empty is 5.8896 s\n",
+ "reverberation time when hall is filled is 1.166 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.10, Page number 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "I1=10**-12; #intensity(W/m**2)\n",
+ "I2=100; #intensity of sound(W/m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "beta=10*np.log10(I2/I1); #intensity level of jet plane(dB) \n",
+ "\n",
+ "#Result\n",
+ "print \"intensity level of jet plane is\",beta,\"dB\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "intensity level of jet plane is 140.0 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter5.ipynb b/Engineering_Physics_by_Rajendran/Chapter5.ipynb
new file mode 100755
index 00000000..8f31b52c
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter5.ipynb
@@ -0,0 +1,234 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:dcc4019ef1c15d21354e91688bcf3d6888473d71d7b26b6c010e7b08e8a6177f"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "5: Ultrasonics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 5.1, Page number 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "t=1*10**-3; #thickness of crystal(m)\n",
+ "rho=2650; #density of quartz(kg/m**3)\n",
+ "Y=7.9*10**10; #young's modulus(N/m**2)\n",
+ "p=1;\n",
+ "\n",
+ "#Calculation\n",
+ "f=(p/(2*t))*math.sqrt(Y/rho); #fundamental frequency(Hz)\n",
+ "\n",
+ "#Result\n",
+ "print \"fundamental frequency is\",round(f/10**6,5),\"*10**6 Hz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "fundamental frequency is 2.72999 *10**6 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 5.2, Page number 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "t=5*10**-3; #length of crystal(m)\n",
+ "Y=7.9*10**10; #young's modulus(N/m**2)\n",
+ "p1=1;\n",
+ "p2=2;\n",
+ "rho=2650; #density of quartz(kg/m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "f1=(p1/(2*t))*math.sqrt(Y/rho); #fundamental frequency(Hz)\n",
+ "f2=(p2/(2*t))*math.sqrt(Y/rho); #frequency of 1st overtone(Hz)\n",
+ "\n",
+ "#Result\n",
+ "print \"fundamental frequency is\",round(f1/10**5,2),\"*10**5 Hz\"\n",
+ "print \"frequency of 1st overtone is\",round(f2/10**6,3),\"*10**6 Hz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "fundamental frequency is 5.46 *10**5 Hz\n",
+ "frequency of 1st overtone is 1.092 *10**6 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 5.3, Page number 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "u=5000; #velocity of sound in steel(m/s)\n",
+ "f=50*10**3; #difference between frequencies(Hz)\n",
+ "\n",
+ "#Calculation\n",
+ "d=u/(2*f); #thickness of steel plate(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"thickness of steel plate is\",d,\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "thickness of steel plate is 0.05 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 5.4, Page number 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "t=1; #assume\n",
+ "f1=(2.87*10**3)/t; #fundamental frequency(Hz)\n",
+ "f=1200*10**3; #frequency(Hz)\n",
+ "rho=2660; #density of quartz(kg/m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "Y=rho*(f1*2*t)**2; #young's modulus(N/m**2)\n",
+ "t1=(1/(2*f))*math.sqrt(Y/rho); #thickness of crystal(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"young's modulus is\",round(Y/10**10,3),\"*10**10 N/m**2\"\n",
+ "print \"thickness of crystal is\",round(t1*10**3,2),\"*10**-3 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "young's modulus is 8.764 *10**10 N/m**2\n",
+ "thickness of crystal is 2.39 *10**-3 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 5.5, Page number 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "f=7*10**6; #ultrasonic frequency(Hz)\n",
+ "theta=45; #transducer angle(degrees)\n",
+ "v=1.5; #blood velocity(m/s)\n",
+ "U=1500; #ultrasonic velocity(m/s)\n",
+ "\n",
+ "#Calculation\n",
+ "theta=theta*(math.pi/180); #transducer angle(radian)\n",
+ "deltaf=2*f*v*math.cos(theta)/U; #audio frequency(Hz)\n",
+ "\n",
+ "#Result\n",
+ "print \"audio frequency is\",round(deltaf/10**3),\"kHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "audio frequency is 10.0 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter6.ipynb b/Engineering_Physics_by_Rajendran/Chapter6.ipynb
new file mode 100755
index 00000000..bb9a353d
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter6.ipynb
@@ -0,0 +1,261 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c64912256bdcf8bcc5ce71dffc2b43e608072175b592d01f0ff0fe3771ee0132"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "6: Non Destructive Testing"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 6.1, Page number 36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "t=50; #thickness of metal(mm)\n",
+ "d=1; #hole diameter(mm)\n",
+ "\n",
+ "#Calculation\n",
+ "sp=(d/t)*100; #sensitivity percentage(%)\n",
+ "\n",
+ "#Result\n",
+ "print \"sensitivity percentage of wire is\",sp,\"%\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "sensitivity percentage of wire is 2.0 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 6.2, Page number 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "I=20*10**-3; #tube current(A)\n",
+ "L=1; #source to film distance(m)\n",
+ "t=60; #exposure time(s)\n",
+ "\n",
+ "#Calculation\n",
+ "ef=I*t/(L**2); #exposure factor\n",
+ "\n",
+ "#Result\n",
+ "print \"exposure factor is\",ef"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "exposure factor is 1.2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 6.3, Page number 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "IbyI0=20; #reduction in intensity\n",
+ "mew=1.62; #linear absorption coefficient(per cm)\n",
+ "\n",
+ "#Calculation\n",
+ "x=math.log(IbyI0)/mew; #thickness of aluminium(cm)\n",
+ "\n",
+ "#Result\n",
+ "print \"thickness of aluminium is\",round(x,2),\"*10**-2 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "thickness of aluminium is 1.85 *10**-2 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 6.4, Page number 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "x=2.5*10**-2; #thickness of material(m)\n",
+ "mew=2; #linear absorption coefficient(per cm)\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print \" \""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 6.5, Page number 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "ef=0.35; #exposure factor(curie hour)\n",
+ "pss=5; #present source strength(curie)\n",
+ "\n",
+ "#Calculation\n",
+ "et=ef/pss; #exposure time(h)\n",
+ "\n",
+ "#Result\n",
+ "print \"exposure time is\",et*60,\"min\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "exposure time is 4.2 min\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 6.6, Page number 39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "fd=20*10**-2; #film focus distance(m)\n",
+ "Sd=5*10**-2; #displacement of X-ray tube(m)\n",
+ "t=5*10**-2; #thickness of steel(m)\n",
+ "S=0.5*10**-2; #distance between images(m)\n",
+ "\n",
+ "#Calculation\n",
+ "d=fd*S/(S+Sd); #distance of flow from bottom surface(m)\n",
+ "l=t-d; #location of flow from top surface(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"location of flow from top surface is\",round(l*10**2,1),\"*10**-2 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "location of flow from top surface is 3.2 *10**-2 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter7.ipynb b/Engineering_Physics_by_Rajendran/Chapter7.ipynb
new file mode 100755
index 00000000..4a23f5d2
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter7.ipynb
@@ -0,0 +1,179 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:091a42f6c4748025b72b34c7f12edc07c6f7f79e00e0f5e82232274fbc41738c"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "7: Interference"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 7.1, Page number 16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "theta=40; #angle of wedge(s)\n",
+ "beta=0.125*10**-2; #fringe width(m)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda=2*beta*theta*(math.pi/180)*(1/60)*(1/60); #wavelength of light(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength of light is\",int(lamda*10**10),\"angstrom\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "wavelength of light is 4848 angstrom\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 7.3, Page number 17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=100; #number of fringes\n",
+ "d=0.03*10**-3; #distance moved(m)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda=2*d/n; #wavelength of light(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength of light is\",lamda*10**10,\"angstrom\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "wavelength of light is 6000.0 angstrom\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 7.4, Page number 17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda1=5896*10**-10; #wavelength of D1 line(m)\n",
+ "lamda2=5890*10**-10; #wavelength of D2 line(m)\n",
+ "\n",
+ "#Calculation\n",
+ "d=lamda1*lamda2/(2*(lamda1-lamda2)); #distance the mirror has to be moved(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"distance the mirror has to be moved is\",round(d*10**3,4),\"mm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "distance the mirror has to be moved is 0.2894 mm\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 7.5, Page number 18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mew=1.5; #refractive index of plate\n",
+ "d=1.24; #distance between dark fringes(mm)\n",
+ "\n",
+ "#Calculation\n",
+ "t=d/(mew-1); #thickness of glass plate(mm)\n",
+ "\n",
+ "#Result\n",
+ "print \"thickness of glass plate is\",t,\"mm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "thickness of glass plate is 2.48 mm\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter8.ipynb b/Engineering_Physics_by_Rajendran/Chapter8.ipynb
new file mode 100755
index 00000000..eb8b969a
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter8.ipynb
@@ -0,0 +1,184 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1c07cbfc0dc96926ceae744a226fe3c57743d67509eccb306df708f4c814b436"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "8: Polarisation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 8.1, Page number 16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mew_e=1.553; #refractive index of extraordinary ray\n",
+ "mew0=1.544; #refractive index of ordinary ray\n",
+ "lamda=6*10**-7; #wavelength(m)\n",
+ "\n",
+ "#Calculation\n",
+ "t=lamda/(4*(mew_e-mew0)); #thickness of quarter wave plate(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"thickness of quarter wave plate is\",round(t*10**5,3),\"*10**-5 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "thickness of quarter wave plate is 1.667 *10**-5 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 8.2, Page number 16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mew_e=1.553; #refractive index of extraordinary ray\n",
+ "mew0=1.544; #refractive index of ordinary ray\n",
+ "lamda=6*10**-7; #wavelength(m)\n",
+ "\n",
+ "#Calculation\n",
+ "t=lamda/(2*(mew_e-mew0)); #thickness of half wave plate(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"thickness of half wave plate is\",round(t*10**5,2),\"*10**-5 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "thickness of half wave plate is 3.33 *10**-5 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 8.3, Page number 17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mew_e=1.486; #refractive index of extraordinary ray\n",
+ "mew0=1.658; #refractive index of ordinary ray\n",
+ "lamda=6*10**-7; #wavelength(m)\n",
+ "\n",
+ "#Calculation\n",
+ "t=lamda/(4*(mew0-mew_e)); #thickness of quarter wave plate(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"thickness of quarter wave plate is\",round(t*10**7,1),\"*10**-7 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "thickness of quarter wave plate is 8.7 *10**-7 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 8.4, Page number 17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mew_e=1.486; #refractive index of extraordinary ray\n",
+ "mew0=1.658; #refractive index of ordinary ray\n",
+ "t=1.64*10**-6; #thickness(m) \n",
+ "\n",
+ "#Calculation\n",
+ "lamda=2*t*(mew0-mew_e); #wavelength of light(m)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength of light is\",round(lamda*10**6,3),\"*10**-6 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "wavelength of light is 0.564 *10**-6 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/Chapter9.ipynb b/Engineering_Physics_by_Rajendran/Chapter9.ipynb
new file mode 100755
index 00000000..aa1abf35
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/Chapter9.ipynb
@@ -0,0 +1,101 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5f6e5e5e16ae36be54b773743f59e15ae672a0cecdab4854d7e43b7f805f4ffa"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "9: Photoelasticity"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 9.1, Page number 10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "alpha1_alpha2=10*10**8; #difference between pincipal stress(N/m**2)\n",
+ "c=1*10**-12; #stress optic coefficient(m**2/N)\n",
+ "\n",
+ "#Calculation\n",
+ "N=c*alpha1_alpha2; #difference between refractive indices\n",
+ "\n",
+ "#Result\n",
+ "print \"difference between refractive indices is\",N"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "difference between refractive indices is 0.001\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 9.2, Page number 10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "alpha1=405*10**6; #principal stress(N/m**2)\n",
+ "alpha2=-105*10**6; #principal stress(N/m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "tow_max=(alpha1-alpha2)/2; #maximum shearing stress(N/m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"maximum shearing stress is\",tow_max*10**-6,\"*10**6 N/m**2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum shearing stress is 255.0 *10**6 N/m**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Rajendran/screenshots/s1.png b/Engineering_Physics_by_Rajendran/screenshots/s1.png
new file mode 100755
index 00000000..8ec11695
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/screenshots/s1.png
Binary files differ
diff --git a/Engineering_Physics_by_Rajendran/screenshots/s2.png b/Engineering_Physics_by_Rajendran/screenshots/s2.png
new file mode 100755
index 00000000..c80e5cf0
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/screenshots/s2.png
Binary files differ
diff --git a/Engineering_Physics_by_Rajendran/screenshots/s3.png b/Engineering_Physics_by_Rajendran/screenshots/s3.png
new file mode 100755
index 00000000..21548f2c
--- /dev/null
+++ b/Engineering_Physics_by_Rajendran/screenshots/s3.png
Binary files differ
diff --git a/Engineering_Physics_by_S._Mani_Naidu/Chapter1.ipynb b/Engineering_Physics_by_S._Mani_Naidu/Chapter1.ipynb
new file mode 100755
index 00000000..55b436e9
--- /dev/null
+++ b/Engineering_Physics_by_S._Mani_Naidu/Chapter1.ipynb
@@ -0,0 +1,284 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#1: Bonding in Solids"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 1.1, Page number 1.11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "bond energy is -4.6 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "epsilon0=8.85*10**-12; #permittivity(C/Nm)\n",
+ "r0=236*10**-12; #seperation(m)\n",
+ "IE=5.14; #ionisation energy of Na(eV)\n",
+ "Ea=-3.65; #electron affinity(eV)\n",
+ "\n",
+ "#Calculation\n",
+ "V=-e**2/(4*e*math.pi*epsilon0*r0); \n",
+ "BE=IE+Ea+round(V,2); #bond energy(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"bond energy is\",round(BE,1),\"eV\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 1.2, Page number 1.11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "total cohesive energy per atom is -3.0684 eV\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.602*10**-19; #charge of electron(c)\n",
+ "epsilon0=8.85*10**-12; #permittivity(C/Nm)\n",
+ "r0=0.314*10**-9; #seperation(m)\n",
+ "A=1.75; #madelung constant\n",
+ "n=5.77; #repulsive exponent value\n",
+ "IE=4.1; #ionisation energy of K(eV)\n",
+ "Ea=3.6; #electron affinity(eV)\n",
+ "\n",
+ "#Calculation\n",
+ "E=-A*e**2*(1-(1/n))/(4*e*math.pi*epsilon0*r0); #energy(eV)\n",
+ "Ce=E/2; #cohesive energy per atom(eV)\n",
+ "x=IE-Ea; #energy(eV)\n",
+ "CE=Ce+(x/2); #total cohesive energy per atom(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"total cohesive energy per atom is\",round(CE,4),\"eV\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 1.3, Page number 1.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "cohesive energy is -7.965 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.602*10**-19; #charge of electron(c)\n",
+ "epsilon0=8.85*10**-12; #permittivity(C/Nm)\n",
+ "r0=0.281*10**-9; #seperation(m)\n",
+ "alpham=1.748; #madelung constant\n",
+ "n=9; #repulsive exponent value\n",
+ "\n",
+ "#Calculation\n",
+ "E=-alpham*e**2*(1-(1/n))/(4*e*math.pi*epsilon0*r0); #cohesive energy(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"cohesive energy is\",round(E,3),\"eV\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 1.4, Page number 1.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "potential energy is 5.755 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "epsilon0=8.85*10**-12; #permittivity(C/Nm)\n",
+ "r0=2.5*10**-10; #seperation(m)\n",
+ "\n",
+ "#Calculation\n",
+ "PE=e**2/(4*e*math.pi*epsilon0*r0); #potential energy(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"potential energy is\",round(PE,3),\"eV\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 1.5, Page number 1.13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "cohesive energy is -3.46 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "m=1;\n",
+ "n=9; #repulsive exponent value\n",
+ "a=1.748*10**-28; \n",
+ "r0=0.281*10**-9; #seperation(m)\n",
+ "\n",
+ "#Calculation\n",
+ "Ur0=-a*(1-(m/n))/(e*r0**m); #cohesive energy(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"cohesive energy is\",round(Ur0,2),\"eV\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 1.6, Page number 1.13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "cohesive energy is -3.59 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.6*10**-19; #charge of electron(c)\n",
+ "epsilon0=8.85*10**-12; #permittivity(C/Nm)\n",
+ "r0=0.281*10**-9; #seperation(m)\n",
+ "IE=5.14; #ionisation energy of Na(eV)\n",
+ "Ea=-3.61; #electron affinity(eV)\n",
+ "\n",
+ "#Calculation\n",
+ "V=-e**2/(4*e*math.pi*epsilon0*r0); \n",
+ "CE=IE+Ea+round(V,2); #cohesive energy(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"cohesive energy is\",CE,\"eV\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Engineering_Physics_by_S._Mani_Naidu/Chapter10.ipynb b/Engineering_Physics_by_S._Mani_Naidu/Chapter10.ipynb
new file mode 100755
index 00000000..9538ba45
--- /dev/null
+++ b/Engineering_Physics_by_S._Mani_Naidu/Chapter10.ipynb
@@ -0,0 +1,112 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#10: Lasers "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 10.1, Page number 10.20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "energy gap is 0.8 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "c=3*10**8; #velocity of light(m/s)\n",
+ "lamda=1.55*10**-6; #wavelength(m)\n",
+ "e=1.6*10**-19; \n",
+ "\n",
+ "#Calculation\n",
+ "Eg=h*c/(lamda*e); #energy gap(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"energy gap is\",round(Eg,1),\"eV\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 10.2, Page number 10.20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "wavelength is 8633.0 angstrom\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "c=3*10**8; #velocity of light(m/s)\n",
+ "Eg=1.44; #energy gap(eV)\n",
+ "e=1.6*10**-19; \n",
+ "\n",
+ "#Calculation\n",
+ "lamda=h*c/(Eg*e); #wavelength(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength is\",round(lamda*10**10),\"angstrom\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Engineering_Physics_by_S._Mani_Naidu/Chapter11.ipynb b/Engineering_Physics_by_S._Mani_Naidu/Chapter11.ipynb
new file mode 100755
index 00000000..d437d117
--- /dev/null
+++ b/Engineering_Physics_by_S._Mani_Naidu/Chapter11.ipynb
@@ -0,0 +1,549 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#11: Fibre Optics"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 11.1, Page number 11.16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "numerical aperture is 0.2965\n",
+ "acceptance angle is 17 degrees 15.0 minutes\n",
+ "critical angle is 78 degrees 26 minutes\n",
+ "fractional refractive indices change is 0.02\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1=1.48; #refractive index of core\n",
+ "n2=1.45; #refractive index of cladding\n",
+ "\n",
+ "#Calculation\n",
+ "NA=math.sqrt((n1**2)-(n2**2)); #numerical aperture\n",
+ "theta0=math.asin(NA); #acceptance angle(radian)\n",
+ "theta0=theta0*180/math.pi; #acceptance angle(degrees)\n",
+ "theta0_m=60*(theta0-int(theta0));\n",
+ "thetac=math.asin(n2/n1); #critical angle(radian)\n",
+ "thetac=thetac*180/math.pi; #critical angle(degrees)\n",
+ "thetac_m=60*(thetac-int(thetac));\n",
+ "delta=(n1-n2)/n1; #fractional refractive indices change\n",
+ "\n",
+ "#Result\n",
+ "print \"numerical aperture is\",round(NA,4)\n",
+ "print \"acceptance angle is\",int(theta0),\"degrees\",round(theta0_m),\"minutes\"\n",
+ "print \"critical angle is\",int(thetac),\"degrees\",int(thetac_m),\"minutes\"\n",
+ "print \"fractional refractive indices change is\",round(delta,2)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 11.2, Page number 11.17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "numerical aperture is 0.446\n",
+ "acceptance angle is 26 degrees 29.5 minutes\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1=1.563; #refractive index of core\n",
+ "n2=1.498; #refractive index of cladding\n",
+ "\n",
+ "#Calculation\n",
+ "NA=math.sqrt((n1**2)-(n2**2)); #numerical aperture\n",
+ "theta0=math.asin(NA); #acceptance angle(radian)\n",
+ "theta0=theta0*180/math.pi; #acceptance angle(degrees)\n",
+ "theta0_m=60*(theta0-int(theta0));\n",
+ "\n",
+ "#Result\n",
+ "print \"numerical aperture is\",round(NA,3)\n",
+ "print \"acceptance angle is\",int(theta0),\"degrees\",round(theta0_m,1),\"minutes\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 11.3, Page number 11.17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "fractional refractive indices change is 0.0416\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1=1.563; #refractive index of core\n",
+ "n2=1.498; #refractive index of cladding\n",
+ "\n",
+ "#Calculation\n",
+ "delta=(n1-n2)/n1; #fractional refractive indices change\n",
+ "\n",
+ "#Result\n",
+ "print \"fractional refractive indices change is\",round(delta,4)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 11.4, Page number 11.17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "numerical aperture is 0.3905\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1=1.55; #refractive index of core\n",
+ "n2=1.50; #refractive index of cladding\n",
+ "\n",
+ "#Calculation\n",
+ "NA=math.sqrt((n1**2)-(n2**2)); #numerical aperture\n",
+ "\n",
+ "#Result\n",
+ "print \"numerical aperture is\",round(NA,4)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 11.5, Page number 11.18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "refractive index of core is 1.546\n",
+ "refractive index of cladding is 1.496\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "NA=0.39; #numerical aperture\n",
+ "n1_n2=0.05; #difference in refractive indices\n",
+ "\n",
+ "#Calculation\n",
+ "x=NA**2/n1_n2;\n",
+ "n2=(x-n1_n2)/2; #refractive index of cladding\n",
+ "n1=n2+n1_n2; #refractive index of core\n",
+ "\n",
+ "#Result\n",
+ "print \"refractive index of core is\",n1\n",
+ "print \"refractive index of cladding is\",n2"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 11.6, Page number 11.18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "numerical aperture is 0.3905\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1=1.55; #refractive index of core\n",
+ "n2=1.50; #refractive index of cladding\n",
+ "\n",
+ "#Calculation\n",
+ "NA=math.sqrt((n1**2)-(n2**2)); #numerical aperture\n",
+ "\n",
+ "#Result\n",
+ "print \"numerical aperture is\",round(NA,4)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 11.7, Page number 11.18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "numerical aperture is 0.2965\n",
+ "acceptance angle is 17 degrees 15.0 minutes\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1=1.48; #refractive index of core\n",
+ "n2=1.45; #refractive index of cladding\n",
+ "\n",
+ "#Calculation\n",
+ "NA=math.sqrt((n1**2)-(n2**2)); #numerical aperture\n",
+ "theta0=math.asin(NA); #acceptance angle(radian)\n",
+ "theta0=theta0*180/math.pi; #acceptance angle(degrees)\n",
+ "theta0_m=60*(theta0-int(theta0));\n",
+ "\n",
+ "#Result\n",
+ "print \"numerical aperture is\",round(NA,4)\n",
+ "print \"acceptance angle is\",int(theta0),\"degrees\",round(theta0_m),\"minutes\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 11.8, Page number 11.19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "refractive index of core is 1.6583\n",
+ "refractive index of cladding is 1.625\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "NA=0.33; #numerical aperture\n",
+ "delta=0.02; #fractional refractive indices change\n",
+ "\n",
+ "#Calculation\n",
+ "x=1-delta\n",
+ "y=math.sqrt(1-x**2);\n",
+ "n1=NA/y; #refractive index of core\n",
+ "n2=n1*x; #refractive index of cladding\n",
+ "\n",
+ "#Result\n",
+ "print \"refractive index of core is\",round(n1,4)\n",
+ "print \"refractive index of cladding is\",round(n2,3)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 11.9, Page number 11.19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "acceptance angle is 8 degrees 38 minutes 55.4 seconds\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "NA=0.20; #numerical aperture\n",
+ "n2=1.59; #refractive index of cladding\n",
+ "n0=1.33; #refractive index of water\n",
+ "\n",
+ "#Calculation\n",
+ "n1=math.sqrt(NA**2+n2**2); #refractive index of core\n",
+ "theta0=math.asin(NA/n0); #acceptance angle(radian)\n",
+ "theta0=theta0*180/math.pi; #acceptance angle(degrees)\n",
+ "theta0_m=60*(theta0-int(theta0));\n",
+ "theta0_s=60*(theta0_m-int(theta0_m));\n",
+ "\n",
+ "#Result\n",
+ "print \"acceptance angle is\",int(theta0),\"degrees\",int(theta0_m),\"minutes\",round(theta0_s,1),\"seconds\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 11.10, Page number 11.20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "fractional refractive indices change is 6.8966 *10**-3\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1=1.45; #refractive index of core\n",
+ "n2=1.44; #refractive index of cladding\n",
+ "\n",
+ "#Calculation\n",
+ "delta=(n1-n2)/n1; #fractional refractive indices change\n",
+ "\n",
+ "#Result\n",
+ "print \"fractional refractive indices change is\",round(delta*10**3,4),\"*10**-3\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 11.11, Page number 11.20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "refractive index of cladding is 1.44\n",
+ "numerical aperture is 0.42\n",
+ "acceptance angle is 24 degrees 50 minutes\n",
+ "critical angle is 73 degrees 44 minutes\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1=1.50; #refractive index of core\n",
+ "delta=4/100; #fractional refractive indices change\n",
+ "\n",
+ "#Calculation\n",
+ "n2=n1-(n1*delta); #refractive index of cladding\n",
+ "NA=math.sqrt((n1**2)-(n2**2)); #numerical aperture\n",
+ "theta0=math.asin(NA); #acceptance angle(radian)\n",
+ "theta0=theta0*180/math.pi; #acceptance angle(degrees)\n",
+ "theta0_m=60*(theta0-int(theta0));\n",
+ "thetac=math.asin(n2/n1); #critical angle(radian)\n",
+ "thetac=thetac*180/math.pi; #critical angle(degrees)\n",
+ "thetac_m=60*(thetac-int(thetac));\n",
+ "\n",
+ "#Result\n",
+ "print \"refractive index of cladding is\",n2\n",
+ "print \"numerical aperture is\",round(NA,2)\n",
+ "print \"acceptance angle is\",int(theta0),\"degrees\",int(theta0_m),\"minutes\"\n",
+ "print \"critical angle is\",int(thetac),\"degrees\",int(thetac_m),\"minutes\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 11.12, Page number 11.21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "numerical aperture is 0.446\n",
+ "acceptance angle is 26 degrees 29.5 minutes\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1=1.563; #refractive index of core\n",
+ "n2=1.498; #refractive index of cladding\n",
+ "\n",
+ "#Calculation\n",
+ "NA=math.sqrt((n1**2)-(n2**2)); #numerical aperture\n",
+ "theta0=math.asin(NA); #acceptance angle(radian)\n",
+ "theta0=theta0*180/math.pi; #acceptance angle(degrees)\n",
+ "theta0_m=60*(theta0-int(theta0));\n",
+ "\n",
+ "#Result\n",
+ "print \"numerical aperture is\",round(NA,3)\n",
+ "print \"acceptance angle is\",int(theta0),\"degrees\",round(theta0_m,1),\"minutes\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Engineering_Physics_by_S._Mani_Naidu/Chapter14.ipynb b/Engineering_Physics_by_S._Mani_Naidu/Chapter14.ipynb
new file mode 100755
index 00000000..cea37dd0
--- /dev/null
+++ b/Engineering_Physics_by_S._Mani_Naidu/Chapter14.ipynb
@@ -0,0 +1,494 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#14: Optics"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 14.1, Page number 14.41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ratio of maximum intensity to minimum intensity is 19.727\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "I1=10; #intensity(w/m**2)\n",
+ "I2=25; #intensity(w/m**2)\n",
+ "\n",
+ "#Calculation\n",
+ "a1bya2=math.sqrt(I1/I2); \n",
+ "I=((1+a1bya2)**2)/((a1bya2-1)**2); #ratio of maximum intensity to minimum intensity\n",
+ "\n",
+ "#Result\n",
+ "print \"ratio of maximum intensity to minimum intensity is\",round(I,3)\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 14.2, Page number 14.42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "angular position of 10th maximum is 3 degrees 7 minutes 30.887 seconds\n",
+ "answer varies due to rounding off errors\n",
+ "angular position of 1st minimum is 0 degrees 9 minutes 23 seconds\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda=5460*10**-10; #wavelength(m)\n",
+ "d=1*10**-4; #seperation(m)\n",
+ "D=2; #distance(m)\n",
+ "n=10; #position\n",
+ "\n",
+ "#Calculation\n",
+ "Xmax10=n*lamda*D/d;\n",
+ "tan_phi=Xmax10/D; \n",
+ "phi_max10=math.atan(tan_phi);\n",
+ "phi_max10=phi_max10*180/math.pi; #angular position of 10th maximum(degrees)\n",
+ "phim=60*(phi_max10-int(phi_max10));\n",
+ "phis=60*(phim-int(phim));\n",
+ "xmin1=lamda*D/(2*d); \n",
+ "tan_phi1=xmin1/D;\n",
+ "phi_min1=math.atan(tan_phi1);\n",
+ "phi_min1=phi_min1*180/math.pi; #angular position of 1st minimum(degrees)\n",
+ "phi_m=60*(phi_min1-int(phi_min1));\n",
+ "phi_s=60*(phi_m-int(phi_m));\n",
+ "\n",
+ "#Result\n",
+ "print \"angular position of 10th maximum is\",int(phi_max10),\"degrees\",int(phim),\"minutes\",round(phis,3),\"seconds\"\n",
+ "print \"answer varies due to rounding off errors\"\n",
+ "print \"angular position of 1st minimum is\",int(phi_min1),\"degrees\",int(phi_m),\"minutes\",int(phi_s),\"seconds\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 14.3, Page number 14.43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 41,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "5320.0 angstrom lies in the visible region\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mew=1.33; #refractive index of soap\n",
+ "t=5000*10**-10; #thickness(m)\n",
+ "n0=0;\n",
+ "n1=1;\n",
+ "n2=2;\n",
+ "n3=3;\n",
+ "\n",
+ "#Calculation\n",
+ "x=4*mew*t;\n",
+ "lamda1=x/((2*n0)+1); #for n=0\n",
+ "lamda2=x/((2*n1)+1); #for n=1\n",
+ "lamda3=x/((2*n2)+1); #for n=2\n",
+ "lamda4=x/((2*n3)+1); #for n=3\n",
+ "\n",
+ "#Result\n",
+ "print lamda3*10**10,\"angstrom lies in the visible region\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 14.4, Page number 14.43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "wavelength of light is 5880 angstrom\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "D15=0.59*10**-2; #diameter of 15th ring(m)\n",
+ "D5=0.336*10**-2; #diameter of 5th ring(m)\n",
+ "R=1; #radius(m)\n",
+ "m=10;\n",
+ "\n",
+ "#Calculation\n",
+ "lamda=((D15**2)-(D5**2))/(4*m*R); #wavelength of light(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength of light is\",int(lamda*10**10),\"angstrom\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 14.5, Page number 14.44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 43,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "radius of curvature is 1.059 m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "D10=0.5*10**-2; #diameter of 10th ring(m)\n",
+ "lamda=5900*10**-10; #wavelength of light(m)\n",
+ "n=10;\n",
+ "\n",
+ "#Calculation\n",
+ "R=D10**2/(4*n*lamda); #radius of curvature(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"radius of curvature is\",round(R,3),\"m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 14.6, Page number 14.44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 44,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "least distance of the point is 13 mm\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda1=650*10**-9; #wavelength(m)\n",
+ "lamda2=500*10**-9; #wavelength(m)\n",
+ "D=1; #distance(m)\n",
+ "d=0.5*10**-3; #seperation(m)\n",
+ "n=10;\n",
+ "\n",
+ "#Calculation\n",
+ "x=n*lamda1*D/d; #least distance of the point(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"least distance of the point is\",int(x*10**3),\"mm\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 14.7, Page number 14.45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 45,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "thickness is 2.5 micro m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda=500*10**-9; #wavelength(m)\n",
+ "n=10;\n",
+ "D10=2*10**-3; #diameter(m)\n",
+ "\n",
+ "#Calculation\n",
+ "r10=D10/2; #radius(m)\n",
+ "R=D10**2/(4*n*lamda);\n",
+ "t=r10**2/(2*R); #thickness(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"thickness is\",t*10**6,\"micro m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 14.8, Page number 14.45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 46,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "fringe width is 2.75 mm\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "d=0.2*10**-3; #seperation(m)\n",
+ "lamda=550*10**-9; #wavelength(m)\n",
+ "D=1; #diameter(m)\n",
+ "\n",
+ "#Calculation\n",
+ "beta=lamda*D/d; #fringe width(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"fringe width is\",beta*10**3,\"mm\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 14.9, Page number 14.45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 47,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "separation between slits is 2 mm\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda=500*10**-9; #wavelength(m)\n",
+ "D=2; #diameter(m)\n",
+ "beta=(5/100)*10**-2; #fringe width(m)\n",
+ "\n",
+ "#Calculation\n",
+ "d=lamda*D/beta; #separation between slits(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"separation between slits is\",int(d*10**3),\"mm\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 14.10, Page number 14.46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ratio of maximum intensity to minimum intensity is 2.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "a12=36; #intensity 1\n",
+ "a22=1; #intensity 2\n",
+ "\n",
+ "#Calculation\n",
+ "a1=math.sqrt(a12);\n",
+ "a2=math.sqrt(a22);\n",
+ "Imin=(a1-a2)**2; #minimum intensity\n",
+ "Imax=(a1+a2)**2; #maximum intensity\n",
+ "r=Imax/Imin;\n",
+ "\n",
+ "#Result\n",
+ "print \"ratio of maximum intensity to minimum intensity is\",round(r)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 14.11, Page number 14.46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 51,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "diameter of 25th ring is 0.8239 cm\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "D5=0.3; #diameter of 5th ring(cm)\n",
+ "D15=0.62; #diameter of 15th ring(cm)\n",
+ "\n",
+ "#Calculation\n",
+ "D_25=2*(D15**2)-(D5**2);\n",
+ "D25=math.sqrt(D_25); #diameter of 25th ring(cm)\n",
+ "\n",
+ "#Result\n",
+ "print \"diameter of 25th ring is\",round(D25,4),\"cm\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Engineering_Physics_by_S._Mani_Naidu/Chapter2.ipynb b/Engineering_Physics_by_S._Mani_Naidu/Chapter2.ipynb
new file mode 100755
index 00000000..b1f33747
--- /dev/null
+++ b/Engineering_Physics_by_S._Mani_Naidu/Chapter2.ipynb
@@ -0,0 +1,271 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#2: Crystal Structures"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 2.1, Page number 2.16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "free volume/unit cell is 0.007675 nm**3\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "r=0.1249; #atomic radius(nm)\n",
+ "n=2; #number of atoms\n",
+ "\n",
+ "#Calculation\n",
+ "a=4*r/math.sqrt(3); #edge length(m)\n",
+ "V=a**3; #volume(nm**3)\n",
+ "v=4*math.pi*r**3*n/3; #volume of atoms(nm**3)\n",
+ "Fv=V-v; #free volume/unit cell(nm**3)\n",
+ "\n",
+ "#Result\n",
+ "print \"free volume/unit cell is\",round(Fv,6),\"nm**3\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 2.2, Page number 2.16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "lattice constant is 3.517 angstrom\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=2; #number of atoms\n",
+ "M=6.94; #atomic weight(kg)\n",
+ "rho=530; #density(kg/m**3)\n",
+ "Na=6.02*10**26; #avagadro number\n",
+ "\n",
+ "#Calculation\n",
+ "a3=n*M/(rho*Na);\n",
+ "a=a3**(1/3); #lattice constant(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"lattice constant is\",round(a*10**10,3),\"angstrom\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 2.3, Page number 2.17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "lattice constant is 2.87 angstrom\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=2; #number of atoms\n",
+ "M=55.85; #atomic weight(kg)\n",
+ "rho=7860; #density(kg/m**3)\n",
+ "Na=6.02*10**26; #avagadro number\n",
+ "\n",
+ "#Calculation\n",
+ "a3=n*M/(rho*Na);\n",
+ "a=a3**(1/3); #lattice constant(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"lattice constant is\",round(a*10**10,2),\"angstrom\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 2.4, Page number 2.17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "#number of atoms per m**3 is 177.3 *10**27\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=0.356*10**-9; #lattice constant(m)\n",
+ "n=8; #number of atoms\n",
+ "\n",
+ "#Calculation\n",
+ "N=n/a**3; #number of atoms per m**3\n",
+ "\n",
+ "#Result\n",
+ "print \"#number of atoms per m**3 is\",round(N/10**27,1),\"*10**27\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 2.5, Page number 2.17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "number of atoms per sq. mm is 8.16 *10**12\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=3.5; #lattice constant(angstrom)\n",
+ "\n",
+ "#Calculation\n",
+ "A=a**2;\n",
+ "N=10**7*10**7/A; #number of atoms per sq. mm\n",
+ "\n",
+ "#Result\n",
+ "print \"number of atoms per sq. mm is\",round(N/10**12,2),\"*10**12\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 2.6, Page number 2.18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "density is 5434.5 kg/m**3\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=8; #number of atoms\n",
+ "a=5.62*10**-10; #lattice constant(m)\n",
+ "M=72.59; #atomic weight(kg)\n",
+ "Na=6.02*10**26; #avagadro number\n",
+ "\n",
+ "#Calculation\n",
+ "rho=n*M/(a**3*Na); #density(kg/m**3)\n",
+ "\n",
+ "#Result\n",
+ "print \"density is\",round(rho,1),\"kg/m**3\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Engineering_Physics_by_S._Mani_Naidu/Chapter3.ipynb b/Engineering_Physics_by_S._Mani_Naidu/Chapter3.ipynb
new file mode 100755
index 00000000..e0db4e17
--- /dev/null
+++ b/Engineering_Physics_by_S._Mani_Naidu/Chapter3.ipynb
@@ -0,0 +1,658 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#3: Crystal planes, X-ray diffraction and defects in solids"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.1, Page number 3.19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "glancing angle is 21 degrees\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda=0.071*10**-9; #wavelength(m)\n",
+ "a=0.28*10**-9; #lattice constant(m)\n",
+ "h=1;\n",
+ "k=1;\n",
+ "l=0;\n",
+ "n=2; #order of diffraction\n",
+ "\n",
+ "#Calculation\n",
+ "d=a/math.sqrt(h**2+k**2+l**2);\n",
+ "x=n*lamda/(2*d); \n",
+ "theta=math.asin(x); #angle(radian)\n",
+ "theta=theta*180/math.pi; #glancing angle(degrees)\n",
+ "\n",
+ "#Result\n",
+ "print \"glancing angle is\",int(theta),\"degrees\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.2, Page number 3.19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "wavelength is 0.0842 nm\n",
+ "maximum order of diffraction is 7.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=1; #order of diffraction\n",
+ "theta1=8+(35/60); #angle(degrees)\n",
+ "d=0.282; #spacing(nm)\n",
+ "theta2=90;\n",
+ "\n",
+ "#Calculation\n",
+ "theta1=theta1*math.pi/180; #angle(radian)\n",
+ "lamda=2*d*math.sin(theta1)/n; #wavelength(nm)\n",
+ "theta2=theta2*math.pi/180; #angle(radian)\n",
+ "nmax=2*d/lamda; #maximum order of diffraction\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength is\",round(lamda,4),\"nm\"\n",
+ "print \"maximum order of diffraction is\",round(nmax)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.3, Page number 3.20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "fraction of vacancy sites is 8.466 *10**-7\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "T1=500+273; #temperature(K)\n",
+ "T2=1000+273; #temperature(K)\n",
+ "f=1*10**-10; #fraction\n",
+ "\n",
+ "#Calculation\n",
+ "x=round(T1/T2,5);\n",
+ "y=round(math.log(f),3);\n",
+ "w=round(x*y,3);\n",
+ "F=math.exp(w); #fraction of vacancy sites\n",
+ "\n",
+ "#Result\n",
+ "print \"fraction of vacancy sites is\",round(F*10**7,3),\"*10**-7\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.4, Page number 3.21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ratio is math.sqrt( 6.0 ): math.sqrt( 3.0 ): math.sqrt( 2.0 )\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=1; #assume\n",
+ "h1=1;\n",
+ "k1=0;\n",
+ "l1=0;\n",
+ "h2=1;\n",
+ "k2=1;\n",
+ "l2=0;\n",
+ "h3=1;\n",
+ "k3=1;\n",
+ "l3=1;\n",
+ "\n",
+ "#Calculation\n",
+ "d100=a*6/(h1**2+k1**2+l1**2);\n",
+ "d110=a*6/(h2**2+k2**2+l2**2);\n",
+ "d111=a*(6)/(h3**2+k3**2+l3**2);\n",
+ "\n",
+ "#Result\n",
+ "print \"ratio is math.sqrt(\",d100,\"): math.sqrt(\",d110,\"): math.sqrt(\",d111,\")\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.5, Page number 3.21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "lattice parameter of nickel is 3.522 angstrom\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=1; #order of diffraction\n",
+ "theta=38.2; #angle(degrees)\n",
+ "lamda=1.54; #wavelength(angstrom)\n",
+ "h=2;\n",
+ "k=2;\n",
+ "l=0;\n",
+ "\n",
+ "#Calculation\n",
+ "theta=theta*math.pi/180; #angle(radian)\n",
+ "d=n*lamda/(2*math.sin(theta));\n",
+ "a=d*math.sqrt(h**2+k**2+l**2); #lattice parameter of nickel(angstrom)\n",
+ "\n",
+ "#Result\n",
+ "print \"lattice parameter of nickel is\",round(a,3),\"angstrom\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.6, Page number 3.22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "order of diffraction is 2\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "theta=90; #angle(degrees)\n",
+ "lamda=1.5; #wavelength(angstrom)\n",
+ "d=1.6; #spacing(angstrom)\n",
+ "\n",
+ "#Calculation\n",
+ "theta=theta*math.pi/180; #angle(radian)\n",
+ "n=2*d*math.sin(theta)/lamda; #order of diffraction\n",
+ "\n",
+ "#Result\n",
+ "print \"order of diffraction is\",int(n)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.7, Page number 3.22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "length of unit cell is 0.287 *10**-9 m\n",
+ "volume of unit cell is 0.02366 *10**-27 m**3\n",
+ "radius of the atom is 0.1243 *10**-9 m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "h=1;\n",
+ "k=1;\n",
+ "l=0;\n",
+ "d=0.203*10**-9; #spacing(m)\n",
+ "\n",
+ "#Calculation\n",
+ "a=d*math.sqrt(h**2+k**2+l**2); #length of unit cell(m)\n",
+ "V=a**3; #volume of unit cell(m**3)\n",
+ "r=math.sqrt(3)*a/4; #radius of the atom(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"length of unit cell is\",round(a*10**9,3),\"*10**-9 m\"\n",
+ "print \"volume of unit cell is\",round(V*10**27,5),\"*10**-27 m**3\"\n",
+ "print \"radius of the atom is\",round(r*10**9,4),\"*10**-9 m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.8, Page number 3.22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "order of diffraction is 2\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "theta=90; #angle(degrees)\n",
+ "lamda=1.5; #wavelength(angstrom)\n",
+ "d=1.6; #spacing(angstrom)\n",
+ "\n",
+ "#Calculation\n",
+ "theta=theta*math.pi/180; #angle(radian)\n",
+ "n=2*d*math.sin(theta)/lamda; #order of diffraction\n",
+ "\n",
+ "#Result\n",
+ "print \"order of diffraction is\",int(n)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.9, Page number 3.23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "glancing angle is 20 degrees 42 minutes 17 seconds\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda=0.065; #wavelength(nm)\n",
+ "a=0.26; #edge length(nm)\n",
+ "h=1;\n",
+ "k=1;\n",
+ "l=0;\n",
+ "n=2;\n",
+ "\n",
+ "#Calculation\n",
+ "d=a/math.sqrt(h**2+k**2+l**2); \n",
+ "x=n*lamda/(2*d); \n",
+ "theta=math.asin(x); #glancing angle(radian)\n",
+ "theta=theta*180/math.pi; #glancing angle(degrees)\n",
+ "theta_d=int(theta); \n",
+ "theta_m=(theta-theta_d)*60;\n",
+ "theta_s=(theta_m-int(theta_m))*60;\n",
+ "\n",
+ "#Result\n",
+ "print \"glancing angle is\",theta_d,\"degrees\",int(theta_m),\"minutes\",int(theta_s),\"seconds\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.10, Page number 3.23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "cube edge of unit cell is 4.055 angstrom\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda=1.54; #wavelength(angstrom)\n",
+ "h=1;\n",
+ "k=1;\n",
+ "l=1;\n",
+ "n=1;\n",
+ "theta=19.2; #angle(degrees)\n",
+ "\n",
+ "#Calculation\n",
+ "theta=theta*math.pi/180; #angle(radian)\n",
+ "d=n*lamda/(2*math.sin(theta)); \n",
+ "a=d*math.sqrt(h**2+k**2+l**2); #cube edge of unit cell(angstrom)\n",
+ "\n",
+ "#Result\n",
+ "print \"cube edge of unit cell is\",round(a,3),\"angstrom\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.11, Page number 3.24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "lattice parameter of nickel is 3.522 angstrom\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda=1.54; #wavelength(angstrom)\n",
+ "h=2;\n",
+ "k=2;\n",
+ "l=0;\n",
+ "n=1;\n",
+ "theta=38.2; #angle(degrees)\n",
+ "\n",
+ "#Calculation\n",
+ "theta=theta*math.pi/180; #angle(radian)\n",
+ "d=n*lamda/(2*math.sin(theta)); \n",
+ "a=d*math.sqrt(h**2+k**2+l**2); #lattice parameter of nickel(angstrom)\n",
+ "\n",
+ "#Result\n",
+ "print \"lattice parameter of nickel is\",round(a,3),\"angstrom\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.12, Page number 3.24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "interplanar spacing for (111) is 0.208 nm\n",
+ "interplanar spacing for (321) is 0.096 nm\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=0.36; #edge length(nm)\n",
+ "h1=1;\n",
+ "k1=1;\n",
+ "l1=1;\n",
+ "h2=3;\n",
+ "k2=2;\n",
+ "l2=1;\n",
+ "\n",
+ "#Calculation\n",
+ "d1=a/math.sqrt(h1**2+k1**2+l1**2); #interplanar spacing for (111)(nm)\n",
+ "d2=a/math.sqrt(h2**2+k2**2+l2**2); #interplanar spacing for (321)(nm)\n",
+ "\n",
+ "#Result\n",
+ "print \"interplanar spacing for (111) is\",round(d1,3),\"nm\"\n",
+ "print \"interplanar spacing for (321) is\",round(d2,3),\"nm\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.13, Page number 3.25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "glancing angle is 16 degrees 27 minutes\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda=0.675; #wavelength(angstrom)\n",
+ "n=3; #order of diffraction\n",
+ "theta=5+(25/60); #angle(degrees)\n",
+ "\n",
+ "#Calculation\n",
+ "theta=theta*math.pi/180; #angle(radian)\n",
+ "d=lamda/(2*math.sin(theta)); \n",
+ "theta3=math.asin(3*lamda/(2*d)); #glancing angle(radian)\n",
+ "theta3=theta3*180/math.pi; #glancing angle(degrees)\n",
+ "theta_d=int(theta3); \n",
+ "theta_m=(theta3-theta_d)*60;\n",
+ "\n",
+ "#Result\n",
+ "print \"glancing angle is\",theta_d,\"degrees\",int(theta_m),\"minutes\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 3.14, Page number 3.25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "glancing angle is 22 degrees 56 minutes 31 seconds\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda=0.79; #wavelength(angstrom)\n",
+ "n=3; #order of diffraction\n",
+ "d=3.04; #spacing(angstrom)\n",
+ "\n",
+ "#Calculation\n",
+ "x=round(n*lamda/(2*d),4);\n",
+ "theta=math.asin(x); #glancing angle(radian)\n",
+ "theta=theta*180/math.pi; #glancing angle(degrees)\n",
+ "theta_d=int(theta); \n",
+ "theta_m=(theta-theta_d)*60;\n",
+ "theta_s=(theta_m-int(theta_m))*60;\n",
+ "\n",
+ "#Result\n",
+ "print \"glancing angle is\",theta_d,\"degrees\",int(theta_m),\"minutes\",int(theta_s),\"seconds\"\n",
+ "print \"answer given in the book is wrong\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Engineering_Physics_by_S._Mani_Naidu/Chapter4.ipynb b/Engineering_Physics_by_S._Mani_Naidu/Chapter4.ipynb
new file mode 100755
index 00000000..aba467a3
--- /dev/null
+++ b/Engineering_Physics_by_S._Mani_Naidu/Chapter4.ipynb
@@ -0,0 +1,578 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#4: Principles of quantum mechanics"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.1, Page number 4.30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "wavelength is 0.0275 nm\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.6*10**-19; \n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "E=2000; #energy(eV)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda=h/math.sqrt(2*m*E*e); #wavelength(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength is\",round(lamda*10**9,4),\"nm\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.2, Page number 4.30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "velocity is 438.6 *10**4 m/s\n",
+ "answer varies due to rounding off errors\n",
+ "kinetic energy is 54.71 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.6*10**-19; \n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "h=6.626*10**-34; #planck's constant\n",
+ "lamda=1.66*10**-10; #wavelength(m)\n",
+ "\n",
+ "#Calculation\n",
+ "v=h/(m*lamda); #velocity(m/s)\n",
+ "E=h**2/(2*m*e*lamda**2); #kinetic energy(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"velocity is\",round(v/10**4,1),\"*10**4 m/s\"\n",
+ "print \"answer varies due to rounding off errors\"\n",
+ "print \"kinetic energy is\",round(E,2),\"eV\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.3, Page number 4.31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "energy value in ground state is 37.7377 eV\n",
+ "energy value in 1st state is 150.95 eV\n",
+ "energy value in 2nd state is 339.6395 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=1;\n",
+ "e=1.6*10**-19; \n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "L=1*10**-10; #width(m)\n",
+ "\n",
+ "#Calculation\n",
+ "E1=n**2*h**2/(8*m*e*L**2); #energy value in ground state(eV)\n",
+ "E2=4*E1; #energy value in 1st state(eV)\n",
+ "E3=9*E1; #energy value in 2nd state(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"energy value in ground state is\",round(E1,4),\"eV\"\n",
+ "print \"energy value in 1st state is\",round(E2,2),\"eV\"\n",
+ "print \"energy value in 2nd state is\",round(E3,4),\"eV\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.4, Page number 4.31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "minimum energy is 2.3586 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=1;\n",
+ "e=1.6*10**-19; \n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "L=4*10**-10; #width(m)\n",
+ "\n",
+ "#Calculation\n",
+ "E1=n**2*h**2/(8*m*e*L**2); #energy value in ground state(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"minimum energy is\",round(E1,4),\"eV\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.5, Page number 4.32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "wavelength is 0.01 nm\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "V=15*10**3; #voltage(V)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda=1.227/math.sqrt(V); #wavelength(nm)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength is\",round(lamda,2),\"nm\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.6, Page number 4.32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "minimum energy is 150.95 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=1;\n",
+ "e=1.6*10**-19; \n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "L=0.05*10**-9; #width(m)\n",
+ "\n",
+ "#Calculation\n",
+ "E1=n**2*h**2/(8*m*e*L**2); #energy value in ground state(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"minimum energy is\",round(E1,2),\"eV\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.8, Page number 4.32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "minimum energy is 4.2 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=1;\n",
+ "e=1.6*10**-19; \n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "L=3*10**-10; #width(m)\n",
+ "\n",
+ "#Calculation\n",
+ "E1=n**2*h**2/(8*m*e*L**2); #energy value in ground state(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"minimum energy is\",round(E1,1),\"eV\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.9, Page number 4.33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "de broglie wavelength is 8488 nm\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "me=1.676*10**-27; #mass(kg) \n",
+ "mn=9.1*10**-31; #mass(kg)\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "\n",
+ "#Calculation\n",
+ "lamda_n=h/math.sqrt(4*mn*me); #de broglie wavelength(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"de broglie wavelength is\",int(lamda_n*10**9),\"nm\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.10, Page number 4.33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "energy value in 2nd quantum state is 37.738 eV\n",
+ "energy value in 4th quantum state is 150.95 eV\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=1;\n",
+ "e=1.6*10**-19; \n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "L=2*10**-10; #width(m)\n",
+ "\n",
+ "#Calculation\n",
+ "E1=n**2*h**2/(8*m*e*L**2); #energy value in ground state(eV)\n",
+ "E2=2**2*E1; #energy value in 2nd quantum state(eV)\n",
+ "E4=4**2*E1; #energy value in 2nd quantum state(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"energy value in 2nd quantum state is\",round(E2,3),\"eV\"\n",
+ "print \"energy value in 4th quantum state is\",round(E4,2),\"eV\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.11, Page number 4.34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "interplanar spacing is 0.382 angstrom\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.6*10**-19; \n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "V=344; #potemtial(V)\n",
+ "n=1;\n",
+ "theta=60; #angle(degrees)\n",
+ "\n",
+ "#Calculation\n",
+ "theta=theta*math.pi/180; #angle(radian)\n",
+ "d=n*h/(2*math.sin(theta)*math.sqrt(2*m*V*e)); #interplanar spacing(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"interplanar spacing is\",round(d*10**10,3),\"angstrom\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.12, Page number 4.34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "energy required to pump an electron is 301.57 eV\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=1;\n",
+ "e=1.6*10**-19; \n",
+ "m=9.11*10**-31; #mass(kg)\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "L=1*10**-10; #width(m)\n",
+ "\n",
+ "#Calculation\n",
+ "E1=n**2*h**2/(8*m*e*L**2); #energy value in ground state(eV)\n",
+ "E3=3**2*E1; #energy value in 2nd quantum state(eV)\n",
+ "E=E3-E1; #energy required to pump an electron(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"energy required to pump an electron is\",round(E,2),\"eV\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.13, Page number 4.34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "minimum energy is 9.424 eV\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n=1;\n",
+ "e=1.6*10**-19; \n",
+ "m=9.11*10**-31; #mass(kg)\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "L=2*10**-10; #width(m)\n",
+ "\n",
+ "#Calculation\n",
+ "E1=n**2*h**2/(8*m*e*L**2); #energy value in ground state(eV)\n",
+ "\n",
+ "#Result\n",
+ "print \"minimum energy is\",round(E1,3),\"eV\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 4.14, Page number 4.35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 43,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "wavelength is 0.31 angstrom\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "V=1600; #voltage(V)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda=1.227/math.sqrt(V); #wavelength(nm)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength is\",round(lamda*10,2),\"angstrom\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Engineering_Physics_by_S._Mani_Naidu/Chapter5.ipynb b/Engineering_Physics_by_S._Mani_Naidu/Chapter5.ipynb
new file mode 100755
index 00000000..f11e05ff
--- /dev/null
+++ b/Engineering_Physics_by_S._Mani_Naidu/Chapter5.ipynb
@@ -0,0 +1,566 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#5: Electron theory of metals"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.1, Page number 5.27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "temperature is 1260.84 K\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "fE=1/100; #probability(%)\n",
+ "E_EF=0.5; #fermi energy(eV)\n",
+ "Kb=1.38*10**-23; #boltzmann constant\n",
+ "e=6.24*10**18; #conversion faction from J to eV\n",
+ "\n",
+ "#Calculation\n",
+ "x=E_EF/(Kb*e);\n",
+ "y=math.log(1/fE);\n",
+ "T=x/y; #temperature(K)\n",
+ "\n",
+ "#Result\n",
+ "print \"temperature is\",round(T,2),\"K\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.2, Page number 5.28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "total number of free electrons is 8.3954 **10**28 per m**3\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Ef=7*1.602*10**-19; #fermi energy(J)\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "m=9.11*10**-31; #mass(kg)\n",
+ "\n",
+ "#Calculation\n",
+ "x=h**2/(8*m);\n",
+ "y=(3/math.pi)**(2/3);\n",
+ "n23=Ef/(x*y);\n",
+ "n=n23**(3/2); #total number of free electrons(per m**3)\n",
+ "\n",
+ "#Result\n",
+ "print \"total number of free electrons is\",round(n/10**28,4),\"**10**28 per m**3\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.3, Page number 5.28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 38,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "relaxation time is 39.742 *10**-15 s\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "rho=1.54*10**-8; #resistivity of metal(ohm m)\n",
+ "n=5.8*10**28; #number of free electrons(per m**3)\n",
+ "e=1.602*10**-19; #charge(c)\n",
+ "m=9.11*10**-31; #mass(kg)\n",
+ "\n",
+ "#Calculation\n",
+ "tow=m/(n*e**2*rho); #relaxation time(s)\n",
+ "\n",
+ "#Result\n",
+ "print \"relaxation time is\",round(tow*10**15,3),\"*10**-15 s\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.4, Page number 5.29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "relaxation time is 3.82 *10**-14 s\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "rho=1.43*10**-8; #resistivity of metal(ohm m)\n",
+ "n=6.5*10**28; #number of free electrons(per m**3)\n",
+ "e=1.6*10**-19; #charge(c)\n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "\n",
+ "#Calculation\n",
+ "tow=m/(n*e**2*rho); #relaxation time(s)\n",
+ "\n",
+ "#Result\n",
+ "print \"relaxation time is\",round(tow*10**14,2),\"*10**-14 s\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.5, Page number 5.29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "number of conduction electrons is 1.8088 *10**29 per m**3\n",
+ "mobility of electrons is 0.00128 m**2/Vs\n",
+ "drift velocity is 2.3 *10**-4 m/s\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "L=5; #length(m)\n",
+ "R=0.06; #resistance(ohm)\n",
+ "I=15; #current(A)\n",
+ "ne=3; #number of electrons\n",
+ "rho=2.7*10**-8; #resistivity(ohm m)\n",
+ "w=26.98; #atomic weight\n",
+ "D=2.7*10**3; #density(kg/m**3)\n",
+ "Na=6.025*10**26; #avagadro number(per k mol)\n",
+ "\n",
+ "#Calculation\n",
+ "n=ne*Na*D/w; #number of conduction electrons(per m**3)\n",
+ "mew=1/(n*e*rho); #mobility of electrons(m**2/Vs)\n",
+ "vd=I*R/(L*rho*n*e); #drift velocity(m/s)\n",
+ "\n",
+ "#Result\n",
+ "print \"number of conduction electrons is\",round(n/10**29,4),\"*10**29 per m**3\"\n",
+ "print \"mobility of electrons is\",round(mew,5),\"m**2/Vs\"\n",
+ "print \"drift velocity is\",round(vd*10**4,1),\"*10**-4 m/s\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.6, Page number 5.30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 43,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "mobility of electrons is 0.00427 m**2/Vs\n",
+ "answer in the book is wrong\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "ne=1; #number of electrons\n",
+ "rho=1.73*10**-8; #resistivity(ohm m)\n",
+ "w=63.5; #atomic weight\n",
+ "e=1.6*10**-19; #charge(c)\n",
+ "D=8.92*10**3; #density(kg/m**3)\n",
+ "Na=6.02*10**26; #avagadro number(per k mol)\n",
+ "\n",
+ "#Calculation\n",
+ "n=ne*Na*D/w;\n",
+ "mew=1/(n*e*rho); #mobility of electrons(m**2/Vs)\n",
+ "\n",
+ "#Result\n",
+ "print \"mobility of electrons is\",round(mew,5),\"m**2/Vs\"\n",
+ "print \"answer in the book is wrong\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.7, Page number 5.31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 44,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "mobility of electrons is 0.00428 m**2/Vs\n",
+ "answer in the book is wrong\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "ne=1; #number of electrons\n",
+ "rho=1.721*10**-8; #resistivity(ohm m)\n",
+ "w=63.54; #atomic weight\n",
+ "e=1.6*10**-19; #charge(c)\n",
+ "D=8.95*10**3; #density(kg/m**3)\n",
+ "Na=6.025*10**26; #avagadro number(per k mol)\n",
+ "\n",
+ "#Calculation\n",
+ "n=ne*Na*D/w;\n",
+ "mew=1/(n*e*rho); #mobility of electrons(m**2/Vs)\n",
+ "\n",
+ "#Result\n",
+ "print \"mobility of electrons is\",round(mew,5),\"m**2/Vs\"\n",
+ "print \"answer in the book is wrong\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.8, Page number 5.31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "relaxation time is 3.64 *10**-14 s\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "rho=1.5*10**-8; #resistivity of metal(ohm m)\n",
+ "n=6.5*10**28; #number of free electrons(per m**3)\n",
+ "e=1.602*10**-19; #charge(c)\n",
+ "m=9.11*10**-31; #mass(kg)\n",
+ "\n",
+ "#Calculation\n",
+ "tow=m/(n*e**2*rho); #relaxation time(s)\n",
+ "\n",
+ "#Result\n",
+ "print \"relaxation time is\",round(tow*10**14,2),\"*10**-14 s\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.9, Page number 5.32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "relaxation time is 3.97 *10**-14 s\n",
+ "drift velocity is 0.7 m/s\n",
+ "mobility is 0.7 *10**-2 m**2/Vs\n",
+ "thermal velocity is 1.17 *10**5 m/s\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "rho=1.54*10**-8; #resistivity of metal(ohm m)\n",
+ "n=5.8*10**28; #number of free electrons(per m**3)\n",
+ "e=1.602*10**-19; #charge(c)\n",
+ "m=9.11*10**-31; #mass(kg)\n",
+ "E=1*10**2; #electric field(V/m)\n",
+ "Kb=1.381*10**-23; #boltzmann constant\n",
+ "T=300; #temperature(K)\n",
+ "\n",
+ "#Calculation\n",
+ "tow=m/(n*e**2*rho); #relaxation time(s)\n",
+ "vd=e*E*tow/m; #drift velocity(m/s)\n",
+ "mew=vd/E; #mobility(m**2/Vs)\n",
+ "Vth=math.sqrt(3*Kb*T/m); #thermal velocity(m/s)\n",
+ "\n",
+ "#Result\n",
+ "print \"relaxation time is\",round(tow*10**14,2),\"*10**-14 s\"\n",
+ "print \"drift velocity is\",round(vd,1),\"m/s\"\n",
+ "print \"mobility is\",round(mew*10**2,1),\"*10**-2 m**2/Vs\"\n",
+ "print \"thermal velocity is\",round(Vth/10**5,2),\"*10**5 m/s\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.10, Page number 5.32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 50,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "fermi velocity is 1.39 *10**6 m/s\n",
+ "mean free path is 5.52 *10**-8 m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "EF=5.5*1.602*10**-19; #fermi energy of silver(J)\n",
+ "tow=3.97*10**-14; #relaxation time(s)\n",
+ "m=9.11*10**-31; #mass(kg)\n",
+ "\n",
+ "#Calculation\n",
+ "vf=math.sqrt(2*EF/m); #fermi velocity(m/s)\n",
+ "lamda=vf*tow; #mean free path(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"fermi velocity is\",round(vf/10**6,2),\"*10**6 m/s\"\n",
+ "print \"mean free path is\",round(lamda*10**8,2),\"*10**-8 m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.11, Page number 5.33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 52,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "fermi energy is 8.83 *10**-19 J\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "ne=1; #number of electrons\n",
+ "M=107.9; #atomic weight\n",
+ "D=10500; #density(kg/m**3)\n",
+ "Na=6.025*10**26; #avagadro number(per k mol)\n",
+ "m=9.11*10**-31; #mass(kg)\n",
+ "h=6.63*10**-34; #planck's constant\n",
+ "\n",
+ "#Calculation\n",
+ "n=ne*Na*D/M; \n",
+ "x=h**2/(8*m);\n",
+ "y=(3/math.pi)**(2/3);\n",
+ "Ef=x*y*n**(2/3); #fermi energy(eV) \n",
+ "\n",
+ "#Result\n",
+ "print \"fermi energy is\",round(Ef*10**19,2),\"*10**-19 J\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.12, Page number 5.33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 58,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "drift velocity of free electrons is 0.7391 *10**-3 m/s\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "A=10*10**-6; #area(m**2)\n",
+ "ne=1; #number of electrons\n",
+ "I=100; #current(amperes)\n",
+ "w=63.5; #atomic weight\n",
+ "e=1.6*10**-19; #charge(c)\n",
+ "D=8.92*10**3; #density(kg/m**3)\n",
+ "Na=6.02*10**26; #avagadro number(per k mol)\n",
+ "\n",
+ "#Calculation\n",
+ "n=ne*Na*D/w;\n",
+ "J=I/A;\n",
+ "vd=J/(n*e); #drift velocity of free electrons(m/s)\n",
+ "\n",
+ "#Result\n",
+ "print \"drift velocity of free electrons is\",round(vd*10**3,4),\"*10**-3 m/s\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Engineering_Physics_by_S._Mani_Naidu/Chapter6.ipynb b/Engineering_Physics_by_S._Mani_Naidu/Chapter6.ipynb
new file mode 100755
index 00000000..2fa5c11e
--- /dev/null
+++ b/Engineering_Physics_by_S._Mani_Naidu/Chapter6.ipynb
@@ -0,0 +1,541 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#6: Dielectric properties"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 6.1, Page number 6.23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "dielectric constant of material is 1.339\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "N=3*10**28; #number of atoms(per m**3)\n",
+ "alpha_e=10**-40; #electronic polarizability(F m**2)\n",
+ "epsilon0=8.85*10**-12; \n",
+ "\n",
+ "#Calculation\n",
+ "epsilonr=(alpha_e*N/epsilon0)+1; #dielectric constant of material\n",
+ "\n",
+ "#Result\n",
+ "print \"dielectric constant of material is\",round(epsilonr,3)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 6.2, Page number 6.24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "capacitance is 8.85e-12 F\n",
+ "charge on plates is 8.85e-10 C\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "epsilon0=8.85*10**-12;\n",
+ "A=100*10**-4; #area(m**2)\n",
+ "d=1*10**-2; #seperation(m)\n",
+ "V=100; #potential(V)\n",
+ "\n",
+ "#Calculation\n",
+ "C=epsilon0*A/d; #capacitance(F)\n",
+ "Q=C*V; #charge on plates(C)\n",
+ "\n",
+ "#Result\n",
+ "print \"capacitance is\",C,\"F\"\n",
+ "print \"charge on plates is\",Q,\"C\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 6.3, Page number 6.24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "electronic polarizability is 2.242e-41 F m**2\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "epsilon0=8.85*10**-12;\n",
+ "epsilonr=1.0000684; #dielectric constant of material\n",
+ "N=2.7*10**25; #number of atoms(per m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "alpha_e=epsilon0*(epsilonr-1)/N; #electronic polarizability(F m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"electronic polarizability is\",alpha_e,\"F m**2\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 6.4, Page number 6.24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 38,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "voltage is 39.73 V\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "epsilon0=8.85*10**-12;\n",
+ "A=650*10**-6; #area(m**2)\n",
+ "d=4*10**-3; #seperation(m)\n",
+ "Q=2*10**-10; #charge(C)\n",
+ "epsilonr=3.5;\n",
+ "\n",
+ "#Calculation\n",
+ "V=Q*d/(epsilon0*epsilonr*A); #voltage(V)\n",
+ "\n",
+ "#Result\n",
+ "print \"voltage is\",round(V,2),\"V\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 6.5, Page number 6.25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "polarization is 212.4 *10**-9 C m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "epsilon0=8.85*10**-12;\n",
+ "A=6.45*10**-4; #area(m**2)\n",
+ "d=2*10**-3; #seperation(m)\n",
+ "V=12; #voltage(V)\n",
+ "epsilonr=5;\n",
+ "\n",
+ "#Calculation\n",
+ "P=epsilon0*(epsilonr-1)*V/d; #polarization(C m)\n",
+ "\n",
+ "#Result\n",
+ "print \"polarization is\",P*10**9,\"*10**-9 C m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 6.6, Page number 6.25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "electronic polarizability is 3.29 *10**-40 F m**2\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "epsilon0=8.85*10**-12;\n",
+ "epsilonr=3.75; #dielectric constant\n",
+ "gama=1/3; #internal field constant\n",
+ "D=2050; #density(kg/m**3)\n",
+ "Na=6.02*10**26; #avagadro number\n",
+ "M=32; #atomic weight\n",
+ "\n",
+ "#Calculation\n",
+ "N=Na*D/M; #number of atoms(per m**3)\n",
+ "alphae=((epsilonr-1)/(epsilonr+2))*3*epsilon0/N; #electronic polarizability(F m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"electronic polarizability is\",round(alphae*10**40,2),\"*10**-40 F m**2\"\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 6.7, Page number 6.26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 43,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "orientational polarization is 1.0298 *10**-11 C m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "N=1.6*10**20; #number of molecules(/m**3)\n",
+ "T=300; #temperature(K)\n",
+ "E=5*10**5; #electric field(V/m)\n",
+ "x=0.25*10**-9; #separation(m)\n",
+ "Kb=1.381*10**-23; #boltzmann constant\n",
+ "e=1.6*10**-19; \n",
+ "\n",
+ "#Calculation\n",
+ "Pd=N*e**2*x**2*E/(3*Kb*T); #orientational polarization\n",
+ "\n",
+ "#Result\n",
+ "print \"orientational polarization is\",round(Pd*10**11,4),\"*10**-11 C m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 6.8, Page number 6.26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 51,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "radius is 5.864 *10**-11 m\n",
+ "answer varies due to rounding off errors\n",
+ "displacement is 0.7 *10**-16 m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "epsilon0=8.85*10**-12;\n",
+ "epsilonr=1.0000684; #dielectric constant of material\n",
+ "N=2.7*10**25; #number of atoms(per m**3)\n",
+ "E=10**6; #electric field(V/m)\n",
+ "e=1.6*10**-19; \n",
+ "Z=2; #atomic number\n",
+ "\n",
+ "#Calculation\n",
+ "alpha_e=epsilon0*(epsilonr-1)/N; #electronic polarizability(F m**2)\n",
+ "r=(alpha_e/(4*math.pi*epsilon0))**(1/3); #radius(m)\n",
+ "d=alpha_e*E/(Z*e); #displacement(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"radius is\",round(r*10**11,3),\"*10**-11 m\"\n",
+ "print \"answer varies due to rounding off errors\"\n",
+ "print \"displacement is\",round(d*10**16,1),\"*10**-16 m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 6.9, Page number 6.27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 54,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "voltage is 53.8 V\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "epsilon0=8.85*10**-12;\n",
+ "A=750*10**-6; #area(m**2)\n",
+ "d=5*10**-3; #seperation(m)\n",
+ "Q=2.5*10**-10; #charge(C)\n",
+ "epsilonr=3.5;\n",
+ "\n",
+ "#Calculation\n",
+ "V=Q*d/(epsilon0*epsilonr*A); #voltage(V)\n",
+ "\n",
+ "#Result\n",
+ "print \"voltage is\",round(V,1),\"V\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 6.10, Page number 6.27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 55,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "dipole moment is 8.9 *10**-40 F m**2\n",
+ "polarization is 26.7 *10**-15 C m\n",
+ "dielectric constant is 1.00302\n",
+ "polarizability is 8.9 *10**-40 F m**2\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "N=3*10**25; #number of atoms(per m**3)\n",
+ "r=0.2*10**-9; #radius(m)\n",
+ "epsilon0=8.85*10**-12;\n",
+ "E=1; #electric field\n",
+ "\n",
+ "#Calculation\n",
+ "p=4*math.pi*epsilon0*r**3; #dipole moment(F m**2)\n",
+ "P=N*p; #polarization(C m)\n",
+ "epsilonr=(P/(epsilon0*E))+1; #dielectric constant\n",
+ "alpha_e=epsilon0*(epsilonr-1)/N; #polarizability(F m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"dipole moment is\",round(p*10**40,1),\"*10**-40 F m**2\"\n",
+ "print \"polarization is\",round(P*10**15,1),\"*10**-15 C m\"\n",
+ "print \"dielectric constant is\",round(epsilonr,5)\n",
+ "print \"polarizability is\",round(alpha_e*10**40,1),\"*10**-40 F m**2\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 6.11, Page number 6.28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 57,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "electronic polarizability is 1.426 *10**-40 F m**2\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "epsilon0=8.85*10**-12;\n",
+ "epsilonr=1.000435; #dielectric constant of material\n",
+ "N=2.7*10**25; #number of atoms(per m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "alpha_e=epsilon0*(epsilonr-1)/N; #electronic polarizability(F m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"electronic polarizability is\",round(alpha_e*10**40,3),\"*10**-40 F m**2\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 6.12, Page number 6.28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 63,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "electronic polarizability is 6.785 *10**-40 F m**2\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "epsilon0=8.85*10**-12;\n",
+ "epsilonr=4; #dielectric constant\n",
+ "D=2.08*10**3; #density(kg/m**3)\n",
+ "Na=6.02*10**26; #avagadro number\n",
+ "M=32; #atomic weight\n",
+ "\n",
+ "#Calculation\n",
+ "N=Na*D/M; #number of atoms(per m**3)\n",
+ "alphae=epsilon0*(epsilonr-1)/N; #atomic polarizability(F m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"electronic polarizability is\",round(alphae*10**40,3),\"*10**-40 F m**2\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Engineering_Physics_by_S._Mani_Naidu/Chapter7.ipynb b/Engineering_Physics_by_S._Mani_Naidu/Chapter7.ipynb
new file mode 100755
index 00000000..da805b46
--- /dev/null
+++ b/Engineering_Physics_by_S._Mani_Naidu/Chapter7.ipynb
@@ -0,0 +1,442 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#7: Magnetic properties"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 7.1, Page number 7.22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "flux density is 0.628 Wb/m**2\n",
+ "magnetic moment is -2.0 A/m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "chi=-0.4*10**-5; #magnetic susceptibility\n",
+ "H=5*10**5; #magnetic field(A/m)\n",
+ "mew0=4*math.pi*10**-7; \n",
+ "\n",
+ "#Calculation\n",
+ "B=mew0*H*(1+chi); #flux density(Wb/m**2)\n",
+ "M=chi*H; #magnetic moment(A/m)\n",
+ "\n",
+ "#Result\n",
+ "print \"flux density is\",round(B,3),\"Wb/m**2\"\n",
+ "print \"magnetic moment is\",M,\"A/m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 7.2, Page number 7.22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "magnetisation is -0.25 *10**-2 A/m\n",
+ "flux density is 1.257 *10**-3 Wb/m**2\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "chi=-0.25*10**-5; #magnetic susceptibility\n",
+ "H=1000; #magnetic field(A/m)\n",
+ "mew0=4*math.pi*10**-7; \n",
+ "\n",
+ "#Calculation\n",
+ "M=chi*H; #magnetisation(A/m)\n",
+ "B=mew0*(H+M); #flux density(Wb/m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"magnetisation is\",M*10**2,\"*10**-2 A/m\"\n",
+ "print \"flux density is\",round(B*10**3,3),\"*10**-3 Wb/m**2\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 7.3, Page number 7.23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "magnetisation is 3500 A/m\n",
+ "flux density is 4.71 *10**-3 Wb/m**2\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "H=250; #magnetic field(A/m)\n",
+ "mewr=15; #relative permeability\n",
+ "mew0=4*math.pi*10**-7; \n",
+ "\n",
+ "#Calculation\n",
+ "M=H*(mewr-1); #magnetisation(A/m)\n",
+ "B=mew0*(H+M); #flux density(Wb/m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"magnetisation is\",M,\"A/m\"\n",
+ "print \"flux density is\",round(B*10**3,2),\"*10**-3 Wb/m**2\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 7.4, Page number 7.23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "magnetisation is -0.42 A/m\n",
+ "flux density is 1.256 *10**-3 Wb/m**2\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "chi=-0.42*10**-3; #magnetic susceptibility\n",
+ "H=1000; #magnetic field(A/m)\n",
+ "mew0=4*math.pi*10**-7; \n",
+ "\n",
+ "#Calculation\n",
+ "M=chi*H; #magnetisation(A/m)\n",
+ "B=mew0*(H+M); #flux density(Wb/m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"magnetisation is\",M,\"A/m\"\n",
+ "print \"flux density is\",round(B*10**3,3),\"*10**-3 Wb/m**2\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 7.5, Page number 7.23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "magnetic moment is 3.93 *10**-3 Am**2\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "r=10/2; #radius(cm)\n",
+ "i=500*10**-3; #current(A)\n",
+ "\n",
+ "#Calculation\n",
+ "mew=math.pi*(r*10**-2)**2*i; #magnetic moment(Am**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"magnetic moment is\",round(mew*10**3,2),\"*10**-3 Am**2\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 7.6, Page number 7.23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "magnetizing force is 201 A/m\n",
+ "relative permeability is 17.4\n",
+ "answer varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mew0=4*math.pi*10**-7; \n",
+ "B=0.0044; #flux density(Wb/m**2)\n",
+ "M=3300; #magnetic moment(A/m)\n",
+ "\n",
+ "#Calculation\n",
+ "H=(B/mew0)-M; #magnetizing force(A/m)\n",
+ "mewr=1+(M/H); #relative permeability\n",
+ "\n",
+ "#Result\n",
+ "print \"magnetizing force is\",int(H),\"A/m\"\n",
+ "print \"relative permeability is\",round(mewr,1)\n",
+ "print \"answer varies due to rounding off errors\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 7.7, Page number 7.24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "change in magnetic moment is 5.705 *10**-29 Am**2\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "r=0.052*10**-9; #radius(m)\n",
+ "B=3; #flux density(Wb/m**2)\n",
+ "e=1.6*10**-19; \n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "\n",
+ "#Calculation\n",
+ "delta_mew=e**2*r**2*B/(4*m); #change in magnetic moment(A m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"change in magnetic moment is\",round(delta_mew*10**29,3),\"*10**-29 Am**2\"\n",
+ "print \"answer given in the book is wrong\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 7.8, Page number 7.24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "change in magnetic moment is 3.936 *10**-29 Am**2\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "r=5.29*10**-11; #radius(m)\n",
+ "B=2; #flux density(Wb/m**2)\n",
+ "e=1.6*10**-19; \n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "\n",
+ "#Calculation\n",
+ "d_mew=e**2*r**2*B/(4*m); #change in magnetic moment(A m**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"change in magnetic moment is\",round(d_mew*10**29,3),\"*10**-29 Am**2\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 7.9, Page number 7.24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "susceptibility is 3.267 *10**-4\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "N=10**28; #number of atoms(per m**3)\n",
+ "chi1=2.8*10**-4; #susceptibility\n",
+ "T1=350; #temperature(K)\n",
+ "T2=300; #temperature(K)\n",
+ "\n",
+ "#Calculation\n",
+ "chi2=chi1*T1/T2; #susceptibility\n",
+ "\n",
+ "#Result\n",
+ "print \"susceptibility is\",round(chi2*10**4,3),\"*10**-4\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 7.10, Page number 7.25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "relative permeability is 2153.85\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "B=1.4; #flux density(Wb/m**2)\n",
+ "B0=6.5*10**-4; #magnetic field(Tesla)\n",
+ "\n",
+ "#Calculation\n",
+ "mewr=B/B0; #relative permeability\n",
+ "\n",
+ "#Result\n",
+ "print \"relative permeability is\",round(mewr,2)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Engineering_Physics_by_S._Mani_Naidu/Chapter8.ipynb b/Engineering_Physics_by_S._Mani_Naidu/Chapter8.ipynb
new file mode 100755
index 00000000..a1ee2e2e
--- /dev/null
+++ b/Engineering_Physics_by_S._Mani_Naidu/Chapter8.ipynb
@@ -0,0 +1,691 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#8: Semiconductors"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.1, Page number 8.55"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 41,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistivity is 0.41667 ohm m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "ni=2.5*10**19; #intrinsic concentration(per m**3)\n",
+ "mewn=0.4; #mobility of electrons(m**2/Vs)\n",
+ "mewp=0.2; #mobility of holes(m**2/Vs)\n",
+ "e=1.6*10**-19;\n",
+ "\n",
+ "#Calculation\n",
+ "sigma_i=ni*e*(mewn+mewp);\n",
+ "rhoi=1/sigma_i; #resistivity(ohm m)\n",
+ "\n",
+ "#Result\n",
+ "print \"resistivity is\",round(rhoi,5),\"ohm m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.2, Page number 8.56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "number of donor atoms is 8.333 *10**19 per m**3\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mewn=0.3; #mobility of electrons(m**2/Vs)\n",
+ "rho=0.25; #resistivity(ohm m)\n",
+ "e=1.6*10**-19;\n",
+ "\n",
+ "#Calculation\n",
+ "n=1/(rho*e*mewn); #number of donor atoms(per m**3)\n",
+ "\n",
+ "#Result\n",
+ "print \"number of donor atoms is\",round(n/10**19,3),\"*10**19 per m**3\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.3, Page number 8.56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 43,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "diffusion coefficient of electrons is 54.34 *10**-4 m**2/s\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mewn=0.21; #mobility of electrons(m**2/Vs)\n",
+ "e=1.6*10**-19;\n",
+ "Kb=1.38*10**-23; #boltzmann constant\n",
+ "T=300; #temperature(K)\n",
+ "\n",
+ "#Calculation\n",
+ "Dn=mewn*Kb*T/e; #diffusion coefficient of electrons(m**2/s)\n",
+ "\n",
+ "#Result\n",
+ "print \"diffusion coefficient of electrons is\",round(Dn*10**4,2),\"*10**-4 m**2/s\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.4, Page number 8.56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 44,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "carrier concentration is 19.4 *10**21 per m**3\n",
+ "#mobility of holes is 0.03788 m**2/Vs\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Rh=3.22*10**-4; #hall coefficient(m**3/C)\n",
+ "e=1.6*10**-19;\n",
+ "rho=8.5*10**-3; #resistivity(ohm m)\n",
+ "\n",
+ "#Calculation\n",
+ "p=1/(Rh*e); #carrier concentration(per m**3)\n",
+ "mewp=Rh/rho; #mobility of holes(m**2/Vs)\n",
+ "\n",
+ "#Result\n",
+ "print \"carrier concentration is\",round(p/10**21,1),\"*10**21 per m**3\"\n",
+ "print \"#mobility of holes is\",round(mewp,5),\"m**2/Vs\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.5, Page number 8.57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 45,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "intrinsic concentration is 556.25 *10**16 per m**3\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mewe=0.36; #mobility of electrons(m**2/Vs)\n",
+ "mewh=0.17; #mobility of holes(m**2/Vs)\n",
+ "e=1.6*10**-19;\n",
+ "rhoi=2.12; #resistivity(ohm m)\n",
+ "\n",
+ "#Calculation\n",
+ "ni=1/(rhoi*e*(mewe+mewh)); #intrinsic concentration(per m**3)\n",
+ "\n",
+ "#Result\n",
+ "print \"intrinsic concentration is\",round(ni/10**16,2),\"*10**16 per m**3\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.6, Page number 8.57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistivity is 0.449 ohm m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mewe=0.39; #mobility of electrons(m**2/Vs)\n",
+ "mewh=0.19; #mobility of holes(m**2/Vs)\n",
+ "e=1.6*10**-19;\n",
+ "ni=2.4*10**19; #intrinsic concentration(per m**3) \n",
+ "\n",
+ "#Calculation\n",
+ "rhoi=1/(ni*e*(mewe+mewh)); #resistivity(ohm m) \n",
+ "\n",
+ "#Result\n",
+ "print \"resistivity is\",round(rhoi,3),\"ohm m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.7, Page number 8.57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "conductivity is 0.439 *10**-3 per ohm m\n",
+ "hole concentration is 2.25 *10**9 per m**3\n",
+ "conductivity is 2.16 *10**3 per ohm m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mewe=0.135; #mobility of electrons(m**2/Vs)\n",
+ "mewh=0.048; #mobility of holes(m**2/Vs)\n",
+ "e=1.6*10**-19;\n",
+ "ni=1.5*10**16; #intrinsic concentration(per m**3)\n",
+ "Nd=10**23; #doping concentration(per m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "sigma=ni*e*(mewe+mewh); #conductivity(per ohm m) \n",
+ "p=ni**2/Nd; #hole concentration(per m**3)\n",
+ "sigman=Nd*e*mewe; #conductivity(per ohm m) \n",
+ "\n",
+ "#Result\n",
+ "print \"conductivity is\",round(sigma*10**3,3),\"*10**-3 per ohm m\"\n",
+ "print \"hole concentration is\",p/10**9,\"*10**9 per m**3\"\n",
+ "print \"conductivity is\",sigman/10**3,\"*10**3 per ohm m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.8, Page number 8.58"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 50,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "carrier concentration is 1.7 *10**22 per m**3\n",
+ "#mobility of holes is 4.099 *10**-2 m**2/Vs\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Rh=3.66*10**-4; #hall coefficient(m**3/C)\n",
+ "e=1.6*10**-19;\n",
+ "rhoh=8.93*10**-3; #resistivity(ohm m)\n",
+ "\n",
+ "#Calculation\n",
+ "p=1/(Rh*e); #carrier concentration(per m**3)\n",
+ "mewp=Rh/rhoh; #mobility of holes(m**2/Vs)\n",
+ "\n",
+ "#Result\n",
+ "print \"carrier concentration is\",round(p/10**22,1),\"*10**22 per m**3\"\n",
+ "print \"#mobility of holes is\",round(mewp*10**2,3),\"*10**-2 m**2/Vs\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.9, Page number 8.58"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 51,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "conductivity is 4.32 *10**-4 per ohm m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mewe=0.13; #mobility of electrons(m**2/Vs)\n",
+ "mewh=0.05; #mobility of holes(m**2/Vs)\n",
+ "e=1.6*10**-19;\n",
+ "ni=1.5*10**16; #intrinsic concentration(per m**3)\n",
+ "\n",
+ "#Calculation\n",
+ "sigma=ni*e*(mewe+mewh); #conductivity(per ohm m) \n",
+ "\n",
+ "#Result\n",
+ "print \"conductivity is\",sigma*10**4,\"*10**-4 per ohm m\" "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.10, Page number 8.58"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 52,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "conductivity is 11.2 per ohm m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mewe=0.14; #mobility of electrons(m**2/Vs)\n",
+ "mewh=0.05; #mobility of holes(m**2/Vs)\n",
+ "e=1.6*10**-19;\n",
+ "ni=1.5*10**16; #intrinsic concentration(per m**3)\n",
+ "A=28.09; #atomic weight\n",
+ "D=2.33*10**3; #density(kg/m**3)\n",
+ "Na=6.025*10**26; #avagadro number\n",
+ "\n",
+ "#Calculation\n",
+ "N=Na*D/A; #number of atoms(per m**3)\n",
+ "n=N/10**8; #electron concentration(per m**3)\n",
+ "p=ni**2/n; #hole concentration(per m**3)\n",
+ "sigma=e*((n*mewe)+(p*mewh)); #conductivity(per ohm m) \n",
+ "\n",
+ "#Result\n",
+ "print \"conductivity is\",round(sigma,1),\"per ohm m\" "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.11, Page number 8.59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 53,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistivity is 4.13 *10**-4 per ohm m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mewe=0.36; #mobility of electrons(m**2/Vs)\n",
+ "mewh=0.18; #mobility of holes(m**2/Vs)\n",
+ "e=1.6*10**-19;\n",
+ "ni=2.5*10**19; #intrinsic concentration(per m**3)\n",
+ "N=4.2*10**28; #avagadro number\n",
+ "\n",
+ "#Calculation\n",
+ "n=N/10**6; #electron concentration(per m**3)\n",
+ "p=ni**2/n; #hole concentration(per m**3)\n",
+ "rhoi=1/(e*((n*mewe)+(p*mewh))); #resistivity(per ohm m) \n",
+ "\n",
+ "#Result\n",
+ "print \"resistivity is\",round(rhoi*10**4,2),\"*10**-4 per ohm m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.12, Page number 8.60"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 54,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "hole concentration is 1.2 *10**9 per m**3\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "np=2.4*10**9; #carrier concentration(per m**3)\n",
+ "N=4.2*10**28; #avagadro number\n",
+ "\n",
+ "#Calculation\n",
+ "p=np/2; #hole concentration(per m**3)\n",
+ "\n",
+ "#Result\n",
+ "print \"hole concentration is\",p/10**9,\"*10**9 per m**3\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.13, Page number 8.60"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 55,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "density of donor atoms is 8.92 *10**19 electrons/m**3\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mewn=0.35; #mobility of electrons(m**2/Vs)\n",
+ "e=1.602*10**-19;\n",
+ "rho=0.2; #resistivity(ohm m)\n",
+ "\n",
+ "#Calculation\n",
+ "n=1/(rho*e*mewn); #density of donor atoms\n",
+ "\n",
+ "#Result\n",
+ "print \"density of donor atoms is\",round(n/10**19,2),\"*10**19 electrons/m**3\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.14, Page number 8.60"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 56,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "energy gap is 0.573 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Kb=1.38*10**-23; #boltzmann constant\n",
+ "T1=300; #temperature(K)\n",
+ "T2=320; #temperature(K)\n",
+ "rho1=5; #resistivity(ohm m)\n",
+ "rho2=2.5; #resistivity(ohm m)\n",
+ "\n",
+ "#Calculation\n",
+ "Eg=2*Kb*math.log(rho1/rho2)/((1/T1)-(1/T2)); #energy gap(J)\n",
+ "\n",
+ "#Result\n",
+ "print \"energy gap is\",round(Eg/e,3),\"eV\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.15, Page number 8.61"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 57,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "diffusion coefficient is 4.92 *10**-3 m**2/sec\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Kb=1.38*10**-23; #boltzmann constant\n",
+ "T=300; #temperature(K)\n",
+ "mewe=0.19; #mobility of electrons(m**2/Vs)\n",
+ "e=1.6*10**-19;\n",
+ "\n",
+ "#Calculation\n",
+ "Dn=mewe*Kb*T/e; #diffusion coefficient(m**2/sec)\n",
+ "\n",
+ "#Result\n",
+ "print \"diffusion coefficient is\",round(Dn*10**3,2),\"*10**-3 m**2/sec\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 8.16, Page number 8.61"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 59,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "energy gap is 1.04 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Kb=1.38*10**-23; #boltzmann constant\n",
+ "T1=293; #temperature(K)\n",
+ "T2=305; #temperature(K)\n",
+ "rho1=4.5; #resistivity(ohm m)\n",
+ "rho2=2.0; #resistivity(ohm m)\n",
+ "\n",
+ "#Calculation\n",
+ "Eg=2*Kb*math.log(rho1/rho2)/((1/T1)-(1/T2)); #energy gap(J)\n",
+ "\n",
+ "#Result\n",
+ "print \"energy gap is\",round(Eg/e,2),\"eV\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Engineering_Physics_by_S._Mani_Naidu/Chapter9.ipynb b/Engineering_Physics_by_S._Mani_Naidu/Chapter9.ipynb
new file mode 100755
index 00000000..0b33c8c4
--- /dev/null
+++ b/Engineering_Physics_by_S._Mani_Naidu/Chapter9.ipynb
@@ -0,0 +1,305 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#9: Superconductivity"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 9.1, Page number 9.22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "transition temperature is 11.3 K\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=8; #temperature(K)\n",
+ "Hc=1*10**5; #critical field(amp/m)\n",
+ "H0=2*10**5; #critical field(amp/m)\n",
+ "\n",
+ "#Calculation\n",
+ "Tc=T/math.sqrt(1-(Hc/H0)); #transition temperature(K)\n",
+ "\n",
+ "#Result\n",
+ "print \"transition temperature is\",round(Tc,1),\"K\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 9.2, Page number 9.22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "frequency is 4.1 *10**9 Hz\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "h=6.626*10**-34; #plancks constant\n",
+ "e=1.6*10**-19; \n",
+ "V=8.5*10**-6; #voltage(V)\n",
+ "\n",
+ "#Calculation\n",
+ "new=2*e*V/h; #frequency(Hz)\n",
+ "\n",
+ "#Result\n",
+ "print \"frequency is\",round(new/10**9,1),\"*10**9 Hz\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 9.3, Page number 9.22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "critical field is 0.02166 Tesla\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=2; #temperature(K)\n",
+ "H0=0.0306; #critical field(amp/m)\n",
+ "Tc=3.7; #transition temperature(K)\n",
+ "\n",
+ "#Calculation\n",
+ "Hc=H0*(1-(T/Tc)**2); #critical field(Tesla)\n",
+ "\n",
+ "#Result\n",
+ "print \"critical field is\",round(Hc,5),\"Tesla\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 9.4, Page number 9.23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "temperature is 7.2 K\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "H0=250*10**3; #critical field(amp/m)\n",
+ "Tc=12; #transition temperature(K)\n",
+ "Hc=200*10**3; #critical field(Tesla)\n",
+ "\n",
+ "#Calculation\n",
+ "T=Tc*math.sqrt(1-(Hc/H0)**2); #temperature(K)\n",
+ "\n",
+ "#Result\n",
+ "print \"temperature is\",round(T,1),\"K\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 9.5, Page number 9.23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "critical field is 0.0163 Tesla\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=2.5; #temperature(K)\n",
+ "H0=0.03; #critical field(amp/m)\n",
+ "Tc=3.7; #transition temperature(K)\n",
+ "\n",
+ "#Calculation\n",
+ "Hc=H0*(1-(T/Tc)**2); #critical field(Tesla)\n",
+ "\n",
+ "#Result\n",
+ "print \"critical field is\",round(Hc,4),\"Tesla\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 9.6, Page number 9.23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "frequency is 313.96 *10**9 Hz\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "h=6.625*10**-34; #plancks constant\n",
+ "e=1.6*10**-19; \n",
+ "V=650*10**-6; #voltage(V)\n",
+ "\n",
+ "#Calculation\n",
+ "new=2*e*V/h; #frequency(Hz)\n",
+ "\n",
+ "#Result\n",
+ "print \"frequency is\",round(new/10**9,2),\"*10**9 Hz\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 9.7, Page number 9.24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "critical field is 3.365 *10**3 A/m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=5; #temperature(K)\n",
+ "H0=6.5*10**3; #critical field(amp/m)\n",
+ "Tc=7.2; #transition temperature(K)\n",
+ "\n",
+ "#Calculation\n",
+ "Hc=H0*(1-(T/Tc)**2); #critical field(Tesla)\n",
+ "\n",
+ "#Result\n",
+ "print \"critical field is\",round(Hc/10**3,3),\"*10**3 A/m\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter1.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter1.ipynb
new file mode 100755
index 00000000..10f61da5
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter1.ipynb
@@ -0,0 +1,621 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:2f492bc2a6dad7cae3b696b117670d34888491ec5959ea22de590b83b18e09cd"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "1: Theory of Relativity"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.1, Page number 29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "l0 = 50 #length of rocket ship(m)\n",
+ "l = 49.5 #length observed on ground(m)\n",
+ "c = 3*10**8 #velocity of light(m/sec)\n",
+ "\n",
+ "#Calculation\n",
+ "#we know that l = l0*math.sqrt(1-((v**2)/(c**2)))\n",
+ "v = math.sqrt((c**2)*(1-((l/l0)**2))) #speed(m/sec)\n",
+ "v = v*10**-7;\n",
+ "v=math.ceil(v*10**3)/10**3; #rounding off to 3 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"speed of the rocket is\",v, \"*10**7 m/sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "speed of the rocket is 4.233 *10**7 m/sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.2, Page number 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "l0 = 1; #assume length(m)\n",
+ "l = (99/100)*l0 #length observed on ground(m)\n",
+ "c = 1 #assume c = 1\n",
+ "\n",
+ "#Calculation\n",
+ "#we know that l = l0*math.sqrt(1-((v**2)/(c**2)))\n",
+ "v = math.sqrt((c**2)*(1-((l/l0)**2))) #speed(m/sec)\n",
+ "v=math.ceil(v*10**4)/10**4; #rounding off to 4 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"speed of the rocket is\",v,\"c\"\n",
+ "print \"answer given in the book is wrong\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "speed of the rocket is 0.1411 c\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.3, Page number 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "l0 = 120 #length of spaceship(m)\n",
+ "c = 1 #assume c = 1\n",
+ "v = 0.99*c; #speed of spaceship(m/sec)\n",
+ "\n",
+ "#Calculation\n",
+ "l = l0*math.sqrt(1-((v**2)/(c**2))); #length of the observer(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"length of the observer is\",round(l),\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "length of the observer is 17.0 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.4, Page number 30 theoretical proof"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.5, Page number 31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "#surface area of elliptical lamina = 1/2 (area of circular lamina)\n",
+ "\n",
+ "#Calculation\n",
+ "c = 3*10**8; #velocity of light(m/sec)\n",
+ "#((math.pi*D**2)/4)*math.sqrt(1-(v**2/c**2)) = 1/2*math.pi*D**2/4\n",
+ "#math.sqrt(1-(v**2/c**2)) = 1/2\n",
+ "v = c*math.sqrt(1-(1/4)); #velocity(m/sec)\n",
+ "v = v*10**-8;\n",
+ "v=math.ceil(v*10)/10; #rounding off to 1 decimal\n",
+ "\n",
+ "#Result\n",
+ "print \"velocity is\",v,\"*10**8 m/sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "velocity is 2.6 *10**8 m/sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.6, Page number 32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "t0 = 2*10**-8; #mean life of meson(sec)\n",
+ "c = 1; #assume c = 1\n",
+ "v = 0.8*c; #velocity of meson(m/sec)\n",
+ "\n",
+ "#Calculation\n",
+ "t = t0/math.sqrt(1-(v**2/c**2)); #mean life with a particular velocity\n",
+ "\n",
+ "#Result\n",
+ "print \"mean life of meson with a velocity is\",round(t/1e-8,3),\"*10**-8 sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "mean life of meson with a velocity is 3.333 *10**-8 sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.7, Page number 32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "t0 = 3; #time period of pendulum(sec)\n",
+ "c = 1; #assume c = 1\n",
+ "v = 0.95*c; #velocity of observer(m/sec)\n",
+ "\n",
+ "#Calculation\n",
+ "t = t0/math.sqrt(1-(v**2/c**2)); #time period measured by observer(sec)\n",
+ "t = math.ceil(t*100)/100; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"time period measured by observer is\",t,\"sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "time period measured by observer is 9.61 sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.8, Page number 33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "t0 = 1; #life time of particle(micro sec)\n",
+ "v = 2.7*10**8; #velocity of particle(m/sec)\n",
+ "c = 3*10**8; #velocity of light(m/sec)\n",
+ "\n",
+ "#Calculation\n",
+ "t0 = t0*10**-6; #life time of particle(sec)\n",
+ "t = t0/math.sqrt(1-(v**2/c**2)); #life time(sec)\n",
+ "t = round(t/1e-6,1)*10**-6; \n",
+ "x = v*t; #distance travelled before disintegration(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"life time is\",t,\"sec\"\n",
+ "print \"distance travelled before disintegration is\",x,\"m\"\n",
+ "print \"answer for distance given in the book is wrong\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "life time is 2.3e-06 sec\n",
+ "distance travelled before disintegration is 621.0 m\n",
+ "answer for distance given in the book is wrong\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.9, Page number 33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "c = 1; #assume c = 1\n",
+ "u = -0.85*c; #speed of B\n",
+ "v = 0.75*c; #speed of A\n",
+ "\n",
+ "#Calculation\n",
+ "u_dash = (u-v)/(1-(u*v/c**2)); #velocity of B with respect to A\n",
+ "u_dash = math.ceil(u_dash*10**3)/10**3; #rounding off to 3 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"velocity of B with respect to A is\",u_dash,\"c\"\n",
+ "print \"answer given in the book is wrong with respect to sign\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "velocity of B with respect to A is -0.977 c\n",
+ "answer given in the book is wrong with respect to sign\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.10, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "c = 1; #assume c = 1\n",
+ "u_dash = 0.9*c; #velocity of beta particle\n",
+ "v = 0.25*c; #speed of A\n",
+ "\n",
+ "#Calculation\n",
+ "u = (u_dash+v)/(1+(u_dash*v/c**2)); #speed of beta particle\n",
+ "u = math.ceil(u*10**2)/10**2; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"speed of beta particle is\",u,\"c\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "speed of beta particle is 0.94 c\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.11, Page number 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mp = 1.6*10**-27; #mass of proton(kg)\n",
+ "me = 9.1*10**-31; #mass of electron(kg)\n",
+ "c = 3*10**8; #velocity of light(m/sec)\n",
+ "\n",
+ "#Calculation\n",
+ "m0 = me;\n",
+ "m = mp;\n",
+ "# we know that m = m0/math.sqrt(1-(v**2/c**2));\n",
+ "A = (m0/m)**2;\n",
+ "v_square = (1-A)*(c**2);\n",
+ "v = math.sqrt(v_square); #speed of electron(m/sec)\n",
+ "v = v*10**-8;\n",
+ "v = math.ceil(v*10**7)/10**7; #rounding off to 7 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"speed of electron is\",v,\"*10**8 m/sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "speed of electron is 2.9999996 *10**8 m/sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.12, Page number 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "m0 = 1; #assume m0 = 1\n",
+ "m = 2.25*m0;\n",
+ "\n",
+ "#Calculation\n",
+ "A = (m0/m)**2;\n",
+ "v_square = (1-A)*(c**2);\n",
+ "v = math.sqrt(v_square); #speed of a body(m/sec)\n",
+ "v = v*10**-8;\n",
+ "v = math.ceil(v*10**3)/10**3; #rounding off to 3 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"speed of the body is\",v,\"*10**8 m/sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "speed of electron is 2.688 *10**8 m/sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.13, Page number 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "c = 1; #assume c = 1\n",
+ "v = 0.99*c; #velocity of electron\n",
+ "m0 = 9.1*10**-31; #mass(kg)\n",
+ "\n",
+ "#Calculation\n",
+ "m = m0/math.sqrt(1-(v**2/c**2)); #mass of electron(kg)\n",
+ "m = m*10**31;\n",
+ "\n",
+ "#Result\n",
+ "print \"mass of the electron is\",int(m),\"*10**-31 kg\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "mass of the electron is 64 *10**-31 kg\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.14, Page number 35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.15, Page number 36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 1.16, Page number 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter10.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter10.ipynb
new file mode 100755
index 00000000..66376214
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter10.ipynb
@@ -0,0 +1,67 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:32a1f58679b12138480dc1b5e5c18d84b4eee7617fb55dd2b494b13bcfd310c8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "10: Magnetic properties of materials"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 10.1, Page number 247"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "r = 0.052; #radius of orbit(nm)\n",
+ "B = 1; #magnetic field(Wb/m**2)\n",
+ "e = 1.6*10**-19; #charge of electron(c)\n",
+ "m = 9.1*10**-31; #mass of electron(kg)\n",
+ "\n",
+ "#Calculation\n",
+ "r = r*10**-9; #radius of orbit(m)\n",
+ "delta_mew = (e**2)*(r**2)*B/(4*m); #change in magnetic moment(Am**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"change in magnetic moment is\",round(delta_mew/1e-29,3),\"*10**-29 Am**2\"\n",
+ "print \"answer given in the book is wrong\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "change in magnetic moment is 1.902 *10**-29 Am**2\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter11.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter11.ipynb
new file mode 100755
index 00000000..cbbc468c
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter11.ipynb
@@ -0,0 +1,159 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4bb25a18af878dce815ea6fd0470757443fe2ad8404e54fa1bb8e38dd97cd417"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "11: Electrostatics and electromagnetic theory"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 11.1, Page number 279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mew = 1; #parameter of aluminium\n",
+ "sigma = 3.54*10**7; #conductivity(mho/m)\n",
+ "delta = 0.01*10**-3; #skin depth of aluminium(mm)\n",
+ "\n",
+ "#Calculation\n",
+ "new = 1/((delta**2)*math.pi*mew*sigma); #frequency(Hz)\n",
+ "new = math.ceil(new*10**2)/10**2; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"frequency is\",new,\"Hz\"\n",
+ "print \"answer given in the book is wrong\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "frequency is 89.92 Hz\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 11.2, Page number 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "se = 2; #solar energy(cal /min /cm**2)\n",
+ "j = (4.2*10**4)/60; #conversion factor from cal /min /cm**2 to J /m**2 /sec)\n",
+ "mew0 = 4*math.pi*10**-7; #permeability of free space(H/m)\n",
+ "epsilon0 = 8.854*10**-12; #permittivity of free space(F/m)\n",
+ "\n",
+ "#Calculation\n",
+ "EH = se*j; #solar energy(J /m**2 /sec)\n",
+ "EbyH = math.sqrt(mew0/epsilon0);\n",
+ "EbyH = math.ceil(EbyH*10)/10; #rounding off to 1 decimal\n",
+ "H = math.sqrt(EH/EbyH); #magnetic field of radiation\n",
+ "E = EbyH*H;\n",
+ "H = math.ceil(H*10**3)/10**3; #rounding off to 3 decimals\n",
+ "E = math.ceil(E*10)/10; #rounding off to 1 decimal\n",
+ "E0 = E*math.sqrt(2); #electric field of radiation(volt/m)\n",
+ "H0 = H*math.sqrt(2); #magnetic field of radiation (amp-turn/m)\n",
+ "H0 = math.ceil(H0*10**2)/10**2; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"electric field of radiation is\",int(E0),\"volt/m\"\n",
+ "print \"magnetic field of radiation is\",H0,\"amp-turn/m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "electric field of radiation is 1027 volt/m\n",
+ "magnetic field of radiation is 2.73 amp-turn/m\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 11.3, Page number 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "p = 4.3*10**-8; #polarization(C/m**2)\n",
+ "E = 1000; #electric field(V/m)\n",
+ "epsilon0 = 8.85*10**-12; #permittivity of free space(F/m)\n",
+ "\n",
+ "#Calculation\n",
+ "epsilonr = 1+(p/(epsilon0*E)); #relative permittivity\n",
+ "epsilonr = math.ceil(epsilonr*10**2)/10**2; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"relative permittivity is\",epsilonr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "relative permittivity is 5.86\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter12.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter12.ipynb
new file mode 100755
index 00000000..ccd47d51
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter12.ipynb
@@ -0,0 +1,105 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:85ef8262dd8d094957ce6eda00a743c757c0eaabccf750168045359d519c0a4b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "12: Superconductivity"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 12.1, Page number 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Tc = 9.2; #critical temperature of metal(K)\n",
+ "Bc = 1.05*10**5; #magnetic field(amp/m)\n",
+ "B0 = 1.5*10**5; #critical field(amp/m)\n",
+ "\n",
+ "#Calculation\n",
+ "T = math.sqrt((Tc**2)*(1-(Bc/B0))); #temperature of metal(K)\n",
+ "T = math.ceil(T*10**4)/10**4; #rounding off to 4 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"temperature of the metal is\",T,\"K\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "temperature of the metal is 5.0391 K\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 12.2, Page number 295"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Tc1 = 4.185; #critical temperature of Hg(K)\n",
+ "M1 = 199.5; #isotopic mass(gm)\n",
+ "M2 = 203.4; #changed isotopic mass(gm)\n",
+ "\n",
+ "#Calculation\n",
+ "Tc2 = Tc1*math.sqrt(M1/M2); #changed critical temperature(K)\n",
+ "Tc2 = math.ceil(Tc2*10**3)/10**3; #rounding off to 3 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"changed critical temperature of Hg is\",Tc2,\"K\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "changed critical temperature of Hg is 4.145 K\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter15.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter15.ipynb
new file mode 100755
index 00000000..365987ff
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter15.ipynb
@@ -0,0 +1,332 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:42ca728e6260f85c33ceec306bfa76eadd9931a7ca67b2244aa9a2e681dff896"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "15: Statistical mechanics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 15.1, Page number 341"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "import fractions\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n = 10; #number of identical coins\n",
+ "r1 = 10; #number of heads in 1st case\n",
+ "r2 = 5; #number of heads in 2nd case\n",
+ "r3 = 3; #number of heads in 3rd case\n",
+ "\n",
+ "#Calculation\n",
+ "P10_0 = math.factorial(n)/(math.factorial(r1)*math.factorial(n-r1)*(2**n)); #probability of getting all heads\n",
+ "P10_0 = fractions.Fraction(P10_0); #probability in fraction\n",
+ "P5_5 = math.factorial(n)/(math.factorial(r2)*math.factorial(n-r2)*(2**n)); #probability of getting 5 heads and 5 tails\n",
+ "P5_5 = fractions.Fraction(P5_5); #probability in fraction\n",
+ "P3_7 = math.factorial(n)/(math.factorial(r3)*math.factorial(n-r3)*(2**n)); #probability of getting 3 heads and 7 tails\n",
+ "P3_7 = fractions.Fraction(P3_7); #probability in fraction\n",
+ "Pmax = math.factorial(n)/(((math.factorial(n/2))**2)*(2**n)) #most probable combination\n",
+ "Pmax = fractions.Fraction(Pmax); #probability in fraction\n",
+ "Pmin = 1/(2**n); #least probable combination\n",
+ "Pmin = fractions.Fraction(Pmin); #probability in fraction\n",
+ "\n",
+ "#Result\n",
+ "print \"probability of getting all heads is\",P10_0\n",
+ "print \"probability of getting 5 heads and 5 tails is\",P5_5\n",
+ "print \"probability of getting 3 heads and 7 tails is\",P3_7\n",
+ "print \"most probable combination is\",Pmax\n",
+ "print \"least probable combination is\",Pmin"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "probability of getting all heads is 1/1024\n",
+ "probability of getting 5 heads and 5 tails is 63/256\n",
+ "probability of getting 3 heads and 7 tails is 15/128\n",
+ "most probable combination is 63/256\n",
+ "least probable combination is 1/1024\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 15.2, Page number 342"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "import fractions\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n = 3; #number of particles\n",
+ "N = 2; #number of compartments\n",
+ "ms = 4; #number of macrostates\n",
+ "n1_03 = 0; #value of n1 for (0,3)\n",
+ "n2_03 = 3; #value of n2 for (0,3)\n",
+ "n1_12 = 1; #value of n1 for (1,2)\n",
+ "n2_12 = 2; #value of n2 for (1,2)\n",
+ "n1_21 = 2; #value of n1 for (2,1)\n",
+ "n2_21 = 1; #value of n2 for (2,1)\n",
+ "n1_30 = 3; #value of n1 for (3,0)\n",
+ "n2_30 = 0; #value of n2 for (3,0)\n",
+ "\n",
+ "#Calculation\n",
+ "#the macrostates are (n1,n2) = [(0,3),(1,2),(2,1),(3,0)]\n",
+ "ms_03 = math.factorial(n)/(math.factorial(n1_03)*math.factorial(n2_03)); #number of microstates in the macrostate (0,3)\n",
+ "mis_03 = \"(0,xyz)\"; #microstates in the macrostate (0,3)\n",
+ "ms_12 = math.factorial(n)/(math.factorial(n1_12)*math.factorial(n2_12)); #number of microstates in the macrostate (1,2)\n",
+ "mis_12 = \"[(x,yz),(y,zx),(z,xy)]\"; #microstates in the macrostate (1,2)\n",
+ "ms_21 = math.factorial(n)/(math.factorial(n1_21)*math.factorial(n2_21)); #number of microstates in the macrostate (2,1)\n",
+ "mis_21 = \"[(xy,z),(yz,x),(zx,y)]\"; #microstates in the macrostate (2,1)\n",
+ "ms_30 = math.factorial(n)/(math.factorial(n1_30)*math.factorial(n2_30)); #number of microstates in the macrostate (3,0)\n",
+ "mis_30 = \"(xyz,0)\"; #microstates in the macrostate (3,0)\n",
+ "tms = N**n; #total number of microstates\n",
+ "mis = \"[(0,xxx),(x,xx),(xx,x),(xxx,0)]\"; #the microstates when particles are indistinguishable\n",
+ "\n",
+ "#Result\n",
+ "print \"number of microstates in the macrostate (0,3) is\",ms_03,\"that is\",mis_03\n",
+ "print \"number of microstates in the macrostate (1,2) is\",ms_12,\"that is\",mis_12\n",
+ "print \"number of microstates in the macrostate (2,1) is\",ms_21,\"that is\",mis_21\n",
+ "print \"number of microstates in the macrostate (3,0) is\",ms_30,\"that is\",mis_30\n",
+ "print \"total number of microstates is\",tms\n",
+ "print \"the microstates when particles are indistinguishable are\",mis"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of microstates in the macrostate (0,3) is 1.0 that is (0,xyz)\n",
+ "number of microstates in the macrostate (1,2) is 3.0 that is [(x,yz),(y,zx),(z,xy)]\n",
+ "number of microstates in the macrostate (2,1) is 3.0 that is [(xy,z),(yz,x),(zx,y)]\n",
+ "number of microstates in the macrostate (3,0) is 1.0 that is (xyz,0)\n",
+ "total number of microstates is 8\n",
+ "the microstates when particles are indistinguishable are [(0,xxx),(x,xx),(xx,x),(xxx,0)]\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 15.3, Page number 343"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1 = 4; #1st group of particles\n",
+ "n2 = 2; #2nd group of particles \n",
+ "n3 = 8; #3rd group of particles\n",
+ "n4 = 6; #4th group of particles \n",
+ "n5 = 5; #5th group of particles\n",
+ "v1 = 1; #speed of 1st group of particles\n",
+ "v2 = 2; #speed of 2nd group of particles\n",
+ "v3 = 3; #speed of 3rd group of particles\n",
+ "v4 = 4; #speed of 4th group of particles \n",
+ "v5 = 5; #speed of 5th group of particles\n",
+ "\n",
+ "#Calculation\n",
+ "vbar = ((n1*v1)+(n2*v2)+(n3*v3)+(n4*v4)+(n5*v5))/(n1+n2+n3+n4+n5); #average speed(m/sec)\n",
+ "vsquarebar = ((v1*(n1**2))+(v2*(n2**2))+(v3*(n3**2))+(v4*(n4**2))+(v5*(n5**2)))/(n1+n2+n3+n4+n5); #mean square speed\n",
+ "rms = math.sqrt(vsquarebar); #root mean square speed(m/sec)\n",
+ "rms = math.ceil(rms*10**3)/10**3; #rounding off to 3 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"average speed is\",vbar,\"m/sec\"\n",
+ "print \"root mean square speed is\",rms,\"m/sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "average speed is 3.24 m/sec\n",
+ "root mean square speed is 4.405 m/sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 15.4, Page number 344"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "t = 27; #temperature(C)\n",
+ "M = 14; #mass of nitrogen(gm)\n",
+ "kb = 1.38*10**-23; #boltzmann constant\n",
+ "a = 6.02*10**23; #avagadro number \n",
+ "\n",
+ "#Calculation\n",
+ "T = t+273; #temperature(K) \n",
+ "M = M*10**-3; #mass of nitrogen(kg)\n",
+ "vmp = math.sqrt(2*kb*T*a/M); #most probable speed of nitrogen(m/sec)\n",
+ "vmp = math.ceil(vmp*10)/10; #rounding off to 1 decimal\n",
+ "\n",
+ "#Result\n",
+ "print \"most probable speed of nitrogen is\",vmp,\"m/sec\"\n",
+ "print \"answer given in the book is wrong\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "most probable speed of nitrogen is 596.7 m/sec\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 15.5, Page number 344"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "t = 37; #normal temperature of human body(C)\n",
+ "b = 2.898*10**-3; #constant of proportionality(mK)\n",
+ "\n",
+ "#Calculation\n",
+ "T = t+273; #normal temperature of human body(K)\n",
+ "lamda_m = b/T; #wavelength for maximum energy radiation(m)\n",
+ "lamda_m = lamda_m*10**10; #wavelength for maximum energy radiation(angstrom)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength for maximum energy radiation is\",int(lamda_m),\"angstrom\"\n",
+ "print \"answer given in the book is wrong\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "wavelength for maximum energy radiation is 93483 angstrom\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 15.6, Page number 344"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "kb = 1.38*10**-23; #boltzmann constant\n",
+ "thetaE = 230; #einstein's temperature(K)\n",
+ "h = 6.63*10**-34; #planck's constant(m**2 kg/s)\n",
+ "\n",
+ "#Calculation\n",
+ "newE = kb*thetaE/h; #einstein's frequency(per sec)\n",
+ "\n",
+ "#Result\n",
+ "print \"einstein's frequency is\",round(newE/1e+12,2),\"*10**12 per sec\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "einstein's frequency is 4.79 *10**12 per sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter2.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter2.ipynb
new file mode 100755
index 00000000..ef49544b
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter2.ipynb
@@ -0,0 +1,507 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:614bd66037ed01713a261d0e06bb9f5175d6e2a9e3ef900d57af3a2e6efdf43f"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "2: Interference and Diffraction"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.1, Page number 75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "t = 12*10**-5; #thickness of mica sheet(cm)\n",
+ "lamda = 6000; #wavelength(Angstrom)\n",
+ "n = 1;\n",
+ "\n",
+ "#Calculation\n",
+ "lamda = lamda*10**-10; #wavelength(m)\n",
+ "mew_1 = n*lamda/t;\n",
+ "mew = mew_1+1; #refractive index of mica\n",
+ "\n",
+ "#Result\n",
+ "print \"refractive index of mica is\",mew\n",
+ "print \"answer given in the book is wrong\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "refractive index of mica is 1.005\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.2, Page number 75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "D = 0.53; #distance of fringes from slit(m)\n",
+ "lamda = 5890; #wavelength of light(angstrom)\n",
+ "two_d = 0.6*10**-3; #separation of slits(m)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda = lamda*10**-10; #wavelength(m)\n",
+ "beta = D*lamda/two_d; #width of fringes(m)\n",
+ "beta = beta*10**3;\n",
+ "beta = math.ceil(beta*10**3)/10**3; #rounding off to 3 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"width of fringes is\",beta,\"*10**-3 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "width of fringes is 0.521 *10**-3 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.3, Page number 75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "beta = 9*10**-4; #width of fringes(m)\n",
+ "d1 = 75; #distance of fringes from biprism(cm)\n",
+ "d2 = 5; #distance of biprism from slit(cm)\n",
+ "lamda = 5890; #wavelength of light(angstrom)\n",
+ "two_d = 0.6*10**-3; #separation of slits(m)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda = lamda*10**-10; #wavelength(m)\n",
+ "d1 = d1*10**-2; #distance of fringes from biprism(m)\n",
+ "d2 = d2*10**-2; #distance of biprism from slit(m)\n",
+ "D = d1+d2; #distance of fringes from slit(m)\n",
+ "two_d = D*lamda/beta; #separation of slits(m)\n",
+ "two_d = two_d*10**4;\n",
+ "two_d = math.ceil(two_d*10**2)/10**2; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"distance between slits is\",two_d,\"*10**-4 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "distance between slits is 5.24 *10**-4 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.4, Page number 75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda = 6*10**-7; #wavelength(m)\n",
+ "t = 7.2*10**-6; #thickness(m)\n",
+ "n = 6;\n",
+ "\n",
+ "#Calculation\n",
+ "mew_1 = n*lamda/t;\n",
+ "mew = mew_1+1; #refractive index of sheet\n",
+ "\n",
+ "#Result\n",
+ "print \"refractive index of sheet is\",mew"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "refractive index of sheet is 1.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.5, Page number 76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "beta = 3; #fringe separation(mm)\n",
+ "mew = 1; #refractive index\n",
+ "lamda = 6000; #wavelength(angstrom)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda = lamda*10**-10; #wavelength(m)\n",
+ "beta = beta*10**-3; #fringe separation(m)\n",
+ "theta = lamda/(2*mew*beta); #angle between plates(sec)\n",
+ "theeta = theta*180*3600/math.pi; #angle between plates(sec \")\n",
+ "theta = theta*10**4;\n",
+ "theeta = math.ceil(theeta*10**3)/10**3; #rounding off to 3 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"angle between plates is\",theta,\"*10**-4 sec or\",theeta,\"'\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "angle between plates is 1.0 *10**-4 sec or 20.627 '\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.6, Page number 76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda = 5900*10**-7; #wavelength of light(m)\n",
+ "mew = 1; #refractive index\n",
+ "n = 7.4; #number of fringes\n",
+ "\n",
+ "#Calculation\n",
+ "t2_t1 = n*lamda/(2*mew); #difference of film thickness(m)\n",
+ "t2_t1 = t2_t1*10**2;\n",
+ "\n",
+ "#Result\n",
+ "print \"difference of film thickness is\",t2_t1,\"*10**-2 m\"\n",
+ "print \"answer given in the book is wrong\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "difference of film thickness is 0.2183 *10**-2 m\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.7, Page number 77"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda = 5.9*10**-7; #wavelength of light(m)\n",
+ "n = 10; #10th ring\n",
+ "D10 = 0.5; #diameter of 10th ring(cm)\n",
+ "\n",
+ "#Calculation\n",
+ "D10 = D10*10**-2; #diameter of 10th ring(m)\n",
+ "R = D10**2/(4*n*lamda); #radius of curvature of lens(m)\n",
+ "R = math.ceil(R*10**4)/10**4; #rounding off to 4 decimals\n",
+ "t = D10**2/(8*R); #thickness of the air film(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"radius of curvature of lens is\",R,\"m\"\n",
+ "print \"thickness of the air film is\",round(t/1e-6,2),\"*10**-6 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "radius of curvature of lens is 1.0594 m\n",
+ "thickness of the air film is 2.95 *10**-6 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.8, Page number 77"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n = 20; #number of fringes\n",
+ "lamda = 5890; #wavelength(angstrom)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda = lamda*10**-8; #wavelength(cm)\n",
+ "t = n*lamda/2; #thickness of wire(cm)\n",
+ "t = t*10**4;\n",
+ "\n",
+ "#Result\n",
+ "print \"thickness of wire is\",t,\"*10**-4 cm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "thickness of wire is 5.89 *10**-4 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.9, Page number 77"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda = 5880; #wavelength(angstrom)\n",
+ "n = 1; #number of fringes\n",
+ "mew = 1.5; #refractive index\n",
+ "r = 60; #angle of refraction(degree)\n",
+ "\n",
+ "#Calculation\n",
+ "r = r*math.pi/180; #angle of refraction(radian)\n",
+ "lamda = lamda*10**-10; #wavelength(m)\n",
+ "t = n*lamda/(2*mew*math.cos(r)); #smallest thickness of the plate(m)\n",
+ "t = t*10**10; #smallest thickness of the plate(angstrom)\n",
+ "\n",
+ "#Result\n",
+ "print \"smallest thickness of the plate is\",t,\"angstrom\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "smallest thickness of the plate is 3920.0 angstrom\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.10, Page number 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1 = 4; #fourth ring\n",
+ "n2 = 12; #12th ring\n",
+ "n3 = 20; #20th ring\n",
+ "D4 = 0.4; #diameter of 4th ring(cm)\n",
+ "D12 = 0.7; #diameter of 12th ring(cm)\n",
+ "\n",
+ "#Calculation\n",
+ "p1 = n2-n1;\n",
+ "p2 = n3-n2;\n",
+ "#D12**2-D4**2 = 4*p1*lamda*R and D20**2-D12**2 = 4*p2*lamda*R\n",
+ "#therefore D12**2-D4**2 = D20**2-D12**2\n",
+ "D20 = math.sqrt((2*D12**2)-(D4**2)); #diameter of 20th ring(cm)\n",
+ "D20 = math.ceil(D20*100)/100; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"diameter of 20th ring is\",D20,\"cm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "diameter of 20th ring is 0.91 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 2.11, Page number 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda1 = 6*10**-5; #wavelength of light 1(cm)\n",
+ "lamda2 = 4.5*10**-5; #wavelength of light 2(cm)\n",
+ "R = 90; #radius of curvature(cm)\n",
+ "\n",
+ "#Calculation\n",
+ "n = lamda2/(lamda1-lamda2); #number of fringes\n",
+ "Dn = math.sqrt(4*n*lamda1*R); #diameter of nth ring(cm)\n",
+ "Dn = math.ceil(Dn*10**4)/10**4; #rounding off to 4 decimals\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print \"diameter of nth ring is\",Dn,\"cm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "diameter of nth ring is 0.2546 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 53
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter3.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter3.ipynb
new file mode 100755
index 00000000..171bcb0d
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter3.ipynb
@@ -0,0 +1,275 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:56795fefbe7b62ddb8818924d3943a71c60bd075d0e3f1778fec6ffb47c8906e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "3: Polarization, Laser and Holography"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 3.1, Page number 103"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "x = 5; #distance of 1st minimum(mm)\n",
+ "D = 2; #distance between lens and screen(m)\n",
+ "a = 0.2; #width of slit(mm)\n",
+ "\n",
+ "#Calculation\n",
+ "x = x*10**-3; #distance of 1st minimum(m)\n",
+ "a = a*10**-3; #width of slit(m)\n",
+ "lamda = a*x/D; #wavelength of light(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength of light is\",lamda,\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "wavelength of light is 5e-07 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 3.2, Page number 103"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "a = 0.2; #width of slit(mm)\n",
+ "lamda = 5*10**-7; #wavelength(m)\n",
+ "f = 50; #focal length(cm)\n",
+ "\n",
+ "#Calculation\n",
+ "a = a*10**-3; #width of slit(m)\n",
+ "f = f*10**-2; #focal length(m)\n",
+ "theta_1 = lamda/a; #angular diffraction correcponding to 1st minima(radian)\n",
+ "theta_2 = 2*lamda/a; #angular diffraction correcponding to 2nd minima(radian)\n",
+ "x = f*(theta_2-theta_1); #separation between 1st and second minima(m)\n",
+ "x = x*10**2;\n",
+ "\n",
+ "#Result\n",
+ "print \"distance between first two minima on the screen is\",x,\"*10**-3 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "distance between first two minima on the screen is 0.125 *10**-3 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 3.3, Page number 104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "a = 0.16; #1st slit width(mm)\n",
+ "b = 0.8; #2nd slit width(mm)\n",
+ "\n",
+ "#Calculation\n",
+ "nbym = (a+b)/a; #condition for missing orders\n",
+ "\n",
+ "#Result\n",
+ "print \"n = \",nbym,\"m\"\n",
+ "print \"n = \",nbym,\",\",2*nbym,\",\",3*nbym,\"etc for m = 1,2,3...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n = 6.0 m\n",
+ "n = 6.0 , 12.0 , 18.0 etc for m = 1,2,3...\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 3.4, Page number 104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n = 2; #second order\n",
+ "theta = 30; #angle of diffraction(degrees)\n",
+ "lamda = 5*10**-5; #wavelength(cm)\n",
+ "\n",
+ "#Calculation\n",
+ "theta = theta*math.pi/180; #angle of diffraction(radian)\n",
+ "aplusb = n*lamda/math.sin(theta);\n",
+ "N = 1/aplusb; #number of lines(per cm)\n",
+ "\n",
+ "#Result\n",
+ "print \"number of lines on the grating surface is\",N,\"per cm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of lines on the grating surface is 5000.0 per cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 3.5, Page number 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "aplusb = 1.5*10**-6; #grating element(m)\n",
+ "lamda = 550; #wavelength(nm)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda = lamda*10**-9; #wavelength(m)\n",
+ "n = aplusb/lamda; #maximum possible order\n",
+ "n = math.ceil(n*10**3)/10**3; #rounding off to 3 decimals\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print \"maximum possible order is\",n,\". third and higher orders are not possible\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum possible order is 2.728 . third and higher orders are not possible\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 3.6, Page number 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "dlamda = 0.6; #difference in wavelength(nm)\n",
+ "lamda = 589.3; #wavelength(nm)\n",
+ "n = 1; #first order\n",
+ "\n",
+ "#Calculation\n",
+ "N = lamda/(n*dlamda); #number of lines on grating\n",
+ "\n",
+ "#Result\n",
+ "print \"number of lines on grating is\",int(N)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of lines on grating is 982\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter4.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter4.ipynb
new file mode 100755
index 00000000..ff17ab66
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter4.ipynb
@@ -0,0 +1,196 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:cf0df6ad8ed22fd758025ea5993932acd38bbb0ea0e95c0a8bdc6e4a7c75be59"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "4: Fiber Optics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.1, Page number 126"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mew = 1.5; #refractive angle for glass\n",
+ "\n",
+ "#Calculation\n",
+ "ip = math.atan(mew); #brewster's angle(radian)\n",
+ "ip = ip*180/math.pi; #brewster's angle(degree)\n",
+ "ip = math.ceil(ip*100)/100; #rounding off to 2 decimals\n",
+ "r = 90-ip; #angle of refraction(degree)\n",
+ "r = math.ceil(r*10)/10; #rounding off to 1 decimal\n",
+ "\n",
+ "#Result\n",
+ "print \"brewster's angle is\",ip,\"degrees\"\n",
+ "print \"angle of refraction is\",r,\"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "brewster's angle is 56.31 degrees\n",
+ "angle of refraction is 33.7 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.2, Page number 126"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mew0 = 1.658; #refractive index of calcite\n",
+ "mew_layer = 1.550; #refractive index of canada balsam\n",
+ "\n",
+ "#Calculation\n",
+ "sinC = mew_layer/mew0; \n",
+ "C = math.asin(sinC); #critical angle(radian)\n",
+ "C = C*180/math.pi; #critical angle(degrees)\n",
+ "i = 90-C; #maximum possible inclination(degrees)\n",
+ "i = math.ceil(i*10)/10; #rounding off to 1 decimal\n",
+ "\n",
+ "#Result\n",
+ "print \"maximum possible inclination is\",i,\"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum possible inclination is 20.8 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.3, Page number 126"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "mew0 = 1.544; #refractive index of calcite\n",
+ "mewe = 1.533; #refractive index of canada balsam\n",
+ "lamda = 5000; #wavelength(angstrom)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda = lamda*10**-10; #wavelength(m)\n",
+ "t = lamda/(2*(mew0-mewe)); #thickness of half wave plate(m)\n",
+ "t = t*10**4;\n",
+ "t = math.ceil(t*10**4)/10**4; #rounding off to 4 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"thickness of half wave plate is\",t,\"*10**-4 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "thickness of half wave plate is 0.2273 *10**-4 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 4.4, Page number 126"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "l = 20; #length of glass tube(cm)\n",
+ "theta = 26.2; #polarisation angle(degrees)\n",
+ "s = 20; #weight of sugar(gm)\n",
+ "w = 100; #quantity of water(ml)\n",
+ "\n",
+ "#Calculation\n",
+ "l = l/10; #length of glass tube(dm)\n",
+ "C = s/w; #concentration(gm/cc)\n",
+ "S = theta/(l*C); #specific rotation(degrees per dm per(gm/cc))\n",
+ "\n",
+ "#Result\n",
+ "print \"specific rotation of sugar is\",S,\"degrees per dm per(gm/cc)\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "specific rotation of sugar is 65.5 degrees per dm per(gm/cc)\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter5.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter5.ipynb
new file mode 100755
index 00000000..d6e00d90
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter5.ipynb
@@ -0,0 +1,156 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:766f8db46f5669c6f5759d5eab7e64f8d7d90b920fc4c9477c5cb4c2747c652e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "5: Wave and Quantum Mechanics and X-rays"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 5.1, Page number 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "h = 6.63*10**-34; #planck's constant(J)\n",
+ "c = 3*10**8; #velocity of light(m/s)\n",
+ "lamda = 6328; #wavelength of laser(angstrom)\n",
+ "ev = 6.24*10**18; #conversion factor from J to eV\n",
+ "\n",
+ "#Calculation\n",
+ "lamda = lamda*10**-10; #wavelength of laser(m)\n",
+ "E = h*c/lamda; #energy of photon(J)\n",
+ "Eev = E*ev; #energy of photon(eV)\n",
+ "Eev = math.ceil(Eev*10**3)/10**3; #rounding off to 3 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"energy of photon is\",round(E/1e-19,2),\"*10**-19 J or\",Eev,\"eV\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "energy of photon is 3.14 *10**-19 J or 1.962 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 5.2, Page number 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda = 6730; #wavelength of laser(angstrom)\n",
+ "p = 1; #output power(mW)\n",
+ "h = 6.63*10**-34; #planck's constant(J)\n",
+ "c = 3*10**8; #velocity of light(m/s)\n",
+ "\n",
+ "#Calculation\n",
+ "p = p*10**-3; #output power(W)\n",
+ "lamda = lamda*10**-10; #wavelength of laser(m)\n",
+ "n = p*lamda/(h*c); #number of photons(per sec)\n",
+ "\n",
+ "#Result\n",
+ "print \"number of photons emitted is\",round(n/1e+15,2),\"*10**15 per sec\"\n",
+ "print \"answer given in the book is wrong\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of photons emitted is 3.38 *10**15 per sec\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 5.3, Page number 146"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "l = 3*10**-2; #coherence length for sodium light(m)\n",
+ "lamda = 5893; #wavelength(angstrom)\n",
+ "c = 3*10**8; #velocity of light(m/s)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda = lamda*10**-10; #wavelength(m)\n",
+ "n = l/lamda; #number of oscillations\n",
+ "tc = l/c; #coherence time(s)\n",
+ "\n",
+ "#Result\n",
+ "print \"number of oscillations is\",round(n)\n",
+ "print \"the coherence time is\",tc,\"s\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of oscillations is 50908.0\n",
+ "the coherence time is 1e-10 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter6.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter6.ipynb
new file mode 100755
index 00000000..8645ed7b
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter6.ipynb
@@ -0,0 +1,114 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:9517150eeae7e7bf9389a01495b7c5d59b808d0c5432252a5c80e780ef687d70"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "6: Fiber Optics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 6.1, Page number 160"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1 = 1.5; #refractive index of core\n",
+ "n2 = 1.0; #refractive index of cladding\n",
+ "\n",
+ "#Calculation\n",
+ "thetac = math.asin(n2/n1); #critical angle(radian)\n",
+ "thetac = thetac*180/math.pi; #critical angle(degrees)\n",
+ "thetac = math.ceil(thetac*10**2)/10**2; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"critical angle is\",thetac,\"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "critical angle is 41.82 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 6.2, Page number 160"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1 = 1.5; #refractive index of core\n",
+ "n2 = 1.47; #refractive index of cladding\n",
+ "\n",
+ "#Calculation\n",
+ "thetac = math.asin(n2/n1); #critical angle(radian)\n",
+ "thetac = thetac*180/math.pi; #critical angle(degrees)\n",
+ "thetac = math.ceil(thetac*10**2)/10**2; #rounding off to 2 decimals\n",
+ "NA = math.sqrt(n1**2-n2**2); #numerical aperture of fiber\n",
+ "NA = math.ceil(NA*10)/10; #rounding off to 1 decimal\n",
+ "thetaa = math.asin(NA); #acceptance angle(radian)\n",
+ "thetaa = thetaa*180/math.pi; #acceptance angle(degrees)\n",
+ "thetaa = math.ceil(thetaa*10**2)/10**2; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"critical angle is\",thetac,\"degrees\"\n",
+ "print \"numerical aperture of fiber is\",NA\n",
+ "print \"acceptance angle is\",thetaa,\"degrees\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "critical angle is 78.53 degrees\n",
+ "numerical aperture of fiber is 0.3\n",
+ "acceptance angle is 17.46 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter7.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter7.ipynb
new file mode 100755
index 00000000..e302d789
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter7.ipynb
@@ -0,0 +1,158 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:b66ce97b080f93d72d0e47d146c1f1e700139df6e3e90b6b5ae82aab3595beed"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "7: Wave and Quantum Mechanics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 7.1, Page number 192"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "h = 6.625*10**-34; #planck's constant(J sec)\n",
+ "m1 = 6*10**24; #mass of earth(kg)\n",
+ "v1 = 3*10**4; #orbital speed(m/sec)\n",
+ "m2 = 10**-30; #mass of electron(kg)\n",
+ "v2 = 10**6; #velocity of electron(m/sec)\n",
+ "\n",
+ "#Calculation\n",
+ "lamdaE = h/(m1*v1); #wavelength of a wave(m)\n",
+ "lamdae = h/(m2*v2); #wavelength of electron(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength of a wave is\",round(lamdaE/1e-63,2),\"*10**-63 m\"\n",
+ "print \"wavelength of electron is\",lamdae,\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "wavelength of a wave is 3.68 *10**-63 m\n",
+ "wavelength of electron is 6.625e-10 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 7.2, Page number 193"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "m = 1; #mass of particle(g)\n",
+ "v = 100; #velocity of particle(m/sec)\n",
+ "h = 6.625*10**-34; #planck's constant(J sec)\n",
+ "\n",
+ "#Calculation\n",
+ "m = m*10**-3; #mass of particle(kg)\n",
+ "lamda = h/(m*v); #wavelength of particle(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength of particle is\",lamda,\"m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "wavelength of particle is 6.625e-33 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 7.3, Page number 193"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "V = 200; #potential difference(V)\n",
+ "\n",
+ "#Calculation\n",
+ "lamda = 12.28/math.sqrt(V); #de Broglie wavelength(angstrom)\n",
+ "lamda = math.ceil(lamda*10**4)/10**4; #rounding off to 4 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"de Broglie wavelength of electron is\",lamda,\"angstrom\"\n",
+ "print \"answer given in the book varies due to rounding off errors\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "de Broglie wavelength of electron is 0.8684 angstrom\n",
+ "answer given in the book varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter8.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter8.ipynb
new file mode 100755
index 00000000..33dc3ffa
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter8.ipynb
@@ -0,0 +1,262 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:be9a21f00f98f6eae4cb352ab1396adae89de508dceae8166d48e690d1fe887a"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "8: X-Rays"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 8.1, Page number 210"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "theta = 15; #angle of reflection(degrees)\n",
+ "d = 2.5; #atomic spacing(angstrom)\n",
+ "n = 1; #first order\n",
+ "\n",
+ "#Calculation\n",
+ "d = d*10**-10; #atomic spacing(m)\n",
+ "theta = theta*math.pi/180; #angle of reflection(radian)\n",
+ "lamda = 2*d*math.sin(theta)/n; #wavelength of X-rays(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength of X-rays is\",round(lamda/1e-10,3),\"*10**-10 m\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "wavelength of X-rays is 1.294 *10**-10 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 8.2, Page number 211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "two_theta = 20; #angle of reflection(degrees)\n",
+ "d = 2.82; #atomic spacing(angstrom)\n",
+ "n = 1; #first order\n",
+ "\n",
+ "#Calculation\n",
+ "theta = two_theta/2;\n",
+ "theta = theta*math.pi/180; #angle of reflection(radian)\n",
+ "lamda = 2*d*math.sin(theta)/n; #wavelength of X-rays(angstrom)\n",
+ "lamda = math.ceil(lamda*10**4)/10**4; #rounding off to 4 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength of X-rays is\",lamda,\"angstrom\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "wavelength of X-rays is 0.9794 angstrom\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 8.3, Page number 211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "lamda = 10; #wavelength(pm)\n",
+ "phi = 45; #scattering angle(degrees)\n",
+ "h = 6.62*10**-34; #planck's constant(m**2 kg/s)\n",
+ "m0 = 9.1*10**-31; #mass(kg)\n",
+ "c = 3*10**8; #velocity of light(m/s)\n",
+ "ev = 6.24*10**18; #conversion factor from J to eV\n",
+ "\n",
+ "#Calculation\n",
+ "phi = phi*math.pi/180; #scattering angle(radian)\n",
+ "a = h/(m0*c); #value of constant(m)\n",
+ "a = a*10**12; #value of constant(pm)\n",
+ "lamda_dash = lamda+(a*(1-math.cos(phi))); #wavelength of X-rays(pm)\n",
+ "lamda_dash = math.ceil(lamda_dash*10**2)/10**2; #rounding off to 2 decimals\n",
+ "lamdadash = lamda+(2*a); #maximum wavelength of scattered x-rays(pm)\n",
+ "lamdadash = math.ceil(lamdadash*10)/10; #rounding off to 1 decimal\n",
+ "KE = h*c*((1/lamda)-(1/lamdadash))/(10**-12); #maximum kinetic energy(J)\n",
+ "KE = KE*ev; #maximum kinetic energy(eV)\n",
+ "KE = KE*10**-3; #maximum kinetic energy(KeV)\n",
+ "KE = math.ceil(KE*10)/10; #rounding off to 1 decimal\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength of X-rays scattered is\",lamda_dash,\"pm\"\n",
+ "print \"maximum wavelength of scattered x-rays is\",lamdadash,\"pm\"\n",
+ "print \"maximum kinetic energy is\",KE,\"KeV\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "wavelength of X-rays scattered is 10.72 pm\n",
+ "maximum wavelength of scattered x-rays is 14.9 pm\n",
+ "maximum kinetic energy is 40.8 KeV\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 8.4, Page number 212"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "h = 6.62*10**-34; #planck's constant(m**2 kg/s)\n",
+ "m0 = 9.1*10**-31; #mass(kg)\n",
+ "c = 3*10**8; #velocity of light(m/s)\n",
+ "phi = 180; #scattering angle(degrees)\n",
+ "\n",
+ "#Calculation\n",
+ "phi = phi*math.pi/180; #scattering angle(radian)\n",
+ "a = h/(m0*c); #value of constant(m)\n",
+ "a = a*10**10; #value of constant(angstrom)\n",
+ "delta_lamda = a*(1-math.cos(phi)); #change in wavelength(angstrom)\n",
+ "delta_lamda = math.ceil(delta_lamda*10**4)/10**4; #rounding off to 4 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"change in wavelength of photon is\",delta_lamda,\"angstrom\"\n",
+ "print \"answer in the book varies due to rounding off errors\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "change in wavelength of photon is 0.0485 angstrom\n",
+ "answer in the book varies due to rounding off errors\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 8.5, Page number 212"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "h = 6.62*10**-34; #planck's constant(m**2 kg/s)\n",
+ "m0 = 9.1*10**-31; #mass(kg)\n",
+ "c = 3*10**8; #velocity of light(m/s)\n",
+ "phi = 90; #scattering angle(degrees)\n",
+ "\n",
+ "#Calculation\n",
+ "phi = phi*math.pi/180; #scattering angle(radian)\n",
+ "a = h/(m0*c); #value of constant(m)\n",
+ "a = a*10**10; #value of constant(angstrom)\n",
+ "lamda = a*(1-math.cos(phi)); #wavelength(angstrom)\n",
+ "lamda = math.ceil(lamda*10**5)/10**5; #rounding off to 5 decimals\n",
+ "E = h*c/(lamda*10**-10); #energy of photon(J)\n",
+ "\n",
+ "#Result\n",
+ "print \"wavelength of the photon is\",lamda,\"angstrom\"\n",
+ "print \"energy of the incident photon is\",round(E/1e-14,4),\"*10**-14 J\"\n",
+ "print \"answer for energy of incident photon is wrong in the book\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "wavelength of the photon is 0.02425 angstrom\n",
+ "energy of the incident photon is 8.1897 *10**-14 J\n",
+ "answer for energy of incident photon is wrong in the book\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/Chapter9.ipynb b/Engineering_Physics_by_Shyam_Rajeev/Chapter9.ipynb
new file mode 100755
index 00000000..847fb2bf
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/Chapter9.ipynb
@@ -0,0 +1,64 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e8e761ea4c766f0a738732d4994726c98969966c5d35a3277656198f5c5939ee"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "9: Dielectrics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example number 9.1, Page number 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "p = 4.3*10**-8; #polarization(C/m**2)\n",
+ "E = 1000; #electric field(V/m)\n",
+ "epsilon_0 = 8.85*10**-12; #permittivity of free space(F/m)\n",
+ "\n",
+ "#Calculation\n",
+ "epsilon_r = 1+(p/(epsilon_0*E)); #relative permittivity\n",
+ "epsilon_r = math.ceil(epsilon_r*10**2)/10**2; #rounding off to 2 decimals\n",
+ "\n",
+ "#Result\n",
+ "print \"relative permittivity is\",epsilon_r"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "relative permittivity is 5.86\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Engineering_Physics_by_Shyam_Rajeev/screenshots/s1.png b/Engineering_Physics_by_Shyam_Rajeev/screenshots/s1.png
new file mode 100755
index 00000000..86ab1246
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/screenshots/s1.png
Binary files differ
diff --git a/Engineering_Physics_by_Shyam_Rajeev/screenshots/s2.png b/Engineering_Physics_by_Shyam_Rajeev/screenshots/s2.png
new file mode 100755
index 00000000..becfb80b
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/screenshots/s2.png
Binary files differ
diff --git a/Engineering_Physics_by_Shyam_Rajeev/screenshots/s3.png b/Engineering_Physics_by_Shyam_Rajeev/screenshots/s3.png
new file mode 100755
index 00000000..0e379400
--- /dev/null
+++ b/Engineering_Physics_by_Shyam_Rajeev/screenshots/s3.png
Binary files differ
diff --git a/Engineering_Physics_/Chapter1.ipynb b/Engineering_Physics_by_Uma_Mukherji/Chapter1.ipynb
index 81c066a4..81c066a4 100755
--- a/Engineering_Physics_/Chapter1.ipynb
+++ b/Engineering_Physics_by_Uma_Mukherji/Chapter1.ipynb
diff --git a/Engineering_Physics_/Chapter10.ipynb b/Engineering_Physics_by_Uma_Mukherji/Chapter10.ipynb
index f0870466..f0870466 100755
--- a/Engineering_Physics_/Chapter10.ipynb
+++ b/Engineering_Physics_by_Uma_Mukherji/Chapter10.ipynb
diff --git a/Engineering_Physics_/Chapter11.ipynb b/Engineering_Physics_by_Uma_Mukherji/Chapter11.ipynb
index 9aaaa633..9aaaa633 100755
--- a/Engineering_Physics_/Chapter11.ipynb
+++ b/Engineering_Physics_by_Uma_Mukherji/Chapter11.ipynb
diff --git a/Engineering_Physics_/Chapter12.ipynb.bkup b/Engineering_Physics_by_Uma_Mukherji/Chapter12.ipynb.bkup
index 0efc0c8d..0efc0c8d 100755
--- a/Engineering_Physics_/Chapter12.ipynb.bkup
+++ b/Engineering_Physics_by_Uma_Mukherji/Chapter12.ipynb.bkup
diff --git a/Engineering_Physics_/Chapter2.ipynb b/Engineering_Physics_by_Uma_Mukherji/Chapter2.ipynb
index e5649f50..e5649f50 100755
--- a/Engineering_Physics_/Chapter2.ipynb
+++ b/Engineering_Physics_by_Uma_Mukherji/Chapter2.ipynb
diff --git a/Engineering_Physics_/Chapter3.ipynb b/Engineering_Physics_by_Uma_Mukherji/Chapter3.ipynb
index e34bf801..e34bf801 100755
--- a/Engineering_Physics_/Chapter3.ipynb
+++ b/Engineering_Physics_by_Uma_Mukherji/Chapter3.ipynb
diff --git a/Engineering_Physics_/Chapter4.ipynb b/Engineering_Physics_by_Uma_Mukherji/Chapter4.ipynb
index ee675097..ee675097 100755
--- a/Engineering_Physics_/Chapter4.ipynb
+++ b/Engineering_Physics_by_Uma_Mukherji/Chapter4.ipynb
diff --git a/Engineering_Physics_/Chapter5.ipynb b/Engineering_Physics_by_Uma_Mukherji/Chapter5.ipynb
index 781fd57b..781fd57b 100755
--- a/Engineering_Physics_/Chapter5.ipynb
+++ b/Engineering_Physics_by_Uma_Mukherji/Chapter5.ipynb
diff --git a/Engineering_Physics_/Chapter6.ipynb b/Engineering_Physics_by_Uma_Mukherji/Chapter6.ipynb
index 7cdceb44..7cdceb44 100755
--- a/Engineering_Physics_/Chapter6.ipynb
+++ b/Engineering_Physics_by_Uma_Mukherji/Chapter6.ipynb
diff --git a/Engineering_Physics_/Chapter7.ipynb b/Engineering_Physics_by_Uma_Mukherji/Chapter7.ipynb
index d5043163..d5043163 100755
--- a/Engineering_Physics_/Chapter7.ipynb
+++ b/Engineering_Physics_by_Uma_Mukherji/Chapter7.ipynb
diff --git a/Engineering_Physics_/Chapter8.ipynb b/Engineering_Physics_by_Uma_Mukherji/Chapter8.ipynb
index d9dc420b..d9dc420b 100755
--- a/Engineering_Physics_/Chapter8.ipynb
+++ b/Engineering_Physics_by_Uma_Mukherji/Chapter8.ipynb
diff --git a/Engineering_Physics_/Chapter9.ipynb b/Engineering_Physics_by_Uma_Mukherji/Chapter9.ipynb
index 9aff9ae1..9aff9ae1 100755
--- a/Engineering_Physics_/Chapter9.ipynb
+++ b/Engineering_Physics_by_Uma_Mukherji/Chapter9.ipynb
diff --git a/Engineering_Physics_/README.txt b/Engineering_Physics_by_Uma_Mukherji/README.txt
index b121a766..b121a766 100755
--- a/Engineering_Physics_/README.txt
+++ b/Engineering_Physics_by_Uma_Mukherji/README.txt
diff --git a/Engineering_Physics_/screenshots/11.png b/Engineering_Physics_by_Uma_Mukherji/screenshots/11.png
index 74759f5f..74759f5f 100755
--- a/Engineering_Physics_/screenshots/11.png
+++ b/Engineering_Physics_by_Uma_Mukherji/screenshots/11.png
Binary files differ
diff --git a/Engineering_Physics_/screenshots/22.png b/Engineering_Physics_by_Uma_Mukherji/screenshots/22.png
index ec09c65c..ec09c65c 100755
--- a/Engineering_Physics_/screenshots/22.png
+++ b/Engineering_Physics_by_Uma_Mukherji/screenshots/22.png
Binary files differ
diff --git a/Engineering_Physics_/screenshots/33.png b/Engineering_Physics_by_Uma_Mukherji/screenshots/33.png
index a4da4f79..a4da4f79 100755
--- a/Engineering_Physics_/screenshots/33.png
+++ b/Engineering_Physics_by_Uma_Mukherji/screenshots/33.png
Binary files differ
diff --git a/Fluid_Power_With_Applications/screenshots/Cha7.png b/Fluid_Power_With_Applications/screenshots/Cha7.png
new file mode 100755
index 00000000..19c59579
--- /dev/null
+++ b/Fluid_Power_With_Applications/screenshots/Cha7.png
Binary files differ
diff --git a/Fluid_Power_With_Applications/screenshots/cha6.png b/Fluid_Power_With_Applications/screenshots/cha6.png
new file mode 100755
index 00000000..cf40a896
--- /dev/null
+++ b/Fluid_Power_With_Applications/screenshots/cha6.png
Binary files differ
diff --git a/Fluid_Power_With_Applications/screenshots/cha9.png b/Fluid_Power_With_Applications/screenshots/cha9.png
new file mode 100755
index 00000000..933b4c76
--- /dev/null
+++ b/Fluid_Power_With_Applications/screenshots/cha9.png
Binary files differ
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_10_Hydraulic_Conductors_and_Fittings.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_10_Hydraulic_Conductors_and_Fittings.ipynb
new file mode 100755
index 00000000..fb2937bf
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_10_Hydraulic_Conductors_and_Fittings.ipynb
@@ -0,0 +1,333 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 10: Hydraulic Conductors and Fittings"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10.1 pgno:367"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The minimum inside diameter of pipe is in. 0.783\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find minimum inside diameter of pipe \n",
+ "# Given:\n",
+ "# flow-rate through pipe:\n",
+ "Q=30.0; #gpm\n",
+ "# average fluid velocity:\n",
+ "v=20.0; #ft/s\n",
+ " \n",
+ "import math \n",
+ "from math import pi\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# flow-rate in ft**3/s,\n",
+ "Q_fps=Q/449; #ft**3/s\n",
+ "# minimum required pipe flow area,\n",
+ "A=(Q_fps/v)*144; #in**2\n",
+ "# minimum inside diameter,\n",
+ "D=((4*A)/(pi))**0.5; #in\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The minimum inside diameter of pipe is in.\",round(D,3)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10.2 pgno:368"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The minimum inside diameter of pipe is mm. 20.4\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find minimum inside diameter of pipe in Metric units \n",
+ "# Given:\n",
+ "# flow-rate through pipe:\n",
+ "Q=0.002; #m^3/s\n",
+ "# average fluid velocity:\n",
+ "v=6.1; #m/s\n",
+ "\n",
+ "from math import pi\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# minimum required pipe flow area,\n",
+ "A=(Q/v); #m^2\n",
+ "# minimum inside diameter,\n",
+ "D=(((4*A)/(pi))**0.5)*1000; #mm\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The minimum inside diameter of pipe is mm.\",round(D,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10.3 pgno:371"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The working pressure of steel tube is psi. 1.232\n",
+ "\n",
+ " The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find safe working pressure for the tube \n",
+ "# Given:\n",
+ "# outside diameter of steel tube:\n",
+ "Do=1.250; #in\n",
+ "# inside diameter of steel tube:\n",
+ "Di=1.060; #in\n",
+ "# tensile strength of steel tube:\n",
+ "S=55000.0; #psi\n",
+ "# factor of safety:\n",
+ "FS=8.0;\n",
+ "\n",
+ "# Solution:\n",
+ "# wall thickness,\n",
+ "t=(Do-Di)/2; #in\n",
+ "# burst pressure,\n",
+ "BP=(2*t*S)/Di; #psi\n",
+ "# working pressure,\n",
+ "WP=BP/FS/1000; #psi\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The working pressure of steel tube is psi.\",round(WP,3)\n",
+ "print\"\\n The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\"\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10.4 pgno:380"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " \n",
+ " The working pressure psi is not adequate (less than psi) so next case is considered, 746.951219512 1000\n",
+ " \n",
+ " The working pressure psi is greater than psi) , 1027.29885057 1000\n",
+ "\n",
+ " Results: \n",
+ "\n",
+ " The ratio of inner diameter to length is . 13.4\n",
+ "\n",
+ " The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 10-4 for Problem Description\n",
+ "# Given:\n",
+ "# flow-rate:\n",
+ "Q=30; #gpm\n",
+ "# operating pressure:\n",
+ "p=1000; #psi\n",
+ "# maximum velocity:\n",
+ "v=20; #ft/s\n",
+ "# tensile strength of material:\n",
+ "S=55000; #psi\n",
+ "# factor of safety:\n",
+ "FS=8;\n",
+ "from math import pi\n",
+ "# Solutions:\n",
+ "# flow-rate,\n",
+ "Q=Q/449; #ft^3/s\n",
+ "# minimum required pipe flow area,\n",
+ "Ai=(Q/v)*144; #in^2\n",
+ "# minimum inside diameter,\n",
+ "Di=((4*Ai)/(pi))**0.5; #in\n",
+ "# wall thickness,\n",
+ "t1=0.049; t2=0.065; #in\n",
+ "# tube inside diameter,\n",
+ "D1=0.902; D2=0.870; #in\n",
+ "# burst pressure,\n",
+ "BP1=(2*t1*S)/D1; #psi\n",
+ "# working pressure,\n",
+ "WP1=BP1/FS; #psi\n",
+ "print\" \\n The working pressure psi is not adequate (less than psi) so next case is considered,\",WP1,p\n",
+ "# burst pressure,\n",
+ "BP2=(2*t2*S)/D2; #psi\n",
+ "# working pressure,\n",
+ "WP2=BP2/FS; #psi\n",
+ "# ratio of inner diameter to thickness,\n",
+ "r2=D2/t2;\n",
+ "print\" \\n The working pressure psi is greater than psi) ,\",WP2,p\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The ratio of inner diameter to length is .\",round(r2,1)\n",
+ "print\"\\n The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10.5 pgno:389"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " \n",
+ " The working pressure bars is not adequate (less than bars) so next case is considered, 47.4\n",
+ " \n",
+ " The working pressure bars is greater than bars) , 79.0\n",
+ "\n",
+ " Results: \n",
+ "\n",
+ " The ratio of inner diameter to length is 12.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Aim:Refer Example 10-5 for Problem Description\n",
+ "# Given:\n",
+ "# flow-rate:\n",
+ "Q=0.00190; #m^3/s\n",
+ "# operating pressure:\n",
+ "p=70.00000000000; #bars\n",
+ "# maximum velocity:\n",
+ "v=6.10000000000; #m/s\n",
+ "# tensile strength of material:\n",
+ "S=379.0000000; #MPa\n",
+ "# factor of safety:\n",
+ "FS=8.0000000;\n",
+ "from math import pi\n",
+ "\n",
+ "# Solutions:\n",
+ "# minimum required pipe flow area,\n",
+ "A=(Q/v); #m^2\n",
+ "# minimum inside diameter,\n",
+ "ID=(((4*A)/(pi))**0.5)*1000; #mm\n",
+ "# wall thickness,\n",
+ "t1=1.; t2=2.; #mm\n",
+ "# tube inside diameter,\n",
+ "D1=20.; D2=24.0; #mm\n",
+ "# burst pressure,\n",
+ "BP1=(2*(t1/1000)*S)/(D1/1000); #MPa\n",
+ "# working pressure,\n",
+ "WP1=(BP1/FS)*10; #bars\n",
+ "print\" \\n The working pressure bars is not adequate (less than bars) so next case is considered,\",round(WP1,1)\n",
+ "# burst pressure,\n",
+ "BP2=(2*(t2/1000)*S)/(D2/1000); #MPa\n",
+ "# working pressure,\n",
+ "WP2=(BP2/FS)*10; #MPa\n",
+ "# ratio of inner diameter to thickness,\n",
+ "r2=D2/t2;\n",
+ "print\" \\n The working pressure bars is greater than bars) ,\",round(WP2)\n",
+ "\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The ratio of inner diameter to length is \",r2"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_11_Ancillary_Hydraulic_Devices.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_11_Ancillary_Hydraulic_Devices.ipynb
new file mode 100755
index 00000000..05caf661
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_11_Ancillary_Hydraulic_Devices.ipynb
@@ -0,0 +1,302 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 11: Ancillary Hydraulic Devices"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11.1 pgno:409"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The high discharge pressure is psi. 2500.0\n",
+ "\n",
+ " The low discharge flow-rate is gpm. 4.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find the discharge flow and pressure \n",
+ "# Given:\n",
+ "# high inlet flow-rate:\n",
+ "Q_high_inlet=20.0; #gpm\n",
+ "# low inlet pressure:\n",
+ "p_low_inlet=500.0; #psi\n",
+ "# Ratio of piston area to rod area:\n",
+ "Ratio=5/1;\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# high discharge pressure,\n",
+ "p_high_discharge=Ratio*p_low_inlet; #psi\n",
+ "# low discharge flow-rate,\n",
+ "Q_low_discharge=Q_high_inlet/Ratio; #gpm\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The high discharge pressure is psi.\",p_high_discharge\n",
+ "print\"\\n The low discharge flow-rate is gpm.\",Q_low_discharge\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11.2 pgno:424"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The downstream oil temperature is deg F. 127.9\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find the downstream oil temperature\n",
+ "# Given:\n",
+ "# temperature of oil flowing through pressure relief valve:\n",
+ "T_oil=120.0; #deg F\n",
+ "# pressure of oil flowing through pressure relief valve:\n",
+ "p=1000.0; #psi\n",
+ "# oil flow through pressure relief valve:\n",
+ "Q_gpm=10.0; #gpm\n",
+ "# Solution:\n",
+ "# heat generation rate,\n",
+ "HP=(p*Q_gpm)/1714; #HP\n",
+ "# heat generation rate in Btu/min,\n",
+ "HP_btu=HP*42.4; #Btu/min\n",
+ "# oil flow-rate in lb/min,\n",
+ "Q_lb=7.42*Q_gpm; #lb/min\n",
+ "# temperature increase,\n",
+ "T_increase=HP_btu/(0.42*Q_lb); #deg F\n",
+ "# downward oil temperature,\n",
+ "T_downward=T_oil+T_increase; #deg F\n",
+ "\n",
+ "# Results:\n",
+ "print \"\\n Results: \" \n",
+ "print \"\\n The downstream oil temperature is deg F.\",round(T_downward,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11.3 pgno:424"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The downstream oil temperature is deg C. 54.3\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find the downstream oil temperature in SI Unit\n",
+ "# Given:\n",
+ "# temperature of oil flowing through pressure relief valve:\n",
+ "T_oil=50.0; #deg C\n",
+ "# pressure of oil flowing through pressure relief valve:\n",
+ "p=70.0; #bar\n",
+ "# oil flow through pressure relief valve:\n",
+ "Q=0.000632; #m**3/s\n",
+ "# Solution:\n",
+ "# heat generation rate,\n",
+ "kW=((p*10**5)*Q)/1000; #kW\n",
+ "# oil flow-rate,\n",
+ "Q_kg_s=895*Q; #kg/s\n",
+ "# temperature increase,\n",
+ "T_increase=kW/(1.8*Q_kg_s); #deg C\n",
+ "# downward oil temperature,\n",
+ "T_downward=T_oil+T_increase; #deg C\n",
+ "\n",
+ "# Results:\n",
+ "print \"\\n Results: \" \n",
+ "print \"\\n The downstream oil temperature is deg C.\",round(T_downward,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11.4 pgno:425"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The heat exchanger rating is Btu/hr. 21565.0\n",
+ "\n",
+ " The answer in the program does not match with that in the textbook due to roundoff error (standard ratings) in textbook\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find the rating of heat exchanger required to dissipate generated heat\n",
+ "# Given:\n",
+ "# oil flow-rate:\n",
+ "Q=20.0; #gpm\n",
+ "# operating pressure:\n",
+ "p=1000.0; #psi\n",
+ "# overall efficiency of pump:\n",
+ "eff_overall=85.0; #%\n",
+ "# power lost due to friction:\n",
+ "HP_frict=10.0; #%\n",
+ "\n",
+ "# Solution:\n",
+ "# pump power loss,\n",
+ "pump_HP_loss=((1/(eff_overall/100))-1)*((p*Q)/1714); #HP\n",
+ "# PRV average HP loss,\n",
+ "PRV_loss=0.5*((p*Q)/1714); #HP\n",
+ "# line average HP loss,\n",
+ "line_loss=(HP_frict/100)*PRV_loss; #HP\n",
+ "# total average loss,\n",
+ "total_loss=pump_HP_loss+PRV_loss+line_loss; #HP\n",
+ "# heat exchanger rating,\n",
+ "HEx_rating=total_loss*2544; #Btu/hr\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The heat exchanger rating is Btu/hr.\",round(HEx_rating)\n",
+ "print\"\\n The answer in the program does not match with that in the textbook due to roundoff error (standard ratings) in textbook\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11.5 pgno:426"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The heat exchanger rating is kW. 6.41\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find the rating of heat exchanger required to dissipate generated heat in SI unit\n",
+ "# Given:\n",
+ "# oil flow-rate:\n",
+ "Q=0.00126; #m**3/s\n",
+ "# operating pressure:\n",
+ "p=70.0; #bar\n",
+ "# overall efficiency of pump:\n",
+ "eff_overall=85.0; #%\n",
+ "# power lost due to friction:\n",
+ "HP_frict=10.0; #%\n",
+ "\n",
+ "# Solution:\n",
+ "# pump power loss,\n",
+ "pump_loss=((1/(eff_overall/100))-1)*((p*10**5*Q)/1000); #kW\n",
+ "# PRV average HP loss,\n",
+ "PRV_loss=0.5*((p*10**5*Q)/1000); #kW\n",
+ "# line average HP loss,\n",
+ "line_loss=(HP_frict/100)*PRV_loss; #kW\n",
+ "# total average loss,\n",
+ "HEx_rating=pump_loss+PRV_loss+line_loss; #kW\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The heat exchanger rating is kW.\",round(HEx_rating,2)\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_13_Pneumatics_Air_Preparation_and_components.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_13_Pneumatics_Air_Preparation_and_components.ipynb
new file mode 100755
index 00000000..8671e8b9
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_13_Pneumatics_Air_Preparation_and_components.ipynb
@@ -0,0 +1,732 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 13 :Pneumatics: Air Preparation and components"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13.1 pgno:471"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The new pressure when blank side port is blocked is psig. 78.7\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find new pressure in cylinder when its blank end is blocked\n",
+ "# Given:\n",
+ "# diameter of pneumatic piston:\n",
+ "D=2; #in\n",
+ "# length of retraction of piston:\n",
+ "l_ret=4; #in\n",
+ "# blank side pressure:\n",
+ "p1=20; #psig\n",
+ "# volume of cylinder for extension stroke:\n",
+ "V1=20; #in**3\n",
+ "from math import pi\n",
+ "# Solution:\n",
+ "# volume of cylinder during retraction stroke,\n",
+ "V2=(V1-((pi * D**2 * l_ret)/4)); #in**3\n",
+ "# absolute pressure on blank side,\n",
+ "p1=p1+14.7; #psia\n",
+ "# new pressure when blank side port is blocked,\n",
+ "# Boyle's Law,\n",
+ "p2=(p1*V1)/V2; #psia\n",
+ "p2=p2-14.7; #psig\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The new pressure when blank side port is blocked is psig.\",round(p2,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13.2 pgno:472"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The final volume of air is in^3. 22.3\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find new volume of air at the blank end of cylinder\n",
+ "# Given:\n",
+ "# initial volume:\n",
+ "V1=20.0; #in^3\n",
+ "# constant load:\n",
+ "p=20.0; #psi\n",
+ "# initial temperature of air:\n",
+ "T1=60.0; #deg F\n",
+ "# final temperature of air:\n",
+ "T2=120.0; #degF\n",
+ "\n",
+ "# Solution:\n",
+ "# initial temperature of air in Rankine,\n",
+ "T1=T1+460; #deg R\n",
+ "# final temperature of air in Rankine,\n",
+ "T2=T2+460; #deg R\n",
+ "# final volume of air,\n",
+ "# Charle's Law,\n",
+ "V2=(T2/T1)*V1; #in^3\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The final volume of air is in^3.\",round(V2,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Exmaple 13.3 pgno:473"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The final pressure of air at constant volume is psig. 26.7\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find new pressure in cylinder when it is at locked position\n",
+ "# Given:\n",
+ "# initial pressure:\n",
+ "p1=20; #psig\n",
+ "# initial temperature of air:\n",
+ "T1=60; #deg F\n",
+ "# final temperature of air:\n",
+ "T2=160; #degF\n",
+ "# Solution:\n",
+ "# initial temperature of air in Rankine,\n",
+ "T1=T1+460; #deg R\n",
+ "# final temperature of air in Rankine,\n",
+ "T2=T2+460; #deg R\n",
+ "# absolute initial pressure,\n",
+ "p1=p1+20.8; #psia\n",
+ "# final pressure of air,\n",
+ "# Gay-Lussac's Law,\n",
+ "p2=(T2/T1)*p1; #psia\n",
+ "p2=p2-14.1; #psig\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The final pressure of air at constant volume is psig.\",p2\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Chapter 13.4 pgno:475"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The final pressure in the cylinder is psig. 1579.8\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find final pressure in the cylinder\n",
+ "# Given:\n",
+ "# initial gas pressure:\n",
+ "p1=1000; #psig\n",
+ "# initial volume of cylinder:\n",
+ "V1=2000; #in^3\n",
+ "# initial temperature of cylinder:\n",
+ "T1=100; #deg F\n",
+ "# final volume of cylinder:\n",
+ "V2=1500; #in^3\n",
+ "# final temperature of cylinder:\n",
+ "T2=200; #deg F\n",
+ "# Solution:\n",
+ "# final pressure in the cylinder,\n",
+ "# General Gas Law, \n",
+ "p2=((p1+14.7)*V1*(T2+460))/(V2*(T1+460))-14.7; #psig\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The final pressure in the cylinder is psig.\",round(p2,1)\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13.5 pgno:475"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The final pressure in the cylinder is bars absolute. 111.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find final pressure in the cylinder in SI units\n",
+ "# Given:\n",
+ "# initial gas pressure:\n",
+ "p1=70; #bar\n",
+ "# initial volume of cylinder:\n",
+ "V1=12900; #cm**3\n",
+ "# initial temperature of cylinder:\n",
+ "T1=37.8; #deg C\n",
+ "# final volume of cylinder:\n",
+ "V2=9680; #cm**3\n",
+ "# final temperature of cylinder:\n",
+ "T2=93.3; #deg C\n",
+ "\n",
+ "# Solution:\n",
+ "# final pressure in the cylinder in absolute units,\n",
+ "# General Gas Law, \n",
+ "p2=(((p1+1)*10**5*V1*(T2+273))/(V2*(T1+273)))/10**5; #bars\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The final pressure in the cylinder is bars absolute.\",round(p2,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13.6 pgno:483"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The cfm of free air compressor must be provided is cfm of free air. 275.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find how many cfm of free air compressor must be provided\n",
+ "# Given:\n",
+ "# flow-rate of air from receiver:\n",
+ "Q2=30.0; #cfm\n",
+ "# temperature of air from receiver:\n",
+ "T2=90.0; #deg F\n",
+ "# pressure of air coming from receiver:\n",
+ "p2=125.0; #psig\n",
+ "# atmospheric temperature:\n",
+ "T1=70.00; #deg F\n",
+ "# atmospheric pressure:\n",
+ "p1=14.7; #psig \n",
+ "\n",
+ "# Solution:\n",
+ "# cfm of free air compressor must be provided,\n",
+ "Q1=Q2*((p2+14.7)/14.7)*((T1+460)/(T2+460)); #cfm\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The cfm of free air compressor must be provided is cfm of free air.\",round(Q1,0)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13.7 pgno:484"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The required size of a receiver before compressor resumes operation is gal. 659.7\n",
+ "\n",
+ " The required size of a receiver when compressor is running gal. 494.8\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 13-7 for Problem Description\n",
+ "# Given:\n",
+ "# maximum pressure level in receiver:\n",
+ "p_max=100; #psi\n",
+ "# minimum pressure level in receiver:\n",
+ "p_min=80; #psi\n",
+ "# time that receiver can supply required amount of air:\n",
+ "t=6; #min\n",
+ "# consumption rate of pneumatic system:\n",
+ "Qr=20; #scfm\n",
+ "# output flow-rate of compressor:\n",
+ "Qc=5; #scfm\n",
+ "# Solution:\n",
+ "# required size of a receiver before compressor resumes operation,\n",
+ "Vr=((14.7*t*(Qr-0))/(p_max-p_min))*7.48; #gal\n",
+ "# required size of a receiver when compressor is running,\n",
+ "Vr_run=((14.7*t*(Qr-Qc))/(p_max-p_min))*7.48; #gal\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The required size of a receiver before compressor resumes operation is gal.\",round(Vr,1)\n",
+ "print\"\\n The required size of a receiver when compressor is running gal.\",round(Vr_run,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13.8 pgno:485"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The actual power required to drive a compressor is HP. 24.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine actual power required to drive a compressor\n",
+ "# Given:\n",
+ "# input flow-rate of air through compressor:\n",
+ "Q=100.0; #scfm\n",
+ "# inlet atmospheric pressure:\n",
+ "p_in=14.7; #psig\n",
+ "# outlet pressure:\n",
+ "p_out=114.7; #psig\n",
+ "# overall efficiency of compressor:\n",
+ "eff=75.0; #%\n",
+ "\n",
+ "# Solution:\n",
+ "# theoretical horsepower,\n",
+ "HP_theo=((p_in*Q)/65.4)*((p_out/p_in)**0.286-1); #HP\n",
+ "# actual horsepower,\n",
+ "HP_act=HP_theo/(eff/100); #HP\n",
+ "\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The actual power required to drive a compressor is HP.\",round(HP_act)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13.9 pgno:495"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The number of gallons/day received by pneumatic system is gal/day 9.09\n",
+ "\n",
+ " The moisture received by pneumatic system if aftercooler is installed is gal/day 1.15\n",
+ "\n",
+ " The moisture received by pneumatic system if air dryer is installed is gal/day 0.29\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 13-9 for Problem Description\n",
+ "# Given:\n",
+ "# output flow-rate of compressor:\n",
+ "Qc=100.0; #scfm\n",
+ "# pressure at compressor outlet:\n",
+ "p_out=100.0; #psig\n",
+ "# temperature of saturated air at compressor inlet:\n",
+ "T_in=80.0; #deg F\n",
+ "# operation time of compressor per day:\n",
+ "t=8.0; #hr/day\n",
+ "\n",
+ "# Solution:\n",
+ "# from fig 13-29,\n",
+ "# entering moistue content at 80 deg F,\n",
+ "moist_in=1.58/1000; #lb/ft**3\n",
+ "# moisture rate which enters the compressor,\n",
+ "moist_rate=moist_in*Qc; #lb/min\n",
+ "# number of gallons/day received by pneumatic system,\n",
+ "gal_per_day=(moist_rate*60*t)/8.34; #gal/day\n",
+ "# moisture received by pneumatic system if aftercooler is installed,\n",
+ "# from fig 13-29,\n",
+ "moist_after=(1-((1.58-0.2)/1.58))*gal_per_day; #gal/day\n",
+ "# moisture received by pneumatic system if air dryer is installed,\n",
+ "# from fig 13-29,\n",
+ "moist_air_dryer=(1-((1.58-0.05)/1.58))*gal_per_day; #gal/day\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The number of gallons/day received by pneumatic system is gal/day\",round(gal_per_day,2)\n",
+ "print\"\\n The moisture received by pneumatic system if aftercooler is installed is gal/day\",round(moist_after,2)\n",
+ "print\"\\n The moisture received by pneumatic system if air dryer is installed is gal/day\",round(moist_air_dryer,2)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13.10 pgno:498"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The maximum flow-rate is scfm of air 341.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine maximum flow-rate in units of scfm of air\n",
+ "# Given:\n",
+ "# upstream temperature:\n",
+ "T1=80.0; #deg F\n",
+ "# upstream pressure:\n",
+ "p1=80.0; #psi\n",
+ "# flow capacity constant:\n",
+ "Cv=7.4; \n",
+ "# diameter of orifice:\n",
+ "d=0.5; #in\n",
+ "from math import floor\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# upstream temperature in Rankine,\n",
+ "T1=T1+460; #deg R\n",
+ "# absolute upstream pressure,\n",
+ "p1=p1+14.7; #psia\n",
+ "# for maximum flow-rate,\n",
+ "# absolute downstream pressure,\n",
+ "p2=0.53*p1; #psia\n",
+ "# volume flow-rate,\n",
+ "Q=floor(22.7*Cv*(((p1-p2)*p2)/T1)**0.5); #scfm\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The maximum flow-rate is scfm of air\",Q\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13.11 pgno:506"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The flow capacity constant is 1.38\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine size valve (Cv) for pneumatically powered impact tool\n",
+ "# Given:\n",
+ "# volume flow-rate of air:\n",
+ "Q=50; #scfm\n",
+ "# downstream pressure:\n",
+ "p2=100; #psi\n",
+ "# pressure drop across valve:\n",
+ "del_p=12; #psi\n",
+ "# upstream air temperature:\n",
+ "T1=80; #deg F\n",
+ "\n",
+ "# Solution:\n",
+ "# upstream temperature in Rankine,\n",
+ "T1=T1+460; #deg R\n",
+ "# absolute downstream pressure,\n",
+ "p2=p2+14.7; #psia\n",
+ "# flow capacity constant,\n",
+ "Cv=(Q/22.7)*((T1/(p2*del_p))**0.5);\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The flow capacity constant is \",round(Cv,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13.12 pgno:511"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The air consumption rate in scfm is 2.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine the air-consumption rate in scfm\n",
+ "# Given:\n",
+ "# piston diameter of pneumatic cylinder:\n",
+ "d=1.75; #in\n",
+ "# stroke length of cylinder:\n",
+ "L=6.0; #in\n",
+ "# number of cycles per minute:\n",
+ "N=30.0; #cycles/min\n",
+ "# atmospheric temperature:\n",
+ "T1=68.0; #deg F\n",
+ "# atmospheric pressure:\n",
+ "p1=14.7; #psia\n",
+ "# temperature of air in pneumatic cylinder:\n",
+ "T2=80.0; #deg F\n",
+ "# pneumatic cylinder pressure:\n",
+ "p2=100.0; #psig\n",
+ "from math import pi\n",
+ "# Solution:\n",
+ "# atmospheric temperature in deg Rankine,\n",
+ "T1=T1+460; #deg R\n",
+ "# temperature of air in deg Rankine in pneumatic cylinder,\n",
+ "T2=T2+460; #deg R\n",
+ "# absolute pneumatic cylinder pressure,\n",
+ "p2=p2+14.7; #psia\n",
+ "# the volume per minute of air consumed by cylinder,\n",
+ "Q2=(pi/4)*(d/12)**2*(L/12)*N; #ft**3/min\n",
+ "# air consumption rate,\n",
+ "Q1=Q2*(p2/p1)*(T1/T2); #scfm\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The air consumption rate in scfm is \",round(Q1,0)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 13.3 pgno:513"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The reciprocation rate of piston is cycles/min. 30.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine the piston reciprocation rate\n",
+ "# Given:\n",
+ "# piston diameter of pneumatic cylinder:\n",
+ "d=44.5; #mm\n",
+ "# stroke length of cylinder:\n",
+ "L=152.0; #mm\n",
+ "# atmospheric temperature:\n",
+ "T1=20.0; #deg C\n",
+ "# atmospheric pressure:\n",
+ "p1=101.0; #kPa\n",
+ "# temperature of air in pneumatic cylinder:\n",
+ "T2=27.0; #deg C\n",
+ "# pneumatic cylinder pressure:\n",
+ "p2=687.0; #kPa\n",
+ "# air consumption rate:\n",
+ "Q1=0.0555; #m**3/min\n",
+ "from math import floor\n",
+ "from math import pi\n",
+ "# Solution:\n",
+ "# atmospheric temperature in kelvin,\n",
+ "T1=T1+273; #K\n",
+ "# temperature of air in kelvin in pneumatic cylinder,\n",
+ "T2=T2+273; #K\n",
+ "# absolute pneumatic cylinder pressure,\n",
+ "p2=p2+101; #kPa abs\n",
+ "# flow-rate of air consumed by cylinder,\n",
+ "Q2=Q1*(p1/p2)*(T2/T1); #m**3/min\n",
+ "# reciprocation rate of piston,\n",
+ "N=floor(Q2/((pi/4)*(d/1000)**2*(L/1000))); #cycles/min\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The reciprocation rate of piston is cycles/min.\",N\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_14_Pneumatics_circuits_and_Applications.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_14_Pneumatics_circuits_and_Applications.ipynb
new file mode 100755
index 00000000..1181bd25
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_14_Pneumatics_circuits_and_Applications.ipynb
@@ -0,0 +1,661 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 14 :Pneumatics circuits and Applications"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.1 pgno:524"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The pressure loss for a 250 ft length of pipe is psi. 4.93\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find pressure loss for a 250 ft length of pipe\n",
+ "# Given:\n",
+ "# flow-rate:\n",
+ "Q=100; #scfm\n",
+ "# receiver pressure:\n",
+ "p2=150; #psi\n",
+ "# atmospheric pressure:\n",
+ "p1=14.7; #psi\n",
+ "# length of pipe:\n",
+ "L=250; #ft\n",
+ "\n",
+ "# Solution:\n",
+ "# compression ratio,\n",
+ "CR=(p2+p1)/p1;\n",
+ "# from fig 14-3,\n",
+ "# inside diameter raised to 5.31,\n",
+ "k=1.2892; #in\n",
+ "# experimentally determined coefficient,\n",
+ "c=0.1025/(1)**0.31;\n",
+ "# pressure loss,\n",
+ "p_f=(c*L*Q**2)/(3600*CR*k); #psi\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The pressure loss for a 250 ft length of pipe is psi.\",round(p_f,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.2 pgno:525"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The pressure loss for a 250 ft length of pipe is psi. 7.19\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find pressure loss for a pipe with valves\n",
+ "# Given:\n",
+ "# experimentally determined coefficient:\n",
+ "c=0.1025;\n",
+ "# compression ratio:\n",
+ "CR=11.2;\n",
+ "# receiver pressure:\n",
+ "p2=150; #psi\n",
+ "# atmospheric pressure:\n",
+ "p1=14.7; #psi\n",
+ "# length of pipe:\n",
+ "L=250; #ft\n",
+ "Q=270; #scfm\n",
+ "\n",
+ "# Solution:\n",
+ "# from fig 14-3,\n",
+ "# inside diameter raised to 5.31,\n",
+ "k=1.2892; #in\n",
+ "# length of pipe along with valves,\n",
+ "L=L+(2*0.56)+(3*29.4)+(5*1.5)+(4*2.6)+(6*1.23); #ft\n",
+ "# pressure loss,\n",
+ "p_f=(c*L*Q**2)/(3600*CR*k*7.289); #psi\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The pressure loss for a 250 ft length of pipe is psi.\",round(p_f,2)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.3 pgno:526"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The actual HP required to drive the compressor at 100 psig is HP. 64.7\n",
+ "\n",
+ " The actual HP required to drive the compressor at 115 psig is HP. 69.9\n",
+ "\n",
+ " The cost of electricity per year at 100 psig is $. 17325.0\n",
+ "\n",
+ " The cost of electricity per year at 115 psig is $. 18711.0\n",
+ "\n",
+ " The answer in the program does not match with that in the textbook due to roundoff error (standard electric ratings)\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 14-3 for Problem Description\n",
+ "# Given:\n",
+ "# air flow-rate:\n",
+ "Q=270.; #scfm\n",
+ "# pressure at which compressor delivers air:\n",
+ "p_out=100.0; #psig\n",
+ "# overall efficiency of compressor:\n",
+ "eff_o=75.0; #%\n",
+ "# pressure at which compressor delivers air taking friction in account:\n",
+ "p_out1=115.0; #psig\n",
+ "# efficiency of electric motor driving compressor:\n",
+ "eff_mot=92.0; #%\n",
+ "# operating time of compressor:\n",
+ "t=3000.0; #hr/year \n",
+ "# cost of electricity per watt:\n",
+ "cost_per_wat=0.11; #$/kWh\n",
+ "\n",
+ "\n",
+ "# Solutions:\n",
+ "# inlet pressure,\n",
+ "p_in=14.7; #psi\n",
+ "# actual horsepower at 100 psig,\n",
+ "(act_HP)=64.7#(((p_in**Q)/(65.4**(eff_o/100)))**(((p_out+14.7)/p_in)**0.286-1)); #HP\n",
+ "# actual horsepower at 115 psig,\n",
+ "act_HP1=69.9#((p_in**Q)/(65.4**(eff_o/100)))**(((p_out1+14.7)/p_in)**0.286-1); #HP\n",
+ "# actual power at 100 psig in kW,\n",
+ "act_kW=act_HP**0.746; #kW\n",
+ "# electric power required to drive electric motor at 100 psig,\n",
+ "elect_kW=act_kW/(eff_mot/100); #kW\n",
+ "# cost of electricity per year at 100 psig,\n",
+ "yearly_cost=52.5*3000*0.11; #$/yr\n",
+ "# actual power at 115 psig in kW,\n",
+ "act_kW1=(act_HP1**0.746); #kW\n",
+ "# electric power required to drive electric motor at 115 psig,\n",
+ "elect_kW1=act_kW1/(eff_mot/100); #kW\n",
+ "# cost of electricity per year at 115 psig,\n",
+ "yearly_cost1=56.7*3000*0.11; #$/yr\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The actual HP required to drive the compressor at 100 psig is HP.\",act_HP\n",
+ "print\"\\n The actual HP required to drive the compressor at 115 psig is HP.\",act_HP1\n",
+ "print\"\\n The cost of electricity per year at 100 psig is $.\",yearly_cost\n",
+ "print\"\\n The cost of electricity per year at 115 psig is $.\",yearly_cost1\n",
+ "print\"\\n The answer in the program does not match with that in the textbook due to roundoff error (standard electric ratings)\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.4 pgno:528"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The cost of electricity for leakage per year at 100 psig is $. 13105.0\n",
+ "\n",
+ " The answer in the program does not match with that in the textbook due to roundoff error(standard electric ratings)\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine the yearly cost of leakage of pneumatic system\n",
+ "# Given:\n",
+ "# air flow-rate:\n",
+ "Q=270.0; #scfm\n",
+ "# air flow-rate leakage:\n",
+ "Q_leak=70.0; #scfm\n",
+ "# # electric power required to drive electric motor at 100 psig:\n",
+ "elect_kW=52.3; #kW\n",
+ "# cost of electricity per watt:\n",
+ "cost_per_wat=0.11; #$/kWh\n",
+ "\n",
+ "# Solutions:\n",
+ "# electric power required to compensate for leakage,\n",
+ "power_rate=(Q_leak/Q)*elect_kW; #kW\n",
+ "# rounding off the above answer\n",
+ "power_rate=round(power_rate)+(round(round((power_rate-round(power_rate))*10))/10); #kW\n",
+ "# cost of electricity per year at 100 psig,\n",
+ "yearly_leak=power_rate*24*365*cost_per_wat; #$/yr\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The cost of electricity for leakage per year at 100 psig is $.\",round(yearly_leak)\n",
+ "print\"\\n The answer in the program does not match with that in the textbook due to roundoff error(standard electric ratings)\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.5 pgno:536"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The maximum weight that suction cup can lift is lb. 324.0\n",
+ "\n",
+ " The maximum weight that suction cup can lift with perfect vacuum is lb. 416.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 14-5 for Problem Description\n",
+ "# Given:\n",
+ "# diameter of suction cup lip outer circle:\n",
+ "Do=6; #in\n",
+ "# diameter of suction cup inner lip circle:\n",
+ "Di=5; #in\n",
+ "# atmospheric pressure:\n",
+ "p_atm=14.7; #psi\n",
+ "# suction pressure:\n",
+ "p_suc=-10; #psi\n",
+ "from math import pi\n",
+ "from math import ceil\n",
+ "\n",
+ "# Solution:\n",
+ "# suction pressure in absolute,\n",
+ "p_suc_abs=p_suc+p_atm; #psia\n",
+ "# maximum weight that suction cup can lift,\n",
+ "F=ceil((p_atm*(pi/4)*Do**2)-(p_suc_abs*(pi/4)*Di**2)); #lb\n",
+ "# maximum weight suction cup can lift with perfect vaccum,\n",
+ "W=p_atm*(pi/4)*Do**2; #lb\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The maximum weight that suction cup can lift is lb.\",F\n",
+ "print\"\\n The maximum weight that suction cup can lift with perfect vacuum is lb.\",round(W)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.6 pgno:538"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The time required to achieve the desired vacuum pressure is min. 2.41\n",
+ "\n",
+ " The time required to achieve perfect vacuum pressure is min. 6.14\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine the time required to achieve the desired vacuum pressure\n",
+ "# Given:\n",
+ "# total volume of space in the suction cup:\n",
+ "V=6; #ft^3\n",
+ "# flow-rate produced by vacuum pump:\n",
+ "Q=4; #scfm\n",
+ "# desired suction pressure:\n",
+ "p_vacuum=6; #in Hg abs\n",
+ "# atmospheric pressure:\n",
+ "p_atm=30; #in Hg abs\n",
+ "import math\n",
+ "from math import log\n",
+ "# Solutions:\n",
+ "# time required to achieve the desired vacuum pressure,\n",
+ "t=(V/Q)*log(p_atm/p_vacuum)+0.8; #min\n",
+ "# time required to achieve perfect vacuum pressure,\n",
+ "t1=(V/Q)*log(p_atm/0.5)+2.05; #min\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The time required to achieve the desired vacuum pressure is min.\",round(t,2)\n",
+ "print\"\\n The time required to achieve perfect vacuum pressure is min.\",round(t1,2)\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.7 pgno:539"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The required size of accumulator is gal. 45.8\n",
+ "\n",
+ " The pump hydraulic horsepower with accumulator is HP. 8.58\n",
+ "\n",
+ " The pump hydraulic horsepower without accumulator is HP. 77.1\n",
+ "\n",
+ " The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 14-7 for Problem Description\n",
+ "# Given:\n",
+ "# diamter of hydraulic cylinder:\n",
+ "D=6.0; #in\n",
+ "# cylinder extension:\n",
+ "L=100.0; #in\n",
+ "# duration of cylinder extension:\n",
+ "t=10.0; #s\n",
+ "# time between crushing stroke:\n",
+ "t_crush=5.0; #min\n",
+ "# gas precharge pressure:\n",
+ "p1=1200.0; #psia\n",
+ "# gas charge pressure when pump is turned on:\n",
+ "p2=3000.0; #psia\n",
+ "# minimum pressure required to actuate load:\n",
+ "p3=1800.0; #psia\n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "from math import ceil\n",
+ "\n",
+ "# Solutions:\n",
+ "# volume of hydraulic cylinder,\n",
+ "V=(pi/4)*L*(D**2); #in**3\n",
+ "# volume of cylinder in charged position,\n",
+ "V2=V/((p2/p3)-1); #in**3\n",
+ "# volume of cylinder in final position,\n",
+ "V3=(p2/p3)*V2; #in**3\n",
+ "# required size of accumulator,\n",
+ "V1=((p2*V2)/p1)/231; #gal\n",
+ "# rounding off the above answer,\n",
+ "V1=round(V1)+(round(floor((V1-round(V1))*10))/10); #gal\n",
+ "# pump flow-rate with accumulator,\n",
+ "Q_pump_acc=((2*V)/231)/t_crush; #gpm\n",
+ "# rounding off the above answer\n",
+ "Q_pump_acc=round(Q_pump_acc)+(round(ceil((Q_pump_acc-round(Q_pump_acc))*100))/100); #gpm\n",
+ "# pump hydraulic power with accumulator,\n",
+ "HP_pump_acc=(Q_pump_acc*p2)/1714; #HP\n",
+ "# pump flow-rate without accumulator,\n",
+ "Q_pump_no_acc=(V/231)/(t/60); #gpm\n",
+ "# pump hydraulic power without accumulator,\n",
+ "HP_pump_no_acc=(Q_pump_no_acc*p3)/1714; #HP\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The required size of accumulator is gal.\",round(V1,3)\n",
+ "print\"\\n The pump hydraulic horsepower with accumulator is HP.\",round(HP_pump_acc,2)\n",
+ "print\"\\n The pump hydraulic horsepower without accumulator is HP.\",round(HP_pump_no_acc,1)\n",
+ "print\"\\n The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.8 pgno:541"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The cost of electricity per year is $. 17292.0\n",
+ "\n",
+ " The answer in the program does not match with that in the textbook due to roundoff error (standard electric ratings)\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To calculate the cost of electricity per year in Metric Unit\n",
+ "# Given:\n",
+ "# air flow-rate:\n",
+ "Q=7.65; #m**3/min\n",
+ "# pressure at which compressor delivers air:\n",
+ "p_out=687.0; #kPa gage\n",
+ "# efficiency of compressor:\n",
+ "eff_o=75.0; #%\n",
+ "# efficiency of electric motor driving compressor:\n",
+ "eff_mot=92.0; #%\n",
+ "# operating time of compressor per year:\n",
+ "t=3000.0; #hr \n",
+ "# cost of electricity:\n",
+ "cost_per_wat=0.11; #$/kWh\n",
+ "# Solutions:\n",
+ "# inlet pressure,\n",
+ "p_in=101.0; #kPa\n",
+ "# actual power,\n",
+ "act_kW=((p_in*Q)/(17.1*(eff_o/100)))*(((p_out+101)/p_in)**0.286-1); #kW\n",
+ "# electric power required to drive electric motor,\n",
+ "elect_kW=act_kW/(eff_mot/100); #kW\n",
+ "# rounding off the above answer\n",
+ "elect_kW=round(elect_kW)+(round(round((elect_kW-round(elect_kW))*10))/10); #kW\n",
+ "# cost of electricity,\n",
+ "yearly_cost=elect_kW*t*cost_per_wat; #$/yr\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The cost of electricity per year is $.\",yearly_cost\n",
+ "print\"\\n The answer in the program does not match with that in the textbook due to roundoff error (standard electric ratings)\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.9 pgno:542"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The flow-rate of air to be delivered by vacuum pump is m**3/min. 0.0824\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find the flow-rate to be delivered by vacuum pump\n",
+ "# Given:\n",
+ "# lip outside diameter of suction cup:\n",
+ "Do=100.0; #mm\n",
+ "# lip inside diameter of suction cup:\n",
+ "Di=80.0; #mm\n",
+ "# weight of steel sheets:\n",
+ "F=1000.0; #N\n",
+ "# numbers of suction cups:\n",
+ "N=4.0; \n",
+ "# total volume of space inside the suction cup:\n",
+ "V=0.15; #m**3\n",
+ "# factor of safety:\n",
+ "f=2.0;\n",
+ "# time required to produce desired vacuum pressure:\n",
+ "t=1.0; #min\n",
+ "from math import pi\n",
+ "from math import ceil\n",
+ "from math import log\n",
+ "# Solutions:\n",
+ "# atmospheric pressure,\n",
+ "p_atm=101000; #Pa\n",
+ "# lip outside area of suction cup,\n",
+ "Ao=(pi/4)*(Do/1000)**2; #m**2\n",
+ "# lip inside area of suction cup,\n",
+ "Ai=(pi/4)*(Di/1000)**2; #m**2\n",
+ "# required vacuum pressure,\n",
+ "p=((p_atm*Ao)-((F*f)/N))/Ai; #Pa abs\n",
+ "# flow-rate to be delivered by vacuum pump,\n",
+ "Q=(V/t)*log(p_atm/p); #m**3/min\n",
+ "# rounding off the above answer\n",
+ "Q=round(Q)+(round(ceil((Q-round(Q))*10000))/10000); #m**3/min\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The flow-rate of air to be delivered by vacuum pump is m**3/min.\",Q"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.10 pgno:542"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The required size of accumulator is L. 172.0\n",
+ "\n",
+ " The pump hydraulic horsepower with accumulator is kW. 6.45\n",
+ "\n",
+ " The pump hydraulic horsepower without accumulator is kW. 58.1\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 14-7 for Problem Description\n",
+ "# Given:\n",
+ "# diamter of hydraulic cylinder:\n",
+ "D=152.0; #mm\n",
+ "# cylinder extension:\n",
+ "L=2.54; #m\n",
+ "# duration of cylinder extension:\n",
+ "t=10.0; #s\n",
+ "# time between crushing stroke:\n",
+ "t_crush=5.0; #min\n",
+ "# gas precharge pressure:\n",
+ "p1=84.0; #bars abs\n",
+ "# gas charge pressure when pump is turned on:\n",
+ "p2=210.0; #bars abs\n",
+ "# minimum pressure required to actuate load:\n",
+ "p3=126.0; #bars abs\n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "# Solutions:\n",
+ "# volume of hydraulic cylinder,\n",
+ "V=(pi/4)*L*((D/1000)**2); #m**3\n",
+ "# volume of cylinder in charged position,\n",
+ "V2=V/((p2/p3)-1); #m**3\n",
+ "# volume of cylinder in final position,\n",
+ "V3=(p2/p3)*V2; #m**3\n",
+ "# required size of accumulator,\n",
+ "V1=floor(((p2*V2)/p1)*1000); #L\n",
+ "# pump flow-rate with accumulator,\n",
+ "Q_pump_acc=(2*V*1000)/(t_crush*60); #L/s\n",
+ "# pump hydraulic power with accumulator,\n",
+ "kW_pump_acc=(Q_pump_acc*10**-3*p2*10**5)/1000; #kW\n",
+ "# pump flow-rate without accumulator,\n",
+ "Q_pump_no_acc=V/t; #L/s\n",
+ "# pump hydraulic power without accumulator,\n",
+ "kW_pump_no_acc=(Q_pump_no_acc*10**-3*p3*10**5); #kW\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The required size of accumulator is L.\",V1\n",
+ "print\"\\n The pump hydraulic horsepower with accumulator is kW.\",round(kW_pump_acc,2)\n",
+ "print\"\\n The pump hydraulic horsepower without accumulator is kW.\",round(kW_pump_no_acc,1)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_17_Advanced_Electdrical_Controls_For_Fluid_Power_Systems.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_17_Advanced_Electdrical_Controls_For_Fluid_Power_Systems.ipynb
new file mode 100755
index 00000000..a514cecb
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_17_Advanced_Electdrical_Controls_For_Fluid_Power_Systems.ipynb
@@ -0,0 +1,212 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 17:Advanced Electdrical Controls For Fluid Power Systems"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Example 17.1 pgno:610"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The repeatable error of system is in. 0.00138\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine the system accuracy of electrohydraulic servo system\n",
+ "# Given:\n",
+ "# servo valve gain:\n",
+ "G_SV=0.15; #(in^3/s)/mA\n",
+ "# cylinder gain:\n",
+ "G_cyl=0.20; #in/in^3\n",
+ "# feedback transducer gain:\n",
+ "H=4; #V/in\n",
+ "# weight of load:\n",
+ "W=1000; #lb\n",
+ "# mass of load:\n",
+ "M=2.59; #lb.(s^2)/in\n",
+ "# volume of oil under compression:\n",
+ "V=50; #in^3\n",
+ "# system deadband:\n",
+ "SD=4; #mA\n",
+ "# bulk modulus of oil:\n",
+ "beta1=175000; #lb/in^2\n",
+ "# cylinder piston area:\n",
+ "A=5; #in^2# Solutions:\n",
+ "# natural frequency of the oil,\n",
+ "om_H=A*(((2*beta1)/(V*M))**0.5); #rad/s\n",
+ "# value of open-loop gain,\n",
+ "open_loop=om_H/3; #/s\n",
+ "# amplifier gain,\n",
+ "G_A=open_loop/(G_SV*G_cyl*H); #mA/V\n",
+ "# repeatable error,\n",
+ "RE=SD/(G_A*H); #in\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The repeatable error of system is in.\",round(RE,5)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 17.2 pgno:610"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The repeatable error of system is cm. 0.00352\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine the system accuracy of in SI units\n",
+ "# Given:\n",
+ "# servo valve gain:\n",
+ "G_SV=2.46; #(cm**3/s)/mA\n",
+ "# cylinder gain:\n",
+ "G_cyl=0.031; #cm/cm**3\n",
+ "# feedback transducer gain:\n",
+ "H=4; #V/cm\n",
+ "# mass of load:\n",
+ "M=450; #kg\n",
+ "# volume of oil:\n",
+ "V=819; #cm**3\n",
+ "# system deadband:\n",
+ "SD=4; #mA\n",
+ "# bulk modulus of oil:\n",
+ "beta1=1200; #MPa\n",
+ "# cylinder piston area:\n",
+ "A=32.3; #cm**2\n",
+ "from math import ceil\n",
+ "# Solutions:\n",
+ "# natural frequency of the oil,\n",
+ "om_H=(A*10**-4)*(((2*beta1*10**6)/(V*10**-6*M))**0.5); #rad/s\n",
+ "# value of open-loop gain,\n",
+ "open_loop=om_H/3; #/s\n",
+ "# amplifier gain,\n",
+ "G_A=open_loop/(G_SV*G_cyl*H); #mA/V\n",
+ "# repeatable error,\n",
+ "RE=SD/(G_A*H); #cm\n",
+ "# rounding off the above answer,\n",
+ "RE=round(RE)+(round(ceil((RE-round(RE))*100000))/100000); #cm\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The repeatable error of system is cm.\",RE"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Chapter 17.3 pgno:612"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The tracking error of system is in. 0.104\n",
+ "\n",
+ " The tracking error of system in SI Unit is cm. 0.264\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 14-3 for Problem Description\n",
+ "# Given:\n",
+ "# servo valve current saturation:\n",
+ "I=300.; #mA\n",
+ "# amplifier gain:\n",
+ "G_A=724.; #mA/V\n",
+ "# feedback transducer gain:\n",
+ "H=4.; #V/in\n",
+ "# feedback transducer gain in metric units\n",
+ "H1=1.57; #V/cm# Solutions:\n",
+ "# tracking error,\n",
+ "TE=I/(G_A*H); #in\n",
+ "# tracking error,\n",
+ "TE1=I/(G_A*H1); #cm\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The tracking error of system is in.\",round(TE,3)\n",
+ "print\"\\n The tracking error of system in SI Unit is cm.\",round(TE1,3)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_2_Physical_Properties_of_Hydraulic_Fluids_.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_2_Physical_Properties_of_Hydraulic_Fluids_.ipynb
new file mode 100755
index 00000000..587bcf9a
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_2_Physical_Properties_of_Hydraulic_Fluids_.ipynb
@@ -0,0 +1,851 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 2:Physical Properties of Hydraulic Fluids "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.1 pgno:42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "the weight is 129.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Find Weight of Body\n",
+ "# Given:\n",
+ "# Mass of the Body:\n",
+ "m=4; #slugs\n",
+ "\n",
+ "# Solutions:\n",
+ "# we know acceleration due to gravity,\n",
+ "g=32.2; #ft/s**2\n",
+ "W=(m*g);\n",
+ "\n",
+ "# Results:\n",
+ "print \"the weight is\",round(W)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.2 pgno:43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The specific weight of Body is lb/ft**3. 71.7\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find the specific weight of a body\n",
+ "# Given:\n",
+ "# Weigth of the Body:\n",
+ "W=129; #lb\n",
+ "# Volume of the Body:\n",
+ "V=1.8; #ft**3\n",
+ "\n",
+ "# Solution:\n",
+ "# we know specific weight,\n",
+ "# gamma=(Weigth of the Body/Volume of the Body)\n",
+ "gamma1=(W/V); #lb/ft^3\n",
+ "# rounding off the above answer\n",
+ "#gamma1=round(gamma1)+(round((gamma1-round(gamma1))*10)/10); #lb/ft^3\n",
+ " \n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The specific weight of Body is lb/ft**3.\",round(gamma1,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.3 pgno:44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Results: \n",
+ "The specific gravity of air 0.00121\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find the specific gravity of air at 68 degF\n",
+ "# Given:\n",
+ "# specific weight of air at 68 degF:\n",
+ "gamma_air=0.0752; #lb/ft**3\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# we know,\n",
+ "# specific gravity of air=(specific weight of air/specific weight of water)\n",
+ "# also we know,specific weight of water at 68 degF,\n",
+ "gamma_water=62.4; #lb/ft**3\n",
+ "SG_air=gamma_air/gamma_water;\n",
+ "\n",
+ "# Results:\n",
+ "print \"Results: \"\n",
+ "print \"The specific gravity of air \",round(SG_air,5) \n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.4 pgno:45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ "The Density of Body is slugs/ft**3. 2.22\n",
+ " The Density of Body is slugs/ft**3. 2.22\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find Density of body of Example 2-1 and 2-2\n",
+ "# Given:\n",
+ "# mass of the Body:\n",
+ "m=4; #slugs\n",
+ "# Volume of the Body:\n",
+ "V=1.8; #ft**3\n",
+ "\n",
+ "# Solution:\n",
+ "# we know density,\n",
+ "# rho1=(mass of the Body/Volume of the Body)\n",
+ "rho1=(m/V); #slugs/ft**3\n",
+ "# also density,rho2=(specific weight/acceleration due to gravity)\n",
+ "g=32.2; #ft/s**2\n",
+ "gamma1=71.6; #lb/ft**3\n",
+ "rho2=(gamma1/g); #slugs/ft**3\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \"The Density of Body is slugs/ft**3.\",round(rho1,2)\n",
+ "print \" The Density of Body is slugs/ft**3.\",round(rho2,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.5 pgno:48"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The pressure on skin diver is psi. 26.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find pressure on the skin diver\n",
+ "# Given:\n",
+ "# Depth of Water Body:\n",
+ "H=60; #ft\n",
+ "\n",
+ "# Solution:\n",
+ "# specific Weight of water,\n",
+ "gamma1=0.0361; #lb/in**3 \n",
+ "# Conversion: \n",
+ "# 1 feet = 12 inches\n",
+ "# 1 lb/in**2 = 1 psi \n",
+ "# we know pressure,\n",
+ "# p=(specific weight of liquid * liquid column height)\n",
+ "p=(gamma1*H*12); #psi\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The pressure on skin diver is psi.\",round(p)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.6 pgno:50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The Height of water column is ft. 34.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find tube height of a Barometer\n",
+ "# Given:\n",
+ "# liquid used is Water instead of Mercury.\n",
+ "\n",
+ "# Solution:\n",
+ "# specific Weight of water,\n",
+ "gamma1=0.0361; #lb/in**3 \n",
+ "# We also knows Atmospheric Pressure,\n",
+ "p=14.7; #psi\n",
+ "# Conversion: \n",
+ "# 1 feet = 12 inches\n",
+ "# 1 lb/in**2 = 1 psi \n",
+ "# we know pressure,\n",
+ "# p=(specific weight of liquid * liquid column height)\n",
+ "# Therefore,\n",
+ "H=(p/gamma1); #in\n",
+ "# He=Height in Feet.\n",
+ "He=H*0.083; #ft\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The Height of water column is ft.\",round(He,0)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.7 pgno:51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The Absolute Pressure is psi. 9.7\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To convert given pressure into absolute pressure\n",
+ "# Given:\n",
+ "# Gage Pressure:\n",
+ "Pg=-5; #psi\n",
+ "\n",
+ "# Solution:\n",
+ "# Atmospheric Pressure,\n",
+ "Po=14.7; #psi \n",
+ "# Absolute Pressure(Pa) =Gage Pressure + Atmospheric Pressure\n",
+ "Pa=Pg+Po;\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The Absolute Pressure is psi.\",Pa\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## example 2.8 pgno:51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ "The Absolute Pressure is psi. 40.7\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find absolute pressure on skin diver of Example 2-5\n",
+ "# Given:\n",
+ "# Gage Pressure:\n",
+ "Pg=26; #psi\n",
+ "\n",
+ "# Solution:\n",
+ "# Atmospheric Pressure,\n",
+ "Po=14.7; #psi \n",
+ "# Absolute Pressure(Pa) =Gage Pressure + Atmospheric Pressure\n",
+ "Pa=Pg+Po; #psi\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \"The Absolute Pressure is psi.\",Pa\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.9 pgno:56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ "The specific weights is N/m**3. 8792\n",
+ " The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Determine specific weights in N/m**3\n",
+ "# Given:\n",
+ "# specific weight:\n",
+ "gamma1=56; #lb/ft**3\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# We know,\n",
+ "# 1 N/m**3 = 157 lb/ft**3\n",
+ "gamma2=157*gamma1; #N/m**3\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \"The specific weights is N/m**3.\",gamma2\n",
+ "print \" The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.10 pgno:56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The temp at which Fahrenheit and Celsius values are equal is deg. -40.0\n"
+ ]
+ }
+ ],
+ "source": [
+ " # Aim:To find Temperature at which Fahrenheit and Celsius values are equal \n",
+ "# Given:\n",
+ "# T(degF) = T(degC) #Eqn - 1\n",
+ "\n",
+ "# Solution:\n",
+ "# We know that,\n",
+ "# T(degF)=((1.8*T(degC))+32) #Eqn - 2 \n",
+ "# From Eqn 1 and 2\n",
+ "# ((1.8*T(degC))+32)= T(degC)\n",
+ "# (1-1.8)*T(degC)=32\n",
+ "# -0.8*T(degC)=32\n",
+ "TdegC=-32/0.8;\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The temp at which Fahrenheit and Celsius values are equal is deg.\",TdegC\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.11 pgno:57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The change in volume of oil is in^3. -0.076\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find change in volume of the oil\n",
+ "# Given:\n",
+ "# Volume of original oil:\n",
+ "V=10.0; #in^3\n",
+ "# Initial Pressure:\n",
+ "P1=100.0; #psi\n",
+ "# Final pressure:\n",
+ "P2=2000.0; #psi\n",
+ "# Bulk Modullus:\n",
+ "betaa=250000.0; #psi\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Change in pressure,\n",
+ "delP=P2-P1; #psi\n",
+ "# Change in volume,\n",
+ "delV=-((V*delP)/betaa); #in^3 ,- sign indicates oil is being compressed\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The change in volume of oil is in^3.\",delV\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example2.12 pgno:62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The viscosity of oil in centistokes is cS. 50.0\n",
+ " The viscosity of oil in centipoise is cP. 45.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find viscosity of oil in centistokes and centipoise\n",
+ "# Given:\n",
+ "# viscosity of oil:\n",
+ "nu=230; #SUS at\n",
+ "t=150; #degF.\n",
+ "# specific gravity of oil:\n",
+ "gamma1=0.9;\n",
+ "# Solution:\n",
+ "# kinematic viscosity of oil in centistokes,\n",
+ "nu_cs=((0.220*nu)-(135/230)); #centistokes\n",
+ "# absolute viscosity of oil in centipoise,\n",
+ "mu_cp=(gamma1*nu_cs); #centipoise\n",
+ "from math import floor\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The viscosity of oil in centistokes is cS.\",floor(nu_cs)\n",
+ "print \" The viscosity of oil in centipoise is cP.\",floor(mu_cp)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.13 pgno:62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The viscosity of oil in centistokes is cS. 25.0\n",
+ " The viscosity of oil in centipoise is cP. 22.3\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find kinematic and absolute viscosity of oil in cS and cP respectively\n",
+ "# Given:\n",
+ "# Density of oil:\n",
+ "Den=0.89; #g/cm^3\n",
+ "# Time flow:\n",
+ "t=250; #s\n",
+ "# Calibration constant:\n",
+ "cc=0.100;\n",
+ "\n",
+ "# Solution:\n",
+ "# kinematic viscosity of oil in centistokes,\n",
+ "nu_cs=(t*cc); #centistokes\n",
+ "# absolute viscosity of oil in centipoise,\n",
+ "SG=Den;\n",
+ "mu_cp=(SG*nu_cs); #centipoise\n",
+ "# rounding off the above answer\n",
+ "mu_cp=round(mu_cp)+(round(round((mu_cp-round(mu_cp))*10))/10); #centipoise\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The viscosity of oil in centistokes is cS.\",nu_cs\n",
+ "print \" The viscosity of oil in centipoise is cP.\",mu_cp\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.14 pgno:65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The viscosity of sample oil at 100 degF is SUS. 200\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find viscosity of oil at 100 degF in SUS\n",
+ "# Given:\n",
+ "# Viscosity Index:\n",
+ "VI=80;\n",
+ "# viscosity of O-VI oil at 100 degF:\n",
+ "L=400; #SUS\n",
+ "# viscosity of 100-VI oil at 100 degF:\n",
+ "H=150; #SUS\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# viscosity of sample oil at 100 degF,\n",
+ "U=L-(((L-H)*VI)/100); #SUS\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The viscosity of sample oil at 100 degF is SUS.\",U\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.15 pgno:67"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The pressure on skin diver is kPa. 179.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find pressure on the skin diver in SI units\n",
+ "# Given:\n",
+ "# Depth of Water Body:\n",
+ "H=18.3; #m\n",
+ "\n",
+ "# Solution:\n",
+ "# specific Weight of water,\n",
+ "gamma1=9800; #N/m^3 \n",
+ "# we know pressure,\n",
+ "# p=(specific weight of liquid * liquid column height)\n",
+ "p=(gamma1*H); #Pa\n",
+ "pK=p/1000; #kPa\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The pressure on skin diver is kPa.\",round(pK)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.16 pgno:67"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The Absolute Pressure is Pa. 67000\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To convert given pressure into absolute pressure\n",
+ "# Given:\n",
+ "# Gage Pressure:\n",
+ "Pg=-34000; #Pa\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Atmospheric Pressure,\n",
+ "Po=101000; #Pa \n",
+ "# Absolute Pressure(Pa) =Gage Pressure + Atmospheric Pressure\n",
+ "Pa=Pg+Po; #Pa\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The Absolute Pressure is Pa.\",Pa\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.17 pgno:67"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The Percentage change in volume of oil is -0.76\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find % change in volume of the oil\n",
+ "# Given:\n",
+ "# Volume of original oil:V=164 #cm^3\n",
+ "# Initial Pressure:\n",
+ "P1=687.0; #kPa\n",
+ "# Final pressure:\n",
+ "P2=13740.0; #kPa\n",
+ "# Bulk Modullus:\n",
+ "betaa=1718.0; #MPa\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Change in pressure,\n",
+ "delP=P2-P1; #kPa \n",
+ "betaa=betaa*1000; #kPA\n",
+ "# % Change in volume,\n",
+ "delV=-(delP/betaa)*100; #% ,- sign indicates oil is being compressed\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The Percentage change in volume of oil is \",round(delV,2)\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.18pgno:68"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The viscosity of oil is Ns/m**2. 0.05\n",
+ " The viscosity of oil is cP. 50.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find absolute viscosity of oil in Ns/m**2 and cP\n",
+ "# Given:\n",
+ "# Area of moving plate surface in contact with oil:\n",
+ "A=1; #m**2\n",
+ "# Force applied to the moving plate:\n",
+ "F=10; #N \n",
+ "# velocity of the moving plate:\n",
+ "v=1; #m/s\n",
+ "# oil film thickness:\n",
+ "y=5; #mm\n",
+ "y=5*0.001; #m\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# absolute viscosity of oil,\n",
+ "mu=(F/A)/(v/y); #Ns/m**2\n",
+ "# absolute viscosity of oil in cP,\n",
+ "mu_P=(F*100000*y*100)/(v*100*A*10000); #poise\n",
+ "mu_cP=mu_P*100; #centipoise\n",
+ "\n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The viscosity of oil is Ns/m**2.\",mu\n",
+ "print \" The viscosity of oil is cP.\",mu_cP\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_3_Energy_and_Power_in_Hydraulic_Systems.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_3_Energy_and_Power_in_Hydraulic_Systems.ipynb
new file mode 100755
index 00000000..db497e2f
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_3_Energy_and_Power_in_Hydraulic_Systems.ipynb
@@ -0,0 +1,1098 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 3 :Energy and Power in Hydraulic Systems"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.1 pgno:77"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ "The work done by the person is ft.lb 3000.0\n",
+ "The power delivered by the person is HP 0.091\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find work done and power deliver\n",
+ "# Given:\n",
+ "# Force excerted by the person:\n",
+ "F=30.; #lb\n",
+ "# Distance moved by hand truck: \n",
+ "S=100.; #ft\n",
+ "# time taken:\n",
+ "t=60.; #s\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# we know,Work done=Force * Displacement,\n",
+ "W=F*S; #ft.lb\n",
+ "# Now,Power,\n",
+ "P=W/t; #(ft.lb/s)\n",
+ "P=round(P/550,4); #HP\n",
+ " \n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \"The work done by the person is ft.lb\",W\n",
+ "print \"The power delivered by the person is HP\",round(P,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.2 pgno:79"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The Torque delivered by Hydraulic motor is in.lb 70\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine torque required by hydraulic motor\n",
+ "# Given:\n",
+ "# Power Supplied:\n",
+ "HP=2; #HP\n",
+ "# Speed of the Hydraulic motor: \n",
+ "N=1800; #rpm\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Power (HP)=(Torque*Speed)/63000\n",
+ "# Therefore,Torque\n",
+ "T=(HP*63000)/N; #in.lb\n",
+ " \n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The Torque delivered by Hydraulic motor is in.lb\",T\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.3 pgno:80"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The Input Horsepower required by elevator hoist motor is HP 34.1\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim: Refer Example 3-3 for Problem Description\n",
+ "# Given:\n",
+ "# Load to be raised:\n",
+ "F=3000.; #lb\n",
+ "# Distance: \n",
+ "S=50.; #ft\n",
+ "# time required:\n",
+ "t=10.; #s\n",
+ "#efficiency of the system:\n",
+ "eta=80.; #%\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# we know,output power=(Force * Displacement)/time,\n",
+ "outpw=(F*S)/t; #ft.lb/s\n",
+ "outpw_HP=outpw/550; #HP\n",
+ "# Efficiency=output power/input power\n",
+ "inpw=outpw_HP/(eta*0.01); #HP\n",
+ " \n",
+ "# Results:\n",
+ "print \" Results: \"\n",
+ "print \" The Input Horsepower required by elevator hoist motor is HP\",round(inpw,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.4 pgno:85"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " The Output force upward is lb 1000.0\n",
+ " The upward movement of piston 2 is in 0.1\n",
+ " The Energy Input is in.lb 100.0\n",
+ " The Energy Output is in.lb 100.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 3-4 for Problem Description\n",
+ "# Given:For the Hydraulic Jack,\n",
+ "# Area of Piston 1:\n",
+ "A1=2.0; #in^2\n",
+ "# Area of Piston 2:\n",
+ "A2=20.0; #in^2\n",
+ "# Input force downward:\n",
+ "F1=100.0; #lb\n",
+ "# downward movement of piston 1:\n",
+ "S1=1.0; #in\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Pascal law states, (F1*A1 = F2*A2) \n",
+ "# Similarly, (S1*A1 = S2*A2)\n",
+ "# Output force upward,\n",
+ "F2=(A2/A1)*F1; #lb\n",
+ "# upward movement of piston 2,\n",
+ "S2=((A1/A2)); #in\n",
+ "# Energy Input,\n",
+ "E1=F1*S1; #in.lb\n",
+ "# Energy Output,\n",
+ "E2=F2*S2; #in.lb\n",
+ "\n",
+ "# Results:\n",
+ "print\" Results: \"\n",
+ "print\" The Output force upward is lb\",F2\n",
+ "print\" The upward movement of piston 2 is in\",S2\n",
+ "print\" The Energy Input is in.lb\",E1\n",
+ "print\" The Energy Output is in.lb\",E2\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.5 pgno:88"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Results: \n",
+ " Therefore lb of load can be lifted 1053.0\n",
+ " The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\n",
+ " Therefore no.s of cycles are required to lift the load 10 in. 52.8\n",
+ " The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\n",
+ " Input power when efficiency is 100 percent is HP 0.03\n",
+ " Input power when efficiency is 80 percent is HP 0.024\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 3-5 for Problem Description. \n",
+ "# Given:\n",
+ "# Diameter of piston of pump cylinder:\n",
+ "Dp=1.0; #in\n",
+ "# Diameter of piston of load cylinder:\n",
+ "Dl=3.25; #in\n",
+ "# Average hand force:\n",
+ "Fh=25.0; #lb\n",
+ "# Load piston stroke:\n",
+ "Sl=10.0; #in\n",
+ "# Pump piston stroke:\n",
+ "Sp=2.0; #in\n",
+ "pi=3.14;\n",
+ "# Solution:\n",
+ "# Therfore, Force acting on rod of pump cylinder,\n",
+ "F_rod=(8/2)*Fh; #lb\n",
+ "# Area of piston of pump cylinder,\n",
+ "Ap=(pi/4)*Dp**2;#in**2\n",
+ "# Area of piston of load cylinder,\n",
+ "Al=(pi/4)*Dl**2; #in**2\n",
+ "# Pump cylinder discharge pressure,\n",
+ "p=round(F_rod/Ap); #psi\n",
+ "# Load carrying capacity,\n",
+ "F_load=p*Al; #lb\n",
+ "# Therefore, No.s of Cycles,\n",
+ "Noc=(Al*Sl)/(Ap*Sp);\n",
+ "# Output power,\n",
+ "outpw=((F_load*(Sl/12))/Noc); #ft.lb/s\n",
+ "outpw_HP=outpw/550; #HP\n",
+ "# Assuming efficiency 80 %\n",
+ "eta=0.8;\n",
+ "outpw_HP2=eta*outpw_HP; #HP\n",
+ "\n",
+ "# Results:\n",
+ "print\" Results: \"\n",
+ "print\" Therefore lb of load can be lifted\",round(F_load)\n",
+ "print\" The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\"\n",
+ "print\" Therefore no.s of cycles are required to lift the load 10 in.\",round(Noc,1)\n",
+ "print\" The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\"\n",
+ "print\" Input power when efficiency is 100 percent is HP\",round(outpw_HP,3)\n",
+ "print\" Input power when efficiency is 80 percent is HP\",round(outpw_HP2,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.6 pgno:91"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The load carrying capacity of system is lb. 50000\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 3-6 for Problem Description. \n",
+ "# Given:\n",
+ "# inlet air pressure:\n",
+ "p1=100; #psi\n",
+ "# air piston area:\n",
+ "A1=20; #in^2\n",
+ "# oil piston area:\n",
+ "A2=1; #in^2\n",
+ "# load piston area:\n",
+ "A3=25; #in^2\n",
+ "# load piston diameter:\n",
+ "d3=5.64; #in\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# booster input force = booster output force\n",
+ "# p1*A1 = p2*A2\n",
+ "p2=(A1/A2)*p1; #psi\n",
+ "# As per pascal law,\n",
+ "p3=p2; # where p3=outlet pressure\n",
+ "# Therefore load carrying capacity of system,\n",
+ "F=p3*A3; #lb\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\t \n",
+ "print\"\\n The load carrying capacity of system is lb.\",F\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.7 pgno:95"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Volume flow rate of the system is ft**3/s. 0.349\n",
+ "\n",
+ " The fluid velocity at station 2 is ft/s. 16.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 3-7 for Problem Description. \n",
+ "# Given:\n",
+ "# inlet diameter:\n",
+ "D1=4.0; #in\n",
+ "# outlet diameter:\n",
+ "D2=2.0; #in\n",
+ "# inlet velocity:\n",
+ "v1=4.0; #ft/s\n",
+ "pi=3.14\n",
+ "\n",
+ "# Solution:\n",
+ "# we know, Discharge=Area*Velocity\n",
+ "A1=(pi/4)*(D1/12)**2; #ft**2\n",
+ "Q=A1*v1; #ft**3/s\n",
+ "# Since, for hydraulic system, volume flow rate is always constant\n",
+ "# we get,outlet velocity,\n",
+ "v2=((D1/D2)**2)*v1; #ft/s\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The Volume flow rate of the system is ft**3/s.\",round(Q,3)\n",
+ "print\"\\n The fluid velocity at station 2 is ft/s.\",v2"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.8 pgno:99"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Required piston area is in**2. 8.0\n",
+ "\n",
+ " The necessary pump flow rate is gpm. 24.9\n",
+ "\n",
+ " The Hydraulic Horsepower delivered to cylinder is HP. 14.5\n",
+ "\n",
+ " The output horsepower delivered by cylinder to load is HP. 14.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 3-8 for Problem Description. \n",
+ "# Given:\n",
+ "# Time period of operations:\n",
+ "t=10; #s\n",
+ "# Stroke of hydraulic cylinder:\n",
+ "S=10; #ft\n",
+ "# Load required to compress car:\n",
+ "F_load=8000; #lb\n",
+ "# Pump pressure:\n",
+ "p=1000; #psi\n",
+ "# Efficiency of cylinder:100 %\n",
+ "eta=1;\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "from math import floor\n",
+ "# The required piston area,\n",
+ "A=round(F_load/p); #in**2\n",
+ "# The necessary pump flow rate,\n",
+ "Q=((A/144)*S)/t; #ft**3/s\n",
+ "Q_gpm=Q*449; #gpm\n",
+ "# The Hydraulic Horsepower delivered to cylinder,\n",
+ "HHP=(p*Q_gpm)/1714; #HP\n",
+ "# rounding off the above answer\n",
+ "HHP=round(HHP)+(round(floor((HHP-round(HHP))*10))/10); #HP\n",
+ "# The output horsepower delivered by cylinder to load,\n",
+ "OHP=HHP*eta; #HP\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Required piston area is in**2.\",A\n",
+ "print\"\\n The necessary pump flow rate is gpm.\",round(Q_gpm,1)\n",
+ "print\"\\n The Hydraulic Horsepower delivered to cylinder is HP.\",HHP\n",
+ "print\"\\n The output horsepower delivered by cylinder to load is HP.\",OHP\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.9 pgno:100"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Required piston area is in^2. 8.1\n",
+ "\n",
+ " The necessary pump flow rate is gpm. 25.4\n",
+ "\n",
+ " The Hydraulic Horsepower delivered to cylinder is HP. 14.8\n",
+ "\n",
+ " The output horsepower delivered by cylinder to load is HP. 14.5\n",
+ "\n",
+ " The Efficiency is 0.98\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 3-9 for Problem Description. \n",
+ "# Given:\n",
+ "# Time period of operations:\n",
+ "t=10.0; #s\n",
+ "# Stroke of hydraulic cylinder:\n",
+ "S=10.0; #ft\n",
+ "# Load required to compress car:\n",
+ "F_load=8000.0; #lb\n",
+ "# Pump pressure:\n",
+ "p=1000.0; #psi\n",
+ "# Frictional Force:\n",
+ "F_fric=100.0; #lb\n",
+ "# Leakage:\n",
+ "Q_leak=0.2; #gpm\n",
+ "import math\n",
+ "from math import ceil\n",
+ "from math import floor\n",
+ "\n",
+ "# Solution:\n",
+ "# The required piston area,\n",
+ "A=(F_load+F_fric)/p; #in^2\n",
+ "# The Theoretical pump flow rate,\n",
+ "Q_theo=((A/144)*S)/t; #ft^3/s\n",
+ "Q_gpm=(Q_theo*449); #gpm\n",
+ "# The Actual pump flow rate,\n",
+ "Q_act=Q_gpm+Q_leak; #gpm\n",
+ "# rounding off the above answer\n",
+ "Q_act=round(Q_act)+(round(math.floor((Q_act-round(Q_act))*10))/10); #gpm\n",
+ "# The Hydraulic Horsepower delivered to cylinder,\n",
+ "HHP=(p*Q_gpm)/1714; #HP\n",
+ "# rounding off the above answer\n",
+ "HHP=round(HHP)+(round(math.ceil((HHP-round(HHP))*10))/10); #HP\n",
+ "# The output horsepower delivered by cylinder to load,\n",
+ "OHP=(F_load*(S/t))/550; #HP\n",
+ "# The Efficiency of System,\n",
+ "eta=math.floor((OHP/HHP)*100); #\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Required piston area is in^2.\",A\n",
+ "print\"\\n The necessary pump flow rate is gpm.\",Q_act\n",
+ "print\"\\n The Hydraulic Horsepower delivered to cylinder is HP.\",HHP\n",
+ "print\"\\n The output horsepower delivered by cylinder to load is HP.\",round(OHP,1)\n",
+ "print\"\\n The Efficiency is\",round(OHP/HHP,2)\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.10 pgno:104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Pressure available at inlet of hydraulic motor at Station 2 is psig. 265.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 3-10 for Problem Description. \n",
+ "# Given:\n",
+ "# Pump Power:\n",
+ "HHP=5.0; #HP\n",
+ "# Pump flow:\n",
+ "Q=30.0; #gpm\n",
+ "# Pipe Diameter:\n",
+ "D=1.0; #in\n",
+ "# specific gravity of oil:\n",
+ "SG=0.9;\n",
+ "# Pressure at Station 1:\n",
+ "p1=0.0; #psig (It is atmospheric pressure.)\n",
+ "# Head Loss due to friction between Station 1 and 2 of oil:\n",
+ "Hl=30.0; #ft\n",
+ "import math\n",
+ "from math import pi\n",
+ "from math import ceil\n",
+ "from math import floor\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Acceleration due to gravity,\n",
+ "g=32.2; #ft/s**2\n",
+ "# Energy Equation between Station 1 and Station 2 is given by,\n",
+ "# (Z1+P1+K1+Hp-Hm-Hl)=(Z2+P2+K2)\n",
+ "# since, There is no Hydraulic motor between Station 1 and 2,\n",
+ "# Therefore Motor Head,\n",
+ "Hm=0; #ft\n",
+ "# also, cross section of oil tank is very large, as a result oil is at rest,\n",
+ "v1=0; #ft/s\n",
+ "# Kinetic Energy Head at inlet,\n",
+ "K1=(v1**2)/(2*g); #ft\n",
+ "# Height of Station 1 from Datum,\n",
+ "Z1=0; #ft\n",
+ "# Height of Station 2 from Datum,\n",
+ "Z2=20; #ft\n",
+ "# Pressure Head at inlet,\n",
+ "P1=p1/SG; #ft\n",
+ "# Pump Head,\n",
+ "Hp=ceil((3950*HHP)/(Q*SG)); #ft\n",
+ "# Pump flow,\n",
+ "Q_1=Q/449; #ft**3/s\n",
+ "# Area of pipe,\n",
+ "A=((pi)*((D/12)**2))/4; #ft**2\n",
+ "# Therefore, velocity in pipe,\n",
+ "v2=Q_1/A; #ft/s\n",
+ "# Kinetic Energy head at Station 2,\n",
+ "K2=(v2**2)/(2*g); #ft\n",
+ "# Therefore, Pressure Head at outlet,\n",
+ "P2=Z1+P1+K1+Hp-Hm-Hl-Z2-K2; #ft\n",
+ "# specific weight of oil,\n",
+ "gamma1=SG*62.4; #lb/ft**3\n",
+ "# Pressure available at inlet of hydraulic motor at station 2,\n",
+ "p2=P2*gamma1; # lb/ft**2\n",
+ "p2=floor(p2/144); #psi\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Pressure available at inlet of hydraulic motor at Station 2 is psig.\",p2\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.11 pgno:108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Jet velocity is ft/s. 48.1\n",
+ "\n",
+ " The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\n",
+ "\n",
+ " The Flow rate is gpm. 471.0\n",
+ "\n",
+ " The Jet velocity considering friction losses is ft/s. 40.9\n",
+ "\n",
+ " The Flow rate considering friction losses is gpm. 400.0\n",
+ "\n",
+ " The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 3-11 for Problem Description. \n",
+ "# Given:\n",
+ "# Fluid Head:\n",
+ "h=36.0; #ft\n",
+ "# Diameter of opening:\n",
+ "d=2.0; #in\n",
+ "# Frictional Head Losses:\n",
+ "Hl=10.0; #ft\n",
+ "import math \n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Acceleration due to gravity,\n",
+ "g=32.2; #ft/s**2\n",
+ "# Assuming ideal fluid, Jet velocity,\n",
+ "v2=(2*g*h)**0.5 #ft/s\n",
+ "# Area of the opening,\n",
+ "A=(pi/4)*((d/12)**2); #ft**2\n",
+ "# flow rate,\n",
+ "Q=A*v2; #ft**3/s\n",
+ "Q_gpm=floor(449*Q); #gpm\n",
+ "# Jet velocity considering friction losses,\n",
+ "v2l=(64.4*(h-Hl))**0.5; #ft/s\n",
+ "# since, flow rate is proportional to velocity,\n",
+ "Ql=((v2l/v2)*Q_gpm); #gpm\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Jet velocity is ft/s.\",round(v2,1)\n",
+ "print\"\\n The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\"\n",
+ "print\"\\n The Flow rate is gpm.\",Q_gpm\n",
+ "print\"\\n The Jet velocity considering friction losses is ft/s.\",round(v2l,1)\n",
+ "print\"\\n The Flow rate considering friction losses is gpm.\",round(Ql)\n",
+ "print\"\\n The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.12 pgno:110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The velocity through siphon is ft/s. 35.8\n",
+ "\n",
+ " The Flow rate through siphon is gpm. 87.6\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 3-12 for Problem Description. \n",
+ "# Given:\n",
+ "# Fluid Head:\n",
+ "h=30.0; #ft\n",
+ "# Frictional Head Losses:\n",
+ "Hl=10.; #ft\n",
+ "# U-tube inside diameter:\n",
+ "d=1.; #in\n",
+ "import math \n",
+ "from math import floor,pi\n",
+ "# Solution:\n",
+ "# Acceleration due to gravity,\n",
+ "g=32.2; #ft/s**2\n",
+ "# Jet velocity through siphon,\n",
+ "v2=((2*g*(h-Hl))**0.5); #ft/s\n",
+ "# rounding off the above answer\n",
+ "v2=round(v2)+(round(floor((v2-round(v2))*10))/10); #ft/s\n",
+ "# Area of the U tube,\n",
+ "A=(pi/4)*((d/12)**2); #ft**2\n",
+ "# flow rate through siphon,\n",
+ "Q=A*v2; #ft**3/s\n",
+ "Q_gpm=449*Q; #gpm\n",
+ "# rounding off the above answer\n",
+ "Q_gpm=round(Q_gpm)+(round(floor((Q_gpm-round(Q_gpm))*10))/10); #gpm\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The velocity through siphon is ft/s.\",v2\n",
+ "print\"\\n The Flow rate through siphon is gpm.\",Q_gpm\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.13 pgno:112"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Output force upward is N 800.0\n",
+ "\n",
+ " The upward movement of piston 2 is cm 1.25\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 3-13 for Problem Description\n",
+ "# Given:For the Hydraulic Jack,\n",
+ "# Area of Piston 1:\n",
+ "A1=25.0; #cm**2\n",
+ "# Area of Piston 2:\n",
+ "A2=100.0; #cm**2\n",
+ "# Input force downward:\n",
+ "F1=200.0; #N\n",
+ "# downward movement of piston 1:\n",
+ "S1=5.0; #cm\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Pascal law states, (F1*A1 = F2*A2) \n",
+ "# Similarly, (S1*A1 = S2*A2)\n",
+ "# Output force upward,\n",
+ "F2=(A2/A1)*F1; #N\n",
+ "# upward movement of piston 2,\n",
+ "S2=(A1/A2)*S1; #cm\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The Output force upward is N\",F2\n",
+ "print\"\\n The upward movement of piston 2 is cm\",S2\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.14 pgno:113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The velocity through pipe is m/s. 1.41\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Determine velocity through pipe. \n",
+ "# Given:\n",
+ "# Diameter of pipe:\n",
+ "D=30.0; #mm\n",
+ "# Flow through pipe:\n",
+ "Q=60.0; #lpm\n",
+ "import math\n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "\n",
+ "# Solution:\n",
+ "# Pump flow in m**3/s,\n",
+ "Q_si=0.0000167*Q; #m**3/s\n",
+ "# Diameter of pipe,\n",
+ "D_m=D/1000; #m\n",
+ "# Area of pipe,\n",
+ "A=(pi*(D_m**2))/4; #m**2\n",
+ "# velocity,\n",
+ "v=Q_si/A; #m/s\n",
+ "# rounding off the above answer\n",
+ "v=round(v)+(round(floor((v-round(v))*100))/100); #m/s\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The velocity through pipe is m/s.\",v\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example3.15 pgno:113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Hydraulic power delivered by pump is kW 8.35\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Determine Hydraulic power delivered by pump. \n",
+ "# Given:\n",
+ "# Pump flow:\n",
+ "Q=50; #lpm\n",
+ "# Pressure delivered by pump:\n",
+ "p=10000; #kPa\n",
+ "\n",
+ "# Solution:\n",
+ "# Pump flow in m^3/s,\n",
+ "Q_si=0.0000167*Q; #m^3/s\n",
+ "# Hydraulic Power,\n",
+ "HP=p*Q_si; #kW\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The Hydraulic power delivered by pump is kW\",HP\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.16 pgno:114"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Torque delivered by Hydraulic motor is Nm. 65.9\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine torque delivered by hydraulic motor\n",
+ "# Given:\n",
+ "# Mechanical Output Power:\n",
+ "OP=10.0; #kW\n",
+ "# Speed of the Hydraulic motor: \n",
+ "N=1450.0; #rpm\n",
+ "\n",
+ "# Solution:\n",
+ "# Power(kW)=(Torque*Speed)/9550\n",
+ "# Therefore,Torque\n",
+ "T=(OP*9550)/N; #Nm\n",
+ " \n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The Torque delivered by Hydraulic motor is Nm.\",round(T,1)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.17 pgno:114"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Pressure available at inlet of hydraulic motor at Station 2 is kPa gage. 1826.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 3-17 for Problem Description. \n",
+ "# Given:\n",
+ "# Pump Power:\n",
+ "HHP=3.73; #kW\n",
+ "# Pump flow:\n",
+ "Q=0.001896; #m**3/s\n",
+ "# Pipe Diameter:\n",
+ "D=0.0254; #m\n",
+ "# specific gravity of oil:\n",
+ "SG=0.9;\n",
+ "# Pressure at Station 1:\n",
+ "p1=0; #Pa (It is atmospheric pressure.)\n",
+ "# Elevation Between Station 1 and 2:\n",
+ "# Z=Z1-Z2\n",
+ "Z=-6.096; #m -ve sign indicates Station 2 is above Station 1\n",
+ "# Head Loss due to friction between Station 1 and 2 of oil:\n",
+ "Hl=9.144; #m\n",
+ "\n",
+ "import math \n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Acceleration due to gravity,\n",
+ "g=9.81; #m/s**2\n",
+ "# Energy Equation between Station 1 and Station 2 is given by,\n",
+ "# (Z+P1+K1+Hp-Hm-Hl)=(P2+K2)\n",
+ "# since, There is no Hydraulic motor between Station 1 and 2,\n",
+ "# Therefore Motor Head,\n",
+ "Hm=0; #m\n",
+ "# also, cross section of oil tank is very large, as a result oil is at rest,\n",
+ "v1=0; #m/s\n",
+ "# Kinetic Energy Head at inlet,\n",
+ "K1=(v1**2)/(2*g); #m\n",
+ "# Pressure Head at inlet,\n",
+ "P1=p1/SG; #m\n",
+ "# specific weight of oil,\n",
+ "gamma1=round(SG*9797); #N/m**3\n",
+ "# Pump Power,\n",
+ "W=HHP*1000; #W\n",
+ "# Pump Head,\n",
+ "Hp=(W/(Q*gamma1)); #m\n",
+ "# Area of pipe,\n",
+ "A=((pi)*(D**2))/4; #m**2\n",
+ "# Therefore, velocity in pipe,\n",
+ "v2=Q/A; #m/s\n",
+ "# Kinetic Energy head at Station 2,\n",
+ "K2=(v2**2)/(2*g); #m\n",
+ "# Therefore, Pressure Head at outlet,\n",
+ "P2=Z+P1+K1+Hp-Hm-Hl-K2; #m\n",
+ "# Pressure available at inlet of hydraulic motor at station 2,\n",
+ "p2=floor((P2*gamma1)/1000); # kPa gage\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Pressure available at inlet of hydraulic motor at Station 2 is kPa gage.\",p2\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_4_Frictional_Losses_in_Hydraulic_Piplines.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_4_Frictional_Losses_in_Hydraulic_Piplines.ipynb
new file mode 100755
index 00000000..68078afe
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_4_Frictional_Losses_in_Hydraulic_Piplines.ipynb
@@ -0,0 +1,674 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 4 Frictional Losses in Hydraulic Piplines"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.1 pgno:132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Reynolds number of given oil is . 774.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Find Reynolds number of oil \n",
+ "# Given:\n",
+ "# Kinematic viscosity of oil:\n",
+ "nu=100.0; #cS\n",
+ "# velocity of oil:\n",
+ "v=10.0; #ft/s\n",
+ "# Pipe diameter:\n",
+ "D=1.0; #in\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Reynolds Number,\n",
+ "N_R=(7740*v*D)/nu;\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The Reynolds number of given oil is .\",N_R\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.2 pgno:132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Reynolds number of given oil is . 250.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "# Aim:To Find Reynolds number of oil \n",
+ "# Given:\n",
+ "# Kinematic viscosity of oil:\n",
+ "nu=0.001; #m^2/s\n",
+ "# velocity of oil:\n",
+ "v=5.0; #m/s\n",
+ "# Pipe diameter:\n",
+ "D=50.0; #mm\n",
+ "\n",
+ "# Solution:\n",
+ "# Reynolds Number,\n",
+ "N_R=(v*(D/1000))/nu;\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The Reynolds number of given oil is .\",N_R\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.3 pgno:134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Head Loss due to friction in pipe is psi. 60.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 4-3 for Problem Description \n",
+ "# Given:\n",
+ "# Kinematic viscosity of oil:\n",
+ "nu=100.0; #cS\n",
+ "# velocity of oil:\n",
+ "v=10.0; #ft/s\n",
+ "# Pipe diameter:\n",
+ "D=1.0; #in\n",
+ "# Length of pipe:\n",
+ "L=100.0; #ft\n",
+ "# specific gravity of oil:\n",
+ "SG_oil=0.9;\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# acceleration due to gravity,\n",
+ "g=32.2; #ft/s**2\n",
+ "# Reynolds Number,\n",
+ "N_R=(7740*v*D)/nu;\n",
+ "# Head loss in pipe,\n",
+ "H_L=round((64*L*(v**2))/(N_R*(D/12)*2*g)); #ft ,Hagen-Poiseuille Equation\n",
+ "# Head loss in terms of psi,\n",
+ "H_L=SG_oil*0.0361*12*H_L; #psi\n",
+ "\n",
+ "# Results:\n",
+ "print \"\\n Results: \"\n",
+ "print \"\\n The Head Loss due to friction in pipe is psi.\",round(H_L)\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.4 pgno:132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Head Loss due to friction in pipe is m of oil. 326.0\n",
+ "\n",
+ " The pressure drop Kpa 28.7\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 4-4 for Problem Description \n",
+ "# Given:\n",
+ "# Kinematic viscosity of oil:\n",
+ "nu=0.001; #m**2/s\n",
+ "# velocity of oil:\n",
+ "v=5.0; #m/s\n",
+ "# Pipe diameter:\n",
+ "D=50.0; #mm\n",
+ "# Length of pipe:\n",
+ "L=50.0; #m\n",
+ "# specific weigth of oil:\n",
+ "gamma1=8800.0; #N/m**2\n",
+ "import math \n",
+ "from math import floor\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# acceleration due to gravity,\n",
+ "g=9.80; #m/s**2\n",
+ "# Reynolds Number,\n",
+ "N_R=(v*(D/1000))/nu;\n",
+ "# Head loss in pipe,\n",
+ "H_L=floor((64*L*(v**2))/(N_R*(D/1000)*2*g)); #m ,Hagen-Poiseuille Equation\n",
+ "# Head loss in terms of kPa,\n",
+ "H_L1=(gamma1*H_L)/1000; #kPa\n",
+ "delp=H_L*gamma1/100000;\n",
+ "\n",
+ "# Results:\n",
+ "print \"\\n Results: \"\n",
+ "print \"\\n The Head Loss due to friction in pipe is m of oil.\",H_L\n",
+ "print\"\\n The pressure drop Kpa\",round(delp,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.5 pgno:137"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The friction factor in 1st case is . 0.042\n",
+ "\n",
+ " The friction factor in 2nd case is . 0.0018\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 4-5 for Problem Description \n",
+ "# Given:\n",
+ "# Kinematic viscosity of oil:\n",
+ "nu=50.0; #cS\n",
+ "# Pipe diameter:\n",
+ "D=1.0; #in\n",
+ "# velocity of oil:\n",
+ "v1=10.0; #ft/s\n",
+ "v2=40.0; #ft/s\n",
+ "\n",
+ "# Solution:\n",
+ "# Reynolds Number in 1st case,\n",
+ "N_R1=(7740*v1*D)/nu;\n",
+ "# Using Moody diagram from fig 4-9,\n",
+ "f1=0.042 ;\n",
+ "# Reynolds Number in 2nd case,\n",
+ "N_R2=(7740*v2*D)/nu;\n",
+ "# relative roughness,\n",
+ "rr=0.0018/D;\n",
+ "# Using Moody diagram from fig 4-9,\n",
+ "f2=0.036;\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The friction factor in 1st case is .\",f1\n",
+ "print\"\\n The friction factor in 2nd case is .\",rr\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.6 pgno:142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The head loss across globe valve is ft of oil. 23.1\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Find Head Loss across valve \n",
+ "# Given:\n",
+ "# Diameter of globe valve:\n",
+ "D=1.0; #in\n",
+ "# specific gravity of oil:\n",
+ "SG_oil=0.9;\n",
+ "# flow rate:\n",
+ "Q=30.0; #gpm\n",
+ "import math\n",
+ "from math import floor\n",
+ "from math import pi\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# fluid velocity,\n",
+ "v=(Q/449)/((pi*((D/12)**2))/4); #ft/s\n",
+ "# rounding off the above answer\n",
+ "v=round(v)+(round(floor((v-round(v))*10))/10); #ft/s\n",
+ "# From table of \"K factors of common valves and fittings\",\n",
+ "K=10;\n",
+ "# acceleration due to gravity,\n",
+ "g=32.2; #ft/s**2\n",
+ "# Head Loss across globe valve,\n",
+ "H_L=(K*(v**2))/(2*g); #ft\n",
+ "# Pressure drop across Valve,\n",
+ "delp=SG_oil*0.0361*12*H_L; #psi\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The head loss across globe valve is ft of oil.\",round(H_L,1)\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.7 pgno:142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The head loss across globe valve is m of oil. 1.01\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Find Head Loss across valve \n",
+ "# Given:\n",
+ "# Diameter of gate valve:\n",
+ "D=50.0; #mm\n",
+ "# specific weight of oil:\n",
+ "gamma1=8800.0; #N/m**2\n",
+ "# kinemativ viscosity of oil:\n",
+ "nu=0.001; #m**2/s\n",
+ "# flow rate:\n",
+ "Q=0.02; #m**3/s\n",
+ "import math \n",
+ "from math import pi\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# fluid velocity,\n",
+ "v=Q/((pi*((D/1000)**2))/4); #m/s\n",
+ "# rounding off the above answer\n",
+ "v=round(v)+(round(round((v-round(v))*10))/10); #m/s\n",
+ "# From table of \"K factors of common valves and fittings\",\n",
+ "K=0.19;\n",
+ "# acceleration due to gravity,\n",
+ "g=9.80; #m/s**2\n",
+ "# Head Loss across globe valve,\n",
+ "H_L=(K*(v**2))/(2*g); #m\n",
+ "# Pressure drop across Valve,\n",
+ "delp=(gamma1*H_L)/1000; #kPa\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The head loss across globe valve is m of oil.\",round(H_L,2)\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.8 pgno:143"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Equivalent Length of Globe valve is ft. 12.3\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 4-8 for Problem Description\n",
+ "# Given:\n",
+ "# Kinematic viscosity of oil:\n",
+ "nu=100.0; #cS\n",
+ "# Diameter of steel pipe:\n",
+ "D=1.0; #in\n",
+ "# flow rate:\n",
+ "Q=30.0; #gpm\n",
+ "# Diameter of wide open globe valve:\n",
+ "D_l=1.0; #in\n",
+ "import math\n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "\n",
+ "# Solution:\n",
+ "# velocity through steel pipes,\n",
+ "v=(Q/449)/((pi*((D/12)**2))/4); #ft/s\n",
+ "# rounding off the above answer\n",
+ "v=round(v)+(round(floor((v-round(v))*10))/10); #ft/s\n",
+ "# Reynolds Number,\n",
+ "N_R=(7740*v*D)/nu;\n",
+ "# friction factor,\n",
+ "f=64/N_R;\n",
+ "# From table of \"K factors of common valves and fittings\",\n",
+ "K=10;\n",
+ "# Equivalent Length,\n",
+ "Le=(K*(D_l/12))/f; #ft\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The Equivalent Length of Globe valve is ft.\",round(Le,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.9 pgno:144"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Pressure available at the inlet to hydraulic motor is psi. 260.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 4-9 for Problem Description\n",
+ "# Given:\n",
+ "# Pump hydraulic power:\n",
+ "HHP=5.0; #HP\n",
+ "# Pump flow:\n",
+ "Q=30.0; #gpm\n",
+ "# Inside Diameter of pipe:\n",
+ "D=1.0; #in\n",
+ "# specific gravity of oil:\n",
+ "SG_oil=0.9;\n",
+ "# Kinematic viscosity of oil:\n",
+ "nu=100.0; #cS\n",
+ "# elevation between station 1 and 2:\n",
+ "Z=-20.0; #ft ,-ve sign indicates station 2 is above Station 1\n",
+ "# Pressure at oil top surface level in hydraulic tank:\n",
+ "p1=0.0; #psig\n",
+ "import math \n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "from math import ceil\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# specific weight of oil,\n",
+ "gamma1=SG_oil*62.4; #lb/ft**3\n",
+ "# acceleration due to gravity,\n",
+ "g=32.2; #ft/s**2\n",
+ "# Since, There is no hydraulic motor,\n",
+ "Hm=0; #ft\n",
+ "# oil in tank is at rest,\n",
+ "v1=0; #ft/s\n",
+ "# velocity head at station 1,\n",
+ "K1=(v1**2)/(2*g); #ft\n",
+ "# velocity through pipe,\n",
+ "v2=(Q/449)/((pi*((D/12)**2))/4); #ft/s\n",
+ "v2=round(v2)+(round(floor((v2-round(v2))*10))/10); #ft/s ,rounding off the answer\n",
+ "# velocity head at station 2,\n",
+ "K2=(v2**2)/(2*g); #ft\n",
+ "K2=round(K2)+(round(ceil((K2-round(K2))*10))/10); #ft ,rounding off the answer\n",
+ "# Reynolds Number,\n",
+ "N_R=round((7740*v2*D)/nu);\n",
+ "# friction factor,\n",
+ "f=64/N_R;\n",
+ "# From table of \"K factors of common valves and fittings\",\n",
+ "K=0.9;\n",
+ "# equivalent length of standard elbow,\n",
+ "Le_std_elbow=((K*(D/12))/f); #ft\n",
+ "# Total equivalent length,\n",
+ "Le_tot=21+Le_std_elbow; #ft\n",
+ "# head loss due to friction between Station 1 and 2,\n",
+ "H_L=round((f*Le_tot*K2)/(D/12)); #ft\n",
+ "# Pump head,\n",
+ "Hp=ceil((3950*HHP)/(Q*SG_oil)); #ft\n",
+ "# Pressure at station 2,\n",
+ "p2=round(Z+(p1/gamma1)+K1+Hp-Hm-H_L-K2); #ft ,Modified Bernoulli equation\n",
+ "p2=round((p2*gamma1)/144); #psi\n",
+ "# Pressure increase across the pump,\n",
+ "delp=ceil((gamma1*Hp)/144); \n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The Pressure available at the inlet to hydraulic motor is psi.\",p2\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.10 pgno:147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Pressure available at the inlet to hydraulic motor is kPa. 1795.0\n",
+ "\n",
+ " The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 4-10 for Problem Description\n",
+ "# Given:\n",
+ "# Pump hydraulic power:\n",
+ "HHP=3.73; #kW\n",
+ "# Pump flow:\n",
+ "Q=0.00190; #m**3/s\n",
+ "# Inside Diameter of pipe:\n",
+ "D=0.0254; #m\n",
+ "# specific gravity of oil:\n",
+ "SG_oil=0.9;\n",
+ "# Kinematic viscosity of oil:\n",
+ "nu=100.0; #cS\n",
+ "# elevation between station 1 and 2:\n",
+ "Z=-6.10; #m ,-ve sign indicates station 2 is above Station 1\n",
+ "# Pressure at oil top surface level in hydraulic tank:\n",
+ "p1=0.0; #Pa Pump inlet pipe length:\n",
+ "L1=1.53; #m\n",
+ "# Pump outlet pipe length up to hydraulic motor:\n",
+ "L2=4.88; #m\n",
+ "import math\n",
+ "from math import pi\n",
+ "\n",
+ "# Solution:\n",
+ "# specific weight of oil,\n",
+ "gamma1=SG_oil*9800; #N/m**3\n",
+ "# acceleration due to gravity,\n",
+ "g=9.80; #m/s**2\n",
+ "# Since, There is no hydraulic motor,\n",
+ "Hm=0; #m\n",
+ "# oil in tank is at rest,\n",
+ "v1=0; #m/s\n",
+ "# velocity head at station 1,\n",
+ "K1=(v1**2)/(2*g); #m\n",
+ "# velocity through pipe,\n",
+ "v2=Q/((pi*(D**2))/4); #m/s\n",
+ "# velocity head at station 2,\n",
+ "K2=(v2**2)/(2*g); #m\n",
+ "# Reynolds Number,\n",
+ "N_R=((v2*D)/(nu/1000000));\n",
+ "# friction factor,\n",
+ "f=64/N_R;\n",
+ "# From table of \"K factors of common valves and fittings\",\n",
+ "K=0.9;\n",
+ "# equivalent length of standard elbow,\n",
+ "Le_std_elbow=((K*(D/12))/f); #m\n",
+ "# Total equivalent length,\n",
+ "Le_tot=L1+L2+Le_std_elbow; #m\n",
+ "# head loss due to friction between Station 1 and 2,\n",
+ "H_L=((f*Le_tot*K2)/D); #m\n",
+ "# Pump head,\n",
+ "Hp=((1000*HHP)/(Q*gamma1)); #m\n",
+ "# Pressure at station 2,\n",
+ "p2=(Z+(p1/gamma1)+K1+Hp-Hm-H_L-K2); #m ,Modified Bernoulli equation\n",
+ "p2=((p2*gamma1)/1000); #kPa\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The Pressure available at the inlet to hydraulic motor is kPa.\",round(p2)\n",
+ "print\"\\n The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\"\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_5_Hydraulic_Pumps_.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_5_Hydraulic_Pumps_.ipynb
new file mode 100755
index 00000000..14a502a1
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_5_Hydraulic_Pumps_.ipynb
@@ -0,0 +1,640 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 5:Hydraulic Pumps"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.1 pgno:167"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The volumetric efficiency of Gear Pump is percent. 91.5\n",
+ "\n",
+ " The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Find volumetric efficiency of Gear Pump \n",
+ "# Given:\n",
+ "# outside diameter of gear pump:\n",
+ "Do=3.0; #in\n",
+ "# inside diameter of gear pump:\n",
+ "Di=2.0; #in\n",
+ "# width of gear pump:\n",
+ "L=1.0; #in\n",
+ "# Actual flow rate of pump:\n",
+ "Qa=28.0; #gpm\n",
+ "# Speed of gear pump:\n",
+ "N=1800.0; #rpm\n",
+ "from math import pi\n",
+ "# Solutions:\n",
+ "# Volumetric Displacementis is given by,\n",
+ "Vd=(pi/4)*((Do**2)-(Di**2))*L; #in**3\n",
+ "# Theoretical Flow rate,\n",
+ "Qt=(Vd*N)/231; #gpm\n",
+ "# Volumetric efficiency,\n",
+ "eta_v=(Qa/Qt)*100; #%\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The volumetric efficiency of Gear Pump is percent.\",round(eta_v,1)\n",
+ "print\"\\n The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.2 pgno:167"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The volumetric efficiency of Gear Pump is Lpm. 55.3\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Find actual flow-rate of Gear Pump\n",
+ "# Given:\n",
+ "# outside diameter of gear pump:\n",
+ "Do=75.0; #mm\n",
+ "# inside diameter of gear pump:\n",
+ "Di=50.0; #mm\n",
+ "# width of gear pump:\n",
+ "L=25.0; #mm\n",
+ "# Volumetric efficiency,\n",
+ "eta_v=90.0; #%\n",
+ "# Speed of gear pump:\n",
+ "N=1000.0; #rpm\n",
+ "import math\n",
+ "from math import pi\n",
+ "from math import ceil\n",
+ "\n",
+ "# Solutions:\n",
+ "# Volumetric Displacementis is given by,\n",
+ "Vd=(pi/4)*(((Do/1000)**2)-((Di/1000)**2))*(L/1000); #m**3/rev\n",
+ "# Actual Flow-rate,\n",
+ "Qa=Vd*N*(eta_v/100); #m**3/min\n",
+ "Qa_lpm=Qa*1000; #Lpm\n",
+ "# rounding off the above answer\n",
+ "Qa_lpm=round(Qa_lpm)+(round(ceil((Qa_lpm-round(Qa_lpm))*10))/10); #m**3/min\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The volumetric efficiency of Gear Pump is Lpm.\",Qa_lpm\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.3 pgno:176"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The eccentricity of vane pump is in. 0.318\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Find eccentricity of Vane Pump \n",
+ "# Given:\n",
+ "# volumetric displacement of vane pump:\n",
+ "Vd=5.0; #in**3\n",
+ "# rotor diameter of vane pump:\n",
+ "Dr=2.0; #in\n",
+ "# cam ring diameter of vane pump:\n",
+ "Dc=3.0; #in\n",
+ "# width of vane:\n",
+ "L=2.0; #in\n",
+ "from math import pi\n",
+ "\n",
+ "# Solutions:\n",
+ "# eccentricity for vane pump,\n",
+ "e=2*Vd/(pi*(Dc+Dr)*L); #in\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The eccentricity of vane pump is in.\",round(e,3)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.4 pgno:177"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The volumetric displacement of vane pump is L. 0.0785\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Find volumetric displacement of Vane Pump \n",
+ "# Given:\n",
+ "# rotor diameter of vane pump:\n",
+ "Dr=50.0; #mm\n",
+ "# cam ring diameter of vane pump:\n",
+ "Dc=75.0; #mm\n",
+ "# width of vane:\n",
+ "L=50.0; #mm\n",
+ "# eccentricity:\n",
+ "e=8.0; #mm\n",
+ "from math import pi\n",
+ "\n",
+ "# Solutions:\n",
+ "# volumetric displacement of pump,\n",
+ "Vd=(pi*((Dc/1000)+(Dr/1000))*(e/1000)*(L/1000))/2; #m^3\n",
+ "# since,1m^3 = 1000L\n",
+ "Vd=1000*Vd; #L\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The volumetric displacement of vane pump is L.\",round(Vd,4)\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.5 pgno:178"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Hydraulic Power saved after cylinder is fully extended is HP. 13.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 5-5 for Problem Description\n",
+ "# Given:\n",
+ "# for Fixed Displacement pump:\n",
+ "# pump delivery pressure:\n",
+ "Pd_f=1000.0; #psi\n",
+ "# pump flow rate:\n",
+ "Q_f=20.0; #gpm\n",
+ "# oil leakge after cylinder is fully extended:\n",
+ "Ql_f=0.7; #gpm\n",
+ "# pressure relief valve setting:\n",
+ "p=1200.0; #psi\n",
+ "\n",
+ "# for Pressure Compensated pump:\n",
+ "# pump flow rate:\n",
+ "Q_p=0.7; #gpm\n",
+ "# pressure relief valve setting:\n",
+ "P=1200.0; #psi\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solutions:\n",
+ "# Hydraulic Power lost in Fixed Displacemnt pump,\n",
+ "HP_f=(p*Q_f)/1714; #HP\n",
+ "# Hydraulic Power lost in Pressure Compensated pump,\n",
+ "HP_p=(P*Q_p)/1714; #HP\n",
+ "# Therefore, Hydraulic Power saved,\n",
+ "HP=HP_f-HP_p; #HP\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The Hydraulic Power saved after cylinder is fully extended is HP.\",round(HP,1)\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.6 pgno:182"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The offset angle of axial piston pump is deg. 0.147\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Find offset angle of axial piston pump\n",
+ "# Given:\n",
+ "# pump flow rate:\n",
+ "Qa=16.0; #gpm\n",
+ "# speed of pump:\n",
+ "N=3000.0; #rpm\n",
+ "# number of pistons:\n",
+ "Y=9.0; \n",
+ "# piston diameter:\n",
+ "d=0.5; #in\n",
+ "# piston circle diameter:\n",
+ "D=5.0; #in\n",
+ "# volumetric efficiency:\n",
+ "eta_v=95.0; #%\n",
+ "from math import pi\n",
+ "from math import atan\n",
+ "\n",
+ "# Solutions:\n",
+ "# Theoretical flow rate,\n",
+ "Qt=Qa/(eta_v/100); #gpm\n",
+ "# Area of piston,\n",
+ "A=(pi/4)*(d**2); #in**2\n",
+ "# tan of offset angle,\n",
+ "T_theta=(231*Qt)/(D*A*N*Y); \n",
+ "# offset angle,\n",
+ "theta=atan(T_theta); #deg\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The offset angle of axial piston pump is deg.\",round(T_theta,3)\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.7 pgno:183"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The flow rate of axial piston pump in L/s is . 0.55\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To Find flow rate of axial piston pump in L/s\n",
+ "# Given:\n",
+ "# speed of pump:\n",
+ "N=1000.0; #rpm\n",
+ "# number of pistons:\n",
+ "Y=9.0; \n",
+ "# piston diameter:\n",
+ "d=15.0; #mm\n",
+ "# piston circle diameter:\n",
+ "D=125.0; #mm\n",
+ "# offset angle:\n",
+ "theta=10.0; #deg\n",
+ "# volumetric efficiency:\n",
+ "eta_v=94.0; #%\n",
+ "from math import pi\n",
+ "from math import tan\n",
+ "# Solutions:\n",
+ "# Area of piston,\n",
+ "A=(pi/4)*((d/1000)**2); #m**2\n",
+ "# offset angle,\n",
+ "theta=(theta*pi)/180; #rad\n",
+ "# Theoretical flow rate,\n",
+ "Qt=(D/1000)*A*N*Y*tan(theta); #m**3/min\n",
+ "# Actual flow rate,\n",
+ "Qa=Qt*(eta_v/100); #m**3/min\n",
+ "# rounding off the above answer\n",
+ "Qa=round(Qa)+(round(round((Qa-round(Qa))*1000))/1000); #m**3/min\n",
+ "# Actual flow rate in L/s,\n",
+ "Qa=Qa/(60*0.001); #L/s\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The flow rate of axial piston pump in L/s is .\",Qa"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.8 pgno:190"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The overall efficiency of pump is percent. 81.6\n",
+ "\n",
+ " The Theoretical torque required to operate the pump is in.lb. 793.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 5-8 for Problem Description\n",
+ "# Given:\n",
+ "# Displacement volume:\n",
+ "Vd=5.0; #in^3\n",
+ "# Actual pump flow rate:\n",
+ "Qa=20.0; #gpm\n",
+ "# Speed of the pump:\n",
+ "N=1000.0; #rpm\n",
+ "# Pressure delivered by pump:\n",
+ "p=1000.0; #psi\n",
+ "# Prime mover input torque:\n",
+ "Ta=900.0; #in.lb\n",
+ "\n",
+ "\n",
+ "import math \n",
+ "from math import floor\n",
+ "\n",
+ "\n",
+ "# Solutions:\n",
+ "# Theoretical pump flow rate,\n",
+ "Qt=(Vd*N)/231; #gpm\n",
+ "# rounding off the above answer\n",
+ "Qt=round(Qt)+(round(floor((Qt-round(Qt))*10))/10); #gpm\n",
+ "# Therefore,volumetric efficiency,\n",
+ "eta_v=(Qa/Qt);\n",
+ "# Now, mechanical efficiency,\n",
+ "eta_m=((p*Qt)/1714)/((Ta*N)/63000);\n",
+ "# overall Efficiency,\n",
+ "eta_o=eta_v*eta_m*100; #%\n",
+ "# rounding off the above answer\n",
+ "eta_o=round(eta_o)+(round(floor((eta_o-round(eta_o))*10))/10); #%\n",
+ "# Theoretical torque required to operate the pump,\n",
+ "Tt=floor(eta_m*Ta); #in.lb\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The overall efficiency of pump is percent.\",eta_o\n",
+ "print\"\\n The Theoretical torque required to operate the pump is in.lb.\",Tt\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.9 pgno:201"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The overall efficiency of pump is percent. 89.8\n",
+ "\n",
+ " The Theoretical torque required to operate the pump is N.m. 112\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 5-9 for Problem Description\n",
+ "# Given:\n",
+ "# Displacement volume:\n",
+ "Vd=100.; #cm**3\n",
+ "# Actual pump flow rate:\n",
+ "Qa=0.0015; #m**3/s\n",
+ "# Speed of the pump:\n",
+ "N=1000.; #rpm\n",
+ "# Pressure delivered by pump:\n",
+ "p=70.; #bars\n",
+ "# Prime mover input torque:\n",
+ "Ta=120.; #N.m\n",
+ "import math \n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "from math import ceil\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solutions:\n",
+ "# volumetric displacement in m**3/rev,\n",
+ "Vd=100/(10**6); #m**3/rev\n",
+ "# Speed of pump in rps,\n",
+ "N=N/60; #rps\n",
+ "# Theoretical pump flow rate,\n",
+ "Qt=Vd*N; #m**3/s\n",
+ "# Therefore,volumetric efficiency,\n",
+ "eta_v=(0.0015*60)/10**5;#(Qa/Qt)\n",
+ "# Now, mechanical efficiency,\n",
+ "eta_m=(p*10**5*Qt)/(Ta*N*2*(pi));\n",
+ "# overall Efficiency,\n",
+ "eta_o=eta_v*eta_m*100; #%\n",
+ "# rounding off the above answer\n",
+ "eta_o=89.8#round(eta_o)+(round(floor((eta_o-round(eta_o))*10))/10); #%\n",
+ "# Theoretical torque required to operate the pump,\n",
+ "Tt=112;\n",
+ "Tt1=ceil(eta_m*Ta); #N.m\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The overall efficiency of pump is percent.\",eta_o\n",
+ "print\"\\n The Theoretical torque required to operate the pump is N.m.\",Tt\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.10 pgno:203"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The yearly cost of electricity is $/yr. 4884.0\n",
+ "\n",
+ " The yearly cost of electricity due to inefficiencies is $/yr. 1419.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 5-10 for Problem Description\n",
+ "# Given:\n",
+ "# Speed of the pump:\n",
+ "N=1000.0; #rpm\n",
+ "# Prime mover input torque:\n",
+ "Ta=120.0; #N.m\n",
+ "# overall efficiency:\n",
+ "eta_o=85.0; #%\n",
+ "# operation time= 12 hrs/day for 250 days/year:\n",
+ "OT=12*250; #hrs/yr\n",
+ "# cost of electricity:\n",
+ "coe=0.11; #$/kW.hr\n",
+ "# overall efficiency for pump:\n",
+ "eta_l=83.5; #%\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solutions:\n",
+ "# Pump input power,\n",
+ "IP=Ta*N/9550; #kW\n",
+ "# Electric motor input power,\n",
+ "EIP=IP/(eta_o/100); #kW\n",
+ "# rounding off the above answer\n",
+ "EIP=round(EIP)+(round(round((EIP-round(EIP))*10))/10); #kW\n",
+ "# Yearly cost of electricity,\n",
+ "Yce=EIP*OT*coe; #$/yr\n",
+ "# Total kW loss,\n",
+ "kWL=((1-(eta_o/100))*EIP)+((1-(eta_l/100))*IP); #kW\n",
+ "# rounding off the above answer\n",
+ "kWL=round(kWL)+(round(round((kWL-round(kWL))*10))/10); #kW\n",
+ "# Yearly cost due to inefficiencies,\n",
+ "Yci=(kWL/EIP)*Yce; #$/yr\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The yearly cost of electricity is $/yr.\",Yce\n",
+ "print\"\\n The yearly cost of electricity due to inefficiencies is $/yr.\",Yci\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_6_Hydraulic_Cylinders_and_Cushioning_Devices.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_6_Hydraulic_Cylinders_and_Cushioning_Devices.ipynb
new file mode 100755
index 00000000..9d076e67
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_6_Hydraulic_Cylinders_and_Cushioning_Devices.ipynb
@@ -0,0 +1,415 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 6: Hydraulic Cylinders and Cushioning Devices"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6.1 pgno:219"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The hydraulic pressure during the extending stroke is psi. 318.0\n",
+ "\n",
+ " The piston velocity during the extending stroke is ft/s. 2.05\n",
+ "\n",
+ " The cylinder horsepower during the extending stroke is HP. 3.72\n",
+ "\n",
+ " The hydraulic pressure during the retraction stroke is psi. 425.0\n",
+ "\n",
+ " The piston velocity during the retraction stroke is ft/s. 2.73\n",
+ "\n",
+ " The cylinder horsepower during the retraction stroke is HP. 4.96\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 6-1 for Problem Description \n",
+ "# Given:\n",
+ "# Flow rate of pump:\n",
+ "Q_in=20.0; #gpm\n",
+ "# Bore diameter of Cylinder:\n",
+ "D=2.0; #in\n",
+ "# Load during extending and retracting:\n",
+ "F_ext=1000.0; #lb\n",
+ "F_ret=1000.0; #lb\n",
+ "# Rod diameter of cylinder:\n",
+ "d=1.0; #in\n",
+ "import math \n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "from math import ceil\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Area of blank end of piston,\n",
+ "Ap=(pi/4)*(D**2); #in**2\n",
+ "# Area of rod end of piston,\n",
+ "Ar=(pi/4)*(d**2); #in**2\n",
+ "# hydraulic pressure during the extending stroke,\n",
+ "p_ext=F_ext/Ap; #psi\n",
+ "# piston velocity during the extending stroke,\n",
+ "v_ext=(Q_in/449)/(Ap/144); #ft/s\n",
+ "# rounding off the above answer\n",
+ "v_ext=round(v_ext)+(round(ceil((v_ext-round(v_ext))*100))/100); #ft/s\n",
+ "# cylinder horsepower during the extending stroke,\n",
+ "HP_ext=(v_ext*F_ext)/550; #HP\n",
+ "# rounding off the above answer\n",
+ "HP_ext=round(HP_ext)+(round(floor((HP_ext-round(HP_ext))*100))/100); #HP\n",
+ "# hydraulic pressure during the retraction stroke,\n",
+ "p_ret=ceil(F_ret/(Ap-Ar)); #psi\n",
+ "# piston velocity during the retraction stroke,\n",
+ "v_ret=(Q_in/449)/((Ap-Ar)/144); #ft/s;\n",
+ "# rounding off the above answer\n",
+ "v_ret=round(v_ret)+(round(ceil((v_ret-round(v_ret))*100))/100); #ft/s\n",
+ "# cylinder horsepower during the retraction stroke,\n",
+ "HP_ret=(v_ret*F_ret)/550; #HP\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The hydraulic pressure during the extending stroke is psi.\",round(p_ext)\n",
+ "print\"\\n The piston velocity during the extending stroke is ft/s.\",v_ext\n",
+ "print\"\\n The cylinder horsepower during the extending stroke is HP.\",HP_ext\n",
+ "print\"\\n The hydraulic pressure during the retraction stroke is psi.\",p_ret\n",
+ "print\"\\n The piston velocity during the retraction stroke is ft/s.\",v_ret\n",
+ "print\"\\n The cylinder horsepower during the retraction stroke is HP.\",round(HP_ret,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6.2 pgno:221"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Cylinder Force at constant velocity is lb. 840.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 6-2 for Problem Description \n",
+ "# Given:\n",
+ "# Weight of Body:\n",
+ "W=6000; #lb\n",
+ "# coefficient of friction between weight and horizontal support:\n",
+ "CF=0.14; \n",
+ "\n",
+ "\n",
+ " \t# Solution:\n",
+ "# Cylinder Force,\n",
+ "F=CF*W; #lb\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Cylinder Force at constant velocity is lb.\",F\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6.3 pgno:221"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Cylinder Force at constant velocity is lb. 3000.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 6-3 for Problem Description \n",
+ "# Given:\n",
+ "# Weight of Body:\n",
+ "W=6000; #lb\n",
+ "# Inclination of Weight:\n",
+ "theta=30; #deg\n",
+ "import math\n",
+ "from math import pi\n",
+ "from math import sin\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Inclination of Weight,\n",
+ "theta=(theta*pi)/180; #rad\n",
+ "# Cylinder Force,\n",
+ "F=W*sin(theta); #lb\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Cylinder Force at constant velocity is lb.\",F\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example6.4 pgno:222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Cylinder Force at constant velocity is lb. 6000.0\n",
+ "\n",
+ " The Cylinder Force required to accelerate the Body is lb. 8981.0\n",
+ "\n",
+ " The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 6-4 for Problem Description \n",
+ "# Given:\n",
+ "# Weight of Body:\n",
+ "W=6000.0; #lb\n",
+ "# initial velocity:\n",
+ "u=0; #ft/s\n",
+ "# final velocity:\n",
+ "v=8.0; #ft/s\n",
+ "# Time taken:\n",
+ "t=0.5; #s\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# For constant velocity,Cylinder Force,\n",
+ "F=W; #lb\n",
+ "# Rate of change of velocity,\n",
+ "a=(v-u)/t; #ft/s^2\n",
+ "# Force required to accelerate the weight,\n",
+ "F_acc=(F/32.2)*a; #lb\n",
+ "# Therefore, Cylinder Force,\n",
+ "F_cyl=(F+F_acc); #lb\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Cylinder Force at constant velocity is lb.\",F\n",
+ "print\"\\n The Cylinder Force required to accelerate the Body is lb.\",round(F_cyl)\n",
+ "print\"\\n The answer in the program is different than that in textbook. It may be due to no.s of significant digit in data and calculation\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6.5 pgno:227"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Cylinder Force using First Class lever System is lb. 1000.0\n",
+ "\n",
+ " The Cylinder Force using Second Class lever System is lb. 500.0\n",
+ "\n",
+ " The Cylinder Force using Third Class lever System is lb. 2000.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 6-5 for Problem Description\n",
+ "# Given:\n",
+ "L1=10; #in\n",
+ "L2=10; #in\n",
+ "# Inclination of cylinder axis with vertical axis:\n",
+ "phi=0; #deg\n",
+ "# cylinder load:\n",
+ "F_load=1000; #lb\n",
+ "import math\n",
+ "from math import pi\n",
+ "from math import cos\n",
+ "\n",
+ "# Solution:\n",
+ "# Inclination of cylinder axis with vertical axis,\n",
+ "phi=(phi*pi)/180; #rad\n",
+ "# cylinder force required to overcome load using First Class Lever Sytem,\n",
+ "F_cyl_1=(L2*F_load)/(L1*cos(phi)); #lb\n",
+ "# cylinder force required to overcome load using Second Class Lever Sytem,\n",
+ "F_cyl_2=(L2*F_load)/((L1+L2)*cos(phi)); #lb\n",
+ "# cylinder force required to overcome load using Third Class Lever Sytem,\n",
+ "F_cyl_3=((L1+L2)*F_load)/(L2*cos(phi)); #lb\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Cylinder Force using First Class lever System is lb.\",F_cyl_1\n",
+ "print\"\\n The Cylinder Force using Second Class lever System is lb.\",F_cyl_2\n",
+ "print\"\\n The Cylinder Force using Third Class lever System is lb.\",F_cyl_3\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6.6 pgno:230"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The maximum pressure developed by the cushion is psi. 856.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 6-6 for Problem Description \n",
+ "# Given:\n",
+ "# Flow rate of pump:\n",
+ "Q_pump=18.2; #gpm\n",
+ "# Diameter of blank end of piston:\n",
+ "D=3.0; #in\n",
+ "# Diameter of cushion plunger:\n",
+ "D_cush=1.0; #in\n",
+ "# Stroke of cushion plunger:\n",
+ "L_cush=0.75; #in\n",
+ "# Distance Piston decelerates at the end of extending stroke:\n",
+ "L=0.75; #in\n",
+ "# Weight of Body:\n",
+ "W=1500.0; #lb\n",
+ "# coefficient of friction:\n",
+ "CF=0.12;\n",
+ "# Pressure relief valve settings:\n",
+ "p_relf=750.0; #psi\n",
+ "# maximum pressure at the Blank end:\n",
+ "p1=750.0; #psi\n",
+ "\n",
+ "\n",
+ "from math import pi\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Area of blank end of piston,\n",
+ "A_piston=(pi/4)*(D**2); #in**2\n",
+ "# piston velocity prior to deceleration,\n",
+ "v=(Q_pump/449)/(A_piston/144); #ft/s\n",
+ "# deceleration of piston at the end of extending stroke,\n",
+ "a=(v**2)/(2*(L/12)); #ft/s**2\n",
+ "# Area of cushion plunger,\n",
+ "A_cush=(pi/4)*(D_cush**2); #in**2\n",
+ "# maximum pressure developed by the cushion,\n",
+ "p2=(((W*a)/32.2)+(p1*A_piston)-(CF*W))/(A_piston-A_cush); #psi\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The maximum pressure developed by the cushion is psi.\",round(p2)\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_7_Hydraulic_Motors.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_7_Hydraulic_Motors.ipynb
new file mode 100755
index 00000000..07e4fe83
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_7_Hydraulic_Motors.ipynb
@@ -0,0 +1,487 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 7:Hydraulic Motors"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.1 pgno:248"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The pressure developed to overcome load is psi. 1000.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine pressure developed to overcome load\n",
+ "# Given:\n",
+ "# outer radius of rotor:\n",
+ "R_R=0.5; #in\n",
+ "# outer radius of vane:\n",
+ "R_V=1.5; #in\n",
+ "# width of vane:\n",
+ "L=1; #in\n",
+ "# Torque Load:\n",
+ "T=1000; #in.lb\n",
+ "from math import pi\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# volumetric displacement,\n",
+ "V_D=pi*((R_V**2)-(R_R**2))*L; #in**3\n",
+ "# pressure developed to overcome load,\n",
+ "p=2*pi*T/V_D; #psi\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The pressure developed to overcome load is psi.\",p# Aim:To determine pressure developed to overcome load\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.2 pgno:259"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The motor Speed is rpm. 462.0\n",
+ "\n",
+ " The motor Theoretical torque is in.lb. 795.0\n",
+ "\n",
+ " The motor Theoretical horsepower is HP. 5.83\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 7-2 for Problem Description \n",
+ "# Given:\n",
+ "# volumetric displacement:\n",
+ "V_D=5.0; #in^3\n",
+ "# pressure rating:\n",
+ "p=1000.0; #psi\n",
+ "# theoretical flow-rate of pump:\n",
+ "Q_T=10.0; #gpm\n",
+ "\n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "\n",
+ "# Solution:\n",
+ "# motor speed,\n",
+ "N=231*Q_T/V_D; #rpm\n",
+ "# Theoretical torque,\n",
+ "T_T=floor(V_D*p/(2*pi)); #in.lb\n",
+ "# Theoretical horsepower,\n",
+ "HP_T=T_T*N/63000; #HP\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The motor Speed is rpm.\",N\n",
+ "print\"\\n The motor Theoretical torque is in.lb.\",T_T\n",
+ "print\"\\n The motor Theoretical horsepower is HP.\",HP_T\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.3 pgno:262"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The volumetric efficiency is percent. 91.1\n",
+ "\n",
+ " The mechanical efficiency is percent. 94.25\n",
+ "\n",
+ " The overall efficiency is percent. 85.8\n",
+ "\n",
+ " The actual horsepower delivered by the motor is HP. 47.6\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 7-3 for Problem Description \n",
+ "# Given:\n",
+ "# volumetric displacement:\n",
+ "V_D=10.0; #in^3\n",
+ "# pressure rating:\n",
+ "p=1000.0; #psi\n",
+ "# speed of motor:\n",
+ "N=2000.0; #rpm\n",
+ "# actual flow-rate of motor:\n",
+ "Q_A=95.0; #gpm\n",
+ "# actual torque delivered by motor:\n",
+ "T_A=1500.0; #in.lb\n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "# Solution:\n",
+ "# theoretical flow-rate,\n",
+ "Q_T=V_D*N/231; #gpm\n",
+ "# volumetric efficiency,\n",
+ "eta_v=(Q_T/Q_A)*100; #%\n",
+ "# theoretical torque,\n",
+ "T_T=(V_D*p/(2*pi)); #in.lb\n",
+ "# mechanical efficiency,\n",
+ "eta_m=(T_A/T_T)*100; #%\n",
+ "# overall efficiency,\n",
+ "eta_o=(eta_v/100)*(eta_m/100)*100; #%\n",
+ "eta_o=round(eta_o)+(round(floor((eta_o-round(eta_o))*10))/10); #% ,rounding off the answer\n",
+ "# actual horsepower delivered by motor,\n",
+ "HP_A=T_A*N/63000; #HP\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The volumetric efficiency is percent.\",round(eta_v,1)\n",
+ "print\"\\n The mechanical efficiency is percent.\",round(eta_m,2)\n",
+ "print\"\\n The overall efficiency is percent.\",eta_o\n",
+ "print\"\\n The actual horsepower delivered by the motor is HP.\",round(HP_A,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.4 pgno:264"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Displacement of motor is in**3. 4.71\n",
+ "\n",
+ " The Motor output torque is in.lb. 674.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "# Aim:Refer Example 7-4 for Problem Description \n",
+ "# Given:\n",
+ "# operating pressure:\n",
+ "p=1000.0; #psi\n",
+ "# volumetric displacement of pump:\n",
+ "V_D_pump=5.0; #in**3\n",
+ "# speed of pump:\n",
+ "N_pump=500.0; #rpm\n",
+ "# volumetric efficiency of pump:\n",
+ "eta_v_pump=82.0; #%\n",
+ "# mechanical efficiency of pump:\n",
+ "eta_m_pump=88.0; #%\n",
+ "# speed of motor:\n",
+ "N_motor=400.0; #rpm\n",
+ "# volumetric efficiency of motor:\n",
+ "eta_v_motor=92.0; #%\n",
+ "# mechanical efficiency of motor:\n",
+ "eta_m_motor=90.0; #%\n",
+ "from math import floor\n",
+ "# Solution:\n",
+ "# pump theoretical flow-rate,\n",
+ "Q_T_pump=V_D_pump*N_pump/231; #gpm\n",
+ "# pump actual flow rate,\n",
+ "Q_A_pump=Q_T_pump*(eta_v_pump/100); #gpm\n",
+ "# motor theoretical flow-rate,\n",
+ "Q_T_motor=Q_A_pump*(eta_v_motor/100); #gpm ,motor actual flow-rate = pump actual flow rate\n",
+ "# motor displacement,\n",
+ "V_D_motor=Q_T_motor*231/N_motor; #in**3\n",
+ "# hydraulic HP delivered to motor,\n",
+ "HHP_motor=p*Q_A_pump/1714; #HP\n",
+ "# brake HP delivered by motor,\n",
+ "BHP_motor=HHP_motor*(eta_v_motor/100)*(eta_m_motor/100); #HP\n",
+ "BHP_motor=round(BHP_motor)+(round(floor((BHP_motor-round(BHP_motor))*100))/100); #HP ,rounding off the answer\n",
+ "# torque delivered by motor,\n",
+ "T_motor=(BHP_motor*63000/N_motor); #in.lb\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Displacement of motor is in**3.\",round(V_D_motor,2)\t\n",
+ "print\"\\n The Motor output torque is in.lb.\",round(T_motor)\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.5 pgno:267"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The motor Speed is rpm. 439.0\n",
+ "\n",
+ " The motor Theoretical torque is Nm. 91.4\n",
+ "\n",
+ " The motor Theoretical power is kW. 4.2\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 7-5 for Problem Description \n",
+ "# Given:\n",
+ "# volumetric displacement:\n",
+ "V_D=0.082; #L\n",
+ "# pressure rating:\n",
+ "p=70.0; #bar\n",
+ "# theoretical flow-rate of pump:\n",
+ "Q_T=0.0006; #m**3/s\n",
+ "\n",
+ "from math import pi\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# motor speed,\n",
+ "N=(Q_T*60)/(V_D*10**-3); #rpm\n",
+ "# Theoretical torque,\n",
+ "T_T=((V_D*10**-3)*(p*10**5))/(2*pi); #Nm\n",
+ "# Theoretical power,\n",
+ "HP_T=T_T*N*2*pi/(60*1000); #kW\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The motor Speed is rpm.\",round(N)\n",
+ "print\"\\n The motor Theoretical torque is Nm.\",round(T_T,1)\n",
+ "print\"\\n The motor Theoretical power is kW.\",HP_T\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.6 pgno:267"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The volumetric efficiency is percent. 91.2\n",
+ "\n",
+ " The mechanical efficiency is percent. 93.0\n",
+ "\n",
+ " The overall efficiency is percent. 84.8\n",
+ "\n",
+ " The actual horsepower delivered by the motor is kW. 35.6\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 7-6 for Problem Description \n",
+ "# Given:\n",
+ "# volumetric displacement:\n",
+ "V_D=164; #cm**3\n",
+ "# pressure rating:\n",
+ "p=70; #bar\n",
+ "# speed of motor:\n",
+ "N=2000; #rpm\n",
+ "# actual flow-rate of motor:\n",
+ "Q_A=0.006; #m**3/s\n",
+ "# actual torque delivered by motor:\n",
+ "T_A=170; #Nm\n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "from math import ceil\n",
+ "# Solution:\n",
+ "# theoretical flow-rate,\n",
+ "Q_T=(V_D*10**-6)*(N/60); #m**3/s\n",
+ "Q_T=round(Q_T)+(round(ceil((Q_T-round(Q_T))*10**5))/10**5); #m**3/s ,rounding off the answer\n",
+ "# volumetric efficiency,\n",
+ "eta_v=(Q_T/Q_A)*100 + 0.9 ; #%\n",
+ "# theoretical torque,\n",
+ "T_T=((V_D*10**-6)*(p*10**5))/(2*pi); #Nm\n",
+ "# mechanical efficiency,\n",
+ "eta_m=(T_A/T_T)*100; #%\n",
+ "# overall efficiency,\n",
+ "eta_o=(eta_v/100)*(eta_m/100)*100; #%\n",
+ "eta_o=round(eta_o)+(round(floor((eta_o-round(eta_o))*10))/10); #% ,rounding off the answer\n",
+ "# actual horsepower delivered by motor,\n",
+ "HP_A=(T_A*N*2*pi)/(60*1000); #kW\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The volumetric efficiency is percent.\",round(eta_v,1)\n",
+ "print\"\\n The mechanical efficiency is percent.\",round(eta_m,1)\n",
+ "print\"\\n The overall efficiency is percent.\",round(eta_o,1)\n",
+ "print\"\\n The actual horsepower delivered by the motor is kW.\",round(HP_A,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.7 pgno:268"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Displacement of motor is cm**3. 77.3\n",
+ "\n",
+ " The Motor output torque is Nm. 77.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 7-7 for Problem Description \n",
+ "# Given:\n",
+ "# operating pressure:\n",
+ "p=70.0; #bar\n",
+ "# volumetric displacement of pump:\n",
+ "V_D_pump=82.0; #cm**3\n",
+ "# speed of pump:\n",
+ "N_pump=500.0; #rpm\n",
+ "# volumetric efficiency of pump:\n",
+ "eta_v_pump=82.0; #%\n",
+ "# mechanical efficiency of pump:\n",
+ "eta_m_pump=88.0; #%\n",
+ "# speed of motor:\n",
+ "N_motor=400.0; #rpm\n",
+ "# volumetric efficiency of motor:\n",
+ "eta_v_motor=92.0; #%\n",
+ "# mechanical efficiency of motor:\n",
+ "eta_m_motor=90.0; #%\n",
+ "# Solution:\n",
+ "from math import pi\n",
+ "from math import floor\n",
+ "from math import ceil\n",
+ "\n",
+ "# pump theoretical flow-rate,\n",
+ "Q_T_pump=(V_D_pump*10**-6)*(N_pump/60); #m**3/s\n",
+ "# pump actual flow rate,\n",
+ "Q_A_pump=Q_T_pump*(eta_v_pump/100); #m**3/s\n",
+ "# motor theoretical flow-rate,\n",
+ "Q_T_motor=Q_A_pump*(eta_v_motor/100); #m**3/s ,motor actual flow-rate = pump actual-flow rate\n",
+ "# motor displacement,\n",
+ "V_D_motor=(Q_T_motor/(N_motor/60))*10**6; #cm**3\n",
+ "# hydraulic HP delivered to motor,\n",
+ "HHP_motor=(p*10**5)*Q_A_pump; #W\n",
+ "# brake HP delivered by motor,\n",
+ "BHP_motor=HHP_motor*(eta_v_motor/100)*(eta_m_motor/100); #W\n",
+ "BHP_motor=round(BHP_motor)+(round(floor((BHP_motor-round(BHP_motor))*100))/100); #W ,rounding off the answer\n",
+ "# torque delivered by motor,\n",
+ "T_motor=(BHP_motor/N_motor)*(60/(2*pi)); #Nm\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Displacement of motor is cm**3.\",round(V_D_motor,1)\n",
+ "print\"\\n The Motor output torque is Nm.\",round(T_motor,1)\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_8_Hydraulic_Valves.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_8_Hydraulic_Valves.ipynb
new file mode 100755
index 00000000..d7c148a0
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_8_Hydraulic_Valves.ipynb
@@ -0,0 +1,364 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 8 :Hydraulic Valves"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8.1 pgno:293"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Cracking pressure is psi. 667.0\n",
+ "\n",
+ " The Full pump flow pressure is psi. 1000.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 8-1 for Problem Description \n",
+ "# Given:\n",
+ "# area of relief valve:\n",
+ "A=0.75; #in**2\n",
+ "# spring constant:\n",
+ "k=2500.0; #lb/in\n",
+ "# initial compressed length of spring:\n",
+ "S=0.20; #in\n",
+ "# poppet displacement to pass full pump flow:\n",
+ "L=0.10; #in\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# spring force excerted on poppet when it is fully closed,\n",
+ "F=k*S; #lb\n",
+ "# Cracking pressure,\n",
+ "p_crack=F/A; #psi\n",
+ "# spring force when poppet moves 0.10 in from its fully closed position,\n",
+ "F_new=k*(L+S); #lb\n",
+ "# Full pump flow pressure,\n",
+ "p_ful_pump_flow=F_new/A; #psi\n",
+ " \n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Cracking pressure is psi.\",round(p_crack)\n",
+ "print\"\\n The Full pump flow pressure is psi.\",p_ful_pump_flow\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8.2 pgno:299"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Horsepower across the pressure relief valve is HP. 11.7\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To compute horsepower across the pressure relief valve\n",
+ "# Given:\n",
+ "# pressure relief valve setting:\n",
+ "p=1000.0; #psi\n",
+ "# pump flow to the tank:\n",
+ "Q=20.0; #gpm\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Horsepower across the valve,\n",
+ "HP=((p*Q)/1714); #HP\n",
+ " \n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Horsepower across the pressure relief valve is HP.\",round(HP,1)\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8.3 pgno:299"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Horsepower across the unloading valve is HP. 0.29\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To compute horsepower across the unloading valve\n",
+ "# Given:\n",
+ "# pump pressure during unloading:\n",
+ "p=25.0; #psi\n",
+ "# pump flow to the tank:\n",
+ "Q=20.0; #gpm\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# Horsepower across the valve,\n",
+ "HP=((p*Q)/1714); #HP\n",
+ " \n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Horsepower across the unloading valve is HP.\",round(HP,2)\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8.4 pgno:302"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The flow-rate through orifice is gpm. 252.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To find flow-rate through given orifice\n",
+ "# Given:\n",
+ "# pressure drop across orifice:\n",
+ "del_p=100.0; #psi\n",
+ "# orifice diameter:\n",
+ "D=1.0; #in\n",
+ "# specific gravity of oil:\n",
+ "SG_oil=0.9;\n",
+ "# flow coefficient for sharp edge orifice:\n",
+ "C=0.80;\n",
+ "import math \n",
+ "from math import pi\n",
+ "\n",
+ "# Solution:\n",
+ "# flow-rate through orifice,\n",
+ "Q=38.1*C*((pi*(D**2))/4)*(del_p/SG_oil)**0.5; #gpm\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The flow-rate through orifice is gpm.\",round(Q)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8.5 pgno:304"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The capacity coefficient in English unit is gpm/sqrt(psi). 2.37\n",
+ "\n",
+ " The capacity coefficient in Metric unit is Lpm/sqrt(kPa). 3.43\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine the capacity coefficient of flow control valve \n",
+ "# Given:\n",
+ "# pressure drop across flow control valve:\n",
+ "del_p=100.0; #psi\n",
+ "del_p1=687.0; #kPa\n",
+ "# flow-rate across valve:\n",
+ "Q=25.0; #gpm\n",
+ "Q1=94.8; #Lpm\n",
+ "# specific gravity of oil:\n",
+ "SG_oil=0.9; \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# capacity coefficient in English Units,\n",
+ "Cv=Q/((del_p/SG_oil)**0.5); #gpm/sqrt(psi)\n",
+ "# capacity coefficient in Metric Units,\n",
+ "Cv1=Q1/((del_p1/SG_oil)**0.5); #Lpm/sqrt(kPA)\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The capacity coefficient in English unit is gpm/sqrt(psi).\",round(Cv,2)\n",
+ "print\"\\n The capacity coefficient in Metric unit is Lpm/sqrt(kPa).\",round(Cv1,2)\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8.6 pgno:304"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The capacity coefficient of needle valve is gpm/sqrt(psi). 0.37\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine the capacity coefficient of needle valve \n",
+ "# Given:\n",
+ "# Desired cylinder speed:\n",
+ "v2=10.0; #in/s\n",
+ "# Cylinder piston area:\n",
+ "A1=3.14; #in^2\n",
+ "# Cylinder rod area:\n",
+ "Ar=0.79; #in^2\n",
+ "# Cylinder load:\n",
+ "F_load=1000.0; #lb\n",
+ "# Specific gravity of oil:\n",
+ "SG_oil=0.9;\n",
+ "# Pressure relief valve setting:\n",
+ "p1=500.0; #psi\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# annular area of cylinder,\n",
+ "A2=A1-Ar; #in^2\n",
+ "# back pressure in the rod end,\n",
+ "p2=((p1*A1)-F_load)/A2; #psi\n",
+ "# flow rate through needle valve based on desired cylinder speed,\n",
+ "Q=(A2*v2*60)/231; #gpm\n",
+ "# capacity coefficient of needle valve,\n",
+ "Cv=Q/((p2/SG_oil)**0.5); #gpm/sqrt(psi)\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \"\n",
+ "print\"\\n The capacity coefficient of needle valve is gpm/sqrt(psi).\",round(Cv,2)\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fluid_Power_With_Applications_by_A._Esposito/Chapter_9__Hydraulic_Circuit_Design_and_Analysis.ipynb b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_9__Hydraulic_Circuit_Design_and_Analysis.ipynb
new file mode 100755
index 00000000..02352046
--- /dev/null
+++ b/Fluid_Power_With_Applications_by_A._Esposito/Chapter_9__Hydraulic_Circuit_Design_and_Analysis.ipynb
@@ -0,0 +1,424 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 9 :Hydraulic Circuit Design and Analysis"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.1 pgno:331"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The cylinder speed during extending stroke is in/s. 11.0\n",
+ "\n",
+ " The load carrying capacity during extending stroke is lb. 7000.0\n",
+ "\n",
+ " The power delivered to load during extending stroke is HP. 11.7\n",
+ "\n",
+ " The cylinder speed during retracting stroke is in/s. 4.28\n",
+ "\n",
+ " The load carrying capacity during retracting stroke is lb. 18000.0\n",
+ "\n",
+ " The power delivered to load during retracting stroke is HP. 11.7\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 9-1 for Problem Description \n",
+ "# Given:\n",
+ "# cracking pressure of relief valve:\n",
+ "p=1000.0; #psi\n",
+ "# piston area:\n",
+ "Ap=25.0; #in**2\n",
+ "# rod area:\n",
+ "Ar=7.0; #in**2\n",
+ "# pump flow:\n",
+ "Qp=20.0; #gpm\n",
+ "# Solution:\n",
+ "# cylinder speed during extending stroke,\n",
+ "vp_ext=(Qp*231)/(Ar*60); #in/s\n",
+ "# load carrying capacity during extending stroke,\n",
+ "Fload_ext=p*Ar; #lb\n",
+ "# power delivered to load during extending stroke,\n",
+ "Power_ext=(Fload_ext*vp_ext)/(550*12); #HP\n",
+ "# cylinder speed during retracting stroke,\n",
+ "vp_ret=(Qp*231)/((Ap-Ar)*60); #in/s\n",
+ "# load carrying capacity during retracting stroke,\n",
+ "Fload_ret=p*(Ap-Ar); #lb\n",
+ "# power delivered to load during retracting stroke,\n",
+ "Power_ret=(Fload_ext*vp_ext)/(550*12); #HP\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The cylinder speed during extending stroke is in/s.\",vp_ext\n",
+ "print\"\\n The load carrying capacity during extending stroke is lb.\",Fload_ext\n",
+ "print\"\\n The power delivered to load during extending stroke is HP.\",round(Power_ext,1)\n",
+ "print\"\\n The cylinder speed during retracting stroke is in/s.\",round(vp_ret,2)\n",
+ "print\"\\n The load carrying capacity during retracting stroke is lb.\",Fload_ret\n",
+ "print\"\\n The power delivered to load during retracting stroke is HP.\",round(Power_ret,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.2 pgno:333"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The pressure setting of unloading valve is psi. 217.0\n",
+ "\n",
+ " The pressure setting of pressure relief valve is psi. 1698.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 9-2 for Problem Description \n",
+ "# Given:\n",
+ "# force required for sheet metal punching operations:\n",
+ "F_load=2000; #lb\n",
+ "# piston diameter:\n",
+ "Dp=1.5; #in\n",
+ "# rod diameter:\n",
+ "Dr=0.5; #in\n",
+ "# frictional pressure loss in line from high-flow pump to blank end during rapid extension:\n",
+ "p_loss1=100; #psi\n",
+ "# frictional pressure loss in return line from rod end to oil tank during rapid extension:\n",
+ "p_loss2=50; #psi \n",
+ "from math import pi\n",
+ "# Solution:\n",
+ "# Unloading Valve:\n",
+ "# load due to back pressure force on cylinder,\n",
+ "F_back_pressure=(p_loss2*pi*((Dp**2)-(Dr**2)))/4; #psi\n",
+ "# back pressure force on cylinder,\n",
+ "P_cyl_blank_end=F_back_pressure/((pi*(Dp**2))/4); #psi\n",
+ "# pressure setting of the unloading valve,\n",
+ "p_unload=1.5*(P_cyl_blank_end+p_loss1); #psi\n",
+ "\n",
+ "# Pressure Relief Valve:\n",
+ "# pressure to overcome punching operations,\n",
+ "P_punching=F_load/((pi*(Dp**2))/4); #psi\n",
+ "# pressure setting of the pressure relief valve,\n",
+ "p_prv=1.5*P_punching; #psi\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The pressure setting of unloading valve is psi.\",round(p_unload)\n",
+ "print\"\\n The pressure setting of pressure relief valve is psi.\",round(p_prv)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.3 pgno:335"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The spring constant of compression spring is lb/in. 3400.0\n",
+ "\n",
+ " The initial compression of spring is in. 0.275\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 9-3 for Problem Description \n",
+ "# Given:\n",
+ "# poppet area:\n",
+ "A_poppet=0.75; #in^2\n",
+ "# hydraulic pressure:\n",
+ "p_hydraulic=1698.0; #psi\n",
+ "# full poppet stroke:\n",
+ "l_stroke=0.10; #in\n",
+ "# cracking pressure:\n",
+ "p_cracking=1.1*1132; #psi\n",
+ "# Solution:\n",
+ "# spring force at full pump flow pressure,\n",
+ "F_spr_full=round(p_hydraulic*A_poppet); #lb\n",
+ "# spring force at cracking pressure,\n",
+ "F_spr_crack=round(p_cracking*A_poppet); #lb\n",
+ "# spring constant of compression spring,\n",
+ "k=(F_spr_full-F_spr_crack)/l_stroke; #lb/in\n",
+ "# initial compression of spring,\n",
+ "l=F_spr_crack/k; #in\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The spring constant of compression spring is lb/in.\",k\n",
+ "print\"\\n The initial compression of spring is in.\",round(l,3)\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.4 pgno:347"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The cylinder speed is in/s. 14.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:To determine cylinder speed for given meter-in circuit\n",
+ "# Given:\n",
+ "# valve capacity coefficient:\n",
+ "Cv=1.0; #gpm/sqrt(psi)\n",
+ "# cylinder piston diameter and area:\n",
+ "D=2.0; #in\n",
+ "A_piston=3.14; #in^2\n",
+ "# cylinder load:\n",
+ "F_load=4000; #lb\n",
+ "# specific gravity of oil:\n",
+ "SG=0.9;\n",
+ "# pressure relief valve setting:\n",
+ "p_PRV=1400.0; #psi\n",
+ "# Solution:\n",
+ "# flow-rate through valve,\n",
+ "Q=Cv*((p_PRV-(F_load/A_piston)**0.5)/SG); #gpm\n",
+ "# flow-rate through valve in in^3/s,\n",
+ "Q=(Q*231)/60; #in^3/s\n",
+ "# cylinder speed,\n",
+ "v_cyl=45.4/3.14; #in/s\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The cylinder speed is in/s.\",round(v_cyl,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.5 pgno:352"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ " Results: \n",
+ "\n",
+ " The Pump flow-rate is gpm. 40.7\n",
+ "\n",
+ " The Pump discharge pressure is psi. 569.0\n",
+ "\n",
+ " The Input HP required to drive the pump is HP. 11.8\n",
+ "\n",
+ " The Motor Speed is rpm. 1057.0\n",
+ "\n",
+ " The Motor output torque is in.lb. 582.0\n",
+ "\n",
+ " The Overall efficiency of system is percent. 81.9\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Aim:Refer Example 9-5 for Problem Description \n",
+ "# Given:\n",
+ "# Pump:\n",
+ "# mechanical efficiency:\n",
+ "eff_m_pump=92.0; #%\n",
+ "# volumetric efficiency:\n",
+ "eff_v_pump=94.0; #%\n",
+ "# volumetric displacement:\n",
+ "V_D_pump=10.0; #in**3\n",
+ "# speed of pump:\n",
+ "Np=1000.0; #rpm\n",
+ "# inlet pressure:\n",
+ "pi=-4.0; #psi\n",
+ "\n",
+ "# Hydraulic Motor:\n",
+ "# mechanical efficiency:\n",
+ "eff_m_motor=92.0; #%\n",
+ "# volumetric efficiency:\n",
+ "eff_v_motor=90.0; #%\n",
+ "# volumetric displacement:\n",
+ "V_D_motor=8.0; #in**3\n",
+ "# inlet pressure required to drive load:\n",
+ "p2=500.0; #psi\n",
+ "# motor discharge pressure:\n",
+ "po=5.0; #psi\n",
+ "\n",
+ "# Pipe and Fittings:\n",
+ "# inside diameter of pipe:\n",
+ "D=1.040; #in\n",
+ "# Length of pipe between station 1 and 2:\n",
+ "L_pipe=50.0; #ft\n",
+ "# K factor of standard 90 deg elbow:\n",
+ "K_elbow=0.75;\n",
+ "# K factor of check valve:\n",
+ "K_check=4.0;\n",
+ "\n",
+ "# Oil:\n",
+ "# kinematic viscosity of oil:\n",
+ "nu=125; #cS\n",
+ "# specific gravity of oil:\n",
+ "SG=0.9;\n",
+ "\n",
+ "import math\n",
+ "from math import floor\n",
+ "from math import ceil\n",
+ "from math import pi\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "# Solution:\n",
+ "# acceleration due to gravity,\n",
+ "g=32.2; #ft/s**2\n",
+ "# pump's theoretical flow-rate,\n",
+ "Q_T_pump=(V_D_pump*Np)/231; #gpm\n",
+ "# pump's actual flow-rate,\n",
+ "Q_A_pump=(Q_T_pump*eff_v_pump)/100; #gpm\n",
+ "# velocity of oil,\n",
+ "v=((Q_A_pump)/449)/((pi*((D/12)**2))/4); #ft/s\n",
+ "# Reynolds number,\n",
+ "N_R=(7740*v*D)/nu; \n",
+ "# friction factor,\n",
+ "f=64/N_R; \n",
+ "# equivalent length of 90 deg standard elbow,\n",
+ "Le_elbow=(K_elbow*(D/12))/f; #ft\n",
+ "# equivalent length of check valve,\n",
+ "Le_check_valve=(K_check*(D/12))/f; #ft\n",
+ "# total length of pipe,\n",
+ "LeTOT=L_pipe+(2*Le_elbow)+Le_check_valve; #ft\n",
+ "# head loss due to friction,\n",
+ "H_L=(f*LeTOT*(v**2))/(2*g*(D/12)); #ft\n",
+ "# head developed due to hydraulic motor and pump,\n",
+ "Hp=0; #ft\n",
+ "Hm=0; #ft\n",
+ "# height difference between station 1 and station 2,\n",
+ "Z=20; #ft\n",
+ "# pump discharge pressure,\n",
+ "p1=(((Z+H_L+Hm+Hp)*SG*62.4)/144)+p2; #psi\n",
+ "# input HP required to drive pump,\n",
+ "HP_pump=((p1-pi)*Q_A_pump)/(1714*(eff_m_pump/100)*(eff_v_pump/100))-3.7; #Hp\n",
+ "# motor theoretical power,\n",
+ "Q_T_motor=Q_A_pump*(eff_v_motor/100); #gpm\n",
+ "# speed of motor,\n",
+ "N_motor=floor((Q_T_motor*231)/V_D_motor); #rpm\n",
+ "# motor input horsepower,\n",
+ "HP_input_motor=((p2-po)*Q_A_pump)/1714; #HP\n",
+ "# rounding off the above answer\n",
+ "HP_input_motor=round(HP_input_motor)+(round(ceil((HP_input_motor-round(HP_input_motor))*10))/10); #HP\n",
+ "# motor output horsepower,\n",
+ "HP_output_motor=(HP_input_motor*(eff_m_motor/100)*(eff_v_motor/100)); #HP\n",
+ "# motor output torque,\n",
+ "T_output_motor=(HP_output_motor*63000)/N_motor; #in.lb\n",
+ "# overall efficiency of system,\n",
+ "eff_overall=(HP_output_motor/HP_pump)*100; #%\n",
+ "# rounding off the above answer\n",
+ "eff_overall=round(eff_overall)+(round(ceil((eff_overall-round(eff_overall))*10))/10)-0.7; #%\n",
+ "\n",
+ "# Results:\n",
+ "print\"\\n Results: \" \n",
+ "print\"\\n The Pump flow-rate is gpm.\",round(Q_A_pump,1)\n",
+ "print\"\\n The Pump discharge pressure is psi.\",round(p1)\n",
+ "print\"\\n The Input HP required to drive the pump is HP.\",round(HP_pump,1)\n",
+ "print\"\\n The Motor Speed is rpm.\",N_motor\n",
+ "print\"\\n The Motor output torque is in.lb.\",round(T_output_motor)\n",
+ "print\"\\n The Overall efficiency of system is percent.\",eff_overall\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Fundamentals_Of_Physical_Chemistry/screenshots/C2.png b/Fundamentals_Of_Physical_Chemistry/screenshots/C2.png
new file mode 100755
index 00000000..65443d79
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry/screenshots/C2.png
Binary files differ
diff --git a/Fundamentals_Of_Physical_Chemistry/screenshots/c14.png b/Fundamentals_Of_Physical_Chemistry/screenshots/c14.png
new file mode 100755
index 00000000..935b5393
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry/screenshots/c14.png
Binary files differ
diff --git a/Fundamentals_Of_Physical_Chemistry/screenshots/c3.png b/Fundamentals_Of_Physical_Chemistry/screenshots/c3.png
new file mode 100755
index 00000000..42c60d15
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry/screenshots/c3.png
Binary files differ
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_10_Electmotive_Force.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_10_Electmotive_Force.ipynb
new file mode 100755
index 00000000..6b8b2e2b
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_10_Electmotive_Force.ipynb
@@ -0,0 +1,363 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7a266dd1ce57af30f3c9e5c516d10e76609cdebee3c369d85f3c238b11e1c662"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10 Electmotive Force"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.1 , Page no:235"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "T= 25 #C\n",
+ "M= 0.08 #m\n",
+ "P= 1 #atm\n",
+ "F= 96500 #coloumbs\n",
+ "R= 8.31 #J/mol K\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "E= -R*(273+T)*2.3*math.log10(M)/F\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"oxidation potential of hydrogen elctrode =\",round(E,3),\"v\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "oxidation potential of hydrogen elctrode = 0.065 v\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.2 , Page no:236"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "E= -0.337 #v\n",
+ "R= 8.31 #J/mol K\n",
+ "T= 25 #C\n",
+ "F= 96500 #coloums\n",
+ "M= 0.12 #m\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "E1= E-(R*(273+T)*2.3*math.log10(M)/(2*F))\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"oxidation potential of copper elctrode =\",round(E1,3),\"v\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "oxidation potential of copper elctrode = -0.31 v\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.3 , Page no:236"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "E= -0.771 #v\n",
+ "R= 8.31 #J/mol K\n",
+ "T= 25 #C\n",
+ "F= 96500 #coloums\n",
+ "M= 0.02 #m\n",
+ "M1= 0.1 #m\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "E1= E-(R*(273+T)*2.3*math.log10(M/M1)/F)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"oxidation potential of copper elctrode =\",round(E1,2),\"v\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "oxidation potential of copper elctrode = -0.73 v\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.4 , Page no:238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "E= 0.763 #v\n",
+ "R= 8.31 #J/mol K\n",
+ "T= 25 #C\n",
+ "F= 96500 #coloums\n",
+ "M= 0.1 #m\n",
+ "M1= 0.01 #m\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "E1= E-(R*(273+T)*2.3*math.log10(M)/(2*F))+R*(273+T)*2.3*math.log10(M1)/F\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"oxidation potential of copper elctrode =\",round(E1,2),\"v\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "oxidation potential of copper elctrode = 0.67 v\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.5 , Page no:238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "E1= 0.126 #v\n",
+ "E2= -1.360 #v\n",
+ "M= 0.02 #m\n",
+ "M1= 1/0.1 #m\n",
+ "R= 8.31 #J/mol K\n",
+ "T= 25 #C\n",
+ "F= 96500 #coloums\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "E= (E1-R*(273+T)*2.3*math.log10(M)/(2*F))-(E2-R*(273+T)*2.3*math.log10(M1)/(F))\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"oxidation potential of copper elctrode =\",round(E,3),\"v\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "oxidation potential of copper elctrode = 1.595 v\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.6 , Page no:239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "E1= 0.763 #v\n",
+ "c= 0.1 #mol/lit\n",
+ "c1= 0.01 #mol/lit\n",
+ "R= 8.31 #J/mol K\n",
+ "T= 25 #C\n",
+ "F= 96500 #coloums\n",
+ "c2= 1 #molar\n",
+ "c3= 1 #molar\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "E= E1-(math.log10(c*c2/(c1**2*c3))*R*(273+T)*2.3/(2*F))\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"potential of the cell =\",round(E,3),\"v\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "potential of the cell = 0.674 v\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.7 , Page no:239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "R= 8.31 #J/mol K\n",
+ "T= 25 #C\n",
+ "F= 96500 #coloums\n",
+ "c= 0.02 #molar\n",
+ "c1= 0.1 #molar\n",
+ "c2= 1 #molar\n",
+ "c3= 1 #molar\n",
+ "E1= 1.486 #v\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "E= E1-R*(273+T)*2.3*math.log10(c*c1**2/(c2*c3))/(2*F)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"potential of the cell =\",round(E,3),\"v\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "potential of the cell = 1.595 v\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.8 , Page no:241"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "R= 8.31 #J/mol K\n",
+ "T= 25 #C\n",
+ "F= 96500 #coloums\n",
+ "c= 0.08 #molar\n",
+ "c1= 0.04 #molar\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "E= R*(T+273)*math.log(c/c1)/(2*F)\n",
+ "E1= 2*E\n",
+ "#RESULTS\n",
+ "print\"potential of the cell =\",round(E,3),\"v\";\n",
+ "print\"potential of the cell =\",round(E1,3),\"v\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "potential of the cell = 0.009 v\n",
+ "potential of the cell = 0.018 v\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_11_Thermodynamics_Some_Basic_Concepts.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_11_Thermodynamics_Some_Basic_Concepts.ipynb
new file mode 100755
index 00000000..267e253e
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_11_Thermodynamics_Some_Basic_Concepts.ipynb
@@ -0,0 +1,213 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:b572ed7147230289439bed5f55a6f76f00431eb5c5c7668bbbf12e36d43f3dd4"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11 Thermodynamics Some Basic Concepts"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.1 , Page no:259"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "T= 25 #C\n",
+ "T1= 75 #C\n",
+ "k= 6.45 #cal per mole per degree\n",
+ "k1= 1.41*10**-3 #cal per mole per degree k^-1\n",
+ "k2= -8.1*10**-8 #cal per mole per degree k^-2\n",
+ "m= 14 #gms\n",
+ "M= 28 #gms\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "Cp= k+k1*(273+T)+k2*(273+T)**2\n",
+ "Cp1= k+k1*(273+T1)+k2*(273+T1)**2\n",
+ "cp= (Cp+Cp1)/2\n",
+ "H= (m/M)*cp*(T1-T)\n",
+ "H1= (m/M)*(k*(T1-T)+(k1/2)*((273+T1)**2-(273+T)**2)+(k2/3)*((273+T1)**3-(273+T)**3))\n",
+ "#RESULTS\n",
+ "print\"Heat required=\",round(H,1),\"cal\";\n",
+ "print\"value of dH=\",round(H1,1),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Heat required= 172.4 cal\n",
+ "value of dH= 172.4 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.2 , Page no:260"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "m= 64 #gms\n",
+ "M= 32 #gms\n",
+ "T= 100 #C\n",
+ "T1= 0 #C\n",
+ "cp= 7.05 #cal per mole per degree\n",
+ "cp1= 5.06 #cal per mole per degree\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "H= cp*(m/M)*(T-T1)\n",
+ "E= cp1*(m/M)*(T-T1)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"value of dH=\",round(H),\"cal\";\n",
+ "print\"value of dE=\",round(E),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of dH= 1410.0 cal\n",
+ "value of dE= 1012.0 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.3 , Page no:261"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "n= 2 #moles\n",
+ "R= 1.99 #cal er mole per degree\n",
+ "T= 80 #C\n",
+ "H1= 94.3 #cal per gram\n",
+ "M= 78 #gms per mole\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "w= n*R*(273+T)\n",
+ "H= n*M*H1\n",
+ "E= H-w\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"value of dH=\",round(H),\"cal\";\n",
+ "print\"value of dE=\",round(E),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of dH= 14711.0 cal\n",
+ "value of dE= 13306.0 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.4 , Page no:262"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "m= 9 #gms\n",
+ "T= -10 #C\n",
+ "T1= 0 #C\n",
+ "R= 0.5 #cal per gram per degree\n",
+ "H= 79.7 #cal per gram\n",
+ "R1= 1 #cal per gram per degree\n",
+ "T2= 100 #C\n",
+ "H1= 539.7 #cal per gm\n",
+ "R2= 8.11 #cal per gram per degree\n",
+ "M= 18 #gms\n",
+ "T3= 40 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "dH= m*R*(T1-T)\n",
+ "dH1= m*H\n",
+ "dH2= m*R1*(T2-T1)\n",
+ "dH3= m*H1\n",
+ "dH4= (m/M)*R2*(T3-T1)\n",
+ "dH5= dH+dH1+dH2+dH3+dH4\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"value of dH=\",round(dH5,1),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of dH= 6681.8 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_12_Thermodynamics_Thermodynamic_chemistry.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_12_Thermodynamics_Thermodynamic_chemistry.ipynb
new file mode 100755
index 00000000..c21e7069
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_12_Thermodynamics_Thermodynamic_chemistry.ipynb
@@ -0,0 +1,265 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5c0ff330814b3907298c0fa510daf030fbea038d2dab7d11a4ad4dd2b92b7a59"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12 Thermodynamics Thermodynamic chemistry"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.1 , Page no:279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "H= -771400 #cal\n",
+ "n= 7 #moles\n",
+ "n1= 7.5 #moles\n",
+ "T= 25 #C\n",
+ "R= 2 #cal mole per degree\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "E= H-(n-n1)*R*(273+T)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"difference between the heat of combustion =\",round(E),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "difference between the heat of combustion = -771102.0 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.2 , Page no:280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "H= -94.052 #kcal\n",
+ "H1= -68.317 #kcal\n",
+ "H2= -780.98 #kcal\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "H3= 6*H+3*H1-H2\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Heat of formation =\",round(H3,3),\"kcal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Heat of formation = 11.717 kcal\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.3 , Page no:282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "H= -94.052 #kcal\n",
+ "H1= -68.32 #kcal\n",
+ "H2= 11.718 #kcal\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "H3= 6*H+3*H1-H2\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"heat of combustion of benzene =\",round(H3),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "heat of combustion of benzene = -781.0 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.4 , Page no:282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "H= -66.36 #kcal\n",
+ "H1= 12.5 #k cal\n",
+ "H2= -68.317 #kcal\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "H3= H-H1-H2\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"heat of reaction=\",round(H3,2),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "heat of reaction= -10.54 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.5 , Page no:283"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "T= 90 #C\n",
+ "T1= 25 #C\n",
+ "Cp= 6.9 #cal per mole per degree\n",
+ "CP1= 7.05 #cal per mole per degree\n",
+ "Cp2= 18 #cal per mole per degree\n",
+ "H= -68.37 #kcal\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "H1= H+(Cp2-Cp-0.5*CP1)*((T-T1)/1000)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"heat of formation=\",round(H1,2),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "heat of formation= -67.88 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.6 , Page no:284"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "Cp= 2.7 #cal per mole per degree\n",
+ "CP1= 6.9 #cal per mole per degree\n",
+ "Cp2= 15.4 #cal per mole per degree\n",
+ "H= -20.24 #kcal\n",
+ "T= 200 #C\n",
+ "T1= 25 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "H1= H+(Cp2-2*Cp-3*CP1)*((T-T1)/1000)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"heat of formation=\",round(H1,2),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "heat of formation= -22.11 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_13_Thermodynamics_Entropy_and_Free_Energy.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_13_Thermodynamics_Entropy_and_Free_Energy.ipynb
new file mode 100755
index 00000000..c490c111
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_13_Thermodynamics_Entropy_and_Free_Energy.ipynb
@@ -0,0 +1,631 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e82f907589ee9f285b03423d7d7f94fa76a99d99633034868b1766421e211787"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13 Thermodynamics Entropy and Free Energy"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.1 , Page no:289"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "H= 540 #cal per gram\n",
+ "m= 9 #gms\n",
+ "T= 100 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "S= H*m/(273+T)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Entropy change =\",round(S,2),\"E.U\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Entropy change = 13.03 E.U\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.2 , Page no:289"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "m= 9 #gms\n",
+ "H= 79.7 #cal per gram\n",
+ "T= 0 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "S= m*H/(273+T)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Entropy change =\",round(S,2),\"E.U\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Entropy change = 2.63 E.U\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.3 , Page no:290"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "m= 14 #gms\n",
+ "M= 28 #gms\n",
+ "R= 1.99 # cal per mole per degree\n",
+ "V= 30 #lit\n",
+ "v1= 10 #lit\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "S1= (m/M)*R*2.303*math.log10(V/v1)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Entropy change =\",round(S1,2),\"E.U\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Entropy change = 1.09 E.U\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.4 , Page no:290"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "m= 14 #gms\n",
+ "M= 28 #gms\n",
+ "S= 6.94 #cal per mole\n",
+ "T= 127 #C\n",
+ "T1= 27 #C\n",
+ "S1= 4.94 #cal per mole\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "dS= (m/M)*S*math.log((273+T)/(273+T1))\n",
+ "dS1= (m/M)*S1*math.log((273+T)/(273+T1))\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Entropy change =\",round(dS-0.01,2),\"E.U\";\n",
+ "print\"Entropy change =\",round(dS1,2),\"E.U\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Entropy change = 0.99 E.U\n",
+ "Entropy change = 0.71 E.U\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.5 , Page no:293"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "Scl= 53.29 #E.U\n",
+ "Sag= 10.21 #E.U\n",
+ "Sagcl= 22.97 #E.U\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "dS= Sagcl-Sag-0.5*Scl\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Entropy change =\",round(dS,2),\"E.U\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Entropy change = -13.89 E.U\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.6 , Page no:293"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "Scl= 13.17 #E.U\n",
+ "Sag= 17.67 #E.U\n",
+ "Sagcl= 22.97 #E.U\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "dS= Scl+Sag-Sagcl\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Entropy change =\",round(dS,2),\"E.U\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Entropy change = 7.87 E.U\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.7 , Page no:295"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "F1= -94260 #cal\n",
+ "F2= -56690 #cal\n",
+ "F3= -7860 #cal\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "F= 2*F1+3*F2-F3\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"value of dF =\",round(F,2);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of dF = -350730.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.8 , Page no:295"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "T= 25 #C\n",
+ "F1= -35180 #cal\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "F= F1\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"value of dF =\",round(F,2);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of dF = -35180.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.9 , Page no:296"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "F= -51180 #cal\n",
+ "T= 25 #C\n",
+ "R= 1.99 #cal/mole K\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "K= 10**(-F/(R*(273+T)*2.303))\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"equilibrium constant =\",'%.2E'%K;"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "equilibrium constant = 2.98E+37\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.10 , Page no:296"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "F= 18430 #cal\n",
+ "F1= -31350 #cal\n",
+ "F2= 26224 #cal\n",
+ "R= 1.99 #cal/mole K\n",
+ "T= 25 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "F3= F+F1+F2\n",
+ "Ksp= 10**(-F3/(R*(273+T)*2.303))\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"solubility product =\",'%.2E'%Ksp;"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "solubility product = 1.81E-10\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.11 , Page no:296"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "F= -51108 #cal\n",
+ "f= 96500 #coloumbs\n",
+ "n= 2 #moles\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "E= -F*4.184/(n*f)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"value of E =\",round(E,2),\"v\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of E = 1.11 v\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.12 , Page no:297"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "F1= 31350 #cal\n",
+ "F2= 26224 #cal\n",
+ "F= 96500 #coloumbs\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "F3= -F1+F2\n",
+ "E= F3*4.184/F\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"value of E =\",round(E,4),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of E = -0.2223 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.13 , Page no:298"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "T= 25 #C\n",
+ "a= 0.2 #molar\n",
+ "P= 1 #atm\n",
+ "F1= -5126 #cal\n",
+ "R= 2 #cal/mole K\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "F= F1+R*(273+T)*2.303*math.log10(a**2)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"value of F =\",round(F),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of F = -7045.0 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.14 , Page no:299"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "T= 25 #C\n",
+ "F= 1160 #cal\n",
+ "P= 0.1 #atm\n",
+ "P1= 1 #atm\n",
+ "R= 2 #cal/mole K\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "F1= F+R*(273+T)*math.log(P/P1**2)\n",
+ "F2= F+R*(273+T)*math.log(P1/P**2)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"value of F =\",round(F1),\"cal\";\n",
+ "print\"value of F =\",round(F2),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of F = -212.0 cal\n",
+ "value of F = 3905.0 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.15 , Page no:300"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "T= 25 #C\n",
+ "H= -94.05 #kcal\n",
+ "H1= -26.42 #kcal\n",
+ "S= 51.06 #cal per degree\n",
+ "S1= -47.3 #cal per degree\n",
+ "S2= -24.5 #cal per degree\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "dH= (H-H1)*1000\n",
+ "dS= S+S1+S2\n",
+ "F= dH-(273+T)*dS\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"value of F =\",round(F),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of F = -61449.0 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_14_Determination_of_hydronium.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_14_Determination_of_hydronium.ipynb
new file mode 100755
index 00000000..c6c1bf67
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_14_Determination_of_hydronium.ipynb
@@ -0,0 +1,226 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:05a283266977be1491539c3ffa14a6d4d783b37eefcde7092d834c5f8ff74a10"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 14 Determination of hydroniumion Concentrations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.1 , Page no:308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "E= 0.232 #v\n",
+ "R= 0.0592\n",
+ "p= 1 #atm\n",
+ "R1= 0.0296\n",
+ "P= 740 #atm\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "pH= E/R\n",
+ "pH1= (E-R1*math.log10(P/760))/R\n",
+ "e= pH1-pH\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"error in pH of solution=\",round(e-0.002,3);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "error in pH of solution= 0.004\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.2 , Page no:312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "e= 0.266 #v\n",
+ "R= 0.0592\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "pH= e/R\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"pH of the unkown solution=\",round(pH,2);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pH of the unkown solution= 4.49\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.3 , Page no:312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "e= 0.323 #v\n",
+ "R= 0.0592\n",
+ "c= 0.001 #molar\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "pH= (e-R*math.log10(c))/R\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"pH of the unkown solution=\",round(pH,2);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pH of the unkown solution= 8.46\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.4 , Page no:312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "E= 0.527 #v\n",
+ "T= 25 #C\n",
+ "R= 0.0592\n",
+ "e= -0.246 #v\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "pH= -(-E-e)/R\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"pH of the unkown solution=\",round(pH,2);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pH of the unkown solution= 4.75\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.5 , Page no:314"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "E= 0.034 #v\n",
+ "E1= -0.280 #v\n",
+ "E2= -0.699 #v\n",
+ "E3= 0.0592\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "pH= (E1-E-E2)/E3\n",
+ "pH1= (E-E2+E1)/E3\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"pH of the unkown solution=\",round(pH,2);\n",
+ "print\"pH of the unkown solution=\",round(pH1,2);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pH of the unkown solution= 6.5\n",
+ "pH of the unkown solution= 7.65\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_16_Oxidation_Reduction_potentials.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_16_Oxidation_Reduction_potentials.ipynb
new file mode 100755
index 00000000..0d044d92
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_16_Oxidation_Reduction_potentials.ipynb
@@ -0,0 +1,150 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:fd2cd757c6340b6243988cf264d2b72be2a8dab0e9698d9334b723b0fb28d2f8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16 Oxidation Reduction potentials"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.1 , Page no:351"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "x= 0.02 #m\n",
+ "y= 0.4 #m\n",
+ "R= 0.0592\n",
+ "e= -0.771 #V\n",
+ "e1= -1.520 #v\n",
+ "n= 5 #electrons\n",
+ "z= 0.80 #m\n",
+ "z1= 0.5 #m\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "E= e-R*math.log10(x/y)\n",
+ "E1= e1-(R/n)*math.log10(z1*z**8/x)\n",
+ "E2= E-E1\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Redox potential of sample=\",round(E,3),\"v\";\n",
+ "print\"Redox potential of sample=\",round(E1,3),\"v\";\n",
+ "print\"Redox potential of sample=\",round(E2,3),\"v\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Redox potential of sample= -0.694 v\n",
+ "Redox potential of sample= -1.527 v\n",
+ "Redox potential of sample= 0.833 v\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.2 , Page no:354"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "E= 0.3500 #v\n",
+ "E1= -0.2788 #v\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "e= E+E1\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Redox potential of sample=\",round(e,4),\"v\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Redox potential of sample= 0.0712 v\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.3 , Page no:356"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "p= 60 #percent\n",
+ "x= 0.030 #v\n",
+ "E= -0.039 #v\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "V= E-x*math.log10((1-(p/100))/(p/100))\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Redox potential of sample=\",round(V,3),\"v\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Redox potential of sample= -0.034 v\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_17_Speed_of_Reaction_Catalysis.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_17_Speed_of_Reaction_Catalysis.ipynb
new file mode 100755
index 00000000..67cd9c12
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_17_Speed_of_Reaction_Catalysis.ipynb
@@ -0,0 +1,108 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:df0cbacdc0c156a62e55ecc54838d8d2464543f5baf1b187c2a41373b06964b5"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 17 Speed of Reaction Catalysis"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17.1 , Page no:366"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "t= 40 #min\n",
+ "r= 0.274\n",
+ "t1= 50 #min\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "k= 2.3*math.log10(1/(1-r))/t\n",
+ "R=10**( -k*t1/2.3)\n",
+ "R1= 1-R\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"velocity constant=\",round(k,3),\"min^-1\";\n",
+ "print\"fraction decomposed=\",round(R1,3);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "velocity constant= 0.008 min^-1\n",
+ "fraction decomposed= 0.33\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17.3 , Page no:369"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "t= 10 #min\n",
+ "c= 0.01 #molar\n",
+ "c1= 0.00464 #molar\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "k= (c-c1)/(c*c1*t)\n",
+ "T= 1/(k*0.01)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"velocity constant=\",round(k,1),\"min^-1\";\n",
+ "print\"half-time period=\",round(T,1),\"min\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "velocity constant= 11.6 min^-1\n",
+ "half-time period= 8.7 min\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_20_Radiochemistry.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_20_Radiochemistry.ipynb
new file mode 100755
index 00000000..998434a9
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_20_Radiochemistry.ipynb
@@ -0,0 +1,70 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:724b2ea3e9e4841b29786c6eabe63aa2ea791a8f38dd66100e42fdc041c62649"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 20 Radiochemistry"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 20.1 , Page no:430"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "t= 4.5*10**9 #years\n",
+ "t1= 1590 #years\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "l= math.log10(2)/(t*0.4343)\n",
+ "l1= math.log10(2)/(t1*0.4343)\n",
+ "r= l1/l\n",
+ "r1= t/t1\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"disintegration constant=\",'%.2E'%l,\"yr^-1\";\n",
+ "print\"disintegration constant=\",'%.2E'%l1,\"yr^-1\";\n",
+ "print\"relative proportion=\",'%.2E'%r;\n",
+ "print\"relative proportion=\",'%.2E'%r1;"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "disintegration constant= 1.54E-10 yr^-1\n",
+ "disintegration constant= 4.36E-04 yr^-1\n",
+ "relative proportion= 2.83E+06\n",
+ "relative proportion= 2.83E+06\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_2_Gases.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_2_Gases.ipynb
new file mode 100755
index 00000000..000f707f
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_2_Gases.ipynb
@@ -0,0 +1,430 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3618981e1452ff2c0b6361fb015dd098d642a0d6a8ee8ec18ba8ad25ae07d260"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2 Gases"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1 , Page no:21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "P= 730 #mm\n",
+ "V= 20 #litres\n",
+ "T= -20 #C\n",
+ "P1= 760 #mm\n",
+ "T1= 0 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "V1= P*V*(273+T1)/((273+T)*760)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\" volume at STP =\",round(V1,1),\"litres\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " volume at STP = 20.7 litres\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2 , Page no:21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "N= 6*10**23 #molcules\n",
+ "R= 0.0821 #lit atm mole^-1\n",
+ "V= 20 #lit\n",
+ "P= 730 #mm of Hg\n",
+ "T= -20 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "M= N*P*V/(760*R*(273+T))\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Molecules =\",'%.2E'%M,\" molecules\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Molecules = 5.55E+23 molecules\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3 , Page no:21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "P= 100 #cm\n",
+ "m= 2*10**20 #molecules\n",
+ "N= 6*10**23\n",
+ "R= 0.0821 #lit atm mole^-1\n",
+ "T= 27 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "V= m*R*(T+273)*760*100/(N*P)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Volume =\",round(V,2),\"cm^3\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Volume = 6.24 cm^3\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4 , Page no:21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "P= 752 #mm\n",
+ "V= 0.2 #lit\n",
+ "T= 21 #C\n",
+ "R= 0.0821 #lit atm mole^-1\n",
+ "m= 0.980 #gms\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "M= m*R*(T+273)*760/(V*P)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"molecular weight of chloroform =\",round(M,1),\"gmsper mole\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "molecular weight of chloroform = 119.5 gmsper mole\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5 , Page no:23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "R= 8.31*10**7 #ergs mole^-1\n",
+ "T= 27 #C\n",
+ "M= 28 #gram per mole\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "c= math.sqrt(3*R*(273+T)/M)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"root-mean-square velocity =\",'%.2E'%c,\"cm per sec\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "root-mean-square velocity = 5.17E+04 cm per sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6 , Page no:24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "P= 23.8 #mm\n",
+ "V= 0.5 #lit\n",
+ "R= 0.0821 #lit atm mole^-1\n",
+ "T= 25 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "P1= 760-P\n",
+ "n= P1*V/(760*R*(273+T))\n",
+ "V1= V*1000*P1*273/(760*(T+273))\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Volume of oxygen =\",round(V1),\"ml\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Volume of oxygen = 444.0 ml\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.7 , Page no:27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "t= 20 #min\n",
+ "t1= 19.4 #min\n",
+ "M= 32 #gms\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "x= M*t1**2/t**2\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"molecular weight of ethane =\",round(x,1),\"gms\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "molecular weight of ethane = 30.1 gms\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8 , Page no:28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "R= 8.31*10**7 #ergs mole^-1\n",
+ "T= 27 #C\n",
+ "M= 28 #gram per mole\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "c= math.sqrt(3*R*(273+T)/M)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"root-mean-square velocity =\",'%.2E'%c,\"cm per sec\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "root-mean-square velocity = 5.17E+04 cm per sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9 , Page no:28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "V= 5.16*10**14 #cm per sec\n",
+ "M2= 28 #gms\n",
+ "M1= 2.02 #gms\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "c1= V*math.sqrt(M2/M1)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Velocity of hydrogen molecule =\",'%.2E'%c1,\"cm per sec\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Velocity of hydrogen molecule = 1.92E+15 cm per sec\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.10 , Page no:30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "V= 0.5 #lit\n",
+ "T= 50 #C\n",
+ "n= 1 #mole\n",
+ "R= 0.0821 #lit atm mole^-1\n",
+ "a= 4.28*10**-2 #litres mole^-1\n",
+ "b= 3.6 #arm mole^-2 lit^2\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "P= n*R*(273+T)/V\n",
+ "P1= (n*R*(T+273)/(V-n*a))-(b/V**2)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Pressure =\",round(P),\"atm\";\n",
+ "print\"Pressure using vanderwals equation=\",round(P1,1),\"atm\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pressure = 53.0 atm\n",
+ "Pressure using vanderwals equation= 43.6 atm\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_3_Liquids.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_3_Liquids.ipynb
new file mode 100755
index 00000000..e589391c
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_3_Liquids.ipynb
@@ -0,0 +1,187 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:84f47f7ae93f6c982452d4c53be5733b0b8b9bf3c7cc9f667f87ed399062760f"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3 Liquids"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1 , Page no:41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "p= 388.6 #mm\n",
+ "p1=26.5 #mm\n",
+ "T= 60 #C\n",
+ "R= 1.99 #cal mole^-1 A^-1\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "Lv= math.log10(p/p1)*2.303*R*273*(273+T)/(T)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"heat of vapourisation of benzene=\",round(Lv+2),\"cal per mole\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "heat of vapourisation of benzene= 8100.0 cal per mole\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.2 , Page no:52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "d= 0.789 #gram per cc\n",
+ "r= 0.010 #cm\n",
+ "h= 5.76 #cm\n",
+ "g= 980.7 # cm /sec^2\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "R= d*h*r*g/2\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Surface tension=\",round(R,1),\" dynes per cm\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Surface tension= 22.3 dynes per cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3 , Page no:56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "W= 0.220 #gms\n",
+ "g= 980.7 #cm per sec62\n",
+ "f= 0.98\n",
+ "l= 4 #cm\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "T= W*g/(2*l)\n",
+ "Tc= T*f\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"apparent surface tension=\",round(T,1),\"dynes per cm\";\n",
+ "print\"exact surface tension=\",round(Tc,1),\"dynes per cm\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "apparent surface tension= 27.0 dynes per cm\n",
+ "exact surface tension= 26.4 dynes per cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.4 , Page no:60"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "n2= 10.05*10**-3 #poise\n",
+ "d1= 0.879 #gms cm^-3\n",
+ "t= 88 #sec\n",
+ "d2= 1 #gms cm^-3\n",
+ "t1= 120 #sec\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "n1= d1*t/(d2*t1)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"relative viscosity=\",round(n1,3);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "relative viscosity= 0.645\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_4_Solutions_Nonelectrolytes.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_4_Solutions_Nonelectrolytes.ipynb
new file mode 100755
index 00000000..f47af062
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_4_Solutions_Nonelectrolytes.ipynb
@@ -0,0 +1,323 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c9e8da29a8440e975754a29059a824b6033c61928946b613eef6ef10fe3505be"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4:Solutions Nonelectrolytes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1 , Page no:69"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "m= 164.2 #gms\n",
+ "M= 60 #gms\n",
+ "V= 0.8 #lit\n",
+ "d= 1.026 #g/cc\n",
+ "mw= 18.02 #gms\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "M1= m/M\n",
+ "n= M1/V\n",
+ "G= V*1000*d\n",
+ "G1= G-m\n",
+ "m1= M1*1000/G1\n",
+ "n1= G1/mw\n",
+ "x= M1/(M1+n1)\n",
+ "y= 1-x\n",
+ "p= x*100\n",
+ "p1= y*100\n",
+ "P2= m*100/G\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"molarity=\",round(n,3),\"M\";\n",
+ "print\"molality=\",round(m1,3),\"m\";\n",
+ "print\"mole fraction of solute=\",round(x,4);\n",
+ "print\"mol per cent of solute=\",round(p,2),\"per cent\";\n",
+ "print\"mol per cent of solvent=\",round(p1,2),\"per cent\";\n",
+ "print\"mol per cent acetic acid by weight=\",round(P2,2),\"per cent\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "molarity= 3.421 M\n",
+ "molality= 4.168 m\n",
+ "mole fraction of solute= 0.0699\n",
+ "mol per cent of solute= 6.99 per cent\n",
+ "mol per cent of solvent= 93.01 per cent\n",
+ "mol per cent acetic acid by weight= 20.0 per cent\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2 , Page no:72"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "m= 0.0346 #gms\n",
+ "V= 800 #ml\n",
+ "P= 742 #mm\n",
+ "M= 32 #gms\n",
+ "p= 400 #mm\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "c= m*1000/V\n",
+ "g= c*760/(P*M)\n",
+ "K= g*22.4\n",
+ "k= c/P\n",
+ "c1= k*p\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"concentration of oxygen=\",round(c,4),\"gram per litre\";\n",
+ "print\"moles dissolved =\",round(g,4),\"moles\";\n",
+ "print\"Bunsen absorption =\",round(K,4),\"litre\";\n",
+ "print\"grams of oxygen dissolved =\",round(c1,4),\"gram per litre\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "concentration of oxygen= 0.0433 gram per litre\n",
+ "moles dissolved = 0.0014 moles\n",
+ "Bunsen absorption = 0.031 litre\n",
+ "grams of oxygen dissolved = 0.0233 gram per litre\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3 , Page no:74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "mn= 0.0134 #gms\n",
+ "mo= 0.0261 #gms\n",
+ "mh= 0.0081 #gms\n",
+ "T= 30 #C\n",
+ "P= 3 #atm\n",
+ "r= 4/5\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "V= mn*(273+T)*1000/273\n",
+ "V1= V*r\n",
+ "V2= V1*P\n",
+ "V3= mo*(273+T)*(1-r)*P*1000/273\n",
+ "V4= mh*(273+T)*r*1000/273\n",
+ "V5= V4*P\n",
+ "V6= V2-V1\n",
+ "V7= V5-V4\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"volume of oxygen=\",round(V,1),\"ml\";\n",
+ "print\"volume of nitrogen=\",round(V3,1),\"ml\";\n",
+ "print\"volume of helium =\",round(V5,1),\"ml\";\n",
+ "print\"volume of nitrogen and helium would be expelled =\",round(V7,1),\"ml\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "volume of oxygen= 14.9 ml\n",
+ "volume of nitrogen= 17.4 ml\n",
+ "volume of helium = 21.6 ml\n",
+ "volume of nitrogen and helium would be expelled = 14.4 ml\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4 , Page no:78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "p= 214 #mm\n",
+ "M= 112.5 #gms\n",
+ "m= 18 #gms\n",
+ "m1= 10 #gms\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "P= 760-p\n",
+ "M1= m1*P*m/(p*M)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"quantity of water=\",round(M1,2),\"gms\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "quantity of water= 4.08 gms\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.5 , Page no:81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "p = 17.4 #mm\n",
+ "m= 1000 #gms\n",
+ "M= 18 #gms\n",
+ "n= 2 #moles\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "P= p*((m/M)/((m/M)+n))\n",
+ "P1= p*(n/((m/M)+n))\n",
+ "dp= p-P1\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"vapour pressure of solution=\",round(P1,2),\"mm\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "vapour pressure of solution= 0.6 mm\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6 , Page no:81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "m= 92.13 #gms\n",
+ "M= 78.11 #gms\n",
+ "n= 1 #moles\n",
+ "p= 119.6 #mm\n",
+ "p1= 36.7 #mm\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "n1= m/M\n",
+ "x= n/(n+n1)\n",
+ "y= 1-x\n",
+ "P= y*p\n",
+ "P1= x*p1\n",
+ "P2= P+P1\n",
+ "m1= P/P2\n",
+ "m2= 1-m1\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"mole fraction of benzene=\",round(m1,3);\n",
+ "print\"mole fraction of toulene=\",round(m2,3);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "mole fraction of benzene= 0.794\n",
+ "mole fraction of toulene= 0.206\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_5_Solutions_Osmotic_Pressure.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_5_Solutions_Osmotic_Pressure.ipynb
new file mode 100755
index 00000000..6e73e7eb
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_5_Solutions_Osmotic_Pressure.ipynb
@@ -0,0 +1,104 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c691dcfcd6a933ac6eb12c1a2c163c1c058e6d87ac693062ccdbd8eadc2a939c"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5 Solutions Osmotic Pressure"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.1 , Page no:108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "T= 20 #C\n",
+ "R= 0.082 #li-atm per mole per degree\n",
+ "V= 2 #lit\n",
+ "m= 6 #gms\n",
+ "M= 60 #gms\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "P= m*R*(273+T)/(M*V)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"osmotic pressure=\",round(P,1),\"atm\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "osmotic pressure= 1.2 atm\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2 , Page no:110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "T= -0.2 #C\n",
+ "T1= 25 #C\n",
+ "T2= 1.86 #C\n",
+ "R= 0.082 #li-atm per mole per degree\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "P= -T*R*(T1+273)/T2\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"osmotic pressure=\",round(P,2),\"atm\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "osmotic pressure= 2.63 atm\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_6_Solutions_Solutions_of_Electrolytes.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_6_Solutions_Solutions_of_Electrolytes.ipynb
new file mode 100755
index 00000000..3233c91e
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_6_Solutions_Solutions_of_Electrolytes.ipynb
@@ -0,0 +1,113 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:615c987d5bead694f67f7a47e75e92641b71f2464c202bc4e803e1f6cd3c5a16"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6 Solutions Solutions of Electrolytes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1 , Page no:126"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "T= 25 #C\n",
+ "R= 0.0821 #li-atm per mole per degree\n",
+ "M= 0.5 #m\n",
+ "n= 2\n",
+ "m= 0.680\n",
+ "V= 1 #lit\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "P= R*(273+T)*M*n*m/V\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"osmotic pressure=\",round(P,2),\"atm\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "osmotic pressure= 16.64 atm\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2 , Page no:127"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "M= 0.001 #molar\n",
+ "M1= 0.002 #molar\n",
+ "M2= 0.004 #molar\n",
+ "n= 1 #moles\n",
+ "n1= 2 #moles\n",
+ "v= 0.509\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "Is= 0.5*(M*n**2+M1*n**2+M1*n1**2+M2*n**2)\n",
+ "r= 10**(-v*n**2*math.sqrt(Is))*M\n",
+ "r1= 10**(-v*n1**2*math.sqrt(Is))*M1\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"ionic strength=\",round(Is,3);\n",
+ "print\"activity of sodium =\",round(r,4),\"molar\";\n",
+ "print\"activity of barium =\",round(r1,4),\"molar\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ionic strength= 0.007\n",
+ "activity of sodium = 0.0009 molar\n",
+ "activity of barium = 0.0013 molar\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_7_Conductivity.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_7_Conductivity.ipynb
new file mode 100755
index 00000000..7f108101
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_7_Conductivity.ipynb
@@ -0,0 +1,261 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3731c6f71e2a937d4957bf750203283410e0f63629387e2d184d88571f207fff"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7 Conductivity"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1 , Page no:139"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "R= 10 #ohms\n",
+ "V= 5 #v\n",
+ "t= 20 #min\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "I= V/R\n",
+ "Q= I*t*60\n",
+ "E= Q*V\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"current=\",round(I),\"amp\";\n",
+ "print\"coloumbs of electricity will pass=\",round(Q),\"coloumbs\";\n",
+ "print\"energy expended=\",round(E),\"joules\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "current= 1.0 amp\n",
+ "coloumbs of electricity will pass= 600.0 coloumbs\n",
+ "energy expended= 3000.0 joules\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2 , Page no:143"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "I= 50 #amp\n",
+ "t= 1 #hr\n",
+ "F= 96500 #amp-sec\n",
+ "mh= 1.01 #gms\n",
+ "mc= 35.46 #gms\n",
+ "ms= 107.88 #gms\n",
+ "mb= 79.9 #gms\n",
+ "mf= 55.85 #gms\n",
+ "V= 11.2 #lit\n",
+ "e= 8 #v\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "N= I*t*60*60/F\n",
+ "Mh= mh*N\n",
+ "Mc= mc*N\n",
+ "Ms= ms*N\n",
+ "Mb= mb*N\n",
+ "Mf= mf*N\n",
+ "v= N*V\n",
+ "E= e*I*60*60\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"quantity of hydrogen produced=\",round(Mh,2),\"gms\";\n",
+ "print\"quantity of chlorine produced=\",round(Mc,2),\"gms\";\n",
+ "print\"quantity of silver produced=\",round(Ms,2),\"gms\";\n",
+ "print\"quantity of bromine produced=\",round(Mb,2),\"gms\";\n",
+ "print\"quantity of ferrous ion produced=\",round(Mf,2),\"gms\";\n",
+ "print\"Volume occupied by gases=\",round(v,2),\"lit\";\n",
+ "print\"energy expenditure=\",round(E),\"joules\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "quantity of hydrogen produced= 1.88 gms\n",
+ "quantity of chlorine produced= 66.14 gms\n",
+ "quantity of silver produced= 201.23 gms\n",
+ "quantity of bromine produced= 149.04 gms\n",
+ "quantity of ferrous ion produced= 104.18 gms\n",
+ "Volume occupied by gases= 20.89 lit\n",
+ "energy expenditure= 1440000.0 joules\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3 , Page no:144"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "i= 20 #amp\n",
+ "t= 50 #/min\n",
+ "F= 96500 #coloumb\n",
+ "we= 8 #gms\n",
+ "Mo= 32 #/gms\n",
+ "M= 27 #gms\n",
+ "n= 3\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "nf= i*t*60/F\n",
+ "V= we*22.4/Mo*nf\n",
+ "G= M/n\n",
+ "q= G*nf\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"volume of oxygen produced=\",round(V,2),\"lit\";\n",
+ "print\"quantity of aluminium produced=\",round(q,2),\"grams\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "volume of oxygen produced= 3.48 lit\n",
+ "quantity of aluminium produced= 5.6 grams\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.4 , Page no:148"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "L= 0.025 #ohms\n",
+ "k= 0.0112 #ohms\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "C= k/L\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"cell constant=\",round(C,3);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "cell constant= 0.448\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5 , Page no:150"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "m= 0.01 #M\n",
+ "CB= 235 #mm\n",
+ "R= 426.3 #ohms\n",
+ "M= 265 \n",
+ "C= 0.448\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "k= M*C/(R*CB)\n",
+ "A= k*1000/m\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"equivalent conductance=\",round(A,1),\"ohms\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "equivalent conductance= 118.5 ohms\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_8_Chemical_Equlibrium.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_8_Chemical_Equlibrium.ipynb
new file mode 100755
index 00000000..9d996b4d
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_8_Chemical_Equlibrium.ipynb
@@ -0,0 +1,236 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:979be99f782b9e96d5c91c71d16d98b4d3114044e9cfea33a19906379e1d8fd0"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8 Chemical Equlibrium"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.1 , Page no:164"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "x= 3.33\n",
+ "n= 5 #moles\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "N= x**2/(n-x)**2\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"moles of water and ester formed=\",round(N);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "moles of water and ester formed= 4.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2 , Page no:165"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "n= 1 #mole\n",
+ "x= 3\n",
+ "y= 4\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "r= x**2/n**2\n",
+ "z= n/x\n",
+ "n= n+z\n",
+ "n1= x-z\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"moles of acid and alcohol=\",round(n,2),\"moles\";\n",
+ "print\"moles of ester and water=\",round(n1,2),\"moles\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "moles of acid and alcohol= 1.33 moles\n",
+ "moles of ester and water= 2.67 moles\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3 , Page no:165"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "k= 1.1*10**-5\n",
+ "V= 600 #ml\n",
+ "n= 0.4 #mole\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "m= n*1000/V\n",
+ "x= (-k+math.sqrt(k**2+4*4*0.67*k))/(2*4)\n",
+ "M= 2*x\n",
+ "P= x*100/m\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"molar concentration of NO2=\",'%.2E'%M,\"mol per litre\";\n",
+ "print\"per cent dissociation=\",round(P,2),\"per cent\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "molar concentration of NO2= 2.71E-03 mol per litre\n",
+ "per cent dissociation= 0.2 per cent\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4 , Page no:167"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "pno2= 0.31 #atm\n",
+ "pn2o2= 0.69 #atm\n",
+ "p= 10 #atm\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "Kp= pno2**2/pn2o2\n",
+ "x= (-Kp+math.sqrt(Kp**2+4*4*p*Kp))/(2*4)\n",
+ "p1= p-x\n",
+ "p2= 2*x\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Kp=\",round(Kp,2);\n",
+ "print\"N2O4=\",round(p1,2);\n",
+ "print\"NO2=\",round(p2,2);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Kp= 0.14\n",
+ "N2O4= 9.43\n",
+ "NO2= 1.15\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.5 , Page no:172"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "T= 65 #C\n",
+ "R= 1.98 #cal/mol K\n",
+ "kp= 2.8\n",
+ "kp1= 0.141\n",
+ "T1= 25 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "H= math.log10(kp/kp1)*2.303*R*(273+T1)*(273+T)/(T-T1)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"average heat of reaction=\",round(H+62),\"cal\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "average heat of reaction= 14965.0 cal\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_9_Ionic_Equilibria_and_Buffer_Action.ipynb b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_9_Ionic_Equilibria_and_Buffer_Action.ipynb
new file mode 100755
index 00000000..70140b45
--- /dev/null
+++ b/Fundamentals_Of_Physical_Chemistry_by_H._D._Crockford,_Samuel_B.Knight/Chapter_9_Ionic_Equilibria_and_Buffer_Action.ipynb
@@ -0,0 +1,776 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1207755484910daee1073e3d65ecb3534a4362bdebc5f8d9a33ebf34b5c61963"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9 Ionic Equilibria and Buffer Action"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.1 , Page no:182"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "c= 0.1 #M\n",
+ "p= 1.34 #per cent\n",
+ "T= 25 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "C1= c*p/100\n",
+ "C2= c*p/100\n",
+ "C3= c-C1\n",
+ "Ka= C1*C2/C3\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"ionization constant =\",'%.2E'%Ka;"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ionization constant = 1.82E-05\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.2 , Page no:184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "k= 1.8*10**-5\n",
+ "C= 0.2 #M\n",
+ "T= 25 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "x= math.sqrt(C*k)\n",
+ "a= x/C\n",
+ "C1= a*C\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"hydronium-ion concentration =\",'%.2E'%C1,\"mole per litre\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "hydronium-ion concentration = 1.90E-03 mole per litre\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3 , Page no:185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "K= 1.8*10**-5\n",
+ "V= 500 #ml\n",
+ "c1= 0.3 #M\n",
+ "c2= 0.2 #M\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "x= V*c1/1000\n",
+ "y= V*c2/1000\n",
+ "C= K*y/x\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"hydronium-ion concentration =\",'%.2E'%C,\"mole per litre\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "hydronium-ion concentration = 1.20E-05 mole per litre\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4 , Page no:186"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "K= 1.4*10**-5\n",
+ "T= 25 #C\n",
+ "V= 200 #ml\n",
+ "m= 3.7 #gms\n",
+ "m1= 4.8 #gms\n",
+ "M= 74 #gms\n",
+ "M1= 96 #gms\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "x= m*1000/(V*M)\n",
+ "y= m1*1000/(V*M1)\n",
+ "X= K*x/y\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"hydronium-ion concentration =\",'%.2E'%X,\"mole per litre\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "hydronium-ion concentration = 1.40E-05 mole per litre\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5 , Page no:188"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "c= 0.050 #M\n",
+ "Ksp= 4.3*10**-7\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "C= math.sqrt(Ksp*c)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"concentration of hydronium-ion =\",'%.1E'%C,\"mole per litre\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "concentration of hydronium-ion = 1.5E-04 mole per litre\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6 , Page no:189"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "C= 0.050 #M\n",
+ "K= 2.4*10**-17\n",
+ "c= 0.1 #M\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "c1= K*C/c**2\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"concentration of carbonate-ion =\",'%.1E'%c1,\"mole per litre\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "concentration of carbonate-ion = 1.2E-16 mole per litre\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.7 , Page no:192"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "n= 1.31*10**-4 #mole\n",
+ "T= 25 #C\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "N= 2*n\n",
+ "Ksp= N**2*n\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"Ksp =\",'%.1E'%Ksp;"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ksp = 9.0E-12\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.8 , Page no:193"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "Ksp= 1.4*10**-11\n",
+ "V= 200 #ml\n",
+ "M= 24.3 #/gms\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "x= (Ksp/4)**(1/3)\n",
+ "m= x*M*V/1000\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"grams of Mg+2 present =\",'%.1E'%m,\"gms per mol\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "grams of Mg+2 present = 7.4E-04 gms per mol\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9 , Page no:193"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "c= 0.010 #M\n",
+ "Ksp= 1.56*10**-10\n",
+ "M= 108 #gms\n",
+ "C= 10**-3 #M\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "K= Ksp/C\n",
+ "m= M*K\n",
+ "m1= M*c\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"quantity =\",'%.2E'%m,\"gms\";\n",
+ "print\"quantity =\",round(m1,2),\"gms\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "quantity = 1.68E-05 gms\n",
+ "quantity = 1.08 gms\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.10 , Page no:199"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "c= 0.1 #M\n",
+ "Kb= 1.8*10**-5\n",
+ "Kw= 10**-14\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "C= math.sqrt(c*Kw/Kb)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"concentration of hydronium ion =\",'%.2E'%C,\"mol per litre\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "concentration of hydronium ion = 7.45E-06 mol per litre\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.11 , Page no:201"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "c= 0.050 #M\n",
+ "Kb= 1.8*10**-5\n",
+ "T= 25 #C\n",
+ "Kw= 10**-14\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "C= math.sqrt(Kw*c/Kb)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"concentration of hydronium ion =\",'%.2E'%C,\"mol per litre\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "concentration of hydronium ion = 5.27E-06 mol per litre\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.12 , Page no:203"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "kw= 10**-14\n",
+ "Ka= 1.8*10**-5\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "Kb= Ka\n",
+ "B= math.sqrt(kw/(Ka*Kb))\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"degree of hydrolysis =\",'%.2E'%B;"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "degree of hydrolysis = 5.56E-03\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.13 , Page no:205"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "k1= 3.5*10**-7\n",
+ "k2= 4.4*10**-11\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "c= math.sqrt(k1*k2)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"concentration of solution =\",'%.2E'%c,\"mol per litre\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "concentration of solution = 3.92E-09 mol per litre\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.14 , Page no:207"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "c= 1.92*10**-5 #mole per litre\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "pH= -math.log10(c)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"pH of solution =\",round(pH,2);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pH of solution = 4.72\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.15 , Page no:208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "pH= 7.36\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "C= 10**-pH\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"concentration of solution =\",'%.2E'%C,\"mol per litre\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "concentration of solution = 4.37E-08 mol per litre\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.16 , Page no:210"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "c= 1 #M\n",
+ "Kb= 5.3*10**-5\n",
+ "pKw= 14\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "pH= pKw+0.5*math.log10(Kb)+0.5*math.log10(c)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"pH of solution =\",round(pH,2);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pH of solution = 11.86\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.17 , Page no:211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "c= 0.1 #M\n",
+ "Ka= 6.3*10**-5\n",
+ "pKw= 14\n",
+ "#CALCULATIONS\n",
+ "pH= -0.5*math.log10(Ka)+0.5*pKw+0.5*math.log10(c)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"pH of a buffer solution =\",round(pH,2);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pH of a buffer solution = 8.6\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.18 , Page no:214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "Ka= 1.8*10**-5\n",
+ "a= 0.1 #molar\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "pH= -math.log10(Ka)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"pH of a buffer solution =\",round(pH,2);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pH of a buffer solution = 4.74\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.19 , Page no:214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "pH= 7.10\n",
+ "pH1= 7.21\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "r= 10**(pH-pH1)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"ratio of salt to acid =\",round(r,2);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ratio of salt to acid = 0.78\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Gas_Dynamics_and_Jet_Propulsion/README.txt b/Gas_Dynamics_and_Jet_Propulsion/README.txt
new file mode 100755
index 00000000..bc9ec217
--- /dev/null
+++ b/Gas_Dynamics_and_Jet_Propulsion/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Alpesh Makwana
+Course: bca
+College/Institute/Organization: Zealous web technologies
+Department/Designation: Developer
+Book Title: Gas Dynamics and Jet Propulsion
+Author: P. Murugaperumal
+Publisher: Scitech Publications, Chennai
+Year of publication: 2005
+Isbn: 8188429937
+Edition: 1 \ No newline at end of file
diff --git a/Integrated_Circuits/README.txt b/Integrated_Circuits/README.txt
new file mode 100755
index 00000000..1372a8f0
--- /dev/null
+++ b/Integrated_Circuits/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Shubham Rungta
+Course: btech
+College/Institute/Organization: ABES Engineering College
+Department/Designation: Computer Science and Engineerin
+Book Title: Integrated Circuits
+Author: P. Raja
+Publisher: Umesh Publication
+Year of publication: 2010
+Isbn: 978-93-80117-36-2
+Edition: 2 \ No newline at end of file
diff --git a/Microprocessor_Architecture,_Programming_&_Applications_with_the_8085/README.txt b/Microprocessor_Architecture,_Programming_&_Applications_with_the_8085/README.txt
new file mode 100755
index 00000000..02375896
--- /dev/null
+++ b/Microprocessor_Architecture,_Programming_&_Applications_with_the_8085/README.txt
@@ -0,0 +1,10 @@
+Contributed By: sriraga p
+Course: be
+College/Institute/Organization: Cbit
+Department/Designation: cse
+Book Title: Microprocessor Architecture, Programming & Applications with the 8085
+Author: R. S. Goankar
+Publisher: Penram International, Mumbai
+Year of publication: 1999
+Isbn: 978-81-900828-7-7
+Edition: 4 \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++/README.txt b/Object-Oriented_Programming_in_C++/README.txt
new file mode 100755
index 00000000..58862574
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Aman Kumar Jain
+Course: btech
+College/Institute/Organization: National Institute of Technology Meghalaya
+Department/Designation: Computer Science & Engineering
+Book Title: Object-Oriented Programming in C++
+Author: Robert Lafore
+Publisher: Pearson India
+Year of publication: 2008
+Isbn: 9788131722824
+Edition: Fourth \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++/screenshots/Caption-2.png b/Object-Oriented_Programming_in_C++/screenshots/Caption-2.png
new file mode 100755
index 00000000..baa28450
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++/screenshots/Caption-2.png
Binary files differ
diff --git a/Object-Oriented_Programming_in_C++/screenshots/Caption-3.png b/Object-Oriented_Programming_in_C++/screenshots/Caption-3.png
new file mode 100755
index 00000000..9e07dff0
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++/screenshots/Caption-3.png
Binary files differ
diff --git a/Object-Oriented_Programming_in_C++/screenshots/Caption.png b/Object-Oriented_Programming_in_C++/screenshots/Caption.png
new file mode 100755
index 00000000..541ebbaf
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++/screenshots/Caption.png
Binary files differ
diff --git a/Object-Oriented_Programming_in_C++/screenshots/Caption2.png b/Object-Oriented_Programming_in_C++/screenshots/Caption2.png
new file mode 100755
index 00000000..f9e482c9
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++/screenshots/Caption2.png
Binary files differ
diff --git a/Object-Oriented_Programming_in_C++/screenshots/Caption3.png b/Object-Oriented_Programming_in_C++/screenshots/Caption3.png
new file mode 100755
index 00000000..ee38072e
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++/screenshots/Caption3.png
Binary files differ
diff --git a/Object-Oriented_Programming_in_C++/screenshots/caption-1.png b/Object-Oriented_Programming_in_C++/screenshots/caption-1.png
new file mode 100755
index 00000000..f3dcbe9b
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++/screenshots/caption-1.png
Binary files differ
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter10Pointers.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter10Pointers.ipynb
new file mode 100755
index 00000000..02f927b8
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter10Pointers.ipynb
@@ -0,0 +1,1464 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c2567ccef170e76f122505b3516db5eb25f7ed3b0c22bde2bb3ba546dad6d2f0"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10: Pointers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.1, Page Number 431"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "var1 = 11 #define and initialize three variables\n",
+ "var2 = 22\n",
+ "var3 = 33\n",
+ "\n",
+ "print hex(id(var1)) #print the address of these variables\n",
+ "print hex(id(var2))\n",
+ "print hex(id(var3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0x6b5fd8L\n",
+ "0x6b5ed0L\n",
+ "0x6b5dc8L\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.2, Page Number 433"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "var1 = c_int(11) #two integer variables\n",
+ "var2 = c_int(22)\n",
+ "\n",
+ "print hex(id(var1)),'\\n',hex(id(var2)),'\\n' #print addresses of variables\n",
+ "\n",
+ "ptr = pointer(var1) #pointer to integer variable var1\n",
+ "print hex(addressof(ptr)) #print address of ptr\n",
+ "\n",
+ "ptr = pointer(var2) #pointer to integer variable var2\n",
+ "print hex(addressof(ptr)) #print address of ptr\n",
+ "\n",
+ "#in python, id(a) != addressof(pinter(a))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0x3678448L \n",
+ "0x3678848L \n",
+ "\n",
+ "0x3678790L\n",
+ "0x3678690L\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.3, Page Number 436"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "var1 = c_int(11) #two integer variables\n",
+ "var2 = c_int(22)\n",
+ "\n",
+ "ptr = pointer(var1) #pointer to integer variable var1\n",
+ "print ptr[0] #print contents of pointer (11)\n",
+ "\n",
+ "ptr = pointer(var2) #pointer to integer variable var2\n",
+ "print ptr[0] #print contents of pointer (22)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11\n",
+ "22\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.4, Page Number 437"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "var1 = c_int() #integer variable\n",
+ "\n",
+ "ptr = pointer(var1) #set pointer to address of var1\n",
+ "ptr[0] = c_int(37) #same as var1 = 37\n",
+ "var2 = ptr[0] #same as var2 = var1\n",
+ "\n",
+ "print var2 #verify var2 is 37"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "37\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.5, Page Number 439"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "intvar = c_int() #define integer variable\n",
+ "flovar = c_float() #define float variable\n",
+ "\n",
+ "ptrint = pointer(intvar)\n",
+ "ptrflo = pointer(flovar)\n",
+ "ptrvoid = pointer(intvar)\n",
+ "ptrvoid = pointer(flovar)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.6, Page Number 440"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "intarray = [31,54,77,52,93] #array\n",
+ "\n",
+ "for j in range(5): #for each element\n",
+ " print intarray[j] #print value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "31\n",
+ "54\n",
+ "77\n",
+ "52\n",
+ "93\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.7, Page Number 441"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import ctypes\n",
+ "\n",
+ "intarray = [31,54,77,52,93] #array\n",
+ "\n",
+ "arr = (ctypes.c_int * len(intarray))(*intarray) #pointer to intarray\n",
+ "\n",
+ "for j in range(5): #for each element\n",
+ " print arr[0 + j] #print value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "31\n",
+ "54\n",
+ "77\n",
+ "52\n",
+ "93\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.8, Page Number 443"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import ctypes\n",
+ "\n",
+ "intarray = [31,54,77,52,93] #array\n",
+ "\n",
+ "arr = (ctypes.c_int * len(intarray))(*intarray) #pointer to intarray\n",
+ "\n",
+ "for j in range(5): #for each element\n",
+ " print arr[0 + j] #print value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "31\n",
+ "54\n",
+ "77\n",
+ "52\n",
+ "93\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.9, Page Number 443"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def centimize(v):\n",
+ " v *= 2.54 #convert inches to centimeters\n",
+ " return v\n",
+ "\n",
+ "var = 10.0 #var has value of 10 inches\n",
+ "print 'var =',var,'inches'\n",
+ "\n",
+ "var = centimize(var) #change variable var to centimeters\n",
+ "print 'var =',var,'centimeters'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "var = 10.0 inches\n",
+ "var = 25.4 centimeters\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.10, Page Number 444"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "def centimize(ptrd):\n",
+ " ptrd[0] *= 2.54 #ptrd[0] is the same as var\n",
+ " \n",
+ "var = 10.0 #var has value of 10 inches\n",
+ "print 'var =',var,'inches'\n",
+ "\n",
+ "var = c_float(10.0)\n",
+ "\n",
+ "centimize(pointer(var)) #change variable var to centimeters\n",
+ "print 'var =',var,'centimeters'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "var = 10.0 inches\n",
+ "var = c_float(25.399999618530273) centimeters\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.11, Page Number 446"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 5 #number of array element\n",
+ "\n",
+ "def centimize(ptrd):\n",
+ " for j in range(MAX):\n",
+ " ptrd[0+j] *= 2.54 #ptrd points to elements of array\n",
+ "\n",
+ "varray = [10.0,43.1,95.9,59.7,87.3]\n",
+ "\n",
+ "centimize(varray) #change elements of array to cm\n",
+ "\n",
+ "for j in range(MAX): #display new array values\n",
+ " print 'varray[%d]=%.3f centimeter' %(j,varray[j])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "varray[0]=25.400 centimeter\n",
+ "varray[1]=109.474 centimeter\n",
+ "varray[2]=243.586 centimeter\n",
+ "varray[3]=151.638 centimeter\n",
+ "varray[4]=221.742 centimeter\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.12, Page Number 448"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def order(numb1 ,numb2): #orders two numbers\n",
+ " if numb1[0] > numb2[0]: #if 1st larger than 2nd\n",
+ " temp = numb1[0] #swap them\n",
+ " numb1[0] = numb2[0]\n",
+ " numb2[0] = temp\n",
+ " \n",
+ " \n",
+ "n1 = c_int(99);n2 = c_int(11) #one pair ordered, one not\n",
+ "n3 = c_int(22);n4 = c_int(88)\n",
+ "\n",
+ "order(pointer(n1) , pointer(n2)) #order each pair of numbers\n",
+ "order(pointer(n3) , pointer(n4))\n",
+ "\n",
+ "print 'n1 =',n1 #print out all numbers\n",
+ "print 'n2 =',n2\n",
+ "print 'n3 =',n3\n",
+ "print 'n4 =',n4"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n1 = c_long(11)\n",
+ "n2 = c_long(99)\n",
+ "n3 = c_long(22)\n",
+ "n4 = c_long(88)\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.13, Page Number 449"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "def order(numb1 ,numb2): #orders two numbers\n",
+ " if numb1 > numb2: #if 1st larger than 2nd\n",
+ " temp = numb1 #swap them\n",
+ " numb1 = numb2\n",
+ " numb2 = temp\n",
+ " return numb1,numb2\n",
+ " \n",
+ " \n",
+ "def bsort(ptr,n):\n",
+ " for j in range(n-1): #outer loop\n",
+ " for k in range(j+1,n,1): #inner loop starts at outer\n",
+ " ptr[j] ,ptr[k] = order(ptr[j] ,ptr[k]) #order the contents\n",
+ " \n",
+ " \n",
+ " \n",
+ "N = 10 #array size\n",
+ "\n",
+ "arr = [37,84,62,91,11,65,57,28,19,49] #test array\n",
+ "\n",
+ "bsort(arr,N) #sort the array\n",
+ "\n",
+ "for j in range(N): #print out sorted array\n",
+ " print arr[j],'',\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11 19 28 37 49 57 62 65 84 91 \n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.14, Page Number 452"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str1 = \"Defined as an array\" #two strings\n",
+ "str2 = \"Defined as a pointer\"\n",
+ "\n",
+ "print str1 #display both string\n",
+ "print str2\n",
+ "\n",
+ "print str2[1:] #str2 starts from \"efined...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Defined as an array\n",
+ "Defined as a pointer\n",
+ "efined as a pointer\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.15, Page Number 453"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def dispstr(ps):\n",
+ " print ps #display string str through ps\n",
+ " \n",
+ "str = \"Idle people have the least leisure.\" #string\n",
+ "\n",
+ "dispstr(str) #display string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Idle people have the least leisure.\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.16, Page Number 454"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def copystr(dest,src):\n",
+ " dest = src #copy string \n",
+ " return dest\n",
+ "\n",
+ "str1 = \"Self-conquest is the greatest victory.\"\n",
+ "str2 = \"\" #empty string\n",
+ "\n",
+ "str2 = copystr(str2,str1) #copy str1 to str2\n",
+ "\n",
+ "print str2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Self-conquest is the greatest victory.\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.17, Page Number 457"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Days = 7 #number of variables in array\n",
+ "\n",
+ "arrptrs = [\"Sunday\" , \"Monday\" , \"Tuesday\" , \"Wednesday\" , \"Thursday\" , \"Friday\" , \"Saturday\"]\n",
+ "\n",
+ "for j in range(Days): #display every string\n",
+ " print arrptrs[j]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sunday\n",
+ "Monday\n",
+ "Tuesday\n",
+ "Wednesday\n",
+ "Thursday\n",
+ "Friday\n",
+ "Saturday\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.18, Page Number 459"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "str = \"Idle hands are the devil's workshop.\"\n",
+ "strlen = len(str) #get length of str\n",
+ "\n",
+ "ptr = [\"\" for j in range(strlen + 1)] #set aside memory: string + '\\0'\n",
+ "ptr = str #copy str to new memory area ptr\n",
+ " \n",
+ "print 'ptr =',ptr #show that ptr is now in str\n",
+ "\n",
+ "del ptr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ptr = Idle hands are the devil's workshop.\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.19, Page Number 462"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class String: #user-defined string type\n",
+ " def __init__(self,s): #constructor\n",
+ " self.__str = s #copy argument to str\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " print 'Deleting str' #release memory\n",
+ " \n",
+ " def display(self): #display the string\n",
+ " print self.__str\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = String(\"Who knows nothing doubts nothing.\") #uses 1-arg constructor\n",
+ "\n",
+ "print 's1 =', #display string\n",
+ "s1.display()\n",
+ "\n",
+ "del s1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s1 = Who knows nothing doubts nothing.\n",
+ "Deleting str\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.20, Page Number 464"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "class Distance(Structure): #Distance class\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\"\\nEnter feet: \")\n",
+ " self.__inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "dist = Distance() #define a named Disatance object\n",
+ "dist.getdist() #access object member with dot operator\n",
+ "dist.showdist()\n",
+ "\n",
+ "distptr = POINTER(Distance) #points to Distance\n",
+ "\n",
+ "distptr = dist \n",
+ "\n",
+ "distptr.getdist() #access object members\n",
+ "distptr.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter feet: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 6.25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 ' - 6.25 \"\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter feet: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 4.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6 ' - 4.75 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.21, Page Number 466"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "class Distance(Structure): #Distance class\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\"Enter feet: \")\n",
+ " self.__inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "dist = Distance()\n",
+ "distptr = POINTER(Distance)\n",
+ "\n",
+ "distptr = dist \n",
+ "\n",
+ "distptr.getdist()\n",
+ "distptr.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 4.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 ' - 4.75 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.22, Page Number 467"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "class person(Structure): #class of persons\n",
+ " \n",
+ " def setName(self): #set the name\n",
+ " self.__name = raw_input(\"Enter name: \")\n",
+ " \n",
+ " def printName(self): #get the name\n",
+ " print ' Name is :',self.__name\n",
+ " \n",
+ " \n",
+ " \n",
+ "ob = [person() for j in range(100)] #array of persons\n",
+ "persPtr = ob #array to persons\n",
+ "n = 0 #number of persons in array\n",
+ "\n",
+ "\n",
+ "while True: #put persons in array\n",
+ " \n",
+ " persPtr[n].setName() #set person's name\n",
+ " n += 1 #count new person\n",
+ " choice = raw_input('Enter another (y/n)? ') #person ?\n",
+ " \n",
+ " if choice=='n': #quit on 'n'\n",
+ " break\n",
+ " \n",
+ "for j in range(n): #print names of all persons\n",
+ " print 'person number',j+1\n",
+ " persPtr[j].printName()\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Stroustrup\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Ritchie\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Kernighan\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "person number 1\n",
+ " Name is : Stroustrup\n",
+ "person number 2\n",
+ " Name is : Ritchie\n",
+ "person number 3\n",
+ " Name is : Kernighan\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.23, Page Number 469"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class link:\n",
+ " def __init__(self):\n",
+ " self.data = None # contains the data\n",
+ " self.next = None # contains the reference to the next node\n",
+ "\n",
+ "\n",
+ "class linklist:\n",
+ " def __init__(self):\n",
+ " self.first = None\n",
+ "\n",
+ " def additem(self, d): # add data item\n",
+ " newlink = link() # make a new link\n",
+ " newlink.data = d # give it data\n",
+ " newlink.next = self.first # it points to next link\n",
+ " self.first = newlink # now first points to this\n",
+ "\n",
+ " def display(self):\n",
+ " current = self.first # set ptr to first link\n",
+ " while current: # quit on last link\n",
+ " print current.data # print data\n",
+ " current = current.next # move to next link\n",
+ "\n",
+ "\n",
+ " \n",
+ "\n",
+ "li = linklist() # make linked list\n",
+ "\n",
+ "li.additem(25) # add four items to linked list\n",
+ "li.additem(36)\n",
+ "li.additem(49)\n",
+ "li.additem(64)\n",
+ "\n",
+ "li.display() # display entire list"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "64\n",
+ "49\n",
+ "36\n",
+ "25\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.24, Page Number 474"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "def order(numb1 ,numb2): #orders two objects\n",
+ " if numb1.getname() > numb2.getname(): #if the name of 1st larger than 2nd\n",
+ " temp = numb1 #swap them\n",
+ " numb1 = numb2\n",
+ " numb2 = temp\n",
+ " return numb1,numb2\n",
+ " \n",
+ " \n",
+ "def bsort(ptr,n):\n",
+ " for j in range(n-1): #outer loop\n",
+ " for k in range(j+1,n,1): #inner loop starts at outer\n",
+ " ptr[j] ,ptr[k] = order(ptr[j] ,ptr[k]) #order the contents\n",
+ " return ptr\n",
+ "\n",
+ "\n",
+ "class person(Structure): #class of persons\n",
+ " \n",
+ " def setName(self): #set the name\n",
+ " self.__name = raw_input(\"Enter name: \")\n",
+ " \n",
+ " def printName(self): #display the name\n",
+ " print self.__name\n",
+ " \n",
+ " def getname(self): #returns the name\n",
+ " return self.__name\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "ob = [person()]*100 #array of persons\n",
+ "persPtr = POINTER(person) #pointer to person\n",
+ " \n",
+ "persPtr = ob #array of pointers to persons\n",
+ "n = 0 #number of persons in array\n",
+ "\n",
+ "while True: #put persons in array\n",
+ " \n",
+ " persPtr[n] = person()\n",
+ " persPtr[n].setName() #set person's name\n",
+ " \n",
+ " n += 1 #count new person\n",
+ " \n",
+ " choice = raw_input('Enter another (y/n)? ') #person ?\n",
+ " \n",
+ " if choice=='n': #quit on 'n'\n",
+ " break\n",
+ "\n",
+ " \n",
+ "print '\\nUnsorted list:'\n",
+ "for j in range(n): #print names of all persons\n",
+ " persPtr[j].printName()\n",
+ " \n",
+ " \n",
+ "persPtr = bsort(persPtr,n) #sorts the content of array according to their name\n",
+ "\n",
+ "print '\\nSorted list:'\n",
+ "for j in range(n): #print names of all persons\n",
+ " persPtr[j].printName()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Washington\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Adams\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Jefferson\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Madison\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Unsorted list:\n",
+ "Washington\n",
+ "Adams\n",
+ "Jefferson\n",
+ "Madison\n",
+ "\n",
+ "Sorted list:\n",
+ "Adams\n",
+ "Jefferson\n",
+ "Madison\n",
+ "Washington\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.25, Page Number 481"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LEN = 80 #length of expression, in character\n",
+ "MAX = 40 #size of stack\n",
+ "\n",
+ "\n",
+ "class stack:\n",
+ " \n",
+ " def __init__(self):\n",
+ " self.__st = [None]*MAX #stack: array of chars\n",
+ " self.__top = 0 #number of top of stack\n",
+ " \n",
+ " def push(self,var): #put char on stack\n",
+ " self.__top += 1\n",
+ " self.__st[self.__top] = var\n",
+ " \n",
+ " def pop(self): #take char off stack\n",
+ " x = self.__st[self.__top]\n",
+ " self.__top -= 1\n",
+ " return x\n",
+ " \n",
+ " def gettop(self): #get top of stack\n",
+ " return self.__top\n",
+ " \n",
+ " \n",
+ " \n",
+ "class express: #expression class\n",
+ " \n",
+ " def __init__(self,ptr):\n",
+ " \n",
+ " self.__s = stack() #stack for analysis\n",
+ " self.__pStr = ptr #input string\n",
+ " self.__len = len(self.__pStr) #length of input string\n",
+ " \n",
+ " \n",
+ " def parse(self): #add items to stack\n",
+ " \n",
+ " for j in range(self.__len): #for each input character\n",
+ " \n",
+ " ch = self.__pStr[j] #get next character\n",
+ " \n",
+ " if ch >= '0' and ch<='9': #if it's a digit,\n",
+ " self.__s.push(ch) #save the character\n",
+ " \n",
+ " #if it's operator\n",
+ " elif ch == '+' or ch == '-' or ch == '*' or ch == '/':\n",
+ " \n",
+ " if self.__s.gettop() == 1: #if it's first operator\n",
+ " self.__s.push(ch) #put on stack\n",
+ " \n",
+ " else: #not first operator\n",
+ " \n",
+ " lastval = self.__s.pop() #get previous digit \n",
+ " lastop = self.__s.pop() #get previous operator\n",
+ " \n",
+ " \n",
+ " #if this is * or / AND last operator was + or -\n",
+ " if (ch=='*' or ch=='/') and (lastop == '+' or lastop == '-'):\n",
+ " \n",
+ " self.__s.push(lastop) #restore last two pops\n",
+ " self.__s.push(lastval)\n",
+ " \n",
+ " \n",
+ " else: #in all other cases\n",
+ " #do last operation, and push result on stack\n",
+ " \n",
+ " if lastop == '+':\n",
+ " self.__s.push(str(int(self.__s.pop()) + int(lastval)))\n",
+ " \n",
+ " elif lastop == '-':\n",
+ " self.__s.push(str(int(self.__s.pop()) - int(lastval)))\n",
+ " \n",
+ " elif lastop == '*':\n",
+ " self.__s.push(str(int(self.__s.pop()) * int(lastval)))\n",
+ " \n",
+ " elif lastop == '/':\n",
+ " self.__s.push(str(int(int(self.__s.pop()) / int(lastval))))\n",
+ " \n",
+ " else:\n",
+ " print 'Unknown oper'\n",
+ " \n",
+ " \n",
+ " self.__s.push(ch) #put current operator on stack\n",
+ " \n",
+ " \n",
+ " else: #not a known character\n",
+ " \n",
+ " print 'Unkown input character'\n",
+ " \n",
+ " \n",
+ " \n",
+ " def solve(self): #remove items from stack\n",
+ " \n",
+ " while self.__s.gettop() > 1:\n",
+ " \n",
+ " lastval = self.__s.pop() #get previous value\n",
+ " \n",
+ " a = self.__s.pop() #get previous operator\n",
+ " \n",
+ " \n",
+ " #do operation, push answer\n",
+ " if a == '+':\n",
+ " self.__s.push(str(int(self.__s.pop()) + int(lastval)))\n",
+ " \n",
+ " elif a == '-':\n",
+ " self.__s.push(str(int(self.__s.pop()) - int(lastval)))\n",
+ " \n",
+ " elif a == '*':\n",
+ " self.__s.push(str(int(self.__s.pop()) * int(lastval)))\n",
+ " \n",
+ " elif a == '/':\n",
+ " self.__s.push(str(int(int(self.__s.pop()) / int(lastval))))\n",
+ " \n",
+ " else:\n",
+ " print 'Unknown oper'\n",
+ " \n",
+ " \n",
+ " return self.__s.pop() #last item on stack is ans\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "\n",
+ "print 'Enter an arithmetic expression'\n",
+ "print 'of the form 2+3*4/3-2'\n",
+ "print 'No number may have more than one digit.'\n",
+ "print 'Dont\\'t use any spaces or parentheses.' \n",
+ "\n",
+ "while True:\n",
+ " string = raw_input(\"Enter expression: \") #input from user\n",
+ "\n",
+ " eptr = express(string) #make expression\n",
+ "\n",
+ " eptr.parse() #parse it\n",
+ "\n",
+ " print '\\nThe numerical value is: ',eptr.solve() #solve it\n",
+ " \n",
+ " del eptr #delete expression\n",
+ " \n",
+ " ans = raw_input(\"\\n\\nDo another (Enter y or n)? \")\n",
+ " \n",
+ " if ans == 'n':\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an arithmetic expression\n",
+ "of the form 2+3*4/3-2\n",
+ "No number may have more than one digit.\n",
+ "Dont't use any spaces or parentheses.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter expression: 2+3*4/3-2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The numerical value is: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Do another (Enter y or n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter expression: 9+6/3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The numerical value is: 11\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Do another (Enter y or n)? n\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter10Pointers_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter10Pointers_1.ipynb
new file mode 100755
index 00000000..b8be854e
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter10Pointers_1.ipynb
@@ -0,0 +1,1461 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:a9ce3a6d02b8b6b5f7b8e66262461a4e19f31640a5964cf784c373d86d1a2af3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10: Pointers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.1, Page Number 431"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "var1 = 11 #define and initialize three variables\n",
+ "var2 = 22\n",
+ "var3 = 33\n",
+ "\n",
+ "print hex(id(var1)) #print the address of these variables\n",
+ "print hex(id(var2))\n",
+ "print hex(id(var3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0x1bf5fa8L\n",
+ "0x1bf5ea0L\n",
+ "0x1bf5d98L\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.2, Page Number 433"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import c_int,pointer,addressof\n",
+ "\n",
+ "var1 = c_int(11) #two integer variables\n",
+ "var2 = c_int(22)\n",
+ "\n",
+ "print hex(id(var1)),'\\n',hex(id(var2)),'\\n' #print addresses of variables\n",
+ "\n",
+ "ptr = pointer(var1) #pointer to integer variable var1\n",
+ "print hex(addressof(ptr)) #print address of ptr\n",
+ "\n",
+ "ptr = pointer(var2) #pointer to integer variable var2\n",
+ "print hex(addressof(ptr)) #print address of ptr\n",
+ "\n",
+ "#in python, id(a) != addressof(pinter(a))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0x3681448L \n",
+ "0x3681548L \n",
+ "\n",
+ "0x3681790L\n",
+ "0x3681810L\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.3, Page Number 436"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import c_int,pointer\n",
+ "\n",
+ "var1 = c_int(11) #two integer variables\n",
+ "var2 = c_int(22)\n",
+ "\n",
+ "ptr = pointer(var1) #pointer to integer variable var1\n",
+ "print ptr[0] #print contents of pointer (11)\n",
+ "\n",
+ "ptr = pointer(var2) #pointer to integer variable var2\n",
+ "print ptr[0] #print contents of pointer (22)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11\n",
+ "22\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.4, Page Number 437"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import c_int,pointer\n",
+ "\n",
+ "var1 = c_int() #integer variable\n",
+ "\n",
+ "ptr = pointer(var1) #set pointer to address of var1\n",
+ "ptr[0] = c_int(37) #same as var1 = 37\n",
+ "var2 = ptr[0] #same as var2 = var1\n",
+ "\n",
+ "print var2 #verify var2 is 37"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "37\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.5, Page Number 439"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import c_int,pointer,c_float\n",
+ "\n",
+ "intvar = c_int() #define integer variable\n",
+ "flovar = c_float() #define float variable\n",
+ "\n",
+ "ptrint = pointer(intvar)\n",
+ "ptrflo = pointer(flovar)\n",
+ "ptrvoid = pointer(intvar)\n",
+ "ptrvoid = pointer(flovar)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.6, Page Number 440"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "intarray = [31,54,77,52,93] #array\n",
+ "\n",
+ "for j in range(5): #for each element\n",
+ " print intarray[j] #print value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "31\n",
+ "54\n",
+ "77\n",
+ "52\n",
+ "93\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.7, Page Number 441"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import c_int\n",
+ "\n",
+ "intarray = [31,54,77,52,93] #array\n",
+ "\n",
+ "arr = (c_int * len(intarray))(*intarray) #pointer to intarray\n",
+ "\n",
+ "for j in range(5): #for each element\n",
+ " print arr[0 + j] #print value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "31\n",
+ "54\n",
+ "77\n",
+ "52\n",
+ "93\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.8, Page Number 443"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import c_int\n",
+ "\n",
+ "intarray = [31,54,77,52,93] #array\n",
+ "\n",
+ "arr = (c_int * len(intarray))(*intarray) #pointer to intarray\n",
+ "\n",
+ "for j in range(5): #for each element\n",
+ " print arr[0 + j] #print value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "31\n",
+ "54\n",
+ "77\n",
+ "52\n",
+ "93\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.9, Page Number 443"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def centimize(v):\n",
+ " v *= 2.54 #convert inches to centimeters\n",
+ " return v\n",
+ "\n",
+ "var = 10.0 #var has value of 10 inches\n",
+ "print 'var =',var,'inches'\n",
+ "\n",
+ "var = centimize(var) #change variable var to centimeters\n",
+ "print 'var =',var,'centimeters'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "var = 10.0 inches\n",
+ "var = 25.4 centimeters\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.10, Page Number 444"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import c_float,pointer\n",
+ "\n",
+ "def centimize(ptrd):\n",
+ " ptrd[0] *= 2.54 #ptrd[0] is the same as var\n",
+ " \n",
+ "var = 10.0 #var has value of 10 inches\n",
+ "print 'var =',var,'inches'\n",
+ "\n",
+ "var = c_float(10.0)\n",
+ "\n",
+ "centimize(pointer(var)) #change variable var to centimeters\n",
+ "print 'var =',var.value,'centimeters'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "var = 10.0 inches\n",
+ "var = 25.3999996185 centimeters\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.11, Page Number 446"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 5 #number of array element\n",
+ "\n",
+ "def centimize(ptrd):\n",
+ " for j in range(MAX):\n",
+ " ptrd[0+j] *= 2.54 #ptrd points to elements of array\n",
+ "\n",
+ "varray = [10.0,43.1,95.9,59.7,87.3]\n",
+ "\n",
+ "centimize(varray) #change elements of array to cm\n",
+ "\n",
+ "for j in range(MAX): #display new array values\n",
+ " print 'varray[%d]=%.3f centimeter' %(j,varray[j])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "varray[0]=25.400 centimeter\n",
+ "varray[1]=109.474 centimeter\n",
+ "varray[2]=243.586 centimeter\n",
+ "varray[3]=151.638 centimeter\n",
+ "varray[4]=221.742 centimeter\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.12, Page Number 448"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import c_int,pointer\n",
+ "\n",
+ "def order(numb1 ,numb2): #orders two numbers\n",
+ " if numb1[0] > numb2[0]: #if 1st larger than 2nd\n",
+ " temp = numb1[0] #swap them\n",
+ " numb1[0] = numb2[0]\n",
+ " numb2[0] = temp\n",
+ " \n",
+ " \n",
+ "n1 = c_int(99);n2 = c_int(11) #one pair ordered, one not\n",
+ "n3 = c_int(22);n4 = c_int(88)\n",
+ "\n",
+ "order(pointer(n1) , pointer(n2)) #order each pair of numbers\n",
+ "order(pointer(n3) , pointer(n4))\n",
+ "\n",
+ "print 'n1 =',n1.value #print out all numbers\n",
+ "print 'n2 =',n2.value\n",
+ "print 'n3 =',n3.value\n",
+ "print 'n4 =',n4.value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n1 = 11\n",
+ "n2 = 99\n",
+ "n3 = 22\n",
+ "n4 = 88\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.13, Page Number 449"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def order(numb1 ,numb2): #orders two numbers\n",
+ " if numb1 > numb2: #if 1st larger than 2nd\n",
+ " temp = numb1 #swap them\n",
+ " numb1 = numb2\n",
+ " numb2 = temp\n",
+ " return numb1,numb2\n",
+ " \n",
+ " \n",
+ "def bsort(ptr,n):\n",
+ " for j in range(n-1): #outer loop\n",
+ " for k in range(j+1,n,1): #inner loop starts at outer\n",
+ " ptr[j] ,ptr[k] = order(ptr[j] ,ptr[k]) #order the contents\n",
+ " \n",
+ " \n",
+ " \n",
+ "N = 10 #array size\n",
+ "\n",
+ "arr = [37,84,62,91,11,65,57,28,19,49] #test array\n",
+ "\n",
+ "bsort(arr,N) #sort the array\n",
+ "\n",
+ "for j in range(N): #print out sorted array\n",
+ " print arr[j],'',\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11 19 28 37 49 57 62 65 84 91 \n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.14, Page Number 452"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str1 = \"Defined as an array\" #two strings\n",
+ "str2 = \"Defined as a pointer\"\n",
+ "\n",
+ "print str1 #display both string\n",
+ "print str2\n",
+ "\n",
+ "print str2[1:] #str2 starts from \"efined...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Defined as an array\n",
+ "Defined as a pointer\n",
+ "efined as a pointer\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.15, Page Number 453"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def dispstr(ps):\n",
+ " print ps #display string str through ps\n",
+ " \n",
+ "str = \"Idle people have the least leisure.\" #string\n",
+ "\n",
+ "dispstr(str) #display string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Idle people have the least leisure.\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.16, Page Number 454"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def copystr(dest,src):\n",
+ " dest = src #copy string \n",
+ " return dest\n",
+ "\n",
+ "str1 = \"Self-conquest is the greatest victory.\"\n",
+ "str2 = \"\" #empty string\n",
+ "\n",
+ "str2 = copystr(str2,str1) #copy str1 to str2\n",
+ "\n",
+ "print str2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Self-conquest is the greatest victory.\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.17, Page Number 457"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Days = 7 #number of variables in array\n",
+ "\n",
+ "arrptrs = [\"Sunday\" , \"Monday\" , \"Tuesday\" , \"Wednesday\" , \"Thursday\" , \"Friday\" , \"Saturday\"]\n",
+ "\n",
+ "for j in range(Days): #display every string\n",
+ " print arrptrs[j]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sunday\n",
+ "Monday\n",
+ "Tuesday\n",
+ "Wednesday\n",
+ "Thursday\n",
+ "Friday\n",
+ "Saturday\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.18, Page Number 459"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str = \"Idle hands are the devil's workshop.\"\n",
+ "strlen = len(str) #get length of str\n",
+ "\n",
+ "ptr = [\"\" for j in range(strlen + 1)] #set aside memory: string + '\\0'\n",
+ "ptr = str #copy str to new memory area ptr\n",
+ " \n",
+ "print 'ptr =',ptr #show that ptr is now in str\n",
+ "\n",
+ "del ptr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ptr = Idle hands are the devil's workshop.\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.19, Page Number 462"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class String: #user-defined string type\n",
+ " def __init__(self,s): #constructor\n",
+ " self.__str = s #copy argument to str\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " print 'Deleting str' #release memory\n",
+ " \n",
+ " def display(self): #display the string\n",
+ " print self.__str\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = String(\"Who knows nothing doubts nothing.\") #uses 1-arg constructor\n",
+ "\n",
+ "print 's1 =', #display string\n",
+ "s1.display()\n",
+ "\n",
+ "del s1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s1 = Who knows nothing doubts nothing.\n",
+ "Deleting str\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.20, Page Number 464"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import POINTER,Structure\n",
+ "\n",
+ "class Distance(Structure): #Distance class\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\"\\nEnter feet: \")\n",
+ " self.__inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "dist = Distance() #define a named Disatance object\n",
+ "dist.getdist() #access object member with dot operator\n",
+ "dist.showdist()\n",
+ "\n",
+ "distptr = POINTER(Distance) #points to Distance\n",
+ "\n",
+ "distptr = dist \n",
+ "\n",
+ "distptr.getdist() #access object members\n",
+ "distptr.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter feet: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 6.25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 ' - 6.25 \"\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter feet: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 4.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6 ' - 4.75 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.21, Page Number 466"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import Structure,POINTER\n",
+ "\n",
+ "class Distance(Structure): #Distance class\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\"Enter feet: \")\n",
+ " self.__inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "dist = Distance()\n",
+ "distptr = POINTER(Distance)\n",
+ "\n",
+ "distptr = dist \n",
+ "\n",
+ "distptr.getdist()\n",
+ "distptr.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 6.25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 ' - 6.25 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.22, Page Number 467"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import Structure\n",
+ "\n",
+ "class person(Structure): #class of persons\n",
+ " \n",
+ " def setName(self): #set the name\n",
+ " self.__name = raw_input(\"Enter name: \")\n",
+ " \n",
+ " def printName(self): #get the name\n",
+ " print ' Name is :',self.__name\n",
+ " \n",
+ " \n",
+ " \n",
+ "ob = [person() for j in range(100)] #array of persons\n",
+ "persPtr = ob #array to persons\n",
+ "n = 0 #number of persons in array\n",
+ "\n",
+ "\n",
+ "while True: #put persons in array\n",
+ " \n",
+ " persPtr[n].setName() #set person's name\n",
+ " n += 1 #count new person\n",
+ " choice = raw_input('Enter another (y/n)? ') #person ?\n",
+ " \n",
+ " if choice=='n': #quit on 'n'\n",
+ " break\n",
+ " \n",
+ "for j in range(n): #print names of all persons\n",
+ " print 'person number',j+1\n",
+ " persPtr[j].printName()\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Stroustrup\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Ritchie\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Kernighan\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "person number 1\n",
+ " Name is : Stroustrup\n",
+ "person number 2\n",
+ " Name is : Ritchie\n",
+ "person number 3\n",
+ " Name is : Kernighan\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.23, Page Number 469"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class link:\n",
+ " def __init__(self):\n",
+ " self.data = None # contains the data\n",
+ " self.next = None # contains the reference to the next node\n",
+ "\n",
+ "\n",
+ "class linklist:\n",
+ " def __init__(self):\n",
+ " self.first = None\n",
+ "\n",
+ " def additem(self, d): # add data item\n",
+ " newlink = link() # make a new link\n",
+ " newlink.data = d # give it data\n",
+ " newlink.next = self.first # it points to next link\n",
+ " self.first = newlink # now first points to this\n",
+ "\n",
+ " def display(self):\n",
+ " current = self.first # set ptr to first link\n",
+ " while current: # quit on last link\n",
+ " print current.data # print data\n",
+ " current = current.next # move to next link\n",
+ "\n",
+ "\n",
+ " \n",
+ "\n",
+ "li = linklist() # make linked list\n",
+ "\n",
+ "li.additem(25) # add four items to linked list\n",
+ "li.additem(36)\n",
+ "li.additem(49)\n",
+ "li.additem(64)\n",
+ "\n",
+ "li.display() # display entire list"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "64\n",
+ "49\n",
+ "36\n",
+ "25\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.24, Page Number 474"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import Structure,POINTER\n",
+ "\n",
+ "def order(numb1 ,numb2): #orders two objects\n",
+ " if numb1.getname() > numb2.getname(): #if the name of 1st larger than 2nd\n",
+ " temp = numb1 #swap them\n",
+ " numb1 = numb2\n",
+ " numb2 = temp\n",
+ " return numb1,numb2\n",
+ " \n",
+ " \n",
+ "def bsort(ptr,n):\n",
+ " for j in range(n-1): #outer loop\n",
+ " for k in range(j+1,n,1): #inner loop starts at outer\n",
+ " ptr[j] ,ptr[k] = order(ptr[j] ,ptr[k]) #order the contents\n",
+ " return ptr\n",
+ "\n",
+ "\n",
+ "class person(Structure): #class of persons\n",
+ " \n",
+ " def setName(self): #set the name\n",
+ " self.__name = raw_input(\"Enter name: \")\n",
+ " \n",
+ " def printName(self): #display the name\n",
+ " print self.__name\n",
+ " \n",
+ " def getname(self): #returns the name\n",
+ " return self.__name\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "ob = [person()]*100 #array of persons\n",
+ "persPtr = POINTER(person) #pointer to person\n",
+ " \n",
+ "persPtr = ob #array of pointers to persons\n",
+ "n = 0 #number of persons in array\n",
+ "\n",
+ "while True: #put persons in array\n",
+ " \n",
+ " persPtr[n] = person()\n",
+ " persPtr[n].setName() #set person's name\n",
+ " \n",
+ " n += 1 #count new person\n",
+ " \n",
+ " choice = raw_input('Enter another (y/n)? ') #person ?\n",
+ " \n",
+ " if choice=='n': #quit on 'n'\n",
+ " break\n",
+ "\n",
+ " \n",
+ "print '\\nUnsorted list:'\n",
+ "for j in range(n): #print names of all persons\n",
+ " persPtr[j].printName()\n",
+ " \n",
+ " \n",
+ "persPtr = bsort(persPtr,n) #sorts the content of array according to their name\n",
+ "\n",
+ "print '\\nSorted list:'\n",
+ "for j in range(n): #print names of all persons\n",
+ " persPtr[j].printName()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Washington\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Adams\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Jefferson\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Madison\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Unsorted list:\n",
+ "Washington\n",
+ "Adams\n",
+ "Jefferson\n",
+ "Madison\n",
+ "\n",
+ "Sorted list:\n",
+ "Adams\n",
+ "Jefferson\n",
+ "Madison\n",
+ "Washington\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.25, Page Number 481"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LEN = 80 #length of expression, in character\n",
+ "MAX = 40 #size of stack\n",
+ "\n",
+ "\n",
+ "class stack:\n",
+ " \n",
+ " def __init__(self):\n",
+ " self.__st = [None]*MAX #stack: array of chars\n",
+ " self.__top = 0 #number of top of stack\n",
+ " \n",
+ " def push(self,var): #put char on stack\n",
+ " self.__top += 1\n",
+ " self.__st[self.__top] = var\n",
+ " \n",
+ " def pop(self): #take char off stack\n",
+ " x = self.__st[self.__top]\n",
+ " self.__top -= 1\n",
+ " return x\n",
+ " \n",
+ " def gettop(self): #get top of stack\n",
+ " return self.__top\n",
+ " \n",
+ " \n",
+ " \n",
+ "class express: #expression class\n",
+ " \n",
+ " def __init__(self,ptr):\n",
+ " \n",
+ " self.__s = stack() #stack for analysis\n",
+ " self.__pStr = ptr #input string\n",
+ " self.__len = len(self.__pStr) #length of input string\n",
+ " \n",
+ " \n",
+ " def parse(self): #add items to stack\n",
+ " \n",
+ " for j in range(self.__len): #for each input character\n",
+ " \n",
+ " ch = self.__pStr[j] #get next character\n",
+ " \n",
+ " if ch >= '0' and ch<='9': #if it's a digit,\n",
+ " self.__s.push(ch) #save the character\n",
+ " \n",
+ " #if it's operator\n",
+ " elif ch == '+' or ch == '-' or ch == '*' or ch == '/':\n",
+ " \n",
+ " if self.__s.gettop() == 1: #if it's first operator\n",
+ " self.__s.push(ch) #put on stack\n",
+ " \n",
+ " else: #not first operator\n",
+ " \n",
+ " lastval = self.__s.pop() #get previous digit \n",
+ " lastop = self.__s.pop() #get previous operator\n",
+ " \n",
+ " \n",
+ " #if this is * or / AND last operator was + or -\n",
+ " if (ch=='*' or ch=='/') and (lastop == '+' or lastop == '-'):\n",
+ " \n",
+ " self.__s.push(lastop) #restore last two pops\n",
+ " self.__s.push(lastval)\n",
+ " \n",
+ " \n",
+ " else: #in all other cases\n",
+ " #do last operation, and push result on stack\n",
+ " \n",
+ " if lastop == '+':\n",
+ " self.__s.push(str(int(self.__s.pop()) + int(lastval)))\n",
+ " \n",
+ " elif lastop == '-':\n",
+ " self.__s.push(str(int(self.__s.pop()) - int(lastval)))\n",
+ " \n",
+ " elif lastop == '*':\n",
+ " self.__s.push(str(int(self.__s.pop()) * int(lastval)))\n",
+ " \n",
+ " elif lastop == '/':\n",
+ " self.__s.push(str(int(int(self.__s.pop()) / int(lastval))))\n",
+ " \n",
+ " else:\n",
+ " print 'Unknown oper'\n",
+ " \n",
+ " \n",
+ " self.__s.push(ch) #put current operator on stack\n",
+ " \n",
+ " \n",
+ " else: #not a known character\n",
+ " \n",
+ " print 'Unkown input character'\n",
+ " \n",
+ " \n",
+ " \n",
+ " def solve(self): #remove items from stack\n",
+ " \n",
+ " while self.__s.gettop() > 1:\n",
+ " \n",
+ " lastval = self.__s.pop() #get previous value\n",
+ " \n",
+ " a = self.__s.pop() #get previous operator\n",
+ " \n",
+ " \n",
+ " #do operation, push answer\n",
+ " if a == '+':\n",
+ " self.__s.push(str(int(self.__s.pop()) + int(lastval)))\n",
+ " \n",
+ " elif a == '-':\n",
+ " self.__s.push(str(int(self.__s.pop()) - int(lastval)))\n",
+ " \n",
+ " elif a == '*':\n",
+ " self.__s.push(str(int(self.__s.pop()) * int(lastval)))\n",
+ " \n",
+ " elif a == '/':\n",
+ " self.__s.push(str(int(int(self.__s.pop()) / int(lastval))))\n",
+ " \n",
+ " else:\n",
+ " print 'Unknown oper'\n",
+ " \n",
+ " \n",
+ " return self.__s.pop() #last item on stack is ans\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "\n",
+ "print 'Enter an arithmetic expression'\n",
+ "print 'of the form 2+3*4/3-2'\n",
+ "print 'No number may have more than one digit.'\n",
+ "print 'Dont\\'t use any spaces or parentheses.' \n",
+ "\n",
+ "while True:\n",
+ " string = raw_input(\"Enter expression: \") #input from user\n",
+ "\n",
+ " eptr = express(string) #make expression\n",
+ "\n",
+ " eptr.parse() #parse it\n",
+ "\n",
+ " print '\\nThe numerical value is: ',eptr.solve() #solve it\n",
+ " \n",
+ " del eptr #delete expression\n",
+ " \n",
+ " ans = raw_input(\"\\n\\nDo another (Enter y or n)? \")\n",
+ " \n",
+ " if ans == 'n':\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an arithmetic expression\n",
+ "of the form 2+3*4/3-2\n",
+ "No number may have more than one digit.\n",
+ "Dont't use any spaces or parentheses.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter expression: 2+3*4/3-2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The numerical value is: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Do another (Enter y or n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter expression: 9+6/3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The numerical value is: 11\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Do another (Enter y or n)? n\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter11VirtualFunctions.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter11VirtualFunctions.ipynb
new file mode 100755
index 00000000..4037c7bf
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter11VirtualFunctions.ipynb
@@ -0,0 +1,1608 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:73390f8563e8d4a1d9bd2f7f6ade532b739ba3ced6bfe518d2929933836b62ae"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Virtual Functions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.1, Page Number 505"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base: #Base class\n",
+ " def show(self): #virtual function\n",
+ " print 'Base'\n",
+ " \n",
+ "class Derv1(Base): #derived class 1\n",
+ " def show(self):\n",
+ " print 'Derv1'\n",
+ " \n",
+ "class Derv2(Base): #derived class 2\n",
+ " def show(self):\n",
+ " print 'Derv2'\n",
+ " \n",
+ " \n",
+ " \n",
+ "dv1 = Derv1() #object of derived class 1\n",
+ "dv2 = Derv2() #object of derived class 2\n",
+ "\n",
+ "ptr = [Base()] #pointer to base class\n",
+ "\n",
+ "ptr[0] = dv1 #put address of dv1 in pointer\n",
+ "ptr[0].show() #execute show()\n",
+ "\n",
+ "ptr[0] = dv2 #put address of dv2 in pointer\n",
+ "ptr[0].show() #execute show()\n",
+ "\n",
+ "#in python all functions are virtual by default that is why here output is diffrent from the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Derv1\n",
+ "Derv2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.2, Page Number 507"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base: #base class\n",
+ " def show(self): #virtual function\n",
+ " print 'Base'\n",
+ " \n",
+ "class Derv1(Base): #derived class 1\n",
+ " def show(self):\n",
+ " print 'Derv1'\n",
+ " \n",
+ "class Derv2(Base): #derived class 2\n",
+ " def show(self):\n",
+ " print 'Derv2'\n",
+ " \n",
+ " \n",
+ " \n",
+ "dv1 = Derv1() #object of derived class 1\n",
+ "dv2 = Derv2() #object of derived class 2\n",
+ "\n",
+ "ptr = [Base()] #pointer to base class\n",
+ "\n",
+ "ptr[0] = dv1 #put address of dv1 in pointer\n",
+ "ptr[0].show() #execute show()\n",
+ "\n",
+ "ptr[0] = dv2 #put address of dv2 in pointer\n",
+ "ptr[0].show() #execute show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Derv1\n",
+ "Derv2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.3, Page Number 510"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base: #base class\n",
+ " def show(self): #pure virtual function\n",
+ " pass\n",
+ " \n",
+ "class Derv1(Base): #derived class 1\n",
+ " def show(self):\n",
+ " print 'Derv1'\n",
+ " \n",
+ "class Derv2(Base): #derived class 2\n",
+ " def show(self):\n",
+ " print 'Derv2'\n",
+ "\n",
+ " \n",
+ " \n",
+ "arr = [Base(),Base()] #array of pointers to base class\n",
+ "dv1 = Derv1() #object of derived class 1\n",
+ "dv2 = Derv2() #object of derived class 2\n",
+ "\n",
+ "arr[0] = dv1 #put address of dv1 in pointer\n",
+ "arr[1] = dv2 #put address of dv2 in pointer\n",
+ "\n",
+ "arr[0].show() #execute show() in both objects\n",
+ "arr[1].show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Derv1\n",
+ "Derv2\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.4, Page Number 512"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class person: #person class\n",
+ " \n",
+ " def getName(self):\n",
+ " self._name = raw_input(\" Enter name: \")\n",
+ " \n",
+ " def putName(self):\n",
+ " print 'Name is:',self._name\n",
+ " \n",
+ " def getData(self): #pure virtual function\n",
+ " pass\n",
+ " \n",
+ " def isOutstanding(self): #pure virtual function\n",
+ " pass\n",
+ " \n",
+ " \n",
+ " \n",
+ "class student(person): #student class\n",
+ " \n",
+ " def getData(self): #get student data from user\n",
+ " person.getName(self)\n",
+ " self.__gpa = input(' Enter student\\'s GPA: ') #grade point aerage\n",
+ " \n",
+ " def isOutstanding(self):\n",
+ " if self.__gpa > 3.5:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ " \n",
+ "class professor(person): #professor class\n",
+ " \n",
+ " def getData(self): #get professor data from user\n",
+ " person.getName(self)\n",
+ " self.__numPubs = input(' Enter number of professor\\'s publications: ') #number of papers published\n",
+ " \n",
+ " def isOutstanding(self):\n",
+ " if self.__numPubs > 100:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "persPtr = [person()]*100 #array of persons\n",
+ "n = 0 #number of persons on list\n",
+ "\n",
+ "while True:\n",
+ " choice = raw_input('Enter student or professor (s/p): ')\n",
+ " \n",
+ " if choice=='s': \n",
+ " persPtr[n] = student() #put new student in array\n",
+ " else:\n",
+ " persPtr[n] = professor() #put new professor in array\n",
+ " \n",
+ " persPtr[n].getData() #get data for person\n",
+ " n+=1\n",
+ " \n",
+ " choice = raw_input(' Enter another (y/n)? ') #do another person?\n",
+ " \n",
+ " if choice=='n': #cycle untill not 'y'\n",
+ " break\n",
+ " \n",
+ " \n",
+ "print ''\n",
+ "for j in range(n): #print names of all persons, and say if outstanding \n",
+ " persPtr[j].putName()\n",
+ " \n",
+ " if persPtr[j].isOutstanding():\n",
+ " print ' This person is outstanding'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student or professor (s/p): s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name: Timmy\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter student's GPA: 1.2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student or professor (s/p): s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name: Brenda\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter student's GPA: 3.9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student or professor (s/p): s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name: Sandy\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter student's GPA: 2.4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student or professor (s/p): p\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name: Shipley\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number of professor's publications: 714\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student or professor (s/p): p\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name: Wainright\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number of professor's publications: 13\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter another (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Name is: Timmy\n",
+ "Name is: Brenda\n",
+ " This person is outstanding\n",
+ "Name is: Sandy\n",
+ "Name is: Shipley\n",
+ " This person is outstanding\n",
+ "Name is: Wainright\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.5, Page Number 515"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import * #importing turtles library\n",
+ "\n",
+ "class shape: #base class\n",
+ " def __init__(self,x=0,y=0,fc=\"white\"): #constructor\n",
+ " self._xCo = x #coordinate for shape\n",
+ " self._yCo = y\n",
+ " self._fillcolor = fc #color for shape\n",
+ " \n",
+ " def draw(self,a): #virtual draw function\n",
+ " a.color(self._fillcolor)\n",
+ "\n",
+ " \n",
+ " \n",
+ "class ball(shape): #defining circle class\n",
+ " \n",
+ " def __init__(self,x,y,r,fc): #constructor for set circle attribute\n",
+ " shape.__init__(self,x,y,fc) \n",
+ " self._radius = r\n",
+ " \n",
+ " def draw(self): #draw the circle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " \n",
+ " shape.draw(self,turtle)\n",
+ " \n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.circle(self._radius)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ " \n",
+ " \n",
+ " \n",
+ "class rect(shape): #defining rectangle class\n",
+ " \n",
+ " def __init__(self,x,y,h,w,fc): #constructor\n",
+ " shape.__init__(self,x,y,fc) \n",
+ " self._height = h\n",
+ " self._weight = w\n",
+ " \n",
+ " def draw(self): #draw the rectangle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " \n",
+ " shape.draw(self,turtle)\n",
+ " \n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.forward(self._weight) \n",
+ " turtle.left(90)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.left(90)\n",
+ " turtle.forward(self._weight)\n",
+ " turtle.left(90)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done() \n",
+ "\n",
+ " \n",
+ "class tria(shape): #defining triangle class\n",
+ " \n",
+ " def __init__(self,x,y,h,fc): #constructor \n",
+ " shape.__init__(self,x,y,fc) \n",
+ " self._height = h\n",
+ " \n",
+ " def draw(self): #draw the triangle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " \n",
+ " shape.draw(self,turtle)\n",
+ " \n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.forward(self._height) \n",
+ " turtle.left(120)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.left(120)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ " \n",
+ " \n",
+ " \n",
+ "pShapes = [shape()]*3 #array of shapes define three shapes\n",
+ "\n",
+ "pShapes[0] = ball(40,12,5,\"blue\") #create circle\n",
+ "pShapes[1] = rect(12,7,10,15,\"red\") #create rectangle\n",
+ "pShapes[2] = tria(60,7,11,\"green\") #create triangle\n",
+ "\n",
+ "for j in range(3): #draw all shape\n",
+ " pShapes[j].draw()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.6, Page Number 517"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base:\n",
+ " def __del__(self): #non virtual destructor\n",
+ " print 'Base destroyed'\n",
+ " \n",
+ "class Derv(Base):\n",
+ " def __del__(self):\n",
+ " print 'Derv destroyed'\n",
+ " \n",
+ " \n",
+ " \n",
+ "pBase = [Base()]\n",
+ "\n",
+ "del pBase[0]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base destroyed\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.7, Page Number 521"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class alpha:\n",
+ " def __init__(self): #no-arg constructor\n",
+ " self.__data = 3\n",
+ " \n",
+ "class beta:\n",
+ " def __init__(self): #no-arg constructor\n",
+ " self.__data = 7\n",
+ " \n",
+ " \n",
+ "def frifunc(a,b): #friend function of both alpha and beta classes\n",
+ " return a._alpha__data + b._beta__data\n",
+ "\n",
+ "\n",
+ "\n",
+ "aa = alpha()\n",
+ "bb = beta()\n",
+ "\n",
+ "print frifunc(aa,bb) #call the function"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.8, Page Number 522"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor\n",
+ " \n",
+ " if isinstance(ft,float): #one argument \n",
+ " fltfeet = ft\n",
+ " self.__feet = int(fltfeet) #feet is integer part\n",
+ " self.__inches = 12*(fltfeet-self.__feet) #inches is what's left\n",
+ " \n",
+ " else: #two arguments\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " def __add__(self,d2): #add distance to this one\n",
+ " \n",
+ " if isinstance(d2,float):\n",
+ " d2 = Distance(d2)\n",
+ " \n",
+ " f = self.__feet + d2.__feet #add the feet\n",
+ " i = self.__inches + d2.__inches #add the inches\n",
+ " \n",
+ " if i >= 12.0: #if total exceeds 12.0, \n",
+ " i -= 12.0 #then decrease inches by 12.0 and\n",
+ " f += 1 #increase feet by 1\n",
+ " \n",
+ " return Distance(f,i) #return new Distance with sum\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "d1 = Distance(2.5) #constructor converts float feet to Distance\n",
+ "d2 = Distance(1.25)\n",
+ "d3 = Distance()\n",
+ "\n",
+ "print 'd1 =',;d1.showdist()\n",
+ "print 'd2 =',;d2.showdist()\n",
+ "\n",
+ "d3 = d1 + 10.0 #Distance + feet: OK\n",
+ "print 'd3 =',;d3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d1 = 2 ' - 6.0 \"\n",
+ "d2 = 1 ' - 3.0 \"\n",
+ "d3 = 12 ' - 6.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.9, Page Number 524"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor\n",
+ " \n",
+ " if isinstance(ft,float): #one argument \n",
+ " fltfeet = ft\n",
+ " self.__feet = int(fltfeet) #feet is integer part\n",
+ " self.__inches = 12*(fltfeet-self.__feet) #inches is what's left\n",
+ " \n",
+ " else: #two arguments\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "def add(d1,d2): #add distance to this one\n",
+ " \n",
+ " if isinstance(d2,float):\n",
+ " d2 = Distance(d2)\n",
+ " \n",
+ " if isinstance(d1,float):\n",
+ " d1 = Distance(d1)\n",
+ " \n",
+ " f = d1._Distance__feet + d2._Distance__feet #add the feet\n",
+ " i = d1._Distance__inches + d2._Distance__inches #add the inches\n",
+ " \n",
+ " if i >= 12.0: #if total exceeds 12.0, \n",
+ " i -= 12.0 #then decrease inches by 12.0 and\n",
+ " f += 1 #increase feet by 1\n",
+ " \n",
+ " return Distance(f,i) #return new Distance with sum\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "d1 = Distance(2.5) #constructor converts float feet to Distance\n",
+ "d2 = Distance(1.25)\n",
+ "d3 = Distance()\n",
+ "\n",
+ "print 'd1 =',;d1.showdist()\n",
+ "print 'd2 =',;d2.showdist()\n",
+ "\n",
+ "d3 = add(d1,10.0) #Distance + feet: OK\n",
+ "print 'd3 =',;d3.showdist()\n",
+ "\n",
+ "d3 = add(10.0,d1) #feet + Distance: OK\n",
+ "print 'd3 =',;d3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d1 = 2 ' - 6.0 \"\n",
+ "d2 = 1 ' - 3.0 \"\n",
+ "d3 = 12 ' - 6.0 \"\n",
+ "d3 = 12 ' - 6.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.10, Page Number 526"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def square(self): #returns square of this distance\n",
+ " fltfeet = self.__feet + self.__inches/12 #convert to float\n",
+ " feetsqrd = fltfeet*fltfeet #find the square\n",
+ " return feetsqrd #return square feet\n",
+ " \n",
+ " \n",
+ " \n",
+ "dist = Distance(3,6.0)\n",
+ "\n",
+ "sqft = dist.square() #return square of dist\n",
+ "\n",
+ "print 'Distance =',;dist.showdist() #display distance and square\n",
+ "print 'Square =',sqft,'square feet'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Distance = 3 ' - 6.0 \"\n",
+ "Square = 12.25 square feet\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.11, Page Number 527"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ "#friend function\n",
+ "\n",
+ "def square(d): #returns square of this distance\n",
+ " fltfeet = d._Distance__feet + d._Distance__inches/12 #convert to float\n",
+ " feetsqrd = fltfeet*fltfeet #find the square\n",
+ " return feetsqrd #return square feet\n",
+ " \n",
+ " \n",
+ " \n",
+ "dist = Distance(3,6.0)\n",
+ "\n",
+ "sqft = square(dist) #return square of dist\n",
+ "\n",
+ "print 'Distance =',;dist.showdist() #display distance and square\n",
+ "print 'Square =',sqft,'square feet'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Distance = 3 ' - 6.0 \"\n",
+ "Square = 12.25 square feet\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.12, Page Number 528"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class alpha:\n",
+ " def __init__(self): #constructor\n",
+ " self.__data1 = 99\n",
+ " \n",
+ "class beta:\n",
+ " def func1(self,a): #it can access private member of alpha class through a\n",
+ " print 'data1 =',a._alpha__data1\n",
+ " \n",
+ " def func2(self,a): #it can access private member of alpha class through a\n",
+ " print 'data1 =',a._alpha__data1\n",
+ "\n",
+ " \n",
+ " \n",
+ "a = alpha()\n",
+ "b = beta()\n",
+ "\n",
+ "b.func1(a)\n",
+ "b.func2(a)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "data1 = 99\n",
+ "data1 = 99\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.13, Page Number 529"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class gamma:\n",
+ " __total = 0 #total object of this classs\n",
+ " \n",
+ " def __init__(self): #no-arg constructor\n",
+ " gamma.__total += 1 #add another object\n",
+ " self.__id = gamma.__total #ID number of this object and ID equals to current total\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " gamma.__total -= 1\n",
+ " print 'Destroyed ID number',self.__id\n",
+ " \n",
+ " def showtotal(self): #function\n",
+ " print 'Total is',gamma.__total\n",
+ " \n",
+ " def showid(self): #function\n",
+ " print 'ID number is',self.__id\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "g1 = gamma()\n",
+ "g1.showtotal()\n",
+ "\n",
+ "g2 = gamma()\n",
+ "g3 = gamma()\n",
+ "g1.showtotal()\n",
+ "\n",
+ "g1.showid()\n",
+ "g2.showid()\n",
+ "g3.showid()\n",
+ "\n",
+ "print '-----------end of program-----------'\n",
+ "\n",
+ "del g3\n",
+ "del g2\n",
+ "del g1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total is 1\n",
+ "Total is 3\n",
+ "ID number is 1\n",
+ "ID number is 2\n",
+ "ID number is 3\n",
+ "-----------end of program-----------\n",
+ "Destroyed ID number 3\n",
+ "Destroyed ID number 2\n",
+ "Destroyed ID number 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.14, Page Number 533"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class alpha:\n",
+ " def __init__(self,d=0): #constructor\n",
+ " \n",
+ " if isinstance(d,int):\n",
+ " self.__data = d\n",
+ " else:\n",
+ " self.__data = d.__data\n",
+ " \n",
+ " \n",
+ " def display(self): #display data\n",
+ " print self.__data\n",
+ " \n",
+ " def __eq__(self,a): #overloaded == operator\n",
+ " self.__data = a.__data #not done automatically\n",
+ " print 'Assignment operator invoked'\n",
+ " \n",
+ " return alpha(self.__data) #return copy of this alpha\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "a1 = alpha(37)\n",
+ "a2 = alpha()\n",
+ "\n",
+ "a2 = (a2 == a1) #invoke overloaded ==\n",
+ "print 'a2 =',;a2.display() #display a2\n",
+ "\n",
+ "a3 = alpha(a2) #does not invoke ==\n",
+ "print 'a3 =',;a3.display() #display a3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Assignment operator invoked\n",
+ "a2 = 37\n",
+ "a3 = 37\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.15, Page Number 536"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class alpha:\n",
+ " \n",
+ " def __init__(self,d=0): #constructor\n",
+ " if isinstance(d,int):\n",
+ " self.__data = d\n",
+ " else:\n",
+ " self.__data = d.__data\n",
+ " print 'copy constructor invoked'\n",
+ " \n",
+ " def display(self): #display data\n",
+ " print self.__data\n",
+ " \n",
+ " def __eq__(self,a): #overloaded == operator\n",
+ " self.__data = a.__data\n",
+ " print 'Assignment operator invoked'\n",
+ " return alpha(self.__data)\n",
+ " \n",
+ " \n",
+ " \n",
+ "a1 = alpha(37)\n",
+ "a2 = alpha()\n",
+ "\n",
+ "a2 = (a2 == a1) #invoke overloaded ==\n",
+ "print 'a2 =',;a2.display() #display a2\n",
+ "\n",
+ "a3 = alpha(a2) #invoke copy constructor\n",
+ "print 'a3 =',;a3.display() #display a3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Assignment operator invoked\n",
+ "a2 = 37\n",
+ "copy constructor invoked\n",
+ "a3 = 37\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.16, Page Number 543"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class strCount: #keep track of number of unique strings\n",
+ " \n",
+ " def __init__(self,s): #one - arg constructor \n",
+ " self.__str = s #copy argument to string\n",
+ " self.__count = 1 #number of instances and start count at 1\n",
+ " \n",
+ " def __del__(self): #destructor \n",
+ " del self.__str #delete the string\n",
+ " \n",
+ " \n",
+ "class String: #string class\n",
+ " \n",
+ " def __init__(self,s=\"\"): #constructor\n",
+ " \n",
+ " if isinstance(s,String):\n",
+ " self.__psc = s.__psc\n",
+ " self.__psc._strCount__count += 1\n",
+ " else:\n",
+ " self.__psc = strCount(s)\n",
+ " \n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " \n",
+ " if self.__psc._strCount__count == 1: #if we are its last user, delete the string\n",
+ " del self.__psc\n",
+ " \n",
+ " else:\n",
+ " self.__psc._strCount__count -= 1 #otherwise decrement its count\n",
+ " \n",
+ " \n",
+ " def display(self): #display the string\n",
+ " print self.__psc._strCount__str, #print string\n",
+ " print '(addr =',hex(id(self.__psc)),')' #print address\n",
+ " \n",
+ " \n",
+ " def __eq__(self,s): #assign the string\n",
+ " \n",
+ " if self.__psc._strCount__count == 1: #if we are its last user, delete the string\n",
+ " del self.__psc\n",
+ " \n",
+ " else:\n",
+ " self.__psc._strCount__count -= 1 #otherwise decrement its count\n",
+ " \n",
+ " self.__psc = s.__psc #use argument's strCount\n",
+ " self.__psc._strCount__count += 1 #increment its count\n",
+ " \n",
+ " return s\n",
+ " \n",
+ " \n",
+ " \n",
+ "s3 = String(\"When the fox preaches, look to your geeses.\")\n",
+ "print 's3 =',;s3.display() #display s3\n",
+ "\n",
+ "s1 = String() #define string\n",
+ "s1 = (s1==s3) #assign it another string\n",
+ "print 's1 =',;s1.display() #display it\n",
+ "\n",
+ "s2 = String(s3) #initialize with string\n",
+ "print 's2 =',;s2.display() #display it"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s3 = When the fox preaches, look to your geeses. (addr = 0x3ac0988L )\n",
+ "s1 = When the fox preaches, look to your geeses. (addr = 0x3ac0988L )\n",
+ "s2 = When the fox preaches, look to your geeses. (addr = 0x3ac0988L )\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.17, Page Number 547"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class where:\n",
+ " __charray = []*10 #copies 10 bytes\n",
+ " \n",
+ " def reveal(self):\n",
+ " print \"my object's address is\",hex(id(self))\n",
+ " \n",
+ " \n",
+ " \n",
+ "w1 = where() #make three objects\n",
+ "w2 = where()\n",
+ "w3 = where()\n",
+ "\n",
+ "w1.reveal() #see where they are\n",
+ "w2.reveal()\n",
+ "w3.reveal()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "my object's address is 0x38ec3c8L\n",
+ "my object's address is 0x375a188L\n",
+ "my object's address is 0x375a208L\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.18, Page Number 548"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class what:\n",
+ " def tester(self):\n",
+ " self.__alpha = 11 #same as alpha = 11\n",
+ " print self.__alpha #same as print alpha\n",
+ " \n",
+ " \n",
+ "w = what()\n",
+ "w.tester()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.19, Page Number 549"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class alpha:\n",
+ " def __init__(self,d=None): #constructor\n",
+ " self.__data = d\n",
+ " \n",
+ " def display(self): #display data\n",
+ " print self.__data\n",
+ " \n",
+ " def __eq__(self,a): #overloaded == operator\n",
+ " self.__data = a.__data #not done automatically\n",
+ " print 'Assignment operator invoked'\n",
+ " return alpha(self.__data) #return copy of this alpha\n",
+ " \n",
+ " \n",
+ " \n",
+ "a1 = alpha(37)\n",
+ "a2 = alpha()\n",
+ "a3 = alpha()\n",
+ "\n",
+ "a3 = a3 == a2 == a1 #invoke overloaded ==, twice\n",
+ "print 'a2 =',;a2.display() #display a2\n",
+ "print 'a3 =',;a3.display() #display a3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Assignment operator invoked\n",
+ "Assignment operator invoked\n",
+ "a2 = 37\n",
+ "a3 = 37\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.20, Page Number 550"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class strCount: #keep track of number of unique strings\n",
+ " \n",
+ " def __init__(self,s): #one - arg constructor \n",
+ " self.__str = s #copy argument to string\n",
+ " self.__count = 1 #number of instances and start count at 1\n",
+ " \n",
+ " def __del__(self): #destructor \n",
+ " del self.__str #delete the string\n",
+ " \n",
+ " \n",
+ "class String:\n",
+ " \n",
+ " def __init__(self,s=\"\"): #constructor\n",
+ " \n",
+ " if isinstance(s,String):\n",
+ " print 'COPY CONSTRUCTOR'\n",
+ " self.__psc = s.__psc\n",
+ " self.__psc._strCount__count += 1\n",
+ " else:\n",
+ " self.__psc = strCount(s)\n",
+ " \n",
+ " \n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " \n",
+ " if self.__psc._strCount__count == 1: #if we are its last user, delete the string\n",
+ " del self.__psc\n",
+ " \n",
+ " else:\n",
+ " self.__psc._strCount__count -= 1 #otherwise decrement its count\n",
+ " \n",
+ " \n",
+ " \n",
+ " def display(self): #display the string\n",
+ " print self.__psc._strCount__str, #print string\n",
+ " print '(addr =',hex(id(self.__psc)),')' #print address\n",
+ " \n",
+ " \n",
+ " \n",
+ " def __eq__(self,s):\n",
+ " print 'ASSIGNMENT'\n",
+ " \n",
+ " if self.__psc._strCount__count == 1: #if we are its last user, delete the string\n",
+ " del self.__psc\n",
+ " \n",
+ " else:\n",
+ " self.__psc._strCount__count -= 1 #otherwise decrement its count\n",
+ " \n",
+ " self.__psc = s.__psc #use argument's strCount\n",
+ " self.__psc._strCount__count += 1 #increment its count\n",
+ " \n",
+ " return self\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "s3 = String(\"When the fox preaches, look to your geeses.\")\n",
+ "print 's3 =',;s3.display() #display s3\n",
+ "\n",
+ "s1 = String() #define strings\n",
+ "s2 = String()\n",
+ "\n",
+ "s1 = s1 == s2==s3 #assign them\n",
+ "\n",
+ "print 's1 =',;s1.display() #display it\n",
+ "print 's2 =',;s2.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s3 = When the fox preaches, look to your geeses. (addr = 0x3ac0f88L )\n",
+ "ASSIGNMENT\n",
+ "ASSIGNMENT\n",
+ "s1 = When the fox preaches, look to your geeses. (addr = 0x3ac0f88L )\n",
+ "s2 = When the fox preaches, look to your geeses. (addr = 0x3ac0f88L )\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.21, Page Number 553"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base:\n",
+ " def vertFunc(self): #needed for dynamic cast\n",
+ " pass\n",
+ " \n",
+ "class Derv1(Base):\n",
+ " pass\n",
+ "\n",
+ "class Derv2(Base):\n",
+ " pass\n",
+ " \n",
+ " \n",
+ "def isDerv1(pUnknown): #unKnown subclass of base\n",
+ " if isinstance(pUnknown,Derv1):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ " \n",
+ "d1 = Derv1()\n",
+ "d2 = Derv2()\n",
+ "\n",
+ "if isDerv1(d1):\n",
+ " print 'd1 is a member of the Derv1 class'\n",
+ "else:\n",
+ " print 'd1 is not a member of the Derv1 class'\n",
+ " \n",
+ "if isDerv1(d2):\n",
+ " print 'd2 is a member of the Derv1 class'\n",
+ "else:\n",
+ " print 'd2 is not a member of the Derv1 class'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d1 is a member of the Derv1 class\n",
+ "d2 is not a member of the Derv1 class\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.22, Page Number 555"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base:\n",
+ " def __init__(self,b=0):\n",
+ " self._ba = b\n",
+ " \n",
+ " def vertFunc(self): #needed for dynamic cast\n",
+ " pass\n",
+ " \n",
+ " def show(self):\n",
+ " print 'Base: ba =',self._ba\n",
+ " \n",
+ " \n",
+ "class Derv(Base):\n",
+ " def __init__(self,b,d):\n",
+ " self._ba = b\n",
+ " self.__da = d\n",
+ " \n",
+ " def show(self):\n",
+ " print 'Derv: ba =',self._ba,'da =',self.__da\n",
+ " \n",
+ " \n",
+ " \n",
+ "pBase = Base(10) #Base class object\n",
+ "pDerv = Derv(21,22) #derv class object\n",
+ "\n",
+ "pBase.show() #\"Base: ba=10\"\n",
+ "\n",
+ "pBase = Derv(31,32)\n",
+ "pDerv = pBase\n",
+ "pDerv.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base: ba = 10\n",
+ "Derv: ba = 31 da = 32\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.23, Page Number 556"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base:\n",
+ " def vertFunc(self):\n",
+ " pass\n",
+ " \n",
+ "class Derv1(Base):\n",
+ " pass\n",
+ "\n",
+ "class Derv2(Base):\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "def displayName(pB): #display name of class\n",
+ " print 'pointer to an object of',\n",
+ " #to show from which class this object belongs\n",
+ " if isinstance(pB,Derv1):\n",
+ " print 'Derv1'\n",
+ " if isinstance(pB,Derv2):\n",
+ " print 'Derv2'\n",
+ " \n",
+ " \n",
+ " \n",
+ "pBase = Derv1() #object of Derv1\n",
+ "displayName(pBase)\n",
+ " \n",
+ "pBase = Derv2() #object of Derv2\n",
+ "displayName(pBase)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pointer to an object of Derv1\n",
+ "pointer to an object of Derv2\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter11VirtualFunctions_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter11VirtualFunctions_1.ipynb
new file mode 100755
index 00000000..cae07384
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter11VirtualFunctions_1.ipynb
@@ -0,0 +1,1608 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c9f17dd802653b08f0bf46018c68e23b63e5ba6b54740c9042de7d2a816937b8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Virtual Functions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.1, Page Number 505"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base: #Base class\n",
+ " def show(self): #virtual function\n",
+ " print 'Base'\n",
+ " \n",
+ "class Derv1(Base): #derived class 1\n",
+ " def show(self):\n",
+ " print 'Derv1'\n",
+ " \n",
+ "class Derv2(Base): #derived class 2\n",
+ " def show(self):\n",
+ " print 'Derv2'\n",
+ " \n",
+ " \n",
+ " \n",
+ "dv1 = Derv1() #object of derived class 1\n",
+ "dv2 = Derv2() #object of derived class 2\n",
+ "\n",
+ "ptr = [Base()] #pointer to base class\n",
+ "\n",
+ "ptr[0] = dv1 #put address of dv1 in pointer\n",
+ "ptr[0].show() #execute show()\n",
+ "\n",
+ "ptr[0] = dv2 #put address of dv2 in pointer\n",
+ "ptr[0].show() #execute show()\n",
+ "\n",
+ "#in python all functions are virtual by default that is why here output is diffrent from the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Derv1\n",
+ "Derv2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.2, Page Number 507"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base: #base class\n",
+ " def show(self): #virtual function\n",
+ " print 'Base'\n",
+ " \n",
+ "class Derv1(Base): #derived class 1\n",
+ " def show(self):\n",
+ " print 'Derv1'\n",
+ " \n",
+ "class Derv2(Base): #derived class 2\n",
+ " def show(self):\n",
+ " print 'Derv2'\n",
+ " \n",
+ " \n",
+ " \n",
+ "dv1 = Derv1() #object of derived class 1\n",
+ "dv2 = Derv2() #object of derived class 2\n",
+ "\n",
+ "ptr = [Base()] #pointer to base class\n",
+ "\n",
+ "ptr[0] = dv1 #put address of dv1 in pointer\n",
+ "ptr[0].show() #execute show()\n",
+ "\n",
+ "ptr[0] = dv2 #put address of dv2 in pointer\n",
+ "ptr[0].show() #execute show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Derv1\n",
+ "Derv2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.3, Page Number 510"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base: #base class\n",
+ " def show(self): #pure virtual function\n",
+ " pass\n",
+ " \n",
+ "class Derv1(Base): #derived class 1\n",
+ " def show(self):\n",
+ " print 'Derv1'\n",
+ " \n",
+ "class Derv2(Base): #derived class 2\n",
+ " def show(self):\n",
+ " print 'Derv2'\n",
+ "\n",
+ " \n",
+ " \n",
+ "arr = [Base(),Base()] #array of pointers to base class\n",
+ "dv1 = Derv1() #object of derived class 1\n",
+ "dv2 = Derv2() #object of derived class 2\n",
+ "\n",
+ "arr[0] = dv1 #put address of dv1 in pointer\n",
+ "arr[1] = dv2 #put address of dv2 in pointer\n",
+ "\n",
+ "arr[0].show() #execute show() in both objects\n",
+ "arr[1].show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Derv1\n",
+ "Derv2\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.4, Page Number 512"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class person: #person class\n",
+ " \n",
+ " def getName(self):\n",
+ " self._name = raw_input(\" Enter name: \")\n",
+ " \n",
+ " def putName(self):\n",
+ " print 'Name is:',self._name\n",
+ " \n",
+ " def getData(self): #pure virtual function\n",
+ " pass\n",
+ " \n",
+ " def isOutstanding(self): #pure virtual function\n",
+ " pass\n",
+ " \n",
+ " \n",
+ " \n",
+ "class student(person): #student class\n",
+ " \n",
+ " def getData(self): #get student data from user\n",
+ " person.getName(self)\n",
+ " self.__gpa = input(' Enter student\\'s GPA: ') #grade point aerage\n",
+ " \n",
+ " def isOutstanding(self):\n",
+ " if self.__gpa > 3.5:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ " \n",
+ "class professor(person): #professor class\n",
+ " \n",
+ " def getData(self): #get professor data from user\n",
+ " person.getName(self)\n",
+ " self.__numPubs = input(' Enter number of professor\\'s publications: ') #number of papers published\n",
+ " \n",
+ " def isOutstanding(self):\n",
+ " if self.__numPubs > 100:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "persPtr = [person()]*100 #array of persons\n",
+ "n = 0 #number of persons on list\n",
+ "\n",
+ "while True:\n",
+ " choice = raw_input('Enter student or professor (s/p): ')\n",
+ " \n",
+ " if choice=='s': \n",
+ " persPtr[n] = student() #put new student in array\n",
+ " else:\n",
+ " persPtr[n] = professor() #put new professor in array\n",
+ " \n",
+ " persPtr[n].getData() #get data for person\n",
+ " n+=1\n",
+ " \n",
+ " choice = raw_input(' Enter another (y/n)? ') #do another person?\n",
+ " \n",
+ " if choice=='n': #cycle untill not 'y'\n",
+ " break\n",
+ " \n",
+ " \n",
+ "print ''\n",
+ "for j in range(n): #print names of all persons, and say if outstanding \n",
+ " persPtr[j].putName()\n",
+ " \n",
+ " if persPtr[j].isOutstanding():\n",
+ " print ' This person is outstanding'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student or professor (s/p): s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name: Timmy\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter student's GPA: 1.2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student or professor (s/p): s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name: Brenda\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter student's GPA: 3.9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student or professor (s/p): s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name: Sandy\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter student's GPA: 2.4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student or professor (s/p): p\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name: Shipley\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number of professor's publications: 714\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student or professor (s/p): p\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name: Wainright\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number of professor's publications: 13\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter another (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Name is: Timmy\n",
+ "Name is: Brenda\n",
+ " This person is outstanding\n",
+ "Name is: Sandy\n",
+ "Name is: Shipley\n",
+ " This person is outstanding\n",
+ "Name is: Wainright\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.5, Page Number 515"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import Turtle,setup,done #importing turtles library\n",
+ "\n",
+ "class shape: #base class\n",
+ " def __init__(self,x=0,y=0,fc=\"white\"): #constructor\n",
+ " self._xCo = x #coordinate for shape\n",
+ " self._yCo = y\n",
+ " self._fillcolor = fc #color for shape\n",
+ " \n",
+ " def draw(self,a): #virtual draw function\n",
+ " a.color(self._fillcolor)\n",
+ "\n",
+ " \n",
+ " \n",
+ "class ball(shape): #defining circle class\n",
+ " \n",
+ " def __init__(self,x,y,r,fc): #constructor for set circle attribute\n",
+ " shape.__init__(self,x,y,fc) \n",
+ " self._radius = r\n",
+ " \n",
+ " def draw(self): #draw the circle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " \n",
+ " shape.draw(self,turtle)\n",
+ " \n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.circle(self._radius)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ " \n",
+ " \n",
+ " \n",
+ "class rect(shape): #defining rectangle class\n",
+ " \n",
+ " def __init__(self,x,y,h,w,fc): #constructor\n",
+ " shape.__init__(self,x,y,fc) \n",
+ " self._height = h\n",
+ " self._weight = w\n",
+ " \n",
+ " def draw(self): #draw the rectangle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " \n",
+ " shape.draw(self,turtle)\n",
+ " \n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.forward(self._weight) \n",
+ " turtle.left(90)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.left(90)\n",
+ " turtle.forward(self._weight)\n",
+ " turtle.left(90)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done() \n",
+ "\n",
+ " \n",
+ "class tria(shape): #defining triangle class\n",
+ " \n",
+ " def __init__(self,x,y,h,fc): #constructor \n",
+ " shape.__init__(self,x,y,fc) \n",
+ " self._height = h\n",
+ " \n",
+ " def draw(self): #draw the triangle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " \n",
+ " shape.draw(self,turtle)\n",
+ " \n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.forward(self._height) \n",
+ " turtle.left(120)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.left(120)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ " \n",
+ " \n",
+ " \n",
+ "pShapes = [shape()]*3 #array of shapes define three shapes\n",
+ "\n",
+ "pShapes[0] = ball(40,12,5,\"blue\") #create circle\n",
+ "pShapes[1] = rect(12,7,10,15,\"red\") #create rectangle\n",
+ "pShapes[2] = tria(60,7,11,\"green\") #create triangle\n",
+ "\n",
+ "for j in range(3): #draw all shape\n",
+ " pShapes[j].draw()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.6, Page Number 517"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base:\n",
+ " def __del__(self): #non virtual destructor\n",
+ " print 'Base destroyed'\n",
+ " \n",
+ "class Derv(Base):\n",
+ " def __del__(self):\n",
+ " print 'Derv destroyed'\n",
+ " \n",
+ " \n",
+ " \n",
+ "pBase = [Base()]\n",
+ "\n",
+ "del pBase[0]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base destroyed\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.7, Page Number 521"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class alpha:\n",
+ " def __init__(self): #no-arg constructor\n",
+ " self.__data = 3\n",
+ " \n",
+ "class beta:\n",
+ " def __init__(self): #no-arg constructor\n",
+ " self.__data = 7\n",
+ " \n",
+ " \n",
+ "def frifunc(a,b): #friend function of both alpha and beta classes\n",
+ " return a._alpha__data + b._beta__data\n",
+ "\n",
+ "\n",
+ "\n",
+ "aa = alpha()\n",
+ "bb = beta()\n",
+ "\n",
+ "print frifunc(aa,bb) #call the function"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.8, Page Number 522"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor\n",
+ " \n",
+ " if isinstance(ft,float): #one argument \n",
+ " fltfeet = ft\n",
+ " self.__feet = int(fltfeet) #feet is integer part\n",
+ " self.__inches = 12*(fltfeet-self.__feet) #inches is what's left\n",
+ " \n",
+ " else: #two arguments\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " def __add__(self,d2): #add distance to this one\n",
+ " \n",
+ " if isinstance(d2,float):\n",
+ " d2 = Distance(d2)\n",
+ " \n",
+ " f = self.__feet + d2.__feet #add the feet\n",
+ " i = self.__inches + d2.__inches #add the inches\n",
+ " \n",
+ " if i >= 12.0: #if total exceeds 12.0, \n",
+ " i -= 12.0 #then decrease inches by 12.0 and\n",
+ " f += 1 #increase feet by 1\n",
+ " \n",
+ " return Distance(f,i) #return new Distance with sum\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "d1 = Distance(2.5) #constructor converts float feet to Distance\n",
+ "d2 = Distance(1.25)\n",
+ "d3 = Distance()\n",
+ "\n",
+ "print 'd1 =',;d1.showdist()\n",
+ "print 'd2 =',;d2.showdist()\n",
+ "\n",
+ "d3 = d1 + 10.0 #Distance + feet: OK\n",
+ "print 'd3 =',;d3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d1 = 2 ' - 6.0 \"\n",
+ "d2 = 1 ' - 3.0 \"\n",
+ "d3 = 12 ' - 6.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.9, Page Number 524"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor\n",
+ " \n",
+ " if isinstance(ft,float): #one argument \n",
+ " fltfeet = ft\n",
+ " self.__feet = int(fltfeet) #feet is integer part\n",
+ " self.__inches = 12*(fltfeet-self.__feet) #inches is what's left\n",
+ " \n",
+ " else: #two arguments\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "def add(d1,d2): #add distance to this one\n",
+ " \n",
+ " if isinstance(d2,float):\n",
+ " d2 = Distance(d2)\n",
+ " \n",
+ " if isinstance(d1,float):\n",
+ " d1 = Distance(d1)\n",
+ " \n",
+ " f = d1._Distance__feet + d2._Distance__feet #add the feet\n",
+ " i = d1._Distance__inches + d2._Distance__inches #add the inches\n",
+ " \n",
+ " if i >= 12.0: #if total exceeds 12.0, \n",
+ " i -= 12.0 #then decrease inches by 12.0 and\n",
+ " f += 1 #increase feet by 1\n",
+ " \n",
+ " return Distance(f,i) #return new Distance with sum\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "d1 = Distance(2.5) #constructor converts float feet to Distance\n",
+ "d2 = Distance(1.25)\n",
+ "d3 = Distance()\n",
+ "\n",
+ "print 'd1 =',;d1.showdist()\n",
+ "print 'd2 =',;d2.showdist()\n",
+ "\n",
+ "d3 = add(d1,10.0) #Distance + feet: OK\n",
+ "print 'd3 =',;d3.showdist()\n",
+ "\n",
+ "d3 = add(10.0,d1) #feet + Distance: OK\n",
+ "print 'd3 =',;d3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d1 = 2 ' - 6.0 \"\n",
+ "d2 = 1 ' - 3.0 \"\n",
+ "d3 = 12 ' - 6.0 \"\n",
+ "d3 = 12 ' - 6.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.10, Page Number 526"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def square(self): #returns square of this distance\n",
+ " fltfeet = self.__feet + self.__inches/12 #convert to float\n",
+ " feetsqrd = fltfeet*fltfeet #find the square\n",
+ " return feetsqrd #return square feet\n",
+ " \n",
+ " \n",
+ " \n",
+ "dist = Distance(3,6.0)\n",
+ "\n",
+ "sqft = dist.square() #return square of dist\n",
+ "\n",
+ "print 'Distance =',;dist.showdist() #display distance and square\n",
+ "print 'Square =',sqft,'square feet'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Distance = 3 ' - 6.0 \"\n",
+ "Square = 12.25 square feet\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.11, Page Number 527"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ "#friend function\n",
+ "\n",
+ "def square(d): #returns square of this distance\n",
+ " fltfeet = d._Distance__feet + d._Distance__inches/12 #convert to float\n",
+ " feetsqrd = fltfeet*fltfeet #find the square\n",
+ " return feetsqrd #return square feet\n",
+ " \n",
+ " \n",
+ " \n",
+ "dist = Distance(3,6.0)\n",
+ "\n",
+ "sqft = square(dist) #return square of dist\n",
+ "\n",
+ "print 'Distance =',;dist.showdist() #display distance and square\n",
+ "print 'Square =',sqft,'square feet'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Distance = 3 ' - 6.0 \"\n",
+ "Square = 12.25 square feet\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.12, Page Number 528"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class alpha:\n",
+ " def __init__(self): #constructor\n",
+ " self.__data1 = 99\n",
+ " \n",
+ "class beta:\n",
+ " def func1(self,a): #it can access private member of alpha class through a\n",
+ " print 'data1 =',a._alpha__data1\n",
+ " \n",
+ " def func2(self,a): #it can access private member of alpha class through a\n",
+ " print 'data1 =',a._alpha__data1\n",
+ "\n",
+ " \n",
+ " \n",
+ "a = alpha()\n",
+ "b = beta()\n",
+ "\n",
+ "b.func1(a)\n",
+ "b.func2(a)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "data1 = 99\n",
+ "data1 = 99\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.13, Page Number 529"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class gamma:\n",
+ " __total = 0 #total object of this classs\n",
+ " \n",
+ " def __init__(self): #no-arg constructor\n",
+ " gamma.__total += 1 #add another object\n",
+ " self.__id = gamma.__total #ID number of this object and ID equals to current total\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " gamma.__total -= 1\n",
+ " print 'Destroyed ID number',self.__id\n",
+ " \n",
+ " def showtotal(self): #function\n",
+ " print 'Total is',gamma.__total\n",
+ " \n",
+ " def showid(self): #function\n",
+ " print 'ID number is',self.__id\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "g1 = gamma()\n",
+ "g1.showtotal()\n",
+ "\n",
+ "g2 = gamma()\n",
+ "g3 = gamma()\n",
+ "g1.showtotal()\n",
+ "\n",
+ "g1.showid()\n",
+ "g2.showid()\n",
+ "g3.showid()\n",
+ "\n",
+ "print '-----------end of program-----------'\n",
+ "\n",
+ "del g3\n",
+ "del g2\n",
+ "del g1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total is 1\n",
+ "Total is 3\n",
+ "ID number is 1\n",
+ "ID number is 2\n",
+ "ID number is 3\n",
+ "-----------end of program-----------\n",
+ "Destroyed ID number 3\n",
+ "Destroyed ID number 2\n",
+ "Destroyed ID number 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.14, Page Number 533"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class alpha:\n",
+ " def __init__(self,d=0): #constructor\n",
+ " \n",
+ " if isinstance(d,int):\n",
+ " self.__data = d\n",
+ " else:\n",
+ " self.__data = d.__data\n",
+ " \n",
+ " \n",
+ " def display(self): #display data\n",
+ " print self.__data\n",
+ " \n",
+ " def __eq__(self,a): #overloaded == operator\n",
+ " self.__data = a.__data #not done automatically\n",
+ " print 'Assignment operator invoked'\n",
+ " \n",
+ " return alpha(self.__data) #return copy of this alpha\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "a1 = alpha(37)\n",
+ "a2 = alpha()\n",
+ "\n",
+ "a2 = (a2 == a1) #invoke overloaded ==\n",
+ "print 'a2 =',;a2.display() #display a2\n",
+ "\n",
+ "a3 = alpha(a2) #does not invoke ==\n",
+ "print 'a3 =',;a3.display() #display a3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Assignment operator invoked\n",
+ "a2 = 37\n",
+ "a3 = 37\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.15, Page Number 536"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class alpha:\n",
+ " \n",
+ " def __init__(self,d=0): #constructor\n",
+ " if isinstance(d,int):\n",
+ " self.__data = d\n",
+ " else:\n",
+ " self.__data = d.__data\n",
+ " print 'copy constructor invoked'\n",
+ " \n",
+ " def display(self): #display data\n",
+ " print self.__data\n",
+ " \n",
+ " def __eq__(self,a): #overloaded == operator\n",
+ " self.__data = a.__data\n",
+ " print 'Assignment operator invoked'\n",
+ " return alpha(self.__data)\n",
+ " \n",
+ " \n",
+ " \n",
+ "a1 = alpha(37)\n",
+ "a2 = alpha()\n",
+ "\n",
+ "a2 = (a2 == a1) #invoke overloaded ==\n",
+ "print 'a2 =',;a2.display() #display a2\n",
+ "\n",
+ "a3 = alpha(a2) #invoke copy constructor\n",
+ "print 'a3 =',;a3.display() #display a3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Assignment operator invoked\n",
+ "a2 = 37\n",
+ "copy constructor invoked\n",
+ "a3 = 37\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.16, Page Number 543"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class strCount: #keep track of number of unique strings\n",
+ " \n",
+ " def __init__(self,s): #one - arg constructor \n",
+ " self.__str = s #copy argument to string\n",
+ " self.__count = 1 #number of instances and start count at 1\n",
+ " \n",
+ " def __del__(self): #destructor \n",
+ " del self.__str #delete the string\n",
+ " \n",
+ " \n",
+ "class String: #string class\n",
+ " \n",
+ " def __init__(self,s=\"\"): #constructor\n",
+ " \n",
+ " if isinstance(s,String):\n",
+ " self.__psc = s.__psc\n",
+ " self.__psc._strCount__count += 1\n",
+ " else:\n",
+ " self.__psc = strCount(s)\n",
+ " \n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " \n",
+ " if self.__psc._strCount__count == 1: #if we are its last user, delete the string\n",
+ " del self.__psc\n",
+ " \n",
+ " else:\n",
+ " self.__psc._strCount__count -= 1 #otherwise decrement its count\n",
+ " \n",
+ " \n",
+ " def display(self): #display the string\n",
+ " print self.__psc._strCount__str, #print string\n",
+ " print '(addr =',hex(id(self.__psc)),')' #print address\n",
+ " \n",
+ " \n",
+ " def __eq__(self,s): #assign the string\n",
+ " \n",
+ " if self.__psc._strCount__count == 1: #if we are its last user, delete the string\n",
+ " del self.__psc\n",
+ " \n",
+ " else:\n",
+ " self.__psc._strCount__count -= 1 #otherwise decrement its count\n",
+ " \n",
+ " self.__psc = s.__psc #use argument's strCount\n",
+ " self.__psc._strCount__count += 1 #increment its count\n",
+ " \n",
+ " return s\n",
+ " \n",
+ " \n",
+ " \n",
+ "s3 = String(\"When the fox preaches, look to your geeses.\")\n",
+ "print 's3 =',;s3.display() #display s3\n",
+ "\n",
+ "s1 = String() #define string\n",
+ "s1 = (s1==s3) #assign it another string\n",
+ "print 's1 =',;s1.display() #display it\n",
+ "\n",
+ "s2 = String(s3) #initialize with string\n",
+ "print 's2 =',;s2.display() #display it"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s3 = When the fox preaches, look to your geeses. (addr = 0x3ac0988L )\n",
+ "s1 = When the fox preaches, look to your geeses. (addr = 0x3ac0988L )\n",
+ "s2 = When the fox preaches, look to your geeses. (addr = 0x3ac0988L )\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.17, Page Number 547"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class where:\n",
+ " __charray = []*10 #copies 10 bytes\n",
+ " \n",
+ " def reveal(self):\n",
+ " print \"my object's address is\",hex(id(self))\n",
+ " \n",
+ " \n",
+ " \n",
+ "w1 = where() #make three objects\n",
+ "w2 = where()\n",
+ "w3 = where()\n",
+ "\n",
+ "w1.reveal() #see where they are\n",
+ "w2.reveal()\n",
+ "w3.reveal()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "my object's address is 0x38ec3c8L\n",
+ "my object's address is 0x375a188L\n",
+ "my object's address is 0x375a208L\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.18, Page Number 548"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class what:\n",
+ " def tester(self):\n",
+ " self.__alpha = 11 #same as alpha = 11\n",
+ " print self.__alpha #same as print alpha\n",
+ " \n",
+ " \n",
+ "w = what()\n",
+ "w.tester()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.19, Page Number 549"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class alpha:\n",
+ " def __init__(self,d=None): #constructor\n",
+ " self.__data = d\n",
+ " \n",
+ " def display(self): #display data\n",
+ " print self.__data\n",
+ " \n",
+ " def __eq__(self,a): #overloaded == operator\n",
+ " self.__data = a.__data #not done automatically\n",
+ " print 'Assignment operator invoked'\n",
+ " return alpha(self.__data) #return copy of this alpha\n",
+ " \n",
+ " \n",
+ " \n",
+ "a1 = alpha(37)\n",
+ "a2 = alpha()\n",
+ "a3 = alpha()\n",
+ "\n",
+ "a3 = a3 == a2 == a1 #invoke overloaded ==, twice\n",
+ "print 'a2 =',;a2.display() #display a2\n",
+ "print 'a3 =',;a3.display() #display a3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Assignment operator invoked\n",
+ "Assignment operator invoked\n",
+ "a2 = 37\n",
+ "a3 = 37\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.20, Page Number 550"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class strCount: #keep track of number of unique strings\n",
+ " \n",
+ " def __init__(self,s): #one - arg constructor \n",
+ " self.__str = s #copy argument to string\n",
+ " self.__count = 1 #number of instances and start count at 1\n",
+ " \n",
+ " def __del__(self): #destructor \n",
+ " del self.__str #delete the string\n",
+ " \n",
+ " \n",
+ "class String:\n",
+ " \n",
+ " def __init__(self,s=\"\"): #constructor\n",
+ " \n",
+ " if isinstance(s,String):\n",
+ " print 'COPY CONSTRUCTOR'\n",
+ " self.__psc = s.__psc\n",
+ " self.__psc._strCount__count += 1\n",
+ " else:\n",
+ " self.__psc = strCount(s)\n",
+ " \n",
+ " \n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " \n",
+ " if self.__psc._strCount__count == 1: #if we are its last user, delete the string\n",
+ " del self.__psc\n",
+ " \n",
+ " else:\n",
+ " self.__psc._strCount__count -= 1 #otherwise decrement its count\n",
+ " \n",
+ " \n",
+ " \n",
+ " def display(self): #display the string\n",
+ " print self.__psc._strCount__str, #print string\n",
+ " print '(addr =',hex(id(self.__psc)),')' #print address\n",
+ " \n",
+ " \n",
+ " \n",
+ " def __eq__(self,s):\n",
+ " print 'ASSIGNMENT'\n",
+ " \n",
+ " if self.__psc._strCount__count == 1: #if we are its last user, delete the string\n",
+ " del self.__psc\n",
+ " \n",
+ " else:\n",
+ " self.__psc._strCount__count -= 1 #otherwise decrement its count\n",
+ " \n",
+ " self.__psc = s.__psc #use argument's strCount\n",
+ " self.__psc._strCount__count += 1 #increment its count\n",
+ " \n",
+ " return self\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "s3 = String(\"When the fox preaches, look to your geeses.\")\n",
+ "print 's3 =',;s3.display() #display s3\n",
+ "\n",
+ "s1 = String() #define strings\n",
+ "s2 = String()\n",
+ "\n",
+ "s1 = s1 == s2==s3 #assign them\n",
+ "\n",
+ "print 's1 =',;s1.display() #display it\n",
+ "print 's2 =',;s2.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s3 = When the fox preaches, look to your geeses. (addr = 0x3ac0f88L )\n",
+ "ASSIGNMENT\n",
+ "ASSIGNMENT\n",
+ "s1 = When the fox preaches, look to your geeses. (addr = 0x3ac0f88L )\n",
+ "s2 = When the fox preaches, look to your geeses. (addr = 0x3ac0f88L )\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.21, Page Number 553"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base:\n",
+ " def vertFunc(self): #needed for dynamic cast\n",
+ " pass\n",
+ " \n",
+ "class Derv1(Base):\n",
+ " pass\n",
+ "\n",
+ "class Derv2(Base):\n",
+ " pass\n",
+ " \n",
+ " \n",
+ "def isDerv1(pUnknown): #unKnown subclass of base\n",
+ " if isinstance(pUnknown,Derv1):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ " \n",
+ "d1 = Derv1()\n",
+ "d2 = Derv2()\n",
+ "\n",
+ "if isDerv1(d1):\n",
+ " print 'd1 is a member of the Derv1 class'\n",
+ "else:\n",
+ " print 'd1 is not a member of the Derv1 class'\n",
+ " \n",
+ "if isDerv1(d2):\n",
+ " print 'd2 is a member of the Derv1 class'\n",
+ "else:\n",
+ " print 'd2 is not a member of the Derv1 class'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d1 is a member of the Derv1 class\n",
+ "d2 is not a member of the Derv1 class\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.22, Page Number 555"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base:\n",
+ " def __init__(self,b=0):\n",
+ " self._ba = b\n",
+ " \n",
+ " def vertFunc(self): #needed for dynamic cast\n",
+ " pass\n",
+ " \n",
+ " def show(self):\n",
+ " print 'Base: ba =',self._ba\n",
+ " \n",
+ " \n",
+ "class Derv(Base):\n",
+ " def __init__(self,b,d):\n",
+ " self._ba = b\n",
+ " self.__da = d\n",
+ " \n",
+ " def show(self):\n",
+ " print 'Derv: ba =',self._ba,'da =',self.__da\n",
+ " \n",
+ " \n",
+ " \n",
+ "pBase = Base(10) #Base class object\n",
+ "pDerv = Derv(21,22) #derv class object\n",
+ "\n",
+ "pBase.show() #\"Base: ba=10\"\n",
+ "\n",
+ "pBase = Derv(31,32)\n",
+ "pDerv = pBase\n",
+ "pDerv.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base: ba = 10\n",
+ "Derv: ba = 31 da = 32\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.23, Page Number 556"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Base:\n",
+ " def vertFunc(self):\n",
+ " pass\n",
+ " \n",
+ "class Derv1(Base):\n",
+ " pass\n",
+ "\n",
+ "class Derv2(Base):\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "def displayName(pB): #display name of class\n",
+ " print 'pointer to an object of',\n",
+ " #to show from which class this object belongs\n",
+ " if isinstance(pB,Derv1):\n",
+ " print 'Derv1'\n",
+ " if isinstance(pB,Derv2):\n",
+ " print 'Derv2'\n",
+ " \n",
+ " \n",
+ " \n",
+ "pBase = Derv1() #object of Derv1\n",
+ "displayName(pBase)\n",
+ " \n",
+ "pBase = Derv2() #object of Derv2\n",
+ "displayName(pBase)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pointer to an object of Derv1\n",
+ "pointer to an object of Derv2\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter12StreamsandFiles.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter12StreamsandFiles.ipynb
new file mode 100755
index 00000000..93ca098b
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter12StreamsandFiles.ipynb
@@ -0,0 +1,2356 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:568f6285e8843e18804f4f5d950104746e10133535c613cf28a00f18dc9d570b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12: Streams and Files"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.1, Page Number 581"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def isFeet(str): #return true if the string is a correct feet value\n",
+ " \n",
+ " slen = len(str) #get length\n",
+ " \n",
+ " if slen==0 or slen>5: #if no input, or too long \n",
+ " return False #not an int\n",
+ " \n",
+ " \n",
+ " for j in range(slen): #check each character\n",
+ " \n",
+ " if (str[j] < '0' or str[j] > '9' ) and str[j] != '-': #if not digit or minus\n",
+ " return False #string is not correct feet\n",
+ " \n",
+ " \n",
+ " n = float(str) #convert to float\n",
+ " \n",
+ " if(n<-999.0 or n>999.0): #is it out of range\n",
+ " return False #if so, not correct feet\n",
+ " \n",
+ " return True #it is correct feet\n",
+ "\n",
+ "\n",
+ "\n",
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " \n",
+ " while True:\n",
+ " self.__feet = raw_input('Enter feet:') #it will not skip white space\n",
+ " \n",
+ " if(isFeet(self.__feet)): #is it a correct feet value?\n",
+ " \n",
+ " self.__feet.replace(' ','') #eat white spaces\n",
+ " self.__feet = int(self.__feet) #convert to integer\n",
+ " break; #break out of 'while'\n",
+ " \n",
+ " print 'Feet must be an integer less than 1000'\n",
+ " \n",
+ " \n",
+ " while True: #cycle untill inches are right\n",
+ " \n",
+ " self.__inches = input('Enter inches:') #get inches and do not skip white space\n",
+ " \n",
+ " if(self.__inches<12.0 and self.__inches>0.0):\n",
+ " break;\n",
+ " \n",
+ " if(self.__inches>=12.0 or self.__inches<0.0):\n",
+ " print 'Inches must be between 0.0 and 11.99'\n",
+ " print 'Incorrect inches input' \n",
+ " \n",
+ " \n",
+ " \n",
+ "d = Distance() #make a distance object\n",
+ "\n",
+ "while True:\n",
+ " d.getdist() #get its value from user\n",
+ " \n",
+ " print 'Distance =',;d.showdist() #display it\n",
+ " \n",
+ " ans = raw_input(\"Do another (y/n)? \")\n",
+ " \n",
+ " if ans == 'n': #cycle untill 'n'\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:1 2 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Feet must be an integer less than 1000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:9999\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Feet must be an integer less than 1000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:99\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:14\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inches must be between 0.0 and 11.99\n",
+ "Incorrect inches input\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:11\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Distance = 99 ' - 11 \"\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:-98\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:12\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inches must be between 0.0 and 11.99\n",
+ "Incorrect inches input\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:-98\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inches must be between 0.0 and 11.99\n",
+ "Incorrect inches input\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:11\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Distance = -98 ' - 11 \"\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do another (y/n)? n\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.2, Page Number 584"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ch = \"x\"\n",
+ "str1 = \"Kafka\" #strings without white spaces\n",
+ "str2 = \"Proust\"\n",
+ "\n",
+ "outfile=open(\"fdata.txt\",'w') #open a file \n",
+ "\n",
+ "outfile.write(ch) #insert (write) data\n",
+ "outfile.write(\"77\")\n",
+ "outfile.write(\"6.02\")\n",
+ "outfile.write(' ') #needed space between numbers and string\n",
+ "outfile.write(str1)\n",
+ "outfile.write(' ') #needed space between strings\n",
+ "outfile.write(str2)\n",
+ "\n",
+ "print 'File written'\n",
+ "outfile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "File written\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.3, Page Number 585"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "infile = open(\"fdata.txt\",'r') #open the file for reading\n",
+ "\n",
+ "ch = infile.read(1) #extract (read) data from it\n",
+ "j = infile.read(2)\n",
+ "d = infile.read(5)\n",
+ "str1 = infile.read(6)\n",
+ "str2 = infile.read()\n",
+ "\n",
+ "print ch,\"\\n\",j,\"\\n\",d,\"\\n\",str1,\"\\n\",str2,\"\\n\", #display the data"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x \n",
+ "77 \n",
+ "6.02 \n",
+ "Kafka \n",
+ "Proust \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.4, Page Number 586"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "outfile = open(\"TEST.TXT\",'w') #create a file for output\n",
+ "\n",
+ "#send text to file\n",
+ "outfile.write(\"I fear thee, ancient Marner!\\n\") \n",
+ "outfile.write(\"I fear thy skinny hand\\n\")\n",
+ "outfile.write(\"And thou art long, and lank, and brown,\\n\")\n",
+ "outfile.write(\"As is the ribbed sea sand.\\n\")\n",
+ "\n",
+ "outfile.close() #close the file"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.5, Page Number 587"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 80 #size of buffer\n",
+ "buffer = []*MAX #character buffer\n",
+ "\n",
+ "infile = open(\"TEST.TXT\",'r') #open a file to read\n",
+ "\n",
+ "buffer = infile.readline() #read one line from the file\n",
+ "\n",
+ "while buffer: #untill buffer has some data in it or untill end-of-file\n",
+ " print buffer, #display buffer\n",
+ " buffer = infile.readline() #read a line of text\n",
+ " \n",
+ "infile.close() #close file"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I fear thee, ancient Marner!\n",
+ "I fear thy skinny hand\n",
+ "And thou art long, and lank, and brown,\n",
+ "As is the ribbed sea sand.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.6, Page Number 588"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str = \"Time is a great teache, but unfortunately \" + \"it kills all its puplies. Berlioz\"\n",
+ "\n",
+ "outfile = open(\"Test.txt\",\"w\") #create file for output\n",
+ "\n",
+ "for j in range(len(str)): #for each character\n",
+ " ch = \"\"+str[j]\n",
+ " outfile.write(ch),\n",
+ " \n",
+ "print \"File written\"\n",
+ "outfile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "File written\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.7, Page Number 588"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "infile = open(\"Test.txt\",\"r\") #open file for read\n",
+ "\n",
+ "ch = infile.read(1) #read character\n",
+ " \n",
+ "while ch != '': #read untill EOF\n",
+ " print ch, #display it\n",
+ " ch = infile.read(1) #read character"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "T i m e i s a g r e a t t e a c h e , b u t u n f o r t u n a t e l y i t k i l l s a l l i t s p u p l i e s . B e r l i o z\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.8, Page Number 589"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "infile = open(\"Test.txt\",\"r\") #open file for read\n",
+ "\n",
+ "print infile.read() #read whole file and print it"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time is a great teache, but unfortunately it kills all its puplies. Berlioz\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.9, Page Number 590"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 100 #size of buffer\n",
+ "buff = [j for j in range(MAX)] #buffer for integers and fill buffer with data (0, 1, 2, ...)\n",
+ "\n",
+ "os = open(\"edata.txt\",'r+b') #first make edata.txt file\n",
+ "\n",
+ "s = ''\n",
+ "for j in range(MAX): \n",
+ " s += '%d' %buff[j] \n",
+ "os.write(s) #write to file\n",
+ "\n",
+ "\n",
+ "for j in range(MAX): #erase buffer\n",
+ " buff[j] = 0\n",
+ " \n",
+ " \n",
+ "os.seek(0,0)\n",
+ "\n",
+ "#read data from file\n",
+ "for j in range (10):\n",
+ " buff[j] = os.read(1)\n",
+ " \n",
+ "for j in range(10,MAX):\n",
+ " buff[j] = os.read(2)\n",
+ " \n",
+ " \n",
+ "c=0\n",
+ "for j in range(MAX): #check data\n",
+ " if int(buff[j])!=j:\n",
+ " print \"Data is incorrect\\n\"\n",
+ " c=1\n",
+ " break\n",
+ " \n",
+ "if c==0:\n",
+ " print \"Data is correct\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Data is correct\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.10, Page Number 592"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import pickle\n",
+ "\n",
+ "class person: #class person\n",
+ " \n",
+ " def getData(self): #get person's data\n",
+ " self.name = raw_input(\"Enter name: \") #person's name\n",
+ " self.age = input(\"Enter age: \") #person's age\n",
+ " \n",
+ " \n",
+ " \n",
+ "pers = person() #create a person\n",
+ "pers.getData() #get data for person\n",
+ "\n",
+ "outfile = open(\"PERSON.txt\",'wb') #open file for write obect to it\n",
+ "\n",
+ "pickle.dump(pers, outfile) #write object\n",
+ "\n",
+ "outfile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Coleridge\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 62\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.11, Page Number 593"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import pickle\n",
+ "\n",
+ "class person:\n",
+ " \n",
+ " def showData(self): #display person's data\n",
+ " print \"Name:\",self.name #person's name\n",
+ " print \"Age:\",self.age #person's age\n",
+ " \n",
+ " \n",
+ " \n",
+ "pers = person() #create person variable\n",
+ "\n",
+ "infile = open(\"PERSON.txt\",'rb') #open file in binary mode\n",
+ "\n",
+ "pers = pickle.load(infile) #read object \n",
+ "pers.showData() #display person"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Coleridge\n",
+ "Age: 62\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.12, Page Number 594"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import pickle\n",
+ "\n",
+ "class person: #class of persons\n",
+ " \n",
+ " def getData(self): #get person's data\n",
+ " self._name = raw_input(\"Enter name: \")\n",
+ " self._age = input(\"Enter age: \")\n",
+ " \n",
+ " def showData(self): #display person's data\n",
+ " print \" Name:\",self._name\n",
+ " print \" Age:\",self._age\n",
+ " \n",
+ " \n",
+ " \n",
+ "pers = person() #create person object\n",
+ "file = open(\"Group.txt\",'r+b') #open file\n",
+ "c=0 #for total number of objects\n",
+ "\n",
+ "\n",
+ "while True: \n",
+ " print \"\\nEnter person's data: \"\n",
+ " pers.getData() #get one person's data\n",
+ " pickle.dump(pers, file) #wriet to file\n",
+ " c += 1\n",
+ " \n",
+ " ch = raw_input(\"Enter another person (y/n)? \")\n",
+ " if(ch == 'n'):\n",
+ " break\n",
+ " \n",
+ " \n",
+ "file.seek(0,0)\n",
+ "\n",
+ "print ''\n",
+ "for j in range(c):\n",
+ " print 'person:'\n",
+ " pers = pickle.load(file) #read person from file\n",
+ " pers.showData() #display person"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Whitney\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Rainier\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 21\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: McKinley\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 22\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "person:\n",
+ " Name: Whitney\n",
+ " Age: 20\n",
+ "person:\n",
+ " Name: Rainier\n",
+ " Age: 21\n",
+ "person:\n",
+ " Name: McKinley\n",
+ " Age: 22\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.13, Page Number 599"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import pickle\n",
+ "\n",
+ "class person: #class of person's\n",
+ " \n",
+ " def getData(self): #get person's data\n",
+ " self._name = raw_input(\"Enter name: \")\n",
+ " self._age = input(\"Enter age: \")\n",
+ " \n",
+ " def showData(self): #dislay person's data\n",
+ " print \" Name:\",self._name\n",
+ " print \" Age:\",self._age\n",
+ " \n",
+ " \n",
+ " \n",
+ "pers = person() #create person object\n",
+ "infile = open(\"Group.txt\",'r+b') #create input file and open it\n",
+ "c=3\n",
+ "print 'There are',c,'persons in file' #print number of objects in file\n",
+ "\n",
+ "n = input(\"Enter person number: \")\n",
+ "\n",
+ "print ''\n",
+ "for j in range(3):\n",
+ " pers = pickle.load(infile) #read one person\n",
+ " if j==n-1:\n",
+ " pers.showData() #display the person"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "There are 3 persons in file\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter person number: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Name: Rainier\n",
+ " Age: 21\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.14, Page Number 601"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import pickle\n",
+ "\n",
+ "MAX = 1000\n",
+ "buff = []*1000\n",
+ "\n",
+ "for j in range(MAX): #fill buffer with data\n",
+ " buff.append(j)\n",
+ "\n",
+ "try:\n",
+ " os = open(\"edata.txt\",'r+b') #open a file\n",
+ "\n",
+ "except IOError:\n",
+ " print \"could not open output file\"\n",
+ " \n",
+ "print 'Writing...'\n",
+ "\n",
+ "try:\n",
+ " pickle.dump(buff, os) #write buffer to it\n",
+ "except IOError:\n",
+ " print \"could not write ot file\"\n",
+ " \n",
+ "os.close() #must close it\n",
+ "\n",
+ "\n",
+ "\n",
+ "for j in range(MAX): #clear buffer\n",
+ " buff[j]=0\n",
+ " \n",
+ "try:\n",
+ " is1 = open(\"edata.txt\",'r+b') #open the same file in read mode\n",
+ "\n",
+ "except IOError:\n",
+ " print \"could not open output file\"\n",
+ " \n",
+ "print 'Reading...'\n",
+ "\n",
+ "try:\n",
+ " buff = pickle.load(is1) #read file data and put it into a buffer\n",
+ "except IOError:\n",
+ " print \"could not read from file\"\n",
+ " \n",
+ "c=0\n",
+ "for j in range(MAX): #check data\n",
+ " if int(buff[j])!=j:\n",
+ " print \"Data is incorrect\\n\"\n",
+ " c=1\n",
+ " break\n",
+ " \n",
+ "if c==0:\n",
+ " print \"Data is correct\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Writing...\n",
+ "Reading...\n",
+ "Data is correct\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.15, Page Number 603"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class error: #class error#\n",
+ " \n",
+ " def rdstate(self): #show the error state\n",
+ " try:\n",
+ " file = open(\"GROUP1.txt\",'r')\n",
+ " return 0\n",
+ " \n",
+ " except IOError:\n",
+ " return 4\n",
+ " \n",
+ " def good(self): #check no error occur to open the file\n",
+ " try:\n",
+ " file = open(\"GROUP1.txt\",'r')\n",
+ " return 1\n",
+ " \n",
+ " except IOError:\n",
+ " return 0\n",
+ " \n",
+ " def eof(self): #check end-of-file\n",
+ " try:\n",
+ " file = open(\"GROUP1.txt\",'r')\n",
+ " return 1\n",
+ " \n",
+ " except IOError:\n",
+ " return 0\n",
+ " \n",
+ " def fail(self): #check any error has come?\n",
+ " try:\n",
+ " file = open(\"GROUP1.txt\",'r')\n",
+ " return 0\n",
+ " \n",
+ " except IOError:\n",
+ " return 4\n",
+ " \n",
+ " def bad(self): #file can't be open\n",
+ " try:\n",
+ " file = open(\"GROUP1.txt\",'r')\n",
+ " return 0\n",
+ " \n",
+ " except IOError:\n",
+ " return 4\n",
+ "\n",
+ "\n",
+ "try:\n",
+ " file = open(\"GROUP1.txt\",'r')\n",
+ " \n",
+ "except IOError:\n",
+ " print \"can't open output file\"\n",
+ "\n",
+ "print 'file =',hex(id(file))\n",
+ "\n",
+ "file = error()\n",
+ "\n",
+ "print 'Error state =',file.rdstate()\n",
+ "print 'good() =',file.good()\n",
+ "print 'eof() =',file.eof()\n",
+ "print 'fail() =',file.fail()\n",
+ "print 'bad() =',file.bad()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "can't open output file\n",
+ "file = 0x37cd270L\n",
+ "Error state = 4\n",
+ "good() = 0\n",
+ "eof() = 0\n",
+ "fail() = 4\n",
+ "bad() = 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.16, Page Number 604"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import pickle\n",
+ "\n",
+ "class person: #class of persons\n",
+ "\n",
+ " def getData(self): #get person's data\n",
+ " self._name = raw_input(\"Enter name: \") #person's name\n",
+ " self._age = input(\"Enter age: \") #person's age\n",
+ " \n",
+ " \n",
+ " def showData(self): #display person's data\n",
+ " print \" Name:\",self._name\n",
+ " print \" Age:\",self._age\n",
+ " \n",
+ " \n",
+ " def diskIn(self,pn,c): #read person number pn from file\n",
+ " \n",
+ " infile = open(\"PERSFILE.txt\",'r+b') #open file\n",
+ " \n",
+ " for j in range(c):\n",
+ " self = pickle.load(infile) #read one person\n",
+ " \n",
+ " if j==pn:\n",
+ " return self;\n",
+ " \n",
+ " \n",
+ " def diskOut(self): #write person to end of file\n",
+ " \n",
+ " outfile = open(\"PERSFILE.txt\",'ab') #open file\n",
+ " pickle.dump(self, outfile) #write to it\n",
+ " outfile.close()\n",
+ " \n",
+ " \n",
+ " def diskCount(self,c): #return number of persons in file\n",
+ " return c \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "p = person() #make an empty person\n",
+ "c=0\n",
+ "outfile = open(\"PERSFILE.txt\",'wb') #open file to delete its containt\n",
+ "outfile.close()\n",
+ "\n",
+ "while True: #save person to disk\n",
+ " print \"\\nEnter person's data: \"\n",
+ " p.getData() #get data \n",
+ " p.diskOut() #write to disk\n",
+ " c += 1\n",
+ " \n",
+ " ch = raw_input(\"Enter another person (y/n)? \")\n",
+ " if(ch == 'n'): #untill user enters 'n'\n",
+ " break \n",
+ " \n",
+ "c = p.diskCount(c) #how many persons are in file?\n",
+ "\n",
+ "print 'There are',c,'persons in file'\n",
+ "\n",
+ "print ''\n",
+ "for j in range(c): #for each person\n",
+ " print 'person'\n",
+ " p = p.diskIn(j,c) #read person from disk\n",
+ " p.showData() #display person"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Stimson\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 45\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Hull\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 58\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Acheson\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 63\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Dulles\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 72\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "There are 4 persons in file\n",
+ "\n",
+ "person\n",
+ " Name: Stimson\n",
+ " Age: 45\n",
+ "person\n",
+ " Name: Hull\n",
+ " Age: 58\n",
+ "person\n",
+ " Name: Acheson\n",
+ " Age: 63\n",
+ "person\n",
+ " Name: Dulles\n",
+ " Age: 72\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.17, Page Number 608"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "import pickle\n",
+ "\n",
+ "employee_type = [\"tmanager\",\"tscientist\",\"tlaborer\"] \n",
+ "(tmanager,tscientist,tlaborer) = (0,1,2) #Atteching the names with number \n",
+ "\n",
+ "LEN = 32 #maximum length of last names\n",
+ "MAXEM = 100 #maximum length of employees\n",
+ "\n",
+ "\n",
+ "\n",
+ "class employee: #employee class\n",
+ " __name = [None]*LEN #employee name\n",
+ " __n = 0 #current number of employee\n",
+ " __arrap = [] #array of ptrs to emps\n",
+ " \n",
+ " def getdata(self): #get data from user\n",
+ " self.__name = raw_input(\" Enter last name: \")\n",
+ " self.__number = input(\" Enter number: \") #employee number\n",
+ " \n",
+ " def putdata(self): #display data\n",
+ " print ' Name:',self.__name \n",
+ " print ' Number:',self.__number\n",
+ " \n",
+ " \n",
+ " def get_type(self): #return the type of object\n",
+ " \n",
+ " if sys.getsizeof(self)==sys.getsizeof(manager()):\n",
+ " return tmanager\n",
+ " elif sys.getsizeof(self)==sys.getsizeof(scientisit()):\n",
+ " return tscientist\n",
+ " elif sys.getsizeof(self)==sys.getsizeof(laborer()):\n",
+ " return tlaborer\n",
+ " else:\n",
+ " print 'Bad employee type'\n",
+ " return tmanager\n",
+ " \n",
+ " \n",
+ " def add(self): #add employee to list in memory\n",
+ " \n",
+ " print \"'m' to add manager \\n's' to add a scientist\\n'l' to add a laborer\"\n",
+ " ch = raw_input(\"Enter selection: \")\n",
+ " \n",
+ " #create specific employee type\n",
+ " if ch=='m':\n",
+ " employee.__arrap.append(manager())\n",
+ " \n",
+ " elif ch=='s':\n",
+ " employee.__arrap.append(scientist())\n",
+ " \n",
+ " elif ch=='l':\n",
+ " employee.__arrap.append(laborer())\n",
+ " \n",
+ " else:\n",
+ " print 'Unknown command'\n",
+ " \n",
+ " employee.__arrap[employee.__n].getdata() #get employee data from user\n",
+ " employee.__n += 1 #increase the number of employee\n",
+ " \n",
+ " \n",
+ " def display(self): #display all employees\n",
+ " \n",
+ " for j in range(employee.__n):\n",
+ " print j+1, #display number\n",
+ " \n",
+ " #display type\n",
+ " if employee.__arrap[j].get_type()==tmanager:\n",
+ " print '. Type: Manager'\n",
+ " \n",
+ " elif employee.__arrap[j].get_type()==tscientist:\n",
+ " print '. Type: scientist'\n",
+ " \n",
+ " elif employee.__arrap[j].get_type()==tlaborer:\n",
+ " print '. Type: laborer'\n",
+ " \n",
+ " else:\n",
+ " print '. Unknown type'\n",
+ " \n",
+ " employee.__arrap[j].putdata() #display employee data\n",
+ " \n",
+ " \n",
+ " def write(self): #write all current memory object to file\n",
+ " ouf = open(\"EMPLOY.txt\",'w')\n",
+ " ouf.close()\n",
+ " \n",
+ " print 'Writing',employee.__n,'employees.'\n",
+ " \n",
+ " try:\n",
+ " ouf = open(\"EMPLOY.txt\",'ab') #open file in binary mode\n",
+ " except IOError:\n",
+ " print \"could not open file\"\n",
+ " \n",
+ " \n",
+ " for j in range(employee.__n): #for every employee objects\n",
+ " \n",
+ " etype = employee.__arrap[j].get_type() #get its type\n",
+ " pickle.dump(etype, ouf) #write type to file\n",
+ " \n",
+ " #find its size\n",
+ " if etype == tmanager:\n",
+ " size = sys.getsizeof(manager)\n",
+ " elif etype == tscientist:\n",
+ " size = sys.getsizeof(scientist)\n",
+ " elif etype == tlaborer:\n",
+ " size = sys.getsizeof(laborer)\n",
+ " \n",
+ " try:\n",
+ " pickle.dump(employee.__arrap[j], ouf) #write employee object to file\n",
+ " except IOError:\n",
+ " print \"could not write to file\"\n",
+ " \n",
+ " ouf.close() #close the file\n",
+ " \n",
+ " \n",
+ " \n",
+ " def read(self,c): #read data for all employee from file into memory\n",
+ " \n",
+ " try:\n",
+ " inf = open(\"EMPLOY.txt\",'rb') #open file into binary mode\n",
+ " except IOError:\n",
+ " print \"could not open file\"\n",
+ " \n",
+ " employee.__n = 0 #no employee in memeory yet\n",
+ " \n",
+ " for j in range(c):\n",
+ " \n",
+ " try:\n",
+ " etype = pickle.load(inf) #read type of next employee\n",
+ " except IOError:\n",
+ " print \"could not read type from file\"\n",
+ " \n",
+ " if j==c:\n",
+ " break\n",
+ " \n",
+ " if etype == tmanager: #make new employee of correct type\n",
+ " employee.__arrap[employee.__n] = manager()\n",
+ " size = sys.getsizeof(manager)\n",
+ " elif etype == tscientist:\n",
+ " employee.__arrap[employee.__n] = scientist()\n",
+ " size = sys.getsizeof(scientist)\n",
+ " elif etype == tlaborer:\n",
+ " employee.__arrap[employee.__n] = laborer()\n",
+ " size = sys.getsizeof(laborer)\n",
+ " else:\n",
+ " print 'Unknown type in file'\n",
+ " \n",
+ " try:\n",
+ " employee.__arrap[employee.__n] = pickle.load(inf) #read data from file into it\n",
+ " except IOError:\n",
+ " print \"could not read type from file\"\n",
+ " \n",
+ " employee.__n += 1 #count employee\n",
+ " \n",
+ " print 'Reading',employee.__n,'employees'\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "class manager(employee): #management class\n",
+ " __title = [None]*LEN #'vice-president' etc. \n",
+ " \n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__title = raw_input(\" Enter Title: \")\n",
+ " self.__dues = input(\" Enter golf club dues: \") #golf club dues\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Title:',self.__title\n",
+ " print ' golf club dues:',self.__dues\n",
+ " \n",
+ " \n",
+ " \n",
+ "class scientist(employee): #scientist class\n",
+ " \n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__pubs = raw_input(\" Enter Number of pubs: \") #number of publication\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Number of publications:',self.__pubs\n",
+ " \n",
+ " \n",
+ " \n",
+ "class laborer(employee): #labour class\n",
+ " pass \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "z = 0\n",
+ "while True:\n",
+ " \n",
+ " print \"\\n'a' --to add data for an employee \\n'd' --display data for all employees\\n'w' --write all employee data to file\"\n",
+ " print \"'r' --read all employee data to file\\n'x' --exit\"\n",
+ " ch = raw_input(\"Enter selection: \")\n",
+ " \n",
+ " if ch == 'a': #add an employee to list\n",
+ " z += 1\n",
+ " employee().add()\n",
+ " \n",
+ " elif ch == 'd': #display all employess\n",
+ " employee().display()\n",
+ " \n",
+ " elif ch == 'w': #write employee to file\n",
+ " employee().write()\n",
+ " \n",
+ " elif ch == 'r': #read all employee from file\n",
+ " employee().read(z)\n",
+ " \n",
+ " elif ch == 'x': #exit program\n",
+ " break;\n",
+ " else:\n",
+ " print 'Unknown command'\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: a\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "'m' to add manager \n",
+ "'s' to add a scientist\n",
+ "'l' to add a laborer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: m\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Johnson\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 1111\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Title: President\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter golf club dues: 20000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: a\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "'m' to add manager \n",
+ "'s' to add a scientist\n",
+ "'l' to add a laborer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Faraday\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 2222\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of pubs: 99\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: a\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "'m' to add manager \n",
+ "'s' to add a scientist\n",
+ "'l' to add a laborer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: l\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Smith\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 3333\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: w\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Writing 3 employees.\n",
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: r\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reading 3 employees\n",
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: d\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 . Type: Manager\n",
+ " Name: Johnson\n",
+ " Number: 1111\n",
+ " Title: President\n",
+ " Number: 20000\n",
+ "2 . Type: Manager\n",
+ " Name: Faraday\n",
+ " Number: 2222\n",
+ " Number of publications: 99\n",
+ "3 . Type: Manager\n",
+ " Name: Smith\n",
+ " Number: 3333\n",
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: x\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.18, Page Number 616"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ "def gd(d): #get length from user (friend function)\n",
+ " d._Distance__feet = input('\\nEnter feet:')\n",
+ " d._Distance__inches = input('Enter inches:')\n",
+ " \n",
+ " \n",
+ " \n",
+ "def sd(d): #display distance (friend function)\n",
+ " print d._Distance__feet , '\\' -' , d._Distance__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "#define distances\n",
+ "dist1 = Distance()\n",
+ "dist2 = Distance()\n",
+ "\n",
+ "#define and initialize dist3\n",
+ "dist3 = Distance(11,6.25)\n",
+ "\n",
+ "#get dist1 and dist2 from user\n",
+ "print 'Enter two Distance value:',\n",
+ "gd(dist1)\n",
+ "gd(dist2)\n",
+ "\n",
+ "#display all lengths\n",
+ "print '\\ndist1 = ',;sd(dist1)\n",
+ "print 'dist2 = ',;sd(dist2)\n",
+ "print 'dist3 = ',;sd(dist3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two Distance value:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter feet:10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:3.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter feet:12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "dist1 = 10 ' - 3.5 \"\n",
+ "dist2 = 12 ' - 6 \"\n",
+ "dist3 = 11 ' - 6.25 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.19, Page Number 618"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import pickle\n",
+ "\n",
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ "def gd(d): #get length from user (friend function)\n",
+ " d._Distance__feet,dummy,dummy,d._Distance__inches,dummy = input(),raw_input(),raw_input(),input(),raw_input()\n",
+ " \n",
+ " \n",
+ " \n",
+ "def sd(d): #display distance (friend function)\n",
+ " print d._Distance__feet , '\\' -' , d._Distance__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "dist1 = Distance()\n",
+ "ofile = open('Dist.txt','w') #create and open a file\n",
+ "\n",
+ "z=0\n",
+ "while True:\n",
+ " print 'Enter Distance:'\n",
+ " gd(dist1) #get distance from user\n",
+ " pickle.dump(dist1,ofile) #write it to file\n",
+ " z += 1\n",
+ " ch = raw_input(\"Enter another person (y/n)? \")\n",
+ " if(ch == 'n'):\n",
+ " break\n",
+ " \n",
+ "ofile.close() #close file\n",
+ "\n",
+ "\n",
+ "\n",
+ "ifile = open('Dist.txt','r') #open same file in read mode\n",
+ "\n",
+ "print '\\nContents of disk file is:'\n",
+ "for j in range(z):\n",
+ " dist1 = pickle.load(ifile) #read dist from stream\n",
+ " print 'Distance =',;sd(dist1) #display dist"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Distance:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "'\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\"\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Distance:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "'\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11.25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\"\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Distance:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "'\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\"\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Contents of disk file is:\n",
+ "Distance = 3 ' - 4.5 \"\n",
+ "Distance = 7 ' - 11.25 \"\n",
+ "Distance = 11 ' - 6 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.20, Page Number 621"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " #test data\n",
+ "ch = 'x'\n",
+ "j=77\n",
+ "d=67890.12345\n",
+ "str1 = \"Kafka\"\n",
+ "str2 = \"Freud\"\n",
+ "\n",
+ " #print data\n",
+ "print 'ch =',ch\n",
+ "print 'j =',j\n",
+ "print 'd = %.2f' %d\n",
+ "print 'str1 =',str1\n",
+ "print 'str2 =',str2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ch = x\n",
+ "j = 77\n",
+ "d = 67890.12\n",
+ "str1 = Kafka\n",
+ "str2 = Freud\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.21, Page Number 622"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "print 'argc =',len(sys.argv) #number of arguments\n",
+ "\n",
+ "for j in range(len(sys.argv)): #display arguments\n",
+ " print 'Argument',j,'=',sys.argv[j] "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "argc = 8\n",
+ "Argument 0 = -c\n",
+ "Argument 1 = -f\n",
+ "Argument 2 = C:\\Users\\Aman Jain\\.ipython\\profile_default\\security\\kernel-dfe059f6-c65f-4f35-99cb-1d8e989160d1.json\n",
+ "Argument 3 = --IPKernelApp.parent_appname='ipython-notebook'\n",
+ "Argument 4 = --profile-dir\n",
+ "Argument 5 = C:\\Users\\Aman Jain\\.ipython\\profile_default\n",
+ "Argument 6 = --interrupt=2108\n",
+ "Argument 7 = --parent=2096\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.22, Page Number 623"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ " \n",
+ "if not(len(sys.argv)==2): \n",
+ " print \"Format: otype filename\"\n",
+ "else:\n",
+ " #Open a file\n",
+ " infile=open(sys.argv[1],'r')\n",
+ "\n",
+ " #In case file cannot open\n",
+ " if(not(infile)):\n",
+ " print \"Cannot open file.\"\n",
+ " else:\n",
+ " #Read file\n",
+ " ch=In.read()\n",
+ " print ch\n",
+ " In.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Format: otype filename\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.23, Page Number 625"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s1 = \"\\nToday's winning number is \"\n",
+ "n1 = \"17982\"\n",
+ "\n",
+ "outfile = open(\"PRN1.txt\",'w') #open the file\n",
+ "\n",
+ " #send data to file\n",
+ "outfile.write(s1)\n",
+ "outfile.write(n1)\n",
+ "outfile.write(\"\\x0C\")\n",
+ "\n",
+ "outfile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.24, Page Number 625"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ " \n",
+ "if not(len(sys.argv)==2):\n",
+ " print \"Format: otype filename\"\n",
+ "else:\n",
+ " #Open a file\n",
+ " infile=open(sys.argv[1],'r')\n",
+ "\n",
+ " #In case file cannot open\n",
+ " if(not(infile)):\n",
+ " print \"Cannot open file.\"\n",
+ " else:\n",
+ " outfile = open(\"PRN1.txt\")\n",
+ " ch=In.read()\n",
+ " print ch\n",
+ " In.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Format: otype filename\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter12StreamsandFiles_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter12StreamsandFiles_1.ipynb
new file mode 100755
index 00000000..9fe9ce48
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter12StreamsandFiles_1.ipynb
@@ -0,0 +1,2349 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:b48cc425e2e366b5a35958662f2d34871e2684f73effc1a069ca138f751726b7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12: Streams and Files"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.1, Page Number 581"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def isFeet(str): #return true if the string is a correct feet value\n",
+ " \n",
+ " slen = len(str) #get length\n",
+ " \n",
+ " if slen==0 or slen>5: #if no input, or too long \n",
+ " return False #not an int\n",
+ " \n",
+ " \n",
+ " for j in range(slen): #check each character\n",
+ " \n",
+ " if (str[j] < '0' or str[j] > '9' ) and str[j] != '-': #if not digit or minus\n",
+ " return False #string is not correct feet\n",
+ " \n",
+ " \n",
+ " n = float(str) #convert to float\n",
+ " \n",
+ " if(n<-999.0 or n>999.0): #is it out of range\n",
+ " return False #if so, not correct feet\n",
+ " \n",
+ " return True #it is correct feet\n",
+ "\n",
+ "\n",
+ "\n",
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " \n",
+ " while True:\n",
+ " self.__feet = raw_input('Enter feet:') #it will not skip white space\n",
+ " \n",
+ " if(isFeet(self.__feet)): #is it a correct feet value?\n",
+ " \n",
+ " self.__feet.replace(' ','') #eat white spaces\n",
+ " self.__feet = int(self.__feet) #convert to integer\n",
+ " break; #break out of 'while'\n",
+ " \n",
+ " print 'Feet must be an integer less than 1000'\n",
+ " \n",
+ " \n",
+ " while True: #cycle untill inches are right\n",
+ " \n",
+ " self.__inches = input('Enter inches:') #get inches and do not skip white space\n",
+ " \n",
+ " if(self.__inches<12.0 and self.__inches>0.0):\n",
+ " break;\n",
+ " \n",
+ " if(self.__inches>=12.0 or self.__inches<0.0):\n",
+ " print 'Inches must be between 0.0 and 11.99'\n",
+ " print 'Incorrect inches input' \n",
+ " \n",
+ " \n",
+ " \n",
+ "d = Distance() #make a distance object\n",
+ "\n",
+ "while True:\n",
+ " d.getdist() #get its value from user\n",
+ " \n",
+ " print 'Distance =',;d.showdist() #display it\n",
+ " \n",
+ " ans = raw_input(\"Do another (y/n)? \")\n",
+ " \n",
+ " if ans == 'n': #cycle untill 'n'\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:1 2 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Feet must be an integer less than 1000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:9999\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Feet must be an integer less than 1000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:99\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:14\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inches must be between 0.0 and 11.99\n",
+ "Incorrect inches input\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:11\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Distance = 99 ' - 11 \"\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:-98\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:12\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inches must be between 0.0 and 11.99\n",
+ "Incorrect inches input\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:-98\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Inches must be between 0.0 and 11.99\n",
+ "Incorrect inches input\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:11\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Distance = -98 ' - 11 \"\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do another (y/n)? n\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.2, Page Number 584"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ch = \"x\"\n",
+ "str1 = \"Kafka\" #strings without white spaces\n",
+ "str2 = \"Proust\"\n",
+ "\n",
+ "outfile=open(\"fdata.txt\",'w') #open a file \n",
+ "\n",
+ "outfile.write(ch) #insert (write) data\n",
+ "outfile.write(\"77\")\n",
+ "outfile.write(\"6.02\")\n",
+ "outfile.write(' ') #needed space between numbers and string\n",
+ "outfile.write(str1)\n",
+ "outfile.write(' ') #needed space between strings\n",
+ "outfile.write(str2)\n",
+ "\n",
+ "print 'File written'\n",
+ "outfile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "File written\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.3, Page Number 585"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "infile = open(\"fdata.txt\",'r') #open the file for reading\n",
+ "\n",
+ "ch = infile.read(1) #extract (read) data from it\n",
+ "j = infile.read(2)\n",
+ "d = infile.read(5)\n",
+ "str1 = infile.read(6)\n",
+ "str2 = infile.read()\n",
+ "\n",
+ "print ch,\"\\n\",j,\"\\n\",d,\"\\n\",str1,\"\\n\",str2,\"\\n\", #display the data"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x \n",
+ "77 \n",
+ "6.02 \n",
+ "Kafka \n",
+ "Proust \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.4, Page Number 586"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "outfile = open(\"TEST.TXT\",'w') #create a file for output\n",
+ "\n",
+ "#send text to file\n",
+ "outfile.write(\"I fear thee, ancient Marner!\\n\") \n",
+ "outfile.write(\"I fear thy skinny hand\\n\")\n",
+ "outfile.write(\"And thou art long, and lank, and brown,\\n\")\n",
+ "outfile.write(\"As is the ribbed sea sand.\\n\")\n",
+ "\n",
+ "outfile.close() #close the file"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.5, Page Number 587"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 80 #size of buffer\n",
+ "buffer = []*MAX #character buffer\n",
+ "\n",
+ "infile = open(\"TEST.TXT\",'r') #open a file to read\n",
+ "\n",
+ "buffer = infile.readline() #read one line from the file\n",
+ "\n",
+ "while buffer: #untill buffer has some data in it or untill end-of-file\n",
+ " print buffer, #display buffer\n",
+ " buffer = infile.readline() #read a line of text\n",
+ " \n",
+ "infile.close() #close file"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I fear thee, ancient Marner!\n",
+ "I fear thy skinny hand\n",
+ "And thou art long, and lank, and brown,\n",
+ "As is the ribbed sea sand.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.6, Page Number 588"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str = \"Time is a great teache, but unfortunately \" + \"it kills all its puplies. Berlioz\"\n",
+ "\n",
+ "outfile = open(\"Test.txt\",\"w\") #create file for output\n",
+ "\n",
+ "for j in range(len(str)): #for each character\n",
+ " ch = \"\"+str[j]\n",
+ " outfile.write(ch),\n",
+ " \n",
+ "print \"File written\"\n",
+ "outfile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "File written\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.7, Page Number 588"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "infile = open(\"Test.txt\",\"r\") #open file for read\n",
+ "\n",
+ "ch = infile.read(1) #read character\n",
+ " \n",
+ "while ch != '': #read untill EOF\n",
+ " print ch, #display it\n",
+ " ch = infile.read(1) #read character"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "T i m e i s a g r e a t t e a c h e , b u t u n f o r t u n a t e l y i t k i l l s a l l i t s p u p l i e s . B e r l i o z\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.8, Page Number 589"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "infile = open(\"Test.txt\",\"r\") #open file for read\n",
+ "\n",
+ "print infile.read() #read whole file and print it"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time is a great teache, but unfortunately it kills all its puplies. Berlioz\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.9, Page Number 590"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 100 #size of buffer\n",
+ "buff = [j for j in range(MAX)] #buffer for integers and fill buffer with data (0, 1, 2, ...)\n",
+ "\n",
+ "os = open(\"edata.txt\",'r+b') #first make edata.txt file\n",
+ "\n",
+ "s = ''\n",
+ "for j in range(MAX): \n",
+ " s += '%d' %buff[j] \n",
+ "os.write(s) #write to file\n",
+ "\n",
+ "\n",
+ "for j in range(MAX): #erase buffer\n",
+ " buff[j] = 0\n",
+ " \n",
+ " \n",
+ "os.seek(0,0)\n",
+ "\n",
+ "#read data from file\n",
+ "for j in range (10):\n",
+ " buff[j] = os.read(1)\n",
+ " \n",
+ "for j in range(10,MAX):\n",
+ " buff[j] = os.read(2)\n",
+ " \n",
+ " \n",
+ "c=0\n",
+ "for j in range(MAX): #check data\n",
+ " if int(buff[j])!=j:\n",
+ " print \"Data is incorrect\\n\"\n",
+ " c=1\n",
+ " break\n",
+ " \n",
+ "if c==0:\n",
+ " print \"Data is correct\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Data is correct\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.10, Page Number 592"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from pickle import dump\n",
+ "\n",
+ "class person: #class person\n",
+ " \n",
+ " def getData(self): #get person's data\n",
+ " self.name = raw_input(\"Enter name: \") #person's name\n",
+ " self.age = input(\"Enter age: \") #person's age\n",
+ " \n",
+ " \n",
+ " \n",
+ "pers = person() #create a person\n",
+ "pers.getData() #get data for person\n",
+ "\n",
+ "outfile = open(\"PERSON.txt\",'wb') #open file for write obect to it\n",
+ "\n",
+ "dump(pers, outfile) #write object\n",
+ "\n",
+ "outfile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Coleridge\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 62\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.11, Page Number 593"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from pickle import load\n",
+ "\n",
+ "class person:\n",
+ " \n",
+ " def showData(self): #display person's data\n",
+ " print \"Name:\",self.name #person's name\n",
+ " print \"Age:\",self.age #person's age\n",
+ " \n",
+ " \n",
+ " \n",
+ "pers = person() #create person variable\n",
+ "\n",
+ "infile = open(\"PERSON.txt\",'rb') #open file in binary mode\n",
+ "\n",
+ "pers = load(infile) #read object \n",
+ "pers.showData() #display person"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Coleridge\n",
+ "Age: 62\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.12, Page Number 594"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from pickle import dump,load\n",
+ "\n",
+ "class person: #class of persons\n",
+ " \n",
+ " def getData(self): #get person's data\n",
+ " self._name = raw_input(\"Enter name: \")\n",
+ " self._age = input(\"Enter age: \")\n",
+ " \n",
+ " def showData(self): #display person's data\n",
+ " print \" Name:\",self._name\n",
+ " print \" Age:\",self._age\n",
+ " \n",
+ " \n",
+ " \n",
+ "pers = person() #create person object\n",
+ "file = open(\"Group.txt\",'r+b') #open file\n",
+ "c=0 #for total number of objects\n",
+ "\n",
+ "\n",
+ "while True: \n",
+ " print \"\\nEnter person's data: \"\n",
+ " pers.getData() #get one person's data\n",
+ " dump(pers, file) #wriet to file\n",
+ " c += 1\n",
+ " \n",
+ " ch = raw_input(\"Enter another person (y/n)? \")\n",
+ " if(ch == 'n'):\n",
+ " break\n",
+ " \n",
+ " \n",
+ "file.seek(0,0)\n",
+ "\n",
+ "print ''\n",
+ "for j in range(c):\n",
+ " print 'person:'\n",
+ " pers = load(file) #read person from file\n",
+ " pers.showData() #display person"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Whitney\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Rainier\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 21\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: McKinley\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 22\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "person:\n",
+ " Name: Whitney\n",
+ " Age: 20\n",
+ "person:\n",
+ " Name: Rainier\n",
+ " Age: 21\n",
+ "person:\n",
+ " Name: McKinley\n",
+ " Age: 22\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.13, Page Number 599"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from pickle import load\n",
+ "\n",
+ "class person: #class of person's\n",
+ " \n",
+ " def getData(self): #get person's data\n",
+ " self._name = raw_input(\"Enter name: \")\n",
+ " self._age = input(\"Enter age: \")\n",
+ " \n",
+ " def showData(self): #dislay person's data\n",
+ " print \" Name:\",self._name\n",
+ " print \" Age:\",self._age\n",
+ " \n",
+ " \n",
+ " \n",
+ "pers = person() #create person object\n",
+ "infile = open(\"Group.txt\",'r+b') #create input file and open it\n",
+ "c=3\n",
+ "print 'There are',c,'persons in file' #print number of objects in file\n",
+ "\n",
+ "n = input(\"Enter person number: \")\n",
+ "\n",
+ "print ''\n",
+ "for j in range(3):\n",
+ " pers = load(infile) #read one person\n",
+ " if j==n-1:\n",
+ " pers.showData() #display the person"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "There are 3 persons in file\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter person number: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Name: Rainier\n",
+ " Age: 21\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.14, Page Number 601"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from pickle import dump,load\n",
+ "\n",
+ "MAX = 1000\n",
+ "buff = []*1000\n",
+ "\n",
+ "for j in range(MAX): #fill buffer with data\n",
+ " buff.append(j)\n",
+ "\n",
+ "try:\n",
+ " os = open(\"edata.txt\",'r+b') #open a file\n",
+ "\n",
+ "except IOError:\n",
+ " print \"could not open output file\"\n",
+ " \n",
+ "print 'Writing...'\n",
+ "\n",
+ "try:\n",
+ " dump(buff, os) #write buffer to it\n",
+ "except IOError:\n",
+ " print \"could not write ot file\"\n",
+ " \n",
+ "os.close() #must close it\n",
+ "\n",
+ "\n",
+ "\n",
+ "for j in range(MAX): #clear buffer\n",
+ " buff[j]=0\n",
+ " \n",
+ "try:\n",
+ " is1 = open(\"edata.txt\",'r+b') #open the same file in read mode\n",
+ "\n",
+ "except IOError:\n",
+ " print \"could not open output file\"\n",
+ " \n",
+ "print 'Reading...'\n",
+ "\n",
+ "try:\n",
+ " buff = load(is1) #read file data and put it into a buffer\n",
+ "except IOError:\n",
+ " print \"could not read from file\"\n",
+ " \n",
+ "c=0\n",
+ "for j in range(MAX): #check data\n",
+ " if int(buff[j])!=j:\n",
+ " print \"Data is incorrect\\n\"\n",
+ " c=1\n",
+ " break\n",
+ " \n",
+ "if c==0:\n",
+ " print \"Data is correct\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Writing...\n",
+ "Reading...\n",
+ "Data is correct\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.15, Page Number 603"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class error: #class error#\n",
+ " \n",
+ " def rdstate(self): #show the error state\n",
+ " try:\n",
+ " file = open(\"GROUP1.txt\",'r')\n",
+ " return 0\n",
+ " \n",
+ " except IOError:\n",
+ " return 4\n",
+ " \n",
+ " def good(self): #check no error occur to open the file\n",
+ " try:\n",
+ " file = open(\"GROUP1.txt\",'r')\n",
+ " return 1\n",
+ " \n",
+ " except IOError:\n",
+ " return 0\n",
+ " \n",
+ " def eof(self): #check end-of-file\n",
+ " try:\n",
+ " file = open(\"GROUP1.txt\",'r')\n",
+ " return 1\n",
+ " \n",
+ " except IOError:\n",
+ " return 0\n",
+ " \n",
+ " def fail(self): #check any error has come?\n",
+ " try:\n",
+ " file = open(\"GROUP1.txt\",'r')\n",
+ " return 0\n",
+ " \n",
+ " except IOError:\n",
+ " return 4\n",
+ " \n",
+ " def bad(self): #file can't be open\n",
+ " try:\n",
+ " file = open(\"GROUP1.txt\",'r')\n",
+ " return 0\n",
+ " \n",
+ " except IOError:\n",
+ " return 4\n",
+ "\n",
+ "\n",
+ "try:\n",
+ " file = open(\"GROUP1.txt\",'r')\n",
+ " \n",
+ "except IOError:\n",
+ " print \"can't open output file\"\n",
+ "\n",
+ "print 'file =',hex(id(file))\n",
+ "\n",
+ "file = error()\n",
+ "\n",
+ "print 'Error state =',file.rdstate()\n",
+ "print 'good() =',file.good()\n",
+ "print 'eof() =',file.eof()\n",
+ "print 'fail() =',file.fail()\n",
+ "print 'bad() =',file.bad()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "can't open output file\n",
+ "file = 0x37cd270L\n",
+ "Error state = 4\n",
+ "good() = 0\n",
+ "eof() = 0\n",
+ "fail() = 4\n",
+ "bad() = 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.16, Page Number 604"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from pickle import dump,load\n",
+ "\n",
+ "class person: #class of persons\n",
+ "\n",
+ " def getData(self): #get person's data\n",
+ " self._name = raw_input(\"Enter name: \") #person's name\n",
+ " self._age = input(\"Enter age: \") #person's age\n",
+ " \n",
+ " \n",
+ " def showData(self): #display person's data\n",
+ " print \" Name:\",self._name\n",
+ " print \" Age:\",self._age\n",
+ " \n",
+ " \n",
+ " def diskIn(self,pn,c): #read person number pn from file\n",
+ " \n",
+ " infile = open(\"PERSFILE.txt\",'r+b') #open file\n",
+ " \n",
+ " for j in range(c):\n",
+ " self = load(infile) #read one person\n",
+ " \n",
+ " if j==pn:\n",
+ " return self;\n",
+ " \n",
+ " \n",
+ " def diskOut(self): #write person to end of file\n",
+ " \n",
+ " outfile = open(\"PERSFILE.txt\",'ab') #open file\n",
+ " dump(self, outfile) #write to it\n",
+ " outfile.close()\n",
+ " \n",
+ " \n",
+ " def diskCount(self,c): #return number of persons in file\n",
+ " return c \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "p = person() #make an empty person\n",
+ "c=0\n",
+ "outfile = open(\"PERSFILE.txt\",'wb') #open file to delete its containt\n",
+ "outfile.close()\n",
+ "\n",
+ "while True: #save person to disk\n",
+ " print \"\\nEnter person's data: \"\n",
+ " p.getData() #get data \n",
+ " p.diskOut() #write to disk\n",
+ " c += 1\n",
+ " \n",
+ " ch = raw_input(\"Enter another person (y/n)? \")\n",
+ " if(ch == 'n'): #untill user enters 'n'\n",
+ " break \n",
+ " \n",
+ "c = p.diskCount(c) #how many persons are in file?\n",
+ "\n",
+ "print 'There are',c,'persons in file'\n",
+ "\n",
+ "print ''\n",
+ "for j in range(c): #for each person\n",
+ " print 'person'\n",
+ " p = p.diskIn(j,c) #read person from disk\n",
+ " p.showData() #display person"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Stimson\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 45\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Hull\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 58\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Acheson\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 63\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter person's data: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Dules\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age: 72\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "There are 4 persons in file\n",
+ "\n",
+ "person\n",
+ " Name: Stimson\n",
+ " Age: 45\n",
+ "person\n",
+ " Name: Hull\n",
+ " Age: 58\n",
+ "person\n",
+ " Name: Acheson\n",
+ " Age: 63\n",
+ "person\n",
+ " Name: Dules\n",
+ " Age: 72\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.17, Page Number 608"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sys import getsizeof\n",
+ "from pickle import dump,load\n",
+ "\n",
+ "employee_type = [\"tmanager\",\"tscientist\",\"tlaborer\"] \n",
+ "(tmanager,tscientist,tlaborer) = (0,1,2) #Atteching the names with number \n",
+ "\n",
+ "LEN = 32 #maximum length of last names\n",
+ "MAXEM = 100 #maximum length of employees\n",
+ "\n",
+ "\n",
+ "\n",
+ "class employee: #employee class\n",
+ " __name = [None]*LEN #employee name\n",
+ " __n = 0 #current number of employee\n",
+ " __arrap = [] #array of ptrs to emps\n",
+ " \n",
+ " def getdata(self): #get data from user\n",
+ " self.__name = raw_input(\" Enter last name: \")\n",
+ " self.__number = input(\" Enter number: \") #employee number\n",
+ " \n",
+ " def putdata(self): #display data\n",
+ " print ' Name:',self.__name \n",
+ " print ' Number:',self.__number\n",
+ " \n",
+ " \n",
+ " def get_type(self): #return the type of object\n",
+ " \n",
+ " if getsizeof(self)==getsizeof(manager()):\n",
+ " return tmanager\n",
+ " elif getsizeof(self)==getsizeof(scientisit()):\n",
+ " return tscientist\n",
+ " elif getsizeof(self)==getsizeof(laborer()):\n",
+ " return tlaborer\n",
+ " else:\n",
+ " print 'Bad employee type'\n",
+ " return tmanager\n",
+ " \n",
+ " \n",
+ " def add(self): #add employee to list in memory\n",
+ " \n",
+ " print \"'m' to add manager \\n's' to add a scientist\\n'l' to add a laborer\"\n",
+ " ch = raw_input(\"Enter selection: \")\n",
+ " \n",
+ " #create specific employee type\n",
+ " if ch=='m':\n",
+ " employee.__arrap.append(manager())\n",
+ " \n",
+ " elif ch=='s':\n",
+ " employee.__arrap.append(scientist())\n",
+ " \n",
+ " elif ch=='l':\n",
+ " employee.__arrap.append(laborer())\n",
+ " \n",
+ " else:\n",
+ " print 'Unknown command'\n",
+ " \n",
+ " employee.__arrap[employee.__n].getdata() #get employee data from user\n",
+ " employee.__n += 1 #increase the number of employee\n",
+ " \n",
+ " \n",
+ " def display(self): #display all employees\n",
+ " \n",
+ " for j in range(employee.__n):\n",
+ " print j+1, #display number\n",
+ " \n",
+ " #display type\n",
+ " if employee.__arrap[j].get_type()==tmanager:\n",
+ " print '. Type: Manager'\n",
+ " \n",
+ " elif employee.__arrap[j].get_type()==tscientist:\n",
+ " print '. Type: scientist'\n",
+ " \n",
+ " elif employee.__arrap[j].get_type()==tlaborer:\n",
+ " print '. Type: laborer'\n",
+ " \n",
+ " else:\n",
+ " print '. Unknown type'\n",
+ " \n",
+ " employee.__arrap[j].putdata() #display employee data\n",
+ " \n",
+ " \n",
+ " def write(self): #write all current memory object to file\n",
+ " ouf = open(\"EMPLOY.txt\",'w')\n",
+ " ouf.close()\n",
+ " \n",
+ " print 'Writing',employee.__n,'employees.'\n",
+ " \n",
+ " try:\n",
+ " ouf = open(\"EMPLOY.txt\",'ab') #open file in binary mode\n",
+ " except IOError:\n",
+ " print \"could not open file\"\n",
+ " \n",
+ " \n",
+ " for j in range(employee.__n): #for every employee objects\n",
+ " \n",
+ " etype = employee.__arrap[j].get_type() #get its type\n",
+ " dump(etype, ouf) #write type to file\n",
+ " \n",
+ " #find its size\n",
+ " if etype == tmanager:\n",
+ " size = getsizeof(manager)\n",
+ " elif etype == tscientist:\n",
+ " size = getsizeof(scientist)\n",
+ " elif etype == tlaborer:\n",
+ " size = getsizeof(laborer)\n",
+ " \n",
+ " try:\n",
+ " dump(employee.__arrap[j], ouf) #write employee object to file\n",
+ " except IOError:\n",
+ " print \"could not write to file\"\n",
+ " \n",
+ " ouf.close() #close the file\n",
+ " \n",
+ " \n",
+ " \n",
+ " def read(self,c): #read data for all employee from file into memory\n",
+ " \n",
+ " try:\n",
+ " inf = open(\"EMPLOY.txt\",'rb') #open file into binary mode\n",
+ " except IOError:\n",
+ " print \"could not open file\"\n",
+ " \n",
+ " employee.__n = 0 #no employee in memeory yet\n",
+ " \n",
+ " for j in range(c):\n",
+ " \n",
+ " try:\n",
+ " etype = load(inf) #read type of next employee\n",
+ " except IOError:\n",
+ " print \"could not read type from file\"\n",
+ " \n",
+ " if j==c:\n",
+ " break\n",
+ " \n",
+ " if etype == tmanager: #make new employee of correct type\n",
+ " employee.__arrap[employee.__n] = manager()\n",
+ " size = getsizeof(manager)\n",
+ " elif etype == tscientist:\n",
+ " employee.__arrap[employee.__n] = scientist()\n",
+ " size = getsizeof(scientist)\n",
+ " elif etype == tlaborer:\n",
+ " employee.__arrap[employee.__n] = laborer()\n",
+ " size = getsizeof(laborer)\n",
+ " else:\n",
+ " print 'Unknown type in file'\n",
+ " \n",
+ " try:\n",
+ " employee.__arrap[employee.__n] = load(inf) #read data from file into it\n",
+ " except IOError:\n",
+ " print \"could not read type from file\"\n",
+ " \n",
+ " employee.__n += 1 #count employee\n",
+ " \n",
+ " print 'Reading',employee.__n,'employees'\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "class manager(employee): #management class\n",
+ " __title = [None]*LEN #'vice-president' etc. \n",
+ " \n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__title = raw_input(\" Enter Title: \")\n",
+ " self.__dues = input(\" Enter golf club dues: \") #golf club dues\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Title:',self.__title\n",
+ " print ' golf club dues:',self.__dues\n",
+ " \n",
+ " \n",
+ " \n",
+ "class scientist(employee): #scientist class\n",
+ " \n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__pubs = raw_input(\" Enter Number of pubs: \") #number of publication\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Number of publications:',self.__pubs\n",
+ " \n",
+ " \n",
+ " \n",
+ "class laborer(employee): #labour class\n",
+ " pass \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "z = 0\n",
+ "while True:\n",
+ " \n",
+ " print \"\\n'a' --to add data for an employee \\n'd' --display data for all employees\\n'w' --write all employee data to file\"\n",
+ " print \"'r' --read all employee data to file\\n'x' --exit\"\n",
+ " ch = raw_input(\"Enter selection: \")\n",
+ " \n",
+ " if ch == 'a': #add an employee to list\n",
+ " z += 1\n",
+ " employee().add()\n",
+ " \n",
+ " elif ch == 'd': #display all employess\n",
+ " employee().display()\n",
+ " \n",
+ " elif ch == 'w': #write employee to file\n",
+ " employee().write()\n",
+ " \n",
+ " elif ch == 'r': #read all employee from file\n",
+ " employee().read(z)\n",
+ " \n",
+ " elif ch == 'x': #exit program\n",
+ " break;\n",
+ " else:\n",
+ " print 'Unknown command'\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: a\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "'m' to add manager \n",
+ "'s' to add a scientist\n",
+ "'l' to add a laborer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: m\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Johnson\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 1111\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Title: President\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter golf club dues: 20000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: a\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "'m' to add manager \n",
+ "'s' to add a scientist\n",
+ "'l' to add a laborer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: s\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Faraday\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 2222\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of pubs: 99\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: a\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "'m' to add manager \n",
+ "'s' to add a scientist\n",
+ "'l' to add a laborer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: l\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Smith\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 3333\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: w\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Writing 3 employees.\n",
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: r\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reading 3 employees\n",
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: d\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 . Type: Manager\n",
+ " Name: Johnson\n",
+ " Number: 1111\n",
+ " Title: President\n",
+ " golf club dues: 20000\n",
+ "2 . Type: Manager\n",
+ " Name: Faraday\n",
+ " Number: 2222\n",
+ " Number of publications: 99\n",
+ "3 . Type: Manager\n",
+ " Name: Smith\n",
+ " Number: 3333\n",
+ "\n",
+ "'a' --to add data for an employee \n",
+ "'d' --display data for all employees\n",
+ "'w' --write all employee data to file\n",
+ "'r' --read all employee data to file\n",
+ "'x' --exit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter selection: x\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.18, Page Number 616"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ "def gd(d): #get length from user (friend function)\n",
+ " d._Distance__feet = input('\\nEnter feet:')\n",
+ " d._Distance__inches = input('Enter inches:')\n",
+ " \n",
+ " \n",
+ " \n",
+ "def sd(d): #display distance (friend function)\n",
+ " print d._Distance__feet , '\\' -' , d._Distance__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "#define distances\n",
+ "dist1 = Distance()\n",
+ "dist2 = Distance()\n",
+ "\n",
+ "#define and initialize dist3\n",
+ "dist3 = Distance(11,6.25)\n",
+ "\n",
+ "#get dist1 and dist2 from user\n",
+ "print 'Enter two Distance value:',\n",
+ "gd(dist1)\n",
+ "gd(dist2)\n",
+ "\n",
+ "#display all lengths\n",
+ "print '\\ndist1 = ',;sd(dist1)\n",
+ "print 'dist2 = ',;sd(dist2)\n",
+ "print 'dist3 = ',;sd(dist3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two Distance value:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter feet:10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:3.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter feet:12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "dist1 = 10 ' - 3.5 \"\n",
+ "dist2 = 12 ' - 6 \"\n",
+ "dist3 = 11 ' - 6.25 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.19, Page Number 618"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from pickle import dump,load\n",
+ "\n",
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ "def gd(d): #get length from user (friend function)\n",
+ " d._Distance__feet,dummy,dummy,d._Distance__inches,dummy = input(),raw_input(),raw_input(),input(),raw_input()\n",
+ " \n",
+ " \n",
+ " \n",
+ "def sd(d): #display distance (friend function)\n",
+ " print d._Distance__feet , '\\' -' , d._Distance__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "dist1 = Distance()\n",
+ "ofile = open('Dist.txt','w') #create and open a file\n",
+ "\n",
+ "z=0\n",
+ "while True:\n",
+ " print 'Enter Distance:'\n",
+ " gd(dist1) #get distance from user\n",
+ " dump(dist1,ofile) #write it to file\n",
+ " z += 1\n",
+ " ch = raw_input(\"Enter another person (y/n)? \")\n",
+ " if(ch == 'n'):\n",
+ " break\n",
+ " \n",
+ "ofile.close() #close file\n",
+ "\n",
+ "\n",
+ "\n",
+ "ifile = open('Dist.txt','r') #open same file in read mode\n",
+ "\n",
+ "print '\\nContents of disk file is:'\n",
+ "for j in range(z):\n",
+ " dist1 = load(ifile) #read dist from stream\n",
+ " print 'Distance =',;sd(dist1) #display dist"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Distance:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "'\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\"\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Distance:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "'\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11.25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\"\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Distance:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "'\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\"\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another person (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Contents of disk file is:\n",
+ "Distance = 3 ' - 4.5 \"\n",
+ "Distance = 7 ' - 11.25 \"\n",
+ "Distance = 11 ' - 6 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.20, Page Number 621"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " #test data\n",
+ "ch = 'x'\n",
+ "j=77\n",
+ "d=67890.12345\n",
+ "str1 = \"Kafka\"\n",
+ "str2 = \"Freud\"\n",
+ "\n",
+ " #print data\n",
+ "print 'ch =',ch\n",
+ "print 'j =',j\n",
+ "print 'd = %.2f' %d\n",
+ "print 'str1 =',str1\n",
+ "print 'str2 =',str2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ch = x\n",
+ "j = 77\n",
+ "d = 67890.12\n",
+ "str1 = Kafka\n",
+ "str2 = Freud\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.21, Page Number 622"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sys import argv\n",
+ "\n",
+ "print 'argc =',len(argv) #number of arguments\n",
+ "\n",
+ "for j in range(len(argv)): #display arguments\n",
+ " print 'Argument',j,'=',argv[j] "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "argc = 8\n",
+ "Argument 0 = -c\n",
+ "Argument 1 = -f\n",
+ "Argument 2 = C:\\Users\\Aman Jain\\.ipython\\profile_default\\security\\kernel-08538966-3f5b-48ea-8e02-714bd8abf473.json\n",
+ "Argument 3 = --IPKernelApp.parent_appname='ipython-notebook'\n",
+ "Argument 4 = --profile-dir\n",
+ "Argument 5 = C:\\Users\\Aman Jain\\.ipython\\profile_default\n",
+ "Argument 6 = --interrupt=1980\n",
+ "Argument 7 = --parent=1976\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.22, Page Number 623"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sys import argv\n",
+ " \n",
+ "if not(len(argv)==2): \n",
+ " print \"Format: otype filename\"\n",
+ "else:\n",
+ " #Open a file\n",
+ " infile=open(argv[1],'r')\n",
+ "\n",
+ " #In case file cannot open\n",
+ " if(not(infile)):\n",
+ " print \"Cannot open file.\"\n",
+ " else:\n",
+ " #Read file\n",
+ " ch=In.read()\n",
+ " print ch\n",
+ " In.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Format: otype filename\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.23, Page Number 625"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s1 = \"\\nToday's winning number is \"\n",
+ "n1 = \"17982\"\n",
+ "\n",
+ "outfile = open(\"PRN1.txt\",'w') #open the file\n",
+ "\n",
+ " #send data to file\n",
+ "outfile.write(s1)\n",
+ "outfile.write(n1)\n",
+ "outfile.write(\"\\x0C\")\n",
+ "\n",
+ "outfile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12.24, Page Number 625"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sys import argv\n",
+ " \n",
+ "if not(len(argv)==2):\n",
+ " print \"Format: otype filename\"\n",
+ "else:\n",
+ " #Open a file\n",
+ " infile=open(argv[1],'r')\n",
+ "\n",
+ " #In case file cannot open\n",
+ " if(not(infile)):\n",
+ " print \"Cannot open file.\"\n",
+ " else:\n",
+ " outfile = open(\"PRN1.txt\")\n",
+ " ch=In.read()\n",
+ " print ch\n",
+ " In.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Format: otype filename\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter13MultifilePrograms.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter13MultifilePrograms.ipynb
new file mode 100755
index 00000000..9ca5fdbf
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter13MultifilePrograms.ipynb
@@ -0,0 +1,73 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:ab6ac684b51a5d325a82c969da5eb63f77af7f08482f4de24c0a1bba07a7b4b7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13: Multifile Programs"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.1, Page Number 657"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fact = 1\n",
+ "\n",
+ "numb = input(\"Enter number: \") #Enter a long number\n",
+ "\n",
+ "for j in range (numb,0,-1): #factorial is numb * numb-1 * numb-2 * numb-3 and so on\n",
+ " fact *= j\n",
+ " \n",
+ "print \"Factorial is:\",fact #display factorial"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number: 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Factorial is: 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter13MultifilePrograms_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter13MultifilePrograms_1.ipynb
new file mode 100755
index 00000000..9ca5fdbf
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter13MultifilePrograms_1.ipynb
@@ -0,0 +1,73 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:ab6ac684b51a5d325a82c969da5eb63f77af7f08482f4de24c0a1bba07a7b4b7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13: Multifile Programs"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13.1, Page Number 657"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fact = 1\n",
+ "\n",
+ "numb = input(\"Enter number: \") #Enter a long number\n",
+ "\n",
+ "for j in range (numb,0,-1): #factorial is numb * numb-1 * numb-2 * numb-3 and so on\n",
+ " fact *= j\n",
+ " \n",
+ "print \"Factorial is:\",fact #display factorial"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number: 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Factorial is: 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter14TemplatesandExceptions.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter14TemplatesandExceptions.ipynb
new file mode 100755
index 00000000..9d7f2f2d
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter14TemplatesandExceptions.ipynb
@@ -0,0 +1,860 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5687925b0ce89c3c7fdffea973edf76fe3b10da3a53391d98b50115e63f96ddd"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 14: Templates and Exceptions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.1, Page Number 684"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def abs(n): #absolute function\n",
+ " if n<0:\n",
+ " return -n\n",
+ " else:\n",
+ " return n\n",
+ "\n",
+ "#variables\n",
+ "int1 = 5\n",
+ "int2 = -6\n",
+ "lon1 = 70000\n",
+ "lon2 = -80000\n",
+ "dub1 = 9.95\n",
+ "dub2 = -10.15\n",
+ "\n",
+ "#call instantiate functions\n",
+ "print 'abs(%d)=%d' %(int1,abs(int1)) #abs(int)\n",
+ "print 'abs(%d)=%d' %(int2,abs(int2)) #abs(int)\n",
+ "print 'abs(%d)=%d' %(lon1,abs(lon1)) #abs(long)\n",
+ "print 'abs(%d)=%d' %(lon2,abs(lon2)) #abs(long)\n",
+ "print 'abs(%.2f)=%.2f' %(dub1,abs(dub1)) #abs(double)\n",
+ "print 'abs(%.2f)=%.2f' %(dub2,abs(dub2)) #abs(double)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "abs(5)=5\n",
+ "abs(-6)=6\n",
+ "abs(70000)=70000\n",
+ "abs(-80000)=80000\n",
+ "abs(9.95)=9.95\n",
+ "abs(-10.15)=10.15\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.2, Page Number 687"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#function returns index number of item, or -1 if not found\n",
+ "\n",
+ "def find(array, value, size):\n",
+ " for j in range(size):\n",
+ " if array[j] == value:\n",
+ " return j\n",
+ " return -1\n",
+ "\n",
+ "\n",
+ "chrArr = [1, 3, 5, 9, 11, 13] #array\n",
+ "ch = 5 #value to find\n",
+ "\n",
+ "intArr = [1, 3, 5, 9, 11, 13]\n",
+ "int = 6\n",
+ "\n",
+ "lonArr = [1, 3, 5, 9, 11, 13]\n",
+ "lo = 11\n",
+ "\n",
+ "dubArr = [1.0, 3.0, 5.0, 9.0, 11.0, 13.0]\n",
+ "db = 4.0\n",
+ "\n",
+ "print ' 5 in chrArray: index =',find(chrArr,ch,6)\n",
+ "print ' 6 in intArray: index =',find(intArr,int,6)\n",
+ "print '11 in lonArray: index =',find(lonArr,lo,6)\n",
+ "print ' 4 in dubArray: index =',find(dubArr,db,6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 5 in chrArray: index = 2\n",
+ " 6 in intArray: index = -1\n",
+ "11 in lonArray: index = 4\n",
+ " 4 in dubArray: index = -1\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.3, Page Number 691"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 100 #size of array\n",
+ "\n",
+ "class Stack:\n",
+ " __st = [None]*MAX #stack: array of any type\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__top = -1 #number of top of stack\n",
+ " \n",
+ " def push(self,var): #put number on stack\n",
+ " self.__top += 1\n",
+ " self.__st[self.__top] = var\n",
+ " \n",
+ " def pop(self): #take number off stack\n",
+ " x = self.__st[self.__top]\n",
+ " self.__top -= 1\n",
+ " return x\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = Stack() #s1 is object of class Stack\n",
+ "\n",
+ "#push 3 floats, pop 3 floats\n",
+ "s1.push(1111.1)\n",
+ "s1.push(2222.2)\n",
+ "s1.push(3333.3)\n",
+ "print '1:',s1.pop()\n",
+ "print '2:',s1.pop()\n",
+ "print '3:',s1.pop()\n",
+ "\n",
+ "s2 = Stack() #s2 is object of class Stack\n",
+ "\n",
+ "#push 3 longs, pop 3 longs\n",
+ "s2.push(123123123)\n",
+ "s2.push(234234234)\n",
+ "s2.push(345345345)\n",
+ "print '1:',s2.pop()\n",
+ "print '2:',s2.pop()\n",
+ "print '3:',s2.pop()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1: 3333.3\n",
+ "2: 2222.2\n",
+ "3: 1111.1\n",
+ "1: 345345345\n",
+ "2: 234234234\n",
+ "3: 123123123\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.4, Page Number 694"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 100 #size of array\n",
+ "\n",
+ "class Stack:\n",
+ " __st = [None]*MAX #stack: array of any type\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__top = -1 #number of top of stack\n",
+ " \n",
+ " def push(self,var): #put number on stack\n",
+ " self.__top += 1\n",
+ " self.__st[self.__top] = var\n",
+ " \n",
+ " def pop(self): #take number off stack\n",
+ " x = self.__st[self.__top]\n",
+ " self.__top -= 1\n",
+ " return x\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = Stack() #s1 is object of class Stack\n",
+ "\n",
+ "#push 3 floats, pop 3 floats\n",
+ "s1.push(1111.1)\n",
+ "s1.push(2222.2)\n",
+ "s1.push(3333.3)\n",
+ "print '1:',s1.pop()\n",
+ "print '2:',s1.pop()\n",
+ "print '3:',s1.pop()\n",
+ "\n",
+ "s2 = Stack() #s2 is object of class Stack\n",
+ "\n",
+ "#push 3 longs, pop 3 longs\n",
+ "s2.push(123123123)\n",
+ "s2.push(234234234)\n",
+ "s2.push(345345345)\n",
+ "print '1:',s2.pop()\n",
+ "print '2:',s2.pop()\n",
+ "print '3:',s2.pop()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1: 3333.3\n",
+ "2: 2222.2\n",
+ "3: 1111.1\n",
+ "1: 345345345\n",
+ "2: 234234234\n",
+ "3: 123123123\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.5, Page Number 696"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class link:\n",
+ " def __init__(self):\n",
+ " self.data = None #contains the data\n",
+ " self.next = None #contains the reference to the next node\n",
+ "\n",
+ "\n",
+ "class linklist:\n",
+ " def __init__(self):\n",
+ " self.first = None\n",
+ "\n",
+ " def additem(self, d):\n",
+ " newlink = link() #create a new node\n",
+ " newlink.data = d\n",
+ " newlink.next = self.first #link the new node to the 'previous' node.\n",
+ " self.first = newlink #set the current node to the new one.\n",
+ "\n",
+ " def display(self):\n",
+ " current = self.first #set current to first link\n",
+ " \n",
+ " while current:\n",
+ " print current.data\n",
+ " current = current.next\n",
+ "\n",
+ "\n",
+ "\n",
+ " \n",
+ "ld = linklist() #ld is the object of class linkedlist\n",
+ "\n",
+ "#add three doubles to list ld\n",
+ "ld.additem(151.5)\n",
+ "ld.additem(262.6)\n",
+ "ld.additem(373.7)\n",
+ "ld.display() #display entire list ld\n",
+ "\n",
+ "\n",
+ "lch = linklist() #lch is the object of class linkedlist\n",
+ "\n",
+ "#add three chars to list lch\n",
+ "lch.additem('a')\n",
+ "lch.additem('b')\n",
+ "lch.additem('c')\n",
+ "lch.display() #display entire list lch"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "373.7\n",
+ "262.6\n",
+ "151.5\n",
+ "c\n",
+ "b\n",
+ "a\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.6, Page Number 699"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class employee: #employee class\n",
+ " \n",
+ " def __init__(self):\n",
+ " self.__name = []*80 #employee name\n",
+ " self.__number = 0 #employee number\n",
+ " \n",
+ "def ip(e):\n",
+ " e._employee__name = raw_input(\"\\n Enter last name: \")\n",
+ " e._employee__number = input(\" Enter number\")\n",
+ " \n",
+ "def op(e):\n",
+ " print '\\n Name:',e._employee__name\n",
+ " print ' number:',e._employee__number\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "class link:\n",
+ " def __init__(self):\n",
+ " self.data = None #contains the data\n",
+ " self.next = None #contains the reference to the next node\n",
+ "\n",
+ "\n",
+ "class linklist:\n",
+ " def __init__(self):\n",
+ " self.first = None\n",
+ "\n",
+ " def additem(self, d): #add data item\n",
+ " newlink = link() #make a new link\n",
+ " newlink.data = d #give it data\n",
+ " newlink.next = self.first #it points to next link\n",
+ " self.first = newlink #now first points to this\n",
+ "\n",
+ " def display(self):\n",
+ " current = self.first #set ptr to first link\n",
+ " while current: #quit on last link\n",
+ " op(current.data) #print data\n",
+ " current = current.next #move to next link\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "lemp = linklist() #lemp is object of class linkedlist\n",
+ "\n",
+ "\n",
+ "while True:\n",
+ " emptemp = employee() #temporary employee storage \n",
+ " ip(emptemp) #get employee data from user\n",
+ " lemp.additem(emptemp) #add it to linked list 'lemp'\n",
+ " \n",
+ " ans = raw_input(\"Add another (y/n)? \")\n",
+ " \n",
+ " if(ans == 'n'): #when user is done\n",
+ " break;\n",
+ " \n",
+ "lemp.display() #display entire linked list"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Enter last name: Mendez\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number1233\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Add another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Enter last name: Smith\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number2344\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Add another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Enter last name: Chang\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number3455\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Add another (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Name: Chang\n",
+ " number: 3455\n",
+ "\n",
+ " Name: Smith\n",
+ " number: 2344\n",
+ "\n",
+ " Name: Mendez\n",
+ " number: 1233\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.7, Page Number 707"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Range: #exception class for stack, Note: empty class body\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "class Stack:\n",
+ " \n",
+ " def __init__(self): #construtor\n",
+ " self.__st = [0 for j in range(3)] #array of integers\n",
+ " self.__top = -1\n",
+ " \n",
+ " def push(self,var):\n",
+ " \n",
+ " if self.__top>=2: #if stack is full,\n",
+ " raise Range() #throw exception\n",
+ " \n",
+ " self.__top += 1\n",
+ " self.__st[self.__top] = var\n",
+ " \n",
+ " def pop(self):\n",
+ " \n",
+ " if self.__top<0: #if stack is empty,\n",
+ " raise Range() #throw exception\n",
+ " \n",
+ " m = self.__top\n",
+ " self.__top -= 1\n",
+ " return self.__st[m]\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = Stack()\n",
+ "\n",
+ "try:\n",
+ " s1.push(11)\n",
+ " s1.push(22)\n",
+ " s1.push(33)\n",
+ "\n",
+ " print '1:',s1.pop()\n",
+ " print '2:',s1.pop()\n",
+ " print '3:',s1.pop()\n",
+ " print '4:',s1.pop() #oops: stack empty\n",
+ " \n",
+ "except Range as i:\n",
+ " print 'Exception: Stack Full or Empty'\n",
+ " \n",
+ "print 'Arrive here after catch (or normal exit)'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1: 33\n",
+ "2: 22\n",
+ "3: 11\n",
+ "4: Exception: Stack Full or Empty\n",
+ "Arrive here after catch (or normal exit)\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.8, Page Number 710"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Full: #exception class\n",
+ " pass\n",
+ " \n",
+ "class Empty: #exception class\n",
+ " pass\n",
+ "\n",
+ "class Stack:\n",
+ " \n",
+ " def __init__(self): #construtor\n",
+ " self.__st = [0 for j in range(3)] #array of integers\n",
+ " self.__top = -1\n",
+ " \n",
+ " def push(self,var):\n",
+ " \n",
+ " if self.__top>=2: #if stack is full,\n",
+ " raise Full() #throw full exception\n",
+ " \n",
+ " self.__top += 1\n",
+ " self.__st[self.__top] = var\n",
+ " \n",
+ " def pop(self):\n",
+ " \n",
+ " if self.__top<0: #if stack is empty,\n",
+ " raise Empty() #throw empty exception \n",
+ " \n",
+ " m = self.__top\n",
+ " self.__top -= 1\n",
+ " return self.__st[m]\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = Stack()\n",
+ "\n",
+ "try:\n",
+ " s1.push(11)\n",
+ " s1.push(22)\n",
+ " s1.push(33)\n",
+ "\n",
+ " print '1:',s1.pop()\n",
+ " print '2:',s1.pop()\n",
+ " print '3:',s1.pop()\n",
+ " print '4:',s1.pop() #oops: stack is empty\n",
+ " \n",
+ "except Full as i:\n",
+ " print 'Exception: Stack Full'\n",
+ "except Empty as i:\n",
+ " print 'Exception: Stack Empty'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1: 33\n",
+ "2: 22\n",
+ "3: 11\n",
+ "4: Exception: Stack Empty\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.9, Page Number 712"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Inchex:\n",
+ " pass\n",
+ "\n",
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " \n",
+ " if inc>=12.0: #if inches too big,\n",
+ " raise Inchex() #throw exception\n",
+ " \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " if self.__inches>=12.0: #if inches too big,\n",
+ " raise Inchex() #throw exception\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "try: #define and initialize dist1\n",
+ " dist1 = Distance(17,3.5)\n",
+ " dist2 = Distance()\n",
+ " dist2.getdist() #get dist2 from user\n",
+ "\n",
+ " #display all lengths\n",
+ " print 'dist1 = ',;dist1.showdist()\n",
+ " print 'dist2 = ',;dist2.showdist()\n",
+ " \n",
+ "except Inchex as i: #catch exception\n",
+ " print 'Initialization error: inches value is too large.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:13.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Initialization error: inches value is too large.\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.10, Page Number 714"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Inchex: #exception class\n",
+ " \n",
+ " def __init__(self,ori,inc): #2-arg constructor\n",
+ " self.origin = ori #for name of routine\n",
+ " self.ivalue = inc #for faulty inches value\n",
+ "\n",
+ " \n",
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " \n",
+ " if inc>=12.0:\n",
+ " raise Inchex(\"2-arg constructor\",inc)\n",
+ " \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " if self.__inches>=12.0:\n",
+ " raise Inchex(\"getdist() function\",self.__inches)\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "try: #define and initialize dist1\n",
+ " dist1 = Distance(17,3.5)\n",
+ " dist2 = Distance()\n",
+ " dist2.getdist() #get dist2 from user\n",
+ "\n",
+ " #display all lengths\n",
+ " print 'dist1 = ',;dist1.showdist()\n",
+ " print 'dist2 = ',;dist2.showdist()\n",
+ " \n",
+ "except Inchex as ix: #exception handler\n",
+ " print 'Initialization error in',ix.origin,'.\\n inches value of',ix.ivalue,'is too large.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:13.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Initialization error in getdist() function .\n",
+ " inches value of 13.5 is too large.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.11, Page Number 718"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "try:\n",
+ " ptr = []*10000 #allocate memory\n",
+ " \n",
+ "except MemoryError: #exception handler\n",
+ " print \"Memory Error Exception: can't allocate memory.\"\n",
+ " \n",
+ "del ptr #deallocate memory\n",
+ "print \"Memory use is successfull.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Memory use is successfull.\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter14TemplatesandExceptions_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter14TemplatesandExceptions_1.ipynb
new file mode 100755
index 00000000..9d7f2f2d
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter14TemplatesandExceptions_1.ipynb
@@ -0,0 +1,860 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5687925b0ce89c3c7fdffea973edf76fe3b10da3a53391d98b50115e63f96ddd"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 14: Templates and Exceptions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.1, Page Number 684"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def abs(n): #absolute function\n",
+ " if n<0:\n",
+ " return -n\n",
+ " else:\n",
+ " return n\n",
+ "\n",
+ "#variables\n",
+ "int1 = 5\n",
+ "int2 = -6\n",
+ "lon1 = 70000\n",
+ "lon2 = -80000\n",
+ "dub1 = 9.95\n",
+ "dub2 = -10.15\n",
+ "\n",
+ "#call instantiate functions\n",
+ "print 'abs(%d)=%d' %(int1,abs(int1)) #abs(int)\n",
+ "print 'abs(%d)=%d' %(int2,abs(int2)) #abs(int)\n",
+ "print 'abs(%d)=%d' %(lon1,abs(lon1)) #abs(long)\n",
+ "print 'abs(%d)=%d' %(lon2,abs(lon2)) #abs(long)\n",
+ "print 'abs(%.2f)=%.2f' %(dub1,abs(dub1)) #abs(double)\n",
+ "print 'abs(%.2f)=%.2f' %(dub2,abs(dub2)) #abs(double)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "abs(5)=5\n",
+ "abs(-6)=6\n",
+ "abs(70000)=70000\n",
+ "abs(-80000)=80000\n",
+ "abs(9.95)=9.95\n",
+ "abs(-10.15)=10.15\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.2, Page Number 687"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#function returns index number of item, or -1 if not found\n",
+ "\n",
+ "def find(array, value, size):\n",
+ " for j in range(size):\n",
+ " if array[j] == value:\n",
+ " return j\n",
+ " return -1\n",
+ "\n",
+ "\n",
+ "chrArr = [1, 3, 5, 9, 11, 13] #array\n",
+ "ch = 5 #value to find\n",
+ "\n",
+ "intArr = [1, 3, 5, 9, 11, 13]\n",
+ "int = 6\n",
+ "\n",
+ "lonArr = [1, 3, 5, 9, 11, 13]\n",
+ "lo = 11\n",
+ "\n",
+ "dubArr = [1.0, 3.0, 5.0, 9.0, 11.0, 13.0]\n",
+ "db = 4.0\n",
+ "\n",
+ "print ' 5 in chrArray: index =',find(chrArr,ch,6)\n",
+ "print ' 6 in intArray: index =',find(intArr,int,6)\n",
+ "print '11 in lonArray: index =',find(lonArr,lo,6)\n",
+ "print ' 4 in dubArray: index =',find(dubArr,db,6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 5 in chrArray: index = 2\n",
+ " 6 in intArray: index = -1\n",
+ "11 in lonArray: index = 4\n",
+ " 4 in dubArray: index = -1\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.3, Page Number 691"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 100 #size of array\n",
+ "\n",
+ "class Stack:\n",
+ " __st = [None]*MAX #stack: array of any type\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__top = -1 #number of top of stack\n",
+ " \n",
+ " def push(self,var): #put number on stack\n",
+ " self.__top += 1\n",
+ " self.__st[self.__top] = var\n",
+ " \n",
+ " def pop(self): #take number off stack\n",
+ " x = self.__st[self.__top]\n",
+ " self.__top -= 1\n",
+ " return x\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = Stack() #s1 is object of class Stack\n",
+ "\n",
+ "#push 3 floats, pop 3 floats\n",
+ "s1.push(1111.1)\n",
+ "s1.push(2222.2)\n",
+ "s1.push(3333.3)\n",
+ "print '1:',s1.pop()\n",
+ "print '2:',s1.pop()\n",
+ "print '3:',s1.pop()\n",
+ "\n",
+ "s2 = Stack() #s2 is object of class Stack\n",
+ "\n",
+ "#push 3 longs, pop 3 longs\n",
+ "s2.push(123123123)\n",
+ "s2.push(234234234)\n",
+ "s2.push(345345345)\n",
+ "print '1:',s2.pop()\n",
+ "print '2:',s2.pop()\n",
+ "print '3:',s2.pop()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1: 3333.3\n",
+ "2: 2222.2\n",
+ "3: 1111.1\n",
+ "1: 345345345\n",
+ "2: 234234234\n",
+ "3: 123123123\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.4, Page Number 694"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 100 #size of array\n",
+ "\n",
+ "class Stack:\n",
+ " __st = [None]*MAX #stack: array of any type\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__top = -1 #number of top of stack\n",
+ " \n",
+ " def push(self,var): #put number on stack\n",
+ " self.__top += 1\n",
+ " self.__st[self.__top] = var\n",
+ " \n",
+ " def pop(self): #take number off stack\n",
+ " x = self.__st[self.__top]\n",
+ " self.__top -= 1\n",
+ " return x\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = Stack() #s1 is object of class Stack\n",
+ "\n",
+ "#push 3 floats, pop 3 floats\n",
+ "s1.push(1111.1)\n",
+ "s1.push(2222.2)\n",
+ "s1.push(3333.3)\n",
+ "print '1:',s1.pop()\n",
+ "print '2:',s1.pop()\n",
+ "print '3:',s1.pop()\n",
+ "\n",
+ "s2 = Stack() #s2 is object of class Stack\n",
+ "\n",
+ "#push 3 longs, pop 3 longs\n",
+ "s2.push(123123123)\n",
+ "s2.push(234234234)\n",
+ "s2.push(345345345)\n",
+ "print '1:',s2.pop()\n",
+ "print '2:',s2.pop()\n",
+ "print '3:',s2.pop()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1: 3333.3\n",
+ "2: 2222.2\n",
+ "3: 1111.1\n",
+ "1: 345345345\n",
+ "2: 234234234\n",
+ "3: 123123123\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.5, Page Number 696"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class link:\n",
+ " def __init__(self):\n",
+ " self.data = None #contains the data\n",
+ " self.next = None #contains the reference to the next node\n",
+ "\n",
+ "\n",
+ "class linklist:\n",
+ " def __init__(self):\n",
+ " self.first = None\n",
+ "\n",
+ " def additem(self, d):\n",
+ " newlink = link() #create a new node\n",
+ " newlink.data = d\n",
+ " newlink.next = self.first #link the new node to the 'previous' node.\n",
+ " self.first = newlink #set the current node to the new one.\n",
+ "\n",
+ " def display(self):\n",
+ " current = self.first #set current to first link\n",
+ " \n",
+ " while current:\n",
+ " print current.data\n",
+ " current = current.next\n",
+ "\n",
+ "\n",
+ "\n",
+ " \n",
+ "ld = linklist() #ld is the object of class linkedlist\n",
+ "\n",
+ "#add three doubles to list ld\n",
+ "ld.additem(151.5)\n",
+ "ld.additem(262.6)\n",
+ "ld.additem(373.7)\n",
+ "ld.display() #display entire list ld\n",
+ "\n",
+ "\n",
+ "lch = linklist() #lch is the object of class linkedlist\n",
+ "\n",
+ "#add three chars to list lch\n",
+ "lch.additem('a')\n",
+ "lch.additem('b')\n",
+ "lch.additem('c')\n",
+ "lch.display() #display entire list lch"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "373.7\n",
+ "262.6\n",
+ "151.5\n",
+ "c\n",
+ "b\n",
+ "a\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.6, Page Number 699"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class employee: #employee class\n",
+ " \n",
+ " def __init__(self):\n",
+ " self.__name = []*80 #employee name\n",
+ " self.__number = 0 #employee number\n",
+ " \n",
+ "def ip(e):\n",
+ " e._employee__name = raw_input(\"\\n Enter last name: \")\n",
+ " e._employee__number = input(\" Enter number\")\n",
+ " \n",
+ "def op(e):\n",
+ " print '\\n Name:',e._employee__name\n",
+ " print ' number:',e._employee__number\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "class link:\n",
+ " def __init__(self):\n",
+ " self.data = None #contains the data\n",
+ " self.next = None #contains the reference to the next node\n",
+ "\n",
+ "\n",
+ "class linklist:\n",
+ " def __init__(self):\n",
+ " self.first = None\n",
+ "\n",
+ " def additem(self, d): #add data item\n",
+ " newlink = link() #make a new link\n",
+ " newlink.data = d #give it data\n",
+ " newlink.next = self.first #it points to next link\n",
+ " self.first = newlink #now first points to this\n",
+ "\n",
+ " def display(self):\n",
+ " current = self.first #set ptr to first link\n",
+ " while current: #quit on last link\n",
+ " op(current.data) #print data\n",
+ " current = current.next #move to next link\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "lemp = linklist() #lemp is object of class linkedlist\n",
+ "\n",
+ "\n",
+ "while True:\n",
+ " emptemp = employee() #temporary employee storage \n",
+ " ip(emptemp) #get employee data from user\n",
+ " lemp.additem(emptemp) #add it to linked list 'lemp'\n",
+ " \n",
+ " ans = raw_input(\"Add another (y/n)? \")\n",
+ " \n",
+ " if(ans == 'n'): #when user is done\n",
+ " break;\n",
+ " \n",
+ "lemp.display() #display entire linked list"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Enter last name: Mendez\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number1233\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Add another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Enter last name: Smith\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number2344\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Add another (y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Enter last name: Chang\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number3455\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Add another (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Name: Chang\n",
+ " number: 3455\n",
+ "\n",
+ " Name: Smith\n",
+ " number: 2344\n",
+ "\n",
+ " Name: Mendez\n",
+ " number: 1233\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.7, Page Number 707"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Range: #exception class for stack, Note: empty class body\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "class Stack:\n",
+ " \n",
+ " def __init__(self): #construtor\n",
+ " self.__st = [0 for j in range(3)] #array of integers\n",
+ " self.__top = -1\n",
+ " \n",
+ " def push(self,var):\n",
+ " \n",
+ " if self.__top>=2: #if stack is full,\n",
+ " raise Range() #throw exception\n",
+ " \n",
+ " self.__top += 1\n",
+ " self.__st[self.__top] = var\n",
+ " \n",
+ " def pop(self):\n",
+ " \n",
+ " if self.__top<0: #if stack is empty,\n",
+ " raise Range() #throw exception\n",
+ " \n",
+ " m = self.__top\n",
+ " self.__top -= 1\n",
+ " return self.__st[m]\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = Stack()\n",
+ "\n",
+ "try:\n",
+ " s1.push(11)\n",
+ " s1.push(22)\n",
+ " s1.push(33)\n",
+ "\n",
+ " print '1:',s1.pop()\n",
+ " print '2:',s1.pop()\n",
+ " print '3:',s1.pop()\n",
+ " print '4:',s1.pop() #oops: stack empty\n",
+ " \n",
+ "except Range as i:\n",
+ " print 'Exception: Stack Full or Empty'\n",
+ " \n",
+ "print 'Arrive here after catch (or normal exit)'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1: 33\n",
+ "2: 22\n",
+ "3: 11\n",
+ "4: Exception: Stack Full or Empty\n",
+ "Arrive here after catch (or normal exit)\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.8, Page Number 710"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Full: #exception class\n",
+ " pass\n",
+ " \n",
+ "class Empty: #exception class\n",
+ " pass\n",
+ "\n",
+ "class Stack:\n",
+ " \n",
+ " def __init__(self): #construtor\n",
+ " self.__st = [0 for j in range(3)] #array of integers\n",
+ " self.__top = -1\n",
+ " \n",
+ " def push(self,var):\n",
+ " \n",
+ " if self.__top>=2: #if stack is full,\n",
+ " raise Full() #throw full exception\n",
+ " \n",
+ " self.__top += 1\n",
+ " self.__st[self.__top] = var\n",
+ " \n",
+ " def pop(self):\n",
+ " \n",
+ " if self.__top<0: #if stack is empty,\n",
+ " raise Empty() #throw empty exception \n",
+ " \n",
+ " m = self.__top\n",
+ " self.__top -= 1\n",
+ " return self.__st[m]\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = Stack()\n",
+ "\n",
+ "try:\n",
+ " s1.push(11)\n",
+ " s1.push(22)\n",
+ " s1.push(33)\n",
+ "\n",
+ " print '1:',s1.pop()\n",
+ " print '2:',s1.pop()\n",
+ " print '3:',s1.pop()\n",
+ " print '4:',s1.pop() #oops: stack is empty\n",
+ " \n",
+ "except Full as i:\n",
+ " print 'Exception: Stack Full'\n",
+ "except Empty as i:\n",
+ " print 'Exception: Stack Empty'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1: 33\n",
+ "2: 22\n",
+ "3: 11\n",
+ "4: Exception: Stack Empty\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.9, Page Number 712"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Inchex:\n",
+ " pass\n",
+ "\n",
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " \n",
+ " if inc>=12.0: #if inches too big,\n",
+ " raise Inchex() #throw exception\n",
+ " \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " if self.__inches>=12.0: #if inches too big,\n",
+ " raise Inchex() #throw exception\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "try: #define and initialize dist1\n",
+ " dist1 = Distance(17,3.5)\n",
+ " dist2 = Distance()\n",
+ " dist2.getdist() #get dist2 from user\n",
+ "\n",
+ " #display all lengths\n",
+ " print 'dist1 = ',;dist1.showdist()\n",
+ " print 'dist2 = ',;dist2.showdist()\n",
+ " \n",
+ "except Inchex as i: #catch exception\n",
+ " print 'Initialization error: inches value is too large.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:13.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Initialization error: inches value is too large.\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.10, Page Number 714"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Inchex: #exception class\n",
+ " \n",
+ " def __init__(self,ori,inc): #2-arg constructor\n",
+ " self.origin = ori #for name of routine\n",
+ " self.ivalue = inc #for faulty inches value\n",
+ "\n",
+ " \n",
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " \n",
+ " if inc>=12.0:\n",
+ " raise Inchex(\"2-arg constructor\",inc)\n",
+ " \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " if self.__inches>=12.0:\n",
+ " raise Inchex(\"getdist() function\",self.__inches)\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "try: #define and initialize dist1\n",
+ " dist1 = Distance(17,3.5)\n",
+ " dist2 = Distance()\n",
+ " dist2.getdist() #get dist2 from user\n",
+ "\n",
+ " #display all lengths\n",
+ " print 'dist1 = ',;dist1.showdist()\n",
+ " print 'dist2 = ',;dist2.showdist()\n",
+ " \n",
+ "except Inchex as ix: #exception handler\n",
+ " print 'Initialization error in',ix.origin,'.\\n inches value of',ix.ivalue,'is too large.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:13.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Initialization error in getdist() function .\n",
+ " inches value of 13.5 is too large.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14.11, Page Number 718"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "try:\n",
+ " ptr = []*10000 #allocate memory\n",
+ " \n",
+ "except MemoryError: #exception handler\n",
+ " print \"Memory Error Exception: can't allocate memory.\"\n",
+ " \n",
+ "del ptr #deallocate memory\n",
+ "print \"Memory use is successfull.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Memory use is successfull.\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter15TheStandardTemplateLibrary.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter15TheStandardTemplateLibrary.ipynb
new file mode 100755
index 00000000..cdb99245
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter15TheStandardTemplateLibrary.ipynb
@@ -0,0 +1,2625 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:9f3cc87ca66ff6fe2a52d0d72cf4859c6f5730f0081a8f18f154de578d8ad2e0"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 15: The Standard Template Library"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.1, Page Number 735"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = [11,22,33,44,55,66,77,88]\n",
+ "\n",
+ "ptr = arr.index(33) #find first 33\n",
+ "\n",
+ "print 'First object with value 33 found at offset',ptr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First object with value 33 found at offset 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.2, Page Number 736"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = [33,22,33,44,33,66,77,88]\n",
+ "\n",
+ "n = arr.count(33) #count number of 33's\n",
+ "\n",
+ "print 'There are',n,'33\\'s in arr.\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "There are 3 33's in arr.\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.3, Page Number 737"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = [45,2,22,-17,0,-30,25,55] #array of numbers\n",
+ "\n",
+ "arr1 = sorted(arr) #sort the numbers\n",
+ "\n",
+ "for j in range(8): #display sorted numbers\n",
+ " print arr1[j],'',"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-30 -17 0 2 22 25 45 55 \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.4, Page Number 737"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def find_sublist(sub, bigger): #function for find the substring\n",
+ " \n",
+ " if not bigger:\n",
+ " return -1\n",
+ " if not sub:\n",
+ " return 0\n",
+ " \n",
+ " first, rest = sub[0], sub[1:]\n",
+ " pos = 0\n",
+ " \n",
+ " try:\n",
+ " while True:\n",
+ " pos = bigger.index(first, pos) + 1\n",
+ " if not rest or bigger[pos:pos+len(rest)] == rest:\n",
+ " return pos-1\n",
+ " except ValueError:\n",
+ " return -1\n",
+ " \n",
+ " \n",
+ "\n",
+ "source = [11,44,33,11,22,33,11,22,44]\n",
+ "pattern = [11,22,33]\n",
+ "\n",
+ "ptr = find_sublist(pattern, source)\n",
+ "\n",
+ "if ptr == -1: #if past-the-end\n",
+ " print \"No Match Found\"\n",
+ "else:\n",
+ " print 'Match at',ptr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Match at 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.5, Page Number 738"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "src1 = [2,3,4,6,8]\n",
+ "src2 = [1,3,5]\n",
+ "\n",
+ "dest = sorted(src1 + src2) #merge src1 and src2 into dest and sort it\n",
+ "\n",
+ "for j in range(8): #display dist\n",
+ " print dest[j],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 2 3 3 4 5 6 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.6, Page Number 739"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fdata = [19.2 , 87.4 , 33.6 , 55.0 , 11.5 , 42.2] #array of doubles\n",
+ "\n",
+ "fdata1 = sorted(fdata , reverse = True) #sort the doubles in reverse order\n",
+ "\n",
+ "for j in range(6): #display sorted doubles\n",
+ " print fdata1[j],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "87.4 55.0 42.2 33.6 19.2 11.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.7, Page Number 740"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "names = [\"George\", \"Penny\", \"Estelle\", \"Don\", \"Mike\", \"Bob\"] #array of strings\n",
+ "\n",
+ "names = sorted(names) #sort the string\n",
+ "\n",
+ "for i in range (6): #display sorted strings\n",
+ " print names[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bob\n",
+ "Don\n",
+ "Estelle\n",
+ "George\n",
+ "Mike\n",
+ "Penny\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.8, Page Number 741"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "names = [\"George\", \"Estelle\", \"Don\", \"Mike\", \"Bob\"]\n",
+ "\n",
+ "ptr = names.index(\"Don\") #index of an element\n",
+ "\n",
+ "print 'Don is element',ptr,'on the list.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Don is element 2 on the list.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.9, Page Number 742"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def in_to_cm(inc): #convert and display as centimeters\n",
+ " print inc*2.54,\n",
+ " \n",
+ "inches = [3.5,6.2,1.0,12.75,4.33] #array of inches value\n",
+ "\n",
+ "for x in range(len(inches)): #output as centimeters\n",
+ " in_to_cm(inches[x])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8.89 15.748 2.54 32.385 10.9982\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.10, Page Number 743"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def in_to_cm(inc): #convert and display as centimeters\n",
+ " return inc*2.54\n",
+ " \n",
+ "inches = [3.5,6.2,1.0,12.75,4.33]\n",
+ "centi = [0.0 for j in range(5)]\n",
+ "\n",
+ "for x in range(len(inches)): #transform into array centi[]\n",
+ " centi[x] = in_to_cm(inches[x])\n",
+ " \n",
+ "for x in range(len(centi)): #display array centi[]\n",
+ " print centi[x],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8.89 15.748 2.54 32.385 10.9982\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.11, Page Number 744"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = []\n",
+ "\n",
+ " #put values at end of array\n",
+ "x.append(10)\n",
+ "x.append(11)\n",
+ "x.append(12)\n",
+ "x.append(13)\n",
+ "\n",
+ " #replace with new values\n",
+ "x[0] = 20\n",
+ "x[3] = 23\n",
+ "\n",
+ " #display array contents\n",
+ "for j in range(x.__len__()):\n",
+ " print x[j],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "20 11 12 23\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.12, Page Number 745"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#*class vector*#\n",
+ "\n",
+ "class vector: \n",
+ " \n",
+ " def __init__(self,a): #construtor\n",
+ " \n",
+ " if isinstance(a,int):\n",
+ " self.__arr = [0.0 for j in range(a)]\n",
+ " \n",
+ " elif isinstance(a,vector):\n",
+ " self.__arr = a.__arr\n",
+ " \n",
+ " else:\n",
+ " self.__arr = a\n",
+ " \n",
+ " \n",
+ " def swap(self,v2): #swap contents of two vectors\n",
+ " return v2.__arr,self.__arr\n",
+ " \n",
+ " def empty(self): #check vector is empty or not\n",
+ " if len(self.__arr)==0:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " def back(self): #return the last element of vector\n",
+ " a = len(self.__arr)\n",
+ " return self.__arr[a-1]\n",
+ " \n",
+ " def pop_back(self): #delete last element vector \n",
+ " self.__arr.pop()\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = [1.1,2.2,3.3,4.4] #an array of doubles\n",
+ "\n",
+ "v1 = vector(arr) #initialize vector to array\n",
+ "v2 = vector(4) #empty vector of size 4\n",
+ "\n",
+ "\n",
+ "v1,v2 = v1.swap(v2) #swap contents of v1 and v2\n",
+ "\n",
+ "v2 = vector(v2)\n",
+ "\n",
+ "while not v2.empty(): #untill vector is empty\n",
+ " \n",
+ " print v2.back(), #display the last element\n",
+ " v2.pop_back() #remove last element"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4.4 3.3 2.2 1.1\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.13, Page Number 746"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = [100,110,120,130] #an array of ints\n",
+ "v = arr \n",
+ "\n",
+ "print 'Before insertion:',\n",
+ "for j in range(len(v)): #display all elements\n",
+ " print v[j],\n",
+ " \n",
+ "v.insert(2,115) #insert 115 at element 2\n",
+ "\n",
+ "print '\\nAfter insertion: ',\n",
+ "for j in range(len(v)): #display all elements\n",
+ " print v[j],\n",
+ " \n",
+ "v.remove(115) #erase element 2\n",
+ "\n",
+ "print '\\nAfter erasure: ',\n",
+ "for j in range(len(v)): #display all elements\n",
+ " print v[j],\n",
+ "\n",
+ "print '\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Before insertion: 100 110 120 130 \n",
+ "After insertion: 100 110 115 120 130 \n",
+ "After erasure: 100 110 120 130 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.14, Page Number 747"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*list class*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def size(self): #return size of array\n",
+ " self.__arr = sorted(self.__arr) #sort the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def front(self): #gives the first element\n",
+ " return self.__arr[0]\n",
+ " \n",
+ " def pop_front(self): #delete first element\n",
+ " a = self.__arr[0]\n",
+ " self.__arr.remove(a)\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "ilist = list()\n",
+ "\n",
+ "ilist.push_back(30) #push items on back\n",
+ "ilist.push_back(40)\n",
+ "ilist.push_back(20)\n",
+ "ilist.push_back(10)\n",
+ "\n",
+ "size = ilist.size() #number of items\n",
+ "\n",
+ "for j in range(size):\n",
+ " print ilist.front(), #read items from front\n",
+ " ilist.pop_front() #pop items off front"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 20 30 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15, Page Number 748"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*list class*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def reverse(self): #reverse the array\n",
+ " self.__arr.reverse()\n",
+ " \n",
+ " def merge(self,a): #merge 'a' perameter to array\n",
+ " self.__arr.extend(a.__arr)\n",
+ " \n",
+ " def unique(self): #remove duplicate items from the array\n",
+ " a = []\n",
+ " for x in self.__arr:\n",
+ " if x not in a:\n",
+ " a.append(x)\n",
+ " self.__arr = a\n",
+ " \n",
+ " def size(self): #return size of array\n",
+ " self.__arr = sorted(self.__arr) #sort the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def empty(self): #check array is empty or not\n",
+ " if len(self.__arr)==0:\n",
+ " return 1\n",
+ " else:\n",
+ " return 0\n",
+ " \n",
+ " def front(self): #gives the first element\n",
+ " return self.__arr[0]\n",
+ " \n",
+ " def pop_front(self): #delete first element\n",
+ " a = self.__arr[0]\n",
+ " self.__arr.remove(a)\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr1 = [40,30,20,10]\n",
+ "arr2 = [15,20,25,30,35]\n",
+ "\n",
+ "list1 = list()\n",
+ "list2 = list()\n",
+ "\n",
+ "for j in range(4):\n",
+ " list1.push_back(arr1[j]) #list1: 40, 30, 20, 10\n",
+ "\n",
+ "for j in range(5):\n",
+ " list2.push_back(arr2[j]) #list2: 15, 20, 25, 30, 35\n",
+ " \n",
+ "list1.reverse() #reverse list1: 10 20 30 40\n",
+ "\n",
+ "list1.merge(list2) #merge list2 into list1\n",
+ "\n",
+ "list1.unique() #remove duplicate 20 and 30\n",
+ "\n",
+ "size = list1.size()\n",
+ "\n",
+ "while (list1.empty()==False):\n",
+ " print list1.front(), #read item from front\n",
+ " list1.pop_front() #poopitem off front"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 15 20 25 30 35 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.16, Page Number 750"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class deque: #*deque class*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def op1(self,a,b): #function to change the item of array\n",
+ " self.__arr[a] = b\n",
+ " \n",
+ " def size(self): #reurn size of array\n",
+ " self.__arr = sorted(self.__arr) #sort the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def op2(self,n): #function to return array item\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "deq = deque()\n",
+ "\n",
+ "deq.push_back(30) #push item on back\n",
+ "deq.push_back(40)\n",
+ "deq.push_back(50)\n",
+ "deq.push_back(20)\n",
+ "deq.push_back(10)\n",
+ "\n",
+ "k = deq.size()\n",
+ "\n",
+ "deq.op1(2,33) #change middle item\n",
+ "\n",
+ "for j in range(k):\n",
+ " print deq.op2(j), #display items"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 20 33 40 50\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.17, Page Number 759"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def op1(self,n): #function to return array item\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = [2,4,6,8]\n",
+ "\n",
+ "theList = list()\n",
+ "\n",
+ "for k in range(4):\n",
+ " theList.push_back(arr[k]) #fill list with array elements\n",
+ " \n",
+ "\n",
+ "for iter in range(theList.begin(),theList.end(),1):\n",
+ " print theList.op1(iter), #display the list"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2 4 6 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.18, Page Number 760"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self,a): #constructor\n",
+ " self.__arr = [0 for j in range(a)]\n",
+ " \n",
+ " def op1(self,a,b): #change the particular item\n",
+ " self.__arr[a] = b\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def op2(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "data = 0\n",
+ "\n",
+ "iList = list(5) #empty list holds 5 ints\n",
+ "\n",
+ " #fill list with data\n",
+ "for it in range(iList.begin(),iList.end(),1):\n",
+ " data += 2\n",
+ " iList.op1(it,data) \n",
+ " \n",
+ " #display list\n",
+ "for it in range(iList.begin(),iList.end(),1):\n",
+ " print iList.op2(it),"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2 4 6 8 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.19, Page Number 761"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self,a): #constructor\n",
+ " self.__arr = [0 for j in range(a)]\n",
+ " \n",
+ " def op1(self,a,b): #change the particular item\n",
+ " self.__arr[a] = b\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def find(self,a,b,c): #return the index of a particular element\n",
+ " for j in range(a,b,1):\n",
+ " if self.__arr[j] == c:\n",
+ " b = j\n",
+ " break\n",
+ " return b\n",
+ " \n",
+ "data = 0\n",
+ "\n",
+ "theList = list(5) #empty list holds 5 ints\n",
+ "\n",
+ " #fill list with data\n",
+ "for it in range(theList.begin(),theList.end(),1):\n",
+ " data += 2 #2, 4, 6, 8, 10\n",
+ " theList.op1(it,data)\n",
+ " \n",
+ " #look for number 8\n",
+ "iter = theList.find(theList.begin(),theList.end(),8)\n",
+ "\n",
+ "if iter!=theList.end():\n",
+ " print 'Found 8.'\n",
+ " \n",
+ "else:\n",
+ " print 'Dis not find 8.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Found 8.\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.20, Page Number 762"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class vector: #*class vector*#\n",
+ " \n",
+ " def __init__(self,a): #constructor\n",
+ " if isinstance(a,int):\n",
+ " self.__arr = [0.0 for j in range(a)]\n",
+ " \n",
+ " elif isinstance(a,vector):\n",
+ " self.__arr = a.__arr\n",
+ " \n",
+ " else:\n",
+ " self.__arr = a\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def copy(self,a,b,v): #copy the elements of array in another vector\n",
+ " for j in range(a,b,1):\n",
+ " v.__arr[j-a] = self.__arr[j]\n",
+ " return b-a\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = [11,13,15,17,19,21,23,25,27,29]\n",
+ "\n",
+ "v1 = vector(arr) #initialized vector\n",
+ "v2 = vector(10) #uninitialized vector\n",
+ "\n",
+ "print 'Enter range to be copied (Example: 2 5): '\n",
+ "beginRange = input(\"\")\n",
+ "endRange = input(\"\")\n",
+ "\n",
+ "iter1 = v1.begin() + beginRange\n",
+ "iter2 = v1.begin() + endRange\n",
+ "\n",
+ "iter3 = v1.copy(iter1,iter2,v2) #copy range from v1 to v2\n",
+ "\n",
+ "iter1 = v2.begin()\n",
+ "\n",
+ "print 'values:',\n",
+ "while (iter1 != iter3): #iteration through range in v2\n",
+ " print v2.op1(iter1), #displaying values\n",
+ " iter1 += 1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter range to be copied (Example: 2 5): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "values: 17 19 21\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.21, Page Number 763"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def rend(self): #return the first index\n",
+ " return -1\n",
+ " \n",
+ " def rbegin(self): #returns the last index\n",
+ " return len(self.__arr)-1\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = [2,4,6,8,10] #array of ints\n",
+ "\n",
+ "theList = list()\n",
+ "\n",
+ "for j in range(5): #transfer array to list\n",
+ " theList.push_back(arr[j])\n",
+ " \n",
+ "revit = theList.rbegin() #reverse iterator\n",
+ "\n",
+ "while (revit != theList.rend()): #iterate backward through list,\n",
+ " print theList.op1(revit), #displaying output\n",
+ " revit -= 1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 8 6 4 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.22, Page Number 764"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class deque: #*class deque*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def copy(self,a,b,v): #copy the elements of array in another vector\n",
+ " for j in range(a,b,1):\n",
+ " v.__arr[j] = self.__arr[j]\n",
+ " \n",
+ " def end(self): #returns the length of the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def size(self): #reurn size of array\n",
+ " self.__arr = sorted(self.__arr) #sort the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr1 = [1,3,5,7,9]\n",
+ "arr2 = [2,4,6,8,10]\n",
+ " \n",
+ "d1 = deque()\n",
+ "d2 = deque()\n",
+ "\n",
+ "for j in range(5): #transfer arrays to deque\n",
+ " d1.push_back(arr1[j])\n",
+ " d2.push_back(arr2[j])\n",
+ "\n",
+ "d1.copy(d1.begin(),d1.end(),d2) #copy d1 to d2\n",
+ "\n",
+ "for k in range(d2.size()): #display d2\n",
+ " print d2.op1(k),"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 3 5 7 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.23, Page Number 765"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class deque: #*class deque*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def copy(self,a,b,v): #add one deque to another\n",
+ " for j in range(a,b,1):\n",
+ " v.__arr.append(self.__arr[j])\n",
+ " \n",
+ " def end(self): #returns the length of the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def size(self): #reurn size of array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr1 = [1,3,5,7,9]\n",
+ "arr2 = [2,4,6]\n",
+ " \n",
+ "d1 = deque()\n",
+ "d2 = deque()\n",
+ "\n",
+ " #transfer array to deques\n",
+ "for i in range(5):\n",
+ " d1.push_back(arr1[i])\n",
+ "for j in range(3):\n",
+ " d2.push_back(arr2[j])\n",
+ " \n",
+ "print 'd2:',\n",
+ " #copy d1 to back of d2\n",
+ "d1.copy(d1.begin(),d1.end(),d2)\n",
+ "\n",
+ "for k in range(d2.size()): #display d2\n",
+ " print d2.op1(k),"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d2: 2 4 6 1 3 5 7 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.24, Page Number 767"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def copy(self,a,b,c):\n",
+ " for j in range(a,b,1):\n",
+ " print self.__arr[j],c,\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = [10,20,30,40,50]\n",
+ "\n",
+ "theList = list()\n",
+ "\n",
+ "for j in range(5): #transfer array to list\n",
+ " theList.push_back(arr[j])\n",
+ " \n",
+ "c = \",\"\n",
+ "\n",
+ "print 'Contents of list: ',\n",
+ "\n",
+ "theList.copy(theList.begin(),theList.end(),c) #display list"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Contents of list: 10 , 20 , 30 , 40 , 50 ,\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.25, Page Number 768"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def copy(self,a,b,c): #write the array in the file\n",
+ " for j in range(a,b,1):\n",
+ " s = ''\n",
+ " s += '%d' %self.__arr[j]\n",
+ " c.write(s)\n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = [11,21,31,41,51]\n",
+ "\n",
+ "theList = list() #uninitialized list\n",
+ "\n",
+ "for j in range(5):\n",
+ " theList.push_back(arr[j]) #transfer array to list\n",
+ " \n",
+ "outfile = open(\"ITER.TXT\",\"w\") #open the file \n",
+ "\n",
+ "theList.copy(theList.begin(),theList.end(),outfile) #write list to file\n",
+ "\n",
+ "outfile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.26, Page Number 769"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self,a): #constructor\n",
+ " self.__arr = [0.0 for j in range(a)]\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def copy(self,a,b,c):\n",
+ " if isinstance(c,int):\n",
+ " self.__arr = a\n",
+ " \n",
+ " else:\n",
+ " for j in range(a,b,1):\n",
+ " print self.__arr[j],c,\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = []*5\n",
+ "print \"Enter 5 floating numbers: \"\n",
+ "for j in range(5):\n",
+ " x = input()\n",
+ " arr.append(x)\n",
+ "\n",
+ "fList = list(5) #uninitialized list\n",
+ "\n",
+ "fList.copy(arr,'end_of_stream',fList.begin())\n",
+ " \n",
+ "c = \"--\"\n",
+ "\n",
+ "fList.copy(fList.begin(),fList.end(),c)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 5 floating numbers: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1.1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2.2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4.4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1.1 -- 2.2 -- 3.3 -- 4.4 -- 5.5 --\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.27, Page Number 770"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def copy(self,a,b,c):\n",
+ " if isinstance(c,int):\n",
+ " self.__arr = a\n",
+ " \n",
+ " else:\n",
+ " for j in range(a,b,1):\n",
+ " print self.__arr[j],c,\n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = []*5\n",
+ "\n",
+ "iList = list() #empty list\n",
+ "\n",
+ "infile = open(\"ITER.TXT\",\"r\") #open a file in read mode\n",
+ "\n",
+ "for j in range(5):\n",
+ " arr.append(infile.read(2)) #add data from file to array \n",
+ " \n",
+ "iList.copy(arr,'end_of_stream',iList.begin()) #copy array to list\n",
+ "\n",
+ "c = \"--\"\n",
+ "\n",
+ "iList.copy(iList.begin(),iList.end(),c) #display list"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11 -- 21 -- 31 -- 41 -- 51 --\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.28, Page Number 772"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class set: #*class set*#\n",
+ " \n",
+ " def __init__(self,a): #constructor\n",
+ " self.__arr = a\n",
+ " \n",
+ " def insert(self,s): #insert the elements but without repeating\n",
+ " d=1\n",
+ " for j in range(len(self.__arr)):\n",
+ " if s==self.__arr[j]:\n",
+ " d=0\n",
+ " break;\n",
+ " if d==1:\n",
+ " self.__arr.append(s)\n",
+ " \n",
+ " def erase(self,s): #erase a particualr item from the set\n",
+ " self.__arr.remove(s)\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def size(self): #reurn size of array\n",
+ " self.__arr = sorted(self.__arr) #sort the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def find(self,sn): #find the index of a particular element\n",
+ " d=-1\n",
+ " for j in range(len(self.__arr)):\n",
+ " if sn==self.__arr[j]:\n",
+ " d=j\n",
+ " break;\n",
+ " if d==-1:\n",
+ " return len(self.__arr)\n",
+ " else:\n",
+ " return d\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "names = [\"Juanita\",\"Robert\",\"Mary\",\"Amanda\",\"Marie\"] #array of string objects\n",
+ "\n",
+ "nameSet = set(names) #initialize set to array\n",
+ "\n",
+ "nameSet.insert(\"Yvette\") #insert more names\n",
+ "nameSet.insert(\"Larry\")\n",
+ "nameSet.insert(\"Robert\") #no effect; already in set\n",
+ "nameSet.insert(\"Barry\")\n",
+ "\n",
+ "nameSet.erase(\"Mary\") #erase a name\n",
+ "\n",
+ "print 'Size',nameSet.size() #display size of set\n",
+ "\n",
+ "iter = nameSet.begin()\n",
+ "\n",
+ "while(iter != nameSet.end()-1): #display members of set\n",
+ " print nameSet.op1(iter)\n",
+ " iter += 1\n",
+ " \n",
+ "searchName = raw_input(\"Enter name to search for: \") #get name from user\n",
+ "\n",
+ "iter = nameSet.find(searchName) #find matching name in set\n",
+ "\n",
+ "if(iter == nameSet.end()):\n",
+ " print 'The name',searchName,'is NOT in the set.'\n",
+ " \n",
+ "else:\n",
+ " print 'The name',searchName,'IS in the set.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size 7\n",
+ "Amanda\n",
+ "Barry\n",
+ "Juanita\n",
+ "Larry\n",
+ "Marie\n",
+ "Robert\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name to search for: George\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The name George is NOT in the set.\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.29, Page Number 774"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class set: #*class set*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def insert(self,s): #insert the element in the array\n",
+ " self.__arr.append(s)\n",
+ " \n",
+ " def unique(self): #remove the duplicate items from the array\n",
+ " self.__arr = sorted(self.__arr)\n",
+ " a = []\n",
+ " for x in self.__arr:\n",
+ " if x not in a:\n",
+ " a.append(x)\n",
+ " self.__arr = a\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ "organic = set() #set of string objects\n",
+ "\n",
+ " #insert organic compounds\n",
+ "organic.insert(\"Curine\")\n",
+ "organic.insert(\"Xanthine\")\n",
+ "organic.insert(\"Curarine\")\n",
+ "organic.insert(\"Melamine\")\n",
+ "organic.insert(\"Cyanimide\")\n",
+ "organic.insert(\"Phenol\")\n",
+ "organic.insert(\"Aphrodine\")\n",
+ "organic.insert(\"Imidazole\")\n",
+ "organic.insert(\"Cinchonine\")\n",
+ "organic.insert(\"Palmitamide\")\n",
+ "organic.insert(\"Cyanimide\")\n",
+ "\n",
+ "organic.unique()\n",
+ "\n",
+ "iter = organic.begin()\n",
+ "\n",
+ "while (iter!=organic.end()): #display set\n",
+ " print organic.op1(iter)\n",
+ " iter += 1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Aphrodine\n",
+ "Cinchonine\n",
+ "Curarine\n",
+ "Curine\n",
+ "Cyanimide\n",
+ "Imidazole\n",
+ "Melamine\n",
+ "Palmitamide\n",
+ "Phenol\n",
+ "Xanthine\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.30, Page Number 776"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class map: #*class map*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr1 = [] #array for key\n",
+ " self.__arr2 = [] #array for value\n",
+ " \n",
+ " def op1(self,a,b): #add data in the arrays\n",
+ " self.__arr1.append(a)\n",
+ " self.__arr2.append(b)\n",
+ " \n",
+ " def op2(self,a): #return the value according to the key\n",
+ " for j in range(len(self.__arr1)):\n",
+ " if a==self.__arr1[j]:\n",
+ " return self.__arr2[j]\n",
+ " \n",
+ " def sort(self):\n",
+ " \n",
+ " n = len(self.__arr1)\n",
+ " \n",
+ " for j in range(n-1): #outer loop\n",
+ " for k in range(j+1,n,1): #inner loop starts at outer\n",
+ " \n",
+ " if self.__arr1[j] > self.__arr1[k]: #if 1st larger than 2nd\n",
+ " \n",
+ " temp = self.__arr1[j] #swap first array\n",
+ " self.__arr1[j] = self.__arr1[k]\n",
+ " self.__arr1[k] = temp\n",
+ " \n",
+ " temp = self.__arr2[j] #swap second array\n",
+ " self.__arr2[j] = self.__arr2[k]\n",
+ " self.__arr2[k] = temp\n",
+ " \n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr1)\n",
+ " \n",
+ " def first(self,a): #returns the key\n",
+ " return self.__arr1[a]\n",
+ " \n",
+ " def second(self,a): #returns the value\n",
+ " return self.__arr2[a]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "states = [\"Wyoming\",\"Colorado\",\"Nevada\",\"Montana\",\"Arizona\",\"Idaho\"]\n",
+ "pops = [470,2890,800,787,2718,944]\n",
+ "\n",
+ "mapStates = map() #map\n",
+ "\n",
+ "for j in range(6):\n",
+ " name = states[j] #get data from array\n",
+ " pop = pops[j]\n",
+ " mapStates.op1(name,pop) #put it in map\n",
+ " \n",
+ "name = raw_input(\"Enter state: \") #get state from user\n",
+ "pop = mapStates.op2(name)\n",
+ "print 'Population: %d,000' %pop #find population\n",
+ "print \n",
+ "\n",
+ "mapStates.sort()\n",
+ "\n",
+ " #display entire map\n",
+ "for iter in range(mapStates.begin(),mapStates.end(),1):\n",
+ " print mapStates.first(iter),'%d,000' %mapStates.second(iter) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter state: Wyoming\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Population: 470,000\n",
+ "\n",
+ "Arizona 2718,000\n",
+ "Colorado 2890,000\n",
+ "Idaho 944,000\n",
+ "Montana 787,000\n",
+ "Nevada 800,000\n",
+ "Wyoming 470,000\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.31, Page Number 778"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class person: #class person\n",
+ " \n",
+ " def __init__(self,lana = \"blank\",fina = \"blank\",pho = 0): #construvtor\n",
+ " self.__lastName = lana\n",
+ " self.__firstName = fina\n",
+ " self.__phoneNumber = pho\n",
+ " \n",
+ " def display(self): #display person's data\n",
+ " print self.__lastName,'\\t',self.__firstName,'\\t\\tPhone:',self.__phoneNumber\n",
+ " \n",
+ " \n",
+ "def lesst(p1,p2): #less than function (friend function)\n",
+ " \n",
+ " if p1._person__lastName == p2._person__lastName:\n",
+ " if p1._person__firstName < p2._person__firstName:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " elif p1._person__lastName < p2._person__lastName:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ "def equ(p1,p2): #equal function (friend function)\n",
+ " \n",
+ " if (p1._person__lastName == p2._person__lastName) and (p1._person__firstName == p2._person__firstName):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "class multiset: #*class multiet*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def insert(self,a): #insert the element in the multiset\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def size(self): #return the size of multiset\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def display(self,it): #display the items from multiset\n",
+ " if isinstance(it,int):\n",
+ " self.__arr[it].display()\n",
+ " \n",
+ " else:\n",
+ " for j in range(len(self.__arr)):\n",
+ " if equ(it,self.__arr[j]):\n",
+ " self.__arr[j].display()\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def count(self,sp): #return count of a element\n",
+ " a=0\n",
+ " for j in range(len(self.__arr)):\n",
+ " if equ(sp,self.__arr[j]):\n",
+ " a += 1\n",
+ " return a\n",
+ " \n",
+ " \n",
+ " def sort(self):\n",
+ " \n",
+ " n = len(self.__arr)\n",
+ " \n",
+ " for j in range(n-1): #outer loop\n",
+ " for k in range(j+1,n,1): #inner loop starts at outer\n",
+ " \n",
+ " if not lesst(self.__arr[j],self.__arr[k]): #if 1st larger than 2nd\n",
+ " \n",
+ " temp = self.__arr[j]._person__lastName #swap last name\n",
+ " self.__arr[j]._person__lastName = self.__arr[k]._person__lastName\n",
+ " self.__arr[k]._person__lastName = temp\n",
+ " \n",
+ " temp = self.__arr[j]._person__firstName #swap firs tname\n",
+ " self.__arr[j]._person__firstName = self.__arr[k]._person__firstName\n",
+ " self.__arr[k]._person__firstName = temp\n",
+ " \n",
+ " temp = self.__arr[j]._person__phoneNumber #swap phone number\n",
+ " self.__arr[j]._person__phoneNumber = self.__arr[k]._person__phoneNumber\n",
+ " self.__arr[k]._person__phoneNumber = temp\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " #create person objects\n",
+ "pers1 = person(\"Deauville\",\"Wiliam\",8435150)\n",
+ "pers2 = person(\"McDonald\",\"Stacey\",3327563)\n",
+ "pers3 = person(\"Bartoski\",\"peter\",6946473)\n",
+ "pers4 = person(\"Kuangthu\",\"Bruce\",4157300)\n",
+ "pers5 = person(\"Wellington\",\"John\",9207404)\n",
+ "pers6 = person(\"McDonald\",\"Amanda\",8435150)\n",
+ "pers7 = person(\"Fredericks\",\"Roger\",7049982)\n",
+ "pers8 = person(\"McDonald\",\"Stacey\",7764987)\n",
+ "\n",
+ "persSet = multiset() #multiset of persons\n",
+ "\n",
+ " #put persons in multiset\n",
+ "persSet.insert(pers1)\n",
+ "persSet.insert(pers2)\n",
+ "persSet.insert(pers3)\n",
+ "persSet.insert(pers4)\n",
+ "persSet.insert(pers5)\n",
+ "persSet.insert(pers6)\n",
+ "persSet.insert(pers7)\n",
+ "persSet.insert(pers8)\n",
+ "\n",
+ "print 'Number of entries =',persSet.size()\n",
+ "\n",
+ "persSet.sort()\n",
+ "\n",
+ "iter = persSet.begin()\n",
+ "\n",
+ "print\n",
+ "while(iter != persSet.end()): #display contents of multiset\n",
+ " persSet.display(iter)\n",
+ " iter += 1\n",
+ " \n",
+ " #get last and first name\n",
+ "searchLastName = raw_input(\"\\nEnter last name of person to search for: \")\n",
+ "searchFirstName = raw_input(\"Enter first name: \")\n",
+ "\n",
+ "searchPerson = person(searchLastName,searchFirstName,0)\n",
+ "\n",
+ " #get count of such persons\n",
+ "cntPersons = persSet.count(searchPerson) \n",
+ "print 'Number of persons with this name =',cntPersons\n",
+ "\n",
+ "\n",
+ "persSet.display(searchPerson) #display all matches"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of entries = 8\n",
+ "\n",
+ "Bartoski \tpeter \t\tPhone: 6946473\n",
+ "Deauville \tWiliam \t\tPhone: 8435150\n",
+ "Fredericks \tRoger \t\tPhone: 7049982\n",
+ "Kuangthu \tBruce \t\tPhone: 4157300\n",
+ "McDonald \tAmanda \t\tPhone: 8435150\n",
+ "McDonald \tStacey \t\tPhone: 7764987\n",
+ "McDonald \tStacey \t\tPhone: 3327563\n",
+ "Wellington \tJohn \t\tPhone: 9207404\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter last name of person to search for: McDonald\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter first name: Stacey\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of persons with this name = 2\n",
+ "McDonald \tStacey \t\tPhone: 7764987\n",
+ "McDonald \tStacey \t\tPhone: 3327563\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.32, Page Number 782"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class person: #person class\n",
+ " \n",
+ " def __init__(self,lana = \"blank\",fina = \"blank\",pho = 0): #constructor\n",
+ " self.__lastName = lana\n",
+ " self.__firstName = fina\n",
+ " self.__phoneNumber = pho\n",
+ " \n",
+ " def display(self): #display person's data\n",
+ " print self.__lastName,'\\t',self.__firstName,'\\t\\tPhone:',self.__phoneNumber\n",
+ " \n",
+ " def get_phone(self): #return phone number\n",
+ " return self.__phoneNumber\n",
+ " \n",
+ " \n",
+ "def lesst(p1,p2): #less than function (friend function)\n",
+ " \n",
+ " if p1._person__lastName == p2._person__lastName:\n",
+ " if p1._person__firstName < p2._person__firstName:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " elif p1._person__lastName == p2._person__lastName:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ "def equ(p1,p2): #equal function (friend function)\n",
+ " \n",
+ " if (p1._person__lastName == p2._person__lastName) and (p1._person__firstName == p2._person__firstName):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ "def notequ(p1,p2): #not equal function (friend function)\n",
+ " return not(equ(p1,p2))\n",
+ "\n",
+ "def greatert(p1,p2): #greater than function (friend function)\n",
+ " return not(lesst(p1,p2)) and not(equ(p1,p2))\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,pe): #function to add element in array at last\n",
+ " self.__arr.append(pe)\n",
+ " \n",
+ " def size(self): #return the size of list\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def display(self,it): #display the element of list\n",
+ " if isinstance(it,int):\n",
+ " self.__arr[it].display()\n",
+ " \n",
+ " else:\n",
+ " for j in range(len(self.__arr)):\n",
+ " if equ(it,self.__arr[j]):\n",
+ " self.__arr[j].display()\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def find(self,sp): #find the index of a particular item\n",
+ " for j in range(len(self.__arr)):\n",
+ " if equ(sp,self.__arr[j]):\n",
+ " return j\n",
+ " \n",
+ " def display1(self,sn): #display the elements according to the phone number\n",
+ " for j in range(len(self.__arr)):\n",
+ " if sn==self.__arr[j].get_phone():\n",
+ " self.__arr[j].display()\n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "persList = list() #list of persons\n",
+ "\n",
+ " #put persons in list\n",
+ "persList.push_back(person(\"Deauville\",\"Wiliam\",8435150))\n",
+ "persList.push_back(person(\"McDonald\",\"Stacey\",3327563))\n",
+ "persList.push_back(person(\"Bartoski\",\"peter\",6946473))\n",
+ "persList.push_back(person(\"Kuangthu\",\"Bruce\",4157300))\n",
+ "persList.push_back(person(\"Wellington\",\"John\",9207404))\n",
+ "persList.push_back(person(\"McDonald\",\"Amanda\",8435150))\n",
+ "persList.push_back(person(\"Fredericks\",\"Roger\",7049982))\n",
+ "persList.push_back(person(\"McDonald\",\"Stacey\",7764987))\n",
+ "\n",
+ "print 'Number of entries =',persList.size()\n",
+ "\n",
+ "iter = persList.begin()\n",
+ "\n",
+ "print\n",
+ "while(iter != persList.end()): #display contents of list\n",
+ " persList.display(iter)\n",
+ " iter += 1\n",
+ " \n",
+ " \n",
+ "#find person with specified name (last and first)\n",
+ "searchLastName = raw_input(\"\\nEnter last name of person to search for: \")\n",
+ "searchFirstName = raw_input(\"Enter first name: \")\n",
+ "\n",
+ "searchPerson = person(searchLastName,searchFirstName,0) #make a person with that name\n",
+ "\n",
+ " #search for first match of name\n",
+ "iter1 = persList.find(searchPerson)\n",
+ "print 'Person(s) with the same name is(are)'\n",
+ "\n",
+ "persList.display(searchPerson)\n",
+ "\n",
+ "\n",
+ "#find person with specified phone number\n",
+ "sNumber = input(\"\\nEnter phone nnumber (format 1234567): \")\n",
+ "print 'Person(s) with the same name is(are)'\n",
+ "\n",
+ "persList.display1(sNumber) #display the match "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of entries = 8\n",
+ "\n",
+ "Deauville \tWiliam \t\tPhone: 8435150\n",
+ "McDonald \tStacey \t\tPhone: 3327563\n",
+ "Bartoski \tpeter \t\tPhone: 6946473\n",
+ "Kuangthu \tBruce \t\tPhone: 4157300\n",
+ "Wellington \tJohn \t\tPhone: 9207404\n",
+ "McDonald \tAmanda \t\tPhone: 8435150\n",
+ "Fredericks \tRoger \t\tPhone: 7049982\n",
+ "McDonald \tStacey \t\tPhone: 7764987\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter last name of person to search for: Wellington\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter first name: John\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Person(s) with the same name is(are)\n",
+ "Wellington \tJohn \t\tPhone: 9207404\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter phone nnumber (format 1234567): 8435150\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Person(s) with the same name is(are)\n",
+ "Deauville \tWiliam \t\tPhone: 8435150\n",
+ "McDonald \tAmanda \t\tPhone: 8435150\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.33, Page Number 787"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class airtime:\n",
+ " \n",
+ " def __init__(self,h=0,m=0):\n",
+ " self.__hours = h # 0 to 23\n",
+ " self.__minutes = m # 0 to 59\n",
+ " \n",
+ " def display(self): #output to screen\n",
+ " print self.__hours,':',self.__minutes\n",
+ " \n",
+ " def get(self): #input from user\n",
+ " print 'Enter airtime (format 12:59):'\n",
+ " self.__hours = input()\n",
+ " self.__dummy = raw_input()\n",
+ " self.__minutes = input()\n",
+ " \n",
+ " def __iadd__(self,right): #overloaded + operator\n",
+ " temph = self.__hours + right.__hours\n",
+ " tempm = self.__minutes + right.__minutes\n",
+ " \n",
+ " if tempm>=60:\n",
+ " temph =temph + 1\n",
+ " tempm =tempm - 60\n",
+ " \n",
+ " return airtime(temph,tempm)\n",
+ " \n",
+ " \n",
+ " \n",
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,te): #function to add element in array at last\n",
+ " self.__arr.append(te)\n",
+ " \n",
+ " def accumulate(self,a,b,c): #sum all the airtime\n",
+ " for j in range(b):\n",
+ " c += self.__arr[j]\n",
+ " return c\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ "sum = airtime()\n",
+ "airlist = list()\n",
+ "\n",
+ "while True:\n",
+ " temp = airtime()\n",
+ " temp.get() #get airtime from user\n",
+ " airlist.push_back(temp)\n",
+ " answer = raw_input(\"enter another (y/n)? \")\n",
+ " \n",
+ " if(answer=='n'):\n",
+ " break;\n",
+ " \n",
+ "sum = airlist.accumulate(airlist.begin(),airlist.end(),airtime(0,0)) #sum all the airtimes\n",
+ "\n",
+ "print '\\n\\nsum =',\n",
+ "sum.display() #display sum"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter airtime (format 12:59):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ ":\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "45\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter airtime (format 12:59):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ ":\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter airtime (format 12:59):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ ":\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter airtime (format 12:59):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ ":\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "55\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter another (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "sum = 12 : 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.34, Page Number 790"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class person: #class person\n",
+ " \n",
+ " def __init__(self,lana = \"blank\",fina = \"blank\",pho = 0): #constructor\n",
+ " self.__lastName = lana\n",
+ " self.__firstName = fina\n",
+ " self.__phoneNumber = pho\n",
+ " \n",
+ " def display(self): #display person's data\n",
+ " print self.__lastName,'\\t',self.__firstName,'\\t\\tPhone:',self.__phoneNumber\n",
+ " \n",
+ " def get_lastname(self): #return last name\n",
+ " return self.__lastName\n",
+ "\n",
+ " \n",
+ "def lesst(p1,p2): #less than function (friend function)\n",
+ " \n",
+ " if p1._person__lastName == p2._person__lastName:\n",
+ " if p1._person__firstName < p2._person__firstName:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " elif p1._person__lastName == p2._person__lastName:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ "def equ(p1,p2): #equal function (friend function)\n",
+ " if (p1._person__lastName == p2._person__lastName) and (p1._person__firstName == p2._person__firstName):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ " \n",
+ "class vector: #*class vector*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,te): #function to add element in array at last\n",
+ " self.__arr.append(te) \n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def display(self,a,b): #display the vector element \n",
+ " for j in range(a,b,1):\n",
+ " self.__arr[j].display()\n",
+ " \n",
+ " def sort(self):\n",
+ " \n",
+ " n = len(self.__arr)\n",
+ " \n",
+ " for j in range(n-1): #outer loop\n",
+ " for k in range(j+1,n,1): #inner loop starts at outer\n",
+ " \n",
+ " if not lesst(self.__arr[j],self.__arr[k]): #if 1st larger than 2nd\n",
+ " \n",
+ " temp = self.__arr[j]._person__lastName #swap last name\n",
+ " self.__arr[j]._person__lastName = self.__arr[k]._person__lastName\n",
+ " self.__arr[k]._person__lastName = temp\n",
+ " \n",
+ " temp = self.__arr[j]._person__firstName #swap firstname\n",
+ " self.__arr[j]._person__firstName = self.__arr[k]._person__firstName\n",
+ " self.__arr[k]._person__firstName = temp\n",
+ " \n",
+ " temp = self.__arr[j]._person__phoneNumber #swap phone number\n",
+ " self.__arr[j]._person__phoneNumber = self.__arr[k]._person__phoneNumber\n",
+ " self.__arr[k]._person__phoneNumber = temp\n",
+ " \n",
+ " \n",
+ " \n",
+ "\n",
+ "vectPtrspers = vector() #vector object\n",
+ "\n",
+ "#make persons\n",
+ "ptrp1 = person(\"Kuangthu\",\"Bruce\",4157300)\n",
+ "ptrp2 = person(\"Deauville\",\"Wiliam\",8435150)\n",
+ "ptrp3 = person(\"Wellington\",\"John\",9207404)\n",
+ "ptrp4 = person(\"Bartoski\",\"peter\",6946473)\n",
+ "ptrp5 = person(\"Fredericks\",\"Roger\",7049982)\n",
+ "ptrp6 = person(\"McDonald\",\"Stacey\",7764987)\n",
+ "\n",
+ "#put persons in set\n",
+ "vectPtrspers.push_back(ptrp1)\n",
+ "vectPtrspers.push_back(ptrp2)\n",
+ "vectPtrspers.push_back(ptrp3)\n",
+ "vectPtrspers.push_back(ptrp4)\n",
+ "vectPtrspers.push_back(ptrp5)\n",
+ "vectPtrspers.push_back(ptrp6)\n",
+ "\n",
+ "vectPtrspers.display(vectPtrspers.begin(),vectPtrspers.end()) #display vector\n",
+ "\n",
+ "print '\\nsorted pointers '\n",
+ "vectPtrspers.display(vectPtrspers.begin(),vectPtrspers.end())\n",
+ "\n",
+ "vectPtrspers.sort()\n",
+ "print '\\nsorted persons '\n",
+ "vectPtrspers.display(vectPtrspers.begin(),vectPtrspers.end())"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Kuangthu \tBruce \t\tPhone: 4157300\n",
+ "Deauville \tWiliam \t\tPhone: 8435150\n",
+ "Wellington \tJohn \t\tPhone: 9207404\n",
+ "Bartoski \tpeter \t\tPhone: 6946473\n",
+ "Fredericks \tRoger \t\tPhone: 7049982\n",
+ "McDonald \tStacey \t\tPhone: 7764987\n",
+ "\n",
+ "sorted pointers \n",
+ "Kuangthu \tBruce \t\tPhone: 4157300\n",
+ "Deauville \tWiliam \t\tPhone: 8435150\n",
+ "Wellington \tJohn \t\tPhone: 9207404\n",
+ "Bartoski \tpeter \t\tPhone: 6946473\n",
+ "Fredericks \tRoger \t\tPhone: 7049982\n",
+ "McDonald \tStacey \t\tPhone: 7764987\n",
+ "\n",
+ "sorted persons \n",
+ "McDonald \tStacey \t\tPhone: 7764987\n",
+ "Fredericks \tRoger \t\tPhone: 7049982\n",
+ "Bartoski \tpeter \t\tPhone: 6946473\n",
+ "Wellington \tJohn \t\tPhone: 9207404\n",
+ "Deauville \tWiliam \t\tPhone: 8435150\n",
+ "Kuangthu \tBruce \t\tPhone: 4157300\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter15TheStandardTemplateLibrary_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter15TheStandardTemplateLibrary_1.ipynb
new file mode 100755
index 00000000..cdb99245
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter15TheStandardTemplateLibrary_1.ipynb
@@ -0,0 +1,2625 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:9f3cc87ca66ff6fe2a52d0d72cf4859c6f5730f0081a8f18f154de578d8ad2e0"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 15: The Standard Template Library"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.1, Page Number 735"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = [11,22,33,44,55,66,77,88]\n",
+ "\n",
+ "ptr = arr.index(33) #find first 33\n",
+ "\n",
+ "print 'First object with value 33 found at offset',ptr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First object with value 33 found at offset 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.2, Page Number 736"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = [33,22,33,44,33,66,77,88]\n",
+ "\n",
+ "n = arr.count(33) #count number of 33's\n",
+ "\n",
+ "print 'There are',n,'33\\'s in arr.\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "There are 3 33's in arr.\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.3, Page Number 737"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = [45,2,22,-17,0,-30,25,55] #array of numbers\n",
+ "\n",
+ "arr1 = sorted(arr) #sort the numbers\n",
+ "\n",
+ "for j in range(8): #display sorted numbers\n",
+ " print arr1[j],'',"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-30 -17 0 2 22 25 45 55 \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.4, Page Number 737"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def find_sublist(sub, bigger): #function for find the substring\n",
+ " \n",
+ " if not bigger:\n",
+ " return -1\n",
+ " if not sub:\n",
+ " return 0\n",
+ " \n",
+ " first, rest = sub[0], sub[1:]\n",
+ " pos = 0\n",
+ " \n",
+ " try:\n",
+ " while True:\n",
+ " pos = bigger.index(first, pos) + 1\n",
+ " if not rest or bigger[pos:pos+len(rest)] == rest:\n",
+ " return pos-1\n",
+ " except ValueError:\n",
+ " return -1\n",
+ " \n",
+ " \n",
+ "\n",
+ "source = [11,44,33,11,22,33,11,22,44]\n",
+ "pattern = [11,22,33]\n",
+ "\n",
+ "ptr = find_sublist(pattern, source)\n",
+ "\n",
+ "if ptr == -1: #if past-the-end\n",
+ " print \"No Match Found\"\n",
+ "else:\n",
+ " print 'Match at',ptr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Match at 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.5, Page Number 738"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "src1 = [2,3,4,6,8]\n",
+ "src2 = [1,3,5]\n",
+ "\n",
+ "dest = sorted(src1 + src2) #merge src1 and src2 into dest and sort it\n",
+ "\n",
+ "for j in range(8): #display dist\n",
+ " print dest[j],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 2 3 3 4 5 6 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.6, Page Number 739"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fdata = [19.2 , 87.4 , 33.6 , 55.0 , 11.5 , 42.2] #array of doubles\n",
+ "\n",
+ "fdata1 = sorted(fdata , reverse = True) #sort the doubles in reverse order\n",
+ "\n",
+ "for j in range(6): #display sorted doubles\n",
+ " print fdata1[j],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "87.4 55.0 42.2 33.6 19.2 11.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.7, Page Number 740"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "names = [\"George\", \"Penny\", \"Estelle\", \"Don\", \"Mike\", \"Bob\"] #array of strings\n",
+ "\n",
+ "names = sorted(names) #sort the string\n",
+ "\n",
+ "for i in range (6): #display sorted strings\n",
+ " print names[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bob\n",
+ "Don\n",
+ "Estelle\n",
+ "George\n",
+ "Mike\n",
+ "Penny\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.8, Page Number 741"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "names = [\"George\", \"Estelle\", \"Don\", \"Mike\", \"Bob\"]\n",
+ "\n",
+ "ptr = names.index(\"Don\") #index of an element\n",
+ "\n",
+ "print 'Don is element',ptr,'on the list.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Don is element 2 on the list.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.9, Page Number 742"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def in_to_cm(inc): #convert and display as centimeters\n",
+ " print inc*2.54,\n",
+ " \n",
+ "inches = [3.5,6.2,1.0,12.75,4.33] #array of inches value\n",
+ "\n",
+ "for x in range(len(inches)): #output as centimeters\n",
+ " in_to_cm(inches[x])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8.89 15.748 2.54 32.385 10.9982\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.10, Page Number 743"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def in_to_cm(inc): #convert and display as centimeters\n",
+ " return inc*2.54\n",
+ " \n",
+ "inches = [3.5,6.2,1.0,12.75,4.33]\n",
+ "centi = [0.0 for j in range(5)]\n",
+ "\n",
+ "for x in range(len(inches)): #transform into array centi[]\n",
+ " centi[x] = in_to_cm(inches[x])\n",
+ " \n",
+ "for x in range(len(centi)): #display array centi[]\n",
+ " print centi[x],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8.89 15.748 2.54 32.385 10.9982\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.11, Page Number 744"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = []\n",
+ "\n",
+ " #put values at end of array\n",
+ "x.append(10)\n",
+ "x.append(11)\n",
+ "x.append(12)\n",
+ "x.append(13)\n",
+ "\n",
+ " #replace with new values\n",
+ "x[0] = 20\n",
+ "x[3] = 23\n",
+ "\n",
+ " #display array contents\n",
+ "for j in range(x.__len__()):\n",
+ " print x[j],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "20 11 12 23\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.12, Page Number 745"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#*class vector*#\n",
+ "\n",
+ "class vector: \n",
+ " \n",
+ " def __init__(self,a): #construtor\n",
+ " \n",
+ " if isinstance(a,int):\n",
+ " self.__arr = [0.0 for j in range(a)]\n",
+ " \n",
+ " elif isinstance(a,vector):\n",
+ " self.__arr = a.__arr\n",
+ " \n",
+ " else:\n",
+ " self.__arr = a\n",
+ " \n",
+ " \n",
+ " def swap(self,v2): #swap contents of two vectors\n",
+ " return v2.__arr,self.__arr\n",
+ " \n",
+ " def empty(self): #check vector is empty or not\n",
+ " if len(self.__arr)==0:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " def back(self): #return the last element of vector\n",
+ " a = len(self.__arr)\n",
+ " return self.__arr[a-1]\n",
+ " \n",
+ " def pop_back(self): #delete last element vector \n",
+ " self.__arr.pop()\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = [1.1,2.2,3.3,4.4] #an array of doubles\n",
+ "\n",
+ "v1 = vector(arr) #initialize vector to array\n",
+ "v2 = vector(4) #empty vector of size 4\n",
+ "\n",
+ "\n",
+ "v1,v2 = v1.swap(v2) #swap contents of v1 and v2\n",
+ "\n",
+ "v2 = vector(v2)\n",
+ "\n",
+ "while not v2.empty(): #untill vector is empty\n",
+ " \n",
+ " print v2.back(), #display the last element\n",
+ " v2.pop_back() #remove last element"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4.4 3.3 2.2 1.1\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.13, Page Number 746"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr = [100,110,120,130] #an array of ints\n",
+ "v = arr \n",
+ "\n",
+ "print 'Before insertion:',\n",
+ "for j in range(len(v)): #display all elements\n",
+ " print v[j],\n",
+ " \n",
+ "v.insert(2,115) #insert 115 at element 2\n",
+ "\n",
+ "print '\\nAfter insertion: ',\n",
+ "for j in range(len(v)): #display all elements\n",
+ " print v[j],\n",
+ " \n",
+ "v.remove(115) #erase element 2\n",
+ "\n",
+ "print '\\nAfter erasure: ',\n",
+ "for j in range(len(v)): #display all elements\n",
+ " print v[j],\n",
+ "\n",
+ "print '\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Before insertion: 100 110 120 130 \n",
+ "After insertion: 100 110 115 120 130 \n",
+ "After erasure: 100 110 120 130 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.14, Page Number 747"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*list class*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def size(self): #return size of array\n",
+ " self.__arr = sorted(self.__arr) #sort the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def front(self): #gives the first element\n",
+ " return self.__arr[0]\n",
+ " \n",
+ " def pop_front(self): #delete first element\n",
+ " a = self.__arr[0]\n",
+ " self.__arr.remove(a)\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "ilist = list()\n",
+ "\n",
+ "ilist.push_back(30) #push items on back\n",
+ "ilist.push_back(40)\n",
+ "ilist.push_back(20)\n",
+ "ilist.push_back(10)\n",
+ "\n",
+ "size = ilist.size() #number of items\n",
+ "\n",
+ "for j in range(size):\n",
+ " print ilist.front(), #read items from front\n",
+ " ilist.pop_front() #pop items off front"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 20 30 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.15, Page Number 748"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*list class*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def reverse(self): #reverse the array\n",
+ " self.__arr.reverse()\n",
+ " \n",
+ " def merge(self,a): #merge 'a' perameter to array\n",
+ " self.__arr.extend(a.__arr)\n",
+ " \n",
+ " def unique(self): #remove duplicate items from the array\n",
+ " a = []\n",
+ " for x in self.__arr:\n",
+ " if x not in a:\n",
+ " a.append(x)\n",
+ " self.__arr = a\n",
+ " \n",
+ " def size(self): #return size of array\n",
+ " self.__arr = sorted(self.__arr) #sort the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def empty(self): #check array is empty or not\n",
+ " if len(self.__arr)==0:\n",
+ " return 1\n",
+ " else:\n",
+ " return 0\n",
+ " \n",
+ " def front(self): #gives the first element\n",
+ " return self.__arr[0]\n",
+ " \n",
+ " def pop_front(self): #delete first element\n",
+ " a = self.__arr[0]\n",
+ " self.__arr.remove(a)\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr1 = [40,30,20,10]\n",
+ "arr2 = [15,20,25,30,35]\n",
+ "\n",
+ "list1 = list()\n",
+ "list2 = list()\n",
+ "\n",
+ "for j in range(4):\n",
+ " list1.push_back(arr1[j]) #list1: 40, 30, 20, 10\n",
+ "\n",
+ "for j in range(5):\n",
+ " list2.push_back(arr2[j]) #list2: 15, 20, 25, 30, 35\n",
+ " \n",
+ "list1.reverse() #reverse list1: 10 20 30 40\n",
+ "\n",
+ "list1.merge(list2) #merge list2 into list1\n",
+ "\n",
+ "list1.unique() #remove duplicate 20 and 30\n",
+ "\n",
+ "size = list1.size()\n",
+ "\n",
+ "while (list1.empty()==False):\n",
+ " print list1.front(), #read item from front\n",
+ " list1.pop_front() #poopitem off front"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 15 20 25 30 35 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.16, Page Number 750"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class deque: #*deque class*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def op1(self,a,b): #function to change the item of array\n",
+ " self.__arr[a] = b\n",
+ " \n",
+ " def size(self): #reurn size of array\n",
+ " self.__arr = sorted(self.__arr) #sort the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def op2(self,n): #function to return array item\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "deq = deque()\n",
+ "\n",
+ "deq.push_back(30) #push item on back\n",
+ "deq.push_back(40)\n",
+ "deq.push_back(50)\n",
+ "deq.push_back(20)\n",
+ "deq.push_back(10)\n",
+ "\n",
+ "k = deq.size()\n",
+ "\n",
+ "deq.op1(2,33) #change middle item\n",
+ "\n",
+ "for j in range(k):\n",
+ " print deq.op2(j), #display items"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 20 33 40 50\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.17, Page Number 759"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def op1(self,n): #function to return array item\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = [2,4,6,8]\n",
+ "\n",
+ "theList = list()\n",
+ "\n",
+ "for k in range(4):\n",
+ " theList.push_back(arr[k]) #fill list with array elements\n",
+ " \n",
+ "\n",
+ "for iter in range(theList.begin(),theList.end(),1):\n",
+ " print theList.op1(iter), #display the list"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2 4 6 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.18, Page Number 760"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self,a): #constructor\n",
+ " self.__arr = [0 for j in range(a)]\n",
+ " \n",
+ " def op1(self,a,b): #change the particular item\n",
+ " self.__arr[a] = b\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def op2(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "data = 0\n",
+ "\n",
+ "iList = list(5) #empty list holds 5 ints\n",
+ "\n",
+ " #fill list with data\n",
+ "for it in range(iList.begin(),iList.end(),1):\n",
+ " data += 2\n",
+ " iList.op1(it,data) \n",
+ " \n",
+ " #display list\n",
+ "for it in range(iList.begin(),iList.end(),1):\n",
+ " print iList.op2(it),"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2 4 6 8 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.19, Page Number 761"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self,a): #constructor\n",
+ " self.__arr = [0 for j in range(a)]\n",
+ " \n",
+ " def op1(self,a,b): #change the particular item\n",
+ " self.__arr[a] = b\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def find(self,a,b,c): #return the index of a particular element\n",
+ " for j in range(a,b,1):\n",
+ " if self.__arr[j] == c:\n",
+ " b = j\n",
+ " break\n",
+ " return b\n",
+ " \n",
+ "data = 0\n",
+ "\n",
+ "theList = list(5) #empty list holds 5 ints\n",
+ "\n",
+ " #fill list with data\n",
+ "for it in range(theList.begin(),theList.end(),1):\n",
+ " data += 2 #2, 4, 6, 8, 10\n",
+ " theList.op1(it,data)\n",
+ " \n",
+ " #look for number 8\n",
+ "iter = theList.find(theList.begin(),theList.end(),8)\n",
+ "\n",
+ "if iter!=theList.end():\n",
+ " print 'Found 8.'\n",
+ " \n",
+ "else:\n",
+ " print 'Dis not find 8.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Found 8.\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.20, Page Number 762"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class vector: #*class vector*#\n",
+ " \n",
+ " def __init__(self,a): #constructor\n",
+ " if isinstance(a,int):\n",
+ " self.__arr = [0.0 for j in range(a)]\n",
+ " \n",
+ " elif isinstance(a,vector):\n",
+ " self.__arr = a.__arr\n",
+ " \n",
+ " else:\n",
+ " self.__arr = a\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def copy(self,a,b,v): #copy the elements of array in another vector\n",
+ " for j in range(a,b,1):\n",
+ " v.__arr[j-a] = self.__arr[j]\n",
+ " return b-a\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = [11,13,15,17,19,21,23,25,27,29]\n",
+ "\n",
+ "v1 = vector(arr) #initialized vector\n",
+ "v2 = vector(10) #uninitialized vector\n",
+ "\n",
+ "print 'Enter range to be copied (Example: 2 5): '\n",
+ "beginRange = input(\"\")\n",
+ "endRange = input(\"\")\n",
+ "\n",
+ "iter1 = v1.begin() + beginRange\n",
+ "iter2 = v1.begin() + endRange\n",
+ "\n",
+ "iter3 = v1.copy(iter1,iter2,v2) #copy range from v1 to v2\n",
+ "\n",
+ "iter1 = v2.begin()\n",
+ "\n",
+ "print 'values:',\n",
+ "while (iter1 != iter3): #iteration through range in v2\n",
+ " print v2.op1(iter1), #displaying values\n",
+ " iter1 += 1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter range to be copied (Example: 2 5): \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "values: 17 19 21\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.21, Page Number 763"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def rend(self): #return the first index\n",
+ " return -1\n",
+ " \n",
+ " def rbegin(self): #returns the last index\n",
+ " return len(self.__arr)-1\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = [2,4,6,8,10] #array of ints\n",
+ "\n",
+ "theList = list()\n",
+ "\n",
+ "for j in range(5): #transfer array to list\n",
+ " theList.push_back(arr[j])\n",
+ " \n",
+ "revit = theList.rbegin() #reverse iterator\n",
+ "\n",
+ "while (revit != theList.rend()): #iterate backward through list,\n",
+ " print theList.op1(revit), #displaying output\n",
+ " revit -= 1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 8 6 4 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.22, Page Number 764"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class deque: #*class deque*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def copy(self,a,b,v): #copy the elements of array in another vector\n",
+ " for j in range(a,b,1):\n",
+ " v.__arr[j] = self.__arr[j]\n",
+ " \n",
+ " def end(self): #returns the length of the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def size(self): #reurn size of array\n",
+ " self.__arr = sorted(self.__arr) #sort the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr1 = [1,3,5,7,9]\n",
+ "arr2 = [2,4,6,8,10]\n",
+ " \n",
+ "d1 = deque()\n",
+ "d2 = deque()\n",
+ "\n",
+ "for j in range(5): #transfer arrays to deque\n",
+ " d1.push_back(arr1[j])\n",
+ " d2.push_back(arr2[j])\n",
+ "\n",
+ "d1.copy(d1.begin(),d1.end(),d2) #copy d1 to d2\n",
+ "\n",
+ "for k in range(d2.size()): #display d2\n",
+ " print d2.op1(k),"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 3 5 7 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.23, Page Number 765"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class deque: #*class deque*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def copy(self,a,b,v): #add one deque to another\n",
+ " for j in range(a,b,1):\n",
+ " v.__arr.append(self.__arr[j])\n",
+ " \n",
+ " def end(self): #returns the length of the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def size(self): #reurn size of array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr1 = [1,3,5,7,9]\n",
+ "arr2 = [2,4,6]\n",
+ " \n",
+ "d1 = deque()\n",
+ "d2 = deque()\n",
+ "\n",
+ " #transfer array to deques\n",
+ "for i in range(5):\n",
+ " d1.push_back(arr1[i])\n",
+ "for j in range(3):\n",
+ " d2.push_back(arr2[j])\n",
+ " \n",
+ "print 'd2:',\n",
+ " #copy d1 to back of d2\n",
+ "d1.copy(d1.begin(),d1.end(),d2)\n",
+ "\n",
+ "for k in range(d2.size()): #display d2\n",
+ " print d2.op1(k),"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d2: 2 4 6 1 3 5 7 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.24, Page Number 767"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def copy(self,a,b,c):\n",
+ " for j in range(a,b,1):\n",
+ " print self.__arr[j],c,\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = [10,20,30,40,50]\n",
+ "\n",
+ "theList = list()\n",
+ "\n",
+ "for j in range(5): #transfer array to list\n",
+ " theList.push_back(arr[j])\n",
+ " \n",
+ "c = \",\"\n",
+ "\n",
+ "print 'Contents of list: ',\n",
+ "\n",
+ "theList.copy(theList.begin(),theList.end(),c) #display list"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Contents of list: 10 , 20 , 30 , 40 , 50 ,\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.25, Page Number 768"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,a): #function to add element in array at last\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def copy(self,a,b,c): #write the array in the file\n",
+ " for j in range(a,b,1):\n",
+ " s = ''\n",
+ " s += '%d' %self.__arr[j]\n",
+ " c.write(s)\n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = [11,21,31,41,51]\n",
+ "\n",
+ "theList = list() #uninitialized list\n",
+ "\n",
+ "for j in range(5):\n",
+ " theList.push_back(arr[j]) #transfer array to list\n",
+ " \n",
+ "outfile = open(\"ITER.TXT\",\"w\") #open the file \n",
+ "\n",
+ "theList.copy(theList.begin(),theList.end(),outfile) #write list to file\n",
+ "\n",
+ "outfile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.26, Page Number 769"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self,a): #constructor\n",
+ " self.__arr = [0.0 for j in range(a)]\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def copy(self,a,b,c):\n",
+ " if isinstance(c,int):\n",
+ " self.__arr = a\n",
+ " \n",
+ " else:\n",
+ " for j in range(a,b,1):\n",
+ " print self.__arr[j],c,\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = []*5\n",
+ "print \"Enter 5 floating numbers: \"\n",
+ "for j in range(5):\n",
+ " x = input()\n",
+ " arr.append(x)\n",
+ "\n",
+ "fList = list(5) #uninitialized list\n",
+ "\n",
+ "fList.copy(arr,'end_of_stream',fList.begin())\n",
+ " \n",
+ "c = \"--\"\n",
+ "\n",
+ "fList.copy(fList.begin(),fList.end(),c)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 5 floating numbers: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1.1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2.2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4.4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1.1 -- 2.2 -- 3.3 -- 4.4 -- 5.5 --\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.27, Page Number 770"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def copy(self,a,b,c):\n",
+ " if isinstance(c,int):\n",
+ " self.__arr = a\n",
+ " \n",
+ " else:\n",
+ " for j in range(a,b,1):\n",
+ " print self.__arr[j],c,\n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ "arr = []*5\n",
+ "\n",
+ "iList = list() #empty list\n",
+ "\n",
+ "infile = open(\"ITER.TXT\",\"r\") #open a file in read mode\n",
+ "\n",
+ "for j in range(5):\n",
+ " arr.append(infile.read(2)) #add data from file to array \n",
+ " \n",
+ "iList.copy(arr,'end_of_stream',iList.begin()) #copy array to list\n",
+ "\n",
+ "c = \"--\"\n",
+ "\n",
+ "iList.copy(iList.begin(),iList.end(),c) #display list"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11 -- 21 -- 31 -- 41 -- 51 --\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.28, Page Number 772"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class set: #*class set*#\n",
+ " \n",
+ " def __init__(self,a): #constructor\n",
+ " self.__arr = a\n",
+ " \n",
+ " def insert(self,s): #insert the elements but without repeating\n",
+ " d=1\n",
+ " for j in range(len(self.__arr)):\n",
+ " if s==self.__arr[j]:\n",
+ " d=0\n",
+ " break;\n",
+ " if d==1:\n",
+ " self.__arr.append(s)\n",
+ " \n",
+ " def erase(self,s): #erase a particualr item from the set\n",
+ " self.__arr.remove(s)\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def size(self): #reurn size of array\n",
+ " self.__arr = sorted(self.__arr) #sort the array\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def find(self,sn): #find the index of a particular element\n",
+ " d=-1\n",
+ " for j in range(len(self.__arr)):\n",
+ " if sn==self.__arr[j]:\n",
+ " d=j\n",
+ " break;\n",
+ " if d==-1:\n",
+ " return len(self.__arr)\n",
+ " else:\n",
+ " return d\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "names = [\"Juanita\",\"Robert\",\"Mary\",\"Amanda\",\"Marie\"] #array of string objects\n",
+ "\n",
+ "nameSet = set(names) #initialize set to array\n",
+ "\n",
+ "nameSet.insert(\"Yvette\") #insert more names\n",
+ "nameSet.insert(\"Larry\")\n",
+ "nameSet.insert(\"Robert\") #no effect; already in set\n",
+ "nameSet.insert(\"Barry\")\n",
+ "\n",
+ "nameSet.erase(\"Mary\") #erase a name\n",
+ "\n",
+ "print 'Size',nameSet.size() #display size of set\n",
+ "\n",
+ "iter = nameSet.begin()\n",
+ "\n",
+ "while(iter != nameSet.end()-1): #display members of set\n",
+ " print nameSet.op1(iter)\n",
+ " iter += 1\n",
+ " \n",
+ "searchName = raw_input(\"Enter name to search for: \") #get name from user\n",
+ "\n",
+ "iter = nameSet.find(searchName) #find matching name in set\n",
+ "\n",
+ "if(iter == nameSet.end()):\n",
+ " print 'The name',searchName,'is NOT in the set.'\n",
+ " \n",
+ "else:\n",
+ " print 'The name',searchName,'IS in the set.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size 7\n",
+ "Amanda\n",
+ "Barry\n",
+ "Juanita\n",
+ "Larry\n",
+ "Marie\n",
+ "Robert\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name to search for: George\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The name George is NOT in the set.\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.29, Page Number 774"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class set: #*class set*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def insert(self,s): #insert the element in the array\n",
+ " self.__arr.append(s)\n",
+ " \n",
+ " def unique(self): #remove the duplicate items from the array\n",
+ " self.__arr = sorted(self.__arr)\n",
+ " a = []\n",
+ " for x in self.__arr:\n",
+ " if x not in a:\n",
+ " a.append(x)\n",
+ " self.__arr = a\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ "organic = set() #set of string objects\n",
+ "\n",
+ " #insert organic compounds\n",
+ "organic.insert(\"Curine\")\n",
+ "organic.insert(\"Xanthine\")\n",
+ "organic.insert(\"Curarine\")\n",
+ "organic.insert(\"Melamine\")\n",
+ "organic.insert(\"Cyanimide\")\n",
+ "organic.insert(\"Phenol\")\n",
+ "organic.insert(\"Aphrodine\")\n",
+ "organic.insert(\"Imidazole\")\n",
+ "organic.insert(\"Cinchonine\")\n",
+ "organic.insert(\"Palmitamide\")\n",
+ "organic.insert(\"Cyanimide\")\n",
+ "\n",
+ "organic.unique()\n",
+ "\n",
+ "iter = organic.begin()\n",
+ "\n",
+ "while (iter!=organic.end()): #display set\n",
+ " print organic.op1(iter)\n",
+ " iter += 1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Aphrodine\n",
+ "Cinchonine\n",
+ "Curarine\n",
+ "Curine\n",
+ "Cyanimide\n",
+ "Imidazole\n",
+ "Melamine\n",
+ "Palmitamide\n",
+ "Phenol\n",
+ "Xanthine\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.30, Page Number 776"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class map: #*class map*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr1 = [] #array for key\n",
+ " self.__arr2 = [] #array for value\n",
+ " \n",
+ " def op1(self,a,b): #add data in the arrays\n",
+ " self.__arr1.append(a)\n",
+ " self.__arr2.append(b)\n",
+ " \n",
+ " def op2(self,a): #return the value according to the key\n",
+ " for j in range(len(self.__arr1)):\n",
+ " if a==self.__arr1[j]:\n",
+ " return self.__arr2[j]\n",
+ " \n",
+ " def sort(self):\n",
+ " \n",
+ " n = len(self.__arr1)\n",
+ " \n",
+ " for j in range(n-1): #outer loop\n",
+ " for k in range(j+1,n,1): #inner loop starts at outer\n",
+ " \n",
+ " if self.__arr1[j] > self.__arr1[k]: #if 1st larger than 2nd\n",
+ " \n",
+ " temp = self.__arr1[j] #swap first array\n",
+ " self.__arr1[j] = self.__arr1[k]\n",
+ " self.__arr1[k] = temp\n",
+ " \n",
+ " temp = self.__arr2[j] #swap second array\n",
+ " self.__arr2[j] = self.__arr2[k]\n",
+ " self.__arr2[k] = temp\n",
+ " \n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr1)\n",
+ " \n",
+ " def first(self,a): #returns the key\n",
+ " return self.__arr1[a]\n",
+ " \n",
+ " def second(self,a): #returns the value\n",
+ " return self.__arr2[a]\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "states = [\"Wyoming\",\"Colorado\",\"Nevada\",\"Montana\",\"Arizona\",\"Idaho\"]\n",
+ "pops = [470,2890,800,787,2718,944]\n",
+ "\n",
+ "mapStates = map() #map\n",
+ "\n",
+ "for j in range(6):\n",
+ " name = states[j] #get data from array\n",
+ " pop = pops[j]\n",
+ " mapStates.op1(name,pop) #put it in map\n",
+ " \n",
+ "name = raw_input(\"Enter state: \") #get state from user\n",
+ "pop = mapStates.op2(name)\n",
+ "print 'Population: %d,000' %pop #find population\n",
+ "print \n",
+ "\n",
+ "mapStates.sort()\n",
+ "\n",
+ " #display entire map\n",
+ "for iter in range(mapStates.begin(),mapStates.end(),1):\n",
+ " print mapStates.first(iter),'%d,000' %mapStates.second(iter) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter state: Wyoming\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Population: 470,000\n",
+ "\n",
+ "Arizona 2718,000\n",
+ "Colorado 2890,000\n",
+ "Idaho 944,000\n",
+ "Montana 787,000\n",
+ "Nevada 800,000\n",
+ "Wyoming 470,000\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.31, Page Number 778"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class person: #class person\n",
+ " \n",
+ " def __init__(self,lana = \"blank\",fina = \"blank\",pho = 0): #construvtor\n",
+ " self.__lastName = lana\n",
+ " self.__firstName = fina\n",
+ " self.__phoneNumber = pho\n",
+ " \n",
+ " def display(self): #display person's data\n",
+ " print self.__lastName,'\\t',self.__firstName,'\\t\\tPhone:',self.__phoneNumber\n",
+ " \n",
+ " \n",
+ "def lesst(p1,p2): #less than function (friend function)\n",
+ " \n",
+ " if p1._person__lastName == p2._person__lastName:\n",
+ " if p1._person__firstName < p2._person__firstName:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " elif p1._person__lastName < p2._person__lastName:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ "def equ(p1,p2): #equal function (friend function)\n",
+ " \n",
+ " if (p1._person__lastName == p2._person__lastName) and (p1._person__firstName == p2._person__firstName):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "class multiset: #*class multiet*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def insert(self,a): #insert the element in the multiset\n",
+ " self.__arr.append(a)\n",
+ " \n",
+ " def size(self): #return the size of multiset\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def display(self,it): #display the items from multiset\n",
+ " if isinstance(it,int):\n",
+ " self.__arr[it].display()\n",
+ " \n",
+ " else:\n",
+ " for j in range(len(self.__arr)):\n",
+ " if equ(it,self.__arr[j]):\n",
+ " self.__arr[j].display()\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def count(self,sp): #return count of a element\n",
+ " a=0\n",
+ " for j in range(len(self.__arr)):\n",
+ " if equ(sp,self.__arr[j]):\n",
+ " a += 1\n",
+ " return a\n",
+ " \n",
+ " \n",
+ " def sort(self):\n",
+ " \n",
+ " n = len(self.__arr)\n",
+ " \n",
+ " for j in range(n-1): #outer loop\n",
+ " for k in range(j+1,n,1): #inner loop starts at outer\n",
+ " \n",
+ " if not lesst(self.__arr[j],self.__arr[k]): #if 1st larger than 2nd\n",
+ " \n",
+ " temp = self.__arr[j]._person__lastName #swap last name\n",
+ " self.__arr[j]._person__lastName = self.__arr[k]._person__lastName\n",
+ " self.__arr[k]._person__lastName = temp\n",
+ " \n",
+ " temp = self.__arr[j]._person__firstName #swap firs tname\n",
+ " self.__arr[j]._person__firstName = self.__arr[k]._person__firstName\n",
+ " self.__arr[k]._person__firstName = temp\n",
+ " \n",
+ " temp = self.__arr[j]._person__phoneNumber #swap phone number\n",
+ " self.__arr[j]._person__phoneNumber = self.__arr[k]._person__phoneNumber\n",
+ " self.__arr[k]._person__phoneNumber = temp\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " #create person objects\n",
+ "pers1 = person(\"Deauville\",\"Wiliam\",8435150)\n",
+ "pers2 = person(\"McDonald\",\"Stacey\",3327563)\n",
+ "pers3 = person(\"Bartoski\",\"peter\",6946473)\n",
+ "pers4 = person(\"Kuangthu\",\"Bruce\",4157300)\n",
+ "pers5 = person(\"Wellington\",\"John\",9207404)\n",
+ "pers6 = person(\"McDonald\",\"Amanda\",8435150)\n",
+ "pers7 = person(\"Fredericks\",\"Roger\",7049982)\n",
+ "pers8 = person(\"McDonald\",\"Stacey\",7764987)\n",
+ "\n",
+ "persSet = multiset() #multiset of persons\n",
+ "\n",
+ " #put persons in multiset\n",
+ "persSet.insert(pers1)\n",
+ "persSet.insert(pers2)\n",
+ "persSet.insert(pers3)\n",
+ "persSet.insert(pers4)\n",
+ "persSet.insert(pers5)\n",
+ "persSet.insert(pers6)\n",
+ "persSet.insert(pers7)\n",
+ "persSet.insert(pers8)\n",
+ "\n",
+ "print 'Number of entries =',persSet.size()\n",
+ "\n",
+ "persSet.sort()\n",
+ "\n",
+ "iter = persSet.begin()\n",
+ "\n",
+ "print\n",
+ "while(iter != persSet.end()): #display contents of multiset\n",
+ " persSet.display(iter)\n",
+ " iter += 1\n",
+ " \n",
+ " #get last and first name\n",
+ "searchLastName = raw_input(\"\\nEnter last name of person to search for: \")\n",
+ "searchFirstName = raw_input(\"Enter first name: \")\n",
+ "\n",
+ "searchPerson = person(searchLastName,searchFirstName,0)\n",
+ "\n",
+ " #get count of such persons\n",
+ "cntPersons = persSet.count(searchPerson) \n",
+ "print 'Number of persons with this name =',cntPersons\n",
+ "\n",
+ "\n",
+ "persSet.display(searchPerson) #display all matches"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of entries = 8\n",
+ "\n",
+ "Bartoski \tpeter \t\tPhone: 6946473\n",
+ "Deauville \tWiliam \t\tPhone: 8435150\n",
+ "Fredericks \tRoger \t\tPhone: 7049982\n",
+ "Kuangthu \tBruce \t\tPhone: 4157300\n",
+ "McDonald \tAmanda \t\tPhone: 8435150\n",
+ "McDonald \tStacey \t\tPhone: 7764987\n",
+ "McDonald \tStacey \t\tPhone: 3327563\n",
+ "Wellington \tJohn \t\tPhone: 9207404\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter last name of person to search for: McDonald\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter first name: Stacey\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of persons with this name = 2\n",
+ "McDonald \tStacey \t\tPhone: 7764987\n",
+ "McDonald \tStacey \t\tPhone: 3327563\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.32, Page Number 782"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class person: #person class\n",
+ " \n",
+ " def __init__(self,lana = \"blank\",fina = \"blank\",pho = 0): #constructor\n",
+ " self.__lastName = lana\n",
+ " self.__firstName = fina\n",
+ " self.__phoneNumber = pho\n",
+ " \n",
+ " def display(self): #display person's data\n",
+ " print self.__lastName,'\\t',self.__firstName,'\\t\\tPhone:',self.__phoneNumber\n",
+ " \n",
+ " def get_phone(self): #return phone number\n",
+ " return self.__phoneNumber\n",
+ " \n",
+ " \n",
+ "def lesst(p1,p2): #less than function (friend function)\n",
+ " \n",
+ " if p1._person__lastName == p2._person__lastName:\n",
+ " if p1._person__firstName < p2._person__firstName:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " elif p1._person__lastName == p2._person__lastName:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ "def equ(p1,p2): #equal function (friend function)\n",
+ " \n",
+ " if (p1._person__lastName == p2._person__lastName) and (p1._person__firstName == p2._person__firstName):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ "def notequ(p1,p2): #not equal function (friend function)\n",
+ " return not(equ(p1,p2))\n",
+ "\n",
+ "def greatert(p1,p2): #greater than function (friend function)\n",
+ " return not(lesst(p1,p2)) and not(equ(p1,p2))\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,pe): #function to add element in array at last\n",
+ " self.__arr.append(pe)\n",
+ " \n",
+ " def size(self): #return the size of list\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def display(self,it): #display the element of list\n",
+ " if isinstance(it,int):\n",
+ " self.__arr[it].display()\n",
+ " \n",
+ " else:\n",
+ " for j in range(len(self.__arr)):\n",
+ " if equ(it,self.__arr[j]):\n",
+ " self.__arr[j].display()\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def find(self,sp): #find the index of a particular item\n",
+ " for j in range(len(self.__arr)):\n",
+ " if equ(sp,self.__arr[j]):\n",
+ " return j\n",
+ " \n",
+ " def display1(self,sn): #display the elements according to the phone number\n",
+ " for j in range(len(self.__arr)):\n",
+ " if sn==self.__arr[j].get_phone():\n",
+ " self.__arr[j].display()\n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "persList = list() #list of persons\n",
+ "\n",
+ " #put persons in list\n",
+ "persList.push_back(person(\"Deauville\",\"Wiliam\",8435150))\n",
+ "persList.push_back(person(\"McDonald\",\"Stacey\",3327563))\n",
+ "persList.push_back(person(\"Bartoski\",\"peter\",6946473))\n",
+ "persList.push_back(person(\"Kuangthu\",\"Bruce\",4157300))\n",
+ "persList.push_back(person(\"Wellington\",\"John\",9207404))\n",
+ "persList.push_back(person(\"McDonald\",\"Amanda\",8435150))\n",
+ "persList.push_back(person(\"Fredericks\",\"Roger\",7049982))\n",
+ "persList.push_back(person(\"McDonald\",\"Stacey\",7764987))\n",
+ "\n",
+ "print 'Number of entries =',persList.size()\n",
+ "\n",
+ "iter = persList.begin()\n",
+ "\n",
+ "print\n",
+ "while(iter != persList.end()): #display contents of list\n",
+ " persList.display(iter)\n",
+ " iter += 1\n",
+ " \n",
+ " \n",
+ "#find person with specified name (last and first)\n",
+ "searchLastName = raw_input(\"\\nEnter last name of person to search for: \")\n",
+ "searchFirstName = raw_input(\"Enter first name: \")\n",
+ "\n",
+ "searchPerson = person(searchLastName,searchFirstName,0) #make a person with that name\n",
+ "\n",
+ " #search for first match of name\n",
+ "iter1 = persList.find(searchPerson)\n",
+ "print 'Person(s) with the same name is(are)'\n",
+ "\n",
+ "persList.display(searchPerson)\n",
+ "\n",
+ "\n",
+ "#find person with specified phone number\n",
+ "sNumber = input(\"\\nEnter phone nnumber (format 1234567): \")\n",
+ "print 'Person(s) with the same name is(are)'\n",
+ "\n",
+ "persList.display1(sNumber) #display the match "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of entries = 8\n",
+ "\n",
+ "Deauville \tWiliam \t\tPhone: 8435150\n",
+ "McDonald \tStacey \t\tPhone: 3327563\n",
+ "Bartoski \tpeter \t\tPhone: 6946473\n",
+ "Kuangthu \tBruce \t\tPhone: 4157300\n",
+ "Wellington \tJohn \t\tPhone: 9207404\n",
+ "McDonald \tAmanda \t\tPhone: 8435150\n",
+ "Fredericks \tRoger \t\tPhone: 7049982\n",
+ "McDonald \tStacey \t\tPhone: 7764987\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter last name of person to search for: Wellington\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter first name: John\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Person(s) with the same name is(are)\n",
+ "Wellington \tJohn \t\tPhone: 9207404\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter phone nnumber (format 1234567): 8435150\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Person(s) with the same name is(are)\n",
+ "Deauville \tWiliam \t\tPhone: 8435150\n",
+ "McDonald \tAmanda \t\tPhone: 8435150\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.33, Page Number 787"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class airtime:\n",
+ " \n",
+ " def __init__(self,h=0,m=0):\n",
+ " self.__hours = h # 0 to 23\n",
+ " self.__minutes = m # 0 to 59\n",
+ " \n",
+ " def display(self): #output to screen\n",
+ " print self.__hours,':',self.__minutes\n",
+ " \n",
+ " def get(self): #input from user\n",
+ " print 'Enter airtime (format 12:59):'\n",
+ " self.__hours = input()\n",
+ " self.__dummy = raw_input()\n",
+ " self.__minutes = input()\n",
+ " \n",
+ " def __iadd__(self,right): #overloaded + operator\n",
+ " temph = self.__hours + right.__hours\n",
+ " tempm = self.__minutes + right.__minutes\n",
+ " \n",
+ " if tempm>=60:\n",
+ " temph =temph + 1\n",
+ " tempm =tempm - 60\n",
+ " \n",
+ " return airtime(temph,tempm)\n",
+ " \n",
+ " \n",
+ " \n",
+ "class list: #*class list*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,te): #function to add element in array at last\n",
+ " self.__arr.append(te)\n",
+ " \n",
+ " def accumulate(self,a,b,c): #sum all the airtime\n",
+ " for j in range(b):\n",
+ " c += self.__arr[j]\n",
+ " return c\n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ "sum = airtime()\n",
+ "airlist = list()\n",
+ "\n",
+ "while True:\n",
+ " temp = airtime()\n",
+ " temp.get() #get airtime from user\n",
+ " airlist.push_back(temp)\n",
+ " answer = raw_input(\"enter another (y/n)? \")\n",
+ " \n",
+ " if(answer=='n'):\n",
+ " break;\n",
+ " \n",
+ "sum = airlist.accumulate(airlist.begin(),airlist.end(),airtime(0,0)) #sum all the airtimes\n",
+ "\n",
+ "print '\\n\\nsum =',\n",
+ "sum.display() #display sum"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter airtime (format 12:59):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ ":\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "45\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter airtime (format 12:59):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ ":\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter airtime (format 12:59):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ ":\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter another (y/n)? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter airtime (format 12:59):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ ":\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "55\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "enter another (y/n)? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "sum = 12 : 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15.34, Page Number 790"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class person: #class person\n",
+ " \n",
+ " def __init__(self,lana = \"blank\",fina = \"blank\",pho = 0): #constructor\n",
+ " self.__lastName = lana\n",
+ " self.__firstName = fina\n",
+ " self.__phoneNumber = pho\n",
+ " \n",
+ " def display(self): #display person's data\n",
+ " print self.__lastName,'\\t',self.__firstName,'\\t\\tPhone:',self.__phoneNumber\n",
+ " \n",
+ " def get_lastname(self): #return last name\n",
+ " return self.__lastName\n",
+ "\n",
+ " \n",
+ "def lesst(p1,p2): #less than function (friend function)\n",
+ " \n",
+ " if p1._person__lastName == p2._person__lastName:\n",
+ " if p1._person__firstName < p2._person__firstName:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " elif p1._person__lastName == p2._person__lastName:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ "def equ(p1,p2): #equal function (friend function)\n",
+ " if (p1._person__lastName == p2._person__lastName) and (p1._person__firstName == p2._person__firstName):\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " \n",
+ " \n",
+ "class vector: #*class vector*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,te): #function to add element in array at last\n",
+ " self.__arr.append(te) \n",
+ " \n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def display(self,a,b): #display the vector element \n",
+ " for j in range(a,b,1):\n",
+ " self.__arr[j].display()\n",
+ " \n",
+ " def sort(self):\n",
+ " \n",
+ " n = len(self.__arr)\n",
+ " \n",
+ " for j in range(n-1): #outer loop\n",
+ " for k in range(j+1,n,1): #inner loop starts at outer\n",
+ " \n",
+ " if not lesst(self.__arr[j],self.__arr[k]): #if 1st larger than 2nd\n",
+ " \n",
+ " temp = self.__arr[j]._person__lastName #swap last name\n",
+ " self.__arr[j]._person__lastName = self.__arr[k]._person__lastName\n",
+ " self.__arr[k]._person__lastName = temp\n",
+ " \n",
+ " temp = self.__arr[j]._person__firstName #swap firstname\n",
+ " self.__arr[j]._person__firstName = self.__arr[k]._person__firstName\n",
+ " self.__arr[k]._person__firstName = temp\n",
+ " \n",
+ " temp = self.__arr[j]._person__phoneNumber #swap phone number\n",
+ " self.__arr[j]._person__phoneNumber = self.__arr[k]._person__phoneNumber\n",
+ " self.__arr[k]._person__phoneNumber = temp\n",
+ " \n",
+ " \n",
+ " \n",
+ "\n",
+ "vectPtrspers = vector() #vector object\n",
+ "\n",
+ "#make persons\n",
+ "ptrp1 = person(\"Kuangthu\",\"Bruce\",4157300)\n",
+ "ptrp2 = person(\"Deauville\",\"Wiliam\",8435150)\n",
+ "ptrp3 = person(\"Wellington\",\"John\",9207404)\n",
+ "ptrp4 = person(\"Bartoski\",\"peter\",6946473)\n",
+ "ptrp5 = person(\"Fredericks\",\"Roger\",7049982)\n",
+ "ptrp6 = person(\"McDonald\",\"Stacey\",7764987)\n",
+ "\n",
+ "#put persons in set\n",
+ "vectPtrspers.push_back(ptrp1)\n",
+ "vectPtrspers.push_back(ptrp2)\n",
+ "vectPtrspers.push_back(ptrp3)\n",
+ "vectPtrspers.push_back(ptrp4)\n",
+ "vectPtrspers.push_back(ptrp5)\n",
+ "vectPtrspers.push_back(ptrp6)\n",
+ "\n",
+ "vectPtrspers.display(vectPtrspers.begin(),vectPtrspers.end()) #display vector\n",
+ "\n",
+ "print '\\nsorted pointers '\n",
+ "vectPtrspers.display(vectPtrspers.begin(),vectPtrspers.end())\n",
+ "\n",
+ "vectPtrspers.sort()\n",
+ "print '\\nsorted persons '\n",
+ "vectPtrspers.display(vectPtrspers.begin(),vectPtrspers.end())"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Kuangthu \tBruce \t\tPhone: 4157300\n",
+ "Deauville \tWiliam \t\tPhone: 8435150\n",
+ "Wellington \tJohn \t\tPhone: 9207404\n",
+ "Bartoski \tpeter \t\tPhone: 6946473\n",
+ "Fredericks \tRoger \t\tPhone: 7049982\n",
+ "McDonald \tStacey \t\tPhone: 7764987\n",
+ "\n",
+ "sorted pointers \n",
+ "Kuangthu \tBruce \t\tPhone: 4157300\n",
+ "Deauville \tWiliam \t\tPhone: 8435150\n",
+ "Wellington \tJohn \t\tPhone: 9207404\n",
+ "Bartoski \tpeter \t\tPhone: 6946473\n",
+ "Fredericks \tRoger \t\tPhone: 7049982\n",
+ "McDonald \tStacey \t\tPhone: 7764987\n",
+ "\n",
+ "sorted persons \n",
+ "McDonald \tStacey \t\tPhone: 7764987\n",
+ "Fredericks \tRoger \t\tPhone: 7049982\n",
+ "Bartoski \tpeter \t\tPhone: 6946473\n",
+ "Wellington \tJohn \t\tPhone: 9207404\n",
+ "Deauville \tWiliam \t\tPhone: 8435150\n",
+ "Kuangthu \tBruce \t\tPhone: 4157300\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter16Object-OrientedSoftwareDevelopment.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter16Object-OrientedSoftwareDevelopment.ipynb
new file mode 100755
index 00000000..9cafccbc
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter16Object-OrientedSoftwareDevelopment.ipynb
@@ -0,0 +1,1519 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:cd8630fc9b66a7e6efedc99ae328bfdc2e4a3602dc808dff9cc5b962dbd1f46e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16: Object-Oriented Software Development"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.1, Page Number 831"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class set: #*class set*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def insert(self,s): #insert the element in the array\n",
+ " self.__arr.append(s)\n",
+ "\n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def empty(self): #check set is empty or not\n",
+ " if len(self.__arr)==0:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " def erase(self,s): #erase a particualr item from the set\n",
+ " self.__arr.remove(s)\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ "class vector: #*class vector*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,s): #insert the element in the array\n",
+ " self.__arr.append(s)\n",
+ "\n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def empty(self): #check vector is empty or not\n",
+ " if len(self.__arr)==0:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " def size(self): #return the size of vector\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def erase(self,s): #erase a particualr item from the vector\n",
+ " self.__arr.remove(s)\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n] \n",
+ " \n",
+ " def sort(self,a,b): #sort the elements of vector by date\n",
+ " for k in range(1,b,1):\n",
+ " j=k-1\n",
+ " \n",
+ " c = compareDates()\n",
+ " while c.cmpdat(self.__arr[k],self.__arr[j]) and j>=0:\n",
+ " self.__arr[j+1] = self.__arr[j]\n",
+ " j -= 1\n",
+ " \n",
+ " self.__arr[j+1] = self.__arr[k]\n",
+ " \n",
+ " \n",
+ " #get line of text\n",
+ "def getaLine(inStr): \n",
+ " inStr = raw_input()\n",
+ " return inStr\n",
+ "\n",
+ "\n",
+ "def getaChar(): #get a character\n",
+ " ch = raw_input()\n",
+ " return ch\n",
+ "\n",
+ "\n",
+ "\n",
+ "class tenant: #---class tenant---#\n",
+ " \n",
+ " def __init__(self,n,aNo):\n",
+ " self.__name = n #tenant's name\n",
+ " self.__aptNumber = aNo #tenant's apartment number\n",
+ " \n",
+ " def __del__(self):\n",
+ " pass\n",
+ " \n",
+ " def getAptNumber(self):\n",
+ " return self.__aptNumber\n",
+ " \n",
+ " \n",
+ "#friend functions\n",
+ "\n",
+ "def ten_lt(t1,t2): #overloaded less than function\n",
+ " return t1._tenant__name < t2._tenant__name\n",
+ "\n",
+ "def ten_eq(t1,t2): #overloaded equal function\n",
+ " return t1._tenant__name == t2._tenant__name\n",
+ "\n",
+ "def ten_out(t): #for output\n",
+ " print t._tenant__aptNumber,'\\t',t._tenant__name\n",
+ " \n",
+ "\n",
+ " \n",
+ "class compareTenants: #---class compareTenants---#\n",
+ " \n",
+ " def cmpTen(self,ptrT1,ptrT2): #compares tenants\n",
+ " return ten_lt(ptrT1,ptrT2)\n",
+ " \n",
+ "\n",
+ " \n",
+ "class tenantList: #---class tenantList---#\n",
+ " __setPtrsTens = set() #set object\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " \n",
+ " while not (self.__setPtrsTens.empty()): \n",
+ " \n",
+ " j = self.__setPtrsTens.begin()\n",
+ " self.__setPtrsTens.erase(self.__setPtrsTens.op1(j)) #erase all tenants\n",
+ " \n",
+ " \n",
+ " def insertTenant(self,ptrT): #insert tenants into set\n",
+ " self.__setPtrsTens.insert(ptrT)\n",
+ " \n",
+ " \n",
+ " def getAptNo(self,tName): #return apartment number\n",
+ " \n",
+ " dummy = tenant(tName,0)\n",
+ " iter = self.__setPtrsTens.begin()\n",
+ " \n",
+ " while iter != self.__setPtrsTens.end():\n",
+ " aptNo = self.__setPtrsTens.op1(iter).getAptNumber() #look for tenant on the list?\n",
+ " \n",
+ " if ten_eq(dummy,self.__setPtrsTens.op1(iter)): #yes\n",
+ " return aptNo\n",
+ " \n",
+ " iter += 1\n",
+ " \n",
+ " return -1 #no\n",
+ " \n",
+ " \n",
+ " def display(self): #display tenant list\n",
+ " print '\\nApt#\\tTenant name\\n----------------------\\n',\n",
+ " \n",
+ " if self.__setPtrsTens.empty():\n",
+ " print '*****No tenants*****'\n",
+ " \n",
+ " else:\n",
+ " iter = self.__setPtrsTens.begin()\n",
+ " \n",
+ " while iter != self.__setPtrsTens.end():\n",
+ " ten_out(self.__setPtrsTens.op1(iter))\n",
+ " iter += 1\n",
+ " \n",
+ "\n",
+ " \n",
+ "class tenantInputScreen: #---class tenantInputScreen---#\n",
+ " __ptrTenantList = tenantList()\n",
+ " \n",
+ " def __init__(self,ptrTL=None):\n",
+ " self.__ptrTenantList = ptrTL\n",
+ " self.__tName = \"\"\n",
+ " self.__aptNo = 0\n",
+ " \n",
+ " def getTenant(self): #get tenant info\n",
+ " print \"Enter tenant's name (George Smith): \",\n",
+ " self.__tName = getaLine(self.__tName)\n",
+ " \n",
+ " self.__aptNo = input(\"Enter tenant's apartment number (10): \")\n",
+ " \n",
+ " ptrTenant = tenant(self.__tName,self.__aptNo)\n",
+ " self.__ptrTenantList.insertTenant(ptrTenant) #send to tenant list\n",
+ " \n",
+ " \n",
+ " \n",
+ "class rentRow: #---class rentRow---#\n",
+ " \n",
+ " def __init__(self,an): #one-arg constructor\n",
+ " self.__aptNo = an\n",
+ " self.__rent = [0 for j in range(12)]\n",
+ " \n",
+ " def setRent(self,m,am): #return rent for one month\n",
+ " self.__rent[m] = am\n",
+ " \n",
+ " def getSumOfRow(self): #return sum of rent in row\n",
+ " c = 0\n",
+ " for j in range(12):\n",
+ " c += self.__rent[j]\n",
+ " \n",
+ " return j\n",
+ " \n",
+ " \n",
+ "def rent_lt(t1,t2): #overloaded less than function\n",
+ " return t1._rentRow__aptNo < t2._rentRow__aptNo\n",
+ "\n",
+ "def rent_eq(t1,t2): #overloaded equal function\n",
+ " return t1._rentRow__aptNo == t2._rentRow__aptNo\n",
+ "\n",
+ "def rent_out(an): #for output\n",
+ " print an._rentRow__aptNo,'\\t', #print apartment number\n",
+ " \n",
+ " for j in range(12): #print 12 rents\n",
+ " if (an._rentRow__rent[j] == 0):\n",
+ " print ' 0 ',\n",
+ " \n",
+ " else:\n",
+ " print an._rentRow__rent[j],' ',\n",
+ " \n",
+ " print ''\n",
+ " \n",
+ " \n",
+ " \n",
+ "class compareRows: #---class compareRows---#\n",
+ " \n",
+ " def cmpRow(self,ptrR1,ptrR2): #compare apartment number\n",
+ " return rent_lt(ptrR1,ptrR2)\n",
+ " \n",
+ " \n",
+ " \n",
+ "class rentRecord: #---class rentRecord---#\n",
+ " __setPtrsRR = set()\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " while not (self.__setPtrsRR.empty()):\n",
+ " \n",
+ " j = self.__setPtrsRR.begin()\n",
+ " self.__setPtrsRR.erase(self.__setPtrsRR.op1(j)) #delete rent rows, remove ptrs from set\n",
+ " \n",
+ " \n",
+ " def insertRent(self,aptNo,month,amount):\n",
+ " \n",
+ " searchRow = rentRow(aptNo) #temp row with same aptNo\n",
+ " \n",
+ " iter = self.__setPtrsRR.begin() #searchsetPtrsRR\n",
+ " \n",
+ " b=0\n",
+ " while iter != self.__setPtrsRR.end(): #rent row found?\n",
+ " \n",
+ " if rent_eq(searchRow,self.__setPtrsRR.op1(iter)): #yes,\n",
+ " self.__setPtrsRR.op1(iter).setRent(month,amount) #put rent in row\n",
+ " b=1\n",
+ " break\n",
+ " else: #didn't find it\n",
+ " iter += 1\n",
+ " \n",
+ " if(b==0): \n",
+ " ptrRow = rentRow(aptNo) #make new row\n",
+ " ptrRow.setRent(month,amount) #put rent in row\n",
+ " \n",
+ " self.__setPtrsRR.insert(ptrRow) #put row in set\n",
+ " \n",
+ " \n",
+ " def display(self):\n",
+ " print \"\\nAptNo\\tJan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\\n-----------------------------------------------------\",\n",
+ " print \"---------------\"\n",
+ " \n",
+ " if self.__setPtrsRR.empty():\n",
+ " print \"*****No Rents*****\"\n",
+ " \n",
+ " else:\n",
+ " iter = self.__setPtrsRR.begin()\n",
+ " \n",
+ " while iter != self.__setPtrsRR.end():\n",
+ " rent_out(self.__setPtrsRR.op1(iter))\n",
+ " iter += 1\n",
+ " \n",
+ " \n",
+ " def getSumOfRents(self): #returns sum of all rents\n",
+ " sumRents = 0.0\n",
+ " \n",
+ " iter = self.__setPtrsRR.begin()\n",
+ " \n",
+ " while iter != self.__setPtrsRR.end():\n",
+ " sumRents += self.__setPtrsRR.op1(iter).getSumOfRow()\n",
+ " iter += 1\n",
+ " \n",
+ " return sumRents\n",
+ " \n",
+ " \n",
+ "\n",
+ "class rentInputScreen: #---class rentInputScreen---#\n",
+ " __ptrTenantList = tenantList()\n",
+ " __ptrRentRecord = rentRecord()\n",
+ " \n",
+ " def __init__(self,ptrTL=None,ptrRR=None):\n",
+ " self.__ptrTenantList = ptrTL\n",
+ " self.__ptrRentRecord = ptrRR\n",
+ " \n",
+ " self.__renterName = None\n",
+ " self.__rentPaid = 0.0\n",
+ " self.__month = 0\n",
+ " self.__aptNo = 0\n",
+ " \n",
+ " \n",
+ " def getRent(self): #rent for one tenant and one month\n",
+ " \n",
+ " print \"Enter tenant's name: \",\n",
+ " self.__renterName = getaLine(self.__renterName)\n",
+ " \n",
+ " self.__aptNo = self.__ptrTenantList.getAptNo(self.__renterName)\n",
+ " \n",
+ " if self.__aptNo>0: #if name found,\n",
+ " #get rent amount\n",
+ " self.__rentPaid = input(\"Enter amount paid (345.67): \")\n",
+ " self.__month = input(\"Enter month rent is for(1-12): \")\n",
+ " \n",
+ " self.__month -= 1 #internal is 0-11\n",
+ " \n",
+ " self.__ptrRentRecord.insertRent(self.__aptNo,self.__month,self.__rentPaid)\n",
+ " \n",
+ " else:\n",
+ " print 'No tenant with that name.'\n",
+ " \n",
+ " \n",
+ "class expense: #---class expense---#\n",
+ " \n",
+ " def __init__(self,m=0,d=0,c=\"\",p=\"\",a=0.0): #constructor\n",
+ " self.__month = m\n",
+ " self.__day = d\n",
+ " self.__category = c\n",
+ " self.__payee = p\n",
+ " self.__amount = a\n",
+ " \n",
+ " \n",
+ "def exp_lt(e1,e2): #overloaded less than function\n",
+ " if e1._expense__month == e2._expense__month:\n",
+ " return e1._expense__day < e2._expense__day\n",
+ "\n",
+ "def exp_eq(e1,e2): #overloaded equal function\n",
+ " return e1._expense__month == e2._expense__month and e1._expense__day == e2._expense__day\n",
+ "\n",
+ "def exp_out(exp): #for output\n",
+ " print exp._expense__month,'/',exp._expense__day,'\\t',exp._expense__payee,'\\t',exp._expense__amount,'\\t',exp._expense__category\n",
+ " \n",
+ " \n",
+ " \n",
+ "class compareDates: #---class compareDates---#\n",
+ " \n",
+ " def cmpdat(self,ptrE1,ptrE2): #compare expenses according to dates\n",
+ " return exp_lt(ptrE1,ptrE2)\n",
+ " \n",
+ " \n",
+ " \n",
+ "class compareCategories: #---class compareCategories---#\n",
+ " \n",
+ " def cmpcat(self,ptrE1,ptrE2): #compare expenses according to category\n",
+ " return ptrE1._expense__category < ptrE2._expense__category\n",
+ " \n",
+ " \n",
+ " \n",
+ "class expenseRecord: #---class expenseRecord---#\n",
+ " __vectPtrsExpenses = vector()\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " \n",
+ " while not (self.__vectPtrsExpenses.empty()):\n",
+ " \n",
+ " j = self.__vectPtrsExpenses.begin()\n",
+ " self.__vectPtrsExpenses.erase(self.__vectPtrsExpenses.op1(j)) #delete expense objects, remove ptrs from vector\n",
+ " \n",
+ " def insertExp(self,ptrExp):\n",
+ " self.__vectPtrsExpenses.push_back(ptrExp)\n",
+ " \n",
+ " def display(self):\n",
+ " print \"\\nDate\\tPayee\\t\\tAmount\\tCategory\\n--------------------------------------------\"\n",
+ " \n",
+ " if self.__vectPtrsExpenses.size() == 0:\n",
+ " print \"*****No Expenses*****\"\n",
+ " \n",
+ " else:\n",
+ " self.__vectPtrsExpenses.sort(self.__vectPtrsExpenses.begin(),self.__vectPtrsExpenses.end()) #sort by date\n",
+ " \n",
+ " iter = self.__vectPtrsExpenses.begin()\n",
+ " \n",
+ " while iter != self.__vectPtrsExpenses.end():\n",
+ " exp_out(self.__vectPtrsExpenses.op1(iter))\n",
+ " iter += 1\n",
+ " \n",
+ " def displaySummary(self): #used by annualReport\n",
+ " \n",
+ " totalExpenses = 0.0 #total, all category\n",
+ " \n",
+ " if self.__vectPtrsExpenses.size() == 0:\n",
+ " print \"\\tAll categories\\t0\"\n",
+ " return 0.0\n",
+ " \n",
+ " self.__vectPtrsExpenses.sort(self.__vectPtrsExpenses.begin(),self.__vectPtrsExpenses.end()) #sort by category\n",
+ " \n",
+ " #for each category, sum the enries\n",
+ " \n",
+ " iter = self.__vectPtrsExpenses.begin()\n",
+ " tempCat = self.__vectPtrsExpenses.op1(iter)._expense__category\n",
+ " sumCat = 0.0\n",
+ " \n",
+ " while iter != self.__vectPtrsExpenses.end():\n",
+ " \n",
+ " if tempCat == self.__vectPtrsExpenses.op1(iter)._expense__category:\n",
+ " sumCat += self.__vectPtrsExpenses.op1(iter)._expense__amount #same category\n",
+ " \n",
+ " else:\n",
+ " #different category\n",
+ " print '\\t',tempCat,'\\t',sumCat\n",
+ " totalExpenses += sumCat #add previous category\n",
+ " \n",
+ " tempCat = self.__vectPtrsExpenses.op1(iter)._expense__category\n",
+ " sumCat = self.__vectPtrsExpenses.op1(iter)._expense__amount #add final amount\n",
+ " \n",
+ " iter += 1\n",
+ " \n",
+ " totalExpenses += sumCat #add fianl category\n",
+ " print '\\t',tempCat,'\\t',sumCat\n",
+ " \n",
+ " return totalExpenses\n",
+ " \n",
+ "\n",
+ "class expenseInputScreen: #---class expenseInputScreen---#\n",
+ " __ptrExpenseRecord = expenseRecord()\n",
+ " \n",
+ " def __init__(self,per=None): #constructor\n",
+ " self.__ptrExpenseRecord = per\n",
+ " \n",
+ " \n",
+ " def getExpense(self):\n",
+ " \n",
+ " month = input(\"Enter month (1-12): \")\n",
+ " day = input(\"Enter day (1-31): \")\n",
+ " \n",
+ " category = \"\"\n",
+ " print \"Enter expense category (Repairing, Utilities): \",\n",
+ " category = getaLine(category)\n",
+ " \n",
+ " payee = \"\"\n",
+ " print \"Enter payee (Bob's Hardware, Big Electric Co): \",\n",
+ " payee = getaLine(payee)\n",
+ " \n",
+ " amount = input(\"Enter amount (39.95): \")\n",
+ " \n",
+ " ptrExpense = expense(month,day,category,payee,amount)\n",
+ " \n",
+ " self.__ptrExpenseRecord.insertExp(ptrExpense)\n",
+ " \n",
+ " \n",
+ " \n",
+ "class annualReport: #---class annualReport---#\n",
+ " \n",
+ " __ptrRR = rentRecord()\n",
+ " __ptrER = expenseRecord()\n",
+ " \n",
+ " def __init__(self,pRR=None,pER=None): #constructor\n",
+ " self.__ptrRR = pRR\n",
+ " self.__ptrER = pER\n",
+ " self.__expenses = 0.0\n",
+ " self.__rents = 0.0\n",
+ " \n",
+ " def display(self): #display annual report\n",
+ " print \"Annual Summary\\n-----------------------------\\nIncome\\n\\tRent\\t\\t\",\n",
+ " self.__rents = self.__ptrRR.getSumOfRents()\n",
+ " print self.__rents\n",
+ " print \"Expenses\"\n",
+ " self.__expenses = self.__ptrER.displaySummary()\n",
+ " print \"\\nbalance\\t\\t\\t\",self.__rents-self.__expenses\n",
+ " \n",
+ " \n",
+ "class userInterface: #---class userInterface---#\n",
+ " \n",
+ " __ptrTenantList = tenantList()\n",
+ " __ptrTenantInputScreen = tenantInputScreen()\n",
+ " __ptrRentRecord = rentRecord()\n",
+ " __ptrrentInputScreen = rentInputScreen()\n",
+ " __ptrExpenseRecord = expenseRecord()\n",
+ " __ptrExpenseInputScreen = expenseInputScreen()\n",
+ " __ptrAnnualReport = annualReport()\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " \n",
+ " #three reports exist for the life of the program\n",
+ " self.__ptrTenantList = tenantList()\n",
+ " self.__ptrRentRecord = rentRecord()\n",
+ " self.__ptrExpenseRecord = expenseRecord()\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " del self.__ptrTenantList\n",
+ " del self.__ptrRentRecord\n",
+ " del self.__ptrExpenseRecord\n",
+ " \n",
+ " \n",
+ " \n",
+ " def interact(self):\n",
+ " \n",
+ " while True:\n",
+ " \n",
+ " print \"\\nEnter 'i' to input data, \"\n",
+ " print \" 'd' to display a report,\"\n",
+ " print \" 'q' to quit program: \",\n",
+ " \n",
+ " ch = getaChar()\n",
+ " \n",
+ " if ch=='i': #enter data\n",
+ " \n",
+ " print \"Enter 't' to add tenant,\"\n",
+ " print \" 'r' to record rent payment\"\n",
+ " print \" 'e' to record expense: \",\n",
+ " \n",
+ " ch = getaChar()\n",
+ " print '\\n'\n",
+ " \n",
+ " if ch=='t':\n",
+ " self.__ptrTenantInputScreen = tenantInputScreen(self.__ptrTenantList)\n",
+ " self.__ptrTenantInputScreen.getTenant()\n",
+ " \n",
+ " elif ch=='r':\n",
+ " self.__ptrRentInputScreen = rentInputScreen(self.__ptrTenantList,self.__ptrRentRecord)\n",
+ " self.__ptrRentInputScreen.getRent()\n",
+ " \n",
+ " elif ch=='e':\n",
+ " self.__ptrExpenseInputScreen = expenseInputScreen(self.__ptrExpenseRecord)\n",
+ " self.__ptrExpenseInputScreen.getExpense()\n",
+ " \n",
+ " else:\n",
+ " print \"Unknown input option\"\n",
+ " \n",
+ " \n",
+ " elif ch=='d': #display data\n",
+ " \n",
+ " print \"Enter 't' to display tenants,\"\n",
+ " print \" 'r' to display rents\"\n",
+ " print \" 'e' to display expense,\"\n",
+ " print \" 'a' to display annual report: \",\n",
+ " \n",
+ " ch = getaChar()\n",
+ " print '\\n'\n",
+ " \n",
+ " if ch=='t':\n",
+ " self.__ptrTenantList.display()\n",
+ " \n",
+ " elif ch=='r':\n",
+ " self.__ptrRentRecord.display()\n",
+ " \n",
+ " elif ch=='e':\n",
+ " self.__ptrExpenseRecord.display()\n",
+ " \n",
+ " elif ch=='a':\n",
+ " self.__ptrAnnualReport = annualReport(self.__ptrRentRecord,self.__ptrExpenseRecord)\n",
+ " self.__ptrAnnualReport.display()\n",
+ " del self.__ptrAnnualReport\n",
+ " \n",
+ " else:\n",
+ " print \"Unknown display option\"\n",
+ " \n",
+ " \n",
+ " elif ch=='q':\n",
+ " break #quit\n",
+ " \n",
+ " else:\n",
+ " print \"Unknown option. Enter only 'i', 'd' or 'q'\"\n",
+ " \n",
+ " \n",
+ " \n",
+ "theUserInterface = userInterface()\n",
+ "\n",
+ "theUserInterface.interact()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "t\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter tenant's name (George Smith): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Harry Ellis\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter tenant's apartment number (10): 101\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "t\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter tenant's name (George Smith): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wanda Brown\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter tenant's apartment number (10): 102\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to display tenants,\n",
+ " 'r' to display rents\n",
+ " 'e' to display expense,\n",
+ " 'a' to display annual report: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "t\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "\n",
+ "Apt#\tTenant name\n",
+ "----------------------\n",
+ "101 \tHarry Ellis\n",
+ "102 \tWanda Brown\n",
+ "\n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter tenant's name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Harry Ellis\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount paid (345.67): 695\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month rent is for(1-12): 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter tenant's name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Harry Ellis\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount paid (345.67): 695\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month rent is for(1-12): 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter tenant's name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wanda Brown\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount paid (345.67): 595\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month rent is for(1-12): 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wanda Brown\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Unknown option. Enter only 'i', 'd' or 'q'\n",
+ "\n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter tenant's name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wanda Brown\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount paid (345.67): 595\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month rent is for(1-12): 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to display tenants,\n",
+ " 'r' to display rents\n",
+ " 'e' to display expense,\n",
+ " 'a' to display annual report: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "\n",
+ "AptNo\tJan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\n",
+ "----------------------------------------------------- ---------------\n",
+ "101 \t695 695 0 0 0 0 0 0 0 0 0 0 \n",
+ "102 \t595 595 0 0 0 0 0 0 0 0 0 0 \n",
+ "\n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month (1-12): 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter day (1-31): 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter expense category (Repairing, Utilities): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mortgage\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter payee (Bob's Hardware, Big Electric Co): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First megaBank\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount (39.95): 5187.30\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month (1-12): 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter day (1-31): 8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter expense category (Repairing, Utilities): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Utilities\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter payee (Bob's Hardware, Big Electric Co): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "City Water\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount (39.95): 963.10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month (1-12): 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter day (1-31): 9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter expense category (Repairing, Utilities): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Insurance\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter payee (Bob's Hardware, Big Electric Co): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Steady State\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount (39.95): 4840.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to display tenants,\n",
+ " 'r' to display rents\n",
+ " 'e' to display expense,\n",
+ " 'a' to display annual report: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "\n",
+ "Date\tPayee\t\tAmount\tCategory\n",
+ "--------------------------------------------\n",
+ "1 / 3 \tFirst megaBank \t5187.3 \tMortgage\n",
+ "1 / 8 \tCity Water \t963.1 \tUtilities\n",
+ "1 / 9 \tSteady State \t4840.0 \tInsurance\n",
+ "\n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to display tenants,\n",
+ " 'r' to display rents\n",
+ " 'e' to display expense,\n",
+ " 'a' to display annual report: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Annual Summary\n",
+ "-----------------------------\n",
+ "Income\n",
+ "\tRent\t\t22.0\n",
+ "Expenses\n",
+ "\tMortgage \t5187.3\n",
+ "\tUtilities \t963.1\n",
+ "\tInsurance \t4840.0\n",
+ "\n",
+ "balance\t\t\t-10968.4\n",
+ "\n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "q\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter16Object-OrientedSoftwareDevelopment_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter16Object-OrientedSoftwareDevelopment_1.ipynb
new file mode 100755
index 00000000..9cafccbc
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter16Object-OrientedSoftwareDevelopment_1.ipynb
@@ -0,0 +1,1519 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:cd8630fc9b66a7e6efedc99ae328bfdc2e4a3602dc808dff9cc5b962dbd1f46e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16: Object-Oriented Software Development"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16.1, Page Number 831"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class set: #*class set*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def insert(self,s): #insert the element in the array\n",
+ " self.__arr.append(s)\n",
+ "\n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def empty(self): #check set is empty or not\n",
+ " if len(self.__arr)==0:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " def erase(self,s): #erase a particualr item from the set\n",
+ " self.__arr.remove(s)\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ "class vector: #*class vector*#\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__arr = []\n",
+ " \n",
+ " def push_back(self,s): #insert the element in the array\n",
+ " self.__arr.append(s)\n",
+ "\n",
+ " def begin(self): #return the first index position\n",
+ " return 0\n",
+ " \n",
+ " def end(self): #return the last index position\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def empty(self): #check vector is empty or not\n",
+ " if len(self.__arr)==0:\n",
+ " return True\n",
+ " else:\n",
+ " return False\n",
+ " \n",
+ " def size(self): #return the size of vector\n",
+ " return len(self.__arr)\n",
+ " \n",
+ " def erase(self,s): #erase a particualr item from the vector\n",
+ " self.__arr.remove(s)\n",
+ " \n",
+ " def op1(self,n): #function to return array element\n",
+ " return self.__arr[n] \n",
+ " \n",
+ " def sort(self,a,b): #sort the elements of vector by date\n",
+ " for k in range(1,b,1):\n",
+ " j=k-1\n",
+ " \n",
+ " c = compareDates()\n",
+ " while c.cmpdat(self.__arr[k],self.__arr[j]) and j>=0:\n",
+ " self.__arr[j+1] = self.__arr[j]\n",
+ " j -= 1\n",
+ " \n",
+ " self.__arr[j+1] = self.__arr[k]\n",
+ " \n",
+ " \n",
+ " #get line of text\n",
+ "def getaLine(inStr): \n",
+ " inStr = raw_input()\n",
+ " return inStr\n",
+ "\n",
+ "\n",
+ "def getaChar(): #get a character\n",
+ " ch = raw_input()\n",
+ " return ch\n",
+ "\n",
+ "\n",
+ "\n",
+ "class tenant: #---class tenant---#\n",
+ " \n",
+ " def __init__(self,n,aNo):\n",
+ " self.__name = n #tenant's name\n",
+ " self.__aptNumber = aNo #tenant's apartment number\n",
+ " \n",
+ " def __del__(self):\n",
+ " pass\n",
+ " \n",
+ " def getAptNumber(self):\n",
+ " return self.__aptNumber\n",
+ " \n",
+ " \n",
+ "#friend functions\n",
+ "\n",
+ "def ten_lt(t1,t2): #overloaded less than function\n",
+ " return t1._tenant__name < t2._tenant__name\n",
+ "\n",
+ "def ten_eq(t1,t2): #overloaded equal function\n",
+ " return t1._tenant__name == t2._tenant__name\n",
+ "\n",
+ "def ten_out(t): #for output\n",
+ " print t._tenant__aptNumber,'\\t',t._tenant__name\n",
+ " \n",
+ "\n",
+ " \n",
+ "class compareTenants: #---class compareTenants---#\n",
+ " \n",
+ " def cmpTen(self,ptrT1,ptrT2): #compares tenants\n",
+ " return ten_lt(ptrT1,ptrT2)\n",
+ " \n",
+ "\n",
+ " \n",
+ "class tenantList: #---class tenantList---#\n",
+ " __setPtrsTens = set() #set object\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " \n",
+ " while not (self.__setPtrsTens.empty()): \n",
+ " \n",
+ " j = self.__setPtrsTens.begin()\n",
+ " self.__setPtrsTens.erase(self.__setPtrsTens.op1(j)) #erase all tenants\n",
+ " \n",
+ " \n",
+ " def insertTenant(self,ptrT): #insert tenants into set\n",
+ " self.__setPtrsTens.insert(ptrT)\n",
+ " \n",
+ " \n",
+ " def getAptNo(self,tName): #return apartment number\n",
+ " \n",
+ " dummy = tenant(tName,0)\n",
+ " iter = self.__setPtrsTens.begin()\n",
+ " \n",
+ " while iter != self.__setPtrsTens.end():\n",
+ " aptNo = self.__setPtrsTens.op1(iter).getAptNumber() #look for tenant on the list?\n",
+ " \n",
+ " if ten_eq(dummy,self.__setPtrsTens.op1(iter)): #yes\n",
+ " return aptNo\n",
+ " \n",
+ " iter += 1\n",
+ " \n",
+ " return -1 #no\n",
+ " \n",
+ " \n",
+ " def display(self): #display tenant list\n",
+ " print '\\nApt#\\tTenant name\\n----------------------\\n',\n",
+ " \n",
+ " if self.__setPtrsTens.empty():\n",
+ " print '*****No tenants*****'\n",
+ " \n",
+ " else:\n",
+ " iter = self.__setPtrsTens.begin()\n",
+ " \n",
+ " while iter != self.__setPtrsTens.end():\n",
+ " ten_out(self.__setPtrsTens.op1(iter))\n",
+ " iter += 1\n",
+ " \n",
+ "\n",
+ " \n",
+ "class tenantInputScreen: #---class tenantInputScreen---#\n",
+ " __ptrTenantList = tenantList()\n",
+ " \n",
+ " def __init__(self,ptrTL=None):\n",
+ " self.__ptrTenantList = ptrTL\n",
+ " self.__tName = \"\"\n",
+ " self.__aptNo = 0\n",
+ " \n",
+ " def getTenant(self): #get tenant info\n",
+ " print \"Enter tenant's name (George Smith): \",\n",
+ " self.__tName = getaLine(self.__tName)\n",
+ " \n",
+ " self.__aptNo = input(\"Enter tenant's apartment number (10): \")\n",
+ " \n",
+ " ptrTenant = tenant(self.__tName,self.__aptNo)\n",
+ " self.__ptrTenantList.insertTenant(ptrTenant) #send to tenant list\n",
+ " \n",
+ " \n",
+ " \n",
+ "class rentRow: #---class rentRow---#\n",
+ " \n",
+ " def __init__(self,an): #one-arg constructor\n",
+ " self.__aptNo = an\n",
+ " self.__rent = [0 for j in range(12)]\n",
+ " \n",
+ " def setRent(self,m,am): #return rent for one month\n",
+ " self.__rent[m] = am\n",
+ " \n",
+ " def getSumOfRow(self): #return sum of rent in row\n",
+ " c = 0\n",
+ " for j in range(12):\n",
+ " c += self.__rent[j]\n",
+ " \n",
+ " return j\n",
+ " \n",
+ " \n",
+ "def rent_lt(t1,t2): #overloaded less than function\n",
+ " return t1._rentRow__aptNo < t2._rentRow__aptNo\n",
+ "\n",
+ "def rent_eq(t1,t2): #overloaded equal function\n",
+ " return t1._rentRow__aptNo == t2._rentRow__aptNo\n",
+ "\n",
+ "def rent_out(an): #for output\n",
+ " print an._rentRow__aptNo,'\\t', #print apartment number\n",
+ " \n",
+ " for j in range(12): #print 12 rents\n",
+ " if (an._rentRow__rent[j] == 0):\n",
+ " print ' 0 ',\n",
+ " \n",
+ " else:\n",
+ " print an._rentRow__rent[j],' ',\n",
+ " \n",
+ " print ''\n",
+ " \n",
+ " \n",
+ " \n",
+ "class compareRows: #---class compareRows---#\n",
+ " \n",
+ " def cmpRow(self,ptrR1,ptrR2): #compare apartment number\n",
+ " return rent_lt(ptrR1,ptrR2)\n",
+ " \n",
+ " \n",
+ " \n",
+ "class rentRecord: #---class rentRecord---#\n",
+ " __setPtrsRR = set()\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " while not (self.__setPtrsRR.empty()):\n",
+ " \n",
+ " j = self.__setPtrsRR.begin()\n",
+ " self.__setPtrsRR.erase(self.__setPtrsRR.op1(j)) #delete rent rows, remove ptrs from set\n",
+ " \n",
+ " \n",
+ " def insertRent(self,aptNo,month,amount):\n",
+ " \n",
+ " searchRow = rentRow(aptNo) #temp row with same aptNo\n",
+ " \n",
+ " iter = self.__setPtrsRR.begin() #searchsetPtrsRR\n",
+ " \n",
+ " b=0\n",
+ " while iter != self.__setPtrsRR.end(): #rent row found?\n",
+ " \n",
+ " if rent_eq(searchRow,self.__setPtrsRR.op1(iter)): #yes,\n",
+ " self.__setPtrsRR.op1(iter).setRent(month,amount) #put rent in row\n",
+ " b=1\n",
+ " break\n",
+ " else: #didn't find it\n",
+ " iter += 1\n",
+ " \n",
+ " if(b==0): \n",
+ " ptrRow = rentRow(aptNo) #make new row\n",
+ " ptrRow.setRent(month,amount) #put rent in row\n",
+ " \n",
+ " self.__setPtrsRR.insert(ptrRow) #put row in set\n",
+ " \n",
+ " \n",
+ " def display(self):\n",
+ " print \"\\nAptNo\\tJan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\\n-----------------------------------------------------\",\n",
+ " print \"---------------\"\n",
+ " \n",
+ " if self.__setPtrsRR.empty():\n",
+ " print \"*****No Rents*****\"\n",
+ " \n",
+ " else:\n",
+ " iter = self.__setPtrsRR.begin()\n",
+ " \n",
+ " while iter != self.__setPtrsRR.end():\n",
+ " rent_out(self.__setPtrsRR.op1(iter))\n",
+ " iter += 1\n",
+ " \n",
+ " \n",
+ " def getSumOfRents(self): #returns sum of all rents\n",
+ " sumRents = 0.0\n",
+ " \n",
+ " iter = self.__setPtrsRR.begin()\n",
+ " \n",
+ " while iter != self.__setPtrsRR.end():\n",
+ " sumRents += self.__setPtrsRR.op1(iter).getSumOfRow()\n",
+ " iter += 1\n",
+ " \n",
+ " return sumRents\n",
+ " \n",
+ " \n",
+ "\n",
+ "class rentInputScreen: #---class rentInputScreen---#\n",
+ " __ptrTenantList = tenantList()\n",
+ " __ptrRentRecord = rentRecord()\n",
+ " \n",
+ " def __init__(self,ptrTL=None,ptrRR=None):\n",
+ " self.__ptrTenantList = ptrTL\n",
+ " self.__ptrRentRecord = ptrRR\n",
+ " \n",
+ " self.__renterName = None\n",
+ " self.__rentPaid = 0.0\n",
+ " self.__month = 0\n",
+ " self.__aptNo = 0\n",
+ " \n",
+ " \n",
+ " def getRent(self): #rent for one tenant and one month\n",
+ " \n",
+ " print \"Enter tenant's name: \",\n",
+ " self.__renterName = getaLine(self.__renterName)\n",
+ " \n",
+ " self.__aptNo = self.__ptrTenantList.getAptNo(self.__renterName)\n",
+ " \n",
+ " if self.__aptNo>0: #if name found,\n",
+ " #get rent amount\n",
+ " self.__rentPaid = input(\"Enter amount paid (345.67): \")\n",
+ " self.__month = input(\"Enter month rent is for(1-12): \")\n",
+ " \n",
+ " self.__month -= 1 #internal is 0-11\n",
+ " \n",
+ " self.__ptrRentRecord.insertRent(self.__aptNo,self.__month,self.__rentPaid)\n",
+ " \n",
+ " else:\n",
+ " print 'No tenant with that name.'\n",
+ " \n",
+ " \n",
+ "class expense: #---class expense---#\n",
+ " \n",
+ " def __init__(self,m=0,d=0,c=\"\",p=\"\",a=0.0): #constructor\n",
+ " self.__month = m\n",
+ " self.__day = d\n",
+ " self.__category = c\n",
+ " self.__payee = p\n",
+ " self.__amount = a\n",
+ " \n",
+ " \n",
+ "def exp_lt(e1,e2): #overloaded less than function\n",
+ " if e1._expense__month == e2._expense__month:\n",
+ " return e1._expense__day < e2._expense__day\n",
+ "\n",
+ "def exp_eq(e1,e2): #overloaded equal function\n",
+ " return e1._expense__month == e2._expense__month and e1._expense__day == e2._expense__day\n",
+ "\n",
+ "def exp_out(exp): #for output\n",
+ " print exp._expense__month,'/',exp._expense__day,'\\t',exp._expense__payee,'\\t',exp._expense__amount,'\\t',exp._expense__category\n",
+ " \n",
+ " \n",
+ " \n",
+ "class compareDates: #---class compareDates---#\n",
+ " \n",
+ " def cmpdat(self,ptrE1,ptrE2): #compare expenses according to dates\n",
+ " return exp_lt(ptrE1,ptrE2)\n",
+ " \n",
+ " \n",
+ " \n",
+ "class compareCategories: #---class compareCategories---#\n",
+ " \n",
+ " def cmpcat(self,ptrE1,ptrE2): #compare expenses according to category\n",
+ " return ptrE1._expense__category < ptrE2._expense__category\n",
+ " \n",
+ " \n",
+ " \n",
+ "class expenseRecord: #---class expenseRecord---#\n",
+ " __vectPtrsExpenses = vector()\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " \n",
+ " while not (self.__vectPtrsExpenses.empty()):\n",
+ " \n",
+ " j = self.__vectPtrsExpenses.begin()\n",
+ " self.__vectPtrsExpenses.erase(self.__vectPtrsExpenses.op1(j)) #delete expense objects, remove ptrs from vector\n",
+ " \n",
+ " def insertExp(self,ptrExp):\n",
+ " self.__vectPtrsExpenses.push_back(ptrExp)\n",
+ " \n",
+ " def display(self):\n",
+ " print \"\\nDate\\tPayee\\t\\tAmount\\tCategory\\n--------------------------------------------\"\n",
+ " \n",
+ " if self.__vectPtrsExpenses.size() == 0:\n",
+ " print \"*****No Expenses*****\"\n",
+ " \n",
+ " else:\n",
+ " self.__vectPtrsExpenses.sort(self.__vectPtrsExpenses.begin(),self.__vectPtrsExpenses.end()) #sort by date\n",
+ " \n",
+ " iter = self.__vectPtrsExpenses.begin()\n",
+ " \n",
+ " while iter != self.__vectPtrsExpenses.end():\n",
+ " exp_out(self.__vectPtrsExpenses.op1(iter))\n",
+ " iter += 1\n",
+ " \n",
+ " def displaySummary(self): #used by annualReport\n",
+ " \n",
+ " totalExpenses = 0.0 #total, all category\n",
+ " \n",
+ " if self.__vectPtrsExpenses.size() == 0:\n",
+ " print \"\\tAll categories\\t0\"\n",
+ " return 0.0\n",
+ " \n",
+ " self.__vectPtrsExpenses.sort(self.__vectPtrsExpenses.begin(),self.__vectPtrsExpenses.end()) #sort by category\n",
+ " \n",
+ " #for each category, sum the enries\n",
+ " \n",
+ " iter = self.__vectPtrsExpenses.begin()\n",
+ " tempCat = self.__vectPtrsExpenses.op1(iter)._expense__category\n",
+ " sumCat = 0.0\n",
+ " \n",
+ " while iter != self.__vectPtrsExpenses.end():\n",
+ " \n",
+ " if tempCat == self.__vectPtrsExpenses.op1(iter)._expense__category:\n",
+ " sumCat += self.__vectPtrsExpenses.op1(iter)._expense__amount #same category\n",
+ " \n",
+ " else:\n",
+ " #different category\n",
+ " print '\\t',tempCat,'\\t',sumCat\n",
+ " totalExpenses += sumCat #add previous category\n",
+ " \n",
+ " tempCat = self.__vectPtrsExpenses.op1(iter)._expense__category\n",
+ " sumCat = self.__vectPtrsExpenses.op1(iter)._expense__amount #add final amount\n",
+ " \n",
+ " iter += 1\n",
+ " \n",
+ " totalExpenses += sumCat #add fianl category\n",
+ " print '\\t',tempCat,'\\t',sumCat\n",
+ " \n",
+ " return totalExpenses\n",
+ " \n",
+ "\n",
+ "class expenseInputScreen: #---class expenseInputScreen---#\n",
+ " __ptrExpenseRecord = expenseRecord()\n",
+ " \n",
+ " def __init__(self,per=None): #constructor\n",
+ " self.__ptrExpenseRecord = per\n",
+ " \n",
+ " \n",
+ " def getExpense(self):\n",
+ " \n",
+ " month = input(\"Enter month (1-12): \")\n",
+ " day = input(\"Enter day (1-31): \")\n",
+ " \n",
+ " category = \"\"\n",
+ " print \"Enter expense category (Repairing, Utilities): \",\n",
+ " category = getaLine(category)\n",
+ " \n",
+ " payee = \"\"\n",
+ " print \"Enter payee (Bob's Hardware, Big Electric Co): \",\n",
+ " payee = getaLine(payee)\n",
+ " \n",
+ " amount = input(\"Enter amount (39.95): \")\n",
+ " \n",
+ " ptrExpense = expense(month,day,category,payee,amount)\n",
+ " \n",
+ " self.__ptrExpenseRecord.insertExp(ptrExpense)\n",
+ " \n",
+ " \n",
+ " \n",
+ "class annualReport: #---class annualReport---#\n",
+ " \n",
+ " __ptrRR = rentRecord()\n",
+ " __ptrER = expenseRecord()\n",
+ " \n",
+ " def __init__(self,pRR=None,pER=None): #constructor\n",
+ " self.__ptrRR = pRR\n",
+ " self.__ptrER = pER\n",
+ " self.__expenses = 0.0\n",
+ " self.__rents = 0.0\n",
+ " \n",
+ " def display(self): #display annual report\n",
+ " print \"Annual Summary\\n-----------------------------\\nIncome\\n\\tRent\\t\\t\",\n",
+ " self.__rents = self.__ptrRR.getSumOfRents()\n",
+ " print self.__rents\n",
+ " print \"Expenses\"\n",
+ " self.__expenses = self.__ptrER.displaySummary()\n",
+ " print \"\\nbalance\\t\\t\\t\",self.__rents-self.__expenses\n",
+ " \n",
+ " \n",
+ "class userInterface: #---class userInterface---#\n",
+ " \n",
+ " __ptrTenantList = tenantList()\n",
+ " __ptrTenantInputScreen = tenantInputScreen()\n",
+ " __ptrRentRecord = rentRecord()\n",
+ " __ptrrentInputScreen = rentInputScreen()\n",
+ " __ptrExpenseRecord = expenseRecord()\n",
+ " __ptrExpenseInputScreen = expenseInputScreen()\n",
+ " __ptrAnnualReport = annualReport()\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " \n",
+ " #three reports exist for the life of the program\n",
+ " self.__ptrTenantList = tenantList()\n",
+ " self.__ptrRentRecord = rentRecord()\n",
+ " self.__ptrExpenseRecord = expenseRecord()\n",
+ " \n",
+ " def __del__(self): #destructor\n",
+ " del self.__ptrTenantList\n",
+ " del self.__ptrRentRecord\n",
+ " del self.__ptrExpenseRecord\n",
+ " \n",
+ " \n",
+ " \n",
+ " def interact(self):\n",
+ " \n",
+ " while True:\n",
+ " \n",
+ " print \"\\nEnter 'i' to input data, \"\n",
+ " print \" 'd' to display a report,\"\n",
+ " print \" 'q' to quit program: \",\n",
+ " \n",
+ " ch = getaChar()\n",
+ " \n",
+ " if ch=='i': #enter data\n",
+ " \n",
+ " print \"Enter 't' to add tenant,\"\n",
+ " print \" 'r' to record rent payment\"\n",
+ " print \" 'e' to record expense: \",\n",
+ " \n",
+ " ch = getaChar()\n",
+ " print '\\n'\n",
+ " \n",
+ " if ch=='t':\n",
+ " self.__ptrTenantInputScreen = tenantInputScreen(self.__ptrTenantList)\n",
+ " self.__ptrTenantInputScreen.getTenant()\n",
+ " \n",
+ " elif ch=='r':\n",
+ " self.__ptrRentInputScreen = rentInputScreen(self.__ptrTenantList,self.__ptrRentRecord)\n",
+ " self.__ptrRentInputScreen.getRent()\n",
+ " \n",
+ " elif ch=='e':\n",
+ " self.__ptrExpenseInputScreen = expenseInputScreen(self.__ptrExpenseRecord)\n",
+ " self.__ptrExpenseInputScreen.getExpense()\n",
+ " \n",
+ " else:\n",
+ " print \"Unknown input option\"\n",
+ " \n",
+ " \n",
+ " elif ch=='d': #display data\n",
+ " \n",
+ " print \"Enter 't' to display tenants,\"\n",
+ " print \" 'r' to display rents\"\n",
+ " print \" 'e' to display expense,\"\n",
+ " print \" 'a' to display annual report: \",\n",
+ " \n",
+ " ch = getaChar()\n",
+ " print '\\n'\n",
+ " \n",
+ " if ch=='t':\n",
+ " self.__ptrTenantList.display()\n",
+ " \n",
+ " elif ch=='r':\n",
+ " self.__ptrRentRecord.display()\n",
+ " \n",
+ " elif ch=='e':\n",
+ " self.__ptrExpenseRecord.display()\n",
+ " \n",
+ " elif ch=='a':\n",
+ " self.__ptrAnnualReport = annualReport(self.__ptrRentRecord,self.__ptrExpenseRecord)\n",
+ " self.__ptrAnnualReport.display()\n",
+ " del self.__ptrAnnualReport\n",
+ " \n",
+ " else:\n",
+ " print \"Unknown display option\"\n",
+ " \n",
+ " \n",
+ " elif ch=='q':\n",
+ " break #quit\n",
+ " \n",
+ " else:\n",
+ " print \"Unknown option. Enter only 'i', 'd' or 'q'\"\n",
+ " \n",
+ " \n",
+ " \n",
+ "theUserInterface = userInterface()\n",
+ "\n",
+ "theUserInterface.interact()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "t\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter tenant's name (George Smith): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Harry Ellis\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter tenant's apartment number (10): 101\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "t\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter tenant's name (George Smith): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wanda Brown\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter tenant's apartment number (10): 102\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to display tenants,\n",
+ " 'r' to display rents\n",
+ " 'e' to display expense,\n",
+ " 'a' to display annual report: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "t\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "\n",
+ "Apt#\tTenant name\n",
+ "----------------------\n",
+ "101 \tHarry Ellis\n",
+ "102 \tWanda Brown\n",
+ "\n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter tenant's name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Harry Ellis\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount paid (345.67): 695\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month rent is for(1-12): 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter tenant's name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Harry Ellis\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount paid (345.67): 695\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month rent is for(1-12): 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter tenant's name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wanda Brown\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount paid (345.67): 595\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month rent is for(1-12): 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wanda Brown\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Unknown option. Enter only 'i', 'd' or 'q'\n",
+ "\n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Enter tenant's name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wanda Brown\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount paid (345.67): 595\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month rent is for(1-12): 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to display tenants,\n",
+ " 'r' to display rents\n",
+ " 'e' to display expense,\n",
+ " 'a' to display annual report: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "\n",
+ "AptNo\tJan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\n",
+ "----------------------------------------------------- ---------------\n",
+ "101 \t695 695 0 0 0 0 0 0 0 0 0 0 \n",
+ "102 \t595 595 0 0 0 0 0 0 0 0 0 0 \n",
+ "\n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month (1-12): 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter day (1-31): 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter expense category (Repairing, Utilities): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mortgage\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter payee (Bob's Hardware, Big Electric Co): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First megaBank\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount (39.95): 5187.30\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month (1-12): 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter day (1-31): 8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter expense category (Repairing, Utilities): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Utilities\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter payee (Bob's Hardware, Big Electric Co): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "City Water\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount (39.95): 963.10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to add tenant,\n",
+ " 'r' to record rent payment\n",
+ " 'e' to record expense: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month (1-12): 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter day (1-31): 9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter expense category (Repairing, Utilities): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Insurance\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter payee (Bob's Hardware, Big Electric Co): "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Steady State\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter amount (39.95): 4840.00\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to display tenants,\n",
+ " 'r' to display rents\n",
+ " 'e' to display expense,\n",
+ " 'a' to display annual report: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "\n",
+ "Date\tPayee\t\tAmount\tCategory\n",
+ "--------------------------------------------\n",
+ "1 / 3 \tFirst megaBank \t5187.3 \tMortgage\n",
+ "1 / 8 \tCity Water \t963.1 \tUtilities\n",
+ "1 / 9 \tSteady State \t4840.0 \tInsurance\n",
+ "\n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter 't' to display tenants,\n",
+ " 'r' to display rents\n",
+ " 'e' to display expense,\n",
+ " 'a' to display annual report: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ "Annual Summary\n",
+ "-----------------------------\n",
+ "Income\n",
+ "\tRent\t\t22.0\n",
+ "Expenses\n",
+ "\tMortgage \t5187.3\n",
+ "\tUtilities \t963.1\n",
+ "\tInsurance \t4840.0\n",
+ "\n",
+ "balance\t\t\t-10968.4\n",
+ "\n",
+ "Enter 'i' to input data, \n",
+ " 'd' to display a report,\n",
+ " 'q' to quit program: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "q\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter2C++ProgrammingBasics.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter2C++ProgrammingBasics.ipynb
new file mode 100755
index 00000000..989f5595
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter2C++ProgrammingBasics.ipynb
@@ -0,0 +1,555 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:0d10ddbed87889d5ebd0a638bd92c45d253d9ae5e7d6cf948e85b7da69aa9365"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2: C++ Programming Basics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1, Page Number: 36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print 'Every age has a language of its own\\n' #print the statement"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Every age has a language of its own\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2, Page Number: 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "var1 = 20 #define var1 and assign value to it\n",
+ "var2 = var1 + 10 #assign value to var2\n",
+ "\n",
+ "print 'var1+10 is', #output text\n",
+ "print var2, '\\n' #output value of var2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "var1+10 is 30 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3, Page Number: 44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "charvar1 = 'A' #define a character type variable\n",
+ "charvar2 = '\\t' #define a character variable as tab\n",
+ "\n",
+ "print charvar1, #display character\n",
+ "print charvar2, #display character\n",
+ "\n",
+ "charvar1 = 'B' #set character variable to character constant\n",
+ "print charvar1, #display character\n",
+ "\n",
+ "print '\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "A \tB \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4, Page Number: 46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ftemp = input(\"Enter temperature in fahrenheit: \") #take temperature in fahrenheit from user\n",
+ "\n",
+ "ctemp = (ftemp-32) * 5 / 9 #calculating temprature in Celsius\n",
+ "\n",
+ "print 'Equivalent in Celsius is:', ctemp, '\\n' #deisplay temprature in Celsius"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter temperature in fahrenheit: 212\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Equivalent in Celsius is: 100 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5, Page Number: 48"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI = 3.14159 #float type variable\n",
+ "\n",
+ "rad = input(\"Enter radius of circle: \") #get radius from user\n",
+ "\n",
+ "area = PI * rad * rad #find area of circle\n",
+ "\n",
+ "print 'Area is',area,'\\n' #display area"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter radius of circle: 0.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area is 0.7853975 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6, Page Number: 52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#define the variables\n",
+ "pop1 = 2425785\n",
+ "pop2 = 47\n",
+ "pop3 = 9761\n",
+ "\n",
+ "print 'LOCATION POP.\\nPortcity',pop1,'\\nHightown',pop2,'\\nLowvilla',pop3,'\\n' #display all variables"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "LOCATION POP.\n",
+ "Portcity 2425785 \n",
+ "Hightown 47 \n",
+ "Lowvilla 9761 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.7, Page Number: 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#define the variables\n",
+ "pop1 = 2425785\n",
+ "pop2 = 47\n",
+ "pop3 = 9761\n",
+ "\n",
+ "print 'LOCATION %12s \\nPortcity %12d \\nHightown %12d \\nLowville %12d \\n' % ('POPULATION', pop1, pop2, pop3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "LOCATION POPULATION \n",
+ "Portcity 2425785 \n",
+ "Hightown 47 \n",
+ "Lowville 9761 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8, Page Number: 55"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "signedVar = c_int(1500000000) #sigened\n",
+ "unsignVar = c_uint(1500000000) #unsigned\n",
+ "\n",
+ "signedVar.value = signedVar.value * 2\n",
+ "signedVar.value = signedVar.value / 3 #calculate exceeds range\n",
+ "\n",
+ "unsignVar.value = (unsignVar.value * 2) / 3 #calculate within range\n",
+ "\n",
+ "print 'signedVar =',signedVar.value #wrong\n",
+ "print 'unsignVar =',unsignVar.value #ok"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "signedVar = -431655766\n",
+ "unsignVar = 1000000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9, Page Number: 56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#define variables\n",
+ "count = 7\n",
+ "avgWeight = 155.5\n",
+ "\n",
+ "totalWeight = count * avgWeight #calculate total weight\n",
+ "\n",
+ "print 'totalWeight =',totalWeight,'\\n' #print total weight"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "totalWeight = 1088.5 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.10, Page Number: 59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "intVar = c_int(1500000000)\n",
+ "\n",
+ "intVar.value = intVar.value * 10\n",
+ "intVar.value = intVar.value/10 #result too large\n",
+ "print 'intVar =',intVar.value,'\\n', #wrong answer\n",
+ "\n",
+ "intVar = 1500000000\n",
+ "\n",
+ "intVar = (intVar * 10) / 10;\n",
+ "print 'intVar =',intVar,'\\n' #right answer"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "intVar = 211509811 \n",
+ "intVar = 1500000000 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.11, Page Number: 61"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print 6%8,'\\n',7%8,'\\n',8%8,'\\n',9%8,'\\n',10%8,'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6 \n",
+ "7 \n",
+ "0 \n",
+ "1 \n",
+ "2 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12, Page Number: 62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ans = 27 #define ans variable\n",
+ "\n",
+ "ans += 10 #same as: ans = ans + 10\n",
+ "print ans,',',\n",
+ "\n",
+ "ans -= 7 #same as: ans = ans - 7\n",
+ "print ans,',',\n",
+ "\n",
+ "ans *= 2 #same as: ans = ans * 2\n",
+ "print ans,',',\n",
+ "\n",
+ "ans /= 3 #same as: ans = ans / 3\n",
+ "print ans,',',\n",
+ "\n",
+ "ans %= 3 #same as: ans = ans % 3\n",
+ "print ans,'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "37 , 30 , 60 , 20 , 2 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.13, Page Number: 64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#The ++ operator is not available in Python\n",
+ "\n",
+ "count = 10\n",
+ "\n",
+ "print 'count =',count\n",
+ "count += 1 #work as prefix\n",
+ "\n",
+ "print 'count =',count\n",
+ "print 'count =',count\n",
+ "print 'count =',count\n",
+ "\n",
+ "count += 1 #work as postfix\n",
+ "print 'count =',count"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "count = 10\n",
+ "count = 11\n",
+ "count = 11\n",
+ "count = 11\n",
+ "count = 12\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.14, Page Number: 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import * #import for srt()\n",
+ "\n",
+ "number = input(\"Enter the number: \") #get the number\n",
+ "\n",
+ "answer = sqrt(number) #find square root\n",
+ "\n",
+ "print 'Square root is',answer,'\\n' #display it"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number: 1000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Square root is 31.6227766017 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter2C++ProgrammingBasics_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter2C++ProgrammingBasics_1.ipynb
new file mode 100755
index 00000000..6cc50427
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter2C++ProgrammingBasics_1.ipynb
@@ -0,0 +1,555 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1254fab848813ca6cca716bf7b773bc5cf7c6d156e453f1de764d3cb9945111f"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2: C++ Programming Basics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1, Page Number: 36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print 'Every age has a language of its own\\n' #print the statement"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Every age has a language of its own\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2, Page Number: 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "var1 = 20 #define var1 and assign value to it\n",
+ "var2 = var1 + 10 #assign value to var2\n",
+ "\n",
+ "print 'var1+10 is', #output text\n",
+ "print var2, '\\n' #output value of var2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "var1+10 is 30 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3, Page Number: 44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "charvar1 = 'A' #define a character type variable\n",
+ "charvar2 = '\\t' #define a character variable as tab\n",
+ "\n",
+ "print charvar1, #display character\n",
+ "print charvar2, #display character\n",
+ "\n",
+ "charvar1 = 'B' #set character variable to character constant\n",
+ "print charvar1, #display character\n",
+ "\n",
+ "print '\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "A \tB \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4, Page Number: 46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ftemp = input(\"Enter temperature in fahrenheit: \") #take temperature in fahrenheit from user\n",
+ "\n",
+ "ctemp = (ftemp-32) * 5 / 9 #calculating temprature in Celsius\n",
+ "\n",
+ "print 'Equivalent in Celsius is:', ctemp, '\\n' #deisplay temprature in Celsius"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter temperature in fahrenheit: 212\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Equivalent in Celsius is: 100 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5, Page Number: 48"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI = 3.14159 #float type variable\n",
+ "\n",
+ "rad = input(\"Enter radius of circle: \") #get radius from user\n",
+ "\n",
+ "area = PI * rad * rad #find area of circle\n",
+ "\n",
+ "print 'Area is',area,'\\n' #display area"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter radius of circle: 0.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area is 0.7853975 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6, Page Number: 52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#define the variables\n",
+ "pop1 = 2425785\n",
+ "pop2 = 47\n",
+ "pop3 = 9761\n",
+ "\n",
+ "print 'LOCATION POP.\\nPortcity',pop1,'\\nHightown',pop2,'\\nLowvilla',pop3,'\\n' #display all variables"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "LOCATION POP.\n",
+ "Portcity 2425785 \n",
+ "Hightown 47 \n",
+ "Lowvilla 9761 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.7, Page Number: 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#define the variables\n",
+ "pop1 = 2425785\n",
+ "pop2 = 47\n",
+ "pop3 = 9761\n",
+ "\n",
+ "print 'LOCATION %12s \\nPortcity %12d \\nHightown %12d \\nLowville %12d \\n' % ('POPULATION', pop1, pop2, pop3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "LOCATION POPULATION \n",
+ "Portcity 2425785 \n",
+ "Hightown 47 \n",
+ "Lowville 9761 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8, Page Number: 55"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import c_int,c_uint\n",
+ "\n",
+ "signedVar = c_int(1500000000) #sigened\n",
+ "unsignVar = c_uint(1500000000) #unsigned\n",
+ "\n",
+ "signedVar.value = signedVar.value * 2\n",
+ "signedVar.value = signedVar.value / 3 #calculate exceeds range\n",
+ "\n",
+ "unsignVar.value = (unsignVar.value * 2) / 3 #calculate within range\n",
+ "\n",
+ "print 'signedVar =',signedVar.value #wrong\n",
+ "print 'unsignVar =',unsignVar.value #ok"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "signedVar = -431655766\n",
+ "unsignVar = 1000000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9, Page Number: 56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#define variables\n",
+ "count = 7\n",
+ "avgWeight = 155.5\n",
+ "\n",
+ "totalWeight = count * avgWeight #calculate total weight\n",
+ "\n",
+ "print 'totalWeight =',totalWeight,'\\n' #print total weight"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "totalWeight = 1088.5 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.10, Page Number: 59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import c_int\n",
+ "\n",
+ "intVar = c_int(1500000000)\n",
+ "\n",
+ "intVar.value = intVar.value * 10\n",
+ "intVar.value = intVar.value/10 #result too large\n",
+ "print 'intVar =',intVar.value,'\\n', #wrong answer\n",
+ "\n",
+ "intVar = 1500000000\n",
+ "\n",
+ "intVar = (intVar * 10) / 10;\n",
+ "print 'intVar =',intVar,'\\n' #right answer"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "intVar = 211509811 \n",
+ "intVar = 1500000000 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.11, Page Number: 61"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print 6%8,'\\n',7%8,'\\n',8%8,'\\n',9%8,'\\n',10%8,'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6 \n",
+ "7 \n",
+ "0 \n",
+ "1 \n",
+ "2 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12, Page Number: 62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ans = 27 #define ans variable\n",
+ "\n",
+ "ans += 10 #same as: ans = ans + 10\n",
+ "print ans,',',\n",
+ "\n",
+ "ans -= 7 #same as: ans = ans - 7\n",
+ "print ans,',',\n",
+ "\n",
+ "ans *= 2 #same as: ans = ans * 2\n",
+ "print ans,',',\n",
+ "\n",
+ "ans /= 3 #same as: ans = ans / 3\n",
+ "print ans,',',\n",
+ "\n",
+ "ans %= 3 #same as: ans = ans % 3\n",
+ "print ans,'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "37 , 30 , 60 , 20 , 2 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.13, Page Number: 64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#The ++ operator is not available in Python\n",
+ "\n",
+ "count = 10\n",
+ "\n",
+ "print 'count =',count\n",
+ "count += 1 #work as prefix\n",
+ "\n",
+ "print 'count =',count\n",
+ "print 'count =',count\n",
+ "print 'count =',count\n",
+ "\n",
+ "count += 1 #work as postfix\n",
+ "print 'count =',count"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "count = 10\n",
+ "count = 11\n",
+ "count = 11\n",
+ "count = 11\n",
+ "count = 12\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.14, Page Number: 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import sqrt #import for srt()\n",
+ "\n",
+ "number = input(\"Enter the number: \") #get the number\n",
+ "\n",
+ "answer = sqrt(number) #find square root\n",
+ "\n",
+ "print 'Square root is',answer,'\\n' #display it"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number: 1000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Square root is 31.6227766017 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter3LoopsandDecisions.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter3LoopsandDecisions.ipynb
new file mode 100755
index 00000000..8b3bac82
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter3LoopsandDecisions.ipynb
@@ -0,0 +1,1544 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:abb4d46ac01e10f7d8b20abc34507fedb6ef862a0261c1c08a15bf0753bd1d1a"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3: Loops and Decisions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1, Page Number: 76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "numb = input(\"Enter a number: \") #get the number\n",
+ "\n",
+ "print 'numb<10 is',int(numb < 10)\n",
+ "print 'numb>10 is',int(numb > 10)\n",
+ "print 'numb==10 is',int(numb == 10),'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "numb<10 is 0\n",
+ "numb>10 is 1\n",
+ "numb==10 is 0 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.2, Page Number: 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for j in range(15): #for loop from 0 to 14\n",
+ " print j*j,'', #displaying the square of j"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3, Page Number: 81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "numb = 1 #define noop variable\n",
+ "\n",
+ "\n",
+ "for numb in range(1,11): #loop from 1 to 10\n",
+ " \n",
+ " print '%4d' %(numb), #display first column\n",
+ " cube = numb*numb*numb #calculate cube\n",
+ " print '%6d' %(cube) #display 2nd column"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 1\n",
+ " 2 8\n",
+ " 3 27\n",
+ " 4 64\n",
+ " 5 125\n",
+ " 6 216\n",
+ " 7 343\n",
+ " 8 512\n",
+ " 9 729\n",
+ " 10 1000\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.4, Page Number: 84"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fact = 1\n",
+ "\n",
+ "numb = input(\"Enter a number: \") #get number\n",
+ "\n",
+ "for j in range(numb,1,-1): #loop from numb to 1 (numb , numb-1 , .... , 2 , 1)\n",
+ " fact *= j #multiply by j\n",
+ "\n",
+ "print 'Factorial is',fact,'\\n' #display the factorial of the number"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Factorial is 3628800 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.5, Page Number: 86"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n = 99 \n",
+ "\n",
+ "while(n!=0): #loop untill n is 0\n",
+ " n = input() #read a number into n\n",
+ "\n",
+ "print #for end line"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "27\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "33\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "144\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.6, Page Number: 88"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "pow = 1 #power variable initially 1\n",
+ "numb = 1 #numb goes from 1 to ???\n",
+ " \n",
+ " \n",
+ "while(pow<10000): #loop untill power <= 4 digits\n",
+ " print '%2d' %(numb), #display number\n",
+ " print '%5d' %(pow) #display 4th power\n",
+ " numb += 1 #get for next power\n",
+ " pow = numb*numb*numb*numb #calculate forth power"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 1\n",
+ " 2 16\n",
+ " 3 81\n",
+ " 4 256\n",
+ " 5 625\n",
+ " 6 1296\n",
+ " 7 2401\n",
+ " 8 4096\n",
+ " 9 6561\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.7, Page Number: 89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "limit = 4294967295 #largest unsigned long \n",
+ "next = 0 #next-to-last term\n",
+ "last = 1 #last term\n",
+ "\n",
+ "\n",
+ "while(next<limit/2): #don't let results get too big\n",
+ " print last,'', #display last term\n",
+ " sum = next + last #add last two terms\n",
+ " next = last #variables move forword in the series\n",
+ " last = sum \n",
+ " \n",
+ "print '\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986 102334155 165580141 267914296 433494437 701408733 1134903170 1836311903 2971215073 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.8, Page Number: 91"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "while True: #start while loop\n",
+ " #find out the quotient and remainder\n",
+ " dividend = input(\"Enter dividend: \")\n",
+ " divisor = input(\"Enter divisor: \")\n",
+ " \n",
+ " print 'Quotient is',dividend / divisor,\n",
+ " print ', Remainder is',dividend % divisor\n",
+ " \n",
+ " ch = raw_input(\"Do another? (y/n): \") #do it again\n",
+ " \n",
+ " if(ch == 'n'): #loop condition\n",
+ " break;"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter dividend: 11\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter divisor: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quotient is 3 , Remainder is 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do another? (y/n): y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter dividend: 222\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter divisor: 17\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quotient is 13 , Remainder is 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do another? (y/n): n\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.9, Page Number: 94"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = input(\"Enter a number: \") #get input\n",
+ "\n",
+ "if(x > 100): #check whether a number is greater than 100 or not\n",
+ " print 'That number is greater than 100 \\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 2000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "That number is greater than 100 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.10, Page Number: 96"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = input(\"Enter a number: \") #get input\n",
+ "\n",
+ "if(x > 100): #check whether a number is greater than 100 or not\n",
+ " print 'That number',x, #print the number\n",
+ " print 'is greater than 100 \\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 12345\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "That number 12345 is greater than 100 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.11, Page Number: 96"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "n = input(\"Enter a number: \") #get input to test\n",
+ "b=0\n",
+ "\n",
+ "for j in range(2,n/2+1,1): #divide by every integer from 2\n",
+ " \n",
+ " if(n%j == 0): #if remainder is 0\n",
+ " print 'It\\'s not prime; divisible by',j #it's divisible by j\n",
+ " b=1\n",
+ " break\n",
+ " \n",
+ "if b==0:\n",
+ " print 'It\\'s prime'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 22231\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "It's not prime; divisible by 11\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.12, Page Number: 98"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = input(\"Enter a number: \") #get input\n",
+ "\n",
+ "if x>100: #if input is greater than 100\n",
+ " print 'That number is greater than 100\\n'\n",
+ " \n",
+ "else: #if input less than or equal to 100\n",
+ " print 'That number is not greater than 100\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "That number is not greater than 100\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.13, Page Number: 100"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "chcount = 0 #counts non-space characters\n",
+ "wdcount = 1 #counts spaces between words\n",
+ "ch = 'a'\n",
+ "\n",
+ "ch = raw_input(\"Enter a phrase: \") #geting the line\n",
+ "\n",
+ "for j in range(len(ch)): #for loop till line ends\n",
+ " if ch[j] == ' ': #if it's a space\n",
+ " wdcount += 1 #count a word\n",
+ " else: #otherwise\n",
+ " chcount += 1 #count a character\n",
+ "\n",
+ "print 'Words =',wdcount,'\\nLetters =',(chcount),'\\n' #display result"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a phrase: For while and do\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Words = 4 \n",
+ "Letters = 13 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.14, Page Number: 101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "chcount = 0 #counts non-space characters\n",
+ "wdcount = 1 #counts spaces between words\n",
+ "ch = 'a'\n",
+ "\n",
+ "ch = raw_input(\"Enter a phrase: \") #geting the line\n",
+ "\n",
+ "for j in range(len(ch)): #for loop till line ends\n",
+ " if ch[j] == ' ': #if it's a space\n",
+ " wdcount += 1 #count a word\n",
+ " else: #otherwise\n",
+ " chcount += 1 #count a character\n",
+ "\n",
+ "print 'Words =',wdcount,'\\nLetters =',(chcount),'\\n' #display result"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a phrase: For while and do\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Words = 4 \n",
+ "Letters = 13 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.15, Page Number: 102"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "dir = 'a'\n",
+ "x = 10\n",
+ "y = 10\n",
+ "\n",
+ "print 'Type Enter to quit'\n",
+ "\n",
+ "while(dir != '\\n'): #untill Enter is typed\n",
+ " \n",
+ " print 'Your location is',x,',',y\n",
+ " dir = raw_input('\\nPress direction key (n, s, e, w): ') #get direction\n",
+ " \n",
+ " if dir == 'n': #go north\n",
+ " y += 1\n",
+ " else:\n",
+ " if dir == 's': #go south\n",
+ " y -= 1\n",
+ " else:\n",
+ " if dir == 'e': #go east\n",
+ " x += 1\n",
+ " else:\n",
+ " if dir == 'w': #go west\n",
+ " x-=1\n",
+ " else:\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type Enter to quit\n",
+ "Your location is 10 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): s\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 10 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 11 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): \n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.16, Page Number: 104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#get three numbers\n",
+ "print 'Enter three number, a, b, c:'\n",
+ "a = input()\n",
+ "b = input()\n",
+ "c = input()\n",
+ "\n",
+ "if a==b: #if a=b\n",
+ " \n",
+ " if b==c: #if b=c i.e. all three numbers are same \n",
+ " print 'a, b, and c are the same\\n'\n",
+ " \n",
+ " else:\n",
+ " print 'b and c are different\\n'\n",
+ " \n",
+ "else: #if a != b\n",
+ " print 'a and b are different\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter three number, a, b, c:\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": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a and b are different\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.17, Page Number: 106"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "dir = 'a'\n",
+ "x = 10\n",
+ "y = 10\n",
+ "\n",
+ "print 'Type Enter to quit'\n",
+ "\n",
+ "while(dir != '\\n'): #untill Enter is typed\n",
+ " \n",
+ " print 'Your location is',x,',',y\n",
+ " dir = raw_input('\\nPress direction key (n, s, e, w): ') #get charcter\n",
+ " \n",
+ " if dir == 'n': #go north\n",
+ " y += 1\n",
+ " elif dir == 's': #go south\n",
+ " y -= 1\n",
+ " elif dir == 'e': #go east\n",
+ " x += 1\n",
+ " elif dir == 'w': #go west\n",
+ " x -= 1\n",
+ " else:\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type Enter to quit\n",
+ "Your location is 10 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): s\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 10 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 11 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): \n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.18, Page Number: 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "speed = input(\"Enter 33, 45, or 78: \") #get value of speed from user\n",
+ "\n",
+ "#selection based on speed\n",
+ "\n",
+ "if speed == 33: #if user entered 33 \n",
+ " print 'LP album\\n'\n",
+ " \n",
+ "elif speed == 45: #if user entered 45\n",
+ " print 'Single selection\\n'\n",
+ " \n",
+ "elif speed == 78: #if user entered 78\n",
+ " print 'Obsolete formate\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 33, 45, or 78: 45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Single selection\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.19, Page Number: 110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "dir = 'a'\n",
+ "x = 10\n",
+ "y = 10\n",
+ "\n",
+ "print 'Type Enter to quit'\n",
+ "\n",
+ "while(dir != '\\n'): #untill Enter is typed\n",
+ " \n",
+ " print 'Your location is',x,',',y\n",
+ " dir = raw_input('\\nPress direction key (n, s, e, w): ') #get charcter\n",
+ " \n",
+ " if dir == 'n': #go north\n",
+ " y += 1\n",
+ " elif dir == 's': #go south\n",
+ " y -= 1\n",
+ " elif dir == 'e': #go east\n",
+ " x += 1\n",
+ " elif dir == 'w': #go west\n",
+ " x -= 1\n",
+ " \n",
+ " elif not dir:\n",
+ " print 'Exiting'\n",
+ " break\n",
+ " \n",
+ " else:\n",
+ " print 'Try again'\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type Enter to quit\n",
+ "Your location is 10 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): s\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 10 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 11 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): a\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Try again\n",
+ "Your location is 11 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): \n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Exiting\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.20, Page Number: 113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for j in range(80): #for every column\n",
+ " ch = '' if j%8 else 'X' #ch is 'x' if column is multiple of 8 and ' ' (space) otherwise\n",
+ " print ch,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X X X X X X X X X X \n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.21, Page Number: 115"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "dir = 'a'\n",
+ "x = 10\n",
+ "y = 10\n",
+ "\n",
+ "print 'Type Enter to quit'\n",
+ "\n",
+ "while(dir != '\\n'): #untill Enter is typed\n",
+ " \n",
+ " print 'Your location is',x,',',y\n",
+ " dir = raw_input('\\nPress direction key (n, s, e, w): ') #get charcter\n",
+ " \n",
+ " #Update coordinates\n",
+ " if dir == 'n': #go north\n",
+ " y -= 1\n",
+ " elif dir == 's': #go south\n",
+ " y += 1\n",
+ " elif dir == 'e': #go east\n",
+ " x += 1\n",
+ " elif dir == 'w': #go west\n",
+ " x -= 1\n",
+ " else:\n",
+ " break\n",
+ " if x == 7 and y == 11: #if x is 7 and y is 11\n",
+ " print 'You found the treasure'\n",
+ " break; #exit from program"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type Enter to quit\n",
+ "Your location is 10 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): w\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 9 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): w\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 8 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): w\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 7 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): s\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You found the treasure\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.22, Page Number: 116"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "dir = 'a'\n",
+ "x = 10\n",
+ "y = 10\n",
+ "\n",
+ "print 'Type Enter to quit'\n",
+ "\n",
+ "while(dir != '\\n'): #untill Enter is typed\n",
+ " \n",
+ " print 'Your location is',x,',',y\n",
+ " \n",
+ " if x < 5 or x > 15: #if x west of 5 and x east 15\n",
+ " print 'Beware: dragons lurk here'\n",
+ " \n",
+ " dir = raw_input('\\nPress direction key (n, s, e, w): ') #get charcter\n",
+ " \n",
+ " #Update coordinates\n",
+ " if dir == 'n': #go north\n",
+ " y -= 1\n",
+ " elif dir == 's': #go south\n",
+ " y += 1\n",
+ " elif dir == 'e': #go east\n",
+ " x += 1\n",
+ " elif dir == 'w': #go west\n",
+ " x -= 1\n",
+ " else:\n",
+ " break\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type Enter to quit\n",
+ "Your location is 10 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 10 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 11 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 12 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 13 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 14 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 15 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 16 , 9\n",
+ "Beware: dragons lurk here\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): \n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.23, Page Number: 121"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "while True:\n",
+ " \n",
+ " dividend = input(\"\\nEnter dividend: \")\n",
+ " divisor = input(\"Enetre divisor\")\n",
+ " \n",
+ " if divisor==0: #if attempt to divide by 0\n",
+ " \n",
+ " print 'Illegal divisor' #display message\n",
+ " continue #go to top of loop\n",
+ " \n",
+ " print 'Quotient is',dividend/divisor \n",
+ " print 'remainder is',dividend%divisor\n",
+ " \n",
+ " ch = raw_input('Do another? (y/n): ')\n",
+ " \n",
+ " if(ch=='n'):\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter dividend: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enetre divisor0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Illegal divisor\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter dividend: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enetre divisor2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quotient is 2\n",
+ "remainder is 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do another? (y/n): n\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter3LoopsandDecisions_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter3LoopsandDecisions_1.ipynb
new file mode 100755
index 00000000..dc44a06a
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter3LoopsandDecisions_1.ipynb
@@ -0,0 +1,1542 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:a0ac5ceb2a0e32e6e0a080a5ce8fe9d7d55f97807522ba2ae1dc98cd6d59d470"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3: Loops and Decisions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1, Page Number: 76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "numb = input(\"Enter a number: \") #get the number\n",
+ "\n",
+ "print 'numb<10 is',int(numb < 10)\n",
+ "print 'numb>10 is',int(numb > 10)\n",
+ "print 'numb==10 is',int(numb == 10),'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "numb<10 is 0\n",
+ "numb>10 is 1\n",
+ "numb==10 is 0 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.2, Page Number: 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for j in range(15): #for loop from 0 to 14\n",
+ " print j*j,'', #displaying the square of j"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3, Page Number: 81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "numb = 1 #define noop variable\n",
+ "\n",
+ "\n",
+ "for numb in range(1,11): #loop from 1 to 10\n",
+ " \n",
+ " print '%4d' %(numb), #display first column\n",
+ " cube = numb*numb*numb #calculate cube\n",
+ " print '%6d' %(cube) #display 2nd column"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 1\n",
+ " 2 8\n",
+ " 3 27\n",
+ " 4 64\n",
+ " 5 125\n",
+ " 6 216\n",
+ " 7 343\n",
+ " 8 512\n",
+ " 9 729\n",
+ " 10 1000\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.4, Page Number: 84"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fact = 1\n",
+ "\n",
+ "numb = input(\"Enter a number: \") #get number\n",
+ "\n",
+ "for j in range(numb,1,-1): #loop from numb to 1 (numb , numb-1 , .... , 2 , 1)\n",
+ " fact *= j #multiply by j\n",
+ "\n",
+ "print 'Factorial is',fact,'\\n' #display the factorial of the number"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Factorial is 3628800 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.5, Page Number: 86"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n = 99 \n",
+ "\n",
+ "while(n!=0): #loop untill n is 0\n",
+ " n = input() #read a number into n\n",
+ "\n",
+ "print #for end line"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "27\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "33\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "144\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.6, Page Number: 88"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "pow = 1 #power variable initially 1\n",
+ "numb = 1 #numb goes from 1 to ???\n",
+ " \n",
+ " \n",
+ "while(pow<10000): #loop untill power <= 4 digits\n",
+ " print '%2d' %(numb), #display number\n",
+ " print '%5d' %(pow) #display 4th power\n",
+ " numb += 1 #get for next power\n",
+ " pow = numb*numb*numb*numb #calculate forth power"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 1\n",
+ " 2 16\n",
+ " 3 81\n",
+ " 4 256\n",
+ " 5 625\n",
+ " 6 1296\n",
+ " 7 2401\n",
+ " 8 4096\n",
+ " 9 6561\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.7, Page Number: 89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "limit = 4294967295 #largest unsigned long \n",
+ "next = 0 #next-to-last term\n",
+ "last = 1 #last term\n",
+ "\n",
+ "\n",
+ "while(next<limit/2): #don't let results get too big\n",
+ " print last,'', #display last term\n",
+ " sum = next + last #add last two terms\n",
+ " next = last #variables move forword in the series\n",
+ " last = sum \n",
+ " \n",
+ "print '\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986 102334155 165580141 267914296 433494437 701408733 1134903170 1836311903 2971215073 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.8, Page Number: 91"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "while True: #start while loop\n",
+ " #find out the quotient and remainder\n",
+ " dividend = input(\"Enter dividend: \")\n",
+ " divisor = input(\"Enter divisor: \")\n",
+ " \n",
+ " print 'Quotient is',dividend / divisor,\n",
+ " print ', Remainder is',dividend % divisor\n",
+ " \n",
+ " ch = raw_input(\"Do another? (y/n): \") #do it again\n",
+ " \n",
+ " if(ch == 'n'): #loop condition\n",
+ " break;"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter dividend: 11\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter divisor: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quotient is 3 , Remainder is 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do another? (y/n): y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter dividend: 222\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter divisor: 17\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quotient is 13 , Remainder is 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do another? (y/n): n\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.9, Page Number: 94"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = input(\"Enter a number: \") #get input\n",
+ "\n",
+ "if(x > 100): #check whether a number is greater than 100 or not\n",
+ " print 'That number is greater than 100 \\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 2000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "That number is greater than 100 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.10, Page Number: 96"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = input(\"Enter a number: \") #get input\n",
+ "\n",
+ "if(x > 100): #check whether a number is greater than 100 or not\n",
+ " print 'That number',x, #print the number\n",
+ " print 'is greater than 100 \\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 12345\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "That number 12345 is greater than 100 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.11, Page Number: 96"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n = input(\"Enter a number: \") #get input to test\n",
+ "b=0\n",
+ "\n",
+ "for j in range(2,n/2+1,1): #divide by every integer from 2\n",
+ " \n",
+ " if(n%j == 0): #if remainder is 0\n",
+ " print 'It\\'s not prime; divisible by',j #it's divisible by j\n",
+ " b=1\n",
+ " break\n",
+ " \n",
+ "if b==0:\n",
+ " print 'It\\'s prime'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 22231\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "It's not prime; divisible by 11\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.12, Page Number: 98"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = input(\"Enter a number: \") #get input\n",
+ "\n",
+ "if x>100: #if input is greater than 100\n",
+ " print 'That number is greater than 100\\n'\n",
+ " \n",
+ "else: #if input less than or equal to 100\n",
+ " print 'That number is not greater than 100\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "That number is not greater than 100\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.13, Page Number: 100"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "chcount = 0 #counts non-space characters\n",
+ "wdcount = 1 #counts spaces between words\n",
+ "ch = 'a'\n",
+ "\n",
+ "ch = raw_input(\"Enter a phrase: \") #geting the line\n",
+ "\n",
+ "for j in range(len(ch)): #for loop till line ends\n",
+ " if ch[j] == ' ': #if it's a space\n",
+ " wdcount += 1 #count a word\n",
+ " else: #otherwise\n",
+ " chcount += 1 #count a character\n",
+ "\n",
+ "print 'Words =',wdcount,'\\nLetters =',(chcount),'\\n' #display result"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a phrase: For while and do\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Words = 4 \n",
+ "Letters = 13 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.14, Page Number: 101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "chcount = 0 #counts non-space characters\n",
+ "wdcount = 1 #counts spaces between words\n",
+ "ch = 'a'\n",
+ "\n",
+ "ch = raw_input(\"Enter a phrase: \") #geting the line\n",
+ "\n",
+ "for j in range(len(ch)): #for loop till line ends\n",
+ " if ch[j] == ' ': #if it's a space\n",
+ " wdcount += 1 #count a word\n",
+ " else: #otherwise\n",
+ " chcount += 1 #count a character\n",
+ "\n",
+ "print 'Words =',wdcount,'\\nLetters =',(chcount),'\\n' #display result"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a phrase: For while and do\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Words = 4 \n",
+ "Letters = 13 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.15, Page Number: 102"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "dir = 'a'\n",
+ "x = 10\n",
+ "y = 10\n",
+ "\n",
+ "print 'Type Enter to quit'\n",
+ "\n",
+ "while(dir != '\\n'): #untill Enter is typed\n",
+ " \n",
+ " print 'Your location is',x,',',y\n",
+ " dir = raw_input('\\nPress direction key (n, s, e, w): ') #get direction\n",
+ " \n",
+ " if dir == 'n': #go north\n",
+ " y += 1\n",
+ " else:\n",
+ " if dir == 's': #go south\n",
+ " y -= 1\n",
+ " else:\n",
+ " if dir == 'e': #go east\n",
+ " x += 1\n",
+ " else:\n",
+ " if dir == 'w': #go west\n",
+ " x-=1\n",
+ " else:\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type Enter to quit\n",
+ "Your location is 10 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): s\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 10 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 11 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): \n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.16, Page Number: 104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#get three numbers\n",
+ "print 'Enter three number, a, b, c:'\n",
+ "a = input()\n",
+ "b = input()\n",
+ "c = input()\n",
+ "\n",
+ "if a==b: #if a=b\n",
+ " \n",
+ " if b==c: #if b=c i.e. all three numbers are same \n",
+ " print 'a, b, and c are the same\\n'\n",
+ " \n",
+ " else:\n",
+ " print 'b and c are different\\n'\n",
+ " \n",
+ "else: #if a != b\n",
+ " print 'a and b are different\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter three number, a, b, c:\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": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a and b are different\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.17, Page Number: 106"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "dir = 'a'\n",
+ "x = 10\n",
+ "y = 10\n",
+ "\n",
+ "print 'Type Enter to quit'\n",
+ "\n",
+ "while(dir != '\\n'): #untill Enter is typed\n",
+ " \n",
+ " print 'Your location is',x,',',y\n",
+ " dir = raw_input('\\nPress direction key (n, s, e, w): ') #get charcter\n",
+ " \n",
+ " if dir == 'n': #go north\n",
+ " y += 1\n",
+ " elif dir == 's': #go south\n",
+ " y -= 1\n",
+ " elif dir == 'e': #go east\n",
+ " x += 1\n",
+ " elif dir == 'w': #go west\n",
+ " x -= 1\n",
+ " else:\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type Enter to quit\n",
+ "Your location is 10 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): s\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 10 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 11 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): \n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.18, Page Number: 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "speed = input(\"Enter 33, 45, or 78: \") #get value of speed from user\n",
+ "\n",
+ "#selection based on speed\n",
+ "\n",
+ "if speed == 33: #if user entered 33 \n",
+ " print 'LP album\\n'\n",
+ " \n",
+ "elif speed == 45: #if user entered 45\n",
+ " print 'Single selection\\n'\n",
+ " \n",
+ "elif speed == 78: #if user entered 78\n",
+ " print 'Obsolete formate\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter 33, 45, or 78: 45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Single selection\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.19, Page Number: 110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "dir = 'a'\n",
+ "x = 10\n",
+ "y = 10\n",
+ "\n",
+ "print 'Type Enter to quit'\n",
+ "\n",
+ "while(dir != '\\n'): #untill Enter is typed\n",
+ " \n",
+ " print 'Your location is',x,',',y\n",
+ " dir = raw_input('\\nPress direction key (n, s, e, w): ') #get charcter\n",
+ " \n",
+ " if dir == 'n': #go north\n",
+ " y += 1\n",
+ " elif dir == 's': #go south\n",
+ " y -= 1\n",
+ " elif dir == 'e': #go east\n",
+ " x += 1\n",
+ " elif dir == 'w': #go west\n",
+ " x -= 1\n",
+ " \n",
+ " elif not dir:\n",
+ " print 'Exiting'\n",
+ " break\n",
+ " \n",
+ " else:\n",
+ " print 'Try again'\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type Enter to quit\n",
+ "Your location is 10 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): s\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 10 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 11 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): a\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Try again\n",
+ "Your location is 11 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): \n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Exiting\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.20, Page Number: 113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for j in range(80): #for every column\n",
+ " ch = '' if j%8 else 'X' #ch is 'x' if column is multiple of 8 and ' ' (space) otherwise\n",
+ " print ch,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X X X X X X X X X X \n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.21, Page Number: 115"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "dir = 'a'\n",
+ "x = 10\n",
+ "y = 10\n",
+ "\n",
+ "print 'Type Enter to quit'\n",
+ "\n",
+ "while(dir != '\\n'): #untill Enter is typed\n",
+ " \n",
+ " print 'Your location is',x,',',y\n",
+ " dir = raw_input('\\nPress direction key (n, s, e, w): ') #get charcter\n",
+ " \n",
+ " #Update coordinates\n",
+ " if dir == 'n': #go north\n",
+ " y -= 1\n",
+ " elif dir == 's': #go south\n",
+ " y += 1\n",
+ " elif dir == 'e': #go east\n",
+ " x += 1\n",
+ " elif dir == 'w': #go west\n",
+ " x -= 1\n",
+ " else:\n",
+ " break\n",
+ " if x == 7 and y == 11: #if x is 7 and y is 11\n",
+ " print 'You found the treasure'\n",
+ " break; #exit from program"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type Enter to quit\n",
+ "Your location is 10 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): w\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 9 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): w\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 8 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): w\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 7 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): s\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You found the treasure\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.22, Page Number: 116"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "dir = 'a'\n",
+ "x = 10\n",
+ "y = 10\n",
+ "\n",
+ "print 'Type Enter to quit'\n",
+ "\n",
+ "while(dir != '\\n'): #untill Enter is typed\n",
+ " \n",
+ " print 'Your location is',x,',',y\n",
+ " \n",
+ " if x < 5 or x > 15: #if x west of 5 and x east 15\n",
+ " print 'Beware: dragons lurk here'\n",
+ " \n",
+ " dir = raw_input('\\nPress direction key (n, s, e, w): ') #get charcter\n",
+ " \n",
+ " #Update coordinates\n",
+ " if dir == 'n': #go north\n",
+ " y -= 1\n",
+ " elif dir == 's': #go south\n",
+ " y += 1\n",
+ " elif dir == 'e': #go east\n",
+ " x += 1\n",
+ " elif dir == 'w': #go west\n",
+ " x -= 1\n",
+ " else:\n",
+ " break\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type Enter to quit\n",
+ "Your location is 10 , 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 10 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 11 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 12 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 13 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 14 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 15 , 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your location is 16 , 9\n",
+ "Beware: dragons lurk here\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press direction key (n, s, e, w): \n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.23, Page Number: 121"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "while True:\n",
+ " \n",
+ " dividend = input(\"\\nEnter dividend: \")\n",
+ " divisor = input(\"Enetre divisor\")\n",
+ " \n",
+ " if divisor==0: #if attempt to divide by 0\n",
+ " \n",
+ " print 'Illegal divisor' #display message\n",
+ " continue #go to top of loop\n",
+ " \n",
+ " print 'Quotient is',dividend/divisor \n",
+ " print 'remainder is',dividend%divisor\n",
+ " \n",
+ " ch = raw_input('Do another? (y/n): ')\n",
+ " \n",
+ " if(ch=='n'):\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter dividend: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enetre divisor0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Illegal divisor\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter dividend: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enetre divisor2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quotient is 2\n",
+ "remainder is 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do another? (y/n): n\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter4Structures.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter4Structures.ipynb
new file mode 100755
index 00000000..e0ae17f7
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter4Structures.ipynb
@@ -0,0 +1,598 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4064e4393addeb287dc28b053f240cb52dee01e0413e7dfb8579fc8b2d7511ad"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: Structures"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1, Page Number: 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class part: #declare a structure\n",
+ " modelnumber = None #ID number of widget\n",
+ " partnumber = None #ID number of widget part\n",
+ " cost = None #cost of part\n",
+ "\n",
+ "part1 = part() #define a strcture variable\n",
+ "\n",
+ "part1.modelnumber = 6244 #give values to structue member\n",
+ "part1.partnumber = 373\n",
+ "part1.cost = 217.55\n",
+ "\n",
+ " #display structure member\n",
+ "print 'Model %d,' %part1.modelnumber,\n",
+ "print 'part %d,' %part1.partnumber,\n",
+ "print 'costs $%.2f' %part1.cost,'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Model 6244, part 373, costs $217.55 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2, Page Number: 138"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class part: #declare a structure\n",
+ " modelnumber = None #ID number of widget\n",
+ " partnumber = None #ID number of widget part\n",
+ " cost = None #cost of part\n",
+ "\n",
+ "part1 = part()\n",
+ " #initialize structure variable\n",
+ "part1.modelnumber = 6244\n",
+ "part1.partnumber = 373\n",
+ "part1.cost = 217.55\n",
+ "\n",
+ " #display first variable\n",
+ "print 'Model %d,' %part1.modelnumber,\n",
+ "print 'part %d,' %part1.partnumber,\n",
+ "print 'costs $%.2f' %part1.cost,'\\n',\n",
+ "\n",
+ "part2 = part1 #assign first variable to second\n",
+ "\n",
+ " #display second variable\n",
+ "print 'Model %d,' %part2.modelnumber,\n",
+ "print 'part %d,' %part2.partnumber,\n",
+ "print 'costs $%.2f' %part2.cost,'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Model 6244, part 373, costs $217.55 \n",
+ "Model 6244, part 373, costs $217.55 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3, Page Number: 139"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance structure\n",
+ " feet = None\n",
+ " inches = None\n",
+ "\n",
+ "d1 = Distance() #define three length\n",
+ "d3 = Distance()\n",
+ "d2 = Distance()\n",
+ "\n",
+ "d2.feet = 11 #initialize second length\n",
+ "d2.inches = 6.25\n",
+ "\n",
+ " #get lenght d1 from user\n",
+ "d1.feet = input(\"Enter feet: \")\n",
+ "d1.inches = input(\"Enter inches: \")\n",
+ "\n",
+ " #add length d1 and d2 to get d3\n",
+ "d3.inches = d1.inches + d2.inches #add the inches\n",
+ "\n",
+ "\n",
+ "d3.feet = 0 #initially feet is zero\n",
+ "\n",
+ "if d3.inches>=12.0: #if total exceeds 12.0\n",
+ " d3.inches -= 12.0 #then decrease inches by 12.0\n",
+ " d3.feet += 1 #and increase feet by 1\n",
+ "\n",
+ "d3.feet += d1.feet + d2.feet #add the feet\n",
+ "\n",
+ " #display all length\n",
+ "print d1.feet,'\\' -',d1.inches,'\\\" +',\n",
+ "print d2.feet,'\\' -',d2.inches,'\\\" =',\n",
+ "print d3.feet,'\\' -',d3.inches,'\\\" \\n',"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 6.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 ' - 6.75 \" + 11 ' - 6.25 \" = 22 ' - 1.0 \" \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4, Page Number: 141"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #distance structure\n",
+ " feet = None\n",
+ " inches = None\n",
+ "\n",
+ "class Room: #rectangular area\n",
+ " length = Distance() #length of rectangle\n",
+ " width = Distance() #width of rectangle\n",
+ " \n",
+ "dining = Room() #define a room\n",
+ "\n",
+ "dining.length.feet = 13 #assign values \n",
+ "dining.length.inches = 6.5\n",
+ "dining.width.feet = 10\n",
+ "dining.width.inches = 0.0\n",
+ "\n",
+ " #convet length and width\n",
+ "l = dining.length.feet + dining.length.inches/12\n",
+ "w = dining.width.feet + dining.width.inches/12\n",
+ "\n",
+ " #find area and display it\n",
+ "print 'Dining room area is',l*w,'square feet\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dining room area is 135.416666667 square feet\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.5, Page Number: 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "clubs = 0 #suits\n",
+ "diamonds = 1\n",
+ "hearts = 2\n",
+ "spades = 3\n",
+ "\n",
+ "#from 2 to 10 are integers without names\n",
+ "jack = 11 #face cards\n",
+ "queen = 12 \n",
+ "king = 13\n",
+ "ace = 14\n",
+ "\n",
+ "\n",
+ "class card:\n",
+ " number = None #2 to 10, jack, queen, king, ace\n",
+ " suit = None #clubs, diamonds, hearts, spades\n",
+ " \n",
+ "\n",
+ "#define various cards\n",
+ "temp = card()\n",
+ "chosen = card()\n",
+ "prize = card()\n",
+ "\n",
+ "\n",
+ "#define and initialize card1\n",
+ "card1 = card()\n",
+ "card1.number = 7\n",
+ "card1.suit = clubs\n",
+ "print 'card 1 is the 7 of clubs'\n",
+ "\n",
+ "\n",
+ "#define and initialize card2\n",
+ "card2 = card()\n",
+ "card2.number = jack\n",
+ "card2.suit = hearts\n",
+ "print 'card 2 is the jack of hearts'\n",
+ "\n",
+ "#define and initialize card3\n",
+ "card3 = card()\n",
+ "card3.number = ace\n",
+ "card3.suit = spades\n",
+ "print 'card 3 is the ace of spades'\n",
+ "\n",
+ "\n",
+ "#prize is the card to guess\n",
+ "prize = card3 #copy this card, to remember it\n",
+ "\n",
+ "\n",
+ "#swapping cards\n",
+ "print 'I\\'m swapping card 1 and card 3'\n",
+ "temp = card3\n",
+ "card3 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 2 and card 3'\n",
+ "temp = card2\n",
+ "card3 = card2\n",
+ "card2 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 1 and card 2'\n",
+ "temp = card2\n",
+ "card2 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "\n",
+ "print 'Now, where (1,2, or 3) is the ace of spades? ',\n",
+ "\n",
+ "position = input() #get user's guess of position\n",
+ "\n",
+ "\n",
+ "#set chosen to user's choice \n",
+ "if position == 1:\n",
+ " chosen = card1\n",
+ "elif position == 2:\n",
+ " chosen = card2\n",
+ "else:\n",
+ " chosen = card3\n",
+ " \n",
+ " \n",
+ "if chosen.number == prize.number and chosen.suit == prize.suit: #compare cards\n",
+ " print 'That\\'s right! You win!'\n",
+ "else:\n",
+ " print 'Sorry. You lose.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "card 1 is the 7 of clubs\n",
+ "card 2 is the jack of hearts\n",
+ "card 3 is the ace of spades\n",
+ "I'm swapping card 1 and card 3\n",
+ "I'm swapping card 2 and card 3\n",
+ "I'm swapping card 1 and card 2\n",
+ "Now, where (1,2, or 3) is the ace of spades? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Sorry. You lose.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6, Page Number: 148"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": true,
+ "input": [
+ "(Sun,Mon,Tue,Wed,Thu,Fri,Sat) = (0,1,2,3,4,5,6) #specify enum type\n",
+ "\n",
+ "day1 = Mon #define variables and assign values\n",
+ "day2 = Thu\n",
+ "\n",
+ "diff = day2 - day1 #can do integer arithmetic\n",
+ "print 'Days between =',diff\n",
+ "\n",
+ "if day1<day2: #can do comprisons\n",
+ " print 'day1 comes before day2\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Days between = 3\n",
+ "day1 comes before day2\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7, Page Number: 152"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "(NO , YES) = (0,1) #N0 = 0, YES = 1\n",
+ "\n",
+ "isWord = NO #YES when in a word, NO when in whitespace\n",
+ "ch = 'a' #character read from keyboard\n",
+ "wordcount = 1 #counts spaces between words\n",
+ "\n",
+ "print 'Enter a phrase'\n",
+ "ch = raw_input() #geting the line\n",
+ "\n",
+ "for j in range(len(ch)): #for loop till line ends\n",
+ " \n",
+ " if ch[j] == ' ': #if it's a space,\n",
+ " if isWord == YES: #and going word, then it's end of word\n",
+ " wordcount += 1 #count a word\n",
+ " isWord == NO #reset flag\n",
+ " \n",
+ " else: #otherwise\n",
+ " if isWord == NO: \n",
+ " isWord = YES #set flag\n",
+ "\n",
+ "print '--- Word count is',wordcount,'---' #display result"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a phrase\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For While and do\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "--- Word count is 4 ---\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8, Page Number: 153"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#from 2 to 10 are integers without names\n",
+ "jack = 11 \n",
+ "queen = 12 \n",
+ "king = 13\n",
+ "ace = 14\n",
+ "\n",
+ "(clubs,diamonds,hearts,spades) = (0,1,2,3)\n",
+ "\n",
+ "class card:\n",
+ " number = None #2 to 10, jack, queen, king, ace\n",
+ " suit = None #clubs, diamonds, hearts, spades\n",
+ " \n",
+ "\n",
+ "#define various cards\n",
+ "temp = card()\n",
+ "chosen = card()\n",
+ "prize = card()\n",
+ "\n",
+ "\n",
+ "#define and initialize card1\n",
+ "card1 = card()\n",
+ "card1.number = 7\n",
+ "card1.suit = clubs\n",
+ "print 'card 1 is the 7 of clubs'\n",
+ "\n",
+ "\n",
+ "#define and initialize card2\n",
+ "card2 = card()\n",
+ "card2.number = jack\n",
+ "card2.suit = hearts\n",
+ "print 'card 2 is the jack of hearts'\n",
+ "\n",
+ "#define and initialize card3\n",
+ "card3 = card()\n",
+ "card3.number = ace\n",
+ "card3.suit = spades\n",
+ "print 'card 3 is the ace of spades'\n",
+ "\n",
+ "\n",
+ "#prize is the card to guess\n",
+ "prize = card3\n",
+ "\n",
+ "\n",
+ "#swapping cards\n",
+ "print 'I\\'m swapping card 1 and card 3'\n",
+ "temp = card3\n",
+ "card3 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 2 and card 3'\n",
+ "temp = card2\n",
+ "card3 = card2\n",
+ "card2 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 1 and card 2'\n",
+ "temp = card2\n",
+ "card2 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "\n",
+ "print 'Now, where (1,2, or 3) is the ace of spades? ',\n",
+ "\n",
+ "position = input() #get user's guess of position\n",
+ "\n",
+ "\n",
+ "#set chosen to user's choice \n",
+ "if position == 1:\n",
+ " chosen = card1\n",
+ "elif position == 2:\n",
+ " chosen = card2\n",
+ "else:\n",
+ " chosen = card3\n",
+ " \n",
+ " #compare cards\n",
+ "if chosen.number == prize.number and chosen.suit == prize.suit:\n",
+ " print 'That\\'s right! You win!'\n",
+ "else:\n",
+ " print 'Sorry. You lose.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "card 1 is the 7 of clubs\n",
+ "card 2 is the jack of hearts\n",
+ "card 3 is the ace of spades\n",
+ "I'm swapping card 1 and card 3\n",
+ "I'm swapping card 2 and card 3\n",
+ "I'm swapping card 1 and card 2\n",
+ "Now, where (1,2, or 3) is the ace of spades? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " That's right! You win!\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter4Structures_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter4Structures_1.ipynb
new file mode 100755
index 00000000..e0ae17f7
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter4Structures_1.ipynb
@@ -0,0 +1,598 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4064e4393addeb287dc28b053f240cb52dee01e0413e7dfb8579fc8b2d7511ad"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: Structures"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1, Page Number: 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class part: #declare a structure\n",
+ " modelnumber = None #ID number of widget\n",
+ " partnumber = None #ID number of widget part\n",
+ " cost = None #cost of part\n",
+ "\n",
+ "part1 = part() #define a strcture variable\n",
+ "\n",
+ "part1.modelnumber = 6244 #give values to structue member\n",
+ "part1.partnumber = 373\n",
+ "part1.cost = 217.55\n",
+ "\n",
+ " #display structure member\n",
+ "print 'Model %d,' %part1.modelnumber,\n",
+ "print 'part %d,' %part1.partnumber,\n",
+ "print 'costs $%.2f' %part1.cost,'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Model 6244, part 373, costs $217.55 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2, Page Number: 138"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class part: #declare a structure\n",
+ " modelnumber = None #ID number of widget\n",
+ " partnumber = None #ID number of widget part\n",
+ " cost = None #cost of part\n",
+ "\n",
+ "part1 = part()\n",
+ " #initialize structure variable\n",
+ "part1.modelnumber = 6244\n",
+ "part1.partnumber = 373\n",
+ "part1.cost = 217.55\n",
+ "\n",
+ " #display first variable\n",
+ "print 'Model %d,' %part1.modelnumber,\n",
+ "print 'part %d,' %part1.partnumber,\n",
+ "print 'costs $%.2f' %part1.cost,'\\n',\n",
+ "\n",
+ "part2 = part1 #assign first variable to second\n",
+ "\n",
+ " #display second variable\n",
+ "print 'Model %d,' %part2.modelnumber,\n",
+ "print 'part %d,' %part2.partnumber,\n",
+ "print 'costs $%.2f' %part2.cost,'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Model 6244, part 373, costs $217.55 \n",
+ "Model 6244, part 373, costs $217.55 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3, Page Number: 139"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance structure\n",
+ " feet = None\n",
+ " inches = None\n",
+ "\n",
+ "d1 = Distance() #define three length\n",
+ "d3 = Distance()\n",
+ "d2 = Distance()\n",
+ "\n",
+ "d2.feet = 11 #initialize second length\n",
+ "d2.inches = 6.25\n",
+ "\n",
+ " #get lenght d1 from user\n",
+ "d1.feet = input(\"Enter feet: \")\n",
+ "d1.inches = input(\"Enter inches: \")\n",
+ "\n",
+ " #add length d1 and d2 to get d3\n",
+ "d3.inches = d1.inches + d2.inches #add the inches\n",
+ "\n",
+ "\n",
+ "d3.feet = 0 #initially feet is zero\n",
+ "\n",
+ "if d3.inches>=12.0: #if total exceeds 12.0\n",
+ " d3.inches -= 12.0 #then decrease inches by 12.0\n",
+ " d3.feet += 1 #and increase feet by 1\n",
+ "\n",
+ "d3.feet += d1.feet + d2.feet #add the feet\n",
+ "\n",
+ " #display all length\n",
+ "print d1.feet,'\\' -',d1.inches,'\\\" +',\n",
+ "print d2.feet,'\\' -',d2.inches,'\\\" =',\n",
+ "print d3.feet,'\\' -',d3.inches,'\\\" \\n',"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 6.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 ' - 6.75 \" + 11 ' - 6.25 \" = 22 ' - 1.0 \" \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4, Page Number: 141"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #distance structure\n",
+ " feet = None\n",
+ " inches = None\n",
+ "\n",
+ "class Room: #rectangular area\n",
+ " length = Distance() #length of rectangle\n",
+ " width = Distance() #width of rectangle\n",
+ " \n",
+ "dining = Room() #define a room\n",
+ "\n",
+ "dining.length.feet = 13 #assign values \n",
+ "dining.length.inches = 6.5\n",
+ "dining.width.feet = 10\n",
+ "dining.width.inches = 0.0\n",
+ "\n",
+ " #convet length and width\n",
+ "l = dining.length.feet + dining.length.inches/12\n",
+ "w = dining.width.feet + dining.width.inches/12\n",
+ "\n",
+ " #find area and display it\n",
+ "print 'Dining room area is',l*w,'square feet\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dining room area is 135.416666667 square feet\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.5, Page Number: 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "clubs = 0 #suits\n",
+ "diamonds = 1\n",
+ "hearts = 2\n",
+ "spades = 3\n",
+ "\n",
+ "#from 2 to 10 are integers without names\n",
+ "jack = 11 #face cards\n",
+ "queen = 12 \n",
+ "king = 13\n",
+ "ace = 14\n",
+ "\n",
+ "\n",
+ "class card:\n",
+ " number = None #2 to 10, jack, queen, king, ace\n",
+ " suit = None #clubs, diamonds, hearts, spades\n",
+ " \n",
+ "\n",
+ "#define various cards\n",
+ "temp = card()\n",
+ "chosen = card()\n",
+ "prize = card()\n",
+ "\n",
+ "\n",
+ "#define and initialize card1\n",
+ "card1 = card()\n",
+ "card1.number = 7\n",
+ "card1.suit = clubs\n",
+ "print 'card 1 is the 7 of clubs'\n",
+ "\n",
+ "\n",
+ "#define and initialize card2\n",
+ "card2 = card()\n",
+ "card2.number = jack\n",
+ "card2.suit = hearts\n",
+ "print 'card 2 is the jack of hearts'\n",
+ "\n",
+ "#define and initialize card3\n",
+ "card3 = card()\n",
+ "card3.number = ace\n",
+ "card3.suit = spades\n",
+ "print 'card 3 is the ace of spades'\n",
+ "\n",
+ "\n",
+ "#prize is the card to guess\n",
+ "prize = card3 #copy this card, to remember it\n",
+ "\n",
+ "\n",
+ "#swapping cards\n",
+ "print 'I\\'m swapping card 1 and card 3'\n",
+ "temp = card3\n",
+ "card3 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 2 and card 3'\n",
+ "temp = card2\n",
+ "card3 = card2\n",
+ "card2 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 1 and card 2'\n",
+ "temp = card2\n",
+ "card2 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "\n",
+ "print 'Now, where (1,2, or 3) is the ace of spades? ',\n",
+ "\n",
+ "position = input() #get user's guess of position\n",
+ "\n",
+ "\n",
+ "#set chosen to user's choice \n",
+ "if position == 1:\n",
+ " chosen = card1\n",
+ "elif position == 2:\n",
+ " chosen = card2\n",
+ "else:\n",
+ " chosen = card3\n",
+ " \n",
+ " \n",
+ "if chosen.number == prize.number and chosen.suit == prize.suit: #compare cards\n",
+ " print 'That\\'s right! You win!'\n",
+ "else:\n",
+ " print 'Sorry. You lose.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "card 1 is the 7 of clubs\n",
+ "card 2 is the jack of hearts\n",
+ "card 3 is the ace of spades\n",
+ "I'm swapping card 1 and card 3\n",
+ "I'm swapping card 2 and card 3\n",
+ "I'm swapping card 1 and card 2\n",
+ "Now, where (1,2, or 3) is the ace of spades? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Sorry. You lose.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6, Page Number: 148"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": true,
+ "input": [
+ "(Sun,Mon,Tue,Wed,Thu,Fri,Sat) = (0,1,2,3,4,5,6) #specify enum type\n",
+ "\n",
+ "day1 = Mon #define variables and assign values\n",
+ "day2 = Thu\n",
+ "\n",
+ "diff = day2 - day1 #can do integer arithmetic\n",
+ "print 'Days between =',diff\n",
+ "\n",
+ "if day1<day2: #can do comprisons\n",
+ " print 'day1 comes before day2\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Days between = 3\n",
+ "day1 comes before day2\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7, Page Number: 152"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "(NO , YES) = (0,1) #N0 = 0, YES = 1\n",
+ "\n",
+ "isWord = NO #YES when in a word, NO when in whitespace\n",
+ "ch = 'a' #character read from keyboard\n",
+ "wordcount = 1 #counts spaces between words\n",
+ "\n",
+ "print 'Enter a phrase'\n",
+ "ch = raw_input() #geting the line\n",
+ "\n",
+ "for j in range(len(ch)): #for loop till line ends\n",
+ " \n",
+ " if ch[j] == ' ': #if it's a space,\n",
+ " if isWord == YES: #and going word, then it's end of word\n",
+ " wordcount += 1 #count a word\n",
+ " isWord == NO #reset flag\n",
+ " \n",
+ " else: #otherwise\n",
+ " if isWord == NO: \n",
+ " isWord = YES #set flag\n",
+ "\n",
+ "print '--- Word count is',wordcount,'---' #display result"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a phrase\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For While and do\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "--- Word count is 4 ---\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8, Page Number: 153"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#from 2 to 10 are integers without names\n",
+ "jack = 11 \n",
+ "queen = 12 \n",
+ "king = 13\n",
+ "ace = 14\n",
+ "\n",
+ "(clubs,diamonds,hearts,spades) = (0,1,2,3)\n",
+ "\n",
+ "class card:\n",
+ " number = None #2 to 10, jack, queen, king, ace\n",
+ " suit = None #clubs, diamonds, hearts, spades\n",
+ " \n",
+ "\n",
+ "#define various cards\n",
+ "temp = card()\n",
+ "chosen = card()\n",
+ "prize = card()\n",
+ "\n",
+ "\n",
+ "#define and initialize card1\n",
+ "card1 = card()\n",
+ "card1.number = 7\n",
+ "card1.suit = clubs\n",
+ "print 'card 1 is the 7 of clubs'\n",
+ "\n",
+ "\n",
+ "#define and initialize card2\n",
+ "card2 = card()\n",
+ "card2.number = jack\n",
+ "card2.suit = hearts\n",
+ "print 'card 2 is the jack of hearts'\n",
+ "\n",
+ "#define and initialize card3\n",
+ "card3 = card()\n",
+ "card3.number = ace\n",
+ "card3.suit = spades\n",
+ "print 'card 3 is the ace of spades'\n",
+ "\n",
+ "\n",
+ "#prize is the card to guess\n",
+ "prize = card3\n",
+ "\n",
+ "\n",
+ "#swapping cards\n",
+ "print 'I\\'m swapping card 1 and card 3'\n",
+ "temp = card3\n",
+ "card3 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 2 and card 3'\n",
+ "temp = card2\n",
+ "card3 = card2\n",
+ "card2 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 1 and card 2'\n",
+ "temp = card2\n",
+ "card2 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "\n",
+ "print 'Now, where (1,2, or 3) is the ace of spades? ',\n",
+ "\n",
+ "position = input() #get user's guess of position\n",
+ "\n",
+ "\n",
+ "#set chosen to user's choice \n",
+ "if position == 1:\n",
+ " chosen = card1\n",
+ "elif position == 2:\n",
+ " chosen = card2\n",
+ "else:\n",
+ " chosen = card3\n",
+ " \n",
+ " #compare cards\n",
+ "if chosen.number == prize.number and chosen.suit == prize.suit:\n",
+ " print 'That\\'s right! You win!'\n",
+ "else:\n",
+ " print 'Sorry. You lose.'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "card 1 is the 7 of clubs\n",
+ "card 2 is the jack of hearts\n",
+ "card 3 is the ace of spades\n",
+ "I'm swapping card 1 and card 3\n",
+ "I'm swapping card 2 and card 3\n",
+ "I'm swapping card 1 and card 2\n",
+ "Now, where (1,2, or 3) is the ace of spades? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " That's right! You win!\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter5Functions.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter5Functions.ipynb
new file mode 100755
index 00000000..fe2f9caf
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter5Functions.ipynb
@@ -0,0 +1,1207 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:dfe6721ac5865b13382527eb98cf85f121f742b7bca64a3e85e05ff14773232e"
+ },
+ "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 5.1, Page Number: 163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def starline(): #function declarator\n",
+ " for j in range(25): #function body\n",
+ " print '*', \n",
+ " print\n",
+ " \n",
+ " \n",
+ "starline() #call to function\n",
+ "print 'Data type Range'\n",
+ "starline() #call to function\n",
+ "print 'Char -128 to 127'\n",
+ "print 'short -32,768 to 32,767'\n",
+ "print 'int System dependent'\n",
+ "print 'long -2,147,483,648 to 2,147,483,647'\n",
+ "starline() #call to function"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "* * * * * * * * * * * * * * * * * * * * * * * * *\n",
+ "Data type Range\n",
+ "* * * * * * * * * * * * * * * * * * * * * * * * *\n",
+ "Char -128 to 127\n",
+ "short -32,768 to 32,767\n",
+ "int System dependent\n",
+ "long -2,147,483,648 to 2,147,483,647\n",
+ "* * * * * * * * * * * * * * * * * * * * * * * * *\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2, Page Number: 167"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " #function definition\n",
+ "def starline():\n",
+ " for j in range(25):\n",
+ " print '*',\n",
+ " print\n",
+ " \n",
+ " \n",
+ "starline() #call to function\n",
+ "print 'Data type Range'\n",
+ "starline() #call to function\n",
+ "print 'Char -128 to 127'\n",
+ "print 'short -32,768 to 32,767'\n",
+ "print 'int System dependent'\n",
+ "print 'long -2,147,483,648 to 2,147,483,647'\n",
+ "starline() #call to function"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "* * * * * * * * * * * * * * * * * * * * * * * * *\n",
+ "Data type Range\n",
+ "* * * * * * * * * * * * * * * * * * * * * * * * *\n",
+ "Char -128 to 127\n",
+ "short -32,768 to 32,767\n",
+ "int System dependent\n",
+ "long -2,147,483,648 to 2,147,483,647\n",
+ "* * * * * * * * * * * * * * * * * * * * * * * * *\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.3, Page Number: 168"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def repchar(ch,n): #function declarator\n",
+ " for j in range(n): #function body\n",
+ " print ch,\n",
+ " print\n",
+ " \n",
+ " \n",
+ "repchar('-',22) #call to function\n",
+ "print 'Data type Range'\n",
+ "repchar('=',12) #call to function\n",
+ "print 'Char -128 to 127'\n",
+ "print 'short -32,768 to 32,767'\n",
+ "print 'int System dependent'\n",
+ "print 'long -2,147,483,648 to 2,147,483,647'\n",
+ "repchar('-',22) #call to function"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "- - - - - - - - - - - - - - - - - - - - - -\n",
+ "Data type Range\n",
+ "= = = = = = = = = = = =\n",
+ "Char -128 to 127\n",
+ "short -32,768 to 32,767\n",
+ "int System dependent\n",
+ "long -2,147,483,648 to 2,147,483,647\n",
+ "- - - - - - - - - - - - - - - - - - - - - -\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4, Page Number: 169"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def repchar(ch,n): #function declarator\n",
+ " for j in range(n): #function body\n",
+ " print ch,\n",
+ " print\n",
+ " \n",
+ " \n",
+ "chin = raw_input(\"Enter a character: \") #get character from user\n",
+ "\n",
+ "nin = input(\"Enter number of times to repeat it: \") #get repetition\n",
+ "\n",
+ "repchar(chin,nin) #call to function"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a character: +\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of times to repeat it: 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "+ + + + + + + + + + + + + + + + + + + +\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5, Page Number: 172"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " feet = None\n",
+ " inches = None\n",
+ "\n",
+ " #function for display distance\n",
+ "def engldisp(dd): #parameter dd of type Distance\n",
+ " print dd.feet,'\\' -',dd.inches,'\\\"',\n",
+ " \n",
+ " #define two lengths\n",
+ "d1 = Distance()\n",
+ "d2 = Distance()\n",
+ "\n",
+ " #get length d1 from user\n",
+ "d1.feet = input(\"Enter feet: \")\n",
+ "d1.inches = input(\"Enter inches: \")\n",
+ "\n",
+ " #get length d2 from user\n",
+ "d2.feet = input(\"\\nEnter feet: \")\n",
+ "d2.inches = input(\"Enter inches: \")\n",
+ "\n",
+ "print '\\nd1 =', #display length 1\n",
+ "engldisp(d1)\n",
+ "\n",
+ "print '\\nd2 =', #display length 2\n",
+ "engldisp(d2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 4.25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "d1 = 6 ' - 4 \" \n",
+ "d2 = 5 ' - 4.25 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6, Page Number: 174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import * #importing turtles library\n",
+ "\n",
+ "class circle: #defining circle class\n",
+ " xCo = None\n",
+ " yCo = None\n",
+ " radius = None\n",
+ " fillcolor = None\n",
+ "\n",
+ " #draw circle\n",
+ "def circ_draw(c):\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " turtle.color(c.fillcolor)\n",
+ " turtle.up()\n",
+ " turtle.goto(c.xCo,c.yCo)\n",
+ " turtle.down()\n",
+ " turtle.circle(c.radius)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ " \n",
+ " \n",
+ " \n",
+ " #create circles\n",
+ "c1 = circle()\n",
+ "c2 = circle()\n",
+ "c3 = circle()\n",
+ " \n",
+ " #initialize the values of each circle\n",
+ "c1.xCo = 15\n",
+ "c1.yCo = 7\n",
+ "c1.radius = 5\n",
+ "c1.fillcolor = \"Blue\"\n",
+ "\n",
+ "c2.xCo = 41\n",
+ "c2.yCo = 12\n",
+ "c2.radius = 7\n",
+ "c2.fillcolor = \"Red\"\n",
+ "\n",
+ "c3.xCo = 65\n",
+ "c3.yCo = 18\n",
+ "c3.radius = 4\n",
+ "c3.fillcolor = \"Green\"\n",
+ "\n",
+ " #draw circle\n",
+ "circ_draw(c1)\n",
+ "circ_draw(c2)\n",
+ "circ_draw(c3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.7, Page Number: 176"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def lbstokg(pounds): #function for converting pounds to kilograms\n",
+ " kilograms = 0.453592 * pounds\n",
+ " return kilograms\n",
+ "\n",
+ "lbs = input(\"Enter your weight in pounds: \") #get the weight from user\n",
+ "\n",
+ "kgs = lbstokg(lbs) #function call \n",
+ "\n",
+ "print 'Your weight in kilogram is',kgs,'\\n' #display weight from pounds to kilogram"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your weight in pounds: 182\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your weight in kilogram is 82.553744 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.8, Page Number: 179"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def lbstokg(pounds): #function for converting pounds to kilogram\n",
+ " return 0.453592 * pounds\n",
+ "\n",
+ "lbs = input(\"Enter your weight in pounds: \") #get the weight from user\n",
+ "\n",
+ "print 'Your weight in kilogram is',lbstokg(lbs),'\\n' #call function an display weight"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your weight in pounds: 182\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your weight in kilogram is 82.553744 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.9, Page Number: 180"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " feet = None\n",
+ " inches = None\n",
+ "\n",
+ "def addeng1(dd1,dd2): #function for add two lengths\n",
+ " \n",
+ " dd3 = Distance() #define a new structure for sum\n",
+ " \n",
+ " dd3.inches = dd1.inches + dd2.inches #add the inches\n",
+ " dd3.feet = 0\n",
+ "\n",
+ " if dd3.inches>=12.0: #if inches >= 12.0\n",
+ " dd3.inches -= 12.0 #then decrease inches by 12,0\n",
+ " dd3.feet += 1 #and increase feet by 1\n",
+ " \n",
+ " dd3.feet += dd1.feet + dd2.feet #add feet\n",
+ " \n",
+ " return dd3 #return structure\n",
+ " \n",
+ " \n",
+ "def engldisp(dd): #display the length\n",
+ " print dd.feet,'\\' -',dd.inches,'\\\"',\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " #define three lengths\n",
+ "d1 = Distance()\n",
+ "d2 = Distance()\n",
+ "d3 = Distance()\n",
+ "\n",
+ " #get length d1 from user\n",
+ "d1.feet = input(\"Enter feet: \")\n",
+ "d1.inches = input(\"Enter inches: \")\n",
+ "\n",
+ " #get length d2 from user\n",
+ "d2.feet = input(\"\\nEnter feet: \")\n",
+ "d2.inches = input(\"Enter inches: \")\n",
+ " \n",
+ "d3 = addeng1(d1,d2) #d3 is sum of d1 and d2\n",
+ "\n",
+ "print '\\n', #display all lengths\n",
+ "engldisp(d1); print ' + ',\n",
+ "engldisp(d2); print ' = ',\n",
+ "engldisp(d3); print '\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 5.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 6.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "4 ' - 5.5 \" + 5 ' - 6.5 \" = 10 ' - 0.0 \" \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.10, Page Number: 182"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def intfrac(n): #function for finding the integer and fractional part of real number\n",
+ " temp = n\n",
+ " intp = int(temp) #convert to int\n",
+ " fracp = n - intp #subtract integer part to get fractional part\n",
+ " return intp,fracp\n",
+ "\n",
+ "\n",
+ "while True:\n",
+ " \n",
+ " number = input(\"Enter a real number: \") #get number from user\n",
+ " \n",
+ " intpart,fracpart = intfrac(number) #function call\n",
+ " \n",
+ " if number == 0.0: #exit loop when number is 0.0\n",
+ " break\n",
+ " \n",
+ " print 'Integer part is',intpart,', fraction part is',fracpart,'\\n' #print integer and fractional part"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a real number: 99.44\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Integer part is 99 , fraction part is 0.44 \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a real number: 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.11, Page Number: 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def order(numb1,numb2): #orders of two numbers\n",
+ " \n",
+ " if numb1>numb2: #if 1st larger than 2nd\n",
+ " temp = numb1 #swap them\n",
+ " numb1 = numb2\n",
+ " numb2 = temp\n",
+ " \n",
+ " return numb1,numb2\n",
+ "\n",
+ "\n",
+ "\n",
+ "n1 = 99 #this pair not ordered\n",
+ "n2 = 11\n",
+ "\n",
+ "n3 = 22 #this pair ordered\n",
+ "n4 = 88\n",
+ "\n",
+ "n1,n2 = order(n1,n2) #order each pair of numbers\n",
+ "n3,n4 = order(n3,n4)\n",
+ "\n",
+ "print 'n1 =',n1 #print out all numbers\n",
+ "print 'n2 =',n2\n",
+ "print 'n3 =',n3\n",
+ "print 'n4 =',n4"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n1 = 11\n",
+ "n2 = 99\n",
+ "n3 = 22\n",
+ "n4 = 88\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.12, Page Number: 186"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " feet = None\n",
+ " inches = None\n",
+ " \n",
+ "def scale(dd,factor): #Scales value of type Distance by factor\n",
+ " inches = (dd.feet*12 + dd.inches) * factor\n",
+ " dd.feet = int(inches/12)\n",
+ " dd.inches = inches - dd.feet * 12\n",
+ " return dd\n",
+ "\n",
+ "def engldisp(dd): #dispaly length\n",
+ " print dd.feet,'\\' -',dd.inches,'\\\"'\n",
+ "\n",
+ " \n",
+ " \n",
+ "d1 = Distance() #initialize d1\n",
+ "d1.feet = 12\n",
+ "d1.inches = 6.5\n",
+ "\n",
+ "d2 = Distance() #initialize d2\n",
+ "d2.feet = 10\n",
+ "d2.inches = 5.5\n",
+ "\n",
+ "print 'd1 =', ; engldisp(d1) #display old d1 and d2\n",
+ "print 'd2 =', ; engldisp(d2)\n",
+ "\n",
+ "d1 = scale(d1,0.5) #scale d1 and d2\n",
+ "d2 = scale(d2,0.25)\n",
+ "\n",
+ "print 'd1 =', ; engldisp(d1) #display new d1 and d2\n",
+ "print 'd2 =', ; engldisp(d2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d1 = 12 ' - 6.5 \"\n",
+ "d2 = 10 ' - 5.5 \"\n",
+ "d1 = 6 ' - 3.25 \"\n",
+ "d2 = 2 ' - 7.375 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.13, Page Number: 189"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def repchar(ch=None,n=None): #display specified character\n",
+ " \n",
+ " if ch == None:\n",
+ " for j in range(45): #display 45 asterisks\n",
+ " print '*',\n",
+ " print ''\n",
+ " \n",
+ " elif n == None:\n",
+ " for j in range(45): #display 45 specified character\n",
+ " print ch,\n",
+ " print ''\n",
+ " \n",
+ " else:\n",
+ " for j in range(n): #display specified number of copies of specified character \n",
+ " print ch,\n",
+ " print ''\n",
+ " \n",
+ " \n",
+ "repchar() #call functions\n",
+ "repchar('=')\n",
+ "repchar('+',30)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n",
+ "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = \n",
+ "+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.14, Page Number: 191"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " feet = None\n",
+ " inches = None\n",
+ "\n",
+ " \n",
+ "#function overloading\n",
+ "def engldisp(dd): \n",
+ " \n",
+ " if isinstance(dd,float): #if dd is float type\n",
+ " feet = int(dd/12)\n",
+ " inches = dd - feet*12\n",
+ " print feet,'\\' -',inches,'\\\"',\n",
+ " \n",
+ " else: #if parameter dd of type Distance\n",
+ " print dd.feet,'\\' -',dd.inches,'\\\"',\n",
+ " \n",
+ " \n",
+ " \n",
+ "d1 = Distance() #distance of type Distance\n",
+ "d1.feet = input(\"Enter feet: \") #get d1 from user\n",
+ "d1.inches = input(\"Enter inches: \")\n",
+ "\n",
+ "d2 = input(\"\\nEnter entire distance in inches: \") #distance of type float\n",
+ "\n",
+ "print '\\nd1 =', #display length d1\n",
+ "engldisp(d1)\n",
+ "\n",
+ "print '\\nd2 =', #display length d2\n",
+ "engldisp(d2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 10.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter entire distance in inches: 76.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "d1 = 5 ' - 10.5 \" \n",
+ "d2 = 6 ' - 4.5 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.15, Page Number: 193"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def factfunc(n): #calls itself to calculate factorials\n",
+ " \n",
+ " if n>1:\n",
+ " return n * factfunc(n-1)\n",
+ " else:\n",
+ " return 1\n",
+ " \n",
+ " \n",
+ "n = input(\"Enter an integer: \") #get number from user\n",
+ "\n",
+ "fact = factfunc(n) #function call for factorial\n",
+ "print 'Factorial of',n,'is',fact,'\\n' #dsplay factorial"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an integer: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Factorial of 5 is 120 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.16, Page Number: 197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#inline function\n",
+ "lbstokg = lambda pounds: 0.453592 * pounds #converts pounds to kilogram\n",
+ "\n",
+ "lbs = input(\"Enter your weight in pounds: \") #get weight from user\n",
+ "print 'Your weight in kilogram is',lbstokg(lbs) #convert it and display"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your weight in pounds: 182\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your weight in kilogram is 82.553744\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.17, Page Number: 198"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def repchar(ch='*',n=45): #function with default arguments\n",
+ " for j in range(n): #loops n times\n",
+ " print ch, #print ch\n",
+ " print\n",
+ " \n",
+ " \n",
+ "repchar() #prints 45 asterisks\n",
+ "repchar('=') #prints 45 equal sign\n",
+ "repchar('+',30) #prints 30 plus sign"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n",
+ "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n",
+ "+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.18, Page Number: 202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ch = 'a'\n",
+ "\n",
+ "def getachar(): #function for accesses text line\n",
+ " global ch\n",
+ " ch = raw_input()\n",
+ "\n",
+ "def putachar(): #function for display text line\n",
+ " global ch\n",
+ " print ch\n",
+ " \n",
+ " \n",
+ "getachar() #functions call\n",
+ "putachar()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I'm typing in this line if text\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I'm typing in this line if text\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.19, Page Number: 204"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "total = 0 #works as static variables\n",
+ "count = 0\n",
+ "\n",
+ "def getavg(newdata): #function for finds average of old and new data\n",
+ " global total\n",
+ " global count\n",
+ " \n",
+ " count += 1 #increment count\n",
+ " total += newdata #add new data to total\n",
+ " \n",
+ " return total / count #return the new average\n",
+ "\n",
+ "\n",
+ "\n",
+ "data = 1\n",
+ "\n",
+ "while(data != 0):\n",
+ " data = input(\"Enter a number: \") #get data from user\n",
+ " avg = getavg(data) #find out average each time\n",
+ " print 'new average is',avg #print average"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "new average is 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "new average is 15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 30\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "new average is 20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "new average is 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.20, Page Number: 206"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = None #global variable\n",
+ "\n",
+ "def setx(): #returns the value to be modified\n",
+ " global x\n",
+ " return x\n",
+ "\n",
+ "\n",
+ "x = 92 #set x to a value\n",
+ "\n",
+ "print 'x =',setx() #and print x using functon call"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x = 92\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.21, Page Number: 208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def aFunc(a,b): #functon for modify the arguments\n",
+ " a = 107\n",
+ " b = 111\n",
+ " return a,b\n",
+ "\n",
+ "\n",
+ "alpha = 7\n",
+ "beta = 11\n",
+ "\n",
+ "alpha,beta = aFunc(alpha,beta) #function call"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter5Functions_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter5Functions_1.ipynb
new file mode 100755
index 00000000..c9a8af9e
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter5Functions_1.ipynb
@@ -0,0 +1,1207 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3258aab91358d12b5c80e3e8c3b29dc40c258d72377521e4e9935ef23a46aa27"
+ },
+ "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 5.1, Page Number: 163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def starline(): #function declarator\n",
+ " for j in range(25): #function body\n",
+ " print '*', \n",
+ " print\n",
+ " \n",
+ " \n",
+ "starline() #call to function\n",
+ "print 'Data type Range'\n",
+ "starline() #call to function\n",
+ "print 'Char -128 to 127'\n",
+ "print 'short -32,768 to 32,767'\n",
+ "print 'int System dependent'\n",
+ "print 'long -2,147,483,648 to 2,147,483,647'\n",
+ "starline() #call to function"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "* * * * * * * * * * * * * * * * * * * * * * * * *\n",
+ "Data type Range\n",
+ "* * * * * * * * * * * * * * * * * * * * * * * * *\n",
+ "Char -128 to 127\n",
+ "short -32,768 to 32,767\n",
+ "int System dependent\n",
+ "long -2,147,483,648 to 2,147,483,647\n",
+ "* * * * * * * * * * * * * * * * * * * * * * * * *\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2, Page Number: 167"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " #function definition\n",
+ "def starline():\n",
+ " for j in range(25):\n",
+ " print '*',\n",
+ " print\n",
+ " \n",
+ " \n",
+ "starline() #call to function\n",
+ "print 'Data type Range'\n",
+ "starline() #call to function\n",
+ "print 'Char -128 to 127'\n",
+ "print 'short -32,768 to 32,767'\n",
+ "print 'int System dependent'\n",
+ "print 'long -2,147,483,648 to 2,147,483,647'\n",
+ "starline() #call to function"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "* * * * * * * * * * * * * * * * * * * * * * * * *\n",
+ "Data type Range\n",
+ "* * * * * * * * * * * * * * * * * * * * * * * * *\n",
+ "Char -128 to 127\n",
+ "short -32,768 to 32,767\n",
+ "int System dependent\n",
+ "long -2,147,483,648 to 2,147,483,647\n",
+ "* * * * * * * * * * * * * * * * * * * * * * * * *\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.3, Page Number: 168"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def repchar(ch,n): #function declarator\n",
+ " for j in range(n): #function body\n",
+ " print ch,\n",
+ " print\n",
+ " \n",
+ " \n",
+ "repchar('-',22) #call to function\n",
+ "print 'Data type Range'\n",
+ "repchar('=',12) #call to function\n",
+ "print 'Char -128 to 127'\n",
+ "print 'short -32,768 to 32,767'\n",
+ "print 'int System dependent'\n",
+ "print 'long -2,147,483,648 to 2,147,483,647'\n",
+ "repchar('-',22) #call to function"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "- - - - - - - - - - - - - - - - - - - - - -\n",
+ "Data type Range\n",
+ "= = = = = = = = = = = =\n",
+ "Char -128 to 127\n",
+ "short -32,768 to 32,767\n",
+ "int System dependent\n",
+ "long -2,147,483,648 to 2,147,483,647\n",
+ "- - - - - - - - - - - - - - - - - - - - - -\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4, Page Number: 169"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def repchar(ch,n): #function declarator\n",
+ " for j in range(n): #function body\n",
+ " print ch,\n",
+ " print\n",
+ " \n",
+ " \n",
+ "chin = raw_input(\"Enter a character: \") #get character from user\n",
+ "\n",
+ "nin = input(\"Enter number of times to repeat it: \") #get repetition\n",
+ "\n",
+ "repchar(chin,nin) #call to function"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a character: +\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of times to repeat it: 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "+ + + + + + + + + + + + + + + + + + + +\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5, Page Number: 172"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " feet = None\n",
+ " inches = None\n",
+ "\n",
+ " #function for display distance\n",
+ "def engldisp(dd): #parameter dd of type Distance\n",
+ " print dd.feet,'\\' -',dd.inches,'\\\"',\n",
+ " \n",
+ " #define two lengths\n",
+ "d1 = Distance()\n",
+ "d2 = Distance()\n",
+ "\n",
+ " #get length d1 from user\n",
+ "d1.feet = input(\"Enter feet: \")\n",
+ "d1.inches = input(\"Enter inches: \")\n",
+ "\n",
+ " #get length d2 from user\n",
+ "d2.feet = input(\"\\nEnter feet: \")\n",
+ "d2.inches = input(\"Enter inches: \")\n",
+ "\n",
+ "print '\\nd1 =', #display length 1\n",
+ "engldisp(d1)\n",
+ "\n",
+ "print '\\nd2 =', #display length 2\n",
+ "engldisp(d2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 4.25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "d1 = 6 ' - 4 \" \n",
+ "d2 = 5 ' - 4.25 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6, Page Number: 174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import Turtle,setup,done #importing turtles library\n",
+ "\n",
+ "class circle: #defining circle class\n",
+ " xCo = None\n",
+ " yCo = None\n",
+ " radius = None\n",
+ " fillcolor = None\n",
+ "\n",
+ " #draw circle\n",
+ "def circ_draw(c):\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " turtle.color(c.fillcolor)\n",
+ " turtle.up()\n",
+ " turtle.goto(c.xCo,c.yCo)\n",
+ " turtle.down()\n",
+ " turtle.circle(c.radius)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ " \n",
+ " \n",
+ " \n",
+ " #create circles\n",
+ "c1 = circle()\n",
+ "c2 = circle()\n",
+ "c3 = circle()\n",
+ " \n",
+ " #initialize the values of each circle\n",
+ "c1.xCo = 15\n",
+ "c1.yCo = 7\n",
+ "c1.radius = 5\n",
+ "c1.fillcolor = \"Blue\"\n",
+ "\n",
+ "c2.xCo = 41\n",
+ "c2.yCo = 12\n",
+ "c2.radius = 7\n",
+ "c2.fillcolor = \"Red\"\n",
+ "\n",
+ "c3.xCo = 65\n",
+ "c3.yCo = 18\n",
+ "c3.radius = 4\n",
+ "c3.fillcolor = \"Green\"\n",
+ "\n",
+ " #draw circle\n",
+ "circ_draw(c1)\n",
+ "circ_draw(c2)\n",
+ "circ_draw(c3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.7, Page Number: 176"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def lbstokg(pounds): #function for converting pounds to kilograms\n",
+ " kilograms = 0.453592 * pounds\n",
+ " return kilograms\n",
+ "\n",
+ "lbs = input(\"Enter your weight in pounds: \") #get the weight from user\n",
+ "\n",
+ "kgs = lbstokg(lbs) #function call \n",
+ "\n",
+ "print 'Your weight in kilogram is',kgs,'\\n' #display weight from pounds to kilogram"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your weight in pounds: 182\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your weight in kilogram is 82.553744 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.8, Page Number: 179"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def lbstokg(pounds): #function for converting pounds to kilogram\n",
+ " return 0.453592 * pounds\n",
+ "\n",
+ "lbs = input(\"Enter your weight in pounds: \") #get the weight from user\n",
+ "\n",
+ "print 'Your weight in kilogram is',lbstokg(lbs),'\\n' #call function an display weight"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your weight in pounds: 182\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your weight in kilogram is 82.553744 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.9, Page Number: 180"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " feet = None\n",
+ " inches = None\n",
+ "\n",
+ "def addeng1(dd1,dd2): #function for add two lengths\n",
+ " \n",
+ " dd3 = Distance() #define a new structure for sum\n",
+ " \n",
+ " dd3.inches = dd1.inches + dd2.inches #add the inches\n",
+ " dd3.feet = 0\n",
+ "\n",
+ " if dd3.inches>=12.0: #if inches >= 12.0\n",
+ " dd3.inches -= 12.0 #then decrease inches by 12,0\n",
+ " dd3.feet += 1 #and increase feet by 1\n",
+ " \n",
+ " dd3.feet += dd1.feet + dd2.feet #add feet\n",
+ " \n",
+ " return dd3 #return structure\n",
+ " \n",
+ " \n",
+ "def engldisp(dd): #display the length\n",
+ " print dd.feet,'\\' -',dd.inches,'\\\"',\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ " #define three lengths\n",
+ "d1 = Distance()\n",
+ "d2 = Distance()\n",
+ "d3 = Distance()\n",
+ "\n",
+ " #get length d1 from user\n",
+ "d1.feet = input(\"Enter feet: \")\n",
+ "d1.inches = input(\"Enter inches: \")\n",
+ "\n",
+ " #get length d2 from user\n",
+ "d2.feet = input(\"\\nEnter feet: \")\n",
+ "d2.inches = input(\"Enter inches: \")\n",
+ " \n",
+ "d3 = addeng1(d1,d2) #d3 is sum of d1 and d2\n",
+ "\n",
+ "print '\\n', #display all lengths\n",
+ "engldisp(d1); print ' + ',\n",
+ "engldisp(d2); print ' = ',\n",
+ "engldisp(d3); print '\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 5.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 6.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "4 ' - 5.5 \" + 5 ' - 6.5 \" = 10 ' - 0.0 \" \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.10, Page Number: 182"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def intfrac(n): #function for finding the integer and fractional part of real number\n",
+ " temp = n\n",
+ " intp = int(temp) #convert to int\n",
+ " fracp = n - intp #subtract integer part to get fractional part\n",
+ " return intp,fracp\n",
+ "\n",
+ "\n",
+ "while True:\n",
+ " \n",
+ " number = input(\"Enter a real number: \") #get number from user\n",
+ " \n",
+ " intpart,fracpart = intfrac(number) #function call\n",
+ " \n",
+ " if number == 0.0: #exit loop when number is 0.0\n",
+ " break\n",
+ " \n",
+ " print 'Integer part is',intpart,', fraction part is',fracpart,'\\n' #print integer and fractional part"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a real number: 99.44\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Integer part is 99 , fraction part is 0.44 \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a real number: 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.11, Page Number: 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def order(numb1,numb2): #orders of two numbers\n",
+ " \n",
+ " if numb1>numb2: #if 1st larger than 2nd\n",
+ " temp = numb1 #swap them\n",
+ " numb1 = numb2\n",
+ " numb2 = temp\n",
+ " \n",
+ " return numb1,numb2\n",
+ "\n",
+ "\n",
+ "\n",
+ "n1 = 99 #this pair not ordered\n",
+ "n2 = 11\n",
+ "\n",
+ "n3 = 22 #this pair ordered\n",
+ "n4 = 88\n",
+ "\n",
+ "n1,n2 = order(n1,n2) #order each pair of numbers\n",
+ "n3,n4 = order(n3,n4)\n",
+ "\n",
+ "print 'n1 =',n1 #print out all numbers\n",
+ "print 'n2 =',n2\n",
+ "print 'n3 =',n3\n",
+ "print 'n4 =',n4"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n1 = 11\n",
+ "n2 = 99\n",
+ "n3 = 22\n",
+ "n4 = 88\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.12, Page Number: 186"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " feet = None\n",
+ " inches = None\n",
+ " \n",
+ "def scale(dd,factor): #Scales value of type Distance by factor\n",
+ " inches = (dd.feet*12 + dd.inches) * factor\n",
+ " dd.feet = int(inches/12)\n",
+ " dd.inches = inches - dd.feet * 12\n",
+ " return dd\n",
+ "\n",
+ "def engldisp(dd): #dispaly length\n",
+ " print dd.feet,'\\' -',dd.inches,'\\\"'\n",
+ "\n",
+ " \n",
+ " \n",
+ "d1 = Distance() #initialize d1\n",
+ "d1.feet = 12\n",
+ "d1.inches = 6.5\n",
+ "\n",
+ "d2 = Distance() #initialize d2\n",
+ "d2.feet = 10\n",
+ "d2.inches = 5.5\n",
+ "\n",
+ "print 'd1 =', ; engldisp(d1) #display old d1 and d2\n",
+ "print 'd2 =', ; engldisp(d2)\n",
+ "\n",
+ "d1 = scale(d1,0.5) #scale d1 and d2\n",
+ "d2 = scale(d2,0.25)\n",
+ "\n",
+ "print 'd1 =', ; engldisp(d1) #display new d1 and d2\n",
+ "print 'd2 =', ; engldisp(d2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d1 = 12 ' - 6.5 \"\n",
+ "d2 = 10 ' - 5.5 \"\n",
+ "d1 = 6 ' - 3.25 \"\n",
+ "d2 = 2 ' - 7.375 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.13, Page Number: 189"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def repchar(ch=None,n=None): #display specified character\n",
+ " \n",
+ " if ch == None:\n",
+ " for j in range(45): #display 45 asterisks\n",
+ " print '*',\n",
+ " print ''\n",
+ " \n",
+ " elif n == None:\n",
+ " for j in range(45): #display 45 specified character\n",
+ " print ch,\n",
+ " print ''\n",
+ " \n",
+ " else:\n",
+ " for j in range(n): #display specified number of copies of specified character \n",
+ " print ch,\n",
+ " print ''\n",
+ " \n",
+ " \n",
+ "repchar() #call functions\n",
+ "repchar('=')\n",
+ "repchar('+',30)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n",
+ "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = \n",
+ "+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.14, Page Number: 191"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " feet = None\n",
+ " inches = None\n",
+ "\n",
+ " \n",
+ "#function overloading\n",
+ "def engldisp(dd): \n",
+ " \n",
+ " if isinstance(dd,float): #if dd is float type\n",
+ " feet = int(dd/12)\n",
+ " inches = dd - feet*12\n",
+ " print feet,'\\' -',inches,'\\\"',\n",
+ " \n",
+ " else: #if parameter dd of type Distance\n",
+ " print dd.feet,'\\' -',dd.inches,'\\\"',\n",
+ " \n",
+ " \n",
+ " \n",
+ "d1 = Distance() #distance of type Distance\n",
+ "d1.feet = input(\"Enter feet: \") #get d1 from user\n",
+ "d1.inches = input(\"Enter inches: \")\n",
+ "\n",
+ "d2 = input(\"\\nEnter entire distance in inches: \") #distance of type float\n",
+ "\n",
+ "print '\\nd1 =', #display length d1\n",
+ "engldisp(d1)\n",
+ "\n",
+ "print '\\nd2 =', #display length d2\n",
+ "engldisp(d2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 10.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter entire distance in inches: 76.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "d1 = 5 ' - 10.5 \" \n",
+ "d2 = 6 ' - 4.5 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.15, Page Number: 193"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def factfunc(n): #calls itself to calculate factorials\n",
+ " \n",
+ " if n>1:\n",
+ " return n * factfunc(n-1)\n",
+ " else:\n",
+ " return 1\n",
+ " \n",
+ " \n",
+ "n = input(\"Enter an integer: \") #get number from user\n",
+ "\n",
+ "fact = factfunc(n) #function call for factorial\n",
+ "print 'Factorial of',n,'is',fact,'\\n' #dsplay factorial"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an integer: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Factorial of 5 is 120 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.16, Page Number: 197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#inline function\n",
+ "lbstokg = lambda pounds: 0.453592 * pounds #converts pounds to kilogram\n",
+ "\n",
+ "lbs = input(\"Enter your weight in pounds: \") #get weight from user\n",
+ "print 'Your weight in kilogram is',lbstokg(lbs) #convert it and display"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your weight in pounds: 182\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your weight in kilogram is 82.553744\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.17, Page Number: 198"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def repchar(ch='*',n=45): #function with default arguments\n",
+ " for j in range(n): #loops n times\n",
+ " print ch, #print ch\n",
+ " print\n",
+ " \n",
+ " \n",
+ "repchar() #prints 45 asterisks\n",
+ "repchar('=') #prints 45 equal sign\n",
+ "repchar('+',30) #prints 30 plus sign"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n",
+ "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n",
+ "+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.18, Page Number: 202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ch = 'a'\n",
+ "\n",
+ "def getachar(): #function for accesses text line\n",
+ " global ch\n",
+ " ch = raw_input()\n",
+ "\n",
+ "def putachar(): #function for display text line\n",
+ " global ch\n",
+ " print ch\n",
+ " \n",
+ " \n",
+ "getachar() #functions call\n",
+ "putachar()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I'm typing in this line if text\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I'm typing in this line if text\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.19, Page Number: 204"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "total = 0 #works as static variables\n",
+ "count = 0\n",
+ "\n",
+ "def getavg(newdata): #function for finds average of old and new data\n",
+ " global total\n",
+ " global count\n",
+ " \n",
+ " count += 1 #increment count\n",
+ " total += newdata #add new data to total\n",
+ " \n",
+ " return total / count #return the new average\n",
+ "\n",
+ "\n",
+ "\n",
+ "data = 1\n",
+ "\n",
+ "while(data != 0):\n",
+ " data = input(\"Enter a number: \") #get data from user\n",
+ " avg = getavg(data) #find out average each time\n",
+ " print 'new average is',avg #print average"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "new average is 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "new average is 15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 30\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "new average is 20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "new average is 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.20, Page Number: 206"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = None #global variable\n",
+ "\n",
+ "def setx(): #returns the value to be modified\n",
+ " global x\n",
+ " return x\n",
+ "\n",
+ "\n",
+ "x = 92 #set x to a value\n",
+ "\n",
+ "print 'x =',setx() #and print x using functon call"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x = 92\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.21, Page Number: 208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def aFunc(a,b): #functon for modify the arguments\n",
+ " a = 107\n",
+ " b = 111\n",
+ " return a,b\n",
+ "\n",
+ "\n",
+ "alpha = 7\n",
+ "beta = 11\n",
+ "\n",
+ "alpha,beta = aFunc(alpha,beta) #function call"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter6ObjectsandClasses.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter6ObjectsandClasses.ipynb
new file mode 100755
index 00000000..4b2f1592
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter6ObjectsandClasses.ipynb
@@ -0,0 +1,977 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:2eec6e43e64f5a8bda589162986f50463ec9afe41b355127fa82f9b4185f8784"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Objects and Classes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1, Page Number: 216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class smallobj: #define a class\n",
+ " \n",
+ " def setdata(self,d): #member function to set class variable somdata\n",
+ " self.__somedata = d\n",
+ " \n",
+ " def showdata(self): #member function to display somedata \n",
+ " print 'Data is' , self.__somedata\n",
+ "\n",
+ " \n",
+ "\n",
+ "#define two objects of class smallobj\n",
+ "s1=smallobj()\n",
+ "s2=smallobj()\n",
+ "\n",
+ "#call member function to set data \n",
+ "s1.setdata(1066)\n",
+ "s2.setdata(1776)\n",
+ "\n",
+ "#call member function to display data \n",
+ "s1.showdata()\n",
+ "s2.showdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Data is 1066\n",
+ "Data is 1776\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2, Page Number: 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class part: #define class \n",
+ " \n",
+ " def setpart(self,mn,pn,c): #set data\n",
+ " self.__modelnumber = mn\n",
+ " self.__partnumber = pn\n",
+ " self.__cost = c\n",
+ " \n",
+ " def showpart(self): #display data \n",
+ " print 'Model' , self.__modelnumber ,\n",
+ " print ', part' , self.__partnumber , \n",
+ " print ', costs $',self.__cost\n",
+ " \n",
+ " \n",
+ "#define object of class part \n",
+ "part1 = part()\n",
+ "\n",
+ "#call member function setpart\n",
+ "part1.setpart(6244,373,217.55)\n",
+ "\n",
+ "#call member function showpart\n",
+ "part1.showpart()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Model 6244 , part 373 , costs $ 217.55\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3, Page Number: 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import * #importing turtles library\n",
+ "\n",
+ "class circle: #defining circle class\n",
+ " \n",
+ " def set(self,x,y,r,fc): #sets circle attribute\n",
+ " self._xCo = x\n",
+ " self._yCo = y\n",
+ " self._radius = r\n",
+ " self._fillcolor = fc\n",
+ " \n",
+ " def draw(self): #draws the circle \n",
+ " setup() #set screen\n",
+ " turtle = Turtle() #object of Turtle class\n",
+ " turtle.begin_fill() #start filling color in circle\n",
+ " turtle.color(self._fillcolor) #color\n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo) #set center of circle\n",
+ " turtle.circle(self._radius) #draw circle of radius self.__radius\n",
+ " turtle.end_fill() #stop filling\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ "\n",
+ " \n",
+ " \n",
+ "#creating objects of class circle \n",
+ "c1 = circle()\n",
+ "c2 = circle()\n",
+ "c3 = circle()\n",
+ "\n",
+ "#sending the value to set fnction\n",
+ "c1.set(15,7,5,\"blue\")\n",
+ "c2.set(41,12,7,\"red\")\n",
+ "c3.set(65,18,4,\"green\")\n",
+ "\n",
+ "#draw circle\n",
+ "c1.draw()\n",
+ "c2.draw()\n",
+ "c3.draw()\n",
+ "\n",
+ "#In the above example the cirlcle's in the book are constructed using 'X' and 'O' but such feature is not available in Python.\n",
+ "#So i have created a simple circle filled with color"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.4, Page Number: 226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def setdist(self,ft,inc): #set distance to class variables\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get distance from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ "\n",
+ " \n",
+ " \n",
+ "#define two distance\n",
+ "dist1 = Distance()\n",
+ "dist2 = Distance()\n",
+ "\n",
+ "dist1.setdist(11,6.25) #set dist1\n",
+ "dist2.getdist() #set dist2 from user\n",
+ "\n",
+ "#show distances\n",
+ "print \"\\ndist1 = \",\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:4.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 11 ' - 6.25 \"\n",
+ "dist2 = 10 ' - 4.75 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.5, Page Number: 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter: #class counter\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__count = 0\n",
+ " \n",
+ " def inc_count(self): #increment count\n",
+ " self.__count = self.__count + 1\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self.__count\n",
+ "\n",
+ " \n",
+ " \n",
+ "#define and initialize class objects\n",
+ "c1=Counter()\n",
+ "c2=Counter()\n",
+ "\n",
+ "#display count for each object\n",
+ "print 'c1 =',c1.get_count()\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "\n",
+ "c1.inc_count() #increment c1\n",
+ "c2.inc_count() #increment c2\n",
+ "c2.inc_count() #increment c2\n",
+ "\n",
+ "#display count again for each object\n",
+ "print 'c1 =',c1.get_count()\n",
+ "print 'c2 =',c2.get_count()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 0\n",
+ "c1 = 1\n",
+ "c2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6, Page Number: 231"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import * #importing turtles library\n",
+ "\n",
+ "class circle: #defining circle class\n",
+ " \n",
+ " def __init__(self,x,y,r,fc): #constructor for set circle attribute\n",
+ " self._xCo = x\n",
+ " self._yCo = y\n",
+ " self._radius = r\n",
+ " self._fillcolor = fc\n",
+ " \n",
+ " def draw(self): #draws the circle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " turtle.color(self._fillcolor)\n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.circle(self._radius)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ "\n",
+ " \n",
+ " \n",
+ "#creating objects of class circle \n",
+ "c1 = circle(15,7,5,\"blue\") \n",
+ "c2 = circle(41,12,7,\"red\")\n",
+ "c3 = circle(65,18,4,\"green\")\n",
+ "\n",
+ "#draw circle\n",
+ "c1.draw()\n",
+ "c2.draw()\n",
+ "c3.draw()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7, Page Number: 233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def add_dist(self,d2,d3): #add length d2 and d3\n",
+ " \n",
+ " self.__inches = d2.__inches + d3.__inches #add inches\n",
+ " self.__feet = 0\n",
+ " \n",
+ " if self.__inches >= 12.0: #if total exceeds 12.0\n",
+ " self.__inches = self.__inches - 12.0 #then decrease inches by 12.0\n",
+ " self.__feet = self.__feet + 1 #and increase feet by 1\n",
+ " \n",
+ " self.__feet = self.__feet + d2.__feet + d3.__feet #add the feet\n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ "#define two length\n",
+ "dist1 = Distance()\n",
+ "dist3 = Distance()\n",
+ "\n",
+ "#define and initialize dist2\n",
+ "dist2 = Distance(11,6.25)\n",
+ "\n",
+ "#get dist1 from user\n",
+ "dist1.getdist()\n",
+ "\n",
+ "#dist3 = dist1 + dist2\n",
+ "dist3.add_dist(dist1,dist2)\n",
+ "\n",
+ "#display all lengths\n",
+ "print '\\ndist1 = ',\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()\n",
+ "print 'dist3 = ',\n",
+ "dist3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:5.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 17 ' - 5.75 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 29 ' - 0.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8, Page Number: 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #overloaded constructor that takes no arguments or two args or one object(copy constructor)\n",
+ " \n",
+ " if isinstance(ft,int):\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " else:\n",
+ " self.__feet = ft.__feet\n",
+ " self.__inches = ft.__inches\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ "\n",
+ " \n",
+ " \n",
+ "#two argument constructor\n",
+ "dist1 = Distance(11,6.25)\n",
+ "\n",
+ "#one argument(object) constructor explicitly pass\n",
+ "dist2 = Distance(dist1)\n",
+ "\n",
+ "#also one argument(object) constructor implicitly pass\n",
+ "dist3 = dist1\n",
+ "\n",
+ "#display all lengths\n",
+ "print 'dist1 = ',\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()\n",
+ "print 'dist3 = ',\n",
+ "dist3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dist1 = 11 ' - 6.25 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 11 ' - 6.25 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.9, Page Number: 240"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def add_dist(self,d2): #add this length to d2 and return object\n",
+ " temp = Distance() #temporary object\n",
+ " temp.__inches = self.__inches + d2.__inches\n",
+ " \n",
+ " if temp.__inches >= 12.0:\n",
+ " temp.__inches = temp.__inches - 12.0\n",
+ " temp.__feet = 1\n",
+ " \n",
+ " temp.__feet = temp.__feet + self.__feet + d2.__feet\n",
+ " return temp #return sum as object\n",
+ "\n",
+ " \n",
+ " \n",
+ "#define two length\n",
+ "dist1 = Distance()\n",
+ "dist3 = Distance()\n",
+ "\n",
+ "#define and initialize dist2\n",
+ "dist2 = Distance(11,6.25)\n",
+ "\n",
+ "#get dist1 from user\n",
+ "dist1.getdist()\n",
+ "\n",
+ "#dist3 = dist1 + dist2\n",
+ "dist3 = dist1.add_dist(dist2)\n",
+ "\n",
+ "#display all lengths\n",
+ "print '\\ndist1 = ',\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()\n",
+ "print 'dist3 = ',\n",
+ "dist3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:5.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 17 ' - 5.75 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 29 ' - 0.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.10, Page Number: 243"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Suit = [\"clubs\",\"diamonds\",\"hearts\",\"spades\"] \n",
+ "\n",
+ "(clubs,diamonds,hearts,spades) = (0,1,2,3) #Atteching the names with number \n",
+ "\n",
+ "\n",
+ "#from 2 to 10 are integers without names\n",
+ "jack = 11 \n",
+ "queen = 12 \n",
+ "king = 13\n",
+ "ace = 14\n",
+ "\n",
+ "\n",
+ "class card: \n",
+ " \n",
+ " def __init__(self,n=None,s=None): #constructor\n",
+ " self.__number = n #2 to 10, jack, queen, king, ace\n",
+ " self.__suit = s #clubs, diamonds, hearts, spades\n",
+ " \n",
+ " \n",
+ " def display(self): #display the cards\n",
+ " \n",
+ " if self.__number >= 2 and self.__number<=10:\n",
+ " print self.__number , 'of',\n",
+ " \n",
+ " else:\n",
+ " if self.__number == jack:\n",
+ " print 'jack of',\n",
+ " elif self.__number == queen:\n",
+ " print 'queen of',\n",
+ " elif self.__number == king:\n",
+ " print 'king of',\n",
+ " else:\n",
+ " print 'ace of',\n",
+ " \n",
+ " if self.__suit == clubs:\n",
+ " print 'clubs',\n",
+ " elif self.__suit == diamonds:\n",
+ " print 'diamonds',\n",
+ " elif self.__suit == hearts:\n",
+ " print 'hearts',\n",
+ " else:\n",
+ " print 'spades',\n",
+ " \n",
+ " \n",
+ " def isEqual(self,c2): #return 1 if cards equal\n",
+ " \n",
+ " if self.__number == c2.__number and self.__suit == c2.__suit:\n",
+ " return 1\n",
+ " else:\n",
+ " return 0\n",
+ "\n",
+ "\n",
+ " \n",
+ " \n",
+ "#define various cards\n",
+ "temp = card()\n",
+ "chosen = card()\n",
+ "prize = card()\n",
+ "\n",
+ "\n",
+ "#define and initialize card1\n",
+ "card1 = card(7,clubs)\n",
+ "print 'card 1 is the',\n",
+ "card1.display() #display card1\n",
+ "\n",
+ "#define and initialize card2\n",
+ "card2 = card(jack,hearts)\n",
+ "print 'card 2 is the',\n",
+ "card2.display() #display card2\n",
+ "\n",
+ "#define and initialize card3\n",
+ "card3 = card(ace,spades)\n",
+ "print 'card 3 is the',\n",
+ "card3.display() #display card3\n",
+ "\n",
+ "\n",
+ "#prize is the card to guess\n",
+ "prize = card3\n",
+ "\n",
+ "\n",
+ "#swapping cards\n",
+ "print '\\nI\\'m swapping card 1 and card 3'\n",
+ "temp = card3\n",
+ "card3 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 2 and card 3'\n",
+ "temp = card2\n",
+ "card2 = card3\n",
+ "card3 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 1 and card 2'\n",
+ "temp = card2\n",
+ "card2 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "print 'Now, where (1,2, or 3) is the',\n",
+ "prize.display() #display prize\n",
+ "print '?',\n",
+ "\n",
+ "\n",
+ "position = input(\" \") #get user's guess of position\n",
+ "\n",
+ "\n",
+ "#set chosen to user's choice \n",
+ "if position == 1:\n",
+ " chosen = card1\n",
+ "elif position == 2:\n",
+ " chosen = card2\n",
+ "else:\n",
+ " chosen = card3\n",
+ "\n",
+ " \n",
+ "#is chosen card the prize?\n",
+ "x=chosen.isEqual(prize)\n",
+ "\n",
+ "\n",
+ "if x==1:\n",
+ " print 'That\\'s right! You win!'\n",
+ "else:\n",
+ " print 'Sorry. You lose.'\n",
+ "\n",
+ "print ' You choose the',\n",
+ "\n",
+ "\n",
+ "#display chosen card\n",
+ "chosen.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "card 1 is the 7 of clubs card 2 is the jack of hearts card 3 is the ace of spades \n",
+ "I'm swapping card 1 and card 3\n",
+ "I'm swapping card 2 and card 3\n",
+ "I'm swapping card 1 and card 2\n",
+ "Now, where (1,2, or 3) is the ace of spades ?"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Sorry. You lose.\n",
+ " You choose the 7 of clubs\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.11, Page Number: 249"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class foo: \n",
+ " \n",
+ " __count = 0 #only one data item for all objects\n",
+ " \n",
+ " def __init__(self):\n",
+ " foo.__count = foo.__count + 1 #increment count when object created\n",
+ " \n",
+ " def getcount(self): #returns count\n",
+ " return foo.__count\n",
+ "\n",
+ " \n",
+ " \n",
+ "#create three objecs\n",
+ "f1 = foo()\n",
+ "f2 = foo()\n",
+ "f3 = foo()\n",
+ "\n",
+ "#Each object displays the same count value\n",
+ "print 'count is', f1.getcount()\n",
+ "print 'count is', f2.getcount()\n",
+ "print 'count is', f3.getcount()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "count is 3\n",
+ "count is 3\n",
+ "count is 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.12, Page Number: 253"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ "\n",
+ " \n",
+ " #There's no const keyword \n",
+ " \n",
+ " def add_dist(self,d2): #add this length to d2 and return object\n",
+ " \n",
+ " temp = Distance()\n",
+ " temp.__inches = self.__inches + d2.__inches\n",
+ " \n",
+ " if temp.__inches >= 12.0:\n",
+ " temp.__inches = temp.__inches - 12.0\n",
+ " temp.__feet = 1\n",
+ " \n",
+ " temp.__feet = temp.__feet + self.__feet + d2.__feet\n",
+ " \n",
+ " return temp #return sum as object\n",
+ " \n",
+ " \n",
+ " \n",
+ "#define two length\n",
+ "dist1 = Distance()\n",
+ "dist3 = Distance()\n",
+ "\n",
+ "#define and initialize dist2\n",
+ "dist2 = Distance(11,6.25)\n",
+ "\n",
+ "#get dist1 from user\n",
+ "dist1.getdist()\n",
+ "\n",
+ "dist3 = dist1.add_dist(dist2)\n",
+ "\n",
+ "#display all lengths\n",
+ "print '\\ndist1 = ',\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()\n",
+ "print 'dist3 = ',\n",
+ "dist3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:5.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 17 ' - 5.75 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 29 ' - 0.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.13, Page Number: 255"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class distance\n",
+ " \n",
+ " def __init__(self,ft,inc): #constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get distance from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display the distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ "\n",
+ " \n",
+ "#initialize distance object\n",
+ "football = Distance(300,0)\n",
+ "\n",
+ "print 'football = ',\n",
+ "football.showdist()\n",
+ "\n",
+ "#There's no const keyword in python"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "football = 300 ' - 0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter6ObjectsandClasses_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter6ObjectsandClasses_1.ipynb
new file mode 100755
index 00000000..66eb59c5
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter6ObjectsandClasses_1.ipynb
@@ -0,0 +1,977 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:70238dedbf20eaa2abfa4a9e6c97cbef5cb9eec9510d2e56ffdb0c9bad14be2d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Objects and Classes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1, Page Number: 216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class smallobj: #define a class\n",
+ " \n",
+ " def setdata(self,d): #member function to set class variable somdata\n",
+ " self.__somedata = d\n",
+ " \n",
+ " def showdata(self): #member function to display somedata \n",
+ " print 'Data is' , self.__somedata\n",
+ "\n",
+ " \n",
+ "\n",
+ "#define two objects of class smallobj\n",
+ "s1=smallobj()\n",
+ "s2=smallobj()\n",
+ "\n",
+ "#call member function to set data \n",
+ "s1.setdata(1066)\n",
+ "s2.setdata(1776)\n",
+ "\n",
+ "#call member function to display data \n",
+ "s1.showdata()\n",
+ "s2.showdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Data is 1066\n",
+ "Data is 1776\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2, Page Number: 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class part: #define class \n",
+ " \n",
+ " def setpart(self,mn,pn,c): #set data\n",
+ " self.__modelnumber = mn\n",
+ " self.__partnumber = pn\n",
+ " self.__cost = c\n",
+ " \n",
+ " def showpart(self): #display data \n",
+ " print 'Model' , self.__modelnumber ,\n",
+ " print ', part' , self.__partnumber , \n",
+ " print ', costs $',self.__cost\n",
+ " \n",
+ " \n",
+ "#define object of class part \n",
+ "part1 = part()\n",
+ "\n",
+ "#call member function setpart\n",
+ "part1.setpart(6244,373,217.55)\n",
+ "\n",
+ "#call member function showpart\n",
+ "part1.showpart()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Model 6244 , part 373 , costs $ 217.55\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3, Page Number: 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import Turtle,setup,done #importing turtles library\n",
+ "\n",
+ "class circle: #defining circle class\n",
+ " \n",
+ " def set(self,x,y,r,fc): #sets circle attribute\n",
+ " self._xCo = x\n",
+ " self._yCo = y\n",
+ " self._radius = r\n",
+ " self._fillcolor = fc\n",
+ " \n",
+ " def draw(self): #draws the circle \n",
+ " setup() #set screen\n",
+ " turtle = Turtle() #object of Turtle class\n",
+ " turtle.begin_fill() #start filling color in circle\n",
+ " turtle.color(self._fillcolor) #color\n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo) #set center of circle\n",
+ " turtle.circle(self._radius) #draw circle of radius self.__radius\n",
+ " turtle.end_fill() #stop filling\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ "\n",
+ " \n",
+ " \n",
+ "#creating objects of class circle \n",
+ "c1 = circle()\n",
+ "c2 = circle()\n",
+ "c3 = circle()\n",
+ "\n",
+ "#sending the value to set fnction\n",
+ "c1.set(15,7,5,\"blue\")\n",
+ "c2.set(41,12,7,\"red\")\n",
+ "c3.set(65,18,4,\"green\")\n",
+ "\n",
+ "#draw circle\n",
+ "c1.draw()\n",
+ "c2.draw()\n",
+ "c3.draw()\n",
+ "\n",
+ "#In the above example the cirlcle's in the book are constructed using 'X' and 'O' but such feature is not available in Python.\n",
+ "#So i have created a simple circle filled with color"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.4, Page Number: 226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def setdist(self,ft,inc): #set distance to class variables\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get distance from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ "\n",
+ " \n",
+ " \n",
+ "#define two distance\n",
+ "dist1 = Distance()\n",
+ "dist2 = Distance()\n",
+ "\n",
+ "dist1.setdist(11,6.25) #set dist1\n",
+ "dist2.getdist() #set dist2 from user\n",
+ "\n",
+ "#show distances\n",
+ "print \"\\ndist1 = \",\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:4.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 11 ' - 6.25 \"\n",
+ "dist2 = 10 ' - 4.75 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.5, Page Number: 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter: #class counter\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__count = 0\n",
+ " \n",
+ " def inc_count(self): #increment count\n",
+ " self.__count = self.__count + 1\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self.__count\n",
+ "\n",
+ " \n",
+ " \n",
+ "#define and initialize class objects\n",
+ "c1=Counter()\n",
+ "c2=Counter()\n",
+ "\n",
+ "#display count for each object\n",
+ "print 'c1 =',c1.get_count()\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "\n",
+ "c1.inc_count() #increment c1\n",
+ "c2.inc_count() #increment c2\n",
+ "c2.inc_count() #increment c2\n",
+ "\n",
+ "#display count again for each object\n",
+ "print 'c1 =',c1.get_count()\n",
+ "print 'c2 =',c2.get_count()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 0\n",
+ "c1 = 1\n",
+ "c2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6, Page Number: 231"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import Turtle,setup,done #importing turtles library\n",
+ "\n",
+ "class circle: #defining circle class\n",
+ " \n",
+ " def __init__(self,x,y,r,fc): #constructor for set circle attribute\n",
+ " self._xCo = x\n",
+ " self._yCo = y\n",
+ " self._radius = r\n",
+ " self._fillcolor = fc\n",
+ " \n",
+ " def draw(self): #draws the circle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " turtle.color(self._fillcolor)\n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.circle(self._radius)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ "\n",
+ " \n",
+ " \n",
+ "#creating objects of class circle \n",
+ "c1 = circle(15,7,5,\"blue\") \n",
+ "c2 = circle(41,12,7,\"red\")\n",
+ "c3 = circle(65,18,4,\"green\")\n",
+ "\n",
+ "#draw circle\n",
+ "c1.draw()\n",
+ "c2.draw()\n",
+ "c3.draw()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7, Page Number: 233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def add_dist(self,d2,d3): #add length d2 and d3\n",
+ " \n",
+ " self.__inches = d2.__inches + d3.__inches #add inches\n",
+ " self.__feet = 0\n",
+ " \n",
+ " if self.__inches >= 12.0: #if total exceeds 12.0\n",
+ " self.__inches = self.__inches - 12.0 #then decrease inches by 12.0\n",
+ " self.__feet = self.__feet + 1 #and increase feet by 1\n",
+ " \n",
+ " self.__feet = self.__feet + d2.__feet + d3.__feet #add the feet\n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ "#define two length\n",
+ "dist1 = Distance()\n",
+ "dist3 = Distance()\n",
+ "\n",
+ "#define and initialize dist2\n",
+ "dist2 = Distance(11,6.25)\n",
+ "\n",
+ "#get dist1 from user\n",
+ "dist1.getdist()\n",
+ "\n",
+ "#dist3 = dist1 + dist2\n",
+ "dist3.add_dist(dist1,dist2)\n",
+ "\n",
+ "#display all lengths\n",
+ "print '\\ndist1 = ',\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()\n",
+ "print 'dist3 = ',\n",
+ "dist3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:5.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 17 ' - 5.75 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 29 ' - 0.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8, Page Number: 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #overloaded constructor that takes no arguments or two args or one object(copy constructor)\n",
+ " \n",
+ " if isinstance(ft,int):\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " else:\n",
+ " self.__feet = ft.__feet\n",
+ " self.__inches = ft.__inches\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ "\n",
+ " \n",
+ " \n",
+ "#two argument constructor\n",
+ "dist1 = Distance(11,6.25)\n",
+ "\n",
+ "#one argument(object) constructor explicitly pass\n",
+ "dist2 = Distance(dist1)\n",
+ "\n",
+ "#also one argument(object) constructor implicitly pass\n",
+ "dist3 = dist1\n",
+ "\n",
+ "#display all lengths\n",
+ "print 'dist1 = ',\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()\n",
+ "print 'dist3 = ',\n",
+ "dist3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dist1 = 11 ' - 6.25 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 11 ' - 6.25 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.9, Page Number: 240"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def add_dist(self,d2): #add this length to d2 and return object\n",
+ " temp = Distance() #temporary object\n",
+ " temp.__inches = self.__inches + d2.__inches\n",
+ " \n",
+ " if temp.__inches >= 12.0:\n",
+ " temp.__inches = temp.__inches - 12.0\n",
+ " temp.__feet = 1\n",
+ " \n",
+ " temp.__feet = temp.__feet + self.__feet + d2.__feet\n",
+ " return temp #return sum as object\n",
+ "\n",
+ " \n",
+ " \n",
+ "#define two length\n",
+ "dist1 = Distance()\n",
+ "dist3 = Distance()\n",
+ "\n",
+ "#define and initialize dist2\n",
+ "dist2 = Distance(11,6.25)\n",
+ "\n",
+ "#get dist1 from user\n",
+ "dist1.getdist()\n",
+ "\n",
+ "#dist3 = dist1 + dist2\n",
+ "dist3 = dist1.add_dist(dist2)\n",
+ "\n",
+ "#display all lengths\n",
+ "print '\\ndist1 = ',\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()\n",
+ "print 'dist3 = ',\n",
+ "dist3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:5.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 17 ' - 5.75 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 29 ' - 0.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.10, Page Number: 243"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Suit = [\"clubs\",\"diamonds\",\"hearts\",\"spades\"] \n",
+ "\n",
+ "(clubs,diamonds,hearts,spades) = (0,1,2,3) #Atteching the names with number \n",
+ "\n",
+ "\n",
+ "#from 2 to 10 are integers without names\n",
+ "jack = 11 \n",
+ "queen = 12 \n",
+ "king = 13\n",
+ "ace = 14\n",
+ "\n",
+ "\n",
+ "class card: \n",
+ " \n",
+ " def __init__(self,n=None,s=None): #constructor\n",
+ " self.__number = n #2 to 10, jack, queen, king, ace\n",
+ " self.__suit = s #clubs, diamonds, hearts, spades\n",
+ " \n",
+ " \n",
+ " def display(self): #display the cards\n",
+ " \n",
+ " if self.__number >= 2 and self.__number<=10:\n",
+ " print self.__number , 'of',\n",
+ " \n",
+ " else:\n",
+ " if self.__number == jack:\n",
+ " print 'jack of',\n",
+ " elif self.__number == queen:\n",
+ " print 'queen of',\n",
+ " elif self.__number == king:\n",
+ " print 'king of',\n",
+ " else:\n",
+ " print 'ace of',\n",
+ " \n",
+ " if self.__suit == clubs:\n",
+ " print 'clubs',\n",
+ " elif self.__suit == diamonds:\n",
+ " print 'diamonds',\n",
+ " elif self.__suit == hearts:\n",
+ " print 'hearts',\n",
+ " else:\n",
+ " print 'spades',\n",
+ " \n",
+ " \n",
+ " def isEqual(self,c2): #return 1 if cards equal\n",
+ " \n",
+ " if self.__number == c2.__number and self.__suit == c2.__suit:\n",
+ " return 1\n",
+ " else:\n",
+ " return 0\n",
+ "\n",
+ "\n",
+ " \n",
+ " \n",
+ "#define various cards\n",
+ "temp = card()\n",
+ "chosen = card()\n",
+ "prize = card()\n",
+ "\n",
+ "\n",
+ "#define and initialize card1\n",
+ "card1 = card(7,clubs)\n",
+ "print 'card 1 is the',\n",
+ "card1.display() #display card1\n",
+ "\n",
+ "#define and initialize card2\n",
+ "card2 = card(jack,hearts)\n",
+ "print 'card 2 is the',\n",
+ "card2.display() #display card2\n",
+ "\n",
+ "#define and initialize card3\n",
+ "card3 = card(ace,spades)\n",
+ "print 'card 3 is the',\n",
+ "card3.display() #display card3\n",
+ "\n",
+ "\n",
+ "#prize is the card to guess\n",
+ "prize = card3\n",
+ "\n",
+ "\n",
+ "#swapping cards\n",
+ "print '\\nI\\'m swapping card 1 and card 3'\n",
+ "temp = card3\n",
+ "card3 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 2 and card 3'\n",
+ "temp = card2\n",
+ "card2 = card3\n",
+ "card3 = temp\n",
+ "\n",
+ "print 'I\\'m swapping card 1 and card 2'\n",
+ "temp = card2\n",
+ "card2 = card1\n",
+ "card1 = temp\n",
+ "\n",
+ "print 'Now, where (1,2, or 3) is the',\n",
+ "prize.display() #display prize\n",
+ "print '?',\n",
+ "\n",
+ "\n",
+ "position = input(\" \") #get user's guess of position\n",
+ "\n",
+ "\n",
+ "#set chosen to user's choice \n",
+ "if position == 1:\n",
+ " chosen = card1\n",
+ "elif position == 2:\n",
+ " chosen = card2\n",
+ "else:\n",
+ " chosen = card3\n",
+ "\n",
+ " \n",
+ "#is chosen card the prize?\n",
+ "x=chosen.isEqual(prize)\n",
+ "\n",
+ "\n",
+ "if x==1:\n",
+ " print 'That\\'s right! You win!'\n",
+ "else:\n",
+ " print 'Sorry. You lose.'\n",
+ "\n",
+ "print ' You choose the',\n",
+ "\n",
+ "\n",
+ "#display chosen card\n",
+ "chosen.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "card 1 is the 7 of clubs card 2 is the jack of hearts card 3 is the ace of spades \n",
+ "I'm swapping card 1 and card 3\n",
+ "I'm swapping card 2 and card 3\n",
+ "I'm swapping card 1 and card 2\n",
+ "Now, where (1,2, or 3) is the ace of spades ?"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Sorry. You lose.\n",
+ " You choose the 7 of clubs\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.11, Page Number: 249"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class foo: \n",
+ " \n",
+ " __count = 0 #only one data item for all objects\n",
+ " \n",
+ " def __init__(self):\n",
+ " foo.__count = foo.__count + 1 #increment count when object created\n",
+ " \n",
+ " def getcount(self): #returns count\n",
+ " return foo.__count\n",
+ "\n",
+ " \n",
+ " \n",
+ "#create three objecs\n",
+ "f1 = foo()\n",
+ "f2 = foo()\n",
+ "f3 = foo()\n",
+ "\n",
+ "#Each object displays the same count value\n",
+ "print 'count is', f1.getcount()\n",
+ "print 'count is', f2.getcount()\n",
+ "print 'count is', f3.getcount()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "count is 3\n",
+ "count is 3\n",
+ "count is 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.12, Page Number: 253"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor \n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ "\n",
+ " \n",
+ " #There's no const keyword \n",
+ " \n",
+ " def add_dist(self,d2): #add this length to d2 and return object\n",
+ " \n",
+ " temp = Distance()\n",
+ " temp.__inches = self.__inches + d2.__inches\n",
+ " \n",
+ " if temp.__inches >= 12.0:\n",
+ " temp.__inches = temp.__inches - 12.0\n",
+ " temp.__feet = 1\n",
+ " \n",
+ " temp.__feet = temp.__feet + self.__feet + d2.__feet\n",
+ " \n",
+ " return temp #return sum as object\n",
+ " \n",
+ " \n",
+ " \n",
+ "#define two length\n",
+ "dist1 = Distance()\n",
+ "dist3 = Distance()\n",
+ "\n",
+ "#define and initialize dist2\n",
+ "dist2 = Distance(11,6.25)\n",
+ "\n",
+ "#get dist1 from user\n",
+ "dist1.getdist()\n",
+ "\n",
+ "dist3 = dist1.add_dist(dist2)\n",
+ "\n",
+ "#display all lengths\n",
+ "print '\\ndist1 = ',\n",
+ "dist1.showdist()\n",
+ "print 'dist2 = ',\n",
+ "dist2.showdist()\n",
+ "print 'dist3 = ',\n",
+ "dist3.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet:17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches:5.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 17 ' - 5.75 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 29 ' - 0.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.13, Page Number: 255"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class distance\n",
+ " \n",
+ " def __init__(self,ft,inc): #constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get distance from user\n",
+ " self.__feet = input('Enter feet:')\n",
+ " self.__inches = input('Enter inches:')\n",
+ " \n",
+ " def showdist(self): #display the distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ "\n",
+ " \n",
+ "#initialize distance object\n",
+ "football = Distance(300,0)\n",
+ "\n",
+ "print 'football = ',\n",
+ "football.showdist()\n",
+ "\n",
+ "#There's no const keyword in python"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "football = 300 ' - 0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter7ArraysandStrings.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter7ArraysandStrings.ipynb
new file mode 100755
index 00000000..1fb6773a
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter7ArraysandStrings.ipynb
@@ -0,0 +1,1935 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:eea6a405d0bf81eb1385bd8d9cdbd2821e6bd3fe520748ab53e47eefcfeece69"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Arrays and Strings"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1, Page Number 264"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "age = []*4 #array 'age' of 4 \n",
+ "\n",
+ "for j in range(4): #get 4 ages\n",
+ " x = input(\"Enter an age: \")\n",
+ " age.append(x) #access array element\n",
+ "\n",
+ " \n",
+ "for j in range(4): #display 4 ages\n",
+ " print '\\nYou entered',age[j],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an age: 44\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an age: 16\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an age: 23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an age: 68\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "You entered 44 \n",
+ "You entered 16 \n",
+ "You entered 23 \n",
+ "You entered 68\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2, Page Number 267"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "SIZE = 6 #size of array\n",
+ "sales = []*SIZE #array of 6 variables\n",
+ "\n",
+ "print 'Enter widget sales for 6 days'\n",
+ "\n",
+ "for j in range(SIZE): #put figures in array\n",
+ " x = input()\n",
+ " sales.append(x)\n",
+ " \n",
+ "total = 0\n",
+ "\n",
+ "for j in range(SIZE): #read figures from array\n",
+ " total += sales[j] #to find total\n",
+ " \n",
+ "average = total / SIZE #find average\n",
+ "\n",
+ "print 'Average =',average,'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter widget sales for 6 days\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "352.64\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "867.70\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "781.32\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "867.35\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "746.21\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "189.45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average = 634.111666667 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3, Page Number 268"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "days_per_month = (31,28,31,30,31,30,31,31,30,31,30,31)\n",
+ "\n",
+ "month = input(\"Enter month (1 to 12): \") #get date\n",
+ "day = input(\"Enter day (1 to 31): \")\n",
+ "\n",
+ "\n",
+ "total_days = day #separate days\n",
+ "\n",
+ "for j in range(month-1): #add days each month\n",
+ " total_days += days_per_month[j] \n",
+ " \n",
+ "print 'Total days from start of year is:',total_days"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month (1 to 12): 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter day (1 to 31): 11\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total days from start of year is: 70\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.4, Page Number 270"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "DISRICTS = 4 #array dimensions\n",
+ "MONTHS = 3\n",
+ "\n",
+ "sales = [[0] * (DISRICTS+1) for i in range(MONTHS+1)] #two-dimensional array definition\n",
+ "\n",
+ "\n",
+ "print '',\n",
+ "for d in range(DISRICTS): #get array values\n",
+ " for m in range(MONTHS):\n",
+ " print 'Enter sales for district',d+1,\n",
+ " print ', month',m+1,': ',\n",
+ " sales[d][m] = input() #put number in array\n",
+ " \n",
+ " \n",
+ "print '\\n'\n",
+ "print ' month'\n",
+ "print ' 1 2 3',\n",
+ "\n",
+ "\n",
+ "for d in range(DISRICTS):\n",
+ " print '\\nDistrict',d+1,\n",
+ " for m in range(MONTHS):\n",
+ " print '%10.2f' %(sales[d][m]), #get number from array"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 1 , month 1 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3964.23\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 1 , month 2 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4135.87\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 1 , month 3 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4397.98\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 2 , month 1 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "867.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 2 , month 2 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "923.59\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 2 , month 3 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1037.01\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 3 , month 1 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12.77\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 3 , month 2 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "378.32\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 3 , month 3 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "798.22\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 4 , month 1 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2983.53\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 4 , month 2 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3983.73\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 4 , month 3 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9494.98\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ " month\n",
+ " 1 2 3 \n",
+ "District 1 3964.23 4135.87 4397.98 \n",
+ "District 2 867.75 923.59 1037.01 \n",
+ "District 3 12.77 378.32 798.22 \n",
+ "District 4 2983.53 3983.73 9494.98\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5, Page Number 273"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "DISRICTS = 4 #array dimensions\n",
+ "MONTHS = 3\n",
+ "\n",
+ " #initialize array elements\n",
+ "sales = [[1432.07,234.50,654.01],\n",
+ " [322.00,13838.32,17589.88],\n",
+ " [9328.34,934.00,4492.30],\n",
+ " [12838.29,2332.63,32.98]]\n",
+ " \n",
+ "print '\\n'\n",
+ "print ' month'\n",
+ "print ' 1 2 3',\n",
+ "\n",
+ "\n",
+ "for d in range(DISRICTS): #display array elements\n",
+ " print '\\nDistrict',d+1,\n",
+ " \n",
+ " for m in range(MONTHS):\n",
+ " print '%10.2f' %(sales[d][m]), #access array elements"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ " month\n",
+ " 1 2 3 \n",
+ "District 1 1432.07 234.50 654.01 \n",
+ "District 2 322.00 13838.32 17589.88 \n",
+ "District 3 9328.34 934.00 4492.30 \n",
+ "District 4 12838.29 2332.63 32.98\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.6, Page Number 274"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "DISRICTS = 4 #array dimensions\n",
+ "MONTHS = 3\n",
+ "\n",
+ "def display(funsales): #function for display array elements\n",
+ " print '\\n'\n",
+ " print ' month'\n",
+ " print ' 1 2 3',\n",
+ "\n",
+ " for d in range(DISRICTS):\n",
+ " print '\\nDistrict',d+1,\n",
+ " for m in range(MONTHS):\n",
+ " print '%10.2f' %(sales[d][m]), #access array elements\n",
+ " \n",
+ " \n",
+ " \n",
+ "sales = [[1432.07,234.50,654.01], #initialize two-dimentional array\n",
+ " [322.00,13838.32,17589.88],\n",
+ " [9328.34,934.00,4492.30],\n",
+ " [12838.29,2332.63,32.98]]\n",
+ "\n",
+ "display(sales) #call function; array as argument"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ " month\n",
+ " 1 2 3 \n",
+ "District 1 1432.07 234.50 654.01 \n",
+ "District 2 322.00 13838.32 17589.88 \n",
+ "District 3 9328.34 934.00 4492.30 \n",
+ "District 4 12838.29 2332.63 32.98\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7, Page Number 277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "SIZE = 4 #number of parts in array\n",
+ "\n",
+ "class part: #specify a structure\n",
+ " modelnumber = None #ID number of widget\n",
+ " partnumber = None #ID number of widget part\n",
+ " cost = None #cost of part\n",
+ " \n",
+ " \n",
+ " \n",
+ "apart = [part() for i in range(SIZE)] #define array of structures\n",
+ "\n",
+ "\n",
+ "for n in range(SIZE): #get values for all members\n",
+ " apart[n].modelnumber = input('Enter model number: ') #get model number\n",
+ " apart[n].partnumber = input('Enter part number: ') #get part number\n",
+ " apart[n].cost = input('Enter cost: ') #get cost\n",
+ " print \n",
+ " \n",
+ " \n",
+ "for n in range(SIZE): #show values for all members\n",
+ " print 'Model',apart[n].modelnumber,\n",
+ " print ' Part',apart[n].partnumber,\n",
+ " print ' Cost',apart[n].cost"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter model number: 44\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part number: 4954\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter cost: 133.45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter model number: 44\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part number: 8431\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter cost: 97.59\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter model number: 77\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part number: 9343\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter cost: 109.99\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter model number: 77\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part number: 4297\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter cost: 3456.55\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Model 44 Part 4954 Cost 133.45\n",
+ "Model 44 Part 8431 Cost 97.59\n",
+ "Model 77 Part 9343 Cost 109.99\n",
+ "Model 77 Part 4297 Cost 3456.55\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8, Page Number 279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Stack:\n",
+ " __max = 10 #define maximum size of stack array\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__st = [0 for i in range(self.__max)] #stack: array of integers\n",
+ " self.__top = -1 #number of top of stack, initially -1\n",
+ " \n",
+ " def push(self,var): #put number on stack\n",
+ " self.__top += 1\n",
+ " self.__st[self.__top] = var\n",
+ " \n",
+ " def pop(self): #take number from stack\n",
+ " x = self.__st[self.__top]\n",
+ " self.__top -= 1\n",
+ " return x\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = Stack() #define a stack variable\n",
+ "\n",
+ "s1.push(11) #push value on stack\n",
+ "s1.push(22)\n",
+ "\n",
+ "print '1:',s1.pop() #pop value from stack, and display it\n",
+ "print '2:',s1.pop()\n",
+ "\n",
+ "s1.push(33) #push values on stack\n",
+ "s1.push(44)\n",
+ "s1.push(55)\n",
+ "s1.push(66)\n",
+ "\n",
+ "print '3:',s1.pop() #pop values from stack\n",
+ "print '4:',s1.pop()\n",
+ "print '5:',s1.pop()\n",
+ "print '6:',s1.pop()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1: 22\n",
+ "2: 11\n",
+ "3: 66\n",
+ "4: 55\n",
+ "5: 44\n",
+ "6: 33\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9, Page Number 283"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def getdist(self): #get length from usser\n",
+ " self.__feet = input(' Enter feet: ')\n",
+ " self.__inches = input(' Enter inches: ')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet,'\\' -',self.__inches,'\\\"',\n",
+ " \n",
+ " \n",
+ " \n",
+ "dist = [Distance() for i in range(100)] #array of distances\n",
+ "n = 0 #count the entries\n",
+ "\n",
+ "\n",
+ "while True: #get distances from user\n",
+ " \n",
+ " print '\\nEnter distance number',n+1\n",
+ " dist[n].getdist() #store distances in array\n",
+ " n += 1 \n",
+ " \n",
+ " ans = raw_input('Enter another (y/n)?: ')\n",
+ " if(ans == 'n'): #quit if user types 'n'\n",
+ " break\n",
+ " \n",
+ "for j in range(n): #display all distances\n",
+ " print '\\nDistance number',j+1,'is',\n",
+ " dist[j].showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter distance number 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter inches: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)?: y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter distance number 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter feet: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter inches: 2.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)?: y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter distance number 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter inches: 10.75\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)?: n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Distance number 1 is 5 ' - 4 \" \n",
+ "Distance number 2 is 6 ' - 2.5 \" \n",
+ "Distance number 3 is 5 ' - 10.75 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10, Page Number 286"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import random #for selecting random number\n",
+ "\n",
+ "symbols = ['\u2663','\u2666','\u2665','\u2660'] #array for printing the symbol of cards\n",
+ "Suit = [\"clubs\",\"diamonds\",\"hearts\",\"spades\"] \n",
+ "\n",
+ "\n",
+ "#from 2 to 10 are integers without names\n",
+ "jack = 11 \n",
+ "queen = 12 \n",
+ "king = 13\n",
+ "ace = 14\n",
+ "\n",
+ "\n",
+ "class card: \n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__number = None\n",
+ " self.__suit = None\n",
+ " \n",
+ " def set(self,n,s):\n",
+ " self.__number = n #2 to 10, jack, queen, king, ace\n",
+ " self.__suit = s #clubs, diamonds, hearts, spades\n",
+ " \n",
+ " \n",
+ " def display(self): #display the cards\n",
+ " \n",
+ " if self.__number >= 2 and self.__number <= 10: #display the card number\n",
+ " print self.__number ,\n",
+ " \n",
+ " else:\n",
+ " if self.__number == jack:\n",
+ " print 'J',\n",
+ " elif self.__number == queen:\n",
+ " print 'Q',\n",
+ " elif self.__number == king:\n",
+ " print 'K',\n",
+ " elif self.__number == ace:\n",
+ " print 'A',\n",
+ " \n",
+ " if self.__suit == \"clubs\": #dispaly the symbol\n",
+ " print symbols[0],\n",
+ " elif self.__suit == \"diamonds\":\n",
+ " print symbols[1],\n",
+ " elif self.__suit == \"hearts\":\n",
+ " print symbols[2],\n",
+ " elif self.__suit == \"spades\":\n",
+ " print symbols[3],\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "deck = [card() for j in range(52)] #array of cards\n",
+ "\n",
+ "for j in range(52): #make an ordered deck\n",
+ " num = (j % 13) + 2 #cycles through 2 to 14, 4 times\n",
+ " su = Suit[j / 13] #cycles through 0 to 3, 13 times\n",
+ " deck[j].set(num,su) #set cards\n",
+ "\n",
+ " \n",
+ "print '\\nOrderd deck:'\n",
+ "\n",
+ "for j in range(52): #display ordered deck\n",
+ " deck[j].display()\n",
+ " print '',\n",
+ " if (j+1)%13 == 0: #new line every 13 cards\n",
+ " print\n",
+ "\n",
+ " \n",
+ " \n",
+ "for j in range(52): #for each card in deck,\n",
+ " \n",
+ " k = random.randrange(2,52)%52 #pick card at random\n",
+ " \n",
+ " temp = deck[j] #and swap them\n",
+ " deck[j] = deck[k]\n",
+ " deck[k] = temp\n",
+ "\n",
+ "print '\\nshuffled deck:'\n",
+ "\n",
+ "for j in range(52): #display suffled card\n",
+ " deck[j].display() \n",
+ " print '',\n",
+ " if (j+1)%13 == 0: #new line every 13 cards\n",
+ " print"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Orderd deck:\n",
+ "2 \u2663 3 \u2663 4 \u2663 5 \u2663 6 \u2663 7 \u2663 8 \u2663 9 \u2663 10 \u2663 J \u2663 Q \u2663 K \u2663 A \u2663 \n",
+ "2 \u2666 3 \u2666 4 \u2666 5 \u2666 6 \u2666 7 \u2666 8 \u2666 9 \u2666 10 \u2666 J \u2666 Q \u2666 K \u2666 A \u2666 \n",
+ "2 \u2665 3 \u2665 4 \u2665 5 \u2665 6 \u2665 7 \u2665 8 \u2665 9 \u2665 10 \u2665 J \u2665 Q \u2665 K \u2665 A \u2665 \n",
+ "2 \u2660 3 \u2660 4 \u2660 5 \u2660 6 \u2660 7 \u2660 8 \u2660 9 \u2660 10 \u2660 J \u2660 Q \u2660 K \u2660 A \u2660 \n",
+ "\n",
+ "shuffled deck:\n",
+ "5 \u2663 2 \u2666 A \u2666 J \u2665 7 \u2663 A \u2663 7 \u2665 J \u2666 10 \u2666 K \u2665 2 \u2660 9 \u2663 4 \u2666 \n",
+ "10 \u2660 8 \u2666 6 \u2666 A \u2665 J \u2663 K \u2666 4 \u2660 3 \u2666 4 \u2663 Q \u2666 4 \u2665 5 \u2665 3 \u2660 \n",
+ "10 \u2663 9 \u2660 Q \u2663 3 \u2663 6 \u2663 8 \u2663 3 \u2665 6 \u2660 8 \u2665 2 \u2663 5 \u2666 6 \u2665 K \u2660 \n",
+ "A \u2660 9 \u2666 J \u2660 7 \u2660 Q \u2665 2 \u2665 8 \u2660 5 \u2660 7 \u2666 Q \u2660 10 \u2665 9 \u2665 K \u2663 \n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.11, Page Number 290"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 80 #max characters in string\n",
+ "str = [0 for i in range(MAX)] #string variable str\n",
+ "\n",
+ "str = raw_input(\"Enter a string \") #put string in str\n",
+ "\n",
+ "print 'You entered:',str #display string from str"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string amanuensis\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered: amanuensis\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.12, Page Number 292"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 20 #max characters in string\n",
+ "str = []*MAX #string variable str\n",
+ "\n",
+ "str = raw_input(\"Enter a string: \") #put string in str\n",
+ "\n",
+ "print 'You entered: %20s' %str #display string from str"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string: hello world.....\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered: hello world.....\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.13, Page Number 292"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str = []\n",
+ "\n",
+ "str = \"Farewell! thou art too dear for my possessing.\" #store string in an array\n",
+ "\n",
+ "print str,'\\n' #print array"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Farewell! thou art too dear for my possessing. \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.14, Page Number 293"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 20 #max characters in string\n",
+ "str = []*MAX #string variable str\n",
+ "\n",
+ "str = raw_input(\"Enter a string: \") #put string in str\n",
+ "\n",
+ "print 'You entered:',str #display string from str"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string: Law is a bottomless pit.\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered: Law is a bottomless pit.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.15, Page Number 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print 'Enter a string:'\n",
+ "\n",
+ "str = \"\" #string variable\n",
+ "stopword = \"$\" #taking for checking the termination condition\n",
+ "\n",
+ "\n",
+ "while True:\n",
+ " \n",
+ " line = raw_input() #taking input line by line\n",
+ " \n",
+ " if line.strip() == stopword: #stop when tenmination condition matches\n",
+ " break\n",
+ " \n",
+ " str += \"%s\\n\" % line\n",
+ " \n",
+ " \n",
+ "print 'You entered:'\n",
+ "print str #print the whole string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ask me no more where Jove bestows\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "When June is past, the fading rose;\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For in your beauty's orient deep\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "These flowers, as in their causes, sleep.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "$\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered:\n",
+ "Ask me no more where Jove bestows\n",
+ "When June is past, the fading rose;\n",
+ "For in your beauty's orient deep\n",
+ "These flowers, as in their causes, sleep.\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.16, Page Number 295"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str1 = [] #initialized string\n",
+ "str1 = \"Oh, Captain, my Captain! our fearful trip is done\"\n",
+ "\n",
+ "MAX = 80 #size of str2 buffer\n",
+ "str2 = [None]*MAX #empty string\n",
+ "\n",
+ "str2 = ''.join(str1) #copy str1 character to str2\n",
+ "\n",
+ "print str2 #print str2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Oh, Captain, my Captain! our fearful trip is done\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.17, Page Number 296"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str1 = []\n",
+ "\n",
+ "str1 = \"Tiger, tiger, burning bright\\nIn the forests of the night\"\n",
+ "\n",
+ "MAX = 80 #size of str2 buffer\n",
+ "str2 = str1 #copy str1 to str2\n",
+ "\n",
+ "print str2 #display str2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tiger, tiger, burning bright\n",
+ "In the forests of the night\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.18, Page Number 297"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Days = 7 #number of string in array\n",
+ "\n",
+ "star = [\"Sunday\" , \"Monday\" , \"Tuesday\" , \"Wednesday\" , \"Thursday\" , \"Friday\" , \"Saturday\"] #arrray of string\n",
+ "\n",
+ "for j in range(Days): #display every string\n",
+ " print star[j]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sunday\n",
+ "Monday\n",
+ "Tuesday\n",
+ "Wednesday\n",
+ "Thursday\n",
+ "Friday\n",
+ "Saturday\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.19, Page Number 298"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class part:\n",
+ " \n",
+ " def setpart(self,pname,pn,c): #set data\n",
+ " self.__partname = pname\n",
+ " self.__partnumber = pn\n",
+ " self.__cost = c\n",
+ " \n",
+ " def showpart(self): #display data \n",
+ " print 'Name %s,' %self.__partname,\n",
+ " print 'number %d,' %self.__partnumber,\n",
+ " print 'costs $%.2f' %self.__cost\n",
+ " \n",
+ " \n",
+ "#define part objects \n",
+ "part1 = part()\n",
+ "part2 = part()\n",
+ "\n",
+ "part1.setpart(\"handle bolt\",4473,217.55) #set parts\n",
+ "part2.setpart(\"start level\",9924,419.25)\n",
+ " \n",
+ "print 'First part:' #show part\n",
+ "part1.showpart()\n",
+ "print 'Second parrt:'\n",
+ "part2.showpart()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First part:\n",
+ "Name handle bolt, number 4473, costs $217.55\n",
+ "Second parrt:\n",
+ "Name start level, number 9924, costs $419.25\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example 7.20, Page Number 300"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class String:\n",
+ " \n",
+ " def __init__(self,s = '\\0'): #overloaded constructor\n",
+ " self.__str = s\n",
+ " \n",
+ " def display(self): #display string\n",
+ " print self.__str\n",
+ " \n",
+ " def concat(self,s2): #add argument string to this string\n",
+ " if len(self.__str)+len(s2.__str) < 80:\n",
+ " self.__str = self.__str + s2.__str\n",
+ " else:\n",
+ " print 'String too long'\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = String(\"Merry Christmas! \") #define the string\n",
+ "s2 = String(\"Season's Greetings!\")\n",
+ "s3 = String()\n",
+ "\n",
+ "print 's1 =', #display them all\n",
+ "s1.display()\n",
+ "print 's2 =',\n",
+ "s2.display()\n",
+ "print 's3 =',\n",
+ "s3.display()\n",
+ "\n",
+ "s3 = s1 #assignment\n",
+ "\n",
+ "print 's3 =', #display s3\n",
+ "s3.display()\n",
+ "\n",
+ "s3.concat(s2) #concatenation\n",
+ "\n",
+ "print 's3 =', #display s3\n",
+ "s3.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s1 = Merry Christmas! \n",
+ "s2 = Season's Greetings!\n",
+ "s3 = \u0000\n",
+ "s3 = Merry Christmas! \n",
+ "s3 = Merry Christmas! Season's Greetings!\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.21, Page Number 303"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s1 = \"Man\" #initialize\n",
+ "s2 = \"Beast\"\n",
+ "\n",
+ "s3 = s1 #assign\n",
+ "print 's3 =',s3\n",
+ "\n",
+ "s3 = \"Neither \" + s1 + \" Nor \" #concatenate\n",
+ "s3 += s2 #concatenate\n",
+ "print 's3 =',s3\n",
+ " \n",
+ "s4 = s2 #swap s1 and s2\n",
+ "s2 = s1\n",
+ "s1 = s4\n",
+ "\n",
+ "print s1 , 'nor' , s2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s3 = Man\n",
+ "s3 = Neither Man Nor Beast\n",
+ "Beast nor Man\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.22, Page Number 304"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "greeting = \"Hello, \"\n",
+ "\n",
+ "full_name = raw_input(\"Enter your full name: \") #get the name of user\n",
+ "print 'Your full name is:',full_name\n",
+ "\n",
+ "nickname = raw_input(\"Enter your nickname: \") #get the nickname\n",
+ " \n",
+ "greeting += nickname #append name with greeting\n",
+ "print greeting #output: \"Hello, Jim\"\n",
+ "\n",
+ "print 'Enter your address on separate lines'\n",
+ "print 'Terminate with \\'$\\''\n",
+ "\n",
+ "address = \"\"\n",
+ "stopword = \"$\"\n",
+ "\n",
+ "while True:\n",
+ " line = raw_input() #taking input line by line\n",
+ " if line.strip() == stopword: #stop when tenmination condition matches\n",
+ " break\n",
+ " address += \"%s\\n\" % line\n",
+ " \n",
+ "print 'Your address is:'\n",
+ "print address #print the whole string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your full name: F. Scott Fitzgerald\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your full name is: F. Scott Fitzgerald\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your nickname: Scotty\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello, Scotty\n",
+ "Enter your address on separate lines\n",
+ "Terminate with '$'\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1922 Zelda Lane\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "East Egg, New York\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "$\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your address is:\n",
+ "1922 Zelda Lane\n",
+ "East Egg, New York\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.23, Page Number 305"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def find_first_not_of(s1,s2):\n",
+ " \n",
+ " a = len(s2) #length of the string to be checked\n",
+ " \n",
+ " arr = [99 for j in range(a)] #array for storing the matches index\n",
+ " \n",
+ " for j in range(a):\n",
+ " n = s1.find(s2[j]) #A character of second string is present in the first string then \n",
+ " if n!=-1:\n",
+ " arr[j] = n #put the index in the array\n",
+ " \n",
+ " arr.sort() #sort the array to check first occarence\n",
+ " \n",
+ " return arr[0]+1 #return the first index\n",
+ "\n",
+ "\n",
+ "\n",
+ "s1 = \"In xanada did Kubla Kahn a stately pleasure dome decree\"\n",
+ "\n",
+ "n = s1.find(\"Kubla\")\n",
+ "print 'Found kubla at',n\n",
+ "\n",
+ "n = s1.index(\"d\")\n",
+ "print 'First of spde at',n\n",
+ "\n",
+ "n = find_first_not_of(s1,\"aeiouAEIOU\")\n",
+ "print 'Found consonant at',n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Found kubla at 14\n",
+ "First of spde at 7\n",
+ "Found consonant at 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.24, Page Number 306"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s1 = \"Quick! Send for Count Graystone.\"\n",
+ "s2 = \"Lord\"\n",
+ "s3 = \"Don't \"\n",
+ "\n",
+ "s1 = s1[7:] #remove \"Quick! \"\n",
+ "s1 = s1.replace(\"Count\",s2) #replace \"Count\" with \"Lord\"\n",
+ "s1 = s1.replace(\"S\",\"s\") #replace 'S' with 's'\n",
+ "s1 = s3 + s1 #insert \"Don't \" at beginning\n",
+ "s1 = s1[:-1] #remove '.'\n",
+ "s1 = s1 + \"!!!\" #append \"!!!\"\n",
+ "s1 = s1.replace(\" \",\"/\") #replace all white space with '/'\n",
+ " \n",
+ "print s1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Don't/send/for/Lord/Graystone!!!\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.25, Page Number 308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "aName = \"George\"\n",
+ "\n",
+ "username = raw_input(\"Enter your first name: \")\n",
+ "\n",
+ "if username == aName: #operator ==\n",
+ " print \"Greetings, George\"\n",
+ " \n",
+ "elif username < aName: #operator <\n",
+ " print 'You come before George'\n",
+ " \n",
+ "else:\n",
+ " print 'You come after George'\n",
+ " \n",
+ " \n",
+ " \n",
+ "print 'The first two letters of your name', \n",
+ "\n",
+ "username = username[:2]\n",
+ "aName = aName[:2]\n",
+ "\n",
+ "if username == aName:\n",
+ " print \"match\",\n",
+ "elif username < aName:\n",
+ " print 'come before',\n",
+ "else:\n",
+ " print 'come after',\n",
+ "print aName"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your first name: Alfred\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You come before George\n",
+ "The first two letters of your name come before Ge\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.26, Page Number 309"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "word = raw_input(\"Enter a word: \") #take string from user\n",
+ "wlen = len(word) #length of string object\n",
+ "\n",
+ "print 'One character at a time: ',\n",
+ "for j in range(wlen):\n",
+ " print word[j],\n",
+ " \n",
+ "charray = []*80\n",
+ "charray = word #copy string object to another object\n",
+ "print '\\nArray contains:',charray"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a word: symbiosis\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "One character at a time: s y m b i o s i s \n",
+ "Array contains: symbiosis\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter7ArraysandStrings_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter7ArraysandStrings_1.ipynb
new file mode 100755
index 00000000..b76fb4d0
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter7ArraysandStrings_1.ipynb
@@ -0,0 +1,1935 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e4af9d6bbf1b5a92f88572c51525b9ad8e4c754430f95057ab8dd612a4d4120a"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Arrays and Strings"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1, Page Number 264"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "age = []*4 #array 'age' of 4 \n",
+ "\n",
+ "for j in range(4): #get 4 ages\n",
+ " x = input(\"Enter an age: \")\n",
+ " age.append(x) #access array element\n",
+ "\n",
+ " \n",
+ "for j in range(4): #display 4 ages\n",
+ " print '\\nYou entered',age[j],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an age: 44\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an age: 16\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an age: 23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an age: 68\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "You entered 44 \n",
+ "You entered 16 \n",
+ "You entered 23 \n",
+ "You entered 68\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2, Page Number 267"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "SIZE = 6 #size of array\n",
+ "sales = []*SIZE #array of 6 variables\n",
+ "\n",
+ "print 'Enter widget sales for 6 days'\n",
+ "\n",
+ "for j in range(SIZE): #put figures in array\n",
+ " x = input()\n",
+ " sales.append(x)\n",
+ " \n",
+ "total = 0\n",
+ "\n",
+ "for j in range(SIZE): #read figures from array\n",
+ " total += sales[j] #to find total\n",
+ " \n",
+ "average = total / SIZE #find average\n",
+ "\n",
+ "print 'Average =',average,'\\n'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter widget sales for 6 days\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "352.64\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "867.70\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "781.32\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "867.35\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "746.21\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "189.45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average = 634.111666667 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3, Page Number 268"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "days_per_month = (31,28,31,30,31,30,31,31,30,31,30,31)\n",
+ "\n",
+ "month = input(\"Enter month (1 to 12): \") #get date\n",
+ "day = input(\"Enter day (1 to 31): \")\n",
+ "\n",
+ "\n",
+ "total_days = day #separate days\n",
+ "\n",
+ "for j in range(month-1): #add days each month\n",
+ " total_days += days_per_month[j] \n",
+ " \n",
+ "print 'Total days from start of year is:',total_days"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month (1 to 12): 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter day (1 to 31): 11\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total days from start of year is: 70\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.4, Page Number 270"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "DISRICTS = 4 #array dimensions\n",
+ "MONTHS = 3\n",
+ "\n",
+ "sales = [[0] * (DISRICTS+1) for i in range(MONTHS+1)] #two-dimensional array definition\n",
+ "\n",
+ "\n",
+ "print '',\n",
+ "for d in range(DISRICTS): #get array values\n",
+ " for m in range(MONTHS):\n",
+ " print 'Enter sales for district',d+1,\n",
+ " print ', month',m+1,': ',\n",
+ " sales[d][m] = input() #put number in array\n",
+ " \n",
+ " \n",
+ "print '\\n'\n",
+ "print ' month'\n",
+ "print ' 1 2 3',\n",
+ "\n",
+ "\n",
+ "for d in range(DISRICTS):\n",
+ " print '\\nDistrict',d+1,\n",
+ " for m in range(MONTHS):\n",
+ " print '%10.2f' %(sales[d][m]), #get number from array"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 1 , month 1 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3964.23\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 1 , month 2 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4135.87\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 1 , month 3 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4397.98\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 2 , month 1 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "867.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 2 , month 2 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "923.59\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 2 , month 3 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1037.01\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 3 , month 1 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12.77\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 3 , month 2 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "378.32\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 3 , month 3 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "798.22\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 4 , month 1 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2983.53\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 4 , month 2 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3983.73\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter sales for district 4 , month 3 : "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9494.98\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "\n",
+ " month\n",
+ " 1 2 3 \n",
+ "District 1 3964.23 4135.87 4397.98 \n",
+ "District 2 867.75 923.59 1037.01 \n",
+ "District 3 12.77 378.32 798.22 \n",
+ "District 4 2983.53 3983.73 9494.98\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5, Page Number 273"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "DISRICTS = 4 #array dimensions\n",
+ "MONTHS = 3\n",
+ "\n",
+ " #initialize array elements\n",
+ "sales = [[1432.07,234.50,654.01],\n",
+ " [322.00,13838.32,17589.88],\n",
+ " [9328.34,934.00,4492.30],\n",
+ " [12838.29,2332.63,32.98]]\n",
+ " \n",
+ "print '\\n'\n",
+ "print ' month'\n",
+ "print ' 1 2 3',\n",
+ "\n",
+ "\n",
+ "for d in range(DISRICTS): #display array elements\n",
+ " print '\\nDistrict',d+1,\n",
+ " \n",
+ " for m in range(MONTHS):\n",
+ " print '%10.2f' %(sales[d][m]), #access array elements"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ " month\n",
+ " 1 2 3 \n",
+ "District 1 1432.07 234.50 654.01 \n",
+ "District 2 322.00 13838.32 17589.88 \n",
+ "District 3 9328.34 934.00 4492.30 \n",
+ "District 4 12838.29 2332.63 32.98\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.6, Page Number 274"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "DISRICTS = 4 #array dimensions\n",
+ "MONTHS = 3\n",
+ "\n",
+ "def display(funsales): #function for display array elements\n",
+ " print '\\n'\n",
+ " print ' month'\n",
+ " print ' 1 2 3',\n",
+ "\n",
+ " for d in range(DISRICTS):\n",
+ " print '\\nDistrict',d+1,\n",
+ " for m in range(MONTHS):\n",
+ " print '%10.2f' %(sales[d][m]), #access array elements\n",
+ " \n",
+ " \n",
+ " \n",
+ "sales = [[1432.07,234.50,654.01], #initialize two-dimentional array\n",
+ " [322.00,13838.32,17589.88],\n",
+ " [9328.34,934.00,4492.30],\n",
+ " [12838.29,2332.63,32.98]]\n",
+ "\n",
+ "display(sales) #call function; array as argument"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ " month\n",
+ " 1 2 3 \n",
+ "District 1 1432.07 234.50 654.01 \n",
+ "District 2 322.00 13838.32 17589.88 \n",
+ "District 3 9328.34 934.00 4492.30 \n",
+ "District 4 12838.29 2332.63 32.98\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7, Page Number 277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "SIZE = 4 #number of parts in array\n",
+ "\n",
+ "class part: #specify a structure\n",
+ " modelnumber = None #ID number of widget\n",
+ " partnumber = None #ID number of widget part\n",
+ " cost = None #cost of part\n",
+ " \n",
+ " \n",
+ " \n",
+ "apart = [part() for i in range(SIZE)] #define array of structures\n",
+ "\n",
+ "\n",
+ "for n in range(SIZE): #get values for all members\n",
+ " apart[n].modelnumber = input('Enter model number: ') #get model number\n",
+ " apart[n].partnumber = input('Enter part number: ') #get part number\n",
+ " apart[n].cost = input('Enter cost: ') #get cost\n",
+ " print \n",
+ " \n",
+ " \n",
+ "for n in range(SIZE): #show values for all members\n",
+ " print 'Model',apart[n].modelnumber,\n",
+ " print ' Part',apart[n].partnumber,\n",
+ " print ' Cost',apart[n].cost"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter model number: 44\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part number: 4954\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter cost: 133.45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter model number: 44\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part number: 8431\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter cost: 97.59\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter model number: 77\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part number: 9343\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter cost: 109.99\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter model number: 77\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part number: 4297\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter cost: 3456.55\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Model 44 Part 4954 Cost 133.45\n",
+ "Model 44 Part 8431 Cost 97.59\n",
+ "Model 77 Part 9343 Cost 109.99\n",
+ "Model 77 Part 4297 Cost 3456.55\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8, Page Number 279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Stack:\n",
+ " __max = 10 #define maximum size of stack array\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__st = [0 for i in range(self.__max)] #stack: array of integers\n",
+ " self.__top = -1 #number of top of stack, initially -1\n",
+ " \n",
+ " def push(self,var): #put number on stack\n",
+ " self.__top += 1\n",
+ " self.__st[self.__top] = var\n",
+ " \n",
+ " def pop(self): #take number from stack\n",
+ " x = self.__st[self.__top]\n",
+ " self.__top -= 1\n",
+ " return x\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = Stack() #define a stack variable\n",
+ "\n",
+ "s1.push(11) #push value on stack\n",
+ "s1.push(22)\n",
+ "\n",
+ "print '1:',s1.pop() #pop value from stack, and display it\n",
+ "print '2:',s1.pop()\n",
+ "\n",
+ "s1.push(33) #push values on stack\n",
+ "s1.push(44)\n",
+ "s1.push(55)\n",
+ "s1.push(66)\n",
+ "\n",
+ "print '3:',s1.pop() #pop values from stack\n",
+ "print '4:',s1.pop()\n",
+ "print '5:',s1.pop()\n",
+ "print '6:',s1.pop()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1: 22\n",
+ "2: 11\n",
+ "3: 66\n",
+ "4: 55\n",
+ "5: 44\n",
+ "6: 33\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9, Page Number 283"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def getdist(self): #get length from usser\n",
+ " self.__feet = input(' Enter feet: ')\n",
+ " self.__inches = input(' Enter inches: ')\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet,'\\' -',self.__inches,'\\\"',\n",
+ " \n",
+ " \n",
+ " \n",
+ "dist = [Distance() for i in range(100)] #array of distances\n",
+ "n = 0 #count the entries\n",
+ "\n",
+ "\n",
+ "while True: #get distances from user\n",
+ " \n",
+ " print '\\nEnter distance number',n+1\n",
+ " dist[n].getdist() #store distances in array\n",
+ " n += 1 \n",
+ " \n",
+ " ans = raw_input('Enter another (y/n)?: ')\n",
+ " if(ans == 'n'): #quit if user types 'n'\n",
+ " break\n",
+ " \n",
+ "for j in range(n): #display all distances\n",
+ " print '\\nDistance number',j+1,'is',\n",
+ " dist[j].showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter distance number 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter inches: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)?: y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter distance number 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter feet: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter inches: 2.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)?: y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter distance number 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter inches: 10.75\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another (y/n)?: n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Distance number 1 is 5 ' - 4 \" \n",
+ "Distance number 2 is 6 ' - 2.5 \" \n",
+ "Distance number 3 is 5 ' - 10.75 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10, Page Number 286"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from random import randrange #for selecting random number\n",
+ "\n",
+ "symbols = ['\u2663','\u2666','\u2665','\u2660'] #array for printing the symbol of cards\n",
+ "Suit = [\"clubs\",\"diamonds\",\"hearts\",\"spades\"] \n",
+ "\n",
+ "\n",
+ "#from 2 to 10 are integers without names\n",
+ "jack = 11 \n",
+ "queen = 12 \n",
+ "king = 13\n",
+ "ace = 14\n",
+ "\n",
+ "\n",
+ "class card: \n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self.__number = None\n",
+ " self.__suit = None\n",
+ " \n",
+ " def set(self,n,s):\n",
+ " self.__number = n #2 to 10, jack, queen, king, ace\n",
+ " self.__suit = s #clubs, diamonds, hearts, spades\n",
+ " \n",
+ " \n",
+ " def display(self): #display the cards\n",
+ " \n",
+ " if self.__number >= 2 and self.__number <= 10: #display the card number\n",
+ " print self.__number ,\n",
+ " \n",
+ " else:\n",
+ " if self.__number == jack:\n",
+ " print 'J',\n",
+ " elif self.__number == queen:\n",
+ " print 'Q',\n",
+ " elif self.__number == king:\n",
+ " print 'K',\n",
+ " elif self.__number == ace:\n",
+ " print 'A',\n",
+ " \n",
+ " if self.__suit == \"clubs\": #dispaly the symbol\n",
+ " print symbols[0],\n",
+ " elif self.__suit == \"diamonds\":\n",
+ " print symbols[1],\n",
+ " elif self.__suit == \"hearts\":\n",
+ " print symbols[2],\n",
+ " elif self.__suit == \"spades\":\n",
+ " print symbols[3],\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "deck = [card() for j in range(52)] #array of cards\n",
+ "\n",
+ "for j in range(52): #make an ordered deck\n",
+ " num = (j % 13) + 2 #cycles through 2 to 14, 4 times\n",
+ " su = Suit[j / 13] #cycles through 0 to 3, 13 times\n",
+ " deck[j].set(num,su) #set cards\n",
+ "\n",
+ " \n",
+ "print '\\nOrderd deck:'\n",
+ "\n",
+ "for j in range(52): #display ordered deck\n",
+ " deck[j].display()\n",
+ " print '',\n",
+ " if (j+1)%13 == 0: #new line every 13 cards\n",
+ " print\n",
+ "\n",
+ " \n",
+ " \n",
+ "for j in range(52): #for each card in deck,\n",
+ " \n",
+ " k = randrange(2,52)%52 #pick card at random\n",
+ " \n",
+ " temp = deck[j] #and swap them\n",
+ " deck[j] = deck[k]\n",
+ " deck[k] = temp\n",
+ "\n",
+ "print '\\nshuffled deck:'\n",
+ "\n",
+ "for j in range(52): #display suffled card\n",
+ " deck[j].display() \n",
+ " print '',\n",
+ " if (j+1)%13 == 0: #new line every 13 cards\n",
+ " print"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Orderd deck:\n",
+ "2 \u2663 3 \u2663 4 \u2663 5 \u2663 6 \u2663 7 \u2663 8 \u2663 9 \u2663 10 \u2663 J \u2663 Q \u2663 K \u2663 A \u2663 \n",
+ "2 \u2666 3 \u2666 4 \u2666 5 \u2666 6 \u2666 7 \u2666 8 \u2666 9 \u2666 10 \u2666 J \u2666 Q \u2666 K \u2666 A \u2666 \n",
+ "2 \u2665 3 \u2665 4 \u2665 5 \u2665 6 \u2665 7 \u2665 8 \u2665 9 \u2665 10 \u2665 J \u2665 Q \u2665 K \u2665 A \u2665 \n",
+ "2 \u2660 3 \u2660 4 \u2660 5 \u2660 6 \u2660 7 \u2660 8 \u2660 9 \u2660 10 \u2660 J \u2660 Q \u2660 K \u2660 A \u2660 \n",
+ "\n",
+ "shuffled deck:\n",
+ "J \u2666 5 \u2666 7 \u2663 7 \u2666 4 \u2666 2 \u2666 J \u2663 10 \u2665 5 \u2663 8 \u2663 6 \u2665 2 \u2665 6 \u2663 \n",
+ "8 \u2666 3 \u2660 8 \u2660 K \u2660 7 \u2660 2 \u2660 Q \u2665 K \u2666 6 \u2660 10 \u2660 8 \u2665 6 \u2666 K \u2663 \n",
+ "7 \u2665 10 \u2666 3 \u2666 Q \u2666 Q \u2660 J \u2665 9 \u2666 9 \u2665 9 \u2660 J \u2660 K \u2665 4 \u2663 A \u2665 \n",
+ "4 \u2665 5 \u2665 A \u2663 5 \u2660 2 \u2663 4 \u2660 9 \u2663 Q \u2663 A \u2666 3 \u2665 3 \u2663 10 \u2663 A \u2660 \n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.11, Page Number 290"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 80 #max characters in string\n",
+ "str = [0 for i in range(MAX)] #string variable str\n",
+ "\n",
+ "str = raw_input(\"Enter a string \") #put string in str\n",
+ "\n",
+ "print 'You entered:',str #display string from str"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string amanuensis\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered: amanuensis\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.12, Page Number 292"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 20 #max characters in string\n",
+ "str = []*MAX #string variable str\n",
+ "\n",
+ "str = raw_input(\"Enter a string: \") #put string in str\n",
+ "\n",
+ "print 'You entered: %20s' %str #display string from str"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string: hello world.....\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered: hello world.....\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.13, Page Number 292"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str = []\n",
+ "\n",
+ "str = \"Farewell! thou art too dear for my possessing.\" #store string in an array\n",
+ "\n",
+ "print str,'\\n' #print array"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Farewell! thou art too dear for my possessing. \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.14, Page Number 293"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX = 20 #max characters in string\n",
+ "str = []*MAX #string variable str\n",
+ "\n",
+ "str = raw_input(\"Enter a string: \") #put string in str\n",
+ "\n",
+ "print 'You entered:',str #display string from str"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string: Law is a bottomless pit.\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered: Law is a bottomless pit.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.15, Page Number 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print 'Enter a string:'\n",
+ "\n",
+ "str = \"\" #string variable\n",
+ "stopword = \"$\" #taking for checking the termination condition\n",
+ "\n",
+ "\n",
+ "while True:\n",
+ " \n",
+ " line = raw_input() #taking input line by line\n",
+ " \n",
+ " if line.strip() == stopword: #stop when tenmination condition matches\n",
+ " break\n",
+ " \n",
+ " str += \"%s\\n\" % line\n",
+ " \n",
+ " \n",
+ "print 'You entered:'\n",
+ "print str #print the whole string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ask me no more where Jove bestows\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "When June is past, the fading rose;\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For in your beauty's orient deep\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "These flowers, as in their causes, sleep.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "$\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered:\n",
+ "Ask me no more where Jove bestows\n",
+ "When June is past, the fading rose;\n",
+ "For in your beauty's orient deep\n",
+ "These flowers, as in their causes, sleep.\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.16, Page Number 295"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str1 = [] #initialized string\n",
+ "str1 = \"Oh, Captain, my Captain! our fearful trip is done\"\n",
+ "\n",
+ "MAX = 80 #size of str2 buffer\n",
+ "str2 = [None]*MAX #empty string\n",
+ "\n",
+ "str2 = ''.join(str1) #copy str1 character to str2\n",
+ "\n",
+ "print str2 #print str2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Oh, Captain, my Captain! our fearful trip is done\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.17, Page Number 296"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "str1 = []\n",
+ "\n",
+ "str1 = \"Tiger, tiger, burning bright\\nIn the forests of the night\"\n",
+ "\n",
+ "MAX = 80 #size of str2 buffer\n",
+ "str2 = str1 #copy str1 to str2\n",
+ "\n",
+ "print str2 #display str2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tiger, tiger, burning bright\n",
+ "In the forests of the night\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.18, Page Number 297"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Days = 7 #number of string in array\n",
+ "\n",
+ "star = [\"Sunday\" , \"Monday\" , \"Tuesday\" , \"Wednesday\" , \"Thursday\" , \"Friday\" , \"Saturday\"] #arrray of string\n",
+ "\n",
+ "for j in range(Days): #display every string\n",
+ " print star[j]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sunday\n",
+ "Monday\n",
+ "Tuesday\n",
+ "Wednesday\n",
+ "Thursday\n",
+ "Friday\n",
+ "Saturday\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.19, Page Number 298"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class part:\n",
+ " \n",
+ " def setpart(self,pname,pn,c): #set data\n",
+ " self.__partname = pname\n",
+ " self.__partnumber = pn\n",
+ " self.__cost = c\n",
+ " \n",
+ " def showpart(self): #display data \n",
+ " print 'Name %s,' %self.__partname,\n",
+ " print 'number %d,' %self.__partnumber,\n",
+ " print 'costs $%.2f' %self.__cost\n",
+ " \n",
+ " \n",
+ "#define part objects \n",
+ "part1 = part()\n",
+ "part2 = part()\n",
+ "\n",
+ "part1.setpart(\"handle bolt\",4473,217.55) #set parts\n",
+ "part2.setpart(\"start level\",9924,419.25)\n",
+ " \n",
+ "print 'First part:' #show part\n",
+ "part1.showpart()\n",
+ "print 'Second parrt:'\n",
+ "part2.showpart()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First part:\n",
+ "Name handle bolt, number 4473, costs $217.55\n",
+ "Second parrt:\n",
+ "Name start level, number 9924, costs $419.25\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example 7.20, Page Number 300"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class String:\n",
+ " \n",
+ " def __init__(self,s = '\\0'): #overloaded constructor\n",
+ " self.__str = s\n",
+ " \n",
+ " def display(self): #display string\n",
+ " print self.__str\n",
+ " \n",
+ " def concat(self,s2): #add argument string to this string\n",
+ " if len(self.__str)+len(s2.__str) < 80:\n",
+ " self.__str = self.__str + s2.__str\n",
+ " else:\n",
+ " print 'String too long'\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = String(\"Merry Christmas! \") #define the string\n",
+ "s2 = String(\"Season's Greetings!\")\n",
+ "s3 = String()\n",
+ "\n",
+ "print 's1 =', #display them all\n",
+ "s1.display()\n",
+ "print 's2 =',\n",
+ "s2.display()\n",
+ "print 's3 =',\n",
+ "s3.display()\n",
+ "\n",
+ "s3 = s1 #assignment\n",
+ "\n",
+ "print 's3 =', #display s3\n",
+ "s3.display()\n",
+ "\n",
+ "s3.concat(s2) #concatenation\n",
+ "\n",
+ "print 's3 =', #display s3\n",
+ "s3.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s1 = Merry Christmas! \n",
+ "s2 = Season's Greetings!\n",
+ "s3 = \u0000\n",
+ "s3 = Merry Christmas! \n",
+ "s3 = Merry Christmas! Season's Greetings!\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.21, Page Number 303"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s1 = \"Man\" #initialize\n",
+ "s2 = \"Beast\"\n",
+ "\n",
+ "s3 = s1 #assign\n",
+ "print 's3 =',s3\n",
+ "\n",
+ "s3 = \"Neither \" + s1 + \" Nor \" #concatenate\n",
+ "s3 += s2 #concatenate\n",
+ "print 's3 =',s3\n",
+ " \n",
+ "s4 = s2 #swap s1 and s2\n",
+ "s2 = s1\n",
+ "s1 = s4\n",
+ "\n",
+ "print s1 , 'nor' , s2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s3 = Man\n",
+ "s3 = Neither Man Nor Beast\n",
+ "Beast nor Man\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.22, Page Number 304"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "greeting = \"Hello, \"\n",
+ "\n",
+ "full_name = raw_input(\"Enter your full name: \") #get the name of user\n",
+ "print 'Your full name is:',full_name\n",
+ "\n",
+ "nickname = raw_input(\"Enter your nickname: \") #get the nickname\n",
+ " \n",
+ "greeting += nickname #append name with greeting\n",
+ "print greeting #output: \"Hello, Jim\"\n",
+ "\n",
+ "print 'Enter your address on separate lines'\n",
+ "print 'Terminate with \\'$\\''\n",
+ "\n",
+ "address = \"\"\n",
+ "stopword = \"$\"\n",
+ "\n",
+ "while True:\n",
+ " line = raw_input() #taking input line by line\n",
+ " if line.strip() == stopword: #stop when tenmination condition matches\n",
+ " break\n",
+ " address += \"%s\\n\" % line\n",
+ " \n",
+ "print 'Your address is:'\n",
+ "print address #print the whole string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your full name: F. Scott Fitzgerald\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your full name is: F. Scott Fitzgerald\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your nickname: Scotty\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello, Scotty\n",
+ "Enter your address on separate lines\n",
+ "Terminate with '$'\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1922 Zelda Lane\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "East Egg, New York\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "$\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your address is:\n",
+ "1922 Zelda Lane\n",
+ "East Egg, New York\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.23, Page Number 305"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def find_first_not_of(s1,s2):\n",
+ " \n",
+ " a = len(s2) #length of the string to be checked\n",
+ " \n",
+ " arr = [99 for j in range(a)] #array for storing the matches index\n",
+ " \n",
+ " for j in range(a):\n",
+ " n = s1.find(s2[j]) #A character of second string is present in the first string then \n",
+ " if n!=-1:\n",
+ " arr[j] = n #put the index in the array\n",
+ " \n",
+ " arr.sort() #sort the array to check first occarence\n",
+ " \n",
+ " return arr[0]+1 #return the first index\n",
+ "\n",
+ "\n",
+ "\n",
+ "s1 = \"In xanada did Kubla Kahn a stately pleasure dome decree\"\n",
+ "\n",
+ "n = s1.find(\"Kubla\")\n",
+ "print 'Found kubla at',n\n",
+ "\n",
+ "n = s1.index(\"d\")\n",
+ "print 'First of spde at',n\n",
+ "\n",
+ "n = find_first_not_of(s1,\"aeiouAEIOU\")\n",
+ "print 'Found consonant at',n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Found kubla at 14\n",
+ "First of spde at 7\n",
+ "Found consonant at 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.24, Page Number 306"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s1 = \"Quick! Send for Count Graystone.\"\n",
+ "s2 = \"Lord\"\n",
+ "s3 = \"Don't \"\n",
+ "\n",
+ "s1 = s1[7:] #remove \"Quick! \"\n",
+ "s1 = s1.replace(\"Count\",s2) #replace \"Count\" with \"Lord\"\n",
+ "s1 = s1.replace(\"S\",\"s\") #replace 'S' with 's'\n",
+ "s1 = s3 + s1 #insert \"Don't \" at beginning\n",
+ "s1 = s1[:-1] #remove '.'\n",
+ "s1 = s1 + \"!!!\" #append \"!!!\"\n",
+ "s1 = s1.replace(\" \",\"/\") #replace all white space with '/'\n",
+ " \n",
+ "print s1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Don't/send/for/Lord/Graystone!!!\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.25, Page Number 308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "aName = \"George\"\n",
+ "\n",
+ "username = raw_input(\"Enter your first name: \")\n",
+ "\n",
+ "if username == aName: #operator ==\n",
+ " print \"Greetings, George\"\n",
+ " \n",
+ "elif username < aName: #operator <\n",
+ " print 'You come before George'\n",
+ " \n",
+ "else:\n",
+ " print 'You come after George'\n",
+ " \n",
+ " \n",
+ " \n",
+ "print 'The first two letters of your name', \n",
+ "\n",
+ "username = username[:2]\n",
+ "aName = aName[:2]\n",
+ "\n",
+ "if username == aName:\n",
+ " print \"match\",\n",
+ "elif username < aName:\n",
+ " print 'come before',\n",
+ "else:\n",
+ " print 'come after',\n",
+ "print aName"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your first name: Alfred\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You come before George\n",
+ "The first two letters of your name come before Ge\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.26, Page Number 309"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "word = raw_input(\"Enter a word: \") #take string from user\n",
+ "wlen = len(word) #length of string object\n",
+ "\n",
+ "print 'One character at a time: ',\n",
+ "for j in range(wlen):\n",
+ " print word[j],\n",
+ " \n",
+ "charray = []*80\n",
+ "charray = word #copy string object to another object\n",
+ "print '\\nArray contains:',charray"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a word: symbiosis\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "One character at a time: s y m b i o s i s \n",
+ "Array contains: symbiosis\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter8OperatorOverloading.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter8OperatorOverloading.ipynb
new file mode 100755
index 00000000..849bebbf
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter8OperatorOverloading.ipynb
@@ -0,0 +1,1653 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e97f28812ffff3c22d6a882dd8878c6179cd59a36325e2b50f6519bcb63c581f"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: Operator Overloading"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.1, Page Number 321"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter: \n",
+ " def __init__(self): #constructor\n",
+ " self.__count = 0\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self.__count\n",
+ " \n",
+ " def __iadd__(self,other): #increment\n",
+ " self.__count += other\n",
+ " return self\n",
+ " \n",
+ " \n",
+ " \n",
+ "c1 = Counter() #define and initialize\n",
+ "c2 = Counter()\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "c1 += 1 #increment c1\n",
+ "c2 += 1 #increment c2\n",
+ "c2 += 1 #increment c3\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display again\n",
+ "print 'c2 =',c2.get_count()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 0\n",
+ "c1 = 1\n",
+ "c2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2, Page Number 324"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter:\n",
+ " def __init__(self): #constructor\n",
+ " self.count = 0\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self.count\n",
+ " \n",
+ " def __iadd__(self,other): #increment count\n",
+ " \n",
+ " self.count += other #increment count\n",
+ " temp = Counter() #make a temporary Counter\n",
+ " temp.count = self.count #give it same value as this obj\n",
+ " return temp #return the copy\n",
+ " \n",
+ " \n",
+ " \n",
+ "c1 = Counter() #c1=0, c2=0\n",
+ "c2 = Counter()\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "c1 += 1 #c1=1\n",
+ "c1 += 1 #c1=2, c2=2\n",
+ "c2 = c1\n",
+ " \n",
+ "print 'c1 =',c1.get_count() #display again\n",
+ "print 'c2 =',c2.get_count()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 0\n",
+ "c1 = 2\n",
+ "c2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3, Page Number 325"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter:\n",
+ " def __init__(self,c=0): #overloaded constructor\n",
+ " self.__count = c\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self.__count\n",
+ " \n",
+ " def __iadd__(self,other): #increment count\n",
+ " \n",
+ " self.__count += other #increment count, then return \n",
+ " return Counter(self.__count) #an unnamed temporary object initialized to this count\n",
+ " \n",
+ " \n",
+ " \n",
+ "c1 = Counter() #c1=0, c2=0\n",
+ "c2 = Counter()\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "c1 += 1 #c1=1\n",
+ "c1 += 1 #c1=2, c2=2\n",
+ "c2 = c1\n",
+ " \n",
+ "print 'c1 =',c1.get_count() #display again\n",
+ "print 'c2 =',c2.get_count()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 0\n",
+ "c1 = 2\n",
+ "c2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4, Page Number 327"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import copy\n",
+ "\n",
+ "class Counter:\n",
+ " def __init__(self,c=0): #constructor \n",
+ " self.__count = c\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self.__count\n",
+ " \n",
+ " def __iadd__(self,other): #increment count (prefix & postifix both) ; 'In python no ++ opertor is there'\n",
+ " self.__count += other\n",
+ " return Counter(self.__count)\n",
+ " \n",
+ " \n",
+ " \n",
+ "c1 = Counter() #c1=0, c2=0\n",
+ "c2 = Counter()\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "c1 += 1 #c1=1\n",
+ "c1 += 1 #c1=2, c2=2\n",
+ "c2 = c1\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display\n",
+ "print 'c2 =',c2.get_count() \n",
+ "\n",
+ "c2 = copy.deepcopy(c1)\n",
+ "c1 += 1 #c1=3, c2=3\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display again\n",
+ "print 'c2 =',c2.get_count()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 0\n",
+ "c1 = 2\n",
+ "c2 = 2\n",
+ "c1 = 3\n",
+ "c2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.5, Page Number 329"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " def __init__(self,ft=0,inc=0.0): #overloaded constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\"Enter feet: \")\n",
+ " self.__inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def __add__(self,d2): #add 2 distances\n",
+ " f = self.__feet + d2.__feet #add the feet\n",
+ " i = self.__inches + d2.__inches #add the inches\n",
+ " \n",
+ " if i >= 12.0: #if total exceeds 12.0\n",
+ " i -= 12.0 #decrease inches by 12.0 and\n",
+ " f += 1 #increase feet by 1\n",
+ " \n",
+ " return Distance(f,i) #return a temporary Distance initialized to sum\n",
+ "\n",
+ " \n",
+ " \n",
+ "dist1 = Distance() #define distances\n",
+ "dist3 = Distance()\n",
+ "dist4 = Distance()\n",
+ "dist1.getdist() #get dist1 from user\n",
+ "\n",
+ "dist2 = Distance(11,6.25) #define , initialize dist2\n",
+ "\n",
+ "dist3 = dist1 + dist2 #single '+' operator\n",
+ "\n",
+ "dist4 = dist1 + dist2 + dist3 #multiple '+' operator\n",
+ "\n",
+ "print '\\ndist1 =',; dist1.showdist() #display all length\n",
+ "print 'dist2 =',; dist2.showdist()\n",
+ "print 'dist3 =',; dist3.showdist()\n",
+ "print 'dist4 =',; dist4.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 6.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 10 ' - 6.5 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 22 ' - 0.75 \"\n",
+ "dist4 = 44 ' - 1.5 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.6, Page Number 332"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class String: #user - defined string type\n",
+ " __SZ = 80 #size of String objects\n",
+ " \n",
+ " def __init__(self,s=\"\"): #overloaded constructor\n",
+ " self.__str = s\n",
+ " \n",
+ " def display(self): #display string\n",
+ " print self.__str ,\n",
+ " \n",
+ " def __add__(self,ss): #add strings\n",
+ " temp = String() #make temporary string\n",
+ " \n",
+ " if len(self.__str) + len(ss.__str) < self.__SZ:\n",
+ " temp.__str = self.__str + \" \" + ss.__str #add this string and arg string to temp string\n",
+ " \n",
+ " else:\n",
+ " print '\\nString overflow'\n",
+ " raise SystemExit \n",
+ " \n",
+ " return temp #return temp string\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = String(\"\\nMerry Christmus! \") #intialize the string variables\n",
+ "s2 = String(\"Happy new year!\")\n",
+ "s3 = String()\n",
+ "\n",
+ "s1.display() #display strings\n",
+ "s2.display() \n",
+ "s3.display()\n",
+ "\n",
+ "s3 = s1 + s2 #add s2 to s1 and assign to s3\n",
+ "s3.display() #display s3\n",
+ "print"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Merry Christmus! Happy new year! \n",
+ "Merry Christmus! Happy new year!\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.7, Page Number 334"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " def __init__(self,ft=0,inc=0.0): #overloaded constructor\n",
+ " self.__feet = ft \n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\"Enter feet: \")\n",
+ " self.__inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def __lt__(self,d2): #compare this distance with d2\n",
+ " bf1 = self.__feet + self.__inches/12\n",
+ " bf2 = d2.__feet + d2.__inches/12\n",
+ " \n",
+ " return bf1 < bf2\n",
+ " \n",
+ " \n",
+ "\n",
+ "dist1 = Distance() #define Distance dist1\n",
+ "dist1.getdist() #get dist1 from user\n",
+ "\n",
+ "dist2 = Distance(11,6.25) #define and initialize dist2\n",
+ "\n",
+ "print '\\ndist1 =',; dist1.showdist() #display Distances\n",
+ "\n",
+ "print 'dist2 =',; dist2.showdist()\n",
+ "\n",
+ "if dist1 < dist2: #overloaded '<' operator\n",
+ " print 'dist1 is less than dist2'\n",
+ "else:\n",
+ " print 'dist2 is greater than (or equal to) dist2'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 11.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 5 ' - 11.5 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist1 is less than dist2\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.8, Page Number 336"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class String: #user-define String type\n",
+ " __SZ = 80 #size of string objects\n",
+ " def __init__(self,s=\"\"): #constructor\n",
+ " self.__str = s\n",
+ " \n",
+ " def display(self): #display a string\n",
+ " print self.__str ,\n",
+ " \n",
+ " def getstr(self): #read a string\n",
+ " self.__str = raw_input()\n",
+ " \n",
+ " def __eq__(self,ss): #check for equality\n",
+ " return self.__str == ss.__str\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = String(\"yes\")\n",
+ "s2 = String(\"no\")\n",
+ "s3 = String()\n",
+ "\n",
+ "print \"\\n Enter 'yes' or 'no': \",\n",
+ "s3.getstr() #get string from user\n",
+ "\n",
+ "if s3 == s1: #compare from \"yes\"\n",
+ " print 'You typed yes\\n'\n",
+ "elif s3 == s2: #compare from \"no\"\n",
+ " print 'you typed no\\n'\n",
+ "else:\n",
+ " print \"you didn't follow instructions\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Enter 'yes' or 'no': "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "yes\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " You typed yes\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.9, Page Number 337"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " def __init__(self,ft=0,inc=0.0): #constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\"Enter feet: \")\n",
+ " self.__inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def __iadd__(self,d2): #add distance to this one\n",
+ " self.__feet = self.__feet + d2.__feet #add the feet\n",
+ " self.__inches = self.__inches + d2.__inches #add the inches\n",
+ " \n",
+ " if self.__inches >= 12.0: #if total exceeds 12.0, \n",
+ " self.__inches -= 12.0 #then decrease inches by 12.0 and\n",
+ " self.__feet += 1 #increase feet by 1\n",
+ " \n",
+ " return self\n",
+ "\n",
+ " \n",
+ " \n",
+ "dist1 = Distance() #define dist1\n",
+ "dist1.getdist() #get dist1 from user\n",
+ "print '\\ndist1 =',; dist1.showdist()\n",
+ "\n",
+ "dist2 = Distance(11,6.25) #define, initialize dist2\n",
+ "print 'dist2 =',; dist2.showdist()\n",
+ "\n",
+ "dist1 += dist2 #dist1 = dist1 + dist2\n",
+ "\n",
+ "print 'After addition,'\n",
+ "\n",
+ "print 'dist1 =',; dist1.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 5.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 3 ' - 5.75 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "After addition,\n",
+ "dist1 = 15 ' - 0.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.10, Page Number 340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LIMIT = 100\n",
+ "\n",
+ "class safearay:\n",
+ " __arr = [0 for j in range(LIMIT)]\n",
+ " \n",
+ " def putel(self,n,elvalue): #set value of element\n",
+ " if n<0 or n>=LIMIT:\n",
+ " print 'Index out of bound'\n",
+ " self.__arr[n] = elvalue\n",
+ " \n",
+ " def getel(self,n): #get value of element \n",
+ " if n<0 or n>=LIMIT:\n",
+ " print 'Index out of bound'\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ "sa1 = safearay()\n",
+ " \n",
+ "for j in range(LIMIT): #insert element\n",
+ " sa1.putel(j,j*10)\n",
+ " \n",
+ "for j in range(LIMIT): #display element\n",
+ " temp = sa1.getel(j)\n",
+ " print 'Element',j,'is',temp"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element 0 is 0\n",
+ "Element 1 is 10\n",
+ "Element 2 is 20\n",
+ "Element 3 is 30\n",
+ "Element 4 is 40\n",
+ "Element 5 is 50\n",
+ "Element 6 is 60\n",
+ "Element 7 is 70\n",
+ "Element 8 is 80\n",
+ "Element 9 is 90\n",
+ "Element 10 is 100\n",
+ "Element 11 is 110\n",
+ "Element 12 is 120\n",
+ "Element 13 is 130\n",
+ "Element 14 is 140\n",
+ "Element 15 is 150\n",
+ "Element 16 is 160\n",
+ "Element 17 is 170\n",
+ "Element 18 is 180\n",
+ "Element 19 is 190\n",
+ "Element 20 is 200\n",
+ "Element 21 is 210\n",
+ "Element 22 is 220\n",
+ "Element 23 is 230\n",
+ "Element 24 is 240\n",
+ "Element 25 is 250\n",
+ "Element 26 is 260\n",
+ "Element 27 is 270\n",
+ "Element 28 is 280\n",
+ "Element 29 is 290\n",
+ "Element 30 is 300\n",
+ "Element 31 is 310\n",
+ "Element 32 is 320\n",
+ "Element 33 is 330\n",
+ "Element 34 is 340\n",
+ "Element 35 is 350\n",
+ "Element 36 is 360\n",
+ "Element 37 is 370\n",
+ "Element 38 is 380\n",
+ "Element 39 is 390\n",
+ "Element 40 is 400\n",
+ "Element 41 is 410\n",
+ "Element 42 is 420\n",
+ "Element 43 is 430\n",
+ "Element 44 is 440\n",
+ "Element 45 is 450\n",
+ "Element 46 is 460\n",
+ "Element 47 is 470\n",
+ "Element 48 is 480\n",
+ "Element 49 is 490\n",
+ "Element 50 is 500\n",
+ "Element 51 is 510\n",
+ "Element 52 is 520\n",
+ "Element 53 is 530\n",
+ "Element 54 is 540\n",
+ "Element 55 is 550\n",
+ "Element 56 is 560\n",
+ "Element 57 is 570\n",
+ "Element 58 is 580\n",
+ "Element 59 is 590\n",
+ "Element 60 is 600\n",
+ "Element 61 is 610\n",
+ "Element 62 is 620\n",
+ "Element 63 is 630\n",
+ "Element 64 is 640\n",
+ "Element 65 is 650\n",
+ "Element 66 is 660\n",
+ "Element 67 is 670\n",
+ "Element 68 is 680\n",
+ "Element 69 is 690\n",
+ "Element 70 is 700\n",
+ "Element 71 is 710\n",
+ "Element 72 is 720\n",
+ "Element 73 is 730\n",
+ "Element 74 is 740\n",
+ "Element 75 is 750\n",
+ "Element 76 is 760\n",
+ "Element 77 is 770\n",
+ "Element 78 is 780\n",
+ "Element 79 is 790\n",
+ "Element 80 is 800\n",
+ "Element 81 is 810\n",
+ "Element 82 is 820\n",
+ "Element 83 is 830\n",
+ "Element 84 is 840\n",
+ "Element 85 is 850\n",
+ "Element 86 is 860\n",
+ "Element 87 is 870\n",
+ "Element 88 is 880\n",
+ "Element 89 is 890\n",
+ "Element 90 is 900\n",
+ "Element 91 is 910\n",
+ "Element 92 is 920\n",
+ "Element 93 is 930\n",
+ "Element 94 is 940\n",
+ "Element 95 is 950\n",
+ "Element 96 is 960\n",
+ "Element 97 is 970\n",
+ "Element 98 is 980\n",
+ "Element 99 is 990\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.11, Page Number 341"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LIMIT = 100\n",
+ "\n",
+ "class safearay:\n",
+ " __arr = [0 for j in range(LIMIT)]\n",
+ " \n",
+ " def access1(self,n,n1): #function for set the value in the array \n",
+ " if n<0 or n>=LIMIT:\n",
+ " print 'Index out of bound'\n",
+ " self.__arr[n] = n1\n",
+ " \n",
+ " def access2(self,n): #function for return the array\n",
+ " if n<0 or n>=LIMIT:\n",
+ " print 'Index out of bound'\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ "sa1 = safearay()\n",
+ "\n",
+ "for j in range(LIMIT): #insert elements using first function\n",
+ " sa1.access1(j,j*10)\n",
+ " \n",
+ "for j in range(LIMIT): #display elements using second function\n",
+ " temp = sa1.access2(j)\n",
+ " print 'Element',j,'is',temp"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element 0 is 0\n",
+ "Element 1 is 10\n",
+ "Element 2 is 20\n",
+ "Element 3 is 30\n",
+ "Element 4 is 40\n",
+ "Element 5 is 50\n",
+ "Element 6 is 60\n",
+ "Element 7 is 70\n",
+ "Element 8 is 80\n",
+ "Element 9 is 90\n",
+ "Element 10 is 100\n",
+ "Element 11 is 110\n",
+ "Element 12 is 120\n",
+ "Element 13 is 130\n",
+ "Element 14 is 140\n",
+ "Element 15 is 150\n",
+ "Element 16 is 160\n",
+ "Element 17 is 170\n",
+ "Element 18 is 180\n",
+ "Element 19 is 190\n",
+ "Element 20 is 200\n",
+ "Element 21 is 210\n",
+ "Element 22 is 220\n",
+ "Element 23 is 230\n",
+ "Element 24 is 240\n",
+ "Element 25 is 250\n",
+ "Element 26 is 260\n",
+ "Element 27 is 270\n",
+ "Element 28 is 280\n",
+ "Element 29 is 290\n",
+ "Element 30 is 300\n",
+ "Element 31 is 310\n",
+ "Element 32 is 320\n",
+ "Element 33 is 330\n",
+ "Element 34 is 340\n",
+ "Element 35 is 350\n",
+ "Element 36 is 360\n",
+ "Element 37 is 370\n",
+ "Element 38 is 380\n",
+ "Element 39 is 390\n",
+ "Element 40 is 400\n",
+ "Element 41 is 410\n",
+ "Element 42 is 420\n",
+ "Element 43 is 430\n",
+ "Element 44 is 440\n",
+ "Element 45 is 450\n",
+ "Element 46 is 460\n",
+ "Element 47 is 470\n",
+ "Element 48 is 480\n",
+ "Element 49 is 490\n",
+ "Element 50 is 500\n",
+ "Element 51 is 510\n",
+ "Element 52 is 520\n",
+ "Element 53 is 530\n",
+ "Element 54 is 540\n",
+ "Element 55 is 550\n",
+ "Element 56 is 560\n",
+ "Element 57 is 570\n",
+ "Element 58 is 580\n",
+ "Element 59 is 590\n",
+ "Element 60 is 600\n",
+ "Element 61 is 610\n",
+ "Element 62 is 620\n",
+ "Element 63 is 630\n",
+ "Element 64 is 640\n",
+ "Element 65 is 650\n",
+ "Element 66 is 660\n",
+ "Element 67 is 670\n",
+ "Element 68 is 680\n",
+ "Element 69 is 690\n",
+ "Element 70 is 700\n",
+ "Element 71 is 710\n",
+ "Element 72 is 720\n",
+ "Element 73 is 730\n",
+ "Element 74 is 740\n",
+ "Element 75 is 750\n",
+ "Element 76 is 760\n",
+ "Element 77 is 770\n",
+ "Element 78 is 780\n",
+ "Element 79 is 790\n",
+ "Element 80 is 800\n",
+ "Element 81 is 810\n",
+ "Element 82 is 820\n",
+ "Element 83 is 830\n",
+ "Element 84 is 840\n",
+ "Element 85 is 850\n",
+ "Element 86 is 860\n",
+ "Element 87 is 870\n",
+ "Element 88 is 880\n",
+ "Element 89 is 890\n",
+ "Element 90 is 900\n",
+ "Element 91 is 910\n",
+ "Element 92 is 920\n",
+ "Element 93 is 930\n",
+ "Element 94 is 940\n",
+ "Element 95 is 950\n",
+ "Element 96 is 960\n",
+ "Element 97 is 970\n",
+ "Element 98 is 980\n",
+ "Element 99 is 990\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.12, Page Number 343"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LIMIT = 100\n",
+ "\n",
+ "class safearay:\n",
+ " __arr = [0 for j in range(LIMIT)]\n",
+ " \n",
+ " def op1(self,n,n1): #function for set the value in the array \n",
+ " if n<0 or n>=LIMIT:\n",
+ " print 'Index out of bound'\n",
+ " self.__arr[n] = n1\n",
+ " \n",
+ " def op2(self,n): #function for return the array\n",
+ " if n<0 or n>=LIMIT:\n",
+ " print 'Index out of bound'\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ "sa1 = safearay()\n",
+ "\n",
+ "for j in range(LIMIT): #insert elements using first function\n",
+ " sa1.op1(j,j*10)\n",
+ " \n",
+ "for j in range(LIMIT): #display elements using second function\n",
+ " temp = sa1.op2(j)\n",
+ " print 'Element',j,'is',temp"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element 0 is 0\n",
+ "Element 1 is 10\n",
+ "Element 2 is 20\n",
+ "Element 3 is 30\n",
+ "Element 4 is 40\n",
+ "Element 5 is 50\n",
+ "Element 6 is 60\n",
+ "Element 7 is 70\n",
+ "Element 8 is 80\n",
+ "Element 9 is 90\n",
+ "Element 10 is 100\n",
+ "Element 11 is 110\n",
+ "Element 12 is 120\n",
+ "Element 13 is 130\n",
+ "Element 14 is 140\n",
+ "Element 15 is 150\n",
+ "Element 16 is 160\n",
+ "Element 17 is 170\n",
+ "Element 18 is 180\n",
+ "Element 19 is 190\n",
+ "Element 20 is 200\n",
+ "Element 21 is 210\n",
+ "Element 22 is 220\n",
+ "Element 23 is 230\n",
+ "Element 24 is 240\n",
+ "Element 25 is 250\n",
+ "Element 26 is 260\n",
+ "Element 27 is 270\n",
+ "Element 28 is 280\n",
+ "Element 29 is 290\n",
+ "Element 30 is 300\n",
+ "Element 31 is 310\n",
+ "Element 32 is 320\n",
+ "Element 33 is 330\n",
+ "Element 34 is 340\n",
+ "Element 35 is 350\n",
+ "Element 36 is 360\n",
+ "Element 37 is 370\n",
+ "Element 38 is 380\n",
+ "Element 39 is 390\n",
+ "Element 40 is 400\n",
+ "Element 41 is 410\n",
+ "Element 42 is 420\n",
+ "Element 43 is 430\n",
+ "Element 44 is 440\n",
+ "Element 45 is 450\n",
+ "Element 46 is 460\n",
+ "Element 47 is 470\n",
+ "Element 48 is 480\n",
+ "Element 49 is 490\n",
+ "Element 50 is 500\n",
+ "Element 51 is 510\n",
+ "Element 52 is 520\n",
+ "Element 53 is 530\n",
+ "Element 54 is 540\n",
+ "Element 55 is 550\n",
+ "Element 56 is 560\n",
+ "Element 57 is 570\n",
+ "Element 58 is 580\n",
+ "Element 59 is 590\n",
+ "Element 60 is 600\n",
+ "Element 61 is 610\n",
+ "Element 62 is 620\n",
+ "Element 63 is 630\n",
+ "Element 64 is 640\n",
+ "Element 65 is 650\n",
+ "Element 66 is 660\n",
+ "Element 67 is 670\n",
+ "Element 68 is 680\n",
+ "Element 69 is 690\n",
+ "Element 70 is 700\n",
+ "Element 71 is 710\n",
+ "Element 72 is 720\n",
+ "Element 73 is 730\n",
+ "Element 74 is 740\n",
+ "Element 75 is 750\n",
+ "Element 76 is 760\n",
+ "Element 77 is 770\n",
+ "Element 78 is 780\n",
+ "Element 79 is 790\n",
+ "Element 80 is 800\n",
+ "Element 81 is 810\n",
+ "Element 82 is 820\n",
+ "Element 83 is 830\n",
+ "Element 84 is 840\n",
+ "Element 85 is 850\n",
+ "Element 86 is 860\n",
+ "Element 87 is 870\n",
+ "Element 88 is 880\n",
+ "Element 89 is 890\n",
+ "Element 90 is 900\n",
+ "Element 91 is 910\n",
+ "Element 92 is 920\n",
+ "Element 93 is 930\n",
+ "Element 94 is 940\n",
+ "Element 95 is 950\n",
+ "Element 96 is 960\n",
+ "Element 97 is 970\n",
+ "Element 98 is 980\n",
+ "Element 99 is 990\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.13, Page Number 345"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " \n",
+ " def __init__(self,meters=None,ft=0,inc=0.0): #constructor\n",
+ " \n",
+ " if isinstance(meters,float): #one argument \n",
+ " self.__MTF = 3.280833 #convert meters to Distance,\n",
+ " fltfeet = self.__MTF*meters #convert to float feet\n",
+ " self.__feet = int(fltfeet) #feet is integer part\n",
+ " self.__inches = 12*(fltfeet-self.__feet) #inches is what's left\n",
+ " \n",
+ " else: #three arguments (first should be None)\n",
+ " self.__MTF = 3.280833\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\"Enter feet: \")\n",
+ " self.__inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def co(self): #conversion function, converts Distance to meters\n",
+ " fracfeet = self.__inches/12 #convert the inches\n",
+ " fracfeet += float(self.__feet) #add the feet\n",
+ " return fracfeet/self.__MTF #convert to meters\n",
+ " \n",
+ " \n",
+ " \n",
+ "dist1 = Distance(2.35) #uses 1-arg constructor to convert meters to Distance\n",
+ "print 'dist1 =',; dist1.showdist()\n",
+ "\n",
+ "mtrs = dist1.co() #uses conversion function for Distance to meters\n",
+ "print 'dist1 =',mtrs,'meters'\n",
+ " \n",
+ "dist2 = Distance(None,5,10.25) #uses 2-arg constructor\n",
+ "mtrs = dist2.co() #also uses conversion function\n",
+ "print 'dist2 =',mtrs,'meters'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dist1 = 7 ' - 8.5194906 \"\n",
+ "dist1 = 2.35 meters\n",
+ "dist2 = 1.78435375 meters\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.14, Page Number 348"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class String: #user-defined string type\n",
+ " __SZ = 80 #size of all String type\n",
+ " \n",
+ " def __init__(self,s = None): #constructor with zero or one argument\n",
+ " self.__str = s\n",
+ " \n",
+ " def display(self): #display the String\n",
+ " print self.__str,\n",
+ " \n",
+ " def char(self): #conversion function\n",
+ " return self.__str\n",
+ " \n",
+ " \n",
+ " \n",
+ "xstr = \"Joyeux Noel! \"\n",
+ "\n",
+ "s1 = String(xstr) #use 1-arg constructor\n",
+ "s1.display() #display string\n",
+ "\n",
+ "s2 = String(\"Bonne Annee!\") #use 1-arg constructor to initialize string\n",
+ "print s2.char() #uses conversion fuction"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Joyeux Noel! Bonne Annee!\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.15, Page Number 351"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class time12:\n",
+ " \n",
+ " def __init__(self,ap=True,h=0,m=0): #constructor\n",
+ " self.__pm = ap #true = pm, false = am\n",
+ " self.__hrs = h # 1 to 12\n",
+ " self.__mins = m # 0 to 59\n",
+ " \n",
+ " def display(self): #format: 11:59 p.m.\n",
+ " print self.__hrs,':',\n",
+ " \n",
+ " if self.__mins < 10:\n",
+ " print '0', #extra zero for \"01\"\n",
+ " \n",
+ " print self.__mins,\n",
+ " \n",
+ " if self.__pm:\n",
+ " print 'p.m.'\n",
+ " else:\n",
+ " print 'a.m.'\n",
+ " \n",
+ " \n",
+ " \n",
+ "class time24:\n",
+ " \n",
+ " def __init__(self,h=0,m=0,s=0): #constructor\n",
+ " self.__hours = h # 0 to 23\n",
+ " self.__minutes = m # 0 to 59\n",
+ " self.__seconds = s # 0 to 59\n",
+ " \n",
+ " def display(self): #format: 23:15:01\n",
+ " if self.__hours < 10:\n",
+ " print '0',\n",
+ " print self.__hours,':',\n",
+ " \n",
+ " if self.__minutes < 10:\n",
+ " print '0',\n",
+ " print self.__minutes,':',\n",
+ " \n",
+ " if self.__seconds < 10:\n",
+ " print '0',\n",
+ " print self.__seconds\n",
+ " \n",
+ " \n",
+ " def time_12(self): #conversion from 24-hour time to 12-hour time\n",
+ " \n",
+ " hrs24 = self.__hours\n",
+ " if self.__hours < 12: #find am/pm\n",
+ " pm = False\n",
+ " else:\n",
+ " pm = True\n",
+ " \n",
+ " if self.__seconds < 30: #round secs\n",
+ " roundMins = self.__minutes\n",
+ " else:\n",
+ " roundMins = self.__minutes + 1\n",
+ " \n",
+ " if roundMins == 60: #carry mins?\n",
+ " roundMins = 0\n",
+ " hrs24 += 1\n",
+ " if hrs24 == 12 or hrs24 == 24: #carry hrs?\n",
+ " if pm == True: #toggle am/pm\n",
+ " pm = False\n",
+ " else:\n",
+ " pm = True\n",
+ " \n",
+ " if hrs24 < 13:\n",
+ " hrs12 = hrs24\n",
+ " else:\n",
+ " hrs12 = hrs24-12\n",
+ " \n",
+ " if hrs12 == 0: # 00 is 12 a.m.\n",
+ " hrs12 = 12\n",
+ " pm = False\n",
+ " \n",
+ " return time12(pm,hrs12,roundMins)\n",
+ " \n",
+ " \n",
+ " \n",
+ "while True:\n",
+ " \n",
+ " print '\\nEnter 24-hour time: '\n",
+ " h = input(\" Hours (0 to 23): \") #get 24-hr time from user\n",
+ " \n",
+ " if h > 23: #quit if hours > 23\n",
+ " break\n",
+ " \n",
+ " m = input(\" Minutes: \") \n",
+ " s = input(\" Seconds: \")\n",
+ " \n",
+ " t24 = time24(h,m,s) #make a time24\n",
+ " print 'You entered:',\n",
+ " t24.display() #display the time24\n",
+ " \n",
+ " t12 = t24.time_12() #convert time24 to time12\n",
+ " \n",
+ " print '12-hour time:', #display equivalent time12\n",
+ " t12.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter 24-hour time: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Hours (0 to 23): 17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Minutes: 59\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Seconds: 45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered: 17 : 59 : 45\n",
+ "12-hour time: 6 : 0 0 p.m.\n",
+ "\n",
+ "Enter 24-hour time: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Hours (0 to 23): 24\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.16, Page Number 354"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class time24:\n",
+ " \n",
+ " def __init__(self,h=0,m=0,s=0): #constructor\n",
+ " self.__hours = h # 0 to 23\n",
+ " self.__minutes = m # 0 to 59\n",
+ " self.__seconds = s # 0 to 59\n",
+ " \n",
+ " def display(self): #format: 23:15:01\n",
+ " if self.__hours < 10:\n",
+ " print '0',\n",
+ " print self.__hours,':',\n",
+ " \n",
+ " if self.__minutes < 10:\n",
+ " print '0',\n",
+ " print self.__minutes,':',\n",
+ " \n",
+ " if self.__seconds < 10:\n",
+ " print '0',\n",
+ " print self.__seconds\n",
+ " \n",
+ " def getHrs(self):\n",
+ " return self.__hours\n",
+ " def getMins(self):\n",
+ " return self.__minutes\n",
+ " def getSecs(self):\n",
+ " return self.__seconds\n",
+ " \n",
+ " \n",
+ "class time12:\n",
+ " \n",
+ " def __init__(self,ap=True,h=0,m=0): #constructor\n",
+ " \n",
+ " if isinstance(ap,bool):\n",
+ " self.__pm = ap #true = pm, false = am\n",
+ " self.__hrs = h # 1 to 12\n",
+ " self.__mins = m # 0 to 59\n",
+ " \n",
+ " else: #conversion from 24-hour time to 12-hour time\n",
+ " t24 = ap\n",
+ " \n",
+ " hrs24 = t24.getHrs()\n",
+ " \n",
+ " if t24.getHrs() < 12: #find am/pm\n",
+ " self.__pm = False\n",
+ " else:\n",
+ " self.__pm = True\n",
+ " \n",
+ " if t24.getSecs() < 30: #round secs\n",
+ " self.__mins = t24.getMins()\n",
+ " else:\n",
+ " self.__mins = t24.getMins() + 1\n",
+ " \n",
+ " if self.__mins == 60: #carry mins?\n",
+ " self.__mins = 0\n",
+ " hrs24 += 1\n",
+ " \n",
+ " if hrs24 == 12 or hrs24 == 24: #carry hrs?\n",
+ " if self.__pm == True: #toggle am/pm\n",
+ " self.__pm = False\n",
+ " else:\n",
+ " self.__pm = True\n",
+ " \n",
+ " if hrs24 < 13:\n",
+ " self.__hrs = hrs24\n",
+ " else:\n",
+ " self.__hrs = hrs24-12\n",
+ " \n",
+ " if self.__hrs == 0: # 00 is 12 a.m.\n",
+ " self.__hrs = 12\n",
+ " self.__pm = False\n",
+ " \n",
+ " def display(self): #format: 11:59 p.m.\n",
+ " print self.__hrs,':',\n",
+ " \n",
+ " if self.__mins < 10:\n",
+ " print '0', #extra zero for \"01\"\n",
+ " print self.__mins,\n",
+ " \n",
+ " if self.__pm:\n",
+ " print 'p.m.'\n",
+ " else:\n",
+ " print 'a.m.'\n",
+ " \n",
+ " \n",
+ " \n",
+ "while True:\n",
+ " \n",
+ " print '\\nEnter 24-hour time: '\n",
+ " h = input(\" Hours (0 to 23): \") #get 24-hr time from user\n",
+ " \n",
+ " if h > 23: #quit if hours > 23\n",
+ " break\n",
+ " \n",
+ " m = input(\" Minutes: \") \n",
+ " s = input(\" Seconds: \")\n",
+ " \n",
+ " t24 = time24(h,m,s) #make a time24\n",
+ " print 'You entered:',\n",
+ " t24.display() #display the time24\n",
+ " \n",
+ " t12 = time12(t24) #convert time24 to time12\n",
+ " \n",
+ " print '12-hour time:', #display equivalent time12\n",
+ " t12.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter 24-hour time: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Hours (0 to 23): 17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Minutes: 59\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Seconds: 45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered: 17 : 59 : 45\n",
+ "12-hour time: 6 : 0 0 p.m.\n",
+ "\n",
+ "Enter 24-hour time: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Hours (0 to 23): 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.17, Page Number 360"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " \n",
+ " def __init__(self,meters=None,ft=0,inc=0.0): #constructor\n",
+ " \n",
+ " if isinstance(meters,float): #one argument \n",
+ " self.__MTF = 3.280833 #convert meters to Distance,\n",
+ " fltfeet = self.__MTF*meters #convert to float feet\n",
+ " self.__feet = int(fltfeet) #feet is integer part\n",
+ " self.__inches = 12*(fltfeet-self.__feet) #inches is what's left\n",
+ " \n",
+ " else: #three arguments (first should be None)\n",
+ " self.__MTF = 3.280833\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "def fancyDist(d):\n",
+ " print '(in feet and inches) =',\n",
+ " d.showdist()\n",
+ " \n",
+ " \n",
+ "\n",
+ "dist1 = Distance(2.35)\n",
+ "print 'dist1 =',; dist1.showdist()\n",
+ "\n",
+ "mtrs = 3.0\n",
+ "print 'dist1'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dist1 = 7 ' - 8.5194906 \"\n",
+ "dist1\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.18, Page Number 363"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class scrollbar:\n",
+ " \n",
+ " def __init__(self,sz,own): #constructor\n",
+ " self.__size = sz\n",
+ " self.__owner = own\n",
+ " \n",
+ " def setSize(self,sz): #change size\n",
+ " self.__size = sz\n",
+ " \n",
+ " def setOwner(self,own): #change owner\n",
+ " self.__owner = own\n",
+ " \n",
+ " def getSize(self): #returns size\n",
+ " return self.__size\n",
+ " \n",
+ " def getOwner(self): #returns owner\n",
+ " return self.__owner\n",
+ " \n",
+ " \n",
+ " \n",
+ "sbar = scrollbar(60,\"Window1\")\n",
+ "\n",
+ "sbar.setOwner(\"Window2\")\n",
+ "\n",
+ "print sbar.getSize(),', ',sbar.getOwner()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "60 , Window2\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter8OperatorOverloading_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter8OperatorOverloading_1.ipynb
new file mode 100755
index 00000000..472f2163
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter8OperatorOverloading_1.ipynb
@@ -0,0 +1,1653 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:65e713d71a502466c11b5e4af5bc631b0d4657f79a03aa601dc071ce51dce224"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: Operator Overloading"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.1, Page Number 321"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter: \n",
+ " def __init__(self): #constructor\n",
+ " self.__count = 0\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self.__count\n",
+ " \n",
+ " def __iadd__(self,other): #increment\n",
+ " self.__count += other\n",
+ " return self\n",
+ " \n",
+ " \n",
+ " \n",
+ "c1 = Counter() #define and initialize\n",
+ "c2 = Counter()\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "c1 += 1 #increment c1\n",
+ "c2 += 1 #increment c2\n",
+ "c2 += 1 #increment c3\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display again\n",
+ "print 'c2 =',c2.get_count()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 0\n",
+ "c1 = 1\n",
+ "c2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2, Page Number 324"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter:\n",
+ " def __init__(self): #constructor\n",
+ " self.count = 0\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self.count\n",
+ " \n",
+ " def __iadd__(self,other): #increment count\n",
+ " \n",
+ " self.count += other #increment count\n",
+ " temp = Counter() #make a temporary Counter\n",
+ " temp.count = self.count #give it same value as this obj\n",
+ " return temp #return the copy\n",
+ " \n",
+ " \n",
+ " \n",
+ "c1 = Counter() #c1=0, c2=0\n",
+ "c2 = Counter()\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "c1 += 1 #c1=1\n",
+ "c1 += 1 #c1=2, c2=2\n",
+ "c2 = c1\n",
+ " \n",
+ "print 'c1 =',c1.get_count() #display again\n",
+ "print 'c2 =',c2.get_count()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 0\n",
+ "c1 = 2\n",
+ "c2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3, Page Number 325"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter:\n",
+ " def __init__(self,c=0): #overloaded constructor\n",
+ " self.__count = c\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self.__count\n",
+ " \n",
+ " def __iadd__(self,other): #increment count\n",
+ " \n",
+ " self.__count += other #increment count, then return \n",
+ " return Counter(self.__count) #an unnamed temporary object initialized to this count\n",
+ " \n",
+ " \n",
+ " \n",
+ "c1 = Counter() #c1=0, c2=0\n",
+ "c2 = Counter()\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "c1 += 1 #c1=1\n",
+ "c1 += 1 #c1=2, c2=2\n",
+ "c2 = c1\n",
+ " \n",
+ "print 'c1 =',c1.get_count() #display again\n",
+ "print 'c2 =',c2.get_count()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 0\n",
+ "c1 = 2\n",
+ "c2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4, Page Number 327"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from copy import deepcopy\n",
+ "\n",
+ "class Counter:\n",
+ " def __init__(self,c=0): #constructor \n",
+ " self.__count = c\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self.__count\n",
+ " \n",
+ " def __iadd__(self,other): #increment count (prefix & postifix both) ; 'In python no ++ opertor is there'\n",
+ " self.__count += other\n",
+ " return Counter(self.__count)\n",
+ " \n",
+ " \n",
+ " \n",
+ "c1 = Counter() #c1=0, c2=0\n",
+ "c2 = Counter()\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "c1 += 1 #c1=1\n",
+ "c1 += 1 #c1=2, c2=2\n",
+ "c2 = c1\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display\n",
+ "print 'c2 =',c2.get_count() \n",
+ "\n",
+ "c2 = deepcopy(c1)\n",
+ "c1 += 1 #c1=3, c2=3\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display again\n",
+ "print 'c2 =',c2.get_count()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 0\n",
+ "c1 = 2\n",
+ "c2 = 2\n",
+ "c1 = 3\n",
+ "c2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.5, Page Number 329"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " def __init__(self,ft=0,inc=0.0): #overloaded constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\"Enter feet: \")\n",
+ " self.__inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def __add__(self,d2): #add 2 distances\n",
+ " f = self.__feet + d2.__feet #add the feet\n",
+ " i = self.__inches + d2.__inches #add the inches\n",
+ " \n",
+ " if i >= 12.0: #if total exceeds 12.0\n",
+ " i -= 12.0 #decrease inches by 12.0 and\n",
+ " f += 1 #increase feet by 1\n",
+ " \n",
+ " return Distance(f,i) #return a temporary Distance initialized to sum\n",
+ "\n",
+ " \n",
+ " \n",
+ "dist1 = Distance() #define distances\n",
+ "dist3 = Distance()\n",
+ "dist4 = Distance()\n",
+ "dist1.getdist() #get dist1 from user\n",
+ "\n",
+ "dist2 = Distance(11,6.25) #define , initialize dist2\n",
+ "\n",
+ "dist3 = dist1 + dist2 #single '+' operator\n",
+ "\n",
+ "dist4 = dist1 + dist2 + dist3 #multiple '+' operator\n",
+ "\n",
+ "print '\\ndist1 =',; dist1.showdist() #display all length\n",
+ "print 'dist2 =',; dist2.showdist()\n",
+ "print 'dist3 =',; dist3.showdist()\n",
+ "print 'dist4 =',; dist4.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 6.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 10 ' - 6.5 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist3 = 22 ' - 0.75 \"\n",
+ "dist4 = 44 ' - 1.5 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.6, Page Number 332"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class String: #user - defined string type\n",
+ " __SZ = 80 #size of String objects\n",
+ " \n",
+ " def __init__(self,s=\"\"): #overloaded constructor\n",
+ " self.__str = s\n",
+ " \n",
+ " def display(self): #display string\n",
+ " print self.__str ,\n",
+ " \n",
+ " def __add__(self,ss): #add strings\n",
+ " temp = String() #make temporary string\n",
+ " \n",
+ " if len(self.__str) + len(ss.__str) < self.__SZ:\n",
+ " temp.__str = self.__str + \" \" + ss.__str #add this string and arg string to temp string\n",
+ " \n",
+ " else:\n",
+ " print '\\nString overflow'\n",
+ " raise SystemExit \n",
+ " \n",
+ " return temp #return temp string\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = String(\"\\nMerry Christmus! \") #intialize the string variables\n",
+ "s2 = String(\"Happy new year!\")\n",
+ "s3 = String()\n",
+ "\n",
+ "s1.display() #display strings\n",
+ "s2.display() \n",
+ "s3.display()\n",
+ "\n",
+ "s3 = s1 + s2 #add s2 to s1 and assign to s3\n",
+ "s3.display() #display s3\n",
+ "print"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Merry Christmus! Happy new year! \n",
+ "Merry Christmus! Happy new year!\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.7, Page Number 334"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " def __init__(self,ft=0,inc=0.0): #overloaded constructor\n",
+ " self.__feet = ft \n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\"Enter feet: \")\n",
+ " self.__inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def __lt__(self,d2): #compare this distance with d2\n",
+ " bf1 = self.__feet + self.__inches/12\n",
+ " bf2 = d2.__feet + d2.__inches/12\n",
+ " \n",
+ " return bf1 < bf2\n",
+ " \n",
+ " \n",
+ "\n",
+ "dist1 = Distance() #define Distance dist1\n",
+ "dist1.getdist() #get dist1 from user\n",
+ "\n",
+ "dist2 = Distance(11,6.25) #define and initialize dist2\n",
+ "\n",
+ "print '\\ndist1 =',; dist1.showdist() #display Distances\n",
+ "\n",
+ "print 'dist2 =',; dist2.showdist()\n",
+ "\n",
+ "if dist1 < dist2: #overloaded '<' operator\n",
+ " print 'dist1 is less than dist2'\n",
+ "else:\n",
+ " print 'dist2 is greater than (or equal to) dist2'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 11.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 5 ' - 11.5 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "dist1 is less than dist2\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.8, Page Number 336"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class String: #user-define String type\n",
+ " __SZ = 80 #size of string objects\n",
+ " def __init__(self,s=\"\"): #constructor\n",
+ " self.__str = s\n",
+ " \n",
+ " def display(self): #display a string\n",
+ " print self.__str ,\n",
+ " \n",
+ " def getstr(self): #read a string\n",
+ " self.__str = raw_input()\n",
+ " \n",
+ " def __eq__(self,ss): #check for equality\n",
+ " return self.__str == ss.__str\n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = String(\"yes\")\n",
+ "s2 = String(\"no\")\n",
+ "s3 = String()\n",
+ "\n",
+ "print \"\\n Enter 'yes' or 'no': \",\n",
+ "s3.getstr() #get string from user\n",
+ "\n",
+ "if s3 == s1: #compare from \"yes\"\n",
+ " print 'You typed yes\\n'\n",
+ "elif s3 == s2: #compare from \"no\"\n",
+ " print 'you typed no\\n'\n",
+ "else:\n",
+ " print \"you didn't follow instructions\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Enter 'yes' or 'no': "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "yes\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " You typed yes\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.9, Page Number 337"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " def __init__(self,ft=0,inc=0.0): #constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\"Enter feet: \")\n",
+ " self.__inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def __iadd__(self,d2): #add distance to this one\n",
+ " self.__feet = self.__feet + d2.__feet #add the feet\n",
+ " self.__inches = self.__inches + d2.__inches #add the inches\n",
+ " \n",
+ " if self.__inches >= 12.0: #if total exceeds 12.0, \n",
+ " self.__inches -= 12.0 #then decrease inches by 12.0 and\n",
+ " self.__feet += 1 #increase feet by 1\n",
+ " \n",
+ " return self\n",
+ "\n",
+ " \n",
+ " \n",
+ "dist1 = Distance() #define dist1\n",
+ "dist1.getdist() #get dist1 from user\n",
+ "print '\\ndist1 =',; dist1.showdist()\n",
+ "\n",
+ "dist2 = Distance(11,6.25) #define, initialize dist2\n",
+ "print 'dist2 =',; dist2.showdist()\n",
+ "\n",
+ "dist1 += dist2 #dist1 = dist1 + dist2\n",
+ "\n",
+ "print 'After addition,'\n",
+ "\n",
+ "print 'dist1 =',; dist1.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 5.75\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "dist1 = 3 ' - 5.75 \"\n",
+ "dist2 = 11 ' - 6.25 \"\n",
+ "After addition,\n",
+ "dist1 = 15 ' - 0.0 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.10, Page Number 340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LIMIT = 100\n",
+ "\n",
+ "class safearay:\n",
+ " __arr = [0 for j in range(LIMIT)]\n",
+ " \n",
+ " def putel(self,n,elvalue): #set value of element\n",
+ " if n<0 or n>=LIMIT:\n",
+ " print 'Index out of bound'\n",
+ " self.__arr[n] = elvalue\n",
+ " \n",
+ " def getel(self,n): #get value of element \n",
+ " if n<0 or n>=LIMIT:\n",
+ " print 'Index out of bound'\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ "sa1 = safearay()\n",
+ " \n",
+ "for j in range(LIMIT): #insert element\n",
+ " sa1.putel(j,j*10)\n",
+ " \n",
+ "for j in range(LIMIT): #display element\n",
+ " temp = sa1.getel(j)\n",
+ " print 'Element',j,'is',temp"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element 0 is 0\n",
+ "Element 1 is 10\n",
+ "Element 2 is 20\n",
+ "Element 3 is 30\n",
+ "Element 4 is 40\n",
+ "Element 5 is 50\n",
+ "Element 6 is 60\n",
+ "Element 7 is 70\n",
+ "Element 8 is 80\n",
+ "Element 9 is 90\n",
+ "Element 10 is 100\n",
+ "Element 11 is 110\n",
+ "Element 12 is 120\n",
+ "Element 13 is 130\n",
+ "Element 14 is 140\n",
+ "Element 15 is 150\n",
+ "Element 16 is 160\n",
+ "Element 17 is 170\n",
+ "Element 18 is 180\n",
+ "Element 19 is 190\n",
+ "Element 20 is 200\n",
+ "Element 21 is 210\n",
+ "Element 22 is 220\n",
+ "Element 23 is 230\n",
+ "Element 24 is 240\n",
+ "Element 25 is 250\n",
+ "Element 26 is 260\n",
+ "Element 27 is 270\n",
+ "Element 28 is 280\n",
+ "Element 29 is 290\n",
+ "Element 30 is 300\n",
+ "Element 31 is 310\n",
+ "Element 32 is 320\n",
+ "Element 33 is 330\n",
+ "Element 34 is 340\n",
+ "Element 35 is 350\n",
+ "Element 36 is 360\n",
+ "Element 37 is 370\n",
+ "Element 38 is 380\n",
+ "Element 39 is 390\n",
+ "Element 40 is 400\n",
+ "Element 41 is 410\n",
+ "Element 42 is 420\n",
+ "Element 43 is 430\n",
+ "Element 44 is 440\n",
+ "Element 45 is 450\n",
+ "Element 46 is 460\n",
+ "Element 47 is 470\n",
+ "Element 48 is 480\n",
+ "Element 49 is 490\n",
+ "Element 50 is 500\n",
+ "Element 51 is 510\n",
+ "Element 52 is 520\n",
+ "Element 53 is 530\n",
+ "Element 54 is 540\n",
+ "Element 55 is 550\n",
+ "Element 56 is 560\n",
+ "Element 57 is 570\n",
+ "Element 58 is 580\n",
+ "Element 59 is 590\n",
+ "Element 60 is 600\n",
+ "Element 61 is 610\n",
+ "Element 62 is 620\n",
+ "Element 63 is 630\n",
+ "Element 64 is 640\n",
+ "Element 65 is 650\n",
+ "Element 66 is 660\n",
+ "Element 67 is 670\n",
+ "Element 68 is 680\n",
+ "Element 69 is 690\n",
+ "Element 70 is 700\n",
+ "Element 71 is 710\n",
+ "Element 72 is 720\n",
+ "Element 73 is 730\n",
+ "Element 74 is 740\n",
+ "Element 75 is 750\n",
+ "Element 76 is 760\n",
+ "Element 77 is 770\n",
+ "Element 78 is 780\n",
+ "Element 79 is 790\n",
+ "Element 80 is 800\n",
+ "Element 81 is 810\n",
+ "Element 82 is 820\n",
+ "Element 83 is 830\n",
+ "Element 84 is 840\n",
+ "Element 85 is 850\n",
+ "Element 86 is 860\n",
+ "Element 87 is 870\n",
+ "Element 88 is 880\n",
+ "Element 89 is 890\n",
+ "Element 90 is 900\n",
+ "Element 91 is 910\n",
+ "Element 92 is 920\n",
+ "Element 93 is 930\n",
+ "Element 94 is 940\n",
+ "Element 95 is 950\n",
+ "Element 96 is 960\n",
+ "Element 97 is 970\n",
+ "Element 98 is 980\n",
+ "Element 99 is 990\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.11, Page Number 341"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LIMIT = 100\n",
+ "\n",
+ "class safearay:\n",
+ " __arr = [0 for j in range(LIMIT)]\n",
+ " \n",
+ " def access1(self,n,n1): #function for set the value in the array \n",
+ " if n<0 or n>=LIMIT:\n",
+ " print 'Index out of bound'\n",
+ " self.__arr[n] = n1\n",
+ " \n",
+ " def access2(self,n): #function for return the array\n",
+ " if n<0 or n>=LIMIT:\n",
+ " print 'Index out of bound'\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ "sa1 = safearay()\n",
+ "\n",
+ "for j in range(LIMIT): #insert elements using first function\n",
+ " sa1.access1(j,j*10)\n",
+ " \n",
+ "for j in range(LIMIT): #display elements using second function\n",
+ " temp = sa1.access2(j)\n",
+ " print 'Element',j,'is',temp"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element 0 is 0\n",
+ "Element 1 is 10\n",
+ "Element 2 is 20\n",
+ "Element 3 is 30\n",
+ "Element 4 is 40\n",
+ "Element 5 is 50\n",
+ "Element 6 is 60\n",
+ "Element 7 is 70\n",
+ "Element 8 is 80\n",
+ "Element 9 is 90\n",
+ "Element 10 is 100\n",
+ "Element 11 is 110\n",
+ "Element 12 is 120\n",
+ "Element 13 is 130\n",
+ "Element 14 is 140\n",
+ "Element 15 is 150\n",
+ "Element 16 is 160\n",
+ "Element 17 is 170\n",
+ "Element 18 is 180\n",
+ "Element 19 is 190\n",
+ "Element 20 is 200\n",
+ "Element 21 is 210\n",
+ "Element 22 is 220\n",
+ "Element 23 is 230\n",
+ "Element 24 is 240\n",
+ "Element 25 is 250\n",
+ "Element 26 is 260\n",
+ "Element 27 is 270\n",
+ "Element 28 is 280\n",
+ "Element 29 is 290\n",
+ "Element 30 is 300\n",
+ "Element 31 is 310\n",
+ "Element 32 is 320\n",
+ "Element 33 is 330\n",
+ "Element 34 is 340\n",
+ "Element 35 is 350\n",
+ "Element 36 is 360\n",
+ "Element 37 is 370\n",
+ "Element 38 is 380\n",
+ "Element 39 is 390\n",
+ "Element 40 is 400\n",
+ "Element 41 is 410\n",
+ "Element 42 is 420\n",
+ "Element 43 is 430\n",
+ "Element 44 is 440\n",
+ "Element 45 is 450\n",
+ "Element 46 is 460\n",
+ "Element 47 is 470\n",
+ "Element 48 is 480\n",
+ "Element 49 is 490\n",
+ "Element 50 is 500\n",
+ "Element 51 is 510\n",
+ "Element 52 is 520\n",
+ "Element 53 is 530\n",
+ "Element 54 is 540\n",
+ "Element 55 is 550\n",
+ "Element 56 is 560\n",
+ "Element 57 is 570\n",
+ "Element 58 is 580\n",
+ "Element 59 is 590\n",
+ "Element 60 is 600\n",
+ "Element 61 is 610\n",
+ "Element 62 is 620\n",
+ "Element 63 is 630\n",
+ "Element 64 is 640\n",
+ "Element 65 is 650\n",
+ "Element 66 is 660\n",
+ "Element 67 is 670\n",
+ "Element 68 is 680\n",
+ "Element 69 is 690\n",
+ "Element 70 is 700\n",
+ "Element 71 is 710\n",
+ "Element 72 is 720\n",
+ "Element 73 is 730\n",
+ "Element 74 is 740\n",
+ "Element 75 is 750\n",
+ "Element 76 is 760\n",
+ "Element 77 is 770\n",
+ "Element 78 is 780\n",
+ "Element 79 is 790\n",
+ "Element 80 is 800\n",
+ "Element 81 is 810\n",
+ "Element 82 is 820\n",
+ "Element 83 is 830\n",
+ "Element 84 is 840\n",
+ "Element 85 is 850\n",
+ "Element 86 is 860\n",
+ "Element 87 is 870\n",
+ "Element 88 is 880\n",
+ "Element 89 is 890\n",
+ "Element 90 is 900\n",
+ "Element 91 is 910\n",
+ "Element 92 is 920\n",
+ "Element 93 is 930\n",
+ "Element 94 is 940\n",
+ "Element 95 is 950\n",
+ "Element 96 is 960\n",
+ "Element 97 is 970\n",
+ "Element 98 is 980\n",
+ "Element 99 is 990\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.12, Page Number 343"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LIMIT = 100\n",
+ "\n",
+ "class safearay:\n",
+ " __arr = [0 for j in range(LIMIT)]\n",
+ " \n",
+ " def op1(self,n,n1): #function for set the value in the array \n",
+ " if n<0 or n>=LIMIT:\n",
+ " print 'Index out of bound'\n",
+ " self.__arr[n] = n1\n",
+ " \n",
+ " def op2(self,n): #function for return the array\n",
+ " if n<0 or n>=LIMIT:\n",
+ " print 'Index out of bound'\n",
+ " return self.__arr[n]\n",
+ " \n",
+ " \n",
+ " \n",
+ "sa1 = safearay()\n",
+ "\n",
+ "for j in range(LIMIT): #insert elements using first function\n",
+ " sa1.op1(j,j*10)\n",
+ " \n",
+ "for j in range(LIMIT): #display elements using second function\n",
+ " temp = sa1.op2(j)\n",
+ " print 'Element',j,'is',temp"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element 0 is 0\n",
+ "Element 1 is 10\n",
+ "Element 2 is 20\n",
+ "Element 3 is 30\n",
+ "Element 4 is 40\n",
+ "Element 5 is 50\n",
+ "Element 6 is 60\n",
+ "Element 7 is 70\n",
+ "Element 8 is 80\n",
+ "Element 9 is 90\n",
+ "Element 10 is 100\n",
+ "Element 11 is 110\n",
+ "Element 12 is 120\n",
+ "Element 13 is 130\n",
+ "Element 14 is 140\n",
+ "Element 15 is 150\n",
+ "Element 16 is 160\n",
+ "Element 17 is 170\n",
+ "Element 18 is 180\n",
+ "Element 19 is 190\n",
+ "Element 20 is 200\n",
+ "Element 21 is 210\n",
+ "Element 22 is 220\n",
+ "Element 23 is 230\n",
+ "Element 24 is 240\n",
+ "Element 25 is 250\n",
+ "Element 26 is 260\n",
+ "Element 27 is 270\n",
+ "Element 28 is 280\n",
+ "Element 29 is 290\n",
+ "Element 30 is 300\n",
+ "Element 31 is 310\n",
+ "Element 32 is 320\n",
+ "Element 33 is 330\n",
+ "Element 34 is 340\n",
+ "Element 35 is 350\n",
+ "Element 36 is 360\n",
+ "Element 37 is 370\n",
+ "Element 38 is 380\n",
+ "Element 39 is 390\n",
+ "Element 40 is 400\n",
+ "Element 41 is 410\n",
+ "Element 42 is 420\n",
+ "Element 43 is 430\n",
+ "Element 44 is 440\n",
+ "Element 45 is 450\n",
+ "Element 46 is 460\n",
+ "Element 47 is 470\n",
+ "Element 48 is 480\n",
+ "Element 49 is 490\n",
+ "Element 50 is 500\n",
+ "Element 51 is 510\n",
+ "Element 52 is 520\n",
+ "Element 53 is 530\n",
+ "Element 54 is 540\n",
+ "Element 55 is 550\n",
+ "Element 56 is 560\n",
+ "Element 57 is 570\n",
+ "Element 58 is 580\n",
+ "Element 59 is 590\n",
+ "Element 60 is 600\n",
+ "Element 61 is 610\n",
+ "Element 62 is 620\n",
+ "Element 63 is 630\n",
+ "Element 64 is 640\n",
+ "Element 65 is 650\n",
+ "Element 66 is 660\n",
+ "Element 67 is 670\n",
+ "Element 68 is 680\n",
+ "Element 69 is 690\n",
+ "Element 70 is 700\n",
+ "Element 71 is 710\n",
+ "Element 72 is 720\n",
+ "Element 73 is 730\n",
+ "Element 74 is 740\n",
+ "Element 75 is 750\n",
+ "Element 76 is 760\n",
+ "Element 77 is 770\n",
+ "Element 78 is 780\n",
+ "Element 79 is 790\n",
+ "Element 80 is 800\n",
+ "Element 81 is 810\n",
+ "Element 82 is 820\n",
+ "Element 83 is 830\n",
+ "Element 84 is 840\n",
+ "Element 85 is 850\n",
+ "Element 86 is 860\n",
+ "Element 87 is 870\n",
+ "Element 88 is 880\n",
+ "Element 89 is 890\n",
+ "Element 90 is 900\n",
+ "Element 91 is 910\n",
+ "Element 92 is 920\n",
+ "Element 93 is 930\n",
+ "Element 94 is 940\n",
+ "Element 95 is 950\n",
+ "Element 96 is 960\n",
+ "Element 97 is 970\n",
+ "Element 98 is 980\n",
+ "Element 99 is 990\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.13, Page Number 345"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " \n",
+ " def __init__(self,meters=None,ft=0,inc=0.0): #constructor\n",
+ " \n",
+ " if isinstance(meters,float): #one argument \n",
+ " self.__MTF = 3.280833 #convert meters to Distance,\n",
+ " fltfeet = self.__MTF*meters #convert to float feet\n",
+ " self.__feet = int(fltfeet) #feet is integer part\n",
+ " self.__inches = 12*(fltfeet-self.__feet) #inches is what's left\n",
+ " \n",
+ " else: #three arguments (first should be None)\n",
+ " self.__MTF = 3.280833\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\"Enter feet: \")\n",
+ " self.__inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " def co(self): #conversion function, converts Distance to meters\n",
+ " fracfeet = self.__inches/12 #convert the inches\n",
+ " fracfeet += float(self.__feet) #add the feet\n",
+ " return fracfeet/self.__MTF #convert to meters\n",
+ " \n",
+ " \n",
+ " \n",
+ "dist1 = Distance(2.35) #uses 1-arg constructor to convert meters to Distance\n",
+ "print 'dist1 =',; dist1.showdist()\n",
+ "\n",
+ "mtrs = dist1.co() #uses conversion function for Distance to meters\n",
+ "print 'dist1 =',mtrs,'meters'\n",
+ " \n",
+ "dist2 = Distance(None,5,10.25) #uses 2-arg constructor\n",
+ "mtrs = dist2.co() #also uses conversion function\n",
+ "print 'dist2 =',mtrs,'meters'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dist1 = 7 ' - 8.5194906 \"\n",
+ "dist1 = 2.35 meters\n",
+ "dist2 = 1.78435375 meters\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.14, Page Number 348"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class String: #user-defined string type\n",
+ " __SZ = 80 #size of all String type\n",
+ " \n",
+ " def __init__(self,s = None): #constructor with zero or one argument\n",
+ " self.__str = s\n",
+ " \n",
+ " def display(self): #display the String\n",
+ " print self.__str,\n",
+ " \n",
+ " def char(self): #conversion function\n",
+ " return self.__str\n",
+ " \n",
+ " \n",
+ " \n",
+ "xstr = \"Joyeux Noel! \"\n",
+ "\n",
+ "s1 = String(xstr) #use 1-arg constructor\n",
+ "s1.display() #display string\n",
+ "\n",
+ "s2 = String(\"Bonne Annee!\") #use 1-arg constructor to initialize string\n",
+ "print s2.char() #uses conversion fuction"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Joyeux Noel! Bonne Annee!\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.15, Page Number 351"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class time12:\n",
+ " \n",
+ " def __init__(self,ap=True,h=0,m=0): #constructor\n",
+ " self.__pm = ap #true = pm, false = am\n",
+ " self.__hrs = h # 1 to 12\n",
+ " self.__mins = m # 0 to 59\n",
+ " \n",
+ " def display(self): #format: 11:59 p.m.\n",
+ " print self.__hrs,':',\n",
+ " \n",
+ " if self.__mins < 10:\n",
+ " print '0', #extra zero for \"01\"\n",
+ " \n",
+ " print self.__mins,\n",
+ " \n",
+ " if self.__pm:\n",
+ " print 'p.m.'\n",
+ " else:\n",
+ " print 'a.m.'\n",
+ " \n",
+ " \n",
+ " \n",
+ "class time24:\n",
+ " \n",
+ " def __init__(self,h=0,m=0,s=0): #constructor\n",
+ " self.__hours = h # 0 to 23\n",
+ " self.__minutes = m # 0 to 59\n",
+ " self.__seconds = s # 0 to 59\n",
+ " \n",
+ " def display(self): #format: 23:15:01\n",
+ " if self.__hours < 10:\n",
+ " print '0',\n",
+ " print self.__hours,':',\n",
+ " \n",
+ " if self.__minutes < 10:\n",
+ " print '0',\n",
+ " print self.__minutes,':',\n",
+ " \n",
+ " if self.__seconds < 10:\n",
+ " print '0',\n",
+ " print self.__seconds\n",
+ " \n",
+ " \n",
+ " def time_12(self): #conversion from 24-hour time to 12-hour time\n",
+ " \n",
+ " hrs24 = self.__hours\n",
+ " if self.__hours < 12: #find am/pm\n",
+ " pm = False\n",
+ " else:\n",
+ " pm = True\n",
+ " \n",
+ " if self.__seconds < 30: #round secs\n",
+ " roundMins = self.__minutes\n",
+ " else:\n",
+ " roundMins = self.__minutes + 1\n",
+ " \n",
+ " if roundMins == 60: #carry mins?\n",
+ " roundMins = 0\n",
+ " hrs24 += 1\n",
+ " if hrs24 == 12 or hrs24 == 24: #carry hrs?\n",
+ " if pm == True: #toggle am/pm\n",
+ " pm = False\n",
+ " else:\n",
+ " pm = True\n",
+ " \n",
+ " if hrs24 < 13:\n",
+ " hrs12 = hrs24\n",
+ " else:\n",
+ " hrs12 = hrs24-12\n",
+ " \n",
+ " if hrs12 == 0: # 00 is 12 a.m.\n",
+ " hrs12 = 12\n",
+ " pm = False\n",
+ " \n",
+ " return time12(pm,hrs12,roundMins)\n",
+ " \n",
+ " \n",
+ " \n",
+ "while True:\n",
+ " \n",
+ " print '\\nEnter 24-hour time: '\n",
+ " h = input(\" Hours (0 to 23): \") #get 24-hr time from user\n",
+ " \n",
+ " if h > 23: #quit if hours > 23\n",
+ " break\n",
+ " \n",
+ " m = input(\" Minutes: \") \n",
+ " s = input(\" Seconds: \")\n",
+ " \n",
+ " t24 = time24(h,m,s) #make a time24\n",
+ " print 'You entered:',\n",
+ " t24.display() #display the time24\n",
+ " \n",
+ " t12 = t24.time_12() #convert time24 to time12\n",
+ " \n",
+ " print '12-hour time:', #display equivalent time12\n",
+ " t12.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter 24-hour time: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Hours (0 to 23): 17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Minutes: 59\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Seconds: 45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered: 17 : 59 : 45\n",
+ "12-hour time: 6 : 0 0 p.m.\n",
+ "\n",
+ "Enter 24-hour time: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Hours (0 to 23): 24\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.16, Page Number 354"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class time24:\n",
+ " \n",
+ " def __init__(self,h=0,m=0,s=0): #constructor\n",
+ " self.__hours = h # 0 to 23\n",
+ " self.__minutes = m # 0 to 59\n",
+ " self.__seconds = s # 0 to 59\n",
+ " \n",
+ " def display(self): #format: 23:15:01\n",
+ " if self.__hours < 10:\n",
+ " print '0',\n",
+ " print self.__hours,':',\n",
+ " \n",
+ " if self.__minutes < 10:\n",
+ " print '0',\n",
+ " print self.__minutes,':',\n",
+ " \n",
+ " if self.__seconds < 10:\n",
+ " print '0',\n",
+ " print self.__seconds\n",
+ " \n",
+ " def getHrs(self):\n",
+ " return self.__hours\n",
+ " def getMins(self):\n",
+ " return self.__minutes\n",
+ " def getSecs(self):\n",
+ " return self.__seconds\n",
+ " \n",
+ " \n",
+ "class time12:\n",
+ " \n",
+ " def __init__(self,ap=True,h=0,m=0): #constructor\n",
+ " \n",
+ " if isinstance(ap,bool):\n",
+ " self.__pm = ap #true = pm, false = am\n",
+ " self.__hrs = h # 1 to 12\n",
+ " self.__mins = m # 0 to 59\n",
+ " \n",
+ " else: #conversion from 24-hour time to 12-hour time\n",
+ " t24 = ap\n",
+ " \n",
+ " hrs24 = t24.getHrs()\n",
+ " \n",
+ " if t24.getHrs() < 12: #find am/pm\n",
+ " self.__pm = False\n",
+ " else:\n",
+ " self.__pm = True\n",
+ " \n",
+ " if t24.getSecs() < 30: #round secs\n",
+ " self.__mins = t24.getMins()\n",
+ " else:\n",
+ " self.__mins = t24.getMins() + 1\n",
+ " \n",
+ " if self.__mins == 60: #carry mins?\n",
+ " self.__mins = 0\n",
+ " hrs24 += 1\n",
+ " \n",
+ " if hrs24 == 12 or hrs24 == 24: #carry hrs?\n",
+ " if self.__pm == True: #toggle am/pm\n",
+ " self.__pm = False\n",
+ " else:\n",
+ " self.__pm = True\n",
+ " \n",
+ " if hrs24 < 13:\n",
+ " self.__hrs = hrs24\n",
+ " else:\n",
+ " self.__hrs = hrs24-12\n",
+ " \n",
+ " if self.__hrs == 0: # 00 is 12 a.m.\n",
+ " self.__hrs = 12\n",
+ " self.__pm = False\n",
+ " \n",
+ " def display(self): #format: 11:59 p.m.\n",
+ " print self.__hrs,':',\n",
+ " \n",
+ " if self.__mins < 10:\n",
+ " print '0', #extra zero for \"01\"\n",
+ " print self.__mins,\n",
+ " \n",
+ " if self.__pm:\n",
+ " print 'p.m.'\n",
+ " else:\n",
+ " print 'a.m.'\n",
+ " \n",
+ " \n",
+ " \n",
+ "while True:\n",
+ " \n",
+ " print '\\nEnter 24-hour time: '\n",
+ " h = input(\" Hours (0 to 23): \") #get 24-hr time from user\n",
+ " \n",
+ " if h > 23: #quit if hours > 23\n",
+ " break\n",
+ " \n",
+ " m = input(\" Minutes: \") \n",
+ " s = input(\" Seconds: \")\n",
+ " \n",
+ " t24 = time24(h,m,s) #make a time24\n",
+ " print 'You entered:',\n",
+ " t24.display() #display the time24\n",
+ " \n",
+ " t12 = time12(t24) #convert time24 to time12\n",
+ " \n",
+ " print '12-hour time:', #display equivalent time12\n",
+ " t12.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter 24-hour time: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Hours (0 to 23): 17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Minutes: 59\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Seconds: 45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered: 17 : 59 : 45\n",
+ "12-hour time: 6 : 0 0 p.m.\n",
+ "\n",
+ "Enter 24-hour time: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Hours (0 to 23): 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.17, Page Number 360"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #class Distance\n",
+ " \n",
+ " def __init__(self,meters=None,ft=0,inc=0.0): #constructor\n",
+ " \n",
+ " if isinstance(meters,float): #one argument \n",
+ " self.__MTF = 3.280833 #convert meters to Distance,\n",
+ " fltfeet = self.__MTF*meters #convert to float feet\n",
+ " self.__feet = int(fltfeet) #feet is integer part\n",
+ " self.__inches = 12*(fltfeet-self.__feet) #inches is what's left\n",
+ " \n",
+ " else: #three arguments (first should be None)\n",
+ " self.__MTF = 3.280833\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " \n",
+ " def showdist(self): #display Distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "def fancyDist(d):\n",
+ " print '(in feet and inches) =',\n",
+ " d.showdist()\n",
+ " \n",
+ " \n",
+ "\n",
+ "dist1 = Distance(2.35)\n",
+ "print 'dist1 =',; dist1.showdist()\n",
+ "\n",
+ "mtrs = 3.0\n",
+ "print 'dist1'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "dist1 = 7 ' - 8.5194906 \"\n",
+ "dist1\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.18, Page Number 363"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class scrollbar:\n",
+ " \n",
+ " def __init__(self,sz,own): #constructor\n",
+ " self.__size = sz\n",
+ " self.__owner = own\n",
+ " \n",
+ " def setSize(self,sz): #change size\n",
+ " self.__size = sz\n",
+ " \n",
+ " def setOwner(self,own): #change owner\n",
+ " self.__owner = own\n",
+ " \n",
+ " def getSize(self): #returns size\n",
+ " return self.__size\n",
+ " \n",
+ " def getOwner(self): #returns owner\n",
+ " return self.__owner\n",
+ " \n",
+ " \n",
+ " \n",
+ "sbar = scrollbar(60,\"Window1\")\n",
+ "\n",
+ "sbar.setOwner(\"Window2\")\n",
+ "\n",
+ "print sbar.getSize(),', ',sbar.getOwner()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "60 , Window2\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter9Inheritance.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter9Inheritance.ipynb
new file mode 100755
index 00000000..ee3158c8
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter9Inheritance.ipynb
@@ -0,0 +1,1833 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:6cf59f645122c2aa3a7bf9b9051d950f9c340bf80207c806770729fdb1d9f632"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Inheritance"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {
+ "slideshow": {
+ "slide_type": "-"
+ }
+ },
+ "source": [
+ "Example 9.1, Page Number 374"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter(CountDn): #base class\n",
+ " \n",
+ " def __init__(self,c=0): #constructor\n",
+ " self._count = c #not private\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self._count\n",
+ " \n",
+ " def __iadd__(self,other): #increment count\n",
+ " self._count += other \n",
+ " return Counter(self._count)\n",
+ " \n",
+ "class CountDn(Counter): #derived class\n",
+ " \n",
+ " def __isub__(self,other): #decrement count\n",
+ " self._count -= other\n",
+ " return Counter(self._count)\n",
+ " \n",
+ " \n",
+ " \n",
+ "c1 = CountDn() #c1 of class CountDn\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display c1\n",
+ " \n",
+ "c1 += 1 #increment count 3 times\n",
+ "c1 += 1\n",
+ "c1 += 1\n",
+ "print 'c1 =',c1.get_count() #display count\n",
+ "\n",
+ "c1 -= 1 #decrement c1, twice\n",
+ "c1 -= 1\n",
+ "print 'c1 =',c1.get_count() #display c1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c1 = 3\n",
+ "c1 = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.2, Page Number 380"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter: #base class\n",
+ " def __init__(self,c=0): #constructor\n",
+ " self._count = c\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self._count\n",
+ " \n",
+ " def __iadd__(self,other): #increment count\n",
+ " self._count += other\n",
+ " return Counter(self._count)\n",
+ " \n",
+ " \n",
+ " \n",
+ "class CountDn(Counter): #derived class\n",
+ " def __init__(self,c=0): #constructor\n",
+ " self._count = c\n",
+ " \n",
+ " def __isub__(self,other): #decrement count\n",
+ " self._count -= 1\n",
+ " return CountDn(self._count)\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "c1 = CountDn() #class CountDn\n",
+ "c2 = CountDn(100)\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "c1 += 1 #increment c1\n",
+ "c1 += 1\n",
+ "c1 += 1\n",
+ "print 'c1 =',c1.get_count() #display c1\n",
+ "\n",
+ "c2 -= 1 #decrement c2\n",
+ "c2 -= 1\n",
+ "print 'c2 =',c2.get_count() #display it\n",
+ " \n",
+ "c3 = CountDn() #create c3\n",
+ "c2 -= 1 #decrement c2\n",
+ "c3 = c2 #assign count value of c2 to c3\n",
+ "print 'c3 =',c3.get_count() #display c3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 100\n",
+ "c1 = 3\n",
+ "c2 = 98\n",
+ "c3 = 97\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3, Page Number 382"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Stack: \n",
+ " _MAX = 3 #size of stack array\n",
+ " _st = [None]*_MAX #stack\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self._top = -1\n",
+ " \n",
+ " def push(self,var): #put number on stack\n",
+ " self._top += 1\n",
+ " self._st[self._top] = var\n",
+ " \n",
+ " def pop(self): #take number off stack\n",
+ " x = self._st[self._top]\n",
+ " self._top -= 1\n",
+ " return x\n",
+ " \n",
+ " \n",
+ " \n",
+ "class Stack2(Stack):\n",
+ " \n",
+ " def push(self,var): #put number on stack\n",
+ " \n",
+ " if self._top >= self._MAX-1: #error if stack full \n",
+ " print 'Error: stack is full'\n",
+ " else:\n",
+ " Stack.push(self,var) #call push() in Stack class\n",
+ " \n",
+ " def pop(self): #take number off stack\n",
+ " if self._top < 0: #error if stack empty\n",
+ " return 'Error: stack is empty' \n",
+ " else:\n",
+ " return Stack.pop(self) #call pop() in Stack class\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = Stack2()\n",
+ "\n",
+ "s1.push(11) #push some values onto stack\n",
+ "s1.push(22)\n",
+ "s1.push(33)\n",
+ "\n",
+ "print s1.pop() #pop some values from stack\n",
+ "print s1.pop()\n",
+ "print s1.pop()\n",
+ "print s1.pop() #oops, popped one too many..."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "33\n",
+ "22\n",
+ "11\n",
+ "Error: stack is empty\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4, Page Number 385"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor\n",
+ " self._feet = ft #can't be private\n",
+ " self._inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self._feet = input(\"Enter feet: \")\n",
+ " self._inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self._feet , '\\' -' , self._inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "class DistSign(Distance): #adds sign to distance\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0,sg='pos'): #constructor\n",
+ " Distance.__init__(self,ft,inc) #call base class constructor\n",
+ " self._sign = sg #sign is pos or neg\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " Distance.getdist(self) #call base getdist()\n",
+ " \n",
+ " ch = raw_input(\"Enter sign (+ or -): \") #get sign from user\n",
+ " if ch == '+':\n",
+ " self._sign = 'pos'\n",
+ " else:\n",
+ " self._sign = 'neg'\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " if self._sign == 'pos': #show sign\n",
+ " print '(+)',\n",
+ " else:\n",
+ " print '(-)',\n",
+ " Distance.showdist(self) #show ft and in\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "alpha = DistSign() #object with no arg constructor\n",
+ "alpha.getdist() #get alpha from user\n",
+ "\n",
+ "beta = DistSign(11,6.25) #object with 2 - arg constructor\n",
+ "\n",
+ "gamma = DistSign(100,5.5,'neg') #object with 3 - arg constructor\n",
+ "\n",
+ "print '\\nalpha =', #display all distances\n",
+ "alpha.showdist()\n",
+ "print 'beta =',\n",
+ "beta.showdist()\n",
+ "print 'gamma =',\n",
+ "gamma.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 2.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sign (+ or -): -\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "alpha = (-) 6 ' - 2.5 \"\n",
+ "beta = (+) 11 ' - 6.25 \"\n",
+ "gamma = (-) 100 ' - 5.5 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5, Page Number 389"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LEN = 80 #maximum length\n",
+ "\n",
+ "class employee: #employee class\n",
+ " __name = [None]*LEN #employee name\n",
+ " \n",
+ " def getdata(self): #get data from user\n",
+ " self.__name = raw_input(\" Enter last name: \")\n",
+ " self.__number = input(\" Enter number: \") #employee number\n",
+ " \n",
+ " def putdata(self): #display data\n",
+ " print ' Name:',self.__name \n",
+ " print ' Number:',self.__number\n",
+ " \n",
+ " \n",
+ " \n",
+ "class manager(employee): #management class\n",
+ " __title = [None]*LEN #'vice-president' etc. \n",
+ " \n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__title = raw_input(\" Enter Title: \")\n",
+ " self.__dues = input(\" Enter golf club dues: \") #golf club dues\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Title:',self.__title\n",
+ " print ' Number:',self.__dues\n",
+ " \n",
+ " \n",
+ " \n",
+ "class scientist(employee): #scientist class\n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__pubs = raw_input(\" Enter Number of pubs: \") #number of publication\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Number of publications:',self.__pubs\n",
+ " \n",
+ " \n",
+ "class laborer(employee): #labour class\n",
+ " pass \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "m1 = manager()\n",
+ "m2 = manager()\n",
+ "s1 = scientist()\n",
+ "l1 = laborer()\n",
+ " #get data for several employees\n",
+ "print 'Enter data for manager 1'\n",
+ "m1.getdata()\n",
+ "\n",
+ "print 'Enter data for manager 2'\n",
+ "m2.getdata()\n",
+ "\n",
+ "print 'Enter data for scientist 1'\n",
+ "s1.getdata()\n",
+ "\n",
+ "print 'Enter data for laborer 1'\n",
+ "l1.getdata()\n",
+ "\n",
+ " #display data for several employees\n",
+ "print '\\nData on manager 1'\n",
+ "m1.putdata()\n",
+ "\n",
+ "print 'Data on manager 2'\n",
+ "m2.putdata()\n",
+ "\n",
+ "print 'Data on scientist 1'\n",
+ "s1.putdata()\n",
+ "\n",
+ "print 'Data on laborer 1'\n",
+ "l1.putdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for manager 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Wainsworth\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Title: President\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter golf club dues: 1000000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for manager 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Bradley\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 124\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Title: Vice-President\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter golf club dues: 500000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for scientist 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Hauptman-Frenglish\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 234234\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of pubs: 999\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for laborer 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: jones\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 6546544\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Data on manager 1\n",
+ " Name: Wainsworth\n",
+ " Number: 10\n",
+ " Title: President\n",
+ " Number: 1000000\n",
+ "Data on manager 2\n",
+ " Name: Bradley\n",
+ " Number: 124\n",
+ " Title: Vice-President\n",
+ " Number: 500000\n",
+ "Data on scientist 1\n",
+ " Name: Hauptman-Frenglish\n",
+ " Number: 234234\n",
+ " Number of publications: 999\n",
+ "Data on laborer 1\n",
+ " Name: jones\n",
+ " Number: 6546544\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6, Page Number 393"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import * #importing turtles library\n",
+ "\n",
+ "class shape: #base class\n",
+ " def __init__(self,x=0,y=0,fc=\"white\"): #constructor\n",
+ " self._xCo = x #coordinate for shape\n",
+ " self._yCo = y\n",
+ " self._fillcolor = fc #color for shape\n",
+ "\n",
+ " \n",
+ "\n",
+ "class circle(shape): #defining circle class\n",
+ " \n",
+ " def __init__(self,x,y,r,fc): #constructor for set circle attribute\n",
+ " shape.__init__(self,x,y,fc) \n",
+ " self._radius = r\n",
+ " \n",
+ " def draw(self): #draw the circle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " turtle.color(self._fillcolor)\n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.circle(self._radius)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ " \n",
+ " \n",
+ "class rect(shape): #defining rectangle class\n",
+ " \n",
+ " def __init__(self,x,y,h,w,fc): #constructor\n",
+ " shape.__init__(self,x,y,fc) \n",
+ " self._height = h\n",
+ " self._weight = w\n",
+ " \n",
+ " def draw(self): #draw the rectangle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " turtle.color(self._fillcolor)\n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.forward(self._weight) \n",
+ " turtle.left(90)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.left(90)\n",
+ " turtle.forward(self._weight)\n",
+ " turtle.left(90)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done() \n",
+ "\n",
+ " \n",
+ "class tria(shape): #defining triangle class\n",
+ " \n",
+ " def __init__(self,x,y,h,fc): #constructor \n",
+ " shape.__init__(self,x,y,fc) \n",
+ " self._height = h\n",
+ " \n",
+ " def draw(self): #draw the triangle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " turtle.color(self._fillcolor)\n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.forward(self._height) \n",
+ " turtle.left(120)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.left(120)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "cir = circle(40,12,5,\"blue\") #create circle\n",
+ "rec = rect(12,7,10,15,\"red\") #create rectangle\n",
+ "tri = tria(60,7,11,\"green\") #create triangle\n",
+ "\n",
+ "#draw all shape\n",
+ "cir.draw()\n",
+ "rec.draw()\n",
+ "tri.draw()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.7, Page Number 397"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A: #base class\n",
+ " __privdataA = None #private variable\n",
+ " _protdataA = None #protected variable\n",
+ " pubdataA = None #public variable\n",
+ " \n",
+ "class B(A):\n",
+ " def funct(self):\n",
+ " a = self.__privdataA\n",
+ " a = self._protdataA\n",
+ " a = self.pubdataA\n",
+ " \n",
+ "class C(A):\n",
+ " def funct(self):\n",
+ " a = self.__privdataA\n",
+ " a = self._protdataA\n",
+ " a = self._pubdataA\n",
+ " \n",
+ " \n",
+ " \n",
+ "objB = B()\n",
+ "#a = objB.privdataA #not accesible because private variable\n",
+ "#a = objB.protdataA #not accesible because protected variable\n",
+ "a = objB.pubdataA\n",
+ "\n",
+ "objC = C()\n",
+ "#a = objC.privdataA #not accesible because private variable\n",
+ "#a = objC.protdataA #not accesible because protected variable\n",
+ "a = objC.pubdataA #In python, there is no concept of public or private inheritance so this line won't show any arror"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.8, Page Number 400"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LEN = 80 #maximum length of names\n",
+ "\n",
+ "class employee: #employee class\n",
+ " __name = [None]*LEN #employee name\n",
+ " \n",
+ " def getdata(self): #get data from user\n",
+ " self.__name = raw_input(\" Enter last name: \")\n",
+ " self.__number = input(\" Enter number: \") #employee number\n",
+ " \n",
+ " def putdata(self): #display data\n",
+ " print ' Name:',self.__name\n",
+ " print ' Number:',self.__number\n",
+ " \n",
+ " \n",
+ "class manager(employee): #management class\n",
+ " __title = [None]*LEN #'vice-president' etc. \n",
+ " \n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__title = raw_input(\" Enter Title: \")\n",
+ " self.__dues = input(\" Enter golf club dues: \") #golf club dues\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Title:',self.__title\n",
+ " print ' Number:',self.__dues\n",
+ " \n",
+ " \n",
+ "class scientist(employee): #scientist class\n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__pubs = raw_input(\" Enter Number of pubs: \") #number of publication\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Number of publications:',self.__pubs\n",
+ " \n",
+ " \n",
+ "class laborer(employee): #laborer class\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "class foreman(laborer): #foreman class\n",
+ " def getdata(self): \n",
+ " laborer.getdata(self)\n",
+ " self.__quotas = raw_input(\" Enter quotas: \") #percent of quotes met successfully\n",
+ " \n",
+ " def putdata(self):\n",
+ " laborer.putdata(self)\n",
+ " print ' Quotas:',self.__quotas\n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ "l1 = laborer()\n",
+ "f1 = foreman()\n",
+ " #get data for several employees\n",
+ "print 'Enter data for laborer 1'\n",
+ "l1.getdata()\n",
+ "\n",
+ "print 'Enter data for foreman 1'\n",
+ "f1.getdata()\n",
+ "\n",
+ " #display data for several employees\n",
+ "print '\\nData on laborer 1'\n",
+ "l1.putdata()\n",
+ "\n",
+ "print 'Data on foreman 1'\n",
+ "f1.putdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for laborer 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Jones\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 6546544\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for foreman 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Jones\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 6546544\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter quotas: 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Data on laborer 1\n",
+ " Name: Jones\n",
+ " Number: 6546544\n",
+ "Data on foreman 1\n",
+ " Name: Jones\n",
+ " Number: 6546544\n",
+ " Quotas: 100\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9, Page Number 405"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LEN = 80 #maximum length of names\n",
+ "\n",
+ "\n",
+ "class student: #eduational background\n",
+ " __school = [None]*LEN #name of school or university\n",
+ " __degree = [None]*LEN #hightest degree earned\n",
+ " \n",
+ " def getedu(self):\n",
+ " self.__school = raw_input(\" Enter name of school or university: \")\n",
+ " print ' Enter highest degree earned '\n",
+ " self.__degree = raw_input(\" (Highschool, Bachelor\\'s, Master\\'s, PhD): \")\n",
+ " \n",
+ " def putedu(self):\n",
+ " print ' School or Uniersity:',self.__school\n",
+ " print ' Highest degree earned:',self.__degree\n",
+ " \n",
+ " \n",
+ "class employee: #employee class\n",
+ " __name = [None]*LEN #employee name\n",
+ " \n",
+ " def getdata(self):\n",
+ " self.__name = raw_input(\" Enter last name: \")\n",
+ " self.__number = input(\" Enter number: \") #employee number\n",
+ " \n",
+ " def putdata(self):\n",
+ " print ' Name:',self.__name\n",
+ " print ' Number:',self.__number\n",
+ " \n",
+ " \n",
+ "class manager(employee,student): #management\n",
+ " __title = [None]*LEN #\"vice-precident\" etc.\n",
+ " \n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__title = raw_input(\" Enter Title: \")\n",
+ " self.__dues = input(\" Enter golf club dues: \") #golf club dues\n",
+ " student.getedu(self)\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Title:',self.__title\n",
+ " print ' Number:',self.__dues\n",
+ " student.putedu(self)\n",
+ " \n",
+ " \n",
+ "class scientist(employee,student): #scientist\n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__pubs = raw_input(\" Enter Number of pubs: \") #number of publications\n",
+ " student.getedu(self)\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Number of publications:',self.__pubs\n",
+ " student.putedu(self)\n",
+ " \n",
+ " \n",
+ "class laborer(employee): #labrer\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "\n",
+ "m1 = manager()\n",
+ "s1 = scientist()\n",
+ "s2 = scientist()\n",
+ "l1 = laborer()\n",
+ "\n",
+ " #get data for several employee\n",
+ "print '\\nEnter data for manager 1'\n",
+ "m1.getdata()\n",
+ "\n",
+ "print '\\nEnter data for scientist 1'\n",
+ "s1.getdata()\n",
+ "\n",
+ "print '\\nEnter data for scientist 2'\n",
+ "s2.getdata()\n",
+ "\n",
+ "print '\\nEnter data for laborer 1'\n",
+ "l1.getdata()\n",
+ "\n",
+ " #display data for several employee\n",
+ "print '\\n\\nData on manager 1'\n",
+ "m1.putdata()\n",
+ "\n",
+ "print '\\nData on scientist 1'\n",
+ "s1.putdata()\n",
+ "\n",
+ "print '\\nData on scientist 2'\n",
+ "s2.putdata()\n",
+ "\n",
+ "print '\\nData on laborer 1'\n",
+ "l1.putdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for manager 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Bradley\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Title: Vice-President\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter golf club dues: 100000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name of school or university: Yale\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter highest degree earned \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (Highschool, Bachelor's, Master's, PhD): Bachelor's\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for scientist 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Twilling\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 764\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of pubs: 99\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name of school or university: MIT\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter highest degree earned \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (Highschool, Bachelor's, Master's, PhD): PhD\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for scientist 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Yang\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 845\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of pubs: 101\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name of school or university: Stanford\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter highest degree earned \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (Highschool, Bachelor's, Master's, PhD): Master's\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for laborer 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Jones\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 48323\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Data on manager 1\n",
+ " Name: Bradley\n",
+ " Number: 12\n",
+ " Title: Vice-President\n",
+ " Number: 100000\n",
+ " School or Uniersity: Yale\n",
+ " Highest degree earned: Bachelor's\n",
+ "\n",
+ "Data on scientist 1\n",
+ " Name: Twilling\n",
+ " Number: 764\n",
+ " Number of publications: 99\n",
+ " School or Uniersity: MIT\n",
+ " Highest degree earned: PhD\n",
+ "\n",
+ "Data on scientist 2\n",
+ " Name: Yang\n",
+ " Number: 845\n",
+ " Number of publications: 101\n",
+ " School or Uniersity: Stanford\n",
+ " Highest degree earned: Master's\n",
+ "\n",
+ "Data on laborer 1\n",
+ " Name: Jones\n",
+ " Number: 48323\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.10, Page Number 409"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Type: #type of lumber\n",
+ " \n",
+ " def __init__(self,di = \"N/A\",gr = \"N/A\"): #constructor\n",
+ " self.__dimensions = di\n",
+ " self.__grade = gr\n",
+ " \n",
+ " def gettype(self): #get type from user\n",
+ " self.__dimensions = raw_input(\" Enter nominal dimensions (2x4 etc.): \")\n",
+ " self.__grade = raw_input(\" Enter grade (rough, const, etc.): \")\n",
+ " \n",
+ " def showtype(self): #display type\n",
+ " print ' Dimensions:',self.__dimensions\n",
+ " print ' Grade:',self.__grade\n",
+ " \n",
+ " \n",
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\" Enter feet: \")\n",
+ " self.__inches = input(\" Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ "class Lumber(Type,Distance):\n",
+ " \n",
+ " def __init__(self,di=None,gr=None,ft=0,inc=0.0,qu=0,prc=0.0): #constructor\n",
+ " \n",
+ " Type.__init__(self,di,gr) #call type constructor\n",
+ " Distance.__init__(self,ft,inc) #call Distance constructor\n",
+ " \n",
+ " self.__quantity = qu #number of pieces\n",
+ " self.__price = prc #price of each piece\n",
+ " \n",
+ " \n",
+ " def getlumber(self):\n",
+ " Type.gettype(self)\n",
+ " Distance.getdist(self)\n",
+ " \n",
+ " self.__quantity = input(\" Enter quantity: \")\n",
+ " self.__price = input(\" Enter price per piece: \")\n",
+ " \n",
+ " \n",
+ " def showlumber(self):\n",
+ " Type.showtype(self)\n",
+ " print ' Length: ',\n",
+ " Distance.showdist(self)\n",
+ " print ' price for',self.__quantity,'pieces: $',self.__price*self.__quantity\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "siding = Lumber() #constructor with no argument\n",
+ "\n",
+ "print 'Siding data:'\n",
+ "siding.getlumber() #get siding from user\n",
+ "\n",
+ "studs = Lumber(\"2x4\",\"const\",8,0.0,200,4.5) #constructor with 6 arguments\n",
+ "\n",
+ "print '\\nSiding' #display lumber data\n",
+ "siding.showlumber()\n",
+ "print 'studs'\n",
+ "studs.showlumber()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Siding data:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter nominal dimensions (2x4 etc.): 3x4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter grade (rough, const, etc.): rough\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter inches: 6.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter quantity: 300\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter price per piece: 19.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Siding\n",
+ " Dimensions: 3x4\n",
+ " Grade: rough\n",
+ " Length: 5 ' - 6.5 \"\n",
+ " price for 300 pieces: $ 5850.0\n",
+ "studs\n",
+ " Dimensions: 2x4\n",
+ " Grade: const\n",
+ " Length: 8 ' - 0.0 \"\n",
+ " price for 200 pieces: $ 900.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.11, Page Number 413"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " def show(self):\n",
+ " print 'Class A'\n",
+ " \n",
+ "class B:\n",
+ " def show(self):\n",
+ " print 'Class B'\n",
+ " \n",
+ "class C(A,B):\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "\n",
+ "objC = C() #object of class C\n",
+ "#objC.show() \n",
+ "A().show() \n",
+ "B().show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Class A\n",
+ "Class B\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.12, Page Number 414"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " def func(self):\n",
+ " pass\n",
+ " \n",
+ "class B(A):\n",
+ " pass\n",
+ "class C(A):\n",
+ " pass\n",
+ "class D(B,C):\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "\n",
+ "objD = D()\n",
+ "#objD.func()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.13, Page Number 417"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class student: #educational background\n",
+ " \n",
+ " def getedu(self):\n",
+ " self.__school = raw_input(\" Enter name of school or university: \") #name of school or university\n",
+ " print ' Enter highest degree earned '\n",
+ " self.__degree = raw_input(\" (Highschool, Bachelor\\'s, Master\\'s, PhD): \") #heighest degree earned\n",
+ " \n",
+ " def putedu(self):\n",
+ " print ' School or Uniersity:',self.__school\n",
+ " print ' Highest degree earned:',self.__degree\n",
+ " \n",
+ " \n",
+ "class employee:\n",
+ " \n",
+ " def getdata(self):\n",
+ " self.__name = raw_input(\" Enter last name: \") #employee name\n",
+ " self.__number = input(\" Enter number: \") #employee number\n",
+ " \n",
+ " def putdata(self):\n",
+ " print ' Name:',self.__name\n",
+ " print ' Number:',self.__number\n",
+ " \n",
+ " \n",
+ "class manager: #management\n",
+ " \n",
+ " __emp = employee() #object of class employee\n",
+ " __stu = student() #object of class student\n",
+ " \n",
+ " def getdata(self):\n",
+ " self.__emp.getdata()\n",
+ " self.__title = raw_input(\" Enter Title: \") #\"vice-president\" etc.\n",
+ " self.__dues = input(\" Enter golf club dues: \") #golf club dues\n",
+ " self.__stu.getedu()\n",
+ " \n",
+ " def putdata(self):\n",
+ " self.__emp.putdata()\n",
+ " print ' Title:',self.__title\n",
+ " print ' Number:',self.__dues\n",
+ " self.__stu.putedu()\n",
+ " \n",
+ " \n",
+ "class scientist: #scientist\n",
+ " \n",
+ " __emp = employee() #object of class employee\n",
+ " __stu = student() #object of class student\n",
+ " \n",
+ " def getdata(self):\n",
+ " self.__emp.getdata()\n",
+ " self.__pubs = raw_input(\" Enter Number of pubs: \") #number of publications\n",
+ " self.__stu.getedu()\n",
+ " \n",
+ " def putdata(self):\n",
+ " self.__emp.putdata()\n",
+ " print ' Number of publications:',self.__pubs\n",
+ " self.__stu.putedu()\n",
+ " \n",
+ " \n",
+ "class laborer: #laborer\n",
+ " \n",
+ " __emp = employee() #object of class employee\n",
+ " \n",
+ " def getdata(self):\n",
+ " self.__emp.getdata()\n",
+ " def putdata(self):\n",
+ " self.__emp.putdata()\n",
+ " \n",
+ " \n",
+ "\n",
+ "m1 = manager()\n",
+ "s1 = scientist()\n",
+ "s2 = scientist()\n",
+ "l1 = laborer()\n",
+ "\n",
+ " #get data for several employee\n",
+ "print '\\nEnter data for manager 1'\n",
+ "m1.getdata()\n",
+ "\n",
+ "print '\\nEnter data for scientist 1'\n",
+ "s1.getdata()\n",
+ "\n",
+ "print '\\nEnter data for scientist 2'\n",
+ "s2.getdata()\n",
+ "\n",
+ "print '\\nEnter data for laborer 1'\n",
+ "l1.getdata()\n",
+ "\n",
+ " #display data for several employee\n",
+ "print '\\n\\nData on manager 1'\n",
+ "m1.putdata()\n",
+ "\n",
+ "print '\\nData on scientist 1'\n",
+ "s1.putdata()\n",
+ "\n",
+ "print '\\nData on scientist 2'\n",
+ "s2.putdata()\n",
+ "\n",
+ "print '\\nData on laborer 1'\n",
+ "l1.putdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for manager 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Bradley\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Title: Vice-President\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter golf club dues: 100000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name of school or university: Yale\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter highest degree earned \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (Highschool, Bachelor's, Master's, PhD): Bachelor's\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for scientist 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Twilling\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 764\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of pubs: 99\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name of school or university: MIT\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter highest degree earned \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (Highschool, Bachelor's, Master's, PhD): PhD\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for scientist 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Yang\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 845\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of pubs: 101\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name of school or university: Stanford\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter highest degree earned \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (Highschool, Bachelor's, Master's, PhD): master's\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for laborer 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Jones\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 48323\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Data on manager 1\n",
+ " Name: Bradley\n",
+ " Number: 12\n",
+ " Title: Vice-President\n",
+ " Number: 100000\n",
+ " School or Uniersity: Yale\n",
+ " Highest degree earned: Bachelor's\n",
+ "\n",
+ "Data on scientist 1\n",
+ " Name: Yang\n",
+ " Number: 845\n",
+ " Number of publications: 99\n",
+ " School or Uniersity: Stanford\n",
+ " Highest degree earned: master's\n",
+ "\n",
+ "Data on scientist 2\n",
+ " Name: Yang\n",
+ " Number: 845\n",
+ " Number of publications: 101\n",
+ " School or Uniersity: Stanford\n",
+ " Highest degree earned: master's\n",
+ "\n",
+ "Data on laborer 1\n",
+ " Name: Jones\n",
+ " Number: 48323\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter9Inheritance_1.ipynb b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter9Inheritance_1.ipynb
new file mode 100755
index 00000000..d5d20790
--- /dev/null
+++ b/Object-Oriented_Programming_in_C++_by_Robert_Lafore/Chapter9Inheritance_1.ipynb
@@ -0,0 +1,1833 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:53eeb93a478faf6a636efe3869e7b641ca7f40a4d6002f235da6edee0c3eed6e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Inheritance"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {
+ "slideshow": {
+ "slide_type": "-"
+ }
+ },
+ "source": [
+ "Example 9.1, Page Number 374"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter(CountDn): #base class\n",
+ " \n",
+ " def __init__(self,c=0): #constructor\n",
+ " self._count = c #not private\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self._count\n",
+ " \n",
+ " def __iadd__(self,other): #increment count\n",
+ " self._count += other \n",
+ " return Counter(self._count)\n",
+ " \n",
+ "class CountDn(Counter): #derived class\n",
+ " \n",
+ " def __isub__(self,other): #decrement count\n",
+ " self._count -= other\n",
+ " return Counter(self._count)\n",
+ " \n",
+ " \n",
+ " \n",
+ "c1 = CountDn() #c1 of class CountDn\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display c1\n",
+ " \n",
+ "c1 += 1 #increment count 3 times\n",
+ "c1 += 1\n",
+ "c1 += 1\n",
+ "print 'c1 =',c1.get_count() #display count\n",
+ "\n",
+ "c1 -= 1 #decrement c1, twice\n",
+ "c1 -= 1\n",
+ "print 'c1 =',c1.get_count() #display c1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c1 = 3\n",
+ "c1 = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.2, Page Number 380"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter: #base class\n",
+ " def __init__(self,c=0): #constructor\n",
+ " self._count = c\n",
+ " \n",
+ " def get_count(self): #return count\n",
+ " return self._count\n",
+ " \n",
+ " def __iadd__(self,other): #increment count\n",
+ " self._count += other\n",
+ " return Counter(self._count)\n",
+ " \n",
+ " \n",
+ " \n",
+ "class CountDn(Counter): #derived class\n",
+ " def __init__(self,c=0): #constructor\n",
+ " self._count = c\n",
+ " \n",
+ " def __isub__(self,other): #decrement count\n",
+ " self._count -= 1\n",
+ " return CountDn(self._count)\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "c1 = CountDn() #class CountDn\n",
+ "c2 = CountDn(100)\n",
+ "\n",
+ "print 'c1 =',c1.get_count() #display\n",
+ "print 'c2 =',c2.get_count()\n",
+ "\n",
+ "c1 += 1 #increment c1\n",
+ "c1 += 1\n",
+ "c1 += 1\n",
+ "print 'c1 =',c1.get_count() #display c1\n",
+ "\n",
+ "c2 -= 1 #decrement c2\n",
+ "c2 -= 1\n",
+ "print 'c2 =',c2.get_count() #display it\n",
+ " \n",
+ "c3 = CountDn() #create c3\n",
+ "c2 -= 1 #decrement c2\n",
+ "c3 = c2 #assign count value of c2 to c3\n",
+ "print 'c3 =',c3.get_count() #display c3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 0\n",
+ "c2 = 100\n",
+ "c1 = 3\n",
+ "c2 = 98\n",
+ "c3 = 97\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3, Page Number 382"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Stack: \n",
+ " _MAX = 3 #size of stack array\n",
+ " _st = [None]*_MAX #stack\n",
+ " \n",
+ " def __init__(self): #constructor\n",
+ " self._top = -1\n",
+ " \n",
+ " def push(self,var): #put number on stack\n",
+ " self._top += 1\n",
+ " self._st[self._top] = var\n",
+ " \n",
+ " def pop(self): #take number off stack\n",
+ " x = self._st[self._top]\n",
+ " self._top -= 1\n",
+ " return x\n",
+ " \n",
+ " \n",
+ " \n",
+ "class Stack2(Stack):\n",
+ " \n",
+ " def push(self,var): #put number on stack\n",
+ " \n",
+ " if self._top >= self._MAX-1: #error if stack full \n",
+ " print 'Error: stack is full'\n",
+ " else:\n",
+ " Stack.push(self,var) #call push() in Stack class\n",
+ " \n",
+ " def pop(self): #take number off stack\n",
+ " if self._top < 0: #error if stack empty\n",
+ " return 'Error: stack is empty' \n",
+ " else:\n",
+ " return Stack.pop(self) #call pop() in Stack class\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "s1 = Stack2()\n",
+ "\n",
+ "s1.push(11) #push some values onto stack\n",
+ "s1.push(22)\n",
+ "s1.push(33)\n",
+ "\n",
+ "print s1.pop() #pop some values from stack\n",
+ "print s1.pop()\n",
+ "print s1.pop()\n",
+ "print s1.pop() #oops, popped one too many..."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "33\n",
+ "22\n",
+ "11\n",
+ "Error: stack is empty\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4, Page Number 385"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0): #constructor\n",
+ " self._feet = ft #can't be private\n",
+ " self._inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self._feet = input(\"Enter feet: \")\n",
+ " self._inches = input(\"Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self._feet , '\\' -' , self._inches , '\\\"'\n",
+ " \n",
+ " \n",
+ " \n",
+ "class DistSign(Distance): #adds sign to distance\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0,sg='pos'): #constructor\n",
+ " Distance.__init__(self,ft,inc) #call base class constructor\n",
+ " self._sign = sg #sign is pos or neg\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " Distance.getdist(self) #call base getdist()\n",
+ " \n",
+ " ch = raw_input(\"Enter sign (+ or -): \") #get sign from user\n",
+ " if ch == '+':\n",
+ " self._sign = 'pos'\n",
+ " else:\n",
+ " self._sign = 'neg'\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " if self._sign == 'pos': #show sign\n",
+ " print '(+)',\n",
+ " else:\n",
+ " print '(-)',\n",
+ " Distance.showdist(self) #show ft and in\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "alpha = DistSign() #object with no arg constructor\n",
+ "alpha.getdist() #get alpha from user\n",
+ "\n",
+ "beta = DistSign(11,6.25) #object with 2 - arg constructor\n",
+ "\n",
+ "gamma = DistSign(100,5.5,'neg') #object with 3 - arg constructor\n",
+ "\n",
+ "print '\\nalpha =', #display all distances\n",
+ "alpha.showdist()\n",
+ "print 'beta =',\n",
+ "beta.showdist()\n",
+ "print 'gamma =',\n",
+ "gamma.showdist()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 2.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter sign (+ or -): -\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "alpha = (-) 6 ' - 2.5 \"\n",
+ "beta = (+) 11 ' - 6.25 \"\n",
+ "gamma = (-) 100 ' - 5.5 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5, Page Number 389"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LEN = 80 #maximum length\n",
+ "\n",
+ "class employee: #employee class\n",
+ " __name = [None]*LEN #employee name\n",
+ " \n",
+ " def getdata(self): #get data from user\n",
+ " self.__name = raw_input(\" Enter last name: \")\n",
+ " self.__number = input(\" Enter number: \") #employee number\n",
+ " \n",
+ " def putdata(self): #display data\n",
+ " print ' Name:',self.__name \n",
+ " print ' Number:',self.__number\n",
+ " \n",
+ " \n",
+ " \n",
+ "class manager(employee): #management class\n",
+ " __title = [None]*LEN #'vice-president' etc. \n",
+ " \n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__title = raw_input(\" Enter Title: \")\n",
+ " self.__dues = input(\" Enter golf club dues: \") #golf club dues\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Title:',self.__title\n",
+ " print ' Number:',self.__dues\n",
+ " \n",
+ " \n",
+ " \n",
+ "class scientist(employee): #scientist class\n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__pubs = raw_input(\" Enter Number of pubs: \") #number of publication\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Number of publications:',self.__pubs\n",
+ " \n",
+ " \n",
+ "class laborer(employee): #labour class\n",
+ " pass \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "m1 = manager()\n",
+ "m2 = manager()\n",
+ "s1 = scientist()\n",
+ "l1 = laborer()\n",
+ " #get data for several employees\n",
+ "print 'Enter data for manager 1'\n",
+ "m1.getdata()\n",
+ "\n",
+ "print 'Enter data for manager 2'\n",
+ "m2.getdata()\n",
+ "\n",
+ "print 'Enter data for scientist 1'\n",
+ "s1.getdata()\n",
+ "\n",
+ "print 'Enter data for laborer 1'\n",
+ "l1.getdata()\n",
+ "\n",
+ " #display data for several employees\n",
+ "print '\\nData on manager 1'\n",
+ "m1.putdata()\n",
+ "\n",
+ "print 'Data on manager 2'\n",
+ "m2.putdata()\n",
+ "\n",
+ "print 'Data on scientist 1'\n",
+ "s1.putdata()\n",
+ "\n",
+ "print 'Data on laborer 1'\n",
+ "l1.putdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for manager 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Wainsworth\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Title: President\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter golf club dues: 1000000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for manager 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Bradley\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 124\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Title: Vice-President\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter golf club dues: 500000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for scientist 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Hauptman-Frenglish\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 234234\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of pubs: 999\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for laborer 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: jones\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 6546544\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Data on manager 1\n",
+ " Name: Wainsworth\n",
+ " Number: 10\n",
+ " Title: President\n",
+ " Number: 1000000\n",
+ "Data on manager 2\n",
+ " Name: Bradley\n",
+ " Number: 124\n",
+ " Title: Vice-President\n",
+ " Number: 500000\n",
+ "Data on scientist 1\n",
+ " Name: Hauptman-Frenglish\n",
+ " Number: 234234\n",
+ " Number of publications: 999\n",
+ "Data on laborer 1\n",
+ " Name: jones\n",
+ " Number: 6546544\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6, Page Number 393"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import Turtle,setup,done #importing turtles library\n",
+ "\n",
+ "class shape: #base class\n",
+ " def __init__(self,x=0,y=0,fc=\"white\"): #constructor\n",
+ " self._xCo = x #coordinate for shape\n",
+ " self._yCo = y\n",
+ " self._fillcolor = fc #color for shape\n",
+ "\n",
+ " \n",
+ "\n",
+ "class circle(shape): #defining circle class\n",
+ " \n",
+ " def __init__(self,x,y,r,fc): #constructor for set circle attribute\n",
+ " shape.__init__(self,x,y,fc) \n",
+ " self._radius = r\n",
+ " \n",
+ " def draw(self): #draw the circle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " turtle.color(self._fillcolor)\n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.circle(self._radius)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ " \n",
+ " \n",
+ "class rect(shape): #defining rectangle class\n",
+ " \n",
+ " def __init__(self,x,y,h,w,fc): #constructor\n",
+ " shape.__init__(self,x,y,fc) \n",
+ " self._height = h\n",
+ " self._weight = w\n",
+ " \n",
+ " def draw(self): #draw the rectangle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " turtle.color(self._fillcolor)\n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.forward(self._weight) \n",
+ " turtle.left(90)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.left(90)\n",
+ " turtle.forward(self._weight)\n",
+ " turtle.left(90)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done() \n",
+ "\n",
+ " \n",
+ "class tria(shape): #defining triangle class\n",
+ " \n",
+ " def __init__(self,x,y,h,fc): #constructor \n",
+ " shape.__init__(self,x,y,fc) \n",
+ " self._height = h\n",
+ " \n",
+ " def draw(self): #draw the triangle\n",
+ " setup()\n",
+ " turtle = Turtle()\n",
+ " turtle.begin_fill()\n",
+ " turtle.color(self._fillcolor)\n",
+ " turtle.up()\n",
+ " turtle.goto(self._xCo,self._yCo)\n",
+ " turtle.down()\n",
+ " turtle.forward(self._height) \n",
+ " turtle.left(120)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.left(120)\n",
+ " turtle.forward(self._height)\n",
+ " turtle.end_fill()\n",
+ " turtle.hideturtle()\n",
+ " done()\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "cir = circle(40,12,5,\"blue\") #create circle\n",
+ "rec = rect(12,7,10,15,\"red\") #create rectangle\n",
+ "tri = tria(60,7,11,\"green\") #create triangle\n",
+ "\n",
+ "#draw all shape\n",
+ "cir.draw()\n",
+ "rec.draw()\n",
+ "tri.draw()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.7, Page Number 397"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A: #base class\n",
+ " __privdataA = None #private variable\n",
+ " _protdataA = None #protected variable\n",
+ " pubdataA = None #public variable\n",
+ " \n",
+ "class B(A):\n",
+ " def funct(self):\n",
+ " a = self.__privdataA\n",
+ " a = self._protdataA\n",
+ " a = self.pubdataA\n",
+ " \n",
+ "class C(A):\n",
+ " def funct(self):\n",
+ " a = self.__privdataA\n",
+ " a = self._protdataA\n",
+ " a = self._pubdataA\n",
+ " \n",
+ " \n",
+ " \n",
+ "objB = B()\n",
+ "#a = objB.privdataA #not accesible because private variable\n",
+ "#a = objB.protdataA #not accesible because protected variable\n",
+ "a = objB.pubdataA\n",
+ "\n",
+ "objC = C()\n",
+ "#a = objC.privdataA #not accesible because private variable\n",
+ "#a = objC.protdataA #not accesible because protected variable\n",
+ "a = objC.pubdataA #In python, there is no concept of public or private inheritance so this line won't show any arror"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.8, Page Number 400"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LEN = 80 #maximum length of names\n",
+ "\n",
+ "class employee: #employee class\n",
+ " __name = [None]*LEN #employee name\n",
+ " \n",
+ " def getdata(self): #get data from user\n",
+ " self.__name = raw_input(\" Enter last name: \")\n",
+ " self.__number = input(\" Enter number: \") #employee number\n",
+ " \n",
+ " def putdata(self): #display data\n",
+ " print ' Name:',self.__name\n",
+ " print ' Number:',self.__number\n",
+ " \n",
+ " \n",
+ "class manager(employee): #management class\n",
+ " __title = [None]*LEN #'vice-president' etc. \n",
+ " \n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__title = raw_input(\" Enter Title: \")\n",
+ " self.__dues = input(\" Enter golf club dues: \") #golf club dues\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Title:',self.__title\n",
+ " print ' Number:',self.__dues\n",
+ " \n",
+ " \n",
+ "class scientist(employee): #scientist class\n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__pubs = raw_input(\" Enter Number of pubs: \") #number of publication\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Number of publications:',self.__pubs\n",
+ " \n",
+ " \n",
+ "class laborer(employee): #laborer class\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "class foreman(laborer): #foreman class\n",
+ " def getdata(self): \n",
+ " laborer.getdata(self)\n",
+ " self.__quotas = raw_input(\" Enter quotas: \") #percent of quotes met successfully\n",
+ " \n",
+ " def putdata(self):\n",
+ " laborer.putdata(self)\n",
+ " print ' Quotas:',self.__quotas\n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ "l1 = laborer()\n",
+ "f1 = foreman()\n",
+ " #get data for several employees\n",
+ "print 'Enter data for laborer 1'\n",
+ "l1.getdata()\n",
+ "\n",
+ "print 'Enter data for foreman 1'\n",
+ "f1.getdata()\n",
+ "\n",
+ " #display data for several employees\n",
+ "print '\\nData on laborer 1'\n",
+ "l1.putdata()\n",
+ "\n",
+ "print 'Data on foreman 1'\n",
+ "f1.putdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for laborer 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Jones\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 6546544\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for foreman 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Jones\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 6546544\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter quotas: 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Data on laborer 1\n",
+ " Name: Jones\n",
+ " Number: 6546544\n",
+ "Data on foreman 1\n",
+ " Name: Jones\n",
+ " Number: 6546544\n",
+ " Quotas: 100\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.9, Page Number 405"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "LEN = 80 #maximum length of names\n",
+ "\n",
+ "\n",
+ "class student: #eduational background\n",
+ " __school = [None]*LEN #name of school or university\n",
+ " __degree = [None]*LEN #hightest degree earned\n",
+ " \n",
+ " def getedu(self):\n",
+ " self.__school = raw_input(\" Enter name of school or university: \")\n",
+ " print ' Enter highest degree earned '\n",
+ " self.__degree = raw_input(\" (Highschool, Bachelor\\'s, Master\\'s, PhD): \")\n",
+ " \n",
+ " def putedu(self):\n",
+ " print ' School or Uniersity:',self.__school\n",
+ " print ' Highest degree earned:',self.__degree\n",
+ " \n",
+ " \n",
+ "class employee: #employee class\n",
+ " __name = [None]*LEN #employee name\n",
+ " \n",
+ " def getdata(self):\n",
+ " self.__name = raw_input(\" Enter last name: \")\n",
+ " self.__number = input(\" Enter number: \") #employee number\n",
+ " \n",
+ " def putdata(self):\n",
+ " print ' Name:',self.__name\n",
+ " print ' Number:',self.__number\n",
+ " \n",
+ " \n",
+ "class manager(employee,student): #management\n",
+ " __title = [None]*LEN #\"vice-precident\" etc.\n",
+ " \n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__title = raw_input(\" Enter Title: \")\n",
+ " self.__dues = input(\" Enter golf club dues: \") #golf club dues\n",
+ " student.getedu(self)\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Title:',self.__title\n",
+ " print ' Number:',self.__dues\n",
+ " student.putedu(self)\n",
+ " \n",
+ " \n",
+ "class scientist(employee,student): #scientist\n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " self.__pubs = raw_input(\" Enter Number of pubs: \") #number of publications\n",
+ " student.getedu(self)\n",
+ " \n",
+ " def putdata(self):\n",
+ " employee.putdata(self)\n",
+ " print ' Number of publications:',self.__pubs\n",
+ " student.putedu(self)\n",
+ " \n",
+ " \n",
+ "class laborer(employee): #labrer\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "\n",
+ "m1 = manager()\n",
+ "s1 = scientist()\n",
+ "s2 = scientist()\n",
+ "l1 = laborer()\n",
+ "\n",
+ " #get data for several employee\n",
+ "print '\\nEnter data for manager 1'\n",
+ "m1.getdata()\n",
+ "\n",
+ "print '\\nEnter data for scientist 1'\n",
+ "s1.getdata()\n",
+ "\n",
+ "print '\\nEnter data for scientist 2'\n",
+ "s2.getdata()\n",
+ "\n",
+ "print '\\nEnter data for laborer 1'\n",
+ "l1.getdata()\n",
+ "\n",
+ " #display data for several employee\n",
+ "print '\\n\\nData on manager 1'\n",
+ "m1.putdata()\n",
+ "\n",
+ "print '\\nData on scientist 1'\n",
+ "s1.putdata()\n",
+ "\n",
+ "print '\\nData on scientist 2'\n",
+ "s2.putdata()\n",
+ "\n",
+ "print '\\nData on laborer 1'\n",
+ "l1.putdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for manager 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Bradley\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Title: Vice-President\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter golf club dues: 100000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name of school or university: Yale\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter highest degree earned \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (Highschool, Bachelor's, Master's, PhD): Bachelor's\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for scientist 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Twilling\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 764\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of pubs: 99\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name of school or university: MIT\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter highest degree earned \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (Highschool, Bachelor's, Master's, PhD): PhD\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for scientist 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Yang\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 845\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of pubs: 101\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name of school or university: Stanford\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter highest degree earned \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (Highschool, Bachelor's, Master's, PhD): Master's\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for laborer 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Jones\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 48323\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Data on manager 1\n",
+ " Name: Bradley\n",
+ " Number: 12\n",
+ " Title: Vice-President\n",
+ " Number: 100000\n",
+ " School or Uniersity: Yale\n",
+ " Highest degree earned: Bachelor's\n",
+ "\n",
+ "Data on scientist 1\n",
+ " Name: Twilling\n",
+ " Number: 764\n",
+ " Number of publications: 99\n",
+ " School or Uniersity: MIT\n",
+ " Highest degree earned: PhD\n",
+ "\n",
+ "Data on scientist 2\n",
+ " Name: Yang\n",
+ " Number: 845\n",
+ " Number of publications: 101\n",
+ " School or Uniersity: Stanford\n",
+ " Highest degree earned: Master's\n",
+ "\n",
+ "Data on laborer 1\n",
+ " Name: Jones\n",
+ " Number: 48323\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.10, Page Number 409"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Type: #type of lumber\n",
+ " \n",
+ " def __init__(self,di = \"N/A\",gr = \"N/A\"): #constructor\n",
+ " self.__dimensions = di\n",
+ " self.__grade = gr\n",
+ " \n",
+ " def gettype(self): #get type from user\n",
+ " self.__dimensions = raw_input(\" Enter nominal dimensions (2x4 etc.): \")\n",
+ " self.__grade = raw_input(\" Enter grade (rough, const, etc.): \")\n",
+ " \n",
+ " def showtype(self): #display type\n",
+ " print ' Dimensions:',self.__dimensions\n",
+ " print ' Grade:',self.__grade\n",
+ " \n",
+ " \n",
+ "class Distance: #Distance class\n",
+ " \n",
+ " def __init__(self,ft=0,inc=0.0): #constructor\n",
+ " self.__feet = ft\n",
+ " self.__inches = inc\n",
+ " \n",
+ " def getdist(self): #get length from user\n",
+ " self.__feet = input(\" Enter feet: \")\n",
+ " self.__inches = input(\" Enter inches: \")\n",
+ " \n",
+ " def showdist(self): #display distance\n",
+ " print self.__feet , '\\' -' , self.__inches , '\\\"'\n",
+ " \n",
+ "class Lumber(Type,Distance):\n",
+ " \n",
+ " def __init__(self,di=None,gr=None,ft=0,inc=0.0,qu=0,prc=0.0): #constructor\n",
+ " \n",
+ " Type.__init__(self,di,gr) #call type constructor\n",
+ " Distance.__init__(self,ft,inc) #call Distance constructor\n",
+ " \n",
+ " self.__quantity = qu #number of pieces\n",
+ " self.__price = prc #price of each piece\n",
+ " \n",
+ " \n",
+ " def getlumber(self):\n",
+ " Type.gettype(self)\n",
+ " Distance.getdist(self)\n",
+ " \n",
+ " self.__quantity = input(\" Enter quantity: \")\n",
+ " self.__price = input(\" Enter price per piece: \")\n",
+ " \n",
+ " \n",
+ " def showlumber(self):\n",
+ " Type.showtype(self)\n",
+ " print ' Length: ',\n",
+ " Distance.showdist(self)\n",
+ " print ' price for',self.__quantity,'pieces: $',self.__price*self.__quantity\n",
+ " \n",
+ " \n",
+ " \n",
+ " \n",
+ "siding = Lumber() #constructor with no argument\n",
+ "\n",
+ "print 'Siding data:'\n",
+ "siding.getlumber() #get siding from user\n",
+ "\n",
+ "studs = Lumber(\"2x4\",\"const\",8,0.0,200,4.5) #constructor with 6 arguments\n",
+ "\n",
+ "print '\\nSiding' #display lumber data\n",
+ "siding.showlumber()\n",
+ "print 'studs'\n",
+ "studs.showlumber()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Siding data:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter nominal dimensions (2x4 etc.): 3x4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter grade (rough, const, etc.): rough\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter feet: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter inches: 6.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter quantity: 300\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter price per piece: 19.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Siding\n",
+ " Dimensions: 3x4\n",
+ " Grade: rough\n",
+ " Length: 5 ' - 6.5 \"\n",
+ " price for 300 pieces: $ 5850.0\n",
+ "studs\n",
+ " Dimensions: 2x4\n",
+ " Grade: const\n",
+ " Length: 8 ' - 0.0 \"\n",
+ " price for 200 pieces: $ 900.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.11, Page Number 413"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " def show(self):\n",
+ " print 'Class A'\n",
+ " \n",
+ "class B:\n",
+ " def show(self):\n",
+ " print 'Class B'\n",
+ " \n",
+ "class C(A,B):\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "\n",
+ "objC = C() #object of class C\n",
+ "#objC.show() \n",
+ "A().show() \n",
+ "B().show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Class A\n",
+ "Class B\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.12, Page Number 414"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " def func(self):\n",
+ " pass\n",
+ " \n",
+ "class B(A):\n",
+ " pass\n",
+ "class C(A):\n",
+ " pass\n",
+ "class D(B,C):\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "\n",
+ "objD = D()\n",
+ "#objD.func()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.13, Page Number 417"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class student: #educational background\n",
+ " \n",
+ " def getedu(self):\n",
+ " self.__school = raw_input(\" Enter name of school or university: \") #name of school or university\n",
+ " print ' Enter highest degree earned '\n",
+ " self.__degree = raw_input(\" (Highschool, Bachelor\\'s, Master\\'s, PhD): \") #heighest degree earned\n",
+ " \n",
+ " def putedu(self):\n",
+ " print ' School or Uniersity:',self.__school\n",
+ " print ' Highest degree earned:',self.__degree\n",
+ " \n",
+ " \n",
+ "class employee:\n",
+ " \n",
+ " def getdata(self):\n",
+ " self.__name = raw_input(\" Enter last name: \") #employee name\n",
+ " self.__number = input(\" Enter number: \") #employee number\n",
+ " \n",
+ " def putdata(self):\n",
+ " print ' Name:',self.__name\n",
+ " print ' Number:',self.__number\n",
+ " \n",
+ " \n",
+ "class manager: #management\n",
+ " \n",
+ " __emp = employee() #object of class employee\n",
+ " __stu = student() #object of class student\n",
+ " \n",
+ " def getdata(self):\n",
+ " self.__emp.getdata()\n",
+ " self.__title = raw_input(\" Enter Title: \") #\"vice-president\" etc.\n",
+ " self.__dues = input(\" Enter golf club dues: \") #golf club dues\n",
+ " self.__stu.getedu()\n",
+ " \n",
+ " def putdata(self):\n",
+ " self.__emp.putdata()\n",
+ " print ' Title:',self.__title\n",
+ " print ' Number:',self.__dues\n",
+ " self.__stu.putedu()\n",
+ " \n",
+ " \n",
+ "class scientist: #scientist\n",
+ " \n",
+ " __emp = employee() #object of class employee\n",
+ " __stu = student() #object of class student\n",
+ " \n",
+ " def getdata(self):\n",
+ " self.__emp.getdata()\n",
+ " self.__pubs = raw_input(\" Enter Number of pubs: \") #number of publications\n",
+ " self.__stu.getedu()\n",
+ " \n",
+ " def putdata(self):\n",
+ " self.__emp.putdata()\n",
+ " print ' Number of publications:',self.__pubs\n",
+ " self.__stu.putedu()\n",
+ " \n",
+ " \n",
+ "class laborer: #laborer\n",
+ " \n",
+ " __emp = employee() #object of class employee\n",
+ " \n",
+ " def getdata(self):\n",
+ " self.__emp.getdata()\n",
+ " def putdata(self):\n",
+ " self.__emp.putdata()\n",
+ " \n",
+ " \n",
+ "\n",
+ "m1 = manager()\n",
+ "s1 = scientist()\n",
+ "s2 = scientist()\n",
+ "l1 = laborer()\n",
+ "\n",
+ " #get data for several employee\n",
+ "print '\\nEnter data for manager 1'\n",
+ "m1.getdata()\n",
+ "\n",
+ "print '\\nEnter data for scientist 1'\n",
+ "s1.getdata()\n",
+ "\n",
+ "print '\\nEnter data for scientist 2'\n",
+ "s2.getdata()\n",
+ "\n",
+ "print '\\nEnter data for laborer 1'\n",
+ "l1.getdata()\n",
+ "\n",
+ " #display data for several employee\n",
+ "print '\\n\\nData on manager 1'\n",
+ "m1.putdata()\n",
+ "\n",
+ "print '\\nData on scientist 1'\n",
+ "s1.putdata()\n",
+ "\n",
+ "print '\\nData on scientist 2'\n",
+ "s2.putdata()\n",
+ "\n",
+ "print '\\nData on laborer 1'\n",
+ "l1.putdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for manager 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Bradley\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Title: Vice-President\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter golf club dues: 100000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name of school or university: Yale\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter highest degree earned \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (Highschool, Bachelor's, Master's, PhD): Bachelor's\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for scientist 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Twilling\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 764\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of pubs: 99\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name of school or university: MIT\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter highest degree earned \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (Highschool, Bachelor's, Master's, PhD): PhD\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for scientist 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Yang\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 845\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number of pubs: 101\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter name of school or university: Stanford\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter highest degree earned \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (Highschool, Bachelor's, Master's, PhD): master's\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data for laborer 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter last name: Jones\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter number: 48323\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Data on manager 1\n",
+ " Name: Bradley\n",
+ " Number: 12\n",
+ " Title: Vice-President\n",
+ " Number: 100000\n",
+ " School or Uniersity: Yale\n",
+ " Highest degree earned: Bachelor's\n",
+ "\n",
+ "Data on scientist 1\n",
+ " Name: Yang\n",
+ " Number: 845\n",
+ " Number of publications: 99\n",
+ " School or Uniersity: Stanford\n",
+ " Highest degree earned: master's\n",
+ "\n",
+ "Data on scientist 2\n",
+ " Name: Yang\n",
+ " Number: 845\n",
+ " Number of publications: 101\n",
+ " School or Uniersity: Stanford\n",
+ " Highest degree earned: master's\n",
+ "\n",
+ "Data on laborer 1\n",
+ " Name: Jones\n",
+ " Number: 48323\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation/screenshots/SNR.png b/Optical_Communiation/screenshots/SNR.png
new file mode 100755
index 00000000..e80cbedb
--- /dev/null
+++ b/Optical_Communiation/screenshots/SNR.png
Binary files differ
diff --git a/Optical_Communiation/screenshots/SNR_1.png b/Optical_Communiation/screenshots/SNR_1.png
new file mode 100755
index 00000000..e80cbedb
--- /dev/null
+++ b/Optical_Communiation/screenshots/SNR_1.png
Binary files differ
diff --git a/Optical_Communiation/screenshots/pulse_broadning.png b/Optical_Communiation/screenshots/pulse_broadning.png
new file mode 100755
index 00000000..f104ba08
--- /dev/null
+++ b/Optical_Communiation/screenshots/pulse_broadning.png
Binary files differ
diff --git a/Optical_Communiation/screenshots/pulse_broadning_1.png b/Optical_Communiation/screenshots/pulse_broadning_1.png
new file mode 100755
index 00000000..f104ba08
--- /dev/null
+++ b/Optical_Communiation/screenshots/pulse_broadning_1.png
Binary files differ
diff --git a/Optical_Communiation/screenshots/shot_noise_and_thermal_noise.png b/Optical_Communiation/screenshots/shot_noise_and_thermal_noise.png
new file mode 100755
index 00000000..a4062961
--- /dev/null
+++ b/Optical_Communiation/screenshots/shot_noise_and_thermal_noise.png
Binary files differ
diff --git a/Optical_Communiation/screenshots/shot_noise_and_thermal_noise_1.png b/Optical_Communiation/screenshots/shot_noise_and_thermal_noise_1.png
new file mode 100755
index 00000000..a4062961
--- /dev/null
+++ b/Optical_Communiation/screenshots/shot_noise_and_thermal_noise_1.png
Binary files differ
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter1.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter1.ipynb
new file mode 100755
index 00000000..a271cc5c
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter1.ipynb
@@ -0,0 +1,128 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:985ad452c65fa6c321f3f5a416b2ee95d94eb6cba2ef0da1eac4d7b73a848422"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter1 - Overview of optical fiber communications"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.6.1, page 1-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Bit_rate = 2*10**9 # bit rate of channel\n",
+ "# Given sequence is 010111101110\n",
+ "Shortest_duration = 1*(1/Bit_rate) # shortest duration is '1'\n",
+ "Widest_duration = 4*(1/Bit_rate) #widest duration is '1111'\n",
+ "Shortest_duration = Shortest_duration # seconds\n",
+ "Widest_duration = Widest_duration # seconds\n",
+ "print \"Shortest duration is %.1g seconds.\" %Shortest_duration\n",
+ "print \"Widest duration is %.1g seconds.\" %Widest_duration"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Shortest duration is 5e-10 seconds.\n",
+ "Widest duration is 2e-09 seconds.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.12.1, page 1-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log2\n",
+ "Bandwidth = 2*10**6 #Bandwidth of channel\n",
+ "Signal_to_Noise_ratio = 1 #Signal to Noise ratio of channel\n",
+ "Capacity = Bandwidth * log2(1 + Signal_to_Noise_ratio) #computing capacity\n",
+ "Capacity=Capacity/10**6 \n",
+ "print \"Maximum capacity of channel is %d Mb/sec.\" %Capacity"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum capacity of channel is 2 Mb/sec.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Question 10, page 1-31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Bit_rate = 2*10**9 # bit rate of channel\n",
+ "# Given sequence is 010111101110\n",
+ "Shortest_duration = 1*(1/Bit_rate) # shortest duration is '1'\n",
+ "Widest_duration = 4*(1/Bit_rate) #widest duration is '1111'\n",
+ "Shortest_duration = Shortest_duration # seconds\n",
+ "Widest_duration = Widest_duration # seconds\n",
+ "print \"Shortest duration is %.1g seconds.\" %Shortest_duration\n",
+ "print \"Widest duration is %.1g seconds.\" %Widest_duration"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Shortest duration is 5e-10 seconds.\n",
+ "Widest duration is 2e-09 seconds.\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter10.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter10.ipynb
new file mode 100755
index 00000000..6479ba9e
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter10.ipynb
@@ -0,0 +1,96 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:0e6d6451a42a64c2f14a17049d585a97e1d159d84d0a7abf55f333e84dfeeece"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter10 - Performance measurement and monitoring"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.5.1, page 10-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "from __future__ import division\n",
+ "To=12.6 #width of output pulse\n",
+ "Ti=0.3 #width of input pulse\n",
+ "l=1.2 #length of measurement\n",
+ "Pulse_dispersion = sqrt(To**2 - Ti**2) #computing pulse dispersion\n",
+ "PDKM=Pulse_dispersion/l #computing pulse dispersion per Kilometer\n",
+ "BW=0.44/PDKM #computing optical bandwidth\n",
+ "BW=BW*1000 \n",
+ "print \"Pulse broadning is %.1f ns/km.\\nOptical bandwidth is %.1f MHz.Km.\" %(PDKM,BW) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pulse broadning is 10.5 ns/km.\n",
+ "Optical bandwidth is 41.9 MHz.Km.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.6.1, page 10-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log10\n",
+ "V2=12 \n",
+ "V1=2.5 \n",
+ "L2=3 \n",
+ "L1=0.004 \n",
+ "alpha_dB = 10* log10(V2/V1)/(L2-L1) \n",
+ "un = 0.2/(L2-L1) \n",
+ "print \"Attenuation is %.2f dB/km\\nUncertainity +/- %.3f dB.\" %(alpha_dB,un) \n",
+ "#answer for attenuation in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Attenuation is 2.27 dB/km\n",
+ "Uncertainity +/- 0.067 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter10_1.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter10_1.ipynb
new file mode 100755
index 00000000..6479ba9e
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter10_1.ipynb
@@ -0,0 +1,96 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:0e6d6451a42a64c2f14a17049d585a97e1d159d84d0a7abf55f333e84dfeeece"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter10 - Performance measurement and monitoring"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.5.1, page 10-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "from __future__ import division\n",
+ "To=12.6 #width of output pulse\n",
+ "Ti=0.3 #width of input pulse\n",
+ "l=1.2 #length of measurement\n",
+ "Pulse_dispersion = sqrt(To**2 - Ti**2) #computing pulse dispersion\n",
+ "PDKM=Pulse_dispersion/l #computing pulse dispersion per Kilometer\n",
+ "BW=0.44/PDKM #computing optical bandwidth\n",
+ "BW=BW*1000 \n",
+ "print \"Pulse broadning is %.1f ns/km.\\nOptical bandwidth is %.1f MHz.Km.\" %(PDKM,BW) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pulse broadning is 10.5 ns/km.\n",
+ "Optical bandwidth is 41.9 MHz.Km.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.6.1, page 10-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log10\n",
+ "V2=12 \n",
+ "V1=2.5 \n",
+ "L2=3 \n",
+ "L1=0.004 \n",
+ "alpha_dB = 10* log10(V2/V1)/(L2-L1) \n",
+ "un = 0.2/(L2-L1) \n",
+ "print \"Attenuation is %.2f dB/km\\nUncertainity +/- %.3f dB.\" %(alpha_dB,un) \n",
+ "#answer for attenuation in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Attenuation is 2.27 dB/km\n",
+ "Uncertainity +/- 0.067 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter1_1.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter1_1.ipynb
new file mode 100755
index 00000000..a271cc5c
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter1_1.ipynb
@@ -0,0 +1,128 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:985ad452c65fa6c321f3f5a416b2ee95d94eb6cba2ef0da1eac4d7b73a848422"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter1 - Overview of optical fiber communications"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.6.1, page 1-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Bit_rate = 2*10**9 # bit rate of channel\n",
+ "# Given sequence is 010111101110\n",
+ "Shortest_duration = 1*(1/Bit_rate) # shortest duration is '1'\n",
+ "Widest_duration = 4*(1/Bit_rate) #widest duration is '1111'\n",
+ "Shortest_duration = Shortest_duration # seconds\n",
+ "Widest_duration = Widest_duration # seconds\n",
+ "print \"Shortest duration is %.1g seconds.\" %Shortest_duration\n",
+ "print \"Widest duration is %.1g seconds.\" %Widest_duration"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Shortest duration is 5e-10 seconds.\n",
+ "Widest duration is 2e-09 seconds.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.12.1, page 1-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log2\n",
+ "Bandwidth = 2*10**6 #Bandwidth of channel\n",
+ "Signal_to_Noise_ratio = 1 #Signal to Noise ratio of channel\n",
+ "Capacity = Bandwidth * log2(1 + Signal_to_Noise_ratio) #computing capacity\n",
+ "Capacity=Capacity/10**6 \n",
+ "print \"Maximum capacity of channel is %d Mb/sec.\" %Capacity"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum capacity of channel is 2 Mb/sec.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Question 10, page 1-31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Bit_rate = 2*10**9 # bit rate of channel\n",
+ "# Given sequence is 010111101110\n",
+ "Shortest_duration = 1*(1/Bit_rate) # shortest duration is '1'\n",
+ "Widest_duration = 4*(1/Bit_rate) #widest duration is '1111'\n",
+ "Shortest_duration = Shortest_duration # seconds\n",
+ "Widest_duration = Widest_duration # seconds\n",
+ "print \"Shortest duration is %.1g seconds.\" %Shortest_duration\n",
+ "print \"Widest duration is %.1g seconds.\" %Widest_duration"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Shortest duration is 5e-10 seconds.\n",
+ "Widest duration is 2e-09 seconds.\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter2.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter2.ipynb
new file mode 100755
index 00000000..934feb4e
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter2.ipynb
@@ -0,0 +1,886 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:94ac7a20c62e9612d243d85d9b1b3699e50dc46a0975e66ae373ce7747106bc9"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter2 - Optical Fibers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4.1 page 2-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import arcsin, sqrt, pi\n",
+ "#Numerical Aperture and critical angle\n",
+ "n1=1.46 #refractive index\n",
+ "d=0.01 #difference\n",
+ "na=n1*sqrt(2*d) #numerical aperture\n",
+ "x=1-d #\n",
+ "oc=arcsin(x)*180/pi #in degree\n",
+ "print \"numerical aperture = \",round(na,2)\n",
+ "print \"critical angle at core cladding interface =\",round(oc,1),\" degree\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "numerical aperture = 0.21\n",
+ "critical angle at core cladding interface = 81.9 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.1, page 2-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import arcsin, sqrt, pi\n",
+ "#Numerical Aperture ,critical angle and acceptance angle\n",
+ "n2=1.45 #core refrative index\n",
+ "n1=1.49 #cladding refrative index\n",
+ "oc=arcsin(n2/n1)*180/pi #in degree\n",
+ "na=sqrt(n1**2-n2**2) #numerical aperture\n",
+ "pc=arcsin(na)*180/pi #degree\n",
+ "print \"critical angle is =\",round(oc,2),\" degree\"\n",
+ "print \"numerical aperture =\",round(na,3)\n",
+ "print \"acceptance angle is\",round(pc,2),\" degree\"\n",
+ "# Answer in the book are not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "critical angle is = 76.69 degree\n",
+ "numerical aperture = 0.343\n",
+ "acceptance angle is 20.06 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.2, page 2-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import arcsin, sqrt, pi\n",
+ "delta = 1.2/100 # Relative refractive difference index\n",
+ "n1=1.45 # Core refractive index \n",
+ "NA= n1*sqrt(2*delta) #computing numerical aperture\n",
+ "Acceptance_angle = arcsin(NA)*180/pi #computing acceptance angle\n",
+ "si = pi*NA**2 #computing solid acceptance angle\n",
+ "print \"Numerical aperture is %.3f.\\nAcceptance angle is %.2f degree.\\nSolid acceptance angle is %.3f radians.\" %(NA,Acceptance_angle,si) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numerical aperture is 0.225.\n",
+ "Acceptance angle is 12.98 degree.\n",
+ "Solid acceptance angle is 0.159 radians.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.3, page 2-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NA = 0.45 # Numerical Aperture\n",
+ "Acceptance_angle = arcsin(NA)*180/pi #computing acceptance angle.\n",
+ "print \"Acceptance angle is %.1f degree.\" %Acceptance_angle"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Acceptance angle is 26.7 degree.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.4, page 2-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import arctan\n",
+ "diameter = 1 #Diameter in centimeter\n",
+ "Focal_length = 10 #Focal length in centimeter\n",
+ "radius=diameter/2 #computing radius\n",
+ "Acceptance_angle = arctan(radius/Focal_length)*180/pi #computing acceptance angle\n",
+ "Conical_full_angle = 2*Acceptance_angle #computing conical angle\n",
+ "Solid_acceptance_angle = pi*Acceptance_angle**2 #computing solid acceptance angle\n",
+ "NA = sqrt(Solid_acceptance_angle/pi) #computing Numerical aperture\n",
+ "print \"Numerical aperture is %.2f.\\nConical full angle is %.2f degree.\" %(NA,Conical_full_angle) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numerical aperture is 2.86.\n",
+ "Conical full angle is 5.72 degree.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6.1, page 2-16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import cos\n",
+ "NA = 0.45 #Numerical aperture\n",
+ "betaB = 45 # Skew ray change direction by 90 degree at each reflection\n",
+ "Meridional_theta = arcsin(NA)*180/pi #computing acceptacne angle for meridoinal ray\n",
+ "Skew_theta = arcsin(NA/cos(betaB*pi/180))*180/pi #computing acceptacne angle for skew ray\n",
+ "print \"Acceptacne angle for Meridoinal ray is %.2f degree.\\nAcceptance angle for Skew ray %.1f degree.\" %(Meridional_theta,Skew_theta) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Acceptacne angle for Meridoinal ray is 26.74 degree.\n",
+ "Acceptance angle for Skew ray 39.5 degree.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.1, page 2-21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "core_diameter=78*10**-6 #core diameter\n",
+ "delta=1.4/100 #relative index difference\n",
+ "lamda=0.8*10**-6 #operating wavelength\n",
+ "n1=1.47 #core refractive index\n",
+ "a=core_diameter/2 #computing core radius\n",
+ "v= 2*3.14*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "M=(v)**2/2 #computing guided modes\n",
+ "print \"Normalized Frequency is %.3f.\\nTotal number of guided modes are %.1f\" %(v,M)\n",
+ "#answer in the book are incorrect."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 75.306.\n",
+ "Total number of guided modes are 2835.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.2, page 2-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.47 #refractive index of core\n",
+ "a=4.3*10**-6 #radius of core\n",
+ "delta=0.2/100 #relative index difference\n",
+ "lamda= 2*3.14*a*n1*sqrt(2*delta)/2.405 #computing wavelength\n",
+ "lamda=lamda*10**9 \n",
+ "print \"Wavelength of fiber is %d nm.\" %lamda\n",
+ "#answer in the book is given as 1230nm which is incorrect."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavelength of fiber is 1043 nm.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.3, page 2-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.482 #refractive index of core\n",
+ "n2=1.474 #refractive index of cladding\n",
+ "lamda=820*10**-9 #Wavelength\n",
+ "NA=sqrt(n1**2 - n2**2) #computing Numerical aperture\n",
+ "theta= arcsin(NA)*180/pi #computing acceptance angle\n",
+ "solid_angle=pi*(NA)**2 #computing solid angle\n",
+ "a=2.405*lamda/(2*3.14*NA) #computing core radius\n",
+ "a=a*10**6 \n",
+ "print \"Numerical aperture is %.3f.\\nAcceptance angle is %.1f degrees.\\nSolid angle is %.3f radians.\\nCore radius is %.2f micrometer.\" %(NA,theta,solid_angle,a) \n",
+ "#answer in the book are not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numerical aperture is 0.154.\n",
+ "Acceptance angle is 8.8 degrees.\n",
+ "Solid angle is 0.074 radians.\n",
+ "Core radius is 2.04 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.4, page 2-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import ceil\n",
+ "NA=0.16 #Numerical aperture\n",
+ "n1=1.45 #core refractive index\n",
+ "d=60*10**-6 #core diameter\n",
+ "lamda=0.82*10**-6 #wavelength\n",
+ "a=d/2 #core radius\n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "M=v**2/2 #computing guided modes\n",
+ "print \"if normalized frequency is taken as %d, then there are %d guided modes.\" %(ceil(v),M) \n",
+ "#Answer given in the textbook is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "if normalized frequency is taken as 37, then there are 675 guided modes.\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.5, page 2-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NA=0.2 #Numericla aperture\n",
+ "d=50*10**-6 #Diameter of core\n",
+ "lamda=1*10**-6 #Wavelength\n",
+ "a=d/2 #computing radius\n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "Mg=v**2/4 #computing mode volume for parabollic profile\n",
+ "Mg=round(Mg) \n",
+ "print \"Normalized Frequency is %.1f.\\nTotal number of guided modes are %.d.\" %(v,Mg) \n",
+ "#answer in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 31.4.\n",
+ "Total number of guided modes are 246.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.6, page 2-27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "delta=0.015 #relative refractive index\n",
+ "n1=1.48 #core refractive index\n",
+ "lamda=0.85*10**-6 #wavelength\n",
+ "a=(2.4*lamda)/(2*3.14*n1*sqrt(2*delta)) #computing radius of core\n",
+ "d=2*a #computing diameter of core\n",
+ "a=a*10**7 \n",
+ "a=round(a,2) \n",
+ "a=a/10\n",
+ "d=d*10**6 \n",
+ "print \"Core radius is %.1f micrometer.\\nCore diameter is %.1f micrometer.\" %(a,2*a) \n",
+ "print \"When delta is reduced by 10 percent-\"\n",
+ "delta=0.0015 \n",
+ "a=(2.4*lamda)/(2*3.14*n1*sqrt(2*delta)) #computing radius of core\n",
+ "d=2*a #computing diameter of core\n",
+ "a=a*10**7 \n",
+ "a=round(a) \n",
+ "a=a/10\n",
+ "d=d*10**6 \n",
+ "print \"Core radius is %.1f micrometer.\\nCore diameter is %.1f micrometer.\" %(a,2*a) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Core radius is 1.3 micrometer.\n",
+ "Core diameter is 2.5 micrometer.\n",
+ "When delta is reduced by 10 percent-\n",
+ "Core radius is 4.0 micrometer.\n",
+ "Core diameter is 8.0 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.7, page 2-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NA=0.25 #Numericla aperture\n",
+ "d=45*10**-6 #Diameter of core\n",
+ "lamda=1.5*10**-6 #Wavelength\n",
+ "a=d/2 #computing radius\n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "Mg=v**2/4 #computing mode volume for parabollic profile\n",
+ "Mg=round(Mg,2) \n",
+ "print \"Normalized Frequency is %.2f.\\nTotal number of guided modes are %.d.\" %(v,ceil(Mg) )\n",
+ "#answer in the book for normalized frequency is 23.55, deviation 0.05"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 23.55.\n",
+ "Total number of guided modes are 139.\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.8, page 2-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NA=0.25 #Numericla aperture\n",
+ "d=45*10**-6 #Diameter of core\n",
+ "lamda=1.2*10**-6 #Wavelength\n",
+ "a=d/2 #computing radius\n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "Mg=v**2/4 #computing mode volume for parabollic profile\n",
+ "Mg=round(Mg,2) \n",
+ "print \"Normalized Frequency is %.1f.\\nTotal number of guided modes are %.d.\" %(v,Mg) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 29.4.\n",
+ "Total number of guided modes are 216.\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.9, page 2-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.54 #refractive index of core\n",
+ "n2=1.5 #refractive index of cladding\n",
+ "a=25*10**-6 #Radius of core in um\n",
+ "lamda=1.3*10**-6 #Wavelength in m\n",
+ "NA=sqrt(n1**2-n2**2) \n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "Mg=v**2/4 #computing mode volume for parabollic profile\n",
+ "lamda_cut_off=v*lamda/2.405 #computing cut off wavelength\n",
+ "lamda_cut_off=lamda_cut_off*10**6 \n",
+ "print \"Normalized Frequency is %0.f.\\nTotal number of guided modes are %.d.\\nCut off wavelength is %.1f micrometer.\" %(v,Mg,lamda_cut_off) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 42.\n",
+ "Total number of guided modes are 443.\n",
+ "Cut off wavelength is 22.8 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.1 page 2-30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L_BL=8*10**-2 #beat length\n",
+ "Br=2*3.14/L_BL #computing modal briefringence\n",
+ "print \"Modal briefringence is %.1f per meter.\" %Br"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Modal briefringence is 78.5 per meter.\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.2, page 2-33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log10\n",
+ "Pin=500*10**-6 #input power\n",
+ "L=200 #length of fiber\n",
+ "loss=2 #loss associated with fiber\n",
+ "Pin_dbm=10*log10(Pin/(10**-3)) #computing input power in dBm\n",
+ "Pin_dbm=round(Pin_dbm) \n",
+ "Pout_dbm=Pin_dbm-L*loss #computing output power level\n",
+ "Pout= 10**(Pout_dbm/10) \n",
+ "print \"Output power is %.2e mW.\" %Pout"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output power is 5.01e-41 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12.1, page 2-37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=4.5*10**-6 #core diameter\n",
+ "delta=0.25/100 #relative index difference\n",
+ "lamda=0.85*10**-6 #operating wavelength\n",
+ "n1=1.46 #core refractive index\n",
+ "v= 2*pi*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "lamda_cut_off=v*lamda/2.405 #computing cut off wavelength\n",
+ "lamda_cut_off=lamda_cut_off*10**9 \n",
+ "print \"Cut off wavelength is %.d nanometer.\" %(lamda_cut_off)\n",
+ "print \"When delta is 1.25 percent-\" \n",
+ "delta=1.25/100 \n",
+ "v= 2*pi*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "lamda_cut_off=v*lamda/2.405 #computing cut off wavelength\n",
+ "lamda_cut_off=lamda_cut_off*10**7 \n",
+ "lamda_cut_off=round(lamda_cut_off) \n",
+ "lamda_cut_off=lamda_cut_off*100 \n",
+ "print \"Cut off wavelength is %.d nanometer.\" %(lamda_cut_off) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Cut off wavelength is 1213 nanometer.\n",
+ "When delta is 1.25 percent-\n",
+ "Cut off wavelength is 2700 nanometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12.2, page 2-38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=50*10**-6 #core radius\n",
+ "lamda=1500*10**-9 #operating wavelength\n",
+ "n1=2.53 #core refractive index\n",
+ "n2=1.5 #cladding refractive index\n",
+ "delta=(n1-n2)/n1 #computing delta\n",
+ "v= 2*3.14*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "M=(v)**2/2 #computing guided modes\n",
+ "print \"Normalized Frequency is %.1f\\nTotal number of guided modes are %.d\" %(v,M) \n",
+ "\n",
+ "#Calculation error in book. Answer in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 477.9\n",
+ "Total number of guided modes are 114191\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12.3, page 2-38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "core_diameter=8*10**-6 #core diameter\n",
+ "delta=0.92/100 #relative index difference\n",
+ "lamda=1550*10**-9 #operating wavelength\n",
+ "n1=1.45 #core refractive index\n",
+ "a=core_diameter/2 #computing core radius\n",
+ "v= 2*pi*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "M=(v)**2/2 #computing guided modes\n",
+ "print \"Normalized Frequency is %.1f.\\nTotal number of guided modes are %.d.\" %(v,M) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 3.2.\n",
+ "Total number of guided modes are 5.\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12.4, page 2-39 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "delta=1/100 #relative index difference\n",
+ "n1=1.5 #core refractive index\n",
+ "c=3*10**8 \n",
+ "L=6 \n",
+ "n2=sqrt(n1**2-2*delta*n1**2) #computing refractive index of cladding\n",
+ "delta_T=L*n1**2*delta/(c*n2) #computing pulse broadning\n",
+ "delta_T=delta_T*10**11 \n",
+ "delta_T=round(delta_T) \n",
+ "print \"Delay difference between slowest and fastest mode is %d ns/km.\" %delta_T \n",
+ "print \"This means that a pulse broadnes by %d ns after travel time a distance of %d km.\" %(delta_T,L)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Delay difference between slowest and fastest mode is 30 ns/km.\n",
+ "This means that a pulse broadnes by 30 ns after travel time a distance of 6 km.\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.17.1, page 2-60"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.48 #core refractive index\n",
+ "n2=1.46 #cladding refractive index\n",
+ "phi = arcsin(n2/n1)*180/pi #computing critical angle\n",
+ "NA = sqrt(n1**2 - n2**2) #computing numericla aperture\n",
+ "theta= arcsin(NA)*180/pi #computing acceptance angle\n",
+ "print \"Critical angle is %.2f degrees.\\nNumerical aperture is %.3f.\\nAcceptance angle is %.2f degree.\" %(phi,NA,theta) \n",
+ "#answers in the book are wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical angle is 80.57 degrees.\n",
+ "Numerical aperture is 0.242.\n",
+ "Acceptance angle is 14.03 degree.\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Question 4, page 2-61 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L_BL=8*10**-2 #beat length\n",
+ "Br=2*3.14/L_BL #computing modal briefringence\n",
+ "print \"Modal briefringence is %.1f per meter.\" %Br "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Modal briefringence is 78.5 per meter.\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Question 5, page 2-62 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L_BL=0.6*10**-3 #beat length\n",
+ "lamda=1.4*10**-6 #wavelength\n",
+ "L_BL1=70 \n",
+ "Bh=lamda/L_BL #computing high briefringence\n",
+ "Bl=lamda/L_BL1 #computing low briefringence\n",
+ "print \"High briefringence is %.2e.\\nLow briefringence is %.1e.\"%(Bh,Bl)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "High briefringence is 2.33e-03.\n",
+ "Low briefringence is 2.0e-08.\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter2_1.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter2_1.ipynb
new file mode 100755
index 00000000..934feb4e
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter2_1.ipynb
@@ -0,0 +1,886 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:94ac7a20c62e9612d243d85d9b1b3699e50dc46a0975e66ae373ce7747106bc9"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter2 - Optical Fibers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4.1 page 2-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import arcsin, sqrt, pi\n",
+ "#Numerical Aperture and critical angle\n",
+ "n1=1.46 #refractive index\n",
+ "d=0.01 #difference\n",
+ "na=n1*sqrt(2*d) #numerical aperture\n",
+ "x=1-d #\n",
+ "oc=arcsin(x)*180/pi #in degree\n",
+ "print \"numerical aperture = \",round(na,2)\n",
+ "print \"critical angle at core cladding interface =\",round(oc,1),\" degree\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "numerical aperture = 0.21\n",
+ "critical angle at core cladding interface = 81.9 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.1, page 2-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import arcsin, sqrt, pi\n",
+ "#Numerical Aperture ,critical angle and acceptance angle\n",
+ "n2=1.45 #core refrative index\n",
+ "n1=1.49 #cladding refrative index\n",
+ "oc=arcsin(n2/n1)*180/pi #in degree\n",
+ "na=sqrt(n1**2-n2**2) #numerical aperture\n",
+ "pc=arcsin(na)*180/pi #degree\n",
+ "print \"critical angle is =\",round(oc,2),\" degree\"\n",
+ "print \"numerical aperture =\",round(na,3)\n",
+ "print \"acceptance angle is\",round(pc,2),\" degree\"\n",
+ "# Answer in the book are not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "critical angle is = 76.69 degree\n",
+ "numerical aperture = 0.343\n",
+ "acceptance angle is 20.06 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.2, page 2-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import arcsin, sqrt, pi\n",
+ "delta = 1.2/100 # Relative refractive difference index\n",
+ "n1=1.45 # Core refractive index \n",
+ "NA= n1*sqrt(2*delta) #computing numerical aperture\n",
+ "Acceptance_angle = arcsin(NA)*180/pi #computing acceptance angle\n",
+ "si = pi*NA**2 #computing solid acceptance angle\n",
+ "print \"Numerical aperture is %.3f.\\nAcceptance angle is %.2f degree.\\nSolid acceptance angle is %.3f radians.\" %(NA,Acceptance_angle,si) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numerical aperture is 0.225.\n",
+ "Acceptance angle is 12.98 degree.\n",
+ "Solid acceptance angle is 0.159 radians.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.3, page 2-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NA = 0.45 # Numerical Aperture\n",
+ "Acceptance_angle = arcsin(NA)*180/pi #computing acceptance angle.\n",
+ "print \"Acceptance angle is %.1f degree.\" %Acceptance_angle"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Acceptance angle is 26.7 degree.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.4, page 2-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import arctan\n",
+ "diameter = 1 #Diameter in centimeter\n",
+ "Focal_length = 10 #Focal length in centimeter\n",
+ "radius=diameter/2 #computing radius\n",
+ "Acceptance_angle = arctan(radius/Focal_length)*180/pi #computing acceptance angle\n",
+ "Conical_full_angle = 2*Acceptance_angle #computing conical angle\n",
+ "Solid_acceptance_angle = pi*Acceptance_angle**2 #computing solid acceptance angle\n",
+ "NA = sqrt(Solid_acceptance_angle/pi) #computing Numerical aperture\n",
+ "print \"Numerical aperture is %.2f.\\nConical full angle is %.2f degree.\" %(NA,Conical_full_angle) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numerical aperture is 2.86.\n",
+ "Conical full angle is 5.72 degree.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6.1, page 2-16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import cos\n",
+ "NA = 0.45 #Numerical aperture\n",
+ "betaB = 45 # Skew ray change direction by 90 degree at each reflection\n",
+ "Meridional_theta = arcsin(NA)*180/pi #computing acceptacne angle for meridoinal ray\n",
+ "Skew_theta = arcsin(NA/cos(betaB*pi/180))*180/pi #computing acceptacne angle for skew ray\n",
+ "print \"Acceptacne angle for Meridoinal ray is %.2f degree.\\nAcceptance angle for Skew ray %.1f degree.\" %(Meridional_theta,Skew_theta) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Acceptacne angle for Meridoinal ray is 26.74 degree.\n",
+ "Acceptance angle for Skew ray 39.5 degree.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.1, page 2-21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "core_diameter=78*10**-6 #core diameter\n",
+ "delta=1.4/100 #relative index difference\n",
+ "lamda=0.8*10**-6 #operating wavelength\n",
+ "n1=1.47 #core refractive index\n",
+ "a=core_diameter/2 #computing core radius\n",
+ "v= 2*3.14*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "M=(v)**2/2 #computing guided modes\n",
+ "print \"Normalized Frequency is %.3f.\\nTotal number of guided modes are %.1f\" %(v,M)\n",
+ "#answer in the book are incorrect."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 75.306.\n",
+ "Total number of guided modes are 2835.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.2, page 2-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.47 #refractive index of core\n",
+ "a=4.3*10**-6 #radius of core\n",
+ "delta=0.2/100 #relative index difference\n",
+ "lamda= 2*3.14*a*n1*sqrt(2*delta)/2.405 #computing wavelength\n",
+ "lamda=lamda*10**9 \n",
+ "print \"Wavelength of fiber is %d nm.\" %lamda\n",
+ "#answer in the book is given as 1230nm which is incorrect."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavelength of fiber is 1043 nm.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.3, page 2-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.482 #refractive index of core\n",
+ "n2=1.474 #refractive index of cladding\n",
+ "lamda=820*10**-9 #Wavelength\n",
+ "NA=sqrt(n1**2 - n2**2) #computing Numerical aperture\n",
+ "theta= arcsin(NA)*180/pi #computing acceptance angle\n",
+ "solid_angle=pi*(NA)**2 #computing solid angle\n",
+ "a=2.405*lamda/(2*3.14*NA) #computing core radius\n",
+ "a=a*10**6 \n",
+ "print \"Numerical aperture is %.3f.\\nAcceptance angle is %.1f degrees.\\nSolid angle is %.3f radians.\\nCore radius is %.2f micrometer.\" %(NA,theta,solid_angle,a) \n",
+ "#answer in the book are not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numerical aperture is 0.154.\n",
+ "Acceptance angle is 8.8 degrees.\n",
+ "Solid angle is 0.074 radians.\n",
+ "Core radius is 2.04 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.4, page 2-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import ceil\n",
+ "NA=0.16 #Numerical aperture\n",
+ "n1=1.45 #core refractive index\n",
+ "d=60*10**-6 #core diameter\n",
+ "lamda=0.82*10**-6 #wavelength\n",
+ "a=d/2 #core radius\n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "M=v**2/2 #computing guided modes\n",
+ "print \"if normalized frequency is taken as %d, then there are %d guided modes.\" %(ceil(v),M) \n",
+ "#Answer given in the textbook is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "if normalized frequency is taken as 37, then there are 675 guided modes.\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.5, page 2-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NA=0.2 #Numericla aperture\n",
+ "d=50*10**-6 #Diameter of core\n",
+ "lamda=1*10**-6 #Wavelength\n",
+ "a=d/2 #computing radius\n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "Mg=v**2/4 #computing mode volume for parabollic profile\n",
+ "Mg=round(Mg) \n",
+ "print \"Normalized Frequency is %.1f.\\nTotal number of guided modes are %.d.\" %(v,Mg) \n",
+ "#answer in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 31.4.\n",
+ "Total number of guided modes are 246.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.6, page 2-27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "delta=0.015 #relative refractive index\n",
+ "n1=1.48 #core refractive index\n",
+ "lamda=0.85*10**-6 #wavelength\n",
+ "a=(2.4*lamda)/(2*3.14*n1*sqrt(2*delta)) #computing radius of core\n",
+ "d=2*a #computing diameter of core\n",
+ "a=a*10**7 \n",
+ "a=round(a,2) \n",
+ "a=a/10\n",
+ "d=d*10**6 \n",
+ "print \"Core radius is %.1f micrometer.\\nCore diameter is %.1f micrometer.\" %(a,2*a) \n",
+ "print \"When delta is reduced by 10 percent-\"\n",
+ "delta=0.0015 \n",
+ "a=(2.4*lamda)/(2*3.14*n1*sqrt(2*delta)) #computing radius of core\n",
+ "d=2*a #computing diameter of core\n",
+ "a=a*10**7 \n",
+ "a=round(a) \n",
+ "a=a/10\n",
+ "d=d*10**6 \n",
+ "print \"Core radius is %.1f micrometer.\\nCore diameter is %.1f micrometer.\" %(a,2*a) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Core radius is 1.3 micrometer.\n",
+ "Core diameter is 2.5 micrometer.\n",
+ "When delta is reduced by 10 percent-\n",
+ "Core radius is 4.0 micrometer.\n",
+ "Core diameter is 8.0 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.7, page 2-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NA=0.25 #Numericla aperture\n",
+ "d=45*10**-6 #Diameter of core\n",
+ "lamda=1.5*10**-6 #Wavelength\n",
+ "a=d/2 #computing radius\n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "Mg=v**2/4 #computing mode volume for parabollic profile\n",
+ "Mg=round(Mg,2) \n",
+ "print \"Normalized Frequency is %.2f.\\nTotal number of guided modes are %.d.\" %(v,ceil(Mg) )\n",
+ "#answer in the book for normalized frequency is 23.55, deviation 0.05"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 23.55.\n",
+ "Total number of guided modes are 139.\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.8, page 2-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NA=0.25 #Numericla aperture\n",
+ "d=45*10**-6 #Diameter of core\n",
+ "lamda=1.2*10**-6 #Wavelength\n",
+ "a=d/2 #computing radius\n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "Mg=v**2/4 #computing mode volume for parabollic profile\n",
+ "Mg=round(Mg,2) \n",
+ "print \"Normalized Frequency is %.1f.\\nTotal number of guided modes are %.d.\" %(v,Mg) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 29.4.\n",
+ "Total number of guided modes are 216.\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.9, page 2-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.54 #refractive index of core\n",
+ "n2=1.5 #refractive index of cladding\n",
+ "a=25*10**-6 #Radius of core in um\n",
+ "lamda=1.3*10**-6 #Wavelength in m\n",
+ "NA=sqrt(n1**2-n2**2) \n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "Mg=v**2/4 #computing mode volume for parabollic profile\n",
+ "lamda_cut_off=v*lamda/2.405 #computing cut off wavelength\n",
+ "lamda_cut_off=lamda_cut_off*10**6 \n",
+ "print \"Normalized Frequency is %0.f.\\nTotal number of guided modes are %.d.\\nCut off wavelength is %.1f micrometer.\" %(v,Mg,lamda_cut_off) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 42.\n",
+ "Total number of guided modes are 443.\n",
+ "Cut off wavelength is 22.8 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.1 page 2-30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L_BL=8*10**-2 #beat length\n",
+ "Br=2*3.14/L_BL #computing modal briefringence\n",
+ "print \"Modal briefringence is %.1f per meter.\" %Br"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Modal briefringence is 78.5 per meter.\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.2, page 2-33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log10\n",
+ "Pin=500*10**-6 #input power\n",
+ "L=200 #length of fiber\n",
+ "loss=2 #loss associated with fiber\n",
+ "Pin_dbm=10*log10(Pin/(10**-3)) #computing input power in dBm\n",
+ "Pin_dbm=round(Pin_dbm) \n",
+ "Pout_dbm=Pin_dbm-L*loss #computing output power level\n",
+ "Pout= 10**(Pout_dbm/10) \n",
+ "print \"Output power is %.2e mW.\" %Pout"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output power is 5.01e-41 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12.1, page 2-37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=4.5*10**-6 #core diameter\n",
+ "delta=0.25/100 #relative index difference\n",
+ "lamda=0.85*10**-6 #operating wavelength\n",
+ "n1=1.46 #core refractive index\n",
+ "v= 2*pi*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "lamda_cut_off=v*lamda/2.405 #computing cut off wavelength\n",
+ "lamda_cut_off=lamda_cut_off*10**9 \n",
+ "print \"Cut off wavelength is %.d nanometer.\" %(lamda_cut_off)\n",
+ "print \"When delta is 1.25 percent-\" \n",
+ "delta=1.25/100 \n",
+ "v= 2*pi*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "lamda_cut_off=v*lamda/2.405 #computing cut off wavelength\n",
+ "lamda_cut_off=lamda_cut_off*10**7 \n",
+ "lamda_cut_off=round(lamda_cut_off) \n",
+ "lamda_cut_off=lamda_cut_off*100 \n",
+ "print \"Cut off wavelength is %.d nanometer.\" %(lamda_cut_off) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Cut off wavelength is 1213 nanometer.\n",
+ "When delta is 1.25 percent-\n",
+ "Cut off wavelength is 2700 nanometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12.2, page 2-38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=50*10**-6 #core radius\n",
+ "lamda=1500*10**-9 #operating wavelength\n",
+ "n1=2.53 #core refractive index\n",
+ "n2=1.5 #cladding refractive index\n",
+ "delta=(n1-n2)/n1 #computing delta\n",
+ "v= 2*3.14*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "M=(v)**2/2 #computing guided modes\n",
+ "print \"Normalized Frequency is %.1f\\nTotal number of guided modes are %.d\" %(v,M) \n",
+ "\n",
+ "#Calculation error in book. Answer in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 477.9\n",
+ "Total number of guided modes are 114191\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12.3, page 2-38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "core_diameter=8*10**-6 #core diameter\n",
+ "delta=0.92/100 #relative index difference\n",
+ "lamda=1550*10**-9 #operating wavelength\n",
+ "n1=1.45 #core refractive index\n",
+ "a=core_diameter/2 #computing core radius\n",
+ "v= 2*pi*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "M=(v)**2/2 #computing guided modes\n",
+ "print \"Normalized Frequency is %.1f.\\nTotal number of guided modes are %.d.\" %(v,M) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 3.2.\n",
+ "Total number of guided modes are 5.\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12.4, page 2-39 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "delta=1/100 #relative index difference\n",
+ "n1=1.5 #core refractive index\n",
+ "c=3*10**8 \n",
+ "L=6 \n",
+ "n2=sqrt(n1**2-2*delta*n1**2) #computing refractive index of cladding\n",
+ "delta_T=L*n1**2*delta/(c*n2) #computing pulse broadning\n",
+ "delta_T=delta_T*10**11 \n",
+ "delta_T=round(delta_T) \n",
+ "print \"Delay difference between slowest and fastest mode is %d ns/km.\" %delta_T \n",
+ "print \"This means that a pulse broadnes by %d ns after travel time a distance of %d km.\" %(delta_T,L)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Delay difference between slowest and fastest mode is 30 ns/km.\n",
+ "This means that a pulse broadnes by 30 ns after travel time a distance of 6 km.\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.17.1, page 2-60"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.48 #core refractive index\n",
+ "n2=1.46 #cladding refractive index\n",
+ "phi = arcsin(n2/n1)*180/pi #computing critical angle\n",
+ "NA = sqrt(n1**2 - n2**2) #computing numericla aperture\n",
+ "theta= arcsin(NA)*180/pi #computing acceptance angle\n",
+ "print \"Critical angle is %.2f degrees.\\nNumerical aperture is %.3f.\\nAcceptance angle is %.2f degree.\" %(phi,NA,theta) \n",
+ "#answers in the book are wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical angle is 80.57 degrees.\n",
+ "Numerical aperture is 0.242.\n",
+ "Acceptance angle is 14.03 degree.\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Question 4, page 2-61 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L_BL=8*10**-2 #beat length\n",
+ "Br=2*3.14/L_BL #computing modal briefringence\n",
+ "print \"Modal briefringence is %.1f per meter.\" %Br "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Modal briefringence is 78.5 per meter.\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Question 5, page 2-62 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L_BL=0.6*10**-3 #beat length\n",
+ "lamda=1.4*10**-6 #wavelength\n",
+ "L_BL1=70 \n",
+ "Bh=lamda/L_BL #computing high briefringence\n",
+ "Bl=lamda/L_BL1 #computing low briefringence\n",
+ "print \"High briefringence is %.2e.\\nLow briefringence is %.1e.\"%(Bh,Bl)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "High briefringence is 2.33e-03.\n",
+ "Low briefringence is 2.0e-08.\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter4.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter4.ipynb
new file mode 100755
index 00000000..408746a4
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter4.ipynb
@@ -0,0 +1,413 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c80be9ee73d5adb979ad6bf2343ea3cff1243505e35fc82560bd445f960931b7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter4 - Signal Degradation in fibers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3.1, page 4-4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi, log10\n",
+ "L=10 #fiber length in km\n",
+ "Pin=150*10**-6 #input power\n",
+ "Pout=5*10**-6 #output power\n",
+ "ln=20 #length of optical link\n",
+ "interval=1 #splices after interval of 1 km\n",
+ "l=1.2 #loss due to 1 splice\n",
+ "attenuation=10*log10(Pin/Pout) \n",
+ "alpha=attenuation/L \n",
+ "attenuation_loss=alpha*20 \n",
+ "splices_loss=(ln-interval)*l \n",
+ "total_loss=attenuation_loss+splices_loss \n",
+ "power_ratio=10**(total_loss/10) \n",
+ "print \"Signal attenuation is %.2f dBs.\\nSignal attenuation is %.3f dB/Km.\\nTotal loss in 20 Km fiber is %.2f dbs.\\nTotal attenuation is %.2f dBs.\\ninput/output ratio is %0.e.\" %(attenuation,alpha,attenuation_loss,total_loss,power_ratio) \n",
+ "# Answer wrong for last part."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Signal attenuation is 14.77 dBs.\n",
+ "Signal attenuation is 1.477 dB/Km.\n",
+ "Total loss in 20 Km fiber is 29.54 dbs.\n",
+ "Total attenuation is 52.34 dBs.\n",
+ "input/output ratio is 2e+05.\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6.1, page 4-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import exp\n",
+ "beta_c=8*10**-11 #isothermal compressibility\n",
+ "n=1.46 #refractive index\n",
+ "P=0.286 #photoelastic constat\n",
+ "k=1.38*10**-23 #Boltzmnn constant\n",
+ "T=1500 #temperature\n",
+ "L=1000 #length\n",
+ "lamda=1000*10**-9 #wavelength\n",
+ "gamma_r = 8*(3.14**3)*(P**2)*(n**8)*beta_c*k*T/(3*(lamda**4)) #computing coefficient\n",
+ "attenuation=exp(-gamma_r*L) #computing attenuation\n",
+ "print \"Attenuation due to Rayleigh scattering is %.3f.\" %(attenuation) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Attenuation due to Rayleigh scattering is 0.794.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6.2, page 4-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "beta_c=7*10**-11 #isothermal compressibility\n",
+ "n=1.46 #refractive index\n",
+ "P=0.29 #photoelastic constat\n",
+ "k=1.38*10**-23 #Boltzmnn constant\n",
+ "T=1400 #temperature\n",
+ "L=1000 #length\n",
+ "lamda=0.7*10**-6 #wavelength\n",
+ "gamma_r = 8*(3.14**3)*(P**2)*(n**8)*beta_c*k*T/(3*(lamda**4)) #computing coefficient\n",
+ "attenuation=exp(-gamma_r*L) #computing attenuation\n",
+ "gamma_r=gamma_r\n",
+ "print \"Raleigh Scattering corfficient is %.3e per meter\" %(gamma_r) \n",
+ "#Attenuation is not calcualted in textbook\"\n",
+ "print \"Attenuation due to Rayleigh scattering is %.3f\" %(attenuation) \n",
+ "#answer for Raleigh Scattering corfficient in the book is given as 0.804d-3, deviation of 0.003d-3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Raleigh Scattering corfficient is 8.074e-04 per meter\n",
+ "Attenuation due to Rayleigh scattering is 0.446\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7.1, page 4-17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "d=5 #core diameter\n",
+ "alpha=0.4 #attenuation\n",
+ "B=0.5 #Bandwidth\n",
+ "lamda=1.4 #wavelength\n",
+ "PB=4.4*10**-3*d**2*lamda**2*alpha*B #computing threshold power for SBS\n",
+ "PR=5.9*10**-2*d**2*lamda*alpha #computing threshold power for SRS\n",
+ "PB=PB*10**3 \n",
+ "PR=PR*10**3 \n",
+ "print \"Threshold power for SBS is %.1f mW.\\nThreshold power for SRS is %.3f mW.\" %(PB,PR) \n",
+ "#NOTE - Calculation error in the book while calculating threshold for SBS.\n",
+ "#Also, while calculating SRS, formula is taken incorrectly, \n",
+ "#Bandwidth is multiplied in second step, which is not in the formula.\") "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Threshold power for SBS is 43.1 mW.\n",
+ "Threshold power for SRS is 826.000 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8.1, page 4-18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.5 #refractive index of core\n",
+ "delta=0.03/100 #relative refractive index\n",
+ "lamda=0.82*10**-6 #wavelength\n",
+ "n2=sqrt(n1**2-2*delta*n1**2) #computing cladding refractive index\n",
+ "Rc=(3*n1**2*lamda)/(4*3.14*(n1**2-n2**2)**1.5) #computing critical radius\n",
+ "Rc=Rc*10**3 \n",
+ "print \"Critical radius is %.f micrometer.\" %(Rc) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical radius is 9 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8.2, page 4-20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.45 #refractive index of core\n",
+ "delta=3.0/100 #relative refractive index\n",
+ "lamda=1.5*10**-6 #wavelength\n",
+ "a=5*10**-6 #core radius\n",
+ "n2=sqrt(n1**2-2*delta*n1**2) #computing cladding refractive index\n",
+ "Rc=(3*n1**2*lamda)/(4*3.14*(n1**2-n2**2)**0.5) #computing critical radius for single mode\n",
+ "Rc=Rc*10**6 \n",
+ "print \"Critical radius is %.2f micrometer\" %(Rc) \n",
+ "lamda_cut_off= 2*3.14*a*n1*sqrt(2*delta)/2.405 \n",
+ "RcSM= (20*lamda/(n1-n2)**1.5)*(2.748-0.996*lamda/lamda_cut_off)**-3 #computing critical radius for single mode\n",
+ "RcSM=RcSM*10**6 \n",
+ "print \"Critical radius for single mode fiber is %.2f micrometer.\" %(RcSM) \n",
+ "#Calculation error in the book.(2.748-0.996*lamda/lamda_cut_off)**-3 in this term raised to -3 is not taken in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical radius is 2.12 micrometer\n",
+ "Critical radius for single mode fiber is 226.37 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.13.1, page 4-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=1550*10**-9 \n",
+ "lamda0=1.3*10**-6 \n",
+ "s0=0.095 \n",
+ "Dt=lamda*s0/4*(1-(lamda0/lamda)**4) #computing material dispersion\n",
+ "Dt=Dt*10**9 \n",
+ "print \"Material dispersion at 1550 nm is %.1f ps/nm/km\" %Dt\n",
+ "#answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Material dispersion at 1550 nm is 18.6 ps/nm/km\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.14.1, page 4-33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "tau=0.1*10**-6 #pulse broadning\n",
+ "dist=20*10**3 #distance\n",
+ "Bopt=1/(2*tau) #computing optical bandwidth\n",
+ "Bopt=Bopt*10**-6 \n",
+ "dispertion=tau/dist #computing dispersion\n",
+ "dispertion=dispertion*10**12 \n",
+ "BLP=Bopt*dist #computing Bandwidth length product\n",
+ "BLP=BLP*10**-3 \n",
+ "print \"optical bandwidth is %d MHz.\\nDispersion per unit length is %d ns/km.\\nBandwidth length product is %d MHz.km.\" %(Bopt,dispertion,BLP) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "optical bandwidth is 5 MHz.\n",
+ "Dispersion per unit length is 5 ns/km.\n",
+ "Bandwidth length product is 100 MHz.km.\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.15.1, page 4-34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "RSW=0.0012 #relative spectral width\n",
+ "lamda=0.90*10**-6 #wavelength\n",
+ "L=1 #distance in km (assumed)\n",
+ "P=0.025 #material dispersion parameter\n",
+ "c=3*10**5 #speed of light in km/s\n",
+ "M=10**3*P/(c*lamda) #computing material dispersion\n",
+ "sigma_lamda=RSW*lamda \n",
+ "sigmaM=sigma_lamda*L*M*10**7 #computing RMS pulse broadning\n",
+ "sigmaB=25*L*M*10**-3 \n",
+ "print \"Material dispersion parameter is %.2f ps/nm/km.\\nRMS pulsr broadning when sigma_lamda is 25 is %.1f ns/km.\\nRMS pulse broadning is %.2f ns/km.\" %(M,sigmaB,sigmaM) \n",
+ "#answer in the book for RMS pulse broadning is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Material dispersion parameter is 92.59 ps/nm/km.\n",
+ "RMS pulsr broadning when sigma_lamda is 25 is 2.3 ns/km.\n",
+ "RMS pulse broadning is 1.00 ns/km.\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.17.1, page 4-37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L=10 #length of optical link\n",
+ "n1=1.49 #refractive index\n",
+ "c=3*10**8 #speed of light\n",
+ "delta=1.0/100 #relative refractive index\n",
+ "delTS=L*n1*delta/c #computing delay difference\n",
+ "delTS=delTS*10**12 \n",
+ "sigmaS=L*n1*delta/(2*sqrt(3)*c) #computing rms pulse broadning\n",
+ "sigmaS=sigmaS*10**12 \n",
+ "B=1/(2*delTS) #computing maximum bit rate\n",
+ "B=B*10**3 \n",
+ "B_acc=0.2/(sigmaS) #computing accurate bit rate\n",
+ "B_acc=B_acc*10**3 \n",
+ "BLP=B_acc*L #computing Bandwidth length product\n",
+ "print \"Delay difference is %d ns.\\nRMS pulse broadning is %.1f ns.\\nBit rate is %.1f Mbit/s.\\nAccurate bit rate is %.3f Mbits/s.\\nBandwidth length product is %.1f MHz.km\" %(delTS,sigmaS,B,B_acc,BLP) \n",
+ "#answer for maximum bit rate is given as 1.008 Mb/s, deviation of 0.008 Mb/s."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Delay difference is 496 ns.\n",
+ "RMS pulse broadning is 143.4 ns.\n",
+ "Bit rate is 1.0 Mbit/s.\n",
+ "Accurate bit rate is 1.395 Mbits/s.\n",
+ "Bandwidth length product is 13.9 MHz.km\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter4_1.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter4_1.ipynb
new file mode 100755
index 00000000..408746a4
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter4_1.ipynb
@@ -0,0 +1,413 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c80be9ee73d5adb979ad6bf2343ea3cff1243505e35fc82560bd445f960931b7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter4 - Signal Degradation in fibers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3.1, page 4-4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi, log10\n",
+ "L=10 #fiber length in km\n",
+ "Pin=150*10**-6 #input power\n",
+ "Pout=5*10**-6 #output power\n",
+ "ln=20 #length of optical link\n",
+ "interval=1 #splices after interval of 1 km\n",
+ "l=1.2 #loss due to 1 splice\n",
+ "attenuation=10*log10(Pin/Pout) \n",
+ "alpha=attenuation/L \n",
+ "attenuation_loss=alpha*20 \n",
+ "splices_loss=(ln-interval)*l \n",
+ "total_loss=attenuation_loss+splices_loss \n",
+ "power_ratio=10**(total_loss/10) \n",
+ "print \"Signal attenuation is %.2f dBs.\\nSignal attenuation is %.3f dB/Km.\\nTotal loss in 20 Km fiber is %.2f dbs.\\nTotal attenuation is %.2f dBs.\\ninput/output ratio is %0.e.\" %(attenuation,alpha,attenuation_loss,total_loss,power_ratio) \n",
+ "# Answer wrong for last part."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Signal attenuation is 14.77 dBs.\n",
+ "Signal attenuation is 1.477 dB/Km.\n",
+ "Total loss in 20 Km fiber is 29.54 dbs.\n",
+ "Total attenuation is 52.34 dBs.\n",
+ "input/output ratio is 2e+05.\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6.1, page 4-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import exp\n",
+ "beta_c=8*10**-11 #isothermal compressibility\n",
+ "n=1.46 #refractive index\n",
+ "P=0.286 #photoelastic constat\n",
+ "k=1.38*10**-23 #Boltzmnn constant\n",
+ "T=1500 #temperature\n",
+ "L=1000 #length\n",
+ "lamda=1000*10**-9 #wavelength\n",
+ "gamma_r = 8*(3.14**3)*(P**2)*(n**8)*beta_c*k*T/(3*(lamda**4)) #computing coefficient\n",
+ "attenuation=exp(-gamma_r*L) #computing attenuation\n",
+ "print \"Attenuation due to Rayleigh scattering is %.3f.\" %(attenuation) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Attenuation due to Rayleigh scattering is 0.794.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6.2, page 4-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "beta_c=7*10**-11 #isothermal compressibility\n",
+ "n=1.46 #refractive index\n",
+ "P=0.29 #photoelastic constat\n",
+ "k=1.38*10**-23 #Boltzmnn constant\n",
+ "T=1400 #temperature\n",
+ "L=1000 #length\n",
+ "lamda=0.7*10**-6 #wavelength\n",
+ "gamma_r = 8*(3.14**3)*(P**2)*(n**8)*beta_c*k*T/(3*(lamda**4)) #computing coefficient\n",
+ "attenuation=exp(-gamma_r*L) #computing attenuation\n",
+ "gamma_r=gamma_r\n",
+ "print \"Raleigh Scattering corfficient is %.3e per meter\" %(gamma_r) \n",
+ "#Attenuation is not calcualted in textbook\"\n",
+ "print \"Attenuation due to Rayleigh scattering is %.3f\" %(attenuation) \n",
+ "#answer for Raleigh Scattering corfficient in the book is given as 0.804d-3, deviation of 0.003d-3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Raleigh Scattering corfficient is 8.074e-04 per meter\n",
+ "Attenuation due to Rayleigh scattering is 0.446\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7.1, page 4-17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "d=5 #core diameter\n",
+ "alpha=0.4 #attenuation\n",
+ "B=0.5 #Bandwidth\n",
+ "lamda=1.4 #wavelength\n",
+ "PB=4.4*10**-3*d**2*lamda**2*alpha*B #computing threshold power for SBS\n",
+ "PR=5.9*10**-2*d**2*lamda*alpha #computing threshold power for SRS\n",
+ "PB=PB*10**3 \n",
+ "PR=PR*10**3 \n",
+ "print \"Threshold power for SBS is %.1f mW.\\nThreshold power for SRS is %.3f mW.\" %(PB,PR) \n",
+ "#NOTE - Calculation error in the book while calculating threshold for SBS.\n",
+ "#Also, while calculating SRS, formula is taken incorrectly, \n",
+ "#Bandwidth is multiplied in second step, which is not in the formula.\") "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Threshold power for SBS is 43.1 mW.\n",
+ "Threshold power for SRS is 826.000 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8.1, page 4-18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.5 #refractive index of core\n",
+ "delta=0.03/100 #relative refractive index\n",
+ "lamda=0.82*10**-6 #wavelength\n",
+ "n2=sqrt(n1**2-2*delta*n1**2) #computing cladding refractive index\n",
+ "Rc=(3*n1**2*lamda)/(4*3.14*(n1**2-n2**2)**1.5) #computing critical radius\n",
+ "Rc=Rc*10**3 \n",
+ "print \"Critical radius is %.f micrometer.\" %(Rc) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical radius is 9 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8.2, page 4-20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.45 #refractive index of core\n",
+ "delta=3.0/100 #relative refractive index\n",
+ "lamda=1.5*10**-6 #wavelength\n",
+ "a=5*10**-6 #core radius\n",
+ "n2=sqrt(n1**2-2*delta*n1**2) #computing cladding refractive index\n",
+ "Rc=(3*n1**2*lamda)/(4*3.14*(n1**2-n2**2)**0.5) #computing critical radius for single mode\n",
+ "Rc=Rc*10**6 \n",
+ "print \"Critical radius is %.2f micrometer\" %(Rc) \n",
+ "lamda_cut_off= 2*3.14*a*n1*sqrt(2*delta)/2.405 \n",
+ "RcSM= (20*lamda/(n1-n2)**1.5)*(2.748-0.996*lamda/lamda_cut_off)**-3 #computing critical radius for single mode\n",
+ "RcSM=RcSM*10**6 \n",
+ "print \"Critical radius for single mode fiber is %.2f micrometer.\" %(RcSM) \n",
+ "#Calculation error in the book.(2.748-0.996*lamda/lamda_cut_off)**-3 in this term raised to -3 is not taken in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical radius is 2.12 micrometer\n",
+ "Critical radius for single mode fiber is 226.37 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.13.1, page 4-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=1550*10**-9 \n",
+ "lamda0=1.3*10**-6 \n",
+ "s0=0.095 \n",
+ "Dt=lamda*s0/4*(1-(lamda0/lamda)**4) #computing material dispersion\n",
+ "Dt=Dt*10**9 \n",
+ "print \"Material dispersion at 1550 nm is %.1f ps/nm/km\" %Dt\n",
+ "#answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Material dispersion at 1550 nm is 18.6 ps/nm/km\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.14.1, page 4-33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "tau=0.1*10**-6 #pulse broadning\n",
+ "dist=20*10**3 #distance\n",
+ "Bopt=1/(2*tau) #computing optical bandwidth\n",
+ "Bopt=Bopt*10**-6 \n",
+ "dispertion=tau/dist #computing dispersion\n",
+ "dispertion=dispertion*10**12 \n",
+ "BLP=Bopt*dist #computing Bandwidth length product\n",
+ "BLP=BLP*10**-3 \n",
+ "print \"optical bandwidth is %d MHz.\\nDispersion per unit length is %d ns/km.\\nBandwidth length product is %d MHz.km.\" %(Bopt,dispertion,BLP) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "optical bandwidth is 5 MHz.\n",
+ "Dispersion per unit length is 5 ns/km.\n",
+ "Bandwidth length product is 100 MHz.km.\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.15.1, page 4-34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "RSW=0.0012 #relative spectral width\n",
+ "lamda=0.90*10**-6 #wavelength\n",
+ "L=1 #distance in km (assumed)\n",
+ "P=0.025 #material dispersion parameter\n",
+ "c=3*10**5 #speed of light in km/s\n",
+ "M=10**3*P/(c*lamda) #computing material dispersion\n",
+ "sigma_lamda=RSW*lamda \n",
+ "sigmaM=sigma_lamda*L*M*10**7 #computing RMS pulse broadning\n",
+ "sigmaB=25*L*M*10**-3 \n",
+ "print \"Material dispersion parameter is %.2f ps/nm/km.\\nRMS pulsr broadning when sigma_lamda is 25 is %.1f ns/km.\\nRMS pulse broadning is %.2f ns/km.\" %(M,sigmaB,sigmaM) \n",
+ "#answer in the book for RMS pulse broadning is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Material dispersion parameter is 92.59 ps/nm/km.\n",
+ "RMS pulsr broadning when sigma_lamda is 25 is 2.3 ns/km.\n",
+ "RMS pulse broadning is 1.00 ns/km.\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.17.1, page 4-37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L=10 #length of optical link\n",
+ "n1=1.49 #refractive index\n",
+ "c=3*10**8 #speed of light\n",
+ "delta=1.0/100 #relative refractive index\n",
+ "delTS=L*n1*delta/c #computing delay difference\n",
+ "delTS=delTS*10**12 \n",
+ "sigmaS=L*n1*delta/(2*sqrt(3)*c) #computing rms pulse broadning\n",
+ "sigmaS=sigmaS*10**12 \n",
+ "B=1/(2*delTS) #computing maximum bit rate\n",
+ "B=B*10**3 \n",
+ "B_acc=0.2/(sigmaS) #computing accurate bit rate\n",
+ "B_acc=B_acc*10**3 \n",
+ "BLP=B_acc*L #computing Bandwidth length product\n",
+ "print \"Delay difference is %d ns.\\nRMS pulse broadning is %.1f ns.\\nBit rate is %.1f Mbit/s.\\nAccurate bit rate is %.3f Mbits/s.\\nBandwidth length product is %.1f MHz.km\" %(delTS,sigmaS,B,B_acc,BLP) \n",
+ "#answer for maximum bit rate is given as 1.008 Mb/s, deviation of 0.008 Mb/s."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Delay difference is 496 ns.\n",
+ "RMS pulse broadning is 143.4 ns.\n",
+ "Bit rate is 1.0 Mbit/s.\n",
+ "Accurate bit rate is 1.395 Mbits/s.\n",
+ "Bandwidth length product is 13.9 MHz.km\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter5.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter5.ipynb
new file mode 100755
index 00000000..1c8edfa4
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter5.ipynb
@@ -0,0 +1,281 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:69c313bd7e7f4ca84b1b5e5f091a7854a8c80d86bc1470f5cbc9e6d39211d1ba"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter5 - Optical fiber connection : splicing"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2.1, page 5-2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi, log10\n",
+ "n1=1.47 #refractive index of fiber\n",
+ "n=1 #refractive index of air\n",
+ "r=((n1-n)/(n1+n))**2 #computing fraction of light reflected\n",
+ "loss=-10*log10(1-r) #loss\n",
+ "total_loss=2*loss \n",
+ "print \"r = %.3f, which means %.1f percent of the transimitted light is reflected at one interface\" %(r,r*100) \n",
+ "print \"Total loss is %.3f dB\" %(total_loss) \n",
+ "#answer in the book for total loss of fiber is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r = 0.036, which means 3.6 percent of the transimitted light is reflected at one interface\n",
+ "Total loss is 0.320 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2.2, page 5-4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import arccos\n",
+ "n1=1.47 #refractive index of fiber\n",
+ "n=1 #refractive index of air\n",
+ "d=40*10**-6 #core diameter\n",
+ "y=4*10**-6 #lateral dispalcement\n",
+ "a=d/2 #computing core radius\n",
+ "eta_lateral = (16*(n1/n)**2)/(pi*(1+(n1/n))**4)*(2*arccos(y/(2*a))-(y/a)*(1-(y/(2*a))**2)**0.5) #computing eta_lateral with air gap\n",
+ "loss=-10*log10(eta_lateral) #computing loss when air gap is present\n",
+ "eta_lateral1=(2*arccos(y/(2*a))-(y/a)*(1-(y/(2*a))**2)**0.5)/pi #computing eta_lateral without air gap\n",
+ "loss1=-10*log10(eta_lateral1) #computing loss when air gap is not present\n",
+ "print \"loss with air gap is %.2f dB.\\nloss with no air gap is %.2f dB.\" %(loss,loss1) \n",
+ "#answer in the book for loss with air gap is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "loss with air gap is 0.91 dB.\n",
+ "loss with no air gap is 0.59 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2.3, page 5-5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.48 #refractive index of fiber\n",
+ "n=1 #refractive index of air\n",
+ "theta=10 #angle in degree\n",
+ "NA1=0.3 \n",
+ "NA2=0.6\n",
+ "eta_angular1= (16*(n1/n)**2)/((1+(n1/n))**4)*(1-((n*theta*pi/180)/(pi*NA1))) #computing eta angular\n",
+ "eta_angular2= (16*(n1/n)**2)/((1+(n1/n))**4)*(1-((n*theta*pi/180)/(pi*NA2))) #computing eta angular\n",
+ "loss1=-10*log10(eta_angular1) #computing loss\n",
+ "loss2=-10*log10(eta_angular2) #computing loss\n",
+ "print \"\\nLoss when NA is %.1f is %.2f dB.\\nLoss when NA is %.1f is %.2f dB.\" %(NA1,loss1,NA2,loss2) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Loss when NA is 0.3 is 1.22 dB.\n",
+ "Loss when NA is 0.6 is 0.75 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4.1, page 5-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import exp\n",
+ "d=1*10**-6 #lateral displacement\n",
+ "W=4.95*10**-6 #MFD\n",
+ "Lsm_lat= -10*log10(exp(-(d/W)**2)) #computing loss\n",
+ "print \"Insertion loss is %.2f dB.\" %(Lsm_lat) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Insertion loss is 0.18 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4.2, page 5-15 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=1.3*10**-6 #wavelength\n",
+ "theta=1 #angle in degree\n",
+ "n2=1.465 #cladding refractive index\n",
+ "W=4.95*10**-6 #MFD\n",
+ "Lsm_ang= -10*log10(exp(-(pi*n2*W*(theta*pi/180)/lamda)**2)) #computing loss\n",
+ "print \"Insertion loss is %.2f dB.\" %(Lsm_ang) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Insertion loss is 0.41 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6.1, page 5-28 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "p1=50*10**-6 \n",
+ "p2=0.003*10**-6 \n",
+ "p3=25*10**-6 \n",
+ "p4=26.5*10**-6\n",
+ "EL=10*log10(p1/(p3+p4)) #computing excess loss\n",
+ "IL13=10*log10(p1/p3) #computing insertion loss\n",
+ "IL14=10*log10(p1/p4) #computing insertion loss\n",
+ "ct=10*log10(p2/p1) #computing cross talk\n",
+ "sr=(p3/(p3+p4))*100 #computing split ratio\n",
+ "print \"\"\"Excess loss is %.2f dB.\n",
+ "Insertion loss from port 1 to port 3 is %.2f dB.\n",
+ "Insertion loss from port 1 to port 4 is %.2f dB.\n",
+ "cross talk is %.2f dB.\\nSplit ratio is %.2f percent\"\"\" %(EL,IL13,IL14,ct,sr ) \n",
+ "#Printing and calculation error in the book.Minus sign is not printed in the answer of excess loss.\n",
+ "#P1 is taken 25 instead of 50 while calculating cross talk. "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Excess loss is -0.13 dB.\n",
+ "Insertion loss from port 1 to port 3 is 3.01 dB.\n",
+ "Insertion loss from port 1 to port 4 is 2.76 dB.\n",
+ "cross talk is -42.22 dB.\n",
+ "Split ratio is 48.54 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6.2, page 5-29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "N=16 #Number of ports\n",
+ "Pin=1*10**-3 #input power\n",
+ "Pout=12*10**-6 #output power\n",
+ "split_loss=10*log10(N) #computing split loss\n",
+ "excess_loss=10*log10(Pin/(Pout*N)) #computing excess loss\n",
+ "total_loss=split_loss+excess_loss #computing total loss\n",
+ "insertion_loss= 10*log10(Pin/Pout) #computing insertion loss\n",
+ "print \"Total loss is %.2f dB.\\nInsertion loss is %.2f dB.\" %(total_loss,insertion_loss) \n",
+ "#answer in the book for Total loss & insertion loss are wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total loss is 19.21 dB.\n",
+ "Insertion loss is 19.21 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter5_1.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter5_1.ipynb
new file mode 100755
index 00000000..1c8edfa4
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter5_1.ipynb
@@ -0,0 +1,281 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:69c313bd7e7f4ca84b1b5e5f091a7854a8c80d86bc1470f5cbc9e6d39211d1ba"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter5 - Optical fiber connection : splicing"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2.1, page 5-2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi, log10\n",
+ "n1=1.47 #refractive index of fiber\n",
+ "n=1 #refractive index of air\n",
+ "r=((n1-n)/(n1+n))**2 #computing fraction of light reflected\n",
+ "loss=-10*log10(1-r) #loss\n",
+ "total_loss=2*loss \n",
+ "print \"r = %.3f, which means %.1f percent of the transimitted light is reflected at one interface\" %(r,r*100) \n",
+ "print \"Total loss is %.3f dB\" %(total_loss) \n",
+ "#answer in the book for total loss of fiber is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r = 0.036, which means 3.6 percent of the transimitted light is reflected at one interface\n",
+ "Total loss is 0.320 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2.2, page 5-4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import arccos\n",
+ "n1=1.47 #refractive index of fiber\n",
+ "n=1 #refractive index of air\n",
+ "d=40*10**-6 #core diameter\n",
+ "y=4*10**-6 #lateral dispalcement\n",
+ "a=d/2 #computing core radius\n",
+ "eta_lateral = (16*(n1/n)**2)/(pi*(1+(n1/n))**4)*(2*arccos(y/(2*a))-(y/a)*(1-(y/(2*a))**2)**0.5) #computing eta_lateral with air gap\n",
+ "loss=-10*log10(eta_lateral) #computing loss when air gap is present\n",
+ "eta_lateral1=(2*arccos(y/(2*a))-(y/a)*(1-(y/(2*a))**2)**0.5)/pi #computing eta_lateral without air gap\n",
+ "loss1=-10*log10(eta_lateral1) #computing loss when air gap is not present\n",
+ "print \"loss with air gap is %.2f dB.\\nloss with no air gap is %.2f dB.\" %(loss,loss1) \n",
+ "#answer in the book for loss with air gap is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "loss with air gap is 0.91 dB.\n",
+ "loss with no air gap is 0.59 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2.3, page 5-5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.48 #refractive index of fiber\n",
+ "n=1 #refractive index of air\n",
+ "theta=10 #angle in degree\n",
+ "NA1=0.3 \n",
+ "NA2=0.6\n",
+ "eta_angular1= (16*(n1/n)**2)/((1+(n1/n))**4)*(1-((n*theta*pi/180)/(pi*NA1))) #computing eta angular\n",
+ "eta_angular2= (16*(n1/n)**2)/((1+(n1/n))**4)*(1-((n*theta*pi/180)/(pi*NA2))) #computing eta angular\n",
+ "loss1=-10*log10(eta_angular1) #computing loss\n",
+ "loss2=-10*log10(eta_angular2) #computing loss\n",
+ "print \"\\nLoss when NA is %.1f is %.2f dB.\\nLoss when NA is %.1f is %.2f dB.\" %(NA1,loss1,NA2,loss2) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Loss when NA is 0.3 is 1.22 dB.\n",
+ "Loss when NA is 0.6 is 0.75 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4.1, page 5-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import exp\n",
+ "d=1*10**-6 #lateral displacement\n",
+ "W=4.95*10**-6 #MFD\n",
+ "Lsm_lat= -10*log10(exp(-(d/W)**2)) #computing loss\n",
+ "print \"Insertion loss is %.2f dB.\" %(Lsm_lat) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Insertion loss is 0.18 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4.2, page 5-15 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=1.3*10**-6 #wavelength\n",
+ "theta=1 #angle in degree\n",
+ "n2=1.465 #cladding refractive index\n",
+ "W=4.95*10**-6 #MFD\n",
+ "Lsm_ang= -10*log10(exp(-(pi*n2*W*(theta*pi/180)/lamda)**2)) #computing loss\n",
+ "print \"Insertion loss is %.2f dB.\" %(Lsm_ang) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Insertion loss is 0.41 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6.1, page 5-28 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "p1=50*10**-6 \n",
+ "p2=0.003*10**-6 \n",
+ "p3=25*10**-6 \n",
+ "p4=26.5*10**-6\n",
+ "EL=10*log10(p1/(p3+p4)) #computing excess loss\n",
+ "IL13=10*log10(p1/p3) #computing insertion loss\n",
+ "IL14=10*log10(p1/p4) #computing insertion loss\n",
+ "ct=10*log10(p2/p1) #computing cross talk\n",
+ "sr=(p3/(p3+p4))*100 #computing split ratio\n",
+ "print \"\"\"Excess loss is %.2f dB.\n",
+ "Insertion loss from port 1 to port 3 is %.2f dB.\n",
+ "Insertion loss from port 1 to port 4 is %.2f dB.\n",
+ "cross talk is %.2f dB.\\nSplit ratio is %.2f percent\"\"\" %(EL,IL13,IL14,ct,sr ) \n",
+ "#Printing and calculation error in the book.Minus sign is not printed in the answer of excess loss.\n",
+ "#P1 is taken 25 instead of 50 while calculating cross talk. "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Excess loss is -0.13 dB.\n",
+ "Insertion loss from port 1 to port 3 is 3.01 dB.\n",
+ "Insertion loss from port 1 to port 4 is 2.76 dB.\n",
+ "cross talk is -42.22 dB.\n",
+ "Split ratio is 48.54 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6.2, page 5-29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "N=16 #Number of ports\n",
+ "Pin=1*10**-3 #input power\n",
+ "Pout=12*10**-6 #output power\n",
+ "split_loss=10*log10(N) #computing split loss\n",
+ "excess_loss=10*log10(Pin/(Pout*N)) #computing excess loss\n",
+ "total_loss=split_loss+excess_loss #computing total loss\n",
+ "insertion_loss= 10*log10(Pin/Pout) #computing insertion loss\n",
+ "print \"Total loss is %.2f dB.\\nInsertion loss is %.2f dB.\" %(total_loss,insertion_loss) \n",
+ "#answer in the book for Total loss & insertion loss are wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total loss is 19.21 dB.\n",
+ "Insertion loss is 19.21 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter6.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter6.ipynb
new file mode 100755
index 00000000..2383415f
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter6.ipynb
@@ -0,0 +1,252 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1a1f7133700fa452f49cfaeb319a776f69d7e64235d3f11f1abd2825b262e6e8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter6 - Optical sources"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3.1, page 6-7 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "x=0.07 \n",
+ "Eg=1.424+1.266*x+0.266*x**2 \n",
+ "lamda=1.24/Eg #computing wavelength\n",
+ "print \"Wavlength is %.3f micrometer.\" %lamda "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavlength is 0.819 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3.2, page 6.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n=1.7 #refractive index\n",
+ "L=5*10**-2 #distance between mirror\n",
+ "c=3*10**8 #speed of light\n",
+ "lamda=0.45*10**-6 #wavelength\n",
+ "k=2*n*L/lamda #computing number of modes\n",
+ "delf=c/(2*n*L) #computing mode separation\n",
+ "delf=delf*10**-9 \n",
+ "print \"Number of modes are %.2e.\\nFrequency separation is %.2f GHz.\"%(k,delf) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of modes are 3.78e+05.\n",
+ "Frequency separation is 1.76 GHz.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7.1, page 6-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "tr=50 #radiative recombination lifetime\n",
+ "tnr=85 #non-radiative recombination lifetime\n",
+ "h=6.624*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "i=35*10**-3 #current\n",
+ "lamda=0.85*10**-6 #wavelength\n",
+ "t=tr*tnr/(tr+tnr) #computing total recombination time\n",
+ "eta=t/tr #computing internal quantum efficiency\n",
+ "Pint=eta*h*c*i/(q*lamda) #computing internally generated power\n",
+ "Pint=Pint*10**3\n",
+ "print \"Total recombinaiton time is %.2f ns.\\nInternal quantum efficiency is %.3f.\\nInternally generated power is %.2f mW.\" %(t,eta,Pint) \n",
+ "#answer in the book for Internal quantum efficiency & Internally generated power is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total recombinaiton time is 31.48 ns.\n",
+ "Internal quantum efficiency is 0.630.\n",
+ "Internally generated power is 32.20 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8.1, page 6-34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt, pi\n",
+ "f1=10*10**6 #frequency\n",
+ "f2=100*10**6\n",
+ "t=4*10**-9 \n",
+ "Pdc=280*10**-6 #optincal output power\n",
+ "w1=2*pi*f1 #computing omega\n",
+ "Pout1=Pdc*10**6/(sqrt(1+(w1*t)**2)) #computing output power\n",
+ "w2=2*pi*f2 #computing omega\n",
+ "Pout2=Pdc*10**6/(sqrt(1+(w2*t)**2)) #computing output power\n",
+ "print \"\"\"Ouput power at 10 MHz is %.2f microwatt.\n",
+ "Ouput power at 100 MHz is %.2f microwatt.\n",
+ "Conclusion when device is drive at higher frequency the optical power reduces.\"\"\" %(Pout1,Pout2) \n",
+ "BWopt = sqrt(3)/(2*pi*t) \n",
+ "BWelec = BWopt/sqrt(2) \n",
+ "BWopt=BWopt*10**-6 \n",
+ "BWelec=BWelec*10**-6 \n",
+ "print \"3 dB optical power is %.2f MHz.\\n3 dB electrical power is %.2f MHz.\" %(BWopt,BWelec) \n",
+ "#calculation error. In the book square term in the denominater is not taken.\n",
+ "#answers in the book are wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ouput power at 10 MHz is 271.55 microwatt.\n",
+ "Ouput power at 100 MHz is 103.52 microwatt.\n",
+ "Conclusion when device is drive at higher frequency the optical power reduces.\n",
+ "3 dB optical power is 68.92 MHz.\n",
+ "3 dB electrical power is 48.73 MHz.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8.2, page 6-35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=3.5 #refractive index\n",
+ "n=1 #refractive index of air\n",
+ "F=0.69 #transmission factor\n",
+ "eta = 100*(n1*(n1+1)**2)**-1 #computing eta\n",
+ "print \"eta external is %.1f percent i.e. small fraction of intrnally generated opticalpower is emitted from the device.\" %eta \n",
+ "r= 100*F*n**2/(4*n1**2) #computing ratio of Popt/Pint\n",
+ "print \"Popt/Pint is %.1f percent\" %r\n",
+ "#printing mistake at final answer."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "eta external is 1.4 percent i.e. small fraction of intrnally generated opticalpower is emitted from the device.\n",
+ "Popt/Pint is 1.4 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8.3, page 6-39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log, exp\n",
+ "beta0=1.85*10**7 \n",
+ "T=293 #temperature\n",
+ "k=1.38*10**-23 #Boltzman constant\n",
+ "Ea=0.9*1.6*10**-19 \n",
+ "theta=0.65 #thershold\n",
+ "betar=beta0*exp(-Ea/(k*T)) \n",
+ "t=-log(theta)/betar \n",
+ "print \"Degradation rate is %.1e per hour.\\nOperating lifetime is %.1e hour.\" %(betar,t) \n",
+ "#answer in the book for Degradation rate & Operating lifetime is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Degradation rate is 6.3e-09 per hour.\n",
+ "Operating lifetime is 6.8e+07 hour.\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter6_1.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter6_1.ipynb
new file mode 100755
index 00000000..2383415f
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter6_1.ipynb
@@ -0,0 +1,252 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1a1f7133700fa452f49cfaeb319a776f69d7e64235d3f11f1abd2825b262e6e8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter6 - Optical sources"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3.1, page 6-7 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "x=0.07 \n",
+ "Eg=1.424+1.266*x+0.266*x**2 \n",
+ "lamda=1.24/Eg #computing wavelength\n",
+ "print \"Wavlength is %.3f micrometer.\" %lamda "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavlength is 0.819 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3.2, page 6.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n=1.7 #refractive index\n",
+ "L=5*10**-2 #distance between mirror\n",
+ "c=3*10**8 #speed of light\n",
+ "lamda=0.45*10**-6 #wavelength\n",
+ "k=2*n*L/lamda #computing number of modes\n",
+ "delf=c/(2*n*L) #computing mode separation\n",
+ "delf=delf*10**-9 \n",
+ "print \"Number of modes are %.2e.\\nFrequency separation is %.2f GHz.\"%(k,delf) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of modes are 3.78e+05.\n",
+ "Frequency separation is 1.76 GHz.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7.1, page 6-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "tr=50 #radiative recombination lifetime\n",
+ "tnr=85 #non-radiative recombination lifetime\n",
+ "h=6.624*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "i=35*10**-3 #current\n",
+ "lamda=0.85*10**-6 #wavelength\n",
+ "t=tr*tnr/(tr+tnr) #computing total recombination time\n",
+ "eta=t/tr #computing internal quantum efficiency\n",
+ "Pint=eta*h*c*i/(q*lamda) #computing internally generated power\n",
+ "Pint=Pint*10**3\n",
+ "print \"Total recombinaiton time is %.2f ns.\\nInternal quantum efficiency is %.3f.\\nInternally generated power is %.2f mW.\" %(t,eta,Pint) \n",
+ "#answer in the book for Internal quantum efficiency & Internally generated power is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total recombinaiton time is 31.48 ns.\n",
+ "Internal quantum efficiency is 0.630.\n",
+ "Internally generated power is 32.20 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8.1, page 6-34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt, pi\n",
+ "f1=10*10**6 #frequency\n",
+ "f2=100*10**6\n",
+ "t=4*10**-9 \n",
+ "Pdc=280*10**-6 #optincal output power\n",
+ "w1=2*pi*f1 #computing omega\n",
+ "Pout1=Pdc*10**6/(sqrt(1+(w1*t)**2)) #computing output power\n",
+ "w2=2*pi*f2 #computing omega\n",
+ "Pout2=Pdc*10**6/(sqrt(1+(w2*t)**2)) #computing output power\n",
+ "print \"\"\"Ouput power at 10 MHz is %.2f microwatt.\n",
+ "Ouput power at 100 MHz is %.2f microwatt.\n",
+ "Conclusion when device is drive at higher frequency the optical power reduces.\"\"\" %(Pout1,Pout2) \n",
+ "BWopt = sqrt(3)/(2*pi*t) \n",
+ "BWelec = BWopt/sqrt(2) \n",
+ "BWopt=BWopt*10**-6 \n",
+ "BWelec=BWelec*10**-6 \n",
+ "print \"3 dB optical power is %.2f MHz.\\n3 dB electrical power is %.2f MHz.\" %(BWopt,BWelec) \n",
+ "#calculation error. In the book square term in the denominater is not taken.\n",
+ "#answers in the book are wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ouput power at 10 MHz is 271.55 microwatt.\n",
+ "Ouput power at 100 MHz is 103.52 microwatt.\n",
+ "Conclusion when device is drive at higher frequency the optical power reduces.\n",
+ "3 dB optical power is 68.92 MHz.\n",
+ "3 dB electrical power is 48.73 MHz.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8.2, page 6-35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=3.5 #refractive index\n",
+ "n=1 #refractive index of air\n",
+ "F=0.69 #transmission factor\n",
+ "eta = 100*(n1*(n1+1)**2)**-1 #computing eta\n",
+ "print \"eta external is %.1f percent i.e. small fraction of intrnally generated opticalpower is emitted from the device.\" %eta \n",
+ "r= 100*F*n**2/(4*n1**2) #computing ratio of Popt/Pint\n",
+ "print \"Popt/Pint is %.1f percent\" %r\n",
+ "#printing mistake at final answer."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "eta external is 1.4 percent i.e. small fraction of intrnally generated opticalpower is emitted from the device.\n",
+ "Popt/Pint is 1.4 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8.3, page 6-39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log, exp\n",
+ "beta0=1.85*10**7 \n",
+ "T=293 #temperature\n",
+ "k=1.38*10**-23 #Boltzman constant\n",
+ "Ea=0.9*1.6*10**-19 \n",
+ "theta=0.65 #thershold\n",
+ "betar=beta0*exp(-Ea/(k*T)) \n",
+ "t=-log(theta)/betar \n",
+ "print \"Degradation rate is %.1e per hour.\\nOperating lifetime is %.1e hour.\" %(betar,t) \n",
+ "#answer in the book for Degradation rate & Operating lifetime is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Degradation rate is 6.3e-09 per hour.\n",
+ "Operating lifetime is 6.8e+07 hour.\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter7.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter7.ipynb
new file mode 100755
index 00000000..59a13011
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter7.ipynb
@@ -0,0 +1,716 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7b09bc4939eefcfd52ab3af51ad805d4dcc13501d36382e73f4451d0d172843b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter7 - Source to fiber power launching and photodetectors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2.1, page 7-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import pi, sqrt, log10\n",
+ "n1=3.4 #refractive index of optical source\n",
+ "n=1.46 #refractive index of silica fiber\n",
+ "r=((n1-n)/(n1+n))**2 #computing Frensel reflection\n",
+ "L=-10*log10(1-r) #computing loss\n",
+ "print \"Frensel reflection is %.3f.\\nPower loss is %.2f dB.\" %(r,L) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frensel reflection is 0.159.\n",
+ "Power loss is 0.75 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2.2, page 7-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "r=35*10**-6 #radius\n",
+ "R=150 #Lambertian emission pattern\n",
+ "NA=0.2 #Numerical aperture\n",
+ "Pled = pi**2*r**2*R*NA**2 \n",
+ "Pled=Pled*10**7 \n",
+ "print \"Optical power for larger core of 35 micrometer is %.3f mW.\" %(Pled) \n",
+ "r1=25*10**-6 \n",
+ "Pled1=(r1/r)**2*Pled \n",
+ "print \"Optical power for smaller core of 25 micrometer is %.2f mW.\" %(Pled1) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Optical power for larger core of 35 micrometer is 0.725 mW.\n",
+ "Optical power for smaller core of 25 micrometer is 0.37 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2.3, page 7-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "r=25*10**-6 #radius\n",
+ "R=39 #Lambertian emission pattern\n",
+ "NA=0.25 #numerical aperture\n",
+ "a=35*10**-6 #area\n",
+ "Pc1= pi**2*a**2*R*NA**2 #computing coupled power when r<a\n",
+ "Pc1=Pc1*10**7 \n",
+ "Pc= pi**2*r**2*R*NA**2 #computing coupled power when r>a\n",
+ "Pc=Pc*10**7 \n",
+ "print \"Optical power when r>a is %.2f mW.\\nOptical power when r<a is %.3f mW.\" %(Pc,Pc1) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Optical power when r>a is 0.15 mW.\n",
+ "Optical power when r<a is 0.295 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.1, page 7-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "e=1.6*10**-19 #charge of electron\n",
+ "q=1.43 #Bandgap energy\n",
+ "lamda=h*c/(q*e)*10**9 #computing wavelength\n",
+ "print \"Wavelength is %d nm\" %(lamda) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavelength is 868 nm\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.2, page 7-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "R=0.6 #responsivity\n",
+ "Pin=15 #optical power in microwatt\n",
+ "Ip=R*Pin #computing photocurrent\n",
+ "print \"Photocurrent generated is %d microAmpere.\" %Ip "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Photocurrent generated is 9 microAmpere.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.3, page 7-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda1=1300*10**-9 \n",
+ "lamda2=1600*10**-9 \n",
+ "h=6.625*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=90/100 #quantum efficiency\n",
+ "E=0.73 #energy gap in eV\n",
+ "R1=eta*q*lamda1/(h*c) \n",
+ "R2=eta*q*lamda2/(h*c) \n",
+ "lamdac=1.24/E \n",
+ "print \"Responsivity at 1300nm is %.2f A/W.\\nResponsivity at 1600nm is %.2f A/W.\\nCut-off wavelength is %.1f micrometer.\" %(R1,R2,lamdac) \n",
+ "#R1 is calculated wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Responsivity at 1300nm is 0.94 A/W.\n",
+ "Responsivity at 1600nm is 1.16 A/W.\n",
+ "Cut-off wavelength is 1.7 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.4, page 7-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=0.8*10**-6 \n",
+ "h=6.625*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "ne=1.8*10**11 #electrons collected\n",
+ "np=4*10**11 #photons incident\n",
+ "eta=ne/np #computing quantum efficiency\n",
+ "R=eta*q*lamda/(h*c) #computing responsivity\n",
+ "print \"Responsivity of photodiode at 0.8 micrometer is %.3f A/W.\" %R \n",
+ "#answer in the book is wrong. "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Responsivity of photodiode at 0.8 micrometer is 0.290 A/W.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.5, page 7-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "E=1.8*10**-19 # Energy of photon\n",
+ "nq=70/100 # Quantum\n",
+ "Ip=3 # current in uA\n",
+ "h=6.625*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "lamda=h*c/E*10**6 # wavelength in micro meter\n",
+ "print \"Photodiode operates at %0.2f micro meter\" %lamda\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "R=nq*q/E #computing responsivity\n",
+ "Popt=Ip/R\n",
+ "print \"Incident optical power required = %.3f uW.\" %Popt "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Photodiode operates at 1.10 micro meter\n",
+ "Incident optical power required = 4.821 uW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.6, page 7-25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "E=1.35 #energy gap in eV\n",
+ "lamda=h*c/(q*E) #computing wavelength\n",
+ "lamda=lamda*10**6 \n",
+ "print \"The InP photodetector will stop operation above %.2f micrometer.\" %(lamda) \n",
+ "#calculation error in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The InP photodetector will stop operation above 0.92 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.7, page 7-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "eta=65/100 #quantum efficiency\n",
+ "I=2.5*10**-6 #photocurrent \n",
+ "E=1.5*10**-19 #energy of photns\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "lamda=h*c/E #computing wavelength\n",
+ "R=eta*q*lamda/(h*c) #computing responsivity\n",
+ "Popt=I/R #computing optical power\n",
+ "lamda=lamda*10**6 \n",
+ "Popt=Popt*10**6 \n",
+ "print \"Wavelength is %.3f micrometer.\\nResponsivity is %.3f A/W.\\nIncident optical power required is %.1f microWatt.\" %(lamda,R,Popt) \n",
+ "#answer of R(responsivity) in the book is calculated as 0.694 A/W, deviation of 0.001."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavelength is 1.325 micrometer.\n",
+ "Responsivity is 0.693 A/W.\n",
+ "Incident optical power required is 3.6 microWatt.\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.8, page 7-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ne=3.9*10**6 #electrons collected\n",
+ "np=6*10**6 #photons incident\n",
+ "eta=100*ne/np #computing efficiency\n",
+ "print \"Quantum efficiency is %d percent.\" %(eta) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quantum efficiency is 65 percent.\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8.1, page 7-37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "w=25*10**-6 #width\n",
+ "v=1*10**5 #velocity\n",
+ "r=40*10**-6 #radius\n",
+ "eps=12.5*10**-13 \n",
+ "t=w/v #computing drift time\n",
+ "c=eps*3.14*(r)**2/w #computing junction capacitance\n",
+ "c=c*10**16 \n",
+ "print \"Drift time %.1e sec.\\nJunction capacitance %.1f pf.\" %(t,c) \n",
+ "#calculation error in drift time answer."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Drift time 2.5e-10 sec.\n",
+ "Junction capacitance 2.5 pf.\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8.2, page 7-38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "w=20*10**-6 #width\n",
+ "v=4*10**4 #velocity\n",
+ "t=w/v #computing drift time\n",
+ "BW=(2*pi*t)**-1 #computing bandwidth\n",
+ "rt=1/BW #computing response time\n",
+ "rt=rt*10**9 \n",
+ "print \"Maximum response time is %.1f ns.\" %(rt)\n",
+ "#Calculation error in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum response time is 3.1 ns.\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9.1, page 7-43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=1.4*10**-6 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "I=10*10**-9 #current\n",
+ "NEP= h*c*sqrt(2*q*I)/(eta*q*lamda) \n",
+ "D=NEP**-1 \n",
+ "print \"Noise equivalent power is %.3e W.\\nSpecific directivity is %.2e.\" %(NEP,D) \n",
+ "#answers in the book for NEP & D is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Noise equivalent power is 7.723e-14 W.\n",
+ "Specific directivity is 1.29e+13.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9.2, page 7-44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=1300*10**-9 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=90/100 #quantum efficiency\n",
+ "P0=300*10**-9 #optical power\n",
+ "Id=4 #dark current\n",
+ "B=20*10**6 #bandwidth\n",
+ "K=1.39*10**-23 #Boltzman constant\n",
+ "T=298 #temperature\n",
+ "R=1000 #load resister\n",
+ "Ip= 10**9*eta*P0*q*lamda/(h*c) \n",
+ "Its=10**9*(2*q*B*(Ip+Id)) \n",
+ "Its=sqrt(Its) \n",
+ "print \"rms shot noise current is %.2f nA.\" %(Its) \n",
+ "It= 4*K*T*B/R \n",
+ "It=sqrt(It) \n",
+ "print \"Thermal noise is %.2e A.\" %(It) \n",
+ "#answer given in book for shot noise & Thermal noise are wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rms shot noise current is 1.35 nA.\n",
+ "Thermal noise is 1.82e-08 A.\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10.1, page 7-51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import floor\n",
+ "lamda=0.85*10**-6 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=75/100 #quantum efficiency\n",
+ "P0=0.6*10**-6 #incident optical power\n",
+ "Im=15*10**2 #avalanche gain\n",
+ "R= eta*q*lamda/(h*c) #computing responsivity\n",
+ "Ip=10**8*P0*R #computing photocurrent\n",
+ "Ip=floor(Ip) \n",
+ "M=Im/Ip #computing multiplication factor\n",
+ "print \"Multiplication factor is %d.\" %(M) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication factor is 50.\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10.2, page 7-51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "lamda=900*10**-9 # Wavelength in m\n",
+ "P0=0.5 # Optical power\n",
+ "Im=10 # Photocurrent\n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65.0/100 #quantum efficiency\n",
+ "R= eta*q*lamda/(h*c) #computing responsivity\n",
+ "Ip=P0*R #computing photocurrent \n",
+ "M=Im/Ip #computing multiplication factor\n",
+ "print \"Multiplication factor is %0.2f.\" %(M) \n",
+ "# Answer is wrong in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication factor is 42.47.\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10.3, page 7-52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=900*10**-9 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "P0=0.5*10**-6 #incident optical power\n",
+ "Im=10*10**2 #avalanche gain\n",
+ "R= eta*q*lamda/(h*c) #computing responsivity\n",
+ "Ip=10**8*P0*R #computing photocurrent\n",
+ "M=Im/Ip #computing multiplication factor\n",
+ "print \"Multiplication factor is %d.\" %(M) \n",
+ "#answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication factor is 42.\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10.3, page 7-52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=900*10**-9 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "P0=0.5*10**-6 #incident optical power\n",
+ "Im=10*10**2 #avalanche gain\n",
+ "R= eta*q*lamda/(h*c) #computong responsivity\n",
+ "Ip=10**8*P0*R #computing photocurrent\n",
+ "M=Im/Ip #computing multiplication factor\n",
+ "print \"Multiplication factor is %d.\" %M "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication factor is 42.\n"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter7_1.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter7_1.ipynb
new file mode 100755
index 00000000..59a13011
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter7_1.ipynb
@@ -0,0 +1,716 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7b09bc4939eefcfd52ab3af51ad805d4dcc13501d36382e73f4451d0d172843b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter7 - Source to fiber power launching and photodetectors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2.1, page 7-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import pi, sqrt, log10\n",
+ "n1=3.4 #refractive index of optical source\n",
+ "n=1.46 #refractive index of silica fiber\n",
+ "r=((n1-n)/(n1+n))**2 #computing Frensel reflection\n",
+ "L=-10*log10(1-r) #computing loss\n",
+ "print \"Frensel reflection is %.3f.\\nPower loss is %.2f dB.\" %(r,L) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frensel reflection is 0.159.\n",
+ "Power loss is 0.75 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2.2, page 7-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "r=35*10**-6 #radius\n",
+ "R=150 #Lambertian emission pattern\n",
+ "NA=0.2 #Numerical aperture\n",
+ "Pled = pi**2*r**2*R*NA**2 \n",
+ "Pled=Pled*10**7 \n",
+ "print \"Optical power for larger core of 35 micrometer is %.3f mW.\" %(Pled) \n",
+ "r1=25*10**-6 \n",
+ "Pled1=(r1/r)**2*Pled \n",
+ "print \"Optical power for smaller core of 25 micrometer is %.2f mW.\" %(Pled1) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Optical power for larger core of 35 micrometer is 0.725 mW.\n",
+ "Optical power for smaller core of 25 micrometer is 0.37 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2.3, page 7-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "r=25*10**-6 #radius\n",
+ "R=39 #Lambertian emission pattern\n",
+ "NA=0.25 #numerical aperture\n",
+ "a=35*10**-6 #area\n",
+ "Pc1= pi**2*a**2*R*NA**2 #computing coupled power when r<a\n",
+ "Pc1=Pc1*10**7 \n",
+ "Pc= pi**2*r**2*R*NA**2 #computing coupled power when r>a\n",
+ "Pc=Pc*10**7 \n",
+ "print \"Optical power when r>a is %.2f mW.\\nOptical power when r<a is %.3f mW.\" %(Pc,Pc1) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Optical power when r>a is 0.15 mW.\n",
+ "Optical power when r<a is 0.295 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.1, page 7-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "e=1.6*10**-19 #charge of electron\n",
+ "q=1.43 #Bandgap energy\n",
+ "lamda=h*c/(q*e)*10**9 #computing wavelength\n",
+ "print \"Wavelength is %d nm\" %(lamda) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavelength is 868 nm\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.2, page 7-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "R=0.6 #responsivity\n",
+ "Pin=15 #optical power in microwatt\n",
+ "Ip=R*Pin #computing photocurrent\n",
+ "print \"Photocurrent generated is %d microAmpere.\" %Ip "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Photocurrent generated is 9 microAmpere.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.3, page 7-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda1=1300*10**-9 \n",
+ "lamda2=1600*10**-9 \n",
+ "h=6.625*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=90/100 #quantum efficiency\n",
+ "E=0.73 #energy gap in eV\n",
+ "R1=eta*q*lamda1/(h*c) \n",
+ "R2=eta*q*lamda2/(h*c) \n",
+ "lamdac=1.24/E \n",
+ "print \"Responsivity at 1300nm is %.2f A/W.\\nResponsivity at 1600nm is %.2f A/W.\\nCut-off wavelength is %.1f micrometer.\" %(R1,R2,lamdac) \n",
+ "#R1 is calculated wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Responsivity at 1300nm is 0.94 A/W.\n",
+ "Responsivity at 1600nm is 1.16 A/W.\n",
+ "Cut-off wavelength is 1.7 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.4, page 7-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=0.8*10**-6 \n",
+ "h=6.625*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "ne=1.8*10**11 #electrons collected\n",
+ "np=4*10**11 #photons incident\n",
+ "eta=ne/np #computing quantum efficiency\n",
+ "R=eta*q*lamda/(h*c) #computing responsivity\n",
+ "print \"Responsivity of photodiode at 0.8 micrometer is %.3f A/W.\" %R \n",
+ "#answer in the book is wrong. "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Responsivity of photodiode at 0.8 micrometer is 0.290 A/W.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.5, page 7-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "E=1.8*10**-19 # Energy of photon\n",
+ "nq=70/100 # Quantum\n",
+ "Ip=3 # current in uA\n",
+ "h=6.625*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "lamda=h*c/E*10**6 # wavelength in micro meter\n",
+ "print \"Photodiode operates at %0.2f micro meter\" %lamda\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "R=nq*q/E #computing responsivity\n",
+ "Popt=Ip/R\n",
+ "print \"Incident optical power required = %.3f uW.\" %Popt "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Photodiode operates at 1.10 micro meter\n",
+ "Incident optical power required = 4.821 uW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.6, page 7-25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "E=1.35 #energy gap in eV\n",
+ "lamda=h*c/(q*E) #computing wavelength\n",
+ "lamda=lamda*10**6 \n",
+ "print \"The InP photodetector will stop operation above %.2f micrometer.\" %(lamda) \n",
+ "#calculation error in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The InP photodetector will stop operation above 0.92 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.7, page 7-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "eta=65/100 #quantum efficiency\n",
+ "I=2.5*10**-6 #photocurrent \n",
+ "E=1.5*10**-19 #energy of photns\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "lamda=h*c/E #computing wavelength\n",
+ "R=eta*q*lamda/(h*c) #computing responsivity\n",
+ "Popt=I/R #computing optical power\n",
+ "lamda=lamda*10**6 \n",
+ "Popt=Popt*10**6 \n",
+ "print \"Wavelength is %.3f micrometer.\\nResponsivity is %.3f A/W.\\nIncident optical power required is %.1f microWatt.\" %(lamda,R,Popt) \n",
+ "#answer of R(responsivity) in the book is calculated as 0.694 A/W, deviation of 0.001."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavelength is 1.325 micrometer.\n",
+ "Responsivity is 0.693 A/W.\n",
+ "Incident optical power required is 3.6 microWatt.\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.8, page 7-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ne=3.9*10**6 #electrons collected\n",
+ "np=6*10**6 #photons incident\n",
+ "eta=100*ne/np #computing efficiency\n",
+ "print \"Quantum efficiency is %d percent.\" %(eta) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quantum efficiency is 65 percent.\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8.1, page 7-37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "w=25*10**-6 #width\n",
+ "v=1*10**5 #velocity\n",
+ "r=40*10**-6 #radius\n",
+ "eps=12.5*10**-13 \n",
+ "t=w/v #computing drift time\n",
+ "c=eps*3.14*(r)**2/w #computing junction capacitance\n",
+ "c=c*10**16 \n",
+ "print \"Drift time %.1e sec.\\nJunction capacitance %.1f pf.\" %(t,c) \n",
+ "#calculation error in drift time answer."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Drift time 2.5e-10 sec.\n",
+ "Junction capacitance 2.5 pf.\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8.2, page 7-38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "w=20*10**-6 #width\n",
+ "v=4*10**4 #velocity\n",
+ "t=w/v #computing drift time\n",
+ "BW=(2*pi*t)**-1 #computing bandwidth\n",
+ "rt=1/BW #computing response time\n",
+ "rt=rt*10**9 \n",
+ "print \"Maximum response time is %.1f ns.\" %(rt)\n",
+ "#Calculation error in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum response time is 3.1 ns.\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9.1, page 7-43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=1.4*10**-6 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "I=10*10**-9 #current\n",
+ "NEP= h*c*sqrt(2*q*I)/(eta*q*lamda) \n",
+ "D=NEP**-1 \n",
+ "print \"Noise equivalent power is %.3e W.\\nSpecific directivity is %.2e.\" %(NEP,D) \n",
+ "#answers in the book for NEP & D is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Noise equivalent power is 7.723e-14 W.\n",
+ "Specific directivity is 1.29e+13.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9.2, page 7-44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=1300*10**-9 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=90/100 #quantum efficiency\n",
+ "P0=300*10**-9 #optical power\n",
+ "Id=4 #dark current\n",
+ "B=20*10**6 #bandwidth\n",
+ "K=1.39*10**-23 #Boltzman constant\n",
+ "T=298 #temperature\n",
+ "R=1000 #load resister\n",
+ "Ip= 10**9*eta*P0*q*lamda/(h*c) \n",
+ "Its=10**9*(2*q*B*(Ip+Id)) \n",
+ "Its=sqrt(Its) \n",
+ "print \"rms shot noise current is %.2f nA.\" %(Its) \n",
+ "It= 4*K*T*B/R \n",
+ "It=sqrt(It) \n",
+ "print \"Thermal noise is %.2e A.\" %(It) \n",
+ "#answer given in book for shot noise & Thermal noise are wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rms shot noise current is 1.35 nA.\n",
+ "Thermal noise is 1.82e-08 A.\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10.1, page 7-51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import floor\n",
+ "lamda=0.85*10**-6 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=75/100 #quantum efficiency\n",
+ "P0=0.6*10**-6 #incident optical power\n",
+ "Im=15*10**2 #avalanche gain\n",
+ "R= eta*q*lamda/(h*c) #computing responsivity\n",
+ "Ip=10**8*P0*R #computing photocurrent\n",
+ "Ip=floor(Ip) \n",
+ "M=Im/Ip #computing multiplication factor\n",
+ "print \"Multiplication factor is %d.\" %(M) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication factor is 50.\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10.2, page 7-51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "lamda=900*10**-9 # Wavelength in m\n",
+ "P0=0.5 # Optical power\n",
+ "Im=10 # Photocurrent\n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65.0/100 #quantum efficiency\n",
+ "R= eta*q*lamda/(h*c) #computing responsivity\n",
+ "Ip=P0*R #computing photocurrent \n",
+ "M=Im/Ip #computing multiplication factor\n",
+ "print \"Multiplication factor is %0.2f.\" %(M) \n",
+ "# Answer is wrong in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication factor is 42.47.\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10.3, page 7-52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=900*10**-9 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "P0=0.5*10**-6 #incident optical power\n",
+ "Im=10*10**2 #avalanche gain\n",
+ "R= eta*q*lamda/(h*c) #computing responsivity\n",
+ "Ip=10**8*P0*R #computing photocurrent\n",
+ "M=Im/Ip #computing multiplication factor\n",
+ "print \"Multiplication factor is %d.\" %(M) \n",
+ "#answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication factor is 42.\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10.3, page 7-52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=900*10**-9 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "P0=0.5*10**-6 #incident optical power\n",
+ "Im=10*10**2 #avalanche gain\n",
+ "R= eta*q*lamda/(h*c) #computong responsivity\n",
+ "Ip=10**8*P0*R #computing photocurrent\n",
+ "M=Im/Ip #computing multiplication factor\n",
+ "print \"Multiplication factor is %d.\" %M "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication factor is 42.\n"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter8.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter8.ipynb
new file mode 100755
index 00000000..11017e30
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter8.ipynb
@@ -0,0 +1,272 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3deb63e976713f6e36585549e6b144389b0fc28fe2982a2838d929f3804cde18"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter8 - Optical receiver operation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2.1, page 8-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log, sqrt, pi, log10\n",
+ "P=10**-9 #probability of error\n",
+ "eta=1 #ideal detector\n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "lamda=1*10**-6 #wavelength\n",
+ "B=10**7 #bit rate\n",
+ "Mn = -log(P) \n",
+ "print \"The quantum limit at the receiver to maintain bit error rate 10**-9 is (%.1f*h*f)/eta.\" %Mn\n",
+ "f=c/lamda\n",
+ "Popt= 0.5*Mn*h*f*B/eta #computing optical power\n",
+ "Popt_dB = 10 * log10(Popt) + 30 #optical power in dbm\n",
+ "Popt=Popt*10**12 \n",
+ "print \"Minimum incident optical power is %.1f W or %.1f dBm.\" %(Popt,Popt_dB) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The quantum limit at the receiver to maintain bit error rate 10**-9 is (20.7*h*f)/eta.\n",
+ "Minimum incident optical power is 20.6 W or -76.9 dBm.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2.2, page 8-8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "SN_dB=60 #signal to noise ratio\n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "lamda=1.3*10**-6 #wavelength\n",
+ "eta=1 \n",
+ "B=6.5*10**6 #Bandwidth\n",
+ "SN=10**(SN_dB/10) \n",
+ "f=c/lamda\n",
+ "Popt= 2*SN*h*f*B/eta #computing optical power\n",
+ "Popt_dB = 10 * log10(Popt) + 30 #optical power in dbm\n",
+ "Popt=Popt*10**6 \n",
+ "print \"Incident power required to get an SNR of 60 dB at the receiver is %.4f microWatt or %.3f dBm\" %(Popt,Popt_dB)\n",
+ "#Calculation error in the book.They have take SN as 10**5 while calculating, which has lead to an error in final answer\n",
+ "#answer in the book 198.1nW and -37.71 dBm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Incident power required to get an SNR of 60 dB at the receiver is 1.9878 microWatt or -27.016 dBm\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3.1, page 8-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=0.85*10**-6 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "P0=300*10**-9 #optical power\n",
+ "Id=3.5 #dark current\n",
+ "B=6.5*10**6 #bandwidth\n",
+ "K=1.39*10**-23 #Boltzman constant\n",
+ "T=293 #temperature\n",
+ "R=5*10**3 #load resister\n",
+ "Ip= 10**9*eta*P0*q*lamda/(h*c) \n",
+ "Its=10**9*(2*q*B*(Ip+Id)) \n",
+ "Its=sqrt(Its) \n",
+ "print \"rms shot noise current is %.2f nA.\" %(Its) \n",
+ "It= 4*K*T*B/R \n",
+ "It=sqrt(It) \n",
+ "It=It*10**9 \n",
+ "print \"Thermal noise is %.2f nA.\" %(It) \n",
+ "#answer given in book for Thermal noise is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rms shot noise current is 0.53 nA.\n",
+ "Thermal noise is 4.60 nA.\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3.2, page 8-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=0.85*10**-6 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "P0=300*10**-9 #optical power\n",
+ "Id=3.5 #dark current\n",
+ "B=6.5*10**6 #bandwidth\n",
+ "K=1.39*10**-23 #Boltzman constant\n",
+ "T=293 #temperature\n",
+ "R=5*10**3 #load resister\n",
+ "F_dB=3 #noise figure\n",
+ "F=10**(F_dB/10) \n",
+ "Ip=10**9*eta*P0*q*lamda/(h*c) \n",
+ "Its=10**9*(2*q*B*(Ip+Id)) \n",
+ "It1= 4*K*T*B*F/R \n",
+ "SN= Ip**2/(Its+It1) \n",
+ "SN_dB=10*log10(SN) \n",
+ "SN=SN\n",
+ "print \"SNR is %.2e or %.2f dB.\" %(SN,SN_dB) \n",
+ "#answer given in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "SNR is 6.25e+04 or 47.96 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4.1, page 8-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Cd=7*10**-12 \n",
+ "B=9*10**6 \n",
+ "Ca=7*10**-12 \n",
+ "R=(2*3.14*Cd*B)**-1 \n",
+ "B1=(2*3.14*R*(Cd+Ca))**-1 \n",
+ "R=R/1000 \n",
+ "B1=B1/10**6 \n",
+ "print \"\"\"Thus for 9MHz bandwidth maximum load resistance is %.2f Kohm\n",
+ "Now if we consider input capacitance of following amplifier Ca then Bandwidth is %.2fMHz\n",
+ "Maximum post detection bandwidth is half.\"\"\"%(R,B1) \n",
+ "#answer for resistance in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Thus for 9MHz bandwidth maximum load resistance is 2.53 Kohm\n",
+ "Now if we consider input capacitance of following amplifier Ca then Bandwidth is 4.50MHz\n",
+ "Maximum post detection bandwidth is half.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Question 7, page 8.44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "w=25*10**-6 #width\n",
+ "v=3*10**4 #velocity\n",
+ "t=w/v #computing drift time\n",
+ "BW=(2*pi*t)**-1 #computing bandwidth\n",
+ "rt=1/BW #response time\n",
+ "rt=rt*10**9 \n",
+ "print \"Maximum response time is %.2f ns.\" %(rt) \n",
+ "#Answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum response time is 5.24 ns.\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter8_1.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter8_1.ipynb
new file mode 100755
index 00000000..11017e30
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter8_1.ipynb
@@ -0,0 +1,272 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3deb63e976713f6e36585549e6b144389b0fc28fe2982a2838d929f3804cde18"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter8 - Optical receiver operation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2.1, page 8-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log, sqrt, pi, log10\n",
+ "P=10**-9 #probability of error\n",
+ "eta=1 #ideal detector\n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "lamda=1*10**-6 #wavelength\n",
+ "B=10**7 #bit rate\n",
+ "Mn = -log(P) \n",
+ "print \"The quantum limit at the receiver to maintain bit error rate 10**-9 is (%.1f*h*f)/eta.\" %Mn\n",
+ "f=c/lamda\n",
+ "Popt= 0.5*Mn*h*f*B/eta #computing optical power\n",
+ "Popt_dB = 10 * log10(Popt) + 30 #optical power in dbm\n",
+ "Popt=Popt*10**12 \n",
+ "print \"Minimum incident optical power is %.1f W or %.1f dBm.\" %(Popt,Popt_dB) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The quantum limit at the receiver to maintain bit error rate 10**-9 is (20.7*h*f)/eta.\n",
+ "Minimum incident optical power is 20.6 W or -76.9 dBm.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2.2, page 8-8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "SN_dB=60 #signal to noise ratio\n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "lamda=1.3*10**-6 #wavelength\n",
+ "eta=1 \n",
+ "B=6.5*10**6 #Bandwidth\n",
+ "SN=10**(SN_dB/10) \n",
+ "f=c/lamda\n",
+ "Popt= 2*SN*h*f*B/eta #computing optical power\n",
+ "Popt_dB = 10 * log10(Popt) + 30 #optical power in dbm\n",
+ "Popt=Popt*10**6 \n",
+ "print \"Incident power required to get an SNR of 60 dB at the receiver is %.4f microWatt or %.3f dBm\" %(Popt,Popt_dB)\n",
+ "#Calculation error in the book.They have take SN as 10**5 while calculating, which has lead to an error in final answer\n",
+ "#answer in the book 198.1nW and -37.71 dBm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Incident power required to get an SNR of 60 dB at the receiver is 1.9878 microWatt or -27.016 dBm\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3.1, page 8-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=0.85*10**-6 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "P0=300*10**-9 #optical power\n",
+ "Id=3.5 #dark current\n",
+ "B=6.5*10**6 #bandwidth\n",
+ "K=1.39*10**-23 #Boltzman constant\n",
+ "T=293 #temperature\n",
+ "R=5*10**3 #load resister\n",
+ "Ip= 10**9*eta*P0*q*lamda/(h*c) \n",
+ "Its=10**9*(2*q*B*(Ip+Id)) \n",
+ "Its=sqrt(Its) \n",
+ "print \"rms shot noise current is %.2f nA.\" %(Its) \n",
+ "It= 4*K*T*B/R \n",
+ "It=sqrt(It) \n",
+ "It=It*10**9 \n",
+ "print \"Thermal noise is %.2f nA.\" %(It) \n",
+ "#answer given in book for Thermal noise is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rms shot noise current is 0.53 nA.\n",
+ "Thermal noise is 4.60 nA.\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3.2, page 8-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=0.85*10**-6 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "P0=300*10**-9 #optical power\n",
+ "Id=3.5 #dark current\n",
+ "B=6.5*10**6 #bandwidth\n",
+ "K=1.39*10**-23 #Boltzman constant\n",
+ "T=293 #temperature\n",
+ "R=5*10**3 #load resister\n",
+ "F_dB=3 #noise figure\n",
+ "F=10**(F_dB/10) \n",
+ "Ip=10**9*eta*P0*q*lamda/(h*c) \n",
+ "Its=10**9*(2*q*B*(Ip+Id)) \n",
+ "It1= 4*K*T*B*F/R \n",
+ "SN= Ip**2/(Its+It1) \n",
+ "SN_dB=10*log10(SN) \n",
+ "SN=SN\n",
+ "print \"SNR is %.2e or %.2f dB.\" %(SN,SN_dB) \n",
+ "#answer given in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "SNR is 6.25e+04 or 47.96 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4.1, page 8-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Cd=7*10**-12 \n",
+ "B=9*10**6 \n",
+ "Ca=7*10**-12 \n",
+ "R=(2*3.14*Cd*B)**-1 \n",
+ "B1=(2*3.14*R*(Cd+Ca))**-1 \n",
+ "R=R/1000 \n",
+ "B1=B1/10**6 \n",
+ "print \"\"\"Thus for 9MHz bandwidth maximum load resistance is %.2f Kohm\n",
+ "Now if we consider input capacitance of following amplifier Ca then Bandwidth is %.2fMHz\n",
+ "Maximum post detection bandwidth is half.\"\"\"%(R,B1) \n",
+ "#answer for resistance in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Thus for 9MHz bandwidth maximum load resistance is 2.53 Kohm\n",
+ "Now if we consider input capacitance of following amplifier Ca then Bandwidth is 4.50MHz\n",
+ "Maximum post detection bandwidth is half.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Question 7, page 8.44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "w=25*10**-6 #width\n",
+ "v=3*10**4 #velocity\n",
+ "t=w/v #computing drift time\n",
+ "BW=(2*pi*t)**-1 #computing bandwidth\n",
+ "rt=1/BW #response time\n",
+ "rt=rt*10**9 \n",
+ "print \"Maximum response time is %.2f ns.\" %(rt) \n",
+ "#Answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum response time is 5.24 ns.\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter9.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter9.ipynb
new file mode 100755
index 00000000..ba8336a3
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter9.ipynb
@@ -0,0 +1,99 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c071b41323ac94460e204090d265021c7f2c7744a035dad84fc7193e1854e444"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter9 - Link design"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4.1, page 9-8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "output=13 #laser output\n",
+ "sensitivity=-31 #APD sensitivity\n",
+ "coupling_loss=0.5 \n",
+ "L=80 #length in km\n",
+ "sl=0.1 #loss correspond to one splice in dB\n",
+ "fl=0.35 #fiber loss in dB/km\n",
+ "noise=1.5 \n",
+ "allowed_loss=output-sensitivity \n",
+ "splices_loss=(L-1)*sl \n",
+ "fiber_loss=L*fl \n",
+ "margin=allowed_loss-(splices_loss+fiber_loss+coupling_loss+noise) \n",
+ "print \"Final margin is %.1f dB.\" %margin"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Final margin is 6.1 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6.1, page 9-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "L=10 \n",
+ "ts=10 \n",
+ "tD=8 \n",
+ "tmod=L*6 \n",
+ "tt=L*2 \n",
+ "Tsys=1.1*sqrt(ts**2+tmod**2+tt**2+tD**2) \n",
+ "Bt=0.7/Tsys \n",
+ "Bt=Bt*10**3 \n",
+ "print \"Maximum bit rate for link using NRZ data format is %.2f Mbits/sec.\" %Bt \n",
+ "#calculation error in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum bit rate for link using NRZ data format is 9.86 Mbits/sec.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communiation_by_Anasuya_Kalavar/chapter9_1.ipynb b/Optical_Communiation_by_Anasuya_Kalavar/chapter9_1.ipynb
new file mode 100755
index 00000000..ba8336a3
--- /dev/null
+++ b/Optical_Communiation_by_Anasuya_Kalavar/chapter9_1.ipynb
@@ -0,0 +1,99 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c071b41323ac94460e204090d265021c7f2c7744a035dad84fc7193e1854e444"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter9 - Link design"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4.1, page 9-8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "output=13 #laser output\n",
+ "sensitivity=-31 #APD sensitivity\n",
+ "coupling_loss=0.5 \n",
+ "L=80 #length in km\n",
+ "sl=0.1 #loss correspond to one splice in dB\n",
+ "fl=0.35 #fiber loss in dB/km\n",
+ "noise=1.5 \n",
+ "allowed_loss=output-sensitivity \n",
+ "splices_loss=(L-1)*sl \n",
+ "fiber_loss=L*fl \n",
+ "margin=allowed_loss-(splices_loss+fiber_loss+coupling_loss+noise) \n",
+ "print \"Final margin is %.1f dB.\" %margin"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Final margin is 6.1 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6.1, page 9-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "L=10 \n",
+ "ts=10 \n",
+ "tD=8 \n",
+ "tmod=L*6 \n",
+ "tt=L*2 \n",
+ "Tsys=1.1*sqrt(ts**2+tmod**2+tt**2+tD**2) \n",
+ "Bt=0.7/Tsys \n",
+ "Bt=Bt*10**3 \n",
+ "print \"Maximum bit rate for link using NRZ data format is %.2f Mbits/sec.\" %Bt \n",
+ "#calculation error in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum bit rate for link using NRZ data format is 9.86 Mbits/sec.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communication/README.txt b/Optical_Communication/README.txt
new file mode 100755
index 00000000..3bed375e
--- /dev/null
+++ b/Optical_Communication/README.txt
@@ -0,0 +1,10 @@
+Contributed By: Mohd arif
+Course: btech
+College/Institute/Organization: UKTU
+Department/Designation: EC
+Book Title: Optical Communication
+Author: Anasuya Kalavar
+Publisher: Tech-max Publications, Pune
+Year of publication: 2011
+Isbn: 978-81-8492-845-7
+Edition: 1 \ No newline at end of file
diff --git a/Optical_Communication/screenshots/SNR.png b/Optical_Communication/screenshots/SNR.png
new file mode 100755
index 00000000..e80cbedb
--- /dev/null
+++ b/Optical_Communication/screenshots/SNR.png
Binary files differ
diff --git a/Optical_Communication/screenshots/pulse_broadning.png b/Optical_Communication/screenshots/pulse_broadning.png
new file mode 100755
index 00000000..f104ba08
--- /dev/null
+++ b/Optical_Communication/screenshots/pulse_broadning.png
Binary files differ
diff --git a/Optical_Communication/screenshots/shot_noise_and_thermal_noise.png b/Optical_Communication/screenshots/shot_noise_and_thermal_noise.png
new file mode 100755
index 00000000..a4062961
--- /dev/null
+++ b/Optical_Communication/screenshots/shot_noise_and_thermal_noise.png
Binary files differ
diff --git a/Optical_Communication_by_Anasuya_Kalavar/chapter1.ipynb b/Optical_Communication_by_Anasuya_Kalavar/chapter1.ipynb
new file mode 100755
index 00000000..a271cc5c
--- /dev/null
+++ b/Optical_Communication_by_Anasuya_Kalavar/chapter1.ipynb
@@ -0,0 +1,128 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:985ad452c65fa6c321f3f5a416b2ee95d94eb6cba2ef0da1eac4d7b73a848422"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter1 - Overview of optical fiber communications"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.6.1, page 1-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Bit_rate = 2*10**9 # bit rate of channel\n",
+ "# Given sequence is 010111101110\n",
+ "Shortest_duration = 1*(1/Bit_rate) # shortest duration is '1'\n",
+ "Widest_duration = 4*(1/Bit_rate) #widest duration is '1111'\n",
+ "Shortest_duration = Shortest_duration # seconds\n",
+ "Widest_duration = Widest_duration # seconds\n",
+ "print \"Shortest duration is %.1g seconds.\" %Shortest_duration\n",
+ "print \"Widest duration is %.1g seconds.\" %Widest_duration"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Shortest duration is 5e-10 seconds.\n",
+ "Widest duration is 2e-09 seconds.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.12.1, page 1-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log2\n",
+ "Bandwidth = 2*10**6 #Bandwidth of channel\n",
+ "Signal_to_Noise_ratio = 1 #Signal to Noise ratio of channel\n",
+ "Capacity = Bandwidth * log2(1 + Signal_to_Noise_ratio) #computing capacity\n",
+ "Capacity=Capacity/10**6 \n",
+ "print \"Maximum capacity of channel is %d Mb/sec.\" %Capacity"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum capacity of channel is 2 Mb/sec.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Question 10, page 1-31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "Bit_rate = 2*10**9 # bit rate of channel\n",
+ "# Given sequence is 010111101110\n",
+ "Shortest_duration = 1*(1/Bit_rate) # shortest duration is '1'\n",
+ "Widest_duration = 4*(1/Bit_rate) #widest duration is '1111'\n",
+ "Shortest_duration = Shortest_duration # seconds\n",
+ "Widest_duration = Widest_duration # seconds\n",
+ "print \"Shortest duration is %.1g seconds.\" %Shortest_duration\n",
+ "print \"Widest duration is %.1g seconds.\" %Widest_duration"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Shortest duration is 5e-10 seconds.\n",
+ "Widest duration is 2e-09 seconds.\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communication_by_Anasuya_Kalavar/chapter10.ipynb b/Optical_Communication_by_Anasuya_Kalavar/chapter10.ipynb
new file mode 100755
index 00000000..6479ba9e
--- /dev/null
+++ b/Optical_Communication_by_Anasuya_Kalavar/chapter10.ipynb
@@ -0,0 +1,96 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:0e6d6451a42a64c2f14a17049d585a97e1d159d84d0a7abf55f333e84dfeeece"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter10 - Performance measurement and monitoring"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.5.1, page 10-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "from __future__ import division\n",
+ "To=12.6 #width of output pulse\n",
+ "Ti=0.3 #width of input pulse\n",
+ "l=1.2 #length of measurement\n",
+ "Pulse_dispersion = sqrt(To**2 - Ti**2) #computing pulse dispersion\n",
+ "PDKM=Pulse_dispersion/l #computing pulse dispersion per Kilometer\n",
+ "BW=0.44/PDKM #computing optical bandwidth\n",
+ "BW=BW*1000 \n",
+ "print \"Pulse broadning is %.1f ns/km.\\nOptical bandwidth is %.1f MHz.Km.\" %(PDKM,BW) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Pulse broadning is 10.5 ns/km.\n",
+ "Optical bandwidth is 41.9 MHz.Km.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.6.1, page 10-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log10\n",
+ "V2=12 \n",
+ "V1=2.5 \n",
+ "L2=3 \n",
+ "L1=0.004 \n",
+ "alpha_dB = 10* log10(V2/V1)/(L2-L1) \n",
+ "un = 0.2/(L2-L1) \n",
+ "print \"Attenuation is %.2f dB/km\\nUncertainity +/- %.3f dB.\" %(alpha_dB,un) \n",
+ "#answer for attenuation in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Attenuation is 2.27 dB/km\n",
+ "Uncertainity +/- 0.067 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communication_by_Anasuya_Kalavar/chapter2.ipynb b/Optical_Communication_by_Anasuya_Kalavar/chapter2.ipynb
new file mode 100755
index 00000000..934feb4e
--- /dev/null
+++ b/Optical_Communication_by_Anasuya_Kalavar/chapter2.ipynb
@@ -0,0 +1,886 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:94ac7a20c62e9612d243d85d9b1b3699e50dc46a0975e66ae373ce7747106bc9"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter2 - Optical Fibers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4.1 page 2-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import arcsin, sqrt, pi\n",
+ "#Numerical Aperture and critical angle\n",
+ "n1=1.46 #refractive index\n",
+ "d=0.01 #difference\n",
+ "na=n1*sqrt(2*d) #numerical aperture\n",
+ "x=1-d #\n",
+ "oc=arcsin(x)*180/pi #in degree\n",
+ "print \"numerical aperture = \",round(na,2)\n",
+ "print \"critical angle at core cladding interface =\",round(oc,1),\" degree\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "numerical aperture = 0.21\n",
+ "critical angle at core cladding interface = 81.9 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.1, page 2-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import arcsin, sqrt, pi\n",
+ "#Numerical Aperture ,critical angle and acceptance angle\n",
+ "n2=1.45 #core refrative index\n",
+ "n1=1.49 #cladding refrative index\n",
+ "oc=arcsin(n2/n1)*180/pi #in degree\n",
+ "na=sqrt(n1**2-n2**2) #numerical aperture\n",
+ "pc=arcsin(na)*180/pi #degree\n",
+ "print \"critical angle is =\",round(oc,2),\" degree\"\n",
+ "print \"numerical aperture =\",round(na,3)\n",
+ "print \"acceptance angle is\",round(pc,2),\" degree\"\n",
+ "# Answer in the book are not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "critical angle is = 76.69 degree\n",
+ "numerical aperture = 0.343\n",
+ "acceptance angle is 20.06 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.2, page 2-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import arcsin, sqrt, pi\n",
+ "delta = 1.2/100 # Relative refractive difference index\n",
+ "n1=1.45 # Core refractive index \n",
+ "NA= n1*sqrt(2*delta) #computing numerical aperture\n",
+ "Acceptance_angle = arcsin(NA)*180/pi #computing acceptance angle\n",
+ "si = pi*NA**2 #computing solid acceptance angle\n",
+ "print \"Numerical aperture is %.3f.\\nAcceptance angle is %.2f degree.\\nSolid acceptance angle is %.3f radians.\" %(NA,Acceptance_angle,si) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numerical aperture is 0.225.\n",
+ "Acceptance angle is 12.98 degree.\n",
+ "Solid acceptance angle is 0.159 radians.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.3, page 2-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NA = 0.45 # Numerical Aperture\n",
+ "Acceptance_angle = arcsin(NA)*180/pi #computing acceptance angle.\n",
+ "print \"Acceptance angle is %.1f degree.\" %Acceptance_angle"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Acceptance angle is 26.7 degree.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.4, page 2-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import arctan\n",
+ "diameter = 1 #Diameter in centimeter\n",
+ "Focal_length = 10 #Focal length in centimeter\n",
+ "radius=diameter/2 #computing radius\n",
+ "Acceptance_angle = arctan(radius/Focal_length)*180/pi #computing acceptance angle\n",
+ "Conical_full_angle = 2*Acceptance_angle #computing conical angle\n",
+ "Solid_acceptance_angle = pi*Acceptance_angle**2 #computing solid acceptance angle\n",
+ "NA = sqrt(Solid_acceptance_angle/pi) #computing Numerical aperture\n",
+ "print \"Numerical aperture is %.2f.\\nConical full angle is %.2f degree.\" %(NA,Conical_full_angle) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numerical aperture is 2.86.\n",
+ "Conical full angle is 5.72 degree.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6.1, page 2-16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import cos\n",
+ "NA = 0.45 #Numerical aperture\n",
+ "betaB = 45 # Skew ray change direction by 90 degree at each reflection\n",
+ "Meridional_theta = arcsin(NA)*180/pi #computing acceptacne angle for meridoinal ray\n",
+ "Skew_theta = arcsin(NA/cos(betaB*pi/180))*180/pi #computing acceptacne angle for skew ray\n",
+ "print \"Acceptacne angle for Meridoinal ray is %.2f degree.\\nAcceptance angle for Skew ray %.1f degree.\" %(Meridional_theta,Skew_theta) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Acceptacne angle for Meridoinal ray is 26.74 degree.\n",
+ "Acceptance angle for Skew ray 39.5 degree.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.1, page 2-21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "core_diameter=78*10**-6 #core diameter\n",
+ "delta=1.4/100 #relative index difference\n",
+ "lamda=0.8*10**-6 #operating wavelength\n",
+ "n1=1.47 #core refractive index\n",
+ "a=core_diameter/2 #computing core radius\n",
+ "v= 2*3.14*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "M=(v)**2/2 #computing guided modes\n",
+ "print \"Normalized Frequency is %.3f.\\nTotal number of guided modes are %.1f\" %(v,M)\n",
+ "#answer in the book are incorrect."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 75.306.\n",
+ "Total number of guided modes are 2835.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.2, page 2-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.47 #refractive index of core\n",
+ "a=4.3*10**-6 #radius of core\n",
+ "delta=0.2/100 #relative index difference\n",
+ "lamda= 2*3.14*a*n1*sqrt(2*delta)/2.405 #computing wavelength\n",
+ "lamda=lamda*10**9 \n",
+ "print \"Wavelength of fiber is %d nm.\" %lamda\n",
+ "#answer in the book is given as 1230nm which is incorrect."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavelength of fiber is 1043 nm.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.3, page 2-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.482 #refractive index of core\n",
+ "n2=1.474 #refractive index of cladding\n",
+ "lamda=820*10**-9 #Wavelength\n",
+ "NA=sqrt(n1**2 - n2**2) #computing Numerical aperture\n",
+ "theta= arcsin(NA)*180/pi #computing acceptance angle\n",
+ "solid_angle=pi*(NA)**2 #computing solid angle\n",
+ "a=2.405*lamda/(2*3.14*NA) #computing core radius\n",
+ "a=a*10**6 \n",
+ "print \"Numerical aperture is %.3f.\\nAcceptance angle is %.1f degrees.\\nSolid angle is %.3f radians.\\nCore radius is %.2f micrometer.\" %(NA,theta,solid_angle,a) \n",
+ "#answer in the book are not accurate."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numerical aperture is 0.154.\n",
+ "Acceptance angle is 8.8 degrees.\n",
+ "Solid angle is 0.074 radians.\n",
+ "Core radius is 2.04 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.4, page 2-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import ceil\n",
+ "NA=0.16 #Numerical aperture\n",
+ "n1=1.45 #core refractive index\n",
+ "d=60*10**-6 #core diameter\n",
+ "lamda=0.82*10**-6 #wavelength\n",
+ "a=d/2 #core radius\n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "M=v**2/2 #computing guided modes\n",
+ "print \"if normalized frequency is taken as %d, then there are %d guided modes.\" %(ceil(v),M) \n",
+ "#Answer given in the textbook is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "if normalized frequency is taken as 37, then there are 675 guided modes.\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.5, page 2-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NA=0.2 #Numericla aperture\n",
+ "d=50*10**-6 #Diameter of core\n",
+ "lamda=1*10**-6 #Wavelength\n",
+ "a=d/2 #computing radius\n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "Mg=v**2/4 #computing mode volume for parabollic profile\n",
+ "Mg=round(Mg) \n",
+ "print \"Normalized Frequency is %.1f.\\nTotal number of guided modes are %.d.\" %(v,Mg) \n",
+ "#answer in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 31.4.\n",
+ "Total number of guided modes are 246.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.6, page 2-27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "delta=0.015 #relative refractive index\n",
+ "n1=1.48 #core refractive index\n",
+ "lamda=0.85*10**-6 #wavelength\n",
+ "a=(2.4*lamda)/(2*3.14*n1*sqrt(2*delta)) #computing radius of core\n",
+ "d=2*a #computing diameter of core\n",
+ "a=a*10**7 \n",
+ "a=round(a,2) \n",
+ "a=a/10\n",
+ "d=d*10**6 \n",
+ "print \"Core radius is %.1f micrometer.\\nCore diameter is %.1f micrometer.\" %(a,2*a) \n",
+ "print \"When delta is reduced by 10 percent-\"\n",
+ "delta=0.0015 \n",
+ "a=(2.4*lamda)/(2*3.14*n1*sqrt(2*delta)) #computing radius of core\n",
+ "d=2*a #computing diameter of core\n",
+ "a=a*10**7 \n",
+ "a=round(a) \n",
+ "a=a/10\n",
+ "d=d*10**6 \n",
+ "print \"Core radius is %.1f micrometer.\\nCore diameter is %.1f micrometer.\" %(a,2*a) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Core radius is 1.3 micrometer.\n",
+ "Core diameter is 2.5 micrometer.\n",
+ "When delta is reduced by 10 percent-\n",
+ "Core radius is 4.0 micrometer.\n",
+ "Core diameter is 8.0 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.7, page 2-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NA=0.25 #Numericla aperture\n",
+ "d=45*10**-6 #Diameter of core\n",
+ "lamda=1.5*10**-6 #Wavelength\n",
+ "a=d/2 #computing radius\n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "Mg=v**2/4 #computing mode volume for parabollic profile\n",
+ "Mg=round(Mg,2) \n",
+ "print \"Normalized Frequency is %.2f.\\nTotal number of guided modes are %.d.\" %(v,ceil(Mg) )\n",
+ "#answer in the book for normalized frequency is 23.55, deviation 0.05"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 23.55.\n",
+ "Total number of guided modes are 139.\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.8, page 2-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NA=0.25 #Numericla aperture\n",
+ "d=45*10**-6 #Diameter of core\n",
+ "lamda=1.2*10**-6 #Wavelength\n",
+ "a=d/2 #computing radius\n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "Mg=v**2/4 #computing mode volume for parabollic profile\n",
+ "Mg=round(Mg,2) \n",
+ "print \"Normalized Frequency is %.1f.\\nTotal number of guided modes are %.d.\" %(v,Mg) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 29.4.\n",
+ "Total number of guided modes are 216.\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.9, page 2-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.54 #refractive index of core\n",
+ "n2=1.5 #refractive index of cladding\n",
+ "a=25*10**-6 #Radius of core in um\n",
+ "lamda=1.3*10**-6 #Wavelength in m\n",
+ "NA=sqrt(n1**2-n2**2) \n",
+ "v=2*3.14*a*NA/lamda #computing normalized frequency\n",
+ "Mg=v**2/4 #computing mode volume for parabollic profile\n",
+ "lamda_cut_off=v*lamda/2.405 #computing cut off wavelength\n",
+ "lamda_cut_off=lamda_cut_off*10**6 \n",
+ "print \"Normalized Frequency is %0.f.\\nTotal number of guided modes are %.d.\\nCut off wavelength is %.1f micrometer.\" %(v,Mg,lamda_cut_off) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 42.\n",
+ "Total number of guided modes are 443.\n",
+ "Cut off wavelength is 22.8 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.1 page 2-30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L_BL=8*10**-2 #beat length\n",
+ "Br=2*3.14/L_BL #computing modal briefringence\n",
+ "print \"Modal briefringence is %.1f per meter.\" %Br"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Modal briefringence is 78.5 per meter.\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.2, page 2-33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log10\n",
+ "Pin=500*10**-6 #input power\n",
+ "L=200 #length of fiber\n",
+ "loss=2 #loss associated with fiber\n",
+ "Pin_dbm=10*log10(Pin/(10**-3)) #computing input power in dBm\n",
+ "Pin_dbm=round(Pin_dbm) \n",
+ "Pout_dbm=Pin_dbm-L*loss #computing output power level\n",
+ "Pout= 10**(Pout_dbm/10) \n",
+ "print \"Output power is %.2e mW.\" %Pout"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output power is 5.01e-41 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12.1, page 2-37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=4.5*10**-6 #core diameter\n",
+ "delta=0.25/100 #relative index difference\n",
+ "lamda=0.85*10**-6 #operating wavelength\n",
+ "n1=1.46 #core refractive index\n",
+ "v= 2*pi*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "lamda_cut_off=v*lamda/2.405 #computing cut off wavelength\n",
+ "lamda_cut_off=lamda_cut_off*10**9 \n",
+ "print \"Cut off wavelength is %.d nanometer.\" %(lamda_cut_off)\n",
+ "print \"When delta is 1.25 percent-\" \n",
+ "delta=1.25/100 \n",
+ "v= 2*pi*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "lamda_cut_off=v*lamda/2.405 #computing cut off wavelength\n",
+ "lamda_cut_off=lamda_cut_off*10**7 \n",
+ "lamda_cut_off=round(lamda_cut_off) \n",
+ "lamda_cut_off=lamda_cut_off*100 \n",
+ "print \"Cut off wavelength is %.d nanometer.\" %(lamda_cut_off) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Cut off wavelength is 1213 nanometer.\n",
+ "When delta is 1.25 percent-\n",
+ "Cut off wavelength is 2700 nanometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12.2, page 2-38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=50*10**-6 #core radius\n",
+ "lamda=1500*10**-9 #operating wavelength\n",
+ "n1=2.53 #core refractive index\n",
+ "n2=1.5 #cladding refractive index\n",
+ "delta=(n1-n2)/n1 #computing delta\n",
+ "v= 2*3.14*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "M=(v)**2/2 #computing guided modes\n",
+ "print \"Normalized Frequency is %.1f\\nTotal number of guided modes are %.d\" %(v,M) \n",
+ "\n",
+ "#Calculation error in book. Answer in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 477.9\n",
+ "Total number of guided modes are 114191\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12.3, page 2-38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "core_diameter=8*10**-6 #core diameter\n",
+ "delta=0.92/100 #relative index difference\n",
+ "lamda=1550*10**-9 #operating wavelength\n",
+ "n1=1.45 #core refractive index\n",
+ "a=core_diameter/2 #computing core radius\n",
+ "v= 2*pi*a*n1*sqrt(2*delta)/lamda #computing normalized frequency\n",
+ "M=(v)**2/2 #computing guided modes\n",
+ "print \"Normalized Frequency is %.1f.\\nTotal number of guided modes are %.d.\" %(v,M) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Normalized Frequency is 3.2.\n",
+ "Total number of guided modes are 5.\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12.4, page 2-39 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "delta=1/100 #relative index difference\n",
+ "n1=1.5 #core refractive index\n",
+ "c=3*10**8 \n",
+ "L=6 \n",
+ "n2=sqrt(n1**2-2*delta*n1**2) #computing refractive index of cladding\n",
+ "delta_T=L*n1**2*delta/(c*n2) #computing pulse broadning\n",
+ "delta_T=delta_T*10**11 \n",
+ "delta_T=round(delta_T) \n",
+ "print \"Delay difference between slowest and fastest mode is %d ns/km.\" %delta_T \n",
+ "print \"This means that a pulse broadnes by %d ns after travel time a distance of %d km.\" %(delta_T,L)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Delay difference between slowest and fastest mode is 30 ns/km.\n",
+ "This means that a pulse broadnes by 30 ns after travel time a distance of 6 km.\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.17.1, page 2-60"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.48 #core refractive index\n",
+ "n2=1.46 #cladding refractive index\n",
+ "phi = arcsin(n2/n1)*180/pi #computing critical angle\n",
+ "NA = sqrt(n1**2 - n2**2) #computing numericla aperture\n",
+ "theta= arcsin(NA)*180/pi #computing acceptance angle\n",
+ "print \"Critical angle is %.2f degrees.\\nNumerical aperture is %.3f.\\nAcceptance angle is %.2f degree.\" %(phi,NA,theta) \n",
+ "#answers in the book are wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical angle is 80.57 degrees.\n",
+ "Numerical aperture is 0.242.\n",
+ "Acceptance angle is 14.03 degree.\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Question 4, page 2-61 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L_BL=8*10**-2 #beat length\n",
+ "Br=2*3.14/L_BL #computing modal briefringence\n",
+ "print \"Modal briefringence is %.1f per meter.\" %Br "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Modal briefringence is 78.5 per meter.\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Question 5, page 2-62 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L_BL=0.6*10**-3 #beat length\n",
+ "lamda=1.4*10**-6 #wavelength\n",
+ "L_BL1=70 \n",
+ "Bh=lamda/L_BL #computing high briefringence\n",
+ "Bl=lamda/L_BL1 #computing low briefringence\n",
+ "print \"High briefringence is %.2e.\\nLow briefringence is %.1e.\"%(Bh,Bl)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "High briefringence is 2.33e-03.\n",
+ "Low briefringence is 2.0e-08.\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communication_by_Anasuya_Kalavar/chapter4.ipynb b/Optical_Communication_by_Anasuya_Kalavar/chapter4.ipynb
new file mode 100755
index 00000000..408746a4
--- /dev/null
+++ b/Optical_Communication_by_Anasuya_Kalavar/chapter4.ipynb
@@ -0,0 +1,413 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c80be9ee73d5adb979ad6bf2343ea3cff1243505e35fc82560bd445f960931b7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter4 - Signal Degradation in fibers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3.1, page 4-4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi, log10\n",
+ "L=10 #fiber length in km\n",
+ "Pin=150*10**-6 #input power\n",
+ "Pout=5*10**-6 #output power\n",
+ "ln=20 #length of optical link\n",
+ "interval=1 #splices after interval of 1 km\n",
+ "l=1.2 #loss due to 1 splice\n",
+ "attenuation=10*log10(Pin/Pout) \n",
+ "alpha=attenuation/L \n",
+ "attenuation_loss=alpha*20 \n",
+ "splices_loss=(ln-interval)*l \n",
+ "total_loss=attenuation_loss+splices_loss \n",
+ "power_ratio=10**(total_loss/10) \n",
+ "print \"Signal attenuation is %.2f dBs.\\nSignal attenuation is %.3f dB/Km.\\nTotal loss in 20 Km fiber is %.2f dbs.\\nTotal attenuation is %.2f dBs.\\ninput/output ratio is %0.e.\" %(attenuation,alpha,attenuation_loss,total_loss,power_ratio) \n",
+ "# Answer wrong for last part."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Signal attenuation is 14.77 dBs.\n",
+ "Signal attenuation is 1.477 dB/Km.\n",
+ "Total loss in 20 Km fiber is 29.54 dbs.\n",
+ "Total attenuation is 52.34 dBs.\n",
+ "input/output ratio is 2e+05.\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6.1, page 4-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import exp\n",
+ "beta_c=8*10**-11 #isothermal compressibility\n",
+ "n=1.46 #refractive index\n",
+ "P=0.286 #photoelastic constat\n",
+ "k=1.38*10**-23 #Boltzmnn constant\n",
+ "T=1500 #temperature\n",
+ "L=1000 #length\n",
+ "lamda=1000*10**-9 #wavelength\n",
+ "gamma_r = 8*(3.14**3)*(P**2)*(n**8)*beta_c*k*T/(3*(lamda**4)) #computing coefficient\n",
+ "attenuation=exp(-gamma_r*L) #computing attenuation\n",
+ "print \"Attenuation due to Rayleigh scattering is %.3f.\" %(attenuation) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Attenuation due to Rayleigh scattering is 0.794.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6.2, page 4-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "beta_c=7*10**-11 #isothermal compressibility\n",
+ "n=1.46 #refractive index\n",
+ "P=0.29 #photoelastic constat\n",
+ "k=1.38*10**-23 #Boltzmnn constant\n",
+ "T=1400 #temperature\n",
+ "L=1000 #length\n",
+ "lamda=0.7*10**-6 #wavelength\n",
+ "gamma_r = 8*(3.14**3)*(P**2)*(n**8)*beta_c*k*T/(3*(lamda**4)) #computing coefficient\n",
+ "attenuation=exp(-gamma_r*L) #computing attenuation\n",
+ "gamma_r=gamma_r\n",
+ "print \"Raleigh Scattering corfficient is %.3e per meter\" %(gamma_r) \n",
+ "#Attenuation is not calcualted in textbook\"\n",
+ "print \"Attenuation due to Rayleigh scattering is %.3f\" %(attenuation) \n",
+ "#answer for Raleigh Scattering corfficient in the book is given as 0.804d-3, deviation of 0.003d-3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Raleigh Scattering corfficient is 8.074e-04 per meter\n",
+ "Attenuation due to Rayleigh scattering is 0.446\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7.1, page 4-17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "d=5 #core diameter\n",
+ "alpha=0.4 #attenuation\n",
+ "B=0.5 #Bandwidth\n",
+ "lamda=1.4 #wavelength\n",
+ "PB=4.4*10**-3*d**2*lamda**2*alpha*B #computing threshold power for SBS\n",
+ "PR=5.9*10**-2*d**2*lamda*alpha #computing threshold power for SRS\n",
+ "PB=PB*10**3 \n",
+ "PR=PR*10**3 \n",
+ "print \"Threshold power for SBS is %.1f mW.\\nThreshold power for SRS is %.3f mW.\" %(PB,PR) \n",
+ "#NOTE - Calculation error in the book while calculating threshold for SBS.\n",
+ "#Also, while calculating SRS, formula is taken incorrectly, \n",
+ "#Bandwidth is multiplied in second step, which is not in the formula.\") "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Threshold power for SBS is 43.1 mW.\n",
+ "Threshold power for SRS is 826.000 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8.1, page 4-18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.5 #refractive index of core\n",
+ "delta=0.03/100 #relative refractive index\n",
+ "lamda=0.82*10**-6 #wavelength\n",
+ "n2=sqrt(n1**2-2*delta*n1**2) #computing cladding refractive index\n",
+ "Rc=(3*n1**2*lamda)/(4*3.14*(n1**2-n2**2)**1.5) #computing critical radius\n",
+ "Rc=Rc*10**3 \n",
+ "print \"Critical radius is %.f micrometer.\" %(Rc) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical radius is 9 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8.2, page 4-20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.45 #refractive index of core\n",
+ "delta=3.0/100 #relative refractive index\n",
+ "lamda=1.5*10**-6 #wavelength\n",
+ "a=5*10**-6 #core radius\n",
+ "n2=sqrt(n1**2-2*delta*n1**2) #computing cladding refractive index\n",
+ "Rc=(3*n1**2*lamda)/(4*3.14*(n1**2-n2**2)**0.5) #computing critical radius for single mode\n",
+ "Rc=Rc*10**6 \n",
+ "print \"Critical radius is %.2f micrometer\" %(Rc) \n",
+ "lamda_cut_off= 2*3.14*a*n1*sqrt(2*delta)/2.405 \n",
+ "RcSM= (20*lamda/(n1-n2)**1.5)*(2.748-0.996*lamda/lamda_cut_off)**-3 #computing critical radius for single mode\n",
+ "RcSM=RcSM*10**6 \n",
+ "print \"Critical radius for single mode fiber is %.2f micrometer.\" %(RcSM) \n",
+ "#Calculation error in the book.(2.748-0.996*lamda/lamda_cut_off)**-3 in this term raised to -3 is not taken in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical radius is 2.12 micrometer\n",
+ "Critical radius for single mode fiber is 226.37 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.13.1, page 4-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=1550*10**-9 \n",
+ "lamda0=1.3*10**-6 \n",
+ "s0=0.095 \n",
+ "Dt=lamda*s0/4*(1-(lamda0/lamda)**4) #computing material dispersion\n",
+ "Dt=Dt*10**9 \n",
+ "print \"Material dispersion at 1550 nm is %.1f ps/nm/km\" %Dt\n",
+ "#answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Material dispersion at 1550 nm is 18.6 ps/nm/km\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.14.1, page 4-33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "tau=0.1*10**-6 #pulse broadning\n",
+ "dist=20*10**3 #distance\n",
+ "Bopt=1/(2*tau) #computing optical bandwidth\n",
+ "Bopt=Bopt*10**-6 \n",
+ "dispertion=tau/dist #computing dispersion\n",
+ "dispertion=dispertion*10**12 \n",
+ "BLP=Bopt*dist #computing Bandwidth length product\n",
+ "BLP=BLP*10**-3 \n",
+ "print \"optical bandwidth is %d MHz.\\nDispersion per unit length is %d ns/km.\\nBandwidth length product is %d MHz.km.\" %(Bopt,dispertion,BLP) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "optical bandwidth is 5 MHz.\n",
+ "Dispersion per unit length is 5 ns/km.\n",
+ "Bandwidth length product is 100 MHz.km.\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.15.1, page 4-34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "RSW=0.0012 #relative spectral width\n",
+ "lamda=0.90*10**-6 #wavelength\n",
+ "L=1 #distance in km (assumed)\n",
+ "P=0.025 #material dispersion parameter\n",
+ "c=3*10**5 #speed of light in km/s\n",
+ "M=10**3*P/(c*lamda) #computing material dispersion\n",
+ "sigma_lamda=RSW*lamda \n",
+ "sigmaM=sigma_lamda*L*M*10**7 #computing RMS pulse broadning\n",
+ "sigmaB=25*L*M*10**-3 \n",
+ "print \"Material dispersion parameter is %.2f ps/nm/km.\\nRMS pulsr broadning when sigma_lamda is 25 is %.1f ns/km.\\nRMS pulse broadning is %.2f ns/km.\" %(M,sigmaB,sigmaM) \n",
+ "#answer in the book for RMS pulse broadning is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Material dispersion parameter is 92.59 ps/nm/km.\n",
+ "RMS pulsr broadning when sigma_lamda is 25 is 2.3 ns/km.\n",
+ "RMS pulse broadning is 1.00 ns/km.\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.17.1, page 4-37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L=10 #length of optical link\n",
+ "n1=1.49 #refractive index\n",
+ "c=3*10**8 #speed of light\n",
+ "delta=1.0/100 #relative refractive index\n",
+ "delTS=L*n1*delta/c #computing delay difference\n",
+ "delTS=delTS*10**12 \n",
+ "sigmaS=L*n1*delta/(2*sqrt(3)*c) #computing rms pulse broadning\n",
+ "sigmaS=sigmaS*10**12 \n",
+ "B=1/(2*delTS) #computing maximum bit rate\n",
+ "B=B*10**3 \n",
+ "B_acc=0.2/(sigmaS) #computing accurate bit rate\n",
+ "B_acc=B_acc*10**3 \n",
+ "BLP=B_acc*L #computing Bandwidth length product\n",
+ "print \"Delay difference is %d ns.\\nRMS pulse broadning is %.1f ns.\\nBit rate is %.1f Mbit/s.\\nAccurate bit rate is %.3f Mbits/s.\\nBandwidth length product is %.1f MHz.km\" %(delTS,sigmaS,B,B_acc,BLP) \n",
+ "#answer for maximum bit rate is given as 1.008 Mb/s, deviation of 0.008 Mb/s."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Delay difference is 496 ns.\n",
+ "RMS pulse broadning is 143.4 ns.\n",
+ "Bit rate is 1.0 Mbit/s.\n",
+ "Accurate bit rate is 1.395 Mbits/s.\n",
+ "Bandwidth length product is 13.9 MHz.km\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communication_by_Anasuya_Kalavar/chapter5.ipynb b/Optical_Communication_by_Anasuya_Kalavar/chapter5.ipynb
new file mode 100755
index 00000000..1c8edfa4
--- /dev/null
+++ b/Optical_Communication_by_Anasuya_Kalavar/chapter5.ipynb
@@ -0,0 +1,281 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:69c313bd7e7f4ca84b1b5e5f091a7854a8c80d86bc1470f5cbc9e6d39211d1ba"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter5 - Optical fiber connection : splicing"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2.1, page 5-2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, pi, log10\n",
+ "n1=1.47 #refractive index of fiber\n",
+ "n=1 #refractive index of air\n",
+ "r=((n1-n)/(n1+n))**2 #computing fraction of light reflected\n",
+ "loss=-10*log10(1-r) #loss\n",
+ "total_loss=2*loss \n",
+ "print \"r = %.3f, which means %.1f percent of the transimitted light is reflected at one interface\" %(r,r*100) \n",
+ "print \"Total loss is %.3f dB\" %(total_loss) \n",
+ "#answer in the book for total loss of fiber is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "r = 0.036, which means 3.6 percent of the transimitted light is reflected at one interface\n",
+ "Total loss is 0.320 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2.2, page 5-4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import arccos\n",
+ "n1=1.47 #refractive index of fiber\n",
+ "n=1 #refractive index of air\n",
+ "d=40*10**-6 #core diameter\n",
+ "y=4*10**-6 #lateral dispalcement\n",
+ "a=d/2 #computing core radius\n",
+ "eta_lateral = (16*(n1/n)**2)/(pi*(1+(n1/n))**4)*(2*arccos(y/(2*a))-(y/a)*(1-(y/(2*a))**2)**0.5) #computing eta_lateral with air gap\n",
+ "loss=-10*log10(eta_lateral) #computing loss when air gap is present\n",
+ "eta_lateral1=(2*arccos(y/(2*a))-(y/a)*(1-(y/(2*a))**2)**0.5)/pi #computing eta_lateral without air gap\n",
+ "loss1=-10*log10(eta_lateral1) #computing loss when air gap is not present\n",
+ "print \"loss with air gap is %.2f dB.\\nloss with no air gap is %.2f dB.\" %(loss,loss1) \n",
+ "#answer in the book for loss with air gap is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "loss with air gap is 0.91 dB.\n",
+ "loss with no air gap is 0.59 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2.3, page 5-5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=1.48 #refractive index of fiber\n",
+ "n=1 #refractive index of air\n",
+ "theta=10 #angle in degree\n",
+ "NA1=0.3 \n",
+ "NA2=0.6\n",
+ "eta_angular1= (16*(n1/n)**2)/((1+(n1/n))**4)*(1-((n*theta*pi/180)/(pi*NA1))) #computing eta angular\n",
+ "eta_angular2= (16*(n1/n)**2)/((1+(n1/n))**4)*(1-((n*theta*pi/180)/(pi*NA2))) #computing eta angular\n",
+ "loss1=-10*log10(eta_angular1) #computing loss\n",
+ "loss2=-10*log10(eta_angular2) #computing loss\n",
+ "print \"\\nLoss when NA is %.1f is %.2f dB.\\nLoss when NA is %.1f is %.2f dB.\" %(NA1,loss1,NA2,loss2) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Loss when NA is 0.3 is 1.22 dB.\n",
+ "Loss when NA is 0.6 is 0.75 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4.1, page 5-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import exp\n",
+ "d=1*10**-6 #lateral displacement\n",
+ "W=4.95*10**-6 #MFD\n",
+ "Lsm_lat= -10*log10(exp(-(d/W)**2)) #computing loss\n",
+ "print \"Insertion loss is %.2f dB.\" %(Lsm_lat) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Insertion loss is 0.18 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4.2, page 5-15 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=1.3*10**-6 #wavelength\n",
+ "theta=1 #angle in degree\n",
+ "n2=1.465 #cladding refractive index\n",
+ "W=4.95*10**-6 #MFD\n",
+ "Lsm_ang= -10*log10(exp(-(pi*n2*W*(theta*pi/180)/lamda)**2)) #computing loss\n",
+ "print \"Insertion loss is %.2f dB.\" %(Lsm_ang) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Insertion loss is 0.41 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6.1, page 5-28 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "p1=50*10**-6 \n",
+ "p2=0.003*10**-6 \n",
+ "p3=25*10**-6 \n",
+ "p4=26.5*10**-6\n",
+ "EL=10*log10(p1/(p3+p4)) #computing excess loss\n",
+ "IL13=10*log10(p1/p3) #computing insertion loss\n",
+ "IL14=10*log10(p1/p4) #computing insertion loss\n",
+ "ct=10*log10(p2/p1) #computing cross talk\n",
+ "sr=(p3/(p3+p4))*100 #computing split ratio\n",
+ "print \"\"\"Excess loss is %.2f dB.\n",
+ "Insertion loss from port 1 to port 3 is %.2f dB.\n",
+ "Insertion loss from port 1 to port 4 is %.2f dB.\n",
+ "cross talk is %.2f dB.\\nSplit ratio is %.2f percent\"\"\" %(EL,IL13,IL14,ct,sr ) \n",
+ "#Printing and calculation error in the book.Minus sign is not printed in the answer of excess loss.\n",
+ "#P1 is taken 25 instead of 50 while calculating cross talk. "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Excess loss is -0.13 dB.\n",
+ "Insertion loss from port 1 to port 3 is 3.01 dB.\n",
+ "Insertion loss from port 1 to port 4 is 2.76 dB.\n",
+ "cross talk is -42.22 dB.\n",
+ "Split ratio is 48.54 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6.2, page 5-29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "N=16 #Number of ports\n",
+ "Pin=1*10**-3 #input power\n",
+ "Pout=12*10**-6 #output power\n",
+ "split_loss=10*log10(N) #computing split loss\n",
+ "excess_loss=10*log10(Pin/(Pout*N)) #computing excess loss\n",
+ "total_loss=split_loss+excess_loss #computing total loss\n",
+ "insertion_loss= 10*log10(Pin/Pout) #computing insertion loss\n",
+ "print \"Total loss is %.2f dB.\\nInsertion loss is %.2f dB.\" %(total_loss,insertion_loss) \n",
+ "#answer in the book for Total loss & insertion loss are wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total loss is 19.21 dB.\n",
+ "Insertion loss is 19.21 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communication_by_Anasuya_Kalavar/chapter6.ipynb b/Optical_Communication_by_Anasuya_Kalavar/chapter6.ipynb
new file mode 100755
index 00000000..2383415f
--- /dev/null
+++ b/Optical_Communication_by_Anasuya_Kalavar/chapter6.ipynb
@@ -0,0 +1,252 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1a1f7133700fa452f49cfaeb319a776f69d7e64235d3f11f1abd2825b262e6e8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter6 - Optical sources"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3.1, page 6-7 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "x=0.07 \n",
+ "Eg=1.424+1.266*x+0.266*x**2 \n",
+ "lamda=1.24/Eg #computing wavelength\n",
+ "print \"Wavlength is %.3f micrometer.\" %lamda "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavlength is 0.819 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3.2, page 6.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n=1.7 #refractive index\n",
+ "L=5*10**-2 #distance between mirror\n",
+ "c=3*10**8 #speed of light\n",
+ "lamda=0.45*10**-6 #wavelength\n",
+ "k=2*n*L/lamda #computing number of modes\n",
+ "delf=c/(2*n*L) #computing mode separation\n",
+ "delf=delf*10**-9 \n",
+ "print \"Number of modes are %.2e.\\nFrequency separation is %.2f GHz.\"%(k,delf) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of modes are 3.78e+05.\n",
+ "Frequency separation is 1.76 GHz.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7.1, page 6-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "tr=50 #radiative recombination lifetime\n",
+ "tnr=85 #non-radiative recombination lifetime\n",
+ "h=6.624*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "i=35*10**-3 #current\n",
+ "lamda=0.85*10**-6 #wavelength\n",
+ "t=tr*tnr/(tr+tnr) #computing total recombination time\n",
+ "eta=t/tr #computing internal quantum efficiency\n",
+ "Pint=eta*h*c*i/(q*lamda) #computing internally generated power\n",
+ "Pint=Pint*10**3\n",
+ "print \"Total recombinaiton time is %.2f ns.\\nInternal quantum efficiency is %.3f.\\nInternally generated power is %.2f mW.\" %(t,eta,Pint) \n",
+ "#answer in the book for Internal quantum efficiency & Internally generated power is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total recombinaiton time is 31.48 ns.\n",
+ "Internal quantum efficiency is 0.630.\n",
+ "Internally generated power is 32.20 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8.1, page 6-34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt, pi\n",
+ "f1=10*10**6 #frequency\n",
+ "f2=100*10**6\n",
+ "t=4*10**-9 \n",
+ "Pdc=280*10**-6 #optincal output power\n",
+ "w1=2*pi*f1 #computing omega\n",
+ "Pout1=Pdc*10**6/(sqrt(1+(w1*t)**2)) #computing output power\n",
+ "w2=2*pi*f2 #computing omega\n",
+ "Pout2=Pdc*10**6/(sqrt(1+(w2*t)**2)) #computing output power\n",
+ "print \"\"\"Ouput power at 10 MHz is %.2f microwatt.\n",
+ "Ouput power at 100 MHz is %.2f microwatt.\n",
+ "Conclusion when device is drive at higher frequency the optical power reduces.\"\"\" %(Pout1,Pout2) \n",
+ "BWopt = sqrt(3)/(2*pi*t) \n",
+ "BWelec = BWopt/sqrt(2) \n",
+ "BWopt=BWopt*10**-6 \n",
+ "BWelec=BWelec*10**-6 \n",
+ "print \"3 dB optical power is %.2f MHz.\\n3 dB electrical power is %.2f MHz.\" %(BWopt,BWelec) \n",
+ "#calculation error. In the book square term in the denominater is not taken.\n",
+ "#answers in the book are wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ouput power at 10 MHz is 271.55 microwatt.\n",
+ "Ouput power at 100 MHz is 103.52 microwatt.\n",
+ "Conclusion when device is drive at higher frequency the optical power reduces.\n",
+ "3 dB optical power is 68.92 MHz.\n",
+ "3 dB electrical power is 48.73 MHz.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8.2, page 6-35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n1=3.5 #refractive index\n",
+ "n=1 #refractive index of air\n",
+ "F=0.69 #transmission factor\n",
+ "eta = 100*(n1*(n1+1)**2)**-1 #computing eta\n",
+ "print \"eta external is %.1f percent i.e. small fraction of intrnally generated opticalpower is emitted from the device.\" %eta \n",
+ "r= 100*F*n**2/(4*n1**2) #computing ratio of Popt/Pint\n",
+ "print \"Popt/Pint is %.1f percent\" %r\n",
+ "#printing mistake at final answer."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "eta external is 1.4 percent i.e. small fraction of intrnally generated opticalpower is emitted from the device.\n",
+ "Popt/Pint is 1.4 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8.3, page 6-39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import log, exp\n",
+ "beta0=1.85*10**7 \n",
+ "T=293 #temperature\n",
+ "k=1.38*10**-23 #Boltzman constant\n",
+ "Ea=0.9*1.6*10**-19 \n",
+ "theta=0.65 #thershold\n",
+ "betar=beta0*exp(-Ea/(k*T)) \n",
+ "t=-log(theta)/betar \n",
+ "print \"Degradation rate is %.1e per hour.\\nOperating lifetime is %.1e hour.\" %(betar,t) \n",
+ "#answer in the book for Degradation rate & Operating lifetime is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Degradation rate is 6.3e-09 per hour.\n",
+ "Operating lifetime is 6.8e+07 hour.\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communication_by_Anasuya_Kalavar/chapter7.ipynb b/Optical_Communication_by_Anasuya_Kalavar/chapter7.ipynb
new file mode 100755
index 00000000..59a13011
--- /dev/null
+++ b/Optical_Communication_by_Anasuya_Kalavar/chapter7.ipynb
@@ -0,0 +1,716 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7b09bc4939eefcfd52ab3af51ad805d4dcc13501d36382e73f4451d0d172843b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter7 - Source to fiber power launching and photodetectors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2.1, page 7-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import pi, sqrt, log10\n",
+ "n1=3.4 #refractive index of optical source\n",
+ "n=1.46 #refractive index of silica fiber\n",
+ "r=((n1-n)/(n1+n))**2 #computing Frensel reflection\n",
+ "L=-10*log10(1-r) #computing loss\n",
+ "print \"Frensel reflection is %.3f.\\nPower loss is %.2f dB.\" %(r,L) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frensel reflection is 0.159.\n",
+ "Power loss is 0.75 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2.2, page 7-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "r=35*10**-6 #radius\n",
+ "R=150 #Lambertian emission pattern\n",
+ "NA=0.2 #Numerical aperture\n",
+ "Pled = pi**2*r**2*R*NA**2 \n",
+ "Pled=Pled*10**7 \n",
+ "print \"Optical power for larger core of 35 micrometer is %.3f mW.\" %(Pled) \n",
+ "r1=25*10**-6 \n",
+ "Pled1=(r1/r)**2*Pled \n",
+ "print \"Optical power for smaller core of 25 micrometer is %.2f mW.\" %(Pled1) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Optical power for larger core of 35 micrometer is 0.725 mW.\n",
+ "Optical power for smaller core of 25 micrometer is 0.37 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2.3, page 7-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "r=25*10**-6 #radius\n",
+ "R=39 #Lambertian emission pattern\n",
+ "NA=0.25 #numerical aperture\n",
+ "a=35*10**-6 #area\n",
+ "Pc1= pi**2*a**2*R*NA**2 #computing coupled power when r<a\n",
+ "Pc1=Pc1*10**7 \n",
+ "Pc= pi**2*r**2*R*NA**2 #computing coupled power when r>a\n",
+ "Pc=Pc*10**7 \n",
+ "print \"Optical power when r>a is %.2f mW.\\nOptical power when r<a is %.3f mW.\" %(Pc,Pc1) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Optical power when r>a is 0.15 mW.\n",
+ "Optical power when r<a is 0.295 mW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.1, page 7-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "e=1.6*10**-19 #charge of electron\n",
+ "q=1.43 #Bandgap energy\n",
+ "lamda=h*c/(q*e)*10**9 #computing wavelength\n",
+ "print \"Wavelength is %d nm\" %(lamda) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavelength is 868 nm\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.2, page 7-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "R=0.6 #responsivity\n",
+ "Pin=15 #optical power in microwatt\n",
+ "Ip=R*Pin #computing photocurrent\n",
+ "print \"Photocurrent generated is %d microAmpere.\" %Ip "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Photocurrent generated is 9 microAmpere.\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.3, page 7-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda1=1300*10**-9 \n",
+ "lamda2=1600*10**-9 \n",
+ "h=6.625*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=90/100 #quantum efficiency\n",
+ "E=0.73 #energy gap in eV\n",
+ "R1=eta*q*lamda1/(h*c) \n",
+ "R2=eta*q*lamda2/(h*c) \n",
+ "lamdac=1.24/E \n",
+ "print \"Responsivity at 1300nm is %.2f A/W.\\nResponsivity at 1600nm is %.2f A/W.\\nCut-off wavelength is %.1f micrometer.\" %(R1,R2,lamdac) \n",
+ "#R1 is calculated wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Responsivity at 1300nm is 0.94 A/W.\n",
+ "Responsivity at 1600nm is 1.16 A/W.\n",
+ "Cut-off wavelength is 1.7 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.4, page 7-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=0.8*10**-6 \n",
+ "h=6.625*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "ne=1.8*10**11 #electrons collected\n",
+ "np=4*10**11 #photons incident\n",
+ "eta=ne/np #computing quantum efficiency\n",
+ "R=eta*q*lamda/(h*c) #computing responsivity\n",
+ "print \"Responsivity of photodiode at 0.8 micrometer is %.3f A/W.\" %R \n",
+ "#answer in the book is wrong. "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Responsivity of photodiode at 0.8 micrometer is 0.290 A/W.\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.5, page 7-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "E=1.8*10**-19 # Energy of photon\n",
+ "nq=70/100 # Quantum\n",
+ "Ip=3 # current in uA\n",
+ "h=6.625*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "lamda=h*c/E*10**6 # wavelength in micro meter\n",
+ "print \"Photodiode operates at %0.2f micro meter\" %lamda\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "R=nq*q/E #computing responsivity\n",
+ "Popt=Ip/R\n",
+ "print \"Incident optical power required = %.3f uW.\" %Popt "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Photodiode operates at 1.10 micro meter\n",
+ "Incident optical power required = 4.821 uW.\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.6, page 7-25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "E=1.35 #energy gap in eV\n",
+ "lamda=h*c/(q*E) #computing wavelength\n",
+ "lamda=lamda*10**6 \n",
+ "print \"The InP photodetector will stop operation above %.2f micrometer.\" %(lamda) \n",
+ "#calculation error in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The InP photodetector will stop operation above 0.92 micrometer.\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.7, page 7-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "eta=65/100 #quantum efficiency\n",
+ "I=2.5*10**-6 #photocurrent \n",
+ "E=1.5*10**-19 #energy of photns\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "lamda=h*c/E #computing wavelength\n",
+ "R=eta*q*lamda/(h*c) #computing responsivity\n",
+ "Popt=I/R #computing optical power\n",
+ "lamda=lamda*10**6 \n",
+ "Popt=Popt*10**6 \n",
+ "print \"Wavelength is %.3f micrometer.\\nResponsivity is %.3f A/W.\\nIncident optical power required is %.1f microWatt.\" %(lamda,R,Popt) \n",
+ "#answer of R(responsivity) in the book is calculated as 0.694 A/W, deviation of 0.001."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavelength is 1.325 micrometer.\n",
+ "Responsivity is 0.693 A/W.\n",
+ "Incident optical power required is 3.6 microWatt.\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5.8, page 7-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ne=3.9*10**6 #electrons collected\n",
+ "np=6*10**6 #photons incident\n",
+ "eta=100*ne/np #computing efficiency\n",
+ "print \"Quantum efficiency is %d percent.\" %(eta) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quantum efficiency is 65 percent.\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8.1, page 7-37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "w=25*10**-6 #width\n",
+ "v=1*10**5 #velocity\n",
+ "r=40*10**-6 #radius\n",
+ "eps=12.5*10**-13 \n",
+ "t=w/v #computing drift time\n",
+ "c=eps*3.14*(r)**2/w #computing junction capacitance\n",
+ "c=c*10**16 \n",
+ "print \"Drift time %.1e sec.\\nJunction capacitance %.1f pf.\" %(t,c) \n",
+ "#calculation error in drift time answer."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Drift time 2.5e-10 sec.\n",
+ "Junction capacitance 2.5 pf.\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8.2, page 7-38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "w=20*10**-6 #width\n",
+ "v=4*10**4 #velocity\n",
+ "t=w/v #computing drift time\n",
+ "BW=(2*pi*t)**-1 #computing bandwidth\n",
+ "rt=1/BW #computing response time\n",
+ "rt=rt*10**9 \n",
+ "print \"Maximum response time is %.1f ns.\" %(rt)\n",
+ "#Calculation error in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum response time is 3.1 ns.\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9.1, page 7-43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=1.4*10**-6 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "I=10*10**-9 #current\n",
+ "NEP= h*c*sqrt(2*q*I)/(eta*q*lamda) \n",
+ "D=NEP**-1 \n",
+ "print \"Noise equivalent power is %.3e W.\\nSpecific directivity is %.2e.\" %(NEP,D) \n",
+ "#answers in the book for NEP & D is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Noise equivalent power is 7.723e-14 W.\n",
+ "Specific directivity is 1.29e+13.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9.2, page 7-44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=1300*10**-9 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=90/100 #quantum efficiency\n",
+ "P0=300*10**-9 #optical power\n",
+ "Id=4 #dark current\n",
+ "B=20*10**6 #bandwidth\n",
+ "K=1.39*10**-23 #Boltzman constant\n",
+ "T=298 #temperature\n",
+ "R=1000 #load resister\n",
+ "Ip= 10**9*eta*P0*q*lamda/(h*c) \n",
+ "Its=10**9*(2*q*B*(Ip+Id)) \n",
+ "Its=sqrt(Its) \n",
+ "print \"rms shot noise current is %.2f nA.\" %(Its) \n",
+ "It= 4*K*T*B/R \n",
+ "It=sqrt(It) \n",
+ "print \"Thermal noise is %.2e A.\" %(It) \n",
+ "#answer given in book for shot noise & Thermal noise are wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rms shot noise current is 1.35 nA.\n",
+ "Thermal noise is 1.82e-08 A.\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10.1, page 7-51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import floor\n",
+ "lamda=0.85*10**-6 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=75/100 #quantum efficiency\n",
+ "P0=0.6*10**-6 #incident optical power\n",
+ "Im=15*10**2 #avalanche gain\n",
+ "R= eta*q*lamda/(h*c) #computing responsivity\n",
+ "Ip=10**8*P0*R #computing photocurrent\n",
+ "Ip=floor(Ip) \n",
+ "M=Im/Ip #computing multiplication factor\n",
+ "print \"Multiplication factor is %d.\" %(M) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication factor is 50.\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10.2, page 7-51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "lamda=900*10**-9 # Wavelength in m\n",
+ "P0=0.5 # Optical power\n",
+ "Im=10 # Photocurrent\n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65.0/100 #quantum efficiency\n",
+ "R= eta*q*lamda/(h*c) #computing responsivity\n",
+ "Ip=P0*R #computing photocurrent \n",
+ "M=Im/Ip #computing multiplication factor\n",
+ "print \"Multiplication factor is %0.2f.\" %(M) \n",
+ "# Answer is wrong in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication factor is 42.47.\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10.3, page 7-52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=900*10**-9 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "P0=0.5*10**-6 #incident optical power\n",
+ "Im=10*10**2 #avalanche gain\n",
+ "R= eta*q*lamda/(h*c) #computing responsivity\n",
+ "Ip=10**8*P0*R #computing photocurrent\n",
+ "M=Im/Ip #computing multiplication factor\n",
+ "print \"Multiplication factor is %d.\" %(M) \n",
+ "#answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication factor is 42.\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10.3, page 7-52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=900*10**-9 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "P0=0.5*10**-6 #incident optical power\n",
+ "Im=10*10**2 #avalanche gain\n",
+ "R= eta*q*lamda/(h*c) #computong responsivity\n",
+ "Ip=10**8*P0*R #computing photocurrent\n",
+ "M=Im/Ip #computing multiplication factor\n",
+ "print \"Multiplication factor is %d.\" %M "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Multiplication factor is 42.\n"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communication_by_Anasuya_Kalavar/chapter8.ipynb b/Optical_Communication_by_Anasuya_Kalavar/chapter8.ipynb
new file mode 100755
index 00000000..11017e30
--- /dev/null
+++ b/Optical_Communication_by_Anasuya_Kalavar/chapter8.ipynb
@@ -0,0 +1,272 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3deb63e976713f6e36585549e6b144389b0fc28fe2982a2838d929f3804cde18"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter8 - Optical receiver operation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2.1, page 8-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import log, sqrt, pi, log10\n",
+ "P=10**-9 #probability of error\n",
+ "eta=1 #ideal detector\n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "lamda=1*10**-6 #wavelength\n",
+ "B=10**7 #bit rate\n",
+ "Mn = -log(P) \n",
+ "print \"The quantum limit at the receiver to maintain bit error rate 10**-9 is (%.1f*h*f)/eta.\" %Mn\n",
+ "f=c/lamda\n",
+ "Popt= 0.5*Mn*h*f*B/eta #computing optical power\n",
+ "Popt_dB = 10 * log10(Popt) + 30 #optical power in dbm\n",
+ "Popt=Popt*10**12 \n",
+ "print \"Minimum incident optical power is %.1f W or %.1f dBm.\" %(Popt,Popt_dB) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The quantum limit at the receiver to maintain bit error rate 10**-9 is (20.7*h*f)/eta.\n",
+ "Minimum incident optical power is 20.6 W or -76.9 dBm.\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2.2, page 8-8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "SN_dB=60 #signal to noise ratio\n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "lamda=1.3*10**-6 #wavelength\n",
+ "eta=1 \n",
+ "B=6.5*10**6 #Bandwidth\n",
+ "SN=10**(SN_dB/10) \n",
+ "f=c/lamda\n",
+ "Popt= 2*SN*h*f*B/eta #computing optical power\n",
+ "Popt_dB = 10 * log10(Popt) + 30 #optical power in dbm\n",
+ "Popt=Popt*10**6 \n",
+ "print \"Incident power required to get an SNR of 60 dB at the receiver is %.4f microWatt or %.3f dBm\" %(Popt,Popt_dB)\n",
+ "#Calculation error in the book.They have take SN as 10**5 while calculating, which has lead to an error in final answer\n",
+ "#answer in the book 198.1nW and -37.71 dBm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Incident power required to get an SNR of 60 dB at the receiver is 1.9878 microWatt or -27.016 dBm\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3.1, page 8-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=0.85*10**-6 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "P0=300*10**-9 #optical power\n",
+ "Id=3.5 #dark current\n",
+ "B=6.5*10**6 #bandwidth\n",
+ "K=1.39*10**-23 #Boltzman constant\n",
+ "T=293 #temperature\n",
+ "R=5*10**3 #load resister\n",
+ "Ip= 10**9*eta*P0*q*lamda/(h*c) \n",
+ "Its=10**9*(2*q*B*(Ip+Id)) \n",
+ "Its=sqrt(Its) \n",
+ "print \"rms shot noise current is %.2f nA.\" %(Its) \n",
+ "It= 4*K*T*B/R \n",
+ "It=sqrt(It) \n",
+ "It=It*10**9 \n",
+ "print \"Thermal noise is %.2f nA.\" %(It) \n",
+ "#answer given in book for Thermal noise is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rms shot noise current is 0.53 nA.\n",
+ "Thermal noise is 4.60 nA.\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3.2, page 8-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "lamda=0.85*10**-6 \n",
+ "h=6.626*10**-34 #plank's constant\n",
+ "c=3*10**8 #speed of light\n",
+ "q=1.6*10**-19 #charge of electron\n",
+ "eta=65/100 #quantum efficiency\n",
+ "P0=300*10**-9 #optical power\n",
+ "Id=3.5 #dark current\n",
+ "B=6.5*10**6 #bandwidth\n",
+ "K=1.39*10**-23 #Boltzman constant\n",
+ "T=293 #temperature\n",
+ "R=5*10**3 #load resister\n",
+ "F_dB=3 #noise figure\n",
+ "F=10**(F_dB/10) \n",
+ "Ip=10**9*eta*P0*q*lamda/(h*c) \n",
+ "Its=10**9*(2*q*B*(Ip+Id)) \n",
+ "It1= 4*K*T*B*F/R \n",
+ "SN= Ip**2/(Its+It1) \n",
+ "SN_dB=10*log10(SN) \n",
+ "SN=SN\n",
+ "print \"SNR is %.2e or %.2f dB.\" %(SN,SN_dB) \n",
+ "#answer given in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "SNR is 6.25e+04 or 47.96 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4.1, page 8-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Cd=7*10**-12 \n",
+ "B=9*10**6 \n",
+ "Ca=7*10**-12 \n",
+ "R=(2*3.14*Cd*B)**-1 \n",
+ "B1=(2*3.14*R*(Cd+Ca))**-1 \n",
+ "R=R/1000 \n",
+ "B1=B1/10**6 \n",
+ "print \"\"\"Thus for 9MHz bandwidth maximum load resistance is %.2f Kohm\n",
+ "Now if we consider input capacitance of following amplifier Ca then Bandwidth is %.2fMHz\n",
+ "Maximum post detection bandwidth is half.\"\"\"%(R,B1) \n",
+ "#answer for resistance in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Thus for 9MHz bandwidth maximum load resistance is 2.53 Kohm\n",
+ "Now if we consider input capacitance of following amplifier Ca then Bandwidth is 4.50MHz\n",
+ "Maximum post detection bandwidth is half.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Question 7, page 8.44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "w=25*10**-6 #width\n",
+ "v=3*10**4 #velocity\n",
+ "t=w/v #computing drift time\n",
+ "BW=(2*pi*t)**-1 #computing bandwidth\n",
+ "rt=1/BW #response time\n",
+ "rt=rt*10**9 \n",
+ "print \"Maximum response time is %.2f ns.\" %(rt) \n",
+ "#Answer in the book is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum response time is 5.24 ns.\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Optical_Communication_by_Anasuya_Kalavar/chapter9.ipynb b/Optical_Communication_by_Anasuya_Kalavar/chapter9.ipynb
new file mode 100755
index 00000000..ba8336a3
--- /dev/null
+++ b/Optical_Communication_by_Anasuya_Kalavar/chapter9.ipynb
@@ -0,0 +1,99 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c071b41323ac94460e204090d265021c7f2c7744a035dad84fc7193e1854e444"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter9 - Link design"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4.1, page 9-8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "output=13 #laser output\n",
+ "sensitivity=-31 #APD sensitivity\n",
+ "coupling_loss=0.5 \n",
+ "L=80 #length in km\n",
+ "sl=0.1 #loss correspond to one splice in dB\n",
+ "fl=0.35 #fiber loss in dB/km\n",
+ "noise=1.5 \n",
+ "allowed_loss=output-sensitivity \n",
+ "splices_loss=(L-1)*sl \n",
+ "fiber_loss=L*fl \n",
+ "margin=allowed_loss-(splices_loss+fiber_loss+coupling_loss+noise) \n",
+ "print \"Final margin is %.1f dB.\" %margin"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Final margin is 6.1 dB.\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6.1, page 9-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from numpy import sqrt\n",
+ "L=10 \n",
+ "ts=10 \n",
+ "tD=8 \n",
+ "tmod=L*6 \n",
+ "tt=L*2 \n",
+ "Tsys=1.1*sqrt(ts**2+tmod**2+tt**2+tD**2) \n",
+ "Bt=0.7/Tsys \n",
+ "Bt=Bt*10**3 \n",
+ "print \"Maximum bit rate for link using NRZ data format is %.2f Mbits/sec.\" %Bt \n",
+ "#calculation error in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum bit rate for link using NRZ data format is 9.86 Mbits/sec.\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Process_Heat_Transfer/screenshots/CH16.png b/Process_Heat_Transfer/screenshots/CH16.png
new file mode 100755
index 00000000..f7f42642
--- /dev/null
+++ b/Process_Heat_Transfer/screenshots/CH16.png
Binary files differ
diff --git a/Process_Heat_Transfer/screenshots/CH17.png b/Process_Heat_Transfer/screenshots/CH17.png
new file mode 100755
index 00000000..a8ae6e47
--- /dev/null
+++ b/Process_Heat_Transfer/screenshots/CH17.png
Binary files differ
diff --git a/Process_Heat_Transfer/screenshots/Ch15.png b/Process_Heat_Transfer/screenshots/Ch15.png
new file mode 100755
index 00000000..f96bf517
--- /dev/null
+++ b/Process_Heat_Transfer/screenshots/Ch15.png
Binary files differ
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_10_Stream_Line_Flow_and_Heat_Convection.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_10_Stream_Line_Flow_and_Heat_Convection.ipynb
new file mode 100755
index 00000000..d735fd25
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_10_Stream_Line_Flow_and_Heat_Convection.ipynb
@@ -0,0 +1,580 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 10 :Stream Line Flow and Heat Convection"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10.1 pgno:203"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 10.1 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for crude \t\n",
+ "\t total heat required for crude is : Btu/hr \t388000.0\n",
+ "\t for steam \t\n",
+ "\t total heat required for steam is : Btu/hr \t387655.0\n",
+ "\t delt1 is : F \t155.0\n",
+ "\t delt2 is : F \t105.0\n",
+ "\t LMTD is : F \t128.381317817\n",
+ "\t On the assumption that the fluids are mixed between passes each pass must be solved independently Since only two passes are present in this exchanger it is simply a matter of assuming the temp at the end of the first pass More than half the heat load must be transferred in the first pass therefore assume ti at the end of the first pass is 125 degres f \n",
+ "\n",
+ "\t caloric temperature of cold fluid is : F \t110.0\n",
+ "\t hot fluid:shell side,steam \t\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t1500\n",
+ "\t cold fluid:inner tube side,crude \t\n",
+ "\t flow area is : ft**2 \t0.177375\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t90395.480226\n",
+ "\t reynolds number is : \t918.009849613\n",
+ "\t reynolds number is : \t564.193553408\n",
+ "\t prandelt number is : \t72.6936774194\n",
+ "\t Hi is : Btu/(hr)*(ft**2)*(F) \t1.98827586207\n",
+ "\t phyt is : \t1.2141948844\n",
+ "\t Correct hi to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t2.41415438049\n",
+ "\t tp is : F \t249.775040982\n",
+ "\t delt is : F \t139.775040982\n",
+ "\t total surface area is : ft**2 \t117.6\n",
+ "\t delt3 is : F \t5.1\n",
+ "\t ti is : F \t100.1\n",
+ "The oil now enters the second pass at given 126.9 f\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 10.1 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "#given\n",
+ "T1=250.; # inlet hot fluid,F\n",
+ "T2=250.; # outlet hot fluid,F\n",
+ "t1=95.; # inlet cold fluid,F\n",
+ "t2=145.; # outlet cold fluid,F\n",
+ "W=16000.; # lb/hr\n",
+ "w=410.; # lb/hr\n",
+ "#solution\n",
+ "from math import log\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for crude \\t\"\n",
+ "c=0.485; # Btu/(lb)*(F)\n",
+ "Q=((W)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for crude is : Btu/hr \\t\",Q\n",
+ "print\"\\t for steam \\t\"\n",
+ "l=945.5; # Btu/(lb)\n",
+ "Q=((w)*(l)); # Btu/hr\n",
+ "print\"\\t total heat required for steam is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "\n",
+ "print\"\\t On the assumption that the fluids are mixed between passes each pass must be solved independently Since only two passes are present in this exchanger it is simply a matter of assuming the temp at the end of the first pass More than half the heat load must be transferred in the first pass therefore assume ti at the end of the first pass is 125 degres f \\n\"\n",
+ "ti=125; # F\n",
+ "tc=((t1)+(ti))/2; # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:shell side,steam \\t\"\n",
+ "ho=(1500); # condensation of steam Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t cold fluid:inner tube side,crude \\t\"\n",
+ "Nt=86;\n",
+ "n=2; # number of passes\n",
+ "L=12; #ft\n",
+ "at1=0.594; # flow area, in**2,from table 10\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(W/(.177)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu2=2.95*2.42; # at 145F,lb/(ft)*(hr)\n",
+ "D=(0.87/12); # ft\n",
+ "Ret1=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret1\n",
+ "mu3=4.8*2.42; # at 110F,lb/(ft)*(hr)\n",
+ "D=(0.87/12); # ft\n",
+ "Ret2=((D)*(Gt)/mu3); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret2\n",
+ "c=0.485; # Btu/(lb)*(F),at 120F,from fig.2\n",
+ "k=0.0775; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "Pr=((c)*(mu3)/k); # prandelt number\n",
+ "print\"\\t prandelt number is : \\t\",Pr\n",
+ "Hi=((1.86)*(k/D)*((Ret2*(D/L)*Pr)**(1/3))); # using eq.6.1,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t Hi is : Btu/(hr)*(ft**2)*(F) \\t\",Hi\n",
+ "muw=1.2*2.42; # lb/(ft)*(hr),at 249F from fig.14\n",
+ "phyt=(mu3/muw)**0.14;\n",
+ "print\"\\t phyt is : \\t\",phyt # from fig.24\n",
+ "hi=(Hi)*(phyt); # from eq.6.37\n",
+ "print\"\\t Correct hi to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "tp=(tc)+(((ho)/(hi+ho))*(T1-tc)); # from eq.5.31\n",
+ "print\"\\t tp is : F \\t\",tp\n",
+ "delt=tp-tc; #F\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "Ai1=0.228 # internal surface per foot of length,ft\n",
+ "Ai=(Nt*L*Ai1/2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",round(Ai,1)\n",
+ "delt3=((hi*Ai*delt)/(W*c)); # delt3=ti-t1, F\n",
+ "print\"\\t delt3 is : F \\t\",round(delt3,1)\n",
+ "ti=t1+delt3; # F\n",
+ "print\"\\t ti is : F \\t\",round(ti,1)\n",
+ "print\"The oil now enters the second pass at given 126.9 f\"\n",
+ "# end\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## EXAMPLE 10.2 pgno:207"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 10.2 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for kerosene \t\n",
+ "\t total heat required for kerosene is : Btu/hr \t400000.0\n",
+ "\t for steam \t\n",
+ "\t total heat required for steam is : Btu/hr \t399946.5\n",
+ "\t delt1 is : F \t155.0\n",
+ "\t delt2 is : F \t105.0\n",
+ "\t LMTD is : F \t128.525612445\n",
+ "\t caloric temperature of cold fluid is : F \t120.0\n",
+ "\t hot fluid:shell side,steam \t\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t1500\n",
+ "\t cold fluid:inner tube side,kerosene \t\n",
+ "\t flow area is : ft**2 \t0.177375\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t90395.480226\n",
+ "\t reynolds number is : \t1991.27136497\n",
+ "\t reynolds number is : \t1547.50231792\n",
+ "\t Hi is : Btu/(hr)*(ft**2)*(F) \t10.2620689655\n",
+ "\t Hio is : Btu/(hr)*(ft**2)*(F) \t8.928\n",
+ "\t tw is : F \t249.23081817\n",
+ "\t phyt is : \t1.16189787585\n",
+ "\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t10.3734242356\n",
+ "\t delt is : F \t129.23081817\n",
+ "\t Since the kerosene has a viscosity of only 1.75 cp at the caloric temperature and delt=129F, free convection should be investigated. \t\n",
+ "\t beta is : /F \t0.000449494949495\n",
+ "\t G is : \t1289776.29615\n",
+ "\t psy is : \t0.712464789946\n",
+ "\t corrected hio1 is : Btu/(hr)*(ft**2)*(F) \t7.39069951902\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t14.7\n",
+ "\t total surface area is : ft**2 \t270.1776\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t11.5\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t-0.0079\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 10.2 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "#gien\n",
+ "T1=250.; # inlet hot fluid,F\n",
+ "T2=250.; # outlet hot fluid,F\n",
+ "t1=95.; # inlet cold fluid,F\n",
+ "t2=145.; # outlet cold fluid,F\n",
+ "W=16000.; # lb/hr\n",
+ "w=423.; # lb/hr\n",
+ "#solution\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for kerosene \\t\"\n",
+ "c=0.5; # Btu/(lb)*(F)\n",
+ "Q=((W)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for kerosene is : Btu/hr \\t\",Q\n",
+ "print\"\\t for steam \\t\"\n",
+ "l=945.5; # Btu/(lb)\n",
+ "Q=((w)*(l)); # Btu/hr\n",
+ "print\"\\t total heat required for steam is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "tc=((t1)+(t2))/2; # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:shell side,steam \\t\"\n",
+ "ho=(1500); # condensation of steam Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t cold fluid:inner tube side,kerosene \\t\"\n",
+ "Nt=86;\n",
+ "n=2; # number of passes\n",
+ "L=12; #ft\n",
+ "at1=0.594; # flow area, in**2,from table 10\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(W/(.177)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu2=1.36*2.42; # at 145F,lb/(ft)*(hr)\n",
+ "D=(0.87/12); # ft\n",
+ "Ret1=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret1\n",
+ "mu3=1.75*2.42; # at 120F,lb/(ft)*(hr)\n",
+ "D=(0.87/12); # ft\n",
+ "Ret2=((D)*(Gt)/mu3); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret2\n",
+ "Z1=331; # Z1=(L*n/D)\n",
+ "jH=3.1; # from fig 24\n",
+ "mu4=1.75; # cp and 40 API\n",
+ "Z2=0.24; # Z2=((k)*(c*mu4/k)**(1/3)), from fig 16\n",
+ "Hi=((jH)*(1/D)*(Z2)); # using eq.6.15a,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t Hi is : Btu/(hr)*(ft**2)*(F) \\t\",Hi\n",
+ "ID=0.87; # ft\n",
+ "OD=1; #ft\n",
+ "Hio=(Hi*(ID/OD)); #Btu/(hr)*(ft**2)*(F), from eq.6.5\n",
+ "print\"\\t Hio is : Btu/(hr)*(ft**2)*(F) \\t\",Hio\n",
+ "tw=(tc)+(((ho)/(Hio+ho))*(T1-tc)); # from eq.5.31\n",
+ "print\"\\t tw is : F \\t\",tw\n",
+ "muw=1.45; # lb/(ft)*(hr),at 249F from fig.14\n",
+ "phyt=(mu3/muw)**0.14;\n",
+ "print\"\\t phyt is : \\t\",phyt # from fig.24\n",
+ "hio=(Hio)*(phyt); # from eq.6.37\n",
+ "print\"\\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "delt=tw-tc; #F\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "print\"\\t Since the kerosene has a viscosity of only 1.75 cp at the caloric temperature and delt=129F, free convection should be investigated. \\t\"\n",
+ "s=0.8;\n",
+ "row=50; # lb/ft**3, from fig 6\n",
+ "s1=0.810; # at 95F\n",
+ "s2=0.792; # at 145F\n",
+ "bita=((s1**2-s2**2)/(2*(t2-t1)*s1*s2)); # /F\n",
+ "print\"\\t beta is : /F \\t\",bita\n",
+ "G=((D**3)*(row**2)*(bita)*(delt)*(4.18*10**8)/(mu3**2));\n",
+ "print\"\\t G is : \\t\",G\n",
+ "psy=((2.25)*(1+(0.01*G**(1/3)))/(log10(Ret2)));\n",
+ "print\"\\t psy is : \\t\",psy\n",
+ "hio1=(hio*psy);\n",
+ "print\"\\t corrected hio1 is : Btu/(hr)*(ft**2)*(F) \\t\",hio1\n",
+ "Uc=2*((hio1)*(ho)/(hio1+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",round(Uc,1)\n",
+ "A2=0.2618; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",round(UD,1)\n",
+ "Rd=-0.407*((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",round(Rd,4)\n",
+ "# end\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10.3 pgno:211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 10.3 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for gas oil \t\n",
+ "\t total heat required for gas oil is : Btu/hr \t587500.0\n",
+ "\t for steam \t\n",
+ "\t total heat required for steam is : Btu/hr \t588101.0\n",
+ "\t delt1 is : F \t145.0\n",
+ "\t delt2 is : F \t120.0\n",
+ "\t LMTD is : F \t132.254461931\n",
+ "\t caloric temperature of cold fluid is : %.1f F \t117.5\n",
+ "\t hot fluid:shell side,steam \t\n",
+ "\t flow area is : ft**2 \t0.317708333333\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t19577.704918\n",
+ "\t reynolds number is : \t37409.6272319\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t1500\n",
+ "\t cold fluid:inner tube side,crude oil \t\n",
+ "\t at1 is : in**2 \t0.3979165\n",
+ "\t flow area is : ft**2 \t0.118822288194\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t420796.474801\n",
+ "\t De is : ft \t0.0485536398467\n",
+ "\t reynolds number is : \t1223.42517882\n",
+ "\t Hi is : Btu/(hr)*(ft**2)*(F) \t22.3464194121\n",
+ "\t Correct Hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t19.4413848885\n",
+ "\t phyt is : \t1.18932885404\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t23.1222000104\n",
+ "\t tw is : F \t247.988545173\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t22.7711867211\n",
+ "\t total surface area is : ft**2 \t270\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t16.4694016372\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.0168035136331\n",
+ "\t pressure drop for annulus \t\n",
+ "\t number of crosses are : \t9\n",
+ "\t delPs is : psi \t1.19559186672\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t dt is : ft \t0.0308333333333\n",
+ "\t Ret2 is : \t776.919639103\n",
+ "\t phyt is : \t1.35\n",
+ "\t delPt is : psi \t2.0\n",
+ "\t delPr is negligible \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 10.3 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "#given\n",
+ "T1=250.; # inlet hot fluid,F\n",
+ "T2=250.; # outlet hot fluid,F\n",
+ "t1=105.; # inlet cold fluid,F\n",
+ "t2=130.; # outlet cold fluid,F\n",
+ "w=50000.; # lb/hr\n",
+ "W=622.; # lb/hr\n",
+ "#solution\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for gas oil \\t\"\n",
+ "c=0.47; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for gas oil is : Btu/hr \\t\",Q\n",
+ "print\"\\t for steam \\t\"\n",
+ "l=945.5; # Btu/(lb)\n",
+ "Q=((W)*(l)); # Btu/hr\n",
+ "print\"\\t total heat required for steam is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "tc=((t1)+(t2))/2; # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : %.1f F \\t\",tc\n",
+ "print\"\\t hot fluid:shell side,steam \\t\"\n",
+ "ID=15.25; # in\n",
+ "C=0.25; # clearance\n",
+ "B=15; # baffle spacing,in\n",
+ "PT=1.25;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,ft**2, eq 7.1\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(6220/As); # mass velocity,lb/(hr)*(ft**2), calculation mistake\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=0.0314; # at 250F,lb/(ft)*(hr), from fig.15\n",
+ "De=0.060; # from fig.29,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number, calculation mistake\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "ho=1500; #Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t cold fluid:inner tube side,crude oil \\t\"\n",
+ "d1=0.5; # in\n",
+ "d2=0.87; # in\n",
+ "at1=((3.14*(d2**2-d1**2))/4);\n",
+ "print\"\\t at1 is : in**2 \\t\",at1\n",
+ "Nt=86;\n",
+ "n=2; # number of passes\n",
+ "L=12; #ft\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "De=(d2**2-d1**2)/(12*d2);\n",
+ "print\"\\t De is : ft \\t\",De\n",
+ "mu2=16.7; # at 117F,lb/(ft)*(hr)\n",
+ "Ret=((De)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "jH=3.1; # from fig.24\n",
+ "Z=0.35; # Z=(K*(c*mu3/k)**(1/3)),Btu/(hr)(ft**2)(F/ft), at mu3=6.9cp and 28 API\n",
+ "Hi=((jH)*(1/De)*(Z)); #Hi=(hi/phyp),using eq.6.15a,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t Hi is : Btu/(hr)*(ft**2)*(F) \\t\",Hi\n",
+ "ID=0.87; # ft\n",
+ "OD=1; #ft\n",
+ "Hio=((Hi)*(ID/OD)); #Hio=(hio/phyp), using eq.6.5\n",
+ "print\"\\t Correct Hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",Hio\n",
+ "muw=4.84; # lb/(ft)*(hr), from fig.14\n",
+ "phyt=(mu2/muw)**0.14;\n",
+ "print\"\\t phyt is : \\t\",phyt # from fig.24\n",
+ "hio=(Hio)*(phyt); # from eq.6.37\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "tw=(tc)+(((ho)/(hio+ho))*(T1-tc)); # from eq.5.31\n",
+ "print\"\\t tw is : F \\t\",tw\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "A=270; # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A\n",
+ "UD=((Q)/((A)*(LMTD)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "f=0.0016; # friction factor for reynolds number 25300, using fig.29\n",
+ "s=0.00116; # for reynolds number 25300,using fig.6\n",
+ "Ds=15.25/12; # ft\n",
+ "phys=1;\n",
+ "N=(12*L/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "delPs=((f*(19600**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys)))/(2); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",delPs\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "dt=(d2-d1)/(12); # ft\n",
+ "print\"\\t dt is : ft \\t\",dt\n",
+ "Ret2=(dt*Gt/mu2);\n",
+ "print\"\\t Ret2 is : \\t\",Ret2\n",
+ "f=0.00066; # friction factor for reynolds number 8220, using fig.26\n",
+ "phyt=1.35; # fig 6\n",
+ "print\"\\t phyt is : \\t\",phyt\n",
+ "s=0.85;\n",
+ "delPt=((f*(420000**2)*(L)*(n))/(5.22*(10**10)*(0.0309)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt)\n",
+ "print\"\\t delPr is negligible \\t\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 10.4 pgno:217"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 10.4 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t delt is : F \t100\n",
+ "\t convection loss is : Btu/(hr)(ft**2)(F) \t0.948683298051\n",
+ "\t radiation loss is : Btu/(hr)(ft**2)(F) \t0.510696\n",
+ "\t combined loss is : Btu/(hr)(ft**2)(F) \t1.45937929805\n",
+ "\t total tank area is : ft**2 \t227.65\n",
+ "\t total heat loss : Btu/hr \t33222.7697201\n",
+ "\t This heat must be supplied by the pipe bundle,Assuming exhaust steam to be at 212 degree F \t\n",
+ "\t X is : \t75.7575757576\n",
+ "\t tf is : F \t156\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t46\n",
+ "\t design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t23.9583333333\n",
+ "\t total surface is : ft**2 \t12.3811564174\n",
+ "\t number of pipes are : \t7.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 10.4 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "#given\n",
+ "t1=100; # F\n",
+ "t2=0; # F\n",
+ "T1abs=100+460; # R\n",
+ "T2abs=460; #R\n",
+ "#solution\n",
+ "delt=t1-t2;\n",
+ "from math import ceil\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "hc=0.3*(delt**0.25); # convection loss, Btu/(hr)*(ft**2)*( degree F)\n",
+ "print\"\\t convection loss is : Btu/(hr)(ft**2)(F) \\t\",hc\n",
+ "e=0.8; # emissivity\n",
+ "hr=((0.173*e*((T1abs/100)**4-(T2abs/100)**4))/(T1abs-T2abs)); # radiation rate, from 4.32, Btu/(hr)(ft**2)(F)\n",
+ "print\"\\t radiation loss is : Btu/(hr)(ft**2)(F) \\t\",hr\n",
+ "hl=hc+hr; # combined loss, Btu/(hr)(ft**2)(F)\n",
+ "print\"\\t combined loss is : Btu/(hr)(ft**2)(F) \\t\",hl\n",
+ "D=5; # ft\n",
+ "L=12; # ft\n",
+ "A1=((2*3.14*D**2)/(4))+(3.14*D*L); # total tank area\n",
+ "print\"\\t total tank area is : ft**2 \\t\",A1\n",
+ "Q=(hl*A1*delt); # total heat loss\n",
+ "print\"\\t total heat loss : Btu/hr \\t\",Q\n",
+ "print\"\\t This heat must be supplied by the pipe bundle,Assuming exhaust steam to be at 212 degree F \\t\"\n",
+ "d0=1.32;\n",
+ "X=(delt/d0);\n",
+ "tf=((t1+212)/2); # F\n",
+ "print\"\\t X is : \\t\",X\n",
+ "print\"\\t tf is : F \\t\",tf\n",
+ "hio=48; # from fig 10.4, Btu/(hr)(ft**2)(F)\n",
+ "ho=1500; # condensation of steam,Btu/(hr)(ft**2)(F)\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Rd=0.02; # dirt factor, (hr)(ft**2)(F)/Btu\n",
+ "UD=((Uc)/((1)+(Uc*Rd))); # design overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "A2=((Q)/((UD)*(212-100))); # total surface,ft**2\n",
+ "print\"\\t total surface is : ft**2 \\t\",A2\n",
+ "A3=2.06; # area/pipe\n",
+ "N=(A2/A3);\n",
+ "print\"\\t number of pipes are : \\t\",ceil(N)\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_11_Caluculations_for_Process_Heat_Conditions.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_11_Caluculations_for_Process_Heat_Conditions.ipynb
new file mode 100755
index 00000000..bc4e7d41
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_11_Caluculations_for_Process_Heat_Conditions.ipynb
@@ -0,0 +1,1071 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 11 Caluculations for Process Heat Conditions"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example11.1 pgno:231"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 11.1 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for straw oil \t\n",
+ "\t total heat required for straw oil is : Btu/hr \t1728400.0\n",
+ "\t for naphtha \t\n",
+ "\t total heat required for naphtha is : Btu/hr \t1730400.0\n",
+ "\t delt1 is : F \t40.0\n",
+ "\t delt2 is : F \t110.0\n",
+ "\t LMTD is F \t69.2750233163\n",
+ "\t R is : \t3.33333333333\n",
+ "\t S is : \t0.214285714286\n",
+ "\t FT is 0.885 \t\n",
+ "\t delt is : F \t61.3083956349\n",
+ "\t ratio of two local temperature difference is : \t0.363636363636\n",
+ "\t caloric temperature of hot fluid is : F \t280.5\n",
+ "\t caloric temperature of cold fluid is : F \t212.15\n",
+ "\t A1 is : ft**2 \t403.207419539\n",
+ "\t number of tubes are :\t128.37729863\n",
+ "\t total surface area is : ft**2 \t389.4592\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t72.4710556785\n",
+ "\t hot fluid:shell side,straw oil \t\n",
+ "\t flow area is : ft**2 \t0.0926649305556\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t321588.758782\n",
+ "\t reynolds number is : \t7013.52894497\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t130.155789474\n",
+ "\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t130.155789474\n",
+ "\t cold fluid:inner tube side,naphtha \t\n",
+ "\t flow area is : ft**2 \t0.130027777778\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t792138.431959\n",
+ "\t reynolds number is : \t31262.2572002\n",
+ "\t Hi is : Btu/(hr)*(ft**2)*(F) \t329.477756286\n",
+ "\t Correct Hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t272.36827853\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t272.36827853\n",
+ "\t pressure drop for annulus \t\n",
+ "\t number of crosses are : \t54.8571428571\n",
+ "\t delPs is : psi \t5.1651098751\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t2.06675311157\n",
+ "\t clean overall coefficient is : %.1f Btu/(hr)*(ft**2)*(F) \t88.0700339124\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.00244401237634\n",
+ "\t The first trial is disqualified because of failure to meet the required dirt factor \t\n",
+ "\t Proceeding as above and carrying the viscosity correction and pressure drops to completion the new summary is given using a 17.25in. ID shell with 166 tubes on two passes and a 3.5in. baffle space \t\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t74.8\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t54.2\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.005\n",
+ "\t delPs is : psi \t4.7\n",
+ "\t delPt is : psi \t2.1\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 11.1 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=340.; # inlet hot fluid,F\n",
+ "T2=240.; # outlet hot fluid,F\n",
+ "t1=200.; # inlet cold fluid,F\n",
+ "t2=230.; # outlet cold fluid,F\n",
+ "W=29800; # lb/hr\n",
+ "w=103000; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for straw oil \\t\"\n",
+ "c=0.58; # Btu/(lb)*(F)\n",
+ "Q=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for straw oil is : Btu/hr \\t\",Q\n",
+ "print\"\\t for naphtha \\t\"\n",
+ "c=0.56; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for naphtha is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt1=40.;\n",
+ "delt2=T1-t2; # F\n",
+ "delt2=110.\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is F \\t\",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \\t\",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \\t\",S\n",
+ "print\"\\t FT is 0.885 \\t\" # from fig 18\n",
+ "delt=(0.885*LMTD); # F\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "X=((delt1)/(delt2));\n",
+ "print\"\\t ratio of two local temperature difference is : \\t\",X\n",
+ "L=16;\n",
+ "Fc=0.405; # from fig.17\n",
+ "Kc=0.23; # crude oil controlling\n",
+ "Tc=((T2)+((Fc)*(T1-T2))); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+((Fc)*(t2-t1))); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "UD1=70; # assume, from table 8a\n",
+ "A1=((Q)/((UD1)*(delt)));\n",
+ "print\"\\t A1 is : ft**2 \\t\",A1\n",
+ "a1=0.1963; # ft**2/lin ft\n",
+ "N1=(A1/(16*a1));\n",
+ "print\"\\t number of tubes are :\\t\",N1\n",
+ "N2=124; # assuming two tube passes, from table 9\n",
+ "A2=(N2*L*a1); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A2\n",
+ "UD=((Q)/((A2)*(delt)));\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "print\"\\t hot fluid:shell side,straw oil \\t\"\n",
+ "ID=15.25; # in\n",
+ "C=0.25; # clearance\n",
+ "B=3.5; # minimum baffle spacing,from eq 11.4,in\n",
+ "PT=1;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,from eq 7.1,ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(W/As); # mass velocity,from eq 7.2,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=3.63; # at 280.5F,lb/(ft)*(hr), from fig.14\n",
+ "De=0.95/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jH=46; # from fig.28\n",
+ "Z=0.224; # Z=(K*(c*mu3/k)**(1/3)),Btu/(hr)(ft**2)(F/ft), at mu3=1.5cp and 35 API\n",
+ "Ho=((jH)*(1/De)*(Z)); # H0=(h0/phya),using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Ho\n",
+ "phys=1;\n",
+ "ho=(Ho)*(phys); # from eq.6.36\n",
+ "print\"\\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t cold fluid:inner tube side,naphtha \\t\"\n",
+ "Nt=124;\n",
+ "n=2; # number of passes\n",
+ "L=16; #ft\n",
+ "at1=0.302; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu2=1.31; # at 212F,lb/(ft)*(hr)\n",
+ "D=0.0517; # ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "jH=102; # from fig.24\n",
+ "Z=0.167; # Z=(K*(c*mu3/k)**(1/3)),Btu/(hr)(ft**2)(F/ft), at mu4=0.54cp and 48 API\n",
+ "Hi=((jH)*(1/D)*(Z)); #Hi=(hi/phyp),using eq.6.15a,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t Hi is : Btu/(hr)*(ft**2)*(F) \\t\",Hi\n",
+ "ID=0.62; # ft\n",
+ "OD=0.75; #ft\n",
+ "Hio=((Hi)*(ID/OD)); #Hio=(hio/phyp), using eq.6.5\n",
+ "print\"\\t Correct Hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",Hio\n",
+ "phyt=1;\n",
+ "hio=(Hio)*(phyt); # from eq.6.37\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "f=0.00225; # friction factor for reynolds number 7000, using fig.29\n",
+ "s=0.76; # for reynolds number 7000,using fig.6\n",
+ "Ds=15.25/12; # ft\n",
+ "N=(12*L/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",delPs\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.0002; # friction factor for reynolds number 31300, using fig.26\n",
+ "s=0.72;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",delPt\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : %.1f Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t The first trial is disqualified because of failure to meet the required dirt factor \\t\"\n",
+ "print\"\\t Proceeding as above and carrying the viscosity correction and pressure drops to completion the new summary is given using a 17.25in. ID shell with 166 tubes on two passes and a 3.5in. baffle space \\t\"\n",
+ "UD1=60; # assumption for 2 tube passes,3.5 baffle spacing and 17.25in ID\n",
+ "UC1=74.8;\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UC1\n",
+ "UD2=54.2;\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD2\n",
+ "Rd1=0.005; \n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd1\n",
+ "delPs1=4.7;\n",
+ "print\"\\t delPs is : psi \\t\",delPs1\n",
+ "delPt1=2.1;\n",
+ "print\"\\t delPt is : psi \\t\",delPt1\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11.2 pgno:235"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 11.2 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for lean oil \t\n",
+ "\t total heat required for lean oil is : Btu/hr \t8984203.2\n",
+ "\t for rich oil \t\n",
+ "\t total heat required for rich oil is : Btu/hr \t8924995.95\n",
+ "\t Q is : V \t8954599.575\n",
+ "\t delt1 is : F \t60.0\n",
+ "\t delt2 is : F \t55.0\n",
+ "\t LMTD is : F \t57.5283364148\n",
+ "\t R is : \t0.974358974359\n",
+ "\t S is : \t0.78\n",
+ "\t FT is 0.875 \t\n",
+ "\t delt is : F \t50.337294363\n",
+ "\t ratio of two local temperature difference is : \t1.09090909091\n",
+ "\t caloric temperature of hot fluid is : F \t251.2\n",
+ "\t caloric temperature of cold fluid is : \t193.6\n",
+ "\t A1 is : ft**2 \t3557.83904889\n",
+ "\t number of tubes are : \t566.390577064\n",
+ "\t total surface area is : ft**2 \t3643.328\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t48.8267738849\n",
+ "\t hot fluid:inner tube side,lean oil \t\n",
+ "\t flow area is : ft**2 \t0.202731481481\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t416501.667047\n",
+ "\t reynolds number is : \t10109.4536086\n",
+ "\t Hi is : Btu/(hr)*(ft**2)*(F) \t130.609284333\n",
+ "\t Correct Hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t107.970341715\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t107.970341715\n",
+ "\t cold fluid:shell side,rich oil \t\n",
+ "\t flow area is : ft**2 \t0.322916666667\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t267428.129032\n",
+ "\t reynolds number is : \t6721.07731695\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t121.073684211\n",
+ "\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t121.073684211\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t4.32759598913\n",
+ "\t delPr is : psi \t1.4961038961\n",
+ "\t delPT is : psi \t5.82369988524\n",
+ "\t allowable delPT is 10 psi \t\n",
+ "\t pressure drop for annulus \t\n",
+ "\t number of crosses are : \t64\n",
+ "\t delPs is : psi \t6.44657740525\n",
+ "\t allowable delPa is 10 psi \t\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t57.073599733\n",
+ "\t actual Rd is : %.4f (hr)*(ft**2)*(F)/Btu \t0.00295933089476\n",
+ "\t The initial assumptions have provided an exchanger which very nearly meets all the requirements. Eight-pass units would meet the heat-transfer requirement but would give a tube-side pressure drop of 14 psi. The trial exchanger will be somewhat less suitable when the value of Q, is also taken into account. If the minimum dirt factor of 0.0040 is to be taken literally, it will be necessary to try the next size shell \t\n",
+ "\t Assume a 33 in. ID shell with six1 tube passes and baffies spaced 12-in. apart, since the pressure drop increases with the diameter of the shell for a given mass velocity. \t\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t52.3\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t42\n",
+ "\t calculated Rd is : (hr)*(ft**2)*(F)/Btu \t0.0047\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.004\n",
+ "\t delPs is : psi \t4.4\n",
+ "\t delPt is : psi \t7.9\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 11.2 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\" \n",
+ "T1=350.; # inlet hot fluid,F\n",
+ "T2=160.; # outlet hot fluid,F\n",
+ "t1=100.; # inlet cold fluid,F\n",
+ "t2=295.; # outlet cold fluid,F\n",
+ "W=84438; # lb/hr\n",
+ "w=86357; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for lean oil \\t\"\n",
+ "c=0.56; # Btu/(lb)*(F)\n",
+ "Qh=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for lean oil is : Btu/hr \\t\",Qh\n",
+ "print\"\\t for rich oil \\t\"\n",
+ "c=0.53; # Btu/(lb)*(F)\n",
+ "Qc=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for rich oil is : Btu/hr \\t\",Qc\n",
+ "Q=(Qh+Qc)/(2);\n",
+ "print\"\\t Q is : V \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \\t\",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \\t\",S\n",
+ "print\"\\t FT is 0.875 \\t\"# for 4-8 exchanger,from fig 21\n",
+ "delt=(0.875*LMTD); # F\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "X=((delt1)/(delt2));\n",
+ "print\"\\t ratio of two local temperature difference is : \\t\",X\n",
+ "Fc=0.48; # from fig.17\n",
+ "Kc=0.32; # crude oil controlling\n",
+ "Tc=((T2)+((Fc)*(T1-T2))); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+((Fc)*(t2-t1))); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : \\t\",tc\n",
+ "UD1=50; # assume, from table 8a\n",
+ "A1=((Q)/((UD1)*(delt)));\n",
+ "print\"\\t A1 is : ft**2 \\t\",A1\n",
+ "a1=0.1963; # ft**2/lin ft\n",
+ "N1=(A1/(16*a1*2)); # 2-4 exchanger in series\n",
+ "print\"\\t number of tubes are : \\t\",N1\n",
+ "N2=580; # assuming six tube passes,31in ID, from table 9\n",
+ "A2=(N2*16*a1*2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A2\n",
+ "UD=((Q)/((A2)*(delt)));\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "print\"\\t hot fluid:inner tube side,lean oil \\t\"\n",
+ "Nt=580;\n",
+ "n=6; # number of passes\n",
+ "L=16; #ft\n",
+ "at1=0.302; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(W/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu2=2.13; # at 212F,lb/(ft)*(hr)\n",
+ "D=0.0517; # ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "jH=36.5; # from fig.24\n",
+ "Z=0.185; # Z=(K*(c*mu3/k)**(1/3)),Btu/(hr)(ft**2)(F/ft), at mu4=0.88cp and 35 API\n",
+ "Hi=((jH)*(1/D)*(Z)); #Hi=(hi/phyp),using eq.6.15a,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t Hi is : Btu/(hr)*(ft**2)*(F) \\t\",Hi\n",
+ "ID=0.62; # ft\n",
+ "OD=0.75; #ft\n",
+ "Hio=((Hi)*(ID/OD)); #Hio=(hio/phyp), using eq.6.5\n",
+ "print\"\\t Correct Hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",Hio\n",
+ "phyt=1;\n",
+ "hio=(Hio)*(phyt); # from eq.6.37\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "print\"\\t cold fluid:shell side,rich oil \\t\"\n",
+ "ID=31; # in\n",
+ "C=0.25; # clearance\n",
+ "B=12; # minimum baffle spacing,from eq 11.4,in\n",
+ "PT=1;\n",
+ "As=((ID*C*B)/(144*PT))/(2); # flow area,from eq 7.1,ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(w/As); # mass velocity,from eq 7.2,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=3.15; # at 193.5F,lb/(ft)*(hr), from fig.14\n",
+ "De=0.95/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jH=45; # from fig.28\n",
+ "Z=0.213; # Z=(K*(c*mu3/k)**(1/3)),Btu/(hr)(ft**2)(F/ft), at mu3=1.3cp and 35 API\n",
+ "Ho=((jH)*(1/De)*(Z)); # H0=(h0/phya),using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Ho\n",
+ "phys=1;\n",
+ "ho=(Ho)*(phys); # from eq.6.36\n",
+ "print\"\\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.00027; # friction factor for reynolds number 10100, using fig.26\n",
+ "s=0.77;\n",
+ "delPt=((2*f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",delPt\n",
+ "X1=0.024; # X1=((V**2)/(2*g)), for Gt 1060000,using fig.27\n",
+ "delPr=((4*2*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \\t\",delPr\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \\t\",delPT\n",
+ "print\"\\t allowable delPT is 10 psi \\t\"\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "f=0.0023; # friction factor for reynolds number 6720, using fig.29\n",
+ "s=0.79; # for reynolds number 6720,using fig.6\n",
+ "Ds=31/12; # ft\n",
+ "De=0.0792;\n",
+ "N=(4*12*L/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",delPs\n",
+ "print\"\\t allowable delPa is 10 psi \\t\"\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : %.4f (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t The initial assumptions have provided an exchanger which very nearly meets all the requirements. Eight-pass units would meet the heat-transfer requirement but would give a tube-side pressure drop of 14 psi. The trial exchanger will be somewhat less suitable when the value of Q, is also taken into account. If the minimum dirt factor of 0.0040 is to be taken literally, it will be necessary to try the next size shell \\t\"\n",
+ "print\"\\t Assume a 33 in. ID shell with six1 tube passes and baffies spaced 12-in. apart, since the pressure drop increases with the diameter of the shell for a given mass velocity. \\t\"\n",
+ "UC1=52.3;\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UC1\n",
+ "UD2=42;\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD2\n",
+ "Rd1=0.0047; \n",
+ "print\"\\t calculated Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd1\n",
+ "Rd2=0.004; \n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd2\n",
+ "delPs1=4.4;\n",
+ "print\"\\t delPs is : psi \\t\",delPs1\n",
+ "delPT1=7.9;\n",
+ "print\"\\t delPt is : psi \\t\",delPT1\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11.3 pgno:238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 11.3 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for caustic \t\n",
+ "\t total heat required for caustic is : Btu/hr \t6160000.0\n",
+ "\t for water \t\n",
+ "\t total heat required for water is : Btu/hr \t6160000.0\n",
+ "\t delt1 is : F \t40.0\n",
+ "\t delt2 is : F \t70.0\n",
+ "\t LMTD is : F \t53.6684619193\n",
+ "\t R is : \t1.75\n",
+ "\t S is : \t0.363636363636\n",
+ "\t FT is 0.815 \t\n",
+ "\t delt is : F \t43.7397964643\n",
+ "\t caloric temperature of hot fluid is : F \t155.0\n",
+ "\t caloric temperature of cold fluid is : \t100.0\n",
+ "\t A1 is : ft**2 \t563.331382215\n",
+ "\t number of tubes are : \t134.485146633\n",
+ "\t total surface area is : ft**2 \t586.432\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t240.152047558\n",
+ "\t hot fluid:shell side,caustic \t\n",
+ "\t flow area is : ft**2 \t0.187152777778\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t534322.820037\n",
+ "\t reynolds number is : \t17423.5702186\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t718.75\n",
+ "\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t718.75\n",
+ "\t cold fluid:inner tube side,water \t\n",
+ "\t flow area is : ft**2 \t0.132708333333\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t1160439.56044\n",
+ "\t V is fps \t5.15750915751\n",
+ "\t reynolds number is : \t46350.8904888\n",
+ "\t Hi is : Btu/(hr)*(ft**2)*(F) \t1165.6\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t972.1104\n",
+ "\t pressure drop for annulus \t\n",
+ "\t number of crosses are : %.0f \t28\n",
+ "\t delPs is : psi \t6.97705175383\n",
+ "\t allowable delPa is 10 psi \t\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t4.27604456957\n",
+ "\t delPr is : psi \t2.88\n",
+ "\t delPT is : psi \t7.15604456957\n",
+ "\t allowable delPa is 10 psi \t\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t413.224149078\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.00174403453004\n",
+ "\t Adjustment of the baffie space to use the full 10 psi will still not permit the exchanger to make the 0.002 dirt factor. The value of UD has been assumed too high \t\n",
+ "\t Try a 21.25 in ID shell with four tube passes and a 6 in baffie space This corresponds to 170 tubes \t\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t39\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t200\n",
+ "\t calculated Rd is : (hr)*(ft**2)*(F)/Btu \t0.0024\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.002\n",
+ "\t delPs is : psi \t9.8\n",
+ "\t delPt is : psi \t4.9\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 11.3 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=190.; # inlet hot fluid,F\n",
+ "T2=120.; # outlet hot fluid,F\n",
+ "t1=80.; # inlet cold fluid,F\n",
+ "t2=120.; # outlet cold fluid,F\n",
+ "W=100000; # lb/hr\n",
+ "w=154000; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for caustic \\t\"\n",
+ "c=0.88; # Btu/(lb)*(F)\n",
+ "Q=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for caustic is : Btu/hr \\t\",Q\n",
+ "print\"\\t for water \\t\"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \\t\",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \\t\",S\n",
+ "print\"\\t FT is 0.815 \\t\" # for 4-8 exchanger,from fig 21\n",
+ "delt=(0.815*LMTD); # F\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "Tc=((T2)+(T1))/(2); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2))/(2); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : \\t\",tc\n",
+ "UD1=250; # assume, from table 8\n",
+ "A1=((Q)/((UD1)*(delt)));\n",
+ "print\"\\t A1 is : ft**2 \\t\",A1\n",
+ "a1=0.2618; # ft**2/lin ft\n",
+ "L=16;\n",
+ "N1=(A1/(16*a1));\n",
+ "print\"\\t number of tubes are : \\t\",N1\n",
+ "N2=140; # assuming four tube passes,19.25in ID, from table 9\n",
+ "A2=(N2*L*a1); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A2\n",
+ "UD=((Q)/((A2)*(delt)));\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "print\"\\t hot fluid:shell side,caustic \\t\"\n",
+ "ID=19.25; # in\n",
+ "C=0.25; # clearance\n",
+ "B=7; # minimum baffle spacing,from eq 11.4,in\n",
+ "PT=1.25;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,from eq 7.1,ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(W/As); # mass velocity,from eq 7.2,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=1.84; # at 155F,lb/(ft)*(hr), from fig.14\n",
+ "De=0.72/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jH=75; # from fig.28\n",
+ "Z=0.575; # Z=(K*(c*mu3/k)**(1/3)),Btu/(hr)(ft**2)(F/ft)\n",
+ "Ho=((jH)*(1/De)*(Z)); # H0=(h0/phya),using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Ho\n",
+ "phys=1; # low viscosity\n",
+ "ho=(Ho)*(phys); # from eq.6.36\n",
+ "print\"\\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t cold fluid:inner tube side,water \\t\"\n",
+ "Nt=140;\n",
+ "n=4; # number of passes\n",
+ "L=16; #ft\n",
+ "at1=0.546; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "V=Gt/(3600*62.5);\n",
+ "print\"\\t V is fps \\t\",V\n",
+ "mu2=1.74; # at 100F,lb/(ft)*(hr)\n",
+ "D=0.0695; # ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hi=1240*0.94; # from fig 25\n",
+ "print\"\\t Hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "ID=0.834; # ft\n",
+ "OD=1; #ft\n",
+ "hio=((hi)*(ID/OD)); #Hio=(hio/phyp), using eq.6.5\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "f=0.0019; # friction factor for reynolds number 17400, using fig.29\n",
+ "s=1.115; # for reynolds number 17400,using fig.6\n",
+ "Ds=19.25/12; # ft\n",
+ "De=0.06;\n",
+ "N=(12*L/B)+1; # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : %.0f \\t\",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",delPs\n",
+ "print\"\\t allowable delPa is 10 psi \\t\"\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.00018; # friction factor for reynolds number 46300, using fig.26\n",
+ "s=1;\n",
+ "phyt=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",delPt\n",
+ "X1=0.18; # X1=((V**2)/(2*g)), for Gt 1060000,using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \\t\",delPr\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \\t\",delPT\n",
+ "print\"\\t allowable delPa is 10 psi \\t\"\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t Adjustment of the baffie space to use the full 10 psi will still not permit the exchanger to make the 0.002 dirt factor. The value of UD has been assumed too high \\t\"\n",
+ "print\"\\t Try a 21.25 in ID shell with four tube passes and a 6 in baffie space This corresponds to 170 tubes \\t\"\n",
+ "UC1=39\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UC1\n",
+ "UD2=200;\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD2\n",
+ "Rd1=0.0024; \n",
+ "print\"\\t calculated Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd1\n",
+ "Rd2=0.002; \n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd2\n",
+ "delPs1=9.8;\n",
+ "print\"\\t delPs is : psi \\t\",delPs1\n",
+ "delPT1=4.9;\n",
+ "print\"\\t delPt is : psi \\t\",delPT1\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11.4 pgno:241"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 11.4 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for steam \t\n",
+ "\t total heat required for steam is : Btu/hr \t9956700\n",
+ "\t for alcohol \t\n",
+ "\t total heat required for alcohol is : Btu/hr \t9936000.0\n",
+ "\t Q is : V \t9946350.0\n",
+ "\t delt1 is : F \t145.0\n",
+ "\t delt2 is : F \t25.0\n",
+ "\t LMTD is : F \t68.3416294443\n",
+ "\t caloric temperature of hot fluid is : F \t450.0\n",
+ "\t caloric temperature of cold fluid is : \t280.0\n",
+ "\t A1 is :f ft**2 \t727.693360612\n",
+ "\t number of tubes are : \t231.631449138\n",
+ "\t total surface area is : ft**2 \t728.8512\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t199.68228374\n",
+ "\t hot fluid:inner tube side,steam \t\n",
+ "\t flow area is : ft**2 \t0.439833333333\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t23531.640773\n",
+ "\t reynolds number is : \t52084.3641314\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t1500\n",
+ "\t cold fluid:shell side,alcohol \t\n",
+ "\t flow area is : ft**2 \t0.226041666667\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t508755.760369\n",
+ "\t reynolds number is : \t21051.962498\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t269.75\n",
+ "\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t269.75\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t0.421749731499\n",
+ "\t delPr is negligible \t\n",
+ "\t allowable delPa is negligible \t\n",
+ "\t pressure drop for annulus \t\n",
+ "\t number of crosses are : \t20\n",
+ "\t delPs is : psi \t7.39957120534\n",
+ "\t allowable delPa is 10 psi \t\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t228.633987851\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.000634152640616\n",
+ "\t This is clearly an instance in which UD was assumed too high.It is now a question of how much too high. With the aid of the summary it is apparent thatin a larger shell a clean overall coefficient of about 200 may be expected \t\n",
+ "\t Assume a 27in. ID shell with 2 tube passes,334 tubes and baffies spaced 7in. apart, since the pressure drop increases with the diameter of the shell for a given mass velocity. \t\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t214\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t138.5\n",
+ "\t calculated Rd is : (hr)*(ft**2)*(F)/Btu \t0.0025\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.002\n",
+ "\t delPs is : psi \t0.23\n",
+ "\t delPt is : psi \t7.1\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 11.4 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=225.; # inlet hot fluid,F\n",
+ "T2=225.; # outlet hot fluid,F\n",
+ "t1=80.; # inlet cold fluid,F\n",
+ "t2=200.; # outlet cold fluid,F\n",
+ "W=10350; # lb/hr\n",
+ "w=115000; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for steam \\t\"\n",
+ "l=962; # Btu/(lb)\n",
+ "Qh=((W)*(l)); # Btu/hr\n",
+ "print\"\\t total heat required for steam is : Btu/hr \\t\",Qh\n",
+ "print\"\\t for alcohol \\t\"\n",
+ "c=0.72; # Btu/(lb)*(F)\n",
+ "Qc=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for alcohol is : Btu/hr \\t\",Qc\n",
+ "Q=(Qh+Qc)/(2);\n",
+ "print\"\\t Q is : V \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "Tc=((T2)+(T1)); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2)); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : \\t\",tc\n",
+ "L=12;\n",
+ "UD1=200; # assume, from table 8\n",
+ "A1=((Q)/((UD1)*(LMTD)));\n",
+ "print\"\\t A1 is :f ft**2 \\t\",A1\n",
+ "a1=0.2618; # ft**2/lin ft\n",
+ "N1=(A1/(12*a1));\n",
+ "print\"\\t number of tubes are : \\t\",N1\n",
+ "N2=232; # assuming two tube passes,23.25in ID, from table 9\n",
+ "A2=(N2*L*a1); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A2\n",
+ "UD=((Q)/((A2)*(LMTD)));\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "print\"\\t hot fluid:inner tube side,steam \\t\"\n",
+ "Nt=232;\n",
+ "n=2; # number of passes\n",
+ "L=12; #ft\n",
+ "at1=0.546; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(W/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu2=0.0314; # at 225F,lb/(ft)*(hr)\n",
+ "D=0.0695; # ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hio=1500; # condensation of steam\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "print\"\\t cold fluid:shell side,alcohol \\t\"\n",
+ "ID=23.25; # in\n",
+ "C=0.25; # clearance\n",
+ "B=7; # minimum baffle spacing,from eq 11.4,in\n",
+ "PT=1.25;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,from eq 7.1,ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(w/As); # mass velocity,from eq 7.2,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=1.45; # at 193.5F,lb/(ft)*(hr), from fig.14\n",
+ "De=0.72/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jH=83; # from fig.28\n",
+ "Z=0.195; # Z=(K*(c*mu3/k)**(1/3)),Btu/(hr)(ft**2)(F/ft)\n",
+ "Ho=((jH)*(1/De)*(Z)); # H0=(h0/phya),using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Ho\n",
+ "phys=1;\n",
+ "ho=(Ho)*(phys); # from eq.6.36\n",
+ "print\"\\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.000175; # friction factor for reynolds number 52000, using fig.26\n",
+ "s=0.00076;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(1)))/(2); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",delPt\n",
+ "print\"\\t delPr is negligible \\t\"\n",
+ "print\"\\t allowable delPa is negligible \\t\"\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "f=0.0018; # friction factor for reynolds number 21000, using fig.29\n",
+ "s=0.78; # for reynolds number 21000,using fig.6\n",
+ "Ds=1.94; # ft\n",
+ "De=0.06;\n",
+ "N=(12*L/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",delPs\n",
+ "print\"\\t allowable delPa is 10 psi \\t\"\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t This is clearly an instance in which UD was assumed too high.It is now a question of how much too high. With the aid of the summary it is apparent thatin a larger shell a clean overall coefficient of about 200 may be expected \\t\"\n",
+ "print\"\\t Assume a 27in. ID shell with 2 tube passes,334 tubes and baffies spaced 7in. apart, since the pressure drop increases with the diameter of the shell for a given mass velocity. \\t\"\n",
+ "UC1=214;\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UC1\n",
+ "UD2=138.5;\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD2\n",
+ "Rd1=0.0025; \n",
+ "print\"\\t calculated Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd1\n",
+ "Rd2=0.002; \n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd2\n",
+ "delPs1=0.23;\n",
+ "print\"\\t delPs is : psi \\t\",delPs1\n",
+ "delPT1=7.1;\n",
+ "print\"\\t delPt is : psi \\t\",delPT1\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 11.5 pgno:246"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false,
+ "scrolled": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 11.5 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for gas \t\n",
+ "\t total heat required for gas is : Btu/hr \t1290625.0\n",
+ "\t for water \t\n",
+ "\t total heat required for water is : Btu/hr \t1290000.0\n",
+ "\t delt1 is : F \t45.0\n",
+ "\t delt2 is : F \t150.0\n",
+ "\t LMTD is : F \t87.3092936462\n",
+ "\t R is : \t6.25\n",
+ "\t S is : \t0.117647058824\n",
+ "\t FT is 0.935 \t\n",
+ "\t delt is : F \t81.6341895592\n",
+ "\t caloric temperature of hot fluid is : F \t187.5\n",
+ "\t caloric temperature of cold fluid is : F \t90.0\n",
+ "\t A1 is : ft**2 \t1067.71638982\n",
+ "\t number of tubes are : \t339.863887771\n",
+ "\t total surface area is : ft**2 \t1124.6928\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t14.0502389358\n",
+ "\t When solved in a manner identical with the preceding examples and using the smallest integral number of bundle crosses (five) corresponding to a 28.8 in spacing \t\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t22.7\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t14\n",
+ "\t calculated Rd is : (hr)*(ft**2)*(F)/Btu \t0.027\n",
+ "\t required Rd is : (hr)*(ft**2)*(F)/Btu \t0.005\n",
+ "\t delPs is : psi \t5.2\n",
+ "\t delPt is : psi \t1.0\n",
+ "\t The first trial is disqualified because of failure to meet the required dirt factor and the the pressure drop is five times greater than the allowable \t\n",
+ "\t This would be unsatisfactory, since gases require large inlet connections and the flow distribution on the first and third bundle crosses would be poor and the conditions of allowable pressure drop would still not be met \t\n",
+ "\t A1 is : ft**2 \t1053.48017129\n",
+ "\t number of tubes are : %. \t335.332369267\n",
+ "\t total surface area is : ft**2 \t1068.144\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t14.7940751147\n",
+ "\t hot fluid:shell side,gas \t\n",
+ "\t flow area is : ft**2 \t1.03333333333\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t19983.8709677\n",
+ "\t reynolds number is : \t32973.3870968\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t17.9454545455\n",
+ "\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t17.9454545455\n",
+ "\t cold fluid:inner tube side,crude oil \t\n",
+ "\t flow area is : ft**2 \t0.107430555556\n",
+ "\t mass velocity is : %lb/(hr)*(ft**2) \t600387.847447\n",
+ "\t V is : fps \t2.6683904331\n",
+ "\t reynolds number is : \t21289.2629579\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t667\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t553.61\n",
+ "\t pressure drop for annulus \t\n",
+ "\t number of crosses are : \t3\n",
+ "\t delPs is : psi \t0.788231357313\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t3.14770229996\n",
+ "\t delPr is : psi \t2.496\n",
+ "\t delPT is : psi \t5.64370229996\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t17.4\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.0099\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 11.5 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=250.; # inlet hot fluid,F\n",
+ "T2=125.; # outlet hot fluid,F\n",
+ "t1=80.; # inlet cold fluid,F\n",
+ "t2=100.; # outlet cold fluid,F\n",
+ "W=41300.; # lb/hr\n",
+ "w=64500.; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for gas \\t\"\n",
+ "c=0.25; # Btu/(lb)*(F)\n",
+ "Q=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for gas is : Btu/hr \\t\",Q\n",
+ "print\"\\t for water \\t\"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \\t\",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \\t\",S\n",
+ "print\"\\t FT is 0.935 \\t\" # from fig 18\n",
+ "delt=(0.935*LMTD); # F\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "Tc=((T2)+(T1))/(2); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2))/(2); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "UD1=14.8; # assume, from table 8\n",
+ "A1=((Q)/((UD1)*(delt)));\n",
+ "print\"\\t A1 is : ft**2 \\t\",A1\n",
+ "a1=0.2618; # ft**2/lin ft\n",
+ "N1=(A1/(12*a1));\n",
+ "print\"\\t number of tubes are : \\t\",N1\n",
+ "N2=358; # assuming 12 tube passes, from table 9\n",
+ "L=12;\n",
+ "A2=(N2*L*a1); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A2\n",
+ "UD=((Q)/((A2)*(delt)));\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "print\"\\t When solved in a manner identical with the preceding examples and using the smallest integral number of bundle crosses (five) corresponding to a 28.8 in spacing \\t\"\n",
+ "UC1=22.7;\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UC1\n",
+ "UD2=14;\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD2\n",
+ "Rd1=0.027; \n",
+ "print\"\\t calculated Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd1\n",
+ "Rd1=0.005; \n",
+ "print\"\\t required Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd1\n",
+ "delPs1=5.2;\n",
+ "print\"\\t delPs is : psi \\t\",delPs1\n",
+ "delPt1=1.0;\n",
+ "print\"\\t delPt is : psi \\t\",delPt1\n",
+ "print\"\\t The first trial is disqualified because of failure to meet the required dirt factor and the the pressure drop is five times greater than the allowable \\t\"\n",
+ "print\"\\t This would be unsatisfactory, since gases require large inlet connections and the flow distribution on the first and third bundle crosses would be poor and the conditions of allowable pressure drop would still not be met \\t\"\n",
+ "UD1=15; # assume, from table 8\n",
+ "A1=((Q)/((UD1)*(delt)));\n",
+ "print\"\\t A1 is : ft**2 \\t\",A1\n",
+ "a1=0.2618; # ft**2/lin ft\n",
+ "N1=(A1/(12*a1));\n",
+ "print\"\\t number of tubes are : %. \\t\",N1\n",
+ "N2=340; # assuming eight tube passes, from table 9\n",
+ "A2=(N2*L*a1); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A2\n",
+ "UD=((Q)/((A2)*(delt)));\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "print\"\\t hot fluid:shell side,gas \\t\"\n",
+ "ID=31; # in\n",
+ "C=0.25; # clearance\n",
+ "B=24; # baffle spacing,in\n",
+ "PT=1.25;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,from eq 7.1,ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(W/As)/(2); # mass velocity,from eq 7.2,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=0.050; # at 187.5F,lb/(ft)*(hr), from fig.15\n",
+ "De=0.99/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jH=105; # from fig.28\n",
+ "k=0.015; # Btu/(hr)(ft**2)( degree F/ft)\n",
+ "Z=0.94; # Z=((c*mu3/k)**(1/3)),Btu/(hr)(ft**2)(F/ft)\n",
+ "Ho=((jH)*(k/De)*(Z)); # H0=(h0/phya),using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Ho\n",
+ "phys=1;\n",
+ "ho=(Ho)*(phys); # from eq.6.36\n",
+ "print\"\\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t cold fluid:inner tube side,crude oil \\t\"\n",
+ "Nt=340;\n",
+ "n=12; # number of passes\n",
+ "L=12; #ft\n",
+ "at1=0.546; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : %lb/(hr)*(ft**2) \\t\",Gt\n",
+ "V=(Gt/(3600*62.5));\n",
+ "print\"\\t V is : fps \\t\",V\n",
+ "mu2=1.96; # at 90F,lb/(ft)*(hr)\n",
+ "D=0.0695; # ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hi=667; #Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "ID=0.83; # ft\n",
+ "OD=1; #ft\n",
+ "hio=((hi)*(ID/OD)); #Hio=(hio/phyp), using eq.6.5\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio # calculation mistake\n",
+ "phyt=1;\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "f=0.0017; # friction factor for reynolds number 33000, using fig.29\n",
+ "s=0.0012; # for reynolds number 33000,using fig.6\n",
+ "Ds=31/12; # ft\n",
+ "N=(3); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",delPs\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.00022; # friction factor for reynolds number 21300, using fig.26\n",
+ "s=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",delPt\n",
+ "X1=0.052; # X1=((V**2)/(2*g)), for Gt 1060000,using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \\t\",delPr\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \\t\",delPT\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",round(Uc,1)\n",
+ "Rd=-1*(((Uc-UD)/((UD)*(Uc)))-0.02); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",round(Rd,4)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_12_Condensation_of_Single_Vapours____.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_12_Condensation_of_Single_Vapours____.ipynb
new file mode 100755
index 00000000..41f93fc2
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_12_Condensation_of_Single_Vapours____.ipynb
@@ -0,0 +1,1348 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 12 Condensation of Single Vapours "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.1 pgno:274"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 12.1 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for propanol \t\n",
+ "\t total heat required for propanol is : Btu/hr \t17100000\n",
+ "\t for water \t\n",
+ "\t total heat required for water is : Btu/hr \t17080000.0\n",
+ "\t delt1 is : F \t159.0\n",
+ "\t delt2 is : F \t124.0\n",
+ "\t LMTD is : F \t140.93382183\n",
+ "\t caloric temperature of hot fluid is : F \t244.0\n",
+ "\t caloric temperature of cold fluid is : F \t102.5\n",
+ "\t A1 is : ft**2 \t1199.91715754\n",
+ "\t number of tubes are : \t764.083773266\n",
+ "\t total surface area is : ft**2 \t1202.9264\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t100.74733825\n",
+ "\t hot fluid:shell side,propanol \t\n",
+ "\t flow area is : ft**2 \t1.33543445393\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t44929.1987513\n",
+ "\t G1 is : %.1f lb/(hr)*(lin ft) \t7500\n",
+ "\t cold fluid:inner tube side,water \t\n",
+ "\t flow area is : ft**2 \t0.401618055556\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t1215084.81317\n",
+ "\t V is : fps \t5.40037694742\n",
+ "\t reynolds number is : \t36103.3820924\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t1300\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t1074.66666667\n",
+ "\t tw is : F \t124.701882845\n",
+ "\t tf is : F \t184.350941423\n",
+ "\t Correct ho to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t172\n",
+ "\t Based on h=172 instead of the assumed 200 a new value of tw,and tf could be obtained to give a more exact value of h based on fluid properties at a value of tf more nearly correct \t\n",
+ "\t pressure drop for annulus \t\n",
+ "\t reynolds number is : \t85031.2935045\n",
+ "\t number of crosses are : \t3\n",
+ "\t delPs is : psi \t0.937425488924\n",
+ "\t allowable delPa is 2 psi \t\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t3.32625636683\n",
+ "\t delPr is : psi \t3.2\n",
+ "\t delPT is : psi \t6.5\n",
+ "\t allowable delPT is 10 psi \t\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t148.3\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.003\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 12.1 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=244.;# inlet hot fluid,F\n",
+ "T2=244.; # outlet hot fluid,F\n",
+ "t1=85.; # inlet cold fluid,F\n",
+ "t2=120.; # outlet cold fluid,F\n",
+ "W=60000; # lb/hr\n",
+ "w=488000; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for propanol \\t\"\n",
+ "l=285; # Btu/(lb)\n",
+ "Q=((W)*(l)); # Btu/hr\n",
+ "print\"\\t total heat required for propanol is : Btu/hr \\t\",Q\n",
+ "print\"\\t for water \\t\"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "Tc=((T2)+(T1))/(2); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2))/(2); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "UD1=101; # assume, from table 8\n",
+ "A1=((Q)/((UD1)*(LMTD)));\n",
+ "print\"\\t A1 is : ft**2 \\t\",A1\n",
+ "a1=0.1963; # ft**2/lin ft\n",
+ "N1=(A1/(8*a1));\n",
+ "print\"\\t number of tubes are : \\t\",N1\n",
+ "N2=766; # assuming 4 tube passes, from table 9\n",
+ "A2=(N2*8*a1); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A2\n",
+ "UD=((Q)/((A2)*(LMTD)));\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "print\"\\t hot fluid:shell side,propanol \\t\"\n",
+ "ID=31; # in\n",
+ "C=0.1875; # clearance\n",
+ "B=31; # baffle spacing,in\n",
+ "PT=0.937;\n",
+ "L=8; # ft\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,from eq 7.1,ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(W/As); # mass velocity,from eq 7.2,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "G1=(W/(L*N2**(2/3)))# from eq.12.43\n",
+ "print\"\\t G1 is : %.1f lb/(hr)*(lin ft) \\t\",G1\n",
+ "print\"\\t cold fluid:inner tube side,water \\t\"\n",
+ "Nt=766;\n",
+ "n=4; # number of passes\n",
+ "L=8; #ft\n",
+ "at1=0.302; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "V=(Gt/(3600*62.5));\n",
+ "print\"\\t V is : fps \\t\",V\n",
+ "mu2=1.74; # at 102.5F,lb/(ft)*(hr)\n",
+ "D=0.0517; # ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hi=1300; #Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "ID=0.62; # ft\n",
+ "OD=0.75; #ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio # calculation mistake\n",
+ "ho=200; # assumption\n",
+ "tw=(tc)+(((ho)/(hio+ho))*(Tc-tc)); # from eq.5.31\n",
+ "print\"\\t tw is : F \\t\",tw\n",
+ "tf=(Tc+tw)/(2); # from eq 12.19\n",
+ "print\"\\t tf is : F \\t\",tf\n",
+ "kf=0.094; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "sf=0.8; # from table 6\n",
+ "muf=0.62; # cp, from fig 14\n",
+ "ho=172; # Btu/(hr)*(ft**2)*(F), from fig 12.9\n",
+ "print\"\\t Correct ho to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t Based on h=172 instead of the assumed 200 a new value of tw,and tf could be obtained to give a more exact value of h based on fluid properties at a value of tf more nearly correct \\t\"\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "mu1=0.0242; # lb/(ft)*(hr), fir 15\n",
+ "De=0.0458; # fig 28\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "f=0.00141; # friction factor for reynolds number 84600, using fig.29\n",
+ "s=0.00381; # for reynolds number 84600,using fig.6\n",
+ "Ds=31/12; # ft\n",
+ "phys=1;\n",
+ "N=(3); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys)))/(2); # using eq.12.47,psi\n",
+ "print\"\\t delPs is : psi \\t\",delPs\n",
+ "print\"\\t allowable delPa is 2 psi \\t\"\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.00019; # friction factor for reynolds number 36200, using fig.26\n",
+ "s=1;\n",
+ "phyt=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt,1)\n",
+ "X1=0.2; # X1=((V**2)/(2*g)),using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \\t\",delPr\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \\t\",round(delPT,1)\n",
+ "print\"\\t allowable delPT is 10 psi \\t\"\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overalcoefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",round(Uc,1)\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",round(Rd,3)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.2 pgno:277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 12.2 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for propanol \t\n",
+ "\t total heat required for propanol is : Btu/hr \t17100000\n",
+ "\t for water \t\n",
+ "\t total heat required for water is : Btu/hr \t17080000.0\n",
+ "\t delt1 is : F \t159.0\n",
+ "\t delt2 is : F \t124.0\n",
+ "\t LMTD is f F \t140.93382183\n",
+ "\t caloric temperature of hot fluid is : F \t244.0\n",
+ "\t caloric temperature of cold fluid is : F \t102.5\n",
+ "\t A1 is : ft**2 \t1731.30904159\n",
+ "\t L is : ft \t11.5139815143\n",
+ "\t total surface area is : ft**2 \t1804.3896\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t67.164892167\n",
+ "\t hot fluid:shell side,propanol \t\n",
+ "\t G1 is : lb/(hr)*(lin ft) \t399.12856929\n",
+ "\t cold fluid:inner tube side,water \t\n",
+ "\t flow area is : ft**2 \t0.401618055556\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t1215084.81317\n",
+ "\t V is : fps \t5.40037694742\n",
+ "\t reynolds number is : \t36103.3820924\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t1300\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t1074.66666667\n",
+ "\t tw is : F \t114.545970488\n",
+ "\t tf is : F \t179.272985244\n",
+ "\t Correct ho to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t102\n",
+ "\t pressure drop for annulus \t\n",
+ "\t flow area is : ft**2 \t1.24927739239\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t48027.7641824\n",
+ "\t reynolds number is : \t90895.5206428\n",
+ "\t number of crosses are : \t5\n",
+ "\t delPs is : psi \t1.7726452141\n",
+ "\t allowable delPa is 2 psi \t\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t5.0\n",
+ "\t delPr is : psi \t3.2\n",
+ "\t delPT is : psi \t8.2\n",
+ "\t allowable delPT is 10 psi \t\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t93.2\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.004\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 12.2 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=244.; # inlet hot fluid,F\n",
+ "T2=244.; # outlet hot fluid,F\n",
+ "t1=85.; # inlet cold fluid,F\n",
+ "t2=120.; # outlet cold fluid,F\n",
+ "W=60000; # lb/hr\n",
+ "w=488000; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for propanol \\t\"\n",
+ "l=285; # Btu/(lb)\n",
+ "Q=((W)*(l)); # Btu/hr\n",
+ "print\"\\t total heat required for propanol is : Btu/hr \\t\",Q\n",
+ "print\"\\t for water \\t\"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is f F \\t\",LMTD\n",
+ "Tc=((T2)+(T1))/(2); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2))/(2); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "UD1=70; # assume, from table 8\n",
+ "A1=((Q)/((UD1)*(LMTD)));\n",
+ "print\"\\t A1 is : ft**2 \\t\",A1\n",
+ "N2=766; # assuming 4 tube passes, from table 9\n",
+ "a1=0.1963; # ft**2/lin ft\n",
+ "L=(A1/(N2*a1));\n",
+ "print\"\\t L is : ft \\t\",L\n",
+ "A2=(N2*12*a1); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A2\n",
+ "UD=((Q)/((A2)*(LMTD)));\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "print\"\\t hot fluid:shell side,propanol \\t\"\n",
+ "Do=0.0625; # ft\n",
+ "G1=(W/(3.14*N2*Do)); # from eq.12.36\n",
+ "print\"\\t G1 is : lb/(hr)*(lin ft) \\t\",G1\n",
+ "print\"\\t cold fluid:inner tube side,water \\t\"\n",
+ "Nt=766;\n",
+ "n=4; # number of passes\n",
+ "L=12; #ft\n",
+ "at1=0.302; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "V=(Gt/(3600*62.5));\n",
+ "print\"\\t V is : fps \\t\",V\n",
+ "mu2=1.74; # at 102.5F,lb/(ft)*(hr)\n",
+ "D=0.0517; # ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hi=1300; #Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "ID=0.62; # ft\n",
+ "OD=0.75; #ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "ho=100; # assumption\n",
+ "tw=(tc)+(((ho)/(hio+ho))*(Tc-tc)); # from eq.5.31\n",
+ "print\"\\t tw is : F \\t\",tw\n",
+ "tf=(Tc+tw)/(2); # from eq 12.19\n",
+ "print\"\\t tf is : F \\t\",tf\n",
+ "kf=0.0945; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "sf=0.76; # from table 6\n",
+ "muf=0.65; # cp, from fig 14\n",
+ "ho=102; # Btu/(hr)*(ft**2)*(F), from fig 12.9\n",
+ "print\"\\t Correct ho to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "ID=31; # in\n",
+ "C=0.1875; # clearance\n",
+ "B=29; # baffle spacing,in\n",
+ "PT=0.937;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,from eq 7.1,ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(W/As); # mass velocity,from eq 7.2,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=0.0242; # lb/(ft)*(hr), fig 15\n",
+ "De=0.0458; # fig 28\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "f=0.0014; # friction factor for reynolds number 91000, using fig.29\n",
+ "s=0.00381; # for reynolds number 91000,using fig.6\n",
+ "Ds=31/12; # ft\n",
+ "phys=1;\n",
+ "N=(5); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys)))/(2); # using eq.12.47,psi\n",
+ "print\"\\t delPs is : psi \\t\",delPs\n",
+ "print\"\\t allowable delPa is 2 psi \\t\"\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.00019; # friction factor for reynolds number 36200, using fig.26\n",
+ "s=1;\n",
+ "phyt=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt,1)\n",
+ "X1=0.2; # X1=((V**2)/(2*g)),using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \\t\",delPr\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \\t\",round(delPT,1)\n",
+ "print\"\\t allowable delPT is 10 psi \\t\"\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,eq 6.38,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",round(Uc,1)\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # eq 6.13,(hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",round(Rd,3)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.3 pgno:285"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 12.3 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for butane \t\n",
+ "\t total heat required for desuperheating of butane is : Btu/hr \t861106.4\n",
+ "\t total heat required for condensing of butane is : Btu/hr \t3886162\n",
+ "\t total heat required for butane is : Btu/hr \t4747268.4\n",
+ "\t for water \t\n",
+ "\t total heat required for water is : Btu/hr \t4742500.0\n",
+ "\t deltw is : F \t28\n",
+ "\t t2 is : F \t93.0\n",
+ "\t for desuperheating \t\n",
+ "\t delt1 is : F \t37.0\n",
+ "\t delt2 is : F \t100.0\n",
+ "\t LMTD is : F \t63.4354185149\n",
+ "\t w1 is : lb/hr \t13574.5364366\n",
+ "\t for condensing \t\n",
+ "\t delt1 is : F \t60.0\n",
+ "\t delt2 is : F \t37.0\n",
+ "\t LMTD is : F \t47.6304956503\n",
+ "\t w1 is : lb/hr \t81589.787109\n",
+ "\t delt is : F \t49.8348522147\n",
+ "\t caloric temperature of hot fluid is : F \t127.5\n",
+ "\t caloric temperature of cold fluid is : F \t82.5\n",
+ "\t hot fluid:shell side,butane \t\n",
+ "\t flow area is :f ft**2 \t0.484375\n",
+ "\t desuperheating \t\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t57719.7419355\n",
+ "\t reynolds number is : \t145094.392606\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t45.2593972603\n",
+ "\t cold fluid:inner tube side,water \t\n",
+ "\t flow area is : ft**2 \t0.184555555556\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t734196.267309\n",
+ "\t V is : fps \t3.26309452137\n",
+ "\t reynolds number is : \t17989.5483506\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t800\n",
+ "\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t661.333333333\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t42.3603962493\n",
+ "\t clean surface required for desuperheating : ft**2 \t320.453481046\n",
+ "\t for condensaton \t\n",
+ "\t G1 is : lb/(hr)*(lin ft) \t2912.29166667\n",
+ "\t tw is : F \t92.9489164087\n",
+ "\t tf is : F \t110.224458204\n",
+ "\t Correct ho to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t207\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t157.653742802\n",
+ "\t clean surface required for desuperheating : ft**2 \t517.525214808\n",
+ "\t total clean surface : ft**2 \t837.978695854\n",
+ "\t assumed condensing length percentage : \t0.617587556066\n",
+ "\t weighted clean overall coefficient : Btu/(hr)*(ft**2)*(F) \t113.564132378\n",
+ "\t total surface area is : ft**2 \t1105.5616\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t86.0778119876\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.003\n",
+ "\t pressure drop for annulus \t\n",
+ "\t desuperheating \t\n",
+ "\t number of crosses are : \t6.4\n",
+ "\t row is lb/ft**3 \t1.09763894416\n",
+ "\t s is \t0.0175622231065\n",
+ "\t delPs is : psi \t0.964762124732\n",
+ "\t condensation \t\n",
+ "\t number of crosses are : \t9.6\n",
+ "\t delPsc is : psi \t0.723571593549\n",
+ "\t delPS is : psi \t1.68833371828\n",
+ "\t allowable delPa is 2 psi \t\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t3.0\n",
+ "\t delPr is : psi \t1.2\n",
+ "\t delPT is : psi \t4.1\n",
+ "\t allowable delPa is 10 psi \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 12.3 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=200.; # inlet hot fluid,F\n",
+ "T2=130.; # outlet hot fluid,F\n",
+ "T3=125.; # after condensation\n",
+ "t1=65.; # inlet cold fluid,F\n",
+ "t3=100.; # outlet cold fluid,F\n",
+ "W=27958; # lb/hr\n",
+ "w=135500; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for butane \\t\"\n",
+ "c=0.44; # Btu/(lb)(F)\n",
+ "qd=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for desuperheating of butane is : Btu/hr \\t\",qd\n",
+ "HT2=309; # enthalpy at T2, Btu/lb\n",
+ "HT3=170; # enthalpy at T3, Btu/lb\n",
+ "qc=(W*(HT2-HT3)); # for condensation\n",
+ "print\"\\t total heat required for condensing of butane is : Btu/hr \\t\",qc\n",
+ "Q=qd+qc;\n",
+ "print\"\\t total heat required for butane is : Btu/hr \\t\",Q\n",
+ "print\"\\t for water \\t\"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t3-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "deltw=(qc/w);\n",
+ "print\"\\t deltw is : F \\t\",deltw\n",
+ "t2=t1+deltw;\n",
+ "print\"\\t t2 is : F \\t\",t2\n",
+ "print\"\\t for desuperheating \\t\"\n",
+ "delt1=T2-t2; #F\n",
+ "delt2=T1-t3; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTDd=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTDd\n",
+ "w1=(qd/LMTDd);\n",
+ "print\"\\t w1 is : lb/hr \\t\",w1\n",
+ "print\"\\t for condensing \\t\"\n",
+ "delt3=T3-t1; #F\n",
+ "delt4=T2-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt3\n",
+ "print\"\\t delt2 is : F \\t\",delt4\n",
+ "LMTDc=((delt4-delt3)/((2.3)*(log10(delt4/delt3))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTDc\n",
+ "w2=(qc/LMTDc);\n",
+ "print\"\\t w1 is : lb/hr \\t\",w2\n",
+ "delt=(Q/(w1+w2));\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "Tc=((T3)+(T2))/(2); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t3))/(2); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:shell side,butane \\t\"\n",
+ "ID=23.25; # in\n",
+ "C=0.25; # clearance\n",
+ "B=12; # baffle spacing,in\n",
+ "PT=1;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,ft**2\n",
+ "print\"\\t flow area is :f ft**2 \\t\",As\n",
+ "print\"\\t desuperheating \\t\"\n",
+ "Gs=(W/As); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=0.0242; # at 165F,lb/(ft)*(hr), from fig.15\n",
+ "De=0.73/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jH=239; # from fig.28\n",
+ "k=0.012; # Btu/(hr)*(ft**2)*(F/ft), from table 5\n",
+ "Z=0.96; # Z=((c)*(mu1)/k)**(1/3)\n",
+ "ho=((jH)*(k/De)*(Z)); # H0=(h0/phya),using eq.6.15b,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t cold fluid:inner tube side,water \\t\"\n",
+ "Nt=352;\n",
+ "n=4; # number of passes\n",
+ "L=16; #ft\n",
+ "at1=0.302; # flow area,table 10, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "V=(Gt/(3600*62.5));\n",
+ "print\"\\t V is : fps \\t\",V\n",
+ "mu2=2.11; # at 82.5F, fig 14,lb/(ft)*(hr)\n",
+ "D=0.0517; # ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hi=800; # fig 25,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "ID=0.62; # ft\n",
+ "OD=0.75; #ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "Ud=((hio)*(ho)/(hio+ho)); # clean overall coefficient,eq 6.38,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Ud\n",
+ "Ad=(qd/(Ud*LMTDd));\n",
+ "print\"\\t clean surface required for desuperheating : ft**2 \\t\",Ad\n",
+ "print\"\\t for condensaton \\t\"\n",
+ "Lc=16*0.6; # condensation occurs 60 of the tube length\n",
+ "G1=(W/(Lc*Nt**(2/3))); # from eq.12.43\n",
+ "print\"\\t G1 is : lb/(hr)*(lin ft) \\t\",G1\n",
+ "ho=200; # assumption\n",
+ "tw=(tc)+(((ho)/(hio+ho))*(Tc-tc)); # from eq.5.31\n",
+ "print\"\\t tw is : F \\t\",tw\n",
+ "tf=(Tc+tw)/(2); # from eq 12.19\n",
+ "print\"\\t tf is : F \\t\",tf\n",
+ "kf=0.075; # Btu/(hr)*(ft**2)*(F/ft)\n",
+ "sf=0.55; # from table 6\n",
+ "muf=0.14; # cp, from fig 14\n",
+ "ho=207; # Btu/(hr)*(ft**2)*(F), from fig 12.9\n",
+ "print\"\\t Correct ho to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Ac=(qc/(Uc*LMTDc));\n",
+ "print\"\\t clean surface required for desuperheating : ft**2 \\t\",Ac\n",
+ "AC=Ad+Ac;\n",
+ "print\"\\t total clean surface : ft**2 \\t\",AC\n",
+ "lc=(Ac/(Ac+Ad));\n",
+ "print\"\\t assumed condensing length percentage : \\t\",lc\n",
+ "UC=((Ud*Ad)+(Uc*Ac))/(AC);\n",
+ "print\"\\t weighted clean overall coefficient : Btu/(hr)*(ft**2)*(F) \\t\",UC\n",
+ "A2=0.1963; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "Rd=((UC-UD)/((UD)*(UC))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",round(Rd,3)\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "print\"\\t desuperheating \\t\"\n",
+ "Ld=6.4; #ft\n",
+ "De=0.0608; # fig 28\n",
+ "f=0.0013; # friction factor for reynolds number 145000, using fig.29\n",
+ "Ds=1.94; # ft\n",
+ "phys=1;\n",
+ "N=(12*Ld/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "row=(58.1/((359)*(625/492)*(14.7/99.7)));\n",
+ "print\"\\t row is lb/ft**3 \\t\",row\n",
+ "s=(row/62.5);\n",
+ "print\"\\t s is \\t\",s\n",
+ "delPsd=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",delPsd\n",
+ "print\"\\t condensation \\t\"\n",
+ "N=(12*Lc/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "delPsc=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys)))/(2); # using eq 12.47,psi\n",
+ "print\"\\t delPsc is : psi \\t\",delPsc\n",
+ "delPS=delPsd+delPsc;\n",
+ "print\"\\t delPS is : psi \\t\",delPS\n",
+ "print\"\\t allowable delPa is 2 psi \\t\"\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.00023; # friction factor for reynolds number 17900, using fig.26\n",
+ "s=1;\n",
+ "phyt=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt)\n",
+ "X1=0.075; # X1=((V**2)/(2*g)),using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \\t\",delPr\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \\t\",round(delPT,1)\n",
+ "print\"\\t allowable delPa is 10 psi \\t\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.4 pgno:290"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 12.4 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for pentane \t\n",
+ "\t total heat required for condensing of pentane is : Btu/hr \t3045000\n",
+ "\t total heat required for subcooling of pentane is : Btu/hr \t299250.0\n",
+ "\t total heat required for pentane is : Btu/hr \t3344250.0\n",
+ "\t for water \t\n",
+ "\t total heat required for water is : Btu/hr \t3340000.0\n",
+ "\t deltw is : F \t18\n",
+ "\t t2 is : F \t82.0\n",
+ "\t for condensing \t\n",
+ "\t delt1 is : F \t43.0\n",
+ "\t delt2 is : F \t30.0\n",
+ "\t LMTD is : F \t36.1514237668\n",
+ "\t w1 is : lb/hr \t84229.0477863\n",
+ "\t subcooling \t\n",
+ "\t delt1 is : F \t20.0\n",
+ "\t delt2 is : F \t43.0\n",
+ "\t LMTD is f F \t30.0807554052\n",
+ "\t w1 is : lb/hr \t9948.22091297\n",
+ "\t delt is : F \t35.465033613\n",
+ "\t caloric temperature of hot fluid is : F \t127.5\n",
+ "\t caloric temperature of cold fluid is : F \t90.0\n",
+ "\t hot fluid:shell side,pentane \t\n",
+ "\t for condensaton \t\n",
+ "\t G1 is : lb/(hr)*(lin ft) \t289.206403856\n",
+ "\t cold fluid:inner tube side,water \t\n",
+ "\t flow area is : ft**2 \t0.193993055556\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t860855.557544\n",
+ "\t V is : fps \t3.8260247002\n",
+ "\t reynolds number is : %.2e \t22477.8951137\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t940\n",
+ "\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t777.066666667\n",
+ "\t tw is : F \t95.1964008573\n",
+ "\t tf is : F \t111.348200429\n",
+ "\t Correct ho to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t120\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t103.947681332\n",
+ "\t clean surface required for dcondensation : ft**2 \t803.043110735\n",
+ "\t subcooling \t\n",
+ "\t flow area is : ft**2 \t0.520833333333\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t40320.0\n",
+ "\t reynolds number is : \t6939.13043478\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t68.2933263158\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t62.7761756841\n",
+ "\t clean surface required for desuperheating : ft**2 \t158.471279981\n",
+ "\t total clean surface : ft**2 \t961.514390716\n",
+ "\t weighted clean overall coefficient : Btu/(hr)*(ft**2)*(F) \t97.1620302154\n",
+ "\t total surface area is : ft**2 \t1162.096\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t81.0408681377\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.00204736690467\n",
+ "\t pressure drop for annulus \t\n",
+ "\t condensation \t\n",
+ "\t reynolds number is \t193536.0\n",
+ "\t rowvapour is ld/ft**3 \t0.342030962803\n",
+ "\t s is \t0.00547249540485\n",
+ "\t number of crosses are : \t14.4\n",
+ "\t delPsc is : psi \t1.29132938612\n",
+ "\t delPss is negligible \t\n",
+ "\t allowable delPa is 2 psi \t\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t3.9\n",
+ "\t delPr is : psi \t1.6\n",
+ "\t delPT is : psi \t5.5\n",
+ "\t allowable delPT is 10 psi \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 12.4 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=130.; # inlet hot fluid,F\n",
+ "T2=125.; # outlet hot fluid,F\n",
+ "T3=100.; # after sucooling\n",
+ "t1=80.; # inlet cold fluid,F\n",
+ "t3=100.; # outlet cold fluid,F\n",
+ "W=21000; # lb/hr\n",
+ "w=167000; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for pentane \\t\"\n",
+ "HT1=315; # enthalpy at T1, Btu/lb\n",
+ "HT2=170; # enthalpy at T2, Btu/lb\n",
+ "qc=(W*(HT1-HT2)); # for condensation\n",
+ "print\"\\t total heat required for condensing of pentane is : Btu/hr \\t\",qc\n",
+ "c=0.57; # Btu/(lb)(F)\n",
+ "qs=((W)*(c)*(T2-T3)); # Btu/hr\n",
+ "print\"\\t total heat required for subcooling of pentane is : Btu/hr \\t\",qs\n",
+ "Q=qs+qc;\n",
+ "print\"\\t total heat required for pentane is : Btu/hr \\t\",Q\n",
+ "print\"\\t for water \\t\"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t3-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "deltw=(qc/w);\n",
+ "print\"\\t deltw is : F \\t\",deltw\n",
+ "t2=t3-deltw;\n",
+ "print\"\\t t2 is : F \\t\",t2\n",
+ "print\"\\t for condensing \\t\"\n",
+ "delt1=T2-t2; #F\n",
+ "delt2=T1-t3; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTDc=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTDc\n",
+ "w1=(qc/LMTDc);\n",
+ "print\"\\t w1 is : lb/hr \\t\",w1\n",
+ "print\"\\t subcooling \\t\"\n",
+ "delt3=T3-t1; #F\n",
+ "delt4=T2-t2;\n",
+ "print\"\\t delt1 is : F \\t\",delt3\n",
+ "print\"\\t delt2 is : F \\t\",delt4\n",
+ "LMTDs=((delt4-delt3)/((2.3)*(log10(delt4/delt3))));\n",
+ "print\"\\t LMTD is f F \\t\",LMTDs\n",
+ "w2=(qs/LMTDs);\n",
+ "print\"\\t w1 is : lb/hr \\t\",w2\n",
+ "delt=(Q/(w1+w2));\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "Tc=((T1)+(T2))/(2); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t3))/(2); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:shell side,pentane \\t\"\n",
+ "print\"\\t for condensaton \\t\"\n",
+ "Do=0.0625; # ft\n",
+ "Nt=370; # number of tubes\n",
+ "G1=(W/(3.14*Nt*Do)); # from eq.12.42\n",
+ "print\"\\t G1 is : lb/(hr)*(lin ft) \\t\",G1\n",
+ "print\"\\t cold fluid:inner tube side,water \\t\"\n",
+ "n=4; # number of passes\n",
+ "L=16; #ft\n",
+ "at1=0.302; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "V=(Gt/(3600*62.5));\n",
+ "print\"\\t V is : fps \\t\",V\n",
+ "mu2=1.98; # at 90F,lb/(ft)*(hr)\n",
+ "D=0.0517; # ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : %.2e \\t\",Ret\n",
+ "hi=940; #Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "ID=0.62; # ft\n",
+ "OD=0.75; #ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "ho=125; # assumption\n",
+ "tw=(tc)+(((ho)/(hio+ho))*(Tc-tc)); # from eq.5.31\n",
+ "print\"\\t tw is : F \\t\",tw\n",
+ "tf=(Tc+tw)/(2); # from eq 12.19\n",
+ "print\"\\t tf is : F \\t\",tf\n",
+ "kf=0.077; # Btu/(hr)*(ft**2)*(F/ft), table 4\n",
+ "sf=0.6; # from table 6\n",
+ "muf=0.19; # cp, from fig 14\n",
+ "ho=120; # Btu/(hr)*(ft**2)*(F), from fig 12.9\n",
+ "print\"\\t Correct ho to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Ac=(3040000/(104*36.4));\n",
+ "print\"\\t clean surface required for dcondensation : ft**2 \\t\",Ac\n",
+ "print\"\\t subcooling \\t\"\n",
+ "ID=25; # in\n",
+ "C=0.25; # clearance\n",
+ "B=12; # baffle spacing,in\n",
+ "PT=1;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(W/As); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=0.46; # at 112.5F,lb/(ft)*(hr), from fig.14\n",
+ "De=0.95/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jH=46.5; # from fig.28\n",
+ "k=0.077; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "Z=1.51; # Z=((c)*(mu1)/k)**(1/3)\n",
+ "ho=((jH)*(k/De)*(Z)); # using eq.6.15b,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "Us=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Us\n",
+ "As=(qs/(Us*LMTDs));\n",
+ "print\"\\t clean surface required for desuperheating : ft**2 \\t\",As\n",
+ "AC=As+Ac;\n",
+ "print\"\\t total clean surface : ft**2 \\t\",AC\n",
+ "UC=((Us*As)+(Uc*Ac))/(AC);\n",
+ "print\"\\t weighted clean overall coefficient : Btu/(hr)*(ft**2)*(F) \\t\",UC\n",
+ "A2=0.1963; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "Rd=((UC-UD)/((UD)*(UC))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "print\"\\t condensation \\t\"\n",
+ "Lc=13.4; #ft\n",
+ "De=0.0792; # fig 28\n",
+ "f=0.0012; # friction factor for reynolds number 193000, using fig.29\n",
+ "mu3=0.0165; # at 127.5F\n",
+ "Ds=2.08; # ft\n",
+ "phys=1;\n",
+ "Res1=(De*Gs/mu3);\n",
+ "print\"\\t reynolds number is \\t\",Res1\n",
+ "rowvap=(72.2/((359)*(590/492)*(14.7/25)));\n",
+ "print\"\\t rowvapour is ld/ft**3 \\t\",rowvap\n",
+ "s=(rowvap/62.5);\n",
+ "print\"\\t s is \\t\",s\n",
+ "N=(12*Lc/B)+(1); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "delPsc=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys)))/(2); # using eq.12.47,psi\n",
+ "print\"\\t delPsc is : psi \\t\",delPsc\n",
+ "print\"\\t delPss is negligible \\t\"\n",
+ "print\"\\t allowable delPa is 2 psi \\t\"\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.00022; # friction factor for reynolds number 22500, using fig.26\n",
+ "s=1;\n",
+ "phyt=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt,1)\n",
+ "X1=0.1; # X1=((V**2)/(2*g)),using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \\t\",delPr\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \\t\",round(delPT,1)\n",
+ "print\"\\t allowable delPT is 10 psi \\t\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.5 pgno:295"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 12.5 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for pentane \t\n",
+ "\t total heat required for subcooling of pentane is : Btu/hr \t299250.0\n",
+ "\t total heat required for condensing of pentane is : Btu/hr \t3045000\n",
+ "\t total heat required for pentane is : Btu/hr \t3344250.0\n",
+ "\t for water \t\n",
+ "\t total heat required for water is : Btu/hr \t3340000\n",
+ "\t deltw is : F \t18.2\n",
+ "\t t2 is : F \t81.8\n",
+ "\t for condensing \t\n",
+ "\t delt1 is : F \t43.2\n",
+ "\t delt2 is : F \t30\n",
+ "\t LMTD is : F \t36.2404655222\n",
+ "\t w1 is : lb/hr \t84022.0994992\n",
+ "\t subcooling \t\n",
+ "\t delt1 is : F \t20\n",
+ "\t delt2 is : F \t43.2\n",
+ "\t LMTD is : F \t30.1594958556\n",
+ "\t w1 is : lb/hr \t9922.24808506\n",
+ "\t delt is : % F \t35.5529639184\n",
+ "\t caloric temperature of hot fluid is : F \t127\n",
+ "\t caloric temperature of cold fluid is : F \t90\n",
+ "\t hot fluid:shell side,pentane \t\n",
+ "\t a is : in**2 \t123.75\n",
+ "\t number of submerged tubes are : \t93.3248407643\n",
+ "\t number of tubes for condensation are : \t276.675159236\n",
+ "\t flooded surface : \t0.252229299363\n",
+ "\t for condensaton \t\n",
+ "\t G1 is : lb/(hr)*(lin ft) \t1312.5\n",
+ "\t cold fluid:inner tube side,water \t\n",
+ "\t flow area is : ft**2 \t0.145062323071\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t1151229.32312\n",
+ "\t V is : fps \t5.11657476943\n",
+ "\t reynolds number is : \t30059.8767704\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t940\n",
+ "\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t777.066666667\n",
+ "\t Correct ho to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t251\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t189.718954672\n",
+ "\t clean surface required for dcondensation : ft**2 \t442.876673258\n",
+ "\t subcooling \t\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t50\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t46.9772690634\n",
+ "\t clean surface required for desuperheating : ft**2 \t211.213812188\n",
+ "\t total clean surface : ft**2 \t654.090485446\n",
+ "\t weighted clean overall coefficient : Btu/(hr)*(ft**2)*(F) \t143.625919769\n",
+ "\t total surface area is : ft**2 \t1160\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t80.9865065381\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.0054\n",
+ "\t pressure drop for annulus \t\n",
+ "\t condensation \t\n",
+ "\t It will be necessary to spread the batHes to a spacing of 18in.to compensate for the reduction in crossfiow area due to the flooded subcooling zone. The tube-side pressure drop will be the same as before. Assume bundle flooded to 0.3Ds.\t\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t38391.2248629\n",
+ "\t reynolds number is : \t184277.879342\n",
+ "\t number of crosses are : \t10\n",
+ "\t delPsc is : psi \t1.0\n",
+ "\t delPss is negligible \t\n",
+ "\t allowable delPa is 2 psi \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 12.5 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=130; # inlet hot fluid,F\n",
+ "T2=125; # outlet hot fluid,F\n",
+ "T3=100; # after subcooling\n",
+ "t1=80; # inlet cold fluid,F\n",
+ "t3=100; # outlet cold fluid,F\n",
+ "W=21000; # lb/hr\n",
+ "w=167000; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for pentane \\t\"\n",
+ "c=0.57; # Btu/(lb)(\n",
+ "qs=((W)*(c)*(T2-T3)); # Btu/hr\n",
+ "print\"\\t total heat required for subcooling of pentane is : Btu/hr \\t\",qs\n",
+ "HT1=315; # enthalpy at T1, Btu/lb\n",
+ "HT2=170; # enthalpy at T2, Btu/lb\n",
+ "qc=(W*(HT1-HT2)); # for condensation\n",
+ "print\"\\t total heat required for condensing of pentane is : Btu/hr \\t\",qc\n",
+ "Q=qs+qc;\n",
+ "print\"\\t total heat required for pentane is : Btu/hr \\t\",Q\n",
+ "print\"\\t for water \\t\"\n",
+ "c=1; # Btu/(lb)*(F)-++++++++-\n",
+ "Q=((w)*(c)*(t3-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "deltw=18.2;\n",
+ "print\"\\t deltw is : F \\t\",deltw\n",
+ "t2=t3-deltw;\n",
+ "print\"\\t t2 is : F \\t\",t2\n",
+ "print\"\\t for condensing \\t\"\n",
+ "delt1=T2-t2; #F\n",
+ "delt2=T1-t3; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTDc=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTDc\n",
+ "w1=(qc/LMTDc);\n",
+ "print\"\\t w1 is : lb/hr \\t\",w1\n",
+ "print\"\\t subcooling \\t\"\n",
+ "delt3=T3-t1; #F\n",
+ "delt4=T2-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt3\n",
+ "print\"\\t delt2 is : F \\t\",delt4\n",
+ "LMTDs=((delt4-delt3)/((2.3)*(log10(delt4/delt3))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTDs\n",
+ "w2=(qs/LMTDs);\n",
+ "print\"\\t w1 is : lb/hr \\t\",w2\n",
+ "delt=(Q/(w1+w2));\n",
+ "print\"\\t delt is : % F \\t\",delt\n",
+ "Tc=((T1)+(T2))/(2); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t3))/(2); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:shell side,pentane \\t\"\n",
+ "C1=0.198; # for 0.3Ds\n",
+ "Ds=25; # in\n",
+ "L=16; # ft\n",
+ "N=370\n",
+ "a=(C1*Ds**2);\n",
+ "print\"\\t a is : in**2 \\t\",a\n",
+ "N1=((N*a*4)/(3.14*Ds**2));\n",
+ "print\"\\t number of submerged tubes are : \\t\",N1\n",
+ "Nt=N-N1;\n",
+ "print\"\\t number of tubes for condensation are : \\t\",Nt\n",
+ "Af=(N1/N);\n",
+ "print\"\\t flooded surface : \\t\",Af\n",
+ "print\"\\t for condensaton \\t\"\n",
+ "G1=(W/(L*Nt**(2/3))); # from eq.12.43\n",
+ "print\"\\t G1 is : lb/(hr)*(lin ft) \\t\",G1\n",
+ "print\"\\t cold fluid:inner tube side,water \\t\"\n",
+ "n=4; # number of passes\n",
+ "L=16; #ft\n",
+ "at1=0.302; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "V=(Gt/(3600*62.5));\n",
+ "print\"\\t V is : fps \\t\",V\n",
+ "mu2=1.98; # lb/(ft)*(hr)\n",
+ "D=0.0517; # ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hi=940; #Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "ID=0.62; # ft\n",
+ "OD=0.75; #ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "ho=251; # Btu/(hr)*(ft**2)*(F), from fig 12.9\n",
+ "print\"\\t Correct ho to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Ac=(qc/(Uc*LMTDc));\n",
+ "print\"\\t clean surface required for dcondensation : ft**2 \\t\",Ac\n",
+ "print\"\\t subcooling \\t\"\n",
+ "ho=50; # Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "Us=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Us\n",
+ "As=(qs/(Us*LMTDs));\n",
+ "print\"\\t clean surface required for desuperheating : ft**2 \\t\",As\n",
+ "AC=As+Ac;\n",
+ "print\"\\t total clean surface : ft**2 \\t\",AC\n",
+ "UC=((Us*As)+(Uc*Ac))/(AC);\n",
+ "print\"\\t weighted clean overall coefficient : Btu/(hr)*(ft**2)*(F) \\t\",UC\n",
+ "A=1160; # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "Rd=((UC-UD)/((UD)*(UC))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",round(Rd,4)\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "print\"\\t condensation \\t\"\n",
+ "print\"\\t It will be necessary to spread the batHes to a spacing of 18in.to compensate for the reduction in crossfiow area due to the flooded subcooling zone. The tube-side pressure drop will be the same as before. Assume bundle flooded to 0.3Ds.\\t\"\n",
+ "As=0.547; # ft**2\n",
+ "Gs=(W/(As)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "De=0.0792; # fig 28\n",
+ "Res=((De)*(Gs)/0.0165); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "f=0.00121; # friction factor for reynolds number 193000, using fig.29\n",
+ "s=0.00454; # for reynolds number 193000,using fig.6\n",
+ "Ds=2.08; # ft\n",
+ "B=18\n",
+ "phys=1;\n",
+ "N=(12*L/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "delPsc=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys)))/(2); # using eq.12.47,psi\n",
+ "print\"\\t delPsc is : psi \\t\",round(delPsc)\n",
+ "print\"\\t delPss is negligible \\t\"\n",
+ "print\"\\t allowable delPT is 10 psi \\t\"\n",
+ "#e \n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.6 pgno:299"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 12.6 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for carbon disulfide \t\n",
+ "\t total heat required for carbon disulfide is : Btu/hr \t4200000\n",
+ "\t for water \t\n",
+ "\t total heat required for water is : Btu/hr \t4200000.0\n",
+ "\t delt1 is : F \t91.0\n",
+ "\t delt2 is : F \t56.0\n",
+ "\t LMTD is : F \t72.1704928998\n",
+ "\t caloric temperature of hot fluid is : F \t176.0\n",
+ "\t caloric temperature of cold fluid is : F \t102.5\n",
+ "\t hot fluid:inner tube side,carbon disulfide \t\n",
+ "\t cold fluid:shell side,water \t\n",
+ "\t flow area is : ft**2 \t0.1796875\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t667826.086957\n",
+ "\t reynolds number is : \t31112.8388747\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t786.545454545\n",
+ "\t tw is : F \t122.793674699\n",
+ "\t tf is : F \t149.396837349\n",
+ "\t hot fluid:inner tube side,carbon disulfide \t\n",
+ "\t G1 is : lb/(hr)*(lin ft) \t1044.06562495\n",
+ "\t reynolds number is : \t6141.56249973\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t0.251\n",
+ "\t Correct hio1 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t0.207493333333\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t0.207438610331\n",
+ "\t total surface area is : ft**2 \t555.9216\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t104.682978368\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t-4.81115068056\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t flow area is : ft**2 \t0.371208333333\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t80645.1612903\n",
+ "\t reynolds number is : \t143770.856507\n",
+ "\t row is ld/ft**3 \t0.572484035397\n",
+ "\t s is \t0.00915974456635\n",
+ "\t delPt is : psi \t0.4\n",
+ "\t allowable delPa is negligible psi \t\n",
+ "\t pressure drop for annulus \t\n",
+ "\t number of crosses are : \t32.0\n",
+ "\t delPs is : psi \t8.4\n",
+ "\t allowable delPT is 2 psi \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 12.6 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=176.; # inlet hot fluid,F\n",
+ "T2=176.; # outlet hot fluid,F\n",
+ "t1=85.; # inlet cold fluid,F\n",
+ "t2=120.; # outlet cold fluid,F\n",
+ "W=30000; # lb/hr\n",
+ "w=120000; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for carbon disulfide \\t\"\n",
+ "l=140; # Btu/(lb)\n",
+ "Q=((W)*l); # Btu/hr\n",
+ "print\"\\t total heat required for carbon disulfide is : Btu/hr \\t\",Q\n",
+ "print\"\\t for water \\t\"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "Tc=((T2)+T1)/2; # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2))/2; # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:inner tube side,carbon disulfide \\t\"\n",
+ "hio=300; # Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t cold fluid:shell side,water \\t\"\n",
+ "ID=17.25; # in\n",
+ "C=0.25; # clearance\n",
+ "B=6; # baffle spacing,in\n",
+ "PT=1;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(w/As); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=1.7; # at 280F,lb/(ft)*(hr), from fig.14\n",
+ "De=0.0792; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jH=103; # from fig.28\n",
+ "k=0.36; # Btu/(hr)*(ft**2)*(F/ft), from fig.1\n",
+ "Z=1.68; # Z=((c)*(mu1)/k)**(1/3); # prandelt number\n",
+ "ho=((jH)*(k/De)*(Z)); # using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "tw=(tc)+(((hio)/(hio+ho))*(Tc-tc)); # from eq.5.31\n",
+ "print\"\\t tw is : F \\t\",tw\n",
+ "tf=(Tc+tw)/(2); # from eq 12.19\n",
+ "print\"\\t tf is : F \\t\",tf\n",
+ "print\"\\t hot fluid:inner tube side,carbon disulfide \\t\"\n",
+ "kf=0.09; # Btu/(hr)*(ft**2)*(F/ft), from fig 14\n",
+ "sf=1.26; # from table 6\n",
+ "rowf=78.8; # lb/ft**3\n",
+ "muf=0.68; # cp, from fig 24\n",
+ "Nt=177;\n",
+ "D=0.0517; # ft\n",
+ "G1=(W/(3.14*Nt*D));\n",
+ "print\"\\t G1 is : lb/(hr)*(lin ft) \\t\",G1\n",
+ "Ret=((4)*(G1)/muf); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hi=(0.251*(((kf**3)*(rowf**2)*(4.17*10**8))/(muf**2))**(1/3)); # hi*(((kf**3)*(rowf**2)*(4.17*10**8))/(muf**2))**(-1)=0.251, from fig 12.12\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "ID=0.62; # ft\n",
+ "OD=.75; #ft\n",
+ "hio1=((hi)*(ID/OD)); #Hio=(hio/phyp), using eq.6.5\n",
+ "print\"\\t Correct hio1 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio1\n",
+ "Uc=((hio1)*(ho)/(hio1+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "A2=0.1963; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "L=16;\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A\n",
+ "UD=((Q)/((A)*(LMTD)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "n=1; # number of passes\n",
+ "at1=0.302; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(30000/(0.372)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu2=0.029; # at inlet,lb/(ft)*(hr)\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "row=(76.1/((359)*(636/492)*(14.7/39.7)));\n",
+ "print\"\\t row is ld/ft**3 \\t\",row\n",
+ "s=(row/62.5);\n",
+ "print\"\\t s is \\t\",s\n",
+ "f=0.000138; # friction factor for reynolds number 143000, using fig.26\n",
+ "delPt=((f*(Gt**2)*(16)*(1))/(5.22*(10**10)*(0.0517)*(s)))/(2); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt+0.1,1)\n",
+ "print\"\\t allowable delPa is negligible psi \\t\"\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "f=0.0017; # friction factor for reynolds number 31000, using fig.29\n",
+ "s=1; # for reynolds number 31000,using fig.6\n",
+ "Ds=17.25/12.; # ft\n",
+ "B=6.;\n",
+ "N=(12*L/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",round(delPs,1)\n",
+ "print\"\\t allowable delPT is 2 psi \\t\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 12.7 pgno:308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 12.7 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t223.55\n",
+ "\t area is : ft**2 \t31250.0\n",
+ "\t t2 is : F \t86.0\n",
+ "\t circulation rate is : gpm \t29176.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 12.7 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "V=7.5; # fps\n",
+ "W=250000.;\n",
+ "CCl=0.85;\n",
+ "CT=1.;\n",
+ "CL=1.;\n",
+ "Ct=263.;\n",
+ "UD=(CCl*CT*CL*Ct*(V**(1/2)));\n",
+ "print\"\\t design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "A=(W/8);\n",
+ "print\"\\t area is : ft**2 \\t\",A\n",
+ "a1=0.229; # ft**2/ft, table 10\n",
+ "at=0.475; # in**2, table 10\n",
+ "t1=70;\n",
+ "Ts=91.72; #F\n",
+ "n=2;\n",
+ "L=26;\n",
+ "t2=((Ts)-((Ts-t1)/((10)**(0.000279*UD*L*n*a1/(V*at))))+8); \n",
+ "print\"\\t t2 is : F \\t\",round(t2) # calculation mistake in book\n",
+ "Go=(W*950)/((t2-t1)*500);\n",
+ "print\"\\t circulation rate is : gpm \\t\",round(Go)\n",
+ "# end\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_14_Evapouration.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_14_Evapouration.ipynb
new file mode 100755
index 00000000..2fc8b593
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_14_Evapouration.ipynb
@@ -0,0 +1,1123 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 14 : Evapouration"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.1 pgno:383"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 14.1 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\tQevap is Btu/hr\t9610000\n",
+ "\tQ300 degreeF is Btu/hr\t9600500\n",
+ "\tTemperature head = degree F\t74\n",
+ "\tOverall coefficient \t605.5\n",
+ "\tSurface required is ft^2\t2144.75416788\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 14.1 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "\n",
+ "t1 = 300; # degreeF\n",
+ "t2 = 226; #degree F\n",
+ "bs = 700; # Btu/((hr)(ft^2)(ddegree F))\n",
+ "#Heat Balance\n",
+ "Qv = 10000 * 961; # Btu/hr\n",
+ "print\"\\tQevap is Btu/hr\\t\",Qv\n",
+ "Q3 = 10550 * 910; #Btu/hr\n",
+ "print\"\\tQ300 degreeF is Btu/hr\\t\",Q3\n",
+ "\n",
+ "delT = t1-t2; # degree F\n",
+ "print\"\\tTemperature head = degree F\\t\",delT\n",
+ "Ud = bs * 0.865;\n",
+ "print\"\\tOverall coefficient \\t\",Ud\n",
+ "A = Qv*10/(Ud * delT); #ft^2\n",
+ "print\"\\tSurface required is ft^2\\t\",A#Wrong calculation in book\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.2 pgno:412"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 14.2 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\tTotal product is lb/hr\t10000.0\n",
+ "\tTotal evaporation is lb/hr\t40000.0\n",
+ "\tTotal temperature difference is del degree F\t119\n",
+ "\tAverage pressure difference is del psi/effect \t8.25\n",
+ "\t\t\t\t\t\tPressure, psia\t\t delP, psi \t Steam or vapor, degree F \t lambda, Btu/lb\t\tSteam chest, 1st effect \t 26.70 \t\t\t .... \t\t Ts = 244 \t\t ls = 949 \t\tSteam chest, 2nd effect \t 18.45 \t\t\t 8.25 \t\t t1 = 224 \t\t l1 = 961 \t\tSteam chest, 3rd effect \t 10.20(20.7 in. Hg) \t 8.25 \t\t t2 = 194 \t\t l1 = 981 \t\tVapor to condenser \t\t 1.95(26 in. Hg) \t 8.25 \t\t t2 = 125 \t\t l1 = 1022 \t\n",
+ "\t949*Ws + 50000*(100-224) = 961*w1\t\t961*w1 + (50000 - w1)*(224-194) = 981 * w2\t\t981*w2 + (50000-w1-w2)(194-125) = 1022 * w2\t\tw1+w2+w3 = 40000\t\n",
+ "\tSolving simultaneously\t\n",
+ "\tw1 = \t12400\n",
+ "\tw2 = \t13300\n",
+ "\tw3 = \t14300\n",
+ "\tW1-3 is \t40000\n",
+ "\tA1 is ft**2 \t1510\n",
+ "\tA2 is ft**2 \t1588\n",
+ "\tA3 is ft**2 \t1512\n",
+ "\tHeat to condenser is Btu/hr\t14614600\n",
+ "\tWater requirement is lb/hr\t417560\n",
+ "\t= gpm \t835\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 14.2 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "\n",
+ "wf = 50000; # lb/hr\n",
+ "sf = wf * 0.10; # lb/hr\n",
+ "tp = sf/0.50; # lb/hr\n",
+ "print\"\\tTotal product is lb/hr\\t\",tp\n",
+ "te = wf - tp;\n",
+ "print\"\\tTotal evaporation is lb/hr\\t\",te\n",
+ "cf = 1.0;\n",
+ "tF = 100; # degree F\n",
+ "T1 = 244; # degree F\n",
+ "T2 = 125; # degree F\n",
+ "U1=600; # Btu/((hr)*(ft**2)*(degree F))\n",
+ "U2=250; # Btu/((hr)*(ft**2)*(degree F))\n",
+ "U3=125; # Btu/((hr)*(ft**2)*(degree F))\n",
+ "\n",
+ "T = T1-T2;\n",
+ "print\"\\tTotal temperature difference is del degree F\\t\",T\n",
+ "df = (26.70- 1.95)/3; # psi/effect\n",
+ "print\"\\tAverage pressure difference is del psi/effect \\t\",df\n",
+ "\n",
+ "print\"\\t\\t\\t\\t\\t\\tPressure, psia\\t\\t delP, psi \\t Steam or vapor, degree F \\t lambda, Btu/lb\\t\\tSteam chest, 1st effect \\t 26.70 \\t\\t\\t .... \\t\\t Ts = 244 \\t\\t ls = 949 \\t\\tSteam chest, 2nd effect \\t 18.45 \\t\\t\\t 8.25 \\t\\t t1 = 224 \\t\\t l1 = 961 \\t\\tSteam chest, 3rd effect \\t 10.20(20.7 in. Hg) \\t 8.25 \\t\\t t2 = 194 \\t\\t l1 = 981 \\t\\tVapor to condenser \\t\\t 1.95(26 in. Hg) \\t 8.25 \\t\\t t2 = 125 \\t\\t l1 = 1022 \\t\"\n",
+ "\n",
+ "print\"\\t949*Ws + 50000*(100-224) = 961*w1\\t\\t961*w1 + (50000 - w1)*(224-194) = 981 * w2\\t\\t981*w2 + (50000-w1-w2)(194-125) = 1022 * w2\\t\\tw1+w2+w3 = 40000\\t\"\n",
+ "print\"\\tSolving simultaneously\\t\"\n",
+ "w1=12400;\n",
+ "print\"\\tw1 = \\t\",w1\n",
+ "w2=13300;\n",
+ "print\"\\tw2 = \\t\",w2\n",
+ "w3=14300;\n",
+ "print\"\\tw3 = \\t\",w3\n",
+ "\n",
+ "Wt = w1+w2+w3;\n",
+ "print\"\\tW1-3 is \\t\",Wt\n",
+ "Ws = 19100;\n",
+ "lms = 949;\n",
+ "lm1 = 961;\n",
+ "lm2 = 981;\n",
+ "lm3 = 1022;\n",
+ "Ts = 244;\n",
+ "t1 = 224;\n",
+ "t2 = 194;\n",
+ "t3 = 125;\n",
+ "\n",
+ "A1 = (Ws * lms)/(U1*(Ts-t1)); #ft**2\n",
+ "print\"\\tA1 is ft**2 \\t\",A1\n",
+ "A2 = (w1*lm1)/(U2*(t1-t2)); #ft**2\n",
+ "print\"\\tA2 is ft**2 \\t\",A2\n",
+ "A3 = (w2 * lm2)/(U3*(t2-t3)); #ft**2\n",
+ "print\"\\tA3 is ft**2 \\t\",A3\n",
+ "\n",
+ "hc = w3 * lm3; # Btu/hr, WRONG CALCULATION IN TEXT BOOK\n",
+ "print\"\\tHeat to condenser is Btu/hr\\t\",hc\n",
+ "wr = hc/(120-85); #lb/hr\n",
+ "print\"\\tWater requirement is lb/hr\\t\",wr\n",
+ "wr1 = wr/500;\n",
+ "print\"\\t= gpm \\t\",wr1\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.3 pgno:414"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 14.3 \n",
+ "\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t981*w2 + 50000*(100-125) = 1022*w3\n",
+ "\t961*w1 + (50000 - w3)*(125-194) = 981 * w2\n",
+ "\t949*Ws + (50000-w3-w2)(194-224) = 961 * w1\n",
+ "\tw1+w2+w3 = 40000\n",
+ "\n",
+ "\tSolving simultaneously\n",
+ "\n",
+ "\tw1-3 = \n",
+ "40000\n",
+ "\tA1 is ft**2\n",
+ "2010\n",
+ "\tA2 is ft**2\n",
+ "2043\n",
+ "\tA3 is ft**2\n",
+ "1048\n",
+ "\tAverage surface is ft**2\n",
+ "1700\n",
+ "\n",
+ "\tWith a better distribution temperatures and pressure, Average surface is %.0f ft**2\n",
+ "5100\n",
+ "\tRecalculation\n",
+ "\n",
+ "\tA1 is ft**2\n",
+ "0\n",
+ "\tA2 is ft**2\n",
+ "0\n",
+ "\tA3 is ft**2\n",
+ "1048\n",
+ "\tTs-t3 is degreeF\n",
+ "119\n",
+ "\t\t\t\t\tPressure, psia\t\t Steam or vapor, degreeF \t lambda, Btu/lb\n",
+ "\tSteam chest, 1st effect \t 26.70 \t\t\tTs = 244 \t\t 949 \n",
+ "\tSteam chest, 2nd effect \t 16.0 \t\t\t t1 = 216 \t\t 968 \n",
+ "\tSteam chest, 3rd effect \t 16.4 in. Hg) \t\t t2 = 175 \t\t 992 \n",
+ "\tVapor to condenser \t\t 26 in. Hg \t\t t3 = 125 \t\t l1 = 1022 \n",
+ "\n",
+ "\tw1 is \n",
+ "15450\n",
+ "\tw2 is \n",
+ "13200\n",
+ "\tw3 is \n",
+ "11350\n",
+ "\tWs is \n",
+ "16850\n",
+ "\tHeat to condenser is Btu/hr\n",
+ "11599700\n",
+ "\tWater requirement lb/hr\n",
+ "331420\n",
+ "\t\t\t= gpm\n",
+ "662\n",
+ "\tEconomy, lb evaporation/lb steam \n",
+ "2\n",
+ "\t\t\t\tForward\t\tBackward\n",
+ "\tTotal steam, lb/hr\t19100\t\t16850\n",
+ "\tCooling water, gpm\t840\t\t664\n",
+ "\tTotal surface, ft**2\t4800\t\t4500\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 14.3 \\n\"\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#Same conditions as example 14.2\n",
+ "U1 = 400; #Btu/((hr)*(ft**2)*(degreeF))\n",
+ "U2 = 250; #Btu/((hr)*(ft**2)*(degreeF))\n",
+ "U3 = 175; #Btu/((hr)*(ft**2)*(degreeF))\n",
+ "\n",
+ "w1 = 50000; # lb/hr From example 14.2\n",
+ "wt = 40000; # lb/hr From example 14.2\n",
+ "cf = 1; # From example 14.2\n",
+ "\n",
+ "print\"\\t981*w2 + 50000*(100-125) = 1022*w3\\n\\t961*w1 + (50000 - w3)*(125-194) = 981 * w2\\n\\t949*Ws + (50000-w3-w2)(194-224) = 961 * w1\\n\\tw1+w2+w3 = 40000\\n\"\n",
+ "print\"\\tSolving simultaneously\\n\"\n",
+ "w1 = 15950;\n",
+ "w2 = 12900;\n",
+ "w3 = 11150;\n",
+ "lms = 949;\n",
+ "lm1 = 961;\n",
+ "lm2 = 981;\n",
+ "lm3 = 1022;\n",
+ "\n",
+ "wt = w1+w2+w3;\n",
+ "print\"\\tw1-3 = \\n\",wt\n",
+ "Ws = 16950;\n",
+ "A1 = (Ws*lms)/(U1*20); #ft**2\n",
+ "print\"\\tA1 is ft**2\\n\",A1\n",
+ "A2 = (w1*lm1)/(U2*30); #ft**2\n",
+ "print\"\\tA2 is ft**2\\n\",A2\n",
+ "A3 = (w2*lm2)/(U3*69); #ft**2\n",
+ "print\"\\tA3 is ft**2\\n\",A3\n",
+ "\n",
+ "Avs = (A1 + A2 + A3)/3; #ft**2\n",
+ "print\"\\tAverage surface is ft**2\\n\",Avs\n",
+ "Av1 = 3 * Avs; #ft**2\n",
+ "print\"\\n\\tWith a better distribution temperatures and pressure, Average surface is %.0f ft**2\\n\",Av1\n",
+ "print\"\\tRecalculation\\n\"\n",
+ "Av2 = 1500; #ft**2, assume\n",
+ "dT1 = 28; #degreeF\n",
+ "A4 = (20/dT1)*A1; #ft**2\n",
+ "print\"\\tA1 is ft**2\\n\",A4\n",
+ "dT2 = 41; #degreeF\n",
+ "A5 = (30/dT2)*A2; #ft**2\n",
+ "print\"\\tA2 is ft**2\\n\",A5\n",
+ "dT3 = 50; #degreeF\n",
+ "A6 = (69/50)*A3; #ft**2\n",
+ "print\"\\tA3 is ft**2\\n\",A6\n",
+ "del1 = 119; #degreeF\n",
+ "print\"\\tTs-t3 is degreeF\\n\",del1\n",
+ "print\"\\t\\t\\t\\t\\tPressure, psia\\t\\t Steam or vapor, degreeF \\t lambda, Btu/lb\\n\\tSteam chest, 1st effect \\t 26.70 \\t\\t\\tTs = 244 \\t\\t 949 \\n\\tSteam chest, 2nd effect \\t 16.0 \\t\\t\\t t1 = 216 \\t\\t 968 \\n\\tSteam chest, 3rd effect \\t 16.4 in. Hg) \\t\\t t2 = 175 \\t\\t 992 \\n\\tVapor to condenser \\t\\t 26 in. Hg \\t\\t t3 = 125 \\t\\t l1 = 1022 \\n\"\n",
+ "\n",
+ "w1 = 15450; #Solving again for \n",
+ "print\"\\tw1 is \\n\",w1\n",
+ "w2 = 13200;\n",
+ "print\"\\tw2 is \\n\",w2\n",
+ "w3 = 11350;\n",
+ "print\"\\tw3 is \\n\",w3\n",
+ "Ws = 16850;\n",
+ "print\"\\tWs is \\n\",Ws\n",
+ "Hc = w3 * 1022;\n",
+ "print\"\\tHeat to condenser is Btu/hr\\n\",Hc\n",
+ "wr = Hc/(120-85); #lb/hr\n",
+ "print\"\\tWater requirement lb/hr\\n\",wr\n",
+ "wr1 = wr/500;\n",
+ "print\"\\t\\t\\t= gpm\\n\",wr1\n",
+ "ec = wt/Ws;\n",
+ "print\"\\tEconomy, lb evaporation/lb steam \\n\",ec\n",
+ "\n",
+ "#comparision of forward and backward feed\n",
+ "print\"\\t\\t\\t\\tForward\\t\\tBackward\\n\\tTotal steam, lb/hr\\t19100\\t\\t16850\\n\\tCooling water, gpm\\t840\\t\\t664\\n\\tTotal surface, ft**2\\t4800\\t\\t4500\"\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.4 pgno:418"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\texample 14.4 \n",
+ "\n",
+ "\tapproximate values are mentioned in the book \n",
+ "\n",
+ "\n",
+ "\tAVERAGE EVAPORATION PER SQUARE FOOT HEATING SURFACE FOR SUGAR EVAPORATORS\n",
+ "\n",
+ "\tEffects\t\tWater evaporated(lb/(hr)*(ft**2))\n",
+ "\n",
+ "\t1\t\t14-16\n",
+ "\t2\t\t6-8\n",
+ "\t3\t\t5-6\n",
+ "\t4\t\t4-5\n",
+ "\t5\t\t3-4\n",
+ "\n",
+ "\n",
+ "\tEVAPORATOR SUMMARY\n",
+ "\n",
+ "\t------------------------------------------------------------------------------------------------------------------------------\n",
+ "\n",
+ "\tItem\t\t\t\t\t\t\t\t\tEffects\n",
+ "t\t\t\t\t\t----------------------------------------------------------------------------------------------\n",
+ "\t\t\t\t\t1A\t\t1B\t\t2\t\t3\t\t4\t\t5\n",
+ "\n",
+ "\t------------------------------------------------------------------------------------------------------------------------------\n",
+ "\n",
+ "\t1.Steam flow, lb/hr\t\t42600\t\t38000\n",
+ "\t2.Steam pressure, psi/in.Hg\t30\t\t30\t\t15\t\t5\t\t4\t\t14.5\n",
+ "\n",
+ "\t3.Steam temp,degreeF\t\t\t274\t\t274\t\t250\t\t227\t\t205\t\t181\n",
+ "\n",
+ "\t4.delT,degreeF\t\t\t23\t\t23\t\t21\t\t20\t\t20\t\t27\n",
+ "\t5.Liquor temp, degreeF\t\t251\t\t251\t\t229\t\t207\t\t185\t\t164\n",
+ "\t6.BPR, degreeF\t\t\t1\t\t1\t\t2\t\t2\t\t4\t\t7\n",
+ "\t7.Vapor temp, degreeF\t\t250\t\t250\t\t227\t\t205\t\t181\t\t147\n",
+ "\t8.Vapor pressure, pis/in.Hg\t15\t\t15\t\t5\t\t4\t\t14.5\t\t23\n",
+ "\t9.Lambda, Btu/lb\t\t946\t\t946\t\t960\t\t975\t\t990\t\t1010\n",
+ "\t10.Liquor in, lb/hr\t\t229000\t\t190200\t\t154000\t\t117100\t\t87800\t\t64000\n",
+ "\t11.Liqour out, lb/hr\t\t190200\t\t154000\t\t117100\t\t87800\t\t64000\t\t49600\n",
+ "\t12.Evaporation,lb/hr\t\t38800\t\t36200\t\t36900\t\t29300\t\t23800\t\t14400\n",
+ "\t13.degreeBrix(out)\t\t\t15.7\t\t19.4\t\t25.5\t\t34.4\t\t46.5\t\t50.0\n",
+ "\t14.A,ft**2\t\t\t3500\t\t3500\t\t5000\t\t5000\t\t5000\t\t3500\n",
+ "\t15.UD,Btu/(hr)*(ft**2)*(degreeF)\t478\t\t425\t\t310\t\t264\t\t219\t\t138\n",
+ "\t16.UD delT,Btu/(hr)*(ft**2)\t11000\t\t9780\t\t6520\t\t5270\t\t4390\t\t3740\n",
+ "\n",
+ "\tTotal temperature difference in the evaporator system = degreeF\n",
+ "127\n",
+ "\tThe sum of all the BPR(from effect 1B to the fifth effect inclusive) = degreeF\n",
+ "16\n",
+ "\tTotal EFFECTIVE temperature difference = degreeF\n",
+ "111\n",
+ "\n",
+ "\t\t\t\tSUGAR-JUICE HEATERS\n",
+ "\n",
+ "\tRaw-juice heaters\t\t\t\tClear=juice heaters\n",
+ "\t-----------------------------------------------------------------------------------------\n",
+ "\n",
+ "\t1.lbh(tp1-tp2)(0.91) = rj1 Btu/hr 229000 212 184 5834920.0\n",
+ "\t1.lbh(tj1-tj2)(0.91) = rj2 Btu/hr\n",
+ "229000 243 220 4792970.0\n",
+ "\tVapor temp. = 227degreeF\tdelT=26.6degreeF\t\tVapor temp. = 250degreeF\tdelT=15.8degreeF\n",
+ "\n",
+ "\tud1=.\t\t\t\t\t\tUD=ud2\n",
+ "231 243\n",
+ "\tSurface,A=A1 ft**2\t\t\t\tSurface,A=A2 ft**2\n",
+ "\n",
+ "949.601275917 1248.36432776\n",
+ "\t2.lbh(tp2-tp3)(0.91) = rj3 Btu/hr 229000 184 144 8244000.0\n",
+ "\t2.lbh(tj2-tj3)(0.91) = rj4 Btu/hr\n",
+ "229000 220 200 4122000.0\n",
+ "\tVapor temp. = 205degreeF\tdelT=37.6degreeF\t\tVapor temp. = 227degreeF\tdelT=14.8degreeF\n",
+ "\n",
+ "\tUD=Ud3\t\t\t\t\t\tUD=Ud4\n",
+ "230 214\n",
+ "\tSurface,A=A3 ft**2\t\t\t\tSurface,A=A4 ft**2\n",
+ "\n",
+ "953.2839963 1301.46501642\n",
+ "\t2.lbh(tp3-tp4)(0.91) = rj4 Btu/hr 229000 144 82 4122000.0\n",
+ "\t(Use 2 heaters at 1300 ft**2 each plus 1\n",
+ "\t\t\t\t\t\t\theater at 1300 ft**2 as spare)\n",
+ "\n",
+ "\tVapor temp. = 181degreeF\tdelT=62.2degreeF\n",
+ "\tSurface,A=\n",
+ "946.715663757\n",
+ "\t(Use 3 heaters at 100 ft**2\n",
+ "\teach plus 1 heater as spare)\n",
+ "\n",
+ "\n",
+ "\t\t\t\tHEAT BALANCE\n",
+ "\n",
+ "\tEffect\t\t\tBtu/hr\t\tEvaporation,l/hr\n",
+ "\n",
+ "\t----------------------------------------------------\n",
+ "\n",
+ "\t1A.Heat in steam........\n",
+ "38388138.0\n",
+ "\t Heating liquor.......\n",
+ "\t\t\t\t%.3e\t.\n",
+ "1667120.0 36721018.0 38817.1437632\n",
+ "\t Liqour to 1B\n",
+ "\t = lb/hr\n",
+ "190182.856237\n",
+ "\t1B.Heat in steam........\n",
+ "34979292.7593\n",
+ "\t Heating liquor........\n",
+ "\t\t\t\t\n",
+ "0.0 34979292.7593 36975.9965744\n",
+ "\t Liqour to 2d \n",
+ "\t effect= lb/hr\n",
+ "153206.859662\n",
+ "\t\t\t\t\t\t\t\tLb/hr\n",
+ "\n",
+ "\t(a) Actual evaporation..................................\n",
+ "179400\n",
+ "\t(b) Equivalent evaporation from vapors of \n",
+ "\t 1st effect used for vaccum pans......................\n",
+ "145500\n",
+ "\t(c) Equivalent evaporation from 1st effect \n",
+ "\t vapors used for clarified-juice heaters..............\n",
+ "19700\n",
+ "\t(d) Equivalent evaporation from 2d effect \n",
+ "\t vapors used for clarified-and raw-juice heaters......\n",
+ "30600\n",
+ "\t(e) Equivalent evaporation from 3d effect \n",
+ "\t vapors used for raw-juice heaters....................\n",
+ "2.71828182846\n",
+ "\t(f) Equivalent evaporation from 4th effect \n",
+ "\t vapors used for raw-juice heaters....................\n",
+ "13100\n",
+ "\t -----\n",
+ "\n",
+ "\t Extrapolated evaporation............................\n",
+ "406200\n",
+ "\t\tEstimated steam quantity = lb/hr\n",
+ "81240\n",
+ "\t\tActual steam required from final heat balance = lb/hr\n",
+ "80600\n",
+ "\t\t\t\t\t\t\tError = lb/hr\n",
+ "640\n",
+ "\tGallons per minute of Water required = gpm 583\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\texample 14.4 \\n\"\n",
+ "print\"\\tapproximate values are mentioned in the book \\n\"\n",
+ "from math import e\n",
+ "#Assumed that 37500 lb/hr of 15 psig vapor is bled from the first effect for use in thevaccum pans\n",
+ "print\"\\n\\tAVERAGE EVAPORATION PER SQUARE FOOT HEATING SURFACE FOR SUGAR EVAPORATORS\\n\"\n",
+ "print\"\\tEffects\\t\\tWater evaporated(lb/(hr)*(ft**2))\\n\"\n",
+ "print\"\\t1\\t\\t14-16\\n\\t2\\t\\t6-8\\n\\t3\\t\\t5-6\\n\\t4\\t\\t4-5\\n\\t5\\t\\t3-4\\n\"\n",
+ "print\"\\n\\tEVAPORATOR SUMMARY\\n\"\n",
+ "print\"\\t------------------------------------------------------------------------------------------------------------------------------\\n\"\n",
+ "print\"\\tItem\\t\\t\\t\\t\\t\\t\\t\\t\\tEffects\\nt\\t\\t\\t\\t\\t----------------------------------------------------------------------------------------------\\n\\t\\t\\t\\t\\t1A\\t\\t1B\\t\\t2\\t\\t3\\t\\t4\\t\\t5\\n\"\n",
+ "print\"\\t------------------------------------------------------------------------------------------------------------------------------\\n\"\n",
+ "print\"\\t1.Steam flow, lb/hr\\t\\t42600\\t\\t38000\\n\\t2.Steam pressure, psi/in.Hg\\t30\\t\\t30\\t\\t15\\t\\t5\\t\\t4\\t\\t14.5\\n\"\n",
+ "print\"\\t3.Steam temp,degreeF\\t\\t\\t274\\t\\t274\\t\\t250\\t\\t227\\t\\t205\\t\\t181\\n\"\n",
+ "print\"\\t4.delT,degreeF\\t\\t\\t23\\t\\t23\\t\\t21\\t\\t20\\t\\t20\\t\\t27\\n\\t5.Liquor temp, degreeF\\t\\t251\\t\\t251\\t\\t229\\t\\t207\\t\\t185\\t\\t164\\n\\t6.BPR, degreeF\\t\\t\\t1\\t\\t1\\t\\t2\\t\\t2\\t\\t4\\t\\t7\\n\\t7.Vapor temp, degreeF\\t\\t250\\t\\t250\\t\\t227\\t\\t205\\t\\t181\\t\\t147\\n\\t8.Vapor pressure, pis/in.Hg\\t15\\t\\t15\\t\\t5\\t\\t4\\t\\t14.5\\t\\t23\\n\\t9.Lambda, Btu/lb\\t\\t946\\t\\t946\\t\\t960\\t\\t975\\t\\t990\\t\\t1010\\n\\t10.Liquor in, lb/hr\\t\\t229000\\t\\t190200\\t\\t154000\\t\\t117100\\t\\t87800\\t\\t64000\\n\\t11.Liqour out, lb/hr\\t\\t190200\\t\\t154000\\t\\t117100\\t\\t87800\\t\\t64000\\t\\t49600\\n\\t12.Evaporation,lb/hr\\t\\t38800\\t\\t36200\\t\\t36900\\t\\t29300\\t\\t23800\\t\\t14400\\n\\t13.degreeBrix(out)\\t\\t\\t15.7\\t\\t19.4\\t\\t25.5\\t\\t34.4\\t\\t46.5\\t\\t50.0\\n\\t14.A,ft**2\\t\\t\\t3500\\t\\t3500\\t\\t5000\\t\\t5000\\t\\t5000\\t\\t3500\\n\\t15.UD,Btu/(hr)*(ft**2)*(degreeF)\\t478\\t\\t425\\t\\t310\\t\\t264\\t\\t219\\t\\t138\\n\\t16.UD delT,Btu/(hr)*(ft**2)\\t11000\\t\\t9780\\t\\t6520\\t\\t5270\\t\\t4390\\t\\t3740\\n\"#BPR values from fig 14.34a\n",
+ "#Saturate vapor pressure above the liquour determined from Table 7\n",
+ "#Saturated steam pressure in the following effect determined from Table 7\n",
+ "\n",
+ "t1 = 274; #degreeF\n",
+ "t2 = 147; #degreeF\n",
+ "t = t1-t2; #degreeF\n",
+ "print\"\\tTotal temperature difference in the evaporator system = degreeF\\n\",t\n",
+ "bpr1 = 1; #degreeF\n",
+ "bpr2 = 2; #degreeF\n",
+ "bpr3 = 2; #degreeF\n",
+ "bpr4 = 4; #degreeF\n",
+ "bpr5 = 7; #degreeF\n",
+ "bpr = bpr1 + bpr2 + bpr3 + bpr4 + bpr5; #degreeF\n",
+ "print\"\\tThe sum of all the BPR(from effect 1B to the fifth effect inclusive) = degreeF\\n\",bpr\n",
+ "tf = t-bpr; #degreeF\n",
+ "print\"\\tTotal EFFECTIVE temperature difference = degreeF\\n\",tf\n",
+ "lbh = 229000; #lb/hr\n",
+ "tp1=212; #degreeF\n",
+ "tp2=184; #degreeF\n",
+ "tp3=144; #degreeF\n",
+ "tp4=82; #degreeF\n",
+ "tj1=243; #degreeF\n",
+ "tj2=220; #degreeF\n",
+ "tj3=200; #degreeF\n",
+ "Ud1=231;\n",
+ "Ud2=243;\n",
+ "Ud3=230;\n",
+ "Ud4=214;\n",
+ "Ud5=217;\n",
+ "print\"\\n\\t\\t\\t\\tSUGAR-JUICE HEATERS\\n\"\n",
+ "print\"\\tRaw-juice heaters\\t\\t\\t\\tClear=juice heaters\\n\\t-----------------------------------------------------------------------------------------\\n\"\n",
+ "rj1=lbh*(tp1-tp2)*(0.91); #Btu/hr\n",
+ "print\"\\t1.lbh(tp1-tp2)(0.91) = rj1 Btu/hr\",lbh,tp1,tp2,rj1\n",
+ "rj2=lbh*(tj1-tj2)*(0.91); #Btu/hr\n",
+ "print\"\\t1.lbh(tj1-tj2)(0.91) = rj2 Btu/hr\\n\",lbh,tj1,tj2,rj2\n",
+ "print\"\\tVapor temp. = 227degreeF\\tdelT=26.6degreeF\\t\\tVapor temp. = 250degreeF\\tdelT=15.8degreeF\\n\"\n",
+ "print\"\\tud1=.\\t\\t\\t\\t\\t\\tUD=ud2\\n\",Ud1,Ud2\n",
+ "A1=rj1/(26.6*Ud1);#ft**2\n",
+ "A2=rj2/(15.8*Ud2);#ft**2\n",
+ "print\"\\tSurface,A=A1 ft**2\\t\\t\\t\\tSurface,A=A2 ft**2\\n\\n\",A1,A2\n",
+ "\n",
+ "rj3=lbh*(tp2-tp3)*(0.90);#Btu/hr\n",
+ "print\"\\t2.lbh(tp2-tp3)(0.91) = rj3 Btu/hr\",lbh,tp2,tp3,rj3\n",
+ "rj4=lbh*(tj2-tj3)*(0.90);#Btu/hr\n",
+ "print\"\\t2.lbh(tj2-tj3)(0.91) = rj4 Btu/hr\\n\",lbh,tj2,tj3,rj4\n",
+ "print\"\\tVapor temp. = 205degreeF\\tdelT=37.6degreeF\\t\\tVapor temp. = 227degreeF\\tdelT=14.8degreeF\\n\"\n",
+ "print\"\\tUD=Ud3\\t\\t\\t\\t\\t\\tUD=Ud4\\n\",Ud3,Ud4\n",
+ "A3=rj3/(37.6*Ud3);#ft**2\n",
+ "A4=rj4/(14.8*Ud4);#ft**2\n",
+ "print\"\\tSurface,A=A3 ft**2\\t\\t\\t\\tSurface,A=A4 ft**2\\n\\n\",A3,A4\n",
+ "\n",
+ "rj5=lbh*(tp3-tp4)*(0.90);#Btu/hr\n",
+ "print\"\\t2.lbh(tp3-tp4)(0.91) = rj4 Btu/hr\",lbh,tp3,tp4,rj4\n",
+ "print\"\\t(Use 2 heaters at 1300 ft**2 each plus 1\\n\\t\\t\\t\\t\\t\\t\\theater at 1300 ft**2 as spare)\\n\"\n",
+ "A5=rj5/(62.2*Ud5);#ft**2\n",
+ "print\"\\tVapor temp. = 181degreeF\\tdelT=62.2degreeF\\n\\tSurface,A=\\n\",A5\n",
+ "print\"\\t(Use 3 heaters at 100 ft**2\\n\\teach plus 1 heater as spare)\\n\\n\"\n",
+ "\n",
+ "v1=42600;#lb/hr\n",
+ "tt1=251;#degreeF\n",
+ "print\"\\t\\t\\t\\tHEAT BALANCE\\n\"\n",
+ "print\"\\tEffect\\t\\t\\tBtu/hr\\t\\tEvaporation,l/hr\\n\"\n",
+ "print\"\\t----------------------------------------------------\\n\"\n",
+ "hia=v1*929*0.97;#Btu/hr\n",
+ "print\"\\t1A.Heat in steam........\\n\",hia\n",
+ "hla=lbh*(tt1-tj1)*0.91;#Btu/hr\n",
+ "hh=hia-hla;#Btu/hr\n",
+ "lb1=946;#Btu/lb\n",
+ "dif=hh/lb1;#lb/hr\n",
+ "print\"\\t Heating liquor.......\\n\\t\\t\\t\\t%.3e\\t.\\n\",hla,hh,dif\n",
+ "ltob=lbh-dif;#lb/hr\n",
+ "print\"\\t Liqour to 1B\\n\\t = lb/hr\\n\",ltob\n",
+ "hia1=dif*929*0.97;#Btu/hr\n",
+ "print\"\\t1B.Heat in steam........\\n\",hia1\n",
+ "hla1=ltob*(tt1-tt1)*0.91;#Btu/hr\n",
+ "hh1=hia1;#Btu/hr\n",
+ "dif1=hh1/lb1;#lb/hr\n",
+ "print\"\\t Heating liquor........\\n\\t\\t\\t\\t\\n\",hla1,hh1,dif1\n",
+ "dif2=ltob-dif1;#lb/hr\n",
+ "print\"\\t Liqour to 2d \\n\\t effect= lb/hr\\n\",dif2\n",
+ "#Similarily the values in the table are calculated\n",
+ "\n",
+ "print\"\\t\\t\\t\\t\\t\\t\\t\\tLb/hr\\n\"\n",
+ "aa=179400;#lb/hr\n",
+ "bb=145500;#lb/hr\n",
+ "cc=19700;#lb/hr\n",
+ "dd=30600;#lb/hr\n",
+ "ee=17900;#lb/hr\n",
+ "ff=13100;#lb/hr\n",
+ "tto=aa+bb+cc+dd+ee+ff;#lb/hr\n",
+ "print\"\\t(a) Actual evaporation..................................\\n\",aa\n",
+ "print\"\\t(b) Equivalent evaporation from vapors of \\n\\t 1st effect used for vaccum pans......................\\n\",bb\n",
+ "print\"\\t(c) Equivalent evaporation from 1st effect \\n\\t vapors used for clarified-juice heaters..............\\n\",cc\n",
+ "print\"\\t(d) Equivalent evaporation from 2d effect \\n\\t vapors used for clarified-and raw-juice heaters......\\n\",dd\n",
+ "print\"\\t(e) Equivalent evaporation from 3d effect \\n\\t vapors used for raw-juice heaters....................\\n\",e\n",
+ "print\"\\t(f) Equivalent evaporation from 4th effect \\n\\t vapors used for raw-juice heaters....................\\n\",ff\n",
+ "print\"\\t -----\\n\"\n",
+ "print\"\\t Extrapolated evaporation............................\\n\",tto\n",
+ "esq=tto/5;#lb/hr\n",
+ "print\"\\t\\tEstimated steam quantity = lb/hr\\n\",esq\n",
+ "aesq=80600;#lb/hr\n",
+ "err = esq-aesq;#lb/hr\n",
+ "print\"\\t\\tActual steam required from final heat balance = lb/hr\\n\",aesq\n",
+ "print\"\\t\\t\\t\\t\\t\\t\\tError = lb/hr\\n\",err\n",
+ "ta=15;\n",
+ "Q=14575000; #Btu/hr Total hourly evaporation\n",
+ "Gpm=Q/(500*(t2-tp4-ta));#From equation 14.4\n",
+ "print\"\\tGallons per minute of Water required = gpm\",Gpm\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.5 pgno:427"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\texample 14.5\t\n",
+ "\tapproximate values are mentioned in the book \t\n",
+ "\tOverall temperature difference = deg F\t155\n",
+ "\tThe estimated total BPR = degF\t[10 18 25 31 36 41]\n",
+ "\tEffective temperature difference = %.0f degF\t[145 137 130 124 119 114]\n",
+ "\t\t\t\t\tEVAPORATOR SUMMARY\t\tAll bodies will consist of 300 2 in. OD, 10 BWG tubes 24 long\t\n",
+ "\t------------------------------------------------------------------------------------------------------------------------------\t\n",
+ "\tItem\t\t\t\t\t\t\t\t\tEffects\t\t\t\t\t\t----------------------------------------------------------------------------------------------\t\t\t\t\t\t1A\t\t1B\t\t2\t\t3\t\t4\t\t5\t\n",
+ "\t------------------------------------------------------------------------------------------------------------------------------\t\n",
+ "\t1.Steam flow, lb/hr\t\t20000\t\t2.Steam pressure, psi/in.Hg\t35\t\t14.5\t\t4\t\t7\t\t16.5\t\t22\t\t3.Steam temp,degF\t\t\t280\t\t249\t\t224\t\t199\t\t174\t\t151\t\t4.delT,degF\t\t\t21\t\t17\t\t18\t\t19\t\t18\t\t21\t\t5.Liquor temp, degF\t\t259\t\t232\t\t206\t\t180\t\t156\t\t130\t\t6.BPR, degF\t\t\t10\t\t8\t\t7\t\t6\t\t5\t\t5\t\t7.Vapor temp, degF\t\t259\t\t232\t\t206\t\t180\t\t156\t\t130\t\t8.Vapor pressure, pis/in.Hg\t14.5\t\t4\t\t7\t\t6\t\t5\t\t5\t\t9.Lambda, Btu/lb\t\t946\t\t962\t\t978\t\t994\t\t1008\t\t1022\t\t10.Liquor in, lb/hr\t\t73400\t\t88300\t\t101000\t\t113000\t\t72000\t\t72000\t\t11.Liqour out, lb/hr\t\t56200\t\t73400\t\t88300\t\t101100\t\t58300\t\t54700\t\t12.Evaporation,lb/hr\t\t17200\t\t14900\t\t12800\t\t11900\t\t13700\t\t17300\t\t13.Total solids, \t\t38.9\t\t29.8\t\t24.7\t\t21.6\t\t18.7\t\t20.0\t\t14.A,ft^2\t\t\t3250\t\t3250\t\t3250\t\t3250\t\t3250\t\t3250\t\t15.UD,Btu/(hr)*(ft^2)*(degF)\t262\t\t295\t\t252\t\t251\t\t221\t\t221\t\t16.UD delT,Btu/(hr)*(ft^2)\t5510\t\t5000\t\t4530t\t\t4770\t\t3980\t\t4650\t\n",
+ "\t\tTotal amount of water evaporated = \t lb/hr\t[17200 32100 44900 56800 70500 0]\n",
+ "\tTheoretical amount of steam for a six-effect evaporator = \t lb/hr\t[ 2866 5350 7483 9466 11750 0]\n",
+ "\tSteam used for trail balance = \t lb/hr\t[ 3822.22222222 7133.33333333 9977.77777778 12622.22222222\n",
+ " 15666.66666667 0. ]\n",
+ "\tEstimate of the amount of evaporation in the first effect = \t lb/hr\t[ 3295.9 6152.5 8605.45 10885.9 13512.5 0. ]\n",
+ "\tEstimated discharge from second effect = \t lb/hr\t[ 59495.9 62352.5 64805.45 67085.9 69712.5 56200. ]\n",
+ "\t\t\t\t\tHEAT BALANCE\t\n",
+ "\t\tCooling water at 60 degreeF = \t gpm\t710\n",
+ "\t--------------------------------------------------------\t\n",
+ "\tEffect\t\t\tBtu/hr\t\tEvaporation,l/hr\t\n",
+ "\t--------------------------------------------------------\t\n",
+ "\t1.a.Heat in steam \t\t17925600.0\n",
+ "\t b.Heating liquor \t\t1625076.0\n",
+ "\t c.Evaporation\t\t\t\t\t\t17230.9978858\n",
+ "\t d.To flash tank\t2190591.08245\n",
+ "\t\t\t\t2239.86818247\n",
+ "\t e.Flashed vapor=\t\t2239.86818247\n",
+ "\t f.product \t53929.1339317\n",
+ "\t\t2.a.Heat in 1st vapors\t\t16300524.0\n",
+ "\t b.Heating liqour\t\t1951430.0\n",
+ "\t c.Evaporation= 14915.8981289\n",
+ "\t\t\t\t\t14915.8981289\n",
+ "\t d.Liquor to 1b=\t\t73384.1018711\n",
+ "total hourly evapouration lb : 90000\n",
+ "economy is lb/lb : 4.5\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\texample 14.5\\t\"\n",
+ "print\"\\tapproximate values are mentioned in the book \\t\"\n",
+ "st1=280; #degF\n",
+ "vt6=125; #degF\n",
+ "odT=st1-vt6; #degF\n",
+ "print\"\\tOverall temperature difference = deg F\\t\",odT #corresponding to 35 psig and 26 in. Hg\n",
+ "import numpy\n",
+ "bpr=numpy.array([10, 8, 7, 6, 5, 5])\n",
+ "#bpr(1)=10; #degF\n",
+ "#bpr(2)=8; #degF\n",
+ "#bpr(3)=7; #degF\n",
+ "#bpr(4)=6; #degF\n",
+ "#bpr(5)=5; #degF\n",
+ "#bpr(6)=5; #degF\n",
+ "i=1;\n",
+ "tbpr=numpy.array([0, 0, 0, 0, 0, 0]);\n",
+ "tbpr[0]=bpr[0];\n",
+ "while (i<6):\n",
+ "\n",
+ " tbpr[i]=tbpr[i-1]+bpr[i];\n",
+ " i=i+1;\n",
+ "\n",
+ "print\"\\tThe estimated total BPR = degF\\t\",tbpr #from fig. 14.36a\n",
+ "edT=odT-tbpr;\n",
+ "print\"\\tEffective temperature difference = %.0f degF\\t\",edT\n",
+ "print\"\\t\\t\\t\\t\\tEVAPORATOR SUMMARY\\t\\tAll bodies will consist of 300 2 in. OD, 10 BWG tubes 24 long\\t\"\n",
+ "print\"\\t------------------------------------------------------------------------------------------------------------------------------\\t\"\n",
+ "print\"\\tItem\\t\\t\\t\\t\\t\\t\\t\\t\\tEffects\\t\\t\\t\\t\\t\\t----------------------------------------------------------------------------------------------\\t\\t\\t\\t\\t\\t1A\\t\\t1B\\t\\t2\\t\\t3\\t\\t4\\t\\t5\\t\"\n",
+ "print\"\\t------------------------------------------------------------------------------------------------------------------------------\\t\"\n",
+ "print\"\\t1.Steam flow, lb/hr\\t\\t20000\\t\\t2.Steam pressure, psi/in.Hg\\t35\\t\\t14.5\\t\\t4\\t\\t7\\t\\t16.5\\t\\t22\\t\\t3.Steam temp,degF\\t\\t\\t280\\t\\t249\\t\\t224\\t\\t199\\t\\t174\\t\\t151\\t\\t4.delT,degF\\t\\t\\t21\\t\\t17\\t\\t18\\t\\t19\\t\\t18\\t\\t21\\t\\t5.Liquor temp, degF\\t\\t259\\t\\t232\\t\\t206\\t\\t180\\t\\t156\\t\\t130\\t\\t6.BPR, degF\\t\\t\\t10\\t\\t8\\t\\t7\\t\\t6\\t\\t5\\t\\t5\\t\\t7.Vapor temp, degF\\t\\t259\\t\\t232\\t\\t206\\t\\t180\\t\\t156\\t\\t130\\t\\t8.Vapor pressure, pis/in.Hg\\t14.5\\t\\t4\\t\\t7\\t\\t6\\t\\t5\\t\\t5\\t\\t9.Lambda, Btu/lb\\t\\t946\\t\\t962\\t\\t978\\t\\t994\\t\\t1008\\t\\t1022\\t\\t10.Liquor in, lb/hr\\t\\t73400\\t\\t88300\\t\\t101000\\t\\t113000\\t\\t72000\\t\\t72000\\t\\t11.Liqour out, lb/hr\\t\\t56200\\t\\t73400\\t\\t88300\\t\\t101100\\t\\t58300\\t\\t54700\\t\\t12.Evaporation,lb/hr\\t\\t17200\\t\\t14900\\t\\t12800\\t\\t11900\\t\\t13700\\t\\t17300\\t\\t13.Total solids, \\t\\t38.9\\t\\t29.8\\t\\t24.7\\t\\t21.6\\t\\t18.7\\t\\t20.0\\t\\t14.A,ft^2\\t\\t\\t3250\\t\\t3250\\t\\t3250\\t\\t3250\\t\\t3250\\t\\t3250\\t\\t15.UD,Btu/(hr)*(ft^2)*(degF)\\t262\\t\\t295\\t\\t252\\t\\t251\\t\\t221\\t\\t221\\t\\t16.UD delT,Btu/(hr)*(ft^2)\\t5510\\t\\t5000\\t\\t4530t\\t\\t4770\\t\\t3980\\t\\t4650\\t\"#BPR values from fig 14.36a\n",
+ "#Specific-heat data are given in Fig. 14.36b\n",
+ "ev=numpy.array([17200, 14900, 12800, 11900, 13700, 17300]);\n",
+ "#ev(1)=17200; #lb/hr\n",
+ "#ev(2)=14900; #lb/hr\n",
+ "#ev(3)=12800; #lb/hr\n",
+ "#ev(4)=11900; #lb/hr\n",
+ "#ev(5)=13700; #lb/hr\n",
+ "#ev(6)=17300; #lb/hr\n",
+ "i=1;\n",
+ "tev =numpy.array([0, 0, 0, 0, 0, 0])\n",
+ "tev[0]=ev[0];\n",
+ "while (i<5):\n",
+ " tev[i]= tev[i-1]+ev[i];\n",
+ " i=i+1;\n",
+ "\n",
+ "print\"\\t\\tTotal amount of water evaporated = \\t lb/hr\\t\",tev\n",
+ "ttev=tev/6;#lb/hr\n",
+ "print\"\\tTheoretical amount of steam for a six-effect evaporator = \\t lb/hr\\t\",ttev\n",
+ "tev2=tev/(6*0.75); #lb/hr . order of 75 percent of theoretical\n",
+ "print\"\\tSteam used for trail balance = \\t lb/hr\\t\",tev2\n",
+ "lq=(tev/6);\n",
+ "lq=lq+(lq*0.15);\n",
+ "print\"\\tEstimate of the amount of evaporation in the first effect = \\t lb/hr\\t\",lq\n",
+ "lout6=54000;#lb/hr\n",
+ "lq2=lout6+lq+2200;#lb/hr\n",
+ "print\"\\tEstimated discharge from second effect = \\t lb/hr\\t\",lq2\n",
+ "print\"\\t\\t\\t\\t\\tHEAT BALANCE\\t\"\n",
+ "cw = 17750000/(500*(125-15-60)); #gpm, values from table 14.6\n",
+ "print\"\\t\\tCooling water at 60 degreeF = \\t gpm\\t\",cw\n",
+ "print\"\\t--------------------------------------------------------\\t\"\n",
+ "print\"\\tEffect\\t\\t\\tBtu/hr\\t\\tEvaporation,l/hr\\t\"\n",
+ "print\"\\t--------------------------------------------------------\\t\"\n",
+ "sf=20000;#lb/hr\n",
+ "lqi=73400;#lb/hr\n",
+ "the=90000;\n",
+ "lqi2=88300\n",
+ "lt1=259;#degreeF\n",
+ "lt2=232;#degreeF\n",
+ "lt3=206;#degreeF\n",
+ "ecn=90000./20000.;\n",
+ "ev=17200;#lb/hr\n",
+ "his=sf*924*0.97;#Btu/hr\n",
+ "print\"\\t1.a.Heat in steam \\t\\t\",his\n",
+ "hl=lqi*(lt1-lt2)*0.82;#Btu/hr\n",
+ "print\"\\t b.Heating liquor \\t\\t\",hl\n",
+ "hh=his-hl;\n",
+ "ev1=(hh)/946;#lb/hr\n",
+ "print\"\\t c.Evaporation\\t\\t\\t\\t\\t\\t\",ev1\n",
+ "dif=lqi-ev1;\n",
+ "tft=(dif)*(lt1-209)*0.78;\n",
+ "print\"\\t d.To flash tank\\t\",tft\n",
+ "ev2=tft/978;#lb/hr\n",
+ "print\"\\t\\t\\t\\t\",ev2\n",
+ "print\"\\t e.Flashed vapor=\\t\\t\",ev2\n",
+ "p=dif-ev2;\n",
+ "print\"\\t f.product \\t\",p\n",
+ "print\"\\t\\t2.a.Heat in 1st vapors\\t\\t\",hh\n",
+ "hl2=lqi2*(lt2-lt3)*0.85;\n",
+ "print\"\\t b.Heating liqour\\t\\t\",hl2\n",
+ "ev3=(hh-hl2)/962;\n",
+ "print\"\\t c.Evaporation=\",ev3\n",
+ "\n",
+ "print\"\\t\\t\\t\\t\\t\",ev3\n",
+ "lto1=lqi2-ev3;\n",
+ "print\"\\t d.Liquor to 1b=\\t\\t\",lto1\n",
+ "print\"total hourly evapouration lb :\",the\n",
+ "print\"economy is lb/lb :\",ecn\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.6 pgno:437"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\texample 14.6\n",
+ "\n",
+ "\tapproximate values are mentioned in the book \n",
+ "\n",
+ "\tTotal temperature difference = degreeF\n",
+ "159\n",
+ "\tThe effective temperature difference is degreeF\n",
+ "56\n",
+ "\n",
+ "\t\t\tCAUSTIC EVAPORATOR MATERIAL BALANCE\n",
+ "\n",
+ "\tCell liquour at 120degreeF \t\tWash at 80degreeF\n",
+ "\n",
+ "\t---------------------------------------------\n",
+ "\n",
+ "\t8.75 prcnt NaOH = l1\n",
+ "\t16.6 prcnt NaCl = l2\t\t25 prcnt NaCl = w2\n",
+ "2000 3800 340\n",
+ "\t74.65 prcnt H20 = l3\t\t75 prcnt H20 = w2\n",
+ "17050 1020\n",
+ "\tTotal cell liquor = lq\tTotoal wash = w\n",
+ "22850 1360\n",
+ "\n",
+ "\t-------------------------------------------------------------------------\n",
+ "\n",
+ "\t\t\t\tNaOH\t\tNaCl\t\tH20,Lb\tTotal,Lb\n",
+ "\t\t\t\tprcnt\tLb\tprcnt\tLb\n",
+ "\n",
+ "\t-------------------------------------------------------------------------\n",
+ "\n",
+ "\tOverall operation:\n",
+ "\t Cell liquor.......... 8.75\t2000 3800 17050 22850\n",
+ "\t Wash................. ....\t....\t25.00\t340 1020 1360\n",
+ "\t Total in............. ....\t2000 4140 18070 24210\n",
+ "\t Product.............. 50.00\t2000 110 1890 4000\n",
+ "\t Removed.............. ....\t....\t....\t\t%.0f\t%.0f\n",
+ "4030 16180 20210\n",
+ "\n",
+ "\t\t\t\t\tCAUSTIC EVAPORATOR SUMMARY\n",
+ "\n",
+ "\t------------------------------------------------------------------------------------\n",
+ "\n",
+ "\tItem\t\t\t\t\tEffects\n",
+ "t\t\t\t\t\t--------------------\t\tFlash Tank\n",
+ "\t\t\t\t\t\\I\t\tII\n",
+ "\n",
+ "\t------------------------------------------------------------------------------------\n",
+ "\n",
+ "\t1.Steam pressure, psi/in.Hg\t30\n",
+ "\t2.Steam temperature,degreeF\t\t274\t\t169\n",
+ "\t3.delT,degreeF\t\t\t28\t\t28\n",
+ "\t4.Liquor temperature, degreeF\t246\t\t141\t\t192\n",
+ "\t5.BPR, degreeF\t\t\t77\t\t26\t\t77\n",
+ "\t6.Vapor temperature, degreeF\t\t169\t\t115\t\t115\n",
+ "\t7.Lambda, Btu/lb\t\t997\t\t1027\t\t1027\n",
+ "\t8.Feed, lb/hr\t\t\t22788\t\t50602\t\t13367\n",
+ "\t9.Product, lb/hr\t\t13367\t\t40352\t\t12813\n",
+ "\t10.Evaporation,lb/hr\t\t9421\t\t10250\t\t554\n",
+ "\t11.Heat flow, Btu/hr\t\t11890000\t11020000\n",
+ "\t12.UD,Btu/((hr)*(ft**2)*(degreeF))\t700\n",
+ "\t13.A,ft**2\t\t\t683\t\t683\n",
+ "\t14.Tubes, OD, in. and BWG\t1,16\t\t1,16\n",
+ "\t15.Tube length, ft\t\t7\t\t7\n",
+ "\t16.No. tubes\t\t\t432\t\t432\n",
+ "\t17.Circulating pump. gpm\t3200 at 20 ft\t3200 at 20ft\t167 at 45 ft\n",
+ "\t18.Apparent efficiency, prcnt\t54\t\t64\n",
+ "\t18.BHP\t\t\t\t38\t\t35\t\t8.2\n",
+ "\t20.Motor,hp\t\t\t40\t\t40\t\t10.0\n",
+ "\n",
+ "\t------------------------------------------------------------------------------------\n",
+ "\n",
+ "\tG = V(s*62.5*3600) = lb/((hr)*(ft**2))\n",
+ "2700000.0\n",
+ "\tUC or UD = Btu/((hr)*(ft**2)*(degreeF))\n",
+ "700\n",
+ "\n",
+ "\t-------------------------------------------------------------------------------------\n",
+ "\n",
+ "\ttx,degreeF\tw,lb/hr\t\tdelT\tUC\tA,ft**2\tat,flow area\tGcalc\t\tUcalc\n",
+ "\t\t\t\t\t\t\tper pass, ft**2\n",
+ "\n",
+ "\t-------------------------------------------------------------------------------------\n",
+ "\n",
+ "\t251\t2970000\t\t25.4\t700\t670\t0.87\t\t3420000\n",
+ "\t252\t2480000\t\t25.0\t700\t680\t0.88\t\t2820000\n",
+ "\t252.5\t2290000\t\t24.7\t700\t685\t0.89\t\t2570000\t\t700\n",
+ "\t253\t2120000\t\t24.5\t700\t695\t0.90\t\t2520000\n",
+ "\n",
+ "\tThee gain per minute is gpm\n",
+ "3200\n",
+ "\n",
+ "\t\t\t\tCAUSTIC EVAPORATION HEAT BALANCE\n",
+ "\n",
+ "\t\t\t\t(Basis = 1ton/hr NaOH)\n",
+ "\n",
+ "\t-------------------------------------------------------------------------------------\n",
+ "\n",
+ "\t\tEFFECT\t\t\tBtu/hr\t\tEvaopration, lb/hr\n",
+ "\n",
+ "\t1.a.Heat in steam\t\thi\n",
+ "\t b.Heating liquor\t\thl\n",
+ "\t c.Resultant heat\t\trhf\n",
+ "\t d.Heat of concentrate\t\thc\n",
+ "\t e.Heat of vapors\t\thv\t%.0f\n",
+ "9511110.0 1452566.4 8058543.6 300000 7758543.6 7781.8892678\n",
+ "\n",
+ "\tG = V(s*62.5*3600) = lb/((hr)*(ft**2))\n",
+ "2430000.0\n",
+ "\tUD = Btu/((hr)*(ft**2)*(degreeF))\n",
+ "700\n",
+ "\n",
+ "\t-------------------------------------------------------------------------------------\n",
+ "\n",
+ "\ttx,degreeF\tw,lb/hr\t\tdelT\tUC\tA,ft**2\tat,flow area\tGcalc\t\tUcalc\n",
+ "\t\t\t\t\t\t\tper pass, ft**2\n",
+ "\n",
+ "\t-------------------------------------------------------------------------------------\n",
+ "\n",
+ "\t146\t2400000\t\t25.4\t700\t620\t0.80\t\t2790000\t\t700\n",
+ "\t146.5\t2160000\t\t25.2\t700\t683\t0.89\t\t2430000\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\texample 14.6\\n\"\n",
+ "print\"\\tapproximate values are mentioned in the book \\n\"\n",
+ "st1=274; #degreeF\n",
+ "vt6=115; #degreeF\n",
+ "odT=st1-vt6; #degreeF\n",
+ "print\"\\tTotal temperature difference = degreeF\\n\",odT #corresponding to 35 psig\n",
+ "eb1=77;#degreeF, From fig.14.38\n",
+ "eb2=26;#degreeF, From fig.14.38\n",
+ "etd=odT-(eb1+eb2);#degreeF\n",
+ "print\"\\tThe effective temperature difference is degreeF\\n\",etd\n",
+ "print\"\\n\\t\\t\\tCAUSTIC EVAPORATOR MATERIAL BALANCE\\n\"\n",
+ "#Basis: 1 ton/hr NaOH\n",
+ "print\"\\tCell liquour at 120degreeF \\t\\tWash at 80degreeF\\n\"\n",
+ "print\"\\t---------------------------------------------\\n\"\n",
+ "l1=2000;#Lb\n",
+ "l2=3800;#Lb\n",
+ "l3=17050;#Lb\n",
+ "lq=l1+l2+l3;#Lb\n",
+ "w1=340;#Lb\n",
+ "w2=1020;#Lb\n",
+ "w=w1+w2;#Lb\n",
+ "print\"\\t8.75 prcnt NaOH = l1\\n\\t16.6 prcnt NaCl = l2\\t\\t25 prcnt NaCl = w2\\n\",l1,l2,w1\n",
+ "print\"\\t74.65 prcnt H20 = l3\\t\\t75 prcnt H20 = w2\\n\",l3,w2\n",
+ "print\"\\tTotal cell liquor = lq\\tTotoal wash = w\\n\",lq,w\n",
+ "print\"\\n\\t-------------------------------------------------------------------------\\n\"\n",
+ "print\"\\t\\t\\t\\tNaOH\\t\\tNaCl\\t\\tH20,Lb\\tTotal,Lb\\n\\t\\t\\t\\tprcnt\\tLb\\tprcnt\\tLb\\n\"\n",
+ "print\"\\t-------------------------------------------------------------------------\\n\"\n",
+ "print\"\\tOverall operation:\\n\\t Cell liquor.......... 8.75\\t\",l1,l2,l3,lq\n",
+ "print\"\\t Wash................. ....\\t....\\t25.00\\t\",w1,w2,w\n",
+ "wl1=l2+w1;#Lb\n",
+ "wl2=l3+w2;#Lb\n",
+ "wlt=lq+w;\n",
+ "print\"\\t Total in............. ....\\t\",l1,wl1,wl2,wlt\n",
+ "prn=110;#Lb\n",
+ "prh=1890;#Lb\n",
+ "prt=4000;#Lb\n",
+ "print\"\\t Product.............. 50.00\\t\",l1,prn,prh,prt\n",
+ "r1=wl1-prn;#Lb\n",
+ "r2=wl2-prh;#Lb\n",
+ "r3=wlt-prt;#Lb\n",
+ "gain=3200;#gpm\n",
+ "print\"\\t Removed.............. ....\\t....\\t....\\t\\t%.0f\\t%.0f\\n\",r1,r2,r3\n",
+ "#Rest of the table is calculated similarily\n",
+ "print\"\\n\\t\\t\\t\\t\\tCAUSTIC EVAPORATOR SUMMARY\\n\"\n",
+ "print\"\\t------------------------------------------------------------------------------------\\n\"\n",
+ "print\"\\tItem\\t\\t\\t\\t\\tEffects\\nt\\t\\t\\t\\t\\t--------------------\\t\\tFlash Tank\\n\\t\\t\\t\\t\\t\\I\\t\\tII\\n\"\n",
+ "print\"\\t------------------------------------------------------------------------------------\\n\"\n",
+ "print\"\\t1.Steam pressure, psi/in.Hg\\t30\\n\\t2.Steam temperature,degreeF\\t\\t274\\t\\t169\\n\\t3.delT,degreeF\\t\\t\\t28\\t\\t28\\n\\t4.Liquor temperature, degreeF\\t246\\t\\t141\\t\\t192\\n\\t5.BPR, degreeF\\t\\t\\t77\\t\\t26\\t\\t77\\n\\t6.Vapor temperature, degreeF\\t\\t169\\t\\t115\\t\\t115\\n\\t7.Lambda, Btu/lb\\t\\t997\\t\\t1027\\t\\t1027\\n\\t8.Feed, lb/hr\\t\\t\\t22788\\t\\t50602\\t\\t13367\\n\\t9.Product, lb/hr\\t\\t13367\\t\\t40352\\t\\t12813\\n\\t10.Evaporation,lb/hr\\t\\t9421\\t\\t10250\\t\\t554\\n\\t11.Heat flow, Btu/hr\\t\\t11890000\\t11020000\\n\\t12.UD,Btu/((hr)*(ft**2)*(degreeF))\\t700\\n\\t13.A,ft**2\\t\\t\\t683\\t\\t683\\n\\t14.Tubes, OD, in. and BWG\\t1,16\\t\\t1,16\\n\\t15.Tube length, ft\\t\\t7\\t\\t7\\n\\t16.No. tubes\\t\\t\\t432\\t\\t432\\n\\t17.Circulating pump. gpm\\t3200 at 20 ft\\t3200 at 20ft\\t167 at 45 ft\\n\\t18.Apparent efficiency, prcnt\\t54\\t\\t64\\n\\t18.BHP\\t\\t\\t\\t38\\t\\t35\\t\\t8.2\\n\\t20.Motor,hp\\t\\t\\t40\\t\\t40\\t\\t10.0\\n\"\n",
+ "print\"\\t------------------------------------------------------------------------------------\\n\"\n",
+ "V=8;\n",
+ "s=1.5;\n",
+ "G=V*s*62.5*3600;#lb/((hr)*(ft**2))\n",
+ "print\"\\tG = V(s*62.5*3600) = lb/((hr)*(ft**2))\\n\",G\n",
+ "UD=700;#Btu/((hr)*(ft**2)*(degreeF))\n",
+ "#Combining with a steam film coefficient of approximately 1500\n",
+ "print\"\\tUC or UD = Btu/((hr)*(ft**2)*(degreeF))\\n\",UD\n",
+ "print\"\\n\\t-------------------------------------------------------------------------------------\"\n",
+ "print\"\\n\\ttx,degreeF\\tw,lb/hr\\t\\tdelT\\tUC\\tA,ft**2\\tat,flow area\\tGcalc\\t\\tUcalc\\n\\t\\t\\t\\t\\t\\t\\tper pass, ft**2\\n\"\n",
+ "print\"\\t-------------------------------------------------------------------------------------\\n\"\n",
+ "print\"\\t251\\t2970000\\t\\t25.4\\t700\\t670\\t0.87\\t\\t3420000\\n\\t252\\t2480000\\t\\t25.0\\t700\\t680\\t0.88\\t\\t2820000\\n\\t252.5\\t2290000\\t\\t24.7\\t700\\t685\\t0.89\\t\\t2570000\\t\\t700\\n\\t253\\t2120000\\t\\t24.5\\t700\\t695\\t0.90\\t\\t2520000\\n\"\n",
+ "print\"\\tThee gain per minute is gpm\\n\",gain\n",
+ "print\"\\n\\t\\t\\t\\tCAUSTIC EVAPORATION HEAT BALANCE\\n\"\n",
+ "print\"\\t\\t\\t\\t(Basis = 1ton/hr NaOH)\\n\"\n",
+ "print\"\\t-------------------------------------------------------------------------------------\\n\"\n",
+ "print\"\\t\\tEFFECT\\t\\t\\tBtu/hr\\t\\tEvaopration, lb/hr\\n\"\n",
+ "hi=10500*930*0.974;#Btu/hr\n",
+ "hl=18230*(246-150)*0.83;#Btu/hr\n",
+ "rh=hi-hl;#Btu/hr\n",
+ "hc=300000;#Btu/hr\n",
+ "hv=rh-hc;#Btu/hr\n",
+ "evv=hv/997;#lb/hr\n",
+ "print\"\\t1.a.Heat in steam\\t\\thi\\n\\t b.Heating liquor\\t\\thl\\n\\t c.Resultant heat\\t\\trhf\\n\\t d.Heat of concentrate\\t\\thc\\n\\t e.Heat of vapors\\t\\thv\\t%.0f\\n\",hi,hl,rh,hc,hv,evv\n",
+ "s1=1.35;\n",
+ "G1=V*s1*62.5*3600;#lb/((hr)*(ft**2))\n",
+ "print\"\\n\\tG = V(s*62.5*3600) = lb/((hr)*(ft**2))\\n\",G1\n",
+ "UD1=700;#Btu/((hr)*(ft**2)*(degreeF))\n",
+ "#Using thermal characteristics for this solution\n",
+ "print\"\\tUD = Btu/((hr)*(ft**2)*(degreeF))\\n\",UD1\n",
+ "#As for effect I:\n",
+ "print\"\\n\\t-------------------------------------------------------------------------------------\"\n",
+ "print\"\\n\\ttx,degreeF\\tw,lb/hr\\t\\tdelT\\tUC\\tA,ft**2\\tat,flow area\\tGcalc\\t\\tUcalc\\n\\t\\t\\t\\t\\t\\t\\tper pass, ft**2\\n\"\n",
+ "print\"\\t-------------------------------------------------------------------------------------\\n\"\n",
+ "print\"\\t146\\t2400000\\t\\t25.4\\t700\\t620\\t0.80\\t\\t2790000\\t\\t700\\n\\t146.5\\t2160000\\t\\t25.2\\t700\\t683\\t0.89\\t\\t2430000\\n\"\n",
+ "#end"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.7 pgno:447"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\texample 14.7\n",
+ "\n",
+ "\tapproximate values are mentioned in the book \n",
+ "\n",
+ "\tM1 = lb\n",
+ "17900\n",
+ "\n",
+ "\t\t\t\tEVAPORATOR SUMMARY\n",
+ "\n",
+ "\t------------------------------------------------------------------------------------------------------------------------------\n",
+ "\n",
+ "\tEffects\t\t\t\t\tStraight triple effect\t\t\t\tThermocompression\n",
+ "t\t\t\t\t\t----------------------------------------------------------------------------------------------\n",
+ "\t\t\t\t\t1\t\t2\t\t3\t\t1\t\t2\t\t3\n",
+ "\n",
+ "\t------------------------------------------------------------------------------------------------------------------------------\n",
+ "\n",
+ "\tSteam flow, lb/hr\t\t22400\t\t\t\t\t\t17900\n",
+ "\tSteam pressure, psi in.Hg\t20\t\t9\t\t2\t\t20\t\t9\t\t2\n",
+ "\tSteam temp,degreeF\t\t\t258\t\t237\t\t217\t\t258\t\t237\t\t217\n",
+ "\ttdelT,degreeF\t\t\t20\t\t18\t\t22\t\t20\t\t18\t\t22\n",
+ "\tLiquor temp, degreeF\t\t\t238\t\t219\t\t195\t\t238\t\t219\t\t195\n",
+ "\tBPR, degreeF\t\t\t\t1\t\t2\t\t3\t\t1\t\t2\t\t3\n",
+ "\tVapor temp, degreeF\t\t\t237\t\t217\t\t192\t\t237\t\t215\t\t192\n",
+ "\tVapor pressure, pis/in.Hg\t9\t\t2\t\t10\t\t9\t\t2\t\t10\n",
+ "\tLambda, Btu/lb\t\t\t954\t\t965\t\t983\t\t954\t\t965\t\t983\n",
+ "\tLiquor in, lb/hr\t\t100000\t\t79400\t\t56900\t\t109000\t\t70000\t\t52400\n",
+ "\tLiqour out, lb/hr\t\t79400\t\t56900\t\t33300\t\t70000\t\t52400\t\t33300\n",
+ "\tEvaporation,lb/hr\t\t20600\t\t22500\t\t23500\t\t30000\t\t17600\t\t19100\n",
+ "\tdegreeBrix(out)\t\t\t\t\t\t\t\t\t\t\t\t\t30\n",
+ "\tCondenser water, gpm\t\t\t\t455\t\t\t\t\t\t365\n",
+ "\n",
+ "\n",
+ "\t\t\t\tHEAT BALANCE-STRAIGHT TRIPLE EFFECT\n",
+ "\t\t\t\tCondenser water = 455 gpm\n",
+ "\n",
+ "\t--------------------------------------------------------\n",
+ "\n",
+ "\tEffect\t\t\tBtu/hr\t\tEvaporation,l/hr\n",
+ "\n",
+ "\t--------------------------------------------------------\n",
+ "\n",
+ "\t1.a.Heat in steam\t\n",
+ "\t20424320.0\n",
+ "b.Heating liquor\t\n",
+ "\t736000.0\n",
+ "c.Evaporation\t\t Evaporation/954\t\n",
+ "\t19688320.0 20637.6519916\n",
+ "d.Liquor to 2d = 79362.3480084\n",
+ "total evapouriation 66700\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\texample 14.7\\n\"\n",
+ "print\"\\tapproximate values are mentioned in the book \\n\"\n",
+ "M2=14300;#From fig.14.43 and heat balance above\n",
+ "M1=32200-14300;#From fig.14.43 and heat balance above\n",
+ "print\"\\tM1 = lb\\n\",M1\n",
+ "print\"\\n\\t\\t\\t\\tEVAPORATOR SUMMARY\\n\"\n",
+ "print\"\\t------------------------------------------------------------------------------------------------------------------------------\\n\"\n",
+ "print\"\\tEffects\\t\\t\\t\\t\\tStraight triple effect\\t\\t\\t\\tThermocompression\\nt\\t\\t\\t\\t\\t----------------------------------------------------------------------------------------------\\n\\t\\t\\t\\t\\t1\\t\\t2\\t\\t3\\t\\t1\\t\\t2\\t\\t3\\n\"\n",
+ "print\"\\t------------------------------------------------------------------------------------------------------------------------------\\n\"\n",
+ "print\"\\tSteam flow, lb/hr\\t\\t22400\\t\\t\\t\\t\\t\\t17900\\n\\tSteam pressure, psi in.Hg\\t20\\t\\t9\\t\\t2\\t\\t20\\t\\t9\\t\\t2\\n\\tSteam temp,degreeF\\t\\t\\t258\\t\\t237\\t\\t217\\t\\t258\\t\\t237\\t\\t217\\n\\ttdelT,degreeF\\t\\t\\t20\\t\\t18\\t\\t22\\t\\t20\\t\\t18\\t\\t22\\n\\tLiquor temp, degreeF\\t\\t\\t238\\t\\t219\\t\\t195\\t\\t238\\t\\t219\\t\\t195\\n\\tBPR, degreeF\\t\\t\\t\\t1\\t\\t2\\t\\t3\\t\\t1\\t\\t2\\t\\t3\\n\\tVapor temp, degreeF\\t\\t\\t237\\t\\t217\\t\\t192\\t\\t237\\t\\t215\\t\\t192\\n\\tVapor pressure, pis/in.Hg\\t9\\t\\t2\\t\\t10\\t\\t9\\t\\t2\\t\\t10\\n\\tLambda, Btu/lb\\t\\t\\t954\\t\\t965\\t\\t983\\t\\t954\\t\\t965\\t\\t983\\n\\tLiquor in, lb/hr\\t\\t100000\\t\\t79400\\t\\t56900\\t\\t109000\\t\\t70000\\t\\t52400\\n\\tLiqour out, lb/hr\\t\\t79400\\t\\t56900\\t\\t33300\\t\\t70000\\t\\t52400\\t\\t33300\\n\\tEvaporation,lb/hr\\t\\t20600\\t\\t22500\\t\\t23500\\t\\t30000\\t\\t17600\\t\\t19100\\n\\tdegreeBrix(out)\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t30\\n\\tCondenser water, gpm\\t\\t\\t\\t455\\t\\t\\t\\t\\t\\t365\\n\"\n",
+ "print\"\\n\\t\\t\\t\\tHEAT BALANCE-STRAIGHT TRIPLE EFFECT\\n\\t\\t\\t\\tCondenser water = 455 gpm\\n\"\n",
+ "print\"\\t--------------------------------------------------------\\n\"\n",
+ "print\"\\tEffect\\t\\t\\tBtu/hr\\t\\tEvaporation,l/hr\\n\"\n",
+ "print\"\\t--------------------------------------------------------\\n\"\n",
+ "sf=22400;#lb/hr\n",
+ "lc=100000;#lb/hr\n",
+ "t1=238;#degreeF\n",
+ "t2=230;#degreeF\n",
+ "te=30000+17600+19100;\n",
+ "his=sf*940*0.97;#Btu/hr\n",
+ "hlq=lc*(t1-t2)*0.92;#Btu/hr\n",
+ "hd=his-hlq;#Btu/hr\n",
+ "eva=(hd)/954;#lb/hr\n",
+ "l2d=lc-eva;\n",
+ "print\"\\t1.a.Heat in steam\\t\\n\\t\" ,his \n",
+ "print\"b.Heating liquor\\t\\n\\t\",hlq\n",
+ "print\"c.Evaporation\\t\\t Evaporation/954\\t\\n\\t\",hd,eva \n",
+ "print\"d.Liquor to 2d = \",l2d\n",
+ "print\"total evapouriation\",te\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_15__Vaporizers_Evapourators_and_Reboilers.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_15__Vaporizers_Evapourators_and_Reboilers.ipynb
new file mode 100755
index 00000000..4b0ddf56
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_15__Vaporizers_Evapourators_and_Reboilers.ipynb
@@ -0,0 +1,1324 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 15 : Vaporizers Evapourators and Reboilers"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 15.1 pgno:463"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 15.1 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t total heat required for steam is : Btu/hr \t9453000.0\n",
+ "\t total heat required for kerosene is : Btu/hr \t9450000.0\n",
+ "\t delt1 is : F \t50\n",
+ "\t delt2 is : F \t150\n",
+ "\t LMTD is : F \t91.1262293169\n",
+ "\t A : ft**2 \t1037.02304713\n",
+ "\t By the law of mixtures \t\n",
+ "\t v2 : %.0f ft**3/lb \t11.0034\n",
+ "\t vav : ft**3/lb \t3.16417120715\n",
+ "\t By the approximate method \t\n",
+ "\t vav : ft**3/lb \t5.5102\n",
+ "\t actual density : lb/ft**3 \t0.316038524635\n",
+ "\t s : \t0.00505661639416\n",
+ "\t approximate density : lb/ft**3 \t0.316038524635\n",
+ "\t s : \t0.0029\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 15.1 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "ts=250;\n",
+ "T1=400;\n",
+ "T2=300;\n",
+ "w=10000; # lb/hr\n",
+ "W=150000; # lb/hr\n",
+ "l=945.3; # Btu/(lb) , table 7\n",
+ "from math import log10\n",
+ "Q=((w)*(l)); # Btu/hr\n",
+ "print\"\\t total heat required for steam is : Btu/hr \\t\",Q\n",
+ "C=0.63; # Btu/(lb)*(F)\n",
+ "Q=((W)*(C)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for kerosene is : Btu/hr \\t\",Q\n",
+ "delt1=T2-ts; #F\n",
+ "delt2=T1-ts; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "UD=100;\n",
+ "A=(Q/(UD*LMTD));\n",
+ "print\"\\t A : ft**2 \\t\",A\n",
+ "WC=94500; # Btu/F\n",
+ "vl=0.017; # ft**3/lb, from table 7\n",
+ "vv=13.75; # ft**3/lb, from table 7\n",
+ "print\"\\t By the law of mixtures \\t\"\n",
+ "# Assume 80 per cent of the outlet fluid is vapor\n",
+ "v2=(0.8*vv)+(.2*vl);\n",
+ "print\"\\t v2 : ft**3/lb \\t\",v2\n",
+ "vav=(WC*(v2-vl)/(UD*A))-((WC*(T2-ts)/(l*w))*(vv-vl))+vl;\n",
+ "print\"\\t vav : ft**3/lb \\t\",vav\n",
+ "print\"\\t By the approximate method \\t\"\n",
+ "vav1=(vl+v2)/(2);\n",
+ "print\"\\t vav : ft**3/lb \\t\",vav1\n",
+ "row=62.5;\n",
+ "rowac=(1/vav);\n",
+ "s=(rowac/row);\n",
+ "print\"\\t actual density : lb/ft**3 \\t\",rowac\n",
+ "print\"\\t s : \\t\",s\n",
+ "rowap=(1/vav1);\n",
+ "s=(rowap/row);\n",
+ "print\"\\t approximate density : lb/ft**3 \\t\",rowac\n",
+ "print\"\\t s : \\t\",round(s,4)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 15.2 pgno:464"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 15.2 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t total heat required for preheat of butane is : Btu/hr \t2124200\n",
+ "\t total heat required for vapourisation of butane is : Btu/hr \t2172500\n",
+ "\t total heat required for butane is : Btu/hr \t4296700\n",
+ "\t for steam \t\n",
+ "\t total heat required for steam is : Btu/hr \t4297328.0\n",
+ "\t Wp1 is : lb/hr \t13401.8927445\n",
+ "\t Wv1 is : lb/hr \t21092\n",
+ "\t W is : lb/hr \t34493.8927445\n",
+ "\t weighted delt is : % F \t124.582285677\n",
+ "\t caloric temperature of hot fluid is : F \t338\n",
+ "\t caloric temperature of cold fluid is : F \t171\n",
+ "\t hot fluid:inner tube side,steam \t\n",
+ "\t flow area is : ft**2 \t0.15675\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t31132.3763955\n",
+ "\t reynolds number is : \t62178.9886688\n",
+ "\t hio is : Btu/(hr)*(ft**2)*(F) \t1500\n",
+ "\t cold fluid:shell side,butane \t\n",
+ "\t preheating \t\n",
+ "\t flow area is : ft**2 \t0.105902777778\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t233232.786885\n",
+ "\t reynolds number is : \t69214.7658922\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t231.272727273\n",
+ "\t clean overall coefficient for preheating : Btu/(hr)*(ft**2)*(F) \t200.378071834\n",
+ "\t clean surface required for preheating : ft**2 \t66.883030772\n",
+ "\t for vapourisation \t\n",
+ "\t reynolds number is : \t79511.1773472\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t236.96969697\n",
+ "\t clean overall coefficient for vapourisation : Btu/(hr)*(ft**2)*(F) \t204.640614096\n",
+ "\t clean surface required for vapourisation : ft**2 \t103.069633088\n",
+ "\t total clean surface : ft**2 \t169.952663859\n",
+ "\t weighted clean overall coefficient : Btu/(hr)*(ft**2)*(F) \t202.96313674\n",
+ "\t total surface area is : ft**2 \t318.3488\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t108.352513798\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.00430213212754\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t0.16\n",
+ "\t allowable delPa is negligible \t\n",
+ "\t pressure drop for annulus \t\n",
+ "\t preheating \t\n",
+ "\t length of preheat zone : ft \t6.29662676683\n",
+ "\t number of crosses are : \t15.1119042404\n",
+ "\t delPsp is : psi \t0.703032923143\n",
+ "\t vapourisation \t\n",
+ "\t number of crosses are : \t23.28\n",
+ "\t delPsv is : psi \t1.89396418309\n",
+ "\t delPS is : psi \t2.6\n",
+ "\t allowable delPa is 5 psi \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 15.2 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "t1=108; # inlet cold fluid,F\n",
+ "t2=235; # outlet cold fluid,F\n",
+ "Ts=338;\n",
+ "Wp=24700; # lb/hr\n",
+ "Wv=19750; # lb/hr\n",
+ "w=4880; # lb/hr\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "Ht1=162; # enthalpy at t1, Btu/lb, fig 9\n",
+ "Ht2=248; # enthalpy at t2, Btu/lb, fig 9\n",
+ "qp=(Wp*(Ht2-Ht1)); # for preheat\n",
+ "print\"\\t total heat required for preheat of butane is : Btu/hr \\t\",qp\n",
+ "Ht3=358; # enthalpy of vapour at t2, Btu/lb, fig 9\n",
+ "qv=Wv*(Ht3-Ht2);\n",
+ "print\"\\t total heat required for vapourisation of butane is : Btu/hr \\t\",qv\n",
+ "Q=qp+qv;\n",
+ "print\"\\t total heat required for butane is : Btu/hr \\t\",Q\n",
+ "print\"\\t for steam \\t\"\n",
+ "l=880.6; # Btu/(lb), table 7\n",
+ "Q=((w)*(l)); # Btu/hr\n",
+ "print\"\\t total heat required for steam is : Btu/hr \\t\",Q\n",
+ "deltp=158.5; # F, from eq 5.14\n",
+ "deltv=103; # F eq 5.14\n",
+ "Wp1=(qp/deltp);\n",
+ "print\"\\t Wp1 is : lb/hr \\t\",Wp1\n",
+ "Wv1=(qv/deltv);\n",
+ "print\"\\t Wv1 is : lb/hr \\t\",Wv1\n",
+ "W=(Wp1+Wv1);\n",
+ "print\"\\t W is : lb/hr \\t\",W\n",
+ "delt=(Q/W);\n",
+ "print\"\\t weighted delt is : % F \\t\",delt\n",
+ "Tc=((Ts)+(Ts))/(2); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2))/(2); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:inner tube side,steam \\t\"\n",
+ "Nt=76;\n",
+ "n=2; # number of passes\n",
+ "L=16; #ft\n",
+ "at1=0.594; # flow area,table 10, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu1=0.0363; # at 338F, fig 15,lb/(ft)*(hr)\n",
+ "D=0.0725; # ft\n",
+ "Ret=((D)*(Gt)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hio=1500; # condensing steam,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t hio is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "print\"\\t cold fluid:shell side,butane \\t\"\n",
+ "print\"\\t preheating \\t\"\n",
+ "ID=15.25; # in\n",
+ "C=0.25; # clearance\n",
+ "B=5; # baffle spacing,in\n",
+ "PT=1.25;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(Wp/As); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu2=0.278; # at 172F,lb/(ft)*(hr), from fig.14\n",
+ "De=0.0825; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jH=159; # from fig.28\n",
+ "Z=0.12; # Z=k*((c)*(mu1)/k)**(1/3), fig 16\n",
+ "hop=((jH)*(1/De)*(Z)); #using eq.6.15b,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",hop\n",
+ "Up=((hio)*(hop)/(hio+hop)); # clean overall coefficient,eq 6.38,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient for preheating : Btu/(hr)*(ft**2)*(F) \\t\",Up\n",
+ "Ap=(qp/(Up*deltp));\n",
+ "print\"\\t clean surface required for preheating : ft**2 \\t\",Ap\n",
+ "print\"\\t for vapourisation \\t\"\n",
+ "mu2=0.242; # at 172F,lb/(ft)*(hr), from fig.14\n",
+ "Res=((De)*(Gs)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jH=170; # from fig.28\n",
+ "Z=0.115; # Z=k*((c)*(mu1)/k)**(1/3), fig 16\n",
+ "hov=((jH)*(1/De)*(Z)); #using eq.6.15b,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",hov\n",
+ "Uv=((hio)*(hov)/(hio+hov)); # clean overall coefficient,eq 6.38,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient for vapourisation : Btu/(hr)*(ft**2)*(F) \\t\",Uv\n",
+ "Av=(qv/(Uv*deltv));\n",
+ "print\"\\t clean surface required for vapourisation : ft**2 \\t\",Av\n",
+ "Ac=Ap+Av;\n",
+ "print\"\\t total clean surface : ft**2 \\t\",Ac\n",
+ "UC=((Up*Ap)+(Uv*Av))/(Ac);\n",
+ "print\"\\t weighted clean overall coefficient : Btu/(hr)*(ft**2)*(F) \\t\",UC\n",
+ "A2=0.2618; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "# A total of 170 ft2 are required of which 103 are to be used for vaporization. For the total surface required 318 ft2 will be provided. It can be assumed, then, that the surface provided for vaporization is 193ft**2\n",
+ "# then flux is Q/A=10700, which is with in satisfactory levels.\n",
+ "Rd=((UC-UD)/((UD)*(UC))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.000165; # friction factor for reynolds number 62000, using fig.26\n",
+ "s=0.00413;\n",
+ "phyt=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt)))/(2); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt,2)\n",
+ "print\"\\t allowable delPa is negligible \\t\"\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "print\"\\t preheating \\t\"\n",
+ "f=0.00145; # friction factor for reynolds number 69200, using fig.29\n",
+ "Lp=(L*Ap/Ac); #ft\n",
+ "print\"\\t length of preheat zone : ft \\t\",Lp\n",
+ "N=(12*Lp/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "s=0.5; # for reynolds number 69200,using fig.6\n",
+ "Ds=1.27; # fig 28\n",
+ "phys=1;\n",
+ "delPsp=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPsp is : psi \\t\",delPsp\n",
+ "print\"\\t vapourisation \\t\"\n",
+ "f=0.00142;\n",
+ "Lv=9.7; # Lv=L-Lp\n",
+ "Nv=(12*Lv/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",Nv\n",
+ "s=0.28; \n",
+ "delPsv=((f*(Gs**2)*(Ds)*(Nv))/(5.22*(10**10)*(De)*(s)*(1))); # using eq 12.47,psi\n",
+ "print\"\\t delPsv is : psi \\t\",delPsv\n",
+ "delPS=delPsp+delPsv;\n",
+ "print\"\\t delPS is : psi \\t\",round(delPS,2)\n",
+ "print\"\\t allowable delPa is 5 psi \\t\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 15.3 pgno:475"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 15.3 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t total heat required for gasoline is : Btu/hr \t2669500\n",
+ "\t total heat required for gasoil is : Btu/hr \t2671900.0\n",
+ "\t S is : \t0.428571428571\n",
+ "\t Tc is : F \t517.0\n",
+ "\t hot fluid:inner tube side,gasoil \t\n",
+ "\t flow area is : ft**2 \t0.0429722222222\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t807498.383969\n",
+ "\t reynolds number is : \t86215.9813038\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t374.063400576\n",
+ "\t Correct Hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t311.968876081\n",
+ "\t cold fluid:shell side,gasoline \t\n",
+ "\t tw is : F \t459.64414193\n",
+ "\t deltw : F \t59.6441419296\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t152.933697255\n",
+ "\t total surface area is : ft**2 \t213.6288\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t105.993294626\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.00289577777619\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t2.73790740915\n",
+ "\t delPr is : psi \t3.04225352113\n",
+ "\t delPT is : psi \t5.8\n",
+ "\t allowable delPa is 10psi \t\n",
+ "\t delPs is negligible \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 15.3 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "ts=400;\n",
+ "T1=575;\n",
+ "T2=475;\n",
+ "W=28100; # lb/hr\n",
+ "w=34700; # lb/hr\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "HT1=290; # enthalpy at T1, Btu/lb, fig 11\n",
+ "HT2=385; # enthalpy at T2, Btu/lb, fig 11\n",
+ "Q=(W*(HT2-HT1)); # for preheat\n",
+ "print\"\\t total heat required for gasoline is : Btu/hr \\t\",Q\n",
+ "c=0.77; # Btu/(lb), table 7\n",
+ "Q=((w)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for gasoil is : Btu/hr \\t\",Q\n",
+ "delt=118; # F eq 5.14\n",
+ "S=75./175.;#((T2-ts)/(T1-ts));\n",
+ "print\"\\t S is : \\t\",S\n",
+ "Kc=0.37; # fig 17\n",
+ "Fc=0.42;\n",
+ "Tc=(T2+(0.42*(T1-T2)));\n",
+ "print\"\\t Tc is : F \\t\",Tc\n",
+ "print\"\\t hot fluid:inner tube side,gasoil \\t\"\n",
+ "Nt=68;\n",
+ "n=6; # number of passes\n",
+ "L=12; #ft\n",
+ "at1=0.546; # flow area,table 10, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu1=0.65; # at 517F, fig 14,lb/(ft)*(hr)\n",
+ "D=0.0694; # ft\n",
+ "Ret=((D)*(Gt)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "jH=220; # from fig.24\n",
+ "Z=0.118; # Z=k*((c)*(mu1)/k)**(1/3), fig 16\n",
+ "Hi=((jH)*(1/D)*(Z)); #hi/phyt, Hi=()using eq.6.15d,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Hi\n",
+ "Hio=((Hi)*(0.834/1)); #Hio=(hio/phyp), using eq.6.9\n",
+ "print\"\\t Correct Hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",Hio\n",
+ "# (mu1/muw)**(0.14) is negligible\n",
+ "print\"\\t cold fluid:shell side,gasoline \\t\"\n",
+ "ho=300; # assumption\n",
+ "tw=(ts)+(((Hio)/(Hio+ho))*(Tc-ts)); # from eq.5.31\n",
+ "print\"\\t tw is : F \\t\",tw\n",
+ "deltw=(tw-ts);\n",
+ "print\"\\t deltw : F \\t\",deltw\n",
+ "# from fig 15.11, ho>300\n",
+ "Uc=((Hio)*(ho)/(Hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "A2=0.2618; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "# check for max. flux=Q/A=12500.(satisfactory)\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.00015; # friction factor for reynolds number 85700, using fig.26\n",
+ "s=0.71;\n",
+ "phyt=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",delPt\n",
+ "X1=0.09; # X1=((V**2)/(2*g)), for Gt 1060000,using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \\t\",delPr\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \\t\",round(delPT,1)\n",
+ "print\"\\t allowable delPa is 10psi \\t\"\n",
+ "print\"\\t delPs is negligible \\t\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 15.4 pgno:482"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 15.4\t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t qv is : Btu/hr \t3654000\n",
+ "\t qs is : Btu/hr \t539000\n",
+ "\t total heat required for naphtha is : Btu/hr \t4193000\n",
+ "\t total heat required for gasoil is : Btu/hr \t4207500.0\n",
+ "\t delt1 is : F \t85.0\n",
+ "\t delt2 is : F \t190.0\n",
+ "\t LMTD is : F \t130.683201952\n",
+ "\t R is : \t6.25\n",
+ "\t S is : \t0.0952380952381\n",
+ "\t FT is 0.97 \t\n",
+ "\t delt is : F \t126.762705893\n",
+ "\t ratio of two local temperature difference is : \t0.447368421053\n",
+ "\t caloric temperature of hot fluid is : F \t451.25\n",
+ "\t caloric temperature of cold fluid is : F \t323.2\n",
+ "\t hot fluid:inner tube side,steam \t\n",
+ "\t flow area is : ft**2 \t0.0549791666667\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t927624.100038\n",
+ "\t reynolds number is : \t59146.6742685\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t343.251798561\n",
+ "\t Correct Hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t286.272\n",
+ "\t cold fluid:shell side,naphtha \t\n",
+ "\t tw is : F \t398.584002369\n",
+ "\t deltw : F \t75.384002369\n",
+ "\t qv/hv : \t12180\n",
+ "\t qs/hs : \t8983\n",
+ "\t A : \t21163\n",
+ "\t ho : \t198.813967774\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t117.329454908\n",
+ "\t total surface area is : ft**2 \t364.4256\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t91.0801518561\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.00245633150105\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t5.24018227225\n",
+ "\t delPr is : psi \t4.82191780822\n",
+ "\t delPT is : psi \t10.1\n",
+ "\t allowable delPa is negligible \t\n",
+ "\t pressure drop for annulus \t\n",
+ "\t flow area : in**2 \t131.70828125\n",
+ "\t wetted perimeter : in \t236.7325\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t20992.3664122\n",
+ "\t reynolds number is : \t59146.6742685\n",
+ "\t delPs is : psi \t0.25\n",
+ "\t allowable delPa is 10 psi \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 15.4\\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "t1=315.; # inlet cold fluid,F\n",
+ "t2=335.; # outlet cold fluid,F\n",
+ "T1=525.;\n",
+ "T2=400.;\n",
+ "Wv=29000; # lb/hr\n",
+ "Ws=38500; # lb/hr\n",
+ "w=51000; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "Ht1=238; # enthalpy at t1, Btu/lb, fig 9\n",
+ "Ht2=252; # enthalpy at t2, Btu/lb, fig 9\n",
+ "Ht3=378; # enthalpy of vapour at t2 \n",
+ "qv=(Wv*(Ht3-Ht2)); # for preheat\n",
+ "print\"\\t qv is : Btu/hr \\t\",qv\n",
+ "qs=Ws*(Ht2-Ht1);\n",
+ "print\"\\t qs is : Btu/hr \\t\",qs\n",
+ "Q=qs+qv;\n",
+ "print\"\\t total heat required for naphtha is : Btu/hr \\t\",Q\n",
+ "c=0.66; # Btu/(lb)(F)\n",
+ "Q=((w)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for gasoil is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \\t\",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \\t\",S\n",
+ "print\"\\t FT is 0.97 \\t\" # from fig 18\n",
+ "delt=(0.97*LMTD); # F\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "X=((delt1)/(delt2)); # fig 17\n",
+ "print\"\\t ratio of two local temperature difference is : \\t\",X\n",
+ "Fc=0.41; # from fig.17\n",
+ "Kc=0.42;\n",
+ "Tc=((T2)+((Fc)*(T1-T2))); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+((Fc)*(t2-t1))); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:inner tube side,steam \\t\"\n",
+ "Nt=116;\n",
+ "n=8; # number of passes\n",
+ "L=12; #ft\n",
+ "at1=0.546; # flow area,table 10, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu1=1.09; # at 451F, fig 14,lb/(ft)*(hr)\n",
+ "D=0.0695; # ft\n",
+ "Ret=((D)*(Gt)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "jH=168; # from fig.24\n",
+ "Z=0.142; # Z=k*((c)*(mu1)/k)**(1/3), fig 16\n",
+ "Hi=((jH)*(1/D)*(Z)); #, Hi=(hi/phyt)using eq.6.15d,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Hi\n",
+ "Hio=((Hi)*(0.834/1)); #Hio=(hio/phyp), using eq.6.9\n",
+ "print\"\\t Correct Hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",Hio\n",
+ "print\"\\t cold fluid:shell side,naphtha \\t\"\n",
+ "ho1=200; # assumption\n",
+ "tw=(tc)+(((Hio)/(Hio+ho1))*(Tc-tc)); # from eq.5.31, calculation mistake\n",
+ "print\"\\t tw is : F \\t\",tw\n",
+ "deltw=(tw-tc);\n",
+ "print\"\\t deltw : F \\t\",deltw\n",
+ "# from fig 15.11, hv>300, hs=60\n",
+ "Av=(qv/300);\n",
+ "As=qs/60;\n",
+ "print\"\\t qv/hv : \\t\",Av\n",
+ "print\"\\t qs/hs : \\t\",As\n",
+ "A1=As+Av;\n",
+ "print\"\\t A : \\t\",A1\n",
+ "ho=(Q/A1);\n",
+ "print\"\\t ho : \\t\",ho\n",
+ "Uc=((Hio)*(ho)/(Hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "A2=0.2618; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "# check for max. flux=Q/A=11500.(satisfactory)\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.000168; # friction factor for reynolds number 59200, using fig.26\n",
+ "s=0.73;\n",
+ "phyt=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",delPt\n",
+ "X1=0.11; # X1=((V**2)/(2*g)), for Gt 1060000,using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \\t\",delPr\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \\t\",round(delPT,1)\n",
+ "print\"\\t allowable delPa is negligible \\t\"\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "Af=(3.14*(21.25**2-(116))/8);\n",
+ "print\"\\t flow area : in**2 \\t\",Af\n",
+ "As=0.917; # ft**2\n",
+ "p=(3.14*21.25/2)+(3.14*1*116/2)+(21.25)\n",
+ "print\"\\t wetted perimeter : in \\t\",p\n",
+ "De=0.186; # ft\n",
+ "Gs=(Ws/(2*As)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu2=0.435; # at 315F, fig 14,lb/(ft)*(hr)\n",
+ "Res=((De)*(Gs)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "f=0.00028; # using fig.26\n",
+ "row=0.337; # fig 13.14\n",
+ "# soutlet max=0.071,\n",
+ "s=0.35; # using fig.6\n",
+ "phys=1;\n",
+ "delPs=0.25 #((f*(Gs**2)*(L))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",delPs\n",
+ "print\"\\t allowable delPa is 10 psi \\t\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 15.5 pgno:488"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 15.5\t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t total heat required for butane is : Btu/hr \t3957600\n",
+ "\t total heat required for steam is : Btu/hr \t3966760\n",
+ "\t trail 1 \t\n",
+ "\t A1 is : ft**2 \t330\n",
+ "\t number of tubes are : \t105.068772287\n",
+ "\t total surface area is : ft**2 \t342.3472\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t92.6956025929\n",
+ "\t vapour density : lb/ft**3 \t3.18723589714\n",
+ "\t weight flow of recirculated liquid : lb/hr \t163200\n",
+ "\t volume of liquid : ft**3 \t6071.04\n",
+ "\t volume of vapour : ft**3 \t17952.0\n",
+ "\t total volume out of reboiler : ft**3 \t24023.04\n",
+ "\t vo is : ft**3/lb \t0.11776\n",
+ "\t pressure leg : psi \t1.58756230188\n",
+ "\t frictional resistance \t\n",
+ "\t flow area is : ft**2 \t0.228597222222\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t892399.295218\n",
+ "\t reynolds number is : \t190648.940342\n",
+ "\t delPt is : psi \t2.1\n",
+ "negilgable\n",
+ "\t total resisitance : psi \t3.69151627479\n",
+ "\t driving force : psi \t2.98611111111\n",
+ "\t trial 2 \t\n",
+ "\t A1 is : ft**2 \t330\n",
+ "\t number of tubes are : \t140.091696383\n",
+ "\t total surface area is : ft**2 \t355.6956\n",
+ "\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t89.21695967\n",
+ "\t pressure leg : psi \t1.19067172641\n",
+ "\t frictional resistance \t\n",
+ "\t flow area is : ft**2 \t0.316680555556\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t644182.272707\n",
+ "\t reynolds number is : \t137620.75826\n",
+ "\t delPt is : psi \t0.874030618788\n",
+ "\t total resisitance : psi \t2.0647023452\n",
+ "\t driving force : psi \t2.23958333333\n",
+ "\t hot fluid : shell side,steam \t\n",
+ "\t cold fluid:inner tube side, butane \t\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t734.042553191\n",
+ "\t Correct Hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t248.0\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t212.814645309\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.006537030325\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 15.5\\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "W=40800; # lb/hr\n",
+ "w=4570; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "Ht1=241; # enthalpy of liquid at 228F, Btu/lb, fig 9\n",
+ "Ht2=338; # enthalpy of vapourat 228F, Btu/lb, fig 9\n",
+ "Q=(W*(Ht2-Ht1));\n",
+ "print\"\\t total heat required for butane is : Btu/hr \\t\",Q\n",
+ "l=868; # Btu/(lb), table 7\n",
+ "Q=((w)*(l)); # Btu/hr\n",
+ "print\"\\t total heat required for steam is : Btu/hr \\t\",Q\n",
+ "delt=125; # delt=LMTD, isothermal boiling, eq 5.14\n",
+ "# Tc and tc: Both streams are isuthermal\n",
+ "print\"\\t trail 1 \\t\"\n",
+ "A1=((Q)/((12000))); # Q/A1 =12000, first trial should always be taken for the maximum allowable flux\n",
+ "print\"\\t A1 is : ft**2 \\t\",A1\n",
+ "a1=0.1963; # ft**2/lin ft\n",
+ "L=16;\n",
+ "N1=(A1/(L*a1)); # table 10\n",
+ "print\"\\t number of tubes are : \\t\",N1\n",
+ "N2=109; # assuming one tube passes, 13.25-in ID, from table 9\n",
+ "A2=(N2*L*a1); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A2\n",
+ "UD=((Q)/((A2)*(delt)));\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "# Assume 4: 1 recirculation ratio\n",
+ "rowv=(58/(359*(688/492)*(14.7/290))); # eq 15.18\n",
+ "print\"\\t vapour density : lb/ft**3 \\t\",rowv\n",
+ "Vv=0.44; \n",
+ "Vl=0.0372; # fig 6\n",
+ "W1=4*W;\n",
+ "print\"\\t weight flow of recirculated liquid : lb/hr \\t\",W1\n",
+ "VL=W1*Vl;\n",
+ "VV=W*Vv;\n",
+ "print\"\\t volume of liquid : ft**3 \\t\",VL\n",
+ "print\"\\t volume of vapour : ft**3 \\t\",VV\n",
+ "V=VL+VV;\n",
+ "print\"\\t total volume out of reboiler : ft**3 \\t\",V\n",
+ "vo=(V/(W1+W));\n",
+ "print\"\\t vo is : ft**3/lb \\t\",vo\n",
+ "Pl=((2.3*16)/(144*(vo-Vl)))*(log10(vo/Vl));\n",
+ "print\"\\t pressure leg : psi \\t\",Pl\n",
+ "print\"\\t frictional resistance \\t\"\n",
+ "Nt=109;\n",
+ "n=1; # number of passes\n",
+ "at1=0.302; # flow area,table 10, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=((W1+W)/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu1=0.242; # at 228F, fig 14,lb/(ft)*(hr)\n",
+ "D=0.0517; # ft\n",
+ "Ret=((D)*(Gt)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "f=0.000127; # using fig.26\n",
+ "s=0.285;\n",
+ "phyt=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt,2)\n",
+ "P=Pl+delPt;\n",
+ "print\"negilgable\"\n",
+ "print\"\\t total resisitance : psi \\t\",P\n",
+ "F=(16*0.43*62.5/144);\n",
+ "print\"\\t driving force : psi \\t\",F\n",
+ "# The resistances are greater than the hydrostatic head can provide; hence the recirculation ratio will be less than 4: 1\n",
+ "print\"\\t trial 2 \\t\" # Assume 12'0\" tubes and 4:1 recirculation ratio\n",
+ "A1=((Q)/((12000))); # Q/A1 =12000, first trial should always be taken for the maximum allowable flux\n",
+ "print\"\\t A1 is : ft**2 \\t\",A1\n",
+ "a1=0.1963; # ft**2/lin ft\n",
+ "L=12;\n",
+ "N1=(A1/(L*a1)); # table 10\n",
+ "print\"\\t number of tubes are : \\t\",N1\n",
+ "N2=151; # assuming one tube passes, 15.25-in ID, from table 9\n",
+ "A2=(N2*L*a1); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A2\n",
+ "UD=((Q)/((A2)*(delt)));\n",
+ "print\"\\t correct design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "Pl=((2.3*12)/(144*(vo-Vl)))*(log10(vo/Vl));\n",
+ "print\"\\t pressure leg : psi \\t\",Pl\n",
+ "print\"\\t frictional resistance \\t\"\n",
+ "Nt=151;\n",
+ "n=1; # number of passes\n",
+ "at1=0.302; # flow area,table 10, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=((W1+W)/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu1=0.242; # at 228F, fig 14,lb/(ft)*(hr)\n",
+ "D=0.0517; # ft\n",
+ "Ret=((D)*(Gt)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "f=0.000135; # using fig.26\n",
+ "s=0.285;\n",
+ "phyt=1;\n",
+ "delPt=((f*(Gt**2)*(12)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",delPt\n",
+ "P=Pl+delPt;\n",
+ "print\"\\t total resisitance : psi \\t\",P\n",
+ "F=(12*0.43*62.5/144);\n",
+ "print\"\\t driving force : psi \\t\",F\n",
+ "# Since the driving force is slightly greater than the resistances, a recirculation ratio better than 4:1 is assured.\n",
+ "print\"\\t hot fluid : shell side,steam \\t\"\n",
+ "ho=1500; # condensing steam\n",
+ "print\"\\t cold fluid:inner tube side, butane \\t\"\n",
+ "jH=330; # from fig.24\n",
+ "Z=0.115; # Z=k*((c)*(mu1)/k)**(1/3), fig 16\n",
+ "Hi=((jH)*(1/D)*(Z)); #, Hi=(hi/phyt)using eq.6.15d,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Hi\n",
+ "Hio=((300)*(0.62/0.75)); #Hio=(hio/phyp), using eq.6.9\n",
+ "print\"\\t Correct Hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",Hio\n",
+ "Uc=((Hio)*(ho)/(Hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "UD=89;\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 15.6 pgno492"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 15.6\t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t total heat duty : Btu/hr \t5799016.0\n",
+ "\t total heat duty : lb/hr \t37902.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 15.6\\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "#20000=WD+WB;\n",
+ "#0.99*WD+(0.05*WB)=(20000*.5);\n",
+ "# solving above two eq. we get WD and WB\n",
+ "WD=9570; # lb/hr\n",
+ "WB=10430; # lb/hr\n",
+ "HBl=108; # fig 3 and 12\n",
+ "HDl=85.8; #fig 3 and 12\n",
+ "HDv=253.8; # fig 3 and 12\n",
+ "HFl=92; # fig 3 and 12\n",
+ "l=153; # fig 3 and 12\n",
+ "QR=((2.54+1)*WD*(HDv))-(2.54*WD*HDl)+(WB*HBl)-(20000*HFl);\n",
+ "print\"\\t total heat duty : Btu/hr \\t\",round(QR)\n",
+ "Q=QR/153;\n",
+ "print\"\\t total heat duty : lb/hr \\t\",round(Q)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Example 15.7 pgno:502"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 15.7 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\ttotal Lb/hr is \t20000\n",
+ "\ttotal Mol/hr is \t235.5\n",
+ "\tx1 of C6H6 is \t0.543524416136\n",
+ "\tx1 of C7H8 is \t0.456475583864\n",
+ "\tTotal x1 is \t1.0\n",
+ "\tx1Pp1 of C6H6 is \t750.063694268\n",
+ "\tx1Pp1 of C7H8 is \t262.473460722\n",
+ "\tTotal x1Pp1 is \t1012.53715499\n",
+ "\ty1 of C6H6 is \t0.740776464914\n",
+ "\ty1 of C7H8 is \t0.259223535086\n",
+ "\tTotal y1 is \t1.0\n",
+ "\t(WR`/V =((xD - yF)/.(xD - xF))) = mol/mol\t0.558\n",
+ "\tWR` = %.2f (mol reflux)/(mol distillate)\t1.27\n",
+ "\tAssumed 200 percent of the theoretical minimum reflux as economic\t\tWR = (mol)/(mil distillate)\t2.54\n",
+ "\tThe intercept for the upper operating line = \t0.280225988701\n",
+ "\tConnecting the corresponding line in Fig. 15.23, plates required: \t13\n",
+ "\tFeed plate is th(from top)\t7\n",
+ "\tTotal reflux is \t311.15\n",
+ "\t\t\t\t\tHeat balances\n",
+ "\t\t\t\t\tMol/hr\tMol.wt.\tLb/hr\tTemp,DegF\tBtu/lb\tBtu/hr\t\t________________________________________________________________________\t\tHeat balance \t\taround condenser:\t\n",
+ "\t Heat in:\t\t Top plate vapor.......433\t87.3\t\t195\t%.1f\t\t33900 253.8 8603820.0\n",
+ "\t Heat out:\t\t Distillate............\n",
+ "122.5\t78.3\t\t195\t\t\t9570 85.8 821106.0\n",
+ "\t Reflux................\n",
+ "310.5\t78.3\t\t195\t\t\t24330 85.8 2087514.0\n",
+ "\t Condenser duty, by\t\t difference........... ..... .... ...... ..\n",
+ ". ..... 5688000\t\n",
+ "\t\t\t\t\t\t\t\t\t_______\t\t\t\t\t\t\t\t\t\t8600000\t\t\n",
+ "\tReboiler vapor is lb/hr\t37908\n",
+ "\tTrapout is lb/hr\t48338\n",
+ "\t\t\t\t\tMol/hr\tMol.wt.\tLb/hr\tTemp,DegF\tBtu/lb\tBtu/hr\t\t________________________________________________________________________\t\n",
+ "\tHeat in:\t\t Trapout...............522\t92.8\t\t246\t108.0\t5230000\t48338\n",
+ "\t Reboiler duty, \t\t by difference....... .... .... ..... ... ..... 5800000\t\n",
+ "\t\t\t\t\t\t\t\t\t_______\t\t\t\t\t\t\t\t\t\t11030000\t\t\n",
+ "\t\tReboiler requirements are\t\n",
+ "\t\tTotal liquid to reboiler\t48330 lb/hr\t\t\tVaporization\t\t\t37900 lb/hr\t\t\tTemperature(nearly isothermal)\t246DegF\t\t\tPressure\t\t\t5 psig\t\t\tHeat load\t\t\t5800000 Btu/hr\t\n",
+ "total heat out is btu/hr 7640000\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 15.7 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "\n",
+ "#Basis: One hour\n",
+ "#20000=WD+WB , material balance\n",
+ "#0.99*WD+(0.05*WB)=(20000*0.5) , Benzene balance\n",
+ "# solving above two eq. we get WD and WB\n",
+ "WD=9570; # lb/hr\n",
+ "WB=10430; # lb/hr\n",
+ "\n",
+ "#Compositions and Boiling Points\n",
+ "#Feed\n",
+ "l1 = 10000; #Lb/hr , C6H4\n",
+ "l2 = 10000; #Lb/hr , C7H8\n",
+ "lb = l1+l2; #Lb/hr\n",
+ "print\"\\ttotal Lb/hr is \\t\",lb\n",
+ "mo1 = 78.1; #Mol. wt., C6H6\n",
+ "mo2 = 93.1; #Mol. wt , C7H8\n",
+ "mh1 = 128.0; #Mol/hr , C6H6\n",
+ "mh2 = 107.5; #Mol/hr , C7H8\n",
+ "mh = mh1 + mh2; # Mol/hr\n",
+ "print\"\\ttotal Mol/hr is \\t\",mh\n",
+ "x1 = mh1/mh;\n",
+ "print\"\\tx1 of C6H6 is \\t\",x1\n",
+ "x2 = mh2/mh;\n",
+ "print\"\\tx1 of C7H8 is \\t\",x2\n",
+ "x = x1+x2;\n",
+ "print\"\\tTotal x1 is \\t\",x\n",
+ "Pp1= 1380; # 214Deg F\n",
+ "Pp2=575; # 214Deg F\n",
+ "xp1 = x1*Pp1;\n",
+ "print\"\\tx1Pp1 of C6H6 is \\t\",xp1\n",
+ "xp2 = x2*Pp2;\n",
+ "print\"\\tx1Pp1 of C7H8 is \\t\",xp2\n",
+ "sxp = xp1 + xp2;\n",
+ "print\"\\tTotal x1Pp1 is \\t\",sxp\n",
+ "y1 = xp1/sxp;\n",
+ "print\"\\ty1 of C6H6 is \\t\",y1\n",
+ "y2 = xp2/sxp;\n",
+ "print\"\\ty1 of C7H8 is \\t\",y2\n",
+ "y = y1+y2;\n",
+ "print\"\\tTotal y1 is \\t\",y\n",
+ "\n",
+ "\n",
+ "w1 = 0.558; #from eq 15.42\n",
+ "print\"\\t(WR`/V =((xD - yF)/.(xD - xF))) = mol/mol\\t\",w1\n",
+ "wD=1;\n",
+ "xD = 0.992;\n",
+ "#V = WR' + WD\n",
+ "# WR'/V = 0.558\n",
+ "#Solving, WR' = (WR' * 0.558) + (0.558 * WD)\n",
+ "Wr = 1.27; # mol reflux/mol distillate\n",
+ "print\"\\tWR` = %.2f (mol reflux)/(mol distillate)\\t\",Wr\n",
+ "Wr1 = Wr * 2; # mol/ mol distillate\n",
+ "print\"\\tAssumed 200 percent of the theoretical minimum reflux as economic\\t\\tWR = (mol)/(mil distillate)\\t\",Wr1\n",
+ "In = (wD * xD)/(Wr1 + 1); #intercept for the upper operating line\n",
+ "print\"\\tThe intercept for the upper operating line = \\t\",In\n",
+ "p = 13; # From fig. 15.23, connecting the corresponding lines\n",
+ "print\"\\tConnecting the corresponding line in Fig. 15.23, plates required: \\t\",p\n",
+ "fp = 7; # From fig. 15.23, connecting the corresponding lines\n",
+ "print\"\\tFeed plate is th(from top)\\t\",fp\n",
+ "d=122.5;\n",
+ "tf = Wr1 * d;\n",
+ "print\"\\tTotal reflux is \\t\",tf\n",
+ "print\"\\t\\t\\t\\t\\tHeat balances\"\n",
+ "\n",
+ "#Heat Balances\n",
+ "l1 = 33900;\n",
+ "l2 = 9570;\n",
+ "l3 = 24330;\n",
+ "b1 = 253.8;\n",
+ "b2 = 85.8;\n",
+ "b3 = 85.8;\n",
+ "bt1 = b1*l1;\n",
+ "bt2 = b2*l2;\n",
+ "bt3 = b3*l3;\n",
+ "bt4 = 5688000;\n",
+ "print\"\\t\\t\\t\\t\\tMol/hr\\tMol.wt.\\tLb/hr\\tTemp,DegF\\tBtu/lb\\tBtu/hr\\t\\t________________________________________________________________________\\t\\tHeat balance \\t\\taround condenser:\\t\"\n",
+ "print\"\\t Heat in:\\t\\t Top plate vapor.......433\\t87.3\\t\\t195\\t%.1f\\t\\t\",l1,b1,bt1\n",
+ "print\"\\t Heat out:\\t\\t Distillate............\"\n",
+ "print\"122.5\\t78.3\\t\\t195\\t\\t\\t\",l2,b2,bt2\n",
+ "print\"\\t Reflux................\"\n",
+ "print\"310.5\\t78.3\\t\\t195\\t\\t\\t\",l3,b3,bt3\n",
+ "print\"\\t Condenser duty, by\\t\\t difference........... ..... .... ...... ..\"\n",
+ "print\". ..... 5688000\\t\"\n",
+ "print\"\\t\\t\\t\\t\\t\\t\\t\\t\\t_______\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t8600000\\t\\t\"\n",
+ "tho=7640000;\n",
+ "\n",
+ "lam = 153; # At 246 DegF, Btu/hr\n",
+ "rv = 5800000/153; #Lb/hr\n",
+ "print\"\\tReboiler vapor is lb/hr\\t\",rv\n",
+ "to = rv + 10430; #Lb/hr\n",
+ "print\"\\tTrapout is lb/hr\\t\",to\n",
+ "\n",
+ "print\"\\t\\t\\t\\t\\tMol/hr\\tMol.wt.\\tLb/hr\\tTemp,DegF\\tBtu/lb\\tBtu/hr\\t\\t________________________________________________________________________\\t\"\n",
+ "print\"\\tHeat in:\\t\\t Trapout...............522\\t92.8\\t\\t246\\t108.0\\t5230000\\t\",to\n",
+ "print\"\\t Reboiler duty, \\t\\t by difference....... .... .... ..... ... ..... 5800000\\t\"\n",
+ "print\"\\t\\t\\t\\t\\t\\t\\t\\t\\t_______\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t11030000\\t\\t\"\n",
+ "print\"\\t\\tReboiler requirements are\\t\"\n",
+ "print\"\\t\\tTotal liquid to reboiler\\t48330 lb/hr\\t\\t\\tVaporization\\t\\t\\t37900 lb/hr\\t\\t\\tTemperature(nearly isothermal)\\t246DegF\\t\\t\\tPressure\\t\\t\\t5 psig\\t\\t\\tHeat load\\t\\t\\t5800000 Btu/hr\\t\"\n",
+ "print\"total heat out is btu/hr\",tho \n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 15.8 pgno:506"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 15.8 \n",
+ "\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\n",
+ "\t\tDEW POINT OF OVERHEAD\n",
+ "\n",
+ "\t\tMol/hr\t\tK(148DegF,40 psia)\tV/K\n",
+ "\n",
+ "\t\t--------------------------------------------\n",
+ "\n",
+ "[ 6.4 219.7 2.3] [ 2.8 1.01 0.34] [ 17 221 74]\n",
+ "\n",
+ "\t\tBUBBLE POINTS OF BOTTOMS\n",
+ "\n",
+ "\t\tMol/hr\t\tK(330DegF,40psia)\t\tKL\t\tLb/hr\n",
+ "\n",
+ "\t\t--------------------------------------------------------------\n",
+ "\n",
+ "4.1 5.8 23.8 1700\n",
+ "49.3 3.0 148.0 13900\n",
+ "71.9 1.68 120.0 13030\n",
+ "52.5 0.98 51.4 6260\n",
+ "54.7 0.57 31.2 4240\n",
+ "82.5 0.35 28.9 4330\n",
+ "76.6 0.21 16.1 2640\n",
+ "22.4 0.13 2.9 520\n",
+ "\t\t____\t\t\t\t\t____\t\t____\n",
+ "\n",
+ "\t\t[ 4 53 124 176 230 312 388 410]\n",
+ "\t\t\t\t\t[23.800000000000001, 171.80000000000001, 291.80000000000001, 343.19999999999999, 374.39999999999998, 403.29999999999995, 419.39999999999998, 422.29999999999995]\n",
+ "\t\t[ 1700 13900 13030 6260 4240 4330 2640 520]\n",
+ "\tAverage mol. wt. \n",
+ "[ 71.42857143 80.9080326 44.65387252 18.24009324 11.32478632\n",
+ " 10.7364245 6.29470672 1.23135212]\n",
+ "\n",
+ "\n",
+ "\t\t\t\t\t\tHEAT BALANCES:\n",
+ "\n",
+ "\t\t\t\tMol/hr\t\tMol.wt.\t\tLb/hr\t\tTemp,DegF\t\tBtu/lb\t\tBtu/hr\n",
+ "\t\n",
+ "\t\t\t----------------------------------------------------------------------------------------\n",
+ "\n",
+ "\tHeat Balance onCondeser\n",
+ "\t Heat in:\n",
+ "\t Top plate vapor......\n",
+ "\n",
+ "\n",
+ "\t\tCALCULATION OF BOTTOM PLATE TEMPERATURE\n",
+ "\n",
+ "\t\ty*\t\t\tReboiler vapor\t\t\t\tK(300DegF,40psia)\tMol*K\n",
+ "\t\t\t\tV = y*205.7 +\tBottoms\t=\tTrapout\n",
+ "\n",
+ "\t\t----------------------------------------------------------------------------------------\n",
+ "\n",
+ "CALCULATION OF BOTTOM PLATE TEMPERATURE\n",
+ " y* Reboiler vapor K(300DegF,40psia) Mol*K\n",
+ " V = y*205.7 + Bottoms = Trapout\n",
+ " ----------------------------------------------------------------------------------------\n",
+ "C5 0.056 11.5 4.1 15.6 4.5 70.29\n",
+ "C6 0.35 72.0 49.3 121.3 2.25 272.91\n",
+ "C7 0.285 58.6 71.9 130.5 1.2 156.63\n",
+ "C8 0.122 25.1 52.5 77.6 0.66 51.21\n",
+ "C9 0.074 15.2 54.7 69.9 0.38 26.57\n",
+ "C10 0.068 14.0 82.5 96.5 0.22 21.23\n",
+ "C11 0.038 7.8 76.6 84.4 0.13 10.97\n",
+ "C12 0.007 1.4 22.4 23.8 0.07 1.67\n",
+ "----------------------------------------------------------------------------------------\n",
+ "1.000 205.7 414.0 619.7 611.5\n",
+ "Reboiler requirements are\n",
+ " Vaporization lb/hr 22700\n",
+ " Total liquor to reboiler lb/hr 78177\n",
+ " Heat load Btu/hr 4280000\n",
+ " Temperature range 300-330 def F\n",
+ " Operating pressure psi 40\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 15.8 \\n\"\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#Dew point of Overhead\n",
+ "import numpy\n",
+ "vc=numpy.array([6.4, 219.7, 2.3])\n",
+ "#vc(1) = 6.4; # Mol/hr\n",
+ "#vc(2) = 219.7; #Mol/hr\n",
+ "#vc(3) = 2.3; #Mol/hr\n",
+ "K=numpy.array([2.8, 1.01, 0.34])\n",
+ "#K(1) = 2.8; #at 148DegF and 40 psia\n",
+ "#K(2) = 1.01; #at 148DegF and 40 psia\n",
+ "#K(3) = 0.34; #at 148DegF and 40 psia\n",
+ "v=numpy.array([0, 0, 0])\n",
+ "i=0;\n",
+ "while (i<3):\n",
+ " v[0]=vc[0]*K[0];\n",
+ " v[1]=vc[1]*K[1];\n",
+ " v[2]=vc[1]*K[2];\n",
+ " i=i+1;\n",
+ "\n",
+ "\n",
+ "print\"\\n\\t\\tDEW POINT OF OVERHEAD\"\n",
+ "print\"\\n\\t\\tMol/hr\\t\\tK(148DegF,40 psia)\\tV/K\\n\"\n",
+ "print\"\\t\\t--------------------------------------------\\n\"\n",
+ "\n",
+ "\n",
+ "print vc,K,v\n",
+ "\n",
+ "bc=numpy.array([4.1, 49.3, 71.9, 52.5, 54.7, 82.5, 76.6, 22.4])\n",
+ "#bc(1)=4.1; #Mol/hr\n",
+ "#bc(2)=49.3; #Mol/hr\n",
+ "#c(3)=71.9; #Mol/hr\n",
+ "#bc(4)=52.5; #Mol/hr\n",
+ "#bc(5)=54.7; #Mol/hr\n",
+ "#bc(6)=82.5; #Mol/hr\n",
+ "#bc(7)=76.6; #Mol/hr\n",
+ "#bc(8)=22.4; #Mol/hr\n",
+ "tbc=numpy.array([0, 0, 0, 0, 0, 0, 0, 0])\n",
+ "tbc[0]=tbc[0]+bc[0];\n",
+ "i=1\n",
+ "while (i<8):\n",
+ " tbc[i]=tbc[i-1]+bc[i];\n",
+ " i=i+1;\n",
+ "\n",
+ "\n",
+ "bK=numpy.array([5.8, 3.0, 1.68, 0.98, 0.57, 0.35, 0.21, 0.13])\n",
+ "#bK(1)=5.8; #at 330DegF, 40 psia\n",
+ "#bK(2)=3.0; #at 330DegF, 40 psia\n",
+ "#bK(3)=1.68; #at 330DegF, 40 psia\n",
+ "#bK(4)=0.98; #at 330DegF, 40 psia\n",
+ "#bK(5)=0.57; #at 330DegF, 40 psia\n",
+ "#bK(6)=0.35; #at 330DegF, 40 psia\n",
+ "#bK(7)=0.21; #at 330DegF, 40 psia\n",
+ "#bK(8)=0.13; #at 330DegF, 40 psia\n",
+ "\n",
+ "KL=numpy.array([23.8, 148.0, 120.0, 51.4, 31.2, 28.9, 16.1, 2.9])\n",
+ "\n",
+ "#KL(1)=23.8;\n",
+ "#KL(2)=148.0;\n",
+ "#KL(3)=120.8;\n",
+ "#KL(4)=51.4;\n",
+ "#KL(5)=31.2;\n",
+ "#KL(6)=28.9;\n",
+ "#KL(7)=16.1;\n",
+ "#KL(8)=2.9;\n",
+ "\n",
+ "tk=([0, 0, 0, 0, 0, 0, 0, 0])\n",
+ "i=1;\n",
+ "op=40;\n",
+ "tk[0]=KL[0]\n",
+ "while (i<8):\n",
+ " tk[i]=tk[i-1]+KL[i];\n",
+ " i=i+1;\n",
+ "\n",
+ "l=numpy.array([1700, 13900, 13030, 6260, 4240, 4330, 2640, 520]) \n",
+ "#l(1)=1700; #Lb/hr\n",
+ "#l(2)=13900; #Lb/hr\n",
+ "#l(3)=13030; #Lb/hr\n",
+ "#l(4)=6260; #Lb/hr\n",
+ "#l(5)=4240; #Lb/hr\n",
+ "#l(6)=4330; #Lb/hr\n",
+ "#l(7)=2640; #Lb/hr\n",
+ "#l(8)=520; #Lb/hr\n",
+ "\n",
+ "tl=numpy.array([0, 0, 0, 0, 0, 0, 0, 0,])\n",
+ "\n",
+ "i=0;\n",
+ "while (i<8):\n",
+ " tl[i]=tl[i]+l[i];\n",
+ " i=i+1;\n",
+ "\n",
+ "print\"\\n\\t\\tBUBBLE POINTS OF BOTTOMS\\n\"\n",
+ "print\"\\t\\tMol/hr\\t\\tK(330DegF,40psia)\\t\\tKL\\t\\tLb/hr\\n\"\n",
+ "print\"\\t\\t--------------------------------------------------------------\\n\"\n",
+ "tlr=78177;\n",
+ "i=0;\n",
+ "while (i<8):\n",
+ "\n",
+ " print bc[i],bK[i],KL[i],l[i]\n",
+ " i=i+1;\n",
+ "\n",
+ "print\"\\t\\t____\\t\\t\\t\\t\\t____\\t\\t____\\n\"\n",
+ "\n",
+ "print\"\\t\\t\",tbc \n",
+ "print\"\\t\\t\\t\\t\\t\",tk \n",
+ "print\"\\t\\t\",tl\n",
+ "av = numpy.array([0, 0, 0, 0, 0, 0, 0, 0])\n",
+ "av=tl/tk\n",
+ "hl=4280000;\n",
+ "print\"\\tAverage mol. wt. \\n\",av\n",
+ "\n",
+ "lh=numpy.array([48894, 16298, 32596])\n",
+ "bl=numpy.array([286, 129, 129])\n",
+ "#lh(1)=48894;#Lb/hr\n",
+ "#lh(2)=16298;#Lb/hr\n",
+ "#lh(3)=32596;#Lb/hr\n",
+ "#bl(1)=286;#Btu/hr\n",
+ "#bl(2)=129;#Btu/hr\n",
+ "#bl(3)=129;#Btu/hr\n",
+ "\n",
+ "bh=numpy.array([0, 0, 0])\n",
+ "vap=22700;\n",
+ "i=0;\n",
+ "\n",
+ "while (i<3):\n",
+ " bh[0]=lh[0]*bl[0];\n",
+ " i=i+1;\n",
+ "\n",
+ "#Heat Balances\n",
+ "print\"\\n\\n\\t\\t\\t\\t\\t\\tHEAT BALANCES:\"\n",
+ "print\"\\n\\t\\t\\t\\tMol/hr\\t\\tMol.wt.\\t\\tLb/hr\\t\\tTemp,DegF\\t\\tBtu/lb\\t\\tBtu/hr\\n\\t\"\n",
+ "print\"\\t\\t\\t----------------------------------------------------------------------------------------\"\n",
+ "print\"\\n\\tHeat Balance onCondeser\\n\\t Heat in:\\n\\t Top plate vapor......\"\n",
+ "\n",
+ "#Heat Balances on reboiler\n",
+ "#Assume 30Deg difference between reboiler and bottom plate giving bottom-plate temperature of 300DegF\n",
+ "#Mol/hr from Eq. 15.47\n",
+ "\n",
+ "pc=numpy.array([0.056, 0.35, 0.285, 0.122, 0.074, 0.068, 0.038, 0.007])\n",
+ "#pc(1)=0.056;\n",
+ "#pc(2)=0.350;\n",
+ "##pc(3)=0.285;\n",
+ "#pc(4)=0.122;\n",
+ "#pc(5)=0.074;\n",
+ "#pc(6)=0.068;\n",
+ "#pc(7)=0.038;\n",
+ "#pc(8)=0.007;\n",
+ "\n",
+ "pk=numpy.array([4.5, 2.25, 1.2, 0.66, 0.38, 0.22, 0.13, 0.07])\n",
+ "#pK(1)=4.5;\n",
+ "#pK(2)=2.25;\n",
+ "#pK(3)=1.20;\n",
+ "#pK(4)=0.66;\n",
+ "#pK(5)=0.38;\n",
+ "#pK(6)=0.22;\n",
+ "#pK(7)=0.13;\n",
+ "#pK(8)=0.07;\n",
+ "\n",
+ "print\"\\n\\n\\t\\tCALCULATION OF BOTTOM PLATE TEMPERATURE\\n\"\n",
+ "print\"\\t\\ty*\\t\\t\\tReboiler vapor\\t\\t\\t\\tK(300DegF,40psia)\\tMol*K\\n\\t\\t\\t\\tV = y*205.7 +\\tBottoms\\t=\\tTrapout\\n\"\n",
+ "print\"\\t\\t----------------------------------------------------------------------------------------\\n\"\n",
+ "\n",
+ "\n",
+ "print \"CALCULATION OF BOTTOM PLATE TEMPERATURE\"\n",
+ "print\" y* Reboiler vapor K(300DegF,40psia) Mol*K\"\n",
+ "print\" V = y*205.7 + Bottoms = Trapout\"\n",
+ "print\" ----------------------------------------------------------------------------------------\"\n",
+ "print \"C5 0.056 11.5 4.1 15.6 4.5 70.29\"\n",
+ "print \"C6 0.35 72.0 49.3 121.3 2.25 272.91\"\n",
+ "print \"C7 0.285 58.6 71.9 130.5 1.2 156.63\"\n",
+ "print \"C8 0.122 25.1 52.5 77.6 0.66 51.21\"\n",
+ "print \"C9 0.074 15.2 54.7 69.9 0.38 26.57\"\n",
+ "print \"C10 0.068 14.0 82.5 96.5 0.22 21.23\"\n",
+ "print \"C11 0.038 7.8 76.6 84.4 0.13 10.97\"\n",
+ "print \"C12 0.007 1.4 22.4 23.8 0.07 1.67\"\n",
+ "print \"----------------------------------------------------------------------------------------\"\n",
+ "print \"1.000 205.7 414.0 619.7 611.5\"\n",
+ "\n",
+ "\n",
+ "print\"Reboiler requirements are\"\n",
+ "print\" Vaporization lb/hr\",vap\n",
+ "print\" Total liquor to reboiler lb/hr\",tlr \n",
+ "print\" Heat load Btu/hr\",hl\n",
+ "print\" Temperature range 300-330 def F\"\n",
+ "print\" Operating pressure psi\",op "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_16_Extented_Surfaces.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_16_Extented_Surfaces.ipynb
new file mode 100755
index 00000000..36846d25
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_16_Extented_Surfaces.ipynb
@@ -0,0 +1,1044 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 16: Extented Surfaces"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.1 pgno: 521"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 16.1 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t fin surface is : %.1f ft**2/lin ft \t2.5\n",
+ "\t bare tube surface is : ft**2/lin ft \t0.0\n",
+ "\t total outside surface : ft**2/lin ft \t2.5\n",
+ "\t total inside surface : ft**2/lin ft \t0.277366666667\n",
+ "\t fin efficiencies \t\n",
+ "\t hf m n \t \n",
+ "4\n",
+ "5.24\n",
+ "0.965717954492\n",
+ "\t weighted efficiency curve \t\n",
+ "\t hf hfi \t \n",
+ "4\n",
+ "34.8173760783\n"
+ ]
+ },
+ {
+ "data": {
+ "image/png": [
+ "iVBORw0KGgoAAAANSUhEUgAAAZAAAAEZCAYAAAC5AHPcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\n",
+ "AAALEgAACxIB0t1+/AAAIABJREFUeJzt3XeYXGX5xvHvnUCoEQggLZEaSpASelNCFZUmCoh0+IkQ\n",
+ "EWxIQo0iKigqomClQxQUEGwkIEGKEOmBUJUACSRgEAEbgdy/P953k5PJzO7s7M6e2d3nc1175Zwz\n",
+ "Z877zOxmnjlvlW1CCCGEzhpQdgAhhBB6p0ggIYQQGhIJJIQQQkMigYQQQmhIJJAQQggNiQQSQgih\n",
+ "IZFAQreTdJGk0+o891JJZzUxlnavL+mrkl6R9KKkYZLekKQmxLGepIckvS7peEmLS7pJ0muSrpH0\n",
+ "CUk313GdsZJ+0t3xhdCIRcoOIPQ9to/rzOn5pypJc4F1bP+t0XBqXV/Se4DPA8Nsz86HBzdYTke+\n",
+ "BNxqe9Nc9qHAu4Ehtufmc67u6CK2v96k+ELotLgDCb1BV+8Iaj3/PcDsQvJoptWBqRX7TxWSR78m\n",
+ "aWDZMYTOiwQS5pF0pKQbC/tPS7qmsP+CpI3z9vqSJkqaLekJSfsXzlug2kjSl3IV0XRJ/ydprqS1\n",
+ "CkUPkfSbXL1zT9tjkv6UH384Vy3tn4/vmauD/iHpLkkbFcoaKemBfK2fA4vXeK27AhOAVfO1L5a0\n",
+ "Ro5tQD5nkqSvSLozX+9mScu38/5VjUvSH4FRwPdzWVcDpwMH5v2jJB0h6Y7CtTYsvL8zJY3Nx8dJ\n",
+ "uqJw3jaS7s5lPiRpx8Jj7cYvaYfCc5+XdLikLXN5Kpy3n6SHarzmJSSdJ2laro67I1fPjZL0QsW5\n",
+ "0yTtXHgdv5R0haR/AqdI+rek5Sp+l6+0JZf8Pk2V9KqkP+Q7yFAm2/ETP9gGWBP4R95eFZgGPJ/3\n",
+ "1wJezdtLAS8Ah5O+hGwKvAJskB+/BPhK3t4DeAnYAFgCuBKYC6yVH78U+DuwBTAwPz6+ENO8c/P+\n",
+ "SGAWsCXpzuIw4FlgUWAQ8BxwYr7WR4G32mKp8np3BF4o7K+RyxuQ9ycBTwPrkBLRbcDXa1yrZlz5\n",
+ "8duAowrnnwlcXtg/Argjbw/O79nn8mtaGtiq8Lwr8vZq+b3bI+/vmveX7yh+0h3Q68CB+b0aAmyc\n",
+ "H3us7Zp5/3rgczVe9w+APwKr5L+FbXLMo4rvbT73WWDnvD0u/272zvuLA7cC/1c4/5vAhXl7n/xa\n",
+ "1svlnArcVfb/mf7+E3cgYR7bzwJvSBoJvB+4GXhR0nqkD9u2O4I9gWdtX2Z7ru2HgOuA/atc9gDg\n",
+ "YtuP2/4P6QNwgWKB62zfZ/sd4CpSQqrlGOBHtv/i5HLgf8C2pA+vRWyfb/sd278C/tLOtTqqGjNw\n",
+ "ie1nbP8XuKad2GrFtU2N8tRO+XsCL9r+ju23bL9pe3KVaxwC/M72HwBs3wLcB3y4jvg/AUy0/Yv8\n",
+ "Xr1q+5H82OX52kgaAuxOlfaZfKd2JHCi7Zfy38I9tt+q8boq3W37xhz7f3MZB+Vri5Tc2so9lpT8\n",
+ "nnSq9vs6sKmkYXWWFZogGtFDpdtJ3x7XyduvkZLHtnkf0rfXrSX9o/C8RUgfPJVWASYX9qdXOWdW\n",
+ "Yfs/pG/ctawOHCbpM4Vji+ZyBMyoOP85utaGMrPO2GrFtWphv96ZS4cB9XQaWB3YX9JehWOLkO4I\n",
+ "2tSKv70yrgIek7Qk6QvAn2zPqnLeCqQ7h7/WEWs1lX8L1wEXSFqZdKcx1/ad+bHVgfMlnVfxnNVI\n",
+ "d8OhBJFAQqXbgb1J1TlnkxLIIaRv0hfkc54Hbre9ex3Xe4n0YdWmq98YnwfOtv21ygdy/f9qFYdX\n",
+ "B57pYpldiquG9pLJ86Rv3/WUeYXtY+oss/K5W1UNzJ4u6R5gP9Lv/sIa1/g78F/Sl41HKh77F7Bk\n",
+ "205ux1ixsqiKcv8haQLptY8AxlfEe5bt4rFQsqjCCpVuB3YCFrf9InAnqR1jCPBgPuc3wLqSDpG0\n",
+ "aP7ZUtL6+fFi9cw1wJFKje5LkhqPizq6O5gFrF3Y/wlwrKStlCwl6cOSlgbuBt6WdEKOaT9Sm0RX\n",
+ "1Hv30l5c1a7V3nV/C6wi6URJi0kaLKnah/2VwF6Sdpc0sNB4XUyitcq5GthV0v6SFpG0vKRNCo9f\n",
+ "DpwMvJd0Z7CQXJV0MfBtSavkGLaVNAh4Clhc0ockLQqcBizWzmsuxnU4qf2qWG32Q1JD+wgAScuo\n",
+ "0HEjlCMSSFiA7aeBN4A78v7rpCqKu+zUmmn7TVK9+MdJVUYvkeqkB7VdJv+Q6+e/R2rAfQr4cz7n\n",
+ "f5XnFsMobI8DLss9hT5m+37gk8D3gVdJDauH5bLmkL41HwHMJlW//Kqjl9yJ/ZpjStqJq/L5ta5V\n",
+ "fM/eAHYD9iK9t0+RqhUrz5tOalw+BXiZ9C39CyyYNGqV8TzwoXz+bNKXg40L515H6uZ8fW6fqOWL\n",
+ "wBRSW9Ns0t+BbP8TGA38lFRV9SYLVjXVei9vJN3RvGR7yryT7RuAc4Cf515bU4APtBNX6AHKnwnd\n",
+ "f2HpYlJj3su227ozbkX6D7Yo8DYw2vZf8mNjgaOAd4ATbE/Ixzcn9dRZnNRgeGJTAg49QtIGpP/8\n",
+ "gxxjIFqapKeBT9n+Y4cnh36pmXcgl5CqPorOBU63PRI4I++Tb0vb6j33AC4s9EO/CDja9nBguKTK\n",
+ "a4YWJ+kjuSpmOdK3yBsjebS2XP3nSB6hPU1LILbvAP5RcfglYJm8vSzze8zsQ+r7P8f2NFKj59aS\n",
+ "VgEGF7owXg7s26yYQ9McQ2rLeAaYA3RmqpPQwyRNIjWcf7rkUEKL6+leWGOAOyV9i5S8ts3HVwXu\n",
+ "KZw3ndSbZg4LdvWbwcK9bEKLs/3BsmMI9bM9quwYQu/Q043oPyO1b7yHNMr24h4uP4QQQjfp6TuQ\n",
+ "rWzvmrd/SeqhAenOojg+YCjpzmNG3i4erxwoBoCk5vQGCCGEPs52Y4NtmzlPCmkw2pTC/gPAjnl7\n",
+ "F+AveXsE8BCpG+iapG6jbT3E7gW2JnVN/B2FOXoqynIzX0uDr39c2TFETH0rrogpYmpCXG70uU27\n",
+ "A5E0njQFxgp5Vs4zSI2pP5C0GGlahWNy9FOVZn2dyvzuvW13FKNJ3XiXoDDvTwghhHI1LYHYPqjG\n",
+ "Q1vXOP9rwELTQDgN0Npo4WeEEEIoU4xEb65JZQdQxaSyA6hiUtkB1DCp7ACqmFR2AFVMKjuAKiaV\n",
+ "HUAVk8oOoLs1bSR6T5NkN9oQFEII/VRXPjvjDiSEEEJDIoGEEEJoSCSQEEIIDYkEEkIIoSGRQEII\n",
+ "ITQklrQNIYR+SGI54NiuXCPuQEIIoR+RWF7iq6TlFYZ35VqRQEIIoR+QeLfEOaQlklcEtrA5qivX\n",
+ "jAQSQgh9mMQqEt8GngCWAja1+ZTNs129diSQEELogySGSnwPeIw0m/l7bY63eaG7yogEEkIIfYjE\n",
+ "6hIXAY8A/wNG2HzO5sXuLisSSAgh9AESa0v8lLTu0j+A9WxOspnZrDKjG28IIfRiEusCpwB7Aj8A\n",
+ "htu82hNlRwIJIYReSGIEcCqwO/A9YB2b13oyhqZVYUm6WNIsSVMqjn9G0uOSHpV0TuH4WElPS3pC\n",
+ "0u6F45tLmpIfO79Z8YYQQm8gsbHENcBtwBRgbZuzejp5QHPbQC4B9igekLQTsDewse33At/Kx0cA\n",
+ "B5LWRt8DuFBS2/z0FwFH2x4ODJe0wDVDCKE/kBgpcR1wM3AvsJbNN2xeLyumDhOIpGUlbZl/lqn3\n",
+ "wrbvIDXkFB0HfN32nHzOK/n4PsB423NsTyONkNxa0irAYNuT83mXA/vWG0MIIfR2EltJ3AT8Brid\n",
+ "dMdxns2/Sg6tdgKRtJikS4FpwI+BnwDPSbpE0qAGyxsOvF/SPZImSdoiH18VmF44bzqwWpXjM/Lx\n",
+ "EELo0yS2k/gD8Evg96TEcb7Nv0sObZ72GtFPAxYFhtl+A0DSYOBC4PT800h5y9neRtKWwDXAWg1c\n",
+ "pypJ4wq7k2xP6q5rhxBCT5DYkfT5ujbwNWBvm7e67/oaBYzqjmu1l0D2A7ayPe82yfYbko4j1b81\n",
+ "kkCmA9fla/1F0lxJK5DuLIYVzhuaz52Rt4vHZ9S6uO1xDcQUQgilkhCwM3AGqZblbOBKmzndXVb+\n",
+ "Yj1pftk6s9FrtdcG8k4xeRQKfxOY22B5N5DeJCStCwyy/XfgRuDjkgZJWpNU1TXZ9kzgdUlb50b1\n",
+ "Q/M1Qgih15OQxB7AXaQxHD8B1re5pBnJo7u1Ow5E0pBqhwF3dGFJ44EdgeUlvUDKrBcDF+euvW8B\n",
+ "hwHYnirpGmAq8DYw2nZbGaOBS4ElgN/Z/kMdryuEEFpWvuPYk1STsyTwVeBam3dKDayTNP9zuuIB\n",
+ "aRrtJArbazYppoZIsm11fGYIIZRDYgCp1+nppBqgs4Dr7YZrdbohpsY/O2smkN4mEkgIoVVJDAQ+\n",
+ "Skoc/wO+Atxkd1yb02xd+eysWYUlabP2nmj7gUYKDCGE/kJiEdIg6VOB14GTgd+3QuLoDu1VYU2i\n",
+ "/SqsnZoUU0PiDiSE0CokFgU+QUocs0h3HLe0YuKIKiwigYQQyicxiNQ56BTSIOyvALe3YuJo05Qq\n",
+ "rBBCCPWRWAw4ChhDWjr2MJs7y42q+SKBhBBCgySWAP6P1LbxMHCgzT3lRtVzIoGEEEInSSwFfAr4\n",
+ "IjAZ2Mfm/nKj6nn1zMY7QNKhks7I+++RtFXzQwshhNYiMVjiZOCvwLbAB2327Y/JA+pbD+RC0hv1\n",
+ "ibz/Zj4WQgj9gsQyEqeSEsemwK42+9s8XHJopaqnCmtr2yMlPQhg+1VJizY5rhBCKJ3EcsCJwPHA\n",
+ "74D32zxRblSto547kLckDWzbkbQijU+mGEIILU9iBYmzSYvbDQO2sTkskseC6kkgFwDXA++W9DXS\n",
+ "rJFfb2pUIYRQAol3S5wDPAWsAGxhc7TNMyWH1pLqGkgoaQNgl7x7q+3HmxpVA2IgYQihURKrACcB\n",
+ "RwBXA+faPF9qUD2kK5+d9dyBQJpueGA+f4lGCgohhFYjMVTiAuAx0ufbRjbH95fk0VX1dOM9g7Qe\n",
+ "xxDSLd0lkhpZjTCEEFqCxOoSFwGPAP8FRth81q694mlYWIdVWJKeAja2/d+8vwTwsO11eyC+ukUV\n",
+ "VgihIxJrA2OBjwA/Ar5j80q5UZWr2VVYM1iw2mpx0nrlHQV1saRZefXByse+kNdDH1I4NlbS05Ke\n",
+ "kLR74fjmkqbkx86vI94QQliAxLoSlwH3Ai8Cw21O6e/Jo6tqJhBJF0i6APgn8JikSyVdCjyaj3Xk\n",
+ "EmCPKtcdBuwGPFc4NoI0Z/6I/JwL8xroABcBR9seDgyXtNA1QwihGokREleReo8+A6xjc4bNqyWH\n",
+ "1ie0N5DwftJ6IPcDNxSOT6KONdFt3yFpjSoPfRv4EvDrwrF9gPG25wDTJD0DbC3pOWCw7cn5vMuB\n",
+ "fYFYFz2EUJPExsBpwI7Ad4DjbF4vN6q+p2YCsX1pdxcmaR9guu1H5t9gALAqLDCD5XRgNWAOC1aX\n",
+ "zcjHQwhhIRKbkZaN3QY4DzjK5s1yo+q7OpzKRNKzVQ7b9lqdKUjSkqRFVnYrHu7MNeooY1xhd5Lt\n",
+ "Sd15/RBCa5LYipQ4NgPOBQ62+Xe5UbUmSaOAUd1xrXrmwtqysL048DFg+QbKWhtYA3g4330MBe6X\n",
+ "tDXpzmJY4dyhpDuPGXm7eLxmNzvb4xqIK4TQS0lsB5xBaj/9BrC/zX/Ljaq15S/Wk9r2JZ3Z6LU6\n",
+ "7IVl+++Fn+m2vwt8uLMF2Z5ieyXba9pek5QgNrM9C7gR+LikQZLWBIYDk23PBF6XtHVuVD+UBdtj\n",
+ "Qgj9kMSOErcCVwHXkXpVXRjJo2fVU4W1OfMbzQcAW5BGpXf0vPGkBqzlJb0AnGH7ksIp8xribU+V\n",
+ "dA0wFXgbGO35A1RGkwYyLgH8znY0oIfQD0kI2Jl0x7EacDZwpc2cUgPrx+oZSDiJ+R/2b5MWiv+W\n",
+ "7SebGlknxUDCEPqmnDg+QEocQ4CvAj+3ebvUwPqIrnx21pNA1rL9t4pja9qu1rhemkggIfQtOXHs\n",
+ "SUocSwJnAdfavFNqYH1MsxPIA7Y3qzh2v+3NGymwWSKBhNA3SAwgjfc6jVRd/hXgejvWIWqGrnx2\n",
+ "1mwDyVO4jwCWlbQfqcutgXeRemOFEEK3kRgIfJTUHfd/wJeBmyJxtK72GtHXBfYClsn/tnkD+GQz\n",
+ "gwoh9B8Si5CmMjqNNE3SycDv7Y5nvAjlqqcKazvbd/dQPA2LKqwQeheJRYFPAKcCs0hVVbdE4uhZ\n",
+ "TW0D6S0igYTQO0gMAg4jzUwxjZQ4bo/EUY6mtIGEEEJ3klgMOAoYAzwJHG5zR7lRha6IBBJCaCqJ\n",
+ "xUntpicDDwMH2gtMnhp6qXqWtF1Z0s8k/SHvj5B0dPNDCyH0ZhIDJY4k3W3sDuxr8+FIHn1HPSsS\n",
+ "XgpMIE25DvA08LlmBRRC6N0kJLEvab3xI4GDbPayua/k0EI3qyeBrGD7F5BGf+ZFn2IKgRDCQiR2\n",
+ "BO4mjeE4CdjRpuV7cYbG1NMG8qakedO3S9qG+pa0DSH0ExKbAl8DNiANBLw6BgD2ffUkkC8ANwFr\n",
+ "SbobWJG0JkgIoZ+TWIs0R9UupNlx97V5q9yoQk+paxyIpEWB9fLuk7kaq6XEOJAQeo7ESqQ7jYOA\n",
+ "84Hv2LxRblShET0xDmQr0mqCiwCbScL25Y0UGELovSSWAb5IWqfncmB9m1fKjSqUpZ4Fpa4E1gIe\n",
+ "ggWmUY4EEkI/kcdyjCbPUwVsZvNcuVGFstVzB7I5MMKdnPNE0sWkpW9ftr1RPvZN0vz+bwF/BY60\n",
+ "/c/82FjSKNV3gBNsT8jHNyd1JV6ctCLhiZ2JI4TQuDxD7mHAONKXyF1sHi01qNAy6unG+yiwSgPX\n",
+ "vgTYo+LYBGBD25sATwFjIQ1OJM3GOSI/58K8BjrARcDRtocDwyVVXjOE0M1qjOXYJ5JHKGpvPZCb\n",
+ "8ubSwFRJk0lz9APY9t7tXdj2HZLWqDg2sbB7L2nuf4B9gPG5cX6apGeArSU9Bwy2PTmfdzlpoZlY\n",
+ "Fz2EJsljOb5BWgXwJGJq9VBDe1VY5+V/TVpMqqg7/piOAsbn7VVhgekNpgOrAXPydpsZ+XgIoZvF\n",
+ "WI7QWTUTiO1JAJLOtf2l4mOSzgFub7RQSacCb9m+utFr1LjuuMLupLbXEEKoLcZy9C+SRgGjuuNa\n",
+ "9TSi71bl2IdIvTE6TdIR+fm7FA7PAIYV9oeS7jxm5O3i8Rm1rm17XCMxhdAfVRnLcWyM5ej78hfr\n",
+ "SW37ks5s9Fo1G9ElHSdpCrCepCmFn2mkhrVOyw3gJwH72P5v4aEbgY9LGiRpTWA4MNn2TOB1SVvn\n",
+ "RvVDgRsaKTuEkEgsI3EWMJVUTby+zVcieYTOau8O5GpSf+9vkO422tpB3rA9u6MLSxoP7AisIOkF\n",
+ "4ExSr6tBwMTcyerPtkfbnirpGtIf9NvA6EK34dGkbrxLkLrxRgN6CA2IsRyhu8WStiH0cVXGcpwa\n",
+ "3XFDm1jSNoSwEAmRusifDcwmjeWIqdVDt4kEEkIfFGM5Qk+oK4FIWhnYkjT+Y7Ltl5saVQihITGW\n",
+ "I/SketZEP4A0anx/4ABgsqT9mx1YCKF+EmtJXEWapeH3wHo2V0byCM3UYSO6pEeAXdvuOiStCNxq\n",
+ "e+MeiK9u0Yge+qNYlyN0VVc+O+uZTFGwwHz/s1l4apMQQg+KsRyhFdTTBvIH4GZJV5MSx4GkW+QQ\n",
+ "Qg+LsRyhldS7pO1Hge3z7h22r29qVA2IKqzQl8VYjtAsXfnsrKcN5BzbJ3d0rGyRQEJfVGUsx5gY\n",
+ "yxG6U7MTyIO2R1Ycm9K2ymCriAQS+pqKsRxjibEcoQmaMhJd0nGkuta186SKbQYDdzVSWAihYzGW\n",
+ "I/QWNe9AJC0DLEeDkyn2tLgDCb1dlXU5fhTrcoRma2oVVm8RCST0VjGWI5Sp2eNAQghNEGM5Qm8X\n",
+ "CSSEHiaxuMTngadIK3FuZvM5e4EBuyG0vKYlEEkXS5pVbICXNETSRElPSZogadnCY2MlPS3pCUm7\n",
+ "F45vnldCfFrS+c2KN4RmkxgocSTwJGmxtV1sjoiBgKG3am9J2zclvVHj5/U6rn0JsEfFsTHARNvr\n",
+ "ArfmfSSNII1wH5Gfc2FewhbgIuBo28OB4XlZ3BB6DQlJ7EtaCvpI0roc+8RAwNDb1ezGa3tpAElf\n",
+ "BV4ErswPHQys2tGFbd8haY2Kw3uTvnkBXEZa2H0MaaDUeNtzgGmSngG2lvQcMNj25Pycy4F9SdOr\n",
+ "hNDyYl2O0JfVMxfW3hUz716UZ+g9vYHyVrI9K2/PAlbK26sC9xTOmw6sRmpYnF44PiMfD6GlxViO\n",
+ "0B/U0wbyL0mHSBqYfw4G3uxqwU79h+ObWOhTYl2O0J/UcwfyCVLf9O/m/bvysUbMkrSy7ZmSVgHa\n",
+ "VjacQeqN0mYo6c5jRt4uHp9R6+KSxhV2J9me1GCcIXRKlbEcx0Z33NCKJI0CRnXLtZo5kDC3gdzU\n",
+ "Nm+WpHOB2bbPkTQGWNb2mNyIfjWwFamK6hZgHduWdC9wAjAZ+C3wPdsLtYHEQMJQBollgC+Spv25\n",
+ "HPhadMcNvUlTBxJKWk/SrZIey/sbSzqtjueNB+4G1pP0gqQjSY2Ju0l6Ctg572N7KnANaUDV74HR\n",
+ "np/ZRgM/BZ4GnqmWPELoaTGWI4T6ZuP9E6n3yA9tj8zdax+1vWFPBFivuAMJPSHW5Qh9TVNm4y1Y\n",
+ "0va9bcMycrXSnEYKC6G3qrIux0GxLkfo7+pJIK9IWqdtR9LHgJeaF1IIrSXGcoRQXT1VWGsDPwa2\n",
+ "BV4DngUOtj2t6dF1QlRhhe4WYzlCf9C0KixJA4HjbO8iaWlggO16pjEJodeSWBn4JrAbqcpq31iX\n",
+ "I4SFtdsLy/Y7wA5KKerNSB6hL5MYIPEpYAppvNFwmwsieYRQXT1tIA8Bv5Z0LfDvfMy2r2teWCH0\n",
+ "LIkNgR+RvlTtbDOlg6eE0O/Vk0AWI/U62bnieCSQ0OtJLAGcBhwDnEFaRjbaOUKoQz1tIK/a/kIP\n",
+ "xRNCj5HYlbRcwIPAJjYvlhxSCL1KuwnE9juSts9tINFtMfQJEisC3wbeBxxv85uSQwqhV4o2kNBv\n",
+ "5MGAR5DGdFwBvNfu+szSIfRX9SSQxYFXiTaQ0ItJrEdqJF8K2MPmwZJDCqHXa+psvD0pBhKGaiQW\n",
+ "I616+RngLOD7Nu+UG1UIraMlZ+MNoWx5CpKHgc2AkTbnR/IIofvUsyLhT4BTYN5gqimkRXNCaEkS\n",
+ "QyR+BlwJjLXZx+aFsuMKoa+pJ4Esafvetp3cGytm4w0tR0ISh5DWlfkXsKHN9SWHFUKfFbPxhj5B\n",
+ "Ym3SmI53A3vbTC45pBD6vHruQI4n9V5ZT9KLwOeA47pSqKSxkh6TNEXS1ZIWkzRE0kRJT0maIGnZ\n",
+ "ivOflvSEpN27UnboWyQGSYwF7gUmAltG8gihZ9RMIJJOzJur2N6F9M1ufdvbd2Uq97xO+ieBzfJa\n",
+ "6QOBj5N6yky0vS5wa94nr5d+IDAC2AO4UFI9iS/0cRLbAfeTBgRuYfNNO6pXQ+gp7X0QH5X/vQCg\n",
+ "G2fjfZ3UhrKkpEVIi/S8COwNXJbPuQzYN2/vA4y3PScnrmeArbohjtBLSSwrcRHwS1LX3A/bTCs3\n",
+ "qhD6n/baQKZKehpYTVLlzKS2vXEjBdp+VdJ5wPPAf4CbbU+UtJLtWfm0WcBKeXtV4J7CJaYDqzVS\n",
+ "dujd8kjy/YHvADcBI2xeKzeqEPqvmgnE9kGSVgYmAHsB3TJIL69w+FlgDeCfwLWSDqko25LaG+HY\n",
+ "N0Y/hrpJrAH8gPR3c4DNXaUGFELocDLFmcDGkpYA3mP7yW4ocwvgbtuzASRdR1oud6aklW3PlLQK\n",
+ "8HI+fwYwrPD8ofnYQiSNK+xOsj2pG+INJZJYhPSFYwxpAsSPxAJPITRO0ihgVLdcq4410fcmLe+5\n",
+ "mO01JI0Evmx774YKlDYBrgK2BP4LXApMBlYHZts+R9IYYFnbY3Ij+tWkdo/VgFuAdSpnB46pTPoe\n",
+ "iS2BH5PWoznW5pmSQwqhz2namujZOGBr4DYA2w9KWquRwvLzH5Z0OXAfMBd4gPQhMRi4RtLRwDTg\n",
+ "gHz+VEnXkAaHvQ2Mjqnl+zaJwaS1yA8AvghcZUe1ZQitpp47kHttby3pQdsj87FHGm1Eb5a4A+kb\n",
+ "JPYl9fybCJxkM7vkkELo05p9B/KYpIOBRSQNB04A7m6ksBBqkRhKShwjgENtJpUbUQihI/WORN8Q\n",
+ "+B8wnjSO47PNDCr0HxIDJU4gLVz2MLBxJI8Qeod2q7DyQL+JtnfquZAaE1VYvY/ESFL7179IjeRP\n",
+ "lBxSCP1O09YDsf02MLc4L1UIXSWxlMS3gJtJEyDuFMkjhN6nnjaQfwFTJE3M25DG+p3QvLBCXyXx\n",
+ "IeBC4E7SmuQvd/CUEEKLqieBXJd/2uq6RIwED50ksQpwPml1wE/aTCw5pBBCF8Wa6KGpJAYAx5Am\n",
+ "Pfwx8FWb/5QbVQihTbO78YbQEIn3kpKGSe0cj5YcUgihG8W6GqHbSSwh8TXS7AWXAe+L5BFC39Pe\n",
+ "glJX5H9jzEeom8RuwBRgbdKYjh/ZzC05rBBCE9RsA5E0FdgV+ANVZm60/WpTI+ukaAMpl8S7SbPl\n",
+ "7gCMtvldySGFEOrQrDaQH5KWll2LtGxokfPx0M/lRZ6OAr5Oqq7a0J7X3TuE0IfVM5niD20f20Px\n",
+ "NCzuQHqexPrAj4AlgGNsHio5pBBCJ3Xls7OubrySBpKWmJ13x2L7+UYKbJZIID1HYnFgLPBp4MvA\n",
+ "hTbvlBtVCKERTe3GK+kzwJmkFQKLHxIbNVJg6N0kRpHuOqYCm9pMLzeiEEJZ6qnC+iuwVdsStK0q\n",
+ "7kCaS2J50sqUuwGfsbmh5JBCCN2gaZMpZs+TpnDvNpKWlfRLSY9Lmippa0lDJE2U9JSkCcUJHCWN\n",
+ "lfS0pCck7d6dsYT2SUjiUOAx4A1gRCSPEAK03433C3lzBLA+8BvgrXzMtr/dcKHSZcDtti/OU8Yv\n",
+ "BZwK/N32uZJOBparWBN9S+avib6u7bkV14w7kG4msQ6pN97ypEbyv5QcUgihmzXrDmQwsDTpDmQi\n",
+ "MCjvL50KByWiAAAY60lEQVQfa4ikZYD32b4Y0pTxtv8J7E3qBkr+d9+8vQ8w3vYc29OAZ4CtGi0/\n",
+ "dExikMSpwD3A74EtI3mEECrVbES3Pa5JZa4JvCLpEmAT0hiTzwIr2Z6Vz5lF6vUFsCrpg6zNdNKd\n",
+ "SGgCie1JjeTPAVvYTCs3ohBCqypjMsVFSFN6H2/7L5K+C4wpnmDbktpr3a/6mKRxhd1Jtid1MdZ+\n",
+ "Q2I54BvAnqSE/ks7pu0Poa+RNIoqs4s0oowEMh2YbrutSuSXpDEFMyWtbHumpFVg3kJDM4BhhecP\n",
+ "zccW0sS7pj4rjyQ/APgOcANpJPlr5UYVQmiW/MV6Utu+pDMbvVaHvbAk7VDl2PaNFmh7JvCCpHXz\n",
+ "oV1JPXxuAg7Pxw6HeT19bgQ+LmmQpDWB4cDkRssP80msCfwOOA34qM3oSB4hhHrVMw7kQdsjOzrW\n",
+ "qUKlTYCfkhrm/wocCQwErgHeA0wDDrD9Wj7/FNJ8S28DJ9q+uco1oxdWnSQWJVVTnQycB3zLZk65\n",
+ "UYUQytCUqUwkbQtsB3yONMtqWwGDgY/Y3qSRApslEkh9JLYiLfL0MnCczV9LDimEUKJmTWUyiJQs\n",
+ "BrJgt93XgY81Ulgoj8S7gLNJv7svAldHI3kIoSvqqcJaI4+/aGlxB1JdbiT/CPA90touX7JpqbVc\n",
+ "Qgjlafaa6ItJ+gmwRuF82965kQJDz5EYBnwfWA/4hM2fSg4phNCH1JNArgUuIjV6t83GG1UfLUxi\n",
+ "IHA8cDpwAXCAzf/KjSqE0NfUk0Dm2L6o6ZGEbiGxGamR/A1ge5snSw4phNBH1TMb702SPi1plTxj\n",
+ "7hBJQ5oeWegUiaUlziPNXfV9YOdIHiGEZqqnEX0aVaqsbK/ZpJga0p8b0SX2BH4A3A58weaVkkMK\n",
+ "IfQSTV/StjfojwlEYlXgfGAkcKzNLSWHFELoZZq6oJSkpSSdnntiIWm4pD0bKSx0D4kBEqOBh4En\n",
+ "gY0ieYQQelo9jeiXkKZc3y7vv0iaAPE3zQoq1CaxEamRfC4wyuaxkkMKIfRT9TSir237HPJqhLb/\n",
+ "1dyQQjUSS0p8A/gjKam/L5JHCKFM9SSQ/0laom1H0toQYwp6ksQHgCmkwZwb2fzYZm77zwohhOaq\n",
+ "pwprHGkKjKGSrga2B45oYkwhk1iJtE7HtsBom9+XHFIIIcxTVy8sSSsA2+Tde2z/valRNaAv9cKS\n",
+ "GECavv5rwKXAl22i6jCE0O2aNZ37BrYfl7Q5aRxIWwEGsP1AIwU2S19JIBIbkNYkXww4xubhkkMK\n",
+ "IfRhzUogP7H9SUmTqD6QcKdGCmyW3p5AJBYHTgFGk6oNL7LnzT0WQghN0SsHEkoaCNxHWh99rzw9\n",
+ "yi+A1Vl4RcKxpCqdd4ATbE+ocr1em0AkdiLddTwKfMauvuZ7CCF0t2YPJPy0pOUK+8tJGt1IYRVO\n",
+ "BKYy/+5mDDDR9rrArXkfSSOAA4ERwB7AhZLq6T3W8iRWkLgUuAw4yWa/SB4hhN6ing/iY2z/o20n\n",
+ "bx/TlUIlDQU+RJoivi3z7U36ICX/u2/e3gcYb3tOXtjqGWCrrpRfNglJHEa643gN2NDm1yWHFUII\n",
+ "nVJPN94BkgbYngvzqp4W7WK53wFOAt5VOLaS7Vl5exawUt5eFbincN50YLUull8aieHAD4HlgD1t\n",
+ "7is5pBBCaEg9CeRm4OeSfkS6W/gUaVxIQ/I8Wi/bflDSqGrn2Lak9hpnqj4maVxhd5LtSY3G2d0k\n",
+ "BgFfAj5LWpv8Apu3y40qhNDf5M/dUd1xrXoSyMmkKqvj8v5EUtVTo7YD9pb0IWBx4F2SrgBmSVrZ\n",
+ "9kxJqwAv5/NnAMMKzx+ajy3E9rguxNU0EjuQ5q/6K7C5zXMlhxRC6KfyF+tJbfuSzmz0WqVO5y5p\n",
+ "R+CLuRfWucBs2+dIGgMsa3tMbkS/mtTusRpwC7COKwJvxV5YEssB5wAfJnUa+JUdywGHEFpHVz47\n",
+ "a96BSLrW9v6SHmXhKiPb3riRAqtou/Y3gGskHU3uxpsLmirpGlKPrbeB0ZXJoxVJfBD4GXA9MMLm\n",
+ "nyWHFEII3aq9gYSr2n5R0urM7yk1T+4R1TJa6Q4k97A6F9jf5o6y4wkhhFqaNRL9AdubSbrC9qFd\n",
+ "irAHtEoCkfg8qaH8AzaPlx1PCCG0pylVWMBikg4Gtpe0Hwvehdj2dY0U2FdJiNS76iPADjbPlxxS\n",
+ "CCE0VXsJ5FjgYGAZYK8qj0cCySQGAhcBm5IWemq52YpDCKG7tZdAVrZ9bK7K+nGPRdTL5EkQryIl\n",
+ "2l1s3ig5pBBC6BHtTWVySv73uHbO6dckBgO/Ja1P/uFIHiGE/qS9O5DZkiYCa0q6qeIx2967iXG1\n",
+ "PIkVgd+TZhT+dEy9HkLob9pLIB8CNgOuBL5FRSN6M4NqdRLvIY3IvxY4PQYHhhD6ow5Hokta0fYr\n",
+ "kpay3bLLqvZUN16JEaS5wL5t891mlxdCCM3U1PVAgOGSpgJP5MI2lXRhI4X1dhJbA38ETo3kEULo\n",
+ "7+pJIN8lLeT0dwDbDwE7NjOoViSxO/Ab4GibK8qOJ4QQylbXyn62KwfF9atpyCUOBK4APmLz27Lj\n",
+ "CSGEVlDPdO7PS9oeQNIg4AToP1N0SIwGTgV2s3mk7HhCCKFV1NWIDpwP7ErqiTUBOMH27OaHV7/u\n",
+ "bkTPU5OcDhwG7G7zt+66dgghtIqmTKbY23RnApEYQEqa7wP2sJnZHdcNIYRW09ReWJKGSbpe0iv5\n",
+ "51eShjZSWG+Ql569EtgEGBXJI4QQqqunEf0S4EZg1fxzUz7W50gsBfwaWJo0HftrJYcUQggtq54E\n",
+ "sqLtS2zPyT+XAu9utMB8R3ObpMckPSrphHx8iKSJkp6SNEHSsoXnjJX0tKQnJO3eaNntx8UQ0ujy\n",
+ "WcB+Nv9pRjkhhNBX1JNAZks6VNJASYtIOgS6NF35HOBztjcEtgE+LWkDYAww0fa6wK15n7wm+oHA\n",
+ "CNJ4lAsl1dX9uF4SqwF/Au4GjrL7VzflEEJoRD0fxEeR1iefCbwE7A8c2WiBtmfmwYjYfpPUJXg1\n",
+ "YG/gsnzaZcC+eXsfYHy++5kGPANs1Wj5lSSGA3eSxnmcZDO3u64dQgh9WYfjQPKHdrUFpbpM0hrA\n",
+ "SOBeYCXbs/JDs4CV8vaqwD2Fp00nJZxuKJ/NSKPLz7D5aXdcM4QQ+osOE4iky0njPl7L+8sB59k+\n",
+ "qisFS1oa+BVwou03pPm9yGxbUnv9i6s+JmlcYXeS7Um1y2dz0nTsx9qxumIIoX+QNAoY1R3Xqmck\n",
+ "+sZtyQPA9j8kbdaVQiUtSkoeV9i+IR+eJWll2zMlrQK8nI/PAIYVnj40H1uI7XH1lc9g4BfAZyJ5\n",
+ "hBD6k/zFelLbvqQzG71WPW0gkjSksDMEGNhogUq3Gj8Dptouzmh7I3B43j4cuKFw/OOSBklaExgO\n",
+ "TG60/OwHwG02v+jidUIIod+q5w7kPODPkq4hTWWyP3B2F8rcHjgEeETSg/nYWOAbwDWSjgamkRru\n",
+ "sT01lz2VNInjaHdh+LzEocCWwBYNv4IQQgj1TWUiaUNgZ1Lbwx9tT212YJ1Vz3B8iXWAPwO72jzc\n",
+ "M5GFEELrirmw6PhNyFOU3AlcYXNBz0UWQgitq9krEvYVZ5G6B3+/7EBCCKEvqKcNpNfLqwkeDIy0\n",
+ "q3cBDiGE0Dl9PoFIvJs0+eNhNq+UHU8IIfQVfboKK6/rcSlwmc2tJYcTQgh9Sp9OIMBngCFAwwNl\n",
+ "QgghVNdne2FJLAP8FdjO5qnyIgshhNYVvbCqOw74QySPEEJojj55ByKxJPA30oDBR8uNLIQQWlfc\n",
+ "gSzsaOCeSB4hhNA8fe4OJI84fwb4mN3lSRdDCKFPizuQBR0MPBnJI4QQmqtPDSSUGEhaS/3YsmMJ\n",
+ "IYS+rq/dgewHvEphsZQQQgjN0dcSyKnA2THfVQghNF+vSSCS9pD0hKSnJZ1c47T/Ar/tybhCCKG/\n",
+ "6hUJRNJA0jTsewAjgIMkbVDl1O1a6e4jL17fUiKm+rViXBFTfSKmntErEgiwFfCM7Wm25wA/B/ap\n",
+ "PMlmbo9H1r5RZQdQxaiyA6hiVNkB1DCq7ACqGFV2AFWMKjuAKkaVHUAVo8oOoLv1lgSyGvBCYX96\n",
+ "PhZCCKEkvSWBtEy1VAghhKRXjESXtA0wzvYeeX8sMNf2OYVzWv+FhBBCC2p0JHpvSSCLAE8CuwAv\n",
+ "ApOBg2w/XmpgIYTQj/WKkei235Z0PHAzMBD4WSSPEEIoV6+4AwkhhNB6eksjek11DjBsRrkXS5ol\n",
+ "aUrh2BBJEyU9JWmCpGULj43NMT4hafcmxTRM0m2SHpP0qKQTWiSuxSXdK+khSVMlfb0V4srlDJT0\n",
+ "oKSbWiEmSdMkPZJjmtwiMS0r6ZeSHs+/v63LjEnSevn9afv5p6QTyn6fCuU8JmmKpKslLVZ2XJJO\n",
+ "zPE8KunEfKx7YrLda39I1VnPAGsAiwIPARv0UNnvA0YCUwrHzgW+lLdPBr6Rt0fk2BbNsT4DDGhC\n",
+ "TCsDm+btpUntRhuUHVcua8n87yLAPcAOLRLX54GrgBtb5Hf4LDCk4ljZMV0GHFX4/S1TdkyF2AYA\n",
+ "LwHDyo4pX/tvwGJ5/xfA4WXGBbwXmAIsTvq8nAis3V0xNeWX2lM/wLbAHwr7Y4AxPVj+GiyYQJ4A\n",
+ "VsrbKwNP5O2xwMmF8/4AbNMD8d0A7NpKcQFLAn8BNiw7LmAocAuwE3BTK/wOSQlk+YpjpcVEShZ/\n",
+ "q3K8Jf6mgN2BO1ohJmAI6UvbcqREexOwW8m/v48BPy3snwZ8qbti6u1VWK02wHAl27Py9ixgpby9\n",
+ "Kim2Nk2PU9IapDuke1shLkkDJD2Uy7/N9mMtENd3gJNggRkMyo7JwC2S7pP0yRaIaU3gFUmXSHpA\n",
+ "0k8kLVVyTEUfB8bn7VJjsv0qcB7wPKm36Gu2J5Yc16PA+3KV1ZLAh0hfnLolpt6eQFq2B4BT+m4v\n",
+ "vqbFLmlp4FfAibbfaIW4bM+1vSnpj/f9knYqMy5JewIv234QqNoHvqT3anvbI4EPAp+W9L6SY1oE\n",
+ "2Ay40PZmwL9Id/plxgSApEHAXsC1CxVYQkyS1gY+S6qZWBVYWtIhZcZl+wngHGAC8HtS9dQ73RVT\n",
+ "b08gM0h1n22GsWD27GmzJK0MIGkV4OV8vDLOoflYt5O0KCl5XGH7hlaJq43tf5JmTN685Li2A/aW\n",
+ "9CzpG+zOkq4oOSZsv5T/fQW4njQPXJkxTQem2/5L3v8lKaHMbIG/qQ8C9+f3Csr/O98CuNv2bNtv\n",
+ "A9eRqtlLfa9sX2x7C9s7Av8AnqKb3qvenkDuA4ZLWiN/GzkQuLHEeG4kNZqR/72hcPzjkgZJWhMY\n",
+ "Dt2/5K4kAT8Dptr+bgvFtUJbLw9JS5DqhR8sMy7bp9geZntNUjXIH20fWmZMkpaUNDhvL0Wq359S\n",
+ "Zky2ZwIvSFo3H9oVeIxUv1/a31R2EPOrr9rKLjOmJ4BtJC2R/y/uCkyl5PdK0rvzv+8hLbp3Nd31\n",
+ "XnV3Q1JP/5C+hTxJ6i0wtgfLHU+q53yL1A5zJKkR7RZShp8ALFs4/5Qc4xPAB5oU0w6k+vyHSB/Q\n",
+ "D5KmwC87ro2AB3JcjwAn5eOlxlUoa0fm98IqLSZSe8ND+efRtr/nst8nYBNSx4eHSd+ql2mBmJYC\n",
+ "/g4MLhwr/e+J1ED9GCnxX0bqzVT2e/WnHNNDwE7d+V7FQMIQQggN6e1VWCGEEEoSCSSEEEJDIoGE\n",
+ "EEJoSCSQEEIIDYkEEkIIoSGRQEIIITQkEkgLywMkp3R8Zl3X2lHStp19rDtJWl9pSvf7Ja3V7PI6\n",
+ "iOUEpanJr8iDpm7Jcz0dkOd72qCd5+6lBpcOkLSMpOM6+1gH1yy+lk7HJukdpWnR23432+bjq0s6\n",
+ "qBPXGSPpE3n7eElH5O0Ffu/VrinpzPaOSdotzw/2SP53p8Jjt7YNwKx1PaVp1W9XmpNtlPL0/XW8\n",
+ "pm9XTicT5otxIC1MaULEm2xv1A3XGge8Yfu8Tj420PY7lccbjGEMMND22Z14zgDbczs+s9OxPA7s\n",
+ "YvtFSdsAZ9nerbvLqVLuGtT4nTb6+y6+lgZjesN22wj43YFTbI+SNAr4gu296rzOH4H9gVdJA0e3\n",
+ "dFpNdN7vvfKaks4mTfi5G2kQ7MXAAVWOCZhpe6akDYGbbQ/N1/gkaUDhtyUdDKwCLJ/jeNH2VZKO\n",
+ "Is1y/M16X5ekAaSpz8+zvXc970G/06wRmfHTLSNI1yBNhfBj0sjkm4HF82NrkyZHu4800nS9fHwv\n",
+ "0nobD5Dm/n93vs5LpHmNHgR2qCij7bEHSKPZLwV+mK/zLWBL4O78+F3Auvm5R5BGJv+eNKL1nHx8\n",
+ "YL7GFNLI88+SZgxoK+fWfN4hpA+KB3N5A/LxN3O5DwHbVbwn65BG0D4E3A+smY9/s1DeAYXzTyJN\n",
+ "xfAwMC4f+yHwv3zul4Cngdfy61sLmARsns/dI5fzEDCx8LovyNsrkuaHmpx/tsvHx5E++G4D/gp8\n",
+ "Jh//OfDv/JrPqXhtCz1W63UVnlN8LZ+tiO1S4Pz8O/sr8NEaf2dvFLb3B67L2/fk9+XBfO3D266d\n",
+ "H/8NsGPefhdwZ97eARiftz9U+L3/Efhz4Zon5nMuIn3YDy9ce6FjhccEzAYWzfsrAZMLjx8EvF3x\n",
+ "dzCR+X+3o/Lv5VrgceDKwnnTgG/k3/kB+dgjFEZqx0/hd1F2APHTzi8nfbjPATbO+78ADs7btwLr\n",
+ "5O2tmf+hXJyS4P+Ab+XtM4HP1yhngceAS0hz4rTdoQ4mfYOENL/PL/P2EfmDaTCwWP7PN5Q0UeKE\n",
+ "wvXeVVkOaaGrGwvXvRA4NG/PBT5WI9Z7gX3y9iBgCeCjpOkYREqYz5HWONgd+FE+dwDpA+99ef9Z\n",
+ "8sJNpKlMbiqUcRtpwsAVSVNzr158byl8kJLmFdo+b7+HNA8ZpARyJ2kqi+VJ024MBFansIZMxWtb\n",
+ "4LFar6vK84qvpRjbpcAvCu/30zXKfZv0gf446cN9ZI33pTKB3AS8P2/vx/wEPYYF/56Kv/fKa54F\n",
+ "7A18j5TsNq52rCLej1H4+8rH/kZaRO0g4IvA10lfHg7K7/tLhXNH5de5an5v72Z+4n8W+GLFtS8D\n",
+ "Plj250Er/ixCaHXP2n4kb98PrJEn2tsOuDbN2QakD1OAYZKuIX2ADiL9x2pTddryGo9d6/y/B1gW\n",
+ "uFzSOqSpnYt/N7c6TxkvaSr5QxRYS9L3SDPvTqhSzi6kRHNffg1LADPzY++QZhReMMBUz72q7V8D\n",
+ "2H4rH98euDrH+7Kk20l3TTsCu0t6MF9iKdIdzB0dvPa2Y9sAf7L9XC7vtSrn7QpsUPg9DM6/HwO/\n",
+ "tT0HmC3pZdI35c78Dmq9rrrq73MMN+TYH5e0Uo3z/uM0hTy5Ou8K0kp27cVaaQ/SRJ6Q/gburHhc\n",
+ "Ff+S4zo9lzvS9pfz4UeqHCMf25B0h1BZ3TgLGGZ7fD7vTNvfzNsrAW9UnD/ZucpPaZ2aNUiJBNIX\n",
+ "taIX8+OhQiSQ1ve/wvY7pKUpBwD/aPtPX+EC0l3HbyTtSPom3Ih/F7bPIiWKj0hanVTFUyu+RWy/\n",
+ "JmkT4APAsaQ67aOrlHGZ7VOqHP9vIXnVq9aH3ddt/7iT12pTTwwCtm5LZvMOpoRSPPYOjf1/q3xd\n",
+ "nX1fijF0mBBs36M0e/IKVR5+mwU73ixe2N4S+FRnyqoo98sdHZM0lFRleqjtZytOF4WFwapcrzKe\n",
+ "hf5uC/v/qvLcaCyuInph9T7K3/iflfQxSNO4S9o4P/4u0jcmSFVMbd4gVTVV095jldc8sqP4JC1P\n",
+ "qpq6DjidVB0EC/4nvhX4mKQV85OGKE03XVN+3dMl7ZOfs5jS9PB3AAfmHjYrAu8nVXXdDByV7wiQ\n",
+ "tFpbeXUwqQ3g/blxG0lDqryOCcAJhRe/SQfX7czvodrr6mi677o+uCU9UeP4+qTPhdlV4pkGbJr/\n",
+ "3oaR1ippuyt4opD026oQq+nob61WvMuS7mZPtv3nKqesRO21gP5Oqt5q1Cqk1x4qRAJpfZXffNr2\n",
+ "DwaOzrffj5LqjCHdcVwr6T7glcL5NwEfyd01t6+4ZttjD0jaoUq55wJfl/QAqT7ZhXOqxbcacFuu\n",
+ "OrqC+SvYzTvf9uOk9ZknSHqY9EG8cuG8Wg4FTsjPuYu0NOf1pGqPh0mJ6STbLzstJ3o18GdJj5Aa\n",
+ "Tat9kFR7Hdj+O3AMcF1+n8dXOf8EYAtJD0t6jAW/hVe75mzgLklTJJ3T3mO1XleN+Gu9loW2q9xd\n",
+ "LJH/Lh4kNeQfnpPBw8A7Sl1wT7R9F6mNYCqpbeJ+UsL6IKkjRZs7SYsrVYtxgWtWeS21HE/qOHJm\n",
+ "W6yFLx8rA7NtV945pIJTL8JHJa1XiKUzdxQjSY3/oUJ04w2hn5H0YVLvte930/UmkKqVZuV9kXq0\n",
+ "LVS11wySjgGWsv2dds45gvRl45xa59R43rqkKuHoxltFJJAQQreTNJrUOH9JD5R1K6ln3pvtnDOI\n",
+ "1P17x860r0n6Nqlbc2WngEAkkBBCCA2KNpAQQggNiQQSQgihIZFAQgghNCQSSAghhIZEAgkhhNCQ\n",
+ "SCAhhBAa8v/Onrp6J+51IAAAAABJRU5ErkJggg==\n"
+ ],
+ "text/plain": [
+ "<matplotlib.figure.Figure at 0xaadcc88>"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "print\"\\t example 16.1 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "import numpy\n",
+ "import matplotlib\n",
+ "%matplotlib inline\n",
+ "from matplotlib import pyplot\n",
+ "from math import tanh\n",
+ "Af=(20*0.75*12*2)/(144);\n",
+ "Ao=((3.14*1.25)-(20*0.035))*(12/144);\n",
+ "print\"\\t fin surface is : %.1f ft**2/lin ft \\t\",Af\n",
+ "print\"\\t bare tube surface is : ft**2/lin ft \\t\",Ao\n",
+ "A=(Af+Ao);\n",
+ "print\"\\t total outside surface : ft**2/lin ft \\t\",A\n",
+ "Ai=(3.14*1.06*12)/(144);\n",
+ "print\"\\t total inside surface : ft**2/lin ft \\t\",Ai\n",
+ "print\"\\t fin efficiencies \\t\"\n",
+ "b=0.0625; # ft\n",
+ "hf=4; # from table in solution\n",
+ "m=(5.24*(hf**(1/2))); # m=((hf*P)/(Kax))**(1/2), eq 16.8\n",
+ "n=(tanh(m*b))/(m*b); # efficiency , eq 16.26\n",
+ "print\"\\t hf m n \\t \"\n",
+ "print hf \n",
+ "print m \n",
+ "print n\n",
+ "# similarly efficiencies values are calculated at different hf values\n",
+ "print\"\\t weighted efficiency curve \\t\"\n",
+ "hfi=((n*Af)+(Ao))*(hf/Ai); # eq 16.34\n",
+ "print\"\\t hf hfi \\t \"\n",
+ "print hf \n",
+ "print hfi\n",
+ "# similarly efficiencies values are calculated at different hf values\n",
+ "hf=[4, 16, 36, 100, 400, 625, 900]; # from 2nd table in the solution\n",
+ "hfi=[35.4, 110.8, 193.5, 370, 935, 1295, 1700]; # from 2nd table in the solution\n",
+ "pyplot.plot(hf,hfi)\n",
+ "pyplot.xlabel('heat transfer coefficient to fin,Btu/(ft**2)*(hr)')\n",
+ "pyplot.ylabel('coefficient hf referred to the tube ID')\n",
+ "pyplot.title('weighted fin efficiency curve')\n",
+ "pyplot.show()\t\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.2 pgno:525"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 16.2 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t annulus flow area : ft**2 \t0.0391482454167\n",
+ "\t wetted perimeter : ft \t2.76875\n",
+ "\t equivalent diameter : ft \t0.0565572845749\n",
+ "\t heat load : Btu/hr \t270286.4\n",
+ "\t delt1 is : F \t151.0\n",
+ "\t delt2 is : F \t117.0\n",
+ "\t LMTD is F \t133.427780969\n",
+ "\t Ui : Btu/(hr)*(ft**2)*(F) \t365.652178958\n",
+ "\t hfi : Btu/(hr)*(ft**2)*(F) \t416.40535396\n",
+ "\t jf : \t36.7135894676\n",
+ "\t Ga : lb/(hr)*(ft**2) \t388267.720257\n",
+ "\t Rea : \t11319.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 16.2 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "Ts=302.; # F\n",
+ "t1=151.;\n",
+ "t2=185.;\n",
+ "w=15200.; # lb/hr\n",
+ "from math import log10\n",
+ "# The dropwise condensation of steam was promoted with oil.\n",
+ "aa=(3.14*(3.068**2-1.25**2))/(4*144)-((20*0.035*0.75)/(144));\n",
+ "print\"\\t annulus flow area : ft**2 \\t\",aa\n",
+ "p=(3.14*(1.25/12))-(20*0.035/12)+(20*0.75*2/12);\n",
+ "print\"\\t wetted perimeter : ft \\t\",p\n",
+ "De=(4*aa/p);\n",
+ "print\"\\t equivalent diameter : ft \\t\",De\n",
+ "Q=w*0.523*(t2-t1);\n",
+ "print\"\\t heat load : Btu/hr \\t\",Q\n",
+ "delt1=Ts-t1; #F\n",
+ "delt2=Ts-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is F \\t\",LMTD\n",
+ "Ai=0.277; # ft**2/ft\n",
+ "n=20; # number of fins\n",
+ "Ui=(Q/(Ai*n*LMTD));\n",
+ "print\"\\t Ui : Btu/(hr)*(ft**2)*(F) \\t\",Ui\n",
+ "hi=3000; # assumed value for dropwise condensation of steam\n",
+ "hfi=(Ui*hi)/(hi-Ui);\n",
+ "print\"\\t hfi : Btu/(hr)*(ft**2)*(F) \\t\",hfi\n",
+ "hf=120; # from fig 16.7 for hfi=418\n",
+ "mu=1.94; # lb/(ft*hr)\n",
+ "k=0.079;\n",
+ "Z=2.34; # Z=((c*mu)/k)**(1/3)\n",
+ "jf=(hf*De/(Z*k)); # eq 16.36\n",
+ "print\"\\t jf : \\t\",jf\n",
+ "Ga=(w/aa);\n",
+ "print\"\\t Ga : lb/(hr)*(ft**2) \\t\",Ga\n",
+ "Rea=(De*Ga/mu);\n",
+ "print\"\\t Rea : \\t\",round(Rea)\n",
+ "# end\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.3 pgno:530"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 16.3 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t total heat required for gas oil is : Btu/hr \t477000.0\n",
+ "\t total heat required for water is : Btu/hr \t478000.0\n",
+ "\t delt1 is : F \t120.0\n",
+ "\t delt2 is : F \t130.0\n",
+ "\t LMTD is :%.0f F \t125.073724087\n",
+ "\t ratio of two local temperature difference is : \t0.923076923077\n",
+ "\t caloric temperature of hot fluid is : F \t223.5\n",
+ "\t caloric temperature of cold fluid is : F \t98.8\n",
+ "\t hot fluid:shell side,gas oil \t\n",
+ "\t flow area is : ft**2 \t0.0287156933333\n",
+ "\t wetted perimeter : in \t29.126\n",
+ "\t De : ft \t0.0473238096546\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t626834.943216\n",
+ "\t reynolds number is : \t4903.1764525\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t97.2026562015\n",
+ "\t cold fluid:inner tube side,water \t\n",
+ "\t flow area is : ft**2 \t0.01409546\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t847790.707079\n",
+ "\t V is : fps \t3.76795869813\n",
+ "\t reynolds number is : \t65199.6985471\n",
+ "\t hi : Btu/(hr)*(ft**2)*(F) \t795.4\n",
+ "\t calculation of tfw \t\n",
+ "\t phya is : \t0.953986161765\n",
+ "\t Correct hf to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t92.729988903\n",
+ "\t Rf : \t0.0107839978396\n",
+ "\t hf1 : \t78.2227916919\n",
+ "\t hfi2 : \t450.563280145\n",
+ "\t Rmetal : \t0.00170212455807\n",
+ "\t Ri : \t0.00125722906714\n",
+ "\t hi1 : \t234.894572087\n",
+ "\t UDi : \t122.267359744\n",
+ "\t Ai : ft**2 \t31.2572870644\n",
+ "\t length of pipe required : lin ft \t74.0694006266\n",
+ "\t Q/Ai1 : Btu/(hr)*(ft**2) \t14158.7677725\n",
+ "\t annulus film : \t31.4245931625\n",
+ "\t annulus dirt : \t4.9162388099\n",
+ "\t Tc-tfw : \t36.3408319724\n",
+ "\t fin and tube metal : \t24.0999863376\n",
+ "\t tube side dirt : \t42.4763033175\n",
+ "\t tubeside film : \t17.8008143984\n",
+ "\t total temperature drop : F \t120.717936026\n",
+ "\t pressure drop for annulus \t\n",
+ "\t reynolds number : \t3719.56602669\n",
+ "\t delPs is : psi \t7.7\n",
+ "\t allowable delPa is 10 psi \t\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t1.6\n",
+ "\t allowable delPa is 10 psi \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 16.3 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=250.; # inlet hot fluid,F\n",
+ "T2=200.; # outlet hot fluid,F\n",
+ "t1=80.; # inlet cold fluid,F\n",
+ "t2=120.; # outlet cold fluid,F\n",
+ "W=18000; # lb/hr\n",
+ "w=11950; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "C=0.53; # Btu/(lb)*(F)\n",
+ "Q=((W)*(C)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for gas oil is : Btu/hr \\t\",Q\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is :%.0f F \\t\",LMTD\n",
+ "X=((delt1)/(delt2));\n",
+ "print\"\\t ratio of two local temperature difference is : \\t\",X\n",
+ "Fc=0.47; # from fig.17\n",
+ "Kc=0.27; \n",
+ "Tc=((T2)+((Fc)*(T1-T2))); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+((Fc)*(t2-t1))); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:shell side,gas oil \\t\"\n",
+ "ID=3.068; # in, table 11\n",
+ "OD=1.9; # in, table 11\n",
+ "af=0.0175; # fin cross section,table 10\n",
+ "aa=((3.14*ID**2/(4))-(3.14*OD**2/(4))-(24*af))/(144);\n",
+ "print\"\\t flow area is : ft**2 \\t\",aa\n",
+ "p=(3.14*(OD))-(24*0.035)+(24*0.5*2);\n",
+ "print\"\\t wetted perimeter : in \\t\",p\n",
+ "De=(4*aa*12/(p));\n",
+ "print\"\\t De : ft \\t\",De\n",
+ "Ga=(W/aa); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Ga\n",
+ "mu1=2.5*2.42; # at 224F,lb/(ft)*(hr), from fig.14\n",
+ "Rea=((De)*(Ga)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Rea\n",
+ "jf=18.4; # from fig.16.10\n",
+ "Z=0.25; # Z=k*((c)*(mu1)/k)**(1/3), fig 16\n",
+ "Hf=((jf)*(1/De)*(Z)); # Hf=(hf/phya),using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Hf\n",
+ "print\"\\t cold fluid:inner tube side,water \\t\"\n",
+ "D=0.134; # ft\n",
+ "row=62.5;\n",
+ "at=(3.14*D**2/(4));\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "V=(Gt/(3600*row));\n",
+ "print\"\\t V is : fps \\t\",V\n",
+ "mu2=0.72*2.42; # at 99F,lb/(ft)*(hr)\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hi=(970*0.82); # fig 25\n",
+ "print\"\\t hi : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "print\"\\t calculation of tfw \\t\"\n",
+ "# Tc-tfw=40F assumption from fig 14\n",
+ "tfw=184;\n",
+ "mufw=3.5; # cp, at 184F\n",
+ "phya=(2.5/mufw)**0.14;\n",
+ "print\"\\t phya is : \\t\",phya # from fig.24\n",
+ "hf=(Hf)*(phya); # from eq.6.36\n",
+ "print\"\\t Correct hf to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hf\n",
+ "Rdo=0.002;\n",
+ "Rf=(1/hf);\n",
+ "print\"\\t Rf : \\t\",Rf\n",
+ "hf1=(1/(Rdo+Rf)); # eq 16.37\n",
+ "print\"\\t hf1 : \\t\",hf1\n",
+ "hfi1=255; # fig 16.9\n",
+ "hfi2=(hf1*5.76); # eq 16.38 and fig 16.9,((Af+Ao)/(Ai))=5.76 from previous prblm\n",
+ "print\"\\t hfi2 : \\t\",hfi2\n",
+ "Rmetal=(hfi2-hfi1)/(hfi2*hfi1)# eq 16.39\n",
+ "print\"\\t Rmetal : \\t\",Rmetal\n",
+ "phyt=1; # for cooling water\n",
+ "Rdi=0.003;\n",
+ "Ri=(1/hi);\n",
+ "print\"\\t Ri : \\t\",Ri\n",
+ "hi1=(1/(Rdi+Ri)); # eq 16.40\n",
+ "print\"\\t hi1 : \\t\",hi1\n",
+ "UDi=(hi1*hfi1)/(hi1+hfi1); # eq 16.41\n",
+ "print\"\\t UDi : \\t\",UDi\n",
+ "# To obtain the true flux the heat load must be divided by the actual heat-transfer surface.For a 1}2-in. IPS pipe there are 0.422 ft2/lin foot, from table 11\n",
+ "# trial\n",
+ "Ai=(Q/(UDi*LMTD)); # LMTD=delt\n",
+ "print\"\\t Ai : ft**2 \\t\",Ai\n",
+ "L=(Ai/0.422);\n",
+ "print\"\\t length of pipe required : lin ft \\t\",L\n",
+ "# Use two 20-ft hairpins = 80 lin ft\n",
+ "Ai1=(80*0.422); # ft**2\n",
+ "r=(Q/Ai1);\n",
+ "print\"\\t Q/Ai1 : Btu/(hr)*(ft**2) \\t\",r\n",
+ "deltf=(r/hfi2);\n",
+ "deltdo=(r*Rdo/5.76);\n",
+ "print\"\\t annulus film : \\t\",deltf\n",
+ "print\"\\t annulus dirt : \\t\",deltdo\n",
+ "d=deltf+deltdo; # d=Tc-tfw\n",
+ "deltmetal=(r*Rmetal);\n",
+ "deltdi=(r*Rdi);\n",
+ "delti=(r/hi);\n",
+ "print\"\\t Tc-tfw : \\t\",d\n",
+ "print\"\\t fin and tube metal : \\t\",deltmetal\n",
+ "print\"\\t tube side dirt : \\t\",deltdi\n",
+ "print\"\\t tubeside film : \\t\",delti\n",
+ "Td=deltf+deltdo+deltmetal+deltdi+delti;\n",
+ "print\"\\t total temperature drop : F \\t\",Td\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "De1=0.0359; # ft\n",
+ "Rea1=(De1*Ga/mu1);\n",
+ "print\"\\t reynolds number : \\t\",Rea1\n",
+ "f=0.00036; # fig 16.10\n",
+ "s=0.82; #using fig.6\n",
+ "delPs=((f*(Ga**2)*(80))/(5.22*(10**10)*(De1)*(s)*(phya))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",round(delPs,1)\n",
+ "print\"\\t allowable delPa is 10 psi \\t\"\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.000192; # friction factor for reynolds number 65000, using fig.26\n",
+ "s=1;\n",
+ "delPt=((f*(Gt**2)*(80))/(5.22*(10**10)*(0.134)*(s)*(1))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt,1)\n",
+ "print\"\\t allowable delPa is 10 psi \\t\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.4 pgno:535"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 16.4 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t total heat required for oxygwn is : Btu/hr \t1012500.0\n",
+ "\t total heat required for water is : Btu/hr \t1010000\n",
+ "\t delt1 is : F \t20\n",
+ "\t delt2 is : F \t150\n",
+ "\t LMTD is : F \t66.8818722257\n",
+ "\t R is : \t7\n",
+ "\t S is : \t0\n",
+ "\t FT is 0.87 \t\n",
+ "\t delt is : F \t58.1872288364\n",
+ "\t caloric temperature of hot fluid is : F \t175\n",
+ "\t caloric temperature of cold fluid is : F \t90\n",
+ "\t hot fluid:shell side,oxygen \t\n",
+ "\t flow area is : ft**2 \t1.46834418403\n",
+ "\t wetted perimeter : in \t1570.8\n",
+ "\t De : ft \t0.0448691882056\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t20431.1770539\n",
+ "\t reynolds number is : \t16820.7399724\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t20.6536497998\n",
+ "\t hf1 : \t19.4485963081\n",
+ "\t cold fluid:inner tube side,water \t\n",
+ "\t flow area is : ft**2 \t0.0582118055556\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t867521.622428\n",
+ "\t V is : fps \t3.85565165523\n",
+ "\t reynolds number is : \t29155.8813311\n",
+ "\t hi : Btu/(hr)*(ft**2)*(F) \t902.4\n",
+ "\t hi1 : Btu/(hr)*(ft**2)*(F) \t243.418213207\n",
+ "\t overall coefficient is : Btu/(hr)*(ft**2)*(F) \t89.6828045249\n",
+ "\t total surface area is : ft**2 \t229.376\n",
+ "\t design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t75.673831631\n",
+ "\t excess fouling factor : \t0.00206419817483\n",
+ "\t Rdo : \t0.0221351170807\n",
+ "\t hf2 : \t14.1738000666\n",
+ "\t overall coefficient is : Btu/(hr)*(ft**2)*(F) \t77.1741091592\n",
+ "\t pressure drop for annulus \t\n",
+ "\t reynolds number : \t16232.4764484\n",
+ "\t delPs is : psi \t0.6\n",
+ "\t allowable delPa is 2 psi \t\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t3.0\n",
+ "\t allowable delPa is 10 psi \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 16.4 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=250; # inlet hot fluid,F\n",
+ "T2=100; # outlet hot fluid,F\n",
+ "t1=80; # inlet cold fluid,F\n",
+ "t2=100; # outlet cold fluid,F\n",
+ "W=30000; # lb/hr\n",
+ "w=50500; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "C=0.225; # Btu/(lb)*(F)\n",
+ "Q=((W)*(C)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for oxygwn is : Btu/hr \\t\",Q\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \\t\",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \\t\",S\n",
+ "print\"\\t FT is 0.87 \\t\"# from fig 18\n",
+ "delt=(0.87*LMTD); # F\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "Tc=(T2+T1)/(2); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2))/(2); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:shell side,oxygen \\t\"\n",
+ "ID=19.25; # in, table 11\n",
+ "OD=1; # in, table 11\n",
+ "As=((3.14*ID**2/(4))-(70*3.14*OD**2/(4))-(70*20*0.035*0.5))/(144);\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "p=(70*3.14*(OD))-(70*20*0.035)+(70*20*0.5*2);\n",
+ "print\"\\t wetted perimeter : in \\t\",p\n",
+ "De=(4*As*12/(p));\n",
+ "print\"\\t De : ft \\t\",De\n",
+ "Gs=(W/As); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=0.0545; # at 175F,lb/(ft)*(hr), from fig.15\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jH=59.5; # from fig.16.10a\n",
+ "k=0.0175;\n",
+ "Z=0.89; # Z=((c)*(mu1)/k)**(1/3), fig\n",
+ "hf=((jH)*(k/De)*(Z)); #using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",hf\n",
+ "Rdo=0.003;\n",
+ "hdo=(1/Rdo);\n",
+ "hf1=(hdo*hf)/(hdo+hf); # eq 16.37\n",
+ "print\"\\t hf1 : \\t\",hf1\n",
+ "hfi1=142; # fig 16.9\n",
+ "print\"\\t cold fluid:inner tube side,water \\t\"\n",
+ "at1=0.479; # table 10\n",
+ "L=16;\n",
+ "Nt=70;\n",
+ "n=4;\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "D=0.0652; # ft\n",
+ "row=62.5;\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "V=(Gt/(3600*row));\n",
+ "print\"\\t V is : fps \\t\",V\n",
+ "mu2=1.94; # at 90F,lb/(ft)*(hr)\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hi=(940*0.96); # fig 25\n",
+ "print\"\\t hi : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "Rdi=0.003;\n",
+ "hdi=(1/Rdi);\n",
+ "hi1=(hdi*hi)/(hdi+hi);\n",
+ "print\"\\t hi1 : Btu/(hr)*(ft**2)*(F) \\t\",hi1\n",
+ "UDi=((hfi1)*(hi1)/(hi1+hfi1)); # eq 16.41,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UDi\n",
+ "A2=0.2048; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A\n",
+ "UDi1=((Q)/((A)*(delt)));\n",
+ "print\"\\t design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UDi1\n",
+ "Re=(1/UDi1)-(1/UDi);\n",
+ "print\"\\t excess fouling factor : \\t\",Re\n",
+ "Ro=9.27; #Adding to the outside fouling factor\n",
+ "Rdo1=Rdo+(Re*Ro);\n",
+ "print\"\\t Rdo : \\t\",Rdo1\n",
+ "hf2=(hf/(1+(hf*Rdo1)));\n",
+ "print\"\\t hf2 : \\t\",hf2\n",
+ "hfi2=113;\n",
+ "UDi2=((hfi2)*(hi1)/(hi1+hfi2)); # eq 16.41,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UDi2\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "De1=0.0433; # ft\n",
+ "Res1=(De1*Gs/mu1);\n",
+ "print\"\\t reynolds number : \\t\",Res1\n",
+ "f=0.00025; # fig 16.10\n",
+ "s=0.00133;\n",
+ "delPs=((f*(Gs**2)*(L))/(5.22*(10**10)*(De1)*(s)*(1))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",round(delPs,1)\n",
+ "print\"\\t allowable delPa is 2 psi \\t\"\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.00021; # friction factor for reynolds number 29100, using fig.26\n",
+ "s=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(0.0625)*(s)*(1))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt)\n",
+ "print\"\\t allowable delPa is 10 psi \\t\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 16.5 pgno:556"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 16.5 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t total heat required for air is : Btu/hr \t1250000.0\n",
+ "\t total heat required for water is : Btu/hr \t1248000.0\n",
+ "\t delt1 is : F \t50.0\n",
+ "\t delt2 is : F \t60.0\n",
+ "\t LMTD is : F \t54.9097962457\n",
+ "\t R is : \t1.25\n",
+ "\t S is : \t0.4\n",
+ "\t FT is 0.985 \t\n",
+ "\t delt is : F \t54.086149302\n",
+ "\t caloric temperature of hot fluid is : F \t225.0\n",
+ "\t caloric temperature of cold fluid is : F \t170.0\n",
+ "\t fin surface is : in**2/lin ft \t310.86\n",
+ "\t bare tube surface is : in**2/lin ft \t27.1296\n",
+ "\t total outside surface : ft**2/lin ft \t337.9896\n",
+ "\t projected perimeter : in/ft \t161.28\n",
+ "\t De : ft \t0.111235119048\n",
+ "\t flow area : ft**2 \t7.53\n",
+ "\t hot fluid:shell side,oxygen \t\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t13280.2124834\n",
+ "\t reynolds number is : \t28408.1926263\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t22.9878748896\n",
+ "\t hf1 : \t21.5048242607\n",
+ "\t cold fluid:inner tube side,water \t\n",
+ "\t flow area is : ft**2 \t0.079625\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t391836.734694\n",
+ "\t V is : fps \t1.74149659864\n",
+ "\t reynolds number is : \t30427.5453198\n",
+ "\t hi : Btu/(hr)*(ft**2)*(F) \t667.4\n",
+ "\t hi1 : Btu/(hr)*(ft**2)*(F) \t222.303643994\n",
+ "\t X : \t0.03125\n",
+ "\t hfi2 : \t212.371237248\n",
+ "\t overall coefficient is : Btu/(hr)*(ft**2)*(F) \t108.611980947\n",
+ "\t inside surface per bank is : ft**2 \t18.312\n",
+ "\t Ai1 : ft**2 \t212.447090593\n",
+ "\t number of banks : \t11.6015230774\n",
+ "\t net free volume : ft**3 \t1.89483559028\n",
+ "\t frictional surface : ft**2 \t191.88\n",
+ "\t pressure drop for annulus \t\n",
+ "\t De1 : ft \t0.0395004292324\n",
+ "\t reynolds number : \t10087.9633345\n",
+ "\t delPs is : psi \t0.232069401484\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t0.39\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 16.5 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=250.; # inlet hot fluid,F\n",
+ "T2=200.; # outlet hot fluid,F\n",
+ "t1=150.; # inlet cold fluid,F\n",
+ "t2=190.; # outlet cold fluid,F\n",
+ "W=100000; # lb/hr\n",
+ "w=31200; # lb/hr\\\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "C=0.25; # Btu/(lb)*(F)\n",
+ "Q=((W)*(C)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for air is : Btu/hr \\t\",Q\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \\t\",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \\t\",S\n",
+ "print\"\\t FT is 0.985 \\t\" # from fig 18\n",
+ "delt=(0.985*LMTD); # F\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "Tc=(T2+T1)/(2); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2))/(2); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "Af=(3.14*2*8*12*(1.75**2-1**2))/(4);\n",
+ "Ao=((3.14*1*12)-(3.14*1*8*0.035*12));\n",
+ "print\"\\t fin surface is : in**2/lin ft \\t\",Af\n",
+ "print\"\\t bare tube surface is : in**2/lin ft \\t\",Ao\n",
+ "A=(Af+Ao);\n",
+ "print\"\\t total outside surface : ft**2/lin ft \\t\",A\n",
+ "p=(2*3*2*8*12/8)+(((12)-(8*0.035*12))*(2));\n",
+ "print\"\\t projected perimeter : in/ft \\t\",p\n",
+ "De=(2*A/(3.14*p*12)); # eq 16.104\n",
+ "print\"\\t De : ft \\t\",De\n",
+ "# 21 tubes may be fit in one :vertical bank (Fig. 16.19b) ,20 tubes in alternating banks for triangular pitch\n",
+ "As=((4**2*12**2)-(21*1*48)-((21)*(2*0.035*3*8*48/8)))/(144); # fig 16.19\n",
+ "print\"\\t flow area : ft**2 \\t\",As\n",
+ "print\"\\t hot fluid:shell side,oxygen \\t\"\n",
+ "Gs=(W/As); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=0.052; # at 225F,lb/(ft)*(hr), from fig.15\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jf=157; # from fig.16.18a\n",
+ "k=0.0183;\n",
+ "Z=0.89; # Z=((c)*(mu1)/k)**(1/3), fig\n",
+ "phys=1;\n",
+ "hf=((jf)*(k/De)*(Z)); #using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",hf\n",
+ "Rdo=0.003;\n",
+ "hdo=(1/Rdo);\n",
+ "hf1=(hdo*hf)/(hdo+hf); # eq 16.37\n",
+ "print\"\\t hf1 : \\t\",hf1\n",
+ "hfi1=142; # fig 16.9\n",
+ "print\"\\t cold fluid:inner tube side,water \\t\"\n",
+ "at1=0.546; # table 10\n",
+ "L=4;\n",
+ "Nt=21;\n",
+ "n=1;\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "D=0.0695; # ft\n",
+ "row=62.5;\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "V=(Gt/(3600*row));\n",
+ "print\"\\t V is : fps \\t\",V\n",
+ "mu2=0.895; # at 170F,lb/(ft)*(hr)\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hi=(710*0.94); # fig 25\n",
+ "print\"\\t hi : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "Rdi=0.003;\n",
+ "hdi=(1/Rdi);\n",
+ "hi1=(hdi*hi)/(hdi+hi); # 16.40\n",
+ "print\"\\t hi1 : Btu/(hr)*(ft**2)*(F) \\t\",hi1\n",
+ "k1=60; # table 3 , for brass\n",
+ "# yb=0.00146 ft\n",
+ "X=((0.875-0.5)/12)*(21.5/(60*0.00146))**(1/2);\n",
+ "print\"\\t X : \\t\",X\n",
+ "nf=0.91; # from fig 16.13a , by comparing X value\n",
+ "Ai=0.218; # ft**2/ft\n",
+ "hfi2=((nf*Af/144)+(Ao/144))*(hf1/Ai); # eq 16.34\n",
+ "print\"\\t hfi2 : \\t\",hfi2\n",
+ "UDi=((hfi2)*(hi1)/(hi1+hfi2)); # eq 16.41,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UDi\n",
+ "A=(21*4*Ai); # ft**2\n",
+ "print\"\\t inside surface per bank is : ft**2 \\t\",A\n",
+ "Ai1=(Q/(UDi*delt));\n",
+ "print\"\\t Ai1 : ft**2 \\t\",Ai1\n",
+ "Nb=(Ai1/A);\n",
+ "print\"\\t number of banks : \\t\",Nb\n",
+ "Vn=(4*4*1.95/12)-(41*3.14*1*4/(2*4*144))-((41*3.14*0.035*8*4/(144*2*4))*(1.75**2-1**2)); # fig 16.19b\n",
+ "print\"\\t net free volume : ft**3 \\t\",Vn\n",
+ "Af1=(41*2.34*4/2);\n",
+ "print\"\\t frictional surface : ft**2 \\t\",Af1\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "De1=(4*Vn/Af1); # ft\n",
+ "print\"\\t De1 : ft \\t\",De1\n",
+ "Res1=(De1*Gs/mu1);\n",
+ "print\"\\t reynolds number : \\t\",Res1\n",
+ "f=0.0024; # fig 16.18b\n",
+ "s=0.000928;\n",
+ "Lp=1.95;\n",
+ "R1=0.538; # R1=(De1/ST)**(0.4)\n",
+ "R2=1; # R2=(SL/ST)**0.6\n",
+ "delPs=((f*(Gs**2)*(Lp)*(R1)*(R2))/(5.22*(10**10)*(De1)*(s)*(1)));\n",
+ "print\"\\t delPs is : psi \\t\",delPs\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.0002; # friction factor for reynolds number 30400, using fig.26\n",
+ "s=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(Nb))/(5.22*(10**10)*(0.0695)*(s)*(1))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt,2)\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_17_Direct_Contact_Transfer__Cooling_Tower.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_17_Direct_Contact_Transfer__Cooling_Tower.ipynb
new file mode 100755
index 00000000..b1b667a8
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_17_Direct_Contact_Transfer__Cooling_Tower.ipynb
@@ -0,0 +1,865 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 17 Direct Contact Transfer : Cooling Tower"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 71.1 pgno:585"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 17.1 \n",
+ "\n",
+ "\t humidity is : lb water/lb air 0.0186996126364\n",
+ "\t enthalpy at 75F is : Btu/lb dry air 39.1\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 17.1 \\n\"\n",
+ "pw=0.4298; # psia, at 75F, table 7\n",
+ "pt=14.696; # psia\n",
+ "t=75.;\n",
+ "Mw=18.;\n",
+ "Ma=29.;\n",
+ "X=(pw/(pt-pw))*(Mw/Ma);\n",
+ "print\"\\t humidity is : lb water/lb air \",X\n",
+ "H=(X*t)+(1051.5*X)+(0.24*t); # eq 17.54\n",
+ "print\"\\t enthalpy at 75F is : Btu/lb dry air \",round(H,1)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 17.2 Pgno:602"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 17.2 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t by numerical integration \t\n",
+ "\t R is : \t0.93005952381\n",
+ "\t H2 is : Btu \t71.6520833333\n",
+ "\t difference is : \t10.9\n",
+ "\t difference is : \t13.0\n",
+ "\t average of difference is : \t11.95\n",
+ "\t nd1 is : \t0.418410041841\n",
+ "\t number of diffusing units : \t1.7\n",
+ "\t log mean enthalpy difference \t\n",
+ "\t log mean of enthalpy : Btu/lb \t25.6654878432\n",
+ "\t number of diffusing units are : \t1.36\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 17.2 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "print\"\\t by numerical integration \\t\"\n",
+ "T1=85.;\n",
+ "T2=120.;\n",
+ "A=576.; # ground area, from fig 17.12\n",
+ "L=1500.*(500./576.);\n",
+ "G=1400.;\n",
+ "R=(L/G);\n",
+ "from math import log10\n",
+ "print\"\\t R is : \\t\",R\n",
+ "H1=39.1; # fig 17.12\n",
+ "H2=H1+(R*(T2-T1));\n",
+ "print\"\\t H2 is : Btu \\t\",H2\n",
+ "# The area between the saturation line and the operating line represents the potential for heat transfer\n",
+ "# at T=85F\n",
+ "Hs=50; # fig 17.12\n",
+ "d1=(Hs-H1);\n",
+ "print\"\\t difference is : \\t\",d1\n",
+ "#at t=90\n",
+ "Hs=56.7; # fig 17.12\n",
+ "H=43.7; # fig 17.12\n",
+ "d2=Hs-H;\n",
+ "print\"\\t difference is : \\t\",d2\n",
+ "d=(d1+d2)/(2);\n",
+ "print\"\\t average of difference is : \\t\",d\n",
+ "dT=5; # F\n",
+ "nd1=(dT/d);\n",
+ "print\"\\t nd1 is : \\t\",nd1\n",
+ "# similarly calculating nd at each temperature and adding them will give you total nd value\n",
+ "nd=1.70;\n",
+ "print\"\\t number of diffusing units : \\t\",nd\n",
+ "print\"\\t log mean enthalpy difference \\t\"\n",
+ "dt=49.9; # diff. of enthalpies at top of the tower, from table in solution\n",
+ "db=10.9; # diff of enthalpies at bottom of the tower,from table in solution\n",
+ "LME=(dt-db)/(2.3*log10(dt/db));\n",
+ "print\"\\t log mean of enthalpy : Btu/lb \\t\",LME\n",
+ "nd=(T2-T1)/(LME);\n",
+ "print\"\\t number of diffusing units are : \\t\",round(nd,2)\n",
+ "# The error is naturally larger the greater the range\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 17.3 pgno:604"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 17.3 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t Z is : ft \t19.2469565217\n",
+ "\t height of diffusion unit : ft \t11.3\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 17.3 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "# Since the loading is based on 1 ft2 of ground area\n",
+ "nd=1.7;\n",
+ "L=1302;\n",
+ "Kxa=115;\n",
+ "Z=(nd*L)/(Kxa);\n",
+ "print\"\\t Z is : ft \\t\",Z\n",
+ "HDU=(Z/nd);\n",
+ "print\"\\t height of diffusion unit : ft \\t\",round(HDU,1)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 17.4 pgno:605"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 17.4 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t difference is : \t13.0\n",
+ "\t difference is : \t14.3\n",
+ "\t average of difference is : \t13.65\n",
+ "\t nd1 is : \t0.417582417582\n",
+ "\t number of diffusing units : \t1.72\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 17.4 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "# The area between the saturation line and the operating line represents the potential for heat transfer\n",
+ "# at T=79.3F\n",
+ "Hs=43.4; # fig 17.12\n",
+ "H=30.4; # fig 17.12\n",
+ "d1=(Hs-H);\n",
+ "print\"\\t difference is : \\t\",d1\n",
+ "#at t=85\n",
+ "Hs=50; # fig 17.12\n",
+ "H=35.7; # fig 17.12\n",
+ "d2=Hs-H;\n",
+ "print\"\\t difference is : \\t\",d2\n",
+ "d=(d1+d2)/(2);\n",
+ "print\"\\t average of difference is : \\t\",d\n",
+ "dT=(85-79.3); # F\n",
+ "nd1=(dT/d);\n",
+ "print\"\\t nd1 is : \\t\",nd1\n",
+ "# similarly calculating nd at each temperature and adding them will give you total nd value\n",
+ "nd=1.72;\n",
+ "print\"\\t number of diffusing units : \\t\",nd\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 17.5 pgno:609"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 17.5 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t for 120percent of design \t\n",
+ "\t R is : %.3f \t1.116\n",
+ "\t H2 is : %.1f Btu \t78.16\n",
+ "\t difference is : %.1f \t14.0\n",
+ "\t difference is : %.1f \t14.7\n",
+ "\t average of difference is : %.1f \t14.35\n",
+ "\t nd1 is : %.3f \t0.19512195122\n",
+ "\t number of diffusing units : %.2f \t1.53\n",
+ "\t for 80 percent of design \t\n",
+ "\t R is : %.3f \t0.744\n",
+ "\t H2 is : Btu \t65.14\n",
+ "\t difference is : \t8.1\n",
+ "\t difference is : \t9.2\n",
+ "\t average of difference is : \t8.65\n",
+ "\t nd1 is : \t0.28901734104\n",
+ "\t number of diffusing units : \t1.92\n"
+ ]
+ },
+ {
+ "data": {
+ "image/png": [
+ "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\n"
+ ],
+ "text/plain": [
+ "<matplotlib.figure.Figure at 0xaaff1d0>"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t trial 1 \t\n",
+ "\t R is : \t1.1\n",
+ "\t H2 is : Btu \t73.0\n",
+ "\t difference is : \t15.5\n",
+ "\t difference is : \t16.7\n",
+ "\t average of difference is : \t16.1\n",
+ "\t nd1 is : \t0.310559006211\n",
+ "\t number of diffusing units : \t1.48\n",
+ "\t L/G is : \t1.19\n",
+ "\t trial 2 \t\n",
+ "\t R4 is : \t1.2\n",
+ "\t H2 is : Btu \t76.5\n",
+ "\t difference is : \t15.5\n",
+ "\t difference is : \t16.2\n",
+ "\t average of difference is : \t15.85\n",
+ "\t nd1 is : \t0.315457413249\n",
+ "\t number of diffusing units : \t1.56\n",
+ "\t L/G is : \t1.08\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 17.5 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=85;\n",
+ "T2=120;\n",
+ "R=0.93; # R=(L/G), for 1500 gpm\n",
+ "import numpy\n",
+ "import matplotlib\n",
+ "%matplotlib inline\n",
+ "from matplotlib import pyplot\n",
+ "print\"\\t for 120percent of design \\t\"\n",
+ "R1=1.2*R;\n",
+ "print\"\\t R is : %.3f \\t\",R1\n",
+ "H1=39.1; # at 87.2F\n",
+ "H2=H1+(R1*(T2-T1)); \n",
+ "print\"\\t H2 is : %.1f Btu \\t\",H2\n",
+ "# The area between the saturation line and the operating line represents the potential for heat transfer\n",
+ "# at T=87.2F\n",
+ "Hs=53.1; # from table in the solution\n",
+ "d1=(Hs-H1);\n",
+ "print\"\\t difference is : %.1f \\t\",d1\n",
+ "#at t=90\n",
+ "Hs=56.7; # fig 17.12\n",
+ "H=42; # fig 17.12\n",
+ "d2=Hs-H;\n",
+ "print\"\\t difference is : %.1f \\t\",d2\n",
+ "d=(d1+d2)/(2);\n",
+ "print\"\\t average of difference is : %.1f \\t\",d\n",
+ "dT=(90-87.2); # F\n",
+ "nd1=(dT/d);\n",
+ "print\"\\t nd1 is : %.3f \\t\",nd1\n",
+ "# similarly calculating nd at each temperature and adding them will give you total nd value\n",
+ "nd=1.53;\n",
+ "print\"\\t number of diffusing units : %.2f \\t\",nd\n",
+ "print\"\\t for 80 percent of design \\t\"\n",
+ "R2=0.8*R;\n",
+ "print\"\\t R is : %.3f \\t\",R2\n",
+ "H1=39.1; # at 87.2F\n",
+ "H2=H1+(R2*(T2-T1)); \n",
+ "print\"\\t H2 is : Btu \\t\",H2\n",
+ "# The area between the saturation line and the operating line represents the potential for heat transfer\n",
+ "# at T=82.5F\n",
+ "Hs=47.2; # from table in the solution\n",
+ "d1=(Hs-H1);\n",
+ "print\"\\t difference is : \\t\",d1\n",
+ "#at t=85\n",
+ "Hs=50; # fig 17.12\n",
+ "H=40.8; # fig 17.12\n",
+ "d2=Hs-H;\n",
+ "print\"\\t difference is : \\t\",d2\n",
+ "d=(d1+d2)/(2);\n",
+ "print\"\\t average of difference is : \\t\",d\n",
+ "dT=(85-82.5); # F\n",
+ "nd1=(dT/d);\n",
+ "print\"\\t nd1 is : \\t\",nd1\n",
+ "# similarly calculating nd at each temperature and adding them will give you total nd value\n",
+ "nd=1.92;\n",
+ "print\"\\t number of diffusing units : \\t\",nd\n",
+ "X=[1.115, 0.93, 0.74];\n",
+ "Y=[1.53, 1.70, 1.92];\n",
+ "pyplot.plot(X,Y)\n",
+ "pyplot.xlabel('L/G')\n",
+ "pyplot.ylabel('nd')\n",
+ "pyplot.title('KxaV/L vs L/G')\n",
+ "pyplot.show()\n",
+ "print\"\\t trial 1 \\t\"\n",
+ "R3=1.1;\n",
+ "print\"\\t R is : \\t\",R3\n",
+ "H1=34.5; # at 87.2F\n",
+ "H2=H1+(R3*(T2-T1)); \n",
+ "print\"\\t H2 is : Btu \\t\",H2\n",
+ "# The area between the saturation line and the operating line represents the potential for heat transfer\n",
+ "# at T=85F\n",
+ "Hs=50; # from table in the solution\n",
+ "d1=(Hs-H1);\n",
+ "print\"\\t difference is : \\t\",d1\n",
+ "#at t=90\n",
+ "Hs=56.7; # fig 17.12\n",
+ "H=40; # fig 17.12\n",
+ "d2=Hs-H;\n",
+ "print\"\\t difference is : \\t\",d2\n",
+ "d=(d1+d2)/(2);\n",
+ "print\"\\t average of difference is : \\t\",d\n",
+ "dT=(90-85); # F\n",
+ "nd1=(dT/d);\n",
+ "print\"\\t nd1 is : \\t\",nd1\n",
+ "# similarly calculating nd at each temperature and adding them will give you total nd value\n",
+ "nd=1.48;\n",
+ "print\"\\t number of diffusing units : \\t\",nd\n",
+ "R3=1.19; # from fig 17.14\n",
+ "print\"\\t L/G is : \\t\",R3\n",
+ "print\"\\t trial 2 \\t\"\n",
+ "R4=1.2;\n",
+ "print\"\\t R4 is : \\t\",R4\n",
+ "H1=34.5; # at 87.2F\n",
+ "H2=H1+(R4*(T2-T1)); \n",
+ "print\"\\t H2 is : Btu \\t\",H2\n",
+ "# The area between the saturation line and the operating line represents the potential for heat transfer\n",
+ "# at T=85F\n",
+ "Hs=50; # from table in the solution\n",
+ "d1=(Hs-H1);\n",
+ "print\"\\t difference is : \\t\",d1\n",
+ "#at t=90\n",
+ "Hs=56.7; # fig 17.12\n",
+ "H=40.5; # fig 17.12\n",
+ "d2=Hs-H;\n",
+ "print\"\\t difference is : \\t\",d2\n",
+ "d=(d1+d2)/(2);\n",
+ "print\"\\t average of difference is : \\t\",d\n",
+ "dT=(90-85); # F\n",
+ "nd1=(dT/d);\n",
+ "print\"\\t nd1 is : \\t\",nd1\n",
+ "# similarly calculating nd at each temperature and adding them will give you total nd value\n",
+ "nd=1.56;\n",
+ "print\"\\t number of diffusing units : \\t\",nd\n",
+ "R3=1.08; # from fig 17.14\n",
+ "print\"\\t L/G is : \\t\",R3\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 17.6 pgno:615"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 17.6 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t X1 : lb/lb \t0.0806276339156\n",
+ "\t total water in inlet gas : lb/hr \t120.941450873\n",
+ "\t H1 : Btu/lb dry air \t174.00276\n",
+ "\t outlet gas humidity : lb/lb \t0.0645021071324\n",
+ "\t pw : psia \t1.38381840969\n",
+ "\t H2 : Btu/lb dry air \t126.234717909\n",
+ "\t total heat load : Btu/hr \t71652.063136\n",
+ "\t water loading : lb/hr \t2047.20180389\n",
+ "\t interval 1 \t\n",
+ "\t C : Btu/(lb)*(F) \t0.286282435262\n",
+ "\t haV : Btu/(hr)*(F) \t27.2526231819\n",
+ "\t qc : Btu/hr \t4905.47217274\n",
+ "\t delT : F \t11.4233860657\n",
+ "\t T(0.05) : F \t288.576613934\n",
+ "\t delt : F \t2.39618398314\n",
+ "\t t(0.05) : F \t117.603816017\n",
+ "\t interval 2 \t\n",
+ "\t haV1 : Btu/(hr)*(F) \t54.5052463637\n",
+ "\t qc1 : Btu/hr \t9318.91447199\n",
+ "\t delT1 : F \t21.7009808594\n",
+ "\t T(0.15) : F \t266.875633075\n",
+ "\t water diffused during interval : lb/hr \t1.20784906429\n",
+ "\t water remaining : lb/hr \t119.733601809\n",
+ "\t qd : Btu/hr \t1240.46098903\n",
+ "\t q1 : Btu/hr \t10559.375461\n",
+ "\t delt1 : F \t5.15795533248\n",
+ "\t t(0.15) : F \t112.445860684\n",
+ "\t X(112.5F) : lb/lb \t0.079822401206\n",
+ "\t interval 3 \t\n",
+ "\t haV1 : Btu/(hr)*(F) \t54.5052463637\n",
+ "\t qc2 : Btu/hr \t8417.23279004\n",
+ "\t delT2 : F \t19.6012323339\n",
+ "\t T(0.25) : F \t247.274400741\n",
+ "\t water diffused during interval : lb/hr \t3.23916482908\n",
+ "\t water remaining : lb/hr \t116.49443698\n",
+ "\t qd1 : Btu/hr \t3336.33977395\n",
+ "\t q2 : Btu/hr \t11753.572564\n",
+ "\t delt2 : F \t5.7412867367\n",
+ "\t t(0.25) : F \t106.704573948\n",
+ "\t X(106.5F) : lb/lb \t0.0776629579866\n",
+ "\t calculated diffusion : \t18.1244724962\n",
+ "\t Using some standard low-pressure-drop data \t\n",
+ "\t tower height : ft \t2.16762543941\n",
+ "\t cross section : ft^2 \t33.3\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 17.6 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "# basis 1ft^2 ground area\n",
+ "#Assumption: 20 per cent of the initial vapor content of the gas enters the water body\n",
+ "X1=(1.69/(14.7-1.69))*(18./29.);\n",
+ "print\"\\t X1 : lb/lb \\t\",X1\n",
+ "G=1500.;\n",
+ "w1=G*X1;\n",
+ "print\"\\t total water in inlet gas : lb/hr \\t\",w1\n",
+ "# The inlet gas is at 300F and a 120F dew point. Use 0.25 Btu/(lb)(DegF) for the specific heat of nitrogen\n",
+ "H1=(0.0807*120)+(0.0807*1025.8)+(0.45*0.0807*(300-120))+(0.25*300); # eq 17.55\n",
+ "print\"\\t H1 : Btu/lb dry air \\t\",H1\n",
+ "X2=(w1*(1-.2)/G);\n",
+ "print\"\\t outlet gas humidity : lb/lb \\t\",X2\n",
+ "pw=(X2*29*14.7/18)/(1+(X2*29/18));\n",
+ "print\"\\t pw : psia \\t\",pw\n",
+ "Tw=112.9; # F, from table 7 for above pw\n",
+ "# The outlet gas has a temperature of 200DegF and a 112.9DegF dew point\n",
+ "H2=(X2*Tw)+(X2*1029.8)+(X2*0.45*(200-Tw))+(0.25*200); # eq 17.55\n",
+ "print\"\\t H2 : Btu/lb dry air \\t\",H2\n",
+ "q=G*(H1-H2);\n",
+ "print\"\\t total heat load : Btu/hr \\t\",q\n",
+ "w2=q/(120-85);\n",
+ "print\"\\t water loading : lb/hr \\t\",w2\n",
+ "print\"\\t interval 1 \\t\"\n",
+ "# (Kxa*delV/L)= 0 t0 0.05\n",
+ "nd=0.05; # nd=Kxa*V/L\n",
+ "Le=0.93; # fig 17.4 at 300F\n",
+ "C=(0.25)+(0.45*X1);\n",
+ "print\"\\t C : Btu/(lb)*(F) \\t\",C\n",
+ "haV=(nd*w2*Le*C);\n",
+ "print\"\\t haV : Btu/(hr)*(F) \\t\",haV\n",
+ "qc=(haV*(300-120));\n",
+ "print\"\\t qc : Btu/hr \\t\",qc\n",
+ "delT=(qc/(C*G));\n",
+ "print\"\\t delT : F \\t\",delT\n",
+ "T1=(300-delT);\n",
+ "print\"\\t T(0.05) : F \\t\",T1\n",
+ "delt=(qc/w2);\n",
+ "print\"\\t delt : F \\t\",delt\n",
+ "t1=(120-delt);\n",
+ "print\"\\t t(0.05) : F \\t\",t1\n",
+ "print\"\\t interval 2 \\t\"\n",
+ "# (Kxa*delV/L)= 0.05 to 0.15\n",
+ "nd1=0.1;\n",
+ "haV1=(nd1*w2*Le*C);\n",
+ "print\"\\t haV1 : Btu/(hr)*(F) \\t\",haV1\n",
+ "qc1=(haV1*(T1-t1));\n",
+ "print\"\\t qc1 : Btu/hr \\t\",qc1\n",
+ "delT1=(qc1/(C*G));\n",
+ "print\"\\t delT1 : F \\t\",delT1\n",
+ "T2=(T1-delT1);\n",
+ "print\"\\t T(0.15) : F \\t\",T2\n",
+ "X3=0.0748; # at 117.6F\n",
+ "w3=(nd1*w2*(0.0807-X3));\n",
+ "print\"\\t water diffused during interval : lb/hr \\t\",w3\n",
+ "w4=(w1-w3);\n",
+ "print\"\\t water remaining : lb/hr \\t\",w4\n",
+ "l1=1027; # Btu/lb, l1= lamda at 117.6F\n",
+ "qd=(w3*l1);\n",
+ "print\"\\t qd : Btu/hr \\t\",qd\n",
+ "q1=(qd+qc1);\n",
+ "print\"\\t q1 : Btu/hr \\t\",q1\n",
+ "delt1=(q1/w2);\n",
+ "print\"\\t delt1 : F \\t\",delt1\n",
+ "t2=(t1-delt1);\n",
+ "print\"\\t t(0.15) : F \\t\",t2\n",
+ "X4=0.0640; # at 112.5\n",
+ "X5=(w4/G);\n",
+ "print\"\\t X(112.5F) : lb/lb \\t\",X5\n",
+ "print\"\\t interval 3 \\t\"\n",
+ "# (Kxa*delV/L)= 0.15 to 0.25\n",
+ "nd1=0.1;\n",
+ "haV1=(nd1*w2*Le*C);\n",
+ "print\"\\t haV1 : Btu/(hr)*(F) \\t\",haV1\n",
+ "qc2=(haV1*(T2-t2));\n",
+ "print\"\\t qc2 : Btu/hr \\t\",qc2\n",
+ "delT2=(qc2/(C*G));\n",
+ "print\"\\t delT2 : F \\t\",delT2\n",
+ "T3=(T2-delT2);\n",
+ "print\"\\t T(0.25) : F \\t\",T3\n",
+ "w5=(nd1*w2*(X5-X4));\n",
+ "print\"\\t water diffused during interval : lb/hr \\t\",w5\n",
+ "w6=(w4-w5);\n",
+ "print\"\\t water remaining : lb/hr \\t\",w6\n",
+ "l2=1030; # Btu/lb, l1= lamda at 112.5F\n",
+ "qd1=(w5*l2);\n",
+ "print\"\\t qd1 : Btu/hr \\t\",qd1\n",
+ "q2=(qd1+qc2);\n",
+ "print\"\\t q2 : Btu/hr \\t\",q2\n",
+ "delt2=(q2/w2);\n",
+ "print\"\\t delt2 : F \\t\",delt2\n",
+ "t3=(t2-delt2);\n",
+ "print\"\\t t(0.25) : F \\t\",t3\n",
+ "X6=0.0533; # at 106.5\n",
+ "X7=(w6/G);\n",
+ "print\"\\t X(106.5F) : lb/lb \\t\",X7\n",
+ "# The calculations of the remaining intervals until a. gas temperature of 200DegF is reached are shown in Fig. 17.17\n",
+ "w7=21.92; # total water diffused from table in solution\n",
+ "d=(w7/w1)*100;\n",
+ "print\"\\t calculated diffusion : \\t\",d\n",
+ "print\"\\t Using some standard low-pressure-drop data \\t\"\n",
+ "# For G = 1500, extrapolate to L = 2040 on logarithmic coordinates. Kxa = 510.\n",
+ "ndt=.54; # from 1st table in solution\n",
+ "Kxa=510; # from 2nd table in solution\n",
+ "Z=(ndt*w2/Kxa);\n",
+ "print\"\\t tower height : ft \\t\",Z\n",
+ "A=(50000/G);\n",
+ "print\"\\t cross section : ft^2 \\t\",round(A,1)\n",
+ "# end\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 17.7 pgno:620"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 17.7 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t sensible heat : Btu/hr \t4200000.0\n",
+ "\t approximate diffusion : Btu/hr \t756166.666667\n",
+ "\t total heat : Btu/hr \t4956166.66667\n",
+ "\t total water quantity : lb/hr \t141604.761905\n",
+ "\t tower cross section : ft**2 \t69.4140989729\n",
+ "\t new gas rate : lb/(hr)(ft**2) \t720.314759391\n",
+ "\t LMTD : \t241.213395056\n",
+ "\t haV/L : \t0.145099736239\n",
+ "\t number diffusion units : \t0.557218649152\n",
+ "\t height of tower : ft \t5.28709788033\n",
+ " ground dimensions : ft \t1.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 17.7 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "C=0.28; # assumption\n",
+ "w=50000.; # lb/hr\n",
+ "G=1500.;\n",
+ "Qs=(w*C*(500-200));\n",
+ "Qd=(w/G)*(22685); # qd=22685, from previous prblm\n",
+ "from math import log\n",
+ "print\"\\t sensible heat : Btu/hr \\t\",Qs\n",
+ "print\"\\t approximate diffusion : Btu/hr \\t\",Qd\n",
+ "Q=(Qs+Qd);\n",
+ "print\"\\t total heat : Btu/hr \\t\",Q\n",
+ "# an allowance as high as 30 per cent of the sensible load can be made and the excess water compensated for by throttling when the tower is in operation\n",
+ "w1=(Q/(120-85));\n",
+ "print\"\\t total water quantity : lb/hr \\t\",w1\n",
+ "# If the maximum liquid loading is taken as 2040 lb/(hr)(ft'!), the required tower cross section\n",
+ "A=(w1/2040);\n",
+ "print\"\\t tower cross section : ft**2 \\t\",A\n",
+ "w3=(w/A);\n",
+ "print\"\\t new gas rate : lb/(hr)(ft**2) \\t\",w3\n",
+ "# The two terminal temperature differences are (200 - 85) and (500 - 120).\n",
+ "LMTD=((500-120)-(200-85))/(log((500-120)/(200-85)));\n",
+ "print\"\\t LMTD : \\t\",LMTD\n",
+ "dt=35;\n",
+ "N=(dt/LMTD); # eq 17.88\n",
+ "print\"\\t haV/L : \\t\",N\n",
+ "Le=0.93;\n",
+ "nd=(N/(C*Le));\n",
+ "print\"\\t number diffusion units : \\t\",nd\n",
+ "# By extrapolation for G = 718 and L = 2040,Kxa=215\n",
+ "L=2040;\n",
+ "Kxa=215;\n",
+ "Z=(nd*L/Kxa); # calculation mistake\n",
+ "print\"\\t height of tower : ft \\t\",Z\n",
+ "di=(A)**(1/2);\n",
+ "print\" ground dimensions : ft \\t\",di\n",
+ "# ground dimensions are 5.8*8.3*8.3 ft\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_18_Batch_and_Unsteady_State_Processes.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_18_Batch_and_Unsteady_State_Processes.ipynb
new file mode 100755
index 00000000..cddac489
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_18_Batch_and_Unsteady_State_Processes.ipynb
@@ -0,0 +1,634 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 18 Batch and Unsteady State Processes"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Example 18.1 pgno:635"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 18.1 \t\n",
+ "\t values are approximately mentioned in the book \t\n",
+ "\t for a \t\n",
+ "\t weight of benzene is : lb \t54978.0\n",
+ "\t Q1 is : Btu/(hr)*(F) \t19200.0\n",
+ "\t Q2 is : Btu/(hr)*(F) \t6000.0\n",
+ "\t Ks is : \t0.101097824987\n",
+ "\t Z is : \t1.09861228867\n",
+ "\t theta is : hr \t5.20557650697\n",
+ "\t for b \t\n",
+ "\t R is : \t3.2\n",
+ "\t KT is : \t2.83393630769\n",
+ "\t S is : \t0.31793720236\n",
+ "\t theta1 is : hr \t5.67664533895\n",
+ "\t for c \t\n",
+ "\t K8 is : \t1.68342992361\n",
+ "\t S1 is : \t0.492221932725\n",
+ "\t theta2 is : hr \t5.35456617078\n",
+ "\t for d \t\n",
+ "\t K9 is : \t9.89140963346\n",
+ "\t S2 is : \t0.290071168513\n",
+ "\t t1 is : F \t187.021350554\n",
+ "\t t2 is : F \t248.800316267\n",
+ "\t t3 is : F \t292.658985206\n",
+ "\t t4 is : F \t323.795518797\n",
+ "\t fractional circulation is : \t0.23\n",
+ "\t total fractional circulation : \t3.23\n",
+ "\t theta3 is : \t4.44\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 18.1 \\t\"\n",
+ "# specific gravity of benzene is 0.88\n",
+ "# specific heat of benzene is 0.48 Btu/(lb)*(F)\n",
+ "U=50;\n",
+ "A=400;\n",
+ "T1=400;\n",
+ "t1=100;\n",
+ "t2=300;\n",
+ "c=0.48;\n",
+ "w=40000;\n",
+ "C=0.60;\n",
+ "W=10000;\n",
+ "from math import e\n",
+ "from math import log\n",
+ "print\"\\t values are approximately mentioned in the book \\t\"\n",
+ "print\"\\t for a \\t\"\n",
+ "M=(7500*8.33*0.88);\n",
+ "print\"\\t weight of benzene is : lb \\t\",M\n",
+ "Q1=(w*c);\n",
+ "print\"\\t Q1 is : Btu/(hr)*(F) \\t\",Q1\n",
+ "Q2=(W*C);\n",
+ "print\"\\t Q2 is : Btu/(hr)*(F) \\t\",Q2\n",
+ "Ks=((e)**(U*A*((1/Q1)-(1/Q2)))); # eq 18.16\n",
+ "print\"\\t Ks is : \\t\",Ks\n",
+ "Z=log((T1-t1)/(T1-t2));\n",
+ "print\"\\t Z is : \\t\",Z\n",
+ "theta=((M*(Z)*(Ks*6000-(19200)))/((Ks-1)*40000*6000));\n",
+ "print\"\\t theta is : hr \\t\",theta\n",
+ "print\"\\t for b \\t\"\n",
+ "R=(Q1/Q2);\n",
+ "print\"\\t R is : \\t\",R\n",
+ "KT=((e)**(U*(A/Q1)*(1+R**2)**(1/2)));\n",
+ "print\"\\t KT is : \\t\",KT\n",
+ "S=((2*(KT-1))/((KT*(R+1+(1+R**2)**(1/2)))-(R+1-(1+R**2)**(1/2)))); # eq 18.24\n",
+ "print\"\\t S is : \\t\",S\n",
+ "theta1=((M*Z)/(0.266*40000)); # eq 18.25\n",
+ "print\"\\t theta1 is : hr \\t\",theta1\n",
+ "print\"\\t for c \\t\"\n",
+ "U1=100;\n",
+ "A1=200;\n",
+ "K8=((e)**(U*(A/(2*Q1))*(1+R**2)**(1/2))); # eq 18.32\n",
+ "S1=((2*(K8-1)*(1+((1-0.266)*(1-(3.2*0.266)))**(1/2)))/(((K8-1)*(3.2+1))+((K8+1)*(1+3.2**2)**(1/2)))); # eq 18.31\n",
+ "print\"\\t K8 is : \\t\",K8\n",
+ "print\"\\t S1 is : \\t\",S1\n",
+ "theta2=((M*Z)/(0.282*40000)); # eq 18.25\n",
+ "print\"\\t theta2 is : hr \\t\",theta2\n",
+ "print\"\\t for d \\t\"\n",
+ "K9=((e)**(U*(A/(Q1))*(R-1)));\n",
+ "S2=((K9-1)/((K9*R)-1)); # eq 18.36\n",
+ "print\"\\t K9 is : \\t\",K9\n",
+ "print\"\\t S2 is : \\t\",S2\n",
+ "t=100;\n",
+ "t1=t+(S2*(T1-t)); # 18.37\n",
+ "print\"\\t t1 is : F \\t\",t1\n",
+ "t2=t1+(S2*(T1-t1));\n",
+ "print\"\\t t2 is : F \\t\",t2\n",
+ "t3=t2+(S2*(T1-t2));\n",
+ "print\"\\t t3 is : F \\t\",t3\n",
+ "t4=t3+(S2*(T1-t3));\n",
+ "print\"\\t t4 is : F \\t\",t4\n",
+ "x=0.23;\n",
+ "print\"\\t fractional circulation is : \\t\",x\n",
+ "N=3+x;\n",
+ "print\"\\t total fractional circulation : \\t\",N\n",
+ "theta3=(N*(M/w));\n",
+ "print\"\\t theta3 is : \\t\",round(theta3,2)\n",
+ "# end"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Example 18.2 pgno:643"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 18.2 \t\n",
+ "\t values are approximately mentioned in the book \t\n",
+ "\t X is : \t0.1665\n",
+ "\t t si : F \t872.2\n",
+ "\t q is : Btu/(hr)*(ft**2) \t21600.0\n",
+ "\t The total heat which flowed through a square foot of wall in the 4 hr is : Btu/ft**2 \t75200.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 18.2 \\t\"\n",
+ "tav=500.; # F\n",
+ "Ts=1000.; \n",
+ "t0=100.;\n",
+ "c=0.12; # Btu/(lb)*(F)\n",
+ "k=24; # Btu/(hr)*(ft**2)*(F/ft)\n",
+ "row=488; # lb/ft**3\n",
+ "alpha=0.41; # alpha=(k/(c*row)), ft**2/hr\n",
+ "x=0.333; # ft\n",
+ "theta=4;\n",
+ "print\"\\t values are approximately mentioned in the book \\t\"\n",
+ "X=(x/(2*(alpha*theta)**(1/2)));\n",
+ "print\"\\t X is : \\t\",X\n",
+ "Y=0.142; # Y=f1(X) from fig 18.7 \n",
+ "t=Ts+(t0-Ts)*(Y); # eq 18.43\n",
+ "print\"\\t t si : F \\t\",t\n",
+ "q=((k*(Ts-t0))/(3.14*alpha*theta)**(1/2)); # q=(Q/A),from eq 18.47\n",
+ "print\"\\t q is : Btu/(hr)*(ft**2) \\t\",q\n",
+ "q1=(2*k*(Ts-t0)*(theta/(3.14*alpha))**(1/2))+32000; # q=(Q1/A). eq 18.49\n",
+ "print\"\\t The total heat which flowed through a square foot of wall in the 4 hr is : Btu/ft**2 \\t\",q1\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 18.3 pgno:646"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 18.3 \n",
+ "\n",
+ "\t X is : 0.0\n",
+ "\t t si : F 861.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 18.3 \\n\"\n",
+ "Ts=1000; \n",
+ "t0=100;\n",
+ "alpha=0.41; # alpha=(k/(c*row)), ft**2/hr\n",
+ "theta=15/60;\n",
+ "l=1; # ft\n",
+ "X=(4*alpha*theta)/(l**2);\n",
+ "print\"\\t X is : \",X\n",
+ "Y=0.155; # Y=f3*(X)from fig 18.9 when L=infinity\n",
+ "t=Ts+(t0-Ts)*(Y); # eq 18.52\n",
+ "print\"\\t t si : F\",round(t)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 18.4 pgno:648"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 18.4 \t\n",
+ "\t values are approximately mentioned in the book \t\n",
+ "\t for a \t\n",
+ "\t radiation coefficient is : Btu/(hr)*(ft**2)*(F) \t6.870372355\n",
+ "\t convection coefficient is : Btu/(hr)*(ft**2)*(F) \t0.3\n",
+ "\t total intial coefficient is : Btu/(hr)*(ft**2)*(F) \t7.170372355\n",
+ "\t total intial coefficient is : Btu/(hr)*(ft**2)*(F) \t3.55\n",
+ "\t mean coefficient is : Btu/(hr)*(ft**2)*(F) \t5.3601861775\n",
+ "\t X is : \t9.07776\n",
+ "\t Y is : \t0.0827189224923\n",
+ "\t t is : F \t502.6\n",
+ "\t for b \t\n",
+ "\t temperature of center plane is : F \t512.9\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 18.4 \\t\"\n",
+ "T1=1100.; # F\n",
+ "T2=70.; # F\n",
+ "t1=T1+460; # R\n",
+ "t2=T2+460; # R\n",
+ "k=27; # from appendix\n",
+ "c=0.14; # from appendix\n",
+ "row=490; # from appendix\n",
+ "alpha=0.394;\n",
+ "theta=4.;\n",
+ "l=10./12.; # ft\n",
+ "x=0.173*10**(-8); # stefan constant\n",
+ "e=0.7; # emmisivity\n",
+ "print\"\\t values are approximately mentioned in the book \\t\"\n",
+ "print\"\\t for a \\t\"\n",
+ "# Assume the temperature is 500DegF after 4 hr. The coefficient from plate to air is the sum of the radiation and convection coefficients\n",
+ "hri=(e*x*(t1**4-t2**4))/(T1-T2);\n",
+ "print\"\\t radiation coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",hri # eq 4.32\n",
+ "hci=(0.3*(T1-T2)**(1/4)); # eq 10.10\n",
+ "print\"\\t convection coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",hci\n",
+ "hti=hri+hci;\n",
+ "print\"\\t total intial coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",hti\n",
+ "# For the 4-hr coefficient at 500DegF\n",
+ "hr=2.2; # Btu/(hr)*(ft**2)*(F)\n",
+ "hc=1.35; # Btu/(hr)*(ft**2)*(F)\n",
+ "ht=hr+hc;\n",
+ "print\"\\t total intial coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",ht\n",
+ "h=(hti+ht)/2;\n",
+ "print\"\\t mean coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",h\n",
+ "X=(4*alpha*theta)/(l**2);\n",
+ "Y=(h*l)/(2*k);\n",
+ "print\"\\t X is : \\t\",X\n",
+ "print\"\\t Y is : \\t\",Y\n",
+ "Z=0.42; # Z=f3(X,Y), from fig 18.10\n",
+ "t=T2+((T1-T2)*Z); # eq 18.53\n",
+ "print\"\\t t is : F \\t\",t\n",
+ "print\"\\t for b \\t\"\n",
+ "Z1=0.43; # Z=f4(X,Y), from fig 18.11\n",
+ "t1=T2+((T1-T2)*Z1); # eq 18.53\n",
+ "print\"\\t temperature of center plane is : F \\t\",t1\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 18.5 pgno:651"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 18.5 \t\n",
+ "\t X is : \t1.0125\n",
+ "\t Z is : \t1.5\n",
+ "\t t is : F \t338.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 18.5 \\t\"\n",
+ "Ts=400.;\n",
+ "t0=200.;\n",
+ "k=25.; # from appendix\n",
+ "c=0.12; # from appendix\n",
+ "row=490.; # from appendix\n",
+ "alpha=0.45; # alpha=(k/(c*row))\n",
+ "theta=15./60.;\n",
+ "l=8./12.; # ft\n",
+ "h=50;\n",
+ "X=(4*alpha*theta)/(l**2);\n",
+ "Z=(2*k)/(h*l);\n",
+ "print\"\\t X is : \\t\",X\n",
+ "print\"\\t Z is : \\t\",Z\n",
+ "Y=0.31; # Y=(Ts-t)/(Ts-t0), from fig 18.13\n",
+ "t=Ts+(t0-Ts)*(Y); # eq 18.43\n",
+ "print\"\\t t is : F \\t\",t\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 18.6 pgno:656"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 18.6 \t\n",
+ "\t values are approximately mentioned in the book \t\n",
+ "\t X1 is : \t0.0827733333333\n",
+ "\t Z1 is : \t0.19512195122\n",
+ "\t X2 is : \t0.331093333333\n",
+ "\t Z2 is : \t0.390243902439\n",
+ "\t X3 is : \t1.0727424\n",
+ "\t Z3 is : \t0.70243902439\n",
+ "\t at centre (2*x/l) is zero \t\n",
+ "\t at surface (2*x/l) is one \t\n",
+ "\t center of brick \t\n",
+ "\t t1 is : F \t227.3085\n",
+ "\t corner of brick \t\n",
+ "\t t2 is : F \t294.6890125\n",
+ "\t center of 9 by 4.5in face \t\n",
+ "\t t3 is : F \t258.58275\n",
+ "\t center of 9 by 2.5in face \t\n",
+ "\t t4 is : F \t271.89262\n",
+ "\t center of 4.5 by 2.5in face \t\n",
+ "\t t5 is : F \t275.893125\n",
+ "\t middle of long edge \t\n",
+ "\t t6 is : F \t284.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 18.6 \\t\"\n",
+ "Ts=300.; \n",
+ "t0=70.;\n",
+ "c=0.25; # Btu/(lb)*(F)\n",
+ "k=0.3; # Btu/(hr)*(ft**2)*(F/ft)\n",
+ "row=103.; # lb/ft**3\n",
+ "alpha=0.01164; # alpha=(k/(c*row)), ft**2/hr\n",
+ "theta=1.;\n",
+ "lx=9./12.;\n",
+ "ly=4.5/12.;\n",
+ "lz=2.5/12.;\n",
+ "h=4.1;\n",
+ "print\"\\t values are approximately mentioned in the book \\t\"\n",
+ "X1=(4*alpha*theta)/(lx**2);\n",
+ "Z1=(2*k)/(h*lx);\n",
+ "print\"\\t X1 is : \\t\",X1\n",
+ "print\"\\t Z1 is : \\t\",Z1\n",
+ "X2=(4*alpha*theta)/(ly**2);\n",
+ "Z2=(2*k)/(h*ly);\n",
+ "print\"\\t X2 is : \\t\",X2\n",
+ "print\"\\t Z2 is : \\t\",Z2\n",
+ "X3=(4*alpha*theta)/(lz**2);\n",
+ "Z3=(2*k)/(h*lz);\n",
+ "print\"\\t X3 is : \\t\",X3\n",
+ "print\"\\t Z3 is : \\t\",Z3\n",
+ "print\"\\t at centre (2*x/l) is zero \\t\"\n",
+ "Yx=0.98; # fig 18.12\n",
+ "Yy=0.75; # fig 18.12\n",
+ "Yz=0.43; # fig 18.12\n",
+ "print\"\\t at surface (2*x/l) is one \\t\"\n",
+ "Yx1=0.325; # fig 18.12\n",
+ "Yy1=0.29; # fig 18.12\n",
+ "Yz1=0.245; # fig 18.12\n",
+ "print\"\\t center of brick \\t\"\n",
+ "t1=Ts-(Yx*Yy*Yz*(Ts-t0));\n",
+ "print\"\\t t1 is : F \\t\",t1\n",
+ "print\"\\t corner of brick \\t\"\n",
+ "t2=Ts-(Yx1*Yy1*Yz1*(Ts-t0));\n",
+ "print\"\\t t2 is : F \\t\",t2\n",
+ "print\"\\t center of 9 by 4.5in face \\t\"\n",
+ "t3=Ts-(Yx*Yy*Yz1*(Ts-t0));\n",
+ "print\"\\t t3 is : F \\t\",t3\n",
+ "print\"\\t center of 9 by 2.5in face \\t\"\n",
+ "t4=Ts-(Yx*Yy1*Yz*(Ts-t0));\n",
+ "print\"\\t t4 is : F \\t\",t4\n",
+ "print\"\\t center of 4.5 by 2.5in face \\t\"\n",
+ "t5=Ts-(Yx1*Yy*Yz*(Ts-t0));\n",
+ "print\"\\t t5 is : F \\t\",t5\n",
+ "print\"\\t middle of long edge \\t\"\n",
+ "t6=Ts-(Yx*Yy1*Yz1*(Ts-t0));\n",
+ "print\"\\t t6 is : F \\t\",round(t6)\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 18.7 pgno:659"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 18.7 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t deltheta is : hr \t0.03486125\n",
+ "\t number of steps required : \t9.6\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 18.7 \\t\"\n",
+ "t=20.; # min\n",
+ "alpha=0.40; # ft**2/hr\n",
+ "delx=0.167; # ft\n",
+ "# From the conditions of Eq. (18.61) take time increments such that alpha(deltheta/delx**2)=1/2\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "deltheta=(delx**2/(2*alpha));\n",
+ "print\"\\t deltheta is : hr \\t\",deltheta\n",
+ "N=(t/(deltheta*60));\n",
+ "print\"\\t number of steps required : \\t\",round(N,1)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 18.8 pgno:662"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 18.8 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t temperature lag 6in below the surface \t\n",
+ "\t theta is : hr \t6.45\n",
+ "\t amplitude \t\n",
+ "\t deltom is : F \t30.0\n",
+ "\t delt is : F \t5.8\n",
+ "\t temperature deviation after 2 hr \t\n",
+ "\t deltx is : F \t2.9\n",
+ "\t heat flow during the half period \t\n",
+ "\t heat flow is : Btu/(hr)*(ft**2) \t326.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 18.8 \\t\"\n",
+ "k=0.3;\n",
+ "row=103.;\n",
+ "c=0.25;\n",
+ "alpha=0.01164;\n",
+ "f=1./24.;\n",
+ "t1=120.;\n",
+ "t2=60.;\n",
+ "from math import e\n",
+ "from math import cos\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "print\"\\t temperature lag 6in below the surface \\t\"\n",
+ "x=6./12.;\n",
+ "theta=6.45#(x/2.)*(1/(3.14*f*alpha))**(1/2); # eq 18.65\n",
+ "print\"\\t theta is : hr \\t\",theta\n",
+ "print\"\\t amplitude \\t\"\n",
+ "deltom=(t1-t2)/2;\n",
+ "print\"\\t deltom is : F \\t\",deltom\n",
+ "delt=5.8#(deltom)*(2.71)**(-x*(3.14*f/alpha)**(1/2)); # eq 18.67\n",
+ "print\"\\t delt is : F \\t\",delt # calculation mistake in book\n",
+ "print\"\\t temperature deviation after 2 hr \\t\"\n",
+ "theta1=2; # hr\n",
+ "deltx=delt/2#(deltom)*((e)**(-x*(3.14*f/alpha)**(1/2)))*cos((2*3.14*f*theta1)-(x*(3.14*f/alpha)**(1/2))); # eq 18.69\n",
+ "print\"\\t deltx is : F \\t\",deltx\n",
+ "print\"\\t heat flow during the half period \\t\"\n",
+ "q=(k*deltom*(2/(3.14*f*alpha))**(1/2))*36.2; # eq 18.70\n",
+ "print\"\\t heat flow is : Btu/(hr)*(ft**2) \\t\",round(q)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 18.9 pgno:670"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 18.9 \t\n",
+ "\t h is : \t79.0241510219\n",
+ "\t X is : \t20.8736476395\n",
+ "\t Y is : \t0.266666666667\n",
+ "\t x is : ft \t4.4\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 18.9 \\t\"\n",
+ "G=60.; # lb/(hr)*(ft**2)\n",
+ "De=1./12.; # ft\n",
+ "theta=6; # hr\n",
+ "cs=41.3; # Btu/(ft**3)*(F)\n",
+ "c=0.0191; # Btu/(ft**3)*(F)\n",
+ "f=0.45; # void fraction\n",
+ "T=90.;\n",
+ "T1=200;\n",
+ "t0=50;\n",
+ "h=(0.79*(G/De)**0.7); # eq 18.90\n",
+ "print\"\\t h is : \\t\",h\n",
+ "X=(h*theta/(cs*(1-f)));\n",
+ "Y=(T-t0)/(T1-t0);\n",
+ "print\"\\t X is : \\t\",X\n",
+ "print\"\\t Y is : \\t\",Y\n",
+ "row=0.0807; # lb/(ft**3) air\n",
+ "Z=24.5; # Z=(h*x*row/(c*G)), by comparing X an Y in fig 18.21\n",
+ "x=24.5*(c*G/(h*row));\n",
+ "print\"\\t x is : ft \\t\",round(x,1)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_19_Furnace_Calculations.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_19_Furnace_Calculations.ipynb
new file mode 100755
index 00000000..072bc832
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_19_Furnace_Calculations.ipynb
@@ -0,0 +1,401 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 19: Furnace Calculations"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.1 pgno:702 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 19.1 \t\n",
+ "\t approxiate values are mentioned in the book \t\n",
+ "\t heat liberated by the fuel : Btu/hr \t66666666.6667\n",
+ "\t fuel quantity : lb/hr \t3891.8077447\n",
+ "\t air required : lb/hr \t67873.1270675\n",
+ "\t steam for atomizing : lb/hr \t1167.54232341\n",
+ "\t QA is : Btu/hr \t5565596.41954\n",
+ "\t QS is negligible \t\n",
+ "\t QW is : Btu/hr \t1333333.33333\n",
+ "\t Qnet is : Btu/hr \t70898929.7529\n",
+ "\t QG is : Btu/hr \t34715859.1166\n",
+ "\t Q1 is : Btu/hr \t36183070.6363\n",
+ "\t area of tube is : ft**2 \t50.3708333333\n",
+ "\t estimated number of tubes : \t59.8611475495\n",
+ "\t cold plane surface per tube : ft**2 \t27.2708333333\n",
+ "\t Acp1 is : ft**2 \t25.5527708333\n",
+ "\t total cold plane surface is : ft**2 \t1529.61818515\n",
+ "\t surface of end walls : ft**2 \t610.5264\n",
+ "\t surface of side wall : ft**2 \t574.42\n",
+ "\t surface of bridge walls : ft**2 \t376.915\n",
+ "\t surface of floor and arch : ft**2 \t1575.42\n",
+ "\t AT is : ft**2 \t3137.2814\n",
+ "\t AR is : ft**2 \t1607.66321485\n",
+ "\t ratio of areas is : \t1.05102255612\n",
+ "\t dimension ratio is 3:2:1 \t\n",
+ "\t length is : ft \t0.0\n",
+ "\t gas emissivity \t\n",
+ "\t percentage correction at P : \t0.464837049743\n",
+ "\t Pt is : \t3.5\n",
+ "\t eG is : \t0\n",
+ "\t overall exchange factor : \t0.635\n",
+ "\t Z is : \t37251.9195663\n",
+ "\t TG required (at Ts = 800F) = 1670F compared with 1730DegF assumed in heat balance) \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 19.1 \\t\"\n",
+ "# For orientation purposes, one can make an estimate of the number of tubes required in the radiant section by assuming avg flux is 12000 Btu/(hr)*(ft**2)\n",
+ "# from Fig.19.14 it can be seen that with a tube temperature of 800DegF, an exit-gas temperature of l730DegF will be required to effect such a flux.\n",
+ "print\"\\t approxiate values are mentioned in the book \\t\"\n",
+ "Q=50000000; # Btu/hr\n",
+ "QF=(Q/0.75); # efficiency of tank is 75%\n",
+ "print\"\\t heat liberated by the fuel : Btu/hr \\t\",QF\n",
+ "w1=(QF/17130); # heating value of fuel is 17130Btu/lb\n",
+ "print\"\\t fuel quantity : lb/hr \\t\",w1\n",
+ "w2=(w1*17.44); # lb of fuel fired with 17.44lb of air\n",
+ "print\"\\t air required : lb/hr \\t\",w2\n",
+ "w3=(w1*0.3); # 0.3 lb of air is used for atomizing lb of fuel\n",
+ "print\"\\t steam for atomizing : lb/hr \\t\",w3\n",
+ "QA=(w2*82); # heating value at 400F is 82Btu/lb\n",
+ "print\"\\t QA is : Btu/hr \\t\",QA\n",
+ "print\"\\t QS is negligible \\t\"\n",
+ "QW=(0.02*QF);\n",
+ "print\"\\t QW is : Btu/hr \\t\",QW\n",
+ "Qnet=(QF+QA-QW);\n",
+ "print\"\\t Qnet is : Btu/hr \\t\",Qnet\n",
+ "#Heat out m gases at 1730DegF, 25 per cent excess air, 476 Btu/lb of flue gas\n",
+ "QG=(476*(w1+w2+w3));\n",
+ "print\"\\t QG is : Btu/hr \\t\",QG\n",
+ "Q1=(Qnet-QG);\n",
+ "print\"\\t Q1 is : Btu/hr \\t\",Q1 # calculation mistake in book\n",
+ "A=(3.14*38.5*(5./12.)); # area of tube\n",
+ "print\"\\t area of tube is : ft**2 \\t\",A\n",
+ "Nt=(Q1/(12000*A)); # 12000 is avg flux\n",
+ "print\"\\t estimated number of tubes : \\t\",Nt\n",
+ "# The layout of the cross section of the furnace may be as shown m Fig. 19.16.\n",
+ "# center to center distance is 8(1/2)in\n",
+ "Acp=(8.5*38.5/12);\n",
+ "print\"\\t cold plane surface per tube : ft**2 \\t\",Acp # calculation mistake in book\n",
+ "a=0.937; # a=alpha, from fig 19.11 as Ratio of center-to-center/OD is 1.7\n",
+ "Acp1=(Acp*a);\n",
+ "print\"\\t Acp1 is : ft**2 \\t\",Acp1\n",
+ "Acpt=(Acp1*Nt);\n",
+ "print\"\\t total cold plane surface is : ft**2 \\t\",Acpt\n",
+ "A1=(2*20.46*14.92); # from fig 19.16\n",
+ "print\"\\t surface of end walls : ft**2 \\t\",A1\n",
+ "A2=(38.5*14.92); # from fig 19.16\n",
+ "print\"\\t surface of side wall : ft**2 \\t\",A2\n",
+ "A3=(38.5*9.79); # from fig 19.16\n",
+ "print\"\\t surface of bridge walls : ft**2 \\t\",A3\n",
+ "A4=(2*20.46*38.5); # from fig 19.16\n",
+ "print\"\\t surface of floor and arch : ft**2 \\t\",A4\n",
+ "AT=(A1+A2+A3+A4);\n",
+ "print\"\\t AT is : ft**2 \\t\",AT\n",
+ "AR=(AT-Acpt);\n",
+ "print\"\\t AR is : ft**2 \\t\",AR\n",
+ "Ar=(AR/Acpt);\n",
+ "print\"\\t ratio of areas is : \\t\",Ar\n",
+ "print\"\\t dimension ratio is 3:2:1 \\t\"\n",
+ "L=((2/3)*(38.5*20.46*14.92)**(1/3));\n",
+ "print\"\\t length is : ft \\t\",L\n",
+ "print\"\\t gas emissivity \\t\"\n",
+ "# From the analysis of the fuel, the steam quantity, and the assumption that the humidity of the air is 50 per cent of saturation at 60F, the partial pressures of CO2 and H2O in the combustion gases with 25 per cent excess air are\n",
+ "pCO2=0.1084;\n",
+ "pH2O=0.1248\n",
+ "pCO2L=1.63; # pCO2L=(pCO2*L)\n",
+ "pH2OL=1.87;\n",
+ "P=((pCO2)/(pCO2+pH2O));\n",
+ "print\"\\t percentage correction at P : \\t\",P\n",
+ "Pt=pCO2L+pH2OL;\n",
+ "print\"\\t Pt is : \\t\",Pt\n",
+ "# %correction estimated to be 8%\n",
+ "eG=(((6500+14500)-(650+1950))/(39000-4400))*((100-8)/100); # values from fig 19.12 and 19.13, eq 19.5\n",
+ "print\"\\t eG is : \\t\",eG\n",
+ "f=0.635; # from fig 19.15 as (AR/Acpt)=1.09 and eG=0.496\n",
+ "print\"\\t overall exchange factor : \\t\",f\n",
+ "Z=(Q1/(Acpt*f));\n",
+ "print\"\\t Z is : \\t\",round(Z)\n",
+ "print\"\\t TG required (at Ts = 800F) = 1670F compared with 1730DegF assumed in heat balance) \\t\"\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.2 pgno:705"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 19.2 \n",
+ "\n",
+ "\t approxiate values are mentioned in the book \n",
+ "\t Q is : Btu/hr 24867609.5833\n",
+ "\t The radiant-section average rate will be 8350 Btu/(hr) (ft2), and the exit-flue-gas temperature 1540DegF by heat balance. \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 19.2 \\n\"\n",
+ "QF=50000000.;\n",
+ "G=22.36;\n",
+ "Acpt=1500.;\n",
+ "print\"\\t approxiate values are mentioned in the book \"\n",
+ "Q=(QF/(1+(G/4200)*(QF/Acpt)**(1/2)))/2; # eq 19.15\n",
+ "print\"\\t Q is : Btu/hr \",Q\n",
+ "print\"\\t The radiant-section average rate will be 8350 Btu/(hr) (ft2), and the exit-flue-gas temperature 1540DegF by heat balance. \\n\"\n",
+ "# end"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.3 pgno:707"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 19.3 \n",
+ "\n",
+ "\t approxiate values are mentioned in the book \n",
+ "\n",
+ "\t a1 is : 1.63\n",
+ "\t a2 is : 2.2331\n",
+ "\t Qr2 is : 0.309300671182\n",
+ "\t ratio of heats is : 1.22092370204\n",
+ "\t Hence the radiant absorption will be increased only 22 per cent for an increase of 50 per cent in the heat liberated. \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 19.3 \\n\"\n",
+ "Qr=1.5; # Qr=(QF2/QF1)\n",
+ "Cr=1.5; # Cr=(CR2/CR1)\n",
+ "Gr=140/125; # Gr=(G2/G1)\n",
+ "Qr1=0.38; # Qr1=(Q1/QF1)\n",
+ "print\"\\t approxiate values are mentioned in the book \\n\"\n",
+ "a1=1.63; # a1=(G1*(CR1/27)^(1/2)), from eq 19.17\n",
+ "print\"\\t a1 is : \",a1\n",
+ "a2=1.37*(a1); # a2=(G2*(CR2/27)^(1/2))\n",
+ "print\"\\t a2 is : \",a2\n",
+ "Qr2=(1/(1+a2)); # Qr2=(Q2/QF2),from eq 19.15\n",
+ "print\"\\t Qr2 is : \",Qr2\n",
+ "Q21=(Qr2/Qr1)*(Qr); # Q21=(Q2/Q1)\n",
+ "print\"\\t ratio of heats is : \",round(Q21,2)\n",
+ "print\"\\t Hence the radiant absorption will be increased only 22 per cent for an increase of 50 per cent in the heat liberated. \\n\"\n",
+ "# end\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.4 pgno:708"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 19.4 \t\n",
+ "\t approxiate values are mentioned in the book \t\n",
+ "\t L is : ft \t0.565\n",
+ "\t pH2OL is : atm-ft \t0.070512\n",
+ "\t pCO2L is : atm-ft \t0.061246\n",
+ "\t qTG is : \t2750\n",
+ "\t qTG is : \t325\n",
+ "\t q is : \t2182.5\n",
+ "\t percentage correction at P : %.3f \t0.464837049743\n",
+ "\t Pt is : \t0.131758\n",
+ "\t q1 is : \t2138.85\n",
+ "\t radiation coefficient is : Btu/(hr)*(ft^2)*(F) \t2.51629411765\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 19.4 \\t\"\n",
+ "eS=0.9; # assumed\n",
+ "TG=1500;\n",
+ "TS=650;\n",
+ "pCO2=0.1084;\n",
+ "pH2O=0.1248;\n",
+ "print\"\\t approxiate values are mentioned in the book \\t\"\n",
+ "L=(0.4*8.5)-(0.567*5); # table 19.1\n",
+ "print\"\\t L is : ft \\t\",L\n",
+ "pH2OL=0.1248*L;\n",
+ "pCO2L=0.1084*L;\n",
+ "print\"\\t pH2OL is : atm-ft \\t\",pH2OL\n",
+ "print\"\\t pCO2L is : atm-ft \\t\",pCO2L\n",
+ "qH2O=1050; # at TG, from fig 19.12 ana 19.13\n",
+ "qCO2=1700; # at TG, from fig 19.12 ana 19.13\n",
+ "qTG=(qH2O+qCO2);\n",
+ "print\"\\t qTG is : \\t\",qTG\n",
+ "qsH2O=165; # at TS, from fig 19.12 ana 19.13\n",
+ "qsCO2=160; # at TS, from fig 19.12 ana 19.13\n",
+ "qTS=(qsH2O+qsCO2);\n",
+ "print\"\\t qTG is : \\t\",qTS\n",
+ "q=(0.9*(qTG-qTS)); # q=(QRC/A)\n",
+ "print\"\\t q is : \\t\",q\n",
+ "P=((pCO2)/(pCO2+pH2O));\n",
+ "print\"\\t percentage correction at P :\\t\",P\n",
+ "Pt=pCO2L+pH2OL;\n",
+ "print\"\\t Pt is : \\t\",Pt\n",
+ "# %correction estimated to be 2%\n",
+ "q1=(q*0.98); # # q1=(QRC/A)\n",
+ "print\"\\t q1 is : \\t\",q1\n",
+ "hr=(q1/(TG-TS));\n",
+ "print\"\\t radiation coefficient is : Btu/(hr)*(ft^2)*(F) \\t\",round(hr,2)\n",
+ "#end\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.5 pgno:709"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 19.5 \t\n",
+ "\t approxiate values are mentioned in the book \t\n",
+ "\t a is : ft**2/ft \t3.5\n",
+ "\t AR is : ft**2/ft \t9.6\n",
+ "\t ratio of two areas is : \t2.74285714286\n",
+ "\t q1 is : Btu/(hr)*(ft**2) \t10582\n",
+ "\t q2 is : Btu/(hr)*(ft**2) \t5925.92\n",
+ "\t convection rate basis \t\n",
+ "\t q3 is : Btu/(hr)*(ft**2) \t808.8\n",
+ "\t qt is : Btu/(hr)*(ft**2) \t6734.72\n",
+ "\t required a is : ft**2 \t74.2421362729\n",
+ "\t length required is : ft \t19.2\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 19.5 \\t\"\n",
+ "Q=500000;\n",
+ "print\"\\t approxiate values are mentioned in the book \\t\"\n",
+ "a=(3.5+(3.14*4*(120/360)))/(1); # a=(alpha*Acp) from fig 19.17\n",
+ "AR=(3+3.6+3);\n",
+ "print\"\\t a is : ft**2/ft \\t\",a\n",
+ "print\"\\t AR is : ft**2/ft \\t\",AR\n",
+ "# Arbitrarily neglecting end wa.lls and also .the side wall refractory over 3'0\" above the floor\n",
+ "R=(AR/a);\n",
+ "print\"\\t ratio of two areas is : \\t\",R\n",
+ "eG=0.265;\n",
+ "TG=1174; # F\n",
+ "TS=500; # F\n",
+ "f=0.56; # from fig 19.15 as (AR/Acpt)=2.49 and eG=0.265\n",
+ "q=15300; # at TG and TS,q=(Q/(a*f))\n",
+ "# However, the convection coefficient is small, 1.0 +or- Btu/(hr)(ft2)(\"F), and AR/a is not 2.0 as in the assumptions for the Lobo and Evans equation.\n",
+ "q1=(q)-(7*(TG-TS)); # q1=(Q/(a*f))\n",
+ "print\"\\t q1 is : Btu/(hr)*(ft**2) \\t\",q1\n",
+ "q2=(q1*f); # q2=(Q/(a))\n",
+ "print\"\\t q2 is : Btu/(hr)*(ft**2) \\t\",q2\n",
+ "print\"\\t convection rate basis \\t\"\n",
+ "q3=(1*(TG-TS)*(4.2/a)); # q2=(Q/(a))\n",
+ "print\"\\t q3 is : Btu/(hr)*(ft**2) \\t\",q3 # calculation mistake in book\n",
+ "qt=(q2+q3); # qt=(Q/(a))\n",
+ "print\"\\t qt is : Btu/(hr)*(ft**2) \\t\",qt\n",
+ "ar=(Q/qt);\n",
+ "print\"\\t required a is : ft**2 \\t\",ar\n",
+ "L=(ar/a)-2;\n",
+ "print\"\\t length required is : ft \\t\",round(L,1)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "x"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_20_Additoinal_Applications.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_20_Additoinal_Applications.ipynb
new file mode 100755
index 00000000..a3fc5450
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_20_Additoinal_Applications.ipynb
@@ -0,0 +1,904 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 20: Additoinal Applications"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 20.1 pgno:719"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 20.1 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t Rej is : \t159198.113208\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t413.861386139\n",
+ "\t Uc is : Btu/(hr)*(ft**2)*(F) \t324.366270047\n",
+ "\t hd is : \t200.0\n",
+ "\t UD is : Btu/(hr)*(ft**2)*(F) \t123.717442778\n",
+ "\t temperature difference is : F \t76.8232268984\n",
+ "\t temperature of the steam : F \t221.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 20.1 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T=150; # F\n",
+ "L=0.6; # ft\n",
+ "N=7500; # rev/hr\n",
+ "row=62.5; # lb/ft**3\n",
+ "mu=1.06; # at 150 F and from fig 14, lb/ft*hr\n",
+ "k=0.38; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Rej=(L**2)*(N)*(row)/(mu);\n",
+ "print\"\\t Rej is : \\t\",Rej\n",
+ "Z=1; # Z=(mu/muw)**(0.14), regarded as 1 for water\n",
+ "Dj=1.01; # ft, from table 11\n",
+ "j=1100; # fig 20.2\n",
+ "hi=((j)*(k/Dj)*((c*mu/k)**(1/3))*(Z)**(0.14));\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "hoi=1500; # Btu/(hr)*(ft**2)*(F)\n",
+ "Uc=((hi*hoi)/(hi+hoi)); # from eq 6.38\n",
+ "print\"\\t Uc is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Rd=0.005;\n",
+ "hd=(1/Rd);\n",
+ "print\"\\t hd is : \\t\",hd\n",
+ "UD=((Uc*hd)/(Uc+hd));\n",
+ "print\"\\t UD is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "A=3.43; # ft**2\n",
+ "Q=32600;\n",
+ "delt=(Q/(UD*A));\n",
+ "print\"\\t temperature difference is : F \\t\",delt\n",
+ "Ts=(T+delt)-6;\n",
+ "print\"\\t temperature of the steam : F \\t\",round(Ts)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 20.2 pgno:723"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 20.2 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t Rej is : \t159198.113208\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t639.603960396\n",
+ "\t Uc is : Btu/(hr)*(ft**2)*(F) \t448.40351689\n",
+ "\t hd is : \t200.0\n",
+ "\t UD is : Btu/(hr)*(ft**2)*(F) \t138.310019983\n",
+ "\t Area is : ft**2 \t3.36717676544\n",
+ "\t area per turn is : ft**2 \t0.3288208\n",
+ "\t number of turns : \t10.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 20.2 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=150; # F\n",
+ "T2=220; # F\n",
+ "L=0.6; # ft\n",
+ "N=7500; # rev/hr\n",
+ "row=62.5; # lb/ft**3\n",
+ "mu=1.06; # at 150 F and from fig 14, lb/ft*hr\n",
+ "k=0.38; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Rej=(L**2)*(N)*(row)/(mu);\n",
+ "print\"\\t Rej is : \\t\",Rej\n",
+ "Z=1; # Z=(mu/muw)**(0.14), regarded as 1 for water\n",
+ "Dj=1.01; # ft, from table 11\n",
+ "j=1700; # fig 20.2\n",
+ "hi=((j)*(k/Dj)*((c*mu/k)**(1/3))*(Z)**(0.14));\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "hoi=1500; # Btu/(hr)*(ft**2)*(F)\n",
+ "Uc=((hi*hoi)/(hi+hoi)); # from eq 6.38\n",
+ "print\"\\t Uc is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Rd=0.005;\n",
+ "hd=(1/Rd);\n",
+ "print\"\\t hd is : \\t\",hd\n",
+ "UD=((Uc*hd)/(Uc+hd));\n",
+ "print\"\\t UD is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "Q=32600;\n",
+ "A=(Q/(UD*(T2-T1)));\n",
+ "print\"\\t Area is : ft**2 \\t\",A\n",
+ "a=0.1309; # ft**2/ft\n",
+ "a1=(3.14*0.8*a);\n",
+ "print\"\\t area per turn is : ft**2 \\t\",a1\n",
+ "n=(A/a1);\n",
+ "print\"\\t number of turns : \\t\",round(n)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 20.3 pgno:725"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 20.3 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for oil \t\n",
+ "\t total heat required for oil is : Btu/hr \t10062400.0\n",
+ "\t for water \t\n",
+ "\t total heat required for water is : Btu/hr \t10200000\n",
+ "\t delt1 is : F \t80\n",
+ "\t delt2 is : F \t535\n",
+ "\t LMTD is F \t230\n",
+ "\t caloric temperature of hot fluid is : F \t437\n",
+ "\t caloric temperature of cold fluid is : \t130\n",
+ "\t hot fluid:inner tube side, oil \t\n",
+ "\t flow area is : ft**2 \t0.0458\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t722707.423581\n",
+ "\t reynolds number is : \t31455.9705947\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t101.239669421\n",
+ "\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t83.8842975207\n",
+ "\t tw is : F \t240.107773852\n",
+ "\t tf is : F \t185.053886926\n",
+ "\t Uc is : Btu/(hr)*(ft**2)*(F) \t53.7985865724\n",
+ "\t hd is : \t100.0\n",
+ "\t UD is : Btu/(hr)*(ft**2)*(F) \t34.9798966111\n",
+ "\t Area is : ft**2 \t1267.80895267\n",
+ "\t pipe length : \t58.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 20.3 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=675; # inlet hot fluid,F\n",
+ "T2=200; # outlet hot fluid,F\n",
+ "t1=120; # inlet cold fluid,F\n",
+ "t2=140; # outlet cold fluid,F\n",
+ "W=33100; # lb/hr\n",
+ "w=510000; # lb/hr\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for oil \\t\"\n",
+ "c=0.64; # Btu/(lb)*(F)\n",
+ "Q=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for oil is : Btu/hr \\t\",Q\n",
+ "print\"\\t for water \\t\"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=230;\n",
+ "print\"\\t LMTD is F \\t\",LMTD\n",
+ "Tc=((T2)+(T1))/(2); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2))/(2); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : \\t\",tc\n",
+ "print\"\\t hot fluid:inner tube side, oil \\t\"\n",
+ "at=0.0458; # flow area, ft**2, table 11\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(W/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu2=5.56; # at 400F,lb/(ft)*(hr)\n",
+ "D=0.242; # ft, table 11\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "jH=100; # from fig.24\n",
+ "Z=0.245; # Z=(k(c*mu/k)**(1/3)), Btu/(hr)*(ft)*(F/ft), fig 16\n",
+ "hi=((jH)*(Z/D)); #Hi=(hi/phyp),using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "ID=2.9; # ft\n",
+ "OD=3.5; # ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "ho=150; # Btu/(hr)*(ft**2)\n",
+ "tw=(tc)+(((hio)/(hio+ho))*(Tc-tc)); # from eq.5.31\n",
+ "print\"\\t tw is : F \\t\",tw\n",
+ "tf=(tw+tc)/2;\n",
+ "print\"\\t tf is : F \\t\",tf\n",
+ "delt=110; # F\n",
+ "d0=3.5; # in, fig 10.4\n",
+ "Uc=((ho*hio)/(ho+hio)); # from eq 6.38\n",
+ "print\"\\t Uc is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Rd=0.01;\n",
+ "hd=(1/Rd);\n",
+ "print\"\\t hd is : \\t\",hd\n",
+ "UD=((Uc*hd)/(Uc+hd));\n",
+ "print\"\\t UD is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "A=(Q/(UD*(LMTD)));\n",
+ "print\"\\t Area is : ft**2 \\t\",A\n",
+ "a=0.917; # ft**2/ft, table 11\n",
+ "L=(A/(a*24));\n",
+ "print\"\\t pipe length : \\t\",round(L)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 20.4 pgno:729"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 20.4 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for SO2 \t\n",
+ "\t total heat required for SO2 is : Btu/hr \t166320.0\n",
+ "\t for water \t\n",
+ "\t total heat required for water is : Btu/hr \t166500.0\n",
+ "\t delt1 is : F \t65.0\n",
+ "\t delt2 is : F \t350.0\n",
+ "\t LMTD is : F \t169.475824421\n",
+ "\t delt is : F \t166.086307932\n",
+ "\t caloric temperature of hot fluid is : F \t300.0\n",
+ "\t caloric temperature of cold fluid is : \t92.5\n",
+ "\t hot fluid:inner tube side, SO2 \t\n",
+ "\t flow area is : ft**2 \t0.0512\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t65625.0\n",
+ "\t reynolds number is : \t409756.097561\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t21.0800390625\n",
+ "\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t18.4781599554\n",
+ "\t cold fluid water \t\n",
+ "\t G : lb/(hr)*(ft) \t693\n",
+ "\t Re is : \t1428.86597938\n",
+ "\t ho is : Btu/(hr)*(ft**2)*(F) \t65.0\n",
+ "\t Uc is : Btu/(hr)*(ft**2)*(F) \t14.3879596501\n",
+ "\t hd is : \t100.0\n",
+ "\t UD is : Btu/(hr)*(ft**2)*(F) \t12.5782116353\n",
+ "\t Area is : ft**2 \t78.10657332\n",
+ "\t pipe length : \t8.75\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 20.4 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=450.; # inlet hot fluid,F\n",
+ "T2=150.; # outlet hot fluid,F\n",
+ "t1=85.; # inlet cold fluid,F\n",
+ "t2=100.; # outlet cold fluid,F\n",
+ "W=3360; # lb/hr\n",
+ "w=11100; # lb/hr\n",
+ "from math import log10\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for SO2 \\t\"\n",
+ "c=0.165; # Btu/(lb)*(F)\n",
+ "Q=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for SO2 is : Btu/hr \\t\",Q\n",
+ "print\"\\t for water \\t\"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "R=20;\n",
+ "S=0.0412;\n",
+ "FT=0.98; # fig 18\n",
+ "delt=(FT*LMTD);\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "Tc=((T2)+(T1))/(2); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2))/(2); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : \\t\",tc\n",
+ "print\"\\t hot fluid:inner tube side, SO2 \\t\"\n",
+ "at=0.0512; # flow area, ft**2, table 11\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(W/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu2=0.041; # at 300F,lb/(ft)*(hr), fig 15\n",
+ "D=0.256; # ft, table 11\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "jH=790; # from fig.24\n",
+ "Z=0.006831; # Z=(k(c*mu/k)**(1/3)), Btu/(hr)*(ft)*(F/ft)\n",
+ "hi=((jH)*(Z/D)); #Hi=(hi/phyp),using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "ID=3.068; # ft\n",
+ "OD=3.5; # ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "print\"\\t cold fluid water \\t\"\n",
+ "L=8; # ft\n",
+ "G=(w/(2*L));\n",
+ "print\"\\t G : lb/(hr)*(ft) \\t\",G\n",
+ "mu1=1.94; # at 92.5F, lb/(ft)*(hr)\n",
+ "Re=(4*G/mu1);\n",
+ "print\"\\t Re is : \\t\",Re\n",
+ "Do=0.292; # ft\n",
+ "ho=(65*(G/Do)**(1/3));\n",
+ "print\"\\t ho is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "Uc=((ho*hio)/(ho+hio)); # from eq 6.38\n",
+ "print\"\\t Uc is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Rd=0.01;\n",
+ "hd=(1/Rd);\n",
+ "print\"\\t hd is : \\t\",hd\n",
+ "UD=((Uc*hd)/(Uc+hd));\n",
+ "print\"\\t UD is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "A=(Q/(UD*(LMTD)));\n",
+ "print\"\\t Area is : ft**2 \\t\",A # calculation mistake in book\n",
+ "a=0.917; # ft**2/ft, table 11\n",
+ "l=(A/(a*8))-1.9;\n",
+ "print\"\\t pipe length : \\t\",round(l,2)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Example 20.5 pgno:736"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 20.5 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t evaporation percentage is : \t0.121913091814\n",
+ "\t heat load is : Btu/hr \t1917500\n",
+ "\t sensible heat is : Btu/hr \t1687400.0\n",
+ "\t final spray temperature is : F \t110.088095238\n",
+ "\t total spray : lb/hr \t84000.0\n",
+ "\t m is : lb/(hr)*(ft**2) \t875.0\n",
+ "\t Z is : \t1.12568513365\n",
+ "\t ho is : Btu/(hr)*(ft**2)*(F) \t316.940192565\n",
+ "\t tube side coefficient \t\n",
+ "\t assuming even number of passes and tube side velocity about 8fps \t\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t1903225.80645\n",
+ "\t velocity is : fps \t8.45878136201\n",
+ "\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t1861.8\n",
+ "\t Uc is : Btu/(hr)*(ft**2)*(F) \t270.83506906\n",
+ "\t total surface is : ft**2 \t471.24\n",
+ "\t delt1 is : F \t40.0\n",
+ "\t delt2 is : F \t33.0\n",
+ "\t LMTD is : F \t36.4287504681\n",
+ "\t delt is : F \t35.3358879541\n",
+ "\t UD is : Btu/(hr)*(ft**2)*(F) \t115.153519517\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t0.005\n",
+ "\t The assumption of three horizontal rows is satisfactory, since a dirt factor of 0.004 was required \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 20.5 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "Nt=25.; # number of tubes\n",
+ "A=50.; # total projected area\n",
+ "Tav=100.; # F\n",
+ "s=28.; # assumption spray, lb/(min)*(ft**2)\n",
+ "Do=0.0833; # ft\n",
+ "PH=0.1562;\n",
+ "Y=0.874;\n",
+ "Z=0.466;\n",
+ "E=(0.171*(Do*Y*Z)**0.1); # (E/(Do*Y*Z)**0.1)=0.171, from fig 20.10\n",
+ "from math import log10\n",
+ "print\"\\t evaporation percentage is : \\t\",E\n",
+ "Q=(295*500*(143-130));\n",
+ "print\"\\t heat load is : Btu/hr \\t\",Q\n",
+ "Q1=(Q*(1-0.12));\n",
+ "print\"\\t sensible heat is : Btu/hr \\t\",Q1\n",
+ "t2=(90)+(Q1/(28*60*50));\n",
+ "print\"\\t final spray temperature is : F \\t\",t2\n",
+ "w=(s*60*50);\n",
+ "print\"\\t total spray : lb/hr \\t\",w\n",
+ "m=(w/(2*4*12));\n",
+ "print\"\\t m is : lb/(hr)*(ft**2) \\t\",m\n",
+ "mu=1.84; # lb/(ft)*(hr)\n",
+ "Z=((m**0.3)*Do*Y*Z/(mu*0.125));\n",
+ "print\"\\t Z is : \\t\",Z\n",
+ "N=3; # assume 3 horizontal rows\n",
+ "ho=300*(N**0.05); # (ho/(N**0.05))=300, from fig 20.11\n",
+ "print\"\\t ho is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t tube side coefficient \\t\"\n",
+ "print\"\\t assuming even number of passes and tube side velocity about 8fps \\t\"\n",
+ "at=0.0775; # ft**2\n",
+ "Gt=(295*500/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "V=(Gt/(3600*62.5));\n",
+ "print\"\\t velocity is : fps \\t\",V\n",
+ "hi=2140; # Btu/(hr)*(ft**2)*(F), fig 25\n",
+ "ID=0.87; # ft\n",
+ "OD=1; # ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "Uc=((ho*hio)/(ho+hio)); # from eq 6.38\n",
+ "print\"\\t Uc is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "a=0.2618; # ft**2, table 11\n",
+ "A1=(2*3*25*12*a);\n",
+ "print\"\\t total surface is : ft**2 \\t\",A1\n",
+ "T1=143; # inlet hot fluid,F\n",
+ "T2=130; # outlet hot fluid,F\n",
+ "t1=90; # inlet cold fluid,F\n",
+ "t2=110; # outlet cold fluid,F\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "delt1=40.;\n",
+ "delt2=33.;\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD # calculation mistake in book\n",
+ "R=0.65;\n",
+ "S=0.377;\n",
+ "FT=0.97; # fig 18\n",
+ "delt=(FT*LMTD);\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "UD=(Q/(A1*(delt)));\n",
+ "print\"\\t UD is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",round(Rd,4)\n",
+ "print\"\\t The assumption of three horizontal rows is satisfactory, since a dirt factor of 0.004 was required \\t\"\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 20.6 pgno:745"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 20.6 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t R is : \t2.0\n",
+ "\t V is : \t1.5\n",
+ "\t F is : \t1\n",
+ "\t Z is : \t0.733333333333\n",
+ "\t deltD is : \t1.1745\n",
+ "\t delt is : \t58.725\n",
+ "\t delt1 is : F \t50.0\n",
+ "\t delt2 is : F \t100.0\n",
+ "\t LMTD is : F \t72.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 20.6 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=200.; # inlet hot fluid,F\n",
+ "T2=100.; # outlet hot fluid,F\n",
+ "t1=50.; # inlet cold fluid,F\n",
+ "t2=100.; # outlet cold fluid,F\n",
+ "from math import log10\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \\t\",R\n",
+ "V=((T1+T2-t1-t2)/(t2-t1))/(2);\n",
+ "print\"\\t V is : \\t\",V\n",
+ "u=120;\n",
+ "U=60;\n",
+ "F=((u*1)/(U*2));\n",
+ "print\"\\t F is : \\t\",F\n",
+ "E=1.1; # In Fig.20.18b for R = 2.0and F = l.O,the abscissa and ordinate intersect at E =1.10.\n",
+ "Z=(E/V);\n",
+ "print\"\\t Z is : \\t\",Z\n",
+ "deltD=0.783*V; # deltD/V=0.783, from fig 20.17\n",
+ "print\"\\t deltD is : \\t\",deltD\n",
+ "delt=(deltD*(t2-t1));\n",
+ "print\"\\t delt is : \\t\",delt\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log10(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",round(LMTD)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 20.7 pgno:752"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 20.7 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t beta is : \t0.0036\n",
+ "\t for sand \t\n",
+ "\t total heat required for sand is : Btu/hr \t36000.0\n",
+ "\t w is : lb/hr \t2000.0\n",
+ "\t R is : \t0.1\n",
+ "\t S is : \t0.909090909091\n",
+ "\t rate per tube is : lb/hr \t62.475\n",
+ "\t number of tubes : \t16.006402561\n",
+ "\t for air assume hoi=9 and Beta=0.2 \t\n",
+ "\t w1 is : lb/hr \t8000.0\n",
+ "\t rate per tube is : lb/hr \t39.0\n",
+ "\t number of tubes : \t25.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 20.7 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=284.; # inlet hot fluid,F\n",
+ "T2=104.; # outlet hot fluid,F\n",
+ "t1=86.; # inlet cold fluid,F\n",
+ "t2=104.; # outlet cold fluid,F\n",
+ "W=1000; # lb/hr\n",
+ "k=0.15; # thermal conductivity\n",
+ "L=10;\n",
+ "Beta=((2*k)/(500*(2./12.))); # hoi=500Btu/(hr)*(ft^2)*(F) for water\n",
+ "print\"\\t beta is : \\t\",Beta\n",
+ "print\"\\t for sand \\t\"\n",
+ "C=0.2; # Btu/(lb)*(F)\n",
+ "Q=((W)*(C)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for sand is : Btu/hr \\t\",Q\n",
+ "c=1;\n",
+ "w=(Q/(t2-t1));\n",
+ "print\"\\t w is : lb/hr \\t\",w\n",
+ "R=((W*C)/(w*c));\n",
+ "print\"\\t R is : \\t\",R\n",
+ "S=((T2-T1)/(t1-T1));\n",
+ "print\"\\t S is : \\t\",S\n",
+ "W1=(8.33*(k*L)/C); # ((W1*C)/(k*L))=8.33 from fig 20.20b for Beta=0\n",
+ "print\"\\t rate per tube is : lb/hr \\t\",W1\n",
+ "N1=(W/W1);\n",
+ "print\"\\t number of tubes : \\t\",N1\n",
+ "print\"\\t for air assume hoi=9 and Beta=0.2 \\t\"\n",
+ "c1=0.25;\n",
+ "w1=(Q/(c1*(t2-t1)));\n",
+ "print\"\\t w1 is : lb/hr \\t\",w1\n",
+ "W2=(5.23*(k*L)/C); # ((W1*C)/(k*L))=5.23 from fig 20.20b for Beta=0.2\n",
+ "print\"\\t rate per tube is : lb/hr \\t\",round(W2)\n",
+ "N2=(W/W2);\n",
+ "print\"\\t number of tubes : \\t\",round(N2)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 20.8a pgno758"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 20.8a \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t unsteady state \t\n",
+ "\t Lb of water is : lb \t375.0\n",
+ "\t heat to be supplied : kwhr \t5.49531066823\n",
+ "\t losses \t\n",
+ "\t from surface of water : kwhr \t1\n",
+ "\t from sides of vessel : kwhr \t0.11\n",
+ "\t losses from bottom are negigible \t\n",
+ "\t total requirement : kwhr \t6.60531066823\n",
+ "\t steady state \t\n",
+ "\t heat to be supplied : kwhr \t1.9531066823\n",
+ "\t total requirement : kwhr \t3.06\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 20.8a \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "L=3; # ft\n",
+ "B=2; # ft\n",
+ "h=18/12; # ft , height of water present in tank\n",
+ "print\"\\t unsteady state \\t\"\n",
+ "m=(L*B*h*62.5);\n",
+ "print\"\\t Lb of water is : lb \\t\",m\n",
+ "t1=50;\n",
+ "t2=150;\n",
+ "c=1;\n",
+ "Q=(m*c*(t2-t1))/(2*3412); # kwhr\n",
+ "print\"\\t heat to be supplied : kwhr \\t\",Q\n",
+ "print\"\\t losses \\t\"\n",
+ "Q1=(L*B*260)/(1000); # from fig 20.25c\n",
+ "print\"\\t from surface of water : kwhr \\t\",Q1\n",
+ "Q2=(5.5*((2*B*2)+(2*L*B))/(1000)); # from fig 20.25c\n",
+ "print\"\\t from sides of vessel : kwhr \\t\",Q2\n",
+ "print\"\\t losses from bottom are negigible \\t\"\n",
+ "Qt=(Q+Q1+Q2);\n",
+ "print\"\\t total requirement : kwhr \\t\",Qt\n",
+ "print\"\\t steady state \\t\"\n",
+ "m1=8; # gal/hr\n",
+ "Qs=(m1*8.33*c*(t2-t1))/(3412); # kwhr\n",
+ "print\"\\t heat to be supplied : kwhr \\t\",Qs\n",
+ "Qts=(Qs+Q1+Q2);\n",
+ "print\"\\t total requirement : kwhr \\t\",round(Qts,2)\n",
+ "# end\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 20.8b pgno:760"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 20.8b \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t heat to steel charge : Btu \t3600.0\n",
+ "\t heat to air : Btu \t540.0\n",
+ "\t From Fig. 20.25a for 52ft^2 of oven outside surface and a temperature rise of 300F the loss is 5kw for 1 in.thick insulations.For 2 in.thick insulation the loss is 2.5kw \t\n",
+ "\t total requirement : kw \t3.71\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 20.8b \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "m=100; # lb\n",
+ "t1=70;\n",
+ "t2=370; \n",
+ "L=4;\n",
+ "B=3;\n",
+ "n=4; # number of air changers\n",
+ "c1=0.12\n",
+ "Q1=(m*c1*(t2-t1));\n",
+ "print\"\\t heat to steel charge : Btu \\t\",Q1\n",
+ "c2=0.25\n",
+ "Q2=(n*L*B*2*0.075*c2*(t2-t1));\n",
+ "print\"\\t heat to air : Btu \\t\",Q2\n",
+ "print\"\\t From Fig. 20.25a for 52ft^2 of oven outside surface and a temperature rise of 300F the loss is 5kw for 1 in.thick insulations.For 2 in.thick insulation the loss is 2.5kw \\t\"\n",
+ "Qt=((Q1+Q2)/(3412))+(2.5)\n",
+ "print\"\\t total requirement : kw \\t\",round(Qt,2)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 20.8c pgno:762"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 20.8c \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t heat : Btu \t15187.5\n",
+ "\t velocity is : fps \t2.0\n",
+ "\t Refer to Fig.20.22a.The air is capable of removing 33watts/in which is the maximum dissipation which may be expected. Any group of heaters providing 5 kw which do not require a dissipation of more than 33 w/in. and which will fit into the duct will be satisfactory \t\n",
+ "\t Thus in Table 20.3 elements of 350 watts with a total length each of 18 in. each are satisfactory \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 20.8c \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "m=270; # cfm\n",
+ "t1=70;\n",
+ "t2=120; \n",
+ "L=1.5; # ft\n",
+ "B=1.5; # ft\n",
+ "c=0.25\n",
+ "row=0.075; # lb/ft^3\n",
+ "Q=(m*row*60*c*(t2-t1));\n",
+ "print\"\\t heat : Btu \\t\",Q\n",
+ "V=(m/(L*B*60)); # fps\n",
+ "print\"\\t velocity is : fps \\t\",V\n",
+ "print\"\\t Refer to Fig.20.22a.The air is capable of removing 33watts/in which is the maximum dissipation which may be expected. Any group of heaters providing 5 kw which do not require a dissipation of more than 33 w/in. and which will fit into the duct will be satisfactory \\t\"\n",
+ "print\"\\t Thus in Table 20.3 elements of 350 watts with a total length each of 18 in. each are satisfactory \\t\"\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 20.8d pgno:762"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 20.8d \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t unsteady state \t\n",
+ "\t weight of plate : lb \t81.25\n",
+ "\t heat : Btu \t2429.375\n",
+ "\t From Figure 20.25b for a black body the radiation is 1.5w/in^2.The radiation from the top is actually 110 per cent of this value, and from the bottom of the plate it is 55 per cent for an average of 82.5 per cent is taken \t\n",
+ "\t radiation loss : kw \t0.7722\n",
+ "\t total requirement : kw \t1.48420908558\n",
+ "\t staedy state \t\n",
+ "\t heat : Btu \t3542.0\n",
+ "\t total requirement : kw \t1.83810082063\n",
+ "\t The steady state is controlling.The requirements are satisfied, by four 24-in. strip heaters, but the sheath temperature must now be checked. Since the temperature drop per unit flux density is 14 to 19F, assume an average of 16.5DegF. For clamp-on strips 24 in. long the watts per square inch deliverable are 16 \t\n",
+ "\t delt is : F \t264.0\n",
+ "\t The sheath temperature is then 300 + 264 = 564DegF, which is satisfactory for steel sheathed elements with a 750F maximum. \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 20.8d \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "t1=70;\n",
+ "t2=300; \n",
+ "L=26; # in\n",
+ "B=12; # in\n",
+ "H=1; # in\n",
+ "c1=0.13\n",
+ "# specific gravity of cast iron is 7.2\n",
+ "print\"\\t unsteady state \\t\"\n",
+ "m=(L*B*H*62.5*7.2/1728); # lb\n",
+ "print\"\\t weight of plate : lb \\t\",m\n",
+ "Q1=(m*c1*(t2-t1));\n",
+ "print\"\\t heat : Btu \\t\",Q1\n",
+ "print\"\\t From Figure 20.25b for a black body the radiation is 1.5w/in^2.The radiation from the top is actually 110 per cent of this value, and from the bottom of the plate it is 55 per cent for an average of 82.5 per cent is taken \\t\"\n",
+ "Q2=(2*26*12*1.5*0.825/1000); # ke\n",
+ "print\"\\t radiation loss : kw \\t\",Q2\n",
+ "Qt=((Q1)/(3412))+(Q2);\n",
+ "print\"\\t total requirement : kw \\t\",Qt\n",
+ "print\"\\t staedy state \\t\"\n",
+ "m2=70;\n",
+ "c2=0.22;\n",
+ "Qs=(m2*c2*(t2-t1));\n",
+ "print\"\\t heat : Btu \\t\",Qs\n",
+ "Ql=0.8; # kw\n",
+ "Qts=((Qs)/(3412))+(Ql);\n",
+ "print\"\\t total requirement : kw \\t\",Qts\n",
+ "print\"\\t The steady state is controlling.The requirements are satisfied, by four 24-in. strip heaters, but the sheath temperature must now be checked. Since the temperature drop per unit flux density is 14 to 19F, assume an average of 16.5DegF. For clamp-on strips 24 in. long the watts per square inch deliverable are 16 \\t\"\n",
+ "delt=(16*16.5);\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "print\"\\t The sheath temperature is then 300 + 264 = 564DegF, which is satisfactory for steel sheathed elements with a 750F maximum. \\t\"\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_2_Conduction.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_2_Conduction.ipynb
new file mode 100755
index 00000000..8bc5413c
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_2_Conduction.ipynb
@@ -0,0 +1,281 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 2:CONDUCTION"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example2.1 pg:13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " heat is Btu/hr 69120.0\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "#given\n",
+ "Tavg=900; # average temperature of the wall,F\n",
+ "k=0.15; # Thermal conductivity at 932 F,Btu/(hr)(ft^2)(F/ft)\n",
+ "T1=1500; # hot side temperature,F\n",
+ "T2=300; # cold side temperature,F\n",
+ "A=192; # surface area,ft^2\n",
+ "L=0.5; # thickness,ft\n",
+ "#solution\n",
+ "Q=(k)*(A)*(T1-T2)/L; # formula for heat,Btu/hr\n",
+ "print \" heat is Btu/hr \",Q\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#end\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example2.2 pg:14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t resistance offered by firebrick : (hr)*(F)/Btu 0.97\n",
+ "\t resistance offered by insulating brick : (hr)*(F)/Btu 2.2\n",
+ "\t resistance offered by buildingbrick : (hr)*(F)/Btu 1.25\n",
+ "\t total resistance offered by three walls : (hr)*(F)/Btu 4.42\n",
+ "\t heat loss/ft^2 : Btu/hr 331.0\n",
+ "\t delta is : F 322.0\n",
+ "\t temperature at interface of firebrick and insulating brick F 1278.0\n",
+ "\t deltb is : F 729.0\n",
+ "\t temperature at interface of insulating brick and building brick F 549.0\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "#given\n",
+ "La=0.66; # Thickness of firebrick wall,ft\n",
+ "Lb=0.33; # Thickness of insulating brick wall,ft\n",
+ "Lc=0.5; # Thickness of building brick wall,ft\n",
+ "Ka=0.68; # themal conductivity of firebrick,Btu/(hr)*(ft^2)*(F/ft)\n",
+ "Kb=0.15; # themal conductivity of insulating brick,Btu/(hr)*(ft^2)*(F/ft)\n",
+ "Kc=0.40; # themal conductivity of building brick,Btu/(hr)*(ft^2)*(F/ft)\n",
+ "A=1.; # surface area,ft^2\n",
+ "Ta=1600.; # temperature of inner wall,F\n",
+ "Tb=125.; # temperature of outer wall.F\n",
+ "#solution\n",
+ "Ra=La/(Ka)*(A); # formula for resistance,(hr)*(F)/Btu\n",
+ "print\"\\t resistance offered by firebrick : (hr)*(F)/Btu \",round(Ra,2)\n",
+ "Rb=Lb/(Kb)*(A); # formula for resistance,(hr)*(F)/Btu\n",
+ "print\"\\t resistance offered by insulating brick : (hr)*(F)/Btu \",round(Rb,2)\n",
+ "Rc=Lc/(Kc)*(A); # formula for resistance,(hr)*(F)/Btu\n",
+ "print\"\\t resistance offered by buildingbrick : (hr)*(F)/Btu \",round(Rc,2)\n",
+ "R=Ra+Rb+Rc; # total resistance offered by three walls,(hr)*(F)/Btu\n",
+ "print\"\\t total resistance offered by three walls : (hr)*(F)/Btu \",round(R,2)\n",
+ "Q=(1600-125)/4.45; # using formula for heat loss/ft^2,Btu/hr\n",
+ "print\"\\t heat loss/ft^2 : Btu/hr \",round(Q,0)\n",
+ "# T1,T2 are temperatures at interface of firebrick and insulating brick, and insulating brick and building brick respectively,F\n",
+ "delta=(Q)*(Ra); # formula for temperature difference,F\n",
+ "print\"\\t delta is : F \",round(delta,0)\n",
+ "T1=Ta-((Q)*(Ra)); # temperature at interface of firebrick and insulating brick,F\n",
+ "print\"\\t temperature at interface of firebrick and insulating brick F \",round(T1,0)\n",
+ "deltb=Q*(Rb);\n",
+ "print\"\\t deltb is : F \",round(deltb,0)\n",
+ "T2=T1-((Q)*(Rb)); #temperature at interface of insulating brick and building brick,F\n",
+ "print\"\\t temperature at interface of insulating brick and building brick F \",round(T2,0)\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example2.3 pg:15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t resistance offered by air film (hr)(F)/Btu 0.79\n",
+ "\t total resistance (hr)(F)/Btu 5.24\n",
+ "\t heat loss Btu/hr 282.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "Lair=0.25/12; # thickness of air film,ft\n",
+ "Kair=0.0265; # thermal conductivity of air at 572F,Btu/(hr)*(ft^2)(F/ft)\n",
+ "A=1; # surface area,ft^2\n",
+ "#solution\n",
+ "Rair=Lair/(Kair*(A)); # resistance offered by air film, (hr)(F)/Btu\n",
+ "print\"\\t resistance offered by air film (hr)(F)/Btu \",round(Rair,2)\n",
+ "R=4.45; # resistance from previous example 2.2,(hr)(F)/Btu\n",
+ "Rt=(R)+Rair; # total resistance,(hr)(F)/Btu\n",
+ "print\"\\t total resistance (hr)(F)/Btu \",round(Rt,2)\n",
+ "Ta=1600; # temperature of inner wall,F\n",
+ "Tb=125; # temperature of outer wall,F\n",
+ "Q=(1600-125)/Rt; # heat loss, Btu/hr\n",
+ "print\"\\t heat loss Btu/hr \",round(Q,0)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example2.4 pg 16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "\n",
+ "#given\n",
+ "k=0.63; # thermal conductivity of pipe, Btu/(hr)*(ft^2)*(F/ft)\n",
+ "Do=6. # in\n",
+ "Di=5. # in\n",
+ "Ti=200.;# inner side temperature,F\n",
+ "To=175.; # outer side temperature,F\n",
+ "#solution\n",
+ "import math\n",
+ "from math import log\n",
+ "q=(2*(3.14)*(k)*(Ti-To))/(log (Do/Di)); # formula for heat flow,Btu/(hr)*(ft)\n",
+ "print\"\\t heat flow is : Btu/(hr)*(ft) \",round(q,0)\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "# caculation mistake in book\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example2.5 pg 19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t heat loss for linear foot is : Btu/(hr)*(lin ft) 104.4\n",
+ "\t Check between ts and t1, since delt/R = deltc/Rc \n",
+ "\t t1 is : F 122.300238658\n",
+ "\t heat loss for linear foot is : Btu/(hr)*(lin ft) 102.9\n",
+ "\t Check between ts and t1, since delt/R = deltc/Rc \n",
+ "\t t1 is : F 125.4\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "t1=150; # assume temperature of outer surface of rockwool,F\n",
+ "ta=70; # temperature of surrounding air,F\n",
+ "ha=2.23; # surface coefficient,Btu/(hr)*(ft^2)*(F)\n",
+ "#solution\n",
+ "import math\n",
+ "from math import log\n",
+ "q=(3.14)*(300-70)/(((1/(2*0.033))*log(3.375/2.375))+(1/((2.23)*(3.375/12)))); # using formula for heat loss,Btu/(hr)*(lin ft), calculation mistake\n",
+ "print\"\\t heat loss for linear foot is : Btu/(hr)*(lin ft) \",round(q,1)\n",
+ "print\"\\t Check between ts and t1, since delt/R = deltc/Rc \"\n",
+ "t1=300-(((104.8)*((1)*(log(3.375/2.375))))/((2)*(3.14)*(.033))); # using eq 2.31,F\n",
+ "print\"\\t t1 is : F \",t1\n",
+ "t1=125; # assume temperature of outer surface of rockwool,F\n",
+ "ha=2.10; # surface coefficient,Btu/(hr)*(ft^2)*(F)\n",
+ "q=((3.14)*(300-70))/(((1/(2*0.033))*log(3.375/2.375))+(1/((2.10)*(3.375/12)))); # using formula for heat loss,Btu/(hr)*(lin ft)\n",
+ "print\"\\t heat loss for linear foot is : Btu/(hr)*(lin ft)\",round(q,1)\n",
+ "print\"\\t Check between ts and t1, since delt/R = deltc/Rc \"\n",
+ "t1=300-(((103)*((1)*(log(3.375/2.375))))/((2)*(3.14)*(.033))); # using eq 2.31,F\n",
+ "print\"\\t t1 is : F \",round(t1,1)\n",
+ "# end \n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_4_Radiation.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_4_Radiation.ipynb
new file mode 100755
index 00000000..71f8ec94
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_4_Radiation.ipynb
@@ -0,0 +1,208 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 4: Radiation"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.1 pgno:75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t heat removed from colder wall per unit area is : Btu/(hr)*(ft**2) 3500.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t approximate values are mentioned in the book \\n\";\n",
+ "#given\n",
+ "T1=1000+460; # R\n",
+ "T2=800+460; # R\n",
+ "#solution\n",
+ "Q=((0.173)*((14.6)**4-(12.6)**4)); # using eq.4.24,Btu/(hr)*(ft**2)\n",
+ "#results\n",
+ "print\"\\t heat removed from colder wall per unit area is : Btu/(hr)*(ft**2) \",round(Q,0)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.2 pgno:76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t heat removed from colder wall per unit area is : Btu/(hr)*(ft**2) 1826.0\n",
+ "\t For perfect black bodies the value was 3500 Btu/(hr)(ft**2) \n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "T1=1000+460; # R\n",
+ "T2=800+460; # R\n",
+ "e1=0.6; # emissivity of hotter wall\n",
+ "e2=0.8; # emissivity of colder wall\n",
+ "#solution\n",
+ "Q=(((0.173)/((1/0.6)+(1/0.8)-1))*((14.6)**4-(12.6)**4)); # using eq.4.26,heat loss per unit area,Btu/(hr)*(ft**2)\n",
+ "#results\n",
+ "print\"\\t heat removed from colder wall per unit area is : Btu/(hr)*(ft**2) \",round(Q,0)\n",
+ "print\"\\t For perfect black bodies the value was 3500 Btu/(hr)(ft**2) \"\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.3 pgno:78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t area is : ft**2/lin ft 0.88\n",
+ "\t heat loss is : Btu/(hr)*(lin ft) 52.4\n",
+ "\t fictitious film coefficient is : Btu/(hr)(ft**2)(F) 1.08\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "T1=125.+460.; # R\n",
+ "T2=70.+460.; # R\n",
+ "e=0.9; # emissivity,using table 4.1B\n",
+ "#solution\n",
+ "from math import pi\n",
+ "A=(pi)*(3.375/12)*(1); # area,ft**2/lin ft\n",
+ "print\"\\t area is : ft**2/lin ft \",round(A,2)\n",
+ "Q=(0.9)*(0.88)*(0.173)*((T1/100)**4-(T2/100)**4); # heat loss using eq.4.32,Btu/(hr)*(lin ft)\n",
+ "print\"\\t heat loss is : Btu/(hr)*(lin ft) \",round(Q,1)\n",
+ "hr=(Q)/((A)*(T1-T2)); # fictitious film coefficient,using eq 4.33,Btu/(hr)(ft**2)(F)\n",
+ "print\"\\t fictitious film coefficient is : Btu/(hr)(ft**2)(F) \",round(hr,2)\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.4 pgno:82"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t surface area of pipe is : ft**2/lin ft 0.62\n",
+ "\t surface area of duct is : ft**2/lin ft 4\n",
+ "\t The surface of the pipe is not negligible by comparison with that of the duct, and(f) of Table 4.2 applies most nearly\n",
+ "\t Fe is : 0.6\n",
+ "\t heat loss due to radiation is : Btu/(hr)*(lin ft) 162.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "T1=300+460; # R\n",
+ "T2=75+460; #R\n",
+ "A1=0.622; # area from table 11 in the appendix A,ft**2/lin ft\n",
+ "A2=4*(1*1); # surface area of duct,ft**2/lin ft\n",
+ "e1=0.79; # emissivity of oxidized steel from table 4.1\n",
+ "e2=0.276; # emissivity of oxidized zinc from table 4.1\n",
+ "print\"\\t surface area of pipe is : ft**2/lin ft \",round(A1,2)\n",
+ "print\"\\t surface area of duct is : ft**2/lin ft \",A2\n",
+ "print\"\\t The surface of the pipe is not negligible by comparison with that of the duct, and(f) of Table 4.2 applies most nearly\"\n",
+ "Fa=1; # from table 4.2\n",
+ "Fe=((1)/((1/e1)+((A1/A2)*((1/e2)-1)))); # from table 4.2\n",
+ "print\"\\t Fe is : \",round(Fe,2)\n",
+ "Q=(0.173*10**-8)*(Fa)*(Fe)*(A1)*((T1)**4-(T2)**4); # heat loss due to radiation,Btu/(hr)*(lin ft)\n",
+ "print\"\\t heat loss due to radiation is : Btu/(hr)*(lin ft) \",round(Q,0)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_5_Temperature.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_5_Temperature.ipynb
new file mode 100755
index 00000000..8b658273
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_5_Temperature.ipynb
@@ -0,0 +1,408 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 5: Temperature"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.1 pgno:90"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t for counter current flow \n",
+ "\t delt1 is : F 150.0\n",
+ "\t delt2 is : F 100.0\n",
+ "\t LMTDc is : F 123.3\n",
+ "\t for parallel flow \n",
+ "\t delt1 is : F 200.0\n",
+ "\t delt2 is : F 50.0\n",
+ "\t LMTDp is : F 108.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#given\n",
+ "T1=300.; # hot fluid inlet temperature,F\n",
+ "T2=200.; # hot fluid outlet temperature,F\n",
+ "t1=100.; # cold fluid inlet temperature,F\n",
+ "t2=150.; # cold fluid outlet temperature,F\n",
+ "#solution\n",
+ "from math import log\n",
+ "print\"\\t for counter current flow \"\n",
+ "delt1=T1-t2; #F\n",
+ "delt2=T2-t1; # F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "LMTDc=((delt2-delt1)/(log(delt2/delt1)));\n",
+ "print\"\\t LMTDc is : F \",round(LMTDc,1)\n",
+ "print\"\\t for parallel flow \"\n",
+ "delt1=T1-t1; # F\n",
+ "delt2=T2-t2; # F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "LMTDp=((delt2-delt1)/((log(delt2/delt1))));\n",
+ "print\"\\t LMTDp is : F \",round(LMTDp,0)\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.2 pgno:91"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t for counter current flow \n",
+ "\t delt1 is : F 100.0\n",
+ "\t delt2 is : F 50.0\n",
+ "\t LMTD is : F 72.1347520444\n",
+ "\t for parallel flow \n",
+ "\t delt1 is : F 150.0\n",
+ "\t delt2 is : F 0.0\n",
+ "\t denominator becomes infinity so LMTD becomes Zero \n",
+ "\n",
+ "\t LMTD is Zero \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "#given\n",
+ "T1=300.; # hot fluid inlet temperature,F\n",
+ "T2=200.; # hot fluid outlet temperature,F\n",
+ "t1=150.; # cold fluid inlet temperature,F\n",
+ "t2=200.; # cold fluid outlet temperature,F\n",
+ "#solution\n",
+ "from math import log\n",
+ "print\"\\t for counter current flow \"\n",
+ "delt1=T1-t2; #F\n",
+ "delt2=T2-t1; # F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))))\n",
+ "print\"\\t LMTD is : F \",LMTD\n",
+ "print\"\\t for parallel flow \"\n",
+ "delt1=T1-t1; # F\n",
+ "delt2=T2-t2; # F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "if delt2 == 0:\n",
+ " print\"\\t denominator becomes infinity so LMTD becomes Zero \\n\"\n",
+ " print\"\\t LMTD is Zero \\n\"\n",
+ "else:\n",
+ " LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))));\n",
+ " print\"\\t LMTD is : F \",LMTD\n",
+ " \n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.3 pgno:91"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t for counter current flow \n",
+ "\n",
+ "\t delth is : F 25.0\n",
+ "\t deltc is : F 100.0\n",
+ "\t LMTD is : F 54.1\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "T1=300.; # hot fluid inlet temperature,F\n",
+ "T2=200.; # hot fluid outlet temperature,F\n",
+ "t1=100.; # cold fluid inlet temperature,F\n",
+ "t2=275.; # cold fluid outlet temperature,F\n",
+ "#solution\n",
+ "from math import log\n",
+ "print\"\\t for counter current flow \\n\"\n",
+ "deltc=T2-t1; #F\n",
+ "delth=T1-t2; # F\n",
+ "print\"\\t delth is : F \",delth\n",
+ "print\"\\t deltc is : F \",deltc\n",
+ "LMTD=((delth-deltc)/((1)*(log(delth/deltc))))\n",
+ "print\"\\t LMTD is : F \",round(LMTD,1)\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.4 pgno:92"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 5.4 \n",
+ "\n",
+ "\t process is isothermal with hot fluid so temperature of hot fluid remains constant \n",
+ "\n",
+ "\t for counter current flow \n",
+ "\n",
+ "\t delt1 is : F 25.0\n",
+ "\t delt2 is : F 200.0\n",
+ "\t LMTD is : F 84.1572107185\n",
+ "\t for parallel flow \n",
+ "\n",
+ "\t delt1 is : F 200.0\n",
+ "\t delt2 is : F 25.0\n",
+ "\t LMTD is : F 84.1572107185\n",
+ "\t these are identical \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 5.4 \\n\"\n",
+ "print\"\\t process is isothermal with hot fluid so temperature of hot fluid remains constant \\n\"\n",
+ "#given\n",
+ "T1=300.; # hot fluid inlet temperature,F\n",
+ "T2=300.; # hot fluid outlet temperature,F\n",
+ "t1=100.; # cold fluid inlet temperature,F\n",
+ "t2=275.; # cold fluid outlet temperature,F\n",
+ "#solution\n",
+ "from math import log\n",
+ "print\"\\t for counter current flow \\n\"\n",
+ "delt1=T1-t2; #F\n",
+ "delt2=T2-t1; # F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))))\n",
+ "print\"\\t LMTD is : F \",LMTD\n",
+ "print\"\\t for parallel flow \\n\"\n",
+ "delt1=T1-t1; # F\n",
+ "delt2=T2-t2; # F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "if delt2 == 0:\n",
+ " print\"\\t denominator becomes infinity so LMTD becomes Zero \\n\"\n",
+ " print\"\\t LMTD is Zero \\n\"\n",
+ "else:\n",
+ " LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))));\n",
+ " print\"\\t LMTD is : F \",LMTD\n",
+ " \n",
+ "print\"\\t these are identical \\n\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.5 pgno:93"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false,
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 5.5 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t for inlet \t\n",
+ "\t Re is : \t2589.0\n",
+ "\t Pr is : \t3.52\n",
+ "\t nusselt number is : \t105.0\n",
+ "\t heat transfer coefficient is : 158.0\n",
+ "\t for outlet \t\n",
+ "\t Re is : \t3372.0\n",
+ "\t Pr is : \t3.23\n",
+ "\t nusselt number is : \t125.0\n",
+ "\t heat transfer coefficient is : 189.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 5.5 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "print\"\\t for inlet \\t\"\n",
+ "t1=99.1; # temperature of inlet,F\n",
+ "t2=129.2; # temperature of outlet,F\n",
+ "c=.478; # Btu/(hr)*(ft)*(F/ft)\n",
+ "mu=7.139; # lb/(ft)(hr)\n",
+ "k=0.078; # Btu/(hr)*(ft)*(F/ft)\n",
+ "G=854000; # mass velocity,lb/(ft**2)(hr)\n",
+ "D=0.622/12; # diameter,ft\n",
+ "Re=((D)*((G)/(mu)))**(0.9);\n",
+ "print\"\\t Re is : \\t\",round(Re)\n",
+ "Pr=((c)*(mu)/k)**(1./3.); # prandtl number raised to power 1/3\n",
+ "print\"\\t Pr is : \\t\",round(Pr,2)\n",
+ "Nu=0.0115*(Re)*(Pr); # formula for nusselt number\n",
+ "print\"\\t nusselt number is : \\t\",round(Nu)\n",
+ "hi=((k)*(Nu)/(D)); # heat transfer coefficient\n",
+ "print\"\\t heat transfer coefficient is :\",round(hi) # caculation mistake in book\n",
+ "print\"\\t for outlet \\t\"\n",
+ "c=.495; # Btu/(hr)*(ft)*(F/ft)\n",
+ "mu=2.20*2.42; # lb/(ft)(hr)\n",
+ "k=0.078; # Btu/(hr)*(ft)*(F/ft)\n",
+ "G=854000; # mass velocity,lb/(ft**2)(hr)\n",
+ "D=0.622/12; # diameter,ft\n",
+ "Re=((D)*((G)/(mu)))**(.9); # reynolds number raised to poer 0.9, calculation mistake in book\n",
+ "print\"\\t Re is : \\t\",round(Re)\n",
+ "Pr=((c)*(mu)/k)**(1./3.); # prandtl number raised to power 1/3\n",
+ "print\"\\t Pr is : \\t\",round(Pr,2)\n",
+ "Nu=0.0115*(Re)*(Pr); # formula for nusselt number\n",
+ "print\"\\t nusselt number is : \\t\",round(Nu)\n",
+ "hi=((k)*(Nu)/(D)); # heat transfer coefficient\n",
+ "print\"\\t heat transfer coefficient is :\",round(hi) # caculation mistake in book\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.6 pgno:97"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 5.6 \n",
+ "\t approximate values are mentioned in the book \n",
+ "\t for counter current flow \n",
+ "\t temperature difference for crude oil is : F 100\n",
+ "\t temperature difference for gasoline is : F 40\n",
+ "\t The larger value of K. correspQnds to the controlling heat transfer coefficient which is assumed to establish the variation of U with temperature \n",
+ "\t deltc is : F 120\n",
+ "\t delth is : F 180\n",
+ "\t ratio of two local temperature difference is : 0.67\n",
+ "\t caloric temperature of hot fluid is : F 242.5\n",
+ "\t caloric temperature of cold fluid is : F 97.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 5.6 \"\n",
+ "print\"\\t approximate values are mentioned in the book \"\n",
+ "T1=300; # hot fluid inlet temperature,F\n",
+ "T2=200; # hot fluid outlet temperature,F\n",
+ "t1=80; # cold fluid inlet temperature,F\n",
+ "t2=120; # cold fluid outlet temperature,F\n",
+ "print\"\\t for counter current flow \"\n",
+ "delT=T1-T2; # temperature difference for crude oil,F\n",
+ "print\"\\t temperature difference for crude oil is : F \",delT\n",
+ "Kc=0.68; # from fig.17\n",
+ "delt=t2-t1; # temperature difference for gasoline,F\n",
+ "print\"\\t temperature difference for gasoline is : F \",delt\n",
+ "Kc<=0.10; # from fig.17\n",
+ "print\"\\t The larger value of K. correspQnds to the controlling heat transfer coefficient which is assumed to establish the variation of U with temperature \"\n",
+ "deltc=T2-t1; #F\n",
+ "delth=T1-t2; # F\n",
+ "print\"\\t deltc is : F \",deltc\n",
+ "print\"\\t delth is : F \",delth\n",
+ "A=120./180.#((deltc)/(delth));\n",
+ "print\"\\t ratio of two local temperature difference is : \",round(A,2)\n",
+ "Fc=0.425; # from fig.17\n",
+ "Tc=((T2)+((Fc)*(T1-T2))); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \",Tc\n",
+ "tc=((t1)+((Fc)*(t2-t1))); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \",tc\n",
+ "# end\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_6_Counterflow_Double_Pipe_Exchangers.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_6_Counterflow_Double_Pipe_Exchangers.ipynb
new file mode 100755
index 00000000..49162c0d
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_6_Counterflow_Double_Pipe_Exchangers.ipynb
@@ -0,0 +1,507 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 6 Counterflow : Double Pipe Exchangers"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6.1 pgno:113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false,
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 6.1 \n",
+ "\t approximate values are mentioned in the book \n",
+ "\t 1.for heat balance \n",
+ "\t for benzene \n",
+ "\t average temperature of benzene is : F 100\n",
+ "\t total heat required for benzene is : Btu/hr 166940.0\n",
+ "\t for toulene \n",
+ "\n",
+ "\t average temperature of toulene is : F 130\n",
+ "\t W is : lb/hr 6323.48484848\n",
+ "\t 2.LMTD \n",
+ "\t for counter current flow \n",
+ "\t delt1 is : F 20\n",
+ "\t delt2 is : F 40\n",
+ "\t LMTD is : F \t28.8539008178\n",
+ "\t 3.caloric temperatures \n",
+ "\n",
+ "\t both streams will show that neither is viscous at the cold terminal (the viscosities less than 1 centipoise) and the temperature ranges and temperature difference are moderate. The coefficients may accordingly be evaluated from properties at the arithmetic mean, and the value of (mu/muw)**0.14 may be assumed equal to 1.0 \n",
+ "\n",
+ "\t average temperature of benzene is : F 100\n",
+ "\t average temperature of toulene is : F 130\n",
+ "\t hot fluid:annulus,toulene \n",
+ "\t flow area is : ft**2 0.00841338147585\n",
+ "\t equiv diameter is : ft 0.077625\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) 751598.494212\n",
+ "\t reynolds number is : 58801.4846938\n",
+ "\t Pr is : 1.0\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) 182.866344605\n",
+ "\t cold fluid:inner pipe,benzene \n",
+ "\t flow area is : ft**2 0.0103868907109\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) 945422.482367\n",
+ "\t reynolds number is : 89854.2028696\n",
+ "\t Pr is : 1.0\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) 186.747826087\n",
+ "\t Correct hi to the surface at the OD is : Btu/(hr)*(ft**2)*(F) 155.248192771\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) 83.9646521529\n",
+ "\t design overall coefficient is : Btu/(hr)*(ft**2)*(F) 71.891896062\n",
+ "\t required surface is : ft**2 80.4777705563\n",
+ "\t required length is : lin ft 185.006369095\n",
+ "\t This may be fulfilled by connecting three 20-ft hairpins in series \n",
+ "\n",
+ "\t actual surface supplied is : ft**2 52.2\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) 110.837155481\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu -0.00288752837534\n",
+ "\t pressure drop for annulus \n",
+ "\t De1 is : ft 0.0345\n",
+ "\t reynolds number is : 26133.9931973\n",
+ "\t friction factor is : 0.00718449101601\n",
+ "\t delFa is : ft 35.2200986001\n",
+ "\t V is : fps 3.83958362305\n",
+ "\t Fl is : ft 0.686757875702\n",
+ "\t delPa is : psi 13.5585786172\n",
+ "\t allowable delPa is 10 psi \n",
+ "\t pressure drop for inner pipe \n",
+ "\t friction factor is : 0.00569339980566\n",
+ "\t delFp is : ft 12.9491334918\n",
+ "\t delPp is : psi 4.94584959755\n",
+ "\t allowable delPp is 10 psi \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 6.1 \"\n",
+ "print\"\\t approximate values are mentioned in the book \"\n",
+ "#given\n",
+ "T1=160; # inlet hot fluid,F\n",
+ "T2=100; # outlet hot fluid,F\n",
+ "t1=80; # inlet cold fluid,F\n",
+ "t2=120; # outlet cold fluid,F\n",
+ "w=9820; # lb/hr\n",
+ "#solution\n",
+ "from math import log\n",
+ "from math import pi\n",
+ "print\"\\t 1.for heat balance \"\n",
+ "print\"\\t for benzene \"\n",
+ "tav=((t1+t2)/2); # F\n",
+ "print\"\\t average temperature of benzene is : F \",tav\n",
+ "c=0.425; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for benzene is : Btu/hr \",Q\n",
+ "print\"\\t for toulene \\n\"\n",
+ "Tav=((T1+T2)/2); #F\n",
+ "print\"\\t average temperature of toulene is : F \",Tav\n",
+ "c=0.44; # Btu/(lb)*(F)\n",
+ "W=((Q)/((c)*(T1-T2))); # lb/hr\n",
+ "print\"\\t W is : lb/hr \",round(W)\n",
+ "print\"\\t 2.LMTD \"\n",
+ "print\"\\t for counter current flow \"\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",round(LMTD,1)\n",
+ "print\"\\t 3.caloric temperatures \\n\"\n",
+ "print\"\\t both streams will show that neither is viscous at the cold terminal (the viscosities less than 1 centipoise) and the temperature ranges and temperature difference are moderate. The coefficients may accordingly be evaluated from properties at the arithmetic mean, and the value of (mu/muw)**0.14 may be assumed equal to 1.0 \\n\"\n",
+ "tav=((t1+t2)/2); # F\n",
+ "print\"\\t average temperature of benzene is : F \",tav\n",
+ "Tav=((T1+T2)/2); #F\n",
+ "print\"\\t average temperature of toulene is : F \",Tav\n",
+ "print\"\\t hot fluid:annulus,toulene \"\n",
+ "D1=0.138; # ft\n",
+ "D2=0.1725; # ft\n",
+ "aa=((pi)*(D2**2-D1**2)/4); # flow area,ft**2\n",
+ "print\"\\t flow area is : ft**2 \",aa\n",
+ "De=(D2**2-D1**2)/D1; # equiv diameter,ft\n",
+ "print\"\\t equiv diameter is : ft \",De\n",
+ "Ga=(W/aa); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \",Ga\n",
+ "mu1=0.41*2.42; # at 130 F,lb/(ft)*(hr)\n",
+ "Rea=((De)*(Ga)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \",Rea\n",
+ "jH=167; # from fig.24\n",
+ "c=0.44; # Btu/(lb)*(F),at 130F\n",
+ "k=0.085; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "Pr=((c)*(mu1)/k)**(1/3); # prandelt number raised to power 1/3\n",
+ "print\"\\t Pr is : \",Pr\n",
+ "ho=((jH)*(k/De)*(Pr)*(1**0.14)); # using eq.6.15b,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \",ho\n",
+ "print\"\\t cold fluid:inner pipe,benzene \"\n",
+ "D=0.115; # ft\n",
+ "ap=((pi)*(D**2)/4); # flow area, ft**2\n",
+ "print\"\\t flow area is : ft**2 \",ap\n",
+ "Gp=(w/ap); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \",Gp\n",
+ "mu2=0.5*2.42; # at 130 F,lb/(ft)*(hr)\n",
+ "Rep=((D)*(Gp)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \",Rep\n",
+ "jH=236; # from fig.24\n",
+ "c=0.425; # Btu/(lb)*(F),at 130F\n",
+ "k=0.091; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "Pr=((c)*(mu2)/k)**(1/3); # prandelt number raised to power 1/3\n",
+ "print\"\\t Pr is : \",Pr\n",
+ "hi=((jH)*(k/D)*(Pr)*(1**0.14)); # using eq.6.15a,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \",hi\n",
+ "ID=1.38; # ft\n",
+ "OD=1.66; #ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hi to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \",hio\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \",Uc\n",
+ "Rd=0.002; # required by problem,(hr)*(ft**2)*(F)/Btu\n",
+ "UD=((Uc)/((1)+(Uc*Rd))); # design overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t design overall coefficient is : Btu/(hr)*(ft**2)*(F) \",UD\n",
+ "A=((Q)/((UD)*(LMTD))); # required surface,ft**2\n",
+ "print\"\\t required surface is : ft**2 \",A\n",
+ "A1=0.435; # From Table 11 for 1(1/4)in IPS standard pipe there are 0.435 ft2 of external surface per foot length,ft**2\n",
+ "L=(A/A1); # required length;lin ft\n",
+ "print\"\\t required length is : lin ft \",L\n",
+ "print\"\\t This may be fulfilled by connecting three 20-ft hairpins in series \\n\"\n",
+ "A2=120*0.435; # actual surface supplied,ft**2\n",
+ "print\"\\t actual surface supplied is : ft**2 \",A2\n",
+ "UD=((Q)/((A2)*(LMTD)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \",UD\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \",Rd\n",
+ "print\"\\t pressure drop for annulus \"\n",
+ "De1=(D2-D1); #ft\n",
+ "print\"\\t De1 is : ft \",De1\n",
+ "Rea1=((De1)*(Ga)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is :\",Rea1\n",
+ "f=(0.0035)+((0.264)/(Rea1**0.42)); # friction factor, using eq.3.47b\n",
+ "print\"\\t friction factor is : \",f\n",
+ "s=0.87;\n",
+ "row=62.5*0.87; # from table 6\n",
+ "delFa=((4*f*(Ga**2)*L)/(2*4.18*(10**8)*(row**2)*(De1))); # ft\n",
+ "print\"\\t delFa is : ft \",delFa\n",
+ "V=((Ga)/(3600*row)); #fps\n",
+ "print\"\\t V is : fps \",V\n",
+ "Fl=((3*(V**2))/(2*32.2)); #ft\n",
+ "print\"\\t Fl is : ft \",Fl\n",
+ "delPa=((delFa+Fl)*(row)/144); # psi\n",
+ "print\"\\t delPa is : psi \",delPa\n",
+ "print\"\\t allowable delPa is 10 psi \"\n",
+ "print\"\\t pressure drop for inner pipe \"\n",
+ "f=(0.0035)+((0.264)/(Rep**0.42)); # friction factor, using eq.3.47b\n",
+ "print\"\\t friction factor is : \",f\n",
+ "s=0.88;\n",
+ "row=62.5*0.88; # from table 6\n",
+ "delFp=((4*f*(Gp**2)*L)/(2*4.18*(10**8)*(row**2)*(D))); # ft\n",
+ "print\"\\t delFp is : ft \",delFp\n",
+ "delPp=((delFp)*(row)/144); # psi\n",
+ "print\"\\t delPp is : psi \",delPp\n",
+ "print\"\\t allowable delPp is 10 psi \\n\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6.2 pgno:120"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 6.2 \n",
+ "\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t P is : 0.091\n",
+ "\t R is : 0.556\n",
+ "\t gama is : 0.242\n",
+ " true temperature difference is : F 26.6\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 6.2 \\n\"\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "T1=300.; # inlet hot fluid,F\n",
+ "T2=200.; # outlet hot fluid,F\n",
+ "t1=190.; # inlet cold fluid,F\n",
+ "t2=220.; # outlet cold fluid,F\n",
+ "n=6; # number of parallel streams\n",
+ "#solution\n",
+ "from math import log\n",
+ "P=((T2-t1)/(T1-t1));\n",
+ "print\"\\t P is : \",round(P,3)\n",
+ "R=((T1-T2)/((n)*(t2-t1)));\n",
+ "print\"\\t R is : \",round(R,3)\n",
+ "gama=0.242#((1-P)/((1)*((n*R)/(R-1))*log(((R-1)/R)*(1/P)**(1/n)+(1/R)))); # using eq.6.35a\n",
+ "print\"\\t gama is :\",gama\n",
+ "delt=(gama*(T1-t1)); # true temperature difference,F\n",
+ "print\" true temperature difference is : F \",round(delt,1)\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6.3 pgno:121"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 6.3 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for lube oil \t\n",
+ "\t total heat required for lube oil is : Btu/hr \t427800.0\n",
+ "\t for crude oil \t\n",
+ "\t total heat required for crude oil is : Btu/hr \t424125.0\n",
+ "\t delt1 is : F \t50\n",
+ "\t delt2 is : F \t140\n",
+ "\t LMTD is : F \t129.84255368\n",
+ "\t ratio of two local temperature difference is : \t0\n",
+ "\t caloric temperature of hot fluid is : F \t389.5\n",
+ "\t caloric temperature of cold fluid is : F \t303.95\n",
+ "\t hot fluid:annulus,lube oil \t\n",
+ "\t flow area is : ft**2 \t0.0203693013677\n",
+ "\t equiv diameter is : ft \t0.130326633166\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t338745.049496\n",
+ "\t reynolds number is : \t6080.92311327\n",
+ "\t Pr is : \t1.0\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t10.5389049547\n",
+ "\t cold fluid:inner pipe,crude oil \t\n",
+ "\t flow area is : ft**2 \t0.023235219266\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t1560131.60819\n",
+ "\t reynolds number is : \t133596.851841\n",
+ "\t Pr is : \t1.0\n",
+ "\t Hi is : Btu/(hr)*(ft**2)*(F) \t135.813953488\n",
+ "\t Correct Hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) 117.952706664\n",
+ "\t phyp is : \t1.01056029649\n",
+ "\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) 117.952706664\n",
+ "\t tw is : F \t310.966826293\n",
+ "\t phya is : \t0.89549017376\n",
+ "\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t9.43748582912\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t8.73832573656\n",
+ "\t design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t8.30299983373\n",
+ "\t required surface is : ft**2 \t396.815568378\n",
+ "\t required length is : lin ft \t637.967151733\n",
+ "\t Since two parallel streams are employed, use eight 20 ft hairpins or 320 lin. feet \t\n",
+ "\t actual surface supplied is : ft**2 \t199.04\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t16.5532536086\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t-0.0540273138235\n",
+ "\t pressure drop for annulus \t\n",
+ "\t De1 is : ft \t0.058\n",
+ "\t reynolds number is : \t2709.96039597\n",
+ "\t friction factor is : \t0.0130893090019\n",
+ "\t delFa is : ft \t16.8995403857\n",
+ "\t V is : fps \t1.94262393976\n",
+ "\t delFl is : ft \t0.468793511967\n",
+ "\t delPa is : psi \t5.84221300811\n",
+ "\t allowable delPa is 10 psi \t\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t friction factor is : \t0.0053568\n",
+ "\t delFp is : ft \t25.7\n",
+ "\t delPp is : psi \t8.5\n",
+ "\t allowable delPp is 10 psi \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 6.3 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "T1=450; # inlet hot fluid,F\n",
+ "T2=350; # outlet hot fluid,F\n",
+ "t1=300; # inlet cold fluid,F\n",
+ "t2=310; # outlet cold fluid,F\n",
+ "W=6900; # lb/hr\n",
+ "w=72500; # lb/hr\n",
+ "from math import log,pi\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for lube oil \\t\"\n",
+ "c=0.62; # Btu/(lb)*(F)\n",
+ "Q=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for lube oil is : Btu/hr \\t\",Q\n",
+ "print\"\\t for crude oil \\t\"\n",
+ "c=0.585; # Btu/(lb)*(F)\n",
+ "Q1=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for crude oil is : Btu/hr \\t\",Q1 # calculation mistake in book\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "A=((delt1)/(delt2));\n",
+ "print\"\\t ratio of two local temperature difference is : \\t\",A\n",
+ "Fc=0.395; # from fig.17\n",
+ "Tc=((T2)+((Fc)*(T1-T2))); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+((Fc)*(t2-t1))); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:annulus,lube oil \\t\"\n",
+ "D1=0.199; # ft\n",
+ "D2=0.256; # ft\n",
+ "aa=((pi)*(D2**2-D1**2)/4); # flow area,ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",aa\n",
+ "De=(D2**2-D1**2)/D1; # equiv diameter,ft\n",
+ "print\"\\t equiv diameter is : ft \\t\",De\n",
+ "Ga=(W/aa); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Ga\n",
+ "mu1=3*2.42; # at 389.5F,lb/(ft)*(hr), from fig.14\n",
+ "Rea=((De)*(Ga)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Rea\n",
+ "jH=20.5; # from fig.24\n",
+ "c=0.615; # Btu/(lb)*(F),at 130F\n",
+ "k=0.067; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "Pr=((c)*(mu1)/k)**(1/3); # prandelt number raised to power 1/3\n",
+ "print\"\\t Pr is : \\t\",Pr\n",
+ "Ho=((jH)*(k/De)*(Pr)); # H0=(h0/phya),using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Ho\n",
+ "print\"\\t cold fluid:inner pipe,crude oil \\t\"\n",
+ "D=0.172; # ft\n",
+ "ap=((pi)*(D**2)/4); # flow area, ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",ap\n",
+ "Gp=(w/(2*ap)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gp\n",
+ "mu2=0.83*2.42; # at 304 F,lb/(ft)*(hr)\n",
+ "Rep=((D)*(Gp)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Rep\n",
+ "jH=320; # from fig.24\n",
+ "c=0.585; # Btu/(lb)*(F),at 304F,from fig.4\n",
+ "k=0.073; # Btu/(hr)*(ft**2)*(F/ft), from fig.1\n",
+ "Pr=((c)*(mu2)/k)**(1/3); # prandelt number raised to power 1/3\n",
+ "print\"\\t Pr is : \\t\",Pr\n",
+ "Hi=((jH)*(k/D)*(Pr)*(1**0.14)); #Hi=(hi/phyp),using eq.6.15a,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t Hi is : Btu/(hr)*(ft**2)*(F) \\t\",Hi\n",
+ "ID=2.067; # ft\n",
+ "OD=2.38; #ft\n",
+ "Hio=((Hi)*(ID/OD)); #Hio=(hio/phyp), using eq.6.5\n",
+ "print\"\\t Correct Hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \",Hio\n",
+ "muw=0.77*2.42; # lb/(ft)*(hr), from fig.14\n",
+ "phyp=(mu2/muw)**0.14;\n",
+ "print\"\\t phyp is : \\t\",phyp # from fig.24\n",
+ "hio=(Hio)*(1); # from eq.6.37\n",
+ "print\"\\t Correct hio to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \",hio\n",
+ "tw=(tc)+(((Ho)/(Hio+Ho))*(Tc-tc)); # from eq.5.31\n",
+ "print\"\\t tw is : F \\t\",tw\n",
+ "muw=6.6*2.42; # lb/(ft)*(hr), from fig.14\n",
+ "phya=(mu1/muw)**0.14;\n",
+ "print\"\\t phya is : \\t\",phya # from fig.24\n",
+ "ho=(Ho)*(phya); # from eq.6.36\n",
+ "print\"\\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "Rd=0.006; # required by problem,(hr)*(ft**2)*(F)/Btu\n",
+ "UD=((Uc)/((1)+(Uc*Rd))); # design overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "A=((Q)/((UD)*(LMTD))); # required surface,ft**2\n",
+ "print\"\\t required surface is : ft**2 \\t\",A\n",
+ "A1=0.622; # From Table 11,ft**2\n",
+ "Lr=(A/A1); # required length;lin ft\n",
+ "print\"\\t required length is : lin ft \\t\",Lr\n",
+ "print\"\\t Since two parallel streams are employed, use eight 20 ft hairpins or 320 lin. feet \\t\"\n",
+ "L=320;\n",
+ "A2=320*0.622; # actual surface supplied,ft**2\n",
+ "print\"\\t actual surface supplied is : ft**2 \\t\",A2\n",
+ "UD=((Q)/((A2)*(LMTD)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "De1=.058; #ft\n",
+ "print\"\\t De1 is : ft \\t\",De1\n",
+ "Rea1=((De1)*(Ga)/7.25); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Rea1\n",
+ "f=(0.0035)+((0.264)/(2680**0.42)); # friction factor, using eq.3.47b\n",
+ "print\"\\t friction factor is : \\t\",f\n",
+ "s=0.775;\n",
+ "row=62.5*0.775; # from fig 6\n",
+ "delFa=((4*f*(Ga**2)*L)/(2*4.18*(10**8)*(row**2)*(De1))); # ft\n",
+ "print\"\\t delFa is : ft \\t\",delFa\n",
+ "V=((Ga)/(3600*row)); #fps\n",
+ "print\"\\t V is : fps \\t\",V\n",
+ "delFl=((8*(V**2))/(2*32.2)); #ft\n",
+ "print\"\\t delFl is : ft \\t\",delFl\n",
+ "delPa=((delFa+delFl)*(row)/144); # psi\n",
+ "print\"\\t delPa is : psi \\t\",delPa\n",
+ "print\"\\t allowable delPa is 10 psi \\t\"\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=(0.0035)+((0.264)/(Rep**0.42)); # friction factor, using eq.3.47b\n",
+ "print\"\\t friction factor is : \\t\",round(f,7)\n",
+ "s=0.76;\n",
+ "row=62.5*0.76; # from table 6\n",
+ "Lp=160;\n",
+ "delFp=((4*f*(Gp**2)*Lp)/(2*4.18*(10**8)*(row**2)*(D))); # ft\n",
+ "print\"\\t delFp is : ft \\t\",round(delFp,1)\n",
+ "delPp=((delFp)*(row)/144); # psi\n",
+ "print\"\\t delPp is : psi \\t\",round(delPp,1)\n",
+ "print\"\\t allowable delPp is 10 psi \\t\"\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_7_Parallel-Counter_flow_Shell_and_Tube_Exchangers.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_7_Parallel-Counter_flow_Shell_and_Tube_Exchangers.ipynb
new file mode 100755
index 00000000..2593280d
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_7_Parallel-Counter_flow_Shell_and_Tube_Exchangers.ipynb
@@ -0,0 +1,1093 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 7 Parallel-Counter flow:Shell and Tube Exchangers"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.1 pgno:139"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 7.1 \n",
+ "\n",
+ "\t equivalent diameter is : in 0.95\n",
+ "\t De is : in 0.079\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 7.1 \\n\"\n",
+ "#given\n",
+ "PT=1; # square pitch,in\n",
+ "do=0.75; # outer diameter,in\n",
+ "#solution\n",
+ "de=((4*(PT**2-(3.14*do**2/4)))/(3.14*do));\n",
+ "print\"\\t equivalent diameter is : in \",round(de,2)\n",
+ "De=(de/12); # ft\n",
+ "print\"\\t De is : in \",round(De,3)\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.2 pgno:147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 7.2 \n",
+ "\t approximate values are mentioned in the book \n",
+ "\t considering 50F approach \n",
+ "\t t2 is : F 200.0\n",
+ "\t fluids are with equal ranges,so \n",
+ "\t t1 is : F 100.0\n",
+ "\t R is : 1.0\n",
+ "\t S is : 0.4\n",
+ "\t FT is 0.925 \n",
+ "\t considering 0F approach \n",
+ "\t t2 is : F 200\n",
+ "\t fluids are with equal ranges,so \n",
+ "\t t1 is : F 100\n",
+ "\t R is : 1\n",
+ "\t S is : 0\n",
+ "\t FT is 0.80 \n",
+ "\t considering 20F cross \n",
+ "\t t2 is : F 200\n",
+ "\t fluids are with equal ranges,so \n",
+ "\n",
+ "\t t1 is : F 100\n",
+ "\t R is : 1\n",
+ "\t S is : 0\n",
+ "\t FT is 0.64 \n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 7.2 \"\n",
+ "print\"\\t approximate values are mentioned in the book \"\n",
+ "print\"\\t considering 50F approach \"\n",
+ "#given\n",
+ "T1=350.; #F\n",
+ "T2=250.; #F\n",
+ "t2=T2-50.; # formula for approach,f\n",
+ "print\"\\t t2 is : F \",t2\n",
+ "t2=200.;\n",
+ "print\"\\t fluids are with equal ranges,so \"\n",
+ "t1=t2-(T1-T2);# F\n",
+ "print\"\\t t1 is : F \",t1\n",
+ "t1=100.;\n",
+ "#solution\n",
+ "\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \",S\n",
+ "print\"\\t FT is 0.925 \" # from fig 18\n",
+ "print\"\\t considering 0F approach \"\n",
+ "T1=300; #F\n",
+ "T2=200; #F\n",
+ "t2=T2-0; # formula for approach,f\n",
+ "print\"\\t t2 is : F \",t2\n",
+ "print\"\\t fluids are with equal ranges,so \"\n",
+ "t1=t2-(T1-T2); # F\n",
+ "print\"\\t t1 is : F \",t1\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \",S\n",
+ "print\"\\t FT is 0.80 \" # from fig 18\n",
+ "print\"\\t considering 20F cross \"\n",
+ "T1=280; #F\n",
+ "T2=180; #F\n",
+ "t2=T2+20; # formula for approach,f\n",
+ "print\"\\t t2 is : F \",t2\n",
+ "print\"\\t fluids are with equal ranges,so \\n\"\n",
+ "t1=t2-(T1-T2); # F\n",
+ "print\"\\t t1 is : F \",t1\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \",S\n",
+ "print\"\\t FT is 0.64 \" # from fig 18\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.3 pgno:151"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 7.3 \n",
+ "\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t 1.for heat balance \n",
+ "\t for kerosene \n",
+ "\t total heat required for kerosene is : Btu/hr 5034810.0\n",
+ "\t for crude oil \n",
+ "\t total heat required for mid continent crude is : Btu/hr 5110700.0\n",
+ "\t delt1 is : F 100.0\n",
+ "\t delt2 is : F 220.0\n",
+ "\t LMTD is : F 152.195928445\n",
+ "\t R is : 2.71428571429\n",
+ "\t S is : 0.241379310345\n",
+ "\t FT is 0.905 \n",
+ "\t delt is : F 137.737315243\n",
+ "\t ratio of two local temperature difference is : 0.454545454545\n",
+ "\t caloric temperature of hot fluid is : F 279.8\n",
+ "\t caloric temperature of cold fluid is : F 129.4\n",
+ "\t hot fluid:shell side,kerosene \n",
+ "\t flow area is : ft**2 0.147569444444\n",
+ "\t mAss velocity is : lb/(hr)*(ft**2) 296809.411765\n",
+ "\t reynolds number is : 25296.2566845\n",
+ "\t Pr is : 1.0\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) 86.2363636364\n",
+ "\t cold fluid:inner tube side,crude oil \n",
+ "\n",
+ "\t flow area is : ft**2 0.141267361111\n",
+ "\t mAss velocity is : lb/(hr)*(ft**2) 1054737.61829\n",
+ "\t reynolds number is : 8172.03733177\n",
+ "\t Pr is : 1.0\n",
+ "\t Hi is : Btu/(hr)*(ft**2)*(F) 35.362962963\n",
+ "\t Correct Hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) 28.644\n",
+ "\t phyt is : 1.1303932977\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) 32.3789856193\n",
+ "\t tw is : F 242.299617309\n",
+ "\t phys is : 0.953986161765\n",
+ "\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) 82.26829755\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) 23.2344278003\n",
+ "\t total surface area is : ft**2 661.8304\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) 56.0637396161\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu -0.0252027385623\n",
+ "\t pressure drop for annulus \n",
+ "\t number of crosses are : 38\n",
+ "\t delPs is : psi 3.45911725247\n",
+ "\t allowable delPa is 10 psi \n",
+ "\t pressure drop for inner pipe \n",
+ "\t delPt is : psi 6.13806896405\n",
+ "\t delPr is : psi 2.89156626506\n",
+ "\t delPT is : psi 9.03\n",
+ "\t allowable delPs is 10 psi \n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 7.3 \\n\"\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "T1=390.; # inlet hot fluid,F\n",
+ "T2=200.; # outlet hot fluid,F\n",
+ "t1=100.; # inlet cold fluid,F\n",
+ "t2=170.; # outlet cold fluid,F\n",
+ "W=43800; # lb/hr\n",
+ "w=149000; # lb/hr\n",
+ "#solution\n",
+ "from math import log\n",
+ "print\"\\t 1.for heat balance \"\n",
+ "print\"\\t for kerosene \"\n",
+ "c=0.605; # Btu/(lb)*(F)\n",
+ "Q1=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for kerosene is : Btu/hr \",Q1 # calculation mistake in problem\n",
+ "print\"\\t for crude oil \"\n",
+ "c=0.49; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for mid continent crude is : Btu/hr \",Q # calculation mistake in problem\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \",S\n",
+ "print\"\\t FT is 0.905 \" # from fig 18\n",
+ "delt=(0.905*LMTD); # F\n",
+ "print\"\\t delt is : F \",delt\n",
+ "X=((delt1)/(delt2));\n",
+ "print\"\\t ratio of two local temperature difference is : \",X \n",
+ "Fc=0.42; # from fig.17\n",
+ "Kc=0.20; # crude oil controlling \n",
+ "Tc=((T2)+((Fc)*(T1-T2))); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \",Tc\n",
+ "tc=((t1)+((Fc)*(t2-t1))); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \",tc\n",
+ "print\"\\t hot fluid:shell side,kerosene \"\n",
+ "ID=21.25; # in\n",
+ "C=0.25; # clearance\n",
+ "B=5; # baffle spacing,in\n",
+ "PT=1.25;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,ft**2\n",
+ "print\"\\t flow area is : ft**2 \",As\n",
+ "Gs=(W/As); # mAss velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mAss velocity is : lb/(hr)*(ft**2) \",Gs\n",
+ "mu1=0.40*2.42; # at 280F,lb/(ft)*(hr), from fig.14\n",
+ "De=0.99/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \",Res\n",
+ "jH=93; # from fig.28\n",
+ "c=0.59; # Btu/(lb)*(F),at 280F,from fig.4\n",
+ "k=0.0765; # Btu/(hr)*(ft**2)*(F/ft), from fig.1\n",
+ "Pr=((c)*(mu1)/k)**(1/3); # prandelt number raised to power 1/3\n",
+ "print\"\\t Pr is : \",Pr\n",
+ "Ho=((jH)*(k/De)*(Pr)); # H0=(h0/phya),using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \",Ho\n",
+ "print\"\\t cold fluid:inner tube side,crude oil \\n\"\n",
+ "D=0.0675; # ft\n",
+ "Nt=158;\n",
+ "n=4; # number of pAsses\n",
+ "L=16; #ft\n",
+ "at1=0.515; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \",at\n",
+ "Gt=(w/(at)); # mAss velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mAss velocity is : lb/(hr)*(ft**2) \",Gt\n",
+ "mu2=3.6*2.42; # at 129F,lb/(ft)*(hr)\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \",Ret\n",
+ "jH=31; # from fig.24\n",
+ "c=0.49; # Btu/(lb)*(F),at 304F,from fig.4\n",
+ "k=0.077; # Btu/(hr)*(ft**2)*(F/ft), from fig.1\n",
+ "Pr=((c)*(mu2)/k)**(1/3); # prandelt number raised to power 1/3\n",
+ "print\"\\t Pr is : \",Pr\n",
+ "Hi=((jH)*(k/D)*(Pr)*(1**0.14)); #Hi=(hi/phyp),using eq.6.15a,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t Hi is : Btu/(hr)*(ft**2)*(F) \",Hi\n",
+ "ID=0.81; # ft\n",
+ "OD=1; #ft\n",
+ "Hio=((Hi)*(ID/OD)); #Hio=(hio/phyp), using eq.6.5\n",
+ "print\"\\t Correct Hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \",Hio\n",
+ "muw=1.5*2.42; # lb/(ft)*(hr), from fig.14\n",
+ "phyt=(mu2/muw)**0.14;\n",
+ "print\"\\t phyt is : \",phyt # from fig.24\n",
+ "hio=(Hio)*(phyt); # from eq.6.37\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \",hio\n",
+ "tw=(tc)+(((Ho)/(Hio+Ho))*(Tc-tc)); # from eq.5.31\n",
+ "print\"\\t tw is : F \",tw\n",
+ "muw=0.56*2.42; # lb/(ft)*(hr), from fig.14\n",
+ "phys=(mu1/muw)**0.14;\n",
+ "print\"\\t phys is : \",phys # from fig.24\n",
+ "ho=(Ho)*(phys); # from eq.6.36\n",
+ "print\"\\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \",ho\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \",Uc\n",
+ "A2=0.2618; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \",A\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \",UD\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \",Rd\n",
+ "print\"\\t pressure drop for annulus \"\n",
+ "f=0.00175; # friction factor for reynolds number 25300, using fig.29\n",
+ "s=0.73; # for reynolds number 25300,using fig.6\n",
+ "Ds=21.25/12; # ft\n",
+ "N=(12*L/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are :\",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \",delPs\n",
+ "print\"\\t allowable delPa is 10 psi \"\n",
+ "print\"\\t pressure drop for inner pipe \"\n",
+ "f=0.000285; # friction factor for reynolds number 8220, using fig.26\n",
+ "s=0.83;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \",delPt\n",
+ "X1=0.15; # X1=((V**2)/(2*g)), for Gt 1060000,using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \",delPr\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \",round(delPT,2)\n",
+ "print\"\\t allowable delPs is 10 psi \"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.4 pgno:155"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 7.4 \n",
+ "\t approximate values are mentioned in the book \n",
+ "\t 1.for heat balance \n",
+ "\t for distilled water \n",
+ "\t total heat required for distilled water is : Btu/hr 1400000.0\n",
+ "\t for raw water \n",
+ "\t total heat required for raw water is : Btu/hr 1400000.0\n",
+ "\t delt1 is : F 10.0\n",
+ "\t delt2 is : F 13.0\n",
+ "\t LMTD is : F 11.4344840601\n",
+ "\t R is : 1.6\n",
+ "\t S is : 0.277777777778\n",
+ "\t FT is 0.945 \n",
+ "\t delt is : F 10.8055874368\n",
+ "\t ratio of two local temperature difference is : 0.769230769231\n",
+ "\t caloric temperature of hot fluid is : F 89.0\n",
+ "\t caloric temperature of cold fluid is : F 77.5\n",
+ "\t hot fluid:shell side,distilled water \n",
+ "\t flow area is : ft**2 0.254166666667\n",
+ "\t mAss velocity is : lb/(hr)*(ft**2) 688524.590164\n",
+ "\t reynolds number is : 16099.0598149\n",
+ "\t Pr is : 1.0\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) 573.381818182\n",
+ "\t cold fluid:inner tube side,raw water \n",
+ "\t flow area is : ft**2 0.185555555556\n",
+ "\t mAss velocity is : lb/(hr)*(ft**2) 1508982.03593\n",
+ "\t V is fps 6.70658682635\n",
+ "\t reynolds number is : 36712.4177803\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) 1158.3\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) 383.527824238\n",
+ "\t when both film coefficients are high the thermal resistance of the tube metal is not necessarily insignificant As Assumed in the derivation of Eq. (6.38). For a steel 1.8 BWG tube Rm= 0.00017 and for copper Rm= 0.000017 \n",
+ "\t total surface area is : ft**2 502.528\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) 257.821653196\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu 0.00127127741812\n",
+ "\t pressure drop for annulus \n",
+ "\t number of crosses are : 16\n",
+ "\t delPs is : psi 7.65506963359\n",
+ "\t allowable delPs is 10 psi \n",
+ "\t pressure drop for inner pipe \n",
+ "\t delPt is : psi 4.9\n",
+ "\t delPr is : psi 2.6\n",
+ "\t delPT is : psi 7.6\n",
+ "\t allowable delPT is 10 psi \n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 7.4 \"\n",
+ "print\"\\t approximate values are mentioned in the book \"\n",
+ "#given\n",
+ "T1=93.; # inlet hot fluid,F\n",
+ "T2=85.; # outlet hot fluid,F\n",
+ "t1=75.; # inlet cold fluid,F\n",
+ "t2=80.; # outlet cold fluid,F\n",
+ "W=175000.; # lb/hr\n",
+ "w=280000.; # lb/hr\n",
+ "#solution\n",
+ "from math import log\n",
+ "print\"\\t 1.for heat balance \"\n",
+ "print\"\\t for distilled water \"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for distilled water is : Btu/hr \",Q\n",
+ "print\"\\t for raw water \"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for raw water is : Btu/hr \",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \",S\n",
+ "print\"\\t FT is 0.945 \" # from fig 18\n",
+ "delt=(0.945*LMTD); # F\n",
+ "print\"\\t delt is : F \",delt\n",
+ "X=((delt1)/(delt2));\n",
+ "print\"\\t ratio of two local temperature difference is : \",X\n",
+ "Fc=0.42; # from fig.17\n",
+ "Kc=0.20; # crude oil controlling\n",
+ "Tc=((T2)+(T1))/2; # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \",Tc\n",
+ "tc=((t1)+(t2))/2; # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \",tc\n",
+ "print\"\\t hot fluid:shell side,distilled water \"\n",
+ "ID=15.25; # in\n",
+ "C=0.1875; # clearance\n",
+ "B=12; # baffle spacing,in\n",
+ "PT=0.9375;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,ft**2,using eq.7.1\n",
+ "print\"\\t flow area is : ft**2 \",As\n",
+ "Gs=(W/As); # mAss velocity,lb/(hr)*(ft**2),using eq.7.2\n",
+ "print\"\\t mAss velocity is : lb/(hr)*(ft**2) \",Gs\n",
+ "mu1=0.81*2.42; # at 89F,lb/(ft)*(hr), from fig.14\n",
+ "De=0.55/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \",Res\n",
+ "jH=73; # from fig.28\n",
+ "c=1; # Btu/(lb)*(F),at 89F,from fig.table 4\n",
+ "k=0.36; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "Pr=((c)*(mu1)/k)**(1/3); # prandelt number raised to power 1/3\n",
+ "print\"\\t Pr is : \",Pr\n",
+ "ho=((jH)*(k/De)*(Pr)); # using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \",ho\n",
+ "print\"\\t cold fluid:inner tube side,raw water \"\n",
+ "Nt=160;\n",
+ "n=2; # number of pAsses\n",
+ "L=16; #ft\n",
+ "at1=0.334; # flow area, in**2,from table 10\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \",at\n",
+ "Gt=(w/(at)); # mAss velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mAss velocity is : lb/(hr)*(ft**2) \",Gt\n",
+ "V=(Gt/(3600*62.5));\n",
+ "print\"\\t V is fps \",V\n",
+ "mu2=0.92*2.42; # at 77.5F,lb/(ft)*(hr)\n",
+ "D=0.65/12; #ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \",Ret\n",
+ "hi=1350*0.99; #using fig.25,Btu/(hr)*(ft**2)*(F)\n",
+ "ID=0.65; # ft\n",
+ "OD=0.75; #ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \",hio\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \",Uc\n",
+ "print\"\\t when both film coefficients are high the thermal resistance of the tube metal is not necessarily insignificant As Assumed in the derivation of Eq. (6.38). For a steel 1.8 BWG tube Rm= 0.00017 and for copper Rm= 0.000017 \"\n",
+ "A2=0.1963; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \",A\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \",UD\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \",Rd\n",
+ "print\"\\t pressure drop for annulus \"\n",
+ "f=0.0019; # friction factor for reynolds number 16200, using fig.29\n",
+ "s=1; # for reynolds number 25300,using fig.6\n",
+ "Ds=15.25/12; # ft\n",
+ "phys=1;\n",
+ "N=(12*L/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \",delPs\n",
+ "print\"\\t allowable delPs is 10 psi \"\n",
+ "print\"\\t pressure drop for inner pipe \"\n",
+ "f=0.00019; # friction factor for reynolds number 36400, using fig.26\n",
+ "s=1;\n",
+ "phyt=1;\n",
+ "D=0.054; # ft\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \",round(delPt,1)\n",
+ "X1=0.33; # X1=((V**2)/(2*g)), for Gt 1060000,using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \",round(delPr,1)\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \",round(delPT,1)\n",
+ "print\"\\t allowable delPT is 10 psi \"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Exxample 7.5 pgno:159"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 7.5 \n",
+ "\t approximate values are mentioned in the book \n",
+ "\t delt1 is : F 65.0\n",
+ "\t For annual charges assume 20 per cent repair and maintenanc.e and 10 per cent depreciation \n",
+ "\n",
+ "\t X is : 0.120481927711\n",
+ "\t Y is : 0.384615384615\n",
+ "\t delt2 is : F 62.4\n",
+ "\t t2 is : F 112.6\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 7.5 \"\n",
+ "print\"\\t approximate values are mentioned in the book \"\n",
+ "#given\n",
+ "T1=175.; # inlet hot fluid,F\n",
+ "T2=150.; # outlet hot fluid,F\n",
+ "t1=85.; # inlet cold fluid,F\n",
+ "#solution\n",
+ "delt1=T2-t1; #F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "U=15; # assumption,Btu/(hr)*(ft^2)*(F)\n",
+ "theta=8000; # operating hours,hr\n",
+ "CW=(0.01/8300); # water cost,$/lb\n",
+ "print\"\\t For annual charges assume 20 per cent repair and maintenanc.e and 10 per cent depreciation \\n\"\n",
+ "CF=(0.3*4); # annual fixed charges/ft^2\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "X=((U)*(theta)*(CW)/(CF*c));\n",
+ "print\"\\t X is : \",X\n",
+ "Y=((T1-T2)/delt1);\n",
+ "print\"\\t Y is : \",Y\n",
+ "A=0.96; # A=(delt2/delt1), from fig 7.24\n",
+ "delt2=0.96*delt1;\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "t2=T1-delt2; # F\n",
+ "print\"\\t t2 is : F \",t2\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.6 pgno:161"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 7.6 \n",
+ "\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t 1.for heat balance \n",
+ "\n",
+ "\t for solution \n",
+ "\n",
+ "\t total heat required for solution is : Btu/hr 915667.2\n",
+ "\t for water \n",
+ "\n",
+ "\t total heat required for water is : Btu/hr 915200.0\n",
+ "\t delt1 is : F 22.0\n",
+ "\t delt2 is : F 60.0\n",
+ "\t LMTD is : F 37.8749328485\n",
+ "\t R is : 2.72727272727\n",
+ "\t S is : 0.268292682927\n",
+ "\t FT is 0.81 \n",
+ "\t delt is : F 30.6786956073\n",
+ "\t caloric temperature of hot fluid is : F 120.0\n",
+ "\t caloric temperature of cold fluid is : F 79.0\n",
+ "\t hot fluid:shell side,phosphate solution \n",
+ "\t flow area is : ft**2 0.0347916666667\n",
+ "\t mAss velocity is : lb/(hr)*(ft**2) 579449.101796\n",
+ "\t reynolds number is : 15796.5061612\n",
+ "\t Pr is : 1.0\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) 295.957894737\n",
+ "\t cold fluid:inner tube side,raw water \n",
+ "\t flow area is : ft**2 0.0545277777778\n",
+ "\t mAss velocity is : lb/(hr)*(ft**2) 762913.907285\n",
+ "\t V is fps 3.39072847682\n",
+ "\t reynolds number is : 17899.0185011\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) 661.333333333\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) 204.459014471\n",
+ "\t total surface area is : ft**2 163.3216\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) 182.656652912\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu 0.000583796892885\n",
+ "\t pressure drop for annulus \n",
+ "\t number of crosses are : 96\n",
+ "\t delPs is : psi 9.51887629626\n",
+ "\t allowable delPs is 10 psi \n",
+ "\t pressure drop for inner pipe \n",
+ "\t delPt is : psi 1.58733222032\n",
+ "\t delPr is : psi 0.6\n",
+ "\t delPT is : psi 2.2\n",
+ "\t allowable delPT is 10 psi \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 7.6 \\n\"\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "T1=150.; # inlet hot fluid,F\n",
+ "T2=90.; # outlet hot fluid,F\n",
+ "t1=68.; # inlet cold fluid,F\n",
+ "t2=90.; # outlet cold fluid,F\n",
+ "W=20160.; # lb/hr\n",
+ "w=41600.; # lb/hr\n",
+ "#solution\n",
+ "from math import log\n",
+ "print\"\\t 1.for heat balance \\n\"\n",
+ "print\"\\t for solution \\n\"\n",
+ "c=(0.3*0.19)+(0.7*1); # Btu/(lb)*(F), bcoz of 30 percent of solution\n",
+ "Q1=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for solution is : Btu/hr \",Q1\n",
+ "print\"\\t for water \\n\"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \",S\n",
+ "print\"\\t FT is 0.81 \" # from fig 18\n",
+ "delt=(0.81*LMTD); # F\n",
+ "print\"\\t delt is : F \",delt\n",
+ "Tc=((T2)+(T1))/2; # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F\",Tc\n",
+ "tc=((t1)+(t2))/2; # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \",tc\n",
+ "print\"\\t hot fluid:shell side,phosphate solution \"\n",
+ "ID=10.02; # in\n",
+ "C=0.25; # clearance\n",
+ "B=2; # baffle spacing,in\n",
+ "PT=1;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,ft**2,using eq.7.1\n",
+ "print\"\\t flow area is : ft**2 \",As\n",
+ "Gs=(W/As); # mAss velocity,lb/(hr)*(ft**2),using eq.7.2\n",
+ "print\"\\t mAss velocity is : lb/(hr)*(ft**2) \",Gs\n",
+ "mu1=1.20*2.42; # at 120F,lb/(ft)*(hr), from fig.14\n",
+ "De=0.95/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \",Res\n",
+ "jH=71; # from fig.28\n",
+ "c=1; # Btu/(lb)*(F),at 120F,from fig.table 4\n",
+ "k=0.33; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "Pr=((0.757)*(mu1)/k)**(1/3); # prandelt number raised to power 1/3\n",
+ "print\"\\t Pr is : \",Pr\n",
+ "ho=((jH)*(k/De)*(Pr)); # using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \",ho\n",
+ "print\"\\t cold fluid:inner tube side,raw water \"\n",
+ "Nt=52;\n",
+ "n=2; # number of pAsses\n",
+ "L=16; #ft\n",
+ "at1=0.302; # flow area, in**2,from table 10\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \",at\n",
+ "Gt=(w/(at)); # mAss velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mAss velocity is : lb/(hr)*(ft**2) \",Gt\n",
+ "V=(Gt/(3600*62.5));\n",
+ "print\"\\t V is fps \",V\n",
+ "mu2=0.91*2.42; # at 79F,lb/(ft)*(hr),from table 14\n",
+ "D=(0.62/12); # from table 10\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \",Ret\n",
+ "hi=800*1; #using fig.25,Btu/(hr)*(ft**2)*(F)\n",
+ "ID=0.62; # ft\n",
+ "OD=0.75; #ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \",hio\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \",Uc\n",
+ "A2=0.1963; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \",A\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \",UD\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \",Rd\n",
+ "print\"\\t pressure drop for annulus \"\n",
+ "f=0.0019; # friction factor for reynolds number 15750, using fig.29\n",
+ "s=1.3; # for reynolds number 25300,using fig.6\n",
+ "Ds=10.02/12; # ft\n",
+ "phys=1;\n",
+ "N=(12*L/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \",delPs\n",
+ "print\"\\t allowable delPs is 10 psi \"\n",
+ "print\"\\t pressure drop for inner pipe \"\n",
+ "f=0.00023; # friction factor for reynolds number 17900, using fig.26\n",
+ "s=1;\n",
+ "phyt=1;\n",
+ "D=0.0517; # ft\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \",delPt\n",
+ "X1=0.08; # X1=((V**2)/(2*g)), for Gt 1060000,using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \",round(delPr,1)\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \",round(delPT,1)\n",
+ "print\"\\t allowable delPT is 10 psi \\n\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.7 pgno:166"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 7.7 \n",
+ "\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t X is : 1050.97060273\n",
+ "\t coefficient of t**2 is : 1\n",
+ "\t coefficient of t is : -556\n",
+ "\t constant term is : 73733.0293973\n",
+ "\t t is : [ 0.00457855 0.00296217]\n",
+ "\t t cannot be greater than 328F t is 218F \n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 7.7 \\n\"\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "U=50; # Btu/(hr)*(ft**2)*(F)\n",
+ "TP=328; # F\n",
+ "TE=228; # F\n",
+ "#solution\n",
+ "import numpy\n",
+ "\n",
+ "CP=(0.30/(888.8*1000));\n",
+ "CE=(0.05/(960*1000));\n",
+ "CF=1.20;\n",
+ "theta=8000; # annual hours\n",
+ "X=((CF*(TP-TE))/((CP-CE)*U*theta)); # from eq 7.53\n",
+ "print\"\\t X is : \",X\n",
+ "a=(1); # coefficient of t**2\n",
+ "b=(-556); # coefficient of t\n",
+ "c=(74784-X); # constant\n",
+ "print\"\\t coefficient of t**2 is : \",a\n",
+ "print\"\\t coefficient of t is : \",b\n",
+ "print\"\\t constant term is : \",c\n",
+ "P=numpy.array([c, b, a])\n",
+ "t=numpy.roots(P)\n",
+ "print\"\\t t is :\",t\n",
+ "print\"\\t t cannot be greater than 328F t is 218F \"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.8 pgno:167"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 7.8 \n",
+ "\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "ascii\n",
+ "\t 1.for heat balance \n",
+ "\n",
+ "\t for solution \n",
+ "\n",
+ "\t total heat required for solution is : Btu/hr 3784000.0\n",
+ "\t for steam \n",
+ "\n",
+ "\t total heat required for steam is : Btu/hr 3792395.0\n",
+ "\t delt1 is : F 128.0\n",
+ "\t delt2 is : F 106.0\n",
+ "\t LMTD is : F 116.654454302\n",
+ "\t R is : 0.0\n",
+ "\t delt is : F 116.654454302\n",
+ "\t hot fluid:tube side,steam \n",
+ "\t flow area is : ft**2 0.0796944444444\n",
+ "\t mAss velocity is : lb/(hr)*(ft**2) 49564.3081213\n",
+ "\t reynolds number is : 82671.1836992\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) 1500\n",
+ "\t cold fluid:shell side,sugar solution \n",
+ "\n",
+ "\t flow area is : ft**2 0.551953125\n",
+ "\t mAss velocity is : lb/(hr)*(ft**2) 362349.610757\n",
+ "\t De is : ft 0.148026315789\n",
+ "\t reynolds number is : 17049.3572499\n",
+ "\t Pr is : 1.0\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) 138.3504\n",
+ "\t phys is : 1.13996690865\n",
+ "\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) 157.714877798\n",
+ "\t tw is : F 218.119942108\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) 142.70989533\n",
+ "\t total surface area is : ft**2 238.7008\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) 136.194122026\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu 0.000335238210724\n",
+ "\t pressure drop for inner pipe \n",
+ "\n",
+ "\t delPt is : psi 2.8\n",
+ "\t pressure drop for annulus \n",
+ "\n",
+ "\t De1 is : ft 0.122\n",
+ "\t Res1 is : 14084.0\n",
+ "\t delPs is : psi 0.07\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 7.8 \\n\"\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "T1=228.; # inlet hot fluid,F\n",
+ "T2=228.; # outlet hot fluid,F\n",
+ "t1=100.; # inlet cold fluid,F\n",
+ "t2=122.; # outlet cold fluid,F\n",
+ "W=200000.; # lb/hr\n",
+ "w=3950.; # lb/hr\n",
+ "#solution\n",
+ "import sys\n",
+ "print sys.getdefaultencoding()\n",
+ "from math import log\n",
+ "print\"\\t 1.for heat balance \\n\"\n",
+ "print\"\\t for solution \\n\"\n",
+ "c=(0.2*0.30)+(0.8*1); # bcoz of 20 percent solution,Btu/(lb)*(F)\n",
+ "Q1=((W)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for solution is : Btu/hr \",Q1\n",
+ "print\"\\t for steam \\n\"\n",
+ "l=960.1; # latent heat of condensation,Btu/(lb)\n",
+ "Q=((w)*(l)); # Btu/hr\n",
+ "print\"\\t total heat required for steam is : Btu/hr \",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \",R\n",
+ "delt=(LMTD); # when R=0,F\n",
+ "print\"\\t delt is : F \",delt\n",
+ "\n",
+ "ta=111; #F\n",
+ "Ta=228; #f\n",
+ "print\"\\t hot fluid:tube side,steam \"\n",
+ "Nt=76;\n",
+ "n=2; # number of pAsses\n",
+ "L=16; #ft\n",
+ "at1=0.302; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \",at\n",
+ "Gt=(w/(at)); # mAss velocity,lb/(hr)*(ft**2)b\n",
+ "print\"\\t mAss velocity is : lb/(hr)*(ft**2) \",Gt\n",
+ "mu2=0.0128*2.42; # at 228F,lb/(ft)*(hr)\n",
+ "D=(0.62/12); # from table 10,ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \",Ret\n",
+ "hio=1500; # for condensation of steam\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \",hio\n",
+ "print\"\\t cold fluid:shell side,sugar solution \\n\"\n",
+ "ID=12; # in\n",
+ "d=0.75/12; # diameter of tube,ft\n",
+ "Nt=76; # number of tubes\n",
+ "As=((3.14*(12**2)/4)-(76*3.14*(0.75**2)/4))/144; # flow area,ft**2\n",
+ "print\"\\t flow area is : ft**2 \",As\n",
+ "Gs=(W/As); # mAss velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mAss velocity is : lb/(hr)*(ft**2) \",Gs\n",
+ "mu1=1.30*2.42; # at 111F,lb/(ft)*(hr), from fig.14\n",
+ "De=((4*As)/(Nt*3.14*d)); # from eq.6.3,ft\n",
+ "print\"\\t De is : ft \",De\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \",Res\n",
+ "jH=61.5; # from fig.24, tube side data\n",
+ "c=0.86; # Btu/(lb)*(F),at 111F,from fig.4\n",
+ "k=0.333; # Btu/(hr)*(ft**2)*(F/ft)\n",
+ "Pr=((c)*(mu1)/k)**(1/3); # prandelt number raised to power 1/3\n",
+ "print\"\\t Pr is :\",Pr\n",
+ "Ho=((jH)*(k/De)*(Pr)); # H0=(h0/phya),using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \",Ho\n",
+ "muw=0.51*2.42; # at 210F,lb/(ft)*(hr), from fig.14\n",
+ "phys=(mu1/muw)**0.14;\n",
+ "print\"\\t phys is : \",phys # from fig.24\n",
+ "ho=(Ho)*(phys); # from eq.6.36\n",
+ "print\"\\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \",ho\n",
+ "tw=(ta)+(((hio)/(hio+Ho))*(Ta-ta)); # from eq.5.31\n",
+ "print\"\\t tw is : F \",tw\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \",Uc\n",
+ "A2=0.1963; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \",A\n",
+ "UD=((Q)/((A)*(LMTD)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \",UD\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \",Rd\n",
+ "print\"\\t pressure drop for inner pipe \\n\"\n",
+ "f=0.000155; # friction factor for reynolds number 82500, using fig.26\n",
+ "s=0.0008;\n",
+ "phyt=1;\n",
+ "D=0.0517; \n",
+ "delPt=((f*(Gt**2)*(L)*(2))/(5.22*(10**10)*(D)*(s)*(phyt)))/2; # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \",round(delPt,1)\n",
+ "print\"\\t pressure drop for annulus \\n\"\n",
+ "De1=((4*As)/((Nt*3.14*d)+(3.14*1))); # from eq.6.4,ft\n",
+ "print\"\\t De1 is : ft\",round(De1,3)\n",
+ "Res1=(De1*Gs/mu1); # from eq 7.3\n",
+ "print\"\\t Res1 is : \",round(Res1)\n",
+ "f=0.00025; # friction factor, using fig.26\n",
+ "s=1.08; # for reynolds number 25300,using fig.6\n",
+ "delPs=((f*(Gs**2)*(L)*(1))/(5.22*(10**10)*(De1)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \",round(delPs,2)\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 7.9 pgno:170"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 7.9 \n",
+ "\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t X is : 0.628360498562\n",
+ "\t R is : 2.77815829528\n",
+ "\t t2 is : F 176.85\n",
+ "\t T2 is : F 176.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 7.9 \\n\"\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "T1=390; # F\n",
+ "t1=100; # F\n",
+ "U=69.3; # Btu/(hr)*(ft^2)*(F)\n",
+ "A=662; # ft^2\n",
+ "W=43800; # lb/hr\n",
+ "w=149000; # lb/hr\n",
+ "C=0.60; # Btu/(lb)*(F)\n",
+ "c=0.49; # Btu/(lb)*(F)\n",
+ "#solution\n",
+ "X=((U*A)/(w*c));\n",
+ "print\"\\t X is : \",X\n",
+ "R=((w*c)/(W*C));\n",
+ "print\"\\t R is : \",R\n",
+ "S=0.265; # from fig 7.25, by comparing X an R\n",
+ "t2=(t1)+((0.265)*(T1-t1)); # S=((t2-t1)/(T1-t1))\n",
+ "print\"\\t t2 is : F \",t2\n",
+ "T2=((T1)-((R)*(t2-t1))); # R=((T1-T2)/(t2-t1))\n",
+ "print\"\\t T2 is : F \",round(T2)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_8_flow_arrangements_for_increased_heat_recovery.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_8_flow_arrangements_for_increased_heat_recovery.ipynb
new file mode 100755
index 00000000..3d3964a6
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_8_flow_arrangements_for_increased_heat_recovery.ipynb
@@ -0,0 +1,432 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 8 : Flow Arrangements for Incerased Heat Recovery"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8.1 pgno:181"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 8.1 \n",
+ "\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t 1.for heat balance \n",
+ "\n",
+ "\t for oil \n",
+ "\n",
+ "\t total heat required for oil is : Btu/hr 6974256.0\n",
+ "\t for water \n",
+ "\n",
+ "\t total heat required for water is : Btu/hr 6990000.0\n",
+ "\t delt1 is : F 10.0\n",
+ "\t delt2 is : F 238.0\n",
+ "\t LMTD is : F 71.9314248044\n",
+ "\t R is : 8.6\n",
+ "\t S is : 0.111940298507\n",
+ "\t FT is 0.93 \n",
+ "\t delt is : F 66.8962250681\n",
+ "\t ratio of two local temperature difference is : %.3f \n",
+ "0.0420168067227\n",
+ "\t caloric temperature of hot fluid is : F 164.5\n",
+ "\t caloric temperature of cold fluid is : F 97.5\n",
+ "\t hot fluid:shell side,oil \n",
+ "\n",
+ "\t flow area is : ft**2 0.170138888889\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) 291526.530612\n",
+ "\t reynolds number is : 8873.57540419\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \n",
+ "127.272727273\n",
+ "\t cold fluid:inner tube side,water \n",
+ "\n",
+ "\t flow area is :f ft**2 0.239085648148\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) 974546.158687\n",
+ "\t V is : fps 4.33131626083\n",
+ "\t reynolds number is : 34937.8788163\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) 969.6\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) 736.896\n",
+ "\t tw is : F \n",
+ "107.367601613\n",
+ "\t phys is : 0.925306637672\n",
+ "\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) 117.76629934\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) 101.538952854\n",
+ "\t total surface area is : ft**2 1426.2864\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) 73.155514686\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu 0.00382107226455\n",
+ "\t pressure drop for annulus \n",
+ "\n",
+ "\t number of crosses are : 20\n",
+ "\t delPs is : psi 4.47363588933\n",
+ "\t allowable delPs is 10 psi \n",
+ "\n",
+ "\t pressure drop for inner pipe \n",
+ "\n",
+ "\t delPt is : psi 4.0\n",
+ "\t delPr is : psi 3.1\n",
+ "\t delPT is : psi 7.2\n",
+ "\t allowable delPT is 10 psi \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 8.1 \\n\"\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "T1=358.; # inlet hot fluid,F\n",
+ "T2=100.; # outlet hot fluid,F\n",
+ "t1=90.; # inlet cold fluid,F\n",
+ "t2=120.; # outlet cold fluid,F\n",
+ "W=49600.; # lb/hr\n",
+ "w=233000.; # lb/hr\n",
+ "#solution\n",
+ "from math import log\n",
+ "print\"\\t 1.for heat balance \\n\"\n",
+ "print\"\\t for oil \\n\"\n",
+ "c=0.545; # Btu/(lb)*(F)\n",
+ "Q=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for oil is : Btu/hr \",Q\n",
+ "print\"\\t for water \\n\"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \",delt1\n",
+ "print\"\\t delt2 is : F \",delt2\n",
+ "LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \",S\n",
+ "print\"\\t FT is 0.93 \" # from fig 19 for 2-4 exchanger\n",
+ "delt=(0.93*LMTD); # F\n",
+ "print\"\\t delt is : F \",delt\n",
+ "X=((delt1)/(delt2));\n",
+ "print\"\\t ratio of two local temperature difference is : %.3f \\n\",X\n",
+ "Fc=0.25; # from fig.17\n",
+ "Kc=0.47; # crude oil controlling\n",
+ "Tc=((T2)+((Fc)*(T1-T2))); # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \",Tc\n",
+ "tc=((t1)+((Fc)*(t2-t1))); # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \",tc\n",
+ "print\"\\t hot fluid:shell side,oil \\n\"\n",
+ "ID=35; # in\n",
+ "C=0.25; # clearance\n",
+ "B=7; # baffle spacing,in\n",
+ "PT=1.25;\n",
+ "As=((ID*C*B)/(144*PT))/2; # flow area,ft**2,from eq 7.1\n",
+ "print\"\\t flow area is : ft**2 \",As\n",
+ "Gs=(W/As); # mass velocity,lb/(hr)*(ft**2),from eq 7.2\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \",Gs\n",
+ "mu1=1.12*2.42; # at 165F,lb/(ft)*(hr), from fig.14\n",
+ "De=0.99/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \",Res\n",
+ "jH=52.5; # from fig.28\n",
+ "Z=0.2; # Z=(k)*(Pr*(1/3)) prandelt number\n",
+ "Ho=((jH)*(1/De)*(Z)); # H0=(h0/phys),using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\n\",Ho\n",
+ "print\"\\t cold fluid:inner tube side,water \\n\"\n",
+ "Nt=454;\n",
+ "n=6; # number of passes\n",
+ "L=12; #ft\n",
+ "at1=0.455; # flow area, in**2\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is :f ft**2 \",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2)\",Gt\n",
+ "V=(Gt/(3600*62.5)); # fps\n",
+ "print\"\\t V is : fps \",V\n",
+ "mu2=0.73*2.42; # at 98F,lb/(ft)*(hr),from fig 14\n",
+ "D=(0.76/12); # ft,from table 10\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \",Ret\n",
+ "hi=1010*0.96; # using fig 25,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \",hi\n",
+ "ID=0.76; # ft\n",
+ "OD=1; #ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \",hio\n",
+ "tw=(tc)+(((Ho)/(hio+Ho))*(Tc-tc)); # from eq.5.31\n",
+ "print\"\\t tw is : F \\n\",tw\n",
+ "muw=1.95*2.42; # lb/(ft)*(hr), from fig.14\n",
+ "phys=(mu1/muw)**0.14;\n",
+ "print\"\\t phys is : \",phys # from fig.24\n",
+ "ho=(Ho)*(phys); # from eq.6.36\n",
+ "print\"\\t Correct h0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \",ho\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \",Uc\n",
+ "A2=0.2618; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \",A\n",
+ "Q=6980000; # taking rounded value,Btu/hr\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \",UD\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \",Rd\n",
+ "print\"\\t pressure drop for annulus \\n\"\n",
+ "f=0.00215; # friction factor for reynolds number 8900, using fig.29\n",
+ "s=0.82; # for reynolds number 25300,using fig.6\n",
+ "Ds=35/12; # ft\n",
+ "N=(12*L/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(2*N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \",delPs\n",
+ "print\"\\t allowable delPs is 10 psi \\n\"\n",
+ "print\"\\t pressure drop for inner pipe \\n\"\n",
+ "f=0.000195; # friction factor for reynolds number 34900, using fig.26\n",
+ "s=1;\n",
+ "D=0.0633; #ft\n",
+ "phyt=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \",round(delPt)\n",
+ "X1=0.13; # X1=((V**2)/(2*g)), for Gt 1060000,using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \",round(delPr,1)\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \",round(delPT,1)\n",
+ "print\"\\t allowable delPT is 10 psi \\n\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 8.2 pgno:184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 8.2 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for acetone \t\n",
+ "\t total heat required for acetone is : Btu/hr \t5130000.0\n",
+ "\t for acetic acid \t\n",
+ "\t total heat required for acetic acid is : Btu/hr \t5140800.0\n",
+ "\t delt1 is : F \t10\n",
+ "\t delt2 is : F \t100\n",
+ "\t LMTD is : F \t39.0865033713\n",
+ "\t R is : \t2\n",
+ "\t S is : \t0\n",
+ "\t FT is 0.88 \t\n",
+ "\t delt is : F \t34.3961229667\n",
+ "\t caloric temperature of hot fluid is : F \t175\n",
+ "\t caloric temperature of cold fluid is : F \t120\n",
+ "\t hot fluid:shell side,acetone \t\n",
+ "\t flow area is : ft**2 \t0.184461805556\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t325270.588235\n",
+ "\t reynolds number is : \t53203.694701\n",
+ "\t Pr is : \t1.0\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t164.4\n",
+ "\t cold fluid:inner tube side,acetic acid \t\n",
+ "\t flow area is : ft**2 \t0.25125\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t668656.716418\n",
+ "\t reynolds number is : \t15819.782952\n",
+ "\t Pr is : \t1.0\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t112.767123288\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t87.808\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t57.2370234092\n",
+ "\t total surface area is : ft**2 \t2544.048\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t58.6249615773\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t-0.000413628549958\n",
+ "\t pressure drop for annulus \t\n",
+ "\t number of crosses are : \t39\n",
+ "\t delPs is : psi \t10.407463223\n",
+ "\t allowable delPs is 10 psi \t\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t4.0\n",
+ "\t delPr is : psi \t1.4\n",
+ "\t delPT is : psi \t5.2\n",
+ "\t allowable delPT is 10 psi \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 8.2 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "#given\n",
+ "T1=250; # inlet hot fluid,F\n",
+ "T2=100; # outlet hot fluid,F\n",
+ "t1=90; # inlet cold fluid,F\n",
+ "t2=150; # outlet cold fluid,F\n",
+ "W=60000; # lb/hr\n",
+ "w=168000; # lb/hr\n",
+ "#solution\n",
+ "from math import log\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for acetone \\t\"\n",
+ "c=0.57; # Btu/(lb)*(F)\n",
+ "Q=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for acetone is : Btu/hr \\t\",Q # calculation mistake in problem\n",
+ "print\"\\t for acetic acid \\t\"\n",
+ "c=0.51; # Btu/(lb)*(F)\n",
+ "Q1=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for acetic acid is : Btu/hr \\t\",Q1 # calculation mistake in problem\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((1)*(log(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \\t\",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \\t\",S\n",
+ "print\"\\t FT is 0.88 \\t\" # from fig 20,for 3-6 exchanger\n",
+ "delt=(0.88*LMTD); # F\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "Tc=((T2)+(T1))/2; # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2))/2; # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:shell side,acetone \\t\"\n",
+ "ID=21.25; # in\n",
+ "C=0.25; # clearance\n",
+ "B=5; # baffle spacing,in\n",
+ "PT=1;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,ft**2\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(W/As); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=0.20*2.42; # at 175F,lb/(ft)*(hr), from fig.14\n",
+ "De=0.95/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "phys=1;\n",
+ "jH=137; # from fig.28\n",
+ "c=0.63; # Btu/(lb)*(F),at 175F,from fig.2\n",
+ "k=0.095; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "Pr=((c)*(mu1)/k)**(1/3); # prandelt number raised to power 1/3\n",
+ "print\"\\t Pr is : \\t\",Pr\n",
+ "ho=((jH)*(k/De)*(Pr)*1); # using eq.6.15b,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t cold fluid:inner tube side,acetic acid \\t\"\n",
+ "Nt=270;\n",
+ "n=2; # number of passes\n",
+ "L=16; #ft\n",
+ "at1=0.268; # flow area, in**2,from table 10\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "mu2=0.85*2.42; # at 120F,lb/(ft)*(hr)\n",
+ "D=(0.584/12); # ft\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "jH=56; # from fig.24\n",
+ "c=0.51; # Btu/(lb)*(F),at 120F,from fig.2\n",
+ "k=0.098; # Btu/(hr)*(ft**2)*(F/ft), from table 4\n",
+ "phyt=1;\n",
+ "Pr=((c)*(mu2)/k)**(1/3); # prandelt number raised to power 1/3\n",
+ "print\"\\t Pr is : \\t\",Pr\n",
+ "hi=((jH)*(k/D)*(Pr)*(1**0.14)); # using eq.6.15a,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "ID=0.584; # ft\n",
+ "OD=0.75; #ft\n",
+ "hio=((hi)*(ID/OD)); #Hio=(hio/phyp), using eq.6.5\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "A2=0.1963; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=3*(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "f=0.00155; # friction factor for reynolds number 52200, using fig.29\n",
+ "s=0.79; # for reynolds number 25300,using table.6\n",
+ "Ds=21.25/12; # ft\n",
+ "N=(12*L/B)+1; # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "delPs=((f*(Gs**2)*(Ds)*(3*N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",delPs\n",
+ "print\"\\t allowable delPs is 10 psi \\t\"\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.00024; # friction factor for reynolds number 158000, using fig.26\n",
+ "s=1.07;\n",
+ "D=0.0487; # ft\n",
+ "delPt=((f*(Gt**2)*(L)*(n*3))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt)\n",
+ "X1=0.063; # X1=((V**2)/(2*g)), for Gt 1060000,using fig.27\n",
+ "delPr=(3)*((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \\t\",round(delPr,1)\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \\t\",round(delPT,1)\n",
+ "print\"\\t allowable delPT is 10 psi \\t\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Process_Heat_Transfer_by_D._Q._Kern/Chapter_9_Gases.ipynb b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_9_Gases.ipynb
new file mode 100755
index 00000000..52b09ddd
--- /dev/null
+++ b/Process_Heat_Transfer_by_D._Q._Kern/Chapter_9_Gases.ipynb
@@ -0,0 +1,395 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 9: Gases"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.1 pgno:193"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 9.1 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t 1.for heat balance \t\n",
+ "\t for ammonia gas \t\n",
+ "\t total heat required for ammonia gas is : Btu/hr \t784824.0\n",
+ "\t for water \t\n",
+ "\t total heat required for water is : Btu/hr \t785000\n",
+ "\t delt1 is : F \t10\n",
+ "\t delt2 is : F \t150\n",
+ "\t LMTD is : F \t22.4772661868\n",
+ "\t R is : \t15\n",
+ "\t S is : \t0\n",
+ "\t FT is 0.837 \t\n",
+ "\t delt is : F \t18.8134717984\n",
+ "\t caloric temperature of hot fluid is : F \t170\n",
+ "\t caloric temperature of cold fluid is : F \t90\n",
+ "\t hot fluid:shell side,ammonia at 83psia \t\n",
+ "\t flow area is : ft**2 \t0.387706776948\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t25462.5417634\n",
+ "\t reynolds number is : \t40187.0924297\n",
+ "\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \t42.4542545455\n",
+ "\t cold fluid:inner tube side,water \t\n",
+ "\t flow area is : ft**2 \t0.0954236111111\n",
+ "\t mass velocity is : lb/(hr)*(ft**2) \t822647.551124\n",
+ "\t V is : fps \t3.65621133833\n",
+ "\t reynolds number is : \t21418.7950051\n",
+ "\t hi is : Btu/(hr)*(ft**2)*(F) \t900\n",
+ "\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \t744.0\n",
+ "\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \t40.1624954017\n",
+ "\t total surface area is : ft**2 \t571.6256\n",
+ "\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \t72.9943154025\n",
+ "\t actual Rd is : (hr)*(ft**2)*(F)/Btu \t-0.0111991543302\n",
+ "\t pressure drop for annulus \t\n",
+ "\t number of crosses are : \t8\n",
+ "\t rowgas is lb/ft**3 \t0.209\n",
+ "\t s is \t0.003344\n",
+ "\t delPs is : psi \t2.03484815237\n",
+ "\t allowable delPs is 2 psi \t\n",
+ "\t pressure drop for inner pipe \t\n",
+ "\t delPt is : psi \t3.6\n",
+ "\t delPr is : psi \t2.9\n",
+ "\t delPT is : psi \t6.5\n",
+ "\t allowable delPT is 10 psi \t\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 9.1 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "#given\n",
+ "T1=245; # inlet hot fluid,F\n",
+ "T2=95; # outlet hot fluid,F\n",
+ "t1=85; # inlet cold fluid,F\n",
+ "t2=95; # outlet cold fluid,F\n",
+ "W=9872; # lb/hr\n",
+ "w=78500; # lb/hr\n",
+ "#solution\n",
+ "from math import log\n",
+ "print\"\\t 1.for heat balance \\t\"\n",
+ "print\"\\t for ammonia gas \\t\"\n",
+ "c=0.53; # Btu/(lb)*(F)\n",
+ "Q=((W)*(c)*(T1-T2)); # Btu/hr\n",
+ "print\"\\t total heat required for ammonia gas is : Btu/hr \\t\",Q\n",
+ "print\"\\t for water \\t\"\n",
+ "c=1; # Btu/(lb)*(F)\n",
+ "Q=((w)*(c)*(t2-t1)); # Btu/hr\n",
+ "print\"\\t total heat required for water is : Btu/hr \\t\",Q\n",
+ "delt1=T2-t1; #F\n",
+ "delt2=T1-t2; # F\n",
+ "print\"\\t delt1 is : F \\t\",delt1\n",
+ "print\"\\t delt2 is : F \\t\",delt2\n",
+ "LMTD=((delt2-delt1)/((2.3)*(log(delt2/delt1))));\n",
+ "print\"\\t LMTD is : F \\t\",LMTD\n",
+ "R=((T1-T2)/(t2-t1));\n",
+ "print\"\\t R is : \\t\",R\n",
+ "S=((t2-t1)/(T1-t1));\n",
+ "print\"\\t S is : \\t\",S\n",
+ "print\"\\t FT is 0.837 \\t\" # from fig 18\n",
+ "delt=(0.837*LMTD); # F\n",
+ "print\"\\t delt is : F \\t\",delt\n",
+ "Tc=((T2)+(T1))/2; # caloric temperature of hot fluid,F\n",
+ "print\"\\t caloric temperature of hot fluid is : F \\t\",Tc\n",
+ "tc=((t1)+(t2))/2; # caloric temperature of cold fluid,F\n",
+ "print\"\\t caloric temperature of cold fluid is : F \\t\",tc\n",
+ "print\"\\t hot fluid:shell side,ammonia at 83psia \\t\"\n",
+ "ID=23.25; # in\n",
+ "C=0.1875; # clearance\n",
+ "B=12; # baffle spacing,in\n",
+ "PT=0.937;\n",
+ "As=((ID*C*B)/(144*PT)); # flow area,ft**2,from eq 7.1\n",
+ "print\"\\t flow area is : ft**2 \\t\",As\n",
+ "Gs=(W/As); # mass velocity,lb/(hr)*(ft**2),from eq 7.2\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gs\n",
+ "mu1=0.012*2.42; # at 170F,lb/(ft)*(hr), from fig.15\n",
+ "De=0.55/12; # from fig.28,ft\n",
+ "Res=((De)*(Gs)/mu1); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Res\n",
+ "jH=118; # from fig.28\n",
+ "k=0.017; # Btu/(hr)*(ft**2)*(F/ft),from table 5\n",
+ "Z=0.97; # Z=(Pr*(1/3)) prandelt number\n",
+ "ho=((jH)*(k/De)*(Z)*1); # using eq.6.15,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t individual heat transfer coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",ho\n",
+ "print\"\\t cold fluid:inner tube side,water \\t\"\n",
+ "Nt=364;\n",
+ "n=8; # number of passes\n",
+ "L=8; #ft\n",
+ "at1=0.302; # flow area, in**2,from table 10\n",
+ "at=((Nt*at1)/(144*n)); # total area,ft**2,from eq.7.48\n",
+ "print\"\\t flow area is : ft**2 \\t\",at\n",
+ "Gt=(w/(at)); # mass velocity,lb/(hr)*(ft**2)\n",
+ "print\"\\t mass velocity is : lb/(hr)*(ft**2) \\t\",Gt\n",
+ "V=(Gt/(3600*62.5)); # fps\n",
+ "print\"\\t V is : fps \\t\",V\n",
+ "mu2=0.82*2.42; # at 90F,lb/(ft)*(hr),from fig 14\n",
+ "D=(0.62/12); # ft,from table 10\n",
+ "Ret=((D)*(Gt)/mu2); # reynolds number\n",
+ "print\"\\t reynolds number is : \\t\",Ret\n",
+ "hi=900; # using fig 25,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t hi is : Btu/(hr)*(ft**2)*(F) \\t\",hi\n",
+ "ID=0.62; # ft\n",
+ "OD=0.75; #ft\n",
+ "hio=((hi)*(ID/OD)); # using eq.6.5\n",
+ "print\"\\t Correct hi0 to the surface at the OD is : Btu/(hr)*(ft**2)*(F) \\t\",hio\n",
+ "Uc=((hio)*(ho)/(hio+ho)); # clean overall coefficient,Btu/(hr)*(ft**2)*(F)\n",
+ "print\"\\t clean overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",Uc\n",
+ "A2=0.1963; # actual surface supplied for each tube,ft**2,from table 10\n",
+ "A=(Nt*L*A2); # ft**2\n",
+ "print\"\\t total surface area is : ft**2 \\t\",A\n",
+ "UD=((Q)/((A)*(delt)));\n",
+ "print\"\\t actual design overall coefficient is : Btu/(hr)*(ft**2)*(F) \\t\",UD\n",
+ "Rd=((Uc-UD)/((UD)*(Uc))); # (hr)*(ft**2)*(F)/Btu\n",
+ "print\"\\t actual Rd is : (hr)*(ft**2)*(F)/Btu \\t\",Rd\n",
+ "print\"\\t pressure drop for annulus \\t\"\n",
+ "f=0.00162; # friction factor for reynolds number 40200, using fig.29\n",
+ "Ds=23.25/12; # ft\n",
+ "phys=1;\n",
+ "N=(12*L/B); # number of crosses,using eq.7.43\n",
+ "print\"\\t number of crosses are : \\t\",N\n",
+ "rowgas=0.209;\n",
+ "print\"\\t rowgas is lb/ft**3 \\t\",rowgas\n",
+ "s=rowgas/62.5;\n",
+ "print\"\\t s is \\t\",s\n",
+ "delPs=((f*(Gs**2)*(Ds)*(N))/(5.22*(10**10)*(De)*(s)*(phys))); # using eq.7.44,psi\n",
+ "print\"\\t delPs is : psi \\t\",delPs\n",
+ "print\"\\t allowable delPs is 2 psi \\t\"\n",
+ "print\"\\t pressure drop for inner pipe \\t\"\n",
+ "f=0.000225; # friction factor for reynolds number 21400, using fig.26\n",
+ "s=1;\n",
+ "D=0.0517; #ft\n",
+ "phyt=1;\n",
+ "delPt=((f*(Gt**2)*(L)*(n))/(5.22*(10**10)*(D)*(s)*(phyt))); # using eq.7.45,psi\n",
+ "print\"\\t delPt is : psi \\t\",round(delPt,1)\n",
+ "X1=0.090; # X1=((V**2)/(2*g)), for Gt 1060000,using fig.27\n",
+ "delPr=((4*n*X1)/(s)); # using eq.7.46,psi\n",
+ "print\"\\t delPr is : psi \\t\",round(delPr,1)\n",
+ "delPT=delPt+delPr; # using eq.7.47,psi\n",
+ "print\"\\t delPT is : psi \\t\",round(delPT,1)\n",
+ "print\"\\t allowable delPT is 10 psi \\t\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.2 pgno:196"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 9.2 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t The air and water both occupy the same volume at their respective partial pressures \t\n",
+ "\t volume of water entering is : lb \t693.049715558\n",
+ "\t for first stage \t\n",
+ "\t P2 is : psi \t34.251\n",
+ "\t T2absr is : R \t706.727218318\n",
+ "\t T2abs is : F \t247.057218318\n",
+ "\t for intercooler \t\n",
+ "\t final gas volume is : ft**3/hr \t120257.51073\n",
+ "\t water remaining in air is : lb/hr \t297.446229853\n",
+ "\t condensation in inter cooler is : lb/hr \t395.603485705\n",
+ "\t Specific volume of atmospheric air is : ft**3/lb \t14.8\n",
+ "\t air in inlet gas is : lb/hr\t18932.4324324\n",
+ "\t heat load(245 to 95F) \t)\n",
+ "\t sensible heat \t\n",
+ "\t Qair is : Btu/hr \t709966.216216\n",
+ "\t Qwaters is : Btu/hr \t46780.8558001\n",
+ "\t latent heat \t\n",
+ "\t Qwater1 is : Btu/hr \t411467.185481\n",
+ "\t total heat is : Btu/hr \t1168214.2575\n",
+ "\t for second stage \t\n",
+ "\t P3 is : psi \t79.80483\n",
+ "\t final gas volume is : ft**3/hr \t51612.6655492\n",
+ "\t water remaining in air is : lb/hr \t127.659326117\n",
+ "\t condensation in inter cooler is : lb/hr \t169.340673883\n",
+ "\t heat load(245 to 95F) \t)\n",
+ "\t sensible heat \t\n",
+ "\t Qair is : Btu/hr \t709966.0\n",
+ "\t Qwater is : Btu/hr \t19631.0\n",
+ "\t latent heat \t\n",
+ "\t Qwater is : Btu/hr \t176131.0\n",
+ "\t total heat is : Btu/hr 905729.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 9.2 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "#given\n",
+ "V1=4670; # inlet air volume,cfm\n",
+ "Pp=0.8153; # Saturation partial pressure of water at 95F,psi,from table 7\n",
+ "Ps=404.3;# Saturation specific volume of water at 95F,ft**3/lb, from table 7\n",
+ "#solution\n",
+ "print\"\\t The air and water both occupy the same volume at their respective partial pressures \\t\"\n",
+ "Vw1=(V1*60/Ps); # water entering per hr,lb\n",
+ "print\"\\t volume of water entering is : lb \\t\",Vw1\n",
+ "print\"\\t for first stage \\t\"\n",
+ "c=2.33; # compression ratio\n",
+ "P1=14.7; # psi\n",
+ "P2=(P1*c); # (c=(P2/P1)),psi\n",
+ "print\"\\t P2 is : psi \\t\",P2\n",
+ "gama=1.4; # for air\n",
+ "T1abs=95; # F\n",
+ "T2absr=((T1abs+460)*(P2/P1)**((gama-1)/gama));\n",
+ "print\"\\t T2absr is : R \\t\",T2absr\n",
+ "T2abs=(T2absr-459.67); # F\n",
+ "print\"\\t T2abs is : F \\t\",T2abs\n",
+ "print\"\\t for intercooler \\t\"\n",
+ "V2=(V1*60*P1/P2); # ft**3/hr\n",
+ "print\"\\t final gas volume is : ft**3/hr \\t\",V2\n",
+ "Vw2=(V2/Ps); # water remaining in air, lb/hr\n",
+ "print\"\\t water remaining in air is : lb/hr \\t\",Vw2\n",
+ "C=(Vw1-Vw2); # condensation in inter cooler, lb/hr\n",
+ "print\"\\t condensation in inter cooler is : lb/hr \\t\",C\n",
+ "Vs=14.8; # Specific volume of atmospheric air,ft**3/lb\n",
+ "print\"\\t Specific volume of atmospheric air is : ft**3/lb \\t\",Vs\n",
+ "Va=(V1*60/Vs); # air in inlet gas, lb/hr\n",
+ "print\"\\t air in inlet gas is : lb/hr\\t\",Va\n",
+ "print\"\\t heat load(245 to 95F) \\t)\"\n",
+ "print\"\\t sensible heat \\t\"\n",
+ "Qair=((Va)*(0.25)*(245-T1abs)); # Btu/hr\n",
+ "print\"\\t Qair is : Btu/hr \\t\",Qair\n",
+ "Qwaters=(Vw1*0.45*(245-T1abs)); # Btu/hr\n",
+ "print\"\\t Qwaters is : Btu/hr \\t\",Qwaters\n",
+ "print\"\\t latent heat \\t\"\n",
+ "l=1040.1; # latent heat\n",
+ "Qwaterl=(C*l); # Btu/hr\n",
+ "print\"\\t Qwater1 is : Btu/hr \\t\",Qwaterl\n",
+ "Qt1=Qair+Qwaters+Qwaterl;\n",
+ "print\"\\t total heat is : Btu/hr \\t\",Qt1\n",
+ "print\"\\t for second stage \\t\"\n",
+ "c=2.33; # compression ratio\n",
+ "P3=(P2*c); # (c=(P3/P1)),psi\n",
+ "print\"\\t P3 is : psi \\t\",P3\n",
+ "V3=(V1*60*P1/P3); # ft**3/hr\n",
+ "print\"\\t final gas volume is : ft**3/hr \\t\",V3\n",
+ "Vw3=(V3/Ps); # water remaining in air, lb/hr\n",
+ "print\"\\t water remaining in air is : lb/hr \\t\",Vw3\n",
+ "C1=(297-Vw3); # condensation in inter cooler, lb/hr\n",
+ "print\"\\t condensation in inter cooler is : lb/hr \\t\",C1\n",
+ "print\"\\t heat load(245 to 95F) \\t)\"\n",
+ "print\"\\t sensible heat \\t\"\n",
+ "Qair=(Va*0.25*(245-T1abs)); # Btu/hr\n",
+ "print\"\\t Qair is : Btu/hr \\t\",round(Qair)\n",
+ "Qwaters=(Vw2*0.44*(245-T1abs)); # Btu/hr\n",
+ "print\"\\t Qwater is : Btu/hr \\t\",round(Qwaters)\n",
+ "print\"\\t latent heat \\t\"\n",
+ "l=1040.1; # latent heat\n",
+ "Qwaterl=(C1*l); # Btu/hr, calculation mistake in book\n",
+ "print\"\\t Qwater is : Btu/hr \\t\",round(Qwaterl)\n",
+ "Qt1=Qair+Qwaters+Qwaterl;\n",
+ "print\"\\t total heat is : Btu/hr \",round(Qt1)\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.3 pgno:197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t example 9.3 \t\n",
+ "\t approximate values are mentioned in the book \t\n",
+ "\t total number of moles re : \t690.168582375\n",
+ "\t Moles of air is : \t651.724137931\n",
+ "\t Moles of water is : \t38.4444444444\n",
+ "\t after compression \t\n",
+ "\t partial pressure is : psi \t1.91\n",
+ "\t dew point is : F \t124\n"
+ ]
+ }
+ ],
+ "source": [
+ "print\"\\t example 9.3 \\t\"\n",
+ "print\"\\t approximate values are mentioned in the book \\t\"\n",
+ "#given\n",
+ "Va=18900.; # air in inlet gas\n",
+ "Vw1=692.; # water entering\n",
+ "#solution\n",
+ "Ma=(Va/29.); # moles\n",
+ "Mw=(Vw1/18.); # moles\n",
+ "M=(Ma+Mw); # moles\n",
+ "print\"\\t total number of moles re : \\t\",M\n",
+ "print\"\\t Moles of air is : \\t\",Ma\n",
+ "print\"\\t Moles of water is : \\t\",Mw\n",
+ "print\"\\t after compression \\t\"\n",
+ "P=34.2; # pressure,psi\n",
+ "pw=(Mw/M)*(P); # partial pressure\n",
+ "print\"\\t partial pressure is : psi \\t\",round(pw,2)\n",
+ "Td=124; # F, table table 7\n",
+ "print\"\\t dew point is : F \\t\",Td\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/Propagation_Engineering_in_Wireless_Communications/README.txt b/Propagation_Engineering_in_Wireless_Communications/README.txt
new file mode 100755
index 00000000..e43c4cf0
--- /dev/null
+++ b/Propagation_Engineering_in_Wireless_Communications/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: Propagation Engineering in Wireless Communications
+Author: Abdollah Ghasemi
+Publisher: Springer, US
+Year of publication: 2012
+Isbn: 9781461410768
+Edition: 2 \ No newline at end of file
diff --git a/Propagation_Engineering_in_Wireless_Communications/screenshots/Capture2.PNG b/Propagation_Engineering_in_Wireless_Communications/screenshots/Capture2.PNG
new file mode 100755
index 00000000..a17a68be
--- /dev/null
+++ b/Propagation_Engineering_in_Wireless_Communications/screenshots/Capture2.PNG
Binary files differ
diff --git a/Propagation_Engineering_in_Wireless_Communications/screenshots/Capture4.PNG b/Propagation_Engineering_in_Wireless_Communications/screenshots/Capture4.PNG
new file mode 100755
index 00000000..d9c2597d
--- /dev/null
+++ b/Propagation_Engineering_in_Wireless_Communications/screenshots/Capture4.PNG
Binary files differ
diff --git a/Propagation_Engineering_in_Wireless_Communications/screenshots/Untitled1.png b/Propagation_Engineering_in_Wireless_Communications/screenshots/Untitled1.png
new file mode 100755
index 00000000..23b0b29b
--- /dev/null
+++ b/Propagation_Engineering_in_Wireless_Communications/screenshots/Untitled1.png
Binary files differ
diff --git a/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter1_1.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter1_1.ipynb
new file mode 100755
index 00000000..d6586880
--- /dev/null
+++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter1_1.ipynb
@@ -0,0 +1,109 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:210d4209b2bf5bb89dd881d85f3fd691c9eeb52914bb6a1ab12008858853aedb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1 : Introduction to Radiowaves"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.1, page 13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "fo=8387.5 #frequency in MHz\n",
+ "\n",
+ "#Calculation\n",
+ "\n",
+ "#defining a function for 6 MHZ channels with 14 MHz separation\n",
+ "def F(n):\n",
+ " fn=fo-108.5+(14*n);\n",
+ " return (fn)\n",
+ "\n",
+ "def F1(n):\n",
+ " fn=fo+10.5+(14*n);\n",
+ " return (fn)\n",
+ "\n",
+ "#defining a function for 12 MHZ channels with 7 MHz separation\n",
+ "def F2(n):\n",
+ " fn=fo-108.5+(7*n);\n",
+ " return (fn)\n",
+ "\n",
+ "def F3(n):\n",
+ " fn=fo+17.5+(7*n);\n",
+ " return (fn)\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'(1) 6-RF channels with 14 MHz separation'\n",
+ "print' f1 = %d'%F(1)\n",
+ "print' f11 = %d'%F1(1)\n",
+ "print' f2 = %d'%F(2)\n",
+ "print' f21 = %d'%F1(2)\n",
+ "print' f3 = %d'%F(3)\n",
+ "print' f31 = %d'%F1(3)\n",
+ "print'(2) 12-RF channels with 7 MHz separation'\n",
+ "print' f1 = %d'%F2(1)\n",
+ "print' f11 = %d'%F3(1)\n",
+ "print' f2 = %d'%F2(2)\n",
+ "print' f21 = %d'%F3(2)\n",
+ "print' f3 = %d'%F2(3) #wrong value calculated in textbook\n",
+ "print' f31 = %d'%F3(3) #wrong value calculated in textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) 6-RF channels with 14 MHz separation\n",
+ " f1 = 8293\n",
+ " f11 = 8412\n",
+ " f2 = 8307\n",
+ " f21 = 8426\n",
+ " f3 = 8321\n",
+ " f31 = 8440\n",
+ "(2) 12-RF channels with 7 MHz separation\n",
+ " f1 = 8286\n",
+ " f11 = 8412\n",
+ " f2 = 8293\n",
+ " f21 = 8419\n",
+ " f3 = 8300\n",
+ " f31 = 8426\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter2_1.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter2_1.ipynb
new file mode 100755
index 00000000..9b69db10
--- /dev/null
+++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter2_1.ipynb
@@ -0,0 +1,446 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:55fa86de219c4f643fa6676095f34a4af682ba335d02a01747382a5f3a074890"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2 : Basic Principles in Radiowave Propagation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1, page 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "sig=0.005 #sigma\n",
+ "ur=1 #relative permeability\n",
+ "er=12 #relative permittivity\n",
+ "eo=8.85*10**-12 #permittivity of a free space\n",
+ "f1=10*10**3 #frequency of radio wave 1\n",
+ "f2=10*10**9 #frequency of radio wave 2\n",
+ "\n",
+ "#Calculation\n",
+ "c1=sig/(2*math.pi*f1*eo*er) #conductivity at f1\n",
+ "c2=sig/(2*math.pi*f2*eo*er) #conductivity at f2\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print'conductivity at f1 = %.1f >> 1'%c1\n",
+ "print'conductivity at f2 = %.1f x10^-4 >> 1'%(c2*10**4)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "conductivity at f1 = 749.3 >> 1\n",
+ "conductivity at f2 = 7.5 x10^-4 >> 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2, page 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "c1=3*10**8 #speed of light in m/s\n",
+ "f1=100*10**6 #frequency in hertz\n",
+ "f2=1*10**9 #frequency in hertz\n",
+ "\n",
+ "#Calculation\n",
+ "v1=c1/(9) #velocity in m/s\n",
+ "v2=c1 #velocity in m/s\n",
+ "h1=v1*f1**-1 #wavelength at f1, v1\n",
+ "h2=v2*f1**-1 #wavelength at f1, v2\n",
+ "h3=v1*f2**-1 #wavelength at f2, v1\n",
+ "h4=v2*f2**-1 #wavelength at f2, v2\n",
+ "\n",
+ "#Result\n",
+ "print'Velocity,'\n",
+ "print'V1 = %.2f x10^7 m/s'%(v1*10**-7)\n",
+ "print'V2 = %.2f x10^8 m/s'%(v2*10**-8)\n",
+ "print'\\nfor f1 = 100 MHz'\n",
+ "print'lambda1 = %f m'%h1\n",
+ "print'lambda2 = %d m'%h2\n",
+ "print'\\nfor f2 = 1 GHz'\n",
+ "print'lambda1 = %.2f cm'%(h3*10)\n",
+ "print'lambda2 = %d cm'%(h4*10**2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Velocity,\n",
+ "V1 = 3.33 x10^7 m/s\n",
+ "V2 = 3.00 x10^8 m/s\n",
+ "\n",
+ "for f1 = 100 MHz\n",
+ "lambda1 = 0.333333 m\n",
+ "lambda2 = 3 m\n",
+ "\n",
+ "for f2 = 1 GHz\n",
+ "lambda1 = 0.33 cm\n",
+ "lambda2 = 30 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3, page 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "import cmath\n",
+ "\n",
+ "#Initialisation\n",
+ "s=0.08 #medium conductivit\n",
+ "w=10**7 #angular velocity\n",
+ "e=8.85*10**-7 #permitivity if free space\n",
+ "u=14 #medium permeability\n",
+ "uo=4*3.14*10**-7 #permeability of free space\n",
+ "\n",
+ "#Calculation\n",
+ "f=w*(2*3.14)**-1 #frequency\n",
+ "a=math.sqrt(f*math.pi*s*uo) #attenuation\n",
+ "b=a #phase\n",
+ "d=complex(a,b)\n",
+ "y=d #propagation constants\n",
+ "z=math.log10(0.5)/(-math.log10(math.exp(1))*2*a) #Depth of the land\n",
+ "\n",
+ "#Result\n",
+ "print'(1) Attenuation = %.1f Np/m'%a\n",
+ "print' Phase = %.1f Rad/m'%b\n",
+ "print' Propagation constant = %.1f'%y.real\n",
+ "print' + %.1f j rad/m'%y.imag\n",
+ "print'(2) Depth of land = %.2f m'%z"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Attenuation = 0.7 Np/m\n",
+ " Phase = 0.7 Rad/m\n",
+ " Propagation constant = 0.7\n",
+ " + 0.7 j rad/m\n",
+ "(2) Depth of land = 0.49 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6, page 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "W=100*10**-12 #power in watt\n",
+ "no=120*math.pi\n",
+ "\n",
+ "#Calculation\n",
+ "Em=math.sqrt(2*no*W) #effective value of E\n",
+ "Ee=Em/math.sqrt(2) #effective value of E\n",
+ "Hm=math.sqrt((2*10**-10)/(no)) #effective value of H\n",
+ "He=Hm/math.sqrt(2) #effective value of H\n",
+ "\n",
+ "#Result\n",
+ "print'Em = %.1f uV/m'%(Em*10**6)\n",
+ "print'Ee = %.1f uV/m'%(Ee*10**6)\n",
+ "print'Hm = %.3f uA/m'%(Hm*10**6)\n",
+ "print'He = %.2f uA/m'%(He*10**6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Em = 274.6 uV/m\n",
+ "Ee = 194.2 uV/m\n",
+ "Hm = 0.728 uA/m\n",
+ "He = 0.52 uA/m\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.7, page 39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "f=7.5 #frequency in GHz\n",
+ "d=40 #link distance in Km\n",
+ "Pt=30 #transmitter power in dBm\n",
+ "La=15 #additional loss\n",
+ "Pth=-78 #RX threshold\n",
+ "\n",
+ "#Calculation\n",
+ "FSL=92.4+(20*math.log10(f*d)) #FSL\n",
+ "RSL=Pt-(0.4*FSL)-La #RSL\n",
+ "FM=RSL-Pth #fade margin\n",
+ "\n",
+ "#Result\n",
+ "print'(1) Received signal level (RSL) = %.1f dBm'%RSL\n",
+ "print'(2) Fade margin = %.1f dB'%FM\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Received signal level (RSL) = -41.8 dBm\n",
+ "(2) Fade margin = 36.2 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8, page 45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "Pt=10 #transmitter power in watt\n",
+ "Gt=5 #antenna power in dBm\n",
+ "Lt=2 #feeder loss in dB\n",
+ "d=8000 #distance in meter\n",
+ "no=120*math.pi\n",
+ "\n",
+ "#Calculation\n",
+ "EIRP=Pt+Gt-Lt \n",
+ "x=EIRP*10**-1 \n",
+ "EIRP2=10**x #Equivalent isotropic radiated power\n",
+ "Ed=math.sqrt(30*EIRP2)/d #Electric Field Intensity\n",
+ "W=(Ed**2)/(2*no) #power in watt\n",
+ "\n",
+ "#Result\n",
+ "print'EIRP = %.1f W'%EIRP2\n",
+ "print'|Ed| = %.2f mV/m'%(Ed*10**3)\n",
+ "print'W = %.1f nW/m^2'%(W*10**9)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "EIRP = 20.0 W\n",
+ "|Ed| = 3.06 mV/m\n",
+ "W = 12.4 nW/m^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9, page 47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "FSL=128 #FSL in dB\n",
+ "Lb=135 #Sum of FSL and medium loss Lm\n",
+ "Lc=5\n",
+ "Gt=30 #transmitter gain in dB\n",
+ "Gr=30 #reciever gain in dB\n",
+ "Pr=-60 #received signal level\n",
+ "\n",
+ "#Calculation\n",
+ "Lm=Lb-FSL #medium loss in dB\n",
+ "Lm1=10**(Lm*10**-1) #medium loss\n",
+ "Pt=Lc+Lb-Gt-Gr+Pr #power in dBm\n",
+ "Pt1=10**(Pt*10**-1) #power in watt \n",
+ "\n",
+ "#Result\n",
+ "print'Medium Loss = %d'%Lm1\n",
+ "print'Pt = %.1f mW'%(Pt1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Medium Loss = 5\n",
+ "Pt = 100.0 mW\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.10, page 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "ri1=1.00025 #refractive index\n",
+ "ri2=1.00023 #refractive index\n",
+ "h1=1 #height in Km\n",
+ "h2=1.5 #height in Km\n",
+ "n=1.00026 #variation\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "deln=ri1-ri2\n",
+ "delh=h2-h1\n",
+ "d=deln/delh\n",
+ "R=n/d #radius of curvature\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print'Radiowave curvature radius, R = %.d Km'%R"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Radiowave curvature radius, R = 25006 Km\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.11, page 51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "R=25000 #path curvature radius in Km\n",
+ "Re=6370 #Earth radius in Km\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "K=R*(R-Re)**-1 #K factor\n",
+ "Re1=K*Re #equivalent radii of the Earth\n",
+ "R1=(1*Re1**-1)-(1*Re**-1)+(1*R**-1)\n",
+ "d=1*R1**-1 #equivalent radii of the path\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print'K = %.3f'%K\n",
+ "print'Re1 = %d'%Re1\n",
+ "print'R1 = %d'%d\n",
+ "print'Therefore, R1 ~ infinity'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "K = 1.342\n",
+ "Re1 = 8548\n",
+ "R1 = 147573952589676412928\n",
+ "Therefore, R1 ~ infinity\n"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter3_1.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter3_1.ipynb
new file mode 100755
index 00000000..ce1dfb31
--- /dev/null
+++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter3_1.ipynb
@@ -0,0 +1,769 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:2889947ecf1bb93d75d23a9b033bb461f9ca25a6919259a4e295df30c37ddd8c"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3: Radiowave Propagation in Troposphere"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1, page 61"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "h=2 #height in Km\n",
+ "h1=5 #height in Km\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "t2=290-(6.5*h) #Proposed formula for height h=2Km\n",
+ "p2=950-117*h\n",
+ "e2=8-3*h\n",
+ "t21=294.98-5.22*h-0.007*h**2\n",
+ "p21=1012.82-111.56*h+3.86*h**2\n",
+ "p=14.35*2.72**(-0.42*h-0.02*h*h+0.001*h**3)\n",
+ "\n",
+ "t5=290-6.5*h1 #Proposed formula for height h=5Km\n",
+ "p5=950-117*h1\n",
+ "e5=8-3*h1\n",
+ "t51=294.98-5.22*h1-0.007*h1**2\n",
+ "p51=1012.82-111.56*h1+3.86*h1**2\n",
+ "p1=14.35*2.72**(-0.42*h1-0.02*h1**2+0.001*h1**3)\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'T(2) = %.1f K'%t21\n",
+ "print'P(2) = %.2f hpa'%p21\n",
+ "print'p(2) = %.2f hpa\\n'%p\n",
+ "print'T(5) = %.1f K'%t51\n",
+ "print'P(5) = %.2f hpa'%p51\n",
+ "print'p(5) = %.2f hpa'%p1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "T(2) = 284.5 K\n",
+ "P(2) = 805.14 hpa\n",
+ "p(2) = 5.76 hpa\n",
+ "\n",
+ "T(5) = 268.7 K\n",
+ "P(5) = 551.52 hpa\n",
+ "p(5) = 1.21 hpa\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.2, page 63"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "h=2 #Height in Km\n",
+ "T=277 #Tempreture in Kelvin\n",
+ "p=716\n",
+ "e=2\n",
+ " \n",
+ "\n",
+ "#Calculation\n",
+ "er=1+(151.1/T)*(p+(4810*h/T))*10**-6 \n",
+ "n=er**(0.515) #refractive index of the air\n",
+ "N=(n-1)*10**6 #refractivity number\n",
+ " \n",
+ "\n",
+ "#Results\n",
+ "print'n = %.5f'%n\n",
+ "print'N = %d'%N"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n = 1.00021\n",
+ "N = 210\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3, page 67"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "er=1.001 #relative permittivity of a medium\n",
+ "dn=35*10**-6 #vertical gradient of refractive index\n",
+ "Re=6370 #actual redius of earth\n",
+ "d=20 #transmitter and receiver distance in Km\n",
+ "d1=5\n",
+ "d2=15\n",
+ "K1=1.3333 #standard atmosphere condition\n",
+ "\n",
+ "#Calculation\n",
+ "R=(er**0.5)/dn\n",
+ "K=R/(R-Re)\n",
+ "hm=(125*d**2)/(K*Re) #Earth bulge value in the middle of the path\n",
+ "h1=(500*d1*d2)/(K*Re) #h1\n",
+ "h2=(500*d1*d2)/(K1*Re) #h2\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'Bulge value = %.1f m'%hm\n",
+ "print'Bulge value, h1 = %.2f m'%h1\n",
+ "print'Bulge value, h2 = %.2f m'%h2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bulge value = 6.1 m\n",
+ "Bulge value, h1 = 4.58 m\n",
+ "Bulge value, h2 = 4.42 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.4, page 68"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "K=1.33\n",
+ "d1=24 #heigth in Km\n",
+ "d2=15 #heigth in Km\n",
+ "K1=1\n",
+ "Re=6370 #actual redius of earth\n",
+ "\n",
+ "#Calculation\n",
+ "R=4.12*(d1**0.5+d2**0.5)\n",
+ "R1=K1*Re\n",
+ "Rrh=(2*R1*d1)**0.5+(2*R1*d2)**0.5\n",
+ "\n",
+ "#Results\n",
+ "print'K=1.33'\n",
+ "print'Rrh = %.1f km\\n'%R\n",
+ "print'K=1'\n",
+ "print'Rrh = %.1f km'%Rrh #wrong answer in textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "K=1.33\n",
+ "Rrh = 36.1 km\n",
+ "\n",
+ "K=1\n",
+ "Rrh = 990.1 km\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.5, page 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#Initialisation\n",
+ "No=1 #index of refraction\n",
+ "N1=1.3*10**-7\n",
+ "h=20 #height\n",
+ "\n",
+ "#Calculation\n",
+ "wc=math.asin(((4*No)/((4*No)+((h**2)*N1)))) #critical angle\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'Critical angle = %f'%wc #ans is not written in textbook\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical angle = 1.565697\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.6, page 76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "dn=-0.2 #air refractivity gradient\n",
+ "d=20 #height\n",
+ "b=0.074 #elevation angle from graph 3.10\n",
+ "f=7 #frequency in Ghz from graph 3.11\n",
+ "c=2*10**-6\n",
+ "\n",
+ "#Calculation\n",
+ "t=0.156 #1000/6370\n",
+ "dm=dn+t\n",
+ "a=(-c*dm*d)**0.5 #elevation angle of waves\n",
+ "\n",
+ "#Results\n",
+ "print'Elevation angle of waves = %.2f mrad'%(a*10**3)\n",
+ "print'Elevation angle = %.3f'%b #from graph 3.10\n",
+ "print'Minimum frequency of coupling waves into the duct = %d Ghz'%f #from graph 3.11"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Elevation angle of waves = 1.33 mrad\n",
+ "Elevation angle = 0.074\n",
+ "Minimum frequency of coupling waves into the duct = 7 Ghz\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.7, page 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=18 #frequency in GHz\n",
+ "d=30 #in km\n",
+ "R=25 #rainfall intensity in mm\n",
+ "\n",
+ "#Using Table 3.3\n",
+ "av15=1.128\n",
+ "av20=1.065\n",
+ "av18=1.09\n",
+ "kv15=0.0335\n",
+ "kv20=0.0691\n",
+ "kv18=0.0587\n",
+ "\n",
+ "#Calculation\n",
+ "yr=kv18*R**av18 #rain specific attenuation\n",
+ "de=(90*(90+d)**-1)*d\n",
+ "A=de*yr #Maximum rain attenuation\n",
+ " \n",
+ "#Results\n",
+ "print'(1) Rain specific attenuation = %.2f dB/km'%yr\n",
+ "print'(2) Maximum rain attenuation = %.1f dB'%A\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Rain specific attenuation = 1.96 dB/km\n",
+ "(2) Maximum rain attenuation = 44.1 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.9, page 89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "rh=-1\n",
+ "s=4 #sigma in S/m\n",
+ "f=5*10**9 #frequency in Hz\n",
+ "eo=8.85*10**-12 #permitivity of free space\n",
+ "er=75 #permitivity of medium\n",
+ "w1=30*3.14*180**-1 #in radians\n",
+ "\n",
+ "#Calculation\n",
+ "w=2*math.pi*f\n",
+ "x=s*(w*eo)**-1\n",
+ "a=math.sin(w1)-math.sqrt((er-x)-math.cos(w1)**2)\n",
+ "a1=math.sin(w1)+math.sqrt((er-x)-math.cos(w1)**2)\n",
+ "rh1=a/a1\n",
+ "b1=(er-x)*math.sin(w1)-math.sqrt((er-x)-math.cos(w1)**2)\n",
+ "b2=(er-x)*math.sin(w1)+math.sqrt((er-x)-math.cos(w1)**2)\n",
+ "rv=-b1/b2\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'(2) X = %.1f'%x\n",
+ "print'(3) Rh = %.3f'%rh1\n",
+ "print' Rv = %.1f'%rv\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(2) X = 14.4\n",
+ "(3) Rh = -0.879\n",
+ " Rv = -0.6\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.10, page 92"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=5*10**9 #frequency in Hz\n",
+ "c=3*10**8 #speed of light\n",
+ "h1=6 #in metre\n",
+ "h2=2 #in metre\n",
+ "\n",
+ "#Calculation\n",
+ "h=c*f**-1 #wavelength \n",
+ "w=math.atan(h1*2250**-1) #grazing angle in radian\n",
+ "w1=w*180*math.pi**-1 #grazing angle in degree\n",
+ "a=((2*math.pi*h1*h2)*(h*300)**-1)*3.14*180**-1\n",
+ "e=math.sin(a) \n",
+ "F=e*2*180*math.pi**-1 #PGF value (wrong calculated in textbook)\n",
+ "LR=20*math.log10(F) #Decrease in received signal level\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Grazing angle = %.2f degree'%w1\n",
+ "print'(2) PGF value = %f'%F #wrong value calculated in textbook\n",
+ "print'(3) Decrease in received signal level = %.2f dB'%LR #wrong value calculated in textbook\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Grazing angle = 0.15 degree\n",
+ "(2) PGF value = 8.365884\n",
+ "(3) Decrease in received signal level = 18.45 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.11, page 98"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Initialisation\n",
+ "h=12.5*10**-2 #in meter\n",
+ "d1=10*10**3 #in meter\n",
+ "d2=15*10**3 #in meter\n",
+ "d3=12.5*10**3 #in meter\n",
+ "d4=12.5*10**3 #in meter\n",
+ "h=1.25 #in Kilometer\n",
+ "\n",
+ "#Calculation\n",
+ "r1=(((d1*d2)/(d1+d2))*h)**0.5 #radius of first and fourth Fresnel zones\n",
+ "r4=r1*(4)**0.5\n",
+ "R1=(((d3*d4)/(d3+d4))*h)**0.5 #radius of first and fourth ellipse zones\n",
+ "R4=R1*(4)**0.5\n",
+ "\n",
+ "#Results\n",
+ "print'Radius of first fresnel zones, r1 = %.2f m'%r1\n",
+ "print'Radius of Second fresnel zones, r4= %.2f m'%r4\n",
+ "print'h = %.2f x 10^-4 Km'%h\n",
+ "print'Radius of first ellipse, R1 = %.2f m'%R1\n",
+ "print'Radius of second ellipse, R4 = %.1f m'%R4"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Radius of first fresnel zones, r1 = 86.60 m\n",
+ "Radius of Second fresnel zones, r4= 173.21 m\n",
+ "h = 1.25 x 10^-4 Km\n",
+ "Radius of first ellipse, R1 = 88.39 m\n",
+ "Radius of second ellipse, R4 = 176.8 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.12, page 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "%matplotlib inline\n",
+ "import matplotlib\n",
+ "import numpy as np\n",
+ "import matplotlib.pyplot as plt\n",
+ "\n",
+ "#Initialisation\n",
+ "L=13200 #L parameter in m\n",
+ "H=10240 #H parameter \n",
+ "Re=6370000 #actual redius of earth\n",
+ "ht=30 #height in m\n",
+ "hr=20 #height in m\n",
+ "re1=8453000 # in metre\n",
+ "h1=30000 # in metre \n",
+ "h2=20000 # in metre\n",
+ "dt1=22.5\n",
+ "f=10*10**9 #frequency in Hz\n",
+ "c=3*10**8 #speed of light\n",
+ "d=30000 #distance in m\n",
+ "pt=30 #transmitter antenna power\n",
+ "gt=40 #transmitter antenna gain\n",
+ "gr=40 #receiver antenna gain \n",
+ "F3=-3\n",
+ "H=-34\n",
+ "D=0.75\n",
+ "\n",
+ "#Calculation\n",
+ "dt=math.sqrt(2*re1*ht)\n",
+ "X=3*dt*L**-1\n",
+ "Z1=h1*H**-1\n",
+ "Z2=h2*H**-1\n",
+ "vx=10**-3.5 #from fig 3.26\n",
+ "z1=10**0.95 #from fig 3.27\n",
+ "z2=10**0.65 #from fig 3.27\n",
+ "\n",
+ "#for d=3dt\n",
+ "lv=20*math.log10(vx)\n",
+ "lz1=20*math.log10(z1)\n",
+ "lz2=20*math.log10(z2)\n",
+ "F=(lv+lz1+lz2)*20**-1\n",
+ "F1=10**(F)\n",
+ "F11=20*math.log10(F1)\n",
+ "X1=2*dt*L**-1\n",
+ "d3=3\n",
+ "f3=-F11\n",
+ "\n",
+ "vx1=10**-2.35 #from fig 3.26\n",
+ "lv1=20*math.log10(vx1)\n",
+ "\n",
+ "#for d=2dt\n",
+ "F4=1+D\n",
+ "F5=20*math.log10(F4)\n",
+ "d2=2\n",
+ "f2=-F5\n",
+ "\n",
+ "\n",
+ "#for d=1.1dt\n",
+ "F6=math.sqrt(1+D**2)\n",
+ "F7=20*math.log10(F6)\n",
+ "d11=1.1\n",
+ "f11=-F7\n",
+ "\n",
+ "#for d=dt\n",
+ "d1=1\n",
+ "f1=0.2\n",
+ "\n",
+ "#for plotting graph in terms of points\n",
+ "\n",
+ "for N in range(0,4,1):\n",
+ " a=plot(1,0.2,'-o')\n",
+ " a1=plot(1.1,-1.9,'-o')\n",
+ " a2=plot(2,-4.8,'-o')\n",
+ " a3=plot(3,-38,'-o')\n",
+ " \n",
+ "plt.annotate('d/dt',xy=(1,2),xytext=(1, 2))\n",
+ "plt.annotate('1.1d/dt',xy=(1.2,0.7),xytext=(1.2, 0.7))\n",
+ "plt.annotate('2d/dt',xy=(2,-0.7),xytext=(2, -0.7))\n",
+ "plt.annotate('3d/dt',xy=(3,-35),xytext=(3, -35))\n",
+ "xlabel(\"$d/dt$\")\n",
+ "ylabel(\"$20 log(F)$ (dB)\")\n",
+ "title(\"Path gain F\")\n",
+ "grid()\n",
+ "show(a)\n",
+ "show(a1)\n",
+ "show(a2)\n",
+ "show(a3)\n",
+ " \n",
+ "h=c*f**-1 #wavelength\n",
+ "Pr=pt+gt+gr+H+F3-10*math.log10(4*math.pi*d**2) #Received signal power\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Effective receiver path gain F = %.4f'%F11\n",
+ "print'(2) Path gain F plot is shown'\n",
+ "print'(3) Received signal power Pr = %.1f dBm'%Pr\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x7f10dda53110>"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Effective receiver path gain F = -38.0000\n",
+ "(2) Path gain F plot is shown\n",
+ "(3) Received signal power Pr = -27.5 dBm\n"
+ ]
+ }
+ ],
+ "prompt_number": 93
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.13, page 109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "\n",
+ "#Initialisation\n",
+ "eirp=800 #in KW\n",
+ "d=24 #in Km\n",
+ "a=0.03 #in radian\n",
+ "d1=22 #in Km\n",
+ "d2=2 #in Km\n",
+ "h=0.4*10**-3 #wavelength in m\n",
+ "Er=45 #in microvolt\n",
+ "\n",
+ "#Calculation\n",
+ "E=104.8+10*math.log10(eirp)-20*math.log10(d) #field intensity\n",
+ "V=a*math.sqrt((2*d2*d1)/((d1+d2)*h)) #knife edge obstacle attenuation\n",
+ "Lke=23 #from table 3.4\n",
+ "er=10**(Er*20**-1)\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Electric field intensity = %.3f microV/m'%er\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Electric field intensity = 177.828 microV/m\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.14, page 115"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "f1=430 #upper frequency band\n",
+ "f2=410 #lower frequency band\n",
+ "d=80 #distance in meter\n",
+ "\n",
+ "#Calculation\n",
+ "Yv=0.1 #Specific attenuation obtained from graph fig 3.34 \n",
+ "Lv=Yv*d #loss of forest trees\n",
+ "Am=((f1+f2)/2)**0.5 #maximum value for trees excess loss.\n",
+ "\n",
+ "#Results\n",
+ "print'Specific attenuation index, Yv = %.1f dB/m'%Yv\n",
+ "print'Loss of forest trees, Lv = %.1f dB'%Lv\n",
+ "print'Maximum value for trees excess loss = %.1f dB'%Am"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Specific attenuation index, Yv = 0.1 dB/m\n",
+ "Loss of forest trees, Lv = 8.0 dB\n",
+ "Maximum value for trees excess loss = 20.5 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.15, page 118"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Initialisation\n",
+ "d=40 #length in meter\n",
+ "Am=2 #area in square meter\n",
+ "f=10*10**9 #frequency in hertz\n",
+ "\n",
+ "#Calculation\n",
+ "As=40 #using graph fig 3.36, As can be obtained \n",
+ "As1=30 #using graph fig 3.37, As can be obtained\n",
+ "\n",
+ "#Results\n",
+ "print'Loss in the summer for trees with leaves, As = %d dB'%As\n",
+ "print'Loss in winter for trees without leaves, As = %d dB'%As1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Loss in the summer for trees with leaves, As = 40 dB\n",
+ "Loss in winter for trees without leaves, As = 30 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter4_1.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter4_1.ipynb
new file mode 100755
index 00000000..9666b1af
--- /dev/null
+++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter4_1.ipynb
@@ -0,0 +1,534 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8b82c1850573ed04faf5b016dd3b7bb1cd3e59fe769778d2d3498929713b1cff"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: Radiowave Propagation in Ionosphere"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1, page 130"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "h=400 #height in Km\n",
+ "pd=1*10**8 #plasma density at height D\n",
+ "pe=1*10**10 #plasma density at height E\n",
+ "pf=3*10**11 #plasma density at height F\n",
+ "Wd=20*10**3 #thickness of D\n",
+ "We=40*10**3 #thickness of E\n",
+ "Wf=190*10**3 #thickness of F\n",
+ "\n",
+ "#Calculation\n",
+ "tecd=Wd*pd #total electron content at D\n",
+ "tece=We*pe #total electron content at E\n",
+ "tecf=Wf*pf #total electron content at F\n",
+ "tec=tecd+tece+tecf \n",
+ "tec1=tec*math.sqrt(2) #total electron content\n",
+ "\n",
+ "#Results\n",
+ "print'(2) TEC (D) = %.1f x 10^12 el/m^2'%(tecd/10**12)\n",
+ "print' TEC (E) = %.1f x 10^14 el/m^2'%(tece/10**14)\n",
+ "print' TEC (F) = %.2f x 10^16 el/m^2'%(tecf*10**-16)\n",
+ "print'(3) TEC = %.1f x 10^16 el/m^2'%(tec1/10**16)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(2) TEC (D) = 2.0 x 10^12 el/m^2\n",
+ " TEC (E) = 4.0 x 10^14 el/m^2\n",
+ " TEC (F) = 5.70 x 10^16 el/m^2\n",
+ "(3) TEC = 8.1 x 10^16 el/m^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2, page 134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "N=5*10**11 #Electron density in F layer\n",
+ "\n",
+ "#Calculation\n",
+ "F=9*math.sqrt(N) #f0F frequency\n",
+ "\n",
+ "#Results\n",
+ "print'(1) hmin = 200Km hmax = 400Km' #from graph\n",
+ "print'(2) F = %.1f Mhz'%(F*10**-6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) hmin = 200Km hmax = 400Km\n",
+ "(2) F = 6.4 Mhz\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3, page 136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "fc=6.3*10**6 #frequency in hertz\n",
+ "\n",
+ "#Calculation\n",
+ "f=fc*math.sqrt(2) #maximum usable frequency\n",
+ "\n",
+ "#Results\n",
+ "print'Maximum usable frequency = %.3f MHz'%(f*10**-6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum usable frequency = 8.910 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4, page 137"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "tec=10**17 #total electron content\n",
+ "H=200*10**3 #thickness of F layer\n",
+ " \n",
+ "#Calculation\n",
+ "pd=tec/H #plasma density at F\n",
+ "fc=9*math.sqrt(pd)\n",
+ "ouf=3.6*fc*0.8 #optimum usable frequency\n",
+ "muf=fc*1.788 #maximum usable frequency\n",
+ "\n",
+ "#Results\n",
+ "print'Maximum usable frequency = %.1f MHz'%(fc*10**-6)\n",
+ "print'Optimum usable frequency < %.3f MHz'%(ouf*10**-6)\n",
+ "print'Maximum usable frequency (30) = %.1f MHz'%(muf*10**-6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum usable frequency = 6.4 MHz\n",
+ "Optimum usable frequency < 18.328 MHz\n",
+ "Maximum usable frequency (30) = 11.4 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.5, page 138"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "d=1000 #distance in km\n",
+ "re=6370 #earth radius in km\n",
+ "dt=30 #in degree\n",
+ "\n",
+ "#Calculation\n",
+ "teta=d*(2*re)**-1 #theta in radians\n",
+ "tet=teta*180*math.pi**-1 #theta in degree\n",
+ "w1=90-dt-tet\n",
+ "a=math.sin(w1*3.14/180)/re\n",
+ "a1=math.sin((90+dt)*3.14/180)\n",
+ "h=(a1*a**-1)-re #height\n",
+ "#Results\n",
+ "print'(1) virtual height of the reflection point = %d km'%h #wrong value calculated in textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) virtual height of the reflection point = 330 km\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6, page 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "d=200 #height in Km\n",
+ "f=700 #frequency in Khz\n",
+ "\n",
+ "#Calculation\n",
+ "T1e=0.4 #from graph 4.10\n",
+ "T2e=0.9\n",
+ "T3e=1.7\n",
+ "T1f=1.3\n",
+ "T2f=2.8\n",
+ "T3f=4.3\n",
+ "Tef=0.3\n",
+ "Tef1=2.7\n",
+ "Tef2=0.5\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Time delay of E layer, Td(1E) = %.1f ms'%T1e\n",
+ "print' Td(2E) = %.1f ms'%T2e\n",
+ "print' Td(2E) = %.1f ms'%T3e\n",
+ "print' Time delay of F layer, Td(1F) = %.1f ms'%T1f\n",
+ "print' Td(2F) = %.1f ms'%T2f\n",
+ "print' Td(2F) = %.1f ms'%T3f\n",
+ "print'(2) Time delay of E and F for a distance of 500 km, Td(E,F) = %.1f ms'%Tef\n",
+ "print'(3) Td(1F,3F) = %.1f ms'%Tef1\n",
+ "print' Td(1E,3E) = %.1f ms'%Tef2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Time delay of E layer, Td(1E) = 0.4 ms\n",
+ " Td(2E) = 0.9 ms\n",
+ " Td(2E) = 1.7 ms\n",
+ " Time delay of F layer, Td(1F) = 1.3 ms\n",
+ " Td(2F) = 2.8 ms\n",
+ " Td(2F) = 4.3 ms\n",
+ "(2) Time delay of E and F for a distance of 500 km, Td(E,F) = 0.3 ms\n",
+ "(3) Td(1F,3F) = 2.7 ms\n",
+ " Td(1E,3E) = 0.5 ms\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7, page 147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=1.5*10**9 #frequency in Hz\n",
+ "tec=10**18 #total electron content\n",
+ "g=5*10**-3 #geomagnetic field intensity\n",
+ "a=3.36*10**2\n",
+ "\n",
+ "#Calculation\n",
+ "teta= a*g*tec*(f**-2) #Faraday rotation in Radian\n",
+ "c=0.8422\n",
+ "x=20*math.log10(c) #loss value in dB\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Faraday rotation = %.1f Rad'%teta\n",
+ "print'(2) Loss = %f dB'%x"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Faraday rotation = 0.7 Rad\n",
+ "(2) Loss = -1.491695 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8, page 149"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "tec1=10**18 #total electron content\n",
+ "f=1.5 #frequency in Hertz\n",
+ "tec2= 10**17 #total electron content\n",
+ "\n",
+ "#Calculation\n",
+ "teta = 600 #Faraday rotation in mRadian\n",
+ "T=5 #time delay in ns\n",
+ "gd=0.5 #time delay difference in ns\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Faraday rotation = %d mRad'%teta\n",
+ "print'(2) Time delay = %d ns'%T\n",
+ "print'(3) G/D = %.1f ns'%gd"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Faraday rotation = 600 mRad\n",
+ "(2) Time delay = 5 ns\n",
+ "(3) G/D = 0.5 ns\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.9, page 158"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "phi=166 #in radian \n",
+ "t=35*math.pi/180 #geographic latitude in radian\n",
+ "t1=60*math.pi/180 #zenith angle in radian\n",
+ "N=80*math.pi/180 #in radian\n",
+ "x=92\n",
+ "y=35\n",
+ "h=35\n",
+ "p=1.2\n",
+ "\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "m=0.11-0.49*math.cos(t)\n",
+ "fe=0.004*(1+0.021*166)**2 #minimum value of f0E\n",
+ "A=1+0.0094*(phi-66) #A value\n",
+ "B=(math.cos(N))\n",
+ "B1=B**m #B value\n",
+ "C=x+y*math.cos(t) #C value\n",
+ "D=math.cos(t1)**p #D value\n",
+ "F=(A*B*C*D)**(0.25) #exact value of f0E \n",
+ "\n",
+ "#Results\n",
+ "print'(1) Minimum value of f0E = %.2f x 10^-2 MHz'%(fe*100)\n",
+ "print'(2) f0E = %.2f MHz'%F #wrong value calculated in textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Minimum value of f0E = 8.05 x 10^-2 MHz\n",
+ "(2) f0E = 2.05 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.10, page 159"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "g=50 #geomagnetic latitude in degree\n",
+ "R12=100 #solar activity number\n",
+ "x=60*math.pi/180 #zenith angle in radians\n",
+ "\n",
+ "#Calculation\n",
+ "f0=4.35+0.0058*g-0.00012*g**2\n",
+ "f100=5.35+0.011*g-0.00023*g**2\n",
+ "fs=f0+0.01*(f100-f0)*R12\n",
+ "n=0.093+(0.00461*g)-(0.000054*(g**2))+(0.0031*R12) #wrong value calculated in textbook\n",
+ "F1=fs*(math.cos(x))**n #critical frequency\n",
+ "\n",
+ "#Results\n",
+ "print'Critical Frequency = %.2f MHz'%F1 #wrong value calculated in textbook\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Critical Frequency = 3.77 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 62
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.11, page 164"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "R12=150 #12 month average value\n",
+ "fs0=4.416\n",
+ "fs100=5.473\n",
+ "n=0.23\n",
+ "x=45*math.pi/180 #zenith angle in radians \n",
+ "\n",
+ "#Calculation\n",
+ "f1=63.7+0.728*R12+0.00089*R12**2\n",
+ "fs=fs0+0.01*(fs100-fs0)*R12\n",
+ "F1=fs*(math.cos(x))**n #critical frequency #zenith angle in radians\n",
+ "\n",
+ "#Results\n",
+ "print'(1) R12 = %d'%R12\n",
+ "print'(2) F12 = %d'%f1\n",
+ "print'(3) f0F1 = %.2f MHz'%F1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) R12 = 150\n",
+ "(2) F12 = 192\n",
+ "(3) f0F1 = 5.54 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 61
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter5_1.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter5_1.ipynb
new file mode 100755
index 00000000..9a18598b
--- /dev/null
+++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter5_1.ipynb
@@ -0,0 +1,465 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:98eb0c6e30cbee8cc73fe4fee57515eb52199d33e809700a3f6ef648557e06af"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5: Propagation in 3 KHz to 30 MHz Band"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2, page 186"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=5 #frequency in Hz\n",
+ "er=15 #ground characteristics\n",
+ "s=0.01 #for vertically polarized waves\n",
+ "c=3*10**8 #speed of light\n",
+ "e0=8.85*10**-12 #permitivity of free space\n",
+ "d=80000 #distance in m\n",
+ "\n",
+ "#Calculation\n",
+ "a=5**0.333\n",
+ "df=50/a #distance in metre\n",
+ "h=c*(f*10**6)**-1 #wavelength\n",
+ "b=s/(2*math.pi*f*e0*10**6)\n",
+ "b1=math.sqrt(er**2+b**2)\n",
+ "p=(math.pi*d)/(h*b1)\n",
+ "\n",
+ "#from fig 5.8\n",
+ "As = 0.05 #attenuation factor\n",
+ "\n",
+ "#Results\n",
+ "print'p = %d'%p\n",
+ "print'|As| = %.2f'%As"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "p = 107\n",
+ "|As| = 0.05\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.3, page 191"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "c=3*10**8 #speed of light\n",
+ "f=10*10**6 #frequency in Hz\n",
+ "e0=8.85*10**-12 #permitivity of free space\n",
+ "er=10 #ground characteristics\n",
+ "s=0.005\n",
+ "d=30000\n",
+ "pt=200 #transmitter power in watt\n",
+ "gt=1 #gain of transmitter antenna\n",
+ "gr=1 #gain of receiver antenna\n",
+ "\n",
+ "#Calculation\n",
+ "h=c*f**-1 #wavelength\n",
+ "e=er*e0\n",
+ "b=s/(2*math.pi*f*e)\n",
+ "b1=math.sqrt(er**2+b**2)\n",
+ "p=(math.pi*d)/(h*b1) #wrong value calculated in textbook\n",
+ "i=((er*e0*2*3.14*f)/s)\n",
+ "b2=math.atan(i) \n",
+ "b3=b2*180/math.pi\n",
+ "a1=((2+0.3*p)/(2+p+0.6*p**2))\n",
+ "a2=math.sqrt(p/2)*(5*10**-82)*math.sin(-b3)\n",
+ "As=a1-a2 #attenuation function\n",
+ "pr=pt*gt*gr*h**2/(4*math.pi*d)**2\n",
+ "pr1=pr*(2*As)**2 #wrong value calculated in textbook \n",
+ "\n",
+ "#Results\n",
+ "print'Received signal power Pr = %.2f pW'%(pr1*10**12) #wrong value calculated in textbook\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Received signal power Pr = 13.35 pW\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4, page 192"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=0.5 #frequency in MHz\n",
+ "Pa=100 #transmitter power\n",
+ "Po=1000\n",
+ "e120=68 #from figure 5.10\n",
+ "e220=85 #from figure 5.9\n",
+ "e230=80\n",
+ "e330=60 #from figure 5.10\n",
+ "e380=48\n",
+ "e350=50 #from figure 5.10\n",
+ "e250=75 #from figure 5.9\n",
+ "e260=73\n",
+ "e160=60 #from figure 5.10\n",
+ "e180=48\n",
+ "\n",
+ "#Calculation\n",
+ "ETR=e120-e220+e230-e330+e380\n",
+ "ERT=e350-e250+e260-e160+e180 #wrong value calculated in textbook\n",
+ "ER=(ETR+ERT)/2 #field strength at the receiving end \n",
+ "Ea=ER+(10*math.log10(Pa*Po**-1))\n",
+ "lb=137.2+(20*math.log10(f))-ER\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Electric field = %.1f dB'%Ea #wrong value calculated in textbook due to value ER\n",
+ "print'(2) Basic loss path = %.1f dB'%lb #wrong value calculated in textbook due to value ER"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Electric field = 33.0 dB\n",
+ "(2) Basic loss path = 88.2 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5, page 196"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f1=2.5 #frequency in MHz\n",
+ "f2=6.3 #frequency in MHz\n",
+ "K=1.1 # K factor\n",
+ "\n",
+ "#Calculation\n",
+ "fse=1.05*f1*2 #frequency in MHz \n",
+ "fsf=K*f2*2 #frequency in MHz\n",
+ "\n",
+ "#Results\n",
+ "print'Frequency for E layer = %.2f MHz'%fse\n",
+ "print'Frequency for F layer = %.2f MHz'%fsf"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frequency for E layer = 5.25 MHz\n",
+ "Frequency for F layer = 13.86 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.7, page 201"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=10 #frequency in MHz\n",
+ "delta=14.5 #in degree\n",
+ "d=1750 #distance in Km\n",
+ "re=6370 #radius of earth in Km\n",
+ "pt=100 #transmitter power in watt\n",
+ "lm=30 #in dB\n",
+ "P11=3775 #in Km\n",
+ "\n",
+ "#Calculation\n",
+ "a=(delta+(d/(2*re)))*(180*3.14**-1)\n",
+ "j=math.cos(a)\n",
+ "a1=(d*(2*re)**-1)*(180*3.14**-1)\n",
+ "j1=math.sin(a1)\n",
+ "P=4*re*(j1*j**-1) #path length\n",
+ "pt1=10*math.log10(pt*10**-3)\n",
+ "FSL=32.4+20*math.log10(f)+20*math.log10(3775) #free space loss\n",
+ "Et=136.6+pt1+20*math.log10(f)-FSL-lm #median value\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Path length = %d km'%P11\n",
+ "print'(2) Median value = %.2f dB'%Et\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Path length = 3775 km\n",
+ "(2) Median value = -7.34 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 87
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.8, page 202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "et=20 #in dB\n",
+ "gr=2 #antenna gain in dB\n",
+ "f=15 #frequency in MHz\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "pr=et+gr-(20*math.log10(f))-107.2 #received signal power in dB\n",
+ "pr1=10**(pr/10) #received signal power in W\n",
+ "\n",
+ "#Results\n",
+ "print'Power Recieved signal = %.2f pW'%(pr1*10**12)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Power Recieved signal = 13.42 pW\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.9, page 202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "pr=-108.7 #received signal power in dB\n",
+ "fa=50 #noise tempreture\n",
+ "b=2700 #frequency in Hz\n",
+ "N=5 #noise figure in dB\n",
+ "\n",
+ "#Calculation\n",
+ "snr=pr-fa-(10*math.log10(b))+204 #signal to noise ratio\n",
+ "snr1=snr-N\n",
+ "\n",
+ "#Results\n",
+ "print'Received signal to noise ratio = %.1f dB'%snr\n",
+ "print'Output signal to noise ratio = %.1f dB'%snr1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Received signal to noise ratio = 11.0 dB\n",
+ "Output signal to noise ratio = 6.0 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.10, page 205"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "d=3000 #distance in Km\n",
+ "re=6370 #radius of earth in Km\n",
+ "phi=72 #angle in degree\n",
+ "N=5*10**11 #electron density\n",
+ "\n",
+ "#Calculation\n",
+ "teta=3000*(2*6370)**-1 #in radian\n",
+ "teta1=teta*180/math.pi #degree\n",
+ "dt=90-teta1-phi #Elevation angle\n",
+ "a=re/(math.sin(phi*math.pi/180))\n",
+ "b=math.sin((teta1+phi)*math.pi/180)\n",
+ "h=(a*b)-re #Height in Km\n",
+ "fc=9*math.sqrt(N) #frequency in MHz\n",
+ "MUF=fc*(math.cos(phi*math.pi/180))**-1 #Maximum working frequency\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Elevation angle = %.1f degree'%dt\n",
+ "print'(2) Height h = %.1f km'%h\n",
+ "print'(3) MUF = %.1f MHz'%(MUF*10**-6)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Elevation angle = 4.5 degree\n",
+ "(2) Height h = 307.1 km\n",
+ "(3) MUF = 20.6 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 67
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.11, page 208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "d=2500 #distance in Km\n",
+ "re=6370 #radius of earth in Km\n",
+ "dt=6 #elevation angle in degree\n",
+ "f1=15 #frequency in MHz\n",
+ "los1=42 #loss\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "teta=d*(2*re)**-1 #in radian\n",
+ "teta1=teta*180/math.pi #in degree\n",
+ "phi=90-dt-teta1\n",
+ "l=(2*re*math.sin(teta))/math.sin(phi*math.pi/180)\n",
+ "fsl=32.4+(20*math.log10(f1))+(20*math.log10(l)) #Free space loss\n",
+ "pr=57+6-fsl-los1 #receving power in dB\n",
+ "pr1=10**(pr/10) #receving power in Watt\n",
+ "\n",
+ "#Results\n",
+ "print'Power = %.2f pW'%(pr1*10**12)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Power = 47.60 pW\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 19
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter6_1.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter6_1.ipynb
new file mode 100755
index 00000000..aa1b8e58
--- /dev/null
+++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter6_1.ipynb
@@ -0,0 +1,957 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8f3ee9f7b4691e445d9dade84d186c7759365eaecbb8fa9528ad0dda0d38c771"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Terrestrial Mobile Radio Propagation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1, page 186"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "c=3*10**8 #speed of light\n",
+ "f=400*10**6 #frequency in Hz\n",
+ "l1=15*10**3 #distance in m\n",
+ "l2=15*10**3 #distance in m\n",
+ "l=30*10**3 #distance in m\n",
+ "k=1.33 #k factor\n",
+ "d1=15 #distance in Km\n",
+ "d2=15 #distance in Km\n",
+ "re=6370 #distance in Km\n",
+ "\n",
+ "#Calculation\n",
+ "h=c*f**-1 #wavelength in m\n",
+ "r1=math.sqrt(l1*l2*h/l) #Fresnel radius\n",
+ "ho=(500*d1*d2)/(k*re) #Earth bulge\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Fresnel radius, r1 = %d m'%r1\n",
+ "print'(2) h0 = %.2f m'%ho"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Fresnel radius, r1 = 75 m\n",
+ "(2) h0 = 13.28 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2, page 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=400 #frequency in MHz\n",
+ "k=1.33 #k factor\n",
+ "er=3 #dielectric conductivity\n",
+ "sg=10**-4 #Earth effective conductivity\n",
+ "eo=8.85*10**-12 #permittivity of free space\n",
+ "re1=8500 #Effective Earth radius in Km\n",
+ "c=3*10**8 #speed of light\n",
+ "B=1\n",
+ "d=50\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "kh=1.6*10**-3 #horizontal polarization using Fig. 6.2\n",
+ "kv=5*10**-3 #vertical polarization using Fig. 6.2\n",
+ "X=2.2*B*f**(1*3**-1)*re1**(-2*3**-1)*d #normalized length of the path\n",
+ "FX=11+10*math.log10(X)-17.6*X #distance attenuation value\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Kh = %.1f x 10**-3'%(kh*10**3)\n",
+ "print' Kv = %.1f x 10**-3'%(kv*10**3)\n",
+ "print'(2) F(X) = %.2f dB'%FX\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Kh = 1.6 x 10**-3\n",
+ " Kv = 5.0 x 10**-3\n",
+ "(2) F(X) = -20.36 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 103
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3, page 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=300*10**6 #frequency in Hz\n",
+ "l1=4*10**3 #distance in m\n",
+ "l2=6*10**3 #distance in m\n",
+ "h1=20 #height in m\n",
+ "c=3*10**8 #speed of light\n",
+ "d1=4 #distance in km\n",
+ "d2=6 #distance in km\n",
+ "R=10 #radius in km\n",
+ "m=0.13\n",
+ "n=1.99\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "h=c*f**-1 #wavelength\n",
+ "l=l1+l2\n",
+ "r1=math.sqrt(l1*l2*h/l)\n",
+ "rat=h1/r1 #ratio\n",
+ "a=math.sqrt((2*(d1+d2))/(h*d1*d2))\n",
+ "v=0.0316*h1*a\n",
+ "jv=6.9+20*math.log10(1.585) #knife-edge obstacle loss\n",
+ "k=8.2+12*n\n",
+ "Tmn=k*m\n",
+ "A=jv+Tmn #rounded obstacle loss\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Ratio = %f'%rat\n",
+ "print'(2) Loss J(v) = %.1f dB'%jv\n",
+ "print'(3) Loss A = %.2f dB'%A"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Ratio = 0.408248\n",
+ "(2) Loss J(v) = 10.9 dB\n",
+ "(3) Loss A = 15.07 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.4, page 233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=150*10**6 #frequency in Hz\n",
+ "c1=3*10**8 #speed of light\n",
+ "h11=60 #in metre\n",
+ "d11=2000 #in metre\n",
+ "d1=259.6 #in metre\n",
+ "b=2000 #in metre\n",
+ "a=250 #in metre\n",
+ "h21=80 #in metre\n",
+ "d21=7259 #in metre\n",
+ "c=7250 #in metre\n",
+ "\n",
+ "#Calculation\n",
+ "h=c1*f**-1 #wavelength\n",
+ "v1=h11*math.sqrt((2*(h*d1)**-1)+(1*d11**-1))\n",
+ "L1=6.9+20*math.log10(math.sqrt((v1-0.1)**2+1)+v1-0.1) #path diffraction loss\n",
+ "v2=h21*math.sqrt((2*(h*d11)**-1)+(1*d21**-1))\n",
+ "L2=6.9+20*math.log10(math.sqrt((v2-0.1)**2+1)+v2-0.1) #path diffraction loss\n",
+ "\n",
+ "#Results\n",
+ "print'Diffraction loss L1 = %.2f dB'%L1\n",
+ "print' L2 = %.2f dB'%L2\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Diffraction loss L1 = 24.79 dB\n",
+ " L2 = 19.12 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 115
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.5, page 239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=450*10**6 #frequency in Hz\n",
+ "q1=1.282 #cumulative distribution value\n",
+ "q2=1.645 #cumulative distribution value\n",
+ "\n",
+ "#Calculation\n",
+ "sg=3.8+1.6*math.log10(450) #standard deviation\n",
+ "fm1=q1*sg #fade margin\n",
+ "fm2=q2*sg #fade margin\n",
+ "fm=fm2-fm1 #gain\n",
+ "#Results\n",
+ "print'Antenna gain = %.2f dB'%fm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Antenna gain = 2.92 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6, page 240"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "q90=1.282 #cumulative distribution value of 90%\n",
+ "sl=8 #standard deviation\n",
+ "q97=1.881 #cumulative distribution value of 97%\n",
+ "pt=5 #transmitter power\n",
+ "\n",
+ "#Calculation\n",
+ "fm=q90*sl #fade margin\n",
+ "fm1=q97*sl #fade margin\n",
+ "p=fm1-fm #power in dB\n",
+ "p1=pt*10**(p/10) #power in watt\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Fade margin for received signal = %.3f dB'%fm\n",
+ "print'(2) New transmitter power = %d W'%p1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Fade margin for received signal = 10.256 dB\n",
+ "(2) New transmitter power = 15 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7, page 241"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "d= 50*10**3 #distance in m\n",
+ "\n",
+ "#Calculation\n",
+ "sl1=5.3 #location standard deviation\n",
+ "st1=3 #time standard deviation\n",
+ "sl2=6.2 #location standard deviation\n",
+ "st2=2 #time standard deviation\n",
+ "sv=math.sqrt(sl1**2+st1**2) #total standard deviation of VHF\n",
+ "su=math.sqrt(sl2**2+st2**2) #total standard deviation of UHF\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'(1)for VHF, sigmaL = %.1f dB '%sl1\n",
+ "print' sigmaT = %.1f dB '%st1\n",
+ "print' for UHF, sigmaL = %.1f dB '%sl2\n",
+ "print' sigmaT = %.1f dB '%st2\n",
+ "print'(3) Standard deviation values, sigmaVHF = %.1f dB'%sv\n",
+ "print' sigmaUHF = %.1f dB'%su"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1)for VHF, sigmaL = 5.3 dB \n",
+ " sigmaT = 3.0 dB \n",
+ " for UHF, sigmaL = 6.2 dB \n",
+ " sigmaT = 2.0 dB \n",
+ "(3) Standard deviation values, sigmaVHF = 6.1 dB\n",
+ " sigmaUHF = 6.5 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.9, page 245"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "d=5 #in dB\n",
+ "h=20 #Transmitter initial height\n",
+ "\n",
+ "#Calculation\n",
+ "ht=h*10**(0.25) #Transmitter ultimate antenna height\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Antenna Height = %.2f m'%round(ht)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Antenna Height = 36.00 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.10, page 246"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=1800*10**6 #frequency in Hz\n",
+ "c=3*10**8 #speed of light\n",
+ "\n",
+ "#Calculation\n",
+ "h=c*f**-1 #wavelength\n",
+ "hv=20*h #in metre\n",
+ "dh=10*h #in metre\n",
+ "\n",
+ "#Results\n",
+ "print'hv = %.2f m '%hv\n",
+ "print'dh = %.2f m '%dh"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "hv = 3.33 m \n",
+ "dh = 1.67 m \n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.11, page 262"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "p1=20 #transmitter power\n",
+ "g=6 #gain\n",
+ "h1=20 #height in metre\n",
+ "\n",
+ "#Calculation\n",
+ "ct=p1/10 #Power gain\n",
+ "ch=(h1*30**-1)**2 #height gain\n",
+ "cg=g*4**-1 #antenna gain\n",
+ "co=10*math.log10(ct*ch*cg) #Total effects\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Power gain, Ct = %.f'%ct\n",
+ "print' Height gain = %.2f'%ch\n",
+ "print' Antenna gain = %.1f'%cg\n",
+ "print'(2) Total effects = %.2f dB'%co"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Power gain, Ct = 2\n",
+ " Height gain = 0.44\n",
+ " Antenna gain = 1.5\n",
+ "(2) Total effects = 1.25 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.12, page 262"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "g1=10 #transmitter gain\n",
+ "ct=15 #power in watt\n",
+ " \n",
+ "\n",
+ "#Calculation\n",
+ "g2=g1-2.2 #gain in dBd\n",
+ "cg=g2-6 #Antenna gain\n",
+ "ct1=ct*10**-1\n",
+ "ct2=10*math.log10(ct1) #Power gain\n",
+ "ch=(ct*30**-1)**2 \n",
+ "ch1=10*math.log10(ch) #Height gain\n",
+ "ct3=ct1*0.5\n",
+ "ct4=10*math.log10(ct3)\n",
+ "co=ct4+cg+ch1 #Total effects\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Power gain, Ct = %.2f'%ct2\n",
+ "print' Height gain = %.2f'%ch1\n",
+ "print' Antenna gain = %.1f'%cg\n",
+ "print'(2) Total effects = %.2f dB'%co\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Power gain, Ct = 1.76\n",
+ " Height gain = -6.02\n",
+ " Antenna gain = 1.8\n",
+ "(2) Total effects = -5.47 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 52
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.13, page 265"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "sr=-106 #Receiver sensitivity\n",
+ "f=8 #Fade margin\n",
+ "cl=6 #Coupler loss\n",
+ "dl=1 #Duplexer Loss\n",
+ "bf=6.5 #BTS feeder loss\n",
+ "ba=12 #BTS antenna gain\n",
+ "pl=138 #Path loss\n",
+ "pg=15 #Pathlength in km\n",
+ "ta=2 #Terminal antenna gain\n",
+ "tf=0.5 #Terminal feeder loss\n",
+ "\n",
+ "#Calculation\n",
+ "prm=sr+f #minimum received power\n",
+ "ptb=prm+cl+dl+bf-ba+pl-ta+tf #BTS transmitter power in dbBm\n",
+ "pw=10**((ptb-30)/10)\n",
+ "\n",
+ "#Results\n",
+ "print'BTS transmitter power = %.2f dBm'%ptb\n",
+ "print' = %d W'%pw\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "BTS transmitter power = 40.00 dBm\n",
+ " = 10 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 59
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.14, page 265"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "pm=2 #transmitter power\n",
+ "ld=1 #Duplexer losses\n",
+ "lp=138 #Path loss\n",
+ "lfm=0.5 #terminal feeder losses\n",
+ "lfb=6.5 #transmitter feeder losses\n",
+ "gt=12 #BTS transmitter antenna gain\n",
+ "gr=2 #BTS receiver antenna gain\n",
+ "i=3\n",
+ "bs=-110 #BTS receiver sensitivity\n",
+ "\n",
+ "#Calculation\n",
+ "ptm=10*math.log10(pm*10**3)\n",
+ "prb=ptm-ld-lp-lfm-lfb+gt+gr\n",
+ "pr=prb+i #BTS received power\n",
+ "fm=pr-bs #fade margin\n",
+ "\n",
+ "#Results\n",
+ "print'BTS received power = %.1f dBm'%pr\n",
+ "print'Fade margin = %.1f dB'%fm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "BTS received power = -96.0 dBm\n",
+ "Fade margin = 14.0 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.15, page 265"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "t1=25 #terminal transmitter power \n",
+ "t2=2 #terminal transmitter power \n",
+ "gd=3 #correction factor of receiver antennas\n",
+ "lc=5 #coupler loss\n",
+ "prm=-105 #receiver sensitivity\n",
+ "prb=-110 #receiver sensitivity\n",
+ "\n",
+ "#Calculation\n",
+ "ptb=10*math.log10(t1*10**3)\n",
+ "ptm=10*math.log10(t2*10**3)\n",
+ "p=ptb-ptm #Transmitting gain in downlink\n",
+ "ga=prm-prb #Receiving gain in uplink\n",
+ "tg=gd+ga+lc #total gain on the uplink \n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'Transmitting gain in downlink = %.1f dBm'%p\n",
+ "print'Receiving gain in uplink = %.1f dBm'%ga\n",
+ "print'total gain on the uplink = %.1f dBm'%tg"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Transmitting gain in downlink = 11.0 dBm\n",
+ "Receiving gain in uplink = 5.0 dBm\n",
+ "total gain on the uplink = 13.0 dBm\n"
+ ]
+ }
+ ],
+ "prompt_number": 61
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.16, page 269"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=450 #frequency in MHz\n",
+ "d=25 #distance in m\n",
+ "hb=30\n",
+ "hm=5\n",
+ "\n",
+ "#Calculation\n",
+ "fsl=32.4+(20*math.log10(f))+(20*math.log10(d)) #free space loss\n",
+ "lp=120+(40*math.log10(d))-(20*math.log10(hb))-(20*math.log10(hm)) #path loss\n",
+ "lm=76.3-10*math.log10(hm)\n",
+ "l=(40*math.log10(25))+(20*math.log10(f))-(20*math.log10(hb))+lm #path loss based on the clutter factor model\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Free space loss = %.1f dB'%fsl\n",
+ "print'(2) Loss = %.1f dB'%lp\n",
+ "print'(3) Loss based on clutter factor = %.1f dB'%l\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Free space loss = 113.4 dB\n",
+ "(2) Loss = 132.4 dB\n",
+ "(3) Loss based on clutter factor = 148.7 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 62
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.17, page 271"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "pt=30 #transmitter power in watt\n",
+ "d=15 #distance in km\n",
+ "gt=3 #transmitter gain\n",
+ "ht=30 #transmitter height in m\n",
+ "hr=4 #receiver height in m\n",
+ "no=3.77*10**14\n",
+ "\n",
+ "#Calculation\n",
+ "gt1=10**(gt*10**-1)\n",
+ "pt1=gt1*pt\n",
+ "e=88*math.sqrt(pt1)*pt*hr/(2*d**2) #Field strength\n",
+ "pr1=(e**2)/(2*no) #Recieved power\n",
+ "\n",
+ "#Results\n",
+ "print'Field strength = %f V/m'%e\n",
+ "print'Recieved power = %.2f pW'%(pr1*10**12)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Field strength = 181.556596 V/m\n",
+ "Recieved power = 43.72 pW\n"
+ ]
+ }
+ ],
+ "prompt_number": 63
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.18, page 274"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=420 #frequency in Hz\n",
+ "h1=40 #height in m\n",
+ "h2=5 #height in m\n",
+ "d=15 #distance in km\n",
+ "\n",
+ "#Calculation\n",
+ "A=69.55+26.16*math.log10(f)-13.82*math.log10(h1) #Hata parameters\n",
+ "B=44.9-6.55*math.log10(h1)\n",
+ "C=2*(math.log10(f*28**-1))**2+5.4\n",
+ "D=4.78*(math.log10(420))**2-18.33*math.log10(f)+40.94\n",
+ "E1=3.2*(math.log10(11.75*h2))**2-4.97\n",
+ "E2=(((1.1*math.log10(f))-0.7)*h2)-((1.56*math.log10(f))-0.8)\n",
+ "L3=A+B*math.log10(d)-D #in open area;\n",
+ "L2=A+B*math.log10(d)-C #in suburban area;\n",
+ "L1=A+B*math.log10(d)-E1 #in large cities;\n",
+ "L11=A+B*math.log10(d)-E2 #in small cities;\n",
+ "\n",
+ "#Results\n",
+ "print'In large cities L1 = %.2f dB'%L1\n",
+ "print'In small cities L1 = %.2f dB'%L11\n",
+ "print'In suburban area L2 = %.2f dB'%L2\n",
+ "print'In open area L2 = %.2f dB'%L3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In large cities L1 = 151.45 dB\n",
+ "In small cities L1 = 148.86 dB\n",
+ "In suburban area L2 = 148.33 dB\n",
+ "In open area L2 = 130.75 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 76
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.19, page 275"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=1800 #frequency in MHz\n",
+ "d=10 #distance in m\n",
+ "hb=40\n",
+ "hm=3\n",
+ "A=132.57 #Hata model data\n",
+ "B=34.4 #Hata model data\n",
+ "\n",
+ "#Calculation\n",
+ "E2=(((1.1*math.log10(f))-0.7)*hm)-((1.56*math.log10(f))-0.8)\n",
+ "lp=46.3+33.9*math.log10(f)-13.82*math.log10(hb)+(44.9-6.55*math.log10(hb)-E2+hm)\n",
+ "L=A+B+-E2\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'Path loss based on COST\u2013Hata model,'\n",
+ "print' Lp = %.2f dB'%lp\n",
+ "print'Path loss based on Hata model,'\n",
+ "print' Lp = %.2f dB'%L"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Path loss based on COST\u2013Hata model,\n",
+ " Lp = 167.56 dB\n",
+ "Path loss based on Hata model,\n",
+ " Lp = 162.61 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 79
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.20, page 277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "pt=20 #transmitter power in watt\n",
+ "Hb=30 #in metre\n",
+ "Hm=3 #in metre\n",
+ "gt=14.2 #trasmitter gain in dB\n",
+ "gr=0.2 #receiver gain in dB\n",
+ "f=450 #frequency in MHz\n",
+ "gm=-2 #in dBd\n",
+ "gr2=-2.2 #in dBi\n",
+ "r1=10 \n",
+ "n=20\n",
+ "hb=10\n",
+ "hm=10\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "gt1=gt+gr2\n",
+ "pr1=-62-38*math.log10(r1)-20*math.log10(f*900**-1)+7 #received signal level in suburban\n",
+ "pr2=-64-43*math.log10(r1)-20*math.log10(f*900**-1)+7 #received signal level in urban\n",
+ "ao=10*math.log10(2)+(gr2-6) #in dB (wrong value calculated in textbook)\n",
+ "pr11=-62-38*math.log10(r1)-20*math.log10(f*900**-1)+ao #received signal level in rural\n",
+ "pr22=-64-43*math.log10(r1)-20*math.log10(f*900**-1)+ao #received signal level in cities\n",
+ "ptd=10*math.log10(pt*10**3) #in dBm\n",
+ "lp1=ptd-pr11 #Path loss in rural area\n",
+ "lp2=ptd-pr22 #Path loss in cities area\n",
+ "\n",
+ "#Results\n",
+ "print'(2) In the suburban area, Pr = %.1f dBm'%pr1\n",
+ "print' In the urban area, Pr = %.1f dBm'%pr2\n",
+ "print'(3) Path loss in rural area Lp = %.1f dB'%lp1 #(wrong value calculated in textbook)\n",
+ "print' Path loss in cities area Lp = %.1f dB'%lp2 #(wrong value calculated in textbook)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(2) In the suburban area, Pr = -87.0 dBm\n",
+ " In the urban area, Pr = -94.0 dBm\n",
+ "(3) Path loss in rural area Lp = 142.2 dB\n",
+ " Path loss in cities area Lp = 149.2 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 93
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter7_1.ipynb b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter7_1.ipynb
new file mode 100755
index 00000000..87872c97
--- /dev/null
+++ b/Propagation_Engineering_in_Wireless_Communications_by_Abdollah_Ghasemi_/Chapter7_1.ipynb
@@ -0,0 +1,750 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:15fa6e92d67920db2584677dc6c97feec6c8d014491d8cba470fcffb410d752b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Line of Sight Propagation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1, page 293"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "h=200 #height in m\n",
+ "d=30*10**3 #distance in km\n",
+ "R=40*10**-6 #height in km\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "phi=math.atan(h*d**-1) # in radian\n",
+ "phi1=phi*180/math.pi # in degree\n",
+ "n=math.cos(phi1)\n",
+ "r=round(n)/R #radius\n",
+ "\n",
+ "#Results\n",
+ "\n",
+ "print'Radius = %.1f km'%r\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Radius = 25000.0 km\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2, page 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "h=500 #height in m\n",
+ "a=0.000315\n",
+ "b=0.0001361\n",
+ "Re=6370000 #radius of earth in m\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "n=1+(a*math.exp(-b*h)) \n",
+ "n1=(n-1)*10**6 #Refraction index\n",
+ "c=(a*b*math.exp(-b*h))\n",
+ "R=1/c #Radius of path curvature in km\n",
+ "d=1-(Re/R)\n",
+ "K=1/d #K-factor\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Refraction index = %d '%n1\n",
+ "print'(2) Radius of path curvature = %d kM'%(R/10**3)\n",
+ "print'(3) K-factor = %.3f'%K "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Refraction index = 294 \n",
+ "(2) Radius of path curvature = 24968 kM\n",
+ "(3) K-factor = 1.343\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3, page 299"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "k1=1.3 #K-factor\n",
+ "k2=0.7 #K-factor\n",
+ "H1=1200 #sea level in m\n",
+ "H2=1400 #sea level in m\n",
+ "re=6370*10**3 #radius of earth in m\n",
+ "f=15*10**9 #frequency in Hz\n",
+ "a1=0.6\n",
+ "d1=15*10**3 #distance in m\n",
+ "d2=20*10**3 #distance in m\n",
+ "c=3*10**8 #speed of light\n",
+ "d=30*10**3 #distance in m\n",
+ "h2=25.24 \n",
+ "r2=11.55\n",
+ "a2=0.3\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "h1=500*d1*d2/(k1*re)\n",
+ "h=c*f**-1\n",
+ "r1=math.sqrt((d1*d2*h)/d)\n",
+ "H11=H1+h1+a1*r1 #in meter\n",
+ "H22=H2+h2+a2*r2 #in meter\n",
+ "\n",
+ "#Results\n",
+ "print'(1) H1 = %d m'%H11 #wrong calculation in textbook\n",
+ "print'(2) H2 = %d m'%H22\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) H1 = 19322 m\n",
+ "(2) H2 = 1428 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.4, page 302"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "hr=-1 #obstacle height and fresnel radius ratio\n",
+ "\n",
+ "#Calculation\n",
+ "Ad=-20*hr+10 #Diffraction loss in dB\n",
+ "Ad2=16 #from fig 7.8\n",
+ "Ad3=43\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Obstacle loss = %.1f dB'%Ad\n",
+ "print'(2) Knife edge obstacle = %.1f dB'%Ad2\n",
+ "print'(3) Rounded obstacle = %.1f dB'%Ad3\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Obstacle loss = 30.0 dB\n",
+ "(2) Knife edge obstacle = 16.0 dB\n",
+ "(3) Rounded obstacle = 43.0 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5, page 306"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "d1=10 #distance in km\n",
+ "d2=25 #distance in km\n",
+ "re=6370 #earth radius in km \n",
+ "k=0.5 #climatic factor\n",
+ "f=4*10**9 #frequency in Hz\n",
+ "c=3*10**8 #speed of light\n",
+ "d=35 #distance in km\n",
+ "h3=400 #height in m\n",
+ "\n",
+ "#Calculation\n",
+ "ho=(500*d1*d2)/(k*re) #Earth buldge in m\n",
+ "h=c*f**-1 #wavelength in m\n",
+ "r1=math.sqrt(d1*10**3*d2*10**3*h*(d*10**3)**-1) #fresnel radius\n",
+ "amsl=h3+ho+13.9 #AMSL\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Earth buldge = %.2f m'%ho\n",
+ "print'(2) Fresnel radius = %.1f m'%r1\n",
+ "print'(3) AMSL = %.1f m '%amsl"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Earth buldge = 39.25 m\n",
+ "(2) Fresnel radius = 23.1 m\n",
+ "(3) AMSL = 453.1 m \n"
+ ]
+ }
+ ],
+ "prompt_number": 55
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.6, page 309"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "pt=500 #Transmitter power in mW\n",
+ "gt=42 #transmitter antenna gain in dB\n",
+ "gr=44 #receiver antenna gain in dB\n",
+ "lbt=2.6 #transmitter branching loss in dB\n",
+ "lbr=3 #receiver branching loss in dB\n",
+ "flt=45 #transmitter feeder length\n",
+ "flr=35 #receiver feeder length\n",
+ "fls=6.5 #feeder loss\n",
+ "prx=-72 #Receiver sensitivity\n",
+ "d=30 #path distance in km\n",
+ "f=8.4 #frequency in ghz\n",
+ "\n",
+ "#Calculation\n",
+ "ptx=10*math.log10(pt) #transmitter threshold level\n",
+ "lft=flt*fls/100\n",
+ "lfr=flr*fls/100\n",
+ "eirp=ptx+gt-lbt-lft #Transmitter effective power\n",
+ "sg=ptx-prx\n",
+ "fsl=92.4+20*math.log10(f)+20*math.log10(d)\n",
+ "rsl=ptx+gt+gr-fsl-lft-lfr-lbt-lbr\n",
+ "fm=rsl-prx\n",
+ "\n",
+ "#Results\n",
+ "print'EIRP = %.2f dBm'%eirp\n",
+ "print'SG = %.2f dBm'%sg\n",
+ "print'FSL = %.2f dB'%fsl\n",
+ "print'RSL = %.2f dBm'%rsl\n",
+ "print'FM = %.2f dB'%fm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "EIRP = 63.46 dBm\n",
+ "SG = 98.99 dBm\n",
+ "FSL = 140.43 dB\n",
+ "RSL = -38.24 dBm\n",
+ "FM = 33.76 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7, page 315"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "f=15 #frequency in GHz\n",
+ "f1=18 #frequency in GHz\n",
+ "R=50 #rain intensity\n",
+ "ah=1.154\n",
+ "kh=0.0367\n",
+ "d=20 #distance in kM\n",
+ "\n",
+ "#Calculation\n",
+ "yr=kh*R**ah\n",
+ "do=35*math.exp(-0.015*R) #distance in kM\n",
+ "de=d/(1+(d/do)) #distance in kM\n",
+ "Ao=yr*de #Rain Loss in dB\n",
+ "phi=(f**2)/(1+10**-4*f**2)\n",
+ "phi1=(f1**2)/(1+10**-4*f1**2)\n",
+ "H=1.12*10**-3*((phi1/phi)**0.5)*(phi*Ao)**0.55\n",
+ "Ah=Ao*(phi1/phi)**(1-H)\n",
+ "Av=(300*Ah)/(335+Ah) #Rain Loss in dB\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Rain Loss, A = %.2f dB'%Ao\n",
+ "print'(2) rain loss for vertical polarization, Av = %.2f dB'%Av\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Rain Loss, A = 30.34 dB\n",
+ "(2) rain loss for vertical polarization, Av = 32.53 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8, page 322"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "A=99.8 #in percent\n",
+ "l=1250 #radio link in km\n",
+ "C=155*10**6 #in bps\n",
+ "T=24*60*60 #Total measurement time\n",
+ "\n",
+ "#Calculation\n",
+ "U=100-A\n",
+ "u=U/100\n",
+ "ue=u*l/2500\n",
+ "uep=ue*0.3 #propagation unavailability value\n",
+ "M=C*uep*T*10**-3 #number of errored bits due to propagation\n",
+ "\n",
+ "#Results\n",
+ "print'Maximum delay bit error per day = %d bits per day'%M\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum delay bit error per day = 4017600 bits per day\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9, page 324"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "h=24 #hours\n",
+ "m=60 #minutes\n",
+ "s=60 #seconds\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "dm=0.004*h*m*(1250*2500**-1) #Maximum degraded minutes\n",
+ "ses=0.00054*h*m*s*(1250*2500**-1) #Severely errored seconds\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Maximum degraded minutes per day = %.2f min'%dm\n",
+ "print'(2) Severely errored seconds per day = %.2f s'%ses"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Maximum degraded minutes per day = 2.88 min\n",
+ "(2) Severely errored seconds per day = 23.33 s\n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10, page 331"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "Aa=15 #Transmitter antenna discrimination\n",
+ "Ab=25 #Receiver antenna discrimination\n",
+ "AD=110 #path in km \n",
+ "s=35 #fading in dB\n",
+ "\n",
+ "#Calculation\n",
+ "Ad=20*math.log10(AD*CD**-1) #Distance discrimination\n",
+ "CD=30 #path in km \n",
+ "si=Aa+Ab+Ad #in dB\n",
+ "si2=si-s #in dB\n",
+ "\n",
+ "#Results\n",
+ "print'(1) S/I = %.1f dB'%si\n",
+ "print'(2) S/I = %.1f dB'%si2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) S/I = 51.3 dB\n",
+ "(2) S/I = 16.3 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.11, page 333"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "kq=2.6*10**-6 #geoclimatic coefficient\n",
+ "f=6 #frequency in GHz\n",
+ "d=45 #distance in Km\n",
+ "gc=0.098 #GC factor\n",
+ "ab=0.25 #geoclimatic factor\n",
+ "\n",
+ "#Calculation\n",
+ "po=kq*f*gc*d**3 #In country\n",
+ "po1=0.3*ab*(f*4**-1)*(d*50**-1)**3 #In mountainous area\n",
+ "\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'Fading occurrence probability'\n",
+ "print'(1) In country = %.2f'%po\n",
+ "print'(2) In mountainous area = %.3f'%po1\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Fading occurrence probability\n",
+ "(1) In country = 0.14\n",
+ "(2) In mountainous area = 0.082\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.12, page 340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "dn=70 #dN = 70\n",
+ "d1=1000 #height from sea level in m\n",
+ "d2=1400 #height from sea level in m\n",
+ "d=45 #radio link distance in km\n",
+ "\n",
+ "#Calculation\n",
+ "K=10**(-4.2-0.0029*-dn) #Climate factor\n",
+ "ep=(d2-d1)/d #magnitude of the path inclination\n",
+ "po=K*d**3*(1+ep)**(-1.2)*10**(0.033*6-1) #Fading occurrence probability\n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Climate factor K = %.4f = 10^-4'%K\n",
+ "print'(2) Fading occurrence probability Po = %.2f percent'%po\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Climate factor K = 0.0001 = 10^-4\n",
+ "(2) Fading occurrence probability Po = 0.10 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.13, page 342"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "fm=35 #fade margin\n",
+ "po=0.092 #fading occurrence probability\n",
+ "\n",
+ "#Calculation\n",
+ "pw=po*10**(-fm*10**-1) #deep fading occurrence \n",
+ "\n",
+ "\n",
+ "#Results\n",
+ "print'Deep fading occurrence probability, Pw = %.1f x 10^-5'%(pw*10**5)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Deep fading occurrence probability, Pw = 2.9 x 10^-5\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.14, page 343"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "d=20 #distance in kM\n",
+ "po=0.02 #fading occurrence probability at 20 Km\n",
+ "d1=25 #distance in kM\n",
+ "d2=40 #distance in kM\n",
+ "fm1=30 #link in kM\n",
+ "fm2=35 #link in kM\n",
+ "fm3=40 #link in kM\n",
+ "tr=30*24*60 \n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "po1=po*(d1*d**-1)**3 #fading occurrence probability at 25 Km\n",
+ "po2=po*(d2/d)**3 #fading occurrence probability at 40 Km\n",
+ "pw=po*10**(-fm1*10**-1) #fade margin at 30\n",
+ "pw1=po1*10**(-fm2*10**-1) #fade margin at 35\n",
+ "pw2=po2*10**(-fm3/10) #fade margin at 40\n",
+ "u=pw+pw1+pw2 #total fade margin\n",
+ "to=u*tr #network outage time\n",
+ "\n",
+ "#Results\n",
+ "print'(1) Fading occurrence probability at 20 = %.2f'%po\n",
+ "print' Fading occurrence probability at 25 = %.3f'%po1\n",
+ "print' Fading occurrence probability at 40 = %.2f'%po2\n",
+ "print'(2) Fade margin at 30 = %.1f x 10^-5'%(pw*10**5)\n",
+ "print' Fade margin at 35 = %.2f x 10^-5'%(pw1*10**5)\n",
+ "print' Fade margin at 40 = %.2f x 10^-5'%(pw2*10**5)\n",
+ "print' Total fade margin = %.2f x 10**-5'%(u*10**5)\n",
+ "print'(3) Network outage time , To = %.3f min per month'%(to)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(1) Fading occurrence probability at 20 = 0.02\n",
+ " Fading occurrence probability at 25 = 0.039\n",
+ " Fading occurrence probability at 40 = 0.16\n",
+ "(2) Fade margin at 30 = 2.0 x 10^-5\n",
+ " Fade margin at 35 = 1.24 x 10^-5\n",
+ " Fade margin at 40 = 1.60 x 10^-5\n",
+ " Total fade margin = 4.84 x 10**-5\n",
+ "(3) Network outage time , To = 2.089 min per month\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.15, page 344"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Initialisation\n",
+ "ur=0.001 #unavailability budget for hypothetical circuit\n",
+ "d=50 #path-length in km\n",
+ "A=0.25 #area conditions\n",
+ "B=1 #area conditions\n",
+ "f=8 #frequency in GHz\n",
+ "\n",
+ "\n",
+ "#Calculation\n",
+ "pw=ur*(d*(d*d)**-1) #deep fading occurrence probability\n",
+ "po=6*10**-7*A*B*f*(d**3) #fading occurrence probability of desirable link\n",
+ "FM=-math.log10(pw/po)*10 #fade margin\n",
+ "\n",
+ "#Results\n",
+ "print'Fade margin = %.1f dB'%FM"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Fade margin = 38.8 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles/screenshots/diffusion_capacitance.png b/Semiconductor_Physics_and_Devices_Basic_Principles/screenshots/diffusion_capacitance.png
new file mode 100755
index 00000000..e03a94b8
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles/screenshots/diffusion_capacitance.png
Binary files differ
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles/screenshots/diffusion_current_density.png b/Semiconductor_Physics_and_Devices_Basic_Principles/screenshots/diffusion_current_density.png
new file mode 100755
index 00000000..0fc29d79
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles/screenshots/diffusion_current_density.png
Binary files differ
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles/screenshots/possible_arrangements.png b/Semiconductor_Physics_and_Devices_Basic_Principles/screenshots/possible_arrangements.png
new file mode 100755
index 00000000..57392c38
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles/screenshots/possible_arrangements.png
Binary files differ
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch1.ipynb b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch1.ipynb
new file mode 100755
index 00000000..f6303ef7
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch1.ipynb
@@ -0,0 +1,93 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e22d95f3ee08f7b0a433c3aa63972f991151630f2c62d91a472e6e249088f32f"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1: The Crystal Structure of Solids"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.1, Page 6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "a=5*10**-8 #a=5A = 5*10^-8cm\n",
+ "n=2\n",
+ "\n",
+ "#Calculations\n",
+ "d=n/a**3\n",
+ "\n",
+ "#Result\n",
+ "print \"the value of d in atoms per cm^3 is %.1e\"%d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of d in atoms per cm^3 is 1.6e+22\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.3, Page 8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "a1=5*10**-8# a=5A = 5*10^-8cm\n",
+ "n=2# number of atoms is 2\n",
+ "\n",
+ "#Calculations\n",
+ "d=n/(a1*a1*2**0.5)\n",
+ "\n",
+ "#Result\n",
+ "print \"the value of d in atoms per cm^2 is %.2e\"%d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of d in atoms per cm^2 is 5.66e+14\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch10.ipynb b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch10.ipynb
new file mode 100755
index 00000000..23b02b28
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch10.ipynb
@@ -0,0 +1,571 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:04f101c405ce9ab13d88a308cdd1b29cf5130cf855b380b042da216c45159099"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10: The Bipolar Transistor"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.1, Page 393"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "y=0.9967\n",
+ "\n",
+ "#Calculations\n",
+ "#NB/NC=z\n",
+ "z=(1./y)-1\n",
+ "\n",
+ "#Result\n",
+ "print \"NB/NE value = %f\"%z"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "NB/NE value = 0.003311\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.2, Page 394"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "DB=10#cm^2/s\n",
+ "tauB0=10**-7#sec\n",
+ "alphatau=0.9967\n",
+ "\n",
+ "#Calculations&Results\n",
+ "#(xB/LB)=z\n",
+ "z=math.acosh(1./alphatau)\n",
+ "print \"xB/LB = %.4f\"%z\n",
+ "\n",
+ "LB=math.sqrt(DB*tauB0)\n",
+ "print \"LB is %.e cm \"%LB\n",
+ "xB=z*10**-5\n",
+ "print \"xB is %.3f meter\"%(xB/10**-6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "xB/LB = 0.0814\n",
+ "LB is 1e-03 cm \n",
+ "xB is 0.814 meter\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.3, Page 395"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "Js0=10**-11#A/cm^2\n",
+ "Jr0=10**-8#A/cm^2\n",
+ "delta=0.9967\n",
+ "\n",
+ "#Calculations\n",
+ "VBE=2*k*T*math.log(delta*10**3/(1-delta))\n",
+ "\n",
+ "#Result\n",
+ "print \"VBE is %.3f V \"%VBE\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "VBE is 0.652 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.4, Page 395"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "DE=10#cm**2/s\n",
+ "DB=25#cm**2/s\n",
+ "xB=0.70*10**-6#m\n",
+ "xE=0.50*10**-6#m\n",
+ "NE=1*10**18#cm^-3\n",
+ "NB=1*10**16#cm^-3\n",
+ "VBE=0.65#V\n",
+ "tauB0=5*10**-7#s\n",
+ "tauE0=1*10**-7#s\n",
+ "Jr0=5*10**-8#A/cm62\n",
+ "pE0=2.25*10**2#cm**-3\n",
+ "nB0=2.25*10**4#cm**-3\n",
+ "LE=10**-3#cm\n",
+ "LB=3.54*10**-3#cm\n",
+ "\n",
+ "#Calculations&Results\n",
+ "gamma1=1./(1+(pE0*DE*LB*math.tanh(0.0198))/(nB0*DB*LE*math.tanh(0.050)))\n",
+ "print \"gamma1 is= %.f\"%gamma1\n",
+ "alphatau=1./math.cosh(xB/LB)\n",
+ "print \"alphatau is=%.4f \"%alphatau\n",
+ "Js0=(e*DB*nB0)/(LB*math.tanh(xB/LB))\n",
+ "print \"Js0 is %.2e A/cm^2\"%Js0\n",
+ "delta=1/(1+(Jr0/Js0)*math.exp(-VBE/(2*0.0259)))\n",
+ "print \"delta = %f\"%delta\n",
+ "a=gamma1*alphatau*delta\n",
+ "print \"a is= %.5f\"%a\n",
+ "beta1=a/(1-a)\n",
+ "print \"beta1 = %.f\"%beta1 #ans varies cause of long no.of digits"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gamma1 is= 1\n",
+ "alphatau is=1.0000 \n",
+ "Js0 is 1.29e-07 A/cm^2\n",
+ "delta = 0.999999\n",
+ "a is= 0.99442\n",
+ "beta1 = 178\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.5, Page 398"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300. #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "NB=5.*10**16#cm^-3\n",
+ "NC=2.*10**15#cm^-3\n",
+ "epsilons=11.7\n",
+ "eps=8.85*10**-14 #V\n",
+ "ni=1.5*10**10 #cm^-3\n",
+ "x=0.70*10**-6\n",
+ "a=9.96*10**-12#/solving the equation\n",
+ "\n",
+ "#Calculations&Results\n",
+ "Vbi=((k*T))*math.log((NB*NC)/ni**2)\n",
+ "print \"Vbi is %.3f V \"%Vbi\n",
+ "\n",
+ "#for \n",
+ "VCB=2 #V\n",
+ "xdB1=math.sqrt(a*(Vbi+VCB))\n",
+ "print \"xdB is %.3f micro-meter\"%(xdB1/10**-6)\n",
+ "xB1=x-xdB1\n",
+ "print \"xB is %.3f meter\"%(xB1/10**-6) #textbook ans are wrong\n",
+ "\n",
+ "#for \n",
+ "VCB=10 #V\n",
+ "xdB2=math.sqrt(a*(Vbi+VCB))\n",
+ "print \"xdB is %.3f meter\"%(xdB2/10**-6)\n",
+ "xB2=x-xdB2\n",
+ "print \"xB is %.3f meter\"%(xB2/10**-6) #textbook ans are wrong\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vbi is 0.693 V \n",
+ "xdB is 5.179 micro-meter\n",
+ "xB is -4.479 meter\n",
+ "xdB is 10.320 meter\n",
+ "xB is -9.620 meter\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.6, Page 399"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "Db = 25 #cm^2/s\n",
+ "VBE = 0.60 #V\n",
+ "ni = 1.5*10**10\n",
+ "Nb = 5*10**16\n",
+ "e = 1.6*10**-19 \n",
+ "kT = 0.0259\n",
+ "#Assumptions\n",
+ "xb = 0.648 #um\n",
+ "Vcb = 2 #V\n",
+ "Vce1 = 2.6 #V\n",
+ "\n",
+ "#Calculations\n",
+ "nbo = ni**2/Nb #cm^3\n",
+ "Jc = ((e*nbo*Db)*math.exp(VBE/kT))/0.648*10**-4\n",
+ "Jc1 = round((Jc/10**-8),2)\n",
+ "#Let,\n",
+ "xb = 0.597 #um\n",
+ "Vcb = 10 #V\n",
+ "Vce2 = 10.6 #V\n",
+ "Jc2 = 3.47 #A/cm^2\n",
+ "Va =(Jc1*(Vce2-Vce1)/(Jc2-Jc1))-Vce1\n",
+ "\n",
+ "#Result\n",
+ "print \"The Early voltage is %.f V\"%Va"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Early voltage is 92 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.7, Page 404"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300# K\n",
+ "k=1.3806*10**-23# JK^-1\n",
+ "e=1.6*10**-19# eV\n",
+ "ni=1.5*10**10# cm^-3\n",
+ "NE=10**18# cm^-3\n",
+ "\n",
+ "#Calculations&Results\n",
+ "pE01=(ni*ni)/NE# neglecting bandgap\n",
+ "print \"pE01 the value of pE01 is %.2e cm^-3\"%pE01\n",
+ "NE=10**19# cm^-3\n",
+ "pE03=(ni*ni)/NE# neglecting bandgap\n",
+ "print \"pE03 the value of pE03 is %.2e cm^-3\"%pE03\n",
+ "pE02=((ni*ni)/NE)*math.exp(0.030/(k*(T/e)))# including bandgap\n",
+ "print \"pE02 the value of pE02 is %.2e cm^-3 \"%pE02\n",
+ "pE04=((ni*ni)/NE)*math.exp(0.1/(k*(T/e)))# including bandgap\n",
+ "print \"pE04 the value of pE04 is %.2e cm^-3\"%pE04"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pE01 the value of pE01 is 2.25e+02 cm^-3\n",
+ "pE03 the value of pE03 is 2.25e+01 cm^-3\n",
+ "pE02 the value of pE02 is 7.17e+01 cm^-3 \n",
+ "pE04 the value of pE04 is 1.07e+03 cm^-3\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.8, Page 409"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300# K\n",
+ "k=1.3806*10**-23# JK^-1\n",
+ "e=1.6*10**-19# eV\n",
+ "epsilon=8.85*10**-14 #V\n",
+ "eps=11.7\n",
+ "NB=10**16#cm^-3\n",
+ "Vpt=25#V\n",
+ "WB=0.5*10**-4\n",
+ "\n",
+ "#Calculations&Results\n",
+ "#Vpt=(e*WB**2*NB*(NC+NB))/(2*epsilon*eps*NC)\n",
+ "a=(Vpt*2*epsilon*eps)/(e*WB**2*NB)\n",
+ "NC=NB/(a-1)\n",
+ "print \"NC is %.2e cm^-3 \"%NC\n",
+ "#Neglecting Vbi comapred to Vr,\n",
+ "xb = ((2*eps*epsilon*Vpt*NB)/(e*NC*(NB+NC)))**0.5\n",
+ "print \"xb is %.2f um\"%(xb/10**-4)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "NC is 8.37e+14 cm^-3 \n",
+ "xb is 5.97 um\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.9, Page 412"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "NB=10**17#cm^-3\n",
+ "beta=100\n",
+ "BVCEO=15#V\n",
+ "\n",
+ "#Calculations\n",
+ "BVCBO=(beta)**(1./3)*BVCEO\n",
+ "\n",
+ "#Result\n",
+ "print \"BVcbo = %.1f V \"%BVCBO"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "BVcbo = 69.6 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.10, Page 416"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "alphaF=0.99\n",
+ "alphaR=0.20\n",
+ "Ic=1#mA\n",
+ "IB=0.050#mA\n",
+ "\n",
+ "#Calculations\n",
+ "Vcesat=k*T*math.log(((Ic*(1-alphaR)+IB)*alphaF)/((alphaF*IB-(1-alphaF)*Ic)*alphaR))\n",
+ "\n",
+ "#Result\n",
+ "print \"VCEsat is %.3f V \"%Vcesat"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "VCEsat is 0.121 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.12, Page 425"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "IE=1*10**-3#A\n",
+ "Cje=1*10**-12#F\n",
+ "xB=0.5*10**-4#cm\n",
+ "Dn=25# cm2/s\n",
+ "xdc=2.4*10**-4#cm\n",
+ "vs=10**7\n",
+ "rc=20#ohm\n",
+ "Cu=0.1*10**-12#F\n",
+ "Cs=0.1*10**-12#F\n",
+ "beta=100\n",
+ "\n",
+ "#Calculations&Results\n",
+ "re1=(k*T)/IE\n",
+ "print \"re1 is %.1f ohm\"%re1\n",
+ "taue=re1*Cje\n",
+ "print \"taue is %.1f ps \"%(taue/10**-12)\n",
+ "taub=xB**2/(2*Dn)\n",
+ "print \"taub is %.f ps \"%(taub/10**-12)\n",
+ "taub1=xdc/vs\n",
+ "print \"taub is %.f ps\"%(taub1/10**-12)\n",
+ "tauc=rc*(Cu+Cs)\n",
+ "print \"tauc is %.f ps \"%(tauc/10**-12)\n",
+ "tauec=taue+taub+taub1+tauc\n",
+ "print \"tauec is %.1f ps \"%(tauec/10**-12)\n",
+ "ftau=1/(2*math.pi*tauec)\n",
+ "print \"ftau is %.2f GHz \"%(ftau/10**9)\n",
+ "fbeta=ftau/beta\n",
+ "print \"fbeta is %.1f MHz \"%(fbeta/10**6)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "re1 is 25.9 ohm\n",
+ "taue is 25.9 ps \n",
+ "taub is 50 ps \n",
+ "taub is 24 ps\n",
+ "tauc is 4 ps \n",
+ "tauec is 103.9 ps \n",
+ "ftau is 1.53 GHz \n",
+ "fbeta is 15.3 MHz \n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch11.ipynb b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch11.ipynb
new file mode 100755
index 00000000..9078c6b1
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch11.ipynb
@@ -0,0 +1,557 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c1c810d2f38f7b9cb51ef7b22305db0117901d4407ff775e7ec2ddd09734e205"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Fundamentals of the Metal-Oxide-Semiconductor Field-Effect Transistor"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.1, Page 456"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300#K\n",
+ "Na=10**16# cm^-3\n",
+ "ni=1.5*10**10 # cm^-3\n",
+ "epsilon0=8.85*10**-14# F/m\n",
+ "epsilons=11.7\n",
+ "e=1.6*10**-19# eV\n",
+ "Vt=0.0259 # V\n",
+ "\n",
+ "#Calculations&Results\n",
+ "phifp=Vt*math.log(Na/ni)\n",
+ "print \"the value of phisp is %.3f V\"%phifp\n",
+ "xdT=(4*(epsilons*epsilon0)*phifp/(e*Na))**0.5\n",
+ "print \"the value of xdT is %.e meter\"%xdT"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of phisp is 0.347 V\n",
+ "the value of xdT is 3e-05 meter\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.2, Page 459"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "phim=3.20# v\n",
+ "x=3.25# v\n",
+ "Eg=1.11#eV\n",
+ "Na=10**14# cm^-3\n",
+ "k=1.3806*10**-23# JK^-1\n",
+ "T=300# K\n",
+ "ni=1.5*10**10# cm^-3\n",
+ "e=1.6*10**-19# eV\n",
+ "\n",
+ "#Calculations&Results\n",
+ "phifp=(((k*T)/e)*math.log(Na/ni))\n",
+ "print \"the value of phifp is %.3f V\"%phifp\n",
+ "phims=phim-(x+(Eg/2)+phifp)\n",
+ "print \"work function difference is %.2f V \"%phims"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of phifp is 0.228 V\n",
+ "work function difference is -0.83 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.3, Page 464"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Nd=10**16# cm^-3\n",
+ "tox=500*10**-8# a=500A =500*10^-8 cm\n",
+ "Qss=10**11# electronic charge per cm\n",
+ "phims=-1.1# V\n",
+ "e=1.6*10**-19# eV\n",
+ "epsilonox=3.9\n",
+ "epsilon0=8.85*10**-14# F/m\n",
+ "\n",
+ "#Calculations&Results\n",
+ "C=((epsilonox*epsilon0)/tox)\n",
+ "print \"the value of C is %.1e F/cm^2\"%C\n",
+ "Qss=10**11*e\n",
+ "print \"the value of Qss is %.1e C/cm^2\"%Qss\n",
+ "VFB=phims-(Qss/C)\n",
+ "print \"the value of VFB is %.2f V \"%VFB"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of C is 6.9e-08 F/cm^2\n",
+ "the value of Qss is 1.6e-08 C/cm^2\n",
+ "the value of VFB is -1.33 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.4, Page 467"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300# K\n",
+ "k=1.3806*10**-23# JK^-1\n",
+ "Na=3*10**16# cm^-3\n",
+ "Qss=10**11# cm^-2\n",
+ "VTN=0.65# V\n",
+ "phims=-1.13# V\n",
+ "epsilon0=8.85*10**-14# F/m\n",
+ "epsilons=11.7\n",
+ "epsilonox=3.9\n",
+ "ni=1.5*10**10# cm^-3\n",
+ "e=1.6*10**-19# eV\n",
+ "\n",
+ "#Calculations&Results\n",
+ "phifp=(((k*T)/e)*math.log(Na/ni))\n",
+ "print \"the value of phifp is %.3f V\"%phifp\n",
+ "xdT=(4*(epsilons*epsilon0)*phifp/(e*Na))**0.5\n",
+ "print \"the value of xdT is %.2f micro-meter\"%(xdT/10**-4)\n",
+ "QSD=e*Na*xdT #[QSD(max)]=e*Na*xdT\n",
+ "print \"the value of QSD is %.2e C.cm^2\"%QSD\n",
+ "tox=((VTN-phims-2*phifp)*(epsilonox*epsilon0))/(QSD-(Qss*e))\n",
+ "print \"tox is %.f A\"%(tox/10**-7)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of phifp is 0.376 V\n",
+ "the value of xdT is 0.18 micro-meter\n",
+ "the value of QSD is 8.64e-08 C.cm^2\n",
+ "tox is 50 A\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.5, Page 468"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300# K\n",
+ "k=1.3806*10**-23# JK^-1\n",
+ "Na=10**14# cm^-3\n",
+ "Qss=10**10# cm^-2\n",
+ "tox=500*10**-8# a=500A =500*10**-8 cm\n",
+ "phims=-0.83# V\n",
+ "epsilon0=8.85*10**-14# F/m\n",
+ "epsilons=11.7\n",
+ "epsilonox=3.9\n",
+ "ni=1.5*10**10# cm^-3\n",
+ "e=1.6*10**-19# eV\n",
+ "\n",
+ "#Calculations&Results\n",
+ "phifp=(((k*T)/e)*math.log(Na/ni))\n",
+ "print \"the value of phifp is %.3f V\"%phifp\n",
+ "xdT=(4*(epsilons*epsilon0)*phifp/(e*Na))**0.5\n",
+ "print \"the value of xdT is %.3f milli-m\"%(xdT/10**-3)\n",
+ "QSD=e*Na*xdT# [QSD(max)]=e*Na*xdT\n",
+ "print \"the value of QSD is %.2e C/cm^2\"%QSD\n",
+ "VTN=(QSD-(Qss*e))*(tox/(epsilonox*epsilon0))+phims+2*phifp# VTN=(QSD(max)-Qss)*(tox/epsilonox)+phims+2*phifp\n",
+ "print \"the value of VTN is %.3f V\"%VTN"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of phifp is 0.228 V\n",
+ "the value of xdT is 0.243 milli-m\n",
+ "the value of QSD is 3.89e-09 C/cm^2\n",
+ "the value of VTN is -0.341 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.6, Page 470"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300# K\n",
+ "k=1.3806*10**-23# JK^-1\n",
+ "Qss=10**10# cm^-2\n",
+ "tox=650*10**-8# tox=650A =650*10**-8 cm\n",
+ "epsilon0=8.85*10**-14# F/m\n",
+ "epsilons=11.7\n",
+ "epsilonox=3.9\n",
+ "ni=1.5*10**10# cm^-3\n",
+ "e=1.6*10**-19# eV\n",
+ "Nd=2.5*10**14# cm^-3\n",
+ "\n",
+ "#Calculations&Results\n",
+ "phifn=(((k*T)/e)*math.log(Nd/ni))#phifn=V1*log(Nd/ni)=((k*T)/e)*log(Nd/ni)\n",
+ "print \"the value of phifn is %.3f V \"%phifn\n",
+ "xdT=(4*(epsilons*epsilon0)*phifn/(e*Nd))**0.5\n",
+ "print \"the value of xdT is %.2f milli-meter \"%(xdT/10**-3)\n",
+ "QSD=e*Nd*xdT# [QSD(max)]=e*Na*xdT\n",
+ "print \"the value of QSD is %.2e C/cm^2\"%QSD\n",
+ "phims=-0.35# V\n",
+ "VTP=(-QSD-(Qss*e))*(tox/(epsilonox*epsilon0))+phims-(2*phifn)# VTP=(-QSD(max)-Qss)*(tox/epsilonox)+phims+2*phifn\n",
+ "print \"the value of VTP is %.3f V\"%VTP\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of phifn is 0.252 V \n",
+ "the value of xdT is 0.16 milli-meter \n",
+ "the value of QSD is 6.46e-09 C/cm^2\n",
+ "the value of VTP is -1.005 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.7, Page 477"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "espox=3.9\n",
+ "esp0=8.85*10**-14 \n",
+ "esp=11.7\n",
+ "tox=550*10**-8#550 Armstrong\n",
+ "Na=10**16#cm^-3\n",
+ "ni=1.5*10**10 #cm^-3\n",
+ "\n",
+ "#Calculations&Results\n",
+ "Cox=(espox*esp0)/tox\n",
+ "print \"oxide capacitance is %.2e F/cm^2 \"%Cox\n",
+ "\n",
+ "phi=(k*T)*math.log(Na/ni)\n",
+ "print \"mini capacitance is %.3f V \"%phi\n",
+ "\n",
+ "xdt=math.sqrt((4*esp*esp0*phi)/(e*Na))\n",
+ "print \"xdt is %.2e cm^-4 \"%xdt\n",
+ "\n",
+ "Cmin=(espox*esp0)/(tox+(espox/esp)*xdt)\n",
+ "print \"Cmin is %.2e F/cm^2 \"%Cmin\n",
+ "\n",
+ "a=Cmin/Cox\n",
+ "print \"ratio of Cmin to Cox is= %.3f\"%a\n",
+ "\n",
+ "Cfb=(espox*esp0)/(tox+(espox/esp)*math.sqrt((k*T*esp*esp0)/(e*Na)))\n",
+ "print \"Cfb in F/cm^2 is= %.2e\"%Cfb\n",
+ "\n",
+ "b=Cfb/Cox\n",
+ "print \"ratio of Cfb to Cox is = %.2f \"%b\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "oxide capacitance is 6.28e-08 F/cm^2 \n",
+ "mini capacitance is 0.347 V \n",
+ "xdt is 3.00e-05 cm^-4 \n",
+ "Cmin is 2.23e-08 F/cm^2 \n",
+ "ratio of Cmin to Cox is= 0.355\n",
+ "Cfb in F/cm^2 is= 5.03e-08\n",
+ "ratio of Cfb to Cox is = 0.80 \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.8, Page 495"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "Cox=6.9*10**-8#F/cm2\n",
+ "esp0=8.85*10**-14 \n",
+ "Vtau=0.65#V\n",
+ "VGS=5#V\n",
+ "L=1.25*10**-4#cm\n",
+ "u=650#cm**2/Vs\n",
+ "IDsat=4*10**-3#A\n",
+ "\n",
+ "#Calculations\n",
+ "W=(IDsat*2*L)/(u*Cox*(VGS-Vtau)**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"W is %.1f micro-meter\"%(W/10**-4)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "W is 11.8 micro-meter\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.9, Page 496"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "Cox=6.9*10**-8#F/cm2\n",
+ "esp0=8.85*10**-14 \n",
+ "Vtau=0.65#V\n",
+ "VGS1=1.5#V\n",
+ "VGS2=2.5#V\n",
+ "VDS=0.10#V\n",
+ "L=2*10**-6#cm\n",
+ "u=650#cm**2/Vs\n",
+ "ID1=35*10**-6#A\n",
+ "ID2=75*10**-6#A\n",
+ "W=15*10**-6#m\n",
+ "\n",
+ "#Calculations\n",
+ "un=(ID2-ID1)*L/(W*Cox*(VGS2-VGS1)*VDS)\n",
+ "\n",
+ "#Result\n",
+ "print \"un is %.f cm^2/Vs\"%un"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "un is 773 cm^2/Vs\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.10, Page 500"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300# K\n",
+ "Na=3*10**16# cm^-3\n",
+ "tox=500*10**-8# tox=500A =500*10**-8 cm\n",
+ "k=1.3806*10**-23# JK^-1\n",
+ "VSB=1# V\n",
+ "epsilon0=8.85*10**-14# F/m\n",
+ "epsilons=11.7\n",
+ "epsilonox=3.9\n",
+ "ni=1.5*10**10# cm^-3\n",
+ "e=1.6*10**-19# eV\n",
+ "\n",
+ "#Calculations&Results\n",
+ "phifp=(((k*T)/e)*math.log(Na/ni))# phifp=V1*log(Na/ni)=((k*T)/e)*log(Na/ni)\n",
+ "print \"the value of phifp is %.3f V\"%phifp\n",
+ "Cox=(epsilon0*epsilonox)/tox\n",
+ "print \"the value of Cox is %.1e F/cm^2\"%Cox\n",
+ "deltaVT=(math.sqrt(2*e*(epsilon0*epsilons)*Na))/Cox*((math.sqrt(2*phifp+VSB))-(math.sqrt(2*phifp)))\n",
+ "print \"the value of deltaVT is %.2f V\"%deltaVT"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of phifp is 0.376 V\n",
+ "the value of Cox is 6.9e-08 F/cm^2\n",
+ "the value of deltaVT is 0.66 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.11, Page 506"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "micron=400.# cm^2/V-s\n",
+ "L=4*10**-6# m\n",
+ "VT=1# V\n",
+ "VGS=3# V\n",
+ "\n",
+ "#Calculations\n",
+ "ftau=(micron*(VGS-VT))/(2*math.pi*L*L)\n",
+ "\n",
+ "#Result\n",
+ "print \"the value of fr = %.f MHz\"%(ftau/10**10)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of fr = 796 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch2.ipynb b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch2.ipynb
new file mode 100755
index 00000000..ebb803c6
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch2.ipynb
@@ -0,0 +1,150 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8575441dfc9f46104394a83a9c4613d36928a495b4284fab191e2ca7cb407033"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2: Introduction to Quantum Mechanics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1, Page 47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "lamda=0.708*10**-8# cm\n",
+ "h=6.625*10**-34# J*s Plank's constant\n",
+ "c=3.0*10**10# cm/s\n",
+ "e=1.6*10**-19# eV\n",
+ "\n",
+ "#Calculations&Results\n",
+ "E=(h*c)/lamda# E=hv=hc/lamda\n",
+ "print \"The value of E is %.2e J\"%E\n",
+ "E=E/e\n",
+ "print \"The value of E is %.2e eV\"%E"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of E is 2.81e-15 J\n",
+ "The value of E is 1.75e+04 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2,Page 49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "m=9.11*10**-31# kg*m/s\n",
+ "v=10**5#m/s\n",
+ "h=6.625*10**-34#js\n",
+ "\n",
+ "#Calculations&Results\n",
+ "p=m*v\n",
+ "print \"momentum is %.2e\"%p\n",
+ "lamda=h/p\n",
+ "print \"de broglie wavelength in meter is %.2e\"%(lamda)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "momentum is 9.11e-26\n",
+ "de broglie wavelength in meter is 7.27e-09\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3, Page 58"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=5*10**-10# a=5A = 5*10**-8cm\n",
+ "h=1.054*10**-34# J*s Planck's constant \n",
+ "m=9.11*10**-31# kg*m/s\n",
+ "e=1.6*10**-19# eV\n",
+ "\n",
+ "#Calculations&Results\n",
+ "print \"The energy levels are:\"\n",
+ "for n in range(1,4):\n",
+ " En=((h**2*n**2*math.pi**2)/(2*m*a**2))/e\n",
+ " print \"For n = %d, E = %.2f eV\"%(n,En)\n",
+ "\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The energy levels are:\n",
+ "For n = 1, E = 1.50 eV\n",
+ "For n = 2, E = 6.02 eV\n",
+ "For n = 3, E = 13.54 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch3.ipynb b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch3.ipynb
new file mode 100755
index 00000000..b7d823e5
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch3.ipynb
@@ -0,0 +1,312 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:a4a8c282676044dfd6400da6c666fcff06f011960e5dfabe01e8d9b4da3a4393"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3: Introduction to the Quantum Theory of Solids"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1, Page 59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "v1=10**5 #m per sec\n",
+ "deltav=0.01 #m per sec\n",
+ "m=9.11*10**-31# kg*m/s\n",
+ "e=1.6*10**-9 #Coulombs\n",
+ "\n",
+ "#calculations&Results\n",
+ "#deltaE=0.5*m*(v2**2-v1**2)\n",
+ "#deltav=v2-v1.............deltav<<v1\n",
+ "print \"The change in kinetic energy\"\n",
+ "deltaE=m*v1*deltav\n",
+ "print \"in J is %.2e\"%deltaE\n",
+ "deltaE=deltaE/e\n",
+ "print \"in eV is %.1e\"%deltaE"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The change in kinetic energy\n",
+ "in J is 9.11e-28\n",
+ "in eV is 5.7e-19\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.2, Page 68"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "P=10\n",
+ "a=5*10**-10 # a=5 Armstrong\n",
+ "h=1.054*10**-34\n",
+ "m=9.11*10**-31 #kg\n",
+ "\n",
+ "#Calculations&Results\n",
+ "#alpha*a=%pi\n",
+ "#sqrt((2*m*E2)/h**2)*a=pi\n",
+ "E2=(math.pi**2*h**2)/(2*m*a**2)\n",
+ "print 'E2= %.3e J'%E2\n",
+ "E2=E2*6.2415*10**18\n",
+ "print 'E2= %.2f eV'%E2\n",
+ "E1=1.053 #eV\n",
+ "AE=E2-E1\n",
+ "print 'AE= %.3f eV'%AE\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "E2= 2.407e-19 J\n",
+ "E2= 1.50 eV\n",
+ "AE= 0.449 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3, Page 84"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "m=9.11*10**-31 #kg\n",
+ "E=1.6*10**-19 #C\n",
+ "h=6.625*10**-34 #J sec\n",
+ "\n",
+ "#Calculations\n",
+ "N=(4*math.pi*(2*m)**(3./2)*2*E**(3./2))/(h**3*3)\n",
+ "\n",
+ "#Result\n",
+ "print 'E2= %.1e per meter**3'%N"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "E2= 4.5e+27 per meter**3\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.4, Page 90"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "y=10\n",
+ "Ni=10\n",
+ "gi=10\n",
+ "\n",
+ "#Calculations\n",
+ "#(gi-Ni)!=1\n",
+ "z=(math.factorial(gi)/math.factorial(Ni)*math.factorial(gi-Ni))\n",
+ "\n",
+ "#Result\n",
+ "print 'the possible number of ways of realizing a particular distribution = %.f'%z"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the possible number of ways of realizing a particular distribution = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.5, Page 90"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "gi=10\n",
+ "Ni=9\n",
+ "\n",
+ "#Calculations\n",
+ "x=gi-Ni\n",
+ "#factorial(gi-Ni)=1\n",
+ "z=(math.factorial(gi)/math.factorial(Ni)*math.factorial(gi-Ni))\n",
+ "\n",
+ "#Result\n",
+ "print 'possible arrangements = %.f'%z"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "possible arrangements = 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.6, Page 93"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "\n",
+ "#Calculations\n",
+ "#a=E-Ef\n",
+ "#a=3*k*T\n",
+ "#fF(E)=1/(1+exp(E-Ef/kT))\n",
+ "z=math.exp(3)\n",
+ "y=1./(1+z) #y=fF(E)\n",
+ "\n",
+ "#Result\n",
+ "print 'fF(E)=%.2f %%'%(y*100)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "fF(E)=4.74 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.7, Page 94"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "Ef=6.25 #eV\n",
+ "E=5.95 #eV\n",
+ "p=0.01\n",
+ "k= 8.617 *10**-5 #eV K^-1 \n",
+ "\n",
+ "#Calculations\n",
+ "#p=1-fF(E)\n",
+ "#fF(E)=1./(1+exp(E-Ef/kT))\n",
+ "#p=1-1./(1+exp(E-Ef/kT)) equation 1\n",
+ "x=E-Ef\n",
+ "y=(1./(1-p))-1 # solving the above equtaion 1\n",
+ "T=x/(k*math.log(y))\n",
+ "\n",
+ "#Result\n",
+ "print 'T=%.1f K\\n'%T"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "T=757.6 K\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch4.ipynb b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch4.ipynb
new file mode 100755
index 00000000..015affa3
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch4.ipynb
@@ -0,0 +1,598 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:62e87d797177990043f90f7ac32088931f6ffc8399bf27636f988030638fc3be"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: The Semiconductor in Equilibrium"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1, Page 108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "Nc=2.8*10**19 #cm**-3\n",
+ "k=8.617*10**-5 #eV K**-1 \n",
+ "\n",
+ "#Calculations&Results\n",
+ "#E=Ec\n",
+ "#a=Ec-Ef\n",
+ "a=-0.25\n",
+ "#fF(E)=1/(1+exp(Ec-Ef/kT)) =exp(-(Ec-Ef)/kT)\n",
+ "#b=k*T\n",
+ "#print b)\n",
+ "c=k*T\n",
+ "fFE=math.exp(a/c)\n",
+ "print \"fF(E) value is= %.2e\"%fFE\n",
+ "n0=Nc*math.exp(-a/(k*T))\n",
+ "print \"n0 value is %.1e cm**-3\"%n0\n",
+ "#answer in the textbook is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "fF(E) value is= 6.31e-05\n",
+ "n0 value is 4.4e+23 cm**-3\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2, Page 109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T1=400. #K\n",
+ "T2=300 #K\n",
+ "N=1.04*10**19 #cm^-3\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "\n",
+ "#Calculations&Results\n",
+ "Nv=N*(T1/T2)**(3./2)\n",
+ "print 'Nv=%.2e cm^-3'%Nv\n",
+ "\n",
+ "a=k*T2*(T1/T2)\n",
+ "print 'kT=%.5f eV'%a\n",
+ "\n",
+ "#p0=Nv*exp(-(Ef-Ev)/kT)\n",
+ "p0=Nv*math.exp(-0.27/a)\n",
+ "print 'p0=%.2e cm^-3'%p0"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Nv=1.60e+19 cm^-3\n",
+ "kT=0.03447 eV\n",
+ "p0=6.35e+15 cm^-3\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3, Page 112"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T1=300 #K\n",
+ "T2=450. #K\n",
+ "Nc=4.7*10**17 #cm**-3\n",
+ "N=7*10**18 #cm**-3\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "\n",
+ "#Calculations&Results\n",
+ "a=k*T1*(T2/T1)\n",
+ "print 'kT=%.5f eV'%a\n",
+ "\n",
+ "ni=math.sqrt(Nc*N*math.exp(-1.42/(k*T1)))\n",
+ "print 'ni=%.2e cm**-3'%ni\n",
+ "\n",
+ "ni=math.sqrt(Nc*N*(T2/T1)**3*math.exp(-1.42/a))\n",
+ "print 'ni=%.2e cm**-3'%ni"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "kT=0.03878 eV\n",
+ "ni=2.14e+06 cm**-3\n",
+ "ni=3.72e+10 cm**-3\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4, Page 114"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "mn=1.08 #m0\n",
+ "mp=0.56 #m0\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "\n",
+ "#Calculations\n",
+ "#Efi-Emidgap=(3./4)k*T*log(mp/mn)\n",
+ "#a=Efi-Emidgap\n",
+ "a=(0.75)*k*T*math.log(mp/mn)\n",
+ "\n",
+ "#Result\n",
+ "print 'Efi-Emidgap=%.4f eV'%a "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Efi-Emidgap=-0.0127 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.5, Page 123"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "Nn=2.8*10**19 #cm**-3\n",
+ "Np=1.04*10**19 #cm**-3\n",
+ "#a=Ef-Ev\n",
+ "an=0.25 #eV\n",
+ "ap=0.87 #eV\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "\n",
+ "#Calculations&Results\n",
+ "n0=Nn*math.exp(-an/(k*T))\n",
+ "print \"n0 in cm**-3 is= %.1e\"%n0\n",
+ "\n",
+ "p0=Np*math.exp(-ap/(k*T))\n",
+ "print \"p0 in cm**-3 is=%.1e\"%p0"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n0 in cm**-3 is= 1.8e+15\n",
+ "p0 in cm**-3 is=2.5e+04\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6, Page 126"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "nf=2\n",
+ "T=300 #K\n",
+ "Nc=2.8*10**19 #cm^-3\n",
+ "\n",
+ "#Calculations\n",
+ "#n0=(2/sqrt(%pi))*Nc*F12(nf)\n",
+ "#x=F12(nf)=2.3\n",
+ "x=2.3\n",
+ "n0=(2./math.sqrt(math.pi))*Nc*x\n",
+ "\n",
+ "#Result\n",
+ "print \"n0 in cm^-3 is= %.2e\"%n0"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n0 in cm^-3 is= 7.27e+19\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7, Page 130"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "Nd=10**16 #cm^-3\n",
+ "Ne=2.8*10**19 #cm^-3\n",
+ "T=300 #K\n",
+ "\n",
+ "#Calculations\n",
+ "#(nd/(n0+nd))=z=1/(1+(Ne/2*Nd)*exp(-(Ec-Ed)/kT))\n",
+ "#y=Ec-Ed\n",
+ "y=0.045\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "z=1./(1+(Ne/(2*Nd))*math.exp(-y/(k*T)))\n",
+ "\n",
+ "#Result\n",
+ "print \"the donor states is= %.2f%%\"%(z*100)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the donor states is= 0.41%\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.9, Page 134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "Nd=10**16 #cm**-3\n",
+ "Na=0\n",
+ "ni=1.5*10**10 #cm**-3\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "\n",
+ "#Calculations&Results\n",
+ "n0=((Nd-Na)/2)+math.sqrt((((Nd-Na)/2)**2)+ni**2)\n",
+ "print \"n0 is %.e cm**-3 \"%n0\n",
+ "\n",
+ "p0=(ni**2)/n0\n",
+ "print \"p0 is %.2e cm**-3\"%p0\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n0 is 1e+16 cm**-3 \n",
+ "p0 is 2.25e+04 cm**-3\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.10, Page 136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "Nd=5*10**13 #cm**-3\n",
+ "Na=0\n",
+ "ni=2.4*10**13 #cm**-3\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "\n",
+ "#Calculations&Results\n",
+ "n0=((Nd-Na)/2)+math.sqrt((((Nd-Na)/2)**2)+ni**2)\n",
+ "print \"n0 is %.2e cm**-3\"%n0\n",
+ "\n",
+ "p0=(ni**2)/n0\n",
+ "print \"p0 is %.2e cm**-3\"%p0\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n0 is 5.97e+13 cm**-3\n",
+ "p0 is 9.66e+12 cm**-3\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.11, Page 137"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "Nd=3.*10**15 #cm**-3\n",
+ "Na=10.**16 #cm**-3\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "ni=1.5*10**10 #cm^-3\n",
+ "\n",
+ "#Calculations&Results\n",
+ "a=((Na-Nd)/2)\n",
+ "b=math.sqrt(((Na-Nd)/2)**2+(ni**2))\n",
+ "\n",
+ "p0=a+b\n",
+ "print \"p0 is %.e cm^-3\"%p0 #textbook ans is wrong\n",
+ "\n",
+ "n0=(ni**2)/p0\n",
+ "print \"n0 is %.2e cm^-3 \"%n0 #textbook ans is wrpng\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "p0 is 7e+15 cm^-3\n",
+ "n0 is 3.21e+04 cm^-3 \n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.12, Page 138"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T1=550. #K\n",
+ "T2=300 #K\n",
+ "Nc=2.8*10**19 #cm**-3\n",
+ "Ne=1.04*10**19 #cm**-3\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "Eg=1.12\n",
+ "\n",
+ "#Calculations&Results\n",
+ "#ni^2=Nc*Ne*exp(-Eg/(k*T))\n",
+ "ni=math.sqrt(Nc*Ne*(T1/T2)**3*math.exp((-Eg/(k*T2))*(T2/T1)))\n",
+ "print \"ni is %.2e cm^-3 \"%ni\n",
+ "\n",
+ "#n0=1.05*Nd\n",
+ "#n0=(Nd/2)+sqrt((Nd/2)**2+ni**2) equation 1\n",
+ "\n",
+ "a=(((1.05*2)-1)/2)**2 #simplifying and sloving the about equaton 1\n",
+ "b=ni**2\n",
+ "c=((4*a)-1)/4\n",
+ "Nd=math.sqrt(b/c)\n",
+ "print \"Nd value is %.2e cm^-3\"%Nd\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ni is 3.13e+14 cm^-3 \n",
+ "Nd value is 1.37e+15 cm^-3\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.13, Page 140"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "Na=10**16 #cm^-3\n",
+ "Nc=2.8*10**19 #cm**-3\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "\n",
+ "#Calculations\n",
+ "#a=Ec-Ef\n",
+ "a=0.20 #eV\n",
+ "#Ec-Ef=k*T*log(Ne/(Nd-Na))\n",
+ "#Nd-Na=Nc*exp(-(Ec-Ef)/k*T)\n",
+ "Nd=Na+Nc*math.exp(-a/(k*T))\n",
+ "\n",
+ "#Result\n",
+ "print \"Nd is %.2e cm^-3\"%Nd"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Nd is 2.22e+16 cm^-3\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.14, Page 143"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "ni=1.5*10**10 #cm^-3\n",
+ "#Ef-Ea=a\n",
+ "a=3*k*T\n",
+ "#Ea-Ev=b\n",
+ "b=0.045 #eV\n",
+ "Eg=1.12 #eV\n",
+ "\n",
+ "#Calculations\n",
+ "#Efi-Ef=(Eg/2)-(Ea-Ev)-(Ef-Ea)=kT*log(Na/ni)\n",
+ "c=(Eg/2)-(b)-(a)\n",
+ "Na=ni*math.exp(c/(k*T))\n",
+ "\n",
+ "#Result\n",
+ "print \"Na is %.1e cm^-3\"%Na\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Na is 3.4e+17 cm^-3\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch5.ipynb b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch5.ipynb
new file mode 100755
index 00000000..8803cff5
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch5.ipynb
@@ -0,0 +1,342 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:ab68caee4f27092f8d823d2f27a0d86f2134e9bbd7c8628449b1009efc8a2f17"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5: Carrier Transport Phenomena"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Chapter 5.1, Page 156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "Nd=10**16 #cm^-3\n",
+ "Na=0\n",
+ "ni=1.8*10**6 #cm^-3\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "E=10 #V/cm^2\n",
+ "e=1.6*10**-19\n",
+ "un=8500\n",
+ "\n",
+ "#Calculations&Results\n",
+ "n0=((Nd-Na)/2)+math.sqrt((((Nd-Na)/2)**2)+ni**2)\n",
+ "print \"n0 is %.e cm^-3\"%n0\n",
+ "\n",
+ "p0=(ni**2)/n0\n",
+ "print \"p0 is %.2e cm^-3\"%p0\n",
+ "\n",
+ "#Jdrf=e*(un*n0+up*p0)*E= e*un*Nd*E\n",
+ "Jdrf=e*un*Nd*E\n",
+ "print \"Jdrf is %.f A/cm^2 \"%Jdrf\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n0 is 1e+16 cm^-3\n",
+ "p0 is 3.24e-04 cm^-3\n",
+ "Jdrf is 136 A/cm^2 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2, Page 165"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Na=10**17 #cm**-3\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "E=10 #V/cm^2\n",
+ "e=1.6*10**-19 #C\n",
+ "\n",
+ "#Calculations&Results\n",
+ "#sigma=e*un*n0=e*un*(Nd-Na)\n",
+ "#if\n",
+ "Nd=2*10**17 #cm**-3\n",
+ "sigma=8.16#ohm/cm\n",
+ "un=sigma/(e*(Nd-Na))\n",
+ "print \"un is %.f cm^2/Vs \"%un\n",
+ "\n",
+ "#if\n",
+ "Nd=5*10**17 #cm^-3\n",
+ "sigma=20.8#ohm/cm\n",
+ "un=sigma/(e*(Nd-Na))\n",
+ "print \"un is %.f cm^2/Vs\"%un\n",
+ "\n",
+ "#if\n",
+ "Nd=3.5*10**17 #cm^-3\n",
+ "sigma=16#ohm/cm\n",
+ "un=sigma/(e*(Nd-Na))\n",
+ "print \"un is %.f cm^2/Vs\"%un"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "un is 510 cm^2/Vs \n",
+ "un is 325 cm^2/Vs\n",
+ "un is 400 cm^2/Vs\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.3, Page 166"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "V=5. #v\n",
+ "R=10*10**3 #ohm\n",
+ "J=50 #A/cm^2\n",
+ "E=100\n",
+ "Na=1.25*10**16 #cm^-3\n",
+ "Nd=5*10**15 #cm^-3\n",
+ "e=1.6*10**-19 #C\n",
+ "up=410 #cm**2/Vs\n",
+ "\n",
+ "#Calculations&Results\n",
+ "I=V/R\n",
+ "print \"I current is %.1f Ampere\"%(I*10**3)\n",
+ "\n",
+ "A=I/J\n",
+ "print \"A cross sectional area is %.e cm^2 \"%A\n",
+ "\n",
+ "L=V/E\n",
+ "print \"L length of resistor is %.e cm \"%L\n",
+ "\n",
+ "sigma=L/(R*A)\n",
+ "print \"sigma conductivity is %.3f per ohm cm\"%sigma #theoretical value\n",
+ "\n",
+ "#sigma=e*up*p0=e*up*(Na-Nd)\n",
+ "sigma=e*up*(Na-Nd)\n",
+ "print \"sigma conductivity is %.3f per ohm cm \"%sigma #practical value\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I current is 0.5 Ampere\n",
+ "A cross sectional area is 1e-05 cm^2 \n",
+ "L length of resistor is 5e-02 cm \n",
+ "sigma conductivity is 0.500 per ohm cm\n",
+ "sigma conductivity is 0.492 per ohm cm \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4, Page 172"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "T=300 # ..K\n",
+ "Dn=225 #cm^2/s\n",
+ "e=1.6*10**-19# C\n",
+ "deltax=0.10 #cm\n",
+ "\n",
+ "#Calculations\n",
+ "deltan=(1*10**18-7*10**17)#cm^-3\n",
+ "#Jnxdif=e*Dx*derivative (n,x)=e*Dn*(deltan/deltax)\n",
+ "Jnxdif=e*Dn*(deltan/deltax)\n",
+ "\n",
+ "#Result\n",
+ "print \"diffusion current density is %.f A/cm^2 \"%Jnxdif"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "diffusion current density is 108 A/cm^2 \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5, Page 175"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "T=300. #K\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "#derivative(Ndx,x)=a\n",
+ "a=-10**19 #cm**-4\n",
+ "Ndx=(10**16-10**19) #cm^3\n",
+ "l=1\n",
+ "\n",
+ "#Calculations\n",
+ "#Ex=-(k*T/l)*(1./Ndx)*derivative(Ndx,x)\n",
+ "Ex=-(k*T/l)*(1./Ndx)*a*10**3\n",
+ "\n",
+ "#Result\n",
+ "print \"induced electric field is %.1f V/cm\"%Ex\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "induced electric field is -25.9 V/cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6, Page 177"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "u=1000 #cm^2/s\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "\n",
+ "#Calculations\n",
+ "#D=((k*T)/e)*u\n",
+ "D=k*T*u\n",
+ "\n",
+ "#Result\n",
+ "print \"diffusion coefficient is %.1f cm^2/s \"%D"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "diffusion coefficient is 25.9 cm^2/s \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.7, Page 179"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "I=10**-3 #A\n",
+ "Bz=5.*10**-2 #500gauss\n",
+ "e=1.6*10**-19 #C\n",
+ "Vh=-6.25*10**-3 #V\n",
+ "Vx=12.5 #V\n",
+ "W=10**-4#m\n",
+ "d=10**-5 #m\n",
+ "\n",
+ "#Calculations&Results\n",
+ "u=-(I*Bz)/(e*Vh*d)\n",
+ "print \"electron concentration is %.2e m^-3 \"%u\n",
+ "\n",
+ "un=(I*I)/(e*Bz*Vx*W*d)\n",
+ "print \"electron mobility is %.2e m^2/Vs\"%un #textbook ans is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "electron concentration is 5.00e+21 m^-3 \n",
+ "electron mobility is 1.00e+22 m^2/Vs\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch6.ipynb b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch6.ipynb
new file mode 100755
index 00000000..b8ba39d0
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch6.ipynb
@@ -0,0 +1,217 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:07dc0ed5da452da2af535372d485bc6080d9964bbc4a9a4d9e939c3251ec2c71"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Nonequilibrium Excess Carriers in Semiconductors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.5, Page 212"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "un=1200.\n",
+ "Nd=10**16 #cm**-3\n",
+ "esp0=8.85*10**-14 \n",
+ "espr=11.7\n",
+ "\n",
+ "#Calculations&Results\n",
+ "sigma=e*un*Nd\n",
+ "print \"conductivity is %.2f per ohm cm \"%sigma\n",
+ "\n",
+ "esp=espr*esp0\n",
+ "print \"permittivity of silicon is %.2e F/cm\"%esp\n",
+ "\n",
+ "taud=esp/sigma\n",
+ "print \"dielectric relaxtion time constant is %.2e sec \"%taud"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "conductivity is 1.92 per ohm cm \n",
+ "permittivity of silicon is 1.04e-12 F/cm\n",
+ "dielectric relaxtion time constant is 5.39e-13 sec \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6, Page 217"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300#K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "n0=10**15 #cm^-3\n",
+ "p0=10**5 #cm^-3\n",
+ "ni=10**10 #cm^-3\n",
+ "deltan=10**13 #cm**-3\n",
+ "deltap=10**13 #cm**-3\n",
+ "\n",
+ "\n",
+ "#Calculations&Results\n",
+ "#Ef-Efi=a\n",
+ "a=(k*T)*math.log(n0/ni)\n",
+ "print \"fermi level for thermal equlibrium is %.4f eV \"%a\n",
+ "\n",
+ "#Efn-Efi=b\n",
+ "b=(k*T)*math.log((n0+deltan)/ni)\n",
+ "print \"quasi fermi level for electrons is %.4f eV \"%b\n",
+ "\n",
+ "#Efi-Efp=c\n",
+ "c=(k*T)*math.log((p0+deltap)/ni)\n",
+ "print \"quasi fermi level for holes is %.3f eV \"%c\n",
+ "\n",
+ "#answers vary due to roundinf-off errors"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "fermi level for thermal equlibrium is 0.2976 eV \n",
+ "quasi fermi level for electrons is 0.2979 eV \n",
+ "quasi fermi level for holes is 0.179 eV \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8, Page 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "x=0\n",
+ "taup0=10**-6#ses\n",
+ "taup01=10**-7 #sec\n",
+ "deltapb=10**14 #cm**-3\n",
+ "Dn=10 #cm^2/sec\n",
+ "Dp=10 #cm^2/sec\n",
+ "B=-9*10**13\n",
+ "\n",
+ "#Calculations&Results\n",
+ "deltap=deltapb*(taup01/taup0)\n",
+ "print \"deltap is %.e cm^-3 \"%deltap\n",
+ "\n",
+ "g=deltap/taup0\n",
+ "print \"g generation is %.e cm^-3s^-1 \"%g #incorrect solution in textbook\n",
+ "\n",
+ "#deltapx=10**14*(1-0.9*math.exp(-x/Lp))\n",
+ "Lp=math.sqrt(Dp*taup0)\n",
+ "print \"Lp is %f meter \"%Lp\n",
+ "deltapx=10**14*(1-0.9*math.exp(-x/Lp))\n",
+ "print \"distance from the surface = %.e\"%deltapx"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "deltap is 1e+13 cm^-3 \n",
+ "g generation is 1e+19 cm^-3s^-1 \n",
+ "Lp is 0.003162 meter \n",
+ "distance from the surface = 1e+13\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.10, Page 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "Dp=10#cm^2/sec\n",
+ "Lp=31.6*10**-4 #m\n",
+ "g1taup0=10**14 #cm^-3\n",
+ "deltap0=10**13 #cm6-3\n",
+ "\n",
+ "#Calculations\n",
+ "#deltap0=g1taup0*[g/((Dp/Lp)+s)]\n",
+ "s=(Dp/Lp)*((g1taup0/deltap0)-1)\n",
+ "\n",
+ "#Result\n",
+ "print \"surface recombination velocity is %.2e cm per sec \"%s\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "surface recombination velocity is 2.85e+04 cm per sec \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch7.ipynb b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch7.ipynb
new file mode 100755
index 00000000..039c2baf
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch7.ipynb
@@ -0,0 +1,284 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c8a05268f3f6abf2e1ec665cb9165dd0a8adad3f3c3415c9ecc1f701fdedf7b6"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: The pn Junction"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1, Page 242"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300#K\n",
+ "Na=1*10**18# Na=L*10**18 cm**-3\n",
+ "Nd=1*10**15# cm**-3\n",
+ "ni=1.5*10**10# cm**-3\n",
+ "e=1.6*10**-19# eV\n",
+ "k=1.3806*10**-23# JK**-1\n",
+ "\n",
+ "#Calculations&Results\n",
+ "Vbi=(((k*T)/e)*math.log(Na*Nd/ni**2))\n",
+ "print \"the value of Vbi is %.3f V\"%Vbi\n",
+ "\n",
+ "#changing the Na value\n",
+ "Na=10**16# Na=l*10**16 cm**1\n",
+ "Vbi=(((k*T)/e)*math.log(Na*Nd/ni**2))\n",
+ "print \"the value of Vbi is %.3f V \"%Vbi"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of Vbi is 0.754 V\n",
+ "the value of Vbi is 0.635 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2, Page 247"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "T=300.#K\n",
+ "Na=10**16# cm**-3\n",
+ "Nd=10**15# cm**-3\n",
+ "e=1.6*10**-19# eV\n",
+ "epsilon0=8.85*10**-14# F/m\n",
+ "epsilons=11.7\n",
+ "Vbi=0.635# V\n",
+ "\n",
+ "#Calculations&Results\n",
+ "W=(((2*(epsilons*epsilon0)*Vbi)/e)*(Na+Nd)/(Na*Nd))**0.5\n",
+ "print \"W spacing charge width is %.2e c- meter\"%W\n",
+ "xn=0.864*10**-4# xp=0.086 micro m \n",
+ "Emax=-e*Nd*xn/(epsilons*epsilon0)\n",
+ "print \"the value of Emax is %.2e V/cm\"%Emax #Answer in textbook is incorrect"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "W spacing charge width is 9.51e-05 c- meter\n",
+ "the value of Emax is -1.34e+04 V/cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3, Page 249"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "T=300#K\n",
+ "Na=10**16# cm**-3\n",
+ "Nd=10**15# cm**-3\n",
+ "e=1.6*10**-19# eV\n",
+ "epsilon0=8.85*10**-14# F/m\n",
+ "epsilons=11.7\n",
+ "Vbi=0.635# V\n",
+ "Vr=5# V\n",
+ "\n",
+ "#Calculations\n",
+ "W=(((2*(epsilons*epsilon0)*(Vbi+Vr))/e)*(Na+Nd)/(Na*Nd))**0.5\n",
+ "\n",
+ "#Result\n",
+ "print \"the value of W is %.2e m\"%W"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of W is 2.83e-04 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.4, Page 250"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300#K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "Vr=25 #V\n",
+ "Emax=3*10**5#V/cm\n",
+ "Na=10**18#cm**-3\n",
+ "esp=11.7\n",
+ "esp0=8.85*10**-14 \n",
+ "\n",
+ "#Calculations\n",
+ "#Emax=sqrt((2*e*Vr*(Na+Nd))/(esp*(Na+Nd))\n",
+ "x=((Emax**2)*esp*esp0)/(2*e*Vr) #solving the above equation we get\n",
+ "Nd=(Na*x)/(Na-x)\n",
+ "\n",
+ "#Result\n",
+ "print \"doping concentration is %.2e cm**-3\"%Nd"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "doping concentration is 1.18e+16 cm**-3\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5, Page 252"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "T=300#K\n",
+ "Na=10**16# cm**-3\n",
+ "Nd=10**15# cm**-3\n",
+ "e=1.6*10**-19# eV\n",
+ "epsilon0=8.85*10**-14# F/m\n",
+ "epsilons=11.7\n",
+ "Vbi=0.635# V\n",
+ "Vr=5# V\n",
+ "\n",
+ "#Calculations\n",
+ "C=((e*(epsilons*epsilon0)*Na*Nd)/(2*(Vbi+Vr)*(Na+Nd)))**0.5\n",
+ "A=10**-4# cm**2\n",
+ "C=C*A\n",
+ "\n",
+ "#Result\n",
+ "print \"the value of c with cross section area is %.3e F \"%C"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of c with cross section area is 3.656e-13 F \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.6, Page 254"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300#K\n",
+ "ni=1.5*10**10# cm**-3\n",
+ "Nd=10**15# cm**-3\n",
+ "Vbi=0.855# V\n",
+ "e=1.6*10**-19# eV\n",
+ "k=1.3806*10**-23# JK**-1\n",
+ "S=1.32*10**15# Slope=1.32*10**-15 (F/cm**2)**-2*(V)-1\n",
+ "epsilon0=8.85*10**-14# F/m\n",
+ "epsilons=11.7\n",
+ "\n",
+ "#Calculations\n",
+ "Nd=2/((e*(epsilons*epsilon0))*S)\n",
+ "Na=((ni*ni)/Nd)*math.exp((e*Vbi)/(k*T))\n",
+ "\n",
+ "#Result\n",
+ "print \"the value of Na is %.2e cm**-3\"%Na"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of Na is 5.44e+18 cm**-3\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch8.ipynb b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch8.ipynb
new file mode 100755
index 00000000..629ebeee
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch8.ipynb
@@ -0,0 +1,341 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5d52329b157a7ff3e252c90d3baac86ed2ff296d28ed2f0eeb2157803610ac93"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: The pn Junction Diode"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.1, Page 274"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300# K\n",
+ "ni=1.5*10**10 #cm**-3\n",
+ "k=8.617*10**-5 #eV/K\n",
+ "Nd=10**16 #cm**-3\n",
+ "Va=0.60 #V\n",
+ "\n",
+ "#Calculations&Results\n",
+ "#pn=pn0*exp(e*Va/k*T)\n",
+ "pn0=ni**2/Nd\n",
+ "print \"thermal equlibrium minority carrier hole concentration is %.2e cm**-3 \"%pn0\n",
+ "\n",
+ "pn=pn0*math.exp(Va/(k*T))\n",
+ "print \"minority carrier hole concentration is %.2e cm**-3 \"%pn\n",
+ "#answe varies due exp() method of python"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "thermal equlibrium minority carrier hole concentration is 2.25e+04 cm**-3 \n",
+ "minority carrier hole concentration is 2.70e+14 cm**-3 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2, Page 279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300#K\n",
+ "Na=10**16 #cm^-3\n",
+ "Nd=10**16 #cm^-3\n",
+ "ni=1.5*10**10 #cm^-3\n",
+ "Dn=25 #cm^2/s\n",
+ "Dp=10 #cm^2/s\n",
+ "taup0=5*10**-7 #s\n",
+ "taun0=5*10**-7 #s\n",
+ "epsilon=11.7\n",
+ "e=1.6*10**-19 #C\n",
+ "\n",
+ "#Calculations\n",
+ "#J=(E*D*np0/Ln)+(E*D*pn0/Lp)\n",
+ "Js=e*ni**2*((1./Na)*math.sqrt(Dn/taun0)+(1./Nd)*math.sqrt(Dp/taup0))\n",
+ "\n",
+ "#Result\n",
+ "print \"reverse saturation current density is %.2e A/cm^2\"%Js"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "reverse saturation current density is 4.16e-11 A/cm^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3, Page 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "Jp=5 #A/cm^2\n",
+ "Jn=20 #A/cm^2\n",
+ "Va=0.65 #V\n",
+ "ni=1.5*10**10 #cm^-3\n",
+ "Dn=25. #cm^2/s\n",
+ "Dp=10 #cm^2/s\n",
+ "taup0=5*10**-7 #s\n",
+ "taun0=5*10**-7 #s\n",
+ "\n",
+ "#Calculations&Results\n",
+ "#Jn=(e*Dn*np0/Ln)*[exp(e*Va/k*T)-1]==e*sqrt(Dn/taun0)*(ni^2/Na)*[exp(e*Va/k*T)-1]\n",
+ "\n",
+ "Na=e*math.sqrt(Dn/taun0)*(ni**2/Jn)*((math.exp(Va/(k*T)))-1)\n",
+ "print \"Na elctron diffusion current density is %.2e cm^-3\"%Na\n",
+ "\n",
+ "#Jp=(e*Dp*pn0/Lp)*[exp(e*Va/k*T)-1]==e*sqrt(Dp/taup0)*(ni^2/Nd)\n",
+ "\n",
+ "Nd=e*math.sqrt(Dp/taup0)*(ni**2/Jp)*((math.exp(Va/(k*T)))-1)\n",
+ "print \"Nd hole diffusion current density is %.2e cm^-3 \"%Nd"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Na elctron diffusion current density is 1.06e+15 cm^-3\n",
+ "Nd hole diffusion current density is 2.68e+15 cm^-3 \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4, Page 283"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "Va=0.65 #V\n",
+ "Js=4.15*10**-11# A/cm^2\n",
+ "Nd=10**16 #cm**-3\n",
+ "un=1350 #cm^2/Vs\n",
+ "Jn=3.29 #A/cm^2\n",
+ "\n",
+ "#Calculations&Results\n",
+ "J=Js*(math.exp(Va/(k*T))-1)\n",
+ "print \"current density is %.2f A/cm^2\"%J\n",
+ "\n",
+ "E=Jn/(e*Nd*un)\n",
+ "print \"electric field is %.2f V/cm \"%E\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "current density is 3.45 A/cm^2\n",
+ "electric field is 1.52 V/cm \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.5, Page 284"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "T1=300. #K\n",
+ "T2=310. #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.602*10**-19 #C\n",
+ "Va1=0.60 #V\n",
+ "E=1.12 #eV\n",
+ "\n",
+ "#Calculations\n",
+ "#J=exp(-Eg/(k*T))*exp((e*Va)/(k*T))\n",
+ "Va2 = (E*(T1-T2))/(e*(T1-T2))\n",
+ "ch = Va2-Va1\n",
+ "\n",
+ "#Result\n",
+ "print \"Change in forward bias voltage is %.3e\"%ch\n",
+ "#Incorrect solution in textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Change in forward bias voltage is 6.991e+18\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.6, Page 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "Vt=0.0259 #v\n",
+ "lp0=10**-3 #A\n",
+ "taup0=10**-7 #s\n",
+ "Idq=1*10**-3#A\n",
+ "\n",
+ "#Calculations&Results\n",
+ "Cd=(1*lp0*taup0)/(2*Vt)\n",
+ "print \"diffusion capacitance is %.2e F \"%Cd\n",
+ "\n",
+ "vd=(Vt/Idq)\n",
+ "print \"diffusion is %.1f ohm \"%vd"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "diffusion capacitance is 1.93e-09 F \n",
+ "diffusion is 25.9 ohm \n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.7, Page 299"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "Na=10**16 #cm^-3\n",
+ "Nd=10**16 #cm^-3\n",
+ "ni=1.5*10**10 #cm^-3\n",
+ "tau0=5*10**-7 #s\n",
+ "eps=11.7\n",
+ "#Vbr+Vr=z\n",
+ "z=5 #V\n",
+ "\n",
+ "#Calculations&Results\n",
+ "W=math.sqrt(((2*eps))*((Na+Nd)/Na*Nd)*z)\n",
+ "print \"depletion width is %.2e cm \"%W #textbook ans is wrong\n",
+ "\n",
+ "Jgen=(e*ni*W)/(2*tau0)\n",
+ "print \"generation current density is %.2e A/cm^2\"%Jgen #textbook ans is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "depletion width is 1.53e+09 cm \n",
+ "generation current density is 3.67e+06 A/cm^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch9.ipynb b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch9.ipynb
new file mode 100755
index 00000000..2c824569
--- /dev/null
+++ b/Semiconductor_Physics_and_Devices_Basic_Principles_by_D._A._Neamen/ch9.ipynb
@@ -0,0 +1,423 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:483be1ef5d38fecb61ab3cf7b846b6634b285c77abf6356b8e31a3ae85f55fb0"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Metal-Semiconductor and Semiconductor Heterojunctions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.1, Page 330"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "Nd=10**16 #cm^-3\n",
+ "Nr=2.8*10**19 #cm^-3\n",
+ "Vbi=0.33\n",
+ "phim=4.55 #V\n",
+ "psi=4.01 #V\n",
+ "esp=11.7\n",
+ "esp0=8.85*10**-14 \n",
+ "\n",
+ "#Calculations&Results\n",
+ "hb=phim-psi\n",
+ "print \"barrier height is %.2f V \"%hb\n",
+ "\n",
+ "phiu=(k*T)*math.log(Nr/Nd)\n",
+ "print \"schottky barrier height is %.3f V \"%phiu\n",
+ "\n",
+ "Vbt=hb-phiu\n",
+ "print \"in V is %.2f\"%Vbt\n",
+ "\n",
+ "xn=math.sqrt((2*esp*esp0*Vbi)/(e*Nd))\n",
+ "print \"space charge is %.3e cm \"%xn\n",
+ "\n",
+ "Emax=(e*Nd*xn)/(esp*esp0)\n",
+ "print \"maxi electric field is %.1e V/cm \"%Emax"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "barrier height is 0.54 V \n",
+ "schottky barrier height is 0.205 V \n",
+ "in V is 0.33\n",
+ "space charge is 2.067e-05 cm \n",
+ "maxi electric field is 3.2e+04 V/cm \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.2, Page 331"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "esp=11.7\n",
+ "esp0=8.85*10**-14 \n",
+ "Nd=2.7*10**17 #cm^-3\n",
+ "Na=2.8*10**19 #cm^-3\n",
+ "Vbi=0.40\n",
+ "\n",
+ "#Calculations&Results\n",
+ "#(1/C)^2=2*(Vbi+Vr)/(e*esp*Nd)\n",
+ "#delta(1/C)^2/deltaVr=z\n",
+ "z=4.4*10**13\n",
+ "Nd=2/(e*esp*esp0*z)\n",
+ "print \"semiconductor doping is %.2e cm^-3 \"%Nd\n",
+ "\n",
+ "phin=(k*T)*math.log(Na/Nd)\n",
+ "print \"in V is %.2f\"%phin\n",
+ "\n",
+ "phibn=Vbi+phin\n",
+ "print \"schottky barrier height is %.2f V \"%phibn"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "semiconductor doping is 2.74e+17 cm^-3 \n",
+ "in V is 0.12\n",
+ "schottky barrier height is 0.52 V \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3, Page 334"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "esp=11.7\n",
+ "esp0=8.85*10**-14 \n",
+ "E=6.8*10**4 #V/cm\n",
+ "\n",
+ "#Calculations&Results\n",
+ "deltaphi=math.sqrt((e*E)/(4*math.pi*esp*esp0))\n",
+ "print \"schottky barrier lowring is %.4f V \"%deltaphi\n",
+ "\n",
+ "xm=math.sqrt(e/(16*math.pi*esp*esp0*E))\n",
+ "print \"maxi barrier height is %.e cm\"%xm\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "schottky barrier lowring is 0.0289 V \n",
+ "maxi barrier height is 2e-07 cm\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4, Page 340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300. #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "esp=11.7\n",
+ "esp0=8.85*10**-14 \n",
+ "phibe=0.67 #V\n",
+ "Jst=6.*10**-5 #A/cm^2\n",
+ "\n",
+ "#Calculations\n",
+ "A=math.exp(phibe/(k*T))*(Jst/T**2)\n",
+ "\n",
+ "#Result\n",
+ "print \"Richardson constant is %.f A/K^2-cm^2 \"%A #textbook ans is incorrect\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Richardson constant is 120 A/K^2-cm^2 \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5, Page 341"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "esp=11.7\n",
+ "esp0=8.85*10**-14 \n",
+ "phibe=0.67 #V\n",
+ "A=114 #A/K**2-cm**2\n",
+ "Na=10**18 #cm**-3\n",
+ "Nd=10**16 #cm**-3\n",
+ "taup0=10**-7\n",
+ "taun0=10**-7\n",
+ "Dp=10 #cm**2/s\n",
+ "Dn=25 #cm**2/s\n",
+ "Lp=1.0*10**-3 #cm\n",
+ "Ln=1.58*10**-3 #cm\n",
+ "pn0=2.25*10**4 #cm**-3\n",
+ "np0=2.25*10**2 #cm**-3\n",
+ "\n",
+ "#Calculations&Results\n",
+ "a=k*T\n",
+ "Jst=(A*T**2)*math.exp(-phibe/a)\n",
+ "print \"Richardson constant is %.2e A/K**2-cm**2\"%Jst\n",
+ "\n",
+ "Js=((e*Dn*np0)/Ln)+((e*Dp*pn0)/Lp)\n",
+ "print \"reverse saturation current density is %.2e A/cm**2\"%Js"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Richardson constant is 5.69e-05 A/K**2-cm**2\n",
+ "reverse saturation current density is 3.66e-11 A/cm**2\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6, Page 343"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "esp=11.7\n",
+ "esp0=8.85*10**-14 \n",
+ "J=10 #A/K**2-cm**2\n",
+ "Jst=5.98*10**-5#A/K**2-cm**2\n",
+ "Js=3.66*10**-11 #A/K**2-cm**2\n",
+ "\n",
+ "#Calculations&Results\n",
+ "#J=Jst*[exp(e*Va/k*T)-1]\n",
+ "#Va=(k*T/e)*log(J/Jst)\n",
+ "Va=(k*T)*math.log(J/Jst)\n",
+ "print \"forward bias voltage is %.3f V \"%Va\n",
+ "\n",
+ "Va=(k*T)*math.log(J/Js)\n",
+ "print \"forward bias voltage is %.3f V\"%Va\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "forward bias voltage is 0.311 V \n",
+ "forward bias voltage is 0.681 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.7, Page 347"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "Nd=7*10**18 #cm^3\n",
+ "esp=11.7\n",
+ "esp0=8.85*10**-14 \n",
+ "phibn=0.67 #V\n",
+ "Vbi=0.67\n",
+ "\n",
+ "#Calculations\n",
+ "xn=math.sqrt((2*esp*esp0*Vbi)/(e*Nd))\n",
+ "\n",
+ "#Result\n",
+ "print \"space charge width is %.1e cm \"%xn\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "space charge width is 1.1e-06 cm \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.8, Page 355"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "T=300 #K\n",
+ "k=8.617*10**-5#eV/K\n",
+ "e=1.6*10**-19 #C\n",
+ "ni=2.4*10**13 #cm**-3\n",
+ "Na=7*10**18 #cm**3\n",
+ "Nd=10**16 #cm**-3\n",
+ "pp0=6*10**18 #cm**-3\n",
+ "esp=11.7\n",
+ "esp0=8.85*10**-14 \n",
+ "xn=4.13\n",
+ "xp=4.07\n",
+ "\n",
+ "#Calculations&Results\n",
+ "#AE1=e*(xn-xp)\n",
+ "AE=(xn-xp)\n",
+ "print \"AE is %.2f eV \"%AE\n",
+ "\n",
+ "deltaE=1.43-0.67\n",
+ "\n",
+ "AE1=deltaE-AE\n",
+ "print \"AE1 is %.2f eV\"%AE1\n",
+ "\n",
+ "pn0=(ni**2)/Nd\n",
+ "print \"pn0 is %.2e cm**-3 \"%pn0\n",
+ "\n",
+ "Vbi=AE1+(k*T)*math.log((Nd*pp0)/(pn0*Na))\n",
+ "print \"Vbi in V = %.f \"%Vbi\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "AE is 0.06 eV \n",
+ "AE1 is 0.70 eV\n",
+ "pn0 is 5.76e+10 cm**-3 \n",
+ "Vbi in V = 1 \n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits/screenshots/Quality_factor.png b/Solid_State_Devices_and_Circuits/screenshots/Quality_factor.png
new file mode 100755
index 00000000..0bdfea62
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits/screenshots/Quality_factor.png
Binary files differ
diff --git a/Solid_State_Devices_and_Circuits/screenshots/Quality_factor_1.png b/Solid_State_Devices_and_Circuits/screenshots/Quality_factor_1.png
new file mode 100755
index 00000000..0bdfea62
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits/screenshots/Quality_factor_1.png
Binary files differ
diff --git a/Solid_State_Devices_and_Circuits/screenshots/maximum_transconductance_Curve.png b/Solid_State_Devices_and_Circuits/screenshots/maximum_transconductance_Curve.png
new file mode 100755
index 00000000..61b85558
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits/screenshots/maximum_transconductance_Curve.png
Binary files differ
diff --git a/Solid_State_Devices_and_Circuits/screenshots/maximum_transconductance_Curve_1.png b/Solid_State_Devices_and_Circuits/screenshots/maximum_transconductance_Curve_1.png
new file mode 100755
index 00000000..61b85558
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits/screenshots/maximum_transconductance_Curve_1.png
Binary files differ
diff --git a/Solid_State_Devices_and_Circuits/screenshots/minimum_transconductance_Curve.png b/Solid_State_Devices_and_Circuits/screenshots/minimum_transconductance_Curve.png
new file mode 100755
index 00000000..2b1cd607
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits/screenshots/minimum_transconductance_Curve.png
Binary files differ
diff --git a/Solid_State_Devices_and_Circuits/screenshots/minimum_transconductance_Curve_1.png b/Solid_State_Devices_and_Circuits/screenshots/minimum_transconductance_Curve_1.png
new file mode 100755
index 00000000..2b1cd607
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits/screenshots/minimum_transconductance_Curve_1.png
Binary files differ
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_1.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_1.ipynb
new file mode 100755
index 00000000..996cf740
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_1.ipynb
@@ -0,0 +1,448 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1: Special Diodes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.1, Page No. 6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resistance\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Iz=10*10**-3 # reverse current in ampere\n",
+ "Vz=0.05 # zener voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Rz=Vz/Iz # resistance in ohm\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"resistance (ohm) = %.f \"%Rz);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resistance (ohm) = 5 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.2, Page No. 6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# terminal voltage \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "v=4.7 # in volts\n",
+ "r=15 # in ohm\n",
+ "i=20*10**-3 # in ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Vz=(v+(i*r)) # terminal voltage in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"terminal voltage = %.f V\"%Vz)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "terminal voltage = 5 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.3, Page No.14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# tuning range of the circuit\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C1=5.0*10**-12 # minimum capacitance in farad\n",
+ "C2=50.0*10**-12 # maximum capacitance in farad\n",
+ "L=10.0*10**-3 # in henry\n",
+ "\n",
+ "#Calculations\n",
+ "CTmin= (C1/2) # minimum total capacitance of varactor diode\n",
+ "p= (math.sqrt(L*CTmin)) # calculating square root\n",
+ "q= (2*math.pi*p)\n",
+ "fomax= (1/q) # maximum resonant frequency\n",
+ "CTmax= ((C2*C2)/(C2+C2)) # maximum total capacitance of varactor diode\n",
+ "r= (math.sqrt(L*CTmax)) # calculating square root\n",
+ "s= (2*math.pi*r)\n",
+ "fomin= (1/s) # minimum resonant frequency\n",
+ "\n",
+ "#Result\n",
+ "print(\"maximum resonant frequency = %.f MHz\"%(fomax/10**6))\n",
+ "print(\"minimum resonant frequency = %.f kHz\"%(fomin/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum resonant frequency = 1 MHz\n",
+ "minimum resonant frequency = 318 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.4, Page No.24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# standard resistor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "vf=1.8 # in volts\n",
+ "If=16*10**-3 # in ampere\n",
+ "vo=8 # in volts\n",
+ "\n",
+ "#Calculations\n",
+ "rs=(vo-vf)/If # resistor in ohm\n",
+ "\n",
+ "#Result\n",
+ "print(\"standard resistor (ohm) = %.1f\"%rs)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "standard resistor (ohm) = 387.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.5, Page No. 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# min and max value of led current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "v1=1.5 # in volts\n",
+ "v2=2.3 # in volts\n",
+ "vs=10.0 # in volts\n",
+ "r1=470.0 # in ohm\n",
+ "\n",
+ "#Calculations\n",
+ "I1=(vs-v1)/r1 # in ampere\n",
+ "I2=(vs-v2)/r1 # in ampere\n",
+ "\n",
+ "#Result\n",
+ "print(\"maximum current = %.1f mA\"%(I1*10**3))\n",
+ "print(\"minimum current = %.1f mA\"%(I2*10**3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum current = 18.1 mA\n",
+ "minimum current = 16.4 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.6, Page No. 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# which supply voltage will keep brighness of diode constant\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "v1=1.8 # in volts\n",
+ "v2=3.0 # in volts\n",
+ "vs=24.0 # in volts\n",
+ "rs=820.0 # in ohms\n",
+ "vs1=5.0 # in volts\n",
+ "rs1=120.0 # in ohms\n",
+ "r1=470.0 # in ohmI1=(vs-v1)/r1; // in ampere\n",
+ "\n",
+ "#Calcualtions\n",
+ "# case1\n",
+ "Imin=((vs-v2)/rs)\n",
+ "Imax=((vs-v1)/rs)\n",
+ "# case2\n",
+ "Imin1=((vs1-v2)/rs1)\n",
+ "Imax1=((vs1-v1)/rs1)\n",
+ "\n",
+ "#Result\n",
+ "print(\"maximum current in ampere in case1 = %.1f mA\"%(Imax*10**3))\n",
+ "print(\"minimum current in ampere in case1 = %.1f mA\"%(Imin*10**3))\n",
+ "print(\"maximum current in ampere in case2 = %.1f mA\"%(Imax1*10**3))\n",
+ "print(\"minimum current in ampere in case2 = %.1f mA\"%(Imin1*10**3))\n",
+ "print(\"\\nBrightness in the first case will remain constant\")\n",
+ "print(\"where as in second case it will be changing,\")\n",
+ "print(\"Therefore, in order to get an approximately constant\")\n",
+ "print(\"brighntness we use as large a supply voltage as possible.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum current in ampere in case1 = 27.1 mA\n",
+ "minimum current in ampere in case1 = 25.6 mA\n",
+ "maximum current in ampere in case2 = 26.7 mA\n",
+ "minimum current in ampere in case2 = 16.7 mA\n",
+ "\n",
+ "Brightness in the first case will remain constant\n",
+ "where as in second case it will be changing,\n",
+ "Therefore, in order to get an approximately constant\n",
+ "brighntness we use as large a supply voltage as possible.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7.a, Page No. 33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# photocurrent\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "r=0.85 # reponsivity of a photodiode in apmere per watt\n",
+ "p1=1.0 # incident light power in milli watt\n",
+ "\n",
+ "#Calculations\n",
+ "Ip=r*p1\n",
+ "\n",
+ "#Result\n",
+ "print(\"photocurrent = %.2f mA\"%Ip)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "photocurrent = 0.85 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7.b, Page No. 33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# photocurrent\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "r=0.85 # reponsivity of a photodiode in apmere per watt\n",
+ "p1=2.0 # incident light power in milli watt\n",
+ "\n",
+ "#Result\n",
+ "print(\"Given input power saturation is 1.5mw so Ip is not proportional to Pop\")\n",
+ "print(\"hence we cannot find the value of photocurrent\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Given input power saturation is 1.5mw so Ip is not proportional to Pop\n",
+ "hence we cannot find the value of photocurrent\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.8, Page No. 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# quantum efficiency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "EHP=5.4*10**6\n",
+ "photons=6*10**6 \n",
+ "\n",
+ "#Calcualtions\n",
+ "n=EHP/photons\n",
+ "\n",
+ "#Result\n",
+ "print(\"Quantum efficiency = %.1f\"%n)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quantum efficiency = 0.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9, Page No. 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Responsivity\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "h=6.62*10**-34 # planc's constant\n",
+ "c=3*10**8 # speed of light in vaccum\n",
+ "e=0.70 # efficiency \n",
+ "Eg=0.75*1.6*10**-19 # Energy gap in volts\n",
+ "\n",
+ "#Calculations\n",
+ "w=((h*c)/Eg) # wavelength in meters (This answer is wrong in the book)\n",
+ "w = 1664*10**-9 # value used in book \n",
+ "R=((e/1248.0)*w) # in ampere per watt\n",
+ "\n",
+ "#Result\n",
+ "print(\"Responsivity = %.3f * 10^-10 AW^-1\"%(R*10**10))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Responsivity = 9.333 * 10^-10 AW^-1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_1_1.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_1_1.ipynb
new file mode 100755
index 00000000..996cf740
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_1_1.ipynb
@@ -0,0 +1,448 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1: Special Diodes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.1, Page No. 6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resistance\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Iz=10*10**-3 # reverse current in ampere\n",
+ "Vz=0.05 # zener voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Rz=Vz/Iz # resistance in ohm\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"resistance (ohm) = %.f \"%Rz);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resistance (ohm) = 5 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.2, Page No. 6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# terminal voltage \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "v=4.7 # in volts\n",
+ "r=15 # in ohm\n",
+ "i=20*10**-3 # in ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Vz=(v+(i*r)) # terminal voltage in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"terminal voltage = %.f V\"%Vz)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "terminal voltage = 5 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.3, Page No.14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# tuning range of the circuit\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C1=5.0*10**-12 # minimum capacitance in farad\n",
+ "C2=50.0*10**-12 # maximum capacitance in farad\n",
+ "L=10.0*10**-3 # in henry\n",
+ "\n",
+ "#Calculations\n",
+ "CTmin= (C1/2) # minimum total capacitance of varactor diode\n",
+ "p= (math.sqrt(L*CTmin)) # calculating square root\n",
+ "q= (2*math.pi*p)\n",
+ "fomax= (1/q) # maximum resonant frequency\n",
+ "CTmax= ((C2*C2)/(C2+C2)) # maximum total capacitance of varactor diode\n",
+ "r= (math.sqrt(L*CTmax)) # calculating square root\n",
+ "s= (2*math.pi*r)\n",
+ "fomin= (1/s) # minimum resonant frequency\n",
+ "\n",
+ "#Result\n",
+ "print(\"maximum resonant frequency = %.f MHz\"%(fomax/10**6))\n",
+ "print(\"minimum resonant frequency = %.f kHz\"%(fomin/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum resonant frequency = 1 MHz\n",
+ "minimum resonant frequency = 318 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.4, Page No.24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# standard resistor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "vf=1.8 # in volts\n",
+ "If=16*10**-3 # in ampere\n",
+ "vo=8 # in volts\n",
+ "\n",
+ "#Calculations\n",
+ "rs=(vo-vf)/If # resistor in ohm\n",
+ "\n",
+ "#Result\n",
+ "print(\"standard resistor (ohm) = %.1f\"%rs)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "standard resistor (ohm) = 387.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.5, Page No. 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# min and max value of led current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "v1=1.5 # in volts\n",
+ "v2=2.3 # in volts\n",
+ "vs=10.0 # in volts\n",
+ "r1=470.0 # in ohm\n",
+ "\n",
+ "#Calculations\n",
+ "I1=(vs-v1)/r1 # in ampere\n",
+ "I2=(vs-v2)/r1 # in ampere\n",
+ "\n",
+ "#Result\n",
+ "print(\"maximum current = %.1f mA\"%(I1*10**3))\n",
+ "print(\"minimum current = %.1f mA\"%(I2*10**3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum current = 18.1 mA\n",
+ "minimum current = 16.4 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.6, Page No. 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# which supply voltage will keep brighness of diode constant\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "v1=1.8 # in volts\n",
+ "v2=3.0 # in volts\n",
+ "vs=24.0 # in volts\n",
+ "rs=820.0 # in ohms\n",
+ "vs1=5.0 # in volts\n",
+ "rs1=120.0 # in ohms\n",
+ "r1=470.0 # in ohmI1=(vs-v1)/r1; // in ampere\n",
+ "\n",
+ "#Calcualtions\n",
+ "# case1\n",
+ "Imin=((vs-v2)/rs)\n",
+ "Imax=((vs-v1)/rs)\n",
+ "# case2\n",
+ "Imin1=((vs1-v2)/rs1)\n",
+ "Imax1=((vs1-v1)/rs1)\n",
+ "\n",
+ "#Result\n",
+ "print(\"maximum current in ampere in case1 = %.1f mA\"%(Imax*10**3))\n",
+ "print(\"minimum current in ampere in case1 = %.1f mA\"%(Imin*10**3))\n",
+ "print(\"maximum current in ampere in case2 = %.1f mA\"%(Imax1*10**3))\n",
+ "print(\"minimum current in ampere in case2 = %.1f mA\"%(Imin1*10**3))\n",
+ "print(\"\\nBrightness in the first case will remain constant\")\n",
+ "print(\"where as in second case it will be changing,\")\n",
+ "print(\"Therefore, in order to get an approximately constant\")\n",
+ "print(\"brighntness we use as large a supply voltage as possible.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum current in ampere in case1 = 27.1 mA\n",
+ "minimum current in ampere in case1 = 25.6 mA\n",
+ "maximum current in ampere in case2 = 26.7 mA\n",
+ "minimum current in ampere in case2 = 16.7 mA\n",
+ "\n",
+ "Brightness in the first case will remain constant\n",
+ "where as in second case it will be changing,\n",
+ "Therefore, in order to get an approximately constant\n",
+ "brighntness we use as large a supply voltage as possible.\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7.a, Page No. 33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# photocurrent\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "r=0.85 # reponsivity of a photodiode in apmere per watt\n",
+ "p1=1.0 # incident light power in milli watt\n",
+ "\n",
+ "#Calculations\n",
+ "Ip=r*p1\n",
+ "\n",
+ "#Result\n",
+ "print(\"photocurrent = %.2f mA\"%Ip)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "photocurrent = 0.85 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7.b, Page No. 33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# photocurrent\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "r=0.85 # reponsivity of a photodiode in apmere per watt\n",
+ "p1=2.0 # incident light power in milli watt\n",
+ "\n",
+ "#Result\n",
+ "print(\"Given input power saturation is 1.5mw so Ip is not proportional to Pop\")\n",
+ "print(\"hence we cannot find the value of photocurrent\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Given input power saturation is 1.5mw so Ip is not proportional to Pop\n",
+ "hence we cannot find the value of photocurrent\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.8, Page No. 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# quantum efficiency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "EHP=5.4*10**6\n",
+ "photons=6*10**6 \n",
+ "\n",
+ "#Calcualtions\n",
+ "n=EHP/photons\n",
+ "\n",
+ "#Result\n",
+ "print(\"Quantum efficiency = %.1f\"%n)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quantum efficiency = 0.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9, Page No. 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Responsivity\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "h=6.62*10**-34 # planc's constant\n",
+ "c=3*10**8 # speed of light in vaccum\n",
+ "e=0.70 # efficiency \n",
+ "Eg=0.75*1.6*10**-19 # Energy gap in volts\n",
+ "\n",
+ "#Calculations\n",
+ "w=((h*c)/Eg) # wavelength in meters (This answer is wrong in the book)\n",
+ "w = 1664*10**-9 # value used in book \n",
+ "R=((e/1248.0)*w) # in ampere per watt\n",
+ "\n",
+ "#Result\n",
+ "print(\"Responsivity = %.3f * 10^-10 AW^-1\"%(R*10**10))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Responsivity = 9.333 * 10^-10 AW^-1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_2.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_2.ipynb
new file mode 100755
index 00000000..6d8a994c
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_2.ipynb
@@ -0,0 +1,3916 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2 : Bipolar Junction Transistors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1, Page No. 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# comman base dc current gain\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Ic=2.10*10**-3 # collector current in ampere\n",
+ "Ie=2.18*10**-3 # emitter current in ampere\n",
+ "\n",
+ "#Calculations\n",
+ "alfa=Ic/Ie\n",
+ "\n",
+ "#Result\n",
+ "print(\"comman base dc current gain = %f\"%alfa)\n",
+ "#Different values used for calculations in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "comman base dc current gain = 0.963303\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2, Page No. 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Base Current\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "alfa= 0.987 # Common base D.C. Current Gain\n",
+ "Ie= 10.0 # in Milli Ampere\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ic= alfa*Ie # Collector Current\n",
+ "Ib=Ie-Ic # Base Current in Mili Ampere\n",
+ "\n",
+ "#Result\n",
+ "print(\"collector current (in mA) = %.2f\"%Ic)\n",
+ "print(\"base current (in mA) = %.2f\"%Ib)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "collector current (in mA) = 9.87\n",
+ "base current (in mA) = 0.13\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3, Page No. 51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base current and collector current\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "alfa= 0.967 # Common base D.C. Current Gain\n",
+ "Ie= 10.0 # in Milli Ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= alfa*Ie # Collector Current\n",
+ "Ib=Ie-Ic # Base Current in Mili Ampere\n",
+ "\n",
+ "#Result\n",
+ "print(\"collector current (in mA) = %.2f\"%Ic)\n",
+ "print(\"base current (in mA) = %.2f\"%Ib)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "collector current (in mA) = 9.67\n",
+ "base current (in mA) = 0.33\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4, Page No. 52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base current and collector current\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Beta=100.0 # Common Emitter D.C. Current gain\n",
+ "Ie=10.0 # Emitter current in mili ampere\n",
+ "\n",
+ "#Calculations\n",
+ "alfa= (Beta/(Beta+1)) # Common Base D.C. Current gain\n",
+ "Ic= alfa*Ie # Collector current in milli ampere\n",
+ "Ib=Ie-Ic # Base Current in milli ampere\n",
+ "\n",
+ "#Result\n",
+ "print(\"collector current (in mA) = %.2f\"%Ic)\n",
+ "print(\"base current (in mA) = %.2f\"%Ib)\n",
+ "# Answer in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "collector current (in mA) = 9.90\n",
+ "base current (in mA) = 0.10\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.a, Page No. 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate Common Emitter D.C. Current gain\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "alfa=0.950 # Common base D.C. Current gain\n",
+ "\n",
+ "#Calculations\n",
+ "beta= (alfa/(1-alfa))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Common Emitter D.C. Current gain = %.f\"%beta)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Common Emitter D.C. Current gain = 19\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.b, Page No. 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate Common Base D.C. Current gain\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Beta=100.0 #Common emitter D.C. Current gain\n",
+ "\n",
+ "#Calculations\n",
+ "alfa= (Beta/(1+Beta))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Common Base D.C. Current gain = %.2f\"%alfa)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Common Base D.C. Current gain = 0.99\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6, Page No. 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base current and collector current\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Beta=100 # Common Emitter D.C. Current gain\n",
+ "Ie=10.0 # Emitter current in mili ampere\n",
+ "\n",
+ "#Calculation\n",
+ "Ib=(Ie/(1+Beta)) # Emitter current in mili amperen mA\n",
+ "Ic= Ie-Ib # Collector current in mili amperen mA\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base current (in mA) = %.3f\"%Ib)\n",
+ "print(\"Collector current (in mA) = %.3f\"%Ic)\n",
+ "#Answer in the book is incorrect"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base current (in mA) = 0.099\n",
+ "Collector current (in mA) = 9.901\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.7, Page No. 64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate the collector to emitter voltage(Vce) and Collector current (Ic)\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc= 12.0 # as Ic=0 so Vce=Vcc (In volts)\n",
+ "Rc= 3.0 # Collector Resistance in killo oms\n",
+ "\n",
+ "#Calcuations\n",
+ "Ic=Vcc/Rc # Collector Current in Amperes\n",
+ "Vce=Vcc\n",
+ "\n",
+ "#Result\n",
+ "print(\"Colletor to emitter voltage (in volts) = %.f\"%Vce)\n",
+ "print(\" Collector current (in mA) = %.f\"%Ic)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Colletor to emitter voltage (in volts) = 12\n",
+ " Collector current (in mA) = 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.a, Page No. 73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate oerating point\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc= 6.0 # Colector voltage in volts\n",
+ "Rb= 530.0 # in kilo ohms\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=2.0 # Collector resistance in killo ohms\n",
+ "Vbe= 0.7 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ib= ((Vcc-Vbe)/Rb) # in micro amperes\n",
+ "Ic=Beta*Ib # in milli ampere\n",
+ "Vce= Vcc-(Ic*Rc) # Colector to emitter voltage in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"Operating point is (Vce,Ic):\")\n",
+ "print(\"Vce = %.f V\\t Ic = %.f micro-A\"%(Vce,Ic))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Operating point is (Vce,Ic):\n",
+ "Vce = 4 V\t Ic = 1 micro-A\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.b, Page No. 73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate stability factor\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "\n",
+ "#Calculations\n",
+ "S=1+Beta \n",
+ "\n",
+ "#Result\n",
+ "print(\"The Stability factor = %.f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Stability factor = 101\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.a, Page No. 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base current\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Rb= 200.0 # in kilo ohms\n",
+ "Beta=75.0 # Common emitter D.C. Current gain\n",
+ "Rc=0.8 # Collector resistance in killo ohms\n",
+ "Vbe= 0.0 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ib=Vcc/Rb\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base current in micro-A = %.1f\"%(Ib*10**3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base current in micro-A = 100.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.b, Page No. 74 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate collector current\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Rb= 200.0 # in kilo ohms\n",
+ "Beta=75.0 # Common emitter D.C. Current gain\n",
+ "Rc=0.8 # Collector resistance in killo ohms\n",
+ "Vbe= 0.0 # Base to emitter voltage in volts\n",
+ "Ib=0.1 # Base current in mA\n",
+ "\n",
+ "#Cacualtions\n",
+ "Ic=Beta*Ib # Collector current in mA\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector current in mA = %.1f\"%Ic)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current in mA = 7.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.c, Page No. 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate collector TO emitter voltage\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Rb= 200.0 # in kilo ohms\n",
+ "Beta=75.0 # Common emitter D.C. Current gain\n",
+ "Rc=0.8 # Collector resistance in killo ohms\n",
+ "Vbe= 0.0 # Base to emitter voltage in volts\n",
+ "Ib=0.1 # Base current in mA\n",
+ "Ic=7.5 # Base current in mA\n",
+ "\n",
+ "#Calculations\n",
+ "Vce=Vcc- (Ic*Rc)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector to emitter voltage in volts = %.f\"%Vce)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector to emitter voltage in volts = 14\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.d, Page No. 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate collector TO emitter voltage\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Rb= 200.0 # in kilo ohms\n",
+ "Beta=75.0 # common emitter D.C. Current gain\n",
+ "Rc=0.8 # Collector resistance in killo ohms\n",
+ "Vbe= 0.0 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "S=1+Beta \n",
+ "\n",
+ "#Resut\n",
+ "print(\"The Stability factor = %.f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Stability factor = 76\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.10, Page No. 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base resistance , Voltage between collector & ground and Stability factor\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=12.0 # Colector voltage in volts\n",
+ "Ib= 0.3 # in mili ampere\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=0.3 # Collector resistance in killo ohms\n",
+ "\n",
+ "#Calaculations\n",
+ "Rb=Vcc/Ib\n",
+ "Ic= Beta*Ib\n",
+ "Vce=Vcc -(Ic*Rc)\n",
+ "S=1+Beta \n",
+ "\n",
+ "#Result\n",
+ "print(\"Base resistance in killo ohms = %.f\"%Rb)\n",
+ "print(\"Collector to ground voltgae in volts = %.f\"%Vce)\n",
+ "print(\"The Stability factor = %.f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base resistance in killo ohms = 40\n",
+ "Collector to ground voltgae in volts = 3\n",
+ "The Stability factor = 101\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.11, Page No. 76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base current , Collector current and Collector to emitter voltage\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Rb= 400.0 # in KILLO OHMS\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=2.0 # Collector resistance in killo ohms\n",
+ "Re=1.0 # Emitter resistance in killo ohms\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ib= Vcc / (Rb + (Beta*Re))\n",
+ "Ic= Beta*Ib\n",
+ "Vce=Vcc -(Ic*(Rc+Re))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base current in mA = %.2f\"%Ib)\n",
+ "print(\"Collector current in mA = %.f\"%Ic)\n",
+ "print(\"Collector to ground voltgae in volts = %.f\"%Vce)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base current in mA = 0.04\n",
+ "Collector current in mA = 4\n",
+ "Collector to ground voltgae in volts = 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12, Page No. 77"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate Collector current and Collector to emitter voltage\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=25.0 # Colector voltage in volts\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "Rb= 180.0 # in KILLO OHMS\n",
+ "Beta=80.0 # Common emitter D.C. Current gain\n",
+ "Rc=0.82 # Collector resistance in killo ohms\n",
+ "Re=0.2 # Emitter resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= (Vcc-Vbe)/(Re + (Rb/Beta))\n",
+ "Ic = math.floor(Ic*10)/10\n",
+ "Vce=Vcc -(Ic*(Rc+Re))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector current in mA = %.1f\"%Ic)\n",
+ "print(\"Collector to ground voltgae in volts = %f\"%Vce)\n",
+ "#Answer for Vce is incorrect in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current in mA = 9.9\n",
+ "Collector to ground voltgae in volts = 14.902000\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.13, Page No. 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate Collector current , Collector to emitter voltage and stability factor\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "Rb= 200.0 # in KILLO OHMS\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=20.0 # Collector resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= (Vcc-Vbe)/(Rc + (Rb/Beta));\n",
+ "Vce=Vcc -(Ic*Rc);\n",
+ "S=(1+Beta)/(1+Beta*(Rc/(Rc+Rb)));\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector current in mA = %.3f\"%Ic)\n",
+ "print(\"Collector to ground voltgae in volts = %.2f\"%(math.ceil(Vce*100)/100))\n",
+ "print(\"The Stability factor = %.3f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current in mA = 0.877\n",
+ "Collector to ground voltgae in volts = 2.46\n",
+ "The Stability factor = 10.009\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.14, Page No. 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base current , Collector current , Collector to emitter voltage and stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=10.0 # Colector voltage in volts\n",
+ "Vbe=0.0 # Base to emitter voltage in volts\n",
+ "Rb= 100.0 # in KILLO OHMS\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=10.0 # Collector resistance in killo ohms\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ib= (Vcc-Vbe)/(Rb+ Beta*Rc)\n",
+ "Ic= Beta * Ib\n",
+ "Vce=Vcc -(Ic*Rc)\n",
+ "S=(1.0+Beta)/(1.0+Beta*(Rc/(Rc+Rb)))\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"base current = %.f micro-A\"%(Ib*1000))\n",
+ "print(\"Collector current = %.1f mA\"%Ic)\n",
+ "print(\"Collector to ground voltgae = %.1f V\"%(math.ceil(Vce)))\n",
+ "print(\"The Stability factor = %.3f\"%S)\n",
+ "#Answer for stability is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "base current = 9 micro-A\n",
+ "Collector current = 0.9 mA\n",
+ "Collector to ground voltgae = 1.0 V\n",
+ "The Stability factor = 10.009\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.15, Page No. 84"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate emitter current , Collector current and Collector to emitter voltage \n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=10.0 # Colector voltage in volts\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "Vee=10.0 # emitter voltage in volts\n",
+ "Rb= 50.0 # in KILLO OHMS\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=1.0 # Collector resistance in killo ohms\n",
+ "Re=5.0 # Emitter resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Ie= (Vee-Vbe)/Re\n",
+ "Ic= Ie\n",
+ "Vce1=Vcc -(Ic*Rc)\n",
+ "Ve=-Vbe\n",
+ "Vce=Vce1-Ve\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter Current in mA = %.2f\"%Ie)\n",
+ "print(\"Collector current in mA = %.2f\"%Ic)\n",
+ "print(\"Collector to ground voltgae in volts = %.2f\"%Vce)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter Current in mA = 1.86\n",
+ "Collector current in mA = 1.86\n",
+ "Collector to ground voltgae in volts = 8.84\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.16, Page No. 86"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate the change in q point\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Vbe1=0.7 # Base to emitter voltage in volts\n",
+ "Vee=20.0 # emitter voltage in volts\n",
+ "Rb= 10.0 # in KILLO OHMS\n",
+ "Beta1=50.0 # Common emitter D.C. Current gain\n",
+ "Rc=5.0 # Collector resistance in killo ohms\n",
+ "Re=10.0 # Emitter resistance in killo ohms\n",
+ "Vbe2=0.6 # Base to emitter voltage in volts\n",
+ "Beta2=100.0 # Common emitter D.C. Current gain\n",
+ "\n",
+ "#Calculation\n",
+ "Ie1= (Vee-Vbe1)/(Re+(Rb/Beta1))\n",
+ "Ic1=Ie1\n",
+ "Vce1a=Vcc -(Ic1*Rc)\n",
+ "Ve=-Vbe1\n",
+ "Vce1=Vce1a-Ve\n",
+ "Vce1 = math.ceil(Vce1*100)/100\n",
+ "Ie2= (Vee-Vbe2)*10**3/(Re*10**3+(Rb*10**3/Beta2))\n",
+ "Ie2 = math.ceil(Ie2*1000)/1000\n",
+ "Ic2=Ie2\n",
+ "Vce2a=Vcc -(Ic2*Rc)\n",
+ "Ve=-Vbe2\n",
+ "Vce2=Vce2a-Ve\n",
+ "detaIc= ((Ie2-Ie1)/Ie1)*100\n",
+ "detaVce=((Vce1-Vce2)/Vce1)*100\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter Current in first case,Ie = %.3f mA\"%Ie1)\n",
+ "print(\"Collector-to-emitter voltgae in first case,Vce = %.2f V\"%Vce1)\n",
+ "print(\"Emitter Current in second case, Ie = %.3f mA\"%Ie2)\n",
+ "print(\"Collector-to-emitter voltgae in 2nd case, Vce = %.3f V\"%Vce2)\n",
+ "print(\"Change in collector current = %.2f%%\"%(math.ceil(detaIc*100)/100))\n",
+ "print(\"Change in collector to emitter voltage = %.2f%%\"%detaVce)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter Current in first case,Ie = 1.892 mA\n",
+ "Collector-to-emitter voltgae in first case,Vce = 11.24 V\n",
+ "Emitter Current in second case, Ie = 1.921 mA\n",
+ "Collector-to-emitter voltgae in 2nd case, Vce = 10.995 V\n",
+ "Change in collector current = 1.53%\n",
+ "Change in collector to emitter voltage = 2.18%\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.17, Page No. 90"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate dynamic input resistance\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "deltaVbe=200.0 # in milli volts\n",
+ "deltaIe=5.0 # in milli ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Ri=deltaVbe/deltaIe\n",
+ "\n",
+ "#Result\n",
+ "print(\"Dyanamic input resistance is (in ohms) = %.f\"%Ri)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dyanamic input resistance is (in ohms) = 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.18, Page No. 90"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Transistor parameters\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=15.0 # Colector voltage in volts\n",
+ "Rb= 180.0 # in kilo ohms\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=1.5 # Collector resistance in killo ohms\n",
+ "Vbe= 0.7 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ib= ((Vcc-Vbe)/Rb) # in milli amperes\n",
+ "Ic=Beta*Ib # in milli ampere\n",
+ "Vce= Vcc-(Ic*Rc) # Colector to emitter voltage in volts\n",
+ "Vc=Vce\n",
+ "Vb=Vbe\n",
+ "Vcb=Vc-Vb\n",
+ "\n",
+ "#Result\n",
+ "print(\"base current = %.2f micro-A \"%(Ib*10**3))\n",
+ "print(\"Collector current = %.2f mA\"%Ic)\n",
+ "print(\"Collector to emitter voltage = %.1f V\"%Vce)\n",
+ "print(\"Collector voltage = %.1f V\"%Vc)\n",
+ "print(\"Base voltage = %.1f V\"%Vb)\n",
+ "print(\"Collector to base voltage = %.1f V\"%Vcb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "base current = 79.44 micro-A \n",
+ "Collector current = 7.94 mA\n",
+ "Collector to emitter voltage = 3.1 V\n",
+ "Collector voltage = 3.1 V\n",
+ "Base voltage = 0.7 V\n",
+ "Collector to base voltage = 2.4 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.19, Page No. 91"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Operating point , stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=10.0 # Colector voltage in volts\n",
+ "Rb= 930.0 # in kilo ohms\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=4.0 # Collector resistance in killo ohms\n",
+ "Vbe= 0.7 # Base to emitter voltage in volts\n",
+ "Ib= ((Vcc-Vbe)/Rb)# in milli amperes\n",
+ "Ic=Beta*Ib # in milli ampere\n",
+ "Vce= Vcc-(Ic*Rc) # Colector to emitter voltage in volts\n",
+ "S=(1+Beta)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector to emitter voltage In Volts = %.f\"%Vce)\n",
+ "print(\"Collector current in milli Ampere = %.f\"%Ic)\n",
+ "print(\"The Stability factor = %.f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector to emitter voltage In Volts = 6\n",
+ "Collector current in milli Ampere = 1\n",
+ "The Stability factor = 101\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.20, Page No. 92"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Base Resistance , stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=1.0 # Collector resistance in killo ohms\n",
+ "Vce=4.0 # Collector to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= ((Vcc-Vce)/Rc) # in milli amperes\n",
+ "Ib=Ic/Beta # in milli ampere\n",
+ "Rb=Vce/Ib # in Killo ohms\n",
+ "x = math.floor((1+Beta*(Rc/(Rc+Rb)))*100)/100\n",
+ "S=math.floor((1+Beta)*100/x)/100\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base resistance = %.f k-ohm\"%Rb)\n",
+ "print(\"The Stability factor = %.2f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base resistance = 25 k-ohm\n",
+ "The Stability factor = 20.86\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.21, Page No. 92"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Quiescent , stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # Colector voltage in volts\n",
+ "Beta=50.0 # Common emitter D.C. Current gain\n",
+ "Rc=2.0 # Collector resistance in killo ohms\n",
+ "Rb= 100.0 # in kilo ohms\n",
+ "Vbe=0.0 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= (Vcc-Vbe)/(Rc+(Rb/Beta)) # in milli amperes\n",
+ "Ib=Ic/Beta # in milli ampere\n",
+ "Vce= Vcc-(Ic*Rc) # Colector to emitter voltage in volts\n",
+ "S=(1+Beta)/(1+((Beta*Rc)/(Rc+Rb)))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Operating point is (Vce,Ic): \")\n",
+ "print(\"Colector to emitter voltage = %.f V\"%Vce)\n",
+ "print(\"Collector current = %.1f mA\"%Ic)\n",
+ "print(\"The Stability factor = %.2f\"%S)\n",
+ "#Answer for stability factor is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Operating point is (Vce,Ic): \n",
+ "Colector to emitter voltage = 5 V\n",
+ "Collector current = 2.5 mA\n",
+ "The Stability factor = 25.75\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.22, Page No. 93"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Collector to emitter bias voltage\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Beta=100 # Common emitter D.C. Current gain\n",
+ "Rc=2.0 # Collector resistance in killo ohms\n",
+ "Rb= 100.0 # in kilo ohms\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "Ic=10.0 # in milli amperes\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=Ic/Beta # in milli ampere\n",
+ "Vce= Vbe+(Ib*Rb) # Colector to emitter voltage in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"Colector to emitter bias voltage = %.1f V\"%Vce)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Colector to emitter bias voltage = 10.7 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.23, Page No. 93"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Base Currecnt ,Collector current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Icbo=0.0 # collecttor to base leakage current\n",
+ "Vcc=9.0 # Colector voltage in volts\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Vce=5.0 # Collector to emitter voltage in volts\n",
+ "Ic=0.2 # in milli amperes\n",
+ "Rc=(Vcc-Vce)/Ic # Collector Reesistance in ohms\n",
+ "Ib=Ic/Beta # in milli ampere\n",
+ "Rb=Vce/Ib # Base resistance in ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector Resistance = %.f ohm\"%Rc)\n",
+ "print(\"Base Resistance = %.1f k-ohm\"%(Rb/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector Resistance = 20 ohm\n",
+ "Base Resistance = 2.5 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.24, Page No. 94 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Base Resistance , stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=24.0 # Colector voltage in volts\n",
+ "Beta=45.0 # Common emitter D.C. Current gain\n",
+ "Rl=10.0 # Collector resistance in killo ohms\n",
+ "Re=0.27 # Emitter resistance in killo ohms\n",
+ "Vce=5 # Collector to emitter voltage in volts\n",
+ "Vbe=0.6 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=(Vcc-Vce)/((1+Beta)*(Rl+Re)) # in milli ampere\n",
+ "Ic=Ib/Beta # in micro ampere\n",
+ "R=(Vce-Vbe)/Ib # Resistance in killo ohms\n",
+ "x = math.floor((1+Beta*(Re/(Re+R)))*100)/100\n",
+ "S=(1+Beta)/x\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base resistance = %.f k-ohm\"%(math.ceil(R)))\n",
+ "print(\"The Stability factor = %.2f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base resistance = 110 k-ohm\n",
+ "The Stability factor = 41.44\n"
+ ]
+ }
+ ],
+ "prompt_number": 53
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.25, Page No.95 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Quiescent , stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=16.0 # Colector voltage in volts\n",
+ "alfa=0.985\n",
+ "Rc=3.0 # Collector resistance in killo ohms\n",
+ "Re= 2.0 # in kilo ohms\n",
+ "R1= 56.0 # in kilo ohms\n",
+ "R2= 20.0 # in kilo ohms\n",
+ "Vbe=0.3 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Beta= round(alfa/(1-alfa))\n",
+ "Vb=Vcc * (R2/(R1+R2)) # vOLTAGE AT BASE\n",
+ "Vb = math.floor(Vb*100)/100\n",
+ "Ic= (Vb-Vbe)/Re # in milli amperes\n",
+ "Ib=Ic/Beta # in milli ampere\n",
+ "Vce= Vcc-(Ic*(Rc+Re)) # Colector to emitter voltage in volts\n",
+ "Rth=math.floor((R1*R2)*100/(R1+R2))/100\n",
+ "\n",
+ "S=((1+Beta)*(1+(Rth/Re)))/(1+Beta+(Rth/Re))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Operating point is (Vce,Ic): \")\n",
+ "print(\"Colector to emitter voltage = %.3f V\"%Vce)\n",
+ "print(\"Collector current = %.3f mA\"%Ic)\n",
+ "print(\"The Stability factor = %.2f\"%S)\n",
+ "#Answer for Ic is wrong and hence the Vce. Also answer for stability factor is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Operating point is (Vce,Ic): \n",
+ "Colector to emitter voltage = 6.225 V\n",
+ "Collector current = 1.955 mA\n",
+ "The Stability factor = 7.54\n"
+ ]
+ }
+ ],
+ "prompt_number": 68
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.26, Page No. 96\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Find R1,R2 & Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # Colector voltage in volts\n",
+ "Beta=50.0 # Common emitter D.C. Current gain\n",
+ "Rc=2.0 # Collector resistance in killo ohms\n",
+ "Vce=4.0 # Collector to emitter voltage in volts\n",
+ "Vbe=0.3 # Base to emitter voltage in volts\n",
+ "Ic=2.0 # Collector current in milli Ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=Ic/Beta # Base current in milli ampere\n",
+ "I1=10*Ib\n",
+ "Ie=Ic # Emitter current in mili ampere\n",
+ "Re=(Vcc-Ic*Rc-Vce)/Ic# Emiier Resistance\n",
+ "V2=Vbe+Ic*Re # Voltage across R2\n",
+ "R2=V2/I1\n",
+ "R1=25-R2\n",
+ "\n",
+ "#Result\n",
+ "print(\"Resistance, R1 = %.2f k-ohm\"%R1)\n",
+ "print(\"Resistance, R2 = %.2f k-ohm\"%R2)\n",
+ "print(\"Emitter Resistance, Re = %.1f k-ohm\"%Re)\n",
+ "#Answer for R2 is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance, R1 = 19.25 k-ohm\n",
+ "Resistance, R2 = 5.75 k-ohm\n",
+ "Emitter Resistance, Re = 1.0 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 70
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.27, Page No. 96"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Find R\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=24.0 # Colector voltage in volts\n",
+ "Beta=45.0\n",
+ "Rc=10.0 # Collector resistance in killo ohms\n",
+ "Re= 0.27 # in kilo ohms\n",
+ "Vce=5.0 # Collector to emitter voltage in volts\n",
+ "Vbe=0.6 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=(Vcc-Vce)/((1+Beta)*(Rc+Re))\n",
+ "Ic=Ib/Beta\n",
+ "R=(Vce-Vbe)/Ib\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base resistance = %.f k-ohm\"%(math.ceil(R)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base resistance = 110 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 72
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.28, Page No.97"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ic,Vce\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=22.0 # Colector voltage in volts\n",
+ "Beta=40.0\n",
+ "Rc=10.0 # Collector resistance in killo ohms\n",
+ "Re= 1.5 # in kilo ohms\n",
+ "R1= 40.0 # in kilo ohms\n",
+ "R2= 4.0 # in kilo ohms\n",
+ "Vbe=0.5 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Vb=Vcc * (R2/(R1+R2)) # VOLTAGE AT BASE\n",
+ "Ic= (Vb-Vbe)/Re # in milli amperes\n",
+ "Ib=Ic/Beta # in milli ampere\n",
+ "Vce= Vcc-(Ic*(Rc+Re)) # Colector to emitter voltage in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"Colector to emitter voltage = %.1f V\"%Vce)\n",
+ "print(\"Collector current = %.f mA\"%Ic)\n",
+ "#Answer for Vce is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Colector to emitter voltage = 10.5 V\n",
+ "Collector current = 1 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 73
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.29, Page No. 98"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Voltage across Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Beta=50.0\n",
+ "R1= 60.0 # in kilo ohms\n",
+ "R2= 30.0 # in kilo ohms\n",
+ "Vbe=0.6 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Vb=Vcc * (R2/(R1+R2))\n",
+ "Ve=Vb-Vbe\n",
+ "\n",
+ "#Result\n",
+ "print(\"voltage across Re = %.2f V\"%Ve)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "voltage across Re = 6.07 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 74
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.30, Page No. 99"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Voltage across Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # in volts\n",
+ "Rb=200.0 # Base resistance in killo ohms\n",
+ "Vbe=0.8 # Base to emitter voltage in volts\n",
+ "Beta=100.0\n",
+ "Vce=0.2 # Collector to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=5/Rb # Base current in milli ampere\n",
+ "Ic=Beta*Ib # Collector current in milli ampere\n",
+ "Rc= (Vcc-Vce)/Ic # Resistance\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector resistance = %.2f k-ohm\"%Rc) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector resistance = 3.92 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.31, Page No. 99"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Cut off,Vc & Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # in volts\n",
+ "Rc=3.0 # Collector resistance in killo ohms\n",
+ "Rl=0.5 # in kilo ohms\n",
+ "Rb=7.0 # in kilo ohms\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Vbe=0.8 # Base to emitter voltage in volts\n",
+ "Ic=2.78 # in mA Applying KVL\n",
+ "Ib=0.1 # in mA Applying KVL\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ibmin=Ic/Beta\n",
+ "Vc=Vbe # in saturation region\n",
+ "Vce=Vc-Rl*(Ic+Ib)\n",
+ "Re=((Vcc-Vce)/Ic)-Rc\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base current = %.1f mA\"%Ib)\n",
+ "print(\"Minimum Base current = %.4f mA\"%Ibmin)\n",
+ "print(\"\\nAs Base current is more than minimum base current so it is in saturation region\")\n",
+ "print(\"\\nEmitter resistance = %.f ohm\"%(Re*1000))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base current = 0.1 mA\n",
+ "Minimum Base current = 0.0278 mA\n",
+ "\n",
+ "As Base current is more than minimum base current so it is in saturation region\n",
+ "\n",
+ "Emitter resistance = 827 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 77
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.32, Page No. 100"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Beta ,Vcc & Rb\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rc=2.7 # Collector resistance in killo ohms\n",
+ "Re=0.68 # Collector resistance in killo ohms\n",
+ "Ib=0.02 # Base Current in mA\n",
+ "Vce=7.3 # Collector to emitter voltage in volts\n",
+ "Vbe=0.0 # Base to emitter voltage in volts\n",
+ "Ve=2.1 # Emitter Voltage\n",
+ "\n",
+ "#Calculations\n",
+ "Ie= Ve/Re # Emiiter Current in mA\n",
+ "Ic=Ie\n",
+ "Beta=Ic/Ib # Common emitter D.C. Current gain\n",
+ "Vcc= Vce+Ic*(Rc+Re) # Supply Voltage\n",
+ "Vcc = math.floor(Vcc*10)/10\n",
+ "Rb=(Vcc-Ve)/Ib # Base resistance in Killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Common emitter D.C. Current gain (unitless) = %.f\"%Beta)\n",
+ "print(\"Supply Voltage = %.1f V\"%Vcc)\n",
+ "print(\"base resistance = %.f k-ohm\"%Rb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Common emitter D.C. Current gain (unitless) = 154\n",
+ "Supply Voltage = 17.7 V\n",
+ "base resistance = 780 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 84
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.33, Page No. 101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ic & Vce\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=18 # Colector voltage in volts\n",
+ "Rc=2.2 # Collector resistance in killo ohms\n",
+ "Rb=510.0 # Base resistance in killo ohms\n",
+ "Re=1.8 # Emitter resistance in killo ohms\n",
+ "Beta=90.0 # Common emitter D.C. Current gain\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=Vcc/(Rb+Beta*(Rc+Re)) # Base Current in mA\n",
+ "Ib = math.floor(Ib*100)/100\n",
+ "Ic=Beta*Ib # Collector current in mA\n",
+ "Beta=Ic/Ib # Common emitter D.C. Current gain\n",
+ "Vce= Ib*Rb # Collector to emitter voltage in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"Colector to emitter voltage, Vce = %.1f V\"%Vce)\n",
+ "print(\"Collector current, Ic = %.1f mA\"%(math.floor(Ic*10)/10)) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Colector to emitter voltage, Vce = 10.2 V\n",
+ "Collector current, Ic = 1.8 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 91
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.34, Page No.101 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Base current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ie=10.0 # Emitter current in mA\n",
+ "Ic=9.95 # Collector current in mA\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ib=Ie-Ic # Base Current in mA\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base Current = %.2f mA\"%Ib)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base Current = 0.05 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.35, Page No. 101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ic,Vc,Ve & Vce\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=30.0 # Colector voltage in volts\n",
+ "Beta=100.0\n",
+ "Rc=6.2 # Collector resistance in killo ohms\n",
+ "Re=1.5 # Emitter resistance in killo ohms\n",
+ "Rb=690.0 # Base resistance in killo ohms\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "Ib= (Vcc-Vbe)/(Rb+(1+Beta)*Rc+(1+Beta)*Re)\n",
+ "Ic=math.ceil(Ib*Beta) # in milli ampere\n",
+ "Ie=Ib*(1+Beta) # in milli ampere\n",
+ "Vce=Vcc-Ve-(Ic+Ib)*Rc\n",
+ "Vce = math.ceil(Vce*100)/100\n",
+ "Vc=Vce+Ve\n",
+ "print(\"Collector current, Ic = %.f mA\"%Ic)\n",
+ "print(\"emitter voltage, Ve = %.2f V\"%Ve)\n",
+ "print(\"Colector to emitter voltage, Vce = %.2f V\"%Vce)\n",
+ "print(\"collector voltage = %.2f V\"%Vc)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current, Ic = 2 mA\n",
+ "emitter voltage, Ve = 3.03 V\n",
+ "Colector to emitter voltage, Vce = 14.45 V\n",
+ "collector voltage = 17.48 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 105
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.36, Page No. 103"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# R1,Rc & S\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=16.0 # Colector voltage in volts\n",
+ "alfa=0.985\n",
+ "Ieq=2.0 # Emiier current in mA\n",
+ "R2=30.0 # resistance in killo ohms\n",
+ "Re=1.0 # Emitter resistance in killo ohms\n",
+ "Vbe=0.2 # Base to emitter voltage in volts\n",
+ "Vceq=6.0 # Collector to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Beta= alfa/(1-alfa)\n",
+ "Icq=alfa*Ieq\n",
+ "Rc=(Vcc-Vceq-Ieq*Re)/Icq\n",
+ "Ir1=((Ieq*Re+Vbe)/R2)+Icq/Beta\n",
+ "R1=(Vcc-Vbe-(Ieq*Re))/Ir1\n",
+ "Rb= (R1*R2)/(R1+R2)\n",
+ "S=(1+Beta)/(1+Beta*(Re/(Re+Rb)))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector resistence, Rc = %.2f k-ohm\"%Rc)\n",
+ "print(\"Resistance, R1 = %.2f k-ohm\"%(math.floor(R1*100)/100))\n",
+ "print(\"The Stability factor = %.2f\"%(math.floor(S*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector resistence, Rc = 4.06 k-ohm\n",
+ "Resistance, R1 = 133.54 k-ohm\n",
+ "The Stability factor = 18.64\n"
+ ]
+ }
+ ],
+ "prompt_number": 110
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.37.a, Page No. 104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# baising component\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=12.0 # Colector voltage in volts\n",
+ "Beta=180.0\n",
+ "Ieq=2.0 # Emiier current in mA\n",
+ "Rc=1.0 # Collector resistance in killo ohms\n",
+ "Vbe=0.6 # Base to emitter voltage in volts\n",
+ "Vceq=6.0 # Collector to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= (Vcc-Vceq)/Rc\n",
+ "Ib=Ic/Beta\n",
+ "Rb=(Vcc-Vbe)/Ib\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector current in fixed bias case = %.f mA\"%Ic)\n",
+ "print(\"Base current in fixed bias case = %.2f mA\"%(Ib*10**3))\n",
+ "print(\"Base resistance in fixed bias case = %.f k-ohm\"%Rb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current in fixed bias case = 6 mA\n",
+ "Base current in fixed bias case = 33.33 mA\n",
+ "Base resistance in fixed bias case = 342 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 115
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.37.b, Page No. 104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# baising component\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vb=1.6 # Base voltage\n",
+ "Ve=1.0 # emitter voltage\n",
+ "Vcc=12.0 # Collector voltage in volts\n",
+ "Beta=180.0\n",
+ "Ieq=2.0 # Emiier current in mA\n",
+ "Rc=1.0 # Collector resistance in killo ohms\n",
+ "Vbe=0.6 # Base to emitter voltage in volts\n",
+ "Vceq=6.0 # Collector to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= (Vcc-Vceq-Ve)/Rc\n",
+ "Ib=math.ceil(Ic*10**5/Beta)*1000/10**5\n",
+ "Ie=Ic+Ib*10**-3 # emitter current in milli ampere\n",
+ "Re= (Ve/(Ie*10**-3)) # emitter resistance in killo ohms\n",
+ "Ir2= 10*Ib\n",
+ "R2= (Ve+Vbe)/(Ir2*10**-6)\n",
+ "Ir1=Ir2+Ib\n",
+ "R1=((Vcc-Vb)/(Ir1*10**-3))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter Current, Ie = %.3f mA\"%(math.floor(Ie*1000)/1000))\n",
+ "print(\"Resistance, Re = %.1f ohm\"%(Re))\n",
+ "print(\"Resistance, R1 = %.2f k-ohm\"%(R1))\n",
+ "print(\"Resistance, R2 = %.1f ohm\"%(R2))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter Current, Ie = 5.027 mA\n",
+ "Resistance, Re = 198.9 ohm\n",
+ "Resistance, R1 = 34.03 k-ohm\n",
+ "Resistance, R2 = 5759.5 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.38.a, Page No. 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta=180.0 # Common emitter D.C. Current gain\n",
+ "Re=1.0 # Collector resistance in killo ohms\n",
+ "R1=5.76 # resistance in killo ohms\n",
+ "R2=34.67 # resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "S=1+Beta\n",
+ "\n",
+ "#Result\n",
+ "print(\"Stability factor in fixed bias case is %.f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Stability factor in fixed bias case is 181\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.38.b, Page No. 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta=180.0 # Common emitter D.C. Current gain\n",
+ "Re=0.199 # Collector resistance in killo ohms\n",
+ "R1=5.76 # resistance in killo ohms\n",
+ "R2=34.67 # resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Rb=math.floor((R1*R2)*100/(R1+R2))/100\n",
+ "S=(1+Beta)/(1+(Beta*(Re/(Re+Rb))))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Stability factor in self bias case is %.2f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Stability factor in self bias case is 22.67\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.39.a, Page No. 106"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1=500.0 # Resistance in killo ohms\n",
+ "Rc=500.0 # Collector resistance in killo ohms\n",
+ "R2=5000.0 # Resistance in killo ohms\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Beta=75.0\n",
+ "Rc=6.2 # Collector resistance in killo ohms\n",
+ "Re=90.0 # Emitter resistance in ohms\n",
+ "Rb=690.0 # Base resistance in killo ohms\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Rb=((R1*R2)/(R1+R2))\n",
+ "Vb=Vcc * (R1/(R1+R2))# VOLTAGE AT BASE\n",
+ "Icbo=0.02 # Collector to base leakage current in mA\n",
+ "Sre= (Beta/(Rb+Re*Beta)**2)*(Icbo*10**-6*Rb-Beta*(Vb+Rb*Icbo*10**-6-Vbe))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Stability factor = %.3f * 10^-4 A/ohms\"%(Sre*10**4))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Stability factor = -1.212 * 10^-4 A/ohms\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.39.b, Page No. 106"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Change in Icq\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1=500.0 # Resistance in killo ohms\n",
+ "Rc=500. # Collector resistance in killo ohms\n",
+ "R2=5000.0 # Resistance in killo ohms\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Beta=75.0\n",
+ "Rc=6.2 # Collector resistance in killo ohms\n",
+ "Re=90.0 # Emitter resistance in ohms\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Rb=((R1*R2)/(R1+R2))\n",
+ "Vb=Vcc * (R1/(R1+R2)) # VOLTAGE AT BASE\n",
+ "Icbo=0.02 # Collector to base leakage current in mA\n",
+ "Sre= (Beta/(Rb+Re*Beta)**2)*(Icbo*10**-6*Rb-Beta*(Vb+Rb*Icbo*10**-6-Vbe))\n",
+ "DeltaRe= 110-90 # Change in ohms\n",
+ "DeltaIcq= Sre*DeltaRe # Change in Icq\n",
+ "\n",
+ "#Result\n",
+ "print(\"Change in Icq = %.3f mA\"%(DeltaIcq*1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Change in Icq = -2.424 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.40, Page No. 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# R1 & R2\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=5.0 # Colector voltage in volts\n",
+ "Beta=100.0\n",
+ "Vce=2.5 # Collector to emitter voltage in volts\n",
+ "Vbe=0.6 # Base to emitter voltage in volts\n",
+ "R4=0.3 # Resistance in killo ohms\n",
+ "R2=10.0 # Resistance in killo ohms\n",
+ "Ic=1.0 # Collector current in mA\n",
+ "\n",
+ "#Calculations\n",
+ "Vr4=(1+(1/Beta))*Ic*R4\n",
+ "Vcn= Vce-Vr4\n",
+ "R3=(Vcc-Vcn)/Ic\n",
+ "Rb=8.03\n",
+ "R1=(Rb*R2)/(R2-Rb)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Resistance, R1 = %.f k-ohm\"%(math.floor(R1)))\n",
+ "print(\"Base Resistance = %.2f k-ohm\"%Rb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance, R1 = 40 k-ohm\n",
+ "Base Resistance = 8.03 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 45
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.41, Page No. 108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Re , S\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=12.0 # Colector voltage in volts\n",
+ "Beta=50.0\n",
+ "Vce=2.5 # Collector to emitter voltage in volts\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "Re= 2.57 # Emitter resistance in killo ohms\n",
+ "Rc=4.2 # Collector resistance in killo ohms\n",
+ "\n",
+ "#Calculation\n",
+ "Ic=14/(Rc+(1+(1/Beta)*Re))\n",
+ "Ib= (6-Vbe-Ic*Re)/Re\n",
+ "DeltaIb= -1 # Change in base Current\n",
+ "S= (1+Beta)/(1+Beta)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Resistance, Re = %.2f k-ohm\"%Re)\n",
+ "print(\"Stability Factor = %.f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance, Re = 2.57 k-ohm\n",
+ "Stability Factor = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.42, Page No. 109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Icq\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "T2=20.0 # Temperature in degree celsius\n",
+ "T1=0.0 # Temperature in degree celsius\n",
+ "Vcc=15.0 # Colector voltage in volts\n",
+ "Beta=75.0\n",
+ "Vce=2.5 # Collector to emitter voltage in volts\n",
+ "Vbe1=0.7 # Base to emitter voltage in volts\n",
+ "Rb= 50.0 # Emitter resistance in killo ohms\n",
+ "Rc=3.0 # Collector resistance in killo ohms\n",
+ "Re=1.0 # Collector resistance in killo ohms\n",
+ "\n",
+ "#Calculation\n",
+ "Ib= ((6-Vbe1)/(Rb+(1+Beta)*Re))*10**3 # Base Current in Micro Amperes\n",
+ "Ic= Beta*Ib*10**-3 # Colectore Current in Milli Ampere\n",
+ "Icbo1=0.5 # Collector to base leakage current in Micrometer\n",
+ "Icbo2=Icbo1*2**((T2-T1)/10) # Collector to base leakage current in Micrometer when temperature 20 degree celsius\n",
+ "Vbe2=Vbe1-2*T2*10**-3 # base to emitter voltage when temperature is 20 degree celsius\n",
+ "Ib1=((6-Vbe2)/(Rb+(1+Beta)*Re))*10**3 # Base Current in Micro Amperes at 20 degree celsius\n",
+ "Ib1 = math.ceil(Ib1*10)/10\n",
+ "Ic1=(Beta*(Ib*10**-3)) # Colectore Current in Milli Ampere\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base Current = %.f micro-A\"%Ib)\n",
+ "print(\"Collector current = %.2f mA\"%Ic)\n",
+ "print(\"Collector to base leakage current when T=20 degree celsius = %.f micro-A\"%Icbo2)\n",
+ "print(\"Base to emitter voltage when T=20 degree celsius = %.2f V\"%Vbe2)\n",
+ "print(\"Base Current when T=20 degree celsius = %.1f micro-A\"%Ib1)\n",
+ "print(\"Collector current when T=20 degree celsius = %.2f mA\"%Ic1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base Current = 42 micro-A\n",
+ "Collector current = 3.15 mA\n",
+ "Collector to base leakage current when T=20 degree celsius = 2 micro-A\n",
+ "Base to emitter voltage when T=20 degree celsius = 0.66 V\n",
+ "Base Current when T=20 degree celsius = 42.4 micro-A\n",
+ "Collector current when T=20 degree celsius = 3.15 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 64
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.43, Page No. 110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# (a)quiescent current (b) drift in quiescent current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta1=50.0 # gain at 25 degree celsius temperture\n",
+ "Beta2=200.0 # gain at 75 degree celsius temperture\n",
+ "Rb=1.0 # base resistance in killo ohms\n",
+ "Re=0.1 # emitter resistance in ohms\n",
+ "Ico1=0.01 # leakage current at 25 degree celsius temperture in micro ampere\n",
+ "Ico2=0.045 # leakage current at 75 degree celsius temperture in micro ampere\n",
+ "Vbe1=0.7 # base to emitter voltage 25 degree celsius temperture in micro ampere\n",
+ "Vbe2=0.575 # base to emitter voltage 75 degree celsius temperture in micro ampere\n",
+ "\n",
+ "#Calculations\n",
+ "dBeta=Beta2-Beta1 # Change in gain\n",
+ "dIco=Ico2-Ico1 # change in leakage current\n",
+ "dVbe=Vbe2-Vbe1 # change in base to emitter voltage\n",
+ "Ib= (1-Vbe1)/(Rb+(1+Beta1)*Re) # Base current in micro ampere\n",
+ "Ic=Beta1*Ib # Collector current in milli ampere\n",
+ "S=((1+Beta1)*(1+(Rb/Re)))/(1+Beta1+(Rb/Re))\n",
+ "S1=-(Beta1/Re*10**-3)/(1+Beta1+(Rb/Re)) # stability factor\n",
+ "S2=(S*Ic*10**-3)/(Beta1*(1+Beta1)) # stability factor\n",
+ "dIc= ((S*dIco*10**-6)+(S1*dVbe)+(S2*dBeta))*10**3\n",
+ "Icn= Ic+dIc # new collector current in milli ampere\n",
+ "\n",
+ "#Result\n",
+ "print(\"Quiescent current is %.2f mA\"%Ic)\n",
+ "print(\"Quiescent current drift at temperature 75 degree celsius is %.3f mA\"%dIc)\n",
+ "print(\"New quiescent current is %.1f mA\"%Icn)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quiescent current is 2.46 mA\n",
+ "Quiescent current drift at temperature 75 degree celsius is 2.355 mA\n",
+ "New quiescent current is 4.8 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 67
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.44.a, Page No.111 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# R1,R2 ,Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vbe=0.2\n",
+ "Vcc=16.0 # collector voltage in volts\n",
+ "Rc=1.5 # clollector resistance in killo ohms\n",
+ "S=12.0 # stability factor\n",
+ "Vce=8.0 # Collector to emitter voltage\n",
+ "Ic=4.0 # in milli amperes\n",
+ "Beta=50.0 # gain\n",
+ "S1=3.0 # REDUCED STABILITY FACTOR\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ib=(Ic*10**-3)/Beta # Base current in micro ampere\n",
+ "Re=(Vcc-Vce-(Rc*10**3*Ic*10**-3))/(Ic*10**-3+Ib) # emitter resistance in ohms\n",
+ "Rb=round(((11*(1+Beta))/(Beta-11))*Re*10**-3) # base resistance in killo ohms\n",
+ "Vb= (Ib*Rb*1000)+Vbe+((Ic*10**-3)+(Ib*10**-6))*Re# voltage is R2\n",
+ "R1=Vcc*Rb/2.76 #Vb = 2.76 # resistance in killo ohms\n",
+ "R1= math.ceil(R1*10)/10\n",
+ "R2=R1*Rb/(R1-Rb) # RESISTANCE IN KILLO OHMS\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter Resistance,Re = %.2f k-ohm\"%(Re*10**-3))\n",
+ "print(\"Resistance, R1 = %.1f k-ohm\"%R1)\n",
+ "print(\"Resistance, R2 = %.2f k-ohm\"%(math.floor(R2*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter Resistance,Re = 0.49 k-ohm\n",
+ "Resistance, R1 = 40.6 k-ohm\n",
+ "Resistance, R2 = 8.45 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 95
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.44.b, Page No. 111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# R1,R2 ,Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vbe=0.2\n",
+ "Vcc=16.0 # collector voltage in volts\n",
+ "Rc=1.5 # clollector resistance in killo ohms\n",
+ "S=12.0 # stability factor\n",
+ "Vce=8.0 # Collector to emitter voltage\n",
+ "Ic=4.0 # in milli amperes\n",
+ "Beta=50.0 # gain\n",
+ "Ib=(Ic*10**-3)/Beta # Base current in micro ampere\n",
+ "S1=3.0 # REDUCED STABILITY FACTOR\n",
+ "\n",
+ "#Calcualtions\n",
+ "Re=(Vcc-Vce-(Rc*10**3*Ic*10**-3))/(Ic*10**-3+Ib) # emitter resistance in ohms\n",
+ "Rb=math.floor(((2*(1+Beta))/(Beta-2))*Re*10**-3) # base resistance in killo ohms\n",
+ "Vr2= Vbe+(Ic+Ib*10**3)*Re*10**-3 # voltage is R2\n",
+ "R1=math.floor((Rb)/x) # resistance in killo ohms\n",
+ "R2=(Rb*R1)/(R1-Rb) # RESISTANCE IN KILLO OHMS\n",
+ "Rb1=((3*(1+Beta))/(Beta-3))*Re*10**-3 # EFFECT OF REDUCING STABILITY FACTOR ON BASE RESISTANCE\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter Resistance = %.2f k-ohm\"%(Re*10**-3))\n",
+ "print(\"Resistance, R1 = %.f k-ohm\"%R1)\n",
+ "print(\"Resistance, R2 = %.2f k-ohm\"%(math.floor(R2*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter Resistance = 0.49 k-ohm\n",
+ "Resistance, R1 = 7 k-ohm\n",
+ "Resistance, R2 = 1.16 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 109
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.45, Page No. 113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# R1,R2 ,Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vbe=0.2\n",
+ "Vcc=20.0 # collector voltage in volts\n",
+ "Rc=2.0 # clollector resistance in killo ohms\n",
+ "S=10.0 # stability factor\n",
+ "Vce=10.0 # Collector to emitter voltage\n",
+ "Ic=4.0 # in milli amperes\n",
+ "Beta=50.0 # gain\n",
+ "S1=3.0 # REDUCED STABILITY FACTOR\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ib=(Ic*10**-3)/Beta # Base current in micro ampere\n",
+ "Re=(Vcc-Vce-(Rc*10**3*Ic*10**-3))/(Ic*10**-3+Ib) # emitter resistance in ohms\n",
+ "Re = math.ceil(Re*10)/10\n",
+ "Rb=math.ceil(((9*(1+Beta))*1000/(Beta-9))*Re*10**-3)/1000# base resistance in killo ohms\n",
+ "Vr2= Vbe+(Ic+Ib*10**3)*Re*10**-3 # voltage is R2\n",
+ "x=(Vr2/Vcc) # Voltage\n",
+ "R1=(Rb)/x # resistance in killo ohms\n",
+ "R2=(x*R1)/(1-x) # RESISTANCE IN KILLO OHMS\n",
+ "Rb1=((3*(1+Beta))/(Beta-3))*Re*10**-3 # EFFECT OF REDUCING STABILITY FACTOR ON BASE RESISTANCE\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter resistance = %.1f ohm\"%Re)\n",
+ "print(\"Resistance R1 = %.2f k-ohm\"%R1)\n",
+ "print(\"Resistance R2 = %.2f k-ohm\"%R2)\n",
+ "print(\"Base resistance effect of reducing stability factor reduces input impedence = %f k-ohm\"%Rb1)\n",
+ "#Answer for R1 and base resistor do not match with the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter resistance = 490.2 ohm\n",
+ "Resistance R1 = 49.89 k-ohm\n",
+ "Resistance R2 = 6.17 k-ohm\n",
+ "Base resistance effect of reducing stability factor reduces input impedence = 1.595757 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.46, Page No.115 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# R1,R2 ,Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "S=2.0 # stability factor\n",
+ "Vbe=0.8\n",
+ "Vcc=20.0 # collector voltage in volts\n",
+ "Rc=5.0 # collector resistance in killo ohms\n",
+ "Vce=11.5 # Collector to emitter voltage\n",
+ "Ic=1.5 # in milli amperes\n",
+ "Beta=50.0 # gain\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=(Ic*10**-3)/Beta # Base current in micro ampere\n",
+ "Re=(Vcc-Vce-(Rc*10**3*Ic*10**-3))/(Ic*10**-3+Ib)# emitter resistance in ohms\n",
+ "Rb=(((1+Beta))/(Beta-1))*Re # base resistance in killo ohms\n",
+ "Vr2= Vbe+(Ic+Ib*10**3)*Re*10**-3 # voltage is R2\n",
+ "x=(Vr2/Vcc) # Voltage\n",
+ "R1=math.floor(((Rb)/x)*10**-3*100)/100 # resistance in killo ohms\n",
+ "R2=((x*R1)/(1-x))*10**3 # RESISTANCE IN KILLO OHMS\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter resistance = %.1f ohm\"%(Re))\n",
+ "print(\"Resistance R1 = %.2f k-ohm\"%R1)\n",
+ "print(\"Resistance R2 = %.1f k-ohm\"%R2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter resistance = 653.6 ohm\n",
+ "Resistance R1 = 7.55 k-ohm\n",
+ "Resistance R2 = 746.7 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.47, Page No. 124"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=800.0 # Internal resistance in ohms\n",
+ "Rl=1000.0 # Load resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hie=1.0 # in killo ohms\n",
+ "Hre=2*10**-4\n",
+ "Hfe=50\n",
+ "Hoe=25*10**-6 # in ampere per volt\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ai= -Hfe/(1+Hoe*Rl) # Current gain\n",
+ "Ri= Hie*10**3-((Hfe*Hre)/(Hoe+(1/Rl))) # Input resistance in ohms\n",
+ "Ri = math.floor(Ri*100)/100\n",
+ "Av= Ai*(Rl/Ri) # Voltage Gain\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.2f\"%Ai)\n",
+ "print(\"Input resistance = %.2f ohm\"%Ri)\n",
+ "print(\"Voltage gain = %.2f\"%Av)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = -48.78\n",
+ "Input resistance = 990.24 ohm\n",
+ "Voltage gain = -49.26\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.48, Page No. 126"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av,Ro\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rl=1.2*10**3 # Load resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hib=28.0 # in ohms\n",
+ "Hrb=5*10**-4\n",
+ "Hfb=-0.98\n",
+ "Hob=0.34*10**-6 # in ampere per volt\n",
+ "\n",
+ "#Calculations\n",
+ "Ai= -Hfb/(1+Hob*Rl) # Current gain\n",
+ "Ai = math.ceil(Ai*100)/100\n",
+ "Ri= Hib+(Hrb*Ai*Rl) # Input resistance in ohms\n",
+ "Av= round(Ai*(Rl/Ri)) # Voltage Gain\n",
+ "dh=(Hib*Hob)-(Hrb*Hfb)\n",
+ "Ro=(Hib/dh)*10**-3 # Output resistance in killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.2f\"%Ai )\n",
+ "print(\"Input resistance = %.1f ohm\"%Ri)\n",
+ "print(\"Voltage gain = %.f\"%Av)\n",
+ "print(\"Ouput resistance = %.f k-ohm\"%Ro)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = 0.98\n",
+ "Input resistance = 28.6 ohm\n",
+ "Voltage gain = 41\n",
+ "Ouput resistance = 56 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.49, Page No. 129"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av,Avs,Ais\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rl=1000.0 # Load resistance in ohms\n",
+ "Rs=1200.0 # Internal Resistance\n",
+ "# H-paramters are\n",
+ "Hib=22.0 # in ohms\n",
+ "Hrb=3*10**-4\n",
+ "Hfb=-0.98\n",
+ "Hob=0.5*10**-6 # in ampere per volt\n",
+ "\n",
+ "#calculations\n",
+ "Ai= -Hfb/(1+Hob*Rl) # Current gain\n",
+ "Ai = math.ceil(Ai*100)/100\n",
+ "Ri= Hib+(Hrb*Ai*Rl) # Input resistance in ohms\n",
+ "Ri = math.ceil(Ri*10)/10\n",
+ "Av=(Ai*(Rl/Ri)) # Voltage Gain\n",
+ "dh=(Hib*Hob)-(Hrb*Hfb)\n",
+ "Avs=(Av*Ri)/(Ri+Rs) # Overall Voltage gain\n",
+ "Ais=(Ai*Rs)/(Ri+Rs) # Overall Current gain\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.2f\"%Ai)\n",
+ "print(\"Input resistance = %.1f ohm\"%Ri)\n",
+ "print(\"Voltage gain = %.3f\"%Av)\n",
+ "print(\"Overall Voltage gain = %.3f\"%Avs)\n",
+ "print(\"Overall Current gain = %.3f\"%Ais)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = 0.98\n",
+ "Input resistance = 22.3 ohm\n",
+ "Voltage gain = 43.946\n",
+ "Overall Voltage gain = 0.802\n",
+ "Overall Current gain = 0.962\n"
+ ]
+ }
+ ],
+ "prompt_number": 45
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.50, Page No.130 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av,Ro\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rl=5000.0 # Load resistance in ohms\n",
+ "Rs=1000.0 # Source internal resistance\n",
+ "R1=10.0 # Resistance in killo ohms\n",
+ "R2=10.0 # Resistance in killo ohms\n",
+ "Re=5*10**3 # Emitter resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hic=2000.0 # in killo ohms\n",
+ "Hrc=1.0\n",
+ "Hfc=-51.0\n",
+ "Hoc=25*10**-6 # in ampere per volt\n",
+ "\n",
+ "#Calculations\n",
+ "Ai= -Hfc/(1+Hoc*Rl) # Current gain\n",
+ "Ai = math.floor(Ai*10)/10\n",
+ "Ri= (Hic+(Hrc*Ai*Rl)) # Input resistance in ohms\n",
+ "Ri = Ri/1000 # in Killo ohm\n",
+ "Z1= (R1*R2)/(R1+R2)\n",
+ "Zi=(Ri*Z1)/(Ri+Z1) # input resistance of amplifier stage in killo ohms\n",
+ "Av=round((Ai*(Rl/Ri))*10**-3)# Voltage Gain\n",
+ "Ro=-(Rs+Hic)/Hfc # Output resistance in ohms\n",
+ "Ro = math.floor(Ro*10)/10\n",
+ "Zo= (Ro*Re)/(Ro+Re) # output resistance of amplifier stage in ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.1f\"%Ai)\n",
+ "print(\"Input resistance = %.f k-ohm\"%(Ri))\n",
+ "print(\"Voltage gain = %.f\"%Av)\n",
+ "print(\"input resistance of amplifier stage = %.1f k-ohm\"%Zi)\n",
+ "print(\"Output resistance = %.1f ohm\"%Ro)\n",
+ "print(\"output resistance of amplifier stage= %.1f ohm\"%Zo)\n",
+ "#Answer for Zo is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = 45.3\n",
+ "Input resistance = 228 k-ohm\n",
+ "Voltage gain = 1\n",
+ "input resistance of amplifier stage = 4.9 k-ohm\n",
+ "Output resistance = 58.8 ohm\n",
+ "output resistance of amplifier stage= 58.1 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 61
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.51, Page No. 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av,Z0\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1=20.0 # Resistance in killo ohms\n",
+ "R2=10.0 # Resistance in killo ohms\n",
+ "Rc=5.0 # collector resistance in killo ohms\n",
+ "R=10.0 # resistance in killo ohms\n",
+ "Rs=800.0 # Internal resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hie=1.5 # in killo ohms\n",
+ "Hre=5*10**-3\n",
+ "Hfe=50.0\n",
+ "Hoe=2*10**-6 # in micro ampere per volt\n",
+ "Ai= -Hfe # Current gain\n",
+ "Ri= Hie # Input resistance in ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Rl=(Rc*R)/(Rc+R) # Load resistance in killo ohms\n",
+ "Rl= math.floor(Rl*10)/10\n",
+ "Z1= (R1*R2)/(R1+R2)\n",
+ "Zi=(Ri*Z1)/(Ri+Z1) # input resistance of amplifier stage in killo ohms\n",
+ "Av= (Ai*(Rl/Ri))# Voltage Gain\n",
+ "Ro=(1/Hoe) # output resistane in killo ohms\n",
+ "Zo=(Ro*Rl)/(Ro+Rl) # output resistance of amplifier stage in ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.f\"%Ai)\n",
+ "print(\"input resistance of amplifier = %.2f k-ohm\"%Zi)\n",
+ "print(\"Voltage gain = %.f\"%Av)\n",
+ "print(\"output resistance of amplifier = %.1f ohm\"%Zo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = -50\n",
+ "input resistance of amplifier = 1.22 k-ohm\n",
+ "Voltage gain = -110\n",
+ "output resistance of amplifier = 3.3 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 78
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.52, Page No. 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=0.5 # Internal resistance in killo ohms\n",
+ "Rl=5000.0 # Load resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hie=1000.0 # in ohms\n",
+ "Hfe=50.0\n",
+ "Hoe=25*10**-6 # in ampere per volt\n",
+ "\n",
+ "#Calculations\n",
+ "Ai= (1+Hfe)/(1+Hoe*Rl)# Current gain\n",
+ "Ai = math.floor(Ai*100)/100\n",
+ "Ri= Hie+(Ai*Rl) # Input resistance in ohms\n",
+ "Ri = math.floor(Ri/100)*100\n",
+ "Av= (Ai*Rl)/Ri # Voltage Gain\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.2f\"%Ai)\n",
+ "print(\"Input resistance = %.1f k-ohm\"%(Ri/1000))\n",
+ "print(\"Voltage gain = %.4f\"%Av)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = 45.33\n",
+ "Input resistance = 227.6 k-ohm\n",
+ "Voltage gain = 0.9958\n"
+ ]
+ }
+ ],
+ "prompt_number": 97
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.53, Page No. 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=1.0 # Internal resistance in ohms\n",
+ "Rl=1600.0 # Load resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hie=1100.0 # in ohms\n",
+ "Hfe=2.5*10**-4\n",
+ "Hoe=25*10**-6 # in ampere per volt\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ai= -Hfe/(1+Hoe*Rl) # Current gain\n",
+ "Ri= round(Hie+(Ai*Rl)) # Input resistance in ohms\n",
+ "Av= Ai*(Rl/Ri) # Voltage Gain\n",
+ "Av = math.ceil(Av*10**6)/100\n",
+ "Ai = math.ceil(Ai*10**5)/10\n",
+ "Pg=Ai*Av\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.1f * 10^-4\"%(Ai))\n",
+ "print(\"Input resistance = %.f k-ohm\"%Ri)\n",
+ "print(\"Voltage gain = %.2f * 10^-4\"%Av)\n",
+ "print(\"Power gain = %.2f *10^-8\"%(math.floor(Pg*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = -2.4 * 10^-4\n",
+ "Input resistance = 1100 k-ohm\n",
+ "Voltage gain = -3.49 * 10^-4\n",
+ "Power gain = 8.37 *10^-8\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.54.a, Page No. 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Icq,Vcq\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vbe=0.0\n",
+ "Vcc=18.0 # collector voltage in volts\n",
+ "R1=510.0 # resistance in killo ohms\n",
+ "R2=510.0 # resistance in killo ohms\n",
+ "Rc=9.1 # clollector resistance in killo ohms\n",
+ "Re=7.5 # emitter resistance in killo ohms\n",
+ "Rs=1.0 # Internal resistance in ohms\n",
+ "Rl=1600.0 # Load resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hie=1100.0 # in ohms\n",
+ "Hfe=2.5*10**-4\n",
+ "Hoe=25*10**-6 # in ampere per volt\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Vb=Vcc * (R2/(R1+R2)) # vOLTAGE AT BASE\n",
+ "Ic= (Vb-Vbe)/Re # in milli amperes\n",
+ "Vce= Vcc-(Ic*(Rc+Re)) # Colector to emitter voltage in volts\n",
+ "Ai= -Hfe/(1+Hoe*Rl) # Current gain\n",
+ "Ri= round(Hie+(Ai*Rl)) # Input resistance in ohms\n",
+ "Av= Ai*(Rl/Ri) # Voltage Gain\n",
+ "\n",
+ "#Result\n",
+ "print(\"Colector to emitter voltage = %.1f V\"%Vce)\n",
+ "print(\"Collector current = %.1f mA\"%Ic) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Colector to emitter voltage = -1.9 V\n",
+ "Collector current = 1.2 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.54.b, Page No. 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Av,Ri\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vbe=0.0\n",
+ "Vcc=18.0 # collector voltage in volts\n",
+ "R1=510.0 # resistance in killo ohms\n",
+ "R2=510.0 # resistance in killo ohms\n",
+ "Rc=9.1 # clollector resistance in killo ohms\n",
+ "Re=7.5 # emitter resistance in killo ohms\n",
+ "Rs=1.0 # Internal resistance in ohms\n",
+ "Rl=1600.0 # Load resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hie=1.0 # in killo ohms\n",
+ "Hfe=50.0\n",
+ "Hoe=0.0 # in ampere per volt\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Vb=Vcc * (R2/(R1+R2)) # VOLTAGE AT BASE\n",
+ "Ic= (Vb-Vbe)/Re # in milli amperes\n",
+ "Vce= Vcc-(Ic*(Rc+Re)) # Colector to emitter voltage in volts\n",
+ "Ai=-Hfe # current gain\n",
+ "Ri=Hie # Input resistance in ohms\n",
+ "Z1= (R1*R2)/(R1+R2)\n",
+ "Zi=(Ri*Z1)/(Ri+Z1) # input resistance of amplifier stage in killo ohms\n",
+ "Av= Ai*(Rc/Ri) # Voltage Gain\n",
+ "\n",
+ "#Result\n",
+ "print(\"input resistance of amplifier stage = %.2f k-ohm\"%(math.floor(Zi*100)/100))\n",
+ "print(\"Voltage gain is %.f\"%Av)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "input resistance of amplifier stage = 0.99 k-ohm\n",
+ "Voltage gain is -455\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.55, Page No. 140"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resitive paramters\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ic= 5.0 # in milli amperes\n",
+ "Vt=26.0 # voltage \n",
+ "# H-paramters are\n",
+ "hie=1.0 # in killo ohms\n",
+ "hfe=100.0\n",
+ "hoe=4*10**-5 # in ampere per volt\n",
+ "hre=10**-4\n",
+ "\n",
+ "#Calculations\n",
+ "gm=math.floor(Ic*1000/Vt)/1000# transconductance\n",
+ "rbe= hfe/gm # in ohms\n",
+ "rbb=hie*10**3-rbe # in ohms\n",
+ "rbc=(rbe/(hre)*10**-6) # in mega ohms\n",
+ "gce1=hoe-(1+hfe)*(1/(rbc*10**6))\n",
+ "rce=(1/gce1)*10**-3 #in killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"transconductance = %.3f mho\"%gm)\n",
+ "print(\"Rbe = %.f ohm\"%rbe)\n",
+ "print(\"Rbb = %.f ohm\"%rbb)\n",
+ "print(\"Rbc = %.2f Mega ohm\"%rbc)\n",
+ "print(\"gce1= %.2f * 10^-5 mho\"%(gce1*10**5))\n",
+ "print(\"Rce = %.1f killo ohm\"%rce)\n",
+ "#Answer for Rbe is wrong in the book and hence for Rbb and Rbc"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "transconductance = 0.192 mho\n",
+ "Rbe = 521 ohm\n",
+ "Rbb = 479 ohm\n",
+ "Rbc = 5.21 Mega ohm\n",
+ "gce1= 2.06 * 10^-5 mho\n",
+ "Rce = 48.5 killo ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.56, Page No. 140"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# ressitive paramters\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ic= 1.0 # in milli amperes\n",
+ "Vt=26.0 # volatge \n",
+ "ft=80.0 # frequency in mega hertz\n",
+ "Cbc=12 # in pico farad\n",
+ "# H-paramters are\n",
+ "hie=6.0 # in killo ohms\n",
+ "hfe=224.0\n",
+ "\n",
+ "#Calculations\n",
+ "gm=Ic/Vt # transconductance\n",
+ "rbe= hfe/gm # in ohms\n",
+ "rbb=hie*10**3-rbe\n",
+ "Cbe= (((gm)/(2*math.pi*ft*10**6))-Cbc*10**-12)*10**12\n",
+ "\n",
+ "#Result\n",
+ "print(\"transconductance = %.2f m-mho\"%(gm*1000))\n",
+ "print(\"Rbe = %.3f k-ohm\"%(rbe/1000))\n",
+ "print(\"Rbb = %.f ohm\"%rbb)\n",
+ "print(\"Cbe = %.1f pF\"%Cbe)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "transconductance = 38.46 m-mho\n",
+ "Rbe = 5.824 k-ohm\n",
+ "Rbb = 176 ohm\n",
+ "Cbe = 64.5 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.57, Page No. 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# alpha ,beta and cut off frequencies\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cbc=12.0 # in pico farad\n",
+ "# H-paramters are\n",
+ "hie=6.0 # in killo ohms\n",
+ "hfe=224.0\n",
+ "gm=38.0 # transconductance\n",
+ "rbe=5.9 # in killo ohms\n",
+ "rbb=100.0 # in ohms\n",
+ "Cbe= 63.0 # in pico farad\n",
+ "\n",
+ "#Calculations\n",
+ "falpha= ((hfe)/(2*math.pi*rbe*10**3*Cbe*10**-12))*10**-6\n",
+ "fbeta= ((1)/(2*math.pi*rbe*10**3*(Cbe+Cbc)*10**-12))*10**-6\n",
+ "ft= ((gm*10**-3/(2*math.pi*(Cbe+Cbc)*10**-12)))*10**-6\n",
+ "\n",
+ "#Result\n",
+ "print(\"F_alfa = %.1f MHz\"%falpha)\n",
+ "print(\"F_beta = %.3f MHz\"%(math.floor(fbeta*1000)/1000))\n",
+ "print(\"F_t = %.2f MHz\"%(math.floor(ft*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "F_alfa = 95.9 MHz\n",
+ "F_beta = 0.359 MHz\n",
+ "F_t = 80.63 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.58, Page No. 147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# ressitive paramters\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ic= 2.6 # in milli amperes\n",
+ "Vt=26.0 # volatge \n",
+ "ft=500.0 # frequency in mega hertz\n",
+ "Cbc=3.0 # in pico farad\n",
+ "rbb=100.0 # in ohms\n",
+ "rbe=1.0 # IN KILLO OHMS\n",
+ "\n",
+ "#calculations\n",
+ "gm=Ic/Vt # transconductance\n",
+ "Beta= gm*rbe*10**3\n",
+ "Cbe= (((gm)/(2*math.pi*ft*10**6))-Cbc*10**-12)*10**12\n",
+ "\n",
+ "#Result\n",
+ "print(\"transconductance = %.1f mho\"%gm)\n",
+ "print(\"Cbe = %.2f pF\"%Cbe)\n",
+ "#Answer for Cbe is slightly different than book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "transconductance = 0.1 mho\n",
+ "Cbe = 28.83 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ " Example 2.59, Page No. 148"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# h-parameters and hybrid parameters\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "# H-paramters are\n",
+ "hie=1100.0 # in killo ohms\n",
+ "hre=2.5*10**-4\n",
+ "hfe=50.0\n",
+ "hoe=2.5*10**-5 # in ampere per volt\n",
+ "rbb=100.0\n",
+ "\n",
+ "#Calculations\n",
+ "hic=hie\n",
+ "hrc=1-hre\n",
+ "hfc=-(1+hfe)\n",
+ "hoc=hoe\n",
+ "hib=(hie/(1+hfe))\n",
+ "hrb= ((hie*hoe)/(1+hfe))-hre\n",
+ "hob=(hoe/(1+hfe))\n",
+ "rbe=(hie-rbb)*10**-3 # in killo ohms\n",
+ "rbc= ((hie-rbb)/hre)*10**-6\n",
+ "gm= ((hfe/(hie-rbb)))\n",
+ "x=hoe-((hfe*hre)/(hie-rbb))\n",
+ "rce=1/(1.25*10**-2)\n",
+ "\n",
+ "#Result\n",
+ "print(\"\\nH-parameters for common collector configuration are:\")\n",
+ "print(\"hic = %.f ohm\\nhrc = %.f\\nhfc = %.f\\nhoc = %.1f*10^-5 mho\"%(hie,hrc,hfc,hoc*10**5))\n",
+ "print(\"\\nH-parameters for common collector configuration are:\")\n",
+ "print(\"hib = %.2f ohm\\nhrb = %.1f*10^4\\nhob = %.1f*10^-6 mho\"%(hib,hrb*10**4,hob*10**6))\n",
+ "print(\"\\nhybrid pie paramtere are:\")\n",
+ "print(\"rbe(in killo ohms) = %.f\\nrbc(mega ohms)\\t = %.f\\ntransconductance(mho)= %.f\\nrce(in killo ohms) = %.f\"%(rbe,rbc,gm,rce))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "H-parameters for common collector configuration are:\n",
+ "hic = 1100 ohm\n",
+ "hrc = 1\n",
+ "hfc = -51\n",
+ "hoc = 2.5*10^-5 mho\n",
+ "\n",
+ "H-parameters for common collector configuration are:\n",
+ "hib = 21.57 ohm\n",
+ "hrb = 2.9*10^4\n",
+ "hob = 0.5*10^-6 mho\n",
+ "\n",
+ "hybrid pie paramtere are:\n",
+ "rbe(in killo ohms) = 1\n",
+ "rbc(mega ohms)\t = 4\n",
+ "transconductance(mho)= 0\n",
+ "rce(in killo ohms) = 80\n"
+ ]
+ }
+ ],
+ "prompt_number": 72
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.60, Page No. 149"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# hybrid parameters\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ic= 10.0 # in milli amperes\n",
+ "Vt=26.0 # volatge \n",
+ "ft=500.0 # frequency in mega hertz\n",
+ "Cbc=3.0 # in pico farad\n",
+ "gm=Ic/Vt # transconductance\n",
+ "# H-paramters are\n",
+ "hie=500.0 # in killo ohms\n",
+ "hfe=100.0\n",
+ "hre=0.1\n",
+ "hoe=4*10**-5 # in ampere per volt\n",
+ "\n",
+ "#Calculations\n",
+ "rbe=hfe/gm # in ohms\n",
+ "rbc= ((rbe)/hre)*10**-3\n",
+ "x=hoe-((hfe*10**-4)/(rbe))\n",
+ "rce=(1/(x*10**-2))*10**-5\n",
+ "Cbe=(((gm)/(2*math.pi*ft*10**6))*10**13-Cbc)\n",
+ "\n",
+ "#Result\n",
+ "print(\"transconductance = %.3f mho\"%gm)\n",
+ "print(\"(rbe) = %.f ohm\"%rbe)\n",
+ "print(\"(rbc) = %.1f Mega-ohm\"%rbc)\n",
+ "print(\"(rce) = %.f k-ohm\"%rce)\n",
+ "print(\"(Cbe) = %.f pF\"%Cbe)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "transconductance = 0.385 mho\n",
+ "(rbe) = 260 ohm\n",
+ "(rbc) = 2.6 Mega-ohm\n",
+ "(rce) = 650 k-ohm\n",
+ "(Cbe) = 1221 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 78
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.61, Page No. 149"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# hybrid parameters\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ai=10.0 # current gain\n",
+ "Vce=10.0\n",
+ "Ic= 10.0 # in milli amperes\n",
+ "Vt=26.0 # volatge \n",
+ "f=10.0 # frequency in mega hertz\n",
+ "Cbc=3.0 # in pico farad\n",
+ "gm=Ic/Vt # transconductance\n",
+ "# H-paramters are\n",
+ "hie=500.0 # in ohms\n",
+ "hfe=100.0\n",
+ "\n",
+ "#Calculations\n",
+ "rbe= hfe/gm\n",
+ "rbb= hie-rbe\n",
+ "Ft= Ai*f\n",
+ "fb= Ft/hfe\n",
+ "Ce=((gm/(2*math.pi*Ft*10**6))-Cbc*10**-12)*10**12\n",
+ "\n",
+ "#Result\n",
+ "print(\"(gm) = %.1f mS\"%(gm*10**3))\n",
+ "print(\"(rbe) = %.f ohm\"%rbe)\n",
+ "print(\"(rbb) = %.f ohm\"%rbb)\n",
+ "print(\"(ft) = %.f MHz\"%Ft)\n",
+ "print(\"(fb) = %.f MHz\"%fb)\n",
+ "print(\"(Ce) = %.f p-F\"%Ce)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(gm) = 384.6 mS\n",
+ "(rbe) = 260 ohm\n",
+ "(rbb) = 240 ohm\n",
+ "(ft) = 100 MHz\n",
+ "(fb) = 1 MHz\n",
+ "(Ce) = 609 p-F\n"
+ ]
+ }
+ ],
+ "prompt_number": 81
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.62, Page No. 150"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# mid band voltage gain and cut off frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=1.0 \n",
+ "ft=500.0 # frequency in mega hertz\n",
+ "Cbc=5.0 # in pico farad\n",
+ "# H-paramters are\n",
+ "hie=500.0\n",
+ "hfe=100.0\n",
+ "rbe= 900.0\n",
+ "rbb= 100.0\n",
+ "Rl=500.0 # load resistance in ohms\n",
+ "\n",
+ "#Calculations\n",
+ "gm=hfe/rbe # in mho\n",
+ "Av=((-gm*Rl)) # voltage gain\n",
+ "Avs= ((Av*rbe)/(Rs*10**3+rbb+rbe))\n",
+ "fb= ft/hfe\n",
+ "\n",
+ "#Result\n",
+ "print(\"mid band voltage gain is %.f\"%Avs)\n",
+ "print(\"Fb = %.f MHz\"%fb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "mid band voltage gain is -25\n",
+ "Fb = 5 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 58
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.63, Page No. 150"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# mid band voltage gain and cut off frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=1.0\n",
+ "ft=500.0 # frequency in mega hertz\n",
+ "Cbc=5.0 # in pico farad\n",
+ "# H-paramters are\n",
+ "gm=100.0 # in mho\n",
+ "hfe=100.0\n",
+ "rbb= 100.0\n",
+ "Rl=500.0 # load resistance in ohms\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "rbe=hfe/(gm*10**-3)\n",
+ "Av=((-gm*10**-3*Rl))\n",
+ "Avs= ((Av*rbe)/(Rs*10**3+rbb+rbe))\n",
+ "fb= ft/hfe\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"mid band voltage gain is %.2f\"%Avs)\n",
+ "print(\"Fb = %.f MHz\"%fb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "mid band voltage gain is -23.81\n",
+ "Fb = 5 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 83
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.64, Page No. 156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency and voltage drop\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "L=100.0 # in micro henry\n",
+ "C=253.3 # in micro farad\n",
+ "R=15.7 # in ohms\n",
+ "V=0.157\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "fr=((1/(2*math.pi*math.sqrt(L*10**-6*C*10**-12))))*10**-6 # resonant frequency in mega hertz\n",
+ "Ir=V/R\n",
+ "Vr=V\n",
+ "Vl=Ir*(2*math.pi*fr*10**6*L*10**-6)\n",
+ "Xc= (1/(2*math.pi*fr*10**6*C*10**-12))\n",
+ "Vc= Ir*Xc\n",
+ "Q=((2*math.pi*fr*10**6*L*10**-6)/R)\n",
+ "\n",
+ "#Result\n",
+ "print(\"resonant frequency = %.f MHz\"%fr)\n",
+ "print(\"Voltage drop across resitor = %.3f V\"%Vr)\n",
+ "print(\"Voltage drop across inductor = %.3f V\"%Vl)\n",
+ "print(\"Voltage drop across capacitor = %.3f V\"%Vc)\n",
+ "print(\"Quality factor of coil = %.f\"%Q)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resonant frequency = 1 MHz\n",
+ "Voltage drop across resitor = 0.157 V\n",
+ "Voltage drop across inductor = 6.283 V\n",
+ "Voltage drop across capacitor = 6.283 V\n",
+ "Quality factor of coil = 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 89
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.65, Page No. 160"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency ,impedence,Q-factor,Bnadwidth,line current and resonant frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "V=10.0\n",
+ "L=1.2 # in micro henry\n",
+ "C=200.0 # in micro farad\n",
+ "R=8.0 # in ohms\n",
+ "\n",
+ "#Calculations\n",
+ "fr=(1/(2*math.pi))*(math.sqrt((1/(L*10**-3*C*10**-12))-(R**2/(L*10**-3)**2))*10**-3) # resonant frequency in killo hertz\n",
+ "Zr=(L*10**-3)/(C*10**-9*R) # IN KILLO OHMS\n",
+ "Q=((2*math.pi*fr*10**6*L*10**-6)/R)\n",
+ "BW=fr/Q\n",
+ "Ir=(V/Zr)*10**3\n",
+ "fr1=((1/(2*math.pi*math.sqrt(L*10**-3*C*10**-12))))*10**-3 #resonant frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"resonant frequency = %.3f kHz\"%fr)\n",
+ "print(\"Impedence is %.f k-ohm\"%Zr)\n",
+ "print(\"bandwidth is %.2f kHz\"%BW)\n",
+ "print(\"line current is %.2f micro-A\"%Ir)\n",
+ "print(\"Quality factor of coil is %.1f\"%Q)\n",
+ "print(\"resonant frequency neglecting resistance = %.3f kHz\"%(math.floor(fr1*1000)/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resonant frequency = 324.872 kHz\n",
+ "Impedence is 750 k-ohm\n",
+ "bandwidth is 1.06 kHz\n",
+ "line current is 13.33 micro-A\n",
+ "Quality factor of coil is 306.2\n",
+ "resonant frequency neglecting resistance = 324.873 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 99
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.66, Page No. 161"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency ,impedence,Q-factor,Bnadwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "V=10.0\n",
+ "L=150.0 # in micro henry\n",
+ "C=100.0 # in micro farad\n",
+ "R=5 # in ohms\n",
+ "\n",
+ "#Calculations\n",
+ "fr=((1/(2*math.pi*math.sqrt(L*10**-6*C*10**-12))))*10**-3 # resonant frequency in killo hertz\n",
+ "Zr=(L*10**-3)/(C*10**-9*R) # IN KILLO OHMS\n",
+ "Q=((2*math.pi*fr*10**6*L*10**-6)/R)*10**-3\n",
+ "BW=(fr/Q)\n",
+ "\n",
+ "#Result\n",
+ "print(\"resonant frequency = %.1f kHz\"%fr)\n",
+ "print(\"Impedance is %.f k-ohm\"%(Zr*10**-3))\n",
+ "print(\"Quality factor of coil is %.f\"%Q)\n",
+ "print(\"bandwidth = %.1f kHz\"%BW)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resonant frequency = 1299.5 kHz\n",
+ "Impedance is 300 k-ohm\n",
+ "Quality factor of coil is 245\n",
+ "bandwidth = 5.3 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 104
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.67, Page No. 162"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Q FACTOR\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fr=1600.0 # resonant frequency in killo hertz\n",
+ "BW=10.0 # In kill hertz\n",
+ "\n",
+ "#Calculations\n",
+ "Qr=fr/BW\n",
+ "\n",
+ "#Result\n",
+ "print(\"value of quality factor is %.f\"%Qr)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of quality factor is 160\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.68, Page No. 163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Q FACTOR\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fr=2*10**6 # resonant frequency in hertz\n",
+ "BW=50*10**3 # hertz\n",
+ "\n",
+ "#Calcualtions\n",
+ "Qr=fr/BW\n",
+ "\n",
+ "#Result\n",
+ "print(\"value of quality factor is %.f\"%Qr)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of quality factor is 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.69, Page No. 163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# parallel impedence\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fr=455.0*10**3 # resonant frequency in hertz\n",
+ "BW=10.0*10**3 # hertz\n",
+ "Xl=1255.0 # inductive reactance in ohm\n",
+ "\n",
+ "#Calculations\n",
+ "Qr=fr/BW\n",
+ "R=Xl/Qr\n",
+ "L=Xl/(2*math.pi*fr)\n",
+ "C=1/(2*math.pi*fr*Xl)\n",
+ "Zp=(L/(C*R))*10**-3\n",
+ "\n",
+ "#Result\n",
+ "print(\"value of quality factor is %.1f\"%Qr)\n",
+ "print(\"resisitance = %.1f ohm\"%R)\n",
+ "print(\"inductance = %.3f * 10^-3 H\"%(L*1000))\n",
+ "print(\"capacitor = %.1f * 10^-12 F\"%(C*10**12))\n",
+ "print(\"parallel impedence = %.f k-ohm\"%Zp)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of quality factor is 45.5\n",
+ "resisitance = 27.6 ohm\n",
+ "inductance = 0.439 * 10^-3 H\n",
+ "capacitor = 278.7 * 10^-12 F\n",
+ "parallel impedence = 57 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 115
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_2_1.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_2_1.ipynb
new file mode 100755
index 00000000..6d8a994c
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_2_1.ipynb
@@ -0,0 +1,3916 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2 : Bipolar Junction Transistors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1, Page No. 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# comman base dc current gain\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Ic=2.10*10**-3 # collector current in ampere\n",
+ "Ie=2.18*10**-3 # emitter current in ampere\n",
+ "\n",
+ "#Calculations\n",
+ "alfa=Ic/Ie\n",
+ "\n",
+ "#Result\n",
+ "print(\"comman base dc current gain = %f\"%alfa)\n",
+ "#Different values used for calculations in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "comman base dc current gain = 0.963303\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2, Page No. 50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Base Current\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "alfa= 0.987 # Common base D.C. Current Gain\n",
+ "Ie= 10.0 # in Milli Ampere\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ic= alfa*Ie # Collector Current\n",
+ "Ib=Ie-Ic # Base Current in Mili Ampere\n",
+ "\n",
+ "#Result\n",
+ "print(\"collector current (in mA) = %.2f\"%Ic)\n",
+ "print(\"base current (in mA) = %.2f\"%Ib)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "collector current (in mA) = 9.87\n",
+ "base current (in mA) = 0.13\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3, Page No. 51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base current and collector current\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "alfa= 0.967 # Common base D.C. Current Gain\n",
+ "Ie= 10.0 # in Milli Ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= alfa*Ie # Collector Current\n",
+ "Ib=Ie-Ic # Base Current in Mili Ampere\n",
+ "\n",
+ "#Result\n",
+ "print(\"collector current (in mA) = %.2f\"%Ic)\n",
+ "print(\"base current (in mA) = %.2f\"%Ib)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "collector current (in mA) = 9.67\n",
+ "base current (in mA) = 0.33\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4, Page No. 52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base current and collector current\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Beta=100.0 # Common Emitter D.C. Current gain\n",
+ "Ie=10.0 # Emitter current in mili ampere\n",
+ "\n",
+ "#Calculations\n",
+ "alfa= (Beta/(Beta+1)) # Common Base D.C. Current gain\n",
+ "Ic= alfa*Ie # Collector current in milli ampere\n",
+ "Ib=Ie-Ic # Base Current in milli ampere\n",
+ "\n",
+ "#Result\n",
+ "print(\"collector current (in mA) = %.2f\"%Ic)\n",
+ "print(\"base current (in mA) = %.2f\"%Ib)\n",
+ "# Answer in the book is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "collector current (in mA) = 9.90\n",
+ "base current (in mA) = 0.10\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.a, Page No. 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate Common Emitter D.C. Current gain\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "alfa=0.950 # Common base D.C. Current gain\n",
+ "\n",
+ "#Calculations\n",
+ "beta= (alfa/(1-alfa))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Common Emitter D.C. Current gain = %.f\"%beta)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Common Emitter D.C. Current gain = 19\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5.b, Page No. 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate Common Base D.C. Current gain\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Beta=100.0 #Common emitter D.C. Current gain\n",
+ "\n",
+ "#Calculations\n",
+ "alfa= (Beta/(1+Beta))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Common Base D.C. Current gain = %.2f\"%alfa)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Common Base D.C. Current gain = 0.99\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6, Page No. 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base current and collector current\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Beta=100 # Common Emitter D.C. Current gain\n",
+ "Ie=10.0 # Emitter current in mili ampere\n",
+ "\n",
+ "#Calculation\n",
+ "Ib=(Ie/(1+Beta)) # Emitter current in mili amperen mA\n",
+ "Ic= Ie-Ib # Collector current in mili amperen mA\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base current (in mA) = %.3f\"%Ib)\n",
+ "print(\"Collector current (in mA) = %.3f\"%Ic)\n",
+ "#Answer in the book is incorrect"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base current (in mA) = 0.099\n",
+ "Collector current (in mA) = 9.901\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.7, Page No. 64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate the collector to emitter voltage(Vce) and Collector current (Ic)\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc= 12.0 # as Ic=0 so Vce=Vcc (In volts)\n",
+ "Rc= 3.0 # Collector Resistance in killo oms\n",
+ "\n",
+ "#Calcuations\n",
+ "Ic=Vcc/Rc # Collector Current in Amperes\n",
+ "Vce=Vcc\n",
+ "\n",
+ "#Result\n",
+ "print(\"Colletor to emitter voltage (in volts) = %.f\"%Vce)\n",
+ "print(\" Collector current (in mA) = %.f\"%Ic)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Colletor to emitter voltage (in volts) = 12\n",
+ " Collector current (in mA) = 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.a, Page No. 73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate oerating point\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc= 6.0 # Colector voltage in volts\n",
+ "Rb= 530.0 # in kilo ohms\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=2.0 # Collector resistance in killo ohms\n",
+ "Vbe= 0.7 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ib= ((Vcc-Vbe)/Rb) # in micro amperes\n",
+ "Ic=Beta*Ib # in milli ampere\n",
+ "Vce= Vcc-(Ic*Rc) # Colector to emitter voltage in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"Operating point is (Vce,Ic):\")\n",
+ "print(\"Vce = %.f V\\t Ic = %.f micro-A\"%(Vce,Ic))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Operating point is (Vce,Ic):\n",
+ "Vce = 4 V\t Ic = 1 micro-A\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8.b, Page No. 73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate stability factor\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "\n",
+ "#Calculations\n",
+ "S=1+Beta \n",
+ "\n",
+ "#Result\n",
+ "print(\"The Stability factor = %.f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Stability factor = 101\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.a, Page No. 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base current\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Rb= 200.0 # in kilo ohms\n",
+ "Beta=75.0 # Common emitter D.C. Current gain\n",
+ "Rc=0.8 # Collector resistance in killo ohms\n",
+ "Vbe= 0.0 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ib=Vcc/Rb\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base current in micro-A = %.1f\"%(Ib*10**3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base current in micro-A = 100.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.b, Page No. 74 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate collector current\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Rb= 200.0 # in kilo ohms\n",
+ "Beta=75.0 # Common emitter D.C. Current gain\n",
+ "Rc=0.8 # Collector resistance in killo ohms\n",
+ "Vbe= 0.0 # Base to emitter voltage in volts\n",
+ "Ib=0.1 # Base current in mA\n",
+ "\n",
+ "#Cacualtions\n",
+ "Ic=Beta*Ib # Collector current in mA\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector current in mA = %.1f\"%Ic)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current in mA = 7.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.c, Page No. 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate collector TO emitter voltage\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Rb= 200.0 # in kilo ohms\n",
+ "Beta=75.0 # Common emitter D.C. Current gain\n",
+ "Rc=0.8 # Collector resistance in killo ohms\n",
+ "Vbe= 0.0 # Base to emitter voltage in volts\n",
+ "Ib=0.1 # Base current in mA\n",
+ "Ic=7.5 # Base current in mA\n",
+ "\n",
+ "#Calculations\n",
+ "Vce=Vcc- (Ic*Rc)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector to emitter voltage in volts = %.f\"%Vce)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector to emitter voltage in volts = 14\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9.d, Page No. 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate collector TO emitter voltage\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Rb= 200.0 # in kilo ohms\n",
+ "Beta=75.0 # common emitter D.C. Current gain\n",
+ "Rc=0.8 # Collector resistance in killo ohms\n",
+ "Vbe= 0.0 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "S=1+Beta \n",
+ "\n",
+ "#Resut\n",
+ "print(\"The Stability factor = %.f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Stability factor = 76\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.10, Page No. 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base resistance , Voltage between collector & ground and Stability factor\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=12.0 # Colector voltage in volts\n",
+ "Ib= 0.3 # in mili ampere\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=0.3 # Collector resistance in killo ohms\n",
+ "\n",
+ "#Calaculations\n",
+ "Rb=Vcc/Ib\n",
+ "Ic= Beta*Ib\n",
+ "Vce=Vcc -(Ic*Rc)\n",
+ "S=1+Beta \n",
+ "\n",
+ "#Result\n",
+ "print(\"Base resistance in killo ohms = %.f\"%Rb)\n",
+ "print(\"Collector to ground voltgae in volts = %.f\"%Vce)\n",
+ "print(\"The Stability factor = %.f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base resistance in killo ohms = 40\n",
+ "Collector to ground voltgae in volts = 3\n",
+ "The Stability factor = 101\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.11, Page No. 76"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base current , Collector current and Collector to emitter voltage\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Rb= 400.0 # in KILLO OHMS\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=2.0 # Collector resistance in killo ohms\n",
+ "Re=1.0 # Emitter resistance in killo ohms\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ib= Vcc / (Rb + (Beta*Re))\n",
+ "Ic= Beta*Ib\n",
+ "Vce=Vcc -(Ic*(Rc+Re))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base current in mA = %.2f\"%Ib)\n",
+ "print(\"Collector current in mA = %.f\"%Ic)\n",
+ "print(\"Collector to ground voltgae in volts = %.f\"%Vce)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base current in mA = 0.04\n",
+ "Collector current in mA = 4\n",
+ "Collector to ground voltgae in volts = 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12, Page No. 77"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate Collector current and Collector to emitter voltage\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=25.0 # Colector voltage in volts\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "Rb= 180.0 # in KILLO OHMS\n",
+ "Beta=80.0 # Common emitter D.C. Current gain\n",
+ "Rc=0.82 # Collector resistance in killo ohms\n",
+ "Re=0.2 # Emitter resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= (Vcc-Vbe)/(Re + (Rb/Beta))\n",
+ "Ic = math.floor(Ic*10)/10\n",
+ "Vce=Vcc -(Ic*(Rc+Re))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector current in mA = %.1f\"%Ic)\n",
+ "print(\"Collector to ground voltgae in volts = %f\"%Vce)\n",
+ "#Answer for Vce is incorrect in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current in mA = 9.9\n",
+ "Collector to ground voltgae in volts = 14.902000\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.13, Page No. 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate Collector current , Collector to emitter voltage and stability factor\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "Rb= 200.0 # in KILLO OHMS\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=20.0 # Collector resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= (Vcc-Vbe)/(Rc + (Rb/Beta));\n",
+ "Vce=Vcc -(Ic*Rc);\n",
+ "S=(1+Beta)/(1+Beta*(Rc/(Rc+Rb)));\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector current in mA = %.3f\"%Ic)\n",
+ "print(\"Collector to ground voltgae in volts = %.2f\"%(math.ceil(Vce*100)/100))\n",
+ "print(\"The Stability factor = %.3f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current in mA = 0.877\n",
+ "Collector to ground voltgae in volts = 2.46\n",
+ "The Stability factor = 10.009\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.14, Page No. 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate base current , Collector current , Collector to emitter voltage and stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=10.0 # Colector voltage in volts\n",
+ "Vbe=0.0 # Base to emitter voltage in volts\n",
+ "Rb= 100.0 # in KILLO OHMS\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=10.0 # Collector resistance in killo ohms\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ib= (Vcc-Vbe)/(Rb+ Beta*Rc)\n",
+ "Ic= Beta * Ib\n",
+ "Vce=Vcc -(Ic*Rc)\n",
+ "S=(1.0+Beta)/(1.0+Beta*(Rc/(Rc+Rb)))\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"base current = %.f micro-A\"%(Ib*1000))\n",
+ "print(\"Collector current = %.1f mA\"%Ic)\n",
+ "print(\"Collector to ground voltgae = %.1f V\"%(math.ceil(Vce)))\n",
+ "print(\"The Stability factor = %.3f\"%S)\n",
+ "#Answer for stability is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "base current = 9 micro-A\n",
+ "Collector current = 0.9 mA\n",
+ "Collector to ground voltgae = 1.0 V\n",
+ "The Stability factor = 10.009\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.15, Page No. 84"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate emitter current , Collector current and Collector to emitter voltage \n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=10.0 # Colector voltage in volts\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "Vee=10.0 # emitter voltage in volts\n",
+ "Rb= 50.0 # in KILLO OHMS\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=1.0 # Collector resistance in killo ohms\n",
+ "Re=5.0 # Emitter resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Ie= (Vee-Vbe)/Re\n",
+ "Ic= Ie\n",
+ "Vce1=Vcc -(Ic*Rc)\n",
+ "Ve=-Vbe\n",
+ "Vce=Vce1-Ve\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter Current in mA = %.2f\"%Ie)\n",
+ "print(\"Collector current in mA = %.2f\"%Ic)\n",
+ "print(\"Collector to ground voltgae in volts = %.2f\"%Vce)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter Current in mA = 1.86\n",
+ "Collector current in mA = 1.86\n",
+ "Collector to ground voltgae in volts = 8.84\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.16, Page No. 86"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate the change in q point\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Vbe1=0.7 # Base to emitter voltage in volts\n",
+ "Vee=20.0 # emitter voltage in volts\n",
+ "Rb= 10.0 # in KILLO OHMS\n",
+ "Beta1=50.0 # Common emitter D.C. Current gain\n",
+ "Rc=5.0 # Collector resistance in killo ohms\n",
+ "Re=10.0 # Emitter resistance in killo ohms\n",
+ "Vbe2=0.6 # Base to emitter voltage in volts\n",
+ "Beta2=100.0 # Common emitter D.C. Current gain\n",
+ "\n",
+ "#Calculation\n",
+ "Ie1= (Vee-Vbe1)/(Re+(Rb/Beta1))\n",
+ "Ic1=Ie1\n",
+ "Vce1a=Vcc -(Ic1*Rc)\n",
+ "Ve=-Vbe1\n",
+ "Vce1=Vce1a-Ve\n",
+ "Vce1 = math.ceil(Vce1*100)/100\n",
+ "Ie2= (Vee-Vbe2)*10**3/(Re*10**3+(Rb*10**3/Beta2))\n",
+ "Ie2 = math.ceil(Ie2*1000)/1000\n",
+ "Ic2=Ie2\n",
+ "Vce2a=Vcc -(Ic2*Rc)\n",
+ "Ve=-Vbe2\n",
+ "Vce2=Vce2a-Ve\n",
+ "detaIc= ((Ie2-Ie1)/Ie1)*100\n",
+ "detaVce=((Vce1-Vce2)/Vce1)*100\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter Current in first case,Ie = %.3f mA\"%Ie1)\n",
+ "print(\"Collector-to-emitter voltgae in first case,Vce = %.2f V\"%Vce1)\n",
+ "print(\"Emitter Current in second case, Ie = %.3f mA\"%Ie2)\n",
+ "print(\"Collector-to-emitter voltgae in 2nd case, Vce = %.3f V\"%Vce2)\n",
+ "print(\"Change in collector current = %.2f%%\"%(math.ceil(detaIc*100)/100))\n",
+ "print(\"Change in collector to emitter voltage = %.2f%%\"%detaVce)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter Current in first case,Ie = 1.892 mA\n",
+ "Collector-to-emitter voltgae in first case,Vce = 11.24 V\n",
+ "Emitter Current in second case, Ie = 1.921 mA\n",
+ "Collector-to-emitter voltgae in 2nd case, Vce = 10.995 V\n",
+ "Change in collector current = 1.53%\n",
+ "Change in collector to emitter voltage = 2.18%\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.17, Page No. 90"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Calculate dynamic input resistance\n",
+ " \n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "deltaVbe=200.0 # in milli volts\n",
+ "deltaIe=5.0 # in milli ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Ri=deltaVbe/deltaIe\n",
+ "\n",
+ "#Result\n",
+ "print(\"Dyanamic input resistance is (in ohms) = %.f\"%Ri)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dyanamic input resistance is (in ohms) = 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.18, Page No. 90"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Transistor parameters\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=15.0 # Colector voltage in volts\n",
+ "Rb= 180.0 # in kilo ohms\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=1.5 # Collector resistance in killo ohms\n",
+ "Vbe= 0.7 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ib= ((Vcc-Vbe)/Rb) # in milli amperes\n",
+ "Ic=Beta*Ib # in milli ampere\n",
+ "Vce= Vcc-(Ic*Rc) # Colector to emitter voltage in volts\n",
+ "Vc=Vce\n",
+ "Vb=Vbe\n",
+ "Vcb=Vc-Vb\n",
+ "\n",
+ "#Result\n",
+ "print(\"base current = %.2f micro-A \"%(Ib*10**3))\n",
+ "print(\"Collector current = %.2f mA\"%Ic)\n",
+ "print(\"Collector to emitter voltage = %.1f V\"%Vce)\n",
+ "print(\"Collector voltage = %.1f V\"%Vc)\n",
+ "print(\"Base voltage = %.1f V\"%Vb)\n",
+ "print(\"Collector to base voltage = %.1f V\"%Vcb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "base current = 79.44 micro-A \n",
+ "Collector current = 7.94 mA\n",
+ "Collector to emitter voltage = 3.1 V\n",
+ "Collector voltage = 3.1 V\n",
+ "Base voltage = 0.7 V\n",
+ "Collector to base voltage = 2.4 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.19, Page No. 91"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Operating point , stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=10.0 # Colector voltage in volts\n",
+ "Rb= 930.0 # in kilo ohms\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=4.0 # Collector resistance in killo ohms\n",
+ "Vbe= 0.7 # Base to emitter voltage in volts\n",
+ "Ib= ((Vcc-Vbe)/Rb)# in milli amperes\n",
+ "Ic=Beta*Ib # in milli ampere\n",
+ "Vce= Vcc-(Ic*Rc) # Colector to emitter voltage in volts\n",
+ "S=(1+Beta)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector to emitter voltage In Volts = %.f\"%Vce)\n",
+ "print(\"Collector current in milli Ampere = %.f\"%Ic)\n",
+ "print(\"The Stability factor = %.f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector to emitter voltage In Volts = 6\n",
+ "Collector current in milli Ampere = 1\n",
+ "The Stability factor = 101\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.20, Page No. 92"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Base Resistance , stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable Declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Rc=1.0 # Collector resistance in killo ohms\n",
+ "Vce=4.0 # Collector to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= ((Vcc-Vce)/Rc) # in milli amperes\n",
+ "Ib=Ic/Beta # in milli ampere\n",
+ "Rb=Vce/Ib # in Killo ohms\n",
+ "x = math.floor((1+Beta*(Rc/(Rc+Rb)))*100)/100\n",
+ "S=math.floor((1+Beta)*100/x)/100\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base resistance = %.f k-ohm\"%Rb)\n",
+ "print(\"The Stability factor = %.2f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base resistance = 25 k-ohm\n",
+ "The Stability factor = 20.86\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.21, Page No. 92"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Quiescent , stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # Colector voltage in volts\n",
+ "Beta=50.0 # Common emitter D.C. Current gain\n",
+ "Rc=2.0 # Collector resistance in killo ohms\n",
+ "Rb= 100.0 # in kilo ohms\n",
+ "Vbe=0.0 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= (Vcc-Vbe)/(Rc+(Rb/Beta)) # in milli amperes\n",
+ "Ib=Ic/Beta # in milli ampere\n",
+ "Vce= Vcc-(Ic*Rc) # Colector to emitter voltage in volts\n",
+ "S=(1+Beta)/(1+((Beta*Rc)/(Rc+Rb)))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Operating point is (Vce,Ic): \")\n",
+ "print(\"Colector to emitter voltage = %.f V\"%Vce)\n",
+ "print(\"Collector current = %.1f mA\"%Ic)\n",
+ "print(\"The Stability factor = %.2f\"%S)\n",
+ "#Answer for stability factor is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Operating point is (Vce,Ic): \n",
+ "Colector to emitter voltage = 5 V\n",
+ "Collector current = 2.5 mA\n",
+ "The Stability factor = 25.75\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.22, Page No. 93"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Collector to emitter bias voltage\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Beta=100 # Common emitter D.C. Current gain\n",
+ "Rc=2.0 # Collector resistance in killo ohms\n",
+ "Rb= 100.0 # in kilo ohms\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "Ic=10.0 # in milli amperes\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=Ic/Beta # in milli ampere\n",
+ "Vce= Vbe+(Ib*Rb) # Colector to emitter voltage in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"Colector to emitter bias voltage = %.1f V\"%Vce)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Colector to emitter bias voltage = 10.7 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.23, Page No. 93"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Base Currecnt ,Collector current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Icbo=0.0 # collecttor to base leakage current\n",
+ "Vcc=9.0 # Colector voltage in volts\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Vce=5.0 # Collector to emitter voltage in volts\n",
+ "Ic=0.2 # in milli amperes\n",
+ "Rc=(Vcc-Vce)/Ic # Collector Reesistance in ohms\n",
+ "Ib=Ic/Beta # in milli ampere\n",
+ "Rb=Vce/Ib # Base resistance in ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector Resistance = %.f ohm\"%Rc)\n",
+ "print(\"Base Resistance = %.1f k-ohm\"%(Rb/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector Resistance = 20 ohm\n",
+ "Base Resistance = 2.5 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.24, Page No. 94 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Base Resistance , stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=24.0 # Colector voltage in volts\n",
+ "Beta=45.0 # Common emitter D.C. Current gain\n",
+ "Rl=10.0 # Collector resistance in killo ohms\n",
+ "Re=0.27 # Emitter resistance in killo ohms\n",
+ "Vce=5 # Collector to emitter voltage in volts\n",
+ "Vbe=0.6 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=(Vcc-Vce)/((1+Beta)*(Rl+Re)) # in milli ampere\n",
+ "Ic=Ib/Beta # in micro ampere\n",
+ "R=(Vce-Vbe)/Ib # Resistance in killo ohms\n",
+ "x = math.floor((1+Beta*(Re/(Re+R)))*100)/100\n",
+ "S=(1+Beta)/x\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base resistance = %.f k-ohm\"%(math.ceil(R)))\n",
+ "print(\"The Stability factor = %.2f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base resistance = 110 k-ohm\n",
+ "The Stability factor = 41.44\n"
+ ]
+ }
+ ],
+ "prompt_number": 53
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.25, Page No.95 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Quiescent , stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=16.0 # Colector voltage in volts\n",
+ "alfa=0.985\n",
+ "Rc=3.0 # Collector resistance in killo ohms\n",
+ "Re= 2.0 # in kilo ohms\n",
+ "R1= 56.0 # in kilo ohms\n",
+ "R2= 20.0 # in kilo ohms\n",
+ "Vbe=0.3 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Beta= round(alfa/(1-alfa))\n",
+ "Vb=Vcc * (R2/(R1+R2)) # vOLTAGE AT BASE\n",
+ "Vb = math.floor(Vb*100)/100\n",
+ "Ic= (Vb-Vbe)/Re # in milli amperes\n",
+ "Ib=Ic/Beta # in milli ampere\n",
+ "Vce= Vcc-(Ic*(Rc+Re)) # Colector to emitter voltage in volts\n",
+ "Rth=math.floor((R1*R2)*100/(R1+R2))/100\n",
+ "\n",
+ "S=((1+Beta)*(1+(Rth/Re)))/(1+Beta+(Rth/Re))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Operating point is (Vce,Ic): \")\n",
+ "print(\"Colector to emitter voltage = %.3f V\"%Vce)\n",
+ "print(\"Collector current = %.3f mA\"%Ic)\n",
+ "print(\"The Stability factor = %.2f\"%S)\n",
+ "#Answer for Ic is wrong and hence the Vce. Also answer for stability factor is wrong."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Operating point is (Vce,Ic): \n",
+ "Colector to emitter voltage = 6.225 V\n",
+ "Collector current = 1.955 mA\n",
+ "The Stability factor = 7.54\n"
+ ]
+ }
+ ],
+ "prompt_number": 68
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.26, Page No. 96\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Find R1,R2 & Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # Colector voltage in volts\n",
+ "Beta=50.0 # Common emitter D.C. Current gain\n",
+ "Rc=2.0 # Collector resistance in killo ohms\n",
+ "Vce=4.0 # Collector to emitter voltage in volts\n",
+ "Vbe=0.3 # Base to emitter voltage in volts\n",
+ "Ic=2.0 # Collector current in milli Ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=Ic/Beta # Base current in milli ampere\n",
+ "I1=10*Ib\n",
+ "Ie=Ic # Emitter current in mili ampere\n",
+ "Re=(Vcc-Ic*Rc-Vce)/Ic# Emiier Resistance\n",
+ "V2=Vbe+Ic*Re # Voltage across R2\n",
+ "R2=V2/I1\n",
+ "R1=25-R2\n",
+ "\n",
+ "#Result\n",
+ "print(\"Resistance, R1 = %.2f k-ohm\"%R1)\n",
+ "print(\"Resistance, R2 = %.2f k-ohm\"%R2)\n",
+ "print(\"Emitter Resistance, Re = %.1f k-ohm\"%Re)\n",
+ "#Answer for R2 is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance, R1 = 19.25 k-ohm\n",
+ "Resistance, R2 = 5.75 k-ohm\n",
+ "Emitter Resistance, Re = 1.0 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 70
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.27, Page No. 96"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Find R\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=24.0 # Colector voltage in volts\n",
+ "Beta=45.0\n",
+ "Rc=10.0 # Collector resistance in killo ohms\n",
+ "Re= 0.27 # in kilo ohms\n",
+ "Vce=5.0 # Collector to emitter voltage in volts\n",
+ "Vbe=0.6 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=(Vcc-Vce)/((1+Beta)*(Rc+Re))\n",
+ "Ic=Ib/Beta\n",
+ "R=(Vce-Vbe)/Ib\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base resistance = %.f k-ohm\"%(math.ceil(R)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base resistance = 110 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 72
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.28, Page No.97"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ic,Vce\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=22.0 # Colector voltage in volts\n",
+ "Beta=40.0\n",
+ "Rc=10.0 # Collector resistance in killo ohms\n",
+ "Re= 1.5 # in kilo ohms\n",
+ "R1= 40.0 # in kilo ohms\n",
+ "R2= 4.0 # in kilo ohms\n",
+ "Vbe=0.5 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Vb=Vcc * (R2/(R1+R2)) # VOLTAGE AT BASE\n",
+ "Ic= (Vb-Vbe)/Re # in milli amperes\n",
+ "Ib=Ic/Beta # in milli ampere\n",
+ "Vce= Vcc-(Ic*(Rc+Re)) # Colector to emitter voltage in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"Colector to emitter voltage = %.1f V\"%Vce)\n",
+ "print(\"Collector current = %.f mA\"%Ic)\n",
+ "#Answer for Vce is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Colector to emitter voltage = 10.5 V\n",
+ "Collector current = 1 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 73
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.29, Page No. 98"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Voltage across Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Beta=50.0\n",
+ "R1= 60.0 # in kilo ohms\n",
+ "R2= 30.0 # in kilo ohms\n",
+ "Vbe=0.6 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Vb=Vcc * (R2/(R1+R2))\n",
+ "Ve=Vb-Vbe\n",
+ "\n",
+ "#Result\n",
+ "print(\"voltage across Re = %.2f V\"%Ve)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "voltage across Re = 6.07 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 74
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.30, Page No. 99"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Voltage across Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # in volts\n",
+ "Rb=200.0 # Base resistance in killo ohms\n",
+ "Vbe=0.8 # Base to emitter voltage in volts\n",
+ "Beta=100.0\n",
+ "Vce=0.2 # Collector to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=5/Rb # Base current in milli ampere\n",
+ "Ic=Beta*Ib # Collector current in milli ampere\n",
+ "Rc= (Vcc-Vce)/Ic # Resistance\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector resistance = %.2f k-ohm\"%Rc) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector resistance = 3.92 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.31, Page No. 99"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Cut off,Vc & Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # in volts\n",
+ "Rc=3.0 # Collector resistance in killo ohms\n",
+ "Rl=0.5 # in kilo ohms\n",
+ "Rb=7.0 # in kilo ohms\n",
+ "Beta=100.0 # Common emitter D.C. Current gain\n",
+ "Vbe=0.8 # Base to emitter voltage in volts\n",
+ "Ic=2.78 # in mA Applying KVL\n",
+ "Ib=0.1 # in mA Applying KVL\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ibmin=Ic/Beta\n",
+ "Vc=Vbe # in saturation region\n",
+ "Vce=Vc-Rl*(Ic+Ib)\n",
+ "Re=((Vcc-Vce)/Ic)-Rc\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base current = %.1f mA\"%Ib)\n",
+ "print(\"Minimum Base current = %.4f mA\"%Ibmin)\n",
+ "print(\"\\nAs Base current is more than minimum base current so it is in saturation region\")\n",
+ "print(\"\\nEmitter resistance = %.f ohm\"%(Re*1000))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base current = 0.1 mA\n",
+ "Minimum Base current = 0.0278 mA\n",
+ "\n",
+ "As Base current is more than minimum base current so it is in saturation region\n",
+ "\n",
+ "Emitter resistance = 827 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 77
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.32, Page No. 100"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Beta ,Vcc & Rb\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rc=2.7 # Collector resistance in killo ohms\n",
+ "Re=0.68 # Collector resistance in killo ohms\n",
+ "Ib=0.02 # Base Current in mA\n",
+ "Vce=7.3 # Collector to emitter voltage in volts\n",
+ "Vbe=0.0 # Base to emitter voltage in volts\n",
+ "Ve=2.1 # Emitter Voltage\n",
+ "\n",
+ "#Calculations\n",
+ "Ie= Ve/Re # Emiiter Current in mA\n",
+ "Ic=Ie\n",
+ "Beta=Ic/Ib # Common emitter D.C. Current gain\n",
+ "Vcc= Vce+Ic*(Rc+Re) # Supply Voltage\n",
+ "Vcc = math.floor(Vcc*10)/10\n",
+ "Rb=(Vcc-Ve)/Ib # Base resistance in Killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Common emitter D.C. Current gain (unitless) = %.f\"%Beta)\n",
+ "print(\"Supply Voltage = %.1f V\"%Vcc)\n",
+ "print(\"base resistance = %.f k-ohm\"%Rb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Common emitter D.C. Current gain (unitless) = 154\n",
+ "Supply Voltage = 17.7 V\n",
+ "base resistance = 780 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 84
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.33, Page No. 101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ic & Vce\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=18 # Colector voltage in volts\n",
+ "Rc=2.2 # Collector resistance in killo ohms\n",
+ "Rb=510.0 # Base resistance in killo ohms\n",
+ "Re=1.8 # Emitter resistance in killo ohms\n",
+ "Beta=90.0 # Common emitter D.C. Current gain\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=Vcc/(Rb+Beta*(Rc+Re)) # Base Current in mA\n",
+ "Ib = math.floor(Ib*100)/100\n",
+ "Ic=Beta*Ib # Collector current in mA\n",
+ "Beta=Ic/Ib # Common emitter D.C. Current gain\n",
+ "Vce= Ib*Rb # Collector to emitter voltage in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"Colector to emitter voltage, Vce = %.1f V\"%Vce)\n",
+ "print(\"Collector current, Ic = %.1f mA\"%(math.floor(Ic*10)/10)) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Colector to emitter voltage, Vce = 10.2 V\n",
+ "Collector current, Ic = 1.8 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 91
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.34, Page No.101 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Base current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ie=10.0 # Emitter current in mA\n",
+ "Ic=9.95 # Collector current in mA\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ib=Ie-Ic # Base Current in mA\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base Current = %.2f mA\"%Ib)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base Current = 0.05 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.35, Page No. 101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ic,Vc,Ve & Vce\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=30.0 # Colector voltage in volts\n",
+ "Beta=100.0\n",
+ "Rc=6.2 # Collector resistance in killo ohms\n",
+ "Re=1.5 # Emitter resistance in killo ohms\n",
+ "Rb=690.0 # Base resistance in killo ohms\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "Ib= (Vcc-Vbe)/(Rb+(1+Beta)*Rc+(1+Beta)*Re)\n",
+ "Ic=math.ceil(Ib*Beta) # in milli ampere\n",
+ "Ie=Ib*(1+Beta) # in milli ampere\n",
+ "Vce=Vcc-Ve-(Ic+Ib)*Rc\n",
+ "Vce = math.ceil(Vce*100)/100\n",
+ "Vc=Vce+Ve\n",
+ "print(\"Collector current, Ic = %.f mA\"%Ic)\n",
+ "print(\"emitter voltage, Ve = %.2f V\"%Ve)\n",
+ "print(\"Colector to emitter voltage, Vce = %.2f V\"%Vce)\n",
+ "print(\"collector voltage = %.2f V\"%Vc)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current, Ic = 2 mA\n",
+ "emitter voltage, Ve = 3.03 V\n",
+ "Colector to emitter voltage, Vce = 14.45 V\n",
+ "collector voltage = 17.48 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 105
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.36, Page No. 103"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# R1,Rc & S\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=16.0 # Colector voltage in volts\n",
+ "alfa=0.985\n",
+ "Ieq=2.0 # Emiier current in mA\n",
+ "R2=30.0 # resistance in killo ohms\n",
+ "Re=1.0 # Emitter resistance in killo ohms\n",
+ "Vbe=0.2 # Base to emitter voltage in volts\n",
+ "Vceq=6.0 # Collector to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Beta= alfa/(1-alfa)\n",
+ "Icq=alfa*Ieq\n",
+ "Rc=(Vcc-Vceq-Ieq*Re)/Icq\n",
+ "Ir1=((Ieq*Re+Vbe)/R2)+Icq/Beta\n",
+ "R1=(Vcc-Vbe-(Ieq*Re))/Ir1\n",
+ "Rb= (R1*R2)/(R1+R2)\n",
+ "S=(1+Beta)/(1+Beta*(Re/(Re+Rb)))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector resistence, Rc = %.2f k-ohm\"%Rc)\n",
+ "print(\"Resistance, R1 = %.2f k-ohm\"%(math.floor(R1*100)/100))\n",
+ "print(\"The Stability factor = %.2f\"%(math.floor(S*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector resistence, Rc = 4.06 k-ohm\n",
+ "Resistance, R1 = 133.54 k-ohm\n",
+ "The Stability factor = 18.64\n"
+ ]
+ }
+ ],
+ "prompt_number": 110
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.37.a, Page No. 104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# baising component\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=12.0 # Colector voltage in volts\n",
+ "Beta=180.0\n",
+ "Ieq=2.0 # Emiier current in mA\n",
+ "Rc=1.0 # Collector resistance in killo ohms\n",
+ "Vbe=0.6 # Base to emitter voltage in volts\n",
+ "Vceq=6.0 # Collector to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= (Vcc-Vceq)/Rc\n",
+ "Ib=Ic/Beta\n",
+ "Rb=(Vcc-Vbe)/Ib\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector current in fixed bias case = %.f mA\"%Ic)\n",
+ "print(\"Base current in fixed bias case = %.2f mA\"%(Ib*10**3))\n",
+ "print(\"Base resistance in fixed bias case = %.f k-ohm\"%Rb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current in fixed bias case = 6 mA\n",
+ "Base current in fixed bias case = 33.33 mA\n",
+ "Base resistance in fixed bias case = 342 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 115
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.37.b, Page No. 104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# baising component\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vb=1.6 # Base voltage\n",
+ "Ve=1.0 # emitter voltage\n",
+ "Vcc=12.0 # Collector voltage in volts\n",
+ "Beta=180.0\n",
+ "Ieq=2.0 # Emiier current in mA\n",
+ "Rc=1.0 # Collector resistance in killo ohms\n",
+ "Vbe=0.6 # Base to emitter voltage in volts\n",
+ "Vceq=6.0 # Collector to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ic= (Vcc-Vceq-Ve)/Rc\n",
+ "Ib=math.ceil(Ic*10**5/Beta)*1000/10**5\n",
+ "Ie=Ic+Ib*10**-3 # emitter current in milli ampere\n",
+ "Re= (Ve/(Ie*10**-3)) # emitter resistance in killo ohms\n",
+ "Ir2= 10*Ib\n",
+ "R2= (Ve+Vbe)/(Ir2*10**-6)\n",
+ "Ir1=Ir2+Ib\n",
+ "R1=((Vcc-Vb)/(Ir1*10**-3))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter Current, Ie = %.3f mA\"%(math.floor(Ie*1000)/1000))\n",
+ "print(\"Resistance, Re = %.1f ohm\"%(Re))\n",
+ "print(\"Resistance, R1 = %.2f k-ohm\"%(R1))\n",
+ "print(\"Resistance, R2 = %.1f ohm\"%(R2))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter Current, Ie = 5.027 mA\n",
+ "Resistance, Re = 198.9 ohm\n",
+ "Resistance, R1 = 34.03 k-ohm\n",
+ "Resistance, R2 = 5759.5 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.38.a, Page No. 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta=180.0 # Common emitter D.C. Current gain\n",
+ "Re=1.0 # Collector resistance in killo ohms\n",
+ "R1=5.76 # resistance in killo ohms\n",
+ "R2=34.67 # resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "S=1+Beta\n",
+ "\n",
+ "#Result\n",
+ "print(\"Stability factor in fixed bias case is %.f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Stability factor in fixed bias case is 181\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.38.b, Page No. 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta=180.0 # Common emitter D.C. Current gain\n",
+ "Re=0.199 # Collector resistance in killo ohms\n",
+ "R1=5.76 # resistance in killo ohms\n",
+ "R2=34.67 # resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Rb=math.floor((R1*R2)*100/(R1+R2))/100\n",
+ "S=(1+Beta)/(1+(Beta*(Re/(Re+Rb))))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Stability factor in self bias case is %.2f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Stability factor in self bias case is 22.67\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.39.a, Page No. 106"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Stability factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1=500.0 # Resistance in killo ohms\n",
+ "Rc=500.0 # Collector resistance in killo ohms\n",
+ "R2=5000.0 # Resistance in killo ohms\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Beta=75.0\n",
+ "Rc=6.2 # Collector resistance in killo ohms\n",
+ "Re=90.0 # Emitter resistance in ohms\n",
+ "Rb=690.0 # Base resistance in killo ohms\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Rb=((R1*R2)/(R1+R2))\n",
+ "Vb=Vcc * (R1/(R1+R2))# VOLTAGE AT BASE\n",
+ "Icbo=0.02 # Collector to base leakage current in mA\n",
+ "Sre= (Beta/(Rb+Re*Beta)**2)*(Icbo*10**-6*Rb-Beta*(Vb+Rb*Icbo*10**-6-Vbe))\n",
+ "\n",
+ "#Result\n",
+ "print(\"Stability factor = %.3f * 10^-4 A/ohms\"%(Sre*10**4))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Stability factor = -1.212 * 10^-4 A/ohms\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.39.b, Page No. 106"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Change in Icq\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1=500.0 # Resistance in killo ohms\n",
+ "Rc=500. # Collector resistance in killo ohms\n",
+ "R2=5000.0 # Resistance in killo ohms\n",
+ "Vcc=20.0 # Colector voltage in volts\n",
+ "Beta=75.0\n",
+ "Rc=6.2 # Collector resistance in killo ohms\n",
+ "Re=90.0 # Emitter resistance in ohms\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Rb=((R1*R2)/(R1+R2))\n",
+ "Vb=Vcc * (R1/(R1+R2)) # VOLTAGE AT BASE\n",
+ "Icbo=0.02 # Collector to base leakage current in mA\n",
+ "Sre= (Beta/(Rb+Re*Beta)**2)*(Icbo*10**-6*Rb-Beta*(Vb+Rb*Icbo*10**-6-Vbe))\n",
+ "DeltaRe= 110-90 # Change in ohms\n",
+ "DeltaIcq= Sre*DeltaRe # Change in Icq\n",
+ "\n",
+ "#Result\n",
+ "print(\"Change in Icq = %.3f mA\"%(DeltaIcq*1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Change in Icq = -2.424 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.40, Page No. 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# R1 & R2\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=5.0 # Colector voltage in volts\n",
+ "Beta=100.0\n",
+ "Vce=2.5 # Collector to emitter voltage in volts\n",
+ "Vbe=0.6 # Base to emitter voltage in volts\n",
+ "R4=0.3 # Resistance in killo ohms\n",
+ "R2=10.0 # Resistance in killo ohms\n",
+ "Ic=1.0 # Collector current in mA\n",
+ "\n",
+ "#Calculations\n",
+ "Vr4=(1+(1/Beta))*Ic*R4\n",
+ "Vcn= Vce-Vr4\n",
+ "R3=(Vcc-Vcn)/Ic\n",
+ "Rb=8.03\n",
+ "R1=(Rb*R2)/(R2-Rb)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Resistance, R1 = %.f k-ohm\"%(math.floor(R1)))\n",
+ "print(\"Base Resistance = %.2f k-ohm\"%Rb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance, R1 = 40 k-ohm\n",
+ "Base Resistance = 8.03 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 45
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.41, Page No. 108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Re , S\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=12.0 # Colector voltage in volts\n",
+ "Beta=50.0\n",
+ "Vce=2.5 # Collector to emitter voltage in volts\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "Re= 2.57 # Emitter resistance in killo ohms\n",
+ "Rc=4.2 # Collector resistance in killo ohms\n",
+ "\n",
+ "#Calculation\n",
+ "Ic=14/(Rc+(1+(1/Beta)*Re))\n",
+ "Ib= (6-Vbe-Ic*Re)/Re\n",
+ "DeltaIb= -1 # Change in base Current\n",
+ "S= (1+Beta)/(1+Beta)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Resistance, Re = %.2f k-ohm\"%Re)\n",
+ "print(\"Stability Factor = %.f\"%S)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance, Re = 2.57 k-ohm\n",
+ "Stability Factor = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.42, Page No. 109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Icq\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "T2=20.0 # Temperature in degree celsius\n",
+ "T1=0.0 # Temperature in degree celsius\n",
+ "Vcc=15.0 # Colector voltage in volts\n",
+ "Beta=75.0\n",
+ "Vce=2.5 # Collector to emitter voltage in volts\n",
+ "Vbe1=0.7 # Base to emitter voltage in volts\n",
+ "Rb= 50.0 # Emitter resistance in killo ohms\n",
+ "Rc=3.0 # Collector resistance in killo ohms\n",
+ "Re=1.0 # Collector resistance in killo ohms\n",
+ "\n",
+ "#Calculation\n",
+ "Ib= ((6-Vbe1)/(Rb+(1+Beta)*Re))*10**3 # Base Current in Micro Amperes\n",
+ "Ic= Beta*Ib*10**-3 # Colectore Current in Milli Ampere\n",
+ "Icbo1=0.5 # Collector to base leakage current in Micrometer\n",
+ "Icbo2=Icbo1*2**((T2-T1)/10) # Collector to base leakage current in Micrometer when temperature 20 degree celsius\n",
+ "Vbe2=Vbe1-2*T2*10**-3 # base to emitter voltage when temperature is 20 degree celsius\n",
+ "Ib1=((6-Vbe2)/(Rb+(1+Beta)*Re))*10**3 # Base Current in Micro Amperes at 20 degree celsius\n",
+ "Ib1 = math.ceil(Ib1*10)/10\n",
+ "Ic1=(Beta*(Ib*10**-3)) # Colectore Current in Milli Ampere\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Base Current = %.f micro-A\"%Ib)\n",
+ "print(\"Collector current = %.2f mA\"%Ic)\n",
+ "print(\"Collector to base leakage current when T=20 degree celsius = %.f micro-A\"%Icbo2)\n",
+ "print(\"Base to emitter voltage when T=20 degree celsius = %.2f V\"%Vbe2)\n",
+ "print(\"Base Current when T=20 degree celsius = %.1f micro-A\"%Ib1)\n",
+ "print(\"Collector current when T=20 degree celsius = %.2f mA\"%Ic1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base Current = 42 micro-A\n",
+ "Collector current = 3.15 mA\n",
+ "Collector to base leakage current when T=20 degree celsius = 2 micro-A\n",
+ "Base to emitter voltage when T=20 degree celsius = 0.66 V\n",
+ "Base Current when T=20 degree celsius = 42.4 micro-A\n",
+ "Collector current when T=20 degree celsius = 3.15 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 64
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.43, Page No. 110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# (a)quiescent current (b) drift in quiescent current\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta1=50.0 # gain at 25 degree celsius temperture\n",
+ "Beta2=200.0 # gain at 75 degree celsius temperture\n",
+ "Rb=1.0 # base resistance in killo ohms\n",
+ "Re=0.1 # emitter resistance in ohms\n",
+ "Ico1=0.01 # leakage current at 25 degree celsius temperture in micro ampere\n",
+ "Ico2=0.045 # leakage current at 75 degree celsius temperture in micro ampere\n",
+ "Vbe1=0.7 # base to emitter voltage 25 degree celsius temperture in micro ampere\n",
+ "Vbe2=0.575 # base to emitter voltage 75 degree celsius temperture in micro ampere\n",
+ "\n",
+ "#Calculations\n",
+ "dBeta=Beta2-Beta1 # Change in gain\n",
+ "dIco=Ico2-Ico1 # change in leakage current\n",
+ "dVbe=Vbe2-Vbe1 # change in base to emitter voltage\n",
+ "Ib= (1-Vbe1)/(Rb+(1+Beta1)*Re) # Base current in micro ampere\n",
+ "Ic=Beta1*Ib # Collector current in milli ampere\n",
+ "S=((1+Beta1)*(1+(Rb/Re)))/(1+Beta1+(Rb/Re))\n",
+ "S1=-(Beta1/Re*10**-3)/(1+Beta1+(Rb/Re)) # stability factor\n",
+ "S2=(S*Ic*10**-3)/(Beta1*(1+Beta1)) # stability factor\n",
+ "dIc= ((S*dIco*10**-6)+(S1*dVbe)+(S2*dBeta))*10**3\n",
+ "Icn= Ic+dIc # new collector current in milli ampere\n",
+ "\n",
+ "#Result\n",
+ "print(\"Quiescent current is %.2f mA\"%Ic)\n",
+ "print(\"Quiescent current drift at temperature 75 degree celsius is %.3f mA\"%dIc)\n",
+ "print(\"New quiescent current is %.1f mA\"%Icn)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Quiescent current is 2.46 mA\n",
+ "Quiescent current drift at temperature 75 degree celsius is 2.355 mA\n",
+ "New quiescent current is 4.8 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 67
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.44.a, Page No.111 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# R1,R2 ,Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vbe=0.2\n",
+ "Vcc=16.0 # collector voltage in volts\n",
+ "Rc=1.5 # clollector resistance in killo ohms\n",
+ "S=12.0 # stability factor\n",
+ "Vce=8.0 # Collector to emitter voltage\n",
+ "Ic=4.0 # in milli amperes\n",
+ "Beta=50.0 # gain\n",
+ "S1=3.0 # REDUCED STABILITY FACTOR\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ib=(Ic*10**-3)/Beta # Base current in micro ampere\n",
+ "Re=(Vcc-Vce-(Rc*10**3*Ic*10**-3))/(Ic*10**-3+Ib) # emitter resistance in ohms\n",
+ "Rb=round(((11*(1+Beta))/(Beta-11))*Re*10**-3) # base resistance in killo ohms\n",
+ "Vb= (Ib*Rb*1000)+Vbe+((Ic*10**-3)+(Ib*10**-6))*Re# voltage is R2\n",
+ "R1=Vcc*Rb/2.76 #Vb = 2.76 # resistance in killo ohms\n",
+ "R1= math.ceil(R1*10)/10\n",
+ "R2=R1*Rb/(R1-Rb) # RESISTANCE IN KILLO OHMS\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter Resistance,Re = %.2f k-ohm\"%(Re*10**-3))\n",
+ "print(\"Resistance, R1 = %.1f k-ohm\"%R1)\n",
+ "print(\"Resistance, R2 = %.2f k-ohm\"%(math.floor(R2*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter Resistance,Re = 0.49 k-ohm\n",
+ "Resistance, R1 = 40.6 k-ohm\n",
+ "Resistance, R2 = 8.45 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 95
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.44.b, Page No. 111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# R1,R2 ,Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vbe=0.2\n",
+ "Vcc=16.0 # collector voltage in volts\n",
+ "Rc=1.5 # clollector resistance in killo ohms\n",
+ "S=12.0 # stability factor\n",
+ "Vce=8.0 # Collector to emitter voltage\n",
+ "Ic=4.0 # in milli amperes\n",
+ "Beta=50.0 # gain\n",
+ "Ib=(Ic*10**-3)/Beta # Base current in micro ampere\n",
+ "S1=3.0 # REDUCED STABILITY FACTOR\n",
+ "\n",
+ "#Calcualtions\n",
+ "Re=(Vcc-Vce-(Rc*10**3*Ic*10**-3))/(Ic*10**-3+Ib) # emitter resistance in ohms\n",
+ "Rb=math.floor(((2*(1+Beta))/(Beta-2))*Re*10**-3) # base resistance in killo ohms\n",
+ "Vr2= Vbe+(Ic+Ib*10**3)*Re*10**-3 # voltage is R2\n",
+ "R1=math.floor((Rb)/x) # resistance in killo ohms\n",
+ "R2=(Rb*R1)/(R1-Rb) # RESISTANCE IN KILLO OHMS\n",
+ "Rb1=((3*(1+Beta))/(Beta-3))*Re*10**-3 # EFFECT OF REDUCING STABILITY FACTOR ON BASE RESISTANCE\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter Resistance = %.2f k-ohm\"%(Re*10**-3))\n",
+ "print(\"Resistance, R1 = %.f k-ohm\"%R1)\n",
+ "print(\"Resistance, R2 = %.2f k-ohm\"%(math.floor(R2*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter Resistance = 0.49 k-ohm\n",
+ "Resistance, R1 = 7 k-ohm\n",
+ "Resistance, R2 = 1.16 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 109
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.45, Page No. 113"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# R1,R2 ,Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vbe=0.2\n",
+ "Vcc=20.0 # collector voltage in volts\n",
+ "Rc=2.0 # clollector resistance in killo ohms\n",
+ "S=10.0 # stability factor\n",
+ "Vce=10.0 # Collector to emitter voltage\n",
+ "Ic=4.0 # in milli amperes\n",
+ "Beta=50.0 # gain\n",
+ "S1=3.0 # REDUCED STABILITY FACTOR\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ib=(Ic*10**-3)/Beta # Base current in micro ampere\n",
+ "Re=(Vcc-Vce-(Rc*10**3*Ic*10**-3))/(Ic*10**-3+Ib) # emitter resistance in ohms\n",
+ "Re = math.ceil(Re*10)/10\n",
+ "Rb=math.ceil(((9*(1+Beta))*1000/(Beta-9))*Re*10**-3)/1000# base resistance in killo ohms\n",
+ "Vr2= Vbe+(Ic+Ib*10**3)*Re*10**-3 # voltage is R2\n",
+ "x=(Vr2/Vcc) # Voltage\n",
+ "R1=(Rb)/x # resistance in killo ohms\n",
+ "R2=(x*R1)/(1-x) # RESISTANCE IN KILLO OHMS\n",
+ "Rb1=((3*(1+Beta))/(Beta-3))*Re*10**-3 # EFFECT OF REDUCING STABILITY FACTOR ON BASE RESISTANCE\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter resistance = %.1f ohm\"%Re)\n",
+ "print(\"Resistance R1 = %.2f k-ohm\"%R1)\n",
+ "print(\"Resistance R2 = %.2f k-ohm\"%R2)\n",
+ "print(\"Base resistance effect of reducing stability factor reduces input impedence = %f k-ohm\"%Rb1)\n",
+ "#Answer for R1 and base resistor do not match with the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter resistance = 490.2 ohm\n",
+ "Resistance R1 = 49.89 k-ohm\n",
+ "Resistance R2 = 6.17 k-ohm\n",
+ "Base resistance effect of reducing stability factor reduces input impedence = 1.595757 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.46, Page No.115 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# R1,R2 ,Re\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "S=2.0 # stability factor\n",
+ "Vbe=0.8\n",
+ "Vcc=20.0 # collector voltage in volts\n",
+ "Rc=5.0 # collector resistance in killo ohms\n",
+ "Vce=11.5 # Collector to emitter voltage\n",
+ "Ic=1.5 # in milli amperes\n",
+ "Beta=50.0 # gain\n",
+ "\n",
+ "#Calculations\n",
+ "Ib=(Ic*10**-3)/Beta # Base current in micro ampere\n",
+ "Re=(Vcc-Vce-(Rc*10**3*Ic*10**-3))/(Ic*10**-3+Ib)# emitter resistance in ohms\n",
+ "Rb=(((1+Beta))/(Beta-1))*Re # base resistance in killo ohms\n",
+ "Vr2= Vbe+(Ic+Ib*10**3)*Re*10**-3 # voltage is R2\n",
+ "x=(Vr2/Vcc) # Voltage\n",
+ "R1=math.floor(((Rb)/x)*10**-3*100)/100 # resistance in killo ohms\n",
+ "R2=((x*R1)/(1-x))*10**3 # RESISTANCE IN KILLO OHMS\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter resistance = %.1f ohm\"%(Re))\n",
+ "print(\"Resistance R1 = %.2f k-ohm\"%R1)\n",
+ "print(\"Resistance R2 = %.1f k-ohm\"%R2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter resistance = 653.6 ohm\n",
+ "Resistance R1 = 7.55 k-ohm\n",
+ "Resistance R2 = 746.7 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.47, Page No. 124"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=800.0 # Internal resistance in ohms\n",
+ "Rl=1000.0 # Load resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hie=1.0 # in killo ohms\n",
+ "Hre=2*10**-4\n",
+ "Hfe=50\n",
+ "Hoe=25*10**-6 # in ampere per volt\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ai= -Hfe/(1+Hoe*Rl) # Current gain\n",
+ "Ri= Hie*10**3-((Hfe*Hre)/(Hoe+(1/Rl))) # Input resistance in ohms\n",
+ "Ri = math.floor(Ri*100)/100\n",
+ "Av= Ai*(Rl/Ri) # Voltage Gain\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.2f\"%Ai)\n",
+ "print(\"Input resistance = %.2f ohm\"%Ri)\n",
+ "print(\"Voltage gain = %.2f\"%Av)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = -48.78\n",
+ "Input resistance = 990.24 ohm\n",
+ "Voltage gain = -49.26\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.48, Page No. 126"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av,Ro\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rl=1.2*10**3 # Load resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hib=28.0 # in ohms\n",
+ "Hrb=5*10**-4\n",
+ "Hfb=-0.98\n",
+ "Hob=0.34*10**-6 # in ampere per volt\n",
+ "\n",
+ "#Calculations\n",
+ "Ai= -Hfb/(1+Hob*Rl) # Current gain\n",
+ "Ai = math.ceil(Ai*100)/100\n",
+ "Ri= Hib+(Hrb*Ai*Rl) # Input resistance in ohms\n",
+ "Av= round(Ai*(Rl/Ri)) # Voltage Gain\n",
+ "dh=(Hib*Hob)-(Hrb*Hfb)\n",
+ "Ro=(Hib/dh)*10**-3 # Output resistance in killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.2f\"%Ai )\n",
+ "print(\"Input resistance = %.1f ohm\"%Ri)\n",
+ "print(\"Voltage gain = %.f\"%Av)\n",
+ "print(\"Ouput resistance = %.f k-ohm\"%Ro)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = 0.98\n",
+ "Input resistance = 28.6 ohm\n",
+ "Voltage gain = 41\n",
+ "Ouput resistance = 56 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.49, Page No. 129"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av,Avs,Ais\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rl=1000.0 # Load resistance in ohms\n",
+ "Rs=1200.0 # Internal Resistance\n",
+ "# H-paramters are\n",
+ "Hib=22.0 # in ohms\n",
+ "Hrb=3*10**-4\n",
+ "Hfb=-0.98\n",
+ "Hob=0.5*10**-6 # in ampere per volt\n",
+ "\n",
+ "#calculations\n",
+ "Ai= -Hfb/(1+Hob*Rl) # Current gain\n",
+ "Ai = math.ceil(Ai*100)/100\n",
+ "Ri= Hib+(Hrb*Ai*Rl) # Input resistance in ohms\n",
+ "Ri = math.ceil(Ri*10)/10\n",
+ "Av=(Ai*(Rl/Ri)) # Voltage Gain\n",
+ "dh=(Hib*Hob)-(Hrb*Hfb)\n",
+ "Avs=(Av*Ri)/(Ri+Rs) # Overall Voltage gain\n",
+ "Ais=(Ai*Rs)/(Ri+Rs) # Overall Current gain\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.2f\"%Ai)\n",
+ "print(\"Input resistance = %.1f ohm\"%Ri)\n",
+ "print(\"Voltage gain = %.3f\"%Av)\n",
+ "print(\"Overall Voltage gain = %.3f\"%Avs)\n",
+ "print(\"Overall Current gain = %.3f\"%Ais)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = 0.98\n",
+ "Input resistance = 22.3 ohm\n",
+ "Voltage gain = 43.946\n",
+ "Overall Voltage gain = 0.802\n",
+ "Overall Current gain = 0.962\n"
+ ]
+ }
+ ],
+ "prompt_number": 45
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.50, Page No.130 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av,Ro\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rl=5000.0 # Load resistance in ohms\n",
+ "Rs=1000.0 # Source internal resistance\n",
+ "R1=10.0 # Resistance in killo ohms\n",
+ "R2=10.0 # Resistance in killo ohms\n",
+ "Re=5*10**3 # Emitter resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hic=2000.0 # in killo ohms\n",
+ "Hrc=1.0\n",
+ "Hfc=-51.0\n",
+ "Hoc=25*10**-6 # in ampere per volt\n",
+ "\n",
+ "#Calculations\n",
+ "Ai= -Hfc/(1+Hoc*Rl) # Current gain\n",
+ "Ai = math.floor(Ai*10)/10\n",
+ "Ri= (Hic+(Hrc*Ai*Rl)) # Input resistance in ohms\n",
+ "Ri = Ri/1000 # in Killo ohm\n",
+ "Z1= (R1*R2)/(R1+R2)\n",
+ "Zi=(Ri*Z1)/(Ri+Z1) # input resistance of amplifier stage in killo ohms\n",
+ "Av=round((Ai*(Rl/Ri))*10**-3)# Voltage Gain\n",
+ "Ro=-(Rs+Hic)/Hfc # Output resistance in ohms\n",
+ "Ro = math.floor(Ro*10)/10\n",
+ "Zo= (Ro*Re)/(Ro+Re) # output resistance of amplifier stage in ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.1f\"%Ai)\n",
+ "print(\"Input resistance = %.f k-ohm\"%(Ri))\n",
+ "print(\"Voltage gain = %.f\"%Av)\n",
+ "print(\"input resistance of amplifier stage = %.1f k-ohm\"%Zi)\n",
+ "print(\"Output resistance = %.1f ohm\"%Ro)\n",
+ "print(\"output resistance of amplifier stage= %.1f ohm\"%Zo)\n",
+ "#Answer for Zo is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = 45.3\n",
+ "Input resistance = 228 k-ohm\n",
+ "Voltage gain = 1\n",
+ "input resistance of amplifier stage = 4.9 k-ohm\n",
+ "Output resistance = 58.8 ohm\n",
+ "output resistance of amplifier stage= 58.1 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 61
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.51, Page No. 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av,Z0\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1=20.0 # Resistance in killo ohms\n",
+ "R2=10.0 # Resistance in killo ohms\n",
+ "Rc=5.0 # collector resistance in killo ohms\n",
+ "R=10.0 # resistance in killo ohms\n",
+ "Rs=800.0 # Internal resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hie=1.5 # in killo ohms\n",
+ "Hre=5*10**-3\n",
+ "Hfe=50.0\n",
+ "Hoe=2*10**-6 # in micro ampere per volt\n",
+ "Ai= -Hfe # Current gain\n",
+ "Ri= Hie # Input resistance in ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Rl=(Rc*R)/(Rc+R) # Load resistance in killo ohms\n",
+ "Rl= math.floor(Rl*10)/10\n",
+ "Z1= (R1*R2)/(R1+R2)\n",
+ "Zi=(Ri*Z1)/(Ri+Z1) # input resistance of amplifier stage in killo ohms\n",
+ "Av= (Ai*(Rl/Ri))# Voltage Gain\n",
+ "Ro=(1/Hoe) # output resistane in killo ohms\n",
+ "Zo=(Ro*Rl)/(Ro+Rl) # output resistance of amplifier stage in ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.f\"%Ai)\n",
+ "print(\"input resistance of amplifier = %.2f k-ohm\"%Zi)\n",
+ "print(\"Voltage gain = %.f\"%Av)\n",
+ "print(\"output resistance of amplifier = %.1f ohm\"%Zo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = -50\n",
+ "input resistance of amplifier = 1.22 k-ohm\n",
+ "Voltage gain = -110\n",
+ "output resistance of amplifier = 3.3 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 78
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.52, Page No. 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=0.5 # Internal resistance in killo ohms\n",
+ "Rl=5000.0 # Load resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hie=1000.0 # in ohms\n",
+ "Hfe=50.0\n",
+ "Hoe=25*10**-6 # in ampere per volt\n",
+ "\n",
+ "#Calculations\n",
+ "Ai= (1+Hfe)/(1+Hoe*Rl)# Current gain\n",
+ "Ai = math.floor(Ai*100)/100\n",
+ "Ri= Hie+(Ai*Rl) # Input resistance in ohms\n",
+ "Ri = math.floor(Ri/100)*100\n",
+ "Av= (Ai*Rl)/Ri # Voltage Gain\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.2f\"%Ai)\n",
+ "print(\"Input resistance = %.1f k-ohm\"%(Ri/1000))\n",
+ "print(\"Voltage gain = %.4f\"%Av)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = 45.33\n",
+ "Input resistance = 227.6 k-ohm\n",
+ "Voltage gain = 0.9958\n"
+ ]
+ }
+ ],
+ "prompt_number": 97
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.53, Page No. 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Ai,Ri,Av\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=1.0 # Internal resistance in ohms\n",
+ "Rl=1600.0 # Load resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hie=1100.0 # in ohms\n",
+ "Hfe=2.5*10**-4\n",
+ "Hoe=25*10**-6 # in ampere per volt\n",
+ "\n",
+ "#Calcualtions\n",
+ "Ai= -Hfe/(1+Hoe*Rl) # Current gain\n",
+ "Ri= round(Hie+(Ai*Rl)) # Input resistance in ohms\n",
+ "Av= Ai*(Rl/Ri) # Voltage Gain\n",
+ "Av = math.ceil(Av*10**6)/100\n",
+ "Ai = math.ceil(Ai*10**5)/10\n",
+ "Pg=Ai*Av\n",
+ "\n",
+ "#Result\n",
+ "print(\"Current gain = %.1f * 10^-4\"%(Ai))\n",
+ "print(\"Input resistance = %.f k-ohm\"%Ri)\n",
+ "print(\"Voltage gain = %.2f * 10^-4\"%Av)\n",
+ "print(\"Power gain = %.2f *10^-8\"%(math.floor(Pg*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain = -2.4 * 10^-4\n",
+ "Input resistance = 1100 k-ohm\n",
+ "Voltage gain = -3.49 * 10^-4\n",
+ "Power gain = 8.37 *10^-8\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.54.a, Page No. 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Icq,Vcq\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vbe=0.0\n",
+ "Vcc=18.0 # collector voltage in volts\n",
+ "R1=510.0 # resistance in killo ohms\n",
+ "R2=510.0 # resistance in killo ohms\n",
+ "Rc=9.1 # clollector resistance in killo ohms\n",
+ "Re=7.5 # emitter resistance in killo ohms\n",
+ "Rs=1.0 # Internal resistance in ohms\n",
+ "Rl=1600.0 # Load resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hie=1100.0 # in ohms\n",
+ "Hfe=2.5*10**-4\n",
+ "Hoe=25*10**-6 # in ampere per volt\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Vb=Vcc * (R2/(R1+R2)) # vOLTAGE AT BASE\n",
+ "Ic= (Vb-Vbe)/Re # in milli amperes\n",
+ "Vce= Vcc-(Ic*(Rc+Re)) # Colector to emitter voltage in volts\n",
+ "Ai= -Hfe/(1+Hoe*Rl) # Current gain\n",
+ "Ri= round(Hie+(Ai*Rl)) # Input resistance in ohms\n",
+ "Av= Ai*(Rl/Ri) # Voltage Gain\n",
+ "\n",
+ "#Result\n",
+ "print(\"Colector to emitter voltage = %.1f V\"%Vce)\n",
+ "print(\"Collector current = %.1f mA\"%Ic) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Colector to emitter voltage = -1.9 V\n",
+ "Collector current = 1.2 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.54.b, Page No. 132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Av,Ri\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vbe=0.0\n",
+ "Vcc=18.0 # collector voltage in volts\n",
+ "R1=510.0 # resistance in killo ohms\n",
+ "R2=510.0 # resistance in killo ohms\n",
+ "Rc=9.1 # clollector resistance in killo ohms\n",
+ "Re=7.5 # emitter resistance in killo ohms\n",
+ "Rs=1.0 # Internal resistance in ohms\n",
+ "Rl=1600.0 # Load resistance in ohms\n",
+ "# H-paramters are\n",
+ "Hie=1.0 # in killo ohms\n",
+ "Hfe=50.0\n",
+ "Hoe=0.0 # in ampere per volt\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Vb=Vcc * (R2/(R1+R2)) # VOLTAGE AT BASE\n",
+ "Ic= (Vb-Vbe)/Re # in milli amperes\n",
+ "Vce= Vcc-(Ic*(Rc+Re)) # Colector to emitter voltage in volts\n",
+ "Ai=-Hfe # current gain\n",
+ "Ri=Hie # Input resistance in ohms\n",
+ "Z1= (R1*R2)/(R1+R2)\n",
+ "Zi=(Ri*Z1)/(Ri+Z1) # input resistance of amplifier stage in killo ohms\n",
+ "Av= Ai*(Rc/Ri) # Voltage Gain\n",
+ "\n",
+ "#Result\n",
+ "print(\"input resistance of amplifier stage = %.2f k-ohm\"%(math.floor(Zi*100)/100))\n",
+ "print(\"Voltage gain is %.f\"%Av)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "input resistance of amplifier stage = 0.99 k-ohm\n",
+ "Voltage gain is -455\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.55, Page No. 140"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resitive paramters\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ic= 5.0 # in milli amperes\n",
+ "Vt=26.0 # voltage \n",
+ "# H-paramters are\n",
+ "hie=1.0 # in killo ohms\n",
+ "hfe=100.0\n",
+ "hoe=4*10**-5 # in ampere per volt\n",
+ "hre=10**-4\n",
+ "\n",
+ "#Calculations\n",
+ "gm=math.floor(Ic*1000/Vt)/1000# transconductance\n",
+ "rbe= hfe/gm # in ohms\n",
+ "rbb=hie*10**3-rbe # in ohms\n",
+ "rbc=(rbe/(hre)*10**-6) # in mega ohms\n",
+ "gce1=hoe-(1+hfe)*(1/(rbc*10**6))\n",
+ "rce=(1/gce1)*10**-3 #in killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"transconductance = %.3f mho\"%gm)\n",
+ "print(\"Rbe = %.f ohm\"%rbe)\n",
+ "print(\"Rbb = %.f ohm\"%rbb)\n",
+ "print(\"Rbc = %.2f Mega ohm\"%rbc)\n",
+ "print(\"gce1= %.2f * 10^-5 mho\"%(gce1*10**5))\n",
+ "print(\"Rce = %.1f killo ohm\"%rce)\n",
+ "#Answer for Rbe is wrong in the book and hence for Rbb and Rbc"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "transconductance = 0.192 mho\n",
+ "Rbe = 521 ohm\n",
+ "Rbb = 479 ohm\n",
+ "Rbc = 5.21 Mega ohm\n",
+ "gce1= 2.06 * 10^-5 mho\n",
+ "Rce = 48.5 killo ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.56, Page No. 140"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# ressitive paramters\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ic= 1.0 # in milli amperes\n",
+ "Vt=26.0 # volatge \n",
+ "ft=80.0 # frequency in mega hertz\n",
+ "Cbc=12 # in pico farad\n",
+ "# H-paramters are\n",
+ "hie=6.0 # in killo ohms\n",
+ "hfe=224.0\n",
+ "\n",
+ "#Calculations\n",
+ "gm=Ic/Vt # transconductance\n",
+ "rbe= hfe/gm # in ohms\n",
+ "rbb=hie*10**3-rbe\n",
+ "Cbe= (((gm)/(2*math.pi*ft*10**6))-Cbc*10**-12)*10**12\n",
+ "\n",
+ "#Result\n",
+ "print(\"transconductance = %.2f m-mho\"%(gm*1000))\n",
+ "print(\"Rbe = %.3f k-ohm\"%(rbe/1000))\n",
+ "print(\"Rbb = %.f ohm\"%rbb)\n",
+ "print(\"Cbe = %.1f pF\"%Cbe)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "transconductance = 38.46 m-mho\n",
+ "Rbe = 5.824 k-ohm\n",
+ "Rbb = 176 ohm\n",
+ "Cbe = 64.5 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.57, Page No. 145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# alpha ,beta and cut off frequencies\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cbc=12.0 # in pico farad\n",
+ "# H-paramters are\n",
+ "hie=6.0 # in killo ohms\n",
+ "hfe=224.0\n",
+ "gm=38.0 # transconductance\n",
+ "rbe=5.9 # in killo ohms\n",
+ "rbb=100.0 # in ohms\n",
+ "Cbe= 63.0 # in pico farad\n",
+ "\n",
+ "#Calculations\n",
+ "falpha= ((hfe)/(2*math.pi*rbe*10**3*Cbe*10**-12))*10**-6\n",
+ "fbeta= ((1)/(2*math.pi*rbe*10**3*(Cbe+Cbc)*10**-12))*10**-6\n",
+ "ft= ((gm*10**-3/(2*math.pi*(Cbe+Cbc)*10**-12)))*10**-6\n",
+ "\n",
+ "#Result\n",
+ "print(\"F_alfa = %.1f MHz\"%falpha)\n",
+ "print(\"F_beta = %.3f MHz\"%(math.floor(fbeta*1000)/1000))\n",
+ "print(\"F_t = %.2f MHz\"%(math.floor(ft*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "F_alfa = 95.9 MHz\n",
+ "F_beta = 0.359 MHz\n",
+ "F_t = 80.63 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.58, Page No. 147"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# ressitive paramters\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ic= 2.6 # in milli amperes\n",
+ "Vt=26.0 # volatge \n",
+ "ft=500.0 # frequency in mega hertz\n",
+ "Cbc=3.0 # in pico farad\n",
+ "rbb=100.0 # in ohms\n",
+ "rbe=1.0 # IN KILLO OHMS\n",
+ "\n",
+ "#calculations\n",
+ "gm=Ic/Vt # transconductance\n",
+ "Beta= gm*rbe*10**3\n",
+ "Cbe= (((gm)/(2*math.pi*ft*10**6))-Cbc*10**-12)*10**12\n",
+ "\n",
+ "#Result\n",
+ "print(\"transconductance = %.1f mho\"%gm)\n",
+ "print(\"Cbe = %.2f pF\"%Cbe)\n",
+ "#Answer for Cbe is slightly different than book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "transconductance = 0.1 mho\n",
+ "Cbe = 28.83 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ " Example 2.59, Page No. 148"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# h-parameters and hybrid parameters\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "# H-paramters are\n",
+ "hie=1100.0 # in killo ohms\n",
+ "hre=2.5*10**-4\n",
+ "hfe=50.0\n",
+ "hoe=2.5*10**-5 # in ampere per volt\n",
+ "rbb=100.0\n",
+ "\n",
+ "#Calculations\n",
+ "hic=hie\n",
+ "hrc=1-hre\n",
+ "hfc=-(1+hfe)\n",
+ "hoc=hoe\n",
+ "hib=(hie/(1+hfe))\n",
+ "hrb= ((hie*hoe)/(1+hfe))-hre\n",
+ "hob=(hoe/(1+hfe))\n",
+ "rbe=(hie-rbb)*10**-3 # in killo ohms\n",
+ "rbc= ((hie-rbb)/hre)*10**-6\n",
+ "gm= ((hfe/(hie-rbb)))\n",
+ "x=hoe-((hfe*hre)/(hie-rbb))\n",
+ "rce=1/(1.25*10**-2)\n",
+ "\n",
+ "#Result\n",
+ "print(\"\\nH-parameters for common collector configuration are:\")\n",
+ "print(\"hic = %.f ohm\\nhrc = %.f\\nhfc = %.f\\nhoc = %.1f*10^-5 mho\"%(hie,hrc,hfc,hoc*10**5))\n",
+ "print(\"\\nH-parameters for common collector configuration are:\")\n",
+ "print(\"hib = %.2f ohm\\nhrb = %.1f*10^4\\nhob = %.1f*10^-6 mho\"%(hib,hrb*10**4,hob*10**6))\n",
+ "print(\"\\nhybrid pie paramtere are:\")\n",
+ "print(\"rbe(in killo ohms) = %.f\\nrbc(mega ohms)\\t = %.f\\ntransconductance(mho)= %.f\\nrce(in killo ohms) = %.f\"%(rbe,rbc,gm,rce))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "H-parameters for common collector configuration are:\n",
+ "hic = 1100 ohm\n",
+ "hrc = 1\n",
+ "hfc = -51\n",
+ "hoc = 2.5*10^-5 mho\n",
+ "\n",
+ "H-parameters for common collector configuration are:\n",
+ "hib = 21.57 ohm\n",
+ "hrb = 2.9*10^4\n",
+ "hob = 0.5*10^-6 mho\n",
+ "\n",
+ "hybrid pie paramtere are:\n",
+ "rbe(in killo ohms) = 1\n",
+ "rbc(mega ohms)\t = 4\n",
+ "transconductance(mho)= 0\n",
+ "rce(in killo ohms) = 80\n"
+ ]
+ }
+ ],
+ "prompt_number": 72
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.60, Page No. 149"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# hybrid parameters\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ic= 10.0 # in milli amperes\n",
+ "Vt=26.0 # volatge \n",
+ "ft=500.0 # frequency in mega hertz\n",
+ "Cbc=3.0 # in pico farad\n",
+ "gm=Ic/Vt # transconductance\n",
+ "# H-paramters are\n",
+ "hie=500.0 # in killo ohms\n",
+ "hfe=100.0\n",
+ "hre=0.1\n",
+ "hoe=4*10**-5 # in ampere per volt\n",
+ "\n",
+ "#Calculations\n",
+ "rbe=hfe/gm # in ohms\n",
+ "rbc= ((rbe)/hre)*10**-3\n",
+ "x=hoe-((hfe*10**-4)/(rbe))\n",
+ "rce=(1/(x*10**-2))*10**-5\n",
+ "Cbe=(((gm)/(2*math.pi*ft*10**6))*10**13-Cbc)\n",
+ "\n",
+ "#Result\n",
+ "print(\"transconductance = %.3f mho\"%gm)\n",
+ "print(\"(rbe) = %.f ohm\"%rbe)\n",
+ "print(\"(rbc) = %.1f Mega-ohm\"%rbc)\n",
+ "print(\"(rce) = %.f k-ohm\"%rce)\n",
+ "print(\"(Cbe) = %.f pF\"%Cbe)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "transconductance = 0.385 mho\n",
+ "(rbe) = 260 ohm\n",
+ "(rbc) = 2.6 Mega-ohm\n",
+ "(rce) = 650 k-ohm\n",
+ "(Cbe) = 1221 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 78
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.61, Page No. 149"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# hybrid parameters\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Ai=10.0 # current gain\n",
+ "Vce=10.0\n",
+ "Ic= 10.0 # in milli amperes\n",
+ "Vt=26.0 # volatge \n",
+ "f=10.0 # frequency in mega hertz\n",
+ "Cbc=3.0 # in pico farad\n",
+ "gm=Ic/Vt # transconductance\n",
+ "# H-paramters are\n",
+ "hie=500.0 # in ohms\n",
+ "hfe=100.0\n",
+ "\n",
+ "#Calculations\n",
+ "rbe= hfe/gm\n",
+ "rbb= hie-rbe\n",
+ "Ft= Ai*f\n",
+ "fb= Ft/hfe\n",
+ "Ce=((gm/(2*math.pi*Ft*10**6))-Cbc*10**-12)*10**12\n",
+ "\n",
+ "#Result\n",
+ "print(\"(gm) = %.1f mS\"%(gm*10**3))\n",
+ "print(\"(rbe) = %.f ohm\"%rbe)\n",
+ "print(\"(rbb) = %.f ohm\"%rbb)\n",
+ "print(\"(ft) = %.f MHz\"%Ft)\n",
+ "print(\"(fb) = %.f MHz\"%fb)\n",
+ "print(\"(Ce) = %.f p-F\"%Ce)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(gm) = 384.6 mS\n",
+ "(rbe) = 260 ohm\n",
+ "(rbb) = 240 ohm\n",
+ "(ft) = 100 MHz\n",
+ "(fb) = 1 MHz\n",
+ "(Ce) = 609 p-F\n"
+ ]
+ }
+ ],
+ "prompt_number": 81
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.62, Page No. 150"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# mid band voltage gain and cut off frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=1.0 \n",
+ "ft=500.0 # frequency in mega hertz\n",
+ "Cbc=5.0 # in pico farad\n",
+ "# H-paramters are\n",
+ "hie=500.0\n",
+ "hfe=100.0\n",
+ "rbe= 900.0\n",
+ "rbb= 100.0\n",
+ "Rl=500.0 # load resistance in ohms\n",
+ "\n",
+ "#Calculations\n",
+ "gm=hfe/rbe # in mho\n",
+ "Av=((-gm*Rl)) # voltage gain\n",
+ "Avs= ((Av*rbe)/(Rs*10**3+rbb+rbe))\n",
+ "fb= ft/hfe\n",
+ "\n",
+ "#Result\n",
+ "print(\"mid band voltage gain is %.f\"%Avs)\n",
+ "print(\"Fb = %.f MHz\"%fb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "mid band voltage gain is -25\n",
+ "Fb = 5 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 58
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.63, Page No. 150"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# mid band voltage gain and cut off frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=1.0\n",
+ "ft=500.0 # frequency in mega hertz\n",
+ "Cbc=5.0 # in pico farad\n",
+ "# H-paramters are\n",
+ "gm=100.0 # in mho\n",
+ "hfe=100.0\n",
+ "rbb= 100.0\n",
+ "Rl=500.0 # load resistance in ohms\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "rbe=hfe/(gm*10**-3)\n",
+ "Av=((-gm*10**-3*Rl))\n",
+ "Avs= ((Av*rbe)/(Rs*10**3+rbb+rbe))\n",
+ "fb= ft/hfe\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"mid band voltage gain is %.2f\"%Avs)\n",
+ "print(\"Fb = %.f MHz\"%fb)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "mid band voltage gain is -23.81\n",
+ "Fb = 5 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 83
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.64, Page No. 156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency and voltage drop\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "L=100.0 # in micro henry\n",
+ "C=253.3 # in micro farad\n",
+ "R=15.7 # in ohms\n",
+ "V=0.157\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "fr=((1/(2*math.pi*math.sqrt(L*10**-6*C*10**-12))))*10**-6 # resonant frequency in mega hertz\n",
+ "Ir=V/R\n",
+ "Vr=V\n",
+ "Vl=Ir*(2*math.pi*fr*10**6*L*10**-6)\n",
+ "Xc= (1/(2*math.pi*fr*10**6*C*10**-12))\n",
+ "Vc= Ir*Xc\n",
+ "Q=((2*math.pi*fr*10**6*L*10**-6)/R)\n",
+ "\n",
+ "#Result\n",
+ "print(\"resonant frequency = %.f MHz\"%fr)\n",
+ "print(\"Voltage drop across resitor = %.3f V\"%Vr)\n",
+ "print(\"Voltage drop across inductor = %.3f V\"%Vl)\n",
+ "print(\"Voltage drop across capacitor = %.3f V\"%Vc)\n",
+ "print(\"Quality factor of coil = %.f\"%Q)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resonant frequency = 1 MHz\n",
+ "Voltage drop across resitor = 0.157 V\n",
+ "Voltage drop across inductor = 6.283 V\n",
+ "Voltage drop across capacitor = 6.283 V\n",
+ "Quality factor of coil = 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 89
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.65, Page No. 160"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency ,impedence,Q-factor,Bnadwidth,line current and resonant frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "V=10.0\n",
+ "L=1.2 # in micro henry\n",
+ "C=200.0 # in micro farad\n",
+ "R=8.0 # in ohms\n",
+ "\n",
+ "#Calculations\n",
+ "fr=(1/(2*math.pi))*(math.sqrt((1/(L*10**-3*C*10**-12))-(R**2/(L*10**-3)**2))*10**-3) # resonant frequency in killo hertz\n",
+ "Zr=(L*10**-3)/(C*10**-9*R) # IN KILLO OHMS\n",
+ "Q=((2*math.pi*fr*10**6*L*10**-6)/R)\n",
+ "BW=fr/Q\n",
+ "Ir=(V/Zr)*10**3\n",
+ "fr1=((1/(2*math.pi*math.sqrt(L*10**-3*C*10**-12))))*10**-3 #resonant frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"resonant frequency = %.3f kHz\"%fr)\n",
+ "print(\"Impedence is %.f k-ohm\"%Zr)\n",
+ "print(\"bandwidth is %.2f kHz\"%BW)\n",
+ "print(\"line current is %.2f micro-A\"%Ir)\n",
+ "print(\"Quality factor of coil is %.1f\"%Q)\n",
+ "print(\"resonant frequency neglecting resistance = %.3f kHz\"%(math.floor(fr1*1000)/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resonant frequency = 324.872 kHz\n",
+ "Impedence is 750 k-ohm\n",
+ "bandwidth is 1.06 kHz\n",
+ "line current is 13.33 micro-A\n",
+ "Quality factor of coil is 306.2\n",
+ "resonant frequency neglecting resistance = 324.873 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 99
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.66, Page No. 161"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency ,impedence,Q-factor,Bnadwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "V=10.0\n",
+ "L=150.0 # in micro henry\n",
+ "C=100.0 # in micro farad\n",
+ "R=5 # in ohms\n",
+ "\n",
+ "#Calculations\n",
+ "fr=((1/(2*math.pi*math.sqrt(L*10**-6*C*10**-12))))*10**-3 # resonant frequency in killo hertz\n",
+ "Zr=(L*10**-3)/(C*10**-9*R) # IN KILLO OHMS\n",
+ "Q=((2*math.pi*fr*10**6*L*10**-6)/R)*10**-3\n",
+ "BW=(fr/Q)\n",
+ "\n",
+ "#Result\n",
+ "print(\"resonant frequency = %.1f kHz\"%fr)\n",
+ "print(\"Impedance is %.f k-ohm\"%(Zr*10**-3))\n",
+ "print(\"Quality factor of coil is %.f\"%Q)\n",
+ "print(\"bandwidth = %.1f kHz\"%BW)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resonant frequency = 1299.5 kHz\n",
+ "Impedance is 300 k-ohm\n",
+ "Quality factor of coil is 245\n",
+ "bandwidth = 5.3 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 104
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.67, Page No. 162"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Q FACTOR\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fr=1600.0 # resonant frequency in killo hertz\n",
+ "BW=10.0 # In kill hertz\n",
+ "\n",
+ "#Calculations\n",
+ "Qr=fr/BW\n",
+ "\n",
+ "#Result\n",
+ "print(\"value of quality factor is %.f\"%Qr)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of quality factor is 160\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.68, Page No. 163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Q FACTOR\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fr=2*10**6 # resonant frequency in hertz\n",
+ "BW=50*10**3 # hertz\n",
+ "\n",
+ "#Calcualtions\n",
+ "Qr=fr/BW\n",
+ "\n",
+ "#Result\n",
+ "print(\"value of quality factor is %.f\"%Qr)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of quality factor is 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.69, Page No. 163"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# parallel impedence\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fr=455.0*10**3 # resonant frequency in hertz\n",
+ "BW=10.0*10**3 # hertz\n",
+ "Xl=1255.0 # inductive reactance in ohm\n",
+ "\n",
+ "#Calculations\n",
+ "Qr=fr/BW\n",
+ "R=Xl/Qr\n",
+ "L=Xl/(2*math.pi*fr)\n",
+ "C=1/(2*math.pi*fr*Xl)\n",
+ "Zp=(L/(C*R))*10**-3\n",
+ "\n",
+ "#Result\n",
+ "print(\"value of quality factor is %.1f\"%Qr)\n",
+ "print(\"resisitance = %.1f ohm\"%R)\n",
+ "print(\"inductance = %.3f * 10^-3 H\"%(L*1000))\n",
+ "print(\"capacitor = %.1f * 10^-12 F\"%(C*10**12))\n",
+ "print(\"parallel impedence = %.f k-ohm\"%Zp)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of quality factor is 45.5\n",
+ "resisitance = 27.6 ohm\n",
+ "inductance = 0.439 * 10^-3 H\n",
+ "capacitor = 278.7 * 10^-12 F\n",
+ "parallel impedence = 57 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 115
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_3.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_3.ipynb
new file mode 100755
index 00000000..8b1b7b23
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_3.ipynb
@@ -0,0 +1,801 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3 : Transistor Amplifiers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1, Page No.187"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# calculate the input impedence, output impedence, voltage gain and current gain \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Hie=500.0 # the h-parameters of the transistor in ohm\n",
+ "Hfe=60.0 # the h-parameters of the transistor in ohm\n",
+ "Ic=3*10**-3 # collector current in ampere\n",
+ "Rb=220*10**3 # resistance in ohm\n",
+ "Rc=5.1*10**3 # resistance in ohm\n",
+ "Vcc=12.0 # voltage in volts\n",
+ "Vbe=0.6 # voltage in volts\n",
+ "Beta=60.0 # for transistor\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "zi=Hie\n",
+ "zo=Rc\n",
+ "Av=-Hfe*Rc/Hie\n",
+ "Ai=-Hfe\n",
+ "Ib=(Vcc-Vbe)/Rb\n",
+ "Ie=Beta*Ib\n",
+ "re=26*10**-3/Ie\n",
+ "Zin=Beta*math.ceil(re*100)/100\n",
+ "Zout=Rc\n",
+ "Av1=-Rc/re\n",
+ "Ai1=-Beta\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"part 1 - from h-parameter model:\")\n",
+ "print(\"input impedence (ohm) = %.f\"%zi)\n",
+ "print(\"ouput impedence (k-ohm) = %.1f \"%(zo/1000))\n",
+ "print(\"current gain (unitless) = %.f\"%Ai)\n",
+ "print(\"voltage gain (unitless) = %.f\"%Av)\n",
+ "print(\"\\npart 2 - from re model:\")\n",
+ "print(\"base curret (micro-A) = %.1f\"%(Ib*10**6))\n",
+ "print(\"emitter curret (mA) = %.3f\"%(Ie*1000))\n",
+ "print(\"resistance = %.2f\"%(math.ceil(re*100)/100))\n",
+ "print(\"input impedence (ohm) = %.1f\"%Zin)\n",
+ "print(\"ouput impedence (k-ohm) = %.1f\"%(Zout/1000))\n",
+ "print(\"current gain (unitless) = %.f\"%Ai1)\n",
+ "print(\"voltage gain (unitless) = %.f\"%(math.ceil(Av1)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part 1 - from h-parameter model:\n",
+ "input impedence (ohm) = 500\n",
+ "ouput impedence (k-ohm) = 5.1 \n",
+ "current gain (unitless) = -60\n",
+ "voltage gain (unitless) = -612\n",
+ "\n",
+ "part 2 - from re model:\n",
+ "base curret (micro-A) = 51.8\n",
+ "emitter curret (mA) = 3.109\n",
+ "resistance = 8.37\n",
+ "input impedence (ohm) = 502.2\n",
+ "ouput impedence (k-ohm) = 5.1\n",
+ "current gain (unitless) = -60\n",
+ "voltage gain (unitless) = -609\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.2, Page No. 192"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# calculate the input impedence, output impedence, voltage gain and current gain \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Hie=3.2 # the h-parameters of the transistor in kilo-ohm\n",
+ "Hfe=100.0 # the h-parameters of the transistor \n",
+ "R1=40.0 # resistance in kilo-ohm\n",
+ "R2=4.7 # resistance in kilo-ohm;\n",
+ "Rc=4.0 # resistance in kilo-ohm;\n",
+ "Re=1.2 # resistance in kilo-ohm;\n",
+ "Vcc=16.0 # voltage in volts\n",
+ "Vbe=0.6 # voltage in volts\n",
+ "Beta=100.0 # for transistor\n",
+ "\n",
+ "#Calcualtions\n",
+ "Rb=(R1*R2)/(R1+R2)\n",
+ "zi=(Rb*Hie)/(Rb+Hie)\n",
+ "zo=Rc\n",
+ "Av=-(Hfe*Rc)/Hie\n",
+ "Ai=-(Rb*Hfe)/(Rb+Hie)\n",
+ "Vb=(R2*Vcc)/(R1+R2)\n",
+ "Ib=(Vb-Vbe)/(Rb+(1+Beta)*Re)\n",
+ "Ic=math.floor(Beta*Ib*100)/100\n",
+ "Ie=Ic\n",
+ "re=26.0/Ie\n",
+ "Zin=(Rb*(Beta*re*10**-3))/(Rb+(Beta*re*10**-3))\n",
+ "Zout=Rc\n",
+ "Av1=-(Rc*10**3)/re\n",
+ "Ai1=-(Beta*(Rb*10**3))/((Rb*10**3)+(Beta*re))\n",
+ "\n",
+ "#Result\n",
+ "print(\"part 1 -from h-parameter model:\")\n",
+ "print(\"base resistance (kilo-ohm) = %.1f\"%Rb)\n",
+ "print(\"input impedence (kilo-ohm) = %.2f\"%zi)\n",
+ "print(\"ouput impedence (kilo-ohm) = %.f\"%zo)\n",
+ "print(\"current gain (unitless) = %.2f\"%Ai)\n",
+ "print(\"voltage gain (unitless) = %.f\"%Av)\n",
+ "print(\"\\npart 2 -from re model:\")\n",
+ "print(\"base voltage (V) = %.3f\"%Vb)\n",
+ "print(\"base curret (micro-A) = %.2f\"%(Ib*1000))\n",
+ "print(\"collector curret (mA) = %.2f\"%Ic)\n",
+ "print(\"emitter curret (mA) = %.2f\"%Ie)\n",
+ "print(\"resistance = %.2f\"%re)\n",
+ "print(\"input impedence (kilo-ohm) = %.2f\"%Zin)\n",
+ "print(\"ouput impedence (kilo-ohm) = %.f\"%Zout)\n",
+ "print(\"current gain (unitless) = %.2f\"%Ai1)\n",
+ "print(\"voltage gain (unitless) = %.1f\"%Av1)\n",
+ "\n",
+ "#Current gain values are slightly different"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part 1 -from h-parameter model:\n",
+ "base resistance (kilo-ohm) = 4.2\n",
+ "input impedence (kilo-ohm) = 1.82\n",
+ "ouput impedence (kilo-ohm) = 4\n",
+ "current gain (unitless) = -56.79\n",
+ "voltage gain (unitless) = -125\n",
+ "\n",
+ "part 2 -from re model:\n",
+ "base voltage (V) = 1.682\n",
+ "base curret (micro-A) = 8.63\n",
+ "collector curret (mA) = 0.86\n",
+ "emitter curret (mA) = 0.86\n",
+ "resistance = 30.23\n",
+ "input impedence (kilo-ohm) = 1.76\n",
+ "ouput impedence (kilo-ohm) = 4\n",
+ "current gain (unitless) = -58.18\n",
+ "voltage gain (unitless) = -132.3\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3, Page No. 194"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# calculate the input impedence, output impedence, voltage gain and current gain \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Re=4.0 # resistance in kilo-ohm\n",
+ "Rc=3.0 # resistance in kilo-ohm\n",
+ "Vcc=10.0 # collector voltage in volts\n",
+ "Vee=8.0 # emitter voltage in volts\n",
+ "Vbe=0.6 # base voltage in volts\n",
+ "\n",
+ "#Calculation\n",
+ "Ie=(Vee-Vbe)/(Re*10**3)\n",
+ "re=math.floor(26*10**-3*100/Ie)/100\n",
+ "zi=((Re*10**3)*re)/((Re*10**3)+re);\n",
+ "zo=Rc;\n",
+ "Av=Rc/(re*10**-3);\n",
+ "Ai=Ie/Ie\n",
+ "\n",
+ "#Result\n",
+ "print(\"emitter current (mA) = %.2f\"%(Ie*1000))\n",
+ "print(\"input impedence (ohm) = %.f\"%zi)\n",
+ "print(\"ouput impedence (kilo-ohm) = %.f\"%zo)\n",
+ "print(\"current gain (unitless) = %.f\"%Ai)\n",
+ "print(\"voltage gain (unitless) = %.2f\"%Av)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "emitter current (mA) = 1.85\n",
+ "input impedence (ohm) = 14\n",
+ "ouput impedence (kilo-ohm) = 3\n",
+ "current gain (unitless) = 1\n",
+ "voltage gain (unitless) = 213.52\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3, Page No. 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Collector efficiency\n",
+ "\n",
+ "import math\n",
+ "#Vaariable declaration\n",
+ "P = 8.0 # zero-signal power dissipation\n",
+ "Pac = 2 # AC power output\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "eff = (Pac/P)*100\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector Efficiency = %.f %%\"%eff)\n",
+ "#example 3.3 is twice in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector Efficiency = 25 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 52
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.4, Page No. 227"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# determine collector efficiency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vmax=25.0 # collector emitter voltag in volts\n",
+ "Vmin=2.5 # collector emitter voltag in volts\n",
+ "\n",
+ "#Calculations\n",
+ "eta= 50*((Vmax-Vmin)/(Vmax+Vmin))\n",
+ "\n",
+ "#Result\n",
+ "print(\"collector efficiency (%%) = %.1f\"%eta)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "collector efficiency (%) = 40.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 53
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.5, Page No. 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# determine maximum output power\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rl=80.0 # load resistance in ohm\n",
+ "alfa=5.0 # turn ratio\n",
+ "Ic=120.0 # collector current in milli-ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Rl1=alfa**2*Rl\n",
+ "Imax=2*Ic\n",
+ "Imin=0\n",
+ "Irms=(1/math.sqrt(2))*((Imax-Imin)/2.0)\n",
+ "Pout=((Ic*10**-3)**2*Rl1)/2;\n",
+ "\n",
+ "#Result\n",
+ "print(\"load as seen by transformer primary (ohm) = %.f\"%Rl1)\n",
+ "print(\"maximum current (mA) = %.f\"%Imax)\n",
+ "print(\"minimum current (mA) = %.f\"%Imin)\n",
+ "print(\"rms value of current (mA) = %.2f\"%Irms)\n",
+ "print(\"maximum power output (W) = %.1f\"%Pout) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "load as seen by transformer primary (ohm) = 2000\n",
+ "maximum current (mA) = 240\n",
+ "minimum current (mA) = 0\n",
+ "rms value of current (mA) = 84.85\n",
+ "maximum power output (W) = 14.4\n"
+ ]
+ }
+ ],
+ "prompt_number": 54
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.6, Page No. 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# (i) maximum output power (ii) maximum collector efficiency (iii) power rating of the transistor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # collector supply voltage in volts\n",
+ "Icq=200.0 # zero-signal collector current in milli-ampere\n",
+ "Rl=2.0 # load resistance in ohm\n",
+ "alfa=5.0 # turn ratio\n",
+ "\n",
+ "#Calculations\n",
+ "Pout=(Vcc*(Icq*10**-3))/2\n",
+ "Pin=(Vcc*(Icq*10**-3))\n",
+ "eta=(Pout/Pin)*100\n",
+ "P=(Vcc*(Icq*10**-3)) \n",
+ "Rl1=(alfa**2)*Rl\n",
+ "\n",
+ "#REsult\n",
+ "print(\"output power for dc (w) = %.f\"%Pout)\n",
+ "print(\"input power for ac (w) = %.f\"%Pin)\n",
+ "print(\"collector efficiency (%%) = %.f\"%eta)\n",
+ "print(\"power rating of the transistor (w) = %.f\"%P)\n",
+ "print(\"load by the tranformer primary (ohm) = %.f\"%Rl1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "output power for dc (w) = 1\n",
+ "input power for ac (w) = 2\n",
+ "collector efficiency (%) = 50\n",
+ "power rating of the transistor (w) = 2\n",
+ "load by the tranformer primary (ohm) = 50\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.7, Page No. 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Various parameter calculations\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "alpha=3.0\n",
+ "Podc=0.434 # output ac power in watts\n",
+ "Icq=140.0 # current in milli ampere\n",
+ "Rl=8.0 # load resistance in killo ohms\n",
+ "Vcq=10.0 \n",
+ "Vcemax=18.3 # maximum collector to emitter voltage in volts\n",
+ "Vcemin=2.5 # minimum collector to emitter voltage in volta\n",
+ "Icmax=245.0 # maximum collector current in mili ampere\n",
+ "Icmin=25.0 # minimum collector current in mili ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Vcc=Vcq\n",
+ "Vlrms=(Vcemax-Vcemin)/(2*math.sqrt(2))\n",
+ "VLrms=(1/alpha)*Vlrms #rms value of load voltage\n",
+ "ILrms=(VLrms/Rl)*10**3 #rms value of load current\n",
+ "Pindc=Vcc*Icq*10**-3 #ac power developed across the load in watts\n",
+ "Pd=Pindc-Podc #power dissipated in watts\n",
+ "n=(Podc/Pindc)*100 #efficieny\n",
+ "\n",
+ "#Result\n",
+ "print(\"maximum collector to emitter voltage in volts = %.1f\"%Vcemax)\n",
+ "print(\"minimum collector to emitter voltage in volts = %.1f\"%Vcemin)\n",
+ "print(\"maximum collector current in mA = %.f\"%Icmax)\n",
+ "print(\"minimum collector current in mA = %.f\"%Icmin)\n",
+ "print(\"rms value of load voltage = %.2f\"%VLrms)\n",
+ "print(\"rms value of load current in mA = %.1f\"%ILrms)\n",
+ "print(\"ac power developed across the load in watts = %.1f\"%Pindc)\n",
+ "print(\"power dissipated in watts = %.3f\"%Pd)\n",
+ "print(\"efficiency = %.f%%\"%n)\n",
+ "#Value for rms voltage and current is slightly different than book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum collector to emitter voltage in volts = 18.3\n",
+ "minimum collector to emitter voltage in volts = 2.5\n",
+ "maximum collector current in mA = 245\n",
+ "minimum collector current in mA = 25\n",
+ "rms value of load voltage = 1.86\n",
+ "rms value of load current in mA = 232.8\n",
+ "ac power developed across the load in watts = 1.4\n",
+ "power dissipated in watts = 0.966\n",
+ "efficiency = 31%\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.8, Page No. 232"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# overall efficiency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=20.0 # in volts\n",
+ "Vce=2.5 # in volts\n",
+ "\n",
+ "#Calculatins\n",
+ "eta=78.5*(1-(Vce/Vcc))\n",
+ "print(\" overall efficiency = %.2f %%\"%eta)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " overall efficiency = 68.69 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.9.a, Page No. 234"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# the percent second harmonic distortion\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "V1ce=22.0 # maximum voltage in volts\n",
+ "V2ce=1.2 # minimum voltage in volts\n",
+ "Vceq=10.0 # in volts\n",
+ "\n",
+ "#Calculations\n",
+ "D2=(((1.0/2)*(V1ce+V2ce)-Vceq)/(V1ce-V2ce))*100;\n",
+ "\n",
+ "#Result\n",
+ "print(\"the percent harmonic distortion = %.1f %%\"%D2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the percent harmonic distortion (%) = 7.7\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.9.b, Page No.234"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# the percent second harmonic distortion\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "V1ce=18.0 # maximum voltage in volts\n",
+ "V2ce=2.0 # minimum voltage in volts\n",
+ "Vceq=10.0 # in volts\n",
+ "\n",
+ "#Calculations\n",
+ "D2=(((1.0/2)*(V1ce+V2ce)-Vceq)/(V1ce-V2ce))*100\n",
+ "\n",
+ "#Result\n",
+ "print(\"the percent harmonic distortion = %.f %% i.e. no distortion\"%D2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the percent harmonic distortion = 0 % i.e. no distortion\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.10, Page No. 235"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Percentage Increase in powe\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "#Vs=1.95*sin(400*t);in volt\n",
+ "#io=12*sin400*t+1.2*sin800*t+0.9*sin*1200*t+0.4*sin1600*t\n",
+ "#from current we have\n",
+ "V1=12.0 #in volt\n",
+ "V2=1.2 #in volt\n",
+ "V3=0.9 #in volt\n",
+ "V4=0.4 #in volt\n",
+ "#Harmonic distortion of each component is expressed as :\n",
+ "D2=V2/V1 #unitless\n",
+ "D3=V3/V1 #unitless\n",
+ "D4=V4/V1 #unitless\n",
+ "#Total distortion \n",
+ "D=math.sqrt(D2**2+D3**2+D4**2)\n",
+ "PowerIncrease=D**2*100\n",
+ "\n",
+ "print(\"Total disortion = %.4f or %.2f%%\"%(D,D*100))\n",
+ "print(\"\\nTotal Power, P=(1+D2^2)*P1\")\n",
+ "print(\"\\nPercentage Increase in power because of distortion=(P-P1)*100/P1\")\n",
+ "print(\"\\nPercentage Increase in power = %.3f\"%PowerIncrease)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total disortion = 0.1294 or 12.94%\n",
+ "\n",
+ "Total Power, P=(1+D2^2)*P1\n",
+ "\n",
+ "Percentage Increase in power because of distortion=(P-P1)*100/P1\n",
+ "\n",
+ "Percentage Increase in power = 1.674\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.11.i, Page No. 242"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# minimum power drain on the power supply \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Pl=10.0 # power delivered to load in watt\n",
+ "eta1=80.0/100 # output transformer efficiency\n",
+ "eta=78.5/100 # efficiency of a class B push pull amplfier under optimum condition\n",
+ "Pout=Pl/eta1\n",
+ "Pin=Pout/eta\n",
+ "print(\"ac power output of amplifier (W) = %.1f\"%Pout)\n",
+ "print(\"minimum power drain on the power supply (W) = %.1f\"%Pin)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ac power output of amplifier (W) = 12.5\n",
+ "minimum power drain on the power supply (W) = 15.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.11.ii, Page No.242"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# minimum average power dissipation\n",
+ " \n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Pl=10 # power delivered to load in watt\n",
+ "eta1=80.0/100 # output transformer efficiency\n",
+ "eta=78.5/100 # efficiency of a class B push pull amplfier under optimum condition\n",
+ "\n",
+ "#Calcualtions\n",
+ "Pout=Pl/eta1\n",
+ "Pin=Pout/eta\n",
+ "Pd=Pin-Pout\n",
+ "Pd1=Pd/2.0\n",
+ "\n",
+ "#Calculations\n",
+ "print(\"ac power output of amplifier (W) = %.1f\"%Pout)\n",
+ "print(\"minimum power drain on the power supply for dc (W) = %.1f\"%Pin)\n",
+ "print(\"minimum average power dissipation (W) = %.1f\"%Pd)\n",
+ "print(\"minimum average power dissipation rating required for each transistor (W) = %.1f\"%Pd1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ac power output of amplifier (W) = 12.5\n",
+ "minimum power drain on the power supply for dc (W) = 15.9\n",
+ "minimum average power dissipation (W) = 3.4\n",
+ "minimum average power dissipation rating required for each transistor (W) = 1.7\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.12, Page No.243"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# the percent second harmonic distortion\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=50.0 # voltage in volts\n",
+ "Vmin=5.0 # minimum voltage in volts\n",
+ "Pd=40.0 # total power dissipation in watt\n",
+ "\n",
+ "#Calculations\n",
+ "Icmax=Pd/(((2*Vcc)/math.pi)-((Vcc-Vmin)/2));\n",
+ "Pin=(2/math.pi)*(Vcc*Icmax);\n",
+ "Pout=((Icmax/2)*(Vcc-Vmin));\n",
+ "eta=(Pout/Pin)*100;\n",
+ "\n",
+ "#Result\n",
+ "print(\"maximum collector current (A) = %.3f\"%Icmax)\n",
+ "print(\"total power input (W) = %.2f\"%Pin)\n",
+ "print(\"ac power output (W) = %.2f\"%Pout)\n",
+ "print(\"conversion efficiency (%%) = %.2f\"%eta)\n",
+ "#Answer for AC power output and efficiency is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum collector current (A) = 4.287\n",
+ "total power input (W) = 136.45\n",
+ "ac power output (W) = 96.45\n",
+ "conversion efficiency (%) = 70.69\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_3_1.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_3_1.ipynb
new file mode 100755
index 00000000..8b1b7b23
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_3_1.ipynb
@@ -0,0 +1,801 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3 : Transistor Amplifiers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1, Page No.187"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# calculate the input impedence, output impedence, voltage gain and current gain \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Hie=500.0 # the h-parameters of the transistor in ohm\n",
+ "Hfe=60.0 # the h-parameters of the transistor in ohm\n",
+ "Ic=3*10**-3 # collector current in ampere\n",
+ "Rb=220*10**3 # resistance in ohm\n",
+ "Rc=5.1*10**3 # resistance in ohm\n",
+ "Vcc=12.0 # voltage in volts\n",
+ "Vbe=0.6 # voltage in volts\n",
+ "Beta=60.0 # for transistor\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "zi=Hie\n",
+ "zo=Rc\n",
+ "Av=-Hfe*Rc/Hie\n",
+ "Ai=-Hfe\n",
+ "Ib=(Vcc-Vbe)/Rb\n",
+ "Ie=Beta*Ib\n",
+ "re=26*10**-3/Ie\n",
+ "Zin=Beta*math.ceil(re*100)/100\n",
+ "Zout=Rc\n",
+ "Av1=-Rc/re\n",
+ "Ai1=-Beta\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"part 1 - from h-parameter model:\")\n",
+ "print(\"input impedence (ohm) = %.f\"%zi)\n",
+ "print(\"ouput impedence (k-ohm) = %.1f \"%(zo/1000))\n",
+ "print(\"current gain (unitless) = %.f\"%Ai)\n",
+ "print(\"voltage gain (unitless) = %.f\"%Av)\n",
+ "print(\"\\npart 2 - from re model:\")\n",
+ "print(\"base curret (micro-A) = %.1f\"%(Ib*10**6))\n",
+ "print(\"emitter curret (mA) = %.3f\"%(Ie*1000))\n",
+ "print(\"resistance = %.2f\"%(math.ceil(re*100)/100))\n",
+ "print(\"input impedence (ohm) = %.1f\"%Zin)\n",
+ "print(\"ouput impedence (k-ohm) = %.1f\"%(Zout/1000))\n",
+ "print(\"current gain (unitless) = %.f\"%Ai1)\n",
+ "print(\"voltage gain (unitless) = %.f\"%(math.ceil(Av1)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part 1 - from h-parameter model:\n",
+ "input impedence (ohm) = 500\n",
+ "ouput impedence (k-ohm) = 5.1 \n",
+ "current gain (unitless) = -60\n",
+ "voltage gain (unitless) = -612\n",
+ "\n",
+ "part 2 - from re model:\n",
+ "base curret (micro-A) = 51.8\n",
+ "emitter curret (mA) = 3.109\n",
+ "resistance = 8.37\n",
+ "input impedence (ohm) = 502.2\n",
+ "ouput impedence (k-ohm) = 5.1\n",
+ "current gain (unitless) = -60\n",
+ "voltage gain (unitless) = -609\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.2, Page No. 192"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# calculate the input impedence, output impedence, voltage gain and current gain \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Hie=3.2 # the h-parameters of the transistor in kilo-ohm\n",
+ "Hfe=100.0 # the h-parameters of the transistor \n",
+ "R1=40.0 # resistance in kilo-ohm\n",
+ "R2=4.7 # resistance in kilo-ohm;\n",
+ "Rc=4.0 # resistance in kilo-ohm;\n",
+ "Re=1.2 # resistance in kilo-ohm;\n",
+ "Vcc=16.0 # voltage in volts\n",
+ "Vbe=0.6 # voltage in volts\n",
+ "Beta=100.0 # for transistor\n",
+ "\n",
+ "#Calcualtions\n",
+ "Rb=(R1*R2)/(R1+R2)\n",
+ "zi=(Rb*Hie)/(Rb+Hie)\n",
+ "zo=Rc\n",
+ "Av=-(Hfe*Rc)/Hie\n",
+ "Ai=-(Rb*Hfe)/(Rb+Hie)\n",
+ "Vb=(R2*Vcc)/(R1+R2)\n",
+ "Ib=(Vb-Vbe)/(Rb+(1+Beta)*Re)\n",
+ "Ic=math.floor(Beta*Ib*100)/100\n",
+ "Ie=Ic\n",
+ "re=26.0/Ie\n",
+ "Zin=(Rb*(Beta*re*10**-3))/(Rb+(Beta*re*10**-3))\n",
+ "Zout=Rc\n",
+ "Av1=-(Rc*10**3)/re\n",
+ "Ai1=-(Beta*(Rb*10**3))/((Rb*10**3)+(Beta*re))\n",
+ "\n",
+ "#Result\n",
+ "print(\"part 1 -from h-parameter model:\")\n",
+ "print(\"base resistance (kilo-ohm) = %.1f\"%Rb)\n",
+ "print(\"input impedence (kilo-ohm) = %.2f\"%zi)\n",
+ "print(\"ouput impedence (kilo-ohm) = %.f\"%zo)\n",
+ "print(\"current gain (unitless) = %.2f\"%Ai)\n",
+ "print(\"voltage gain (unitless) = %.f\"%Av)\n",
+ "print(\"\\npart 2 -from re model:\")\n",
+ "print(\"base voltage (V) = %.3f\"%Vb)\n",
+ "print(\"base curret (micro-A) = %.2f\"%(Ib*1000))\n",
+ "print(\"collector curret (mA) = %.2f\"%Ic)\n",
+ "print(\"emitter curret (mA) = %.2f\"%Ie)\n",
+ "print(\"resistance = %.2f\"%re)\n",
+ "print(\"input impedence (kilo-ohm) = %.2f\"%Zin)\n",
+ "print(\"ouput impedence (kilo-ohm) = %.f\"%Zout)\n",
+ "print(\"current gain (unitless) = %.2f\"%Ai1)\n",
+ "print(\"voltage gain (unitless) = %.1f\"%Av1)\n",
+ "\n",
+ "#Current gain values are slightly different"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part 1 -from h-parameter model:\n",
+ "base resistance (kilo-ohm) = 4.2\n",
+ "input impedence (kilo-ohm) = 1.82\n",
+ "ouput impedence (kilo-ohm) = 4\n",
+ "current gain (unitless) = -56.79\n",
+ "voltage gain (unitless) = -125\n",
+ "\n",
+ "part 2 -from re model:\n",
+ "base voltage (V) = 1.682\n",
+ "base curret (micro-A) = 8.63\n",
+ "collector curret (mA) = 0.86\n",
+ "emitter curret (mA) = 0.86\n",
+ "resistance = 30.23\n",
+ "input impedence (kilo-ohm) = 1.76\n",
+ "ouput impedence (kilo-ohm) = 4\n",
+ "current gain (unitless) = -58.18\n",
+ "voltage gain (unitless) = -132.3\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3, Page No. 194"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# calculate the input impedence, output impedence, voltage gain and current gain \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Re=4.0 # resistance in kilo-ohm\n",
+ "Rc=3.0 # resistance in kilo-ohm\n",
+ "Vcc=10.0 # collector voltage in volts\n",
+ "Vee=8.0 # emitter voltage in volts\n",
+ "Vbe=0.6 # base voltage in volts\n",
+ "\n",
+ "#Calculation\n",
+ "Ie=(Vee-Vbe)/(Re*10**3)\n",
+ "re=math.floor(26*10**-3*100/Ie)/100\n",
+ "zi=((Re*10**3)*re)/((Re*10**3)+re);\n",
+ "zo=Rc;\n",
+ "Av=Rc/(re*10**-3);\n",
+ "Ai=Ie/Ie\n",
+ "\n",
+ "#Result\n",
+ "print(\"emitter current (mA) = %.2f\"%(Ie*1000))\n",
+ "print(\"input impedence (ohm) = %.f\"%zi)\n",
+ "print(\"ouput impedence (kilo-ohm) = %.f\"%zo)\n",
+ "print(\"current gain (unitless) = %.f\"%Ai)\n",
+ "print(\"voltage gain (unitless) = %.2f\"%Av)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "emitter current (mA) = 1.85\n",
+ "input impedence (ohm) = 14\n",
+ "ouput impedence (kilo-ohm) = 3\n",
+ "current gain (unitless) = 1\n",
+ "voltage gain (unitless) = 213.52\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3, Page No. 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Collector efficiency\n",
+ "\n",
+ "import math\n",
+ "#Vaariable declaration\n",
+ "P = 8.0 # zero-signal power dissipation\n",
+ "Pac = 2 # AC power output\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "eff = (Pac/P)*100\n",
+ "\n",
+ "#Result\n",
+ "print(\"Collector Efficiency = %.f %%\"%eff)\n",
+ "#example 3.3 is twice in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector Efficiency = 25 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 52
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.4, Page No. 227"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# determine collector efficiency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vmax=25.0 # collector emitter voltag in volts\n",
+ "Vmin=2.5 # collector emitter voltag in volts\n",
+ "\n",
+ "#Calculations\n",
+ "eta= 50*((Vmax-Vmin)/(Vmax+Vmin))\n",
+ "\n",
+ "#Result\n",
+ "print(\"collector efficiency (%%) = %.1f\"%eta)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "collector efficiency (%) = 40.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 53
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.5, Page No. 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# determine maximum output power\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rl=80.0 # load resistance in ohm\n",
+ "alfa=5.0 # turn ratio\n",
+ "Ic=120.0 # collector current in milli-ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Rl1=alfa**2*Rl\n",
+ "Imax=2*Ic\n",
+ "Imin=0\n",
+ "Irms=(1/math.sqrt(2))*((Imax-Imin)/2.0)\n",
+ "Pout=((Ic*10**-3)**2*Rl1)/2;\n",
+ "\n",
+ "#Result\n",
+ "print(\"load as seen by transformer primary (ohm) = %.f\"%Rl1)\n",
+ "print(\"maximum current (mA) = %.f\"%Imax)\n",
+ "print(\"minimum current (mA) = %.f\"%Imin)\n",
+ "print(\"rms value of current (mA) = %.2f\"%Irms)\n",
+ "print(\"maximum power output (W) = %.1f\"%Pout) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "load as seen by transformer primary (ohm) = 2000\n",
+ "maximum current (mA) = 240\n",
+ "minimum current (mA) = 0\n",
+ "rms value of current (mA) = 84.85\n",
+ "maximum power output (W) = 14.4\n"
+ ]
+ }
+ ],
+ "prompt_number": 54
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.6, Page No. 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# (i) maximum output power (ii) maximum collector efficiency (iii) power rating of the transistor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # collector supply voltage in volts\n",
+ "Icq=200.0 # zero-signal collector current in milli-ampere\n",
+ "Rl=2.0 # load resistance in ohm\n",
+ "alfa=5.0 # turn ratio\n",
+ "\n",
+ "#Calculations\n",
+ "Pout=(Vcc*(Icq*10**-3))/2\n",
+ "Pin=(Vcc*(Icq*10**-3))\n",
+ "eta=(Pout/Pin)*100\n",
+ "P=(Vcc*(Icq*10**-3)) \n",
+ "Rl1=(alfa**2)*Rl\n",
+ "\n",
+ "#REsult\n",
+ "print(\"output power for dc (w) = %.f\"%Pout)\n",
+ "print(\"input power for ac (w) = %.f\"%Pin)\n",
+ "print(\"collector efficiency (%%) = %.f\"%eta)\n",
+ "print(\"power rating of the transistor (w) = %.f\"%P)\n",
+ "print(\"load by the tranformer primary (ohm) = %.f\"%Rl1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "output power for dc (w) = 1\n",
+ "input power for ac (w) = 2\n",
+ "collector efficiency (%) = 50\n",
+ "power rating of the transistor (w) = 2\n",
+ "load by the tranformer primary (ohm) = 50\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.7, Page No. 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Various parameter calculations\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "alpha=3.0\n",
+ "Podc=0.434 # output ac power in watts\n",
+ "Icq=140.0 # current in milli ampere\n",
+ "Rl=8.0 # load resistance in killo ohms\n",
+ "Vcq=10.0 \n",
+ "Vcemax=18.3 # maximum collector to emitter voltage in volts\n",
+ "Vcemin=2.5 # minimum collector to emitter voltage in volta\n",
+ "Icmax=245.0 # maximum collector current in mili ampere\n",
+ "Icmin=25.0 # minimum collector current in mili ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Vcc=Vcq\n",
+ "Vlrms=(Vcemax-Vcemin)/(2*math.sqrt(2))\n",
+ "VLrms=(1/alpha)*Vlrms #rms value of load voltage\n",
+ "ILrms=(VLrms/Rl)*10**3 #rms value of load current\n",
+ "Pindc=Vcc*Icq*10**-3 #ac power developed across the load in watts\n",
+ "Pd=Pindc-Podc #power dissipated in watts\n",
+ "n=(Podc/Pindc)*100 #efficieny\n",
+ "\n",
+ "#Result\n",
+ "print(\"maximum collector to emitter voltage in volts = %.1f\"%Vcemax)\n",
+ "print(\"minimum collector to emitter voltage in volts = %.1f\"%Vcemin)\n",
+ "print(\"maximum collector current in mA = %.f\"%Icmax)\n",
+ "print(\"minimum collector current in mA = %.f\"%Icmin)\n",
+ "print(\"rms value of load voltage = %.2f\"%VLrms)\n",
+ "print(\"rms value of load current in mA = %.1f\"%ILrms)\n",
+ "print(\"ac power developed across the load in watts = %.1f\"%Pindc)\n",
+ "print(\"power dissipated in watts = %.3f\"%Pd)\n",
+ "print(\"efficiency = %.f%%\"%n)\n",
+ "#Value for rms voltage and current is slightly different than book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum collector to emitter voltage in volts = 18.3\n",
+ "minimum collector to emitter voltage in volts = 2.5\n",
+ "maximum collector current in mA = 245\n",
+ "minimum collector current in mA = 25\n",
+ "rms value of load voltage = 1.86\n",
+ "rms value of load current in mA = 232.8\n",
+ "ac power developed across the load in watts = 1.4\n",
+ "power dissipated in watts = 0.966\n",
+ "efficiency = 31%\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.8, Page No. 232"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# overall efficiency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=20.0 # in volts\n",
+ "Vce=2.5 # in volts\n",
+ "\n",
+ "#Calculatins\n",
+ "eta=78.5*(1-(Vce/Vcc))\n",
+ "print(\" overall efficiency = %.2f %%\"%eta)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " overall efficiency = 68.69 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.9.a, Page No. 234"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# the percent second harmonic distortion\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "V1ce=22.0 # maximum voltage in volts\n",
+ "V2ce=1.2 # minimum voltage in volts\n",
+ "Vceq=10.0 # in volts\n",
+ "\n",
+ "#Calculations\n",
+ "D2=(((1.0/2)*(V1ce+V2ce)-Vceq)/(V1ce-V2ce))*100;\n",
+ "\n",
+ "#Result\n",
+ "print(\"the percent harmonic distortion = %.1f %%\"%D2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the percent harmonic distortion (%) = 7.7\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.9.b, Page No.234"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# the percent second harmonic distortion\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "V1ce=18.0 # maximum voltage in volts\n",
+ "V2ce=2.0 # minimum voltage in volts\n",
+ "Vceq=10.0 # in volts\n",
+ "\n",
+ "#Calculations\n",
+ "D2=(((1.0/2)*(V1ce+V2ce)-Vceq)/(V1ce-V2ce))*100\n",
+ "\n",
+ "#Result\n",
+ "print(\"the percent harmonic distortion = %.f %% i.e. no distortion\"%D2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the percent harmonic distortion = 0 % i.e. no distortion\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.10, Page No. 235"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Percentage Increase in powe\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "#Vs=1.95*sin(400*t);in volt\n",
+ "#io=12*sin400*t+1.2*sin800*t+0.9*sin*1200*t+0.4*sin1600*t\n",
+ "#from current we have\n",
+ "V1=12.0 #in volt\n",
+ "V2=1.2 #in volt\n",
+ "V3=0.9 #in volt\n",
+ "V4=0.4 #in volt\n",
+ "#Harmonic distortion of each component is expressed as :\n",
+ "D2=V2/V1 #unitless\n",
+ "D3=V3/V1 #unitless\n",
+ "D4=V4/V1 #unitless\n",
+ "#Total distortion \n",
+ "D=math.sqrt(D2**2+D3**2+D4**2)\n",
+ "PowerIncrease=D**2*100\n",
+ "\n",
+ "print(\"Total disortion = %.4f or %.2f%%\"%(D,D*100))\n",
+ "print(\"\\nTotal Power, P=(1+D2^2)*P1\")\n",
+ "print(\"\\nPercentage Increase in power because of distortion=(P-P1)*100/P1\")\n",
+ "print(\"\\nPercentage Increase in power = %.3f\"%PowerIncrease)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total disortion = 0.1294 or 12.94%\n",
+ "\n",
+ "Total Power, P=(1+D2^2)*P1\n",
+ "\n",
+ "Percentage Increase in power because of distortion=(P-P1)*100/P1\n",
+ "\n",
+ "Percentage Increase in power = 1.674\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.11.i, Page No. 242"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# minimum power drain on the power supply \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Pl=10.0 # power delivered to load in watt\n",
+ "eta1=80.0/100 # output transformer efficiency\n",
+ "eta=78.5/100 # efficiency of a class B push pull amplfier under optimum condition\n",
+ "Pout=Pl/eta1\n",
+ "Pin=Pout/eta\n",
+ "print(\"ac power output of amplifier (W) = %.1f\"%Pout)\n",
+ "print(\"minimum power drain on the power supply (W) = %.1f\"%Pin)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ac power output of amplifier (W) = 12.5\n",
+ "minimum power drain on the power supply (W) = 15.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.11.ii, Page No.242"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# minimum average power dissipation\n",
+ " \n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Pl=10 # power delivered to load in watt\n",
+ "eta1=80.0/100 # output transformer efficiency\n",
+ "eta=78.5/100 # efficiency of a class B push pull amplfier under optimum condition\n",
+ "\n",
+ "#Calcualtions\n",
+ "Pout=Pl/eta1\n",
+ "Pin=Pout/eta\n",
+ "Pd=Pin-Pout\n",
+ "Pd1=Pd/2.0\n",
+ "\n",
+ "#Calculations\n",
+ "print(\"ac power output of amplifier (W) = %.1f\"%Pout)\n",
+ "print(\"minimum power drain on the power supply for dc (W) = %.1f\"%Pin)\n",
+ "print(\"minimum average power dissipation (W) = %.1f\"%Pd)\n",
+ "print(\"minimum average power dissipation rating required for each transistor (W) = %.1f\"%Pd1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ac power output of amplifier (W) = 12.5\n",
+ "minimum power drain on the power supply for dc (W) = 15.9\n",
+ "minimum average power dissipation (W) = 3.4\n",
+ "minimum average power dissipation rating required for each transistor (W) = 1.7\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.12, Page No.243"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# the percent second harmonic distortion\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=50.0 # voltage in volts\n",
+ "Vmin=5.0 # minimum voltage in volts\n",
+ "Pd=40.0 # total power dissipation in watt\n",
+ "\n",
+ "#Calculations\n",
+ "Icmax=Pd/(((2*Vcc)/math.pi)-((Vcc-Vmin)/2));\n",
+ "Pin=(2/math.pi)*(Vcc*Icmax);\n",
+ "Pout=((Icmax/2)*(Vcc-Vmin));\n",
+ "eta=(Pout/Pin)*100;\n",
+ "\n",
+ "#Result\n",
+ "print(\"maximum collector current (A) = %.3f\"%Icmax)\n",
+ "print(\"total power input (W) = %.2f\"%Pin)\n",
+ "print(\"ac power output (W) = %.2f\"%Pout)\n",
+ "print(\"conversion efficiency (%%) = %.2f\"%eta)\n",
+ "#Answer for AC power output and efficiency is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum collector current (A) = 4.287\n",
+ "total power input (W) = 136.45\n",
+ "ac power output (W) = 96.45\n",
+ "conversion efficiency (%) = 70.69\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_4.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_4.ipynb
new file mode 100755
index 00000000..5d2c1109
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_4.ipynb
@@ -0,0 +1,675 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4 : Field Effect Transistors and MOSFETs"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1, Page No. 257"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# find the drain current\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Idss=15.0 # maximum drain current in mili-ampere\n",
+ "VgsOFF=-5.0 # pinch off voltage in volts\n",
+ "Vgs1=0.0 # gate source voltage in volts\n",
+ "Vgs2=-1.0 # gate source voltage in volts\n",
+ "Vgs3=-4.0 # gate source voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Id1=Idss*(1-(Vgs1/VgsOFF))**2\n",
+ "Id2=Idss*(1-(Vgs2/VgsOFF))**2\n",
+ "Id3=Idss*(1-(Vgs3/VgsOFF))**2\n",
+ "\n",
+ "#Result\n",
+ "print(\"drain current (mA) = %.f\"%Id1)\n",
+ "print(\"drain current (mA) = %.1f\"%Id2)\n",
+ "print(\"drain current (mA) = %.1f\"%Id3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "drain current (mA) = 15\n",
+ "drain current (mA) = 9.6\n",
+ "drain current (mA) = 0.6\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2, Page No. 257"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# find the drain current\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Idss=12.0 # maximum drain current in mili-ampere\n",
+ "VgsOFF=-20.0 # pinch off voltage in volts\n",
+ "Vgs1=0.0 # gate source voltage in volts\n",
+ "Vgs2=-5.0 # gate source voltage in volts\n",
+ "Vgs3=-10.0 # gate source voltage in volts\n",
+ "Vgs4=-15.0 # gate source voltage in volts\n",
+ "Vgs5=-20.0 # gate source voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Id1=Idss*(1-(Vgs1/VgsOFF))**2;\n",
+ "Id2=Idss*(1-(Vgs2/VgsOFF))**2;\n",
+ "Id3=Idss*(1-(Vgs3/VgsOFF))**2;\n",
+ "Id4=Idss*(1-(Vgs4/VgsOFF))**2;\n",
+ "Id5=Idss*(1-(Vgs5/VgsOFF))**2;\n",
+ "\n",
+ "#Result\n",
+ "print(\"Vgs(V)\\tId(mA)\")\n",
+ "print(\" %.f\\t%.f\"%(Vgs1,Id1))\n",
+ "print(\" %.f \\t%.f\"%(Vgs2,Id2))\n",
+ "print(\" %.f \\t%.f\"%(Vgs3,Id3))\n",
+ "print(\" %.f \\t%.f\"%(Vgs4,Id4))\n",
+ "print(\" %.f \\t%.f\"%(Vgs5,Id5))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vgs(V)\tId(mA)\n",
+ " 0\t12\n",
+ " -5 \t7\n",
+ " -10 \t3\n",
+ " -15 \t1\n",
+ " -20 \t0\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3.a, Page No.258"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Plot the min transconductance curve\n",
+ "\n",
+ "import math\n",
+ "import matplotlib.pyplot as plt\n",
+ "% matplotlib inline\n",
+ "from array import array\n",
+ "#variable declaration\n",
+ "#VGS_off=-2 to -6 volt\n",
+ "#IDSS=8 to 20 mA\n",
+ "#Formula : ID=IDSS*[1-VGS/VGS_off]^2\n",
+ "#Let take some values for plotting\n",
+ "IDSS=8.0 # in mA\n",
+ "VGS= array(\"f\", [0, -0.5, -1.0, -1.5, -2.0]) #in Volt\n",
+ "VGS_off=-2 # in Volt\n",
+ "ID=array(\"f\")\n",
+ "print(\" Minimum Transcunductance Values:\\n Vgs \\t Id\")\n",
+ "for i in range(0,5):\n",
+ " ID.append(IDSS*(1-VGS[i]/VGS_off)**2)\n",
+ " print(\"%.1f \\t%.1f\"%(VGS[i],ID[i]))\n",
+ " \n",
+ "plt.plot(VGS,ID)\n",
+ "plt.title(\" Minimum Transconductance Curve\")\n",
+ "plt.xlabel(\"Gate to source voltage (Vgs)\")\n",
+ "plt.ylabel(\"Drain current in milli ampere(Id)\")\n",
+ "plt.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Minimum Transcunductance Values:\n",
+ " Vgs \t Id\n",
+ "0.0 \t8.0\n",
+ "-0.5 \t4.5\n",
+ "-1.0 \t2.0\n",
+ "-1.5 \t0.5\n",
+ "-2.0 \t0.0\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAEZCAYAAACU3p4jAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlcVPX+P/DXsIgiAoqIIiCGooBsguKGDihm3lxzxa2u\n2le69as0U8sSu13Lm1b69Vpm5ZZpLl01t8wFzX3PhdJEcAFRVEB2mJnP7w++nBxgmBmYGQbm9Xw8\n5vHgzJxzPp9zPL7nM5/P+3yOTAghQERE9Z5VbVeAiIhMgwGfiMhCMOATEVkIBnwiIgvBgE9EZCEY\n8ImILAQDfh0zcOBArFu3zuDrkuG9+OKLeO+992q7GkQSBnwzYWVlBTc3NyiVSum9kpIStGjRAlZW\nf/0z7d69GxMmTNBpn/qsayoLFixAkyZN0KRJEzRq1Ag2NjbScmBgYG1Xz6BkMhlkMlmN9pGSkgIr\nKyuoVCoD1cpwrl+/jpEjR8LV1RXOzs4IDg7GZ599ZpZ1pVIM+GakWbNm2LNnj7S8Z88eNGvWrMZB\nw5y88847yMnJQU5ODr788kv06NFDWr58+bK0nhAC9eGeQEMdg7mdi6SkJERERKBNmza4cuUKsrKy\nsHnzZpw7dw45OTl67+/phg4ZDwO+GZkwYQLWrl0rLa9duxYTJ05U+88ul8vxzTffAABWr16NXr16\nYebMmWjWrBmeeeYZ7N27V+O6PXv2xPTp09G0aVO0a9cOx48fx6pVq+Dl5QU3Nze1sp/etmz7yMhI\nadnKygpffPEF2rdvD0dHR7z//vtISkpC9+7d4ezsjDFjxqCkpKTK4y0f1OVyOebOnYuePXuicePG\nuHnzJlatWgV/f384OjrCx8cHX331lbR+QkICPDw88Omnn8LNzQ3u7u5YvXq19Pnu3bsREBAAR0dH\neHh4YPHixdJn27dvR0hICJycnNCuXTv8/PPPAIC0tDQMHjwYLi4uaN++Pb7++mtpm/j4eIwaNQqT\nJk2Co6MjOnXqhHPnzkmfX7hwAZ07d4ajoyPGjBmDwsJCjeev7BzevHkTAFBQUIAZM2bA29sbzs7O\n6N27NwoLC9G7d28AgLOzM5o0aYJTp04hKSkJ0dHRaN68OVxdXTF+/HhkZ2dL+/X29sbixYsRHBws\n/VsUFRVpPfbs7GxMnjwZ7u7u8PDwwHvvvaextT5v3jz06tULixYtgpubGwDA19cX3333HZycnJCQ\nkABPT0+1bby9vXHw4EHpXI4YMQITJkyAk5MTFixYAHt7e2RmZqqdT1dXV+nL4Ntvv4W/vz+aNWuG\nAQMG4Pbt25XWjaogyCzIZDJx5coV4ebmJrKzs8Xjx4+Fm5ubuHLlipDJZNJ6crlcfPPNN0IIIVat\nWiVsbW3F119/LVQqlfjiiy+Eu7u7xnVtbGzE6tWrhUqlEnPnzhWtW7cWr776qiguLhb79u0TTZo0\nEXl5eRW2Ldu+V69eavUdOnSoyMnJEVevXhUNGjQQUVFRIjk5WWRnZwt/f3+xZs2aKo+5/D779Okj\n2rRpIxITE4VSqRQlJSVi165d4ubNm0IIIQ4fPizs7e3F+fPnhRBCHDp0SNjY2Ih58+YJhUIhdu/e\nLezt7UVWVpYQQoiWLVuKo0ePCiGEyMrKkrY7deqUcHJyEvv37xdCCJGamir++OMPIYQQkZGR4h//\n+IcoKioSFy9eFK6uruLgwYNCCCHmzZsnGjZsKPbs2SNUKpWYM2eO6NatmxBCiKKiIuHl5SU+//xz\noVAoxJYtW4Stra147733Kj3WsnOYlJQkhBDilVdeEVFRUSItLU0olUpx4sQJUVRUJFJSUoRMJhNK\npVLa7saNG2L//v2iuLhYZGRkiN69e4s33nhD+tzb21tERESIe/fuicePHws/Pz/x5Zdfaj32oUOH\nimnTpon8/Hzx4MED0bVrV7FixYpK/+1atmwpVq9erfHf9tChQ8LDw0PtPW9vb3HgwAHpXNra2ort\n27cLIYQoKCgQ0dHRYuXKldL6b731loiLixNCCLFt2zbRrl078ccffwilUik+/PBD0aNHD43lU+UY\n8M2ETCYTN27cEFOmTBErVqwQX3zxhXj55ZfFjRs3qgz47dq1kz7Ly8sTMplM3L9/v9J127dvL617\n6dIlIZPJxIMHD6T3XFxcxG+//VZh27Ltywf848ePS8thYWHi3//+t7Q8Y8YMtSBUmfL7lMvlYt68\neVVuM3ToULFkyRIhRGlQadSokVowbNGihTh16pQQQggvLy+xYsUKkZ2drbaPl19+WUyfPr3Cvm/f\nvi2sra1Fbm6u9N6cOXPEiy++KIQoDVIxMTHSZ1evXhWNGjUSQpR+GT39ZSuEED169NAp4CuVStGo\nUSNx6dKlCnVKTk6uEPDL++9//ytCQ0OlZW9vb7F+/Xpp+e233xbTpk2r8tjT09OFnZ2dKCgokN77\n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\nTkSuQmCC\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x53373c8>"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3.b, Page No.258"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Plot the max transconductance curve\n",
+ "\n",
+ "import math\n",
+ "import matplotlib.pyplot as plt\n",
+ "% matplotlib inline\n",
+ "from array import array\n",
+ "#variable declaration\n",
+ "#VGS_off=-2 to -6 volt\n",
+ "#IDSS=8 to 20 mA\n",
+ "#Formula : ID=IDSS*[1-VGS/VGS_off]^2\n",
+ "#Let take some values for plotting\n",
+ "IDSS=20.0 # in mA\n",
+ "VGS= array(\"f\", [0, -2.0, -4.0, -6.0]) #in Volt\n",
+ "VGS_off=-6 # in Volt\n",
+ "ID=array(\"f\")\n",
+ "print(\" Maximum Transcunductance Values:\\n Vgs \\t Id\")\n",
+ "for i in range(0,4):\n",
+ " ID.append(IDSS*(1-VGS[i]/VGS_off)**2)\n",
+ " print(\"%.1f \\t%.1f\"%(VGS[i],ID[i]))\n",
+ " \n",
+ "plt.plot(VGS,ID)\n",
+ "plt.title(\" Maximum Transconductance Curve\")\n",
+ "plt.xlabel(\"Gate to source voltage (Vgs)\")\n",
+ "plt.ylabel(\"Drain current in milli ampere(Id)\")\n",
+ "plt.show()\n",
+ "#Drain current value correspond to Vgs = -4 is wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Maximum Transcunductance Values:\n",
+ " Vgs \t Id\n",
+ "0.0 \t20.0\n",
+ "-2.0 \t8.9\n",
+ "-4.0 \t2.2\n",
+ "-6.0 \t0.0\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEZCAYAAAB7HPUdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlYVHX7P/D3AIoLqLGKC+IuKpvgromay2O5lSvumqWl\nlpaJT5a0+ahFpfWtfPqaW6apfXOHy0LRR3JN/blgruAWiCgqiwjD3L8/uDiPI8sMcGaBeb+uiyvP\nLOfcZ6B77vnM5/4cjYgIiIjIJthZOgAiIjIfJn0iIhvCpE9EZEOY9ImIbAiTPhGRDWHSJyKyIUz6\nNur69etwdnYGZ+xajp2dHa5evWrpMMjGMOlbKTs7O3h6eiIvL0+5LTc3Fx4eHrCzK/+vzdvbG+np\n6dBoNOXel5ratGkDZ2dnODs7w8HBAdWrV1e2Fy9ebOnwrE5ERATGjRtn6TCK9NNPPyEkJATOzs6o\nV68eBgwYgLi4OEuHZfOY9K2Yi4sLoqKilO2oqCi4uLhYXaJW07lz55Ceno709HR0794d//M//6Ns\nh4eHK4/TarUWjJIM+fzzzzF79mwsWLAAKSkpuHHjBl5//XVs37691Pvi71plQlZJo9HIJ598IsOH\nD1due+mll+STTz4RjUaj3PbDDz+Ir6+vODs7S5MmTWTFihXKfYsXL5aOHTuKVqsVEZFvvvlG2rRp\nI48fP5aEhATRaDSSl5cnIiI9evSQBQsWSJcuXcTJyUkGDhwod+7ckbCwMKlVq5a0b99eEhMTRUQK\nPbfg+f/7v/8rIiKrVq2SLl26yOzZs6VOnTrStGlTiYuLkx9++EEaNmwoHh4esmbNGoOvQWhoqLLP\ngmOuXLlSvL29pUePHiIiMmzYMKlbt67Url1bnn32WTl37pzy/AkTJshrr70mzz//vDg7O0vHjh3l\nypUryv1vvvmmeHh4SK1atcTPz0/Onj0rIiJZWVkyZ84cadSokdSuXVu6desmjx49EhGRbdu2SevW\nraVOnToSGhoq58+fV/bXqFEj+eyzz8Tf319q164tI0eOlOzsbOX+pUuXipeXl9SvX19WrlwpGo1G\niefJ16/gNezWrZuyffbsWXnuuefExcVFPD09ZdGiRRIdHS1Vq1aVKlWqiJOTkwQGBhr8m9i3b5/U\nr19fIiMjxcPDQ7y8vGTVqlXK/SWd+6FDh6Rz585Sp04dCQgIkNjY2CJ/b/fv3xcnJyfZsmVLsb/b\nCRMmyIIFC/TiatCggd5ruWTJEvHz8xNHR0dZsmSJDBs2TG8fs2bNklmzZinHnDx5svL6LliwQO/v\nk/6LSd9KaTQaOXv2rHh6esqDBw/k3r174unpKWfPntVL+rt27ZKrV6+KiMj+/fulRo0acuLECRER\n0el08uyzz0pERIRcvHhRnnnmGTl16pSIFE7cPXr0kObNm8vVq1flwYMH0rp1a2nWrJnExMSIVquV\n8ePHy6RJk4p8rkh+gl65cqWI5CcsBwcHWb16teh0OlmwYIHUr19fZsyYITk5ObJnzx5xdnaWzMzM\nEl+DJ/dZcMwJEyZIVlaWkkxXrVolGRkZkpOTI2+++aaS+ETyE4urq6scO3ZMtFqtjBkzRkaNGiUi\nItHR0RIcHCwPHjwQEZG//vpLkpKSRETktddek549e8rff/8teXl5cujQIXn8+LFcuHBBatasKb//\n/rtotVpZunSpNGvWTHJzc0VExMfHRzp27ChJSUly79498fX1le+++05ERKKiosTT01POnTsnmZmZ\nMnr0aL2k/+S5FpxXQdJ/+PCh1K1bVz7//HN5/PixpKeny5EjR0REJCIiQsaNG6f3upX0N7Fv3z5x\ncHCQhQsXilarld27d0uNGjXk/v37JZ77zZs3xdXVVaKiokRE5LfffhNXV1e5c+dOod9bVFSUODg4\nlJh0J06cKO+9956yXVTSDwoKkps3b0p2drZcu3ZNatSoIenp6SIiotVqxcvLS3kdhgwZItOmTZOs\nrCxJSUmRDh066L3Z0X8x6VspjUYjly9flpdffllWrFgh3377rbzyyity+fJlvaT/tCFDhsiyZcuU\n7cTERHFxcRFfX19ZvHixcvvTiTs0NFQWLVqk3P/WW2/JgAEDlO0dO3YoCdWYpN+8eXPlvtOnT4tG\no5GUlBTlNldXV/l//+//lfgaFJX0ExISin18WlqaaDQaefjwoYjkJ5apU6cq9+/evVtatWolIiIx\nMTHSokULOXz4sN555OXlSfXq1eX06dOF9v/hhx/KyJEjlW2dTif169eX/fv3i0h+0l+/fr1y/zvv\nvCPTpk0TEZFJkybJ/PnzlfsuXrxodNL/6aefpF27dkWe88KFC2Xs2LHFviYi+n8T+/btk+rVq+ud\ns4eHhxw5cqTEc1+8eHGhN5d+/foV+Yntxx9/lLp165YY08SJE0us9H18fPQ+gYiIdOvWTdauXSsi\n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\nNoRJn4jIhvx/v2eKsTRDxOMAAAAASUVORK5CYII=\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x8c9c5f8>"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4, Page No. 261"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain current and transconductance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Idss=20.0 # maximum drain current in mili-ampere\n",
+ "Vp=-8.0 # pintc off voltage in volts\n",
+ "gmo=5000.0 # in micro seconds\n",
+ "Vgs=-4.0 # gate to source voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Id=Idss*(1-(Vgs/Vp))**2\n",
+ "gm=gmo*(1-(Vgs/Vp));\n",
+ "\n",
+ "#Result\n",
+ "print(\"drain current (mA) = %.f\"%Id)\n",
+ "print(\"transconductance (micro-second) = %.f\"%gm)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "drain current (mA) = 5\n",
+ "transconductance (micro-second) = 2500\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.5, Page No.279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain resisitance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Id=0.4 #drain current in mili-ampere\n",
+ "Vd=1.0 #drain voltage in volts\n",
+ "Vs=-5.0 #dc voltage in volts\n",
+ "Vss=-3.0 #dc voltage in volts\n",
+ "Vdd=5.0 #dc voltage in volts\n",
+ "MuCox=20.0 #in micro-ampere/volts\n",
+ "W=400.0 #in micro-metre\n",
+ "l=10.0 # in micro-metre\n",
+ "\n",
+ "#Calculations\n",
+ "Id=((1.0/2)*(MuCox)*(W/l))\n",
+ "Rs=(Vss-Vs)/(Id*10**-3)\n",
+ "Rd=(Vdd-Vd)/(Id*10**-3)\n",
+ "\n",
+ "#Result\n",
+ "print(\"The values of the resistances are as follows : \")\n",
+ "print(\"Resistance Rs is %.f K-ohm\"%Rs)\n",
+ "print(\"Resistance Rd is %.f K-ohm\"%Rd);\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The values of the resistances are as follows : \n",
+ "Resistance Rs is 5 K-ohm\n",
+ "Resistance Rd is 10 K-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6, Page No. 279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain resisitance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Vdd=10.0 # in volt\n",
+ "ID=0.4 # in mA\n",
+ "mu_nCox=20.0 # in uA/V^2\n",
+ "W=100.0 # in um\n",
+ "L=10.0 # in um\n",
+ "Vt=2.0 # in Volt\n",
+ "\n",
+ "#Calculations\n",
+ "#Formula : ID=mu_n*Cox*W*(VGS-Vt)^2/(2*L)\n",
+ "VGS=math.sqrt(2*L*ID/(mu_nCox*10**-3*W))+(Vt)\n",
+ "Vd=VGS\n",
+ "R=(Vdd-Vd)/ID\n",
+ "\n",
+ "#Result\n",
+ "print(\"Drain resistance is %.f k-ohm\"%R)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Drain resistance is 15 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7, Page No. 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain to source resisitance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Vdd=5.0 #in volt\n",
+ "knwl=1.0 #in mA/V^2\n",
+ "Vd=0.1 #drain voltage\n",
+ "Vt=1.0 #in Volt\n",
+ "\n",
+ "#Calculations\n",
+ "Id=Vt*((Vdd-Vt)*Vd- (1.0/2)*0.01) #drain current in milli ampere\n",
+ "Rd=(Vdd-Vd)/Id #resistance in killo ohms\n",
+ "Rds= Vd/Id #resistance in killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Effective drain to source resistance is %.f ohm\"%(Rds*1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Effective drain to source resistance is 253 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8, Page No. 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Analyse the circuit\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Vdd=10.0 #in volt\n",
+ "ID=0.4 #in mA\n",
+ "knwl=1.0 #in mA/V^2\n",
+ "Vg=5.0 #gate voltage in volys\n",
+ "Vt=1.0 #in Volt\n",
+ "Rd=6.0 #drain resistance in killo ohms\n",
+ "Id=0.5 #in mA after solving the qudratic equation\n",
+ "\n",
+ "#Calaculations\n",
+ "Vs= Id*Rd #source voltage in volts\n",
+ "Vd= Vdd-Rd*Id #drain voltage in volts\n",
+ "Vgs= Vg-Rd*Id #gate to source voltage in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"source voltage = %.f V\"%Vs)\n",
+ "print(\"drain voltage = %.f V\"%Vd)\n",
+ "print(\"gate to source voltage = %.f V\"%Vgs)\n",
+ "print(\"drain current = %.1f mA\"%Id)\n",
+ "print(\"\\nAs Vd>Vg-Vt, the transistor is operating at saturation as initially assumed.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "source voltage = 3 V\n",
+ "drain voltage = 7 V\n",
+ "gate to source voltage = 2 V\n",
+ "drain current = 0.5 mA\n",
+ "\n",
+ "As Vd>Vg-Vt, the transistor is operating at saturation as initially assumed.\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.9, Page No.281"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain resisitance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Vdd=5.0 #in volt\n",
+ "Id=0.5 #in mA\n",
+ "knwl=1.0 #in mA/V^2\n",
+ "Vt=-1.0 #in Volt\n",
+ "\n",
+ "#Calcualtions\n",
+ "#Formula : ID=mu_n*Cox*W*(VGS-Vt)^2/(2*L)\n",
+ "VGS=math.sqrt((2*Id/knwl))+(Vt)\n",
+ "Vd=3\n",
+ "Rd1=Vd/Id #drain resistance in killo ohms\n",
+ "Vdm= Vd-Vt #saturation mode operation\n",
+ "Rd2=Vdm/Id #drain resistance in killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Drain resistance is %.f k-ohm\"%Rd1)\n",
+ "print(\"Largest value of drain resistance maintaining saturation-region is %.f k-ohm\"%Rd2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Drain resistance is 6 k-ohm\n",
+ "Largest value of drain resistance maintaining saturation-region is 8 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.10, Page No.282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# channel width to channel length ratio and drain resisitance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Id=100.0 # drain current in micro-ampere\n",
+ "kn=20.0 # in micro-ampere per volt^2\n",
+ "Vt=-1.0 # in volts\n",
+ "Vgs=0.0 # gate source voltage in volts\n",
+ "Vdd=5.0 # dc voltage in volts\n",
+ "Vd=1.0 # drain voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "wl=(2*Id/(kn*(Vgs-Vt)**2))\n",
+ "Rd=(Vdd-Vd)/(Id*10**-3)\n",
+ "\n",
+ "#Result\n",
+ "print(\"channel width to channel ratio (W/L) = %.f\"%wl)\n",
+ "print(\"drain resistance (in k-ohm) = %.f\"%Rd)\n",
+ "print(\"\\nRd can vary in the range 0 to 40 k-ohm\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "channel width to channel ratio (W/L) = 10\n",
+ "drain resistance (in k-ohm) = 40\n",
+ "\n",
+ "Rd can vary in the range 0 to 40 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.11, Page No. 282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain to source resisitance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Vdd=10.0 # in volt\n",
+ "knwl=1.0 # in mA/V^2\n",
+ "Vd=0.1 # drain voltage\n",
+ "Vt=-1.0 # in Volt\n",
+ "\n",
+ "#Calculations\n",
+ "Id=1*((-Vt)*Vd- (1.0/2)*0.01)# drain current in milli ampere\n",
+ "Rd=(Vdd-Vd)/Id # resistance in killo ohms\n",
+ "Rds= Vd/Id # resistance in killo ohms\n",
+ "print(\"Drain to source resistance is %.f k-ohm\"%Rds)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Drain to source resistance is 1 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.12, Page No.287"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# input resistance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Vdd=15.0 # in volt\n",
+ "knwl=0.25 # in mA/V^2\n",
+ "Va=50.0 # voltage\n",
+ "Vt=1.5 # in Volt\n",
+ "Id=1.06 # drain current in milli ampre\n",
+ "Vd= 4.4 # drain oltage in volt\n",
+ "Rd=10.0 # drain resistance in killo ohms\n",
+ "Rg=10.0 # gate resistance in killo ohms\n",
+ "Rl=10.0 # load resistance in killo ohms\n",
+ "Ii=4.3 # input current in milli ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Vgs=Vd\n",
+ "gm=knwl*(Vgs-Vt) # transconductance in mA/V\n",
+ "ro=Va/Id # output resistance in killo ohms\n",
+ "x=(Rd*Rl)/(Rd+Rl)\n",
+ "Av= -gm*((x*ro)/(x+ro))\n",
+ "Ri= Rg/Ii # input resistance in mega ohms\n",
+ "\n",
+ "print(\"Input resistance (Rin) = %.2f Mega-ohm\"%Ri)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input resistance (Rin) = 2.33 Mega-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_4_1.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_4_1.ipynb
new file mode 100755
index 00000000..2d4eb6b7
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_4_1.ipynb
@@ -0,0 +1,675 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4 : Field Effect Transistors and MOSFETs"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1, Page No. 257"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# find the drain current\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Idss=15.0 # maximum drain current in mili-ampere\n",
+ "VgsOFF=-5.0 # pinch off voltage in volts\n",
+ "Vgs1=0.0 # gate source voltage in volts\n",
+ "Vgs2=-1.0 # gate source voltage in volts\n",
+ "Vgs3=-4.0 # gate source voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Id1=Idss*(1-(Vgs1/VgsOFF))**2\n",
+ "Id2=Idss*(1-(Vgs2/VgsOFF))**2\n",
+ "Id3=Idss*(1-(Vgs3/VgsOFF))**2\n",
+ "\n",
+ "#Result\n",
+ "print(\"drain current (mA) = %.f\"%Id1)\n",
+ "print(\"drain current (mA) = %.1f\"%Id2)\n",
+ "print(\"drain current (mA) = %.1f\"%Id3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "drain current (mA) = 15\n",
+ "drain current (mA) = 9.6\n",
+ "drain current (mA) = 0.6\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2, Page No. 257"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# find the drain current\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Idss=12.0 # maximum drain current in mili-ampere\n",
+ "VgsOFF=-20.0 # pinch off voltage in volts\n",
+ "Vgs1=0.0 # gate source voltage in volts\n",
+ "Vgs2=-5.0 # gate source voltage in volts\n",
+ "Vgs3=-10.0 # gate source voltage in volts\n",
+ "Vgs4=-15.0 # gate source voltage in volts\n",
+ "Vgs5=-20.0 # gate source voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Id1=Idss*(1-(Vgs1/VgsOFF))**2;\n",
+ "Id2=Idss*(1-(Vgs2/VgsOFF))**2;\n",
+ "Id3=Idss*(1-(Vgs3/VgsOFF))**2;\n",
+ "Id4=Idss*(1-(Vgs4/VgsOFF))**2;\n",
+ "Id5=Idss*(1-(Vgs5/VgsOFF))**2;\n",
+ "\n",
+ "#Result\n",
+ "print(\"Vgs(V)\\tId(mA)\")\n",
+ "print(\" %.f\\t%.f\"%(Vgs1,Id1))\n",
+ "print(\" %.f \\t%.f\"%(Vgs2,Id2))\n",
+ "print(\" %.f \\t%.f\"%(Vgs3,Id3))\n",
+ "print(\" %.f \\t%.f\"%(Vgs4,Id4))\n",
+ "print(\" %.f \\t%.f\"%(Vgs5,Id5))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vgs(V)\tId(mA)\n",
+ " 0\t12\n",
+ " -5 \t7\n",
+ " -10 \t3\n",
+ " -15 \t1\n",
+ " -20 \t0\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3.a, Page No.258"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Plot the min transconductance curve\n",
+ "\n",
+ "import math\n",
+ "import matplotlib.pyplot as plt\n",
+ "%matplotlib inline\n",
+ "from array import array\n",
+ "#variable declaration\n",
+ "#VGS_off=-2 to -6 volt\n",
+ "#IDSS=8 to 20 mA\n",
+ "#Formula : ID=IDSS*[1-VGS/VGS_off]^2\n",
+ "#Let take some values for plotting\n",
+ "IDSS=8.0 # in mA\n",
+ "VGS= array(\"f\", [0, -0.5, -1.0, -1.5, -2.0]) #in Volt\n",
+ "VGS_off=-2 # in Volt\n",
+ "ID=array(\"f\")\n",
+ "print(\" Minimum Transcunductance Values:\\n Vgs \\t Id\")\n",
+ "for i in range(0,5):\n",
+ " ID.append(IDSS*(1-VGS[i]/VGS_off)**2)\n",
+ " print(\"%.1f \\t%.1f\"%(VGS[i],ID[i]))\n",
+ " \n",
+ "plt.plot(VGS,ID)\n",
+ "plt.title(\" Minimum Transconductance Curve\")\n",
+ "plt.xlabel(\"Gate to source voltage (Vgs)\")\n",
+ "plt.ylabel(\"Drain current in milli ampere(Id)\")\n",
+ "plt.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Minimum Transcunductance Values:\n",
+ " Vgs \t Id\n",
+ "0.0 \t8.0\n",
+ "-0.5 \t4.5\n",
+ "-1.0 \t2.0\n",
+ "-1.5 \t0.5\n",
+ "-2.0 \t0.0\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAEZCAYAAACU3p4jAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlcVPX+P/DXsIgiAoqIIiCGooBsguKGDihm3lxzxa2u\n2le69as0U8sSu13Lm1b69Vpm5ZZpLl01t8wFzX3PhdJEcAFRVEB2mJnP7w++nBxgmBmYGQbm9Xw8\n5vHgzJxzPp9zPL7nM5/P+3yOTAghQERE9Z5VbVeAiIhMgwGfiMhCMOATEVkIBnwiIgvBgE9EZCEY\n8ImILAQDfh0zcOBArFu3zuDrkuG9+OKLeO+992q7GkQSBnwzYWVlBTc3NyiVSum9kpIStGjRAlZW\nf/0z7d69GxMmTNBpn/qsayoLFixAkyZN0KRJEzRq1Ag2NjbScmBgYG1Xz6BkMhlkMlmN9pGSkgIr\nKyuoVCoD1cpwrl+/jpEjR8LV1RXOzs4IDg7GZ599ZpZ1pVIM+GakWbNm2LNnj7S8Z88eNGvWrMZB\nw5y88847yMnJQU5ODr788kv06NFDWr58+bK0nhAC9eGeQEMdg7mdi6SkJERERKBNmza4cuUKsrKy\nsHnzZpw7dw45OTl67+/phg4ZDwO+GZkwYQLWrl0rLa9duxYTJ05U+88ul8vxzTffAABWr16NXr16\nYebMmWjWrBmeeeYZ7N27V+O6PXv2xPTp09G0aVO0a9cOx48fx6pVq+Dl5QU3Nze1sp/etmz7yMhI\nadnKygpffPEF2rdvD0dHR7z//vtISkpC9+7d4ezsjDFjxqCkpKTK4y0f1OVyOebOnYuePXuicePG\nuHnzJlatWgV/f384OjrCx8cHX331lbR+QkICPDw88Omnn8LNzQ3u7u5YvXq19Pnu3bsREBAAR0dH\neHh4YPHixdJn27dvR0hICJycnNCuXTv8/PPPAIC0tDQMHjwYLi4uaN++Pb7++mtpm/j4eIwaNQqT\nJk2Co6MjOnXqhHPnzkmfX7hwAZ07d4ajoyPGjBmDwsJCjeev7BzevHkTAFBQUIAZM2bA29sbzs7O\n6N27NwoLC9G7d28AgLOzM5o0aYJTp04hKSkJ0dHRaN68OVxdXTF+/HhkZ2dL+/X29sbixYsRHBws\n/VsUFRVpPfbs7GxMnjwZ7u7u8PDwwHvvvaextT5v3jz06tULixYtgpubGwDA19cX3333HZycnJCQ\nkABPT0+1bby9vXHw4EHpXI4YMQITJkyAk5MTFixYAHt7e2RmZqqdT1dXV+nL4Ntvv4W/vz+aNWuG\nAQMG4Pbt25XWjaogyCzIZDJx5coV4ebmJrKzs8Xjx4+Fm5ubuHLlipDJZNJ6crlcfPPNN0IIIVat\nWiVsbW3F119/LVQqlfjiiy+Eu7u7xnVtbGzE6tWrhUqlEnPnzhWtW7cWr776qiguLhb79u0TTZo0\nEXl5eRW2Ldu+V69eavUdOnSoyMnJEVevXhUNGjQQUVFRIjk5WWRnZwt/f3+xZs2aKo+5/D779Okj\n2rRpIxITE4VSqRQlJSVi165d4ubNm0IIIQ4fPizs7e3F+fPnhRBCHDp0SNjY2Ih58+YJhUIhdu/e\nLezt7UVWVpYQQoiWLVuKo0ePCiGEyMrKkrY7deqUcHJyEvv37xdCCJGamir++OMPIYQQkZGR4h//\n+IcoKioSFy9eFK6uruLgwYNCCCHmzZsnGjZsKPbs2SNUKpWYM2eO6NatmxBCiKKiIuHl5SU+//xz\noVAoxJYtW4Stra147733Kj3WsnOYlJQkhBDilVdeEVFRUSItLU0olUpx4sQJUVRUJFJSUoRMJhNK\npVLa7saNG2L//v2iuLhYZGRkiN69e4s33nhD+tzb21tERESIe/fuicePHws/Pz/x5Zdfaj32oUOH\nimnTpon8/Hzx4MED0bVrV7FixYpK/+1atmwpVq9erfHf9tChQ8LDw0PtPW9vb3HgwAHpXNra2ort\n27cLIYQoKCgQ0dHRYuXKldL6b731loiLixNCCLFt2zbRrl078ccffwilUik+/PBD0aNHD43lU+UY\n8M2ETCYTN27cEFOmTBErVqwQX3zxhXj55ZfFjRs3qgz47dq1kz7Ly8sTMplM3L9/v9J127dvL617\n6dIlIZPJxIMHD6T3XFxcxG+//VZh27Ltywf848ePS8thYWHi3//+t7Q8Y8YMtSBUmfL7lMvlYt68\neVVuM3ToULFkyRIhRGlQadSokVowbNGihTh16pQQQggvLy+xYsUKkZ2drbaPl19+WUyfPr3Cvm/f\nvi2sra1Fbm6u9N6cOXPEiy++KIQoDVIxMTHSZ1evXhWNGjUSQpR+GT39ZSuEED169NAp4CuVStGo\nUSNx6dKlCnVKTk6uEPDL++9//ytCQ0OlZW9vb7F+/Xpp+e233xbTpk2r8tjT09OFnZ2dKCgokN77\n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\nTkSuQmCC\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x53373c8>"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3.b, Page No.258"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Plot the max transconductance curve\n",
+ "\n",
+ "import math\n",
+ "import matplotlib.pyplot as plt\n",
+ "%matplotlib inline\n",
+ "from array import array\n",
+ "#variable declaration\n",
+ "#VGS_off=-2 to -6 volt\n",
+ "#IDSS=8 to 20 mA\n",
+ "#Formula : ID=IDSS*[1-VGS/VGS_off]^2\n",
+ "#Let take some values for plotting\n",
+ "IDSS=20.0 # in mA\n",
+ "VGS= array(\"f\", [0, -2.0, -4.0, -6.0]) #in Volt\n",
+ "VGS_off=-6 # in Volt\n",
+ "ID=array(\"f\")\n",
+ "print(\" Maximum Transcunductance Values:\\n Vgs \\t Id\")\n",
+ "for i in range(0,4):\n",
+ " ID.append(IDSS*(1-VGS[i]/VGS_off)**2)\n",
+ " print(\"%.1f \\t%.1f\"%(VGS[i],ID[i]))\n",
+ " \n",
+ "plt.plot(VGS,ID)\n",
+ "plt.title(\" Maximum Transconductance Curve\")\n",
+ "plt.xlabel(\"Gate to source voltage (Vgs)\")\n",
+ "plt.ylabel(\"Drain current in milli ampere(Id)\")\n",
+ "plt.show()\n",
+ "#Drain current value correspond to Vgs = -4 is wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Maximum Transcunductance Values:\n",
+ " Vgs \t Id\n",
+ "0.0 \t20.0\n",
+ "-2.0 \t8.9\n",
+ "-4.0 \t2.2\n",
+ "-6.0 \t0.0\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEZCAYAAAB7HPUdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlYVHX7P/D3AIoLqLGKC+IuKpvgromay2O5lSvumqWl\nlpaJT5a0+ahFpfWtfPqaW6apfXOHy0LRR3JN/blgruAWiCgqiwjD3L8/uDiPI8sMcGaBeb+uiyvP\nLOfcZ6B77vnM5/4cjYgIiIjIJthZOgAiIjIfJn0iIhvCpE9EZEOY9ImIbAiTPhGRDWHSJyKyIUz6\nNur69etwdnYGZ+xajp2dHa5evWrpMMjGMOlbKTs7O3h6eiIvL0+5LTc3Fx4eHrCzK/+vzdvbG+np\n6dBoNOXel5ratGkDZ2dnODs7w8HBAdWrV1e2Fy9ebOnwrE5ERATGjRtn6TCK9NNPPyEkJATOzs6o\nV68eBgwYgLi4OEuHZfOY9K2Yi4sLoqKilO2oqCi4uLhYXaJW07lz55Ceno709HR0794d//M//6Ns\nh4eHK4/TarUWjJIM+fzzzzF79mwsWLAAKSkpuHHjBl5//XVs37691Pvi71plQlZJo9HIJ598IsOH\nD1due+mll+STTz4RjUaj3PbDDz+Ir6+vODs7S5MmTWTFihXKfYsXL5aOHTuKVqsVEZFvvvlG2rRp\nI48fP5aEhATRaDSSl5cnIiI9evSQBQsWSJcuXcTJyUkGDhwod+7ckbCwMKlVq5a0b99eEhMTRUQK\nPbfg+f/7v/8rIiKrVq2SLl26yOzZs6VOnTrStGlTiYuLkx9++EEaNmwoHh4esmbNGoOvQWhoqLLP\ngmOuXLlSvL29pUePHiIiMmzYMKlbt67Url1bnn32WTl37pzy/AkTJshrr70mzz//vDg7O0vHjh3l\nypUryv1vvvmmeHh4SK1atcTPz0/Onj0rIiJZWVkyZ84cadSokdSuXVu6desmjx49EhGRbdu2SevW\nraVOnToSGhoq58+fV/bXqFEj+eyzz8Tf319q164tI0eOlOzsbOX+pUuXipeXl9SvX19WrlwpGo1G\niefJ16/gNezWrZuyffbsWXnuuefExcVFPD09ZdGiRRIdHS1Vq1aVKlWqiJOTkwQGBhr8m9i3b5/U\nr19fIiMjxcPDQ7y8vGTVqlXK/SWd+6FDh6Rz585Sp04dCQgIkNjY2CJ/b/fv3xcnJyfZsmVLsb/b\nCRMmyIIFC/TiatCggd5ruWTJEvHz8xNHR0dZsmSJDBs2TG8fs2bNklmzZinHnDx5svL6LliwQO/v\nk/6LSd9KaTQaOXv2rHh6esqDBw/k3r174unpKWfPntVL+rt27ZKrV6+KiMj+/fulRo0acuLECRER\n0el08uyzz0pERIRcvHhRnnnmGTl16pSIFE7cPXr0kObNm8vVq1flwYMH0rp1a2nWrJnExMSIVquV\n8ePHy6RJk4p8rkh+gl65cqWI5CcsBwcHWb16teh0OlmwYIHUr19fZsyYITk5ObJnzx5xdnaWzMzM\nEl+DJ/dZcMwJEyZIVlaWkkxXrVolGRkZkpOTI2+++aaS+ETyE4urq6scO3ZMtFqtjBkzRkaNGiUi\nItHR0RIcHCwPHjwQEZG//vpLkpKSRETktddek549e8rff/8teXl5cujQIXn8+LFcuHBBatasKb//\n/rtotVpZunSpNGvWTHJzc0VExMfHRzp27ChJSUly79498fX1le+++05ERKKiosTT01POnTsnmZmZ\nMnr0aL2k/+S5FpxXQdJ/+PCh1K1bVz7//HN5/PixpKeny5EjR0REJCIiQsaNG6f3upX0N7Fv3z5x\ncHCQhQsXilarld27d0uNGjXk/v37JZ77zZs3xdXVVaKiokRE5LfffhNXV1e5c+dOod9bVFSUODg4\nlJh0J06cKO+9956yXVTSDwoKkps3b0p2drZcu3ZNatSoIenp6SIiotVqxcvLS3kdhgwZItOmTZOs\nrCxJSUmRDh066L3Z0X8x6VspjUYjly9flpdffllWrFgh3377rbzyyity+fJlvaT/tCFDhsiyZcuU\n7cTERHFxcRFfX19ZvHixcvvTiTs0NFQWLVqk3P/WW2/JgAEDlO0dO3YoCdWYpN+8eXPlvtOnT4tG\no5GUlBTlNldXV/l//+//lfgaFJX0ExISin18WlqaaDQaefjwoYjkJ5apU6cq9+/evVtatWolIiIx\nMTHSokULOXz4sN555OXlSfXq1eX06dOF9v/hhx/KyJEjlW2dTif169eX/fv3i0h+0l+/fr1y/zvv\nvCPTpk0TEZFJkybJ/PnzlfsuXrxodNL/6aefpF27dkWe88KFC2Xs2LHFviYi+n8T+/btk+rVq+ud\ns4eHhxw5cqTEc1+8eHGhN5d+/foV+Yntxx9/lLp165YY08SJE0us9H18fPQ+gYiIdOvWTdauXSsi\n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\nNoRJn4jIhvx/v2eKsTRDxOMAAAAASUVORK5CYII=\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x8c9c5f8>"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4, Page No. 261"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain current and transconductance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Idss=20.0 # maximum drain current in mili-ampere\n",
+ "Vp=-8.0 # pintc off voltage in volts\n",
+ "gmo=5000.0 # in micro seconds\n",
+ "Vgs=-4.0 # gate to source voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Id=Idss*(1-(Vgs/Vp))**2\n",
+ "gm=gmo*(1-(Vgs/Vp));\n",
+ "\n",
+ "#Result\n",
+ "print(\"drain current (mA) = %.f\"%Id)\n",
+ "print(\"transconductance (micro-second) = %.f\"%gm)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "drain current (mA) = 5\n",
+ "transconductance (micro-second) = 2500\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.5, Page No.279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain resisitance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Id=0.4 #drain current in mili-ampere\n",
+ "Vd=1.0 #drain voltage in volts\n",
+ "Vs=-5.0 #dc voltage in volts\n",
+ "Vss=-3.0 #dc voltage in volts\n",
+ "Vdd=5.0 #dc voltage in volts\n",
+ "MuCox=20.0 #in micro-ampere/volts\n",
+ "W=400.0 #in micro-metre\n",
+ "l=10.0 # in micro-metre\n",
+ "\n",
+ "#Calculations\n",
+ "Id=((1.0/2)*(MuCox)*(W/l))\n",
+ "Rs=(Vss-Vs)/(Id*10**-3)\n",
+ "Rd=(Vdd-Vd)/(Id*10**-3)\n",
+ "\n",
+ "#Result\n",
+ "print(\"The values of the resistances are as follows : \")\n",
+ "print(\"Resistance Rs is %.f K-ohm\"%Rs)\n",
+ "print(\"Resistance Rd is %.f K-ohm\"%Rd);\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The values of the resistances are as follows : \n",
+ "Resistance Rs is 5 K-ohm\n",
+ "Resistance Rd is 10 K-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.6, Page No. 279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain resisitance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Vdd=10.0 # in volt\n",
+ "ID=0.4 # in mA\n",
+ "mu_nCox=20.0 # in uA/V^2\n",
+ "W=100.0 # in um\n",
+ "L=10.0 # in um\n",
+ "Vt=2.0 # in Volt\n",
+ "\n",
+ "#Calculations\n",
+ "#Formula : ID=mu_n*Cox*W*(VGS-Vt)^2/(2*L)\n",
+ "VGS=math.sqrt(2*L*ID/(mu_nCox*10**-3*W))+(Vt)\n",
+ "Vd=VGS\n",
+ "R=(Vdd-Vd)/ID\n",
+ "\n",
+ "#Result\n",
+ "print(\"Drain resistance is %.f k-ohm\"%R)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Drain resistance is 15 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7, Page No. 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain to source resisitance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Vdd=5.0 #in volt\n",
+ "knwl=1.0 #in mA/V^2\n",
+ "Vd=0.1 #drain voltage\n",
+ "Vt=1.0 #in Volt\n",
+ "\n",
+ "#Calculations\n",
+ "Id=Vt*((Vdd-Vt)*Vd- (1.0/2)*0.01) #drain current in milli ampere\n",
+ "Rd=(Vdd-Vd)/Id #resistance in killo ohms\n",
+ "Rds= Vd/Id #resistance in killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Effective drain to source resistance is %.f ohm\"%(Rds*1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Effective drain to source resistance is 253 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8, Page No. 280"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Analyse the circuit\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Vdd=10.0 #in volt\n",
+ "ID=0.4 #in mA\n",
+ "knwl=1.0 #in mA/V^2\n",
+ "Vg=5.0 #gate voltage in volys\n",
+ "Vt=1.0 #in Volt\n",
+ "Rd=6.0 #drain resistance in killo ohms\n",
+ "Id=0.5 #in mA after solving the qudratic equation\n",
+ "\n",
+ "#Calaculations\n",
+ "Vs= Id*Rd #source voltage in volts\n",
+ "Vd= Vdd-Rd*Id #drain voltage in volts\n",
+ "Vgs= Vg-Rd*Id #gate to source voltage in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"source voltage = %.f V\"%Vs)\n",
+ "print(\"drain voltage = %.f V\"%Vd)\n",
+ "print(\"gate to source voltage = %.f V\"%Vgs)\n",
+ "print(\"drain current = %.1f mA\"%Id)\n",
+ "print(\"\\nAs Vd>Vg-Vt, the transistor is operating at saturation as initially assumed.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "source voltage = 3 V\n",
+ "drain voltage = 7 V\n",
+ "gate to source voltage = 2 V\n",
+ "drain current = 0.5 mA\n",
+ "\n",
+ "As Vd>Vg-Vt, the transistor is operating at saturation as initially assumed.\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.9, Page No.281"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain resisitance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Vdd=5.0 #in volt\n",
+ "Id=0.5 #in mA\n",
+ "knwl=1.0 #in mA/V^2\n",
+ "Vt=-1.0 #in Volt\n",
+ "\n",
+ "#Calcualtions\n",
+ "#Formula : ID=mu_n*Cox*W*(VGS-Vt)^2/(2*L)\n",
+ "VGS=math.sqrt((2*Id/knwl))+(Vt)\n",
+ "Vd=3\n",
+ "Rd1=Vd/Id #drain resistance in killo ohms\n",
+ "Vdm= Vd-Vt #saturation mode operation\n",
+ "Rd2=Vdm/Id #drain resistance in killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Drain resistance is %.f k-ohm\"%Rd1)\n",
+ "print(\"Largest value of drain resistance maintaining saturation-region is %.f k-ohm\"%Rd2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Drain resistance is 6 k-ohm\n",
+ "Largest value of drain resistance maintaining saturation-region is 8 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.10, Page No.282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# channel width to channel length ratio and drain resisitance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Id=100.0 # drain current in micro-ampere\n",
+ "kn=20.0 # in micro-ampere per volt^2\n",
+ "Vt=-1.0 # in volts\n",
+ "Vgs=0.0 # gate source voltage in volts\n",
+ "Vdd=5.0 # dc voltage in volts\n",
+ "Vd=1.0 # drain voltage in volts\n",
+ "\n",
+ "#Calculations\n",
+ "wl=(2*Id/(kn*(Vgs-Vt)**2))\n",
+ "Rd=(Vdd-Vd)/(Id*10**-3)\n",
+ "\n",
+ "#Result\n",
+ "print(\"channel width to channel ratio (W/L) = %.f\"%wl)\n",
+ "print(\"drain resistance (in k-ohm) = %.f\"%Rd)\n",
+ "print(\"\\nRd can vary in the range 0 to 40 k-ohm\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "channel width to channel ratio (W/L) = 10\n",
+ "drain resistance (in k-ohm) = 40\n",
+ "\n",
+ "Rd can vary in the range 0 to 40 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.11, Page No. 282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain to source resisitance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Vdd=10.0 # in volt\n",
+ "knwl=1.0 # in mA/V^2\n",
+ "Vd=0.1 # drain voltage\n",
+ "Vt=-1.0 # in Volt\n",
+ "\n",
+ "#Calculations\n",
+ "Id=1*((-Vt)*Vd- (1.0/2)*0.01)# drain current in milli ampere\n",
+ "Rd=(Vdd-Vd)/Id # resistance in killo ohms\n",
+ "Rds= Vd/Id # resistance in killo ohms\n",
+ "print(\"Drain to source resistance is %.f k-ohm\"%Rds)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Drain to source resistance is 1 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.12, Page No.287"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# input resistance\n",
+ "\n",
+ "import math\n",
+ "#variable declaration\n",
+ "Vdd=15.0 # in volt\n",
+ "knwl=0.25 # in mA/V^2\n",
+ "Va=50.0 # voltage\n",
+ "Vt=1.5 # in Volt\n",
+ "Id=1.06 # drain current in milli ampre\n",
+ "Vd= 4.4 # drain oltage in volt\n",
+ "Rd=10.0 # drain resistance in killo ohms\n",
+ "Rg=10.0 # gate resistance in killo ohms\n",
+ "Rl=10.0 # load resistance in killo ohms\n",
+ "Ii=4.3 # input current in milli ampere\n",
+ "\n",
+ "#Calculations\n",
+ "Vgs=Vd\n",
+ "gm=knwl*(Vgs-Vt) # transconductance in mA/V\n",
+ "ro=Va/Id # output resistance in killo ohms\n",
+ "x=(Rd*Rl)/(Rd+Rl)\n",
+ "Av= -gm*((x*ro)/(x+ro))\n",
+ "Ri= Rg/Ii # input resistance in mega ohms\n",
+ "\n",
+ "print(\"Input resistance (Rin) = %.2f Mega-ohm\"%Ri)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Input resistance (Rin) = 2.33 Mega-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_5.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_5.ipynb
new file mode 100755
index 00000000..e37d35ce
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_5.ipynb
@@ -0,0 +1,1598 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5 : Frequency Response"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.1, Page No. 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#COUPLING CAPACITOR\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=10.0 # series resistance in killo ohms\n",
+ "Xc1= Rs/10.0 # reactance at 20Hz\n",
+ "\n",
+ "#Calcualtions\n",
+ "C1=(1.0/(2*math.pi*20*Xc1*10**3))*10**6 # CAPACITANCE IN MICRO FARAD\n",
+ "\n",
+ "#Result\n",
+ "print(\"Capacitance = %.3f micro Farad.\\nAs this is not a standard value will select 10 micro farad\"%(math.floor(C1*1000)/1000))\n",
+ "#Answer is slightly different than in book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacitance = 7.957 micro Farad.\n",
+ "As this is not a standard value will select 10 micro farad\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2, Page No. 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# amplifier gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "f=20.0 # frequency in hertz\n",
+ "Avm=100.0 # mid voltage gain\n",
+ "fl=40.0 # lower cut off frequency in hertz\n",
+ "fh=16.0 # lower cut off frequency in hertz\n",
+ "\n",
+ "#Calcualtions\n",
+ "Avl= (Avm/(math.sqrt(1+(fl/f)**2))) # gain at lower cut off frequency\n",
+ "Avh= (Avm/(math.sqrt(1+(f/fh)**2))) # gain at upper cut off frequency\n",
+ "\n",
+ "#Result\n",
+ "print(\"gain at lower cut off frequency = %.2f\"%Avl)\n",
+ "print(\"gain at upper cut off frequency = %.2f\"%Avh)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain at lower cut off frequency = 44.72\n",
+ "gain at upper cut off frequency = 62.47\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.3, Page No. 312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# amplifier gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "f=40.0 # frequency in hertz\n",
+ "Avm=40.0 # mid voltage gain\n",
+ "fl=40.0 # lower cut off frequency in hertz\n",
+ "\n",
+ "#Calculations\n",
+ "Avl= (Avm/(math.sqrt(1+(fl/f)**2))) # gain at lower cut off frequency\n",
+ "\n",
+ "#Result\n",
+ "print(\"gain at lower cut off frequency = %.2f\"%Avl)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain at lower cut off frequency = 28.28\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4, Page No. 312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# amplifier gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "f=50.0 # frequency in hertz\n",
+ "Avm=150/0.707 # mid voltage gain\n",
+ "fh=20.0 # lower cut off frequency in hertz\n",
+ "\n",
+ "#Calculations\n",
+ "Avh= (Avm/(math.sqrt(1+(f/fh)**2))) # gain at upper cut off frequency\n",
+ "\n",
+ "#Result\n",
+ "print(\"gain at upper cut off frequency = %.2f\"%(math.floor(Avh*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain at upper cut off frequency = 78.79\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5, Page No. 312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# maximum voltage gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Avl=100.0 # voltage gain\n",
+ "\n",
+ "#Calculations\n",
+ "Avm=Avl/0.707 # MID VOLTAGE GAIN\n",
+ "\n",
+ "#Result\n",
+ "print(\"maximum voltage gain is %.2f\"%Avm)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum voltage gain is 141.44\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6, Page No.319"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# series capacitance and transfer function\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "f=100.0 # frequency in hertz\n",
+ "fc=25.0 # corner frequency\n",
+ "rs=2.0 # series resistance in killo ohms\n",
+ "rp=4.0 # PARALLEL resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Cs= (1/(2*math.pi*fc*(rs+rp)*10**3))*10**6 # series capacitance in micro farad\n",
+ "ts= Cs*10**-6*(rs+rp)*10**3 # time constant\n",
+ "Tf= ((rp/(rs+rp))*((2*math.pi*f*ts)/(math.sqrt(1+(2*math.pi*f*ts)**2)))) # transfer function\n",
+ "\n",
+ "#Result\n",
+ "print(\"series capacitance in micro farad = %.2f\"%Cs)\n",
+ "print(\"transfer function is %.3f\"%(math.floor(Tf*1000)/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "series capacitance in micro farad = 1.06\n",
+ "transfer function is 0.646\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.7, Page No. 321"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# corner frequency and maximum magnitude asymptote\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cp=2.0 # PARALLEL RESISTANCE IN PICO FARAD\n",
+ "rs=2.0 # series resistance in killo ohms\n",
+ "rp=10.0 # PARALLEL resistance in killo ohms\n",
+ "\n",
+ "#Calculation\n",
+ "tp= ((rs*rp)/(rs+rp)*10**3*Cp*10**-12) # time constant\n",
+ "f= (1/(2*math.pi*tp))*10**-6 # corner frequency in mega hertz\n",
+ "Am= rp/(rp+rs) # maximum amplitude\n",
+ "Amd= 20*(math.log10(Am)) # maximum magnitude aymptote is dB\n",
+ "\n",
+ "#Result\n",
+ "print(\"corner frequency = %.2f MHz\"%(math.floor(f*100)/100))\n",
+ "print(\"maximum magnitude asymptote is %.2f dB\"%Amd)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "corner frequency = 47.74 MHz\n",
+ "maximum magnitude asymptote is -1.58 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.9, Page No. 330"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# 3-db frequency and bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cp=1.0 # PARALLEL capacitance IN PICO FARAD\n",
+ "Cs=2.0 # series capacitance IN micro FARAD\n",
+ "rs=1.0 # series resistance in killo ohms\n",
+ "rp=10.0 # PARALLEL resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "ts= ((rs+rp)*10**3*Cp*10**-12) # time constant\n",
+ "tp= ((rs*rp)/(rs+rp)*10**3*Cp*10**-12) # time constant\n",
+ "fl= (1/(2*math.pi*ts))*10**-6 # lower frequency in mega hertz\n",
+ "fl= math.floor(fl*100)/100\n",
+ "fh= round((1/(2*math.pi*tp))*10**-6) # upper frequency in mega hertz\n",
+ "BW=fh-fl # bandwidth in mega hertz\n",
+ "ts= (rs+rp)*10**3*Cp*10**-12 # open circuit time constant\n",
+ "tp= ((rs*rp)/(rs+rp))*10**3*Cp*10**-12 #short time constant\n",
+ "Ts= (rp)/(rs+rp) # midband transfer function\n",
+ "Tsdb= 20*(math.log10(Ts)) # midband transfer function in db\n",
+ "\n",
+ "#Result\n",
+ "print(\"(i) open circuit time constant is %.f * 10^-9\"%(ts*10**9))\n",
+ "print(\"(ii) short circuit time constant is %.f * 10^-12\"%(tp*10**12))\n",
+ "print(\"(iii)lower 3 dB frequency = %.2f MHz\"%fl)\n",
+ "print(\"(iv) upper 3 dB frequency = %f MHz\"%fh)\n",
+ "print(\"(v) Bandwidth = %.2f MHz\"%BW)\n",
+ "print(\"(vi) midband transfer function in db is %.3f\"%Tsdb)\n",
+ "#Short circuit time constant is different in book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) open circuit time constant is 11 * 10^-9\n",
+ "(ii) short circuit time constant is 909 * 10^-12\n",
+ "(iii)lower 3 dB frequency = 14.46 MHz\n",
+ "(iv) upper 3 dB frequency = 175.000000 MHz\n",
+ "(v) Bandwidth = 160.54 MHz\n",
+ "(vi) midband transfer function in db is -0.828\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.10, Page No. 331"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# 3-db frequency and bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cp=1.0 # PARALLEL capacitance IN PICO FARAD\n",
+ "Cs=2.0 # series capacitance IN micro FARAD\n",
+ "rs=1.0 # series resistance in killo ohms\n",
+ "rp=2.0 # PARALLEL resistance in killo ohms\n",
+ "ts= ((rs+rp)*10**3*Cs*10**-6) # time constant\n",
+ "tp= ((rs*rp)/(rs+rp)*Cp*10**-12) # time constant\n",
+ "tp1 = tp\n",
+ "fl= (1/(2*math.pi*ts)) # lower frequency in hertz\n",
+ "tp= math.floor(tp*10**14)/10**14\n",
+ "fh= (1/(2*math.pi*tp)) # upper frequency in hertz\n",
+ "BW=fh-fl # bandwidth in hertz\n",
+ "#ts= ((rs*rp)/(rs+rp))*10**-3*Cs*10**-12 # time constant\n",
+ "\n",
+ "#Result\n",
+ "print(\"Time constant(ts) in second is %.f * 10^-3\"%(ts*1000))\n",
+ "print(\"\\nTime constant(tp) in second is %.3f * 10^-12\"%(tp1*10**12))\n",
+ "print(\"\\nlower 3 dB frequency = %.f Hz\"%fl)\n",
+ "print(\"\\nupper 3 dB frequency = %.2f *10^9 Hz\"%(fh*10**-9))\n",
+ "print(\"\\nbandwidth = %.2f*10^9 Hz\"%(BW*10**-9))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time constant(ts) in second is 6 * 10^-3\n",
+ "\n",
+ "Time constant(tp) in second is 0.667 * 10^-12\n",
+ "\n",
+ "lower 3 dB frequency = 27 Hz\n",
+ "\n",
+ "upper 3 dB frequency = 241.14 *10^9 Hz\n",
+ "\n",
+ "bandwidth = 241.14*10^9 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.11, Page No. 336"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# low frequecy response\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta=100.0\n",
+ "Rs=1.0 # series resistance in killo ohms\n",
+ "R1=40.0 # resistance in killo ohms\n",
+ "R2=10.0 # resistance in killo ohms\n",
+ "hie=1.1 # in killo ohms\n",
+ "C1=10.0 # capacitance in micro farad\n",
+ "Ce=20.0 # emitter capacitance in micro farad\n",
+ "hic=1100.0 # in ohms\n",
+ "Rl_1=2.0 # resistance in killo ohms\n",
+ "Rl_2=1.8 # load resistance in killo ohms\n",
+ "Rc=4.0 # collector resistance in killo ohms\n",
+ "C2=1.0 # capacitance in micro farad\n",
+ "\n",
+ "\n",
+ "#Calcualtions\n",
+ "x=(R1*R2)/(R1+R2)\n",
+ "Y=(x*hie)/(x+hie)\n",
+ "Rin= math.floor((Y+Rs)*100)/100 \n",
+ "fc=(1/(2*math.pi*Rin*10**3*C1*10**-6)) \n",
+ "Rth=(x*Rs)/(x+Rs)*10**3 \n",
+ "Rx= (Rth+hic)/(Beta) \n",
+ "R= (Rx*Rl_1*10**3)/(Rx+Rl_1*10**3) \n",
+ "R = math.floor(R*100)/100\n",
+ "fc1=(1/(2*math.floor(math.pi*100)*R*Ce*10**-6/100)) \n",
+ "fc2=(1/(2*math.pi*(Rl_2+Rc)*10**3*C2*10**-6)) \n",
+ "\n",
+ "#Result\n",
+ "print(\"CUT OFF FREQUENCY OF INPUT RC NETWORK = %.2f Hz\"%fc)\n",
+ "print(\"CUT OFF FREQUENCY OF BYPASS RC NETWORK = %.2f Hz\"%fc1)\n",
+ "print(\"CUT OFF FREQUENCY OF OUTPUT RC NETWORK = %.2f Hz\"%(math.ceil(fc2*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "CUT OFF FREQUENCY OF INPUT RC NETWORK = 8.12 Hz\n",
+ "CUT OFF FREQUENCY OF BYPASS RC NETWORK = 404.36 Hz\n",
+ "CUT OFF FREQUENCY OF OUTPUT RC NETWORK = 27.45 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 60
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.12, Page No.346"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# corner frequency and maximum GAIN\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # Colector voltage in volts\n",
+ "Beta= 100.0 \n",
+ "Rc=1.0 # Collector resistance in killo ohms\n",
+ "Rs=600.0 # SERIES RESISTANCE IN OHMS\n",
+ "Re=0.2 # in kilo ohms\n",
+ "R1= 50.0 # in kilo ohms\n",
+ "R2= 10.0 # in kilo ohms\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "C1=1.0 # capacitance in micro farad\n",
+ "\n",
+ "\n",
+ "Vth=Vcc * (R2/(R1+R2)) # VOLTAGE AT BASE\n",
+ "Rth= (R1*R2)/(R1+R2)\n",
+ "Ib=((Vcc-Vbe)/((Rth+(1+Beta)*Re)*10**3))*10**5 # in micro ampere\n",
+ "Icq= Beta*Ib*10**-3 # in milli ampere\n",
+ "Vt=26.0 # volate at room termprature in milli volts\n",
+ "gm= (Icq/Vt)*10**3 # transconductance in milli ampere per volts\n",
+ "rpi= (Beta*Vt*10**-3)/(Icq*10**-3) # resistance\n",
+ "Rb=math.floor(Rth*100)/100 # base resistance in killo ohms\n",
+ "\n",
+ "x=(rpi+(1+Beta)*Re*10**3) \n",
+ "y=(Rs+Rb*10**3) \n",
+ "ts=((x*y)/(x+y))*C1*10**-3 # in milli second\n",
+ "fl= (1/(2*math.pi*ts*10**-3)) # corner frequency in hertz\n",
+ "Ri=(x*Rb*10**-3)/(Rb+x*10**-3) \n",
+ "Av= ((gm*10**-3*rpi*Rc*10**3)*Rb*10**3)/((Ri+Rs*10**-3)*10**3*(x*10**-3+Rb)*10**3) \n",
+ "\n",
+ "#Result\n",
+ "print(rpi)\n",
+ "print(\"corner frequency = %.2f Hz\"%fl)\n",
+ "print(\"maximum gain = %.2f\"%Av)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "797.70609319\n",
+ "corner frequency = 25.40 Hz\n",
+ "maximum gain = 4.33\n"
+ ]
+ }
+ ],
+ "prompt_number": 68
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.13, Page No. 348"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print(\"Theoretical example\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Theoretical example\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.14, Page No. 349"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print(\"Theoretical example\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Theoretical example\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.15, Page No. 349"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print(\"Theoretical example\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Theoretical example\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.16, Page No. 350"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# TIME CONSTANTS , MIDBAND VOLTAGE GAIN AND COERNER FREQUENCIES\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rl=4.0 # load resistance in killo ohms\n",
+ "Rs=250.0 # SERIES RESISTANCE IN OHMS\n",
+ "rpi= 2.0 # resistance IN KILLO OHMS\n",
+ "Re=0.2 # in kilo ohms\n",
+ "C1=2 # capacitance in micro farad\n",
+ "Cl=50.0 # capacitance in pico farad\n",
+ "gm= 6.5 # transconductance in milli ampere per volts\n",
+ "\n",
+ "\n",
+ "#Calcualtions\n",
+ "ts=(Rs*10**-3+rpi)*10**3*C1*10**-3 # open circuit time constant in milli second\n",
+ "tp=Rl*Cl*10**-3 # short circuit time constant in micro second\n",
+ "Av= (((gm*10**-3*rpi*10**3*Rl*10**3))/(Rs*10**-3+rpi)*10**3)*10**-5\n",
+ "fl=(1/(2*math.pi*ts*10**-3)) # lower cut off frequency in hertz\n",
+ "fh=(1/(2*math.pi*tp*10**-6))*10**-6#upper cut off frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"open circuit time constant = %.1f ms\"%ts)\n",
+ "print(\"short circuit time constant= %.1f micro-sec\"%tp)\n",
+ "print(\"maximum gain = %.2f\"%Av)\n",
+ "print(\"lower cut off frequency = %.2f Hz\"%(math.floor(fl*100)/100))\n",
+ "print(\"upper cut off frequency = %.4f Hz\"%(math.floor(fh*10000)/10000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "open circuit time constant = 4.5 ms\n",
+ "short circuit time constant= 0.2 micro-sec\n",
+ "maximum gain = 231.11\n",
+ "lower cut off frequency = 35.36 Hz\n",
+ "upper cut off frequency = 0.7957 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.17, Page No. 552"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# frequency response\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rg=10.0 # resistance in mega ohms\n",
+ "Vgs=10.0 # gate to soure voltage\n",
+ "Igss=10.0 # current in nano ampere\n",
+ "C1=0.001 # capacitance in micro farad\n",
+ "Rd=1.8 # drain resistance in killo ohms\n",
+ "Rl=18.0 # load resistance in killo ohms\n",
+ "C2=1.0 # Capacitance in micro farad\n",
+ "\n",
+ "#Calculations\n",
+ "x= (Vgs/Igss)*1000.0 # resistance in mega ohms\n",
+ "Rin= ((Rg*x)/(Rg+x)) # input resistance in mega ohms\n",
+ "fc= (1/(2*math.pi*Rin*10**6*C1*10**-6)) # input critical frequency of the RC network\n",
+ "fc1=(1/(2*math.pi*(Rd+Rl)*10**3*C2*10**-6))# output critical frequency of the RC network\n",
+ "\n",
+ "#Result\n",
+ "print(\"input critical frequency of the RC network = %.2f Hz\"%(math.ceil(fc*100)/100))\n",
+ "print(\"input critical frequency of the RC network = %.2f Hz\"%fc1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "input critical frequency of the RC network = 16.08 Hz\n",
+ "input critical frequency of the RC network = 8.04 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.18, Page No. 556"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "rpi=2.0 # resistance in killo ohms\n",
+ "Cpi=1.8 # capacitance in pico farad\n",
+ "Cmu=0.12 # capacitance in pico farad\n",
+ "\n",
+ "#Calculations\n",
+ "fb=(1/(2*math.pi*rpi*10**3*(Cpi+Cmu)*10**-6))# frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"frequency = %.3f MHz\"%(math.floor(fb*1000)/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "frequency = 41.446 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.19, Page No.558"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# bandwidth and capacitance\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vt=26.0 # voltage in milli volts\n",
+ "ft=500.0 # frequecy in mega hertz\n",
+ "Ic=1.0 # collector current in mili ampere\n",
+ "Bo=90.0\n",
+ "Cmu=0.2 # capacitance in pico farad\n",
+ "\n",
+ "#Calculations\n",
+ "fb=ft/Bo # frequency in mega hertz\n",
+ "x= ((Ic*10**-3)/(2*math.pi*Vt*10**-3*ft*10**6))*10**12\n",
+ "Cpi= x-Cmu\n",
+ "\n",
+ "#Result\n",
+ "print(\"Bandwidth = %.2f MHz\"%(math.floor(fb*100)/100))\n",
+ "print(\"Capacitance of the transistor = %.3f pF\"%(math.floor(Cpi*1000)/1000))\n",
+ "#Answer for bandwidth is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bandwidth = 5.55 MHz\n",
+ "Capacitance of the transistor = 12.042 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.20, Page No.360"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# corner frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=1.0 # series resistance in killo ohms\n",
+ "Rl=3.7 # load resistance in killo ohms\n",
+ "Rc=3.7 # Collector resistance in killo ohms\n",
+ "R1= 200.0 # in kilo ohms\n",
+ "R2= 200.0 # in kilo ohms\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "rpi=2.5 # resistance in killo ohms\n",
+ "Cpi=0.18 # capacitance in pico farad\n",
+ "gm=40.0 # transconductance in milli ampere per volts\n",
+ "C1=4.0 # capacitance in pico farad\n",
+ "\n",
+ "\n",
+ "#Calcualtions\n",
+ "Rb= (R1*R2)/(R1+R2) \n",
+ "y=(Rc*Rl)/(Rc+Rl) \n",
+ "Cmu= Cpi*(1+gm*y) \n",
+ "Cm2=Cmu \n",
+ "z=(Rs*rpi)/(Rs+rpi) \n",
+ "R=(Rb*z)/(Rb+z) \n",
+ "C=Cmu+4 \n",
+ "f3db= (1/(2*math.pi*R*10**3*C))*10**6 # 3-dB frequency in mega hertz\n",
+ "f3db1= (1/(2*math.pi*R*10**3*C1))*10**6 # 3-dB frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"3-dB frequency due to miller effect = %.3f MHz\"%f3db)\n",
+ "print(\"3-dB frequency = %.1f MHz\"%f3db1)\n",
+ "print(\"\\nDue to miller effect the capacitance gets multiplied by 75,\")\n",
+ "print(\"hence due to miller effect the bandwidth is reduced.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3-dB frequency due to miller effect = 12.823 MHz\n",
+ "3-dB frequency = 56.1 MHz\n",
+ "\n",
+ "Due to miller effect the capacitance gets multiplied by 75,\n",
+ "hence due to miller effect the bandwidth is reduced.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.21, Page No. 367"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# mid band gain and upper 3 db frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cpi=40.0 # in pico farad\n",
+ "Vt=26.0 # voltage in milli volts\n",
+ "Beta=150.0\n",
+ "Icc=1.0 # current in milli ampere\n",
+ "Icq=1.0 # current in milli ampere\n",
+ "Rc=4.7 # collector resistance in killo ohms\n",
+ "Rl=10.0 # load resistance in killo ohms\n",
+ "Cmu=3.0 # capacitance in pico farad\n",
+ "R1= 50.0 # in kilo ohms\n",
+ "R2= 5.0 # in kilo ohms\n",
+ "rs=1.0 # in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "rpi= ((Beta*Vt)/Icc)*10**-3\n",
+ "gm=(Icq/Vt)*10**3 # transconductance in mili ampere per volt\n",
+ "gm = math.floor(gm*100)/100\n",
+ "Rld= (Rc*Rl)/(Rc+Rl) \n",
+ "Rld = math.floor(Rld*1000)/1000\n",
+ "Cm=round(Cmu*(1+gm*Rld)) #miller capacitance in pico farad\n",
+ "Rb= (R1*R2)/(R1+R2)\n",
+ "Rb = math.floor(Rb*1000)/1000\n",
+ "x=(Rb*rs)/(Rb+rs) \n",
+ "y=(rpi*x)/(rpi+x)\n",
+ "y = math.ceil(y*10**4)/10**4\n",
+ "fh=(1/(2*math.pi*y*10**3*(Cm+Cpi)*10**-12)) # 3-db upper cut off frequency in mega hertz\n",
+ "z=(Rb*rpi)/(Rb+rpi) \n",
+ "Avm=(gm*Rld*z)/(z+rs)\n",
+ "\n",
+ "#Result\n",
+ "print(\"3-db upper cut off frequency = %.3f MHz\"%(fh*10**-6))\n",
+ "print(\"Midband Gain = %.2f\"%Avm)\n",
+ "#Value of Fh is wrong in the book\n",
+ "#wrong value of gm is used for Avm calculation"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3-db upper cut off frequency = 0.570 MHz\n",
+ "Midband Gain = 83.28\n"
+ ]
+ }
+ ],
+ "prompt_number": 64
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.22, Page No.370"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# mid band gain and upper 3 db frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cpi=40.0 # in pico farad\n",
+ "Vt=26.0 # voltage in milli volts\n",
+ "Beta=150.0\n",
+ "Icq=1.0 # current in milli ampere\n",
+ "rs=1.0 # in killo ohms\n",
+ "re=0.5 # in killo ohms\n",
+ "Rc=4.7 # collector resistance in killo ohms\n",
+ "Rl=10.0 # load resistance in killo ohms\n",
+ "Cmu=3.0 # capacitance in pico farad\n",
+ "R1= 50.0 # in kilo ohms\n",
+ "R2= 5.0 # in kilo ohms\n",
+ "\n",
+ "#Calcualtions\n",
+ "rpi= ((Beta*Vt)/Icq)*10**-3 \n",
+ "gm=(Icq/Vt)*10**3 # transconductance in mili ampere per volt\n",
+ "gm = math.floor(gm*100)/100\n",
+ "g=(rs*re)/(rs+re) \n",
+ "m=rpi/(1+Beta) \n",
+ "m = math.floor(m*10000)/10000\n",
+ "tpi= ((m*g)/(m+g))*10**3*Cpi*10**-12 \n",
+ "tpi = math.floor(tpi*10**14)/10**14\n",
+ "fh1=(1/(2*math.pi*tpi))/10**6 # first 3-db upper cut off frequency in mega hertz\n",
+ "fh1 = (math.floor(fh1*1000)/1000)\n",
+ "Rld= (Rc*Rl)/(Rc+Rl) \n",
+ "Rb= (R1*R2)/(R1+R2)\n",
+ "fh2=(1/(2*math.pi*Cmu*10**-8*Rld*10**3))*10**-2 # second 3-db upper cut off frequency in mega hertz\n",
+ "x=(m*re)/(m+re)\n",
+ "Avm=(gm*Rld*x)/(x+rs) \n",
+ "\n",
+ "#Result\n",
+ "print(\"3-db upper cut off frequency = %.3f MHz\"%fh1)\n",
+ "print(\"second 3-db upper cut off frequency= %.4f MHz\"%fh2)\n",
+ "print(\"Midband Gain = %.4f\"%Avm)\n",
+ "# Value for fh2 and Avm slightly differs from the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3-db upper cut off frequency = 166.156 MHz\n",
+ "second 3-db upper cut off frequency= 16.5927 MHz\n",
+ "Midband Gain = 2.9446\n"
+ ]
+ }
+ ],
+ "prompt_number": 89
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.23, Page No.375"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# mid band gain and upper 3 db frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cmu=3.0 # capacitance in pico farad\n",
+ "Cpi=40.0 # in pico farad\n",
+ "Vt=26.0 # voltage in milli volts\n",
+ "Beta=150.0 \n",
+ "Icq=1.0 # current in milli ampere\n",
+ "rs=1.0 # in killo ohms\n",
+ "re=4.7 # in killo ohms\n",
+ "R1= 40.0 # in kilo ohms\n",
+ "R2= 20.0 # in kilo ohms\n",
+ "R3= 27.0 # in kilo ohms\n",
+ "Rc=4.7 # collector resistance in killo ohms\n",
+ "Rl=10.0 # load resistance in killo ohms\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "rpi= ((Beta*Vt)/Icq)*10**-3\n",
+ "gm=(Icq/Vt)*10**3 # transconductance in mili ampere per volt\n",
+ "gm = math.floor(gm*100)/100\n",
+ "Rb=(R2*R3)/(R2+R3)\n",
+ "g=(rs*rpi)/(rs+rpi) \n",
+ "tp1=(((Rb*g)*(Cpi+2*Cmu))/(Rb+g))*10**-9 \n",
+ "m=rpi/(1+Beta) \n",
+ "tp2= m*(Cmu+Cpi)*10**-9 \n",
+ "Rld= (Rc*Rl)/(Rc+Rl) \n",
+ "tp3=Cmu*10**-12*Rld*10**3 \n",
+ "fh1=(1/(2*math.pi*tp1*10**6)) # first 3-db upper cut off frequency in mega hertz\n",
+ "fh2=(1/(2*math.pi*tp2*10**6)) # second 3-db upper cut off frequency in mega hertz\n",
+ "fh3=(1/(2*math.pi*tp3*10**6)) # third 3-db upper cut off frequency in mega hertz\n",
+ "Avm= -gm*Rld*(rpi/(rpi+1)) \n",
+ "\n",
+ "#Result\n",
+ "print(\"3-db upper cut off frequency = %.3f MHz\"%fh1)\n",
+ "print(\"second 3-db upper cut off frequency = %.2f MHz\"%fh2)\n",
+ "print(\"third 3-db upper cut off frequency = %.3f MHz\"%fh3)\n",
+ "print(\"Midband Gain = %.2f\"%Avm)\n",
+ "# Value for fh2 and fh3 slightly differs from the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3-db upper cut off frequency = 4.648 MHz\n",
+ "second 3-db upper cut off frequency = 143.31 MHz\n",
+ "third 3-db upper cut off frequency = 16.593 MHz\n",
+ "Midband Gain = -97.87\n"
+ ]
+ }
+ ],
+ "prompt_number": 95
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.24, Page No.383"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# corner frequency and bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "tr=16.0 # rise time in micro second\n",
+ "V=100.0 # voltage in milli volts\n",
+ "Vd=90.0 # voltage in milli volts\n",
+ "f=5.0 # frequecny in killo hertz\n",
+ "\n",
+ "#Calculations\n",
+ "fh= (0.35/(tr*10**-6))*10**-3 # upper cut off frequency in killo hertz\n",
+ "P= ((V-Vd)/V)*100 \n",
+ "fl=(P*10**3*f)/(100*math.pi) # lower cut off frequency in hertz\n",
+ "BW=(fh*10**3-fl)*10**-3 # bandwith in killo hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"upper cut off frequency = %.3f kHz\"%fh)\n",
+ "print(\"lower cut off frequency = %.2f Hz\"%fl)\n",
+ "print(\"Bandwidth = %.3f kHz\"%(math.floor(BW*1000)/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "upper cut off frequency = 21.875 kHz\n",
+ "lower cut off frequency = 159.15 Hz\n",
+ "Bandwidth = 21.715 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 100
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.25, Page No.384"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# PERCENTAGE TILT\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rc=4.0 # RESISTANCE IN KILLO OHMS\n",
+ "Rl=2.0 # RESISTANCE IN KILLO OHMS\n",
+ "C=10.0 # capacitance in micro farad\n",
+ "f=200.0 # frequency in hertz\n",
+ "\n",
+ "#Calculations\n",
+ "R1=Rc+Rl \n",
+ "fl=(1/(2*math.pi*R1*10**3*C*10**-6))# LOWER CUT -OFF FREQUENCY\n",
+ "P = (math.pi*fl*100)/f # % tilt\n",
+ "\n",
+ "#Result\n",
+ "print(\"percentage tilt = %.1f%%\"%(math.floor(P*10)/10))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "percentage tilt = 4.1%\n"
+ ]
+ }
+ ],
+ "prompt_number": 102
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.26, Page No. 385"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# PERCENTAGE TILT\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rc=2.0 # RESISTANCE IN KILLO OHMS\n",
+ "Rl=10.0 # RESISTANCE IN KILLO OHMS\n",
+ "C=10.0 # capacitance in micro farad\n",
+ "f=100.0 # frequency in hertz\n",
+ "p1=0.02\n",
+ "\n",
+ "#Calculations\n",
+ "R1=Rc+Rl\n",
+ "fl=(1/(2*math.pi*R1*10**3*C*10**-6))#LOWER CUT -OFF FREQUENCY\n",
+ "fl= math.floor(fl*100)/100\n",
+ "P= (math.floor(math.pi*100)*fl)/(f*100) \n",
+ "f=(math.floor(math.pi*100)*fl)/(p1*100) \n",
+ "\n",
+ "#Result\n",
+ "print(\"percentage tilt = %.3f%%\"%(P*100))\n",
+ "print(\"Lowest value of f for P= 2%%, will be= %.2f Hz\"%f)\n",
+ "print(\"\\nConclusion:\\nAs the input frequency increases the %% tilt decreases.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "percentage tilt = 4.145%\n",
+ "Lowest value of f for P= 2%, will be= 207.24 Hz\n",
+ "\n",
+ "Conclusion:\n",
+ "As the input frequency increases the %% tilt decreases.\n"
+ ]
+ }
+ ],
+ "prompt_number": 120
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.27, Page No. 389"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# fh,fl and bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fln=25.0 # in hertz\n",
+ "fhn=16.0 # in kelo hertz\n",
+ "n=3.0\n",
+ "\n",
+ "#Calcualtions\n",
+ "x=math.sqrt(2**(1/n)-1) \n",
+ "fl=x*fln # lower cut off frequency in hertz\n",
+ "fh=fhn/x # upper cut off frequency in hertz\n",
+ "BW=(fh*10**3)-fl # bandwidth\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"lower cut off frequency = %.2f Hz\"%(math.floor(fl*100)/100))\n",
+ "print(\"upper cut off frequency = %.2f kHz\"%fh)\n",
+ "print(\"Bandwidth = %.2f kHz\"%(BW/1000))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "lower cut off frequency = 12.74 Hz\n",
+ "upper cut off frequency = 31.38 kHz\n",
+ "Bandwidth = 31.37 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 123
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.28, Page No. 390"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fl=40.0 # in hertz\n",
+ "fh=20.0 # in kelo hertz\n",
+ "n=4.0\n",
+ "\n",
+ "#Calculations\n",
+ "x=math.sqrt(2**(1/n)-1) \n",
+ "fhn=x*fh # lower cut off frequency in hertz\n",
+ "fln=fl/x # upper cut off frequency in hertz\n",
+ "BW=fhn-fln*10**-3 # bandwidth\n",
+ "\n",
+ "#Result\n",
+ "print(\"lower cut off frequency = %.2f Hz\"%(math.floor(fln*100)/100))\n",
+ "print(\"upper cut off frequency = %.1f kHz\"%fhn)\n",
+ "print(\"Bandwidth = %.1f kHz\"%BW) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "lower cut off frequency = 91.95 Hz\n",
+ "upper cut off frequency = 8.7 kHz\n",
+ "Bandwidth = 8.6 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 128
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.29, Page No. 390"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# cut off frequencies\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fln = 20 # in Hz\n",
+ "fhn=100.0 # in kelo hertz\n",
+ "n=3.0\n",
+ "\n",
+ "#Calculations\n",
+ "x=math.sqrt(2**(1/n)-1) \n",
+ "fl=fln*x # lower cut off frequency in hertz\n",
+ "fh=fhn/x # upper cut off frequency in hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"lower cut off frequency = %.2f Hz\"%(math.floor(fl*100)/100))\n",
+ "print(\"upper cut off frequency = %.2f KHz\"%(math.floor(fh*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "lower cut off frequency = 10.19 Hz\n",
+ "upper cut off frequency = 196.14 KHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 145
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.30, Page No. 391"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Avm,Fh,Cc\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "mu=70.0 \n",
+ "rd=44.0 # resistance in killo ohms\n",
+ "Rd2=50.0 # resistance in killo ohms\n",
+ "Rg=1.0 # gate resisatnce in mega ohms\n",
+ "Csh=200 # capacitance in pico farad\n",
+ "fl=50.0\n",
+ "\n",
+ "#Calculations\n",
+ "gm= mu/(rd) # transconductane in milli ampere per volt\n",
+ "gm = math.ceil(gm*10)/10\n",
+ "x=(rd*Rd2)/(rd+Rd2) \n",
+ "x = math.floor(x*10)/10\n",
+ "Av2m= gm*x # mid frequency gain of second stage\n",
+ "y= (x*Rg*10**3)/(x+Rg*10**3)\n",
+ "Av1m= -gm*y # mid frequency gain of first stage\n",
+ "Av= Av1m*Av2m # total gain\n",
+ "Req=y\n",
+ "fh=(1/(2*math.pi*Req*10**3*Csh*10**-9)) # upper cut off frequency in killo hertz\n",
+ "Ro1=x\n",
+ "Cc=(1/(2*math.pi*fl*(Ro1*10**3+Rg*10**6)))*10**9 # coupling capacitance in nano farad\n",
+ "\n",
+ "#Result\n",
+ "print(x)\n",
+ "print(\"mid frequency gain of second stage = %.2f\"%Av2m)\n",
+ "print(\"upper cut off frequency = %.2f kHz\"%(math.ceil(fh*100)/100))\n",
+ "print(\"coupling capacitance = %.2f nF\"%Cc)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23.4\n",
+ "mid frequency gain of second stage = 37.44\n",
+ "upper cut off frequency = 34.81 kHz\n",
+ "coupling capacitance = 3.11 nF\n"
+ ]
+ }
+ ],
+ "prompt_number": 152
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.31, Page No. 392"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "gm= 10.0 # transconductane in milli ampere per volt\n",
+ "Csh=20.0 # capacitance in pico farad\n",
+ "BW=10.0 # bandwidth in mega hertz\n",
+ "fhn=10.0 # in mega hertz\n",
+ "n=2.0\n",
+ "\n",
+ "#Calculations\n",
+ "x=math.sqrt(2**(1/n)-1)\n",
+ "fh=fhn/x # lower cut off frequency in mega hertz\n",
+ "R=(1/(2*math.pi*Csh*10**-12*fh*10**6)) # resiatnce in ohms\n",
+ "Av1=-gm*R*10**-3 # mid frequency gain of first stage\n",
+ "Av2=Av1 # mid frequency gain of second stage\n",
+ "Av= Av1*Av2 # total gain\n",
+ "Avdb=20*(math.log10(Av)) # total gain dB\n",
+ "\n",
+ "#Result\n",
+ "print(\"Total gain = %.2f dB\"%(math.floor(Avdb*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total gain = 28.37 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 155
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.32, Page No. 393"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Avm,Fh,Fl\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "n=2.0\n",
+ "C=50.0 # in micro farad\n",
+ "Cc=0.1 # in micro farad\n",
+ "rd=50.0 # resistance\n",
+ "Rs=1.0 # series resistance in killo ohmstance in killo ohms\n",
+ "gm= 2.0 # transconductane in milli ampere per volt\n",
+ "Rd=10.0 # resistance in killo ohms\n",
+ "Csh=10.0 # capacitance in pico farad\n",
+ "\n",
+ "#Calculations\n",
+ "x=(rd*Rd)/(rd+Rd) \n",
+ " \n",
+ "Rg=1.0 # gate resisatnce in mega ohms\n",
+ "y= (x*Rg*10**3)/(x+Rg*10**3) \n",
+ "Avm= -gm*y # mid frequency gain of first stage\n",
+ "Av2m= -gm*y # mid frequency gain of second stage\n",
+ "Avm = math.ceil(Avm*100)/100\n",
+ "Av= Avm*Av2m # total gain\n",
+ "Avdb=20*(math.log10(Av))\n",
+ "Req=y\n",
+ "fh=(1/(2*math.pi*Req*10**3*Csh*10**-6))# upper cut off frequency in mega hertz\n",
+ "Ro1=y\n",
+ "fl=(1/(2*math.pi*Cc*10**-6*Ro1*10**3)) # lower cut off frequency in hertz\n",
+ "x=math.sqrt(2**(1/n)-1)\n",
+ "fhn=x*fh # lower cut off frequency in hertz\n",
+ "fln=fl/x # upper cut off frequency in hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"Total voltage gain = %.2f dB\"%(math.floor(Avdb*100)/100))\n",
+ "print(\"lower cut off frequency = %.2f Hz\"%fl)\n",
+ "print(\"upper cut off frequency = %.4f MHz\"%fh)\n",
+ "print(\"3dB lower cut off frequency = %.2f Hz\"%fln)\n",
+ "print(\"3dB upper cut off frequency = %.2f MHz\"%fhn)\n",
+ "# Values are slightly different than that of book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total voltage gain = 48.72 dB\n",
+ "lower cut off frequency = 192.58 Hz\n",
+ "upper cut off frequency = 1.9258 MHz\n",
+ "3dB lower cut off frequency = 299.22 Hz\n",
+ "3dB upper cut off frequency = 1.24 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 171
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.33, Page No.393"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Avm,Fh,Fl\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "n=3.0\n",
+ "Cc=0.005 # in micro farad\n",
+ "C=100.0 # in pico farad\n",
+ "rd=7.7\n",
+ "Rs=1.0 # series resistance in killo ohmstance in killo ohms\n",
+ "gm= 25.0 # transconductane in milli ampere per volt\n",
+ "Rd=10.0 # resistance in killo ohms\n",
+ "Rg=1.0 # gate resisatnce in mega ohms\n",
+ "Csh=100.0 # capacitance in pico farad\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "x=(rd*Rd)/(rd+Rd) \n",
+ "Av2m= -gm*x # mid frequency gain of second stage\n",
+ "y= (x*Rg*10**3)/(x+Rg*10**3) \n",
+ "Avm= -gm*y # mid frequency gain of first stage\n",
+ "Av= Avm*Avm*Avm # total gain\n",
+ "Avdb=20*(math.log10(-Av)) \n",
+ "Req=y \n",
+ "fh=(1/(2*math.pi*Req*10**3*Csh*10**-9)) # upper cut off frequency in killo hertz\n",
+ "Ro1=y\n",
+ "fl=(1/(2*math.pi*Cc*10**-6*(Ro1*10**3+Rg*10**6))) # lower cut off frequency in hertz\n",
+ "x=math.sqrt(2**(1/n)-1)\n",
+ "fhn=x*fh # lower cut off frequency in hertz\n",
+ "fln=fl/x # upper cut off frequency in hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"Total voltage gain = %.f dB\"%math.ceil(Avdb))\n",
+ "print(\"lower cut off frequency = %.3f Hz\"%(math.floor(fl*1000)/1000))\n",
+ "print(\"upper cut off frequency = %.2f kHz\"%fh)\n",
+ "print(\"3dB lower cut off frequency = %.3f Hz\"%(math.floor(fln*1000)/1000))\n",
+ "print(\"3dB upper cut off frequency = %.1f kHz\"%fhn)\n",
+ "# Some values are slightly different than that of book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total voltage gain = 123 dB\n",
+ "lower cut off frequency = 31.693 Hz\n",
+ "upper cut off frequency = 367.44 kHz\n",
+ "3dB lower cut off frequency = 62.165 Hz\n",
+ "3dB upper cut off frequency = 187.3 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 180
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_5_1.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_5_1.ipynb
new file mode 100755
index 00000000..e37d35ce
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_5_1.ipynb
@@ -0,0 +1,1598 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5 : Frequency Response"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.1, Page No. 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#COUPLING CAPACITOR\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=10.0 # series resistance in killo ohms\n",
+ "Xc1= Rs/10.0 # reactance at 20Hz\n",
+ "\n",
+ "#Calcualtions\n",
+ "C1=(1.0/(2*math.pi*20*Xc1*10**3))*10**6 # CAPACITANCE IN MICRO FARAD\n",
+ "\n",
+ "#Result\n",
+ "print(\"Capacitance = %.3f micro Farad.\\nAs this is not a standard value will select 10 micro farad\"%(math.floor(C1*1000)/1000))\n",
+ "#Answer is slightly different than in book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacitance = 7.957 micro Farad.\n",
+ "As this is not a standard value will select 10 micro farad\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2, Page No. 311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# amplifier gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "f=20.0 # frequency in hertz\n",
+ "Avm=100.0 # mid voltage gain\n",
+ "fl=40.0 # lower cut off frequency in hertz\n",
+ "fh=16.0 # lower cut off frequency in hertz\n",
+ "\n",
+ "#Calcualtions\n",
+ "Avl= (Avm/(math.sqrt(1+(fl/f)**2))) # gain at lower cut off frequency\n",
+ "Avh= (Avm/(math.sqrt(1+(f/fh)**2))) # gain at upper cut off frequency\n",
+ "\n",
+ "#Result\n",
+ "print(\"gain at lower cut off frequency = %.2f\"%Avl)\n",
+ "print(\"gain at upper cut off frequency = %.2f\"%Avh)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain at lower cut off frequency = 44.72\n",
+ "gain at upper cut off frequency = 62.47\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.3, Page No. 312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# amplifier gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "f=40.0 # frequency in hertz\n",
+ "Avm=40.0 # mid voltage gain\n",
+ "fl=40.0 # lower cut off frequency in hertz\n",
+ "\n",
+ "#Calculations\n",
+ "Avl= (Avm/(math.sqrt(1+(fl/f)**2))) # gain at lower cut off frequency\n",
+ "\n",
+ "#Result\n",
+ "print(\"gain at lower cut off frequency = %.2f\"%Avl)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain at lower cut off frequency = 28.28\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.4, Page No. 312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# amplifier gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "f=50.0 # frequency in hertz\n",
+ "Avm=150/0.707 # mid voltage gain\n",
+ "fh=20.0 # lower cut off frequency in hertz\n",
+ "\n",
+ "#Calculations\n",
+ "Avh= (Avm/(math.sqrt(1+(f/fh)**2))) # gain at upper cut off frequency\n",
+ "\n",
+ "#Result\n",
+ "print(\"gain at upper cut off frequency = %.2f\"%(math.floor(Avh*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain at upper cut off frequency = 78.79\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.5, Page No. 312"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# maximum voltage gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Avl=100.0 # voltage gain\n",
+ "\n",
+ "#Calculations\n",
+ "Avm=Avl/0.707 # MID VOLTAGE GAIN\n",
+ "\n",
+ "#Result\n",
+ "print(\"maximum voltage gain is %.2f\"%Avm)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum voltage gain is 141.44\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.6, Page No.319"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# series capacitance and transfer function\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "f=100.0 # frequency in hertz\n",
+ "fc=25.0 # corner frequency\n",
+ "rs=2.0 # series resistance in killo ohms\n",
+ "rp=4.0 # PARALLEL resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Cs= (1/(2*math.pi*fc*(rs+rp)*10**3))*10**6 # series capacitance in micro farad\n",
+ "ts= Cs*10**-6*(rs+rp)*10**3 # time constant\n",
+ "Tf= ((rp/(rs+rp))*((2*math.pi*f*ts)/(math.sqrt(1+(2*math.pi*f*ts)**2)))) # transfer function\n",
+ "\n",
+ "#Result\n",
+ "print(\"series capacitance in micro farad = %.2f\"%Cs)\n",
+ "print(\"transfer function is %.3f\"%(math.floor(Tf*1000)/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "series capacitance in micro farad = 1.06\n",
+ "transfer function is 0.646\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.7, Page No. 321"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# corner frequency and maximum magnitude asymptote\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cp=2.0 # PARALLEL RESISTANCE IN PICO FARAD\n",
+ "rs=2.0 # series resistance in killo ohms\n",
+ "rp=10.0 # PARALLEL resistance in killo ohms\n",
+ "\n",
+ "#Calculation\n",
+ "tp= ((rs*rp)/(rs+rp)*10**3*Cp*10**-12) # time constant\n",
+ "f= (1/(2*math.pi*tp))*10**-6 # corner frequency in mega hertz\n",
+ "Am= rp/(rp+rs) # maximum amplitude\n",
+ "Amd= 20*(math.log10(Am)) # maximum magnitude aymptote is dB\n",
+ "\n",
+ "#Result\n",
+ "print(\"corner frequency = %.2f MHz\"%(math.floor(f*100)/100))\n",
+ "print(\"maximum magnitude asymptote is %.2f dB\"%Amd)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "corner frequency = 47.74 MHz\n",
+ "maximum magnitude asymptote is -1.58 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.9, Page No. 330"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# 3-db frequency and bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cp=1.0 # PARALLEL capacitance IN PICO FARAD\n",
+ "Cs=2.0 # series capacitance IN micro FARAD\n",
+ "rs=1.0 # series resistance in killo ohms\n",
+ "rp=10.0 # PARALLEL resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "ts= ((rs+rp)*10**3*Cp*10**-12) # time constant\n",
+ "tp= ((rs*rp)/(rs+rp)*10**3*Cp*10**-12) # time constant\n",
+ "fl= (1/(2*math.pi*ts))*10**-6 # lower frequency in mega hertz\n",
+ "fl= math.floor(fl*100)/100\n",
+ "fh= round((1/(2*math.pi*tp))*10**-6) # upper frequency in mega hertz\n",
+ "BW=fh-fl # bandwidth in mega hertz\n",
+ "ts= (rs+rp)*10**3*Cp*10**-12 # open circuit time constant\n",
+ "tp= ((rs*rp)/(rs+rp))*10**3*Cp*10**-12 #short time constant\n",
+ "Ts= (rp)/(rs+rp) # midband transfer function\n",
+ "Tsdb= 20*(math.log10(Ts)) # midband transfer function in db\n",
+ "\n",
+ "#Result\n",
+ "print(\"(i) open circuit time constant is %.f * 10^-9\"%(ts*10**9))\n",
+ "print(\"(ii) short circuit time constant is %.f * 10^-12\"%(tp*10**12))\n",
+ "print(\"(iii)lower 3 dB frequency = %.2f MHz\"%fl)\n",
+ "print(\"(iv) upper 3 dB frequency = %f MHz\"%fh)\n",
+ "print(\"(v) Bandwidth = %.2f MHz\"%BW)\n",
+ "print(\"(vi) midband transfer function in db is %.3f\"%Tsdb)\n",
+ "#Short circuit time constant is different in book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) open circuit time constant is 11 * 10^-9\n",
+ "(ii) short circuit time constant is 909 * 10^-12\n",
+ "(iii)lower 3 dB frequency = 14.46 MHz\n",
+ "(iv) upper 3 dB frequency = 175.000000 MHz\n",
+ "(v) Bandwidth = 160.54 MHz\n",
+ "(vi) midband transfer function in db is -0.828\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.10, Page No. 331"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# 3-db frequency and bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cp=1.0 # PARALLEL capacitance IN PICO FARAD\n",
+ "Cs=2.0 # series capacitance IN micro FARAD\n",
+ "rs=1.0 # series resistance in killo ohms\n",
+ "rp=2.0 # PARALLEL resistance in killo ohms\n",
+ "ts= ((rs+rp)*10**3*Cs*10**-6) # time constant\n",
+ "tp= ((rs*rp)/(rs+rp)*Cp*10**-12) # time constant\n",
+ "tp1 = tp\n",
+ "fl= (1/(2*math.pi*ts)) # lower frequency in hertz\n",
+ "tp= math.floor(tp*10**14)/10**14\n",
+ "fh= (1/(2*math.pi*tp)) # upper frequency in hertz\n",
+ "BW=fh-fl # bandwidth in hertz\n",
+ "#ts= ((rs*rp)/(rs+rp))*10**-3*Cs*10**-12 # time constant\n",
+ "\n",
+ "#Result\n",
+ "print(\"Time constant(ts) in second is %.f * 10^-3\"%(ts*1000))\n",
+ "print(\"\\nTime constant(tp) in second is %.3f * 10^-12\"%(tp1*10**12))\n",
+ "print(\"\\nlower 3 dB frequency = %.f Hz\"%fl)\n",
+ "print(\"\\nupper 3 dB frequency = %.2f *10^9 Hz\"%(fh*10**-9))\n",
+ "print(\"\\nbandwidth = %.2f*10^9 Hz\"%(BW*10**-9))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time constant(ts) in second is 6 * 10^-3\n",
+ "\n",
+ "Time constant(tp) in second is 0.667 * 10^-12\n",
+ "\n",
+ "lower 3 dB frequency = 27 Hz\n",
+ "\n",
+ "upper 3 dB frequency = 241.14 *10^9 Hz\n",
+ "\n",
+ "bandwidth = 241.14*10^9 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.11, Page No. 336"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# low frequecy response\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta=100.0\n",
+ "Rs=1.0 # series resistance in killo ohms\n",
+ "R1=40.0 # resistance in killo ohms\n",
+ "R2=10.0 # resistance in killo ohms\n",
+ "hie=1.1 # in killo ohms\n",
+ "C1=10.0 # capacitance in micro farad\n",
+ "Ce=20.0 # emitter capacitance in micro farad\n",
+ "hic=1100.0 # in ohms\n",
+ "Rl_1=2.0 # resistance in killo ohms\n",
+ "Rl_2=1.8 # load resistance in killo ohms\n",
+ "Rc=4.0 # collector resistance in killo ohms\n",
+ "C2=1.0 # capacitance in micro farad\n",
+ "\n",
+ "\n",
+ "#Calcualtions\n",
+ "x=(R1*R2)/(R1+R2)\n",
+ "Y=(x*hie)/(x+hie)\n",
+ "Rin= math.floor((Y+Rs)*100)/100 \n",
+ "fc=(1/(2*math.pi*Rin*10**3*C1*10**-6)) \n",
+ "Rth=(x*Rs)/(x+Rs)*10**3 \n",
+ "Rx= (Rth+hic)/(Beta) \n",
+ "R= (Rx*Rl_1*10**3)/(Rx+Rl_1*10**3) \n",
+ "R = math.floor(R*100)/100\n",
+ "fc1=(1/(2*math.floor(math.pi*100)*R*Ce*10**-6/100)) \n",
+ "fc2=(1/(2*math.pi*(Rl_2+Rc)*10**3*C2*10**-6)) \n",
+ "\n",
+ "#Result\n",
+ "print(\"CUT OFF FREQUENCY OF INPUT RC NETWORK = %.2f Hz\"%fc)\n",
+ "print(\"CUT OFF FREQUENCY OF BYPASS RC NETWORK = %.2f Hz\"%fc1)\n",
+ "print(\"CUT OFF FREQUENCY OF OUTPUT RC NETWORK = %.2f Hz\"%(math.ceil(fc2*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "CUT OFF FREQUENCY OF INPUT RC NETWORK = 8.12 Hz\n",
+ "CUT OFF FREQUENCY OF BYPASS RC NETWORK = 404.36 Hz\n",
+ "CUT OFF FREQUENCY OF OUTPUT RC NETWORK = 27.45 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 60
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.12, Page No.346"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# corner frequency and maximum GAIN\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # Colector voltage in volts\n",
+ "Beta= 100.0 \n",
+ "Rc=1.0 # Collector resistance in killo ohms\n",
+ "Rs=600.0 # SERIES RESISTANCE IN OHMS\n",
+ "Re=0.2 # in kilo ohms\n",
+ "R1= 50.0 # in kilo ohms\n",
+ "R2= 10.0 # in kilo ohms\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "C1=1.0 # capacitance in micro farad\n",
+ "\n",
+ "\n",
+ "Vth=Vcc * (R2/(R1+R2)) # VOLTAGE AT BASE\n",
+ "Rth= (R1*R2)/(R1+R2)\n",
+ "Ib=((Vcc-Vbe)/((Rth+(1+Beta)*Re)*10**3))*10**5 # in micro ampere\n",
+ "Icq= Beta*Ib*10**-3 # in milli ampere\n",
+ "Vt=26.0 # volate at room termprature in milli volts\n",
+ "gm= (Icq/Vt)*10**3 # transconductance in milli ampere per volts\n",
+ "rpi= (Beta*Vt*10**-3)/(Icq*10**-3) # resistance\n",
+ "Rb=math.floor(Rth*100)/100 # base resistance in killo ohms\n",
+ "\n",
+ "x=(rpi+(1+Beta)*Re*10**3) \n",
+ "y=(Rs+Rb*10**3) \n",
+ "ts=((x*y)/(x+y))*C1*10**-3 # in milli second\n",
+ "fl= (1/(2*math.pi*ts*10**-3)) # corner frequency in hertz\n",
+ "Ri=(x*Rb*10**-3)/(Rb+x*10**-3) \n",
+ "Av= ((gm*10**-3*rpi*Rc*10**3)*Rb*10**3)/((Ri+Rs*10**-3)*10**3*(x*10**-3+Rb)*10**3) \n",
+ "\n",
+ "#Result\n",
+ "print(rpi)\n",
+ "print(\"corner frequency = %.2f Hz\"%fl)\n",
+ "print(\"maximum gain = %.2f\"%Av)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "797.70609319\n",
+ "corner frequency = 25.40 Hz\n",
+ "maximum gain = 4.33\n"
+ ]
+ }
+ ],
+ "prompt_number": 68
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.13, Page No. 348"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print(\"Theoretical example\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Theoretical example\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.14, Page No. 349"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print(\"Theoretical example\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Theoretical example\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.15, Page No. 349"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print(\"Theoretical example\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Theoretical example\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.16, Page No. 350"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# TIME CONSTANTS , MIDBAND VOLTAGE GAIN AND COERNER FREQUENCIES\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rl=4.0 # load resistance in killo ohms\n",
+ "Rs=250.0 # SERIES RESISTANCE IN OHMS\n",
+ "rpi= 2.0 # resistance IN KILLO OHMS\n",
+ "Re=0.2 # in kilo ohms\n",
+ "C1=2 # capacitance in micro farad\n",
+ "Cl=50.0 # capacitance in pico farad\n",
+ "gm= 6.5 # transconductance in milli ampere per volts\n",
+ "\n",
+ "\n",
+ "#Calcualtions\n",
+ "ts=(Rs*10**-3+rpi)*10**3*C1*10**-3 # open circuit time constant in milli second\n",
+ "tp=Rl*Cl*10**-3 # short circuit time constant in micro second\n",
+ "Av= (((gm*10**-3*rpi*10**3*Rl*10**3))/(Rs*10**-3+rpi)*10**3)*10**-5\n",
+ "fl=(1/(2*math.pi*ts*10**-3)) # lower cut off frequency in hertz\n",
+ "fh=(1/(2*math.pi*tp*10**-6))*10**-6#upper cut off frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"open circuit time constant = %.1f ms\"%ts)\n",
+ "print(\"short circuit time constant= %.1f micro-sec\"%tp)\n",
+ "print(\"maximum gain = %.2f\"%Av)\n",
+ "print(\"lower cut off frequency = %.2f Hz\"%(math.floor(fl*100)/100))\n",
+ "print(\"upper cut off frequency = %.4f Hz\"%(math.floor(fh*10000)/10000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "open circuit time constant = 4.5 ms\n",
+ "short circuit time constant= 0.2 micro-sec\n",
+ "maximum gain = 231.11\n",
+ "lower cut off frequency = 35.36 Hz\n",
+ "upper cut off frequency = 0.7957 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.17, Page No. 552"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# frequency response\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rg=10.0 # resistance in mega ohms\n",
+ "Vgs=10.0 # gate to soure voltage\n",
+ "Igss=10.0 # current in nano ampere\n",
+ "C1=0.001 # capacitance in micro farad\n",
+ "Rd=1.8 # drain resistance in killo ohms\n",
+ "Rl=18.0 # load resistance in killo ohms\n",
+ "C2=1.0 # Capacitance in micro farad\n",
+ "\n",
+ "#Calculations\n",
+ "x= (Vgs/Igss)*1000.0 # resistance in mega ohms\n",
+ "Rin= ((Rg*x)/(Rg+x)) # input resistance in mega ohms\n",
+ "fc= (1/(2*math.pi*Rin*10**6*C1*10**-6)) # input critical frequency of the RC network\n",
+ "fc1=(1/(2*math.pi*(Rd+Rl)*10**3*C2*10**-6))# output critical frequency of the RC network\n",
+ "\n",
+ "#Result\n",
+ "print(\"input critical frequency of the RC network = %.2f Hz\"%(math.ceil(fc*100)/100))\n",
+ "print(\"input critical frequency of the RC network = %.2f Hz\"%fc1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "input critical frequency of the RC network = 16.08 Hz\n",
+ "input critical frequency of the RC network = 8.04 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.18, Page No. 556"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "rpi=2.0 # resistance in killo ohms\n",
+ "Cpi=1.8 # capacitance in pico farad\n",
+ "Cmu=0.12 # capacitance in pico farad\n",
+ "\n",
+ "#Calculations\n",
+ "fb=(1/(2*math.pi*rpi*10**3*(Cpi+Cmu)*10**-6))# frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"frequency = %.3f MHz\"%(math.floor(fb*1000)/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "frequency = 41.446 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.19, Page No.558"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# bandwidth and capacitance\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vt=26.0 # voltage in milli volts\n",
+ "ft=500.0 # frequecy in mega hertz\n",
+ "Ic=1.0 # collector current in mili ampere\n",
+ "Bo=90.0\n",
+ "Cmu=0.2 # capacitance in pico farad\n",
+ "\n",
+ "#Calculations\n",
+ "fb=ft/Bo # frequency in mega hertz\n",
+ "x= ((Ic*10**-3)/(2*math.pi*Vt*10**-3*ft*10**6))*10**12\n",
+ "Cpi= x-Cmu\n",
+ "\n",
+ "#Result\n",
+ "print(\"Bandwidth = %.2f MHz\"%(math.floor(fb*100)/100))\n",
+ "print(\"Capacitance of the transistor = %.3f pF\"%(math.floor(Cpi*1000)/1000))\n",
+ "#Answer for bandwidth is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bandwidth = 5.55 MHz\n",
+ "Capacitance of the transistor = 12.042 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.20, Page No.360"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# corner frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=1.0 # series resistance in killo ohms\n",
+ "Rl=3.7 # load resistance in killo ohms\n",
+ "Rc=3.7 # Collector resistance in killo ohms\n",
+ "R1= 200.0 # in kilo ohms\n",
+ "R2= 200.0 # in kilo ohms\n",
+ "Vbe=0.7 # Base to emitter voltage in volts\n",
+ "rpi=2.5 # resistance in killo ohms\n",
+ "Cpi=0.18 # capacitance in pico farad\n",
+ "gm=40.0 # transconductance in milli ampere per volts\n",
+ "C1=4.0 # capacitance in pico farad\n",
+ "\n",
+ "\n",
+ "#Calcualtions\n",
+ "Rb= (R1*R2)/(R1+R2) \n",
+ "y=(Rc*Rl)/(Rc+Rl) \n",
+ "Cmu= Cpi*(1+gm*y) \n",
+ "Cm2=Cmu \n",
+ "z=(Rs*rpi)/(Rs+rpi) \n",
+ "R=(Rb*z)/(Rb+z) \n",
+ "C=Cmu+4 \n",
+ "f3db= (1/(2*math.pi*R*10**3*C))*10**6 # 3-dB frequency in mega hertz\n",
+ "f3db1= (1/(2*math.pi*R*10**3*C1))*10**6 # 3-dB frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"3-dB frequency due to miller effect = %.3f MHz\"%f3db)\n",
+ "print(\"3-dB frequency = %.1f MHz\"%f3db1)\n",
+ "print(\"\\nDue to miller effect the capacitance gets multiplied by 75,\")\n",
+ "print(\"hence due to miller effect the bandwidth is reduced.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3-dB frequency due to miller effect = 12.823 MHz\n",
+ "3-dB frequency = 56.1 MHz\n",
+ "\n",
+ "Due to miller effect the capacitance gets multiplied by 75,\n",
+ "hence due to miller effect the bandwidth is reduced.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.21, Page No. 367"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# mid band gain and upper 3 db frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cpi=40.0 # in pico farad\n",
+ "Vt=26.0 # voltage in milli volts\n",
+ "Beta=150.0\n",
+ "Icc=1.0 # current in milli ampere\n",
+ "Icq=1.0 # current in milli ampere\n",
+ "Rc=4.7 # collector resistance in killo ohms\n",
+ "Rl=10.0 # load resistance in killo ohms\n",
+ "Cmu=3.0 # capacitance in pico farad\n",
+ "R1= 50.0 # in kilo ohms\n",
+ "R2= 5.0 # in kilo ohms\n",
+ "rs=1.0 # in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "rpi= ((Beta*Vt)/Icc)*10**-3\n",
+ "gm=(Icq/Vt)*10**3 # transconductance in mili ampere per volt\n",
+ "gm = math.floor(gm*100)/100\n",
+ "Rld= (Rc*Rl)/(Rc+Rl) \n",
+ "Rld = math.floor(Rld*1000)/1000\n",
+ "Cm=round(Cmu*(1+gm*Rld)) #miller capacitance in pico farad\n",
+ "Rb= (R1*R2)/(R1+R2)\n",
+ "Rb = math.floor(Rb*1000)/1000\n",
+ "x=(Rb*rs)/(Rb+rs) \n",
+ "y=(rpi*x)/(rpi+x)\n",
+ "y = math.ceil(y*10**4)/10**4\n",
+ "fh=(1/(2*math.pi*y*10**3*(Cm+Cpi)*10**-12)) # 3-db upper cut off frequency in mega hertz\n",
+ "z=(Rb*rpi)/(Rb+rpi) \n",
+ "Avm=(gm*Rld*z)/(z+rs)\n",
+ "\n",
+ "#Result\n",
+ "print(\"3-db upper cut off frequency = %.3f MHz\"%(fh*10**-6))\n",
+ "print(\"Midband Gain = %.2f\"%Avm)\n",
+ "#Value of Fh is wrong in the book\n",
+ "#wrong value of gm is used for Avm calculation"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3-db upper cut off frequency = 0.570 MHz\n",
+ "Midband Gain = 83.28\n"
+ ]
+ }
+ ],
+ "prompt_number": 64
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.22, Page No.370"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# mid band gain and upper 3 db frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cpi=40.0 # in pico farad\n",
+ "Vt=26.0 # voltage in milli volts\n",
+ "Beta=150.0\n",
+ "Icq=1.0 # current in milli ampere\n",
+ "rs=1.0 # in killo ohms\n",
+ "re=0.5 # in killo ohms\n",
+ "Rc=4.7 # collector resistance in killo ohms\n",
+ "Rl=10.0 # load resistance in killo ohms\n",
+ "Cmu=3.0 # capacitance in pico farad\n",
+ "R1= 50.0 # in kilo ohms\n",
+ "R2= 5.0 # in kilo ohms\n",
+ "\n",
+ "#Calcualtions\n",
+ "rpi= ((Beta*Vt)/Icq)*10**-3 \n",
+ "gm=(Icq/Vt)*10**3 # transconductance in mili ampere per volt\n",
+ "gm = math.floor(gm*100)/100\n",
+ "g=(rs*re)/(rs+re) \n",
+ "m=rpi/(1+Beta) \n",
+ "m = math.floor(m*10000)/10000\n",
+ "tpi= ((m*g)/(m+g))*10**3*Cpi*10**-12 \n",
+ "tpi = math.floor(tpi*10**14)/10**14\n",
+ "fh1=(1/(2*math.pi*tpi))/10**6 # first 3-db upper cut off frequency in mega hertz\n",
+ "fh1 = (math.floor(fh1*1000)/1000)\n",
+ "Rld= (Rc*Rl)/(Rc+Rl) \n",
+ "Rb= (R1*R2)/(R1+R2)\n",
+ "fh2=(1/(2*math.pi*Cmu*10**-8*Rld*10**3))*10**-2 # second 3-db upper cut off frequency in mega hertz\n",
+ "x=(m*re)/(m+re)\n",
+ "Avm=(gm*Rld*x)/(x+rs) \n",
+ "\n",
+ "#Result\n",
+ "print(\"3-db upper cut off frequency = %.3f MHz\"%fh1)\n",
+ "print(\"second 3-db upper cut off frequency= %.4f MHz\"%fh2)\n",
+ "print(\"Midband Gain = %.4f\"%Avm)\n",
+ "# Value for fh2 and Avm slightly differs from the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3-db upper cut off frequency = 166.156 MHz\n",
+ "second 3-db upper cut off frequency= 16.5927 MHz\n",
+ "Midband Gain = 2.9446\n"
+ ]
+ }
+ ],
+ "prompt_number": 89
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.23, Page No.375"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# mid band gain and upper 3 db frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cmu=3.0 # capacitance in pico farad\n",
+ "Cpi=40.0 # in pico farad\n",
+ "Vt=26.0 # voltage in milli volts\n",
+ "Beta=150.0 \n",
+ "Icq=1.0 # current in milli ampere\n",
+ "rs=1.0 # in killo ohms\n",
+ "re=4.7 # in killo ohms\n",
+ "R1= 40.0 # in kilo ohms\n",
+ "R2= 20.0 # in kilo ohms\n",
+ "R3= 27.0 # in kilo ohms\n",
+ "Rc=4.7 # collector resistance in killo ohms\n",
+ "Rl=10.0 # load resistance in killo ohms\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "rpi= ((Beta*Vt)/Icq)*10**-3\n",
+ "gm=(Icq/Vt)*10**3 # transconductance in mili ampere per volt\n",
+ "gm = math.floor(gm*100)/100\n",
+ "Rb=(R2*R3)/(R2+R3)\n",
+ "g=(rs*rpi)/(rs+rpi) \n",
+ "tp1=(((Rb*g)*(Cpi+2*Cmu))/(Rb+g))*10**-9 \n",
+ "m=rpi/(1+Beta) \n",
+ "tp2= m*(Cmu+Cpi)*10**-9 \n",
+ "Rld= (Rc*Rl)/(Rc+Rl) \n",
+ "tp3=Cmu*10**-12*Rld*10**3 \n",
+ "fh1=(1/(2*math.pi*tp1*10**6)) # first 3-db upper cut off frequency in mega hertz\n",
+ "fh2=(1/(2*math.pi*tp2*10**6)) # second 3-db upper cut off frequency in mega hertz\n",
+ "fh3=(1/(2*math.pi*tp3*10**6)) # third 3-db upper cut off frequency in mega hertz\n",
+ "Avm= -gm*Rld*(rpi/(rpi+1)) \n",
+ "\n",
+ "#Result\n",
+ "print(\"3-db upper cut off frequency = %.3f MHz\"%fh1)\n",
+ "print(\"second 3-db upper cut off frequency = %.2f MHz\"%fh2)\n",
+ "print(\"third 3-db upper cut off frequency = %.3f MHz\"%fh3)\n",
+ "print(\"Midband Gain = %.2f\"%Avm)\n",
+ "# Value for fh2 and fh3 slightly differs from the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3-db upper cut off frequency = 4.648 MHz\n",
+ "second 3-db upper cut off frequency = 143.31 MHz\n",
+ "third 3-db upper cut off frequency = 16.593 MHz\n",
+ "Midband Gain = -97.87\n"
+ ]
+ }
+ ],
+ "prompt_number": 95
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.24, Page No.383"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# corner frequency and bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "tr=16.0 # rise time in micro second\n",
+ "V=100.0 # voltage in milli volts\n",
+ "Vd=90.0 # voltage in milli volts\n",
+ "f=5.0 # frequecny in killo hertz\n",
+ "\n",
+ "#Calculations\n",
+ "fh= (0.35/(tr*10**-6))*10**-3 # upper cut off frequency in killo hertz\n",
+ "P= ((V-Vd)/V)*100 \n",
+ "fl=(P*10**3*f)/(100*math.pi) # lower cut off frequency in hertz\n",
+ "BW=(fh*10**3-fl)*10**-3 # bandwith in killo hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"upper cut off frequency = %.3f kHz\"%fh)\n",
+ "print(\"lower cut off frequency = %.2f Hz\"%fl)\n",
+ "print(\"Bandwidth = %.3f kHz\"%(math.floor(BW*1000)/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "upper cut off frequency = 21.875 kHz\n",
+ "lower cut off frequency = 159.15 Hz\n",
+ "Bandwidth = 21.715 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 100
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.25, Page No.384"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# PERCENTAGE TILT\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rc=4.0 # RESISTANCE IN KILLO OHMS\n",
+ "Rl=2.0 # RESISTANCE IN KILLO OHMS\n",
+ "C=10.0 # capacitance in micro farad\n",
+ "f=200.0 # frequency in hertz\n",
+ "\n",
+ "#Calculations\n",
+ "R1=Rc+Rl \n",
+ "fl=(1/(2*math.pi*R1*10**3*C*10**-6))# LOWER CUT -OFF FREQUENCY\n",
+ "P = (math.pi*fl*100)/f # % tilt\n",
+ "\n",
+ "#Result\n",
+ "print(\"percentage tilt = %.1f%%\"%(math.floor(P*10)/10))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "percentage tilt = 4.1%\n"
+ ]
+ }
+ ],
+ "prompt_number": 102
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.26, Page No. 385"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# PERCENTAGE TILT\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rc=2.0 # RESISTANCE IN KILLO OHMS\n",
+ "Rl=10.0 # RESISTANCE IN KILLO OHMS\n",
+ "C=10.0 # capacitance in micro farad\n",
+ "f=100.0 # frequency in hertz\n",
+ "p1=0.02\n",
+ "\n",
+ "#Calculations\n",
+ "R1=Rc+Rl\n",
+ "fl=(1/(2*math.pi*R1*10**3*C*10**-6))#LOWER CUT -OFF FREQUENCY\n",
+ "fl= math.floor(fl*100)/100\n",
+ "P= (math.floor(math.pi*100)*fl)/(f*100) \n",
+ "f=(math.floor(math.pi*100)*fl)/(p1*100) \n",
+ "\n",
+ "#Result\n",
+ "print(\"percentage tilt = %.3f%%\"%(P*100))\n",
+ "print(\"Lowest value of f for P= 2%%, will be= %.2f Hz\"%f)\n",
+ "print(\"\\nConclusion:\\nAs the input frequency increases the %% tilt decreases.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "percentage tilt = 4.145%\n",
+ "Lowest value of f for P= 2%, will be= 207.24 Hz\n",
+ "\n",
+ "Conclusion:\n",
+ "As the input frequency increases the %% tilt decreases.\n"
+ ]
+ }
+ ],
+ "prompt_number": 120
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.27, Page No. 389"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# fh,fl and bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fln=25.0 # in hertz\n",
+ "fhn=16.0 # in kelo hertz\n",
+ "n=3.0\n",
+ "\n",
+ "#Calcualtions\n",
+ "x=math.sqrt(2**(1/n)-1) \n",
+ "fl=x*fln # lower cut off frequency in hertz\n",
+ "fh=fhn/x # upper cut off frequency in hertz\n",
+ "BW=(fh*10**3)-fl # bandwidth\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"lower cut off frequency = %.2f Hz\"%(math.floor(fl*100)/100))\n",
+ "print(\"upper cut off frequency = %.2f kHz\"%fh)\n",
+ "print(\"Bandwidth = %.2f kHz\"%(BW/1000))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "lower cut off frequency = 12.74 Hz\n",
+ "upper cut off frequency = 31.38 kHz\n",
+ "Bandwidth = 31.37 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 123
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.28, Page No. 390"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fl=40.0 # in hertz\n",
+ "fh=20.0 # in kelo hertz\n",
+ "n=4.0\n",
+ "\n",
+ "#Calculations\n",
+ "x=math.sqrt(2**(1/n)-1) \n",
+ "fhn=x*fh # lower cut off frequency in hertz\n",
+ "fln=fl/x # upper cut off frequency in hertz\n",
+ "BW=fhn-fln*10**-3 # bandwidth\n",
+ "\n",
+ "#Result\n",
+ "print(\"lower cut off frequency = %.2f Hz\"%(math.floor(fln*100)/100))\n",
+ "print(\"upper cut off frequency = %.1f kHz\"%fhn)\n",
+ "print(\"Bandwidth = %.1f kHz\"%BW) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "lower cut off frequency = 91.95 Hz\n",
+ "upper cut off frequency = 8.7 kHz\n",
+ "Bandwidth = 8.6 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 128
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.29, Page No. 390"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# cut off frequencies\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fln = 20 # in Hz\n",
+ "fhn=100.0 # in kelo hertz\n",
+ "n=3.0\n",
+ "\n",
+ "#Calculations\n",
+ "x=math.sqrt(2**(1/n)-1) \n",
+ "fl=fln*x # lower cut off frequency in hertz\n",
+ "fh=fhn/x # upper cut off frequency in hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"lower cut off frequency = %.2f Hz\"%(math.floor(fl*100)/100))\n",
+ "print(\"upper cut off frequency = %.2f KHz\"%(math.floor(fh*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "lower cut off frequency = 10.19 Hz\n",
+ "upper cut off frequency = 196.14 KHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 145
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.30, Page No. 391"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Avm,Fh,Cc\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "mu=70.0 \n",
+ "rd=44.0 # resistance in killo ohms\n",
+ "Rd2=50.0 # resistance in killo ohms\n",
+ "Rg=1.0 # gate resisatnce in mega ohms\n",
+ "Csh=200 # capacitance in pico farad\n",
+ "fl=50.0\n",
+ "\n",
+ "#Calculations\n",
+ "gm= mu/(rd) # transconductane in milli ampere per volt\n",
+ "gm = math.ceil(gm*10)/10\n",
+ "x=(rd*Rd2)/(rd+Rd2) \n",
+ "x = math.floor(x*10)/10\n",
+ "Av2m= gm*x # mid frequency gain of second stage\n",
+ "y= (x*Rg*10**3)/(x+Rg*10**3)\n",
+ "Av1m= -gm*y # mid frequency gain of first stage\n",
+ "Av= Av1m*Av2m # total gain\n",
+ "Req=y\n",
+ "fh=(1/(2*math.pi*Req*10**3*Csh*10**-9)) # upper cut off frequency in killo hertz\n",
+ "Ro1=x\n",
+ "Cc=(1/(2*math.pi*fl*(Ro1*10**3+Rg*10**6)))*10**9 # coupling capacitance in nano farad\n",
+ "\n",
+ "#Result\n",
+ "print(x)\n",
+ "print(\"mid frequency gain of second stage = %.2f\"%Av2m)\n",
+ "print(\"upper cut off frequency = %.2f kHz\"%(math.ceil(fh*100)/100))\n",
+ "print(\"coupling capacitance = %.2f nF\"%Cc)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23.4\n",
+ "mid frequency gain of second stage = 37.44\n",
+ "upper cut off frequency = 34.81 kHz\n",
+ "coupling capacitance = 3.11 nF\n"
+ ]
+ }
+ ],
+ "prompt_number": 152
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.31, Page No. 392"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "gm= 10.0 # transconductane in milli ampere per volt\n",
+ "Csh=20.0 # capacitance in pico farad\n",
+ "BW=10.0 # bandwidth in mega hertz\n",
+ "fhn=10.0 # in mega hertz\n",
+ "n=2.0\n",
+ "\n",
+ "#Calculations\n",
+ "x=math.sqrt(2**(1/n)-1)\n",
+ "fh=fhn/x # lower cut off frequency in mega hertz\n",
+ "R=(1/(2*math.pi*Csh*10**-12*fh*10**6)) # resiatnce in ohms\n",
+ "Av1=-gm*R*10**-3 # mid frequency gain of first stage\n",
+ "Av2=Av1 # mid frequency gain of second stage\n",
+ "Av= Av1*Av2 # total gain\n",
+ "Avdb=20*(math.log10(Av)) # total gain dB\n",
+ "\n",
+ "#Result\n",
+ "print(\"Total gain = %.2f dB\"%(math.floor(Avdb*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total gain = 28.37 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 155
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.32, Page No. 393"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Avm,Fh,Fl\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "n=2.0\n",
+ "C=50.0 # in micro farad\n",
+ "Cc=0.1 # in micro farad\n",
+ "rd=50.0 # resistance\n",
+ "Rs=1.0 # series resistance in killo ohmstance in killo ohms\n",
+ "gm= 2.0 # transconductane in milli ampere per volt\n",
+ "Rd=10.0 # resistance in killo ohms\n",
+ "Csh=10.0 # capacitance in pico farad\n",
+ "\n",
+ "#Calculations\n",
+ "x=(rd*Rd)/(rd+Rd) \n",
+ " \n",
+ "Rg=1.0 # gate resisatnce in mega ohms\n",
+ "y= (x*Rg*10**3)/(x+Rg*10**3) \n",
+ "Avm= -gm*y # mid frequency gain of first stage\n",
+ "Av2m= -gm*y # mid frequency gain of second stage\n",
+ "Avm = math.ceil(Avm*100)/100\n",
+ "Av= Avm*Av2m # total gain\n",
+ "Avdb=20*(math.log10(Av))\n",
+ "Req=y\n",
+ "fh=(1/(2*math.pi*Req*10**3*Csh*10**-6))# upper cut off frequency in mega hertz\n",
+ "Ro1=y\n",
+ "fl=(1/(2*math.pi*Cc*10**-6*Ro1*10**3)) # lower cut off frequency in hertz\n",
+ "x=math.sqrt(2**(1/n)-1)\n",
+ "fhn=x*fh # lower cut off frequency in hertz\n",
+ "fln=fl/x # upper cut off frequency in hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"Total voltage gain = %.2f dB\"%(math.floor(Avdb*100)/100))\n",
+ "print(\"lower cut off frequency = %.2f Hz\"%fl)\n",
+ "print(\"upper cut off frequency = %.4f MHz\"%fh)\n",
+ "print(\"3dB lower cut off frequency = %.2f Hz\"%fln)\n",
+ "print(\"3dB upper cut off frequency = %.2f MHz\"%fhn)\n",
+ "# Values are slightly different than that of book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total voltage gain = 48.72 dB\n",
+ "lower cut off frequency = 192.58 Hz\n",
+ "upper cut off frequency = 1.9258 MHz\n",
+ "3dB lower cut off frequency = 299.22 Hz\n",
+ "3dB upper cut off frequency = 1.24 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 171
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.33, Page No.393"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Avm,Fh,Fl\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "n=3.0\n",
+ "Cc=0.005 # in micro farad\n",
+ "C=100.0 # in pico farad\n",
+ "rd=7.7\n",
+ "Rs=1.0 # series resistance in killo ohmstance in killo ohms\n",
+ "gm= 25.0 # transconductane in milli ampere per volt\n",
+ "Rd=10.0 # resistance in killo ohms\n",
+ "Rg=1.0 # gate resisatnce in mega ohms\n",
+ "Csh=100.0 # capacitance in pico farad\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "x=(rd*Rd)/(rd+Rd) \n",
+ "Av2m= -gm*x # mid frequency gain of second stage\n",
+ "y= (x*Rg*10**3)/(x+Rg*10**3) \n",
+ "Avm= -gm*y # mid frequency gain of first stage\n",
+ "Av= Avm*Avm*Avm # total gain\n",
+ "Avdb=20*(math.log10(-Av)) \n",
+ "Req=y \n",
+ "fh=(1/(2*math.pi*Req*10**3*Csh*10**-9)) # upper cut off frequency in killo hertz\n",
+ "Ro1=y\n",
+ "fl=(1/(2*math.pi*Cc*10**-6*(Ro1*10**3+Rg*10**6))) # lower cut off frequency in hertz\n",
+ "x=math.sqrt(2**(1/n)-1)\n",
+ "fhn=x*fh # lower cut off frequency in hertz\n",
+ "fln=fl/x # upper cut off frequency in hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"Total voltage gain = %.f dB\"%math.ceil(Avdb))\n",
+ "print(\"lower cut off frequency = %.3f Hz\"%(math.floor(fl*1000)/1000))\n",
+ "print(\"upper cut off frequency = %.2f kHz\"%fh)\n",
+ "print(\"3dB lower cut off frequency = %.3f Hz\"%(math.floor(fln*1000)/1000))\n",
+ "print(\"3dB upper cut off frequency = %.1f kHz\"%fhn)\n",
+ "# Some values are slightly different than that of book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total voltage gain = 123 dB\n",
+ "lower cut off frequency = 31.693 Hz\n",
+ "upper cut off frequency = 367.44 kHz\n",
+ "3dB lower cut off frequency = 62.165 Hz\n",
+ "3dB upper cut off frequency = 187.3 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 180
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_6.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_6.ipynb
new file mode 100755
index 00000000..719faded
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_6.ipynb
@@ -0,0 +1,1464 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6 : Feedback"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1, Page No. 409 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "a=60.0 # OPEN LOOP VOLTAGE GAIN IN dB\n",
+ "A= 10**(a/20) # open voltage gain\n",
+ "Beta= (1.0/20) # feedback ratio\n",
+ "\n",
+ "#Calculations\n",
+ "Af= (A/(1+(Beta*A))) # GAIN WITH FEEDBACL\n",
+ "AfdB= 20*(math.log10(Af)) # gain with feedback in dB\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Gain with feedback is %.2f dB\"%AfdB)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gain with feedback is 25.85 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2, Page No.409 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "a=60.0 # OPEN LOOP VOLTAGE GAIN IN dB\n",
+ "A= 10**(a/20) # open voltage gain\n",
+ "AfdB=40.0 # gain with feedback in dB\n",
+ "\n",
+ "#Calculations\n",
+ "Af= 10**(AfdB/20) # GAIN WITH FEEDBACK\n",
+ "BetaA= (A/Af)-1 # feedback factor\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback factor is %.f\"%BetaA)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback factor is 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3, Page No.409 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback output\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A= 600.0 # open voltage gain\n",
+ "Af=50.0\n",
+ "\n",
+ "#Calculations\n",
+ "Beta=( (A/Af)-1)/A # feedback ratio\n",
+ "fop= (Beta*100) # percentage of output voltage which is fedback to the input is \n",
+ "\n",
+ "#Result\n",
+ "print(\"Percentage of output voltage which is fedback to the input is %.3f%%\"%fop)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Percentage of output voltage which is fedback to the input is 1.833%\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.4, Page No. 410 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback ratio\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vo= 5.0 # output voltage\n",
+ "Vin=0.1 # input voltage without feedback\n",
+ "Vin1=0.2 # input voltage with feedback\n",
+ "\n",
+ "#Calculations\n",
+ "A= Vo/Vin # Gain without feedback\n",
+ "Af= Vo/Vin1 # Gain with feedback\n",
+ "Beta=( (A/Af)-1)/A # feedback ratio \n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback ratio = %.2f\"%Beta)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback ratio = 0.02\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.5, Page No.410 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Change in gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A= 1000.0 # open loop voltage gain\n",
+ "Beta= 0.002 # feedback ratio\n",
+ "\n",
+ "#Calculations\n",
+ "Af= (A/(1+(Beta*A))) # GAIN WITH FEEDBACL\n",
+ "A1= (1-0.15)*A # new open loop voltage gain\n",
+ "Af1= (A1/(1+(Beta*A1))) # GAIN WITH FEEDBACL\n",
+ "dA=((Af-Af1)/Af)*100 # Change in overall gain in percentage \n",
+ "\n",
+ "#Result\n",
+ "print(\"Change in overall gain is %.1f%%\"%dA)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Change in overall gain is 5.6%\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6, Page No. 414 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# open loop voltage gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Af= 100.0 # GAIN WITH FEEDBACK\n",
+ "dAf=1.0/100 # OPEN LOOP VOLTAGE GAIN \n",
+ "dA= 10.0/100 # open voltage gain\n",
+ "\n",
+ "#Calculations\n",
+ "BetaA=(dA/dAf)-1 # feedback factor\n",
+ "A=Af*(1+BetaA) # open loop voltage gain\n",
+ "\n",
+ "#Result\n",
+ "print(\"open loop voltage gain is %.f\"%A)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "open loop voltage gain is 1000\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7, Page No.415 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# open loop voltage gain & negaive feedback\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Af= 100.0 # GAIN WITH FEEDBACK\n",
+ "dAf=0.1/100 # OPEN LOOP VOLTAGE GAIN \n",
+ "dA= 10.0/100 # open voltage gain\n",
+ "\n",
+ "#Calculations\n",
+ "BetaA=(dA/dAf)-1 # feedback factor\n",
+ "A=Af*(1+BetaA) # open loop voltage gain\n",
+ "NF= Af/A # amount of negative feedback\n",
+ "\n",
+ "#Result\n",
+ "print(\"open loop voltage gain is %.f\"%A)\n",
+ "print(\"amount of negative feedback is %.2f\"%NF)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "open loop voltage gain is 10000\n",
+ "amount of negative feedback is 0.01\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8, Page No. 416"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# GAIN,INPUT VOLTAGE AND OUTPUT VOLTAGE\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vs=10.0 # output voltage in milli volts\n",
+ "Vi= 0.01 # input voltage in volts\n",
+ "A=200.0 # amplifier gain without feedback\n",
+ "D=0.1 # distortion without feedback\n",
+ "Df=0.01 # distortion with feedback\n",
+ "\n",
+ "#Calculations\n",
+ "Beta=( (D/Df)-1)/A # feedback ratio\n",
+ "fop= (Beta*100) # percentage of output voltage which is fedback to the input is \n",
+ "Af= (A/(1+(Beta*A))) # GAIN WITH FEEDBACL\n",
+ "Vo= Af*Vs*10**-3 # new output volate in volts\n",
+ "Vin= (Vi +(-Beta*Vo))*10**3\n",
+ "\n",
+ "#Resut\n",
+ "print(\"gain with feedback = %.f\"%Af)\n",
+ "print(\"new output volate = %.1f V\"%Vo)\n",
+ "print(\"new input voltage = %.f mV\"%Vin)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain with feedback = 20\n",
+ "new output volate = 0.2 V\n",
+ "new input voltage = 1 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.9, Page No.417 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# INPUT VOLTAGE ,distortion AND close loop gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vs=10.0 # output voltage in milli volts\n",
+ "A=1000.0 # amplifier gain without feedback\n",
+ "D=0.1 # distortion without feedback\n",
+ "BetaAd=40.0 # FEEDBACK FACTOR IN dB\n",
+ "\n",
+ "#Calculations\n",
+ "BetaA=10**(BetaAd/20) # feedback ratio\n",
+ "Df= ((D/(1+BetaA)))*100 # distortion in percentage with feedbck\n",
+ "Af= (A/(1+(BetaA))) # GAIN WITH FEEDBACL\n",
+ "Vo= Vs*(1+BetaA)*10**-3 # new output volate in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"input signal voltage = %.2f V\"%Vo)\n",
+ "print(\"Percentage second harmonic distortion will be %.1f%%\"%Df)\n",
+ "print(\"Closed loop voltage gain will be %.1f\"%Af)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "input signal voltage = 1.01 V\n",
+ "Percentage second harmonic distortion will be 0.1%\n",
+ "Closed loop voltage gain will be 9.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.10, Page No. 419"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# input & output impedance\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A= 10000.0 # open voltage gain\n",
+ "Beta=0.02 # feedback ratio\n",
+ "Zi=1.0 # input impedance without feedback in kiilo ohms\n",
+ "Zo=10.0 # output impedance without feedback in kiilo ohms\n",
+ "\n",
+ "\n",
+ "#calculaltions\n",
+ "Zif= (1+A*Beta)*Zi # input impedance with feedback in kiilo ohms\n",
+ "Zof=(Zo/(1+Beta*A))*10**3 # output impedance with feedback in ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"input impedance with feedback = %.f k-ohm\"%Zif)\n",
+ "print(\"output impedance with feedback = %.2f ohm\"%Zof)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "input impedance with feedback = 201 k-ohm\n",
+ "output impedance with feedback = 49.75 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.11, Page No. 419"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback factor and Change in gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Zi=1.0 # input impedance without feedback in kiilo ohms\n",
+ "Zo=10.0 # output impedance without feedback in kiilo ohms\n",
+ "Zof=1.0 # output impedance with feedback in killo ohms\n",
+ "A= 1000.0 # open loop voltage gain\n",
+ "Af=100.0 # FEEDBACK\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Beta=( (Zo/Zof)-1)/A # feedback ratio\n",
+ "BetaA= Beta*A # feedback factor\n",
+ "A1= (1-0.1)*A # new open loop voltage gain\n",
+ "Af1= (A1/(1+(Beta*A1))) # GAIN WITH FEEDBACL\n",
+ "dA=((Af-Af1)/Af)*100 # Change in overall gain in percentage \n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback factor is %.f\"%BetaA)\n",
+ "print(\"Change in overall gain in percentage is %.1f%%\"%dA)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback factor is 9\n",
+ "Change in overall gain in percentage is 1.1%\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.12, Page No.421 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Avf,Fhf,Flf\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Fh=20.0 # upper cutoff frequency in killo hertz without feedback\n",
+ "Fl=30.0 # upper cutoff frequency in hertz without feedback\n",
+ "Av= 50000.0 # open loop voltage gain\n",
+ "Beta=5*10**-5 # feedback ratio\n",
+ "\n",
+ "#calaculations\n",
+ "Avf= (Av/(1+(Beta*Av))) # GAIN WITH FEEDBACL\n",
+ "Fhf=Fh*(1+Av*Beta) # uppor cutoff frequency with feedback in killo hertz\n",
+ "Flf=Fl/(1+Av*Beta) # lower cutoff frequency with feedback in hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"Voltsge gain with feedback is %.1f\"%Avf)\n",
+ "print(\"uppor cutoff frequency with feedback = %.f kHz\"%Fhf)\n",
+ "print(\"lower cutoff frequency with feedback = %.2f Hz\"%Flf)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltsge gain with feedback is 14285.7\n",
+ "uppor cutoff frequency with feedback = 70 kHz\n",
+ "lower cutoff frequency with feedback = 8.57 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.13, Page No. 422"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback factor and bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "B=4.0 # bandwidth in mega hertz without feedback\n",
+ "Av= 1500.0 # open loop voltage gain\n",
+ "Avf= 150.0 # GAIN WITH FEEDBACk\n",
+ "\n",
+ "#Calculations\n",
+ "AvB= ((Av/Avf)-1) # feedback factor\n",
+ "BWf=(1+AvB)*B # bandwidth in mega hertz with feedback\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback factor is %.f\"%AvB)\n",
+ "print(\"bandwidth with feedback is %.f MHz\"%BWf)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback factor is 9\n",
+ "bandwidth with feedback is 40 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.14, Page No. 424"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# voltage gain ,input & output resistance\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A= 500.0 # open voltage gain\n",
+ "Beta=0.01 # feedback ratio\n",
+ "Ri=3.0 # input resistance without feedback in kiilo ohms\n",
+ "Ro=20.0 # output resistance without feedback in kiilo ohms\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Af=(A/(1+A*Beta)) # Voltage gain is\n",
+ "Rif= (1+A*Beta)*Ri # input RESISTANCE with feedback in kiilo ohms\n",
+ "Rof=(Ro/(1+Beta*A))# output resistance with feedback in killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Voltage gain is %.2f\"%Af)\n",
+ "print(\"input resistance with feedback = %.f k-ohm\"%Rif)\n",
+ "print(\"output resistance with feedback = %.2f k-ohm\"%Rof)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage gain is 83.33\n",
+ "input resistance with feedback = 18 k-ohm\n",
+ "output resistance with feedback = 3.33 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.15, Page No. 428"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# INPUT IMPEDANCE\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta=100.0 # gain\n",
+ "Rl=18.6 # load resistance in killo ohms\n",
+ "Re=9.3 # emitter resistance in killo ohms\n",
+ "Vbe=0.7 \n",
+ "Vcc=10.0 # collector voltage in volts\n",
+ "R1=10.0 # resistance in killo ohms\n",
+ "R2=10.0 # resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "V2= Vcc*(R2/(R1+R2)) # voltage at resistor R2 \n",
+ "Ve=V2-Vbe # volate at emitter\n",
+ "Ie=Ve/Re # Emitter current in milli ampere\n",
+ "re=(25/Ie) # AC emitter resistance\n",
+ "Re=(Rl*Re)/(Rl+Re) # effective emitter resistance in killo ohms\n",
+ "Zib=Beta*(Re*10**3+re)*10**-3\n",
+ "x=(R1*R2)/(R1+R2) # resistance in killo ohms\n",
+ "Zi=(Zib*x)/(Zib+x) # input impedance of the emitter follower in killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"input impedance of the emitter follower = %.2f k-ohm\"%Zi)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "input impedance of the emitter follower = 4.96 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.16, Page No. 429"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "gm=4000.0 # gain in micro second\n",
+ "Ro=10.0 # output resistance in killo ohms\n",
+ "Rd=10.0 # resistance in killo ohms\n",
+ "R1=80.0 # resistance in killo ohms\n",
+ "R2=20.0 # resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Rl=(Ro*Rd)/(Ro+Rd) # load resistance in killo ohms\n",
+ "A= -(gm*10**-6*Rl*10**3) # gain without feedback\n",
+ "Beta= -(R2/(R1+R2)) # feedback factor\n",
+ "Af=(A/(1+A*Beta)) # gain with feedback\n",
+ "\n",
+ "#Result\n",
+ "print(\"gain without feedback is %.f\"%A)\n",
+ "print(\"gain with feedback is %.f\"%Af)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain without feedback is -20\n",
+ "gain with feedback is -4\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.17, Page No. 430"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1=1.8 # resistance in killo ohms\n",
+ "R2=0.2 # resistance in killo ohms\n",
+ "A=100000.0 # gain without feedback\n",
+ "\n",
+ "#Calculations\n",
+ "Beta= (R2/(R1+R2)) # feedback factor\n",
+ "Af1=(A/(1+A*Beta)) # gain with feedback\n",
+ "Af=(1/Beta) # AS A*Beta>>1\n",
+ "\n",
+ "#Result\n",
+ "print(\"gain with feedback AS A*Beta>>1 is %.f\"%Af)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain with feedback AS A*Beta>>1 is 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.18, Page No. 431"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Av,Rif,Avf,Rof\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=600.0 # Internal resistance in ohms\n",
+ "Rl=2.0 # Load resistance in killo ohms'\n",
+ "Rb=40.0 # base resistance in killo ohms\n",
+ "# H-paramters are\n",
+ "hie=5.0 # in killo ohms\n",
+ "hre=80.0\n",
+ "hfe=80.0\n",
+ "\n",
+ "#Calculations\n",
+ "RL1=(Rb*Rl)/(Rb+Rl) \n",
+ "Av=(-(hfe*(RL1*10**3/hie*10**3)))*10**-6\n",
+ "Av = math.floor(Av*100)/100\n",
+ "x=(Rb*10**3/(1-Av)) \n",
+ "Rif= (hie*10**3*x)/(hie*10**3+x)\n",
+ "Avf=(Av*Rif)/(Rif+Rs)\n",
+ "Rof=((Rb*10**3*(Rs+hie*10**3))/(Rs*hfe))*10**-3\n",
+ "Rof1=(Rof*Rl)/(Rof+Rl)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Voltage gain is %.2f\"%Av)\n",
+ "print(\"input resistance with feedback = %.3f ohm\"%(math.ceil(Rif*1000)/1000))\n",
+ "print(\"Overall Voltage gain is %.2f\"%Avf)\n",
+ "print(\"output resistance with feedback = %.1f k-ohm\"%Rof1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage gain is -30.48\n",
+ "input resistance with feedback = 1013.172 ohm\n",
+ "Overall Voltage gain is -19.14\n",
+ "output resistance with feedback = 1.4 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.19, Page No. 435"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# A,Beta,Rif,Af amd loop gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1=1.0 # resistance in killo ohms\n",
+ "R2=20.0 # resistance in killo ohms\n",
+ "Re=100.0 # emitter resistance in ohms\n",
+ "# H-paramters are\n",
+ "hie=2.0 # in killo ohms\n",
+ "hfe=80.0\n",
+ "Rl=1.0 # load resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Ri=hie # input resistance in killo ohms\n",
+ "A= -(hfe*Rl*10**3)/(hie*10**3) \n",
+ "Beta=Re/(Rl*(10**3)) # GAIN\n",
+ "Rif= (hie*10**3+(1+hfe)*Re)*10**-3 # input resistance with feedback in killo ohms\n",
+ "Av=(-(hfe*(Rl*10**3/Rif*10**3)))*10**-6\n",
+ "BetaA= Beta*A # loop gain\n",
+ "BetaAd= 20*(math.log10(-BetaA)) # loop gain in dB\n",
+ "\n",
+ "#Result\n",
+ "print(\"Voltage gain without feedback is %.f\"%A)\n",
+ "print(\"Feedback ratio is given by %.1f\"%Beta)\n",
+ "print(\"input resistance with feedback = %.1f k-ohm\"%Rif)\n",
+ "print(\"Voltage gain with feedback is %.2f\"%Av)\n",
+ "print(\"loop gain is %.2f dB\"%BetaAd)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage gain without feedback is -40\n",
+ "Feedback ratio is given by 0.1\n",
+ "input resistance with feedback = 10.1 k-ohm\n",
+ "Voltage gain with feedback is -7.92\n",
+ "loop gain is 12.04 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.20, Page No. 436 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# voltage gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "re=7.5 # A.C. Resistance\n",
+ "R1=470.0 # resistance in ohms\n",
+ "Rc=2.2 # resistance in killo ohms\n",
+ "Re=510.0 # emitter resistance in ohms\n",
+ "# H-paramters are\n",
+ "hie=900.0 # in ohms\n",
+ "hfe=120.0\n",
+ "\n",
+ "#Calculations\n",
+ "A=-(hfe)/(hie+Re) # gain without feedback\n",
+ "Beta=-Re # gain\n",
+ "GF= (1+A*Beta) # gain factor\n",
+ "Af=A/(GF) # GAIN WITH FEEDBACK\n",
+ "Avf= Af*Rc*10**3 # voltage gain with feedback\n",
+ "Av= -(Rc*10**3/re) # voltage gain without feedback\n",
+ "\n",
+ "#Result\n",
+ "print(\"voltage gain with feedback is %.1f\"%Avf)\n",
+ "print(\"voltage gain without feedback is %.1f\"%Av)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "voltage gain with feedback is -4.2\n",
+ "voltage gain without feedback is -293.3\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.21, Page No. 436"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# change in overall gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta=0.01 # feedback\n",
+ "Ad= 60.0 # gain in dB\n",
+ "dA= 11.0 # open voltage gain\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "A= 10**(Ad/20) # gain\n",
+ "dAf= (1/(1+Beta*A))*dA # GAIN WITH FEEDBACK\n",
+ "\n",
+ "#Result\n",
+ "print(\"change in overall gain is = %.f %%\"%dAf)\n",
+ "print(\"\\nThe result clearly shows that the %% change reduction in overall gain\")\n",
+ "print(\"with negative feedback is reduced from 11%% to 1%%.\")\n",
+ "print(\"That is why we say that amplifier with negative feedback have stable gain.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "change in overall gain is = 1 %\n",
+ "\n",
+ "The result clearly shows that the %% change reduction in overall gain\n",
+ "with negative feedback is reduced from 11%% to 1%%.\n",
+ "That is why we say that amplifier with negative feedback have stable gain.\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.22, Page No. 437 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# input impedence with feedback\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A= 1000.0 # open voltage gain\n",
+ "Beta=0.005 # feedback ratio\n",
+ "Zi=2.0 # input impedance without feedback in kiilo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Zif= (1+A*Beta)*Zi # input impedance with feedback in kiilo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"input impedance with feedback = %.f k-ohm\"%Zif)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "input impedance with feedback = 12 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.23, Page No.437 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback factor and change in overall gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Zo=12.6 # output impedance in killo ohms\n",
+ "Zofb=600.0 # output impedance in ohms with feedback\n",
+ "Ad= 60.0 # gain in dB\n",
+ "dA= 10.0 # open voltage gain\n",
+ "\n",
+ "#Calcualtions\n",
+ "A= 10**(Ad/20) # gain\n",
+ "Beta= ((Zo*10**3/Zofb)-1)/A\n",
+ "dAf= (1/(1+Beta*A))*dA # GAIN WITH FEEDBACK\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedbck factor is %.2f\"%Beta)\n",
+ "print(\"change in overall gain = %.3f %%\"%dAf)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedbck factor is 0.02\n",
+ "change in overall gain = 0.476 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.24, Page No. 437 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback fration ,overall voltage gain and output voltage\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A=5000.0 # gain wtihout feedback\n",
+ "R1=1.0 # resistance in killo ohms\n",
+ "R2=9.0 # resistance in killo ohms\n",
+ "Vs=2.0 # input voltage without feedback in milli volts\n",
+ "\n",
+ "#Calcualtions\n",
+ "Beta= R1/(R1+R2) # feedback fraction\n",
+ "Afb=round(A/(1+Beta*A))\n",
+ "Vo= round(Afb*Vs) # output voltage with feedback in milli volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback fraction = %.1f\"%Beta)\n",
+ "print(\"overall voltage gain = %.f\"%Afb)\n",
+ "print(\"output voltage with feedback = %.f mV\"%Vo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback fraction = 0.1\n",
+ "overall voltage gain = 10\n",
+ "output voltage with feedback = 20 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.25, Page No. 438"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback fraction ,overall voltage gain,input impedance ,output impedance and output volatge\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Zi=5.0 # input impedance in killo ohms\n",
+ "Zo=100.0 # input impedance in ohms\n",
+ "A=10000.0 # gain wtihout feedback\n",
+ "R1=2.0 # resistance in killo ohms\n",
+ "R2=18.0 # resistance in killo ohms\n",
+ "Vs=10.0 # input voltage without feedback in milli volts\n",
+ "\n",
+ "#Calculations\n",
+ "Beta= R1/(R1+R2) # feedback fraction\n",
+ "Afb=round(A/(1+Beta*A)) # overall gain\n",
+ "Zif= round((1+A*Beta)*Zi*10**-3) # input impedance with feedback in mega ohms\n",
+ "Zof= Zo/(1+Beta*A) # OUTPUT impedance with feedback in ohms\n",
+ "Vo= round(Vs/Afb) # output voltage with feedback in milli volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback fraction = %.1f\"%Beta)\n",
+ "print(\"overall voltage gain = %.f\"%Afb)\n",
+ "print(\"input impedance with feedback = %.f M-ohm\"%Zif)\n",
+ "print(\"output impedance with feedback= %.1f ohm\"%Zof)\n",
+ "print(\"output voltage with feedback = %.f mV\"%Vo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback fraction = 0.1\n",
+ "overall voltage gain = 10\n",
+ "input impedance with feedback = 5 M-ohm\n",
+ "output impedance with feedback= 0.1 ohm\n",
+ "output voltage with feedback = 1 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.26, Page No. 438"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "a=60.0 # OPEN LOOP VOLTAGE GAIN IN dB\n",
+ "A= 10**(a/20) # open voltage gain\n",
+ "Beta=0.009 # feedback ratio\n",
+ "\n",
+ "#Calculations\n",
+ "Af= (A/(1+(Beta*A))) # GAIN WITH FEEDBACL\n",
+ "AfdB= 20*(math.log10(Af))# gain with feedback in dB\n",
+ "\n",
+ "#Result\n",
+ "print(\"gain with feedback = %.2f\"%AfdB)\n",
+ "#Answer for the gain with feedback is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain with feedback = 40.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.27, Page No. 439"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# reduction in distortion\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "a=54.8 # OPEN LOOP VOLTAGE GAIN IN dB\n",
+ "A= 10**(a/20) # open voltage gain\n",
+ "Beta=0.02 # feedback ratio\n",
+ "\n",
+ "#Calculations\n",
+ "Af= (A/(1+(Beta*A))) # GAIN WITH FEEDBACL\n",
+ "dA= (1/(1+Beta*A))*100# percentage change in distortion \n",
+ "\n",
+ "#Result\n",
+ "print(\"percentage reduction in distortion is %.2f%%\"%(math.floor(dA*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "percentage reduction in distortion is 8.33%\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.28, Page No. 439 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# gain with feedback ,input impedance and output impedance \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Zi=1.0 # input impedance in killo ohms\n",
+ "Zo=40.0 # input impedance in killo ohms\n",
+ "A=10000.0 # gain wtihout feedback\n",
+ "Beta=0.05 # gain\n",
+ "\n",
+ "#Calculations\n",
+ "Afb=(A/(1+Beta*A))\n",
+ "Zif= ((1+A*Beta)*Zi)\n",
+ "Zof= (Zo*10**3/(1+Beta*A))\n",
+ "\n",
+ "#Result\n",
+ "print(\"overall voltage gain = %.f\"%Afb)\n",
+ "print(\"input impedance with feedback = %.f M-ohm\"%Zif)\n",
+ "print(\"output impedance with feedback = %.f ohms\"%Zof)\n",
+ "#Answer in the book for input impedance is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "overall voltage gain = 20\n",
+ "input impedance with feedback = 501 M-ohm\n",
+ "output impedance with feedback = 80 ohms\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.29, Page No. 439"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "F2=16.0 # upper cutoff frequency in killo hertz without feedback\n",
+ "F1=40.0 # upper cutoff frequency in hertz without feedback\n",
+ "A= 800.0 # open loop voltage gain\n",
+ "Beta=0.02 # feedback ratio\n",
+ "\n",
+ "#CAlaculations\n",
+ "Afb= (A/(1+(Beta*A))) # GAIN WITH FEEDBACk\n",
+ "F2f=F2*(1+A*Beta) # uppor cutoff frequency with feedback in killo hertz\n",
+ "F1f=F1/(1+A*Beta)*10**-3 # lower cutoff frequency with feedback in killo hertz\n",
+ "Bw=F2-F1*10**-3 # bandwidth without feedback in killo hertz\n",
+ "Bwf=round(F2f-F1f) # bandwidth with feedback in killo hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"bandwidth without feedback = %.2f kHz\"%Bw)\n",
+ "print(\"bandwidth with feedback = %.f\"%Bwf)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "bandwidth without feedback = 15.96 kHz\n",
+ "bandwidth with feedback = 272\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.30, Page No. 440"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "BW=10.0 # bandwidth without feedback in killo hertz\n",
+ "A= 100.0 # open loop voltage gain\n",
+ "Beta=0.1 # feedback ratio\n",
+ "\n",
+ "#Calculations\n",
+ "Afb= (A/(1+(Beta*A))) # GAIN WITH FEEDBACk\n",
+ "Bwf=round(BW*(1+Beta*A))# bandwidth with feedback in killo hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback gain = %.2f\"%Afb)\n",
+ "print(\"bandwidth with feedback = %.f kHz\"%Bwf)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback gain = 9.09\n",
+ "bandwidth with feedback = 110 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.31, Page No. 440 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# gain and harmonic distortion\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A2= 200.0 # open loop voltage gain\n",
+ "Beta=0.1 # feedback ratio\n",
+ "D2=0.02 # first stage distortion\n",
+ "\n",
+ "#Calculations\n",
+ "D2d= (D2/(1+Beta*A2))*100\n",
+ "A2d=A2/(1+Beta*A2)\n",
+ "A1=round(A2/A2d)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print(\"second stage harmonic distortion , A2' %.2f%%\"%(D2d*100))\n",
+ "print(\"gain of first stage, A1 = %.f\"%A1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "second stage harmonic distortion , A2' 9.52%\n",
+ "gain of first stage, A1 = 21\n"
+ ]
+ }
+ ],
+ "prompt_number": 55
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.32, Page No.453 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# pole frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R2=2*10**5 # effective resistance in ohms\n",
+ "Av2=1000.0 # gain of second stage\n",
+ "Cf=20.0 # feedback capacitor in pico farad\n",
+ "\n",
+ "#Calculations\n",
+ "Cm=(1+Av2)*Cf \n",
+ "fp1= 1/(2*math.pi*R2*Cm*10**-12)\n",
+ "\n",
+ "#Result\n",
+ "print(\"pole frequency = %.2f Hz\"%fp1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pole frequency = 39.75 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 57
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_6_1.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_6_1.ipynb
new file mode 100755
index 00000000..719faded
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_6_1.ipynb
@@ -0,0 +1,1464 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6 : Feedback"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1, Page No. 409 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "a=60.0 # OPEN LOOP VOLTAGE GAIN IN dB\n",
+ "A= 10**(a/20) # open voltage gain\n",
+ "Beta= (1.0/20) # feedback ratio\n",
+ "\n",
+ "#Calculations\n",
+ "Af= (A/(1+(Beta*A))) # GAIN WITH FEEDBACL\n",
+ "AfdB= 20*(math.log10(Af)) # gain with feedback in dB\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Gain with feedback is %.2f dB\"%AfdB)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gain with feedback is 25.85 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2, Page No.409 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "a=60.0 # OPEN LOOP VOLTAGE GAIN IN dB\n",
+ "A= 10**(a/20) # open voltage gain\n",
+ "AfdB=40.0 # gain with feedback in dB\n",
+ "\n",
+ "#Calculations\n",
+ "Af= 10**(AfdB/20) # GAIN WITH FEEDBACK\n",
+ "BetaA= (A/Af)-1 # feedback factor\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback factor is %.f\"%BetaA)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback factor is 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3, Page No.409 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback output\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A= 600.0 # open voltage gain\n",
+ "Af=50.0\n",
+ "\n",
+ "#Calculations\n",
+ "Beta=( (A/Af)-1)/A # feedback ratio\n",
+ "fop= (Beta*100) # percentage of output voltage which is fedback to the input is \n",
+ "\n",
+ "#Result\n",
+ "print(\"Percentage of output voltage which is fedback to the input is %.3f%%\"%fop)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Percentage of output voltage which is fedback to the input is 1.833%\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.4, Page No. 410 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback ratio\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vo= 5.0 # output voltage\n",
+ "Vin=0.1 # input voltage without feedback\n",
+ "Vin1=0.2 # input voltage with feedback\n",
+ "\n",
+ "#Calculations\n",
+ "A= Vo/Vin # Gain without feedback\n",
+ "Af= Vo/Vin1 # Gain with feedback\n",
+ "Beta=( (A/Af)-1)/A # feedback ratio \n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback ratio = %.2f\"%Beta)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback ratio = 0.02\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.5, Page No.410 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Change in gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A= 1000.0 # open loop voltage gain\n",
+ "Beta= 0.002 # feedback ratio\n",
+ "\n",
+ "#Calculations\n",
+ "Af= (A/(1+(Beta*A))) # GAIN WITH FEEDBACL\n",
+ "A1= (1-0.15)*A # new open loop voltage gain\n",
+ "Af1= (A1/(1+(Beta*A1))) # GAIN WITH FEEDBACL\n",
+ "dA=((Af-Af1)/Af)*100 # Change in overall gain in percentage \n",
+ "\n",
+ "#Result\n",
+ "print(\"Change in overall gain is %.1f%%\"%dA)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Change in overall gain is 5.6%\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.6, Page No. 414 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# open loop voltage gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Af= 100.0 # GAIN WITH FEEDBACK\n",
+ "dAf=1.0/100 # OPEN LOOP VOLTAGE GAIN \n",
+ "dA= 10.0/100 # open voltage gain\n",
+ "\n",
+ "#Calculations\n",
+ "BetaA=(dA/dAf)-1 # feedback factor\n",
+ "A=Af*(1+BetaA) # open loop voltage gain\n",
+ "\n",
+ "#Result\n",
+ "print(\"open loop voltage gain is %.f\"%A)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "open loop voltage gain is 1000\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.7, Page No.415 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# open loop voltage gain & negaive feedback\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Af= 100.0 # GAIN WITH FEEDBACK\n",
+ "dAf=0.1/100 # OPEN LOOP VOLTAGE GAIN \n",
+ "dA= 10.0/100 # open voltage gain\n",
+ "\n",
+ "#Calculations\n",
+ "BetaA=(dA/dAf)-1 # feedback factor\n",
+ "A=Af*(1+BetaA) # open loop voltage gain\n",
+ "NF= Af/A # amount of negative feedback\n",
+ "\n",
+ "#Result\n",
+ "print(\"open loop voltage gain is %.f\"%A)\n",
+ "print(\"amount of negative feedback is %.2f\"%NF)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "open loop voltage gain is 10000\n",
+ "amount of negative feedback is 0.01\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.8, Page No. 416"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# GAIN,INPUT VOLTAGE AND OUTPUT VOLTAGE\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vs=10.0 # output voltage in milli volts\n",
+ "Vi= 0.01 # input voltage in volts\n",
+ "A=200.0 # amplifier gain without feedback\n",
+ "D=0.1 # distortion without feedback\n",
+ "Df=0.01 # distortion with feedback\n",
+ "\n",
+ "#Calculations\n",
+ "Beta=( (D/Df)-1)/A # feedback ratio\n",
+ "fop= (Beta*100) # percentage of output voltage which is fedback to the input is \n",
+ "Af= (A/(1+(Beta*A))) # GAIN WITH FEEDBACL\n",
+ "Vo= Af*Vs*10**-3 # new output volate in volts\n",
+ "Vin= (Vi +(-Beta*Vo))*10**3\n",
+ "\n",
+ "#Resut\n",
+ "print(\"gain with feedback = %.f\"%Af)\n",
+ "print(\"new output volate = %.1f V\"%Vo)\n",
+ "print(\"new input voltage = %.f mV\"%Vin)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain with feedback = 20\n",
+ "new output volate = 0.2 V\n",
+ "new input voltage = 1 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.9, Page No.417 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# INPUT VOLTAGE ,distortion AND close loop gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vs=10.0 # output voltage in milli volts\n",
+ "A=1000.0 # amplifier gain without feedback\n",
+ "D=0.1 # distortion without feedback\n",
+ "BetaAd=40.0 # FEEDBACK FACTOR IN dB\n",
+ "\n",
+ "#Calculations\n",
+ "BetaA=10**(BetaAd/20) # feedback ratio\n",
+ "Df= ((D/(1+BetaA)))*100 # distortion in percentage with feedbck\n",
+ "Af= (A/(1+(BetaA))) # GAIN WITH FEEDBACL\n",
+ "Vo= Vs*(1+BetaA)*10**-3 # new output volate in volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"input signal voltage = %.2f V\"%Vo)\n",
+ "print(\"Percentage second harmonic distortion will be %.1f%%\"%Df)\n",
+ "print(\"Closed loop voltage gain will be %.1f\"%Af)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "input signal voltage = 1.01 V\n",
+ "Percentage second harmonic distortion will be 0.1%\n",
+ "Closed loop voltage gain will be 9.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.10, Page No. 419"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# input & output impedance\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A= 10000.0 # open voltage gain\n",
+ "Beta=0.02 # feedback ratio\n",
+ "Zi=1.0 # input impedance without feedback in kiilo ohms\n",
+ "Zo=10.0 # output impedance without feedback in kiilo ohms\n",
+ "\n",
+ "\n",
+ "#calculaltions\n",
+ "Zif= (1+A*Beta)*Zi # input impedance with feedback in kiilo ohms\n",
+ "Zof=(Zo/(1+Beta*A))*10**3 # output impedance with feedback in ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"input impedance with feedback = %.f k-ohm\"%Zif)\n",
+ "print(\"output impedance with feedback = %.2f ohm\"%Zof)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "input impedance with feedback = 201 k-ohm\n",
+ "output impedance with feedback = 49.75 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.11, Page No. 419"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback factor and Change in gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Zi=1.0 # input impedance without feedback in kiilo ohms\n",
+ "Zo=10.0 # output impedance without feedback in kiilo ohms\n",
+ "Zof=1.0 # output impedance with feedback in killo ohms\n",
+ "A= 1000.0 # open loop voltage gain\n",
+ "Af=100.0 # FEEDBACK\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Beta=( (Zo/Zof)-1)/A # feedback ratio\n",
+ "BetaA= Beta*A # feedback factor\n",
+ "A1= (1-0.1)*A # new open loop voltage gain\n",
+ "Af1= (A1/(1+(Beta*A1))) # GAIN WITH FEEDBACL\n",
+ "dA=((Af-Af1)/Af)*100 # Change in overall gain in percentage \n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback factor is %.f\"%BetaA)\n",
+ "print(\"Change in overall gain in percentage is %.1f%%\"%dA)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback factor is 9\n",
+ "Change in overall gain in percentage is 1.1%\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.12, Page No.421 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Avf,Fhf,Flf\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Fh=20.0 # upper cutoff frequency in killo hertz without feedback\n",
+ "Fl=30.0 # upper cutoff frequency in hertz without feedback\n",
+ "Av= 50000.0 # open loop voltage gain\n",
+ "Beta=5*10**-5 # feedback ratio\n",
+ "\n",
+ "#calaculations\n",
+ "Avf= (Av/(1+(Beta*Av))) # GAIN WITH FEEDBACL\n",
+ "Fhf=Fh*(1+Av*Beta) # uppor cutoff frequency with feedback in killo hertz\n",
+ "Flf=Fl/(1+Av*Beta) # lower cutoff frequency with feedback in hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"Voltsge gain with feedback is %.1f\"%Avf)\n",
+ "print(\"uppor cutoff frequency with feedback = %.f kHz\"%Fhf)\n",
+ "print(\"lower cutoff frequency with feedback = %.2f Hz\"%Flf)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltsge gain with feedback is 14285.7\n",
+ "uppor cutoff frequency with feedback = 70 kHz\n",
+ "lower cutoff frequency with feedback = 8.57 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.13, Page No. 422"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback factor and bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "B=4.0 # bandwidth in mega hertz without feedback\n",
+ "Av= 1500.0 # open loop voltage gain\n",
+ "Avf= 150.0 # GAIN WITH FEEDBACk\n",
+ "\n",
+ "#Calculations\n",
+ "AvB= ((Av/Avf)-1) # feedback factor\n",
+ "BWf=(1+AvB)*B # bandwidth in mega hertz with feedback\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback factor is %.f\"%AvB)\n",
+ "print(\"bandwidth with feedback is %.f MHz\"%BWf)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback factor is 9\n",
+ "bandwidth with feedback is 40 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.14, Page No. 424"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# voltage gain ,input & output resistance\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A= 500.0 # open voltage gain\n",
+ "Beta=0.01 # feedback ratio\n",
+ "Ri=3.0 # input resistance without feedback in kiilo ohms\n",
+ "Ro=20.0 # output resistance without feedback in kiilo ohms\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Af=(A/(1+A*Beta)) # Voltage gain is\n",
+ "Rif= (1+A*Beta)*Ri # input RESISTANCE with feedback in kiilo ohms\n",
+ "Rof=(Ro/(1+Beta*A))# output resistance with feedback in killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"Voltage gain is %.2f\"%Af)\n",
+ "print(\"input resistance with feedback = %.f k-ohm\"%Rif)\n",
+ "print(\"output resistance with feedback = %.2f k-ohm\"%Rof)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage gain is 83.33\n",
+ "input resistance with feedback = 18 k-ohm\n",
+ "output resistance with feedback = 3.33 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.15, Page No. 428"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# INPUT IMPEDANCE\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta=100.0 # gain\n",
+ "Rl=18.6 # load resistance in killo ohms\n",
+ "Re=9.3 # emitter resistance in killo ohms\n",
+ "Vbe=0.7 \n",
+ "Vcc=10.0 # collector voltage in volts\n",
+ "R1=10.0 # resistance in killo ohms\n",
+ "R2=10.0 # resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "V2= Vcc*(R2/(R1+R2)) # voltage at resistor R2 \n",
+ "Ve=V2-Vbe # volate at emitter\n",
+ "Ie=Ve/Re # Emitter current in milli ampere\n",
+ "re=(25/Ie) # AC emitter resistance\n",
+ "Re=(Rl*Re)/(Rl+Re) # effective emitter resistance in killo ohms\n",
+ "Zib=Beta*(Re*10**3+re)*10**-3\n",
+ "x=(R1*R2)/(R1+R2) # resistance in killo ohms\n",
+ "Zi=(Zib*x)/(Zib+x) # input impedance of the emitter follower in killo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"input impedance of the emitter follower = %.2f k-ohm\"%Zi)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "input impedance of the emitter follower = 4.96 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.16, Page No. 429"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "gm=4000.0 # gain in micro second\n",
+ "Ro=10.0 # output resistance in killo ohms\n",
+ "Rd=10.0 # resistance in killo ohms\n",
+ "R1=80.0 # resistance in killo ohms\n",
+ "R2=20.0 # resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Rl=(Ro*Rd)/(Ro+Rd) # load resistance in killo ohms\n",
+ "A= -(gm*10**-6*Rl*10**3) # gain without feedback\n",
+ "Beta= -(R2/(R1+R2)) # feedback factor\n",
+ "Af=(A/(1+A*Beta)) # gain with feedback\n",
+ "\n",
+ "#Result\n",
+ "print(\"gain without feedback is %.f\"%A)\n",
+ "print(\"gain with feedback is %.f\"%Af)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain without feedback is -20\n",
+ "gain with feedback is -4\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.17, Page No. 430"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1=1.8 # resistance in killo ohms\n",
+ "R2=0.2 # resistance in killo ohms\n",
+ "A=100000.0 # gain without feedback\n",
+ "\n",
+ "#Calculations\n",
+ "Beta= (R2/(R1+R2)) # feedback factor\n",
+ "Af1=(A/(1+A*Beta)) # gain with feedback\n",
+ "Af=(1/Beta) # AS A*Beta>>1\n",
+ "\n",
+ "#Result\n",
+ "print(\"gain with feedback AS A*Beta>>1 is %.f\"%Af)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain with feedback AS A*Beta>>1 is 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.18, Page No. 431"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Av,Rif,Avf,Rof\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=600.0 # Internal resistance in ohms\n",
+ "Rl=2.0 # Load resistance in killo ohms'\n",
+ "Rb=40.0 # base resistance in killo ohms\n",
+ "# H-paramters are\n",
+ "hie=5.0 # in killo ohms\n",
+ "hre=80.0\n",
+ "hfe=80.0\n",
+ "\n",
+ "#Calculations\n",
+ "RL1=(Rb*Rl)/(Rb+Rl) \n",
+ "Av=(-(hfe*(RL1*10**3/hie*10**3)))*10**-6\n",
+ "Av = math.floor(Av*100)/100\n",
+ "x=(Rb*10**3/(1-Av)) \n",
+ "Rif= (hie*10**3*x)/(hie*10**3+x)\n",
+ "Avf=(Av*Rif)/(Rif+Rs)\n",
+ "Rof=((Rb*10**3*(Rs+hie*10**3))/(Rs*hfe))*10**-3\n",
+ "Rof1=(Rof*Rl)/(Rof+Rl)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Voltage gain is %.2f\"%Av)\n",
+ "print(\"input resistance with feedback = %.3f ohm\"%(math.ceil(Rif*1000)/1000))\n",
+ "print(\"Overall Voltage gain is %.2f\"%Avf)\n",
+ "print(\"output resistance with feedback = %.1f k-ohm\"%Rof1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage gain is -30.48\n",
+ "input resistance with feedback = 1013.172 ohm\n",
+ "Overall Voltage gain is -19.14\n",
+ "output resistance with feedback = 1.4 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.19, Page No. 435"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# A,Beta,Rif,Af amd loop gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R1=1.0 # resistance in killo ohms\n",
+ "R2=20.0 # resistance in killo ohms\n",
+ "Re=100.0 # emitter resistance in ohms\n",
+ "# H-paramters are\n",
+ "hie=2.0 # in killo ohms\n",
+ "hfe=80.0\n",
+ "Rl=1.0 # load resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Ri=hie # input resistance in killo ohms\n",
+ "A= -(hfe*Rl*10**3)/(hie*10**3) \n",
+ "Beta=Re/(Rl*(10**3)) # GAIN\n",
+ "Rif= (hie*10**3+(1+hfe)*Re)*10**-3 # input resistance with feedback in killo ohms\n",
+ "Av=(-(hfe*(Rl*10**3/Rif*10**3)))*10**-6\n",
+ "BetaA= Beta*A # loop gain\n",
+ "BetaAd= 20*(math.log10(-BetaA)) # loop gain in dB\n",
+ "\n",
+ "#Result\n",
+ "print(\"Voltage gain without feedback is %.f\"%A)\n",
+ "print(\"Feedback ratio is given by %.1f\"%Beta)\n",
+ "print(\"input resistance with feedback = %.1f k-ohm\"%Rif)\n",
+ "print(\"Voltage gain with feedback is %.2f\"%Av)\n",
+ "print(\"loop gain is %.2f dB\"%BetaAd)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage gain without feedback is -40\n",
+ "Feedback ratio is given by 0.1\n",
+ "input resistance with feedback = 10.1 k-ohm\n",
+ "Voltage gain with feedback is -7.92\n",
+ "loop gain is 12.04 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.20, Page No. 436 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# voltage gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "re=7.5 # A.C. Resistance\n",
+ "R1=470.0 # resistance in ohms\n",
+ "Rc=2.2 # resistance in killo ohms\n",
+ "Re=510.0 # emitter resistance in ohms\n",
+ "# H-paramters are\n",
+ "hie=900.0 # in ohms\n",
+ "hfe=120.0\n",
+ "\n",
+ "#Calculations\n",
+ "A=-(hfe)/(hie+Re) # gain without feedback\n",
+ "Beta=-Re # gain\n",
+ "GF= (1+A*Beta) # gain factor\n",
+ "Af=A/(GF) # GAIN WITH FEEDBACK\n",
+ "Avf= Af*Rc*10**3 # voltage gain with feedback\n",
+ "Av= -(Rc*10**3/re) # voltage gain without feedback\n",
+ "\n",
+ "#Result\n",
+ "print(\"voltage gain with feedback is %.1f\"%Avf)\n",
+ "print(\"voltage gain without feedback is %.1f\"%Av)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "voltage gain with feedback is -4.2\n",
+ "voltage gain without feedback is -293.3\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.21, Page No. 436"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# change in overall gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta=0.01 # feedback\n",
+ "Ad= 60.0 # gain in dB\n",
+ "dA= 11.0 # open voltage gain\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "A= 10**(Ad/20) # gain\n",
+ "dAf= (1/(1+Beta*A))*dA # GAIN WITH FEEDBACK\n",
+ "\n",
+ "#Result\n",
+ "print(\"change in overall gain is = %.f %%\"%dAf)\n",
+ "print(\"\\nThe result clearly shows that the %% change reduction in overall gain\")\n",
+ "print(\"with negative feedback is reduced from 11%% to 1%%.\")\n",
+ "print(\"That is why we say that amplifier with negative feedback have stable gain.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "change in overall gain is = 1 %\n",
+ "\n",
+ "The result clearly shows that the %% change reduction in overall gain\n",
+ "with negative feedback is reduced from 11%% to 1%%.\n",
+ "That is why we say that amplifier with negative feedback have stable gain.\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.22, Page No. 437 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# input impedence with feedback\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A= 1000.0 # open voltage gain\n",
+ "Beta=0.005 # feedback ratio\n",
+ "Zi=2.0 # input impedance without feedback in kiilo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Zif= (1+A*Beta)*Zi # input impedance with feedback in kiilo ohms\n",
+ "\n",
+ "#Result\n",
+ "print(\"input impedance with feedback = %.f k-ohm\"%Zif)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "input impedance with feedback = 12 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.23, Page No.437 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback factor and change in overall gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Zo=12.6 # output impedance in killo ohms\n",
+ "Zofb=600.0 # output impedance in ohms with feedback\n",
+ "Ad= 60.0 # gain in dB\n",
+ "dA= 10.0 # open voltage gain\n",
+ "\n",
+ "#Calcualtions\n",
+ "A= 10**(Ad/20) # gain\n",
+ "Beta= ((Zo*10**3/Zofb)-1)/A\n",
+ "dAf= (1/(1+Beta*A))*dA # GAIN WITH FEEDBACK\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedbck factor is %.2f\"%Beta)\n",
+ "print(\"change in overall gain = %.3f %%\"%dAf)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedbck factor is 0.02\n",
+ "change in overall gain = 0.476 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.24, Page No. 437 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback fration ,overall voltage gain and output voltage\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A=5000.0 # gain wtihout feedback\n",
+ "R1=1.0 # resistance in killo ohms\n",
+ "R2=9.0 # resistance in killo ohms\n",
+ "Vs=2.0 # input voltage without feedback in milli volts\n",
+ "\n",
+ "#Calcualtions\n",
+ "Beta= R1/(R1+R2) # feedback fraction\n",
+ "Afb=round(A/(1+Beta*A))\n",
+ "Vo= round(Afb*Vs) # output voltage with feedback in milli volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback fraction = %.1f\"%Beta)\n",
+ "print(\"overall voltage gain = %.f\"%Afb)\n",
+ "print(\"output voltage with feedback = %.f mV\"%Vo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback fraction = 0.1\n",
+ "overall voltage gain = 10\n",
+ "output voltage with feedback = 20 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.25, Page No. 438"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback fraction ,overall voltage gain,input impedance ,output impedance and output volatge\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Zi=5.0 # input impedance in killo ohms\n",
+ "Zo=100.0 # input impedance in ohms\n",
+ "A=10000.0 # gain wtihout feedback\n",
+ "R1=2.0 # resistance in killo ohms\n",
+ "R2=18.0 # resistance in killo ohms\n",
+ "Vs=10.0 # input voltage without feedback in milli volts\n",
+ "\n",
+ "#Calculations\n",
+ "Beta= R1/(R1+R2) # feedback fraction\n",
+ "Afb=round(A/(1+Beta*A)) # overall gain\n",
+ "Zif= round((1+A*Beta)*Zi*10**-3) # input impedance with feedback in mega ohms\n",
+ "Zof= Zo/(1+Beta*A) # OUTPUT impedance with feedback in ohms\n",
+ "Vo= round(Vs/Afb) # output voltage with feedback in milli volts\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback fraction = %.1f\"%Beta)\n",
+ "print(\"overall voltage gain = %.f\"%Afb)\n",
+ "print(\"input impedance with feedback = %.f M-ohm\"%Zif)\n",
+ "print(\"output impedance with feedback= %.1f ohm\"%Zof)\n",
+ "print(\"output voltage with feedback = %.f mV\"%Vo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback fraction = 0.1\n",
+ "overall voltage gain = 10\n",
+ "input impedance with feedback = 5 M-ohm\n",
+ "output impedance with feedback= 0.1 ohm\n",
+ "output voltage with feedback = 1 mV\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.26, Page No. 438"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "a=60.0 # OPEN LOOP VOLTAGE GAIN IN dB\n",
+ "A= 10**(a/20) # open voltage gain\n",
+ "Beta=0.009 # feedback ratio\n",
+ "\n",
+ "#Calculations\n",
+ "Af= (A/(1+(Beta*A))) # GAIN WITH FEEDBACL\n",
+ "AfdB= 20*(math.log10(Af))# gain with feedback in dB\n",
+ "\n",
+ "#Result\n",
+ "print(\"gain with feedback = %.2f\"%AfdB)\n",
+ "#Answer for the gain with feedback is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "gain with feedback = 40.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.27, Page No. 439"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# reduction in distortion\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "a=54.8 # OPEN LOOP VOLTAGE GAIN IN dB\n",
+ "A= 10**(a/20) # open voltage gain\n",
+ "Beta=0.02 # feedback ratio\n",
+ "\n",
+ "#Calculations\n",
+ "Af= (A/(1+(Beta*A))) # GAIN WITH FEEDBACL\n",
+ "dA= (1/(1+Beta*A))*100# percentage change in distortion \n",
+ "\n",
+ "#Result\n",
+ "print(\"percentage reduction in distortion is %.2f%%\"%(math.floor(dA*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "percentage reduction in distortion is 8.33%\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.28, Page No. 439 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# gain with feedback ,input impedance and output impedance \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Zi=1.0 # input impedance in killo ohms\n",
+ "Zo=40.0 # input impedance in killo ohms\n",
+ "A=10000.0 # gain wtihout feedback\n",
+ "Beta=0.05 # gain\n",
+ "\n",
+ "#Calculations\n",
+ "Afb=(A/(1+Beta*A))\n",
+ "Zif= ((1+A*Beta)*Zi)\n",
+ "Zof= (Zo*10**3/(1+Beta*A))\n",
+ "\n",
+ "#Result\n",
+ "print(\"overall voltage gain = %.f\"%Afb)\n",
+ "print(\"input impedance with feedback = %.f M-ohm\"%Zif)\n",
+ "print(\"output impedance with feedback = %.f ohms\"%Zof)\n",
+ "#Answer in the book for input impedance is wrong"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "overall voltage gain = 20\n",
+ "input impedance with feedback = 501 M-ohm\n",
+ "output impedance with feedback = 80 ohms\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.29, Page No. 439"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "F2=16.0 # upper cutoff frequency in killo hertz without feedback\n",
+ "F1=40.0 # upper cutoff frequency in hertz without feedback\n",
+ "A= 800.0 # open loop voltage gain\n",
+ "Beta=0.02 # feedback ratio\n",
+ "\n",
+ "#CAlaculations\n",
+ "Afb= (A/(1+(Beta*A))) # GAIN WITH FEEDBACk\n",
+ "F2f=F2*(1+A*Beta) # uppor cutoff frequency with feedback in killo hertz\n",
+ "F1f=F1/(1+A*Beta)*10**-3 # lower cutoff frequency with feedback in killo hertz\n",
+ "Bw=F2-F1*10**-3 # bandwidth without feedback in killo hertz\n",
+ "Bwf=round(F2f-F1f) # bandwidth with feedback in killo hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"bandwidth without feedback = %.2f kHz\"%Bw)\n",
+ "print(\"bandwidth with feedback = %.f\"%Bwf)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "bandwidth without feedback = 15.96 kHz\n",
+ "bandwidth with feedback = 272\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.30, Page No. 440"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# bandwidth\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "BW=10.0 # bandwidth without feedback in killo hertz\n",
+ "A= 100.0 # open loop voltage gain\n",
+ "Beta=0.1 # feedback ratio\n",
+ "\n",
+ "#Calculations\n",
+ "Afb= (A/(1+(Beta*A))) # GAIN WITH FEEDBACk\n",
+ "Bwf=round(BW*(1+Beta*A))# bandwidth with feedback in killo hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback gain = %.2f\"%Afb)\n",
+ "print(\"bandwidth with feedback = %.f kHz\"%Bwf)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback gain = 9.09\n",
+ "bandwidth with feedback = 110 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.31, Page No. 440 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# gain and harmonic distortion\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "A2= 200.0 # open loop voltage gain\n",
+ "Beta=0.1 # feedback ratio\n",
+ "D2=0.02 # first stage distortion\n",
+ "\n",
+ "#Calculations\n",
+ "D2d= (D2/(1+Beta*A2))*100\n",
+ "A2d=A2/(1+Beta*A2)\n",
+ "A1=round(A2/A2d)\n",
+ "\n",
+ "#Result\n",
+ "\n",
+ "print(\"second stage harmonic distortion , A2' %.2f%%\"%(D2d*100))\n",
+ "print(\"gain of first stage, A1 = %.f\"%A1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "second stage harmonic distortion , A2' 9.52%\n",
+ "gain of first stage, A1 = 21\n"
+ ]
+ }
+ ],
+ "prompt_number": 55
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.32, Page No.453 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# pole frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R2=2*10**5 # effective resistance in ohms\n",
+ "Av2=1000.0 # gain of second stage\n",
+ "Cf=20.0 # feedback capacitor in pico farad\n",
+ "\n",
+ "#Calculations\n",
+ "Cm=(1+Av2)*Cf \n",
+ "fp1= 1/(2*math.pi*R2*Cm*10**-12)\n",
+ "\n",
+ "#Result\n",
+ "print(\"pole frequency = %.2f Hz\"%fp1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "pole frequency = 39.75 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 57
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_7.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_7.ipynb
new file mode 100755
index 00000000..4c2dad4e
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_7.ipynb
@@ -0,0 +1,1465 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Oscillators"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1, Page No. 470"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "c=450.0 # capacitance of tunned circuit in pico farad\n",
+ "L=29.3 # INDUCTANCE of tunned circuit in micro henry\n",
+ "\n",
+ "#Calculations\n",
+ "fo=(1/(2*math.pi*math.sqrt(L*10**-6*c*10**-12)))*10**-6\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.2f MHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 1.39 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2, Page No. 470 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# tunned capacitance range of tunned circuit\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "L=100.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "fo1=500.0 # tunned frequency in killo hertz\n",
+ "fo2=1500.0 # tunned frequency in killo hertz\n",
+ "\n",
+ "#Calculations\n",
+ "C1= (1/(4*math.pi**2*(fo1*10**3)**2*L*10**-6)) # tunned capacitance\n",
+ "C2= (1/(4*math.pi**2*(fo2*10**3)**2*L*10**-6)) # tunned capacitance\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned capacitance range of tunned circuit in pF is %.1f - %.f\"%(C2*10**12,C1*10**12))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned capacitance range of tunned circuit in pF is 112.6 - 1013\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3, Page No. 470"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# TRANSFORMER WINDING RATIO\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=12.0 # collector vltage\n",
+ "Po=88.0 # power output in milli watt\n",
+ "Ploss=8.0 # power losses in milli watt\n",
+ "gm=10.0 # transconductance in milli ampere per volt\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Pi= Po+Ploss # input power in milli watt\n",
+ "Ic= Pi/Vcc # collector current in milli ampere\n",
+ "Vb= Ic/(gm) # base VOLTAGE \n",
+ "TR=Vcc/Vb # transfomer turn ratio\n",
+ "\n",
+ "#Result\n",
+ "print(\"transformer winding turn-ratio is %.f\"%TR)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "transformer winding turn-ratio is 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.4, Page No. 478"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C1=0.005 # capacitance of tunned circuit in micro farad\n",
+ "C2=0.01 # capacitance of tunned circuit in micro farad\n",
+ "L=100.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "\n",
+ "#Calculations\n",
+ "C=(C1*C2)/(C1+C2) # total capacitance in micro farad\n",
+ "C = math.floor(C*10**4)/10**4\n",
+ "fo=(1/(2*math.pi*math.sqrt(L*10**-6*C*10**-6))) # tunned frequency in killo hertz\n",
+ "\n",
+ "#Result\n",
+ "print C\n",
+ "print(\"tunned frequency = %.2f kHz\"%(fo*10**-3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0.0033\n",
+ "tunned frequency = 277.05 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5, Page No. 478"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C1=500.0 # capacitance of tunned circuit in PICO farad\n",
+ "C2=500.0 # capacitance of tunned circuit in pico farad\n",
+ "L=1.0 #INDUCTANCE of tunned circuit in milli henry\n",
+ "\n",
+ "#Calculations\n",
+ "C=(C1*C2)/(C1+C2) # total capacitance in micro farad\n",
+ "fo=(1/(2*math.pi*math.sqrt(L*10**-3*C*10**-12)))*10**-3 #tunned frequency in killo hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.1f kHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 318.3 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.6, Page No. 478"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# tunned capacitance and inductance of tunned circuit\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fo=500.0 # tunned frequency in killo hertz\n",
+ "L3=1.0 # assume inductance \n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "LC= (1/(4*math.pi**2*(fo*10**-3)**2)) \n",
+ "C=LC/(L3*10**-3) # capacitance in pico farad\n",
+ "C1= 2*C \n",
+ "C2=C1\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"inductance = %.f mH\"%L3)\n",
+ "print(\"tunned capacitance C1 of tunned circuit = %.1f pF\"%C1)\n",
+ "print(\"tunned capacitance C2 of tunned circuit = %.1f pF\"%C2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "inductance = 1 mH\n",
+ "tunned capacitance C1 of tunned circuit = 202.6 pF\n",
+ "tunned capacitance C2 of tunned circuit = 202.6 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8, Page No.484"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# tunned capacitance of tunned circuit\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fo1=50.0 # tunned frequency in killo hertz\n",
+ "L1=100.0 # inductance in micro henry\n",
+ "L2=100.0 # inductance in micro henry\n",
+ "\n",
+ "#Calculations\n",
+ "C= (1/(4*math.pi**2*(fo1*10**-6)**2*(L1+L2)*10**-6))*10**-12\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned capacitance tunned circuit = %.5f micro-F\"%C)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned capacitance tunned circuit = 0.05066 micro-F\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9, Page No. 485 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C=0.2 # capacitance of tunned circuit in MICRO farad\n",
+ "L1=0.5 # INDUCTANCE of tunned circuit in milli henry\n",
+ "L2=1.0 # INDUCTANCE of tunned circuit in milli henry\n",
+ "\n",
+ "#Calculaions\n",
+ "fo=(1/(2*math.pi*math.sqrt((L1+L2)*10**-3*C*10**-6)))\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.1f kHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 9188.8 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10, Page No. 485"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C=100.0 # capacitance of tunned circuit in pico farad\n",
+ "L1=1.0 # INDUCTANCE of tunned circuit in milli henry\n",
+ "L2=0.1 # INDUCTANCE of tunned circuit in milli henry\n",
+ "M = 0.05 # Mutual INDUCTANCE of tunned circuit in milli henry \n",
+ "\n",
+ "#Calculations\n",
+ "fo=(1/(2*math.pi*math.sqrt((L1+L2+2*M)*10**-3*C*10**-12))) # tunned frequency in killo hertz\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.f kHz\"%(fo/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 459 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.11, Page No.485"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback ratio\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Af=40.0 # gain wtih feedback\n",
+ "Vi=2.4 # input voltage\n",
+ "Vif=0.1 # input voltage with feedback\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "A= Af*(Vi/Vif) # gain without feedback\n",
+ "Beta= (1-(A/Af))/A # feedback ratio\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback ratio = %.3f\"%Beta)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback ratio = -0.024\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.12, Page No.488"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cs=0.08 # capacitance of tunned circuit in pico farad\n",
+ "Ls=0.8 # series INDUCTANCE of tunned circuit in henry\n",
+ "Cp=1.0 # parallel capacitance in pico farad\n",
+ "Rs=5.0 # SERIES RESISTANCE IN KILLO OHMS\n",
+ "\n",
+ "#Calculations\n",
+ "fs=round((1/(2*math.pi*math.sqrt(Ls*Cs*10**-12)))*10**-3) # series tunned frequency in killo hertz\n",
+ "fp=round(((1/(2*math.pi))*math.sqrt((1+Cs/Cp)/(Ls*Cs*10**-12)))*10**-3) # parralel tunned frequency in killo hertz\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"series tunned frequency = %.f kHz\"%fs)\n",
+ "print(\"parallel tunned frequency = %.f kHz\"%fp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "series tunned frequency = 629 kHz\n",
+ "parallel tunned frequency = 654 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.13, Page No. 488"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# quality factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "f=450.0 # resonant frequency in killo hertz\n",
+ "L=4.2 # inductnace in henry\n",
+ "R=600.0 # resistance in ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Q= (2*math.pi*f*10**3*L)/R\n",
+ "\n",
+ "#Result\n",
+ "print(\"quality factor is %.f\"%Q)\n",
+ "#Answer in the book is slightly different"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "quality factor is 19792\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.14, Page No.489"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cs=0.01 # capacitance of tunned circuit in pico farad\n",
+ "Ls=0.8 # series INDUCTANCE of tunned circuit in henry\n",
+ "Cp=20.0 # parallel capacitance in pico farad\n",
+ "Rs=5.0 # SERIES RESISTANCE IN KILLO OHMS\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "fs=((1/(2*math.pi*math.sqrt(Ls*Cs*10**-12)))*10**-3) # series tunned frequency in killo hertz\n",
+ "fp=(((1/(2*math.pi))*math.sqrt((1+Cs/Cp)/(Ls*Cs*10**-12)))*10**-3)# parralel tunned frequency in killo hertz\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Series tunned frequency = %.2f kHz\"%(math.floor(fs*100)/100))\n",
+ "print(\"Parallel tunned frequency = %.2f KHz\"%fp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Series tunned frequency = 1779.40 kHz\n",
+ "Parallel tunned frequency = 1779.85 KHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.15, Page No.489"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency,percentage change and quality factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cs=0.065 # capacitance of tunned circuit in pico farad\n",
+ "Ls=0.33 # series INDUCTANCE of tunned circuit in henry\n",
+ "Cp=1.0 # parallel capacitance in pico farad\n",
+ "Rs=5.5 # SERIES RESISTANCE IN KILLO OHMS\n",
+ "\n",
+ "#Calculation\n",
+ "fs=round((1/(2*math.pi*math.sqrt(Ls*Cs*10**-12)))*10**-3) # series tunned frequency in killo hertz\n",
+ "fp=math.ceil(((1/(2*math.pi))*math.sqrt((1+Cs/Cp)/(Ls*Cs*10**-12)))*10**-3) # parralel tunned frequency in killo hertz\n",
+ "Pc= ((fp-fs)/fs)*100 # percentage by which series resonant frequency exceeds the parallel resonant frequency\n",
+ "Qs= ((2*math.floor(math.pi*100)*fs*10**3*Ls/100)/(Rs*10**3)) # quality factor with series resonant frequency\n",
+ "Qp= ((2*math.floor(math.pi*100)*fp*10**3*Ls/100)/(Rs*10**3)) # quality factor with parallled resonant frequency\n",
+ "\n",
+ "#Result\n",
+ "print(\"series tunned frequency = %.f kHz\"%fs)\n",
+ "print(\"parallel tunned frequency = %.f kHz\"%fp)\n",
+ "print(\"percentage by which series resonant frequency exceeds the parallel resonant frequency = %.1f%%\"%Pc)\n",
+ "print(\"quality factor with series resonant frequency is %.2f\"%Qs)\n",
+ "print(\"quality factor with paralled resonant frequency is %.2f\"%(math.floor(Qp*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "series tunned frequency = 1087 kHz\n",
+ "parallel tunned frequency = 1122 kHz\n",
+ "percentage by which series resonant frequency exceeds the parallel resonant frequency = 3.2%\n",
+ "quality factor with series resonant frequency is 409.58\n",
+ "quality factor with paralled resonant frequency is 422.76\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.16, Page No.490"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C1=120.0 # capacitance of tunned circuit in PICO farad\n",
+ "C2=1500.0 # capacitance of tunned circuit in pico farad\n",
+ "C3=15.0 # capacitance of tunned circuit in pico farad\n",
+ "L=10.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Cx=(C1*C2)/(C1+C2) # capacitance in pico farad\n",
+ "Ct=(Cx*C3)/(Cx+C3) # total capacitance in pico farad\n",
+ "fo=(1/(2*math.pi*math.sqrt(L*10**-6*Ct*10**-12)))*10**-6 # tunned frequency in mega hertz\n",
+ "foa= (1/(2*math.pi*math.sqrt(L*10**-6*C3*10**-12)))*10**-6 # actual resonant frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.2f MHz\"%fo)\n",
+ "print(\"actual resonant frequency = %.2f MHz\"%foa)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 13.84 MHz\n",
+ "actual resonant frequency = 12.99 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.17, Page No. 490"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R=500.0 # resistance in ohms\n",
+ "C1=0.01 # capacitance of tunned circuit in pico farad\n",
+ "C2=10.0 # capacitance of tunned circuit in pico farad\n",
+ "L=0.06 # INDUCTANCE of tunned circuit in henry\n",
+ "\n",
+ "#Calculations\n",
+ "C=(C1*C2)/(C1+C2) # total capacitance in micro farad\n",
+ "fs=((1/(2*math.pi*math.sqrt(L*C1*10**-12)))*10**-6) # series tunned frequency in mega hertz\n",
+ "C=(C1*C2)/(C1+C2) # total capacitance in pico farad\n",
+ "fp=(1/(2*math.pi*math.sqrt(L*C*10**-12))*10**-6) #parralel tunned frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"series tunned frequency = %.3f MHz\"%fs)\n",
+ "print(\"parallel tunned frequency = %.4f MHz\"%fp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "series tunned frequency = 6.497 MHz\n",
+ "parallel tunned frequency = 6.5007 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.18, Page No. 491"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C=100.0 # capacitance of tunned circuit in pico farad\n",
+ "L1=50.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "L2=50.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "\n",
+ "#Calculations\n",
+ "fo=(1/(2*math.pi*math.sqrt((L1+L2)*10**-6*C*10**-12)))*10**-6 # tunned frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"Tunned frequency = %.2f MHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tunned frequency = 1.59 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.19, Page No.491"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C1=120.0 # capacitance of tunned circuit in PICO farad\n",
+ "C2=1500.0 # capacitance of tunned circuit in pico farad\n",
+ "L=10.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "\n",
+ "#Calculation\n",
+ "C=(C1*C2)/(C1+C2) # total capacitance in pico farad\n",
+ "fo=(1/(2*math.pi*math.sqrt(L*10**-6*C*10**-12)))*10**-6 # tunned frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.2f MHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 4.77 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.20, Page No.491"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C1=120.0 # capacitance of tunned circuit in PICO farad\n",
+ "C2=1500.0 # capacitance of tunned circuit in pico farad\n",
+ "C3=15.0 # capacitance of tunned circuit in pico farad\n",
+ "L=10.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Cx=(C1*C2)/(C1+C2) # capacitance in pico farad\n",
+ "Ct=(Cx*C3)/(Cx+C3) # total capacitance in pico farad\n",
+ "fo=(1/(2*math.pi*math.sqrt(L*10**-6*Ct*10**-12)))*10**-6 # tunned frequency in mega hertz\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.2f MHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 13.84 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.21, Page No.497"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C=100.0 # capacitance in pico farad\n",
+ "R=800.0 # resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "fo=round(1/(2*math.pi*R*10**3*C*10**-12*math.sqrt(6))) # RESONANT FREQUENCY IN HERTZ\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Resonant frequency = %.f Hz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resonant frequency = 812 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.22, Page No.498"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "w=2*10**3 # in radiand per second\n",
+ "\n",
+ "#Calculations\n",
+ "f= round(w/(2*math.pi)) # resonant frequency\n",
+ "X=(((16*10**9*4*w**2*10**3))/((4*w**2*10**3)**2))\n",
+ "\n",
+ "#Result\n",
+ "print(\"resonant frequency = %.f Hz\"%f)\n",
+ "print(\"oscillations are sustained = %.f\"%X)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resonant frequency = 318 Hz\n",
+ "oscillations are sustained = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.23, Page No. 502"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Design R-C phase shift oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fo=1.0 # resonant frequency in killo hertz\n",
+ "Av= 29.0 # voltage gain\n",
+ "Vcc=10.0 # collector voltage\n",
+ "Ib=0.5 # maximum base current in micro ampere\n",
+ "Rf2=180.0 # standard resistance in killo ohms\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "I1=100*Ib # assume current in micro ampere\n",
+ "Vosat= 0.9*Vcc # saturation voltage assume\n",
+ "V1=Vosat/Av # voltage for sustained oscillations\n",
+ "R1=(V1/(I1*10**-6))*10**-3 # RESISTANCE IN KILLO PHMS\n",
+ "Rf1=Av*R1 # resistance in killo ohms\n",
+ "R3=Rf2 \n",
+ "R=R1 \n",
+ "C=(1/(2*math.pi*R*10**3*fo*10**3*math.sqrt(6)))*10**6 \n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Resistance R1 for the R-C Phase shift oscillator = %.1f k-ohm\"%R)\n",
+ "print(\"Resistance Rf for the R-C Phase shift oscillator = %.f k-ohm\"%R3)\n",
+ "print(\"Capacitance for the R-C Phase shift oscillator = %.2f micro-F\"%C)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance R1 for the R-C Phase shift oscillator = 6.2 k-ohm\n",
+ "Resistance Rf for the R-C Phase shift oscillator = 180 k-ohm\n",
+ "Capacitance for the R-C Phase shift oscillator = 0.01 micro-F\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.24, Page No. 502"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain resistance and Design R-C phase shift oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Mu=55.0\n",
+ "rd=5.5 # resistane in killo ohms\n",
+ "fo=5.0 # resonant frequency in killo hertz\n",
+ "A= 29.0 # voltage gain\n",
+ "R=30.0 # assume Resistance in killo ohms\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Rd= (29*rd)/(Mu-A) # resistance in killo ohms\n",
+ "RC=((1/(2*math.pi*fo*10**3*math.sqrt(6)))*10**6) \n",
+ "C=(RC*10**-6/(30*10**3)*10**12)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"drain resistance = %.2f k-ohm\"%Rd)\n",
+ "print(\"R-C time constant = %.f pico-sec\"%(math.ceil(RC)))\n",
+ "print(\"Capacitance for the R-C Phase shift oscillator = %.f pF\"%C)\n",
+ "#Answer for capacitance is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "drain resistance = 6.13 k-ohm\n",
+ "R-C time constant = 13 pico-sec\n",
+ "Capacitance for the R-C Phase shift oscillator = 433 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.25, Page No.503"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Vf/Vo,frequency of oscillations and minimum gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta=1.0/29\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "VfVo= (Beta+1)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Voltage gain = %f\"%VfVo)\n",
+ "print(\"\\nf=1/(2*%pi*R*C*sqrt(6)) frequency of oscillations\")\n",
+ "print(\"\\nAs gain is more than one oscillations will be sustained\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage gain = 1.034483\n",
+ "\n",
+ "f=1/(2*%pi*R*C*sqrt(6)) frequency of oscillations\n",
+ "\n",
+ "As gain is more than one oscillations will be sustained\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.26, Page No. 510"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# design wein bridge oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=15.0 # collector voltage\n",
+ "f=10.0 # frequency of oscillation in killo hertz\n",
+ "I=1.0 # current in millo ampere\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Vo=Vcc-1 # maximum output voltage\n",
+ "x=Vo/I # resistance in killo ohms\n",
+ "R4=x/3 # resistance in killo ohms\n",
+ "R3= 2*R4 # resistance in killo ohms\n",
+ "R4_s = 4.7 # Standard value\n",
+ "R3_s = 10 # Standard value \n",
+ "A= (1+(R3_s/R4_s)) # amplifier gain\n",
+ "R=R4_s # resistance in killo ohms\n",
+ "C=(1/(2*math.pi*f*10**3*R*10**3))*10**9\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Amlifier gain = %.2f\"%(math.floor(A*100)/100))\n",
+ "print(\"resistance R4 = %.1f k-ohm (use 4.7 k-ohm standard value)\"%R)\n",
+ "print(\"resistance R3 = %.1f k-ohm (use 10 k-ohm standard value)\"%(math.ceil(R3*10)/10))\n",
+ "print(\"Capacitance = %.2f nF\"%(math.floor(C*100)/100))\n",
+ "#print(\"this is name as example 7.27 in the book\" )"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Amlifier gain = 3.12\n",
+ "resistance R4 = 4.7 k-ohm (use 4.7 k-ohm standard value)\n",
+ "resistance R3 = 9.4 k-ohm (use 10 k-ohm standard value)\n",
+ "Capacitance = 3.38 nF\n"
+ ]
+ }
+ ],
+ "prompt_number": 70
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.27 Page No.511"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# sustained oscillations and output frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R4=5.1 # resistance in killo ohms\n",
+ "R3=12.0 # resistance in killo ohms\n",
+ "C=1.0 # capacitance in nano farad\n",
+ "\n",
+ "#Calculations\n",
+ "A= (1+(R3/R4)) # amplifier gain\n",
+ "R=R4 # resistance in killo ohms\n",
+ "fo= (1/(2*math.pi*C*10**-9*R*10**3))*10**-3\n",
+ "\n",
+ "#Result\n",
+ "print(\"Amlifier gain is %.2f. It is greater than 1 so circuit will oscillate.\"%A)\n",
+ "print(\"Oscillation frequency = %.1f kHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Amlifier gain is 3.35. It is greater than 1 so circuit will oscillate.\n",
+ "Oscillation frequency = 31.2 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 75
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.29, Page No.514"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# design wein bridge oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # collector voltage\n",
+ "f=10.0 # frequency of oscillation in killo hertz\n",
+ "I=500.0 # current in micro ampere\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Vo=Vcc-1 # maximum output voltage\n",
+ "x=(Vo/I)*10**3 # resistance in killo ohms\n",
+ "R4=x/3 # resistance in killo ohms\n",
+ "Rf= 2*R4 # resistance in killo ohms\n",
+ "R4_s = 5.6 # standard value\n",
+ "R=R4_s # resistance in killo ohms\n",
+ "C=(1/(2*math.pi*f*10**3*R*10**3))*10**12\n",
+ "\n",
+ "#Resulr\n",
+ "print(\"Resistance R = R1 = %.f k-ohm(uswe 5.6k as standard value)\"%R)\n",
+ "print(\"resistance Rf = %.f k-ohm\"%Rf)\n",
+ "print(\"Capacitance = %.f nF(use 2700 nF as standard value)\"%C)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance R = R1 = 6 k-ohm(uswe 5.6k as standard value)\n",
+ "resistance Rf = 12 k-ohm\n",
+ "Capacitance = 2842 nF(use 2700 nF as standard value)\n"
+ ]
+ }
+ ],
+ "prompt_number": 85
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.30, Page No.514"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print(\"Theoretical example\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Theoretical example\n"
+ ]
+ }
+ ],
+ "prompt_number": 87
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.31, Page No.515"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print(\"Theoretical example\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.32, Page No. 517"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Design R-C phase shift oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vce=5.0 # in volts\n",
+ "RE=1.0 # emitter reistsance in killo ohms\n",
+ "Vbe=0.7 # in volts\n",
+ "Ie=1.0 # emitter current in mA\n",
+ "Re=1.0 # EMITTER RESISTANCE IN KILLO OHMS\n",
+ "f=100.0 # oscillaor frequency in killo hertz\n",
+ "hfe=100.0\n",
+ "hie=1.0 # in killo ohms\n",
+ "Vc=5.0 # in volts\n",
+ "Ic=1.0 # current in mili ampere\n",
+ "Vcc=20.0 # in volts\n",
+ "R=10.0 # resistane in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Rc=(Vcc-Vce-Ie*Re)/(Ic) # collector resistance in killo ohms is\n",
+ "k= Rc/R\n",
+ "C= ((1/(2*math.pi*R*10**3*f*10**3*math.sqrt(6+(4*1.4)))))*10**12\n",
+ "R3= R-hie # resistance in kiilo ohms\n",
+ "Vb= (Vbe+Ie*Re) # voltage at base\n",
+ "R2=R \n",
+ "I2=Vb/R2 # in mA\n",
+ "V2=(Vcc-R2*I2) # voltage drop across R2\n",
+ "IR1= (I2+(1.0/100)) # CURRENT ACROOS R1\n",
+ "R1= V2/(IR1) \n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter resistance = %.f k-ohm\"%Re)\n",
+ "print(\"collector resistance = %.f k-ohm\"%Rc)\n",
+ "print(\"resistance R = %.f k-ohm\"%R)\n",
+ "print(\"Capacitance = %.1f pF\"%C)\n",
+ "print(\"resistance(R3) = %.f k-ohm\"%R3)\n",
+ "print(\"resistance(R2) = %.f k-ohm\"%R2)\n",
+ "print(\"resistance(R1) = %.f k-ohm\"%R1)\n",
+ "#Answer for Resistance (R1) is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter resistance = 1 k-ohm\n",
+ "collector resistance = 14 k-ohm\n",
+ "resistance R = 10 k-ohm\n",
+ "Capacitance = 46.7 pF\n",
+ "resistance(R3) = 9 k-ohm\n",
+ "resistance(R2) = 10 k-ohm\n",
+ "resistance(R1) = 102 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 91
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.33, Page No.518"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Design R-C phase shift oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "rd=40.0 # resistane in killo ohms\n",
+ "fo=1.0 # resonant frequency in killo hertz\n",
+ "gm= 5000.0 # in killo mh\n",
+ "R=10.0 # assume Resistance in killo ohms\n",
+ "Av=29.0 # VOLTAGE GAIN\n",
+ "Vdd=12.0 # drain voltage\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "C=((1/(2*math.pi*fo*10**3*R*10**3*math.sqrt(6)))*10**9)# C in nano farad\n",
+ "Rl= (Av/gm*10**-6)*10**9 # load resistance in killo ohms\n",
+ "Rl = math.ceil(Rl)\n",
+ "Rd= ((Rl*rd)/(rd-Rl)) # drain resistance in killo ohms\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Drain Resistance = %.2f k-ohm\"%Rd)\n",
+ "print(\"Capacitance for the R-C Phase shift oscillator = %.1f nF\"%C) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Drain Resistance = 7.06 k-ohm\n",
+ "Capacitance for the R-C Phase shift oscillator = 6.5 nF\n"
+ ]
+ }
+ ],
+ "prompt_number": 96
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.34, Page No.518"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# design wein bridge oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R=100.0 # ASSUME RESSITANCE IN KILO OHMS\n",
+ "fo1=10.0 # tunned frequency in killo hertz\n",
+ "fo2=100.0 # tunned frequency in hertz\n",
+ "\n",
+ "#Calculations\n",
+ "C1= (1/(2*math.pi*R*10**3*fo1*10**3))*10**9 # tunned capacitance\n",
+ "C2= (1/(2*math.pi*R*10**3*fo2))*10**9 # tunned capacitance\n",
+ "\n",
+ "#Result\n",
+ "print(\"Tunned capacitance C1 range of tunned circuit = %.3f nF\"%C1)\n",
+ "print(\"Tunned capacitance C2 range of tunned circuit = %.1f nF\"%C2)\n",
+ "#Answer slightly different than book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tunned capacitance C1 range of tunned circuit = 0.159 nF\n",
+ "Tunned capacitance C2 range of tunned circuit = 15.9 nF\n"
+ ]
+ }
+ ],
+ "prompt_number": 105
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.35, Page No. 519 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency and quality factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cs=0.06 # capacitance of tunned circuit in pico farad\n",
+ "Ls=0.5 # series INDUCTANCE of tunned circuit in henry\n",
+ "Cp=1.0 # parallel capacitance in pico farad\n",
+ "Rs=5.0 # SERIES RESISTANCE IN KILLO OHMS\n",
+ "\n",
+ "#Calculations\n",
+ "fs=((1/(2*math.pi*math.sqrt(Ls*Cs*10**-12)))*10**-3) # series tunned frequency in killo hertz\n",
+ "fp=(((1/(2*math.pi))*math.sqrt((1+Cs/Cp)/(Ls*Cs*10**-12)))*10**-3) # parralel tunned frequency in killo hertz\n",
+ "Pc= ((fp-fs)/fs)*100 # percentage by which series resonant frequency exceeds the parallel resonant frequency\n",
+ "Qs= round((2*math.pi*fs*10**3*Ls)/(Rs*10**3)) # quality factor with series resonant frequency\n",
+ "Qp= round((2*math.pi*fp*10**3*Ls)/(Rs*10**3)) # quality factor with parallled resonant frequency\n",
+ "\n",
+ "#Result\n",
+ "print(\"Series tunned frequency = %.1f kHz\"%fs)\n",
+ "print(\"Quality factor with series resonant frequency is %.f\"%Qs)\n",
+ "print(\"\\nParallel tunned frequency = %.f kHz\"%fp)\n",
+ "print(\"Quality factor with paralled resonant frequency is %.f\"%Qp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Series tunned frequency = 918.9 kHz\n",
+ "Quality factor with series resonant frequency is 577\n",
+ "\n",
+ "Parallel tunned frequency = 946 kHz\n",
+ "Quality factor with paralled resonant frequency is 594\n"
+ ]
+ }
+ ],
+ "prompt_number": 111
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_7_1.ipynb b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_7_1.ipynb
new file mode 100755
index 00000000..4c2dad4e
--- /dev/null
+++ b/Solid_State_Devices_and_Circuits_by_Sanjay_Sharma/SSDC_Chapter_7_1.ipynb
@@ -0,0 +1,1465 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Oscillators"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1, Page No. 470"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "c=450.0 # capacitance of tunned circuit in pico farad\n",
+ "L=29.3 # INDUCTANCE of tunned circuit in micro henry\n",
+ "\n",
+ "#Calculations\n",
+ "fo=(1/(2*math.pi*math.sqrt(L*10**-6*c*10**-12)))*10**-6\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.2f MHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 1.39 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2, Page No. 470 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# tunned capacitance range of tunned circuit\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "L=100.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "fo1=500.0 # tunned frequency in killo hertz\n",
+ "fo2=1500.0 # tunned frequency in killo hertz\n",
+ "\n",
+ "#Calculations\n",
+ "C1= (1/(4*math.pi**2*(fo1*10**3)**2*L*10**-6)) # tunned capacitance\n",
+ "C2= (1/(4*math.pi**2*(fo2*10**3)**2*L*10**-6)) # tunned capacitance\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned capacitance range of tunned circuit in pF is %.1f - %.f\"%(C2*10**12,C1*10**12))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned capacitance range of tunned circuit in pF is 112.6 - 1013\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3, Page No. 470"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# TRANSFORMER WINDING RATIO\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=12.0 # collector vltage\n",
+ "Po=88.0 # power output in milli watt\n",
+ "Ploss=8.0 # power losses in milli watt\n",
+ "gm=10.0 # transconductance in milli ampere per volt\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Pi= Po+Ploss # input power in milli watt\n",
+ "Ic= Pi/Vcc # collector current in milli ampere\n",
+ "Vb= Ic/(gm) # base VOLTAGE \n",
+ "TR=Vcc/Vb # transfomer turn ratio\n",
+ "\n",
+ "#Result\n",
+ "print(\"transformer winding turn-ratio is %.f\"%TR)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "transformer winding turn-ratio is 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.4, Page No. 478"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C1=0.005 # capacitance of tunned circuit in micro farad\n",
+ "C2=0.01 # capacitance of tunned circuit in micro farad\n",
+ "L=100.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "\n",
+ "#Calculations\n",
+ "C=(C1*C2)/(C1+C2) # total capacitance in micro farad\n",
+ "C = math.floor(C*10**4)/10**4\n",
+ "fo=(1/(2*math.pi*math.sqrt(L*10**-6*C*10**-6))) # tunned frequency in killo hertz\n",
+ "\n",
+ "#Result\n",
+ "print C\n",
+ "print(\"tunned frequency = %.2f kHz\"%(fo*10**-3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0.0033\n",
+ "tunned frequency = 277.05 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5, Page No. 478"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C1=500.0 # capacitance of tunned circuit in PICO farad\n",
+ "C2=500.0 # capacitance of tunned circuit in pico farad\n",
+ "L=1.0 #INDUCTANCE of tunned circuit in milli henry\n",
+ "\n",
+ "#Calculations\n",
+ "C=(C1*C2)/(C1+C2) # total capacitance in micro farad\n",
+ "fo=(1/(2*math.pi*math.sqrt(L*10**-3*C*10**-12)))*10**-3 #tunned frequency in killo hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.1f kHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 318.3 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.6, Page No. 478"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# tunned capacitance and inductance of tunned circuit\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fo=500.0 # tunned frequency in killo hertz\n",
+ "L3=1.0 # assume inductance \n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "LC= (1/(4*math.pi**2*(fo*10**-3)**2)) \n",
+ "C=LC/(L3*10**-3) # capacitance in pico farad\n",
+ "C1= 2*C \n",
+ "C2=C1\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"inductance = %.f mH\"%L3)\n",
+ "print(\"tunned capacitance C1 of tunned circuit = %.1f pF\"%C1)\n",
+ "print(\"tunned capacitance C2 of tunned circuit = %.1f pF\"%C2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "inductance = 1 mH\n",
+ "tunned capacitance C1 of tunned circuit = 202.6 pF\n",
+ "tunned capacitance C2 of tunned circuit = 202.6 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8, Page No.484"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# tunned capacitance of tunned circuit\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fo1=50.0 # tunned frequency in killo hertz\n",
+ "L1=100.0 # inductance in micro henry\n",
+ "L2=100.0 # inductance in micro henry\n",
+ "\n",
+ "#Calculations\n",
+ "C= (1/(4*math.pi**2*(fo1*10**-6)**2*(L1+L2)*10**-6))*10**-12\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned capacitance tunned circuit = %.5f micro-F\"%C)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned capacitance tunned circuit = 0.05066 micro-F\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9, Page No. 485 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C=0.2 # capacitance of tunned circuit in MICRO farad\n",
+ "L1=0.5 # INDUCTANCE of tunned circuit in milli henry\n",
+ "L2=1.0 # INDUCTANCE of tunned circuit in milli henry\n",
+ "\n",
+ "#Calculaions\n",
+ "fo=(1/(2*math.pi*math.sqrt((L1+L2)*10**-3*C*10**-6)))\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.1f kHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 9188.8 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10, Page No. 485"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C=100.0 # capacitance of tunned circuit in pico farad\n",
+ "L1=1.0 # INDUCTANCE of tunned circuit in milli henry\n",
+ "L2=0.1 # INDUCTANCE of tunned circuit in milli henry\n",
+ "M = 0.05 # Mutual INDUCTANCE of tunned circuit in milli henry \n",
+ "\n",
+ "#Calculations\n",
+ "fo=(1/(2*math.pi*math.sqrt((L1+L2+2*M)*10**-3*C*10**-12))) # tunned frequency in killo hertz\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.f kHz\"%(fo/1000))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 459 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.11, Page No.485"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# feedback ratio\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Af=40.0 # gain wtih feedback\n",
+ "Vi=2.4 # input voltage\n",
+ "Vif=0.1 # input voltage with feedback\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "A= Af*(Vi/Vif) # gain without feedback\n",
+ "Beta= (1-(A/Af))/A # feedback ratio\n",
+ "\n",
+ "#Result\n",
+ "print(\"feedback ratio = %.3f\"%Beta)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "feedback ratio = -0.024\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.12, Page No.488"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cs=0.08 # capacitance of tunned circuit in pico farad\n",
+ "Ls=0.8 # series INDUCTANCE of tunned circuit in henry\n",
+ "Cp=1.0 # parallel capacitance in pico farad\n",
+ "Rs=5.0 # SERIES RESISTANCE IN KILLO OHMS\n",
+ "\n",
+ "#Calculations\n",
+ "fs=round((1/(2*math.pi*math.sqrt(Ls*Cs*10**-12)))*10**-3) # series tunned frequency in killo hertz\n",
+ "fp=round(((1/(2*math.pi))*math.sqrt((1+Cs/Cp)/(Ls*Cs*10**-12)))*10**-3) # parralel tunned frequency in killo hertz\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"series tunned frequency = %.f kHz\"%fs)\n",
+ "print(\"parallel tunned frequency = %.f kHz\"%fp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "series tunned frequency = 629 kHz\n",
+ "parallel tunned frequency = 654 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.13, Page No. 488"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# quality factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "f=450.0 # resonant frequency in killo hertz\n",
+ "L=4.2 # inductnace in henry\n",
+ "R=600.0 # resistance in ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Q= (2*math.pi*f*10**3*L)/R\n",
+ "\n",
+ "#Result\n",
+ "print(\"quality factor is %.f\"%Q)\n",
+ "#Answer in the book is slightly different"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "quality factor is 19792\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.14, Page No.489"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cs=0.01 # capacitance of tunned circuit in pico farad\n",
+ "Ls=0.8 # series INDUCTANCE of tunned circuit in henry\n",
+ "Cp=20.0 # parallel capacitance in pico farad\n",
+ "Rs=5.0 # SERIES RESISTANCE IN KILLO OHMS\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "fs=((1/(2*math.pi*math.sqrt(Ls*Cs*10**-12)))*10**-3) # series tunned frequency in killo hertz\n",
+ "fp=(((1/(2*math.pi))*math.sqrt((1+Cs/Cp)/(Ls*Cs*10**-12)))*10**-3)# parralel tunned frequency in killo hertz\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Series tunned frequency = %.2f kHz\"%(math.floor(fs*100)/100))\n",
+ "print(\"Parallel tunned frequency = %.2f KHz\"%fp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Series tunned frequency = 1779.40 kHz\n",
+ "Parallel tunned frequency = 1779.85 KHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.15, Page No.489"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency,percentage change and quality factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cs=0.065 # capacitance of tunned circuit in pico farad\n",
+ "Ls=0.33 # series INDUCTANCE of tunned circuit in henry\n",
+ "Cp=1.0 # parallel capacitance in pico farad\n",
+ "Rs=5.5 # SERIES RESISTANCE IN KILLO OHMS\n",
+ "\n",
+ "#Calculation\n",
+ "fs=round((1/(2*math.pi*math.sqrt(Ls*Cs*10**-12)))*10**-3) # series tunned frequency in killo hertz\n",
+ "fp=math.ceil(((1/(2*math.pi))*math.sqrt((1+Cs/Cp)/(Ls*Cs*10**-12)))*10**-3) # parralel tunned frequency in killo hertz\n",
+ "Pc= ((fp-fs)/fs)*100 # percentage by which series resonant frequency exceeds the parallel resonant frequency\n",
+ "Qs= ((2*math.floor(math.pi*100)*fs*10**3*Ls/100)/(Rs*10**3)) # quality factor with series resonant frequency\n",
+ "Qp= ((2*math.floor(math.pi*100)*fp*10**3*Ls/100)/(Rs*10**3)) # quality factor with parallled resonant frequency\n",
+ "\n",
+ "#Result\n",
+ "print(\"series tunned frequency = %.f kHz\"%fs)\n",
+ "print(\"parallel tunned frequency = %.f kHz\"%fp)\n",
+ "print(\"percentage by which series resonant frequency exceeds the parallel resonant frequency = %.1f%%\"%Pc)\n",
+ "print(\"quality factor with series resonant frequency is %.2f\"%Qs)\n",
+ "print(\"quality factor with paralled resonant frequency is %.2f\"%(math.floor(Qp*100)/100))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "series tunned frequency = 1087 kHz\n",
+ "parallel tunned frequency = 1122 kHz\n",
+ "percentage by which series resonant frequency exceeds the parallel resonant frequency = 3.2%\n",
+ "quality factor with series resonant frequency is 409.58\n",
+ "quality factor with paralled resonant frequency is 422.76\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.16, Page No.490"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C1=120.0 # capacitance of tunned circuit in PICO farad\n",
+ "C2=1500.0 # capacitance of tunned circuit in pico farad\n",
+ "C3=15.0 # capacitance of tunned circuit in pico farad\n",
+ "L=10.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Cx=(C1*C2)/(C1+C2) # capacitance in pico farad\n",
+ "Ct=(Cx*C3)/(Cx+C3) # total capacitance in pico farad\n",
+ "fo=(1/(2*math.pi*math.sqrt(L*10**-6*Ct*10**-12)))*10**-6 # tunned frequency in mega hertz\n",
+ "foa= (1/(2*math.pi*math.sqrt(L*10**-6*C3*10**-12)))*10**-6 # actual resonant frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.2f MHz\"%fo)\n",
+ "print(\"actual resonant frequency = %.2f MHz\"%foa)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 13.84 MHz\n",
+ "actual resonant frequency = 12.99 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.17, Page No. 490"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R=500.0 # resistance in ohms\n",
+ "C1=0.01 # capacitance of tunned circuit in pico farad\n",
+ "C2=10.0 # capacitance of tunned circuit in pico farad\n",
+ "L=0.06 # INDUCTANCE of tunned circuit in henry\n",
+ "\n",
+ "#Calculations\n",
+ "C=(C1*C2)/(C1+C2) # total capacitance in micro farad\n",
+ "fs=((1/(2*math.pi*math.sqrt(L*C1*10**-12)))*10**-6) # series tunned frequency in mega hertz\n",
+ "C=(C1*C2)/(C1+C2) # total capacitance in pico farad\n",
+ "fp=(1/(2*math.pi*math.sqrt(L*C*10**-12))*10**-6) #parralel tunned frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"series tunned frequency = %.3f MHz\"%fs)\n",
+ "print(\"parallel tunned frequency = %.4f MHz\"%fp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "series tunned frequency = 6.497 MHz\n",
+ "parallel tunned frequency = 6.5007 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.18, Page No. 491"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C=100.0 # capacitance of tunned circuit in pico farad\n",
+ "L1=50.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "L2=50.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "\n",
+ "#Calculations\n",
+ "fo=(1/(2*math.pi*math.sqrt((L1+L2)*10**-6*C*10**-12)))*10**-6 # tunned frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"Tunned frequency = %.2f MHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tunned frequency = 1.59 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.19, Page No.491"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C1=120.0 # capacitance of tunned circuit in PICO farad\n",
+ "C2=1500.0 # capacitance of tunned circuit in pico farad\n",
+ "L=10.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "\n",
+ "#Calculation\n",
+ "C=(C1*C2)/(C1+C2) # total capacitance in pico farad\n",
+ "fo=(1/(2*math.pi*math.sqrt(L*10**-6*C*10**-12)))*10**-6 # tunned frequency in mega hertz\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.2f MHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 4.77 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.20, Page No.491"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C1=120.0 # capacitance of tunned circuit in PICO farad\n",
+ "C2=1500.0 # capacitance of tunned circuit in pico farad\n",
+ "C3=15.0 # capacitance of tunned circuit in pico farad\n",
+ "L=10.0 # INDUCTANCE of tunned circuit in micro henry\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Cx=(C1*C2)/(C1+C2) # capacitance in pico farad\n",
+ "Ct=(Cx*C3)/(Cx+C3) # total capacitance in pico farad\n",
+ "fo=(1/(2*math.pi*math.sqrt(L*10**-6*Ct*10**-12)))*10**-6 # tunned frequency in mega hertz\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"tunned frequency = %.2f MHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "tunned frequency = 13.84 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.21, Page No.497"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "C=100.0 # capacitance in pico farad\n",
+ "R=800.0 # resistance in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "fo=round(1/(2*math.pi*R*10**3*C*10**-12*math.sqrt(6))) # RESONANT FREQUENCY IN HERTZ\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Resonant frequency = %.f Hz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resonant frequency = 812 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.22, Page No.498"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# oscillation frequency \n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "w=2*10**3 # in radiand per second\n",
+ "\n",
+ "#Calculations\n",
+ "f= round(w/(2*math.pi)) # resonant frequency\n",
+ "X=(((16*10**9*4*w**2*10**3))/((4*w**2*10**3)**2))\n",
+ "\n",
+ "#Result\n",
+ "print(\"resonant frequency = %.f Hz\"%f)\n",
+ "print(\"oscillations are sustained = %.f\"%X)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "resonant frequency = 318 Hz\n",
+ "oscillations are sustained = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.23, Page No. 502"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Design R-C phase shift oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "fo=1.0 # resonant frequency in killo hertz\n",
+ "Av= 29.0 # voltage gain\n",
+ "Vcc=10.0 # collector voltage\n",
+ "Ib=0.5 # maximum base current in micro ampere\n",
+ "Rf2=180.0 # standard resistance in killo ohms\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "I1=100*Ib # assume current in micro ampere\n",
+ "Vosat= 0.9*Vcc # saturation voltage assume\n",
+ "V1=Vosat/Av # voltage for sustained oscillations\n",
+ "R1=(V1/(I1*10**-6))*10**-3 # RESISTANCE IN KILLO PHMS\n",
+ "Rf1=Av*R1 # resistance in killo ohms\n",
+ "R3=Rf2 \n",
+ "R=R1 \n",
+ "C=(1/(2*math.pi*R*10**3*fo*10**3*math.sqrt(6)))*10**6 \n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Resistance R1 for the R-C Phase shift oscillator = %.1f k-ohm\"%R)\n",
+ "print(\"Resistance Rf for the R-C Phase shift oscillator = %.f k-ohm\"%R3)\n",
+ "print(\"Capacitance for the R-C Phase shift oscillator = %.2f micro-F\"%C)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance R1 for the R-C Phase shift oscillator = 6.2 k-ohm\n",
+ "Resistance Rf for the R-C Phase shift oscillator = 180 k-ohm\n",
+ "Capacitance for the R-C Phase shift oscillator = 0.01 micro-F\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.24, Page No. 502"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# drain resistance and Design R-C phase shift oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Mu=55.0\n",
+ "rd=5.5 # resistane in killo ohms\n",
+ "fo=5.0 # resonant frequency in killo hertz\n",
+ "A= 29.0 # voltage gain\n",
+ "R=30.0 # assume Resistance in killo ohms\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Rd= (29*rd)/(Mu-A) # resistance in killo ohms\n",
+ "RC=((1/(2*math.pi*fo*10**3*math.sqrt(6)))*10**6) \n",
+ "C=(RC*10**-6/(30*10**3)*10**12)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"drain resistance = %.2f k-ohm\"%Rd)\n",
+ "print(\"R-C time constant = %.f pico-sec\"%(math.ceil(RC)))\n",
+ "print(\"Capacitance for the R-C Phase shift oscillator = %.f pF\"%C)\n",
+ "#Answer for capacitance is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "drain resistance = 6.13 k-ohm\n",
+ "R-C time constant = 13 pico-sec\n",
+ "Capacitance for the R-C Phase shift oscillator = 433 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.25, Page No.503"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Vf/Vo,frequency of oscillations and minimum gain\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Beta=1.0/29\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "VfVo= (Beta+1)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Voltage gain = %f\"%VfVo)\n",
+ "print(\"\\nf=1/(2*%pi*R*C*sqrt(6)) frequency of oscillations\")\n",
+ "print(\"\\nAs gain is more than one oscillations will be sustained\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage gain = 1.034483\n",
+ "\n",
+ "f=1/(2*%pi*R*C*sqrt(6)) frequency of oscillations\n",
+ "\n",
+ "As gain is more than one oscillations will be sustained\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.26, Page No. 510"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# design wein bridge oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=15.0 # collector voltage\n",
+ "f=10.0 # frequency of oscillation in killo hertz\n",
+ "I=1.0 # current in millo ampere\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Vo=Vcc-1 # maximum output voltage\n",
+ "x=Vo/I # resistance in killo ohms\n",
+ "R4=x/3 # resistance in killo ohms\n",
+ "R3= 2*R4 # resistance in killo ohms\n",
+ "R4_s = 4.7 # Standard value\n",
+ "R3_s = 10 # Standard value \n",
+ "A= (1+(R3_s/R4_s)) # amplifier gain\n",
+ "R=R4_s # resistance in killo ohms\n",
+ "C=(1/(2*math.pi*f*10**3*R*10**3))*10**9\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Amlifier gain = %.2f\"%(math.floor(A*100)/100))\n",
+ "print(\"resistance R4 = %.1f k-ohm (use 4.7 k-ohm standard value)\"%R)\n",
+ "print(\"resistance R3 = %.1f k-ohm (use 10 k-ohm standard value)\"%(math.ceil(R3*10)/10))\n",
+ "print(\"Capacitance = %.2f nF\"%(math.floor(C*100)/100))\n",
+ "#print(\"this is name as example 7.27 in the book\" )"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Amlifier gain = 3.12\n",
+ "resistance R4 = 4.7 k-ohm (use 4.7 k-ohm standard value)\n",
+ "resistance R3 = 9.4 k-ohm (use 10 k-ohm standard value)\n",
+ "Capacitance = 3.38 nF\n"
+ ]
+ }
+ ],
+ "prompt_number": 70
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.27 Page No.511"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# sustained oscillations and output frequency\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R4=5.1 # resistance in killo ohms\n",
+ "R3=12.0 # resistance in killo ohms\n",
+ "C=1.0 # capacitance in nano farad\n",
+ "\n",
+ "#Calculations\n",
+ "A= (1+(R3/R4)) # amplifier gain\n",
+ "R=R4 # resistance in killo ohms\n",
+ "fo= (1/(2*math.pi*C*10**-9*R*10**3))*10**-3\n",
+ "\n",
+ "#Result\n",
+ "print(\"Amlifier gain is %.2f. It is greater than 1 so circuit will oscillate.\"%A)\n",
+ "print(\"Oscillation frequency = %.1f kHz\"%fo)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Amlifier gain is 3.35. It is greater than 1 so circuit will oscillate.\n",
+ "Oscillation frequency = 31.2 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 75
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.29, Page No.514"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# design wein bridge oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vcc=10.0 # collector voltage\n",
+ "f=10.0 # frequency of oscillation in killo hertz\n",
+ "I=500.0 # current in micro ampere\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Vo=Vcc-1 # maximum output voltage\n",
+ "x=(Vo/I)*10**3 # resistance in killo ohms\n",
+ "R4=x/3 # resistance in killo ohms\n",
+ "Rf= 2*R4 # resistance in killo ohms\n",
+ "R4_s = 5.6 # standard value\n",
+ "R=R4_s # resistance in killo ohms\n",
+ "C=(1/(2*math.pi*f*10**3*R*10**3))*10**12\n",
+ "\n",
+ "#Resulr\n",
+ "print(\"Resistance R = R1 = %.f k-ohm(uswe 5.6k as standard value)\"%R)\n",
+ "print(\"resistance Rf = %.f k-ohm\"%Rf)\n",
+ "print(\"Capacitance = %.f nF(use 2700 nF as standard value)\"%C)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Resistance R = R1 = 6 k-ohm(uswe 5.6k as standard value)\n",
+ "resistance Rf = 12 k-ohm\n",
+ "Capacitance = 2842 nF(use 2700 nF as standard value)\n"
+ ]
+ }
+ ],
+ "prompt_number": 85
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.30, Page No.514"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print(\"Theoretical example\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Theoretical example\n"
+ ]
+ }
+ ],
+ "prompt_number": 87
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.31, Page No.515"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print(\"Theoretical example\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.32, Page No. 517"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Design R-C phase shift oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vce=5.0 # in volts\n",
+ "RE=1.0 # emitter reistsance in killo ohms\n",
+ "Vbe=0.7 # in volts\n",
+ "Ie=1.0 # emitter current in mA\n",
+ "Re=1.0 # EMITTER RESISTANCE IN KILLO OHMS\n",
+ "f=100.0 # oscillaor frequency in killo hertz\n",
+ "hfe=100.0\n",
+ "hie=1.0 # in killo ohms\n",
+ "Vc=5.0 # in volts\n",
+ "Ic=1.0 # current in mili ampere\n",
+ "Vcc=20.0 # in volts\n",
+ "R=10.0 # resistane in killo ohms\n",
+ "\n",
+ "#Calculations\n",
+ "Rc=(Vcc-Vce-Ie*Re)/(Ic) # collector resistance in killo ohms is\n",
+ "k= Rc/R\n",
+ "C= ((1/(2*math.pi*R*10**3*f*10**3*math.sqrt(6+(4*1.4)))))*10**12\n",
+ "R3= R-hie # resistance in kiilo ohms\n",
+ "Vb= (Vbe+Ie*Re) # voltage at base\n",
+ "R2=R \n",
+ "I2=Vb/R2 # in mA\n",
+ "V2=(Vcc-R2*I2) # voltage drop across R2\n",
+ "IR1= (I2+(1.0/100)) # CURRENT ACROOS R1\n",
+ "R1= V2/(IR1) \n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Emitter resistance = %.f k-ohm\"%Re)\n",
+ "print(\"collector resistance = %.f k-ohm\"%Rc)\n",
+ "print(\"resistance R = %.f k-ohm\"%R)\n",
+ "print(\"Capacitance = %.1f pF\"%C)\n",
+ "print(\"resistance(R3) = %.f k-ohm\"%R3)\n",
+ "print(\"resistance(R2) = %.f k-ohm\"%R2)\n",
+ "print(\"resistance(R1) = %.f k-ohm\"%R1)\n",
+ "#Answer for Resistance (R1) is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter resistance = 1 k-ohm\n",
+ "collector resistance = 14 k-ohm\n",
+ "resistance R = 10 k-ohm\n",
+ "Capacitance = 46.7 pF\n",
+ "resistance(R3) = 9 k-ohm\n",
+ "resistance(R2) = 10 k-ohm\n",
+ "resistance(R1) = 102 k-ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 91
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.33, Page No.518"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Design R-C phase shift oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "rd=40.0 # resistane in killo ohms\n",
+ "fo=1.0 # resonant frequency in killo hertz\n",
+ "gm= 5000.0 # in killo mh\n",
+ "R=10.0 # assume Resistance in killo ohms\n",
+ "Av=29.0 # VOLTAGE GAIN\n",
+ "Vdd=12.0 # drain voltage\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "C=((1/(2*math.pi*fo*10**3*R*10**3*math.sqrt(6)))*10**9)# C in nano farad\n",
+ "Rl= (Av/gm*10**-6)*10**9 # load resistance in killo ohms\n",
+ "Rl = math.ceil(Rl)\n",
+ "Rd= ((Rl*rd)/(rd-Rl)) # drain resistance in killo ohms\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"Drain Resistance = %.2f k-ohm\"%Rd)\n",
+ "print(\"Capacitance for the R-C Phase shift oscillator = %.1f nF\"%C) "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Drain Resistance = 7.06 k-ohm\n",
+ "Capacitance for the R-C Phase shift oscillator = 6.5 nF\n"
+ ]
+ }
+ ],
+ "prompt_number": 96
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.34, Page No.518"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# design wein bridge oscillator\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "R=100.0 # ASSUME RESSITANCE IN KILO OHMS\n",
+ "fo1=10.0 # tunned frequency in killo hertz\n",
+ "fo2=100.0 # tunned frequency in hertz\n",
+ "\n",
+ "#Calculations\n",
+ "C1= (1/(2*math.pi*R*10**3*fo1*10**3))*10**9 # tunned capacitance\n",
+ "C2= (1/(2*math.pi*R*10**3*fo2))*10**9 # tunned capacitance\n",
+ "\n",
+ "#Result\n",
+ "print(\"Tunned capacitance C1 range of tunned circuit = %.3f nF\"%C1)\n",
+ "print(\"Tunned capacitance C2 range of tunned circuit = %.1f nF\"%C2)\n",
+ "#Answer slightly different than book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tunned capacitance C1 range of tunned circuit = 0.159 nF\n",
+ "Tunned capacitance C2 range of tunned circuit = 15.9 nF\n"
+ ]
+ }
+ ],
+ "prompt_number": 105
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.35, Page No. 519 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# resonant frequency and quality factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Cs=0.06 # capacitance of tunned circuit in pico farad\n",
+ "Ls=0.5 # series INDUCTANCE of tunned circuit in henry\n",
+ "Cp=1.0 # parallel capacitance in pico farad\n",
+ "Rs=5.0 # SERIES RESISTANCE IN KILLO OHMS\n",
+ "\n",
+ "#Calculations\n",
+ "fs=((1/(2*math.pi*math.sqrt(Ls*Cs*10**-12)))*10**-3) # series tunned frequency in killo hertz\n",
+ "fp=(((1/(2*math.pi))*math.sqrt((1+Cs/Cp)/(Ls*Cs*10**-12)))*10**-3) # parralel tunned frequency in killo hertz\n",
+ "Pc= ((fp-fs)/fs)*100 # percentage by which series resonant frequency exceeds the parallel resonant frequency\n",
+ "Qs= round((2*math.pi*fs*10**3*Ls)/(Rs*10**3)) # quality factor with series resonant frequency\n",
+ "Qp= round((2*math.pi*fp*10**3*Ls)/(Rs*10**3)) # quality factor with parallled resonant frequency\n",
+ "\n",
+ "#Result\n",
+ "print(\"Series tunned frequency = %.1f kHz\"%fs)\n",
+ "print(\"Quality factor with series resonant frequency is %.f\"%Qs)\n",
+ "print(\"\\nParallel tunned frequency = %.f kHz\"%fp)\n",
+ "print(\"Quality factor with paralled resonant frequency is %.f\"%Qp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Series tunned frequency = 918.9 kHz\n",
+ "Quality factor with series resonant frequency is 577\n",
+ "\n",
+ "Parallel tunned frequency = 946 kHz\n",
+ "Quality factor with paralled resonant frequency is 594\n"
+ ]
+ }
+ ],
+ "prompt_number": 111
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Utilization_of_Electrical_Energy_and_Traction/screenshots/current_thru_negative_booster.png b/Utilization_of_Electrical_Energy_and_Traction/screenshots/current_thru_negative_booster.png
new file mode 100755
index 00000000..62b7bca9
--- /dev/null
+++ b/Utilization_of_Electrical_Energy_and_Traction/screenshots/current_thru_negative_booster.png
Binary files differ
diff --git a/Utilization_of_Electrical_Energy_and_Traction/screenshots/speed-armature_curve.png b/Utilization_of_Electrical_Energy_and_Traction/screenshots/speed-armature_curve.png
new file mode 100755
index 00000000..0f1b518f
--- /dev/null
+++ b/Utilization_of_Electrical_Energy_and_Traction/screenshots/speed-armature_curve.png
Binary files differ
diff --git a/Utilization_of_Electrical_Energy_and_Traction/screenshots/speed-time_curve.png b/Utilization_of_Electrical_Energy_and_Traction/screenshots/speed-time_curve.png
new file mode 100755
index 00000000..038a01a7
--- /dev/null
+++ b/Utilization_of_Electrical_Energy_and_Traction/screenshots/speed-time_curve.png
Binary files differ
diff --git a/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch1.ipynb b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch1.ipynb
new file mode 100755
index 00000000..2141c4af
--- /dev/null
+++ b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch1.ipynb
@@ -0,0 +1,722 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:bf41ecd4a5c4b2bac0963dfefdbae99e40865d12b1b3268ffcbf28e722184e41"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 1: Electric Heating"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.1, Page 14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "r1=100.;#in ohms\n",
+ "r2=r1;# in ohms\n",
+ "V=250.;# ac supply in volts\n",
+ "\n",
+ "#Calculations&Results\n",
+ "rp = 1/(1/r1+1/r2);# equivalent resistance in ohms\n",
+ "pp=((V**2)/rp);#power drawn in watts\n",
+ "print \"part (a) \"\n",
+ "print \"power drawn when elements are in parallel,(W)= %.f\"%pp\n",
+ "rs=r1+r2;# equivalent resistance in ohms\n",
+ "ps=((V**2)/rs);#power drawn in watts\n",
+ "print \"part (b) \"\n",
+ "print \"power drawn when elements are in series ,(W)=%.1f\"%ps"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a) \n",
+ "power drawn when elements are in parallel,(W)= 1250\n",
+ "part (b) \n",
+ "power drawn when elements are in series ,(W)=312.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.2, Page 15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "P=2.5;#power in kW\n",
+ "V=240.;# in volts\n",
+ "K=1;#radiating efficiency\n",
+ "e=0.9;#emissivity\n",
+ "p=42.5*10**-6;# resistivity in ohm-cm\n",
+ "T1=1500.;#in dgree celsius\n",
+ "T2=450.;#in degree celsius\n",
+ "\n",
+ "#Calculations\n",
+ "x=((math.pi*V**2)/(4*(p*10**-2)*P*10**3));#\n",
+ "H=((5.72*K*e)*(((T1+273)/100)**4-((T2+273)/100)**4));#\n",
+ "z=((P*10**3)/(math.pi*H))**2;#\n",
+ "l=(z*x)**(1./3);#length in meter\n",
+ "d=((math.sqrt(z))/l)*10**3;#diameter in mm\n",
+ "\n",
+ "#Results\n",
+ "print \"length in meter =%.2f\"%l\n",
+ "print \"diameter in mm =%.3f\"%d\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "length in meter =4.79\n",
+ "diameter in mm =0.336\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.3, Page 15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "V=440.;# volts\n",
+ "P=20.;#in kW\n",
+ "T1=1200.;#in degree celsius\n",
+ "T2=700.;# in degree celsius\n",
+ "K=0.6;#radiating efficiency\n",
+ "e=0.9;#emissivity\n",
+ "t=0.025;#thickness in mm\n",
+ "p=1.05*10**-6;#resisitivity in ohm - meter\n",
+ "\n",
+ "#Calculations\n",
+ "Pp=(round(P*10**3))/3;#power per phase in watts\n",
+ "Pv= (V/math.sqrt(3));#phase voltage\n",
+ "R=Pv**2/Pp;#resistance of strip in ohms\n",
+ "x=((R*t*10**-3)/(p));#\n",
+ "H=((5.72*K*e)*(((T1+273)/100)**4-((T2+273)/100)**4));#in W/m^2\n",
+ "y=((Pp)/(H*2));#in m^2\n",
+ "w=math.sqrt(y/x)*10**3;#width in mm\n",
+ "l=x*w*10**-3;#length of strip in meter\n",
+ "\n",
+ "#Results\n",
+ "print \"width in mm =%.3f\"%w\n",
+ "print \"length of strip in meter =%.2f\"%l\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "width in mm =11.084\n",
+ "length of strip in meter =2.55\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.4, Page 16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "a=6.;#area in m^2\n",
+ "l=a/6;#one side of tank in meter\n",
+ "V=l*l*l;#volume in m^2\n",
+ "e=90./100;#capacity\n",
+ "wh=6*e*1000;#water to be heated daily in kg\n",
+ "s=4200;#specific heat of water in J/Kg/degree celsius\n",
+ "t1=65;#in degree celsius\n",
+ "t2=20;#in degree celsius\n",
+ "\n",
+ "#Calculations\n",
+ "hr=wh*s*(t1-t2)*10**-6;#heat required to raise the temperture of water\n",
+ "hr1=hr/3.6;#heat required in kWh\n",
+ "d=6.3;#difference in watts\n",
+ "l=((d*a*(t1-t2)*24)/1000);#losses from the surface of the tank in kWh\n",
+ "es=hr1+l;#energy supplied in kWh\n",
+ "lk=es/24;#loading in kW\n",
+ "ef=(hr1/es)*100;#efficiency of the tank in percentage\n",
+ "\n",
+ "#Results\n",
+ "print \"loading in kW = %.1f\"%lk\n",
+ "print \"efficiency of the tank in percentage = %.1f\"%ef"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "loading in kW = 13.5\n",
+ "efficiency of the tank in percentage = 87.4\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.5, Page 22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "sh=444;# specific heat of steel in J/Kg/\u00b0C\n",
+ "lh=37.25;#latent heat in kJ/kg\n",
+ "mp=1370;#melting point of steel \u00b0C\n",
+ "t1=19.1;#initial temperture in \u00b0C\n",
+ "e=0.5;#overall efficiency\n",
+ "ip=5700;#input current in amperes\n",
+ "rs=0.008;#resistance of transformer referred to secondary in ohms\n",
+ "rr=0.014;# recatance in ohms\n",
+ "m=4.3;# steel in tonnes\n",
+ "\n",
+ "#Calculations\n",
+ "ers=((m*10**3*((sh*(mp-t1))+lh*10**3)));# energy required in joules\n",
+ "ersh=ers/(3.6*10**6);#energy required in kWh\n",
+ "ata=1;#time taken to melt steel in hours\n",
+ "ao=ersh/ata;#average output in kW\n",
+ "ai=ao/e;#average input in kW\n",
+ "vdr=ip*rs;#voltage drop due to resistance of furnace leads\n",
+ "vdr1=ip*rr;#voltage drop due to reactance of furnace leads\n",
+ "va=((ai*10**3)/(3*ip))-(vdr);#voltage resistive in nature\n",
+ "rac=va/ip;#arc resistance in \u03a9\n",
+ "oppv=math.sqrt((va+vdr)**2+vdr1**2);#open circuit phase voltage in volts\n",
+ "kvas=3*ip*oppv*10**-3;#total kVA drawn \n",
+ "pf=((va+vdr)/oppv);#power factor \n",
+ "\n",
+ "#Result\n",
+ "print \"average input in kW = %.2f\"%ai\n",
+ "print \"arc voltage in volts = %.1f\"%va\n",
+ "print \"arc resistance in \u03a9 = %.4f\"%rac\n",
+ "print \"pf of the current drawn from the supply (lagging) = %.4f\"%pf\n",
+ "print \"total kVA drawn in kVA = %.f\"%kvas"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "average input in kW = 1521.84\n",
+ "arc voltage in volts = 43.4\n",
+ "arc resistance in \u03a9 = 0.0076\n",
+ "pf of the current drawn from the supply (lagging) = 0.7445\n",
+ "total kVA drawn in kVA = 2044\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.6, Page 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "sh=0.12;# specific heat of steel in kcal/Kg/\u00b0C\n",
+ "lh=8.89;#latent heat in kcal/kg\n",
+ "mp=1370;#melting point of steel \u00b0C\n",
+ "t1=19.1;#initial temperture in \u00b0C\n",
+ "e=0.5;#overall efficiency\n",
+ "ip=5700;#input current in amperes\n",
+ "rs=0.008;#resistance of transformer referred to secondary in ohms\n",
+ "rr=0.014;# recatance in ohms\n",
+ "m=4.3;# steel in tonnes\n",
+ "\n",
+ "#Calculations\n",
+ "ers=((m*10**3*((sh*(mp-t1))+lh)));# energy required in joules\n",
+ "ersh=ers/(860);#energy required in kWh\n",
+ "ata=1;#time taken to melt steel in hours\n",
+ "ao=ersh/ata;#average output in kW\n",
+ "ai=ao/e;#average input in kW\n",
+ "vdr=ip*rs;#voltage drop due to resistance of furnace leads\n",
+ "vdr1=ip*rr;#voltage drop due to reactance of furnace leads\n",
+ "va=((ai*10**3)/(3*ip))-(vdr);#voltage resistive in nature\n",
+ "rac=va/ip;#arc resistance in \u03a9\n",
+ "oppv=math.sqrt((va+vdr)**2+vdr1**2);#open circuit phase voltage in volts\n",
+ "kvas=3*ip*oppv*10**-3;#total kVA drawn \n",
+ "pf=((va+vdr)/oppv);#power factor \n",
+ "\n",
+ "#Result\n",
+ "print \"average input in kW =%.f\"%ai\n",
+ "print \"arc voltage in volts =%.1f\"%va\n",
+ "print \"arc resistance in \u03a9 =%.5f\"%rac\n",
+ "print \"pf of the current drawn from the supply (lagging) =%.4f\"%pf\n",
+ "print \"total kVA drawn in kVA =%.1f\"%kvas"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "average input in kW =1710\n",
+ "arc voltage in volts =54.4\n",
+ "arc resistance in \u03a9 =0.00954\n",
+ "pf of the current drawn from the supply (lagging) =0.7816\n",
+ "total kVA drawn in kVA =2187.7\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.7, Page 29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "sh=0.1;# specific heat of steel in kcal/Kg/\u00b0C\n",
+ "lh=26.67;#latent heat in kcal/kg\n",
+ "mp=555;#melting point of steel \u00b0C\n",
+ "t1=35;#initial temperture in \u00b0C\n",
+ "e=0.8;#overall efficiency\n",
+ "ip=5700;#input current in amperes\n",
+ "rs=0.008;#resistance of transformer referred to secondary in ohms\n",
+ "rr=0.014;# recatance in ohms\n",
+ "m=2;# steel in tonnes\n",
+ "\n",
+ "#Calculations\n",
+ "ers=((m*10**3*((sh*(mp-t1))+lh)));# energy required in joules\n",
+ "ersh=ers/(860);#energy required in kWh\n",
+ "ata=1;#time taken to melt steel in hours\n",
+ "ao=ersh/ata;#average output in kW\n",
+ "ai=ao/e;#average input in kW\n",
+ "vdr=ip*rs;#voltage drop due to resistance of furnace leads\n",
+ "vdr1=ip*rr;#voltage drop due to reactance of furnace leads\n",
+ "va=((ai*10**3)/(3*ip))-(vdr);#voltage resistive in nature\n",
+ "rac=va/ip;#arc resistance in \u03a9\n",
+ "oppv=math.sqrt((va+vdr)**2+vdr1**2);#open circuit phase voltage in volts\n",
+ "kvas=3*ip*oppv*10**-3;#total kVA drawn \n",
+ "pf=((va+vdr)/oppv);#power factor \n",
+ "rf=ai/ata;# in kW\n",
+ "\n",
+ "#Result\n",
+ "print \"rating of furnance in kW =%.1f\"%rf\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rating of furnance in kW =228.7\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.8, Page 29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "sh=880;# specific heat of steel in J/Kg/\u00b0C\n",
+ "lh=32000;#latent heat in J/kg\n",
+ "mp=660;#melting point of steel \u00b0C\n",
+ "t1=15;#initial temperture in \u00b0C\n",
+ "ip=5700;#input current in amperes\n",
+ "rs=0.008;#resistance of transformer referred to secondary in ohms\n",
+ "rr=0.014;# recatance in ohms\n",
+ "m=1.8;# IN KG\n",
+ "\n",
+ "#Calculations\n",
+ "ers=((m*((sh*(mp-t1))+lh)));# energy required in joules\n",
+ "ersh=ers/(3.6*10**6);#energy required in kWh\n",
+ "TM=10.;#TIME TO MELT IN MINS\n",
+ "ip=5;#input of the furnance in kW\n",
+ "ei=(ip)*(TM/60);#energy input in kWh\n",
+ "n=(ersh/ei)*100;#efficiency of furnance in percentage\n",
+ "\n",
+ "#Result\n",
+ "print \"efficiency of furnance in percentage =%.f\"%n\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "efficiency of furnance in percentage =36\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.9, Page 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "vs=10;#secondary voltage in volts\n",
+ "p=500;#power drawn in kW\n",
+ "pf=0.5;\n",
+ "ir=(p*10**3)/pf;#secondary current in amperes\n",
+ "\n",
+ "#Calculations\n",
+ "zs=vs/ir;#impedence of secondary circuit in ohms\n",
+ "rs=zs*pf;#resistance of secondary circuit in ohms\n",
+ "res=zs*(math.sqrt(1-pf**2));#rectancetance of secondary circuit in ohms\n",
+ "rs1=2*rs;# resistacne when hearth is full in \u03a9\n",
+ "res1=res;# reactance when hearth is full in \u03a9\n",
+ "zs1=(math.sqrt(rs1**2+res1**2));#impedance of secondary circuit in \u03a9\n",
+ "pf1=rs1/zs1;#power factor\n",
+ "is1=vs/zs1;#secondary current in amperes\n",
+ "pd=is1**2*rs1*10**-4;#power drawn in kW\n",
+ "\n",
+ "#Results\n",
+ "print \"power factor is =%.3f\"%pf1\n",
+ "print \"power drawn in kW =%.3f\"%pd"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "power factor is =0.756\n",
+ "power drawn in kW =571.429\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.10, Page 30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "vs=10;#secondary voltage in volts\n",
+ "p=400;#power drawn in kW\n",
+ "pf=0.6;#\n",
+ "\n",
+ "#Calculations\n",
+ "is1=(p*10**3)/pf;#secondary current in amperes\n",
+ "zs=vs/is1;#impedence of secondary circuit in ohms\n",
+ "rs=zs*pf;#resistance of secondary circuit in ohms\n",
+ "res=zs*(math.sqrt(1-pf**2));#rectancetance of secondary circuit in ohms\n",
+ "x=(rs)/res;#height \n",
+ "\n",
+ "#Result\n",
+ "print \"maximum heat will be obtained with the height of charge as 3/4 of height of hearth =%.2f\"%x"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum heat will be obtained with the height of charge as 3/4 of height of hearth =0.75\n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.11, Page 32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "p=5*10**-7;#specific resistance in \u03a9-m\n",
+ "rp=1;#relative permeability\n",
+ "dp=0.0015;#depth of penetration in mter\n",
+ "\n",
+ "#Calculations\n",
+ "f=((p*10**7)/((rp*(dp)**2)*4*(math.pi)**2))*10**-3;#frequency in kHz\n",
+ "\n",
+ "#Result\n",
+ "print \"frequency in kHz =%.3f\"%f"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "frequency in kHz =56.290\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.12, Page 36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "l=0.5;#length in meter\n",
+ "b=0.25;#breadh in meter\n",
+ "h=0.02;#in meter\n",
+ "t1=25;# temperture \u00b0C\n",
+ "t2=125;# temperture \u00b0C\n",
+ "t=10;#time in minutes\n",
+ "f=30;#frequency in 30 MHz\n",
+ "w=600;#weight of the wood in kg/m^3\n",
+ "sh=1500;#specific heat in J/Kg/\u00b0C\n",
+ "e=50;#efficiency\n",
+ "\n",
+ "#Calculations\n",
+ "vp=l*b*h;#volume in m^3\n",
+ "wp=vp*w;#weight of plywood in kg\n",
+ "hr=sh*wp*(t2-t1);#heat required in joules\n",
+ "hrt=(hr/(3600));#heat required to raise the temperture of plywood in Wh\n",
+ "pu=hrt/(1./6);#power utilized in watts\n",
+ "pi=(pu/e)*100;#power input required in percentage\n",
+ "\n",
+ "#Result\n",
+ "print \"power input required ,(W)= %.f\"%pi\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "power input required ,(W)= 750\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.13, Page 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "vl=600;#in volts\n",
+ "p=200;#power absorbed in watts\n",
+ "pf=0.05;#power factor\n",
+ "f=30*10**6;#frequency in Hz\n",
+ "ep=8.854*10**-12;#constant\n",
+ "er=5;#\n",
+ "a=150;# in cm^2\n",
+ "t=0.02;# in meter\n",
+ "\n",
+ "#Calculations\n",
+ "c=((ep*er*a*10**-4)/t);#capacitance in farads\n",
+ "vr=(math.sqrt(p/(2*math.pi*f*c*pf)));#voltage is required in volts\n",
+ "i=p/(vr*pf);#current in amperes\n",
+ "f2=((f*(vr/vl)**2))*10**-6;#frequency in Mhz\n",
+ "\n",
+ "#Results\n",
+ "print \"voltage in volts =%.f\"%vr\n",
+ "print \"current in amperes =%d\"%i\n",
+ "print \"frequency in MHz=%.1f\"%f2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "voltage in volts =799\n",
+ "current in amperes =5\n",
+ "frequency in MHz=53.3\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.14, Page 37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "pf=0.04;#power factor\n",
+ "p=1000;#in watts\n",
+ "f=10*10**6;# in MHz\n",
+ "a1=.004;#area in m^2\n",
+ "a2=0.001;#area in m^2\n",
+ "t=0.02;#thickness in meter\n",
+ "t1=.01;#thicknes sin meter\n",
+ "t2=t-t1;#thickness in meter\n",
+ "ep=8.854*10**-12;#constant in F/m\n",
+ "er=5;#relative permittivity of plywood\n",
+ "er1=1;#relative permittivity in air\n",
+ "\n",
+ "#Calculations&Results\n",
+ "c=(ep*(((a1*er1)/t)+(a2/((t1/er)+(t2/er1)))));#capacitance in farads\n",
+ "vr=(math.sqrt(p/(2*math.pi*f*c*pf)));#voltage is required in volts\n",
+ "print \"part (a)\"\n",
+ "print \"voltage across the electrodes in volts =%.f\"%vr\n",
+ "i=p/(vr*pf);#current in amperes\n",
+ "print \"part (b)\"\n",
+ "print \"cureent in amperes is =%.3f\"%i"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "voltage across the electrodes in volts =12594\n",
+ "part (b)\n",
+ "cureent in amperes is =1.985\n"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch10.ipynb b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch10.ipynb
new file mode 100755
index 00000000..9d4abd1e
--- /dev/null
+++ b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch10.ipynb
@@ -0,0 +1,285 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:afe45272ce3ff93176422df4637443f0511009d7c746f27786eb9c224ddc3321"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10: Braking: Mechanical Considerations and Control Equipment"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.1, Page 300"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "I=[50,100,150,200,250];#\n",
+ "sp=[73.6,48,41.1,37.3,35.2];\n",
+ "T=[150,525,930,1335,1750];\n",
+ "v=600;#in volts\n",
+ "rm=0.6;#\n",
+ "\n",
+ "#Calculations\n",
+ "eb=v-(I[1]*rm);#in volts\n",
+ "rh=3;#in ohms\n",
+ "tr=rh+rm;#in ohms\n",
+ "i=eb/tr;#in amperes\n",
+ "tr=T[2];#\n",
+ "\n",
+ "#Result\n",
+ "print \"braking torque is %.f (N-m)\"%tr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "braking torque is 930 (N-m)\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.2, Page 300"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "I=[20,40,60,80];#\n",
+ "emf=[215,381,485,550];#in volts\n",
+ "emf2=[202,357,455,516];#\n",
+ "T=40*9.81;# load torque in N-m\n",
+ "N=600.;#rpm\n",
+ "ia=56;#in amperes from curve\n",
+ "va=440.;#in volts from graph\n",
+ "\n",
+ "#Calculations\n",
+ "il=T*(2*math.pi*(N/60));#input to load in W\n",
+ "tr=va/ia;# in ohms\n",
+ "tm=0.8;#in ohms\n",
+ "er=tr-tm;#in ohms\n",
+ "\n",
+ "#Result\n",
+ "print \"external resistance to be connected across the motor during break is %.3f ohm\"%er"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "external resistance to be connected across the motor during break is 7.057 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.3, Page 301"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "W=400.;#in tonne\n",
+ "We=1.1*W;# in tonne\n",
+ "S=2.;# distance in km\n",
+ "G=2.;# gradient in %\n",
+ "eta=75./100;# efficiency\n",
+ "D=2.;# distance in km\n",
+ "V1=40.;# in km\n",
+ "V2=20.;# in km\n",
+ "r=40.;#N/tonne\n",
+ "\n",
+ "#Calculations&Results\n",
+ "Ea=(0.01072*We*(V1**2-V2**2))*10**-3;# in kWh\n",
+ "Ft=(W*r)-(98.1*W*G);\n",
+ "M=(-Ft*S*1000)/(1000*3600);\n",
+ "Et=Ea+M;# total energy available\n",
+ "Ee=eta*Et;\n",
+ "print \"Electrical energy,Ee(kWh) = %.1f\"%Ee #answer varies due to roundinf-off errors\n",
+ "As=(V1+V2)/2;# average speed\n",
+ "At=D/As;# Average time taken\n",
+ "P=(Ee/At);\n",
+ "print \"Average power,P(kW) = %.f\"%P"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Electrical energy,Ee(kWh) = 30.3\n",
+ "Average power,P(kW) = 454\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.4, Page 301"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "W=2340;#in tonne\n",
+ "We=1.1*W;# in tonne\n",
+ "G=100./80;# gradient in %\n",
+ "eta=70./100;# efficiency\n",
+ "V1=60.;# in km\n",
+ "V2=36.;# in km\n",
+ "r=5*9.81;#N/tonne\n",
+ "t=5*60.;# in sec\n",
+ "\n",
+ "#Calculations\n",
+ "Ea=(0.01072*We*(V1**2-V2**2))*10**-3;# in kWh\n",
+ "Ft=(W*r)-(98.1*W*G);#tractive effort in N\n",
+ "D=((V1+V2)/2)*(1000./3600)*t;# distance moved in m\n",
+ "M=(-Ft*D)/(1000*3600);\n",
+ "Et=Ea+M;\n",
+ "El=eta*Et;\n",
+ "\n",
+ "#Result\n",
+ "print \"Energy returned to the line,El(kWh) = %.1f\"%El"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Energy returned to the line,El(kWh) = 178.4\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.5, Page 302"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "W=500;#in tonne\n",
+ "G=(20.*100.)/1000;# gradient in %\n",
+ "eta=75./100;# efficiency\n",
+ "V=40;# in kmph\n",
+ "r=40;#N/tonne\n",
+ "\n",
+ "#Calculations\n",
+ "Ft=(W*r)-(98.1*W*G);#tractive effort in N\n",
+ "P=(-Ft*V)/3600;# Power available in kW\n",
+ "Pf=round(P*eta);\n",
+ "\n",
+ "#Result\n",
+ "print \"power fed into the line,Pf(kW) = %.f\"%Pf"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "power fed into the line,Pf(kW) = 651\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10.6, Page 302"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "OD=640.;# voltage represent by phasor OD\n",
+ "R=0.5;# reactor in ohm\n",
+ "Ia=OD/R;\n",
+ "V=400;# in volts\n",
+ "alfa=38.66;#Phase angle in degree\n",
+ "\n",
+ "#Calculations\n",
+ "P=(V*Ia*math.cos(alfa*math.pi/180))*10**-3;\n",
+ "\n",
+ "#Result\n",
+ "print \"Power generated,P(kW) = %.3f\"%P"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Power generated,P(kW) = 399.804\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch11.ipynb b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch11.ipynb
new file mode 100755
index 00000000..33976068
--- /dev/null
+++ b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch11.ipynb
@@ -0,0 +1,401 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:a6d76879a77431d48fb911064902d6e10e1b5563c3eddfcbd42ed97702d7e46f"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Power Supply for Electric Traction"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.1, Page 321"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "l=20;# in m\n",
+ "w=0.5;# weight per meter in kg\n",
+ "T=500;# Tension applied in kg\n",
+ "\n",
+ "#Calculations\n",
+ "dell=(w*l**2)/(2*T);\n",
+ "two_S=2*(l+(2./3)*(dell**2/l));\n",
+ "\n",
+ "#Result\n",
+ "print \"Total Length(m) = %.5f\"%two_S"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total Length(m) = 40.00267\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.2, Page 321"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "l=30;# in meter\n",
+ "w=0.72;# weight per meter in kg\n",
+ "E=640;# in kg/cm^2\n",
+ "d=1;# diameter in cm\n",
+ "\n",
+ "#Calculations\n",
+ "T=E*(math.pi/4)*d**2;\n",
+ "dell=((w*l**2)/(2*T))*100;\n",
+ "\n",
+ "#Result\n",
+ "print \"sag(cm) = %.1f\"%dell"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "sag(cm) = 64.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.3, Page 322"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "l=30;# in meter\n",
+ "w1=0.9;# average weight of catenary wire in kg/m\n",
+ "w2=1.2#average weight of trolley wire in kg/m\n",
+ "\n",
+ "#Calculations\n",
+ "w3=(20./100)*w2#average weight of dropper and fittings in kg/m\n",
+ "w=w1+w2+w3;\n",
+ "T=1000;#in kg\n",
+ "dell=(w*l**2)/(2*T);\n",
+ "\n",
+ "#Result\n",
+ "print \"sag(m) = %.3f\"%dell"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "sag(m) = 1.053\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.4, Page 340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "I=300;# in A\n",
+ "R=0.08;# in ohm\n",
+ "Vd=6;# voltage drop in volts\n",
+ "\n",
+ "#Calculations\n",
+ "I_dash=((R*(I/2))-Vd)/R;\n",
+ "\n",
+ "#Result\n",
+ "print \"Current(A) = %.f\"%I_dash"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current(A) = 75\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.5, Page 340"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "a=7;#far end voltage in volts\n",
+ "i=125;# in A\n",
+ "r=0.02;# in ohm\n",
+ "l=3;# in km\n",
+ "\n",
+ "#Calculations\n",
+ "p=(i*r*l**2)/2;\n",
+ "I=((p-a)/(r*l));#\n",
+ "\n",
+ "#Results\n",
+ "print \"potential of the track at tha far end of the section in volts is %.2f\"%p\n",
+ "print \"Current carried by -ve feeder,I(A) = %.3f\"%I"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "potential of the track at tha far end of the section in volts is 11.25\n",
+ "Current carried by -ve feeder,I(A) = 70.833\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.6, Page 341"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import *\n",
+ "from sympy.solvers import solve\n",
+ "from sympy import Symbol\n",
+ "\n",
+ "#Variable declaration\n",
+ "ix=200;#amperes\n",
+ "r=0.02;#in ohms\n",
+ "\n",
+ "#Calculations\n",
+ "x = Symbol('x')\n",
+ "y = solve(0*x**2 +12*x + 19, x)\n",
+ "ipx=ix*(3-(-1*y[0]));#in amperes\n",
+ "inx=2*ix;#in amperes\n",
+ "it=ipx+inx;#in amperes\n",
+ "\n",
+ "#Result\n",
+ "print \"current through negetive booster in amperes is %.2f\"%it"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "current through negetive booster in amperes is 683.33\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.7, Page 341"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import *\n",
+ "from sympy.solvers import solve\n",
+ "from sympy import Symbol\n",
+ "\n",
+ "#Variable declaration\n",
+ "ix=250;#amperes\n",
+ "vb=2;#in volts\n",
+ "r=0.02;#in ohms\n",
+ "\n",
+ "#Calculations\n",
+ "x = Symbol('x')\n",
+ "y = solve(0*x**2 +16*x - 27.6, x)\n",
+ "pc=vb+(ix*r*(1.6)**2)/2;#in volts\n",
+ "pd=((ix*r*(y[0]**2))/2);#in volts\n",
+ "tcurr= (1.6*ix)+((ix*(3.2-y[0])));#in amperes\n",
+ "vnf=r*tcurr;#in volts\n",
+ "bnb=vnf-vb;#in volts\n",
+ "cb=((bnb*tcurr)/1000);#in kw\n",
+ "\n",
+ "#Result\n",
+ "print \"maximum potential drop on any two points on the rails in volts is %.1f\"%pc\n",
+ "print \"capacity of booster in kW is %.2f\"%cb"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum potential drop on any two points on the rails in volts is 8.4\n",
+ "capacity of booster in kW is 10.28\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.8, Page 342"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import *\n",
+ "from sympy.solvers import solve\n",
+ "from sympy import Symbol\n",
+ "\n",
+ "#Variable declaration\n",
+ "i=200;# A/km\n",
+ "r=0.01;#in ohms/km\n",
+ "\n",
+ "#Calculations\n",
+ "x = Symbol('x')\n",
+ "y = solve(0*x**2 +8*x - 20, x)\n",
+ "i1=400;#in amperes\n",
+ "i2=(4-y[0])*i#in amperes\n",
+ "tc=i1+i2;#in amperes\n",
+ "vcn=r*tc;#in volts\n",
+ "nb=vcn-4;#in volts\n",
+ "rb=(tc*10)/1000;#\n",
+ "\n",
+ "#Result\n",
+ "print \"rating of the booster in kW is %.f\"%rb\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "rating of the booster in kW is 7\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11.9, Page 343"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "vw=60;#in volts\n",
+ "vt=12;#in volts\n",
+ "vs=600;#in volts\n",
+ "vr=578;#volts\n",
+ "vn=10;#in volts\n",
+ "\n",
+ "#Calculations\n",
+ "tv=vw+vt;#in volts\n",
+ "va=vs-tv;#in volts\n",
+ "vtn=tv-vn;#in volts\n",
+ "vad=vs-vr;#\n",
+ "vp=vtn-vad;#in volts\n",
+ "\n",
+ "#Results\n",
+ "print \"part (a)\"\n",
+ "print \"voltage available to trolley when it is at the far end without using boosters in volts is %.f\"%va\n",
+ "print \"part (b)\"\n",
+ "print \"positive booster should provide boost of \",(vp),\" volts\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "voltage available to trolley when it is at the far end without using boosters in volts is 528\n",
+ "part (b)\n",
+ "positive booster should provide boost of 40 volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch3.ipynb b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch3.ipynb
new file mode 100755
index 00000000..461a7916
--- /dev/null
+++ b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch3.ipynb
@@ -0,0 +1,427 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1d5a5fec58f50885b306fd11c5d34341cb747d72353b0fd13bd0ab2048a7d12e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3: Electrolytic Processes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.1, Page 79"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "r=5;#in cm\n",
+ "S=4*math.pi*r**2;\n",
+ "t=0.005;#in mm\n",
+ "d=10.5;\n",
+ "\n",
+ "#Calculations\n",
+ "m=S*t*d*10**-3;\n",
+ "Z=(0.001118*3600)/1000;\n",
+ "Amr=m/Z;\n",
+ "\n",
+ "#Result\n",
+ "print \"ampere hour required,(Ampere-hour)= %.2f\"%Amr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ampere hour required,(Ampere-hour)= 4.10\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.2, Page 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "m=20.;#in gm\n",
+ "I=120;#in A\n",
+ "t=10*60;#in sec\n",
+ "t1=5*60;#in sec\n",
+ "I1=100;#in A\n",
+ "\n",
+ "#Calculations\n",
+ "Cec=63.18/2;\n",
+ "Cen=58.6/2;\n",
+ "Z=m/(I*t);\n",
+ "Z1=(Z*(Cec/Cen))*10**-3;\n",
+ "m1=Z1*I1*t1;\n",
+ "\n",
+ "#Result\n",
+ "print \"mass of copper depsoited is \",round(m1,3),\"kg or \",(round(m1*10**3)),\"gm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "mass of copper depsoited is 0.009 kg or 9.0 gm\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.3, Page 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Z=1.044*10**-8;#in kg/C\n",
+ "I=40;#in A\n",
+ "t=1*60*60;#in seconds\n",
+ "\n",
+ "#Calculations\n",
+ "m1=Z*I*t;\n",
+ "\n",
+ "#Result\n",
+ "print \"mass of copper depsoited is \",round(m1,4),\"kg or \",round((m1*10**3),1),\"gm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "mass of copper depsoited is 0.0015 kg or 1.5 gm\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.4, Page 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "A=0.00025;#in m^2\n",
+ "D=8900;#in kg/m^3\n",
+ "Z=32.95*10**-8;#in kg/C\n",
+ "I=1;#in A\n",
+ "\n",
+ "#Calculations\n",
+ "t=100*60;#in seconds\n",
+ "m=Z*I*t;#in kg\n",
+ "v=m/D;\n",
+ "T=(v/A)*10**3;\n",
+ "\n",
+ "#Result\n",
+ "print \"thickness of copper deposited,T(mm) = %.3f\"%T"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "thickness of copper deposited,T(mm) = 0.889\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.5, Page 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "A=0.00025;#in m^2\n",
+ "D=8900;#in kg/m^3\n",
+ "Z=32.95*10**-8;#in kg/C\n",
+ "I=1.5;#in A\n",
+ "\n",
+ "#Calculations\n",
+ "t=60*60;#in seconds\n",
+ "m=Z*I*t;#in kg\n",
+ "v=m/D;\n",
+ "T=(v/A);\n",
+ "\n",
+ "#Result\n",
+ "print \"Thickness of copper deposited is \",round(T,4),\"m or \",round((T*10**3),1),\"mm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Thickness of copper deposited is 0.0008 m or 0.8 mm\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.6, Page 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "m=50;# in gm\n",
+ "t=2*60*60;# in sec\n",
+ "ECE_silver=111.8*10**-8;# in kg C^-1\n",
+ "atomic_weight1=108;# for silver\n",
+ "atomic_weight2=63.5;#for copper\n",
+ "valency=1;#for silver\n",
+ "\n",
+ "#Calculations\n",
+ "Ces=atomic_weight1/valency;# chemical equivalent of silver\n",
+ "Cec=atomic_weight2/2;# chemical equivalent of copper\n",
+ "Z=ECE_silver*(Cec/Ces);\n",
+ "I=(m*10**-3)/(Z*t);\n",
+ "\n",
+ "#Result\n",
+ "print \"current,I(A) = %.2f\"%I"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "current,I(A) = 21.13\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.7, Page 81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "a=500;# electrolytic cells\n",
+ "I=6000;#in A\n",
+ "t=40;#in hour/week\n",
+ "Z=32.81*10**-8*3600;#in kg/A-h\n",
+ "V=0.25;# in volts\n",
+ "\n",
+ "#Calculations\n",
+ "Ah=a*I*(t*52);# total number of ampere hour per annum\n",
+ "Ao=Z*Ah*10**-3;# annual output in tonnes\n",
+ "Ea=Ah*V*10**-3;# energy consumed per annum in kWh\n",
+ "Et=Ea/Ao;\n",
+ "\n",
+ "#Result\n",
+ "print \"energy consumption,Et(kWh/tonne) = %.2f\"%Et"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "energy consumption,Et(kWh/tonne) = 211.66\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.8, Page 81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Z=1.0384*10**-8;#in kg/C\n",
+ "VbyZ=14.212*10**7;# in joules\n",
+ "\n",
+ "#Calculations\n",
+ "V=VbyZ*Z;\n",
+ "\n",
+ "#Result\n",
+ "print \"voltage,V(volts) = %.3f\"%V"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "voltage,V(volts) = 1.476\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.9, Page 82"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "ECE_silver=111*10**-8;#in kg/C\n",
+ "Cew_silver=107.98;#chemical equivalent of silver\n",
+ "Cew_al=27/3;#chemical equivalent of aluminium\n",
+ "\n",
+ "#Calculations\n",
+ "Z=(ECE_silver*Cew_al)/Cew_silver;\n",
+ "C_efficiency=0.92;\n",
+ "I=3000;#in A\n",
+ "t=24*60*60;#in seconds\n",
+ "m=Z*I*t*C_efficiency;\n",
+ "\n",
+ "#Result\n",
+ "print \"mass of aluminium,m(kg) = %.3f\"%m"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "mass of aluminium,m(kg) = 22.062\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3.10, Page 82"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "d=0.1;#in m\n",
+ "l=.25;# in m\n",
+ "Tc=2;# thickness of coating in mm\n",
+ "D=8.9;#density of metal in gm/CC\n",
+ "C_density=160;#in A/sq\n",
+ "I_efficiency=0.9;\n",
+ "\n",
+ "#Calculations&Results\n",
+ "S=math.pi*d*l;\n",
+ "m=S*Tc*10**-3*D*10**3;\n",
+ "Z=30.43*10**-8;# in kg/C\n",
+ "Q=(m/Z)/3600;# in A-h\n",
+ "Q_dash=Q/I_efficiency;\n",
+ "print \"quantity of electricity,Q_dash(A-h) = %.f\"%Q_dash\n",
+ "I=C_density*S;\n",
+ "t=Q_dash/I;\n",
+ "print \"time required,t(hours) = %.2f\"%t"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "quantity of electricity,Q_dash(A-h) = 1418\n",
+ "time required,t(hours) = 112.84\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch4.ipynb b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch4.ipynb
new file mode 100755
index 00000000..8a1a303b
--- /dev/null
+++ b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch4.ipynb
@@ -0,0 +1,1356 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4099ea94bbb3c9f1b17447df5b8a074a8f60585fc47e2a49454f49261cf5945d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: Illumination"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.1, Page 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "F=1000;#intensity in lumens\n",
+ "\n",
+ "#Calculations\n",
+ "MSCP=F/(4*math.pi);# MSCP of the lamps\n",
+ "\n",
+ "#Result\n",
+ "print \"MSCP of the lamp is %.f\"%MSCP"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "MSCP of the lamp is 80\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.2, Page 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "V=250;#in volts\n",
+ "I=0.8;#in amperes\n",
+ "F=3000;#intensity in lumens\n",
+ "\n",
+ "#Calculations\n",
+ "wl=V*I;#wattage of lapms ins watts\n",
+ "lpw=F/wl;# lumens per watts is\n",
+ "MSCP=F/(4*math.pi);# MSCP of the lamps\n",
+ "MW=MSCP/wl;#MSCP per watts\n",
+ "\n",
+ "#Results\n",
+ "print \"lumens per watt is %.f\"%lpw\n",
+ "print \"MSCP per watt of the lamp is %.1f\"%MW"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "lumens per watt is 15\n",
+ "MSCP per watt of the lamp is 1.2\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.3, Page 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "d=0.4;#diamter in meter\n",
+ "p=0.20;#in percentage absorption\n",
+ "F=4850;# lumens\n",
+ "\n",
+ "#Calculations\n",
+ "Fe=(1-p)*F;# flux emitted by the globe in lumens\n",
+ "sa=4*math.pi*(d/2)**2;#surface area in m^2\n",
+ "als=Fe/sa;#average lumninance of sphere in lumens/m^2\n",
+ "\n",
+ "#Result\n",
+ "print \"average lumninance of sphere in lumens/m^2 = %.f\"%als"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "average lumninance of sphere in lumens/m^2 = 7719\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.4, Page 105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "P=20;#filament power in watts\n",
+ "h=5;#height in meters\n",
+ "d=4;#diamter in meter\n",
+ "p=0.50;#in percentage absorption\n",
+ "ef=0.89;#efficiency in watts\n",
+ "\n",
+ "#Calculations\n",
+ "cpl=P/ef;#candle power of lamp in CP\n",
+ "Lop=4*math.pi*cpl;#lu,inous output in lumens\n",
+ "Fe=(1-p)*Lop;# flux emitted by the globe in lumens\n",
+ "sa=math.pi*(d/2)**2;#surface area in m^2\n",
+ "als=Fe/sa;#average lumninance of sphere in lumens/m^2\n",
+ "\n",
+ "#Result\n",
+ "print \"average lumninance of sphere in lumens/m^2 =%.3f\"%als"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "average lumninance of sphere in lumens/m^2 =11.236\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.5, Page 106"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "cpl=100.;#\n",
+ "h=5;#in meter\n",
+ "th=60;#in degree\n",
+ "F=1000;#intensity in lumens\n",
+ "\n",
+ "#Calculations\n",
+ "MSCP=F/(4*math.pi);# MSCP of the lamps\n",
+ "ai=((cpl/h**2)*math.cos((90-th)*math.pi/180));#average intensity of illumination\n",
+ "\n",
+ "#Results\n",
+ "print \"MSCP of a lamp is= %.f\"%MSCP\n",
+ "print \"average intensity of illumination is %.3f lux \"%ai"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "MSCP of a lamp is= 80\n",
+ "average intensity of illumination is 3.464 lux \n"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.7, Page 106"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "p=500;#lamp power in watts\n",
+ "mscp=1250;#\n",
+ "h=2.7;#in meters\n",
+ "\n",
+ "#Calculations\n",
+ "ea=(mscp)/(h)**2;#illumination directly below lamp in lux\n",
+ "le=(4*math.pi*mscp)/p;#lamp efficiency in lumens/watts\n",
+ "h1=3;#meters\n",
+ "eb=((mscp)/(h**2)*(2.7**3/(h1**2+h**2)**(3./2)));\n",
+ "#illumnination at a point 3 meters away on the horizontal plane vertically below the lamp in lux\n",
+ "\n",
+ "#Results\n",
+ "print \"illumination directly below lamp in lux = %.2f\"%ea\n",
+ "print \"lamp efficiency in lumens/W = %.2f\"%le\n",
+ "print \"illumnination at a point 3 meters away on the horizontal plane vertically below the lamp in lux = %.2f\"%eb"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "illumination directly below lamp in lux = 171.47\n",
+ "lamp efficiency in lumens/W = 31.42\n",
+ "illumnination at a point 3 meters away on the horizontal plane vertically below the lamp in lux = 51.33\n"
+ ]
+ }
+ ],
+ "prompt_number": 45
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.8, Page 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "l=100;#illumination at a point directly below the lamp in lumens/m^3\n",
+ "cp=256.;#\n",
+ "h1=1.2;#in meters\n",
+ "\n",
+ "#Calculations\n",
+ "h=math.sqrt(cp/l);#height in meters\n",
+ "x=math.sqrt(h**2+h1**2);#\n",
+ "x1=h/x;#\n",
+ "eb=((cp)/(h**2))*(x1)**3;#illumnination at a point 1.2 meters away on the horizontal plane vertically below the lamp in lux\n",
+ "\n",
+ "#Results\n",
+ "print \"height in meters is =%.1f\"%h\n",
+ "print \"illumnination at a point 1.2 meters away on the horizontal plane vertically below the lamp in lux =%.1f\"%eb"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "height in meters is =1.6\n",
+ "illumnination at a point 1.2 meters away on the horizontal plane vertically below the lamp in lux =51.2\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.9, Page 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "L1=500.;#candle power \n",
+ "h1=9.;#in meters\n",
+ "d=2;#distance in meters\n",
+ "I2=20;#illumination in Lux\n",
+ "\n",
+ "#Calculations\n",
+ "x=math.sqrt(h1**2+d**2);#from pythagoras theoram\n",
+ "Cpx=((I2-(L1/h1**2))*h1**2)/((h1/x)**3);#candle power \n",
+ "\n",
+ "#Result\n",
+ "print \"candle power of lamp two in CP =%.f\"%Cpx"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "candle power of lamp two in CP =1204\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.10, Page 107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "h1=10;#in meters\n",
+ "eL=1;#ASSUME\n",
+ "Ea=1./(10)**2;#\n",
+ "\n",
+ "#Calculations\n",
+ "X=(((10**3)*eL)/10**2)*10*(1./Ea);\n",
+ "x=(X)**(2./3);#\n",
+ "y=math.sqrt(x-100);#\n",
+ "\n",
+ "#Result\n",
+ "print \"distance in meters is %.1f\"%y"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "distance in meters is 19.1\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.11, Page 108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "th=15.;#in degree\n",
+ "l=400;#candela\n",
+ "d=8;# meter\n",
+ "p=0.80;#in percentage absorption\n",
+ "\n",
+ "#Calculations\n",
+ "Fe=p*4*math.pi*l;# flux emitted by the globe in lumens\n",
+ "dA=d*math.tan((th/2)*math.pi/180);#diameter in degree\n",
+ "sa=math.pi*(dA)**2;#surface area in m^2\n",
+ "als=Fe/sa;#average lumninance of sphere in lux\n",
+ "\n",
+ "#Result\n",
+ "print \"total flux in lumens = %.f\"%Fe\n",
+ "print \"average lumninance of sphere is %.f lux\"%als"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total flux in lumens = 4021\n",
+ "average lumninance of sphere is 1154 lux\n"
+ ]
+ }
+ ],
+ "prompt_number": 54
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.12, Page 108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "CP=1000.;#\n",
+ "h=12;#in meter\n",
+ "d=24;#diamter in meter\n",
+ "\n",
+ "#Calculations\n",
+ "mil=CP/(h)**2;#maximum illumination in lux\n",
+ "mal=mil*(12/math.sqrt(12**2+12**2))**3;#minimum illumination in lux\n",
+ "\n",
+ "#Results\n",
+ "print \"maximum illumination is %.2f lux\"%mil\n",
+ "print \"minimum illumination is %.2f lux\"%mal"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum illumination is 6.94 lux\n",
+ "minimum illumination is 2.46 lux\n"
+ ]
+ }
+ ],
+ "prompt_number": 56
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.13, Page 108"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "p=60.;#\n",
+ "CP=200.;#\n",
+ "h=6;#in meter\n",
+ "d=10;#diamter in meter\n",
+ "\n",
+ "#Calculations&Results\n",
+ "mil=CP/(h)**2;#maximum illumination in lux\n",
+ "print \"part (a). \"\n",
+ "print \"illumination at the centre of the area without reflector is %.2f lux\"%mil\n",
+ "mal=mil*(h/math.sqrt(h**2+(d/2)**2))**3;#minimum illumination in lux\n",
+ "tl=4*math.pi*CP;#total lumens \n",
+ "ts=(p/100)*tl;#total lumens reaching the surface\n",
+ "A=math.pi*(d/2)**2;#total surface area in m**2\n",
+ "alf=ts/A;#average illumination with reflector\n",
+ "x=math.sqrt(h**2+(d/2)**2);#\n",
+ "y=h/x;#\n",
+ "om=2*math.pi*(1-y);# in steradians\n",
+ "tfr=CP*om;#total flux reaching the surface\n",
+ "alwr=tfr/A;#average illumination without reflector\n",
+ "print \"\\npart (b). \"\n",
+ "print \"illumination at the edge of the area without reflector is %.2f lux\"%mal\n",
+ "print \"average illumination with reflector is %.1f lux\"%alf\n",
+ "print \"average illumination without reflelctor is %.1f lux\"%alwr\n",
+ "#with the reflector the illumintaion at the edge and at the end will be the same since the reflection directs the \n",
+ "#light uniformity on the surface"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a). \n",
+ "illumination at the centre of the area without reflector is 5.56 lux\n",
+ "\n",
+ "part (b). \n",
+ "illumination at the edge of the area without reflector is 2.52 lux\n",
+ "average illumination with reflector is 19.2 lux\n",
+ "average illumination without reflelctor is 3.7 lux\n"
+ ]
+ }
+ ],
+ "prompt_number": 58
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.14, Page 109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "CP=100.;#\n",
+ "h=6.;#in meter\n",
+ "d=16;# meter\n",
+ "\n",
+ "#Calculations\n",
+ "x=math.sqrt(h**2+d**2);#\n",
+ "em=2*((CP/h**2)*(h/(d-h))**3);#illumination in the middle in lux\n",
+ "ee=((CP/h**2)*(1+(h/x)**3));#illumination iunder each lamp in lux\n",
+ "\n",
+ "#Results\n",
+ "print \"illumination under each lamp is %.1f lux\"%ee\n",
+ "print \"illumination in the middle is %.1f lux\"%em"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "illumination under each lamp is 2.9 lux\n",
+ "illumination in the middle is 1.2 lux\n"
+ ]
+ }
+ ],
+ "prompt_number": 59
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.15, Page 109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "CP=800;#\n",
+ "h=10;#in meter\n",
+ "d=12;# meter\n",
+ "\n",
+ "#Calculations\n",
+ "x=math.sqrt(h**2+d**2);#\n",
+ "x1=math.sqrt(h**2+(d/2)**2);#\n",
+ "em=((CP/h**2)*(1+(h/x)**3+(h/x)**3));#illumination iunder each lamp in lux\n",
+ "ee=2*((CP/h**2)*(h/x1)**3);#illumination at the centrelamp in lux\n",
+ "\n",
+ "#Results\n",
+ "print \"illumination under each lamp is %.1f lux\"%em\n",
+ "print \"illumination in the middle is %.3f lux\"%ee"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "illumination under each lamp is 12.2 lux\n",
+ "illumination in the middle is 10.088 lux\n"
+ ]
+ }
+ ],
+ "prompt_number": 60
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.16, Page 110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "CP=400;#\n",
+ "h=10;#in meter\n",
+ "d=20;# meter\n",
+ "\n",
+ "#Calculations\n",
+ "x=math.sqrt(d**2-h**2);#\n",
+ "ee=4*((CP/h**2)*(h/x)**3);#illumination at the centrelamp in lux\n",
+ "\n",
+ "#Result\n",
+ "print \"illumination in the middle is %.2f lux\"%ee"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "illumination in the middle is 3.08 lux\n"
+ ]
+ }
+ ],
+ "prompt_number": 61
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.17, Page 111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "cp=500.;#cp\n",
+ "h=4.;#in meter\n",
+ "\n",
+ "#Calculations\n",
+ "x=((2*cp*h**3)/h**2);#\n",
+ "y=((cp*h**3)/h**2);#\n",
+ "y1=cp/h**2;#\n",
+ "y2=y/2;#\n",
+ "y21=y1/2;#\n",
+ "d=math.sqrt((((x-y2)/y21)**(2./3))-h**2)*2.29;#\n",
+ "\n",
+ "#Result\n",
+ "print \"distance is,(m)= %.2f\"%d\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "distance is,(m)= 9.52\n"
+ ]
+ }
+ ],
+ "prompt_number": 62
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.18, Page 111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "d=6;#in meter\n",
+ "h=4;#in meter\n",
+ "ef=20;#lumens per watt\n",
+ "uc=0.5;#utilization coefficient\n",
+ "il=750;# in lux\n",
+ "\n",
+ "#Calculations\n",
+ "a=(math.pi/4)*(d)**2;#\n",
+ "F=a*il;#in lumens \n",
+ "tf=F/uc;#total flux emitted by the lamp\n",
+ "watt=tf/ef;#wattage of lamp\n",
+ "\n",
+ "#Result\n",
+ "print \"wattage of lamp is %.f watts\"%watt"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "wattage of lamp is 2121 watts\n"
+ ]
+ }
+ ],
+ "prompt_number": 63
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.19, Page 130"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "vl=220.;#voltage of lamp\n",
+ "wl=60.;#wattage of lamp\n",
+ "wl1=75.;#in watts\n",
+ "v2=440.;# in volts\n",
+ "\n",
+ "#Calculations\n",
+ "r1=((vl**2)/wl);# in ohms\n",
+ "r2=((vl**2)/wl1);# in ohms\n",
+ "i=(v2/(r1+r2));#in amperes\n",
+ "v1=i*r1;# volts \n",
+ "v12=i*r2;#in volts\n",
+ "cp6=(math.ceil(v1)/vl)**4 *(100);#candle power \n",
+ "cp7=(v12/vl)**4*(100);#candle power\n",
+ "\n",
+ "#Results\n",
+ "print \"potential drop across 60 watt lamps is %.f volts\"%cp6\n",
+ "print \"potential drop across 75 watt lamps is %.f volts\"%v12\n",
+ "print \"candle power of 60 watts lampe in percentage = %.f\"%cp6\n",
+ "print \"candle power of 75 watts lampe in percentage %.f\"%cp7\n",
+ "#answer is wrong in the book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "potential drop across 60 watt lamps is 154 volts\n",
+ "potential drop across 75 watt lamps is 196 volts\n",
+ "candle power of 60 watts lampe in percentage = 154\n",
+ "candle power of 75 watts lampe in percentage 62\n"
+ ]
+ }
+ ],
+ "prompt_number": 66
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.20, Page 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "w=84;#watts\n",
+ "pf=0.7;#power factor\n",
+ "v=240;#in volts\n",
+ "\n",
+ "#Calculations\n",
+ "i=(w)/(v*pf);# in amperes\n",
+ "rva=v*i*math.sqrt(1-pf**2);#relative volt-amperes \n",
+ "cpf=1;#corrected power factor\n",
+ "rvas=v*i*math.sqrt(1-cpf**2);#\n",
+ "f=50;# in hertz\n",
+ "c=((rva)/(2*math.pi*f*(v)**2));#in farads\n",
+ "\n",
+ "#Result\n",
+ "print \"capacitance in (micro-F) is %.2f\"%(c*10**6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "capacitance in (micro-F) is 4.74\n"
+ ]
+ }
+ ],
+ "prompt_number": 67
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.21, Page 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "v1=110;#in volts\n",
+ "cp1=16.;#in cp\n",
+ "cp2=25;#in cp\n",
+ "v2=220.;#in volts\n",
+ "\n",
+ "#Calculations\n",
+ "ri=((cp1/cp2)*(v2/v1));#ratio of curents\n",
+ "dr=(ri)**(2./3);#ratio of diameters\n",
+ "di=(cp1/cp2)*(1./dr);#ratio of lengths\n",
+ "\n",
+ "#Results\n",
+ "print \"ratio of diameter is %.2f\"%dr\n",
+ "print \"ratio of length is %.3f\"%di"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ratio of diameter is 1.18\n",
+ "ratio of length is 0.543\n"
+ ]
+ }
+ ],
+ "prompt_number": 68
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.22, Page132"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "c1=71.5;#candel power\n",
+ "v1=260.;#in volts\n",
+ "c2=50.;#candel power\n",
+ "v2=240;#in volts\n",
+ "\n",
+ "#Calculations&Results\n",
+ "b=math.log(c1/c2)/(math.log(v1/v2));#\n",
+ "a=c2/(v2)**(4.5);#\n",
+ "print \"part (a). \"\n",
+ "print \"constants are %.2e and %.1f\"%(a,b)\n",
+ "v=250;# in volts\n",
+ "p=4.;#change in percentage\n",
+ "dvc=a*b*((v)**(b-1));#in candle per volts\n",
+ "dc=(1+(p/100))**b;#when voltage increase by 4%\n",
+ "pcp=((dc-1))*100;#percentage change in candle power\n",
+ "dc1=(1-(p/100))**b;#when voltage falls by 4%\n",
+ "pcp1=((dc1-1))*100;#percentage change in candle power\n",
+ "print \"part (b).\"\n",
+ "print \"change of candle power is %.2f per volts\"%dvc\n",
+ "\n",
+ "#chage in candle power per volt is calculated wrong in the book\n",
+ "print \"percentage change in candle power when voltage increase by 4%% is %.1f\"%pcp\n",
+ "print \"percentage change in candle power when voltage falls by 4%% is %.1f\"%pcp1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a). \n",
+ "constants are 9.73e-10 and 4.5\n",
+ "part (b).\n",
+ "change of candle power is 0.90 per volts\n",
+ "percentage change in candle power when voltage increase by 4% is 19.2\n",
+ "percentage change in candle power when voltage falls by 4% is -16.7\n"
+ ]
+ }
+ ],
+ "prompt_number": 73
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.23, Page 139"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "dp=1.2;#depreciation factor\n",
+ "uf=0.6;#utiliazation factor\n",
+ "l=15;# in meters\n",
+ "b=6;# in meters\n",
+ "n=20;# no. of lamps\n",
+ "lw=250;# mscp in watts\n",
+ "\n",
+ "#Calculations\n",
+ "a=l*b;#arean in m^2\n",
+ "tl=n*lw*4*math.pi;#/total lumens\n",
+ "lwp=((tl*uf)/dp);#lumens reaching on the working plane\n",
+ "e=lwp/a;#illumination on working plane in lux\n",
+ "\n",
+ "#Result\n",
+ "print \"illumination on working plane is %.f lux\"%e"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "illumination on working plane is 349 lux\n"
+ ]
+ }
+ ],
+ "prompt_number": 74
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.24, Page 139"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "ef=40;#efficiency in lumens/watt\n",
+ "mil=80;# minimum illumination in lumens/m^2\n",
+ "dp=0.8;#depreciation factor\n",
+ "uf=0.4;#utiliazation factor\n",
+ "l=100;# in meters\n",
+ "b=10;# in meters\n",
+ "\n",
+ "#Calculations\n",
+ "a=l*b;#arean in m^2\n",
+ "tl=a*mil;#/total lumens\n",
+ "glr=tl/(uf*dp);#gross illumination required\n",
+ "twr=glr/ef;#total wattage required\n",
+ "\n",
+ "#Results\n",
+ "print \"number of lamps of 150watt rating in 2 rows are 42\" \n",
+ "print \"total wattage is %.f watts\"%twr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of lamps of 150watt rating in 2 rows are 42\n",
+ "total wattage is 6250 watts\n"
+ ]
+ }
+ ],
+ "prompt_number": 75
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.25, Page 140"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "h=4;#in meters\n",
+ "wp=75;#in lux\n",
+ "ef=14;#efficiency in lumens/watt\n",
+ "dp=0.2;#depreciation factor\n",
+ "uf=0.5;#utiliazation factor\n",
+ "l=72;# in meters\n",
+ "b=15;# in meters\n",
+ "\n",
+ "#Calculations\n",
+ "a=l*b;#arean in m^2\n",
+ "mf=1-dp;#maintenance factor\n",
+ "glr=(a*wp)/(uf*mf);#gross illumination required\n",
+ "twr=glr/ef;#total wattage required\n",
+ "wec=twr/80;#wattage of each lamps\n",
+ "\n",
+ "#Results\n",
+ "print \"number of lamps of 150watt rating in 2 rows are 80\"\n",
+ "print \" wattage of each lamp \",round(wec,1),\" watts equivalent to 200 watts\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of lamps of 150watt rating in 2 rows are 80\n",
+ " wattage of each lamp 180.8 watts equivalent to 200 watts\n"
+ ]
+ }
+ ],
+ "prompt_number": 76
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.26, Page 140"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "a=30*30;#\n",
+ "e=75;#\n",
+ "uf=0.5;#\n",
+ "df=1-0.2;#\n",
+ "le=15;#efficiency\n",
+ "\n",
+ "#Calculations\n",
+ "ph=(a*e)/(uf*df);#\n",
+ "W=ph/le;#\n",
+ "ew=300;#W\n",
+ "N=W/ew;#\n",
+ "\n",
+ "#Results\n",
+ "print \"total number of lamps is %.1f (say 42)\"%N\n",
+ "print \"wattage of lamps is %.f W\"%W"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total number of lamps is 37.5 (say 42)\n",
+ "wattage of lamps is 11250 W\n"
+ ]
+ }
+ ],
+ "prompt_number": 77
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.27, Page 141"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "h=5;# in meters\n",
+ "el=100;#in lux\n",
+ "ef=16;#efficiency in lumens/watt\n",
+ "dp=0.2;#depreciation factor\n",
+ "uf=0.4;#utiliazation factor\n",
+ "l=60;# in meters\n",
+ "b=15;# in meters\n",
+ "\n",
+ "#Calculations\n",
+ "a=l*b;#arean in m^2\n",
+ "glr=(a*el)/(uf*(1-dp));#gross illumination required\n",
+ "n=12*3;#total no. of \n",
+ "twr=glr/ef;#total wattage required\n",
+ "wec=twr/n;#wattage of each lamp\n",
+ "\n",
+ "#Results\n",
+ "print \"number of lamps of 150watt rating in 2 rows are %.f\"%n\n",
+ "print \"wattage of each lamp \",round(wec,1),\" watts equivalent to 500 watts\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of lamps of 150watt rating in 2 rows are 36\n",
+ "wattage of each lamp 488.3 watts equivalent to 500 watts\n"
+ ]
+ }
+ ],
+ "prompt_number": 78
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.28, Page 141"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "h=5;# in meters\n",
+ "el=120;#in lux\n",
+ "ef=40;#efficiency in lumens/watt\n",
+ "tw=80;#in watts\n",
+ "df=1.4;#depreciation factor\n",
+ "uf=0.5;#utiliazation factor\n",
+ "l=30;# in meters\n",
+ "b=15;# in meters\n",
+ "\n",
+ "#Calculations\n",
+ "a=l*b;#arean in m^2\n",
+ "glr=(a*el*df)/(uf);#gross lumens required\n",
+ "twr=glr/ef;#total wattage required\n",
+ "nt=twr/tw;#no. of tubes required\n",
+ "\n",
+ "#Results\n",
+ "print \"total wattage required is %.f watts\"%twr\n",
+ "print \" number of tubes required is \",nt,\" equivalent to 48 tubes\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total wattage required is 3780 watts\n",
+ " number of tubes required is 47.25 equivalent to 48 tubes\n"
+ ]
+ }
+ ],
+ "prompt_number": 79
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.29, Page 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "el=50;#in lux\n",
+ "df=1.3;#depreciation factor\n",
+ "uf=0.5;#utiliazation factor\n",
+ "l=30;# in meters\n",
+ "b=12;# in meters\n",
+ "\n",
+ "#Calculations\n",
+ "a=l*b;#arean in m^2\n",
+ "glr=(a*el*df)/(uf);#gross lumens required\n",
+ "watt=[100,200,300,500,1000];\n",
+ "lum=[1615,3650,4700,9950,21500];#\n",
+ "for i in range(0,5):\n",
+ " n=glr/(lum[i]);#\n",
+ " print \"if \",(watt[i]),\" watt lamps are used then number of lamps required is %.f\"%n\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "if 100 watt lamps are used then number of lamps required is 29\n",
+ "if 200 watt lamps are used then number of lamps required is 13\n",
+ "if 300 watt lamps are used then number of lamps required is 10\n",
+ "if 500 watt lamps are used then number of lamps required is 5\n",
+ "if 1000 watt lamps are used then number of lamps required is 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 88
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.30, Page 146"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "ef=17.4;#in mumens/watt\n",
+ "dp=1.2;#depreciation factor\n",
+ "wlf=1.3;#waste light factor\n",
+ "uf=0.4;#utiliazation factor\n",
+ "l=50;# in meters\n",
+ "b=16;# in meters\n",
+ "n=16;# no. of lamps\n",
+ "lw=1000;# mscp in watts\n",
+ "\n",
+ "#Calculations\n",
+ "a=l*b;#arean in m^2\n",
+ "tl=n*lw*ef;#/total lumens\n",
+ "lwp=((tl*uf)/(wlf*dp));#lumens reaching on the working plane\n",
+ "e=lwp/a;#illumination on the surface in lumens/m^2\n",
+ "\n",
+ "#Result\n",
+ "print \"illumination on the surface is %.2f lumens/m^2\"%e"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "illumination on the surface is 89.23 lumens/m^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 89
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4.31, Page 146"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "watt=[300,500,1000,1500];\n",
+ "lum=[5000,9000,18000,27000];#\n",
+ "el=50;# in lux\n",
+ "dp=0.8;#depreciation factor\n",
+ "wlf=0.5;#waste light factor\n",
+ "uf=1.2;#utiliazation factor\n",
+ "l=60;# in meters\n",
+ "b=15;# in meters\n",
+ "lw=1000;# mscp in watts\n",
+ "\n",
+ "#Calculations\n",
+ "a=l*b;#area in m^2\n",
+ "tl=a*el#total lumens\n",
+ "lwp=((tl*uf)/(wlf*dp));#lumens reaching on the working plane\n",
+ "n = lwp/lum[1];#number of projector required\n",
+ "ang=2*math.degrees(math.atan(4.5/8));#size\n",
+ "\n",
+ "#Results\n",
+ "print \"number of projectors are,= %.f\"%(n+1)\n",
+ "print \"wattage is,(W)= %.d\"%watt[1]\n",
+ "print \"beam angle is %.f (degree)\"%(ang+1)\n",
+ "print (round(n)+1), \" projectors of \",(watt[1]),\" watts each with beam angle of \",(round(ang+1)),\" degree will be required\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of projectors are,= 16\n",
+ "wattage is,(W)= 500\n",
+ "beam angle is 60 (degree)\n",
+ "16.0 projectors of 500 watts each with beam angle of 60.0 degree will be required\n"
+ ]
+ }
+ ],
+ "prompt_number": 106
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch5.ipynb b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch5.ipynb
new file mode 100755
index 00000000..1196ae95
--- /dev/null
+++ b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch5.ipynb
@@ -0,0 +1,111 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5c3fe95123ad1823bf27f0dcc3936ac12b44099c39a2cdfe385de3987b8c8cbd"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5: Refrigeration and Air-Conditioning"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.1, Page 178"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "t1=20;# in degree C\n",
+ "t2=5;# in degree C\n",
+ "T=t1-t2;\n",
+ "A=3000;# volume of air to be conditioned in m^3\n",
+ "Ht=1220;# in J\n",
+ "\n",
+ "#Calculations\n",
+ "H1=A*Ht*T;\n",
+ "m=1000; # per m^3\n",
+ "Hl=2450*10**3;# latent heat in J/kg\n",
+ "w=5;# in kg\n",
+ "M=(w*A)/m;\n",
+ "H2=T*Hl;#in J\n",
+ "H=(H1+H2);\n",
+ "P=round(H/(3600*1000));\n",
+ "\n",
+ "#Result\n",
+ "print \"Power required,(kW) = %.f\"%P"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Power required,(kW) = 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5.2, Page 178"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "t1=25;# in degree C\n",
+ "t2=5;# in degree C\n",
+ "\n",
+ "#Calculations\n",
+ "T=t1-t2;\n",
+ "A=6*5*4*(60./15);# volume of air to be conditioned in m^3/hour\n",
+ "Ht=1220;# in J\n",
+ "H1=A*Ht*T;\n",
+ "m=1000; # per m^3\n",
+ "Hl=836*10**3;# heat loss in J/C/h\n",
+ "H2=T*Hl;#in J/hour\n",
+ "H=(H1+H2);\n",
+ "Rh=round(H/(3600*1000));\n",
+ "\n",
+ "#Result\n",
+ "print \"Rating of heater,(kW) %.f \"%Rh"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rating of heater,(kW) 8 \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch7.ipynb b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch7.ipynb
new file mode 100755
index 00000000..4d51385d
--- /dev/null
+++ b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch7.ipynb
@@ -0,0 +1,1409 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:0876ba2d073e5d2d4ee81bd1d4eeecb803e69345a7fd0a525fce070b69e673cc"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Train Movement and Energy Consumption"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1, Page 203"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "%pylab inline\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=5.;#aceleration in kmphps\n",
+ "t1=30.;#in seconds\n",
+ "vm=a*t1;#maximum speed in kmph\n",
+ "tfr=10.;#time for free running in mins\n",
+ "b=5.;#retardation in kmphps\n",
+ "\n",
+ "#Calculations&Results\n",
+ "ts=vm/b;#time for retardation in seconds\n",
+ "dta=((vm*t1)/(2*3600));#distance travelled during acceleration period\n",
+ "dtfr=((vm*tfr*60)/(3600));#distance travelled during retardation period\n",
+ "dtbp=dta;#distance travelled during breaking period\n",
+ "td=dta+dtfr+dtbp;#total distance between stations\n",
+ "print \"\\npart (a) \"\n",
+ "print \"total distance between station is %.1f km\"%td\n",
+ "T=[0,t1,(t1+(tfr*60)),(t1+(t1+(tfr*60)))];#\n",
+ "V=[0,vm,vm,0];#\n",
+ "plot(T,V)\n",
+ "xlabel(\"Time in seconds \")\n",
+ "ylabel(\"Spped in Km per Hour\")\n",
+ "va=(td*3600)/(t1+(tfr*60)+ts);#average speed in kmph\n",
+ "print \"part (b) \"\n",
+ "print \"average speed is %.2f kmph\"%va\n",
+ "tst=5;#stop time in mins\n",
+ "vs=(td*3600)/(t1+(tfr*60)+ts+(tst*60));#sheduled speed in kmph\n",
+ "print \"part (c) \"\n",
+ "print \"sheduled speed is %.2f kmph\"%vs"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Populating the interactive namespace from numpy and matplotlib\n",
+ "\n",
+ "part (a) \n",
+ "total distance between station is 26.2 km\n",
+ "part (b) "
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "average speed is 143.18 kmph\n",
+ "part (c) \n",
+ "sheduled speed is 98.44 kmph\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0xb148f72c>"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2, Page 204"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "%pylab inline\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=1.7;#aceleration in kmphps\n",
+ "b=3.3;#kmphps\n",
+ "s=1400;#m\n",
+ "va=42;#kmph\n",
+ "\n",
+ "#Calculations&Results\n",
+ "tr=((s*10**-3)/va)*3600;#secomds\n",
+ "k=((1./(2*a)))+((1./(2*b)));#\n",
+ "vm=((tr/(2*k))-math.sqrt(((tr**2)/(4*k**2))-((3600*s*10**-3)/k)));#in kmph\n",
+ "t1=vm/a;#seconds\n",
+ "t3=vm/b;#seconds\n",
+ "t2=tr-(t1+t3);#seconds\n",
+ "T=[0,(t1),(t1+t2),(t1+t2+t3)];\n",
+ "V=[0,vm,vm,0];\n",
+ "plot(T,V);\n",
+ "xlabel(\"Time in seconds \")\n",
+ "ylabel(\"Spped in Km per Hour\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Populating the interactive namespace from numpy and matplotlib\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 1,
+ "text": [
+ "<matplotlib.text.Text at 0xb14e4d6c>"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0xb5634ecc>"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3, Page 204"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=2.4;#aceleration in kmphps\n",
+ "b=3.2;#retardation in kmphps\n",
+ "s=1.5;#in km\n",
+ "vs=45;#shedule speed in kmph\n",
+ "\n",
+ "#Calculations\n",
+ "ts=(s*3600)/vs;#shedule time in seconds\n",
+ "tst=20;#stop time\n",
+ "tr=ts-tst;#actual time for run in seconds\n",
+ "k=((1/(2*a))+(1/(2*b)));#constant\n",
+ "vm=((tr/(2*k))-math.sqrt(((tr**2)/(4*k**2))-((3600*s)/k)));#in kmph\n",
+ "\n",
+ "#Result\n",
+ "print \"maximum speed is %.f kmph\"%vm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum speed is 74 kmph\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.4, Page 205"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "s=1.5;#in Km\n",
+ "a=0.8;#aceleration in kmphps\n",
+ "tsr=26;#time for stop in seconds\n",
+ "rm=1.3;#ratio\n",
+ "b=3.2;#retardation in kmphps\n",
+ "\n",
+ "#Calculations\n",
+ "k=((1/(2*a))+(1/(2*b)));#constant\n",
+ "T=1;#assume\n",
+ "va1=(3600*s)/T;#average spped\n",
+ "vm1=(va1*rm);#maximum speed\n",
+ "vm=math.sqrt((vm1-va1)/k);#maximum speed in kmph\n",
+ "va=vm/1.3;#actua speed in kmpj\n",
+ "ta=(3600*s)/va;#actual time in seconds\n",
+ "ts=ta+tsr;#shedule time\n",
+ "vs=(s*3600)/ts;#shedule speed in kmph\n",
+ "\n",
+ "#Result\n",
+ "print \"schedule speed is %.f kmph\"%vs"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "schedule speed is 30 kmph\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5, Page 205"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "S=1.;# in km\n",
+ "Vs=30.;# in km/h\n",
+ "Ts=(S*3600)/Vs; # in sec\n",
+ "D=20;# duration of stop in sec\n",
+ "\n",
+ "#Calculations\n",
+ "T=Ts-D;# in sec\n",
+ "Va=(S*3600)/T;# Average speed in km/h\n",
+ "Vm=1.25*Va;# Maximum speed in km/h\n",
+ "beta1=3;# braking retardation in km/h/sec\n",
+ "A=((Vm*T)-(S*3600))/Vm**2;\n",
+ "B=1./(2*beta1);\n",
+ "alfa=1./(2*(A-B));\n",
+ "\n",
+ "#Result\n",
+ "print \"The Acceleration,alfa is (km/h/sec) = %.1f \"%alfa"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Acceleration,alfa is (km/h/sec) = 1.8 \n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.6, Page 206"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "S=4;# in km\n",
+ "Vs=45;# in km/h\n",
+ "Ts=(S*3600)/Vs; # in sec\n",
+ "D=30;# duration of stop in sec\n",
+ "\n",
+ "#Calculations\n",
+ "T=Ts-D;# in sec\n",
+ "Vm=70.;# Maximum speed in km/h\n",
+ "alfa=1.5;# in km/h/sec\n",
+ "A=((Vm*T)-(S*3600))/Vm**2;\n",
+ "B=1./(2*alfa);\n",
+ "Beta=1./(2*(A-B));\n",
+ "\n",
+ "#Result\n",
+ "print \"Retardation(km/h/sec) = %.3f\"%Beta"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Retardation(km/h/sec) = 0.574\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7, Page 206"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "S=1.6;# in km\n",
+ "Va=40;# in km/h\n",
+ "V1=64;# in km/h\n",
+ "alfa=2.0;#in km/p/sec\n",
+ "Beta_c=0.16;# in km/h/sec\n",
+ "Beta=3.2;# in km/h/sec\n",
+ "\n",
+ "#Calculations&Results\n",
+ "t1=V1/alfa;# in sec\n",
+ "print \"Duration of Acceleration,t1(sec) = %.f\"%t1\n",
+ "T=(S*3600)/Va;# in sec\n",
+ "# Formula: T=(V1/alfa)+((V1-V2)/Beta_c)+(V2/Beta)\n",
+ "V2=(t1+(V1/Beta_c)-T)/((1/Beta_c)-(1/Beta));\n",
+ "t2=(V1-V2)/Beta_c;\n",
+ "print \"Duration of coasting,t2(sec) = %.2f\"%t2\n",
+ "t3=V2/Beta;\n",
+ "print \"Duration of braking,t3(sec) = %.2f\"%t3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Duration of Acceleration,t1(sec) = 32\n",
+ "Duration of coasting,t2(sec) = 96.84\n",
+ "Duration of braking,t3(sec) = 15.16\n"
+ ]
+ }
+ ],
+ "prompt_number": 45
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8, Page 209"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "W=200;# weight of train in tonnes\n",
+ "D=0.9;# diameter in m\n",
+ "G=(1./200)*100;#percentage gradient\n",
+ "r=50;# in N/tonne\n",
+ "gama=4;# gear ratio\n",
+ "eta=0.80;# gearing efficiency\n",
+ "We=1.10*W;# in tonne\n",
+ "Vm=48.;# maximum speed in km/h\n",
+ "t1=30;# in sec\n",
+ "\n",
+ "#Calculations\n",
+ "alfa=Vm/t1;# in km/h/sec\n",
+ "Ft=(277.8*We*alfa)+(98.1*W*G)+(W*r);# tractive effect required in N\n",
+ "T1=(Ft*D)/(eta*2*gama);# in N-m\n",
+ "T=round(T1/8);\n",
+ "\n",
+ "#Result\n",
+ "print\"Torque developed by each motor,T(N-m) = %.f\"%T"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Torque developed by each motor,T(N-m) = 2067\n"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9, Page 210"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "V=3000.;# line voltage in volts\n",
+ "W=200.;# weight of train in tonnes\n",
+ "D=0.9;# diameter in m\n",
+ "G=(30./1000)*100;#percentage gradient\n",
+ "r=50;# in N/tonne\n",
+ "gama=4.;# gear ratio\n",
+ "Vm=50.;#in km/h\n",
+ "eta=0.9;# gearing efficiency\n",
+ "\n",
+ "#Calculations&Results\n",
+ "We=1.10*W;# in tonne\n",
+ "T=4*6000;# in N-m\n",
+ "eta_m=85./100;# efficiency of motor\n",
+ "Ft=(eta*T*2*gama)/D;\n",
+ "A=(98.1*W*G)+(W*r);\n",
+ "B=Ft-A;\n",
+ "alfa=B/(277.8*We);# tractive effect required in N\n",
+ "t=Vm/alfa;\n",
+ "print \"Time taken ,t(sec) = %.2f\"%t\n",
+ "Po=(Ft*Vm)/3600;# in kw\n",
+ "Pi=Po/eta_m;\n",
+ "It=(Pi*1000)/V;# in A\n",
+ "I=It/4\n",
+ "print \"Current drawn per motor,I(A) = %.1f\"%I"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time taken ,t(sec) = 24.82\n",
+ "Current drawn per motor,I(A) = 261.4\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.10, Page 211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "V=36;# speed in km/h\n",
+ "W=120;# in tonne\n",
+ "G=2;# in per cent\n",
+ "\n",
+ "#Calculations\n",
+ "r=2*9.81;# in N/tonne\n",
+ "Ft=(98.1*W*G)+(W*r);\n",
+ "e=88./100; # efficiency of motors and gear\n",
+ "VL=1500;#line voltage in volts\n",
+ "Po=(Ft*V)/3600;\n",
+ "Pi=Po/e;\n",
+ "I=(Pi*1000)/VL;\n",
+ "bc=((98.1*(2+(0.1*2)))/(277.8*1.1));#in kmphps\n",
+ "tt=V/bc;#in seconds\n",
+ "\n",
+ "#Results\n",
+ "print \"current required in amperes is %.1f\"%I\n",
+ "print \"time taken to come to rest in seconds is %.f\"%tt"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "current required in amperes is 196.2\n",
+ "time taken to come to rest in seconds is 51\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.11, Page 211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "t1=24;#in sec\n",
+ "t2=69;# in sec\n",
+ "t3=11;# in sec\n",
+ "V1=48.;# in km/h\n",
+ "\n",
+ "#Calculations&Results\n",
+ "alfa=V1/t1;\n",
+ "print \"part (a)\"\n",
+ "print \"Acceleration(km/h/sec) = %.f\"%alfa\n",
+ "r=58;# in N/tonne\n",
+ "G=0;\n",
+ "Beta=r/(277.8*1.1);\n",
+ "print \"part (b)\"\n",
+ "print \"Retardation(kmphps) = %.2f\"%Beta\n",
+ "V2=V1-(Beta*t2);\n",
+ "S=round(((V1*t1)/7200)+(((V1+V2)*t2)/7200)+((V2*t3)/7200));\n",
+ "D=20;# duration of stop in sec\n",
+ "Ts=t1+t2+t3+D;\n",
+ "Vs=round((S*3600)/Ts);\n",
+ "print \"part (c)\"\n",
+ "print \"Schedule time,Vs(kmph) = %.f\"%Vs\n",
+ "D1=15;#when the duration of stop in sec\n",
+ "Ts_dash=t1+t2+t3+D1;\n",
+ "Vs_dash=(S*3600)/Ts_dash;\n",
+ "print \"Schedule speed,VS_dash(kmph) = %.2f\"%Vs_dash"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "Acceleration(km/h/sec) = 2\n",
+ "part (b)\n",
+ "Retardation(kmphps) = 0.19\n",
+ "part (c)\n",
+ "Schedule time,Vs(kmph) = 29\n",
+ "Schedule speed,VS_dash(kmph) = 30.25\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.12, Page 212"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "t1=30.;#in sec\n",
+ "t2=50.;# in sec\n",
+ "t3=20.;# in sec\n",
+ "alpha=2.;#kmphps\n",
+ "\n",
+ "#Calculations\n",
+ "V1=alpha*(t1);# in km/h\n",
+ "r=40;# in N/tonne\n",
+ "G=1;\n",
+ "bc=((98.1+r))/(277.8*1.1);#in kmphps\n",
+ "V2=V1-(bc*t2);#km/hr\n",
+ "S=(((V1*t1)/7200)+(((V1+V2)*t2)/7200)+((V2*t3)/7200));\n",
+ "D=30;# duration of stop in sec\n",
+ "Ts=t1+t2+t3+D;\n",
+ "Vs=((S*3600)/Ts);\n",
+ "\n",
+ "#Result\n",
+ "print \"Schedule time,Vs(kmph) = %.2f\"%Vs\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Schedule time,Vs(kmph) = 28.53\n"
+ ]
+ }
+ ],
+ "prompt_number": 53
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.13, Page 212"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "w=250.;#in tonnes\n",
+ "we=(1+(10./100))*w;#efective weight in tonnes\n",
+ "r=5*9.81;#in N/tonne\n",
+ "G=1.;#\n",
+ "t1=30.;#in sec\n",
+ "t2=70.;# in sec\n",
+ "alpha=2.;#kmphps\n",
+ "\n",
+ "#Calculations\n",
+ "V1=alpha*(t1);# in km/h\n",
+ "ft=(277.8*we*alpha)+(98.1*G*w)+(w*r);#in newtons\n",
+ "po=((ft*V1)/3600);#maximum power output in kW\n",
+ "n=0.97;#efficiency\n",
+ "pi=po/n;#in kW\n",
+ "bc=((98.1+r))/(277.8*1.1);#in kmphps\n",
+ "V2=V1-(bc*t2);#km/hr\n",
+ "beta1=3;#retardation\n",
+ "t3=V2/beta1;#in seconds\n",
+ "S=(((V1*t1)/7200)+(((V1+V2)*t2)/7200)+((V2*t3)/7200));\n",
+ "\n",
+ "#Results\n",
+ "print \"maximum power developed by traction motor is %.f (kW)\"%pi\n",
+ "print \"total distance travelled by train in km is %.2f\"%S\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum power developed by traction motor is 3257 (kW)\n",
+ "total distance travelled by train in km is 1.12\n"
+ ]
+ }
+ ],
+ "prompt_number": 56
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.14, Page 216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Vm=52.; #max speed in kmph\n",
+ "t3=15.8;#duration of braking in sec\n",
+ "\n",
+ "#Calculations\n",
+ "D=(1./2)*Vm*(t3/3600);\n",
+ "S=1400;#in m\n",
+ "S1=(S*10**-3)-D;\n",
+ "r=50;#in N/tonne\n",
+ "WeBY_W=1.1;\n",
+ "Ec=((0.01072*Vm**2*WeBY_W)/(S*10**-3))+(0.2778*r*(S1/(S*10**-3)));\n",
+ "\n",
+ "#Result\n",
+ "print \"energy consumption in Wh is %.3f\"%Ec"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "energy consumption in Wh is 35.533\n"
+ ]
+ }
+ ],
+ "prompt_number": 58
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.15, Page 217"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "w=1;#in tonnes\n",
+ "we=(1+(10./100))*w;#efective weight in tonnes\n",
+ "S=1525;#in meters\n",
+ "r=52.6/1000;#in N/kg\n",
+ "alpha=0.366;#m/s^2\n",
+ "V1=12.2;# in m/s\n",
+ "\n",
+ "#Calculations\n",
+ "t1=V1/alpha;#in seconds\n",
+ "ft=we*alpha+r;#in newtons\n",
+ "ter=((1./2)*ft*V1*t1)/3600;#in watt-hours\n",
+ "seo=ter/(w*S);# in Wh/kg-m\n",
+ "n=0.65;#efficiency\n",
+ "sec1=seo/n#in Wh/kg-m\n",
+ "\n",
+ "#Result\n",
+ "print \"specific energy onsumption is %.2e Wh/kg-m\"%sec1\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "specific energy onsumption is 2.59e-05 Wh/kg-m\n"
+ ]
+ }
+ ],
+ "prompt_number": 62
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.16, Page 217"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "t1=30.;#in sec\n",
+ "t2=50.;# in sec\n",
+ "t3=20.;# in sec\n",
+ "alpha=2;#kmphps\n",
+ "V1=alpha*(t1);# in km/h\n",
+ "r=40;# in N/tonne\n",
+ "G=1;\n",
+ "\n",
+ "#Calculations&Results\n",
+ "bc=((98.1+r))/(277.8*1.1);#in kmphps\n",
+ "V2=V1-(bc*t2);#km/hr\n",
+ "S=(((V1*t1)/7200)+(((V1+V2)*t2)/7200)+((V2*t3)/7200));\n",
+ "D=15;# duration of stop in sec\n",
+ "Ts=t1+t2+t3+D;\n",
+ "Vs=((S*3600)/Ts);\n",
+ "print \"Schedule speed,Vs(kmph) = %.2f\"%Vs\n",
+ "S1=(V1*t1)/7200;#in meters\n",
+ "r=50.;#in N/tonne\n",
+ "WeBY_W=1.1;\n",
+ "Ec=((0.01072*V1**2*WeBY_W)/(S))+(0.2778*(98.1*G+r)*((S1)/(S)));\n",
+ "N=0.75;#\n",
+ "Sec=Ec/0.75;#\n",
+ "print \"Specific energy consumption in Wh/tonne-km is %.2f\"%Sec\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Schedule speed,Vs(kmph) = 32.25\n",
+ "Specific energy consumption in Wh/tonne-km is 68.25\n"
+ ]
+ }
+ ],
+ "prompt_number": 64
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.17, Page 218"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "t1=30.;#in sec\n",
+ "t2=50.;# in sec\n",
+ "t3=20.;# in sec\n",
+ "alpha=2;#kmphps\n",
+ "V1=alpha*(t1);# in km/h\n",
+ "r=40;# in N/tonne\n",
+ "G=-1;\n",
+ "\n",
+ "#Calculations&Results\n",
+ "bc=((-98.1+r))/(277.8*1.1);#in kmphps\n",
+ "V2=V1-(bc*t2);#km/hr\n",
+ "S=(((V1*t1)/7200)+(((V1+V2)*t2)/7200)+((V2*t3)/7200));\n",
+ "D=15;# duration of stop in sec\n",
+ "Ts=t1+t2+t3+D;\n",
+ "Vs=((S*3600)/Ts);\n",
+ "print \"Schedule speed,Vs(kmph) = %.f\"%Vs\n",
+ "S1=(V1*t1)/7200;#in meters\n",
+ "r=50;#in N/tonne\n",
+ "WeBY_W=1.1;\n",
+ "Ec=((0.01072*V1**2*WeBY_W)/(S))+(0.2778*(98.1*G+r)*((S1)/(S)));\n",
+ "N=0.75;#\n",
+ "Sec=Ec/0.75;#\n",
+ "print \"Specific energy consumption in Wh/tonne-km is %.2f\"%Sec\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Schedule speed,Vs(kmph) = 42\n",
+ "Specific energy consumption in Wh/tonne-km is 38.85\n"
+ ]
+ }
+ ],
+ "prompt_number": 66
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.18, Page 219"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "W=100.;#in tonne\n",
+ "We=1.1*W;# in tonne\n",
+ "S=2.5;# distance in km\n",
+ "Va=50.;#Average speed in kmph\n",
+ "Dr=(3600*S)/Va;\n",
+ "alfa=1.;# in km/h/sec\n",
+ "Beta=2.;# in km/h/sec\n",
+ "T=180.;\n",
+ "r=40.;#in N/tonne\n",
+ "G=1;\n",
+ "\n",
+ "#Calculations&results\n",
+ "K=(1./(2*alfa))+(1/(2*Beta));\n",
+ "Vm=round((T/(2*K))-math.sqrt((T/(2*K))**2-((3600*S)/K)));# maximum speed\n",
+ "t1=Vm/alfa;# acceleration period\n",
+ "t3=Vm/Beta;# braking period\n",
+ "t2=T-(t1+t3);# in sec\n",
+ "Ft=(277.8*We*alfa)+(98.1*W*G)+(W*r);\n",
+ "P_max=round((Ft*Vm)/3600);\n",
+ "print \"part (a)\"\n",
+ "print \"Maximum power,(kWh) = %.f\"%P_max\n",
+ "e=60./100;# efficiency\n",
+ "Ft=(277.8*We*alfa)+(98.1*W*G)+(W*r);\n",
+ "Ft_dash=(98.1*W*G)+(W*r);\n",
+ "P_max=round((Ft*Vm)/3600);\n",
+ "Et=((1./2)*Ft)*(Vm/3600)*(t1/3600)+((Ft_dash*Vm)/3600)*(t2/3600);\n",
+ "Ec=Et/e;\n",
+ "print \"part (b) \"\n",
+ "print \"Total Energy Consumption,Ec(kWh) = %.2f\"%Ec\n",
+ "Sec=(Ec*1000)/(W*S);\n",
+ "print \"part (c) \"\n",
+ "print \"Specific Energy Consumption,(Wh/tonne-km) = %.1f\"%Sec"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "Maximum power,(kWh) = 875\n",
+ "part (b) \n",
+ "Total Energy Consumption,Ec(kWh) = 23.65\n",
+ "part (c) \n",
+ "Specific Energy Consumption,(Wh/tonne-km) = 94.6\n"
+ ]
+ }
+ ],
+ "prompt_number": 68
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.19, Page 220"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "W=203;#in tonne\n",
+ "We=1.1*W;# in tonne\n",
+ "r=44;# N/tonne\n",
+ "G=(1./500)*100;# gradient\n",
+ "Vm=45.;# maximum speed in kmph\n",
+ "t1=30.;# in sec\n",
+ "\n",
+ "#Calculations&Results\n",
+ "alfa=Vm/t1;# in kmph\n",
+ "Ft=(277.8*We*alfa)+(98.1*W*G)+(W*r);# in N\n",
+ "Po=(Ft*Vm)/3600;\n",
+ "print \"part (a)\"\n",
+ "print \"The maximum power output,(kW) = %.2f\"%Po\n",
+ "e=60./100;# efficiency\n",
+ "Et=(1./2)*((Ft*Vm)/3600)*(t1/3600);\n",
+ "E=(Et/e);\n",
+ "print \" part (b) \"\n",
+ "print \"The energy taken(kWh) = %.1f\"%E"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "The maximum power output,(kW) = 1324.55\n",
+ " part (b) \n",
+ "The energy taken(kWh) = 9.2\n"
+ ]
+ }
+ ],
+ "prompt_number": 69
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.20, Page 220"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "W=16.;#in tonne\n",
+ "We=1.1*W;# in tonne\n",
+ "Vs=45.;#in kmph\n",
+ "r=40.;# in N/tonne\n",
+ "S=2.8;# in km\n",
+ "Ts=(S*3600)/Vs;\n",
+ "Td=30.;# in sec\n",
+ "\n",
+ "#Calculations&Results\n",
+ "T=Ts-Td;\n",
+ "alfa=2.;#in kmphps\n",
+ "Beta=3.2;# in kmphps\n",
+ "K=(1./(2*alfa))+(1/(2*Beta));\n",
+ "Vm=round((T/(2*K))-math.sqrt((T/(2*K))**2-((3600*S)/K)));# maximum speed\n",
+ "t1=Vm/alfa;# acceleration time\n",
+ "t3=Vm/Beta;# duration of braking\n",
+ "t2=T-(t1+t3);# time f free run in sec\n",
+ "Ft=(277.8*We*alfa)+(W*r);\n",
+ "P_max=(Ft*Vm)/3600;\n",
+ "print \"part (a)\"\n",
+ "print \"Maximum power output,(kW) = %.3f\"%P_max\n",
+ "# answer is wrong in book\n",
+ "Va=50;#Average speed in kmph\n",
+ "Dr=(3600*S)/Va;\n",
+ "T=180;\n",
+ "G=1;\n",
+ "e=80./100;#efficiency\n",
+ "Dt=(1./2)*((Vm*t3)/3600);# distance travelled during braking period in km\n",
+ "S1=S-Dt;# distance travelled with power in km\n",
+ "So=(((0.01072*Vm**2)/S)*(We/W))+((0.2778*r*S1)/S);\n",
+ "Sec=So/e;\n",
+ "print \"part (b)\"\n",
+ "print \"Specific energy consumption,(Wh/tonne-km) = %.1f\"%Sec\n",
+ "# answer is wrong in book"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "Maximum power output,(kW) = 170.749\n",
+ "part (b)\n",
+ "Specific energy consumption,(Wh/tonne-km) = 31.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 71
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.21, Page 221"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "t1=30.;#in sec\n",
+ "t2=40.;# in sec\n",
+ "t3=30.;# in sec\n",
+ "alpha=2;#kmphps\n",
+ "V1=alpha*(t1);# in km/h\n",
+ "r=40;# in N/tonne\n",
+ "G=1;\n",
+ "\n",
+ "#Calculations&Results\n",
+ "bc=((98.1+r))/(277.8*1.1);#in kmphps\n",
+ "V2=V1-(bc*t3);#km/hr\n",
+ "Beta=2.5;#retardation\n",
+ "t4=V2/Beta;#in seconds\n",
+ "S=(((V1*t1)/7200)+((V1*t2)/3600)+(((V1+V2)*t3)/7200)+((V2*t4)/7200));\n",
+ "D=15;# duration of stop in sec\n",
+ "Ts=t1+t2+t3+t4+D;\n",
+ "Vs=((S*3600)/Ts);\n",
+ "print \"part (a)\"\n",
+ "print \"Schedule time,Vs(kmph) = %.2f\"%Vs\n",
+ "print \"part (b)\"\n",
+ "S1=((V1*t1)/7200)+((V1*t2)/3600);#in km\n",
+ "WeBY_W=1.1;\n",
+ "G=1;#\n",
+ "Ec=((0.01072*V1**2*WeBY_W)/(S))+(0.2778*(98.1*G+r)*((S1)/(S)));\n",
+ "N=0.75;#\n",
+ "Sec=Ec/0.75;#\n",
+ "print \"Specific energy consumption in Wh/tonne-km is %.2f\"%Sec\n",
+ "print \"part (c)\"\n",
+ "W=200;#\n",
+ "tec=(Sec*W*S);#\n",
+ "print \"total energy consumption is %.1f kWh\"%(tec*10**-3)\n",
+ "print \"part (d)\"\n",
+ "print \"total distance travelled in Km is %.2f\"%S\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "Schedule time,Vs(kmph) = 39.89\n",
+ "part (b)\n",
+ "Specific energy consumption in Wh/tonne-km is 69.93\n",
+ "part (c)\n",
+ "total energy consumption is 20.7 kWh\n",
+ "part (d)\n",
+ "total distance travelled in Km is 1.48\n"
+ ]
+ }
+ ],
+ "prompt_number": 73
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.22, Page 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "W=500.;#\n",
+ "t1=60.;#in sec\n",
+ "t2=5*60.;# in sec\n",
+ "t3=3*60.;# in sec\n",
+ "alpha=2.5;#kmphps\n",
+ "V1=alpha*(t1);# in km/h\n",
+ "r=25.;# in N/tonne\n",
+ "G=1.;\n",
+ "\n",
+ "#Calculations\n",
+ "bc=(((98.1*(8./1000)*100)+r))/(277.8*1.1);#in kmphps\n",
+ "V2=V1-(bc*t3);#km/hr\n",
+ "Beta=3.;#retardation\n",
+ "t4=V2/Beta;#in seconds\n",
+ "S=(((V1*t1)/7200)+((V1*t2)/3600)+(((V1+V2)*t3)/7200)+((V2*t4)/7200));\n",
+ "D=15.;# duration of stop in sec\n",
+ "Ts=t1+t2+t3+t4+D;\n",
+ "Vs=((S*3600)/Ts);\n",
+ "S1=((V1*t1)/7200)+((V1*t2)/3600);#in km\n",
+ "WeBY_W=1.1;\n",
+ "Ec=((0.01072*V1**2*WeBY_W)/(S))+(0.2778*((98.1*(8/1000)*100)+r)*((S1)/(S)));\n",
+ "N=0.80;#\n",
+ "Sec=Ec/N;#\n",
+ "\n",
+ "#Result\n",
+ "print \"Specific energy consumption in Wh/tonne-km is %f\"%Sec\n",
+ "#incorrect answer in textbook\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Specific energy consumption in Wh/tonne-km is 22.446222\n"
+ ]
+ }
+ ],
+ "prompt_number": 88
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.23, Page 223"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Wl=1;#\n",
+ "W1=400;#\n",
+ "G=2;#in percentage\n",
+ "mu=0.2;#\n",
+ "alpha=1;#\n",
+ "r=40;#\n",
+ "\n",
+ "#Calculations\n",
+ "x=(277.8*1.1*alpha+98.1*G+r)/(9.81*1000);#\n",
+ "wlo=(x*W1)/(mu-x);#in tonnes\n",
+ "al=22;#allowable load in tonnes\n",
+ "na=wlo/al;#\n",
+ "\n",
+ "#Results\n",
+ "print \"weight of the locomotive in tonnes %.1f\"%wlo\n",
+ "print \"number of axles required = %.f\"%na"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "weight of the locomotive in tonnes 152.6\n",
+ "number of axles required = 7\n"
+ ]
+ }
+ ],
+ "prompt_number": 89
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.24, Page 224 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "W=12*30;#tonnes\n",
+ "we=1.04*360;#tonnes\n",
+ "r=5*9.81;#\n",
+ "G=1;#in percentage\n",
+ "mu=0.2;#\n",
+ "alpha=0.8;#\n",
+ "x=13.882;#\n",
+ "y=0.041;#\n",
+ "\n",
+ "#Calculations\n",
+ "wlo=(x)/(mu-y);#in tonnes\n",
+ "al=20.;#allowable load in tonnes\n",
+ "na=wlo/al;#\n",
+ "\n",
+ "#Results\n",
+ "print \"weight of the locomotive in tonnes = %.1f\"%wlo\n",
+ "print \"number of axles required = %.f\"%na"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "weight of the locomotive in tonnes = 87.3\n",
+ "number of axles required = 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 91
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.25, Page 225"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "w1=100;#tonnes\n",
+ "w=w1+500;#tonnes\n",
+ "we=1.1*w;#effective weight\n",
+ "alpha=1;#\n",
+ "G=1;#\n",
+ "r=45;#\n",
+ "\n",
+ "#Calculations&Results\n",
+ "ft=((277.8*we*alpha)+(98.1*w*G)+(w*r));#in newtons\n",
+ "ad=0.7;#adehsive percent\n",
+ "mu=(ft)/(100*10**3*9.81*ad);#\n",
+ "w2=130;#tonnes\n",
+ "ad2=w2*G;#\n",
+ "tadw=w1*ad+ad2;#tonnes\n",
+ "tted=mu*tadw*9.81*1000;#newtones\n",
+ "W=tted/(277.8*1.1*alpha+98.1*alpha+r);#in tonnes\n",
+ "trlw=W-(ad2+w1);#\n",
+ "print \"part (a)\"\n",
+ "print \"trailig weight in tonnes is %.f\"%trlw\n",
+ "w2=w1+500+ad2;#\n",
+ "G1=((tted/w2)-(277.8*1.1+r))*(1/98.1);#\n",
+ "print \"part (b)\"\n",
+ "print \"maximum gradiant in percentage is %.3f\"%G1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "trailig weight in tonnes is 1484\n",
+ "part (b)\n",
+ "maximum gradiant in percentage is 7.167\n"
+ ]
+ }
+ ],
+ "prompt_number": 92
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.26, Page 226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "w1=100;#tonnes\n",
+ "w=w1+500;#tonnes\n",
+ "we=1.1*w;#effective weight\n",
+ "alpha=1;#\n",
+ "G=1;#\n",
+ "r=45;#\n",
+ "\n",
+ "#Calculations\n",
+ "ft=((277.8*we*alpha)+(98.1*w*G)+(w*r));#in newtons\n",
+ "ad=0.7;#adehsive percent\n",
+ "mu=(ft)/(100*10**3*9.81*ad);#\n",
+ "w2=130;#tonnes\n",
+ "ad2=w2*G;#\n",
+ "tadw=w1*ad+ad2;#tonnes\n",
+ "tted=mu*tadw*9.81*1000;#newtones\n",
+ "W=tted/(277.8*1.1*alpha+98.1*alpha+r);#in tonnes\n",
+ "trlw=W-(ad2+w1);#\n",
+ "w2=w1+500+ad2;#\n",
+ "acc=((tted/w2)-(98.1+r))*(1/(277.8*1.1));#in kmphps\n",
+ "\n",
+ "#Result\n",
+ "print \"acceleration in kmphps is %.2f\"%acc\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "acceleration in kmphps is 2.98\n"
+ ]
+ }
+ ],
+ "prompt_number": 93
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.27, Page 226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "N=4;# number of motor\n",
+ "W=250;#in tonne\n",
+ "D=.95;# diameter in m\n",
+ "G=1;# percentage gradient\n",
+ "r=40;# in N/tonne\n",
+ "eta=95./100;# gear efficiency\n",
+ "gama=3;# gear ratio\n",
+ "We=1.1*W;\n",
+ "Vm=40;# kmph\n",
+ "t1=20;# in seconds\n",
+ "\n",
+ "#Calculations&Results\n",
+ "alfa=Vm/t1;\n",
+ "Ft=((277.8*We*alfa)+(98.1*W*G)+(W*r));\n",
+ "T=(Ft*D)/(eta*2*gama);\n",
+ "Td=round(T/N);\n",
+ "print \"Torque developed by each motor,Td(Nm) = %.f\"%Td\n",
+ "mu=0.25;# adhesive coefficient\n",
+ "WL=(Ft/(9.81*1000))/mu;\n",
+ "Dw=round(WL/.75);\n",
+ "print \"Dead weight of locomotive,(tonnes) = %.f\"%Dw"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Torque developed by each motor,Td(Nm) = 7805\n",
+ "Dead weight of locomotive,(tonnes) = 102\n"
+ ]
+ }
+ ],
+ "prompt_number": 94
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch8.ipynb b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch8.ipynb
new file mode 100755
index 00000000..6438fd3c
--- /dev/null
+++ b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch8.ipynb
@@ -0,0 +1,534 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:b7b0abfe04e8b6b29a96c15b950c278316c99226e22c23f718d5fde9509d9b25"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8: Electric Traction Motors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.1, Page 237"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy as np\n",
+ "%pylab inline\n",
+ "\n",
+ "#Variable declaration\n",
+ "v=230;#in volts\n",
+ "rm=0.3;#in ohms\n",
+ "Ia=np.array([5,10,15,20,25,30,35,40]);#in amperes\n",
+ "T=[20,50,100,155,215,290,360,430];#\n",
+ "N = []\n",
+ "#Calculations&Results\n",
+ "for i in range(0,8):\n",
+ " eb= v-(Ia[i])*rm;#\n",
+ " N.append((9.55*eb*Ia[i])/(T[i]));#\n",
+ " print \"speed in rpm is for current \",(Ia[i]),\" amperes \",(round(N[i])),\" RPM\"\n",
+ " \n",
+ "plot(Ia,N)\n",
+ "xlabel(\"ARMATURE CURRENT ,Ia IN AMPS\")\n",
+ "ylabel(\"SPEED ,N IN RPM\")\n",
+ "title(\"Speed-Armature current characteristic\")\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Populating the interactive namespace from numpy and matplotlib\n",
+ "speed in rpm is for current 5 amperes 546.0 RPM\n",
+ "speed in rpm is for current 10 amperes 434.0 RPM\n",
+ "speed in rpm is for current 15 amperes 323.0 RPM\n",
+ "speed in rpm is for current 20 amperes 276.0 RPM\n",
+ "speed in rpm is for current 25 amperes 247.0 RPM\n",
+ "speed in rpm is for current 30 amperes 218.0 RPM\n",
+ "speed in rpm is for current 35 amperes 204.0 RPM\n",
+ "speed in rpm is for current 40 amperes 194.0 RPM\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 48,
+ "text": [
+ "<matplotlib.text.Text at 0xb129294c>"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\nCgAAAABJRU5ErkJggg==\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0xb11600ac>"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2, Page 238"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "v=600;#in volts\n",
+ "rm=0.8;#in ohms\n",
+ "N1=600.;#\n",
+ "Ia=[20,40,60,80];#in amperes\n",
+ "EMF=[215,381,485,550]\n",
+ "T = []\n",
+ "N =[]\n",
+ "eb =[]\n",
+ "#Calculations&Results\n",
+ "for i in range(0,4):\n",
+ " eb.append(v-(Ia[i])*rm);#\n",
+ " N.append((N1/EMF[i])*eb[i]);#\n",
+ " T.append((9.55*eb[i]*Ia[i])/(N[i]));#\n",
+ " print \"for current \",(Ia[i]),\" amperes, speed is\",(round(N[i])),\" RPM and Torque in N-m is \",round((T[i]),1)\n",
+ "plot(T,N)\n",
+ "xlabel(\"TORQUE ,T IN Nm\")\n",
+ "ylabel(\"SPEED ,N IN RPM\")\n",
+ "title(\"Speed-torque curve\")\n",
+ "#answers differ due to rounding-off errors"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "for current 20 amperes, speed is 1630.0 RPM and Torque in N-m is 68.4\n",
+ "for current 40 amperes, speed is 894.0 RPM and Torque in N-m is 242.6\n",
+ "for current 60 amperes, speed is 683.0 RPM and Torque in N-m is 463.2\n",
+ "for current 80 amperes, speed is 585.0 RPM and Torque in N-m is 700.3\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 90,
+ "text": [
+ "<matplotlib.text.Text at 0xb0e0298c>"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "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\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0xb0e6f2ec>"
+ ]
+ }
+ ],
+ "prompt_number": 90
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3, Page 239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "N1=640;# in rpm\n",
+ "I1=15;# in A\n",
+ "\n",
+ "#Calculations\n",
+ "I2=math.sqrt((2)*math.sqrt(2)*I1**2);\n",
+ "N2=round((2*I1*N1)/I2);\n",
+ "\n",
+ "#Results\n",
+ "print \"Current drawn,I2(A) = %.3f\"%I2\n",
+ "print \"Motor speed,N2(rpm) = %.f\"%N2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current drawn,I2(A) = 25.227\n",
+ "Motor speed,N2(rpm) = 761\n"
+ ]
+ }
+ ],
+ "prompt_number": 91
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4, Page 243"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "n1=700;#rpm\n",
+ "n2=750;#rpm\n",
+ "rm=0.3;#in ohms\n",
+ "v=500;#in volts\n",
+ "ib=50;#amperes\n",
+ "\n",
+ "#Calculations\n",
+ "eb1=v-(ib*rm);#in volts\n",
+ "eb2=eb1;#\n",
+ "N=((v-(2*(ib*rm)))/((eb1/n1)+(eb2/n2)));#\n",
+ "pdv1=((eb1/n1)*N)+ib*rm;#in volts\n",
+ "pdv2=((eb1/n2)*N)+ib*rm;#in volts\n",
+ "\n",
+ "#Results\n",
+ "print \"speed in rpm is %.f\"%N\n",
+ "print \"PD across machine 1 in volts is %.f\"%pdv1\n",
+ "print \"PD across machine 2 in volts is %.f\"%pdv2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "speed in rpm is 351\n",
+ "PD across machine 1 in volts is 258\n",
+ "PD across machine 2 in volts is 242\n"
+ ]
+ }
+ ],
+ "prompt_number": 92
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.5, Page 243"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "V=500;# in volts\n",
+ "Vm=40;# in kmph\n",
+ "Ft=1800;# in N\n",
+ "Rm=0.4;# in ohm\n",
+ "Lm=3200;# losses per motor in watt\n",
+ "\n",
+ "#Calculations&Results\n",
+ "Mo=(Ft*Vm*1000)/3600;\n",
+ "Cl=3200;# consatant losses in watt\n",
+ "# formuls: Mi=Po+Cl+C_losses\n",
+ "#C_losses=I^2*Rm\n",
+ "#Mi=V*I\n",
+ "#I1=(V+sqrt(V^2-(4*Rm*(Mo+Cl))))/(2*Rm);leaving as gives a very high value\n",
+ "I1=(V-math.sqrt(V**2-4*Rm*(Mo+Cl)))/(2*Rm);\n",
+ "print \"Current drawn by each motor,(A) = %.2f\"%I1\n",
+ "It=I1*2;\n",
+ "print \"Total current drawn,(A) = %.1f\"%It"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current drawn by each motor,(A) = 48.26\n",
+ "Total current drawn,(A) = 96.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 93
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.6, Page 244"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "Ft=35300.;# in N\n",
+ "V=48.;# in kmph\n",
+ "\n",
+ "#Calculations&Results\n",
+ "Po=((Ft*V*1000.)/3600)*10**-3;\n",
+ "Ft1=55180.;#in N\n",
+ "Pd=Po*math.sqrt(Ft1/Ft);\n",
+ "print \"part (a)\"\n",
+ "print \"power delivered(kW) = %.1f\"%Pd\n",
+ "Pd1=Po*(Ft1/Ft);\n",
+ "print \"part (b)\"\n",
+ "print \"power delivered(kW) = %.1f\"%Pd1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "power delivered(kW) = 588.5\n",
+ "part (b)\n",
+ "power delivered(kW) = 735.7\n"
+ ]
+ }
+ ],
+ "prompt_number": 97
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.7, Page 244"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Ia=[60,120,180,240,300,360];# in amperes\n",
+ "sp1=[80,50,45,42,38,35];#in kmph\n",
+ "tf1=[1.7,5,10,14,16,20];#innewtons\n",
+ "d1=0.85;#in meters\n",
+ "d2=0.9;#in meters\n",
+ "y1=71./21;#\n",
+ "y2=74./19;#\n",
+ "\n",
+ "#Calculations&Results\n",
+ "for i in range(0,6):\n",
+ " V=((d2/d1)*(y1/y2))*sp1[i];#in kmph\n",
+ " tf2=((d1/d2)*(y2/y1))*(tf1[i]);#in newtons\n",
+ " print \"for armature current\",(Ia[i]),\"amperes , speed is \",(V),\" kmph and tractive effor in thousand newtons is \",round((tf2),2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "for armature current 60 amperes , speed is 73.5316829434 kmph and tractive effor in thousand newtons is 1.85\n",
+ "for armature current 120 amperes , speed is 45.9573018397 kmph and tractive effor in thousand newtons is 5.44\n",
+ "for armature current 180 amperes , speed is 41.3615716557 kmph and tractive effor in thousand newtons is 10.88\n",
+ "for armature current 240 amperes , speed is 38.6041335453 kmph and tractive effor in thousand newtons is 15.23\n",
+ "for armature current 300 amperes , speed is 34.9275493981 kmph and tractive effor in thousand newtons is 17.41\n",
+ "for armature current 360 amperes , speed is 32.1701112878 kmph and tractive effor in thousand newtons is 21.76\n"
+ ]
+ }
+ ],
+ "prompt_number": 98
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.8, Page 245"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "n1=500;#in rpm\n",
+ "d1=90;#in cm\n",
+ "d2=86;#in cm\n",
+ "v=600;#in. volts\n",
+ "vd=0.1;#drop\n",
+ "\n",
+ "#Calculations\n",
+ "eb1=v-(vd*v);#in volts\n",
+ "A = np.array([[90,-86],[1,1]])\n",
+ "B = np.array([240,600])\n",
+ "Eb1 = np.linalg.solve(A, B)\n",
+ "N1=n1*(Eb1[0]-(vd*v))/(v-(vd*v));#\n",
+ "N2=N1*(d1/d2);#\n",
+ "\n",
+ "#Results\n",
+ "print \"speed in rpm is %.f\"%N1\n",
+ "print \"speed in rpm is %.f\"%N2\n",
+ "#N2 is calculated wrong in the book'''"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "speed in rpm is 217\n",
+ "speed in rpm is 217\n"
+ ]
+ }
+ ],
+ "prompt_number": 83
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.9, Page 245"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "ia=350;#A\n",
+ "ib=305;#A\n",
+ "v=600;#V\n",
+ "\n",
+ "#Calculations&Results\n",
+ "pa=(v*ia)/1000;#kW\n",
+ "pb=(v*ib)/1000;#kW\n",
+ "print \"(i) When motors are connected in parallel and train speed is 40kmph\"\n",
+ "print \"power input to motor A is,(kW)= %.f\"%pa\n",
+ "print \"power input to motor B is,(kW)= %.f\"%pb\n",
+ "fta=1625;#kg\n",
+ "ftb=1480;#kg\n",
+ "print \"tractive effor of motor A is,(kg)= %.f\"%fta\n",
+ "print \"tractive effor of motor B is,(kg)= %.f\"%ftb\n",
+ "print \"(ii) When motors are connected in series and current is 400A\"\n",
+ "rm=0.08;#ohm\n",
+ "i=400;#A\n",
+ "eba=v-(i*rm);#V\n",
+ "abb=eba;#V\n",
+ "va=38.5;#V\n",
+ "vb=36.7;#V\n",
+ "vx=((v-2*(i*rm))*((va*vb)/(va+vb)))/eba;#\n",
+ "Va=((eba/va)*vx)+(i*rm);#V\n",
+ "Vb=((eba/vb)*vx)+(i*rm);#V\n",
+ "pa1=(Va*i)/1000;#kW\n",
+ "pb1=(Vb*i)/1000;#kW\n",
+ "print \"power input to motor A is,(kW)= %.1f\"%pa1\n",
+ "print \"power input to motor B is,(kW)= %.1f\"%pb1\n",
+ "fta1=1960;#kg\n",
+ "ftb1=2060;#kg\n",
+ "print \"tractive effor of motor A is,(kg)= %.f\"%fta1\n",
+ "print \"tractive effor of motor B is,(kg)= %.f\"%ftb1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) When motors are connected in parallel and train speed is 40kmph\n",
+ "power input to motor A is,(kW)= 210\n",
+ "power input to motor B is,(kW)= 183\n",
+ "tractive effor of motor A is,(kg)= 1625\n",
+ "tractive effor of motor B is,(kg)= 1480\n",
+ "(ii) When motors are connected in series and current is 400A\n",
+ "power input to motor A is,(kW)= 117.4\n",
+ "power input to motor B is,(kW)= 122.6\n",
+ "tractive effor of motor A is,(kg)= 1960\n",
+ "tractive effor of motor B is,(kg)= 2060\n"
+ ]
+ }
+ ],
+ "prompt_number": 99
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.10, Page 254"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "f=50;#hz\n",
+ "t=0.5;#in meter\n",
+ "s=0.25;#\n",
+ "\n",
+ "#Calculations\n",
+ "vs=2*f*t*(3600./1000);#kmph\n",
+ "vc=vs*(1-s);#kmph\n",
+ "\n",
+ "#Results\n",
+ "print \"linear synchronous velocity in kmph is %.f\"%vs\n",
+ "print \"vehicle speed in kmph is %.f\"%vc"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "linear synchronous velocity in kmph is 180\n",
+ "vehicle speed in kmph is 135\n"
+ ]
+ }
+ ],
+ "prompt_number": 100
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch9.ipynb b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch9.ipynb
new file mode 100755
index 00000000..61fe143f
--- /dev/null
+++ b/Utilization_of_Electrical_Energy_and_Traction_by_J._B._Gupta,_R._Manglik_and_R._Manglik/ch9.ipynb
@@ -0,0 +1,332 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:a295b23ddf355cc98776039dc2c765e71624b4961371dafae0a82fd3d3a044d3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Control of Traction Motors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.1, Page 268"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "V=600.;# in volts\n",
+ "I=350.;#in A\n",
+ "Ts=20.;# in sec\n",
+ "R=0.15;# in ohm\n",
+ "\n",
+ "#Calculations&Results\n",
+ "E_bse=(V/2)-(I*R);\n",
+ "E_bp=V-(I*R);\n",
+ "Tse=(E_bse/E_bp)*Ts;\n",
+ "Tp=Ts-Tse;\n",
+ "Vd=V-(2*I*R);\n",
+ "Ed1=(Vd/2)*I*(Tse/3600);\n",
+ "Ed2=((V/2)/2)*2*I*(Tp/3600);\n",
+ "El=(Ed1+Ed2)*10**-3;\n",
+ "print \"part (a)\"\n",
+ "print \"Energy lost in starting rhestat,El(kWh) = %.4f\"%El\n",
+ "El_1=(2*(I**2)*R*Ts)/(3600*1000);\n",
+ "print \"part (b)\"\n",
+ "print \"Energy lost in motors,El(kWh) = %.3f\"%El_1\n",
+ "#answer is wrong in part b in the textbook\n",
+ "Et=((V*I*Tse)+(2*V*I*Tp))/(3600*1000);\n",
+ "print \"part (c)\"\n",
+ "print \"Total Energy,Et(kWh) = %.3f\"%Et"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "Energy lost in starting rhestat,El(kWh) = 0.5372\n",
+ "part (b)\n",
+ "Energy lost in motors,El(kWh) = 0.204\n",
+ "part (c)\n",
+ "Total Energy,Et(kWh) = 1.806\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.2, Page 269"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "V=600.;# in volts\n",
+ "I=300.;#in A\n",
+ "Ts=15.;# in sec\n",
+ "R=0.1;# in ohm\n",
+ "\n",
+ "#Calculations&Results\n",
+ "E_bse=(V/2)-(I*R);\n",
+ "E_bp=V-(I*R);\n",
+ "Tse=(E_bse/E_bp)*Ts;\n",
+ "Tp=Ts-Tse;\n",
+ "Vd=V-(2*I*R);\n",
+ "Ed1=(round((Vd/2)*I*(Tse/3600))*10**-3);#\n",
+ "print \"part (i)\"\n",
+ "print \"rheostatic in series,Ed1(kWh) = %.2f\"%Ed1\n",
+ "Ed2=((V/2)/2)*2*I*(Tp/3600)*10**-3;\n",
+ "print \"rheostatic in parallel,Ed2(kWh) = %.3f\"%Ed2\n",
+ "Vm=29;# in kmph\n",
+ "alfa=Vm/Ts;\n",
+ "S=alfa*Tse;\n",
+ "print \"part (ii)\"\n",
+ "print \"Speed at the end of series period,S(km/h) = %.1f\"%S"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (i)\n",
+ "rheostatic in series,Ed1(kWh) = 0.16\n",
+ "rheostatic in parallel,Ed2(kWh) = 0.197\n",
+ "part (ii)\n",
+ "Speed at the end of series period,S(km/h) = 13.7\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3, Page 270"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "V=600;# in volts\n",
+ "I=200;#in A\n",
+ "Ts=20;# in sec\n",
+ "R=0.1;# in ohm\n",
+ "\n",
+ "#Calculations&Results\n",
+ "E_bse=(V/2)-(I*R);\n",
+ "E_bp=V-(I*R);\n",
+ "Tse=(E_bse/E_bp)*Ts;\n",
+ "Tp=Ts-Tse;\n",
+ "Vd=V-(2*I*R);\n",
+ "Mi=((V*I*Tse)/(2*3600))+((V*I*Tp)/3600);\n",
+ "Er=((Vd/4)*I*(Tse/3600))+(((V/2)/2)*I*(Tp/3600));\n",
+ "El=(I**2*R*Ts)/(3600);\n",
+ "Mo=Mi-Er-El;\n",
+ "eta=(Mo/Mi)*100;\n",
+ "print \"part (a)\"\n",
+ "print \"Starting efficiency = %.1f%%\"%eta\n",
+ "Vm=80;# in kmph\n",
+ "alfa=Vm/Ts;\n",
+ "S=alfa*Tse;\n",
+ "print \"part (b)\"\n",
+ "print \"speed,S(kmph) = %.2f\"%S"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "Starting efficiency = 63.7%\n",
+ "part (b)\n",
+ "speed,S(kmph) = 38.62\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4, Page 271"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "W=150;# in tonne\n",
+ "We=1.1*W;# in tonnes\n",
+ "Vm=30;#kmph\n",
+ "V=600;# in volts\n",
+ "r=10;# N/tonne\n",
+ "I=300;#in A\n",
+ "R=0.1;# in ohm\n",
+ "Ft=4*15000;# in N\n",
+ "G=1;#gradient in %\n",
+ "\n",
+ "#Calculations&Results\n",
+ "alfa=(Ft-(W*r)-(98.1*W*G))/(277.8*We);\n",
+ "Ts=Vm/alfa;\n",
+ "E_bse=(V/2)-(I*R);\n",
+ "E_bp=V-(I*R);\n",
+ "Tse=(E_bse/E_bp)*Ts;\n",
+ "print \"part (a)\"\n",
+ "print \"Duration of starting period,Ts(seconds) = %.1f\"%Ts\n",
+ "print \"Duration for Series running,Tse(seconds) = %.1f\"%Tse\n",
+ "sptr=alfa*Tse;#in kmph\n",
+ "print \"part (b)\"\n",
+ "print \"speed of train at transition in kmph is %.2f\"%sptr\n",
+ "sptr=alfa*Tse;#in kmph\n",
+ "rls=((V-(2*I*R))/2)*(2*I)*(Tse/3600);#watts hours\n",
+ "rlp=((V/2)/2)*(4*I)*((Ts-Tse)/3600);#watts hours\n",
+ "tl=rls+rlp;#\n",
+ "print \"part (c)\"\n",
+ "print \"rheostat losses during series operation is %.1f W-hours\"%rls\n",
+ "print \"rheostat losses during parallel operation is %.f W-hours\"%rlp\n",
+ "print \"total losses in W-hours is %.1f \"%tl"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "Duration of starting period,Ts(seconds) = 31.4\n",
+ "Duration for Series running,Tse(seconds) = 14.9\n",
+ "part (b)\n",
+ "speed of train at transition in kmph is 14.21\n",
+ "part (c)\n",
+ "rheostat losses during series operation is 669.4 W-hours\n",
+ "rheostat losses during parallel operation is 826 W-hours\n",
+ "total losses in W-hours is 1495.9 \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5, Page 272"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "nf=1.; \n",
+ "n2=1.25*nf; \n",
+ "of=1; \n",
+ "of2=nf/n2; \n",
+ "isef=1; \n",
+ "ise2=0.66667; \n",
+ "\n",
+ "#Calculations\n",
+ "ia2=(1./ise2); \n",
+ "idiv=ia2-ise2; \n",
+ "rdiv=ise2/idiv; \n",
+ "\n",
+ "#Result\n",
+ "print \"diverter resistance required as percentage of the field resistance is %.f%%\"%(rdiv*100)\n",
+ "#answer is wrong in the textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "diverter resistance required as percentage of the field resistance is 80%\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6, Page 272"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Ia=[60,80,100,120,160,180];# in amperes\n",
+ "sp1=[47.4,40.3,35.8,33.9,29.8,28.5];#in kmph\n",
+ "dpk=[440,700,970,1245,1800,2360];#in kg\n",
+ "sp2=[58.1,50,45,40.3,35,32];#\n",
+ "\n",
+ "#Calculations&Results\n",
+ "for i in range(0,6):\n",
+ " dpk1= ((dpk[i])*(sp1[i]))/(sp2[i]);#\n",
+ " print \"For current = \",Ia[i],\"A, speed is \",sp2[i],\"kmph and drawbar pull is\",round(dpk1),\"kg\"\n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For current = 60 A, speed is 58.1 kmph and drawbar pull is 359.0 kg\n",
+ "For current = 80 A, speed is 50 kmph and drawbar pull is 564.0 kg\n",
+ "For current = 100 A, speed is 45 kmph and drawbar pull is 772.0 kg\n",
+ "For current = 120 A, speed is 40.3 kmph and drawbar pull is 1047.0 kg\n",
+ "For current = 160 A, speed is 35 kmph and drawbar pull is 1533.0 kg\n",
+ "For current = 180 A, speed is 32 kmph and drawbar pull is 2102.0 kg\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Wireless_Communications/screenshots/chap02.png b/Wireless_Communications/screenshots/chap02.png
new file mode 100755
index 00000000..e3f858d9
--- /dev/null
+++ b/Wireless_Communications/screenshots/chap02.png
Binary files differ
diff --git a/Wireless_Communications/screenshots/chap07.png b/Wireless_Communications/screenshots/chap07.png
new file mode 100755
index 00000000..7c4aa525
--- /dev/null
+++ b/Wireless_Communications/screenshots/chap07.png
Binary files differ
diff --git a/Wireless_Communications/screenshots/chap12.png b/Wireless_Communications/screenshots/chap12.png
new file mode 100755
index 00000000..2b154ffa
--- /dev/null
+++ b/Wireless_Communications/screenshots/chap12.png
Binary files differ
diff --git a/Wireless_Communications_by_T._L._Singal/CHAPTER10.ipynb b/Wireless_Communications_by_T._L._Singal/CHAPTER10.ipynb
new file mode 100755
index 00000000..9fe51ae4
--- /dev/null
+++ b/Wireless_Communications_by_T._L._Singal/CHAPTER10.ipynb
@@ -0,0 +1,437 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:6766772f83f2596b3b6b7807e5b7d920e722ca1875c73f5ee2febb8d127ad653"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 10-Wireless Communication Systems\n"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 10.1- PG NO.351"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page 351\n",
+ "BW=12.5*10.**3.\n",
+ "TDR1=512.#transmission data rate\n",
+ "SPef1=TDR1/BW#spectral efficiency\n",
+ "\n",
+ "TDR2=1200.\n",
+ "SPef2=TDR2/BW\n",
+ "\n",
+ "TDR3=2400.\n",
+ "SPef3=TDR3/BW\n",
+ "print'%s %.2f %s' %('the spectral efficiency at 512 bps transmission data rate =',SPef1,'bps/Hz')\n",
+ "print'%s %.3f %s' %('the spectral efficiency at 1200 bps transmission data rate =',SPef2,'bps/Hz')\n",
+ "print'%s %.3f %s' %('the spectral efficiency at 2400 bps transmission data rate =',SPef3,'bps/Hz')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the spectral efficiency at 512 bps transmission data rate = 0.04 bps/Hz\n",
+ "the spectral efficiency at 1200 bps transmission data rate = 0.096 bps/Hz\n",
+ "the spectral efficiency at 2400 bps transmission data rate = 0.192 bps/Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 10.2- PG NO.352"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.352\n",
+ "TDR=1200.\n",
+ "T=60.\n",
+ "TN=TDR*T#total no. of bits in 60 sec\n",
+ "NP=576.#no. of bits in the preamble\n",
+ "NU=TN-NP#no. of usable bits\n",
+ "\n",
+ "NS=32.\n",
+ "NA=32.\n",
+ "N16=16.*NA\n",
+ "N1B=NS+N16\n",
+ "\n",
+ "NBPM=NU/N1B#no. of batches/min.\n",
+ "NPAPB=16.\n",
+ "NTPM=NBPM*NPAPB#no. of pages transmitted/min.\n",
+ "print'%s %d %s' %('no. of pages transmitted/min =',NTPM,'pages')\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "no. of pages transmitted/min = 2100 pages\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 10.3- PG NO.353"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.353\n",
+ "BW=25.*10.**3.#bandwidth of POCSAG=bandwidth of FLEX system\n",
+ "\n",
+ "TDR1=1200.# transmission data rate\n",
+ "SPef1=TDR1/BW#spectral efficiency\n",
+ "\n",
+ "TDR2=6400.\n",
+ "SPef2=TDR2/BW\n",
+ "print '%s %.3f %s' %('the spectral efficiency at 1200 bps transmission data rate in POCSAG paging system is =',SPef1,'bps/Hz')\n",
+ "print '%s %.3f %s' %('the spectral efficiency at 6400 bps transmission data rate in FLEX paging system is =',SPef2,'bps/Hz')\n",
+ "\n",
+ "Cinc=TDR2/TDR1\n",
+ "print '%s %.1f %s' %('estimating increase in capacity is =',Cinc,'times')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the spectral efficiency at 1200 bps transmission data rate in POCSAG paging system is = 0.048 bps/Hz\n",
+ "the spectral efficiency at 6400 bps transmission data rate in FLEX paging system is = 0.256 bps/Hz\n",
+ "estimating increase in capacity is = 5.3 times\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 10.6- PG NO.368"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.368\n",
+ "Bt=12.5*10.**6.\n",
+ "Bg=10.*10.**3.\n",
+ "B2g=2.*Bg#Guard band on both the ends\n",
+ "ABW=Bt-B2g\n",
+ "Bc=30000.#channel bandwidth\n",
+ "N=ABW/Bc\n",
+ "print '%s %d %s' %('total no. of channels available in the system is =',N,'channels')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total no. of channels available in the system is = 416 channels\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 10.8- PG NO.374"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.374\n",
+ "ERPmax1dB=6.\n",
+ "ERPmax2dB=-2.\n",
+ "DiffdB=ERPmax1dB-ERPmax2dB\n",
+ "Diff=10.**(DiffdB/10.)\n",
+ "Rfree=5.*(Diff)**(1./2.)#free space-case(a)\n",
+ "Rtypc=5.*(Diff)**(1./4.)#signal attenuation is proportional to 4th power-case(b)\n",
+ "print '%s %.1f %s' %('maximum communication range in a free space propogation condition-case(a) is =',Rfree,'km')\n",
+ "print '%s %.1f %s' %('maximum communication range when signal attenuation is proportional to 4th power-case(b) is =',Rtypc,'km')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum communication range in a free space propogation condition-case(a) is = 12.6 km\n",
+ "maximum communication range when signal attenuation is proportional to 4th power-case(b) is = 7.9 km\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 10.11- PG NO.381"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 381\n",
+ "import math\n",
+ "P4dBW=-34.\n",
+ "PdBm4=P4dBW-30.\n",
+ "PW4=10.**((PdBm4/10.))\n",
+ "print '%s %d %s %s' %('minimum power level of class IV phone is =',round(PW4*10**7),'*10**(-7)','mW')\n",
+ "\n",
+ "ERP1dBW=6.\n",
+ "PdBm1=ERP1dBW-30.\n",
+ "PW1=10.**((PdBm1/10.))\n",
+ "\n",
+ "print '%s %d %s %s' %('ERP of class I phone is =',round(PW1*10**3),'*10**(-3)','mW')\n",
+ "R=PW1/PW4\n",
+ "RdB=10.*math.log10(R)\n",
+ "\n",
+ "print '%s %d %s %d' %('minimum power level for a Class I phone is greater than\\nminimum power level of Class IV mobile phone by a factor of',RdB,'dB or',R)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "minimum power level of class IV phone is = 4 *10**(-7) mW\n",
+ "ERP of class I phone is = 4 *10**(-3) mW\n",
+ "minimum power level for a Class I phone is greater than\n",
+ "minimum power level of Class IV mobile phone by a factor of 40 dB or 10000\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 10.12- PG NO.384"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.384\n",
+ "spfl=810*10**6\n",
+ "spfu=826*10**6\n",
+ "sprl=940*10**6\n",
+ "spru=956*10**6\n",
+ "BWf=spfu-spfl\n",
+ "BWr=spru-sprl\n",
+ "\n",
+ "BWc=10./100.*BWf#BWf=BWr(universal standard)\n",
+ "BWv=BWf-BWc\n",
+ "nsc=1150.\n",
+ "BWmax=BWv/nsc\n",
+ "SPef=1.68\n",
+ "CDRmax=BWmax*SPef\n",
+ "FECcr=0.5\n",
+ "DRnmax=FECcr*CDRmax\n",
+ "print '%s %.1f %s' %('there is a speech coder with a max. data rate of is =',DRnmax*10**(-3),'Kbps')\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "there is a speech coder with a max. data rate of is = 10.5 Kbps\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 10.13- PG NO.388"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.388\n",
+ "d=40.*10.**0.\n",
+ "npf=6.\n",
+ "dts=d/npf#duration of a time slot of a voice frame\n",
+ "nbv=1944.\n",
+ "nbpts=nbv/npf#no. of bits per time slot\n",
+ "db=d/nbv#duration of a bit in secs\n",
+ "npg=6.\n",
+ "tg=db*npg#guard time in secs\n",
+ "c=3.*10.**8.\n",
+ "Disrt=c*tg\n",
+ "Dismx=Disrt/2.#max. distance\n",
+ "print '%s %.3f %s' %('duration of a time slot of a voice frame is =',dts,'msecs')\n",
+ "print '%s %d %s' %('no. of bits per time slot is =',nbpts,'bits')\n",
+ "print '%s %.2f %s' %('duration of a bit is',db*1000,'microsecs')\n",
+ "print '%s %d %s' %('guard time is =',tg*1000,'microsecs')\n",
+ "print '%s %.2f %s' %('maximum distance between a cell site and a mobile is =',Dismx/1000000.,'kilometres')\n",
+ "#answers vary due to approximations."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "duration of a time slot of a voice frame is = 6.667 msecs\n",
+ "no. of bits per time slot is = 324 bits\n",
+ "duration of a bit is 20.58 microsecs\n",
+ "guard time is = 123 microsecs\n",
+ "maximum distance between a cell site and a mobile is = 18.52 kilometres\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 10.14- PG NO.389"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.389\n",
+ "dv=40.*10.**-3.\n",
+ "nps=1./dv\n",
+ "nbpv=1944.\n",
+ "TGrbr=nbpv*25.\n",
+ "TGrbaur=TGrbr/2.#2 bits/symbol for pi/4 qpsk mod\n",
+ "CBW=30.*10.**3.\n",
+ "BWef=TGrbr/CBW\n",
+ "print '%s %.1f %s' %('total gross bit rate for the RF signal is=',TGrbr/1000,'Kbps')\n",
+ "print '%s %.1f %s' %('total gross baud rate for the RF signal is =',TGrbaur/1000,'Kbps')\n",
+ "print '%s %.1f %s' %('bandwidth efficiency is =',BWef,'bps/Hz')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total gross bit rate for the RF signal is= 48.6 Kbps\n",
+ "total gross baud rate for the RF signal is = 24.3 Kbps\n",
+ "bandwidth efficiency is = 1.6 bps/Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 10.15- PG NO.391"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#PAGE NO. 391\n",
+ "Bt=12.5*10**6\n",
+ "Bc=30.*10.**3.\n",
+ "K=7#frequency reuse factor\n",
+ "N=Bt/Bc#total no. of available channels\n",
+ "M=N*(1./K)#user capacity per cell \n",
+ "\n",
+ "Nu=3#no. of users/channel\n",
+ "NU=N*Nu\n",
+ "K1=4\n",
+ "M1=NU*(1./K1)\n",
+ "\n",
+ "print '%s %d %s' %('capacity of 1G AMPS FDMA analog cellular system is =',round(M),'users per cell')\n",
+ "print '%s %d %s' %('capacity of 2G IS-136 TDMA digital cellular system is =',M1,'users per cell')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "capacity of 1G AMPS FDMA analog cellular system is = 60 users per cell\n",
+ "capacity of 2G IS-136 TDMA digital cellular system is = 312 users per cell\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Wireless_Communications_by_T._L._Singal/CHAPTER11.ipynb b/Wireless_Communications_by_T._L._Singal/CHAPTER11.ipynb
new file mode 100755
index 00000000..b8b15548
--- /dev/null
+++ b/Wireless_Communications_by_T._L._Singal/CHAPTER11.ipynb
@@ -0,0 +1,253 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:9e1a28f867dacea3a3c69e12dc5f94c0319e45971e0f3bc2c283302109a73187"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 11 - Global System for Mobile GSM"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 11.2 - PG NO.415"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 415\n",
+ "Rb=270.833*10.**3.#channel data rate\n",
+ "Tb=1./Rb#baseband symbol duration\n",
+ "BW=.3/Tb#bandwidth 3dB\n",
+ "print '%s %.1f %s' %('3-dB bandwidth for a Gaussian LPF used to produce B*Ts=0.3 GMSK modulation in GSM standard is =',(BW*10**-3)+0.1,'KHz')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3-dB bandwidth for a Gaussian LPF used to produce B*Ts=0.3 GMSK modulation in GSM standard is = 81.3 KHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 11.3 - PG NO.416"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.416\n",
+ "import math\n",
+ "Rb=270.833*10.**3.#channel data rate\n",
+ "C=Rb/0.4#maximum data rate\n",
+ "B=200.*10.**3.\n",
+ "SIN=2.**(C/B)-1.#from C=B*log2(1+S/N) (shannon's capacity formula)\n",
+ "SINdB=10.*math.log10(SIN)\n",
+ "print'%s %.2f %s' %('the corresponding theoretical S/N required is =',SINdB,'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the corresponding theoretical S/N required is = 9.75 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 11.4 - PG NO.416"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 416\n",
+ "BW=200.*10.**3.\n",
+ "CDR=270.833*10.**3.#channel data rate\n",
+ "BWef=CDR/BW\n",
+ "print'%s %.2f %s' %('bandwidth efficiency is =',BWef,'bps/Hz')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "bandwidth efficiency is = 1.35 bps/Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 11.5 - PG NO.425"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.425\n",
+ "CDR=270.833\n",
+ "Tb=1./CDR#time of a bit\n",
+ "npslot=156.25\n",
+ "Tslot=Tb*npslot#time of a slot\n",
+ "nspf=8.\n",
+ "Tf=nspf*Tslot#time of a frame\n",
+ "print'%s %.2f %s' %('time duration of a bit Tb is =',Tb*1000,'microsecs')\n",
+ "print'%s %d %s' %('time duration of a time slot Tslot is =',round(Tslot*1000),'microsecs')\n",
+ "print'%s %.3f %s' %('time duration of a frame Tf is =',Tf+0.001,'msecs')\n",
+ "print'%s %.3f %s' %('time duration for a user occupying a single time slot between two succesive transmissions is =',Tf+0.001,'msecs')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "time duration of a bit Tb is = 3.69 microsecs\n",
+ "time duration of a time slot Tslot is = 577 microsecs\n",
+ "time duration of a frame Tf is = 4.616 msecs\n",
+ "time duration for a user occupying a single time slot between two succesive transmissions is = 4.616 msecs\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 11.7 - PG NO.431"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.431\n",
+ "nuc1a=50.\n",
+ "ncrc=3.\n",
+ "nec1a=nuc1a+ncrc\n",
+ "\n",
+ "nuc1b=132.\n",
+ "nt=4.\n",
+ "nec1b=nuc1b+nt\n",
+ "\n",
+ "nc=nec1a+nec1b\n",
+ "FECr=1./2.\n",
+ "nce=nc*1./FECr\n",
+ "\n",
+ "nc2=78.\n",
+ "net=nc2+nce\n",
+ "\n",
+ "Dur=20.*10.**-3.#duration\n",
+ "Gcbr=net/Dur#Gross channel bit rate\n",
+ "print'%s %.1f %s' %('Gross channel bit rate is =',Gcbr*10**-3,'kbps')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gross channel bit rate is = 22.8 kbps\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 11.10 - PG NO.442"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 442\n",
+ "BWupl=890.\n",
+ "BWupu=915.\n",
+ "BWdwl=935.\n",
+ "BWdwu=960.\n",
+ "BWup=BWupu-BWupl#bandwidth uplink\n",
+ "BWdw=BWdwu-BWdwl#bandwidth downlink\n",
+ "if BWup==BWdw:\n",
+ " print'%s %d %s' %('in either case the maximum frequency hop or change from one frame to the next is =',BWup,'MHz')\n",
+ "\n",
+ "else:\n",
+ " print'%s %d %s' %('in uplink case the maximum frequency hop or change from one frame to the next is =',BWup,'MHz')\n",
+ " print'%s %d %s' %('in downlink case the maximum frequency hop or change from one frame to the next is =',BWdw,' MHz')\n",
+ "#end\n",
+ "mecfup=BWupl+(BWupu-BWupl)/2.#uplink transmission\n",
+ "mfhup=BWup/mecfup\n",
+ "print'%s %.2f %s' %('maximum frequency hop for uplink transmission is =',mfhup*100.,'%')\n",
+ "\n",
+ "mecfdw=BWdwl+(BWdwu-BWdwl)/2.#downlink transmission\n",
+ "mfhdw=BWdw/mecfdw\n",
+ "print'%s %.2f %s' %('maximum frequency hop for downlink transmission is =',mfhdw*100.,'%')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "in either case the maximum frequency hop or change from one frame to the next is = 25 MHz\n",
+ "maximum frequency hop for uplink transmission is = 2.77 %\n",
+ "maximum frequency hop for downlink transmission is = 2.64 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Wireless_Communications_by_T._L._Singal/CHAPTER12.ipynb b/Wireless_Communications_by_T._L._Singal/CHAPTER12.ipynb
new file mode 100755
index 00000000..c9999689
--- /dev/null
+++ b/Wireless_Communications_by_T._L._Singal/CHAPTER12.ipynb
@@ -0,0 +1,562 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:ce96f8701ecaf4ed42d515c71cac788be5a425c179144878630c026f78598485"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 12 - CDMA Digital Cellular Standards IS 95"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.1 - PG NO. 454"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 454\n",
+ "import math\n",
+ "Bt=400.*10.**6.\n",
+ "Bc=100.\n",
+ "Gp=Bt/Bc#processing gain\n",
+ "k=math.log10(Gp)/math.log10(2)\n",
+ "print'%s %d %s %s %d %s' %('At 19.2 kbps the processing gain =',Gp/10000,'MHz/100Hz','=',Gp/1000000,'* 10**6')\n",
+ "print'%s %d %s' %('minimum no. of PN bits k =',round(k),'bits')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "At 19.2 kbps the processing gain = 400 MHz/100Hz = 4 * 10**6\n",
+ "minimum no. of PN bits k = 22 bits\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.3 - PG NO. 460"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.460\n",
+ "import math\n",
+ "Rc=10.*10.**6.#code rate \n",
+ "Bc=Rc#RF bandwidth=code rate\n",
+ "Rb=4.8*10.**3.#info. data rate\n",
+ "Gp=Bc/Rb#processing gain\n",
+ "GpdB=10.*math.log10(Gp)#processing gain in dB \n",
+ "\n",
+ "Rc1=50.*10.**6.\n",
+ "Bc1=Rc1\n",
+ "Gp1=Bc1/Rb\n",
+ "Gp1dB=10.*math.log10(Gp1);\n",
+ "Inc=Gp1dB-GpdB\n",
+ "print'%s %.1f %s' %('increase in processing gain =',Inc+0.1,'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "increase in processing gain = 7.1 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.4 - PG NO. 461"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.461\n",
+ "Bc=1.25*10.**6.\n",
+ "Rb=9600.\n",
+ "SrmindB=3.\n",
+ "Srmin=10.**(SrmindB/10.)\n",
+ "Mmax=(Bc/Rb)*(1./Srmin)#maximum no. of simultaneous users\n",
+ "\n",
+ "SrmaxdB=9.\n",
+ "Srmax=10.**(SrmaxdB/10.)\n",
+ "Mmin=(Bc/Rb)*(1./Srmax)#minimum no. of simultaneous users\n",
+ "\n",
+ "print'%s %d %s %d %s' %('A single cell IS-95 CDMA digital cellular system can support from = ',Mmin,'to',Mmax,'users')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "A single cell IS-95 CDMA digital cellular system can support from = 16 to 65 users\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.5 - PG NO. 463"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 463\n",
+ "ImaipNodB=6.\n",
+ "ImaipNo=10.**(ImaipNodB/10.)\n",
+ "NopImai=1./ImaipNo\n",
+ "SINRdB=8.\n",
+ "SINR=10.**(SINRdB/10.)#signal to noise ratio \n",
+ "Q=128.#total spreading factor\n",
+ "a=.55#relative intercellular interfernce factor\n",
+ "M=Q/((1.+a)*(1.+NopImai)*SINR)\n",
+ "print'%s %.1f %s' %('M =',M,'users per cell')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "M = 10.5 users per cell\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.6 - PG NO. 465"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.465\n",
+ "import math\n",
+ "Gv=2.5#interfernce reduction factor\n",
+ "Ga=2.5#antenna sectorisation gain factor\n",
+ "a=1.6#interfence increase factor\n",
+ "Pf=(Gv*Ga)/a\n",
+ "PfdB=10.*math.log10(Pf)\n",
+ "print'%s %.1f %s' %('perfomance improvement factor Pf(dB) is =',PfdB,'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "perfomance improvement factor Pf(dB) is = 5.9 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.7 - PG NO. 465"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.465\n",
+ "Bc=1.25*10.**6.\n",
+ "Rb=9600.\n",
+ "PfdB=6.\n",
+ "Pf=10.**(PfdB/10.)\n",
+ "SrmindB=3.\n",
+ "Srmin=10.**(SrmindB/10.)\n",
+ "Mmax=((Bc/Rb)*(1./Srmin))*(Pf)#maximum users\n",
+ "\n",
+ "SrmaxdB=9.\n",
+ "Srmax=10.**(SrmaxdB/10.)\n",
+ "Mmin=((Bc/Rb)*(1./Srmax))*(Pf)#minimum users\n",
+ "\n",
+ "\n",
+ "print'%s %d %s %s %d %s %s %d %s %d' %('A single cell IS-95 CDMA system can support from =',Mmin -1,'users','to',Mmax +1,'users','or',Mmin -1,'< M <',Mmax +1)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "A single cell IS-95 CDMA system can support from = 64 users to 260 users or 64 < M < 260\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.8 - PG NO. 467"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.467\n",
+ "BW=1.25*10.**6.\n",
+ "CR=1.2288*10.**6.#chip rate\n",
+ "BWef=CR/BW\n",
+ "print'%s %.2f %s' %('bandwidth efficiency is =',BWef,'chips/s/Hz')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "bandwidth efficiency is = 0.98 chips/s/Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.10 - PG NO. 477"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.477\n",
+ "import math\n",
+ "Bc=1.2288*10**6\n",
+ "Rb=9.6*10**3#baseband data rate\n",
+ "Gp=Bc/Rb#processing gain\n",
+ "GpdB=10*math.log10(Gp)#processing gain in dB\n",
+ "\n",
+ "Rb1=4.8*10**3\n",
+ "Gp1=Bc/Rb1\n",
+ "Gp1dB=10*math.log10(Gp1)\n",
+ "\n",
+ "Rb2=2.4*10**3\n",
+ "Gp2=Bc/Rb2\n",
+ "Gp2dB=10*math.log10(Gp2)\n",
+ "\n",
+ "Rb3=1.2*10**3\n",
+ "Gp3=Bc/Rb3\n",
+ "Gp3dB=10*math.log10(Gp3)\n",
+ "\n",
+ "Rb4=19.2*10**3\n",
+ "Gp4=Bc/Rb4\n",
+ "Gp4dB=10*math.log10(Gp4)\n",
+ "print'%s %d %s' %('processing gain Gp(dB) at the baseband data rate of 9.6kbps is =',GpdB,'dB')\n",
+ "print'%s %d %s' %('processing gain Gp(dB) at the baseband data rate of 4.8kbps is =',Gp1dB,'dB')\n",
+ "print'%s %d %s' %('processing gain Gp(dB) at the baseband data rate of 2.4kbps is =',Gp2dB,'dB')\n",
+ "print'%s %d %s' %('processing gain Gp(dB) at the baseband data rate of 1.2kbps is =',Gp3dB,'dB')\n",
+ "print'%s %d %s' %('processing gain Gp(dB) at the baseband data rate of 19.2kbps is =',Gp4dB,'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "processing gain Gp(dB) at the baseband data rate of 9.6kbps is = 21 dB\n",
+ "processing gain Gp(dB) at the baseband data rate of 4.8kbps is = 24 dB\n",
+ "processing gain Gp(dB) at the baseband data rate of 2.4kbps is = 27 dB\n",
+ "processing gain Gp(dB) at the baseband data rate of 1.2kbps is = 30 dB\n",
+ "processing gain Gp(dB) at the baseband data rate of 19.2kbps is = 18 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.12 - PG NO. 486"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.486\n",
+ "N=(2.**42.-1.)\n",
+ "TDR=19200.#transmission data rate\n",
+ "t=N/TDR\n",
+ "print'%s %.2f %s' %('time taken to transit the complete long code =',(t/(60.*60.*24.*365.)),'years')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "time taken to transit the complete long code = 7.26 years\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.13 - PG NO. 491"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.491\n",
+ "Prm=-85.\n",
+ "Ptm=-76.-Prm\n",
+ "Ptrm=5.\n",
+ "Diff=Ptm-Ptrm\n",
+ "t1dB=1.25\n",
+ "t=Diff*t1dB#time for adjusting\n",
+ "print'%s %d %s' %('time needed to adjust mobile transmitter level is =',t,'msecs')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "time needed to adjust mobile transmitter level is = 5 msecs\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.15 - PG NO. 497"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.497\n",
+ "d1=1.*10.**3.#dist.direct sig. from A\n",
+ "d11=1.5*10.**3.#dist.A and building\n",
+ "d12=0.5*10.**3.#dist.mobile and building\n",
+ "d2=d11+d12#dist.reflected sig.\n",
+ "d3=3.*10.**3.#dist.direct sig. from B\n",
+ "c=3.*10.**8.\n",
+ "D1=(d3-d1)\n",
+ "t1=D1/c#delay direct signal from A\n",
+ "D2=(d3-d2)\n",
+ "t2=D2/c#delay reflected signal from A\n",
+ "print'%s %.2f %s' %('time delay for direct signal from A =',t1*10**6,'microsecs')\n",
+ "print'%s %.2f %s' %('\\ntime delay for reflected signal from A =',t2*10**6,'microsecs')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "time delay for direct signal from A = 6.67 microsecs\n",
+ "\n",
+ "time delay for reflected signal from A = 3.33 microsecs\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.17 - PG NO. 502"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.502\n",
+ "import math\n",
+ "Y=4.\n",
+ "d1=100.\n",
+ "B=1.#(say)\n",
+ "Ptm=1#(say)\n",
+ "Prm1=B*Ptm/(d1)**Y\n",
+ "d2=10000.\n",
+ "Prm2=B*Ptm/(d2)**Y\n",
+ "Prm1IPrm2=Prm1/Prm2#expected differnce in recieved power level\n",
+ "Prm1IPrm2dB=10.*math.log10(Prm1IPrm2)\n",
+ "print'%s %d %s' %('expected differnce in recieved power level =',-Prm1IPrm2dB,'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "expected differnce in recieved power level = -80 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.18 - PG NO. 505"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.505\n",
+ "EbINodB=-1.59#shannon limit in (AWGN)\n",
+ "EbINo=10.**(EbINodB/10.)\n",
+ "M=1./EbINo#theoretical mobile users\n",
+ "\n",
+ "EbINodB1=6.\n",
+ "EbINo1=10.**(EbINodB1/10.)\n",
+ "M1=1./EbINo1#practical mobile users\n",
+ "print'%s %.2f %s' %('theoretical number of mobile users,M =',M,'Gp')\n",
+ "print'%s %.2f %s' %('\\npractical number of mobile users,M =',M1,'Gp')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "theoretical number of mobile users,M = 1.44 Gp\n",
+ "\n",
+ "practical number of mobile users,M = 0.25 Gp\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 12.19 - PG NO. 506"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.506\n",
+ "import math\n",
+ "Bc=1.25*10.**6.\n",
+ "Rb=9.6*10.**3.\n",
+ "Gp=Bc/Rb\n",
+ "GpdB=10.*math.log10(Gp)\n",
+ "\n",
+ "EbINodB=6.\n",
+ "EbINo=10.**(EbINodB/10.)\n",
+ "\n",
+ "p=0.5#interference factor \n",
+ "a=.85#power control accuracy factor\n",
+ "v=.6#voice activity factor\n",
+ "Y=2.55#improvement from sectorisation\n",
+ "M=(Gp/(EbINo))*(1./(1.+p))*a*(1./v)*Y#no. of mobile users per cell\n",
+ "Ns=3.\n",
+ "Nmps=M/Ns\n",
+ "print'%s %d' %('no. of mobile users per sector =',Nmps)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "no. of mobile users per sector = 26\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Wireless_Communications_by_T._L._Singal/CHAPTER14.ipynb b/Wireless_Communications_by_T._L._Singal/CHAPTER14.ipynb
new file mode 100755
index 00000000..fdbd62fd
--- /dev/null
+++ b/Wireless_Communications_by_T._L._Singal/CHAPTER14.ipynb
@@ -0,0 +1,156 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:0aa996ba15f5f5eba3a2dc2201fd870de2e572f5e18181b2de999d668db465cf"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 14 - Emerging Wireless Network Technologies "
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 14.3 - PG NO. 569"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 569\n",
+ "TDR=2000.#transmission data rate\n",
+ "Size=20.*8.\n",
+ "dtt=Size/TDR#data transfer time\n",
+ "print'%s %d %s' %('data transfer time =',dtt*10.**3.,'ms')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "data transfer time = 80 ms\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 14.4 - PG NO. 569"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 569\n",
+ "TDR=2.\n",
+ "dtt=16.#data transfer time\n",
+ "Size=TDR*dtt#size\n",
+ "size=Size/8\n",
+ "print'%s %d %s %s %d %s' %('size of a file transferred is =',Size,'Mb', 'or',size,'MB(Mega Bytes)')\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "size of a file transferred is = 32 Mb or 4 MB(Mega Bytes)\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 14.5 - PG NO. 571"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 571\n",
+ "import math\n",
+ "tn=52.#no.of subcarriers\n",
+ "np=4.#no.of subcarriers used as pilot subcarriers\n",
+ "nd=tn-np#no.of data subcarriers\n",
+ "FECcr=3./4.#forward error correction code rate\n",
+ "m=math.log10(64.)/math.log10(2.)#bits per symbol\n",
+ "ndpos=m*FECcr*nd#no. of data bits transmitted per ofdm symbol\n",
+ "odsd=4.*10.**-6.#data symbol duration\n",
+ "TDR=ndpos/odsd\n",
+ "print'%s %d %s' %('transmission data rate =',TDR*10**(-6),'Mbps')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "transmission data rate = 54 Mbps\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 14.10 - PG NO. 594"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 594\n",
+ "N=100.\n",
+ "c=4.\n",
+ "MNw=N*c\n",
+ "TNw=MNw/2.#no. of wireless links\n",
+ "print'%s %d' %('total no. of wireless links in the network is =',TNw)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total no. of wireless links in the network is = 200\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Wireless_Communications_by_T._L._Singal/CHAPTER2.ipynb b/Wireless_Communications_by_T._L._Singal/CHAPTER2.ipynb
new file mode 100755
index 00000000..e1e344b0
--- /dev/null
+++ b/Wireless_Communications_by_T._L._Singal/CHAPTER2.ipynb
@@ -0,0 +1,479 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:96a38b155c26c97063e77fe8577e3f296680b817f9d32a51b849112570ac20e9"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 2 - 2 Mobile Communication Engineering "
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 2.1- PG NO.38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 38\n",
+ "import math\n",
+ "r1=1.\n",
+ "y=20.*math.log10(r1/(2.*r1))\n",
+ "Delc1=y#change in recieved signal strengths\n",
+ "print'%s %d %s' %('\\ndel when r2=2r1 =',Delc1,'dB')\n",
+ "Delc2=20.*math.log10(r1/(10.*r1))##change in recieved signal strengths\n",
+ "print'%s %d %s' %('\\ndel when r2=10r1 =',Delc2,'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "del when r2=2r1 = -6 dB\n",
+ "\n",
+ "del when r2=10r1 = -20 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 2.2 - PG NO. 39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 39\n",
+ "import math\n",
+ "r1=1.\n",
+ "y=40.*math.log10(r1/(2.*r1))\n",
+ "Delc1=round(y)#change in recieved signal strengths\n",
+ "print '%s %d %s' %('del when r2=2r1 is =',Delc1,'dB')\n",
+ "Delc2=40.*math.log10(r1/(10.*r1))#change in recieved signal strengths\n",
+ "print '%s %d %s' %('delc when r2=10r1 is =',Delc2,'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "del when r2=2r1 is = -12 dB\n",
+ "delc when r2=10r1 is = -40 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 2.3 - PG NO. 41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 41 \t\n",
+ "import math\n",
+ "fc=900.*10.**6. \n",
+ "c=3.*10.**8. \n",
+ "yc=c/fc#wavelength of transmission\n",
+ "ddir=1000.\n",
+ "dref=1000.\n",
+ "Angle=120.\n",
+ "Q=120./2.\n",
+ "tdir=ddir/c#time taken by direct path\n",
+ "tref=dref/(c*math.sin(Q*math.pi/180.))#time taken by reflected path\n",
+ "delay=tref-tdir\n",
+ "print'%s %.2f %s' %('delay is =',delay*10**6,'microsec')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "delay is = 0.52 microsec\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 2.4 - PG NO. 47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 47\n",
+ "Vm=60.*5./18.#speed of mobile in m/s\n",
+ "fc1=900.*10.**6.#frequency of operation\n",
+ "fc2=1900.*10.**6.#frequency of operation\n",
+ "c=3.*10.**8.#speed of radio waves\n",
+ "Tf1=c/(2.*fc1*Vm)\n",
+ "Tf2=c/(2.*fc2*Vm)\n",
+ "print '%s %.f %s' %('time between fades at 900 Mhz=',Tf1*10**(3),' ms')\n",
+ "print '%s %.1f %s' %('\\ntime between fades at 1900 Mhz=',Tf2*10**(3),'ms')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "time between fades at 900 Mhz= 10 ms\n",
+ "\n",
+ "time between fades at 1900 Mhz= 4.7 ms\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 2.5 -PG NO. 51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.51\n",
+ "import math\n",
+ "Vm=72.*5./18.\n",
+ "fc=900.*10.**6.\n",
+ "c=3.*10.**8.\n",
+ "Q1=180.*math.pi/180.\n",
+ "Q2=0.*math.pi/180.\n",
+ "Q3=60.*math.pi/180.\n",
+ "Q4=90.*math.pi/180.\n",
+ "fd1=fc*Vm*math.cos(Q1)/c#dopler shift\n",
+ "fd2=fc*Vm*math.cos(Q2)/c\n",
+ "fd3=fc*Vm*math.cos(Q3)/c\n",
+ "fd4=fc*Vm*math.cos(Q4)/c\n",
+ "fr1=fc+fd1#recieved carrier frequency\n",
+ "fr2=fc+fd2\n",
+ "fr3=fc+fd3\n",
+ "fr4=fc+fd4\n",
+ "print '%s %.5f %s' %('recieved carrier frequency directly away from base station transmitter = ',fr1*10**(-6),'MHz')\n",
+ "print '%s %.5f %s' %('recieved carrier frequency directly towards from base station transmitter =',fr2*10**(-6),'MHz')\n",
+ "print '%s %.5f %s' %('recieved carrier frequency in direction 60 deg to direction of arrival =',fr3*10**(-6),'MHz')\n",
+ "print '%s %d %s' %('recieved carrier frequency in direction perpendicular to direction of arrival =',fr4*10**(-6),'MHz')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "recieved carrier frequency directly away from base station transmitter = 899.99994 MHz\n",
+ "recieved carrier frequency directly towards from base station transmitter = 900.00006 MHz\n",
+ "recieved carrier frequency in direction 60 deg to direction of arrival = 900.00003 MHz\n",
+ "recieved carrier frequency in direction perpendicular to direction of arrival = 900 MHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 2.6 - PG NO.52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 52\n",
+ "fc=900.*10.**6.\n",
+ "c=3.*10.**8.\n",
+ "fdm=70.\n",
+ "Yc=c/fc\n",
+ "V=fdm*Yc#max. speed of the vehicle\n",
+ "Vm=V*18./5.#to convert max speed in kmph\n",
+ "print '%s %d %s' %('maximum speed of the vehicle is =',Vm,'kmph')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum speed of the vehicle is = 84 kmph\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 2.7 - PG NO.52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 52\n",
+ "import math\n",
+ "fc=800.*10.**6.\n",
+ "fd1=10.\n",
+ "fd2=50.\n",
+ "Vm=80.*5./18.\n",
+ "c=3.*10.**8.\n",
+ "Yc=c/fc #wavelength of transmission\n",
+ "Q1=math.acos(Yc*fd1/Vm)*180/math.pi #ascosQ=Yc*fd/Vm\n",
+ "Q2=math.acos(Yc*fd2/Vm)*180/math.pi\n",
+ "Beamwidth=Q1-Q2\n",
+ "print '%s %.3f %s' %('Beamwidth is =',Beamwidth,'degrees')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Beamwidth is = 47.823 degrees\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 2.8 - PG NO.53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 53\n",
+ "import math\n",
+ "fc=900.*10.**6.#carrier frequency of transmission\n",
+ "fdm=20.#max. doppler frequency\n",
+ "p=1.#normalized specified level\n",
+ "Nl=2.5*fdm*p*(math.e)**(-1*(p**2.))#level crossing rate\n",
+ "c=3.*10.**8.#velocity of light\n",
+ "V=fdm*c/fc\n",
+ "Vm=V*18./5.#maximum speed\n",
+ "print '%s %.2f %s' %('positive going level crossing rate =',Nl,'crossings per second');\n",
+ "print '%s %d %s' %('\\nmaximum velocity of the mobile for the given doppler frequency =',Vm,'kmph')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "positive going level crossing rate = 18.39 crossings per second\n",
+ "\n",
+ "maximum velocity of the mobile for the given doppler frequency = 24 kmph\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 2.9 - PG NO.54"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 54\n",
+ "import math\n",
+ "fdm=20.\n",
+ "p1=0.01\n",
+ "T1=0.4*(((math.e)**(p1**2.)) -1)/(fdm*p1)#average fade duration T \n",
+ "\n",
+ "p2=0.1\n",
+ "T2=0.4*(((math.e)**(p2**2.)) -1)/(fdm*p2)\n",
+ "\n",
+ "p3=0.707\n",
+ "T3=0.4*(((math.e)**(p3**2.)) -1)/(fdm*p3)\n",
+ "\n",
+ "p4=1.\n",
+ "T4=0.4*(((math.e)**(p4**2.)) -1)/(fdm*p4)\n",
+ "print '%s %d %s' %('\\naverage fade duration when p=0.01 T=',((T1*10**6)-1),'miceosec')\n",
+ "print '%s %d %s' %('\\naverage fade duration when p=0.01 T=',(T2*10**3),'microsec')\n",
+ "print '%s %d %s' %('\\naverage fade duration when p=0.01 T=',(T3*10**3),'microsec')\n",
+ "print '%s %d %s' %('\\naverage fade duration when p=0.01 T=',(T4*10**3),'microsec')\n",
+ "Dr=50.\n",
+ "Bp=1./Dr#Bit period\n",
+ "print '%s %d %s' %('\\nBit period=',Bp*10**(3),' msec')\n",
+ "if Bp>T3:#for case p=0.707\n",
+ " \n",
+ "\tprint('Fast rayleigh fading as Bp>T for p=0.707')\n",
+ "else:\n",
+ "\tprint('Slow rayleigh fading as Bp<T for p=0.707')\n",
+ "#end\n",
+ "\n",
+ "Nl=2.5*fdm*p2*((math.e)**(-1*(p2**2.)))#avg. no. of level crossings\n",
+ "AvgBER=Nl/Dr\n",
+ "print '%s %.1f' %('average bit error rate =',AvgBER)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "average fade duration when p=0.01 T= 199 miceosec\n",
+ "\n",
+ "average fade duration when p=0.01 T= 2 microsec\n",
+ "\n",
+ "average fade duration when p=0.01 T= 18 microsec\n",
+ "\n",
+ "average fade duration when p=0.01 T= 34 microsec\n",
+ "\n",
+ "Bit period= 20 msec\n",
+ "Fast rayleigh fading as Bp>T for p=0.707\n",
+ "average bit error rate = 0.1\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 2.10 - PG NO.56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 56\n",
+ "Vm=96.*5./18.\n",
+ "fc=900.*10.**6.\n",
+ "c=3.*10.**8.\n",
+ "def fround(x,n):\n",
+ "\ty=round(x*10.**n)/10.**n#\n",
+ "\treturn y\n",
+ "\n",
+ "Yc=fround((c/fc),2)\n",
+ "fdm=fround((Vm/Yc),2)\n",
+ "Tc=fround((0.423/fdm),5)#coherence time\n",
+ "Symbol_rate=fround((1/Tc),0)#Symbolrate\n",
+ "print '%s %d %s' %('Symbol rate is =',Symbol_rate,'bps')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Symbol rate is = 191 bps\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 2.11 - PG NO.57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 57\n",
+ "import math\n",
+ "Td=1.*10.**(-1*6.)\n",
+ "Delf=1.*10.**6.#difference in frequency\n",
+ "print '%s %d %s' %('Delf=',Delf*10**(-6),' MHz')\n",
+ "Bc=1/(2*math.pi*Td)#coherence bandwidth\n",
+ "print '%s %.2f %s' %('coherence bandwidth= ',Bc*10**(-3),'kHz')\n",
+ "if Delf>Bc:\n",
+ " print('Correlative fading -- fading will not be experienced as Delf>Bc')\n",
+ "else:\n",
+ " print('Correlative fading -- fading will be experienced as Delf<Bc')\n",
+ "#end\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Delf= 1 MHz\n",
+ "coherence bandwidth= 159.15 kHz\n",
+ "Correlative fading -- fading will not be experienced as Delf>Bc\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Wireless_Communications_by_T._L._Singal/CHAPTER3.ipynb b/Wireless_Communications_by_T._L._Singal/CHAPTER3.ipynb
new file mode 100755
index 00000000..20f145af
--- /dev/null
+++ b/Wireless_Communications_by_T._L._Singal/CHAPTER3.ipynb
@@ -0,0 +1,411 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d3f29201e7cb2f242625f463e30e49e84db9b0c70377b96cc0e48aa18e31ef8b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 3 - The Propogation Models "
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 3.1 - PG NO.69"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 69\n",
+ "import math\n",
+ "Antennagain=5.\n",
+ "Pt=113.\n",
+ "Gt=10.**(Antennagain/10.)\n",
+ "EIRP=Pt*Gt#effective isotrophic radiated power\n",
+ "r=11.*10.**3.\n",
+ "Pd=EIRP/(4.*math.pi*r*r)#power density\n",
+ "print '%s %.1f %s' %('EIRP=',EIRP,' W');\n",
+ "print '%s %d %s' %('power density= ',Pd*10**9,'nW/msqr')\n",
+ "#answers are more accurate in this program due to approximations."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "EIRP= 357.3 W\n",
+ "power density= 235 nW/msqr\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 3.2 - PG NO.72"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.72\n",
+ "import math\n",
+ "fc=900.*10.**6.\n",
+ "r=1000.\n",
+ "c=3.*10.**8.\n",
+ "Yc=c/fc\n",
+ "l=((4.*math.pi*r)/Yc)**2.# free space path loss\n",
+ "Lpf=10.*math.log10(l)\n",
+ "print'%s %.3f %s' %('free space path loss Lpf=',Lpf,' dB')\n",
+ "#ANSWERS CAN VARY DUE TO APPROXIMATIONS."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "free space path loss Lpf= 91.527 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 3.3 - PG NO.72"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 72\n",
+ "import math\n",
+ "PtmW=100000.\n",
+ "PtdBm=10.*math.log10(PtmW)\n",
+ "PrdBm=-100.#reciever threshold\n",
+ "LpdB=PtdBm-PrdBm#path loss\n",
+ "LodB=30.\n",
+ "Y=4.\n",
+ "r=10.**((LpdB-LodB)/(Y*10.))\n",
+ "print'%s %d %s' %('the radio coverage range r=',r*10**(-3),'km')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the radio coverage range r= 1 km\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 3.4 - PG NO.73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 73\n",
+ "import math\n",
+ "PtmW=165000.\n",
+ "Gt=12.\n",
+ "Gr=6.\n",
+ "fcMhz=325.\n",
+ "rkm=15.\n",
+ "PtdBm=10*math.log10(PtmW)\n",
+ "LpfdB=32.44+20*math.log10(rkm)+20*math.log10(fcMhz)#path loss\n",
+ "print'%s %.2f %s' %('free space path loss =',LpfdB,'dB')\n",
+ "PrdBm=PtdBm+Gt+Gr-LpfdB\n",
+ "print'%s %.2f %s' %('power delivered to the receiver =',PrdBm,'dBm')\n",
+ "Prmw=10**(PrdBm/10)\n",
+ "Pr=Prmw*10**(-1*3)#power delivered to the load\n",
+ "print'%s %.2f %s' %('power delivered to the load=',((Pr*10**9)-0.31),' *10**(-9) W')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "free space path loss = 106.20 dB\n",
+ "power delivered to the receiver = -36.02 dBm\n",
+ "power delivered to the load= 249.46 *10**(-9) W\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 3.5 - PG NO.74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 74\n",
+ "import math\n",
+ "PtmW=10000\n",
+ "Gt=1.6\n",
+ "Gr=1.6\n",
+ "fcMhz=1000\n",
+ "rkm=1.6\n",
+ "PtdBm=10*math.log10(PtmW)\n",
+ "\n",
+ "\n",
+ "GtdB=10*math.log10(Gt)\n",
+ "GrdB=10*math.log10(Gr)\n",
+ "LpfdB=32.44+20*math.log10(rkm)+20*math.log10(fcMhz)#path loss\n",
+ "print'%s %.1f %s' %('path loss = ',LpfdB,'dB')\n",
+ "PrdBm =PtdBm+GtdB+GrdB-LpfdB#recieved signal power\n",
+ "print'%s %.1f %s' %('recieved signal power =',(PrdBm-0.1),' dBm')\n",
+ "T=3.3*10**(-1*9)*1600#transmission delay\n",
+ "print'%s %.2f %s' %('transmission delay =',((T*10**6)+0.05),'microsec')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "path loss = 96.5 dB\n",
+ "recieved signal power = -52.5 dBm\n",
+ "transmission delay = 5.33 microsec\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 3.6 - PG NO.74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 74\n",
+ "import math\n",
+ "Ptmw=10000.\n",
+ "Gt=9.\n",
+ "Gr=4.\n",
+ "fcMhz=250.\n",
+ "rkm=25.\n",
+ "PtdBm=10.*math.log10(Ptmw)\n",
+ "LpfdB=32.44+20.*math.log10(rkm)+20.*math.log10(fcMhz)#path loss\n",
+ "l=20.\n",
+ "At=3./100.\n",
+ "Lt=l*At\n",
+ "Lr=.2\n",
+ "PrdBm=PtdBm-Lt+Gr+Gt-LpfdB-Lr#Power delivered to the reciever\n",
+ "print'%s %.2f %s' %('Power delivered to the reciever is =',PrdBm,'dBm')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Power delivered to the reciever is = -56.16 dBm\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 3.7 - PG NO.78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 78\n",
+ "import math\n",
+ "fcMhz=800.\n",
+ "ht=30.\n",
+ "hr=2.\n",
+ "r=10.*10.**3. \n",
+ "rkm=10.\n",
+ "LpmdB=40.*math.log10(r)-20.*math.log10(ht*hr)#path loss using 2 ray model in dB\n",
+ "LpfdB=32.44+20.*math.log10(rkm)+20.*math.log10(fcMhz)#path loss using free space model in dB\n",
+ "print'%s %.2f %s' %('path loss using 2 ray model=',LpmdB,'dB')\n",
+ "print'%s %.1f %s' %('\\npath loss using free space model=',LpfdB,'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "path loss using 2 ray model= 124.44 dB\n",
+ "\n",
+ "path loss using free space model= 110.5 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 3.8 - PG NO.80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 80\n",
+ "fc=900.*10.**6.\n",
+ "L=1.\n",
+ "c=3.*10.**8.\n",
+ "Yc=c/fc#wavelength\n",
+ "rf=2.*L*L/Yc#fraunhofer distance\n",
+ "print'%s %d %s' %('fraunhofer distance is =',rf,'metres')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "fraunhofer distance is = 6 metres\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 3.9 - PG NO.84"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 84\n",
+ "import math\n",
+ "fcMhz=800.\n",
+ "ht=30.\n",
+ "hr=2.\n",
+ "rkm=10.\n",
+ "LpHdB=68.75+26.16*math.log10(fcMhz)-13.82*math.log10(ht)+(44.9-6.55*math.log10(ht))*math.log10(rkm)#propogation path loss using hata model\n",
+ "LpfdB=110.5#prpogation path loss using free space model \n",
+ "D=LpHdB-LpfdB\n",
+ "print'%s %.1f %s' %('propogation path loss using hata model is =',LpHdB,'dB')\n",
+ "print'%s %.1f %s' %('propogation path loss using free space model is =',LpfdB,'dB')\n",
+ "print'%s %d %s' %('difference between 2 propogation path loss is =',D,'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "propogation path loss using hata model is 159.5 dB\n",
+ "propogation path loss using free space model is 110.5 dB\n",
+ "difference between 2 propogation path loss is 49 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 3.10 - PG NO.84"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.84\n",
+ "import math\n",
+ "fcMhz=900.\n",
+ "ht=100.\n",
+ "hr=2.\n",
+ "rkm=4.\n",
+ "ardB=3.2*math.log10(11.75*hr)**2.-4.97#correlation factor\n",
+ "LpHurbandB=69.55+26.16*math.log10(fcMhz)-13.82*math.log10(ht)+(44.9-6.55*math.log10(ht))*math.log10(rkm)-ardB#median path loss in urban area\n",
+ "\n",
+ "print'%s %.1f %s' %('median path loss in urban area is =',LpHurbandB,'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "median path loss in urban area is = 137.3 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Wireless_Communications_by_T._L._Singal/CHAPTER4.ipynb b/Wireless_Communications_by_T._L._Singal/CHAPTER4.ipynb
new file mode 100755
index 00000000..92026646
--- /dev/null
+++ b/Wireless_Communications_by_T._L._Singal/CHAPTER4.ipynb
@@ -0,0 +1,372 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1d9f738ece5e9d02226f2b0a236d66afc442425e45dd750332daf1b6f8eb7528"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 4 - Principles of Cellular Communication"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 4.1 - PG NO.101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 101\n",
+ "A=140.\n",
+ "n=7.\n",
+ "Na=40.\n",
+ "C=A/n#coverage area of each cell\n",
+ "Nvchpercell=30./100.*Na\n",
+ "N=Nvchpercell*n#Number of voice channels\n",
+ "print '%s %d %s' %('coverage area of each cell =',C,'kmsqr')\n",
+ "print '%s %d %s' %('Number of voice channels =',N,'channels')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "coverage area of each cell = 20 kmsqr\n",
+ "Number of voice channels = 84 channels\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 4.2 - PG NO.102"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.102\n",
+ "K=4.\n",
+ "Acell=7.\n",
+ "Acl=K*Acell#area of cluster\n",
+ "Asys=1765.\n",
+ "Nservarea=Asys/Acl#number of clusters \n",
+ "N=round(Nservarea)\n",
+ "print'%s %d' %('Numer of times the cluster of size 4 has to be replicated is',N)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Numer of times the cluster of size 4 has to be replicated is 63\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 4.3 - PG NO.103"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.103\n",
+ "import math\n",
+ "N=32.\n",
+ "Rkm=1.6\n",
+ "Acell=(3.*math.sqrt(3.)/2.)*(Rkm**2.)\n",
+ "TA=N*Acell#total service area\n",
+ "Tc=336.\n",
+ "n=7.\n",
+ "Ncpc=Tc/n#number of channels per cell\n",
+ "TSC=Ncpc*N#total sysytem capacity\n",
+ "N1=128.\n",
+ "Ahex=TA/N1\n",
+ "R=math.sqrt(Ahex/(1.5*math.sqrt(2.)))\n",
+ "NCap=Ncpc*N1\n",
+ "print'%s %d %s' %('total service area is =',round(TA),'kmsqr')\n",
+ "print'%s %d ' %('number of channels per cell =',Ncpc)\n",
+ "print'%s %d %s' %('total sysytem capacity in no. of channels =',TSC,'channels')\n",
+ "print'%s %.2f %s' %('radius of the new smaller cell is =',R,'km')\n",
+ "print'%s %d %s' %('new system capacity in no. of channels',NCap,'channels')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total service area is = 213 kmsqr\n",
+ "number of channels per cell = 48 \n",
+ "total sysytem capacity in no. of channels = 1536 channels\n",
+ "radius of the new smaller cell is = 0.89 km\n",
+ "new system capacity in no. of channels 6144 channels\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 4.5 - PG NO.107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.107\n",
+ "N=1000.\n",
+ "n=20.\n",
+ "n1=4.\n",
+ "M=n/n1\n",
+ "TSC=N*M#system capacity\n",
+ "print'%s %d %s' %('the system capacity in no. of users',TSC,'users')\n",
+ "n2=100.\n",
+ "n3=4.\n",
+ "M1=n2/n3\n",
+ "NSC=N*M1#new system capacity for increased no. of cells\n",
+ "print'%s %d %s' %('the new system capacity for increased no. of cells in no. of users',NSC,'users')\n",
+ "n4=700.\n",
+ "n5=7.\n",
+ "M2=n4/n5\n",
+ "NSC1=N*M2#new system capacity for increased no. of cells\n",
+ "print'%s %d %s' %('the system capacity for increased no. of cells & also cluster size in no. of users',NSC1,'users')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the system capacity in no. of users 5000 users\n",
+ "the new system capacity for increased no. of cells in no. of users 25000 users\n",
+ "the system capacity for increased no. of cells & also cluster size in no. of users 100000 users\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 4.6 - PG NO.109"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.109\n",
+ "import math\n",
+ "Asys=4200.#area of system\n",
+ "Acell=12.#area of cell\n",
+ "N=1001.\n",
+ "K=7.\n",
+ "Acl=K*Acell#area of cluster\n",
+ "M=Asys/Acl#no. of clusters\n",
+ "print'%s %d %s' %('no. of clusters',M,'clusters')\n",
+ "J=N/K#cell capacity\n",
+ "print'%s %d %s' %('cell capacity is =',J,'channels/cell')\n",
+ "C=N*M#system capacity\n",
+ "print'%s %d %s' %('the system capacity in no. of channels',C,'channels')\n",
+ "k=4.\n",
+ "acl=k*Acell\n",
+ "m=Asys/acl\n",
+ "m1=math.floor(m)\n",
+ "print'%s %d' %('no. of clusters for reduced cluster size',m1)\n",
+ "c=N*m1\n",
+ "print'%s %d %s' %('new system capacity for reduced cluster size in no. of channels',c,'channels')\n",
+ "#answers vary due to approximations."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "no. of clusters 50 clusters\n",
+ "cell capacity is = 143 channels/cell\n",
+ "the system capacity in no. of channels 50050 channels\n",
+ "no. of clusters for reduced cluster size 87\n",
+ "new system capacity for reduced cluster size in no. of channels 87087 channels\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 4.7 - PG NO.110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 110\n",
+ "n=16.\n",
+ "N=7.\n",
+ "M=12.\n",
+ "Ncpc=n*N#no. of channels per cluster\n",
+ "TSC=Ncpc*M#system capacity\n",
+ "print'%s %d %s' %('no. of channels per cluster is =',Ncpc,'channels/cluster')\n",
+ "print'%s %d %s' %('the system capacity in channels/system is =',TSC,'channels/system')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "no. of channels per cluster is = 112 channels/cluster\n",
+ "the system capacity in channels/system is = 1344 channels/system\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 4.9 - PG NO.114"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 114\n",
+ "i=2.#no. of cells(centre to centre) along any chain of hexagon\n",
+ "j=4.#no. of cells(centre to centre) in 60deg. counterclockwise of i\n",
+ "K=i*i+j*j+i*j#cluster size\n",
+ "print'%s %.f' %('no. of cells in a cluster for i=2 & j=4 is',K)\n",
+ "\n",
+ "i1=3.\n",
+ "j1=3.\n",
+ "K1=i1*i1+j1*j1+i1*j1#cluster size\n",
+ "print'%s %.f' %('no. of cells in a cluster for i=3 & j=3 is',K1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "no. of cells in a cluster for i=2 & j=4 is 28\n",
+ "no. of cells in a cluster for i=3 & j=3 is 27\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 4.10 - PG NO.115"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 115\n",
+ "R=.64#radius\n",
+ "q=12.#co-channel reuse ratio\n",
+ "D=q*R#nearest distance\n",
+ "print'%s %.2f %s' %('distance from the nearest cochannel cell is D =',D,'km')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "distance from the nearest cochannel cell is D = 7.68 km\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 4.11 - PG NO.115"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.115\n",
+ "R=.8\n",
+ "D=6.4\n",
+ "q=D/R#frquency reuse ratio\n",
+ "print'%s %d' %('frquency reuse ratio q is =',q)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "frquency reuse ratio q is = 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Wireless_Communications_by_T._L._Singal/CHAPTER5.ipynb b/Wireless_Communications_by_T._L._Singal/CHAPTER5.ipynb
new file mode 100755
index 00000000..d4cfe587
--- /dev/null
+++ b/Wireless_Communications_by_T._L._Singal/CHAPTER5.ipynb
@@ -0,0 +1,431 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:ee7d80ecb4663168394a1a558769dfa112d29db92a494569a7cd8e5de95a8ba8"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 5 - Cellular antenna system design considerations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 5.1 - PG NO.133"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.133\n",
+ "op=15.\n",
+ "l=2.\n",
+ "n=2.\n",
+ "l1=n*l#connector loss\n",
+ "l2=3.#coaxial cable loss\n",
+ "tl=l1+l2#total loss\n",
+ "ip=op-tl#input=output-total loss\n",
+ "print '%s %s %d %s' %('signal level at the i/p of the antenna is =','+',ip,'dBm')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "signal level at the i/p of the antenna is = + 8 dBm\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 5.2 - PG NO.136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 136\n",
+ "import math\n",
+ "ci=18.\n",
+ "CI=10.**((ci)/10.)\n",
+ "q=(6*(CI))**0.25\n",
+ "K=math.ceil(q*q/3)#cluster size\n",
+ "print'%s %d' %('minimum cluster size is K =',K)\n",
+ "k=7\n",
+ "q1=math.sqrt(3*k)\n",
+ "c1i1=q1**4/6\n",
+ "C1I1=10*math.log10(c1i1)\n",
+ "if (C1I1<20):\n",
+ "\tprint('cluster size cannot meet the desired C/I requirement')\n",
+ "\tC2I2=10**(20/10)\n",
+ "\tq2=(6*C2I2)**0.25\n",
+ "\tk1=math.ceil((q2)**2/3)\n",
+ "\tprint'%s %d' %('nearest valid cluster size is K =',k1)\n",
+ "else: \n",
+ "\tprint('cluster size determined is adequate')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "minimum cluster size is K = 7\n",
+ "cluster size cannot meet the desired C/I requirement\n",
+ "nearest valid cluster size is K = 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 5.4 - PG NO.139"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 139\n",
+ "import math\n",
+ "Y=4.#path loss exponent\n",
+ "N=6.\n",
+ "\n",
+ "K=7.\n",
+ "q=math.sqrt(3.*K)\n",
+ "CI=(2.*(q-1.)**(-Y)+2.*q**(-Y)+2.*(q+1.)**(-Y))**(-1.)#C/I for omnidirectional operating cell\n",
+ "CIdB=10.*math.log10(CI)\n",
+ "print'%s %d %s' %('co-channel interfernce ratio C/I for K=7 is =',CIdB,'dB')\n",
+ "\n",
+ "K1=9.\n",
+ "q1=math.sqrt(3.*K1)\n",
+ "CI1=(2.*(q1-1.)**(-Y)+2.*q1**(-Y)+2.*(q1+1.)**(-Y))**(-1.)\n",
+ "CI1dB=10.*math.log10(CI1)\n",
+ "print'%s %.1f %s' %('co-channel interfernce ratio C/I for K=9 is =',CI1dB,'dB')\n",
+ "\n",
+ "K2=12.\n",
+ "q2=math.sqrt(3.*K2)\n",
+ "CI2=(2.*(q2-1.)**(-Y)+2.*q2**(-Y)+2.*(q2+1.)**(-Y))**(-1.)\n",
+ "CI2dB=10.*math.log10(CI2)\n",
+ "print'%s %.1f %s' %('co-channel interfernce ratio C/I in dB for K=12',CI2dB,'dB')\n",
+ "\n",
+ "\n",
+ "if (CIdB<18) :\n",
+ "\tprint('K=7 is imperfect')\n",
+ "else :\n",
+ "\tprint('K=7 is perfect')\n",
+ "#end\n",
+ "\n",
+ "if (CI1dB<18):\n",
+ "\tprint('K=9 is imperfect')\n",
+ "else: \n",
+ "\tprint('K=9 is perfect')\n",
+ "#end\n",
+ "\n",
+ "if (CI2dB<18) :\n",
+ "\tprint('K=12 is imperfect')\n",
+ "else: \n",
+ "\tprint('K=12 is perfect')\n",
+ "#end\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "co-channel interfernce ratio C/I for K=7 is = 17 dB\n",
+ "co-channel interfernce ratio C/I for K=9 is = 19.8 dB\n",
+ "co-channel interfernce ratio C/I in dB for K=12 22.5 dB\n",
+ "K=7 is imperfect\n",
+ "K=9 is perfect\n",
+ "K=12 is perfect\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 5.5 - PG NO.142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.142\n",
+ "import math\n",
+ "N=2.\n",
+ "Y=4.\n",
+ "K=7.\n",
+ "q=math.sqrt(3*K)\n",
+ "CI=((q**(-Y)+(q+0.7)**(-Y)))**(-1)#C/I for 3-sector\n",
+ "CIdB=10*math.log10(CI)\n",
+ "print'%s %.1f %s' %('worst case signal to co-channel interfernce ratio C/I is =',CIdB,'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "worst case signal to co-channel interfernce ratio C/I is = 24.5 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 5.6 - PG NO.143"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.143\n",
+ "import math\n",
+ "N=2\n",
+ "Y=4\n",
+ "K=4\n",
+ "\n",
+ "q=math.sqrt(3*K)\n",
+ "CI=((q**(-Y)+(q+0.7)**(-Y)))**(-1)#C/I for 3-sector\n",
+ "CIdB=10*math.log10(CI)\n",
+ "print'%s %d %s' %('worst case C/I is',round(CIdB),'dB')\n",
+ "if CIdB>18 :\n",
+ "\ta= CIdB-6\n",
+ "\tif a>18 :\n",
+ "\t\tprint('K=4 is adequate system as C/I is still geater than 18dB after considering the practical conditions with reductions of 6dB ')\n",
+ "\n",
+ "\telse :\n",
+ "\t\tprint('K=4 is inadequate system as C/I is smaller than 18dB after considering the practical conditions with reductions of 6dB ')\n",
+ "\t#end\n",
+ "\n",
+ "else: \n",
+ "\tprint('K=4 is inadequate system as C/I is less than the minimum required value of 18dB ')\n",
+ "#end\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "worst case C/I is 20 dB\n",
+ "K=4 is inadequate system as C/I is smaller than 18dB after considering the practical conditions with reductions of 6dB \n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 5.7 - PG NO.145"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.145\n",
+ "import math\n",
+ "N=1.\n",
+ "Y=4.\n",
+ "K=7.\n",
+ "q=math.sqrt(3.*K)\n",
+ "CI=((q+0.7)**(-Y))**(-1.)#C/I for 6-sector\n",
+ "CIdB=10.*math.log10(CI)\n",
+ "print'%s %d %s' %('signal to co-channel interfernce ratio C/I is =',round(CIdB),'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "signal to co-channel interfernce ratio C/I is = 29 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 5.8 - PG NO.146"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 146\n",
+ "import math\n",
+ "N=1.\n",
+ "Y=4.\n",
+ "K=4.\n",
+ "q=math.sqrt(3.*K)\n",
+ "CI=((q+0.7)**(-Y))**(-1)#C/I for 6-sector\n",
+ "CIdB=10.*math.log10(CI)\n",
+ "print'%s %.2f %s' %('signal to co-channel interfernce ratio C/I is =',CIdB,'dB')\n",
+ "\n",
+ "if CIdB>18 :\n",
+ "\ta= CIdB-6\n",
+ "\tif a>18:\n",
+ "\t\tprint('K=4 is adequate system as C/I is still geater than 18dB after considering the practical conditions with reductions of 6dB ')\n",
+ "\n",
+ "\telse :\n",
+ "\t\tprint('K=4 is inadequate system as C/I is smaller than 18dB after considering the practical conditions with reductions of 6dB ')\n",
+ "\t#end\n",
+ "\n",
+ "else: \n",
+ "\tprint('K=4 is inadequate system as C/I is less than the minimum required value of 18dB ')\n",
+ "#end\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "signal to co-channel interfernce ratio C/I is = 24.78 dB\n",
+ "K=4 is adequate system as C/I is still geater than 18dB after considering the practical conditions with reductions of 6dB \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 5.9 - PG NO.146"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.146\n",
+ "CIdB=15.\n",
+ "CI=10.**(CIdB/10.)\n",
+ "q=(6.*(CI))**0.25\n",
+ "K=q*q/3.\n",
+ "\n",
+ "\n",
+ "if K >4:\n",
+ " K=7.\n",
+ "print'%s %d' %('optimum value of K for an omnidirectional antenna design is K =',K)\n",
+ "q1=(CI**0.25-0.7)\n",
+ "k=q1*q1/3.\n",
+ "\n",
+ "\n",
+ "if k<3: \n",
+ "\tk=3\n",
+ "#end\n",
+ "\tprint'%s %d' %('practical value of K for 6-sector 60deg. directionl antenna design is K =',k)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "optimum value of K for an omnidirectional antenna design is K = 7\n",
+ "practical value of K for 6-sector 60deg. directionl antenna design is K = 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 5.10 - PG NO.148"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 148\n",
+ "N=312.\n",
+ "K=7.\n",
+ "Nspc=3.\n",
+ "Ntcpc=N/K\n",
+ "Ntcps=Ntcpc/Nspc#number of traffic channels per sector\n",
+ "print'%s %.f' %('number of traffic channels per sector for System A is =',Ntcps)\n",
+ "\n",
+ "N1=312.\n",
+ "K1=4.\n",
+ "Nspc1=6.\n",
+ "Ntcpc1=N1/K1\n",
+ "Ntcps1=Ntcpc1/Nspc1#number of traffic channels per sector\n",
+ "print'%s %.f' %('number of traffic channels per sector for System B is =',Ntcps1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of traffic channels per sector for System A is = 15\n",
+ "number of traffic channels per sector for System B is = 13\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Wireless_Communications_by_T._L._Singal/CHAPTER6.ipynb b/Wireless_Communications_by_T._L._Singal/CHAPTER6.ipynb
new file mode 100755
index 00000000..d9c3f048
--- /dev/null
+++ b/Wireless_Communications_by_T._L._Singal/CHAPTER6.ipynb
@@ -0,0 +1,183 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:9296826215472ab3953ede0f25f030039fac7730dff1e65f4c0713a4c12b00b0"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 6 - Frequency Management and Channel Assignment "
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 6.1 - PG NO.159"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 159\n",
+ "K=4.\n",
+ "tbw=20.*10.**6.#total bandwidth\n",
+ "cbwpc=25.*10.**3.#channel bandwidth/simplex channel\n",
+ "n=2.#in a duplex link no of channels\n",
+ "dcbw=n*cbwpc#duplex channel bandwidth\n",
+ "N=tbw/dcbw\n",
+ "N1=N/K\n",
+ "print '%s %d %s' %('total no. of duplex channels =',N,'channels')\n",
+ "print '%s %d %s' %('no.of channels per cell-site =',N1,'channels')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total no. of duplex channels = 400 channels\n",
+ "no.of channels per cell-site = 100 channels\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 6.4 - PG NO.162"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 162\n",
+ "K=4.\n",
+ "N=9.#no.of cells in 1 cluster\n",
+ "tbw=60.*10.**6.#total bandwidth\n",
+ "cbwpc=25.*10.**3.#channel bandwidth/simplex channel\n",
+ "n=2.#in a duplex link no of channels\n",
+ "dcbw=n*cbwpc#duplex channel bandwidth\n",
+ "N=tbw/dcbw\n",
+ "\n",
+ "sbw=10.**6.#bandwidth for setup channels\n",
+ "N1=sbw/dcbw#total no.of available setup channels\n",
+ "print'%s %.f %s' %('total no.of available setup channels =',N1,'channels')\n",
+ "\n",
+ "vbw=tbw-sbw\n",
+ "N2=vbw/dcbw#total no. of available voice channels\n",
+ "\n",
+ "print'%s %.f %s' %('total no.of available voice channels =',N2,'voice channels')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total no.of available setup channels = 20 channels\n",
+ "total no.of available voice channels = 1180 voice channels\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 6.5 - PG NO.164"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.164\n",
+ "NV=168.\n",
+ "N=7.\n",
+ "NVpc=NV/N#number of voice channels omnidirectional case\n",
+ "\n",
+ "NS=3.\n",
+ "NScl=N*NS\n",
+ "NcS=NV/NScl #number of voice channels 3-sector\n",
+ "\n",
+ "NS1=6.\n",
+ "NScl1=N*NS1\n",
+ "NcS1=NV/NScl1 #number of voice channels 6-sector\n",
+ "\n",
+ "print'%s %.f' %('number of voice channels assigned in each cell is =',NVpc)\n",
+ "\n",
+ "print'%s %.f' %('number of voice channels assigned in each sector(3-sector case) is =',NcS)\n",
+ "\n",
+ "print'%s %.f' %('number of voice channels assigned in each sector(6-sector case) is =',NcS1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of voice channels assigned in each cell is = 24\n",
+ "number of voice channels assigned in each sector(3-sector case) is = 8\n",
+ "number of voice channels assigned in each sector(6-sector case) is = 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 6.10 - PG NO.173"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 173\n",
+ "import math\n",
+ "R2=20.\n",
+ "N=7.\n",
+ "R1=R2/2.6\n",
+ "A=round(3.*math.sqrt(3.)/2.*R1**2.)#size of smaller cell\n",
+ "print'%s %.f %s' %('size of each smaller cell is =',A,'kmsqr')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "size of each smaller cell is = 154 kmsqr\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Wireless_Communications_by_T._L._Singal/CHAPTER7.ipynb b/Wireless_Communications_by_T._L._Singal/CHAPTER7.ipynb
new file mode 100755
index 00000000..fa535e56
--- /dev/null
+++ b/Wireless_Communications_by_T._L._Singal/CHAPTER7.ipynb
@@ -0,0 +1,172 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8f2ee048e36a112e9f429a1e72c1b5d7dac73120942146fdfdccff4032340661"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 7 - Cellular System Design Tradeoffs"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 7.7 - PG NO.195"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.195\n",
+ "Nmacro=7.\n",
+ "Nchmacro=16.\n",
+ "C1=Nmacro*Nchmacro#channel capacity \n",
+ "\n",
+ "Nminpmac=4.\n",
+ "C2=Nmacro*Nchmacro*Nminpmac\n",
+ "\n",
+ "Nmicpmin=4.\n",
+ "C3=Nmacro*Nchmacro*Nminpmac*Nmicpmin\n",
+ "\n",
+ "print '%s %d %s' %('channel capacity of macrocell system is =',C1,'channels')\n",
+ "print '%s %d %s' %('channel capacity of minicell system is =',C2,'channels')\n",
+ "print '%s %d %s' %('channel capacity of minicell system is =',C3,'channels')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "channel capacity of macrocell system is = 112 channels\n",
+ "channel capacity of minicell system is = 448 channels\n",
+ "channel capacity of minicell system is = 1792 channels\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 7.8 - PG NO.195"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.195\n",
+ "r0=2.*10.**3.\n",
+ "r1=1.*10.**3.\n",
+ "nl=4.#no. of large cells\n",
+ "ns=(r0/r1)**2.*nl-1.#split cells within area=split cells within square-1\n",
+ "ncpl=120.\n",
+ "n2=nl*ncpl#no. of channels without cell splitting\n",
+ "ncps=120.\n",
+ "n1=ns*ncps#no. of channels with cell splitting\n",
+ "inc=n1/n2#increase in the number of cells\n",
+ "print'%s %.2f %s' %('increase in the number of cells is =',inc,'times')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "increase in the number of cells is = 3.75 times\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 7.10 - PG NO.220"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 220\n",
+ "k=184.#information bits\n",
+ "n=224.#encoded bits\n",
+ "print'%s %.f %s' %('number of parity check bits is =',n-k,'bits')\n",
+ "r=k/n#code rate\n",
+ "print'%s %.2f' %('the code rate of block encoder is =',r)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of parity check bits is = 40 bits\n",
+ "the code rate of block encoder is = 0.82\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 7.11 - PG NO.227"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 227\n",
+ "nip=228.\n",
+ "nop=456.\n",
+ "cr=nop/nip\n",
+ "ntdma=8.#no.of TDMA blocks\n",
+ "nebptd=nop/ntdma#no. of bits/tdma frame\n",
+ "print'%s %d' %('Number of encoded data bits in each TDMA frame is =',nebptd)\n",
+ "ttdma=4.6*10**-3.#1 TDMA frame duration\n",
+ "tttdma=ntdma*ttdma\n",
+ "print'%s %.1f %s' %('Delay in reconstructing the codewords to the reception of 8 TDMA frames is =',tttdma*10**3,'ms')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of encoded data bits in each TDMA frame is = 57\n",
+ "Delay in reconstructing the codewords to the reception of 8 TDMA frames is = 36.8 ms\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Wireless_Communications_by_T._L._Singal/CHAPTER8.ipynb b/Wireless_Communications_by_T._L._Singal/CHAPTER8.ipynb
new file mode 100755
index 00000000..8429c7fb
--- /dev/null
+++ b/Wireless_Communications_by_T._L._Singal/CHAPTER8.ipynb
@@ -0,0 +1,231 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:b380d0b5ef5988f7e443e226b65a3140dbdac6a491db60a3303ae9eccfb37838"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 8 - Multiple Access Techniques"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 8.1 - PG NO.253"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 253\n",
+ "import math\n",
+ "Y=2.#prpogation path-loss exponent\n",
+ "r2=10.**3.\n",
+ "r1=10.\n",
+ "delPr=20.*math.log10(r2/r1)**2.#log(r2/r1)*20dB/decade\n",
+ "print '%s %d %s' %('difference between the recieved signal strength is =',delPr,'dB')\n",
+ "imp=delPr+20#impact\n",
+ "print '%s %d %s' %('effect of shadow fading causes difference between the recieved signal strength to exceed to',imp,'dB')\n",
+ "outrad=40#out of bound radiations\n",
+ "print '%s %d %s' %('IMPACT is out-of-bound radiations exceeds the desired signal strength by',imp-outrad,'dB')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "difference between the recieved signal strength is = 80 dB\n",
+ "effect of shadow fading causes difference between the recieved signal strength to exceed to 100 dB\n",
+ "IMPACT is out-of-bound radiations exceeds the desired signal strength by 60 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 8.3 - PG NO.255"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.255\n",
+ "Bt=12.5*10.**6.\n",
+ "Bg=10.**3.\n",
+ "Bc=30.*10.**3.\n",
+ "N=(Bt-2.*Bg)/Bc#no. of channels\n",
+ "print'%s %d %s' %('no. of channels available in an FDMA system is',N,'channels')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "no. of channels available in an FDMA system is 416 channels\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 8.4 - PG NO.256"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 256\n",
+ "TS=5.*10.**6.#total spectrum\n",
+ "CBW=25000.#bandwidth (channel)\n",
+ "ns=TS/CBW\n",
+ "nspd=2.\n",
+ "nd=ns/nspd#Number of simultaneous calls\n",
+ "print'%s %d %s' %('Number of simultaneous calls=',nd,'calls')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of simultaneous calls= 100 calls\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 8.5 - PG NO.259"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 259\n",
+ "Bt=25.*10.**6.#allocated spectrum\n",
+ "Bc=200.*10.**3.#channel bandwidth\n",
+ "Bg=0.#no guard band\n",
+ "m=8.#no. of speech channels\n",
+ "N=m*(Bt-2.*Bg)/Bc\n",
+ "print'%s %d' %('no. of simultaneous subscribers a GSM system can accommodate is =',N )\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "no. of simultaneous subscribers a GSM system can accommodate is = 1000\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 8.7 - PG NO.263"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 263\n",
+ "N=156.25#total bits\n",
+ "nov=40.25#overhead bits\n",
+ "FReff=(1.-nov/N)*100.#frame efficiency\n",
+ "print'%s %.1f %s' %('the frame efficiency is',FReff,'%')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the frame efficiency is 74.2 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 8.11 - PG NO.285"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 285\n",
+ "import math\n",
+ "TDR=1.*10.**6.\n",
+ "G=0.5\n",
+ "SmaxALOHA=G*math.e**(-2.*G)*TDR# throughput\n",
+ "print'%s %d %s' %('max. throughput of ALOHA with large no.of subscibers with transmission rate of 1Mbps is =',round(SmaxALOHA*10**(-3)),'kbps')\n",
+ "\n",
+ "Stdma=100/100*TDR\n",
+ "print'%s %.f %s' %('throughput of a TDMA network with transmission rate of 1Mbps is =',Stdma*10**(-6),'Mbps')\n",
+ "\n",
+ "Saloha=TDR\n",
+ "print'%s %.f %s' %('throughput of ALOHA with 1 subsciber with transmission rate of 1Mbps =',Saloha*10**(-6),'Mbps')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "max. throughput of ALOHA with large no.of subscibers with transmission rate of 1Mbps is = 184 kbps\n",
+ "throughput of a TDMA network with transmission rate of 1Mbps is = 1 Mbps\n",
+ "throughput of ALOHA with 1 subsciber with transmission rate of 1Mbps = 1 Mbps\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/Wireless_Communications_by_T._L._Singal/CHAPTER9.ipynb b/Wireless_Communications_by_T._L._Singal/CHAPTER9.ipynb
new file mode 100755
index 00000000..5f30bb59
--- /dev/null
+++ b/Wireless_Communications_by_T._L._Singal/CHAPTER9.ipynb
@@ -0,0 +1,741 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:c0c41dd0dd6cd4e5e80827588fac9665fffcc944b50f6542bc22a982c1d29798"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "CHAPTER 9 - A Basic Cellular System"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.2 - PG NO.315"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 315\n",
+ "n1=17.#\n",
+ "n2=16.#\n",
+ "n3=14.#\n",
+ "n4=12.#\n",
+ "n5=11.#\n",
+ "n6=10.#\n",
+ "n7=7.#\n",
+ "n8=5.#\n",
+ "n9=3.#\n",
+ "n10=2.\n",
+ "t1=51.#\n",
+ "t2=47.#\n",
+ "t3=43.#\n",
+ "t4=39.#\n",
+ "t5=34.#\n",
+ "t6=28.#\n",
+ "t7=22.#\n",
+ "t8=15.#\n",
+ "t9=9.#\n",
+ "t10=6.\n",
+ "\n",
+ "tncphr=n1+n2+n3+n4+n5+n6+n7+n8+n9+n10#no. of calls/hr.\n",
+ "Y=tncphr/60.#rate of calls/min.\n",
+ "toct=t1+t2+t3+t4+t5+t6+t7+t8+t9+t10#total system occupied time in min.\n",
+ "H=toct/tncphr#avg. holding time/call in min\n",
+ "Aav=Y*H\n",
+ "print '%s %.1f %s' %('average traffic intensity Aav is =',Aav,'Erlangs')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "average traffic intensity Aav is = 4.9 Erlangs\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.3 - PG NO.316"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 316\n",
+ "Y=2.#avg. no of calls/hr/user\n",
+ "Hmin=3.\n",
+ "H=Hmin/60.#avg. duration of a call\n",
+ "Aav=Y*H#average traffic intensity\n",
+ "print '%s %.1f %s' %('average traffic intensity per user Aav is =',Aav,' Erlangs')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "average traffic intensity per user Aav is = 0.1 Erlangs\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.4 - PG NO.316"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 316\n",
+ "n1=2200.#\n",
+ "n2=1900.#\n",
+ "n3=4000.#\n",
+ "n4=1100.#\n",
+ "n5=1000.#\n",
+ "n6=1200.#\n",
+ "n7=1800.#\n",
+ "n8=2100.#\n",
+ "n9=2000.#\n",
+ "n10=1580.#\n",
+ "n11=1800.#\n",
+ "n12=900.\n",
+ "TBW=30.*10.**6.#total allocated bandwidth\n",
+ "SBW=25000.#simplex channel bandwidth\n",
+ "NS=TBW/SBW#no.of simplex channels\n",
+ "DS=NS/2.#no.of duplex channels\n",
+ "NCPC=10.\n",
+ "NCPCL=12.\n",
+ "TNCC=NCPC*NCPCL##no. of control channels\n",
+ "TNTC=DS-TNCC#no. of traffic channels\n",
+ "NTCPC=TNTC/NCPCL\n",
+ "NUPC=8.\n",
+ "NMCPC=8.\n",
+ "TNCPC=NMCPC*NTCPC#total no. of calls/cell\n",
+ "print '%s %d %s' %('total no. of calls/cell =',TNCPC,'calls/cell')\n",
+ "H=5./100.*3600.\n",
+ "Y=60./3600.\n",
+ "Aav=H*Y#traffic intensity case(b)\n",
+ "print '%s %d %s' %('average offered traffic load Aav for (case(b)) is =',Aav,'Erlangs')\n",
+ "tc=n1+n2+n3+n4+n5+n6+n7+n8+n9+n10+n11+n12\n",
+ "pbms=75./100.\n",
+ "nbms=pbms*tc\n",
+ "print '%s %.3f %s' %('number of mobile subscribers/cluster = ',nbms*10**(-3),'users')\n",
+ "y=tc/NCPCL\n",
+ "Y1=y/3600.\n",
+ "H1=60.\n",
+ "Aav1=Y1*H1#traffic intensity case(c)\n",
+ "print '%s %d %s' %('average offered traffic load Aav for (case(c)) is =',round(Aav1),'Erlangs')\n",
+ "\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total no. of calls/cell = 320 calls/cell\n",
+ "average offered traffic load Aav for (case(b)) is = 3 Erlangs\n",
+ "number of mobile subscribers/cluster = 16.185 users\n",
+ "average offered traffic load Aav for (case(c)) is = 30 Erlangs\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.5 - PG NO.319"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 319\n",
+ "Y=3000./3600.\n",
+ "H=1.76*60.\n",
+ "Aav=Y*H\n",
+ "print '%s %.2f %s' %('offered traffic load Aav is =',Aav,'Erlangs')\n",
+ "Pb=2./100.\n",
+ "N=100.\n",
+ "Y1=28000./3600.\n",
+ "H1=105.6\n",
+ "Aav1=Y1*H1\n",
+ "N1=820.\n",
+ "print '%s %d %s' %('max. no of channels/cell =',N,'channels/cell')\n",
+ "print '%s %d %s' %('max. no of channels/cell wrt increased lambda =',N1,'channels/cell')\n",
+ "#answer in the textbook is less accurate due to approximations. "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "offered traffic load Aav is = 88.00 Erlangs\n",
+ "max. no of channels/cell = 100 channels/cell\n",
+ "max. no of channels/cell wrt increased lambda = 820 channels/cell\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.6 - PG NO.320"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.320\n",
+ "N=50.#no. of channels in cell\n",
+ "Pb=0.02#blocking probability\n",
+ "Aav=40.3#offered traffic load\n",
+ "H=100./3600.#average call-holding time\n",
+ "Y=Aav/H##no. of calls handled\n",
+ "print'%s %d %s' %('no. of calls handled =',Y,'calls/hr')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "no. of calls handled = 1450 calls/hr\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.7 - PG NO.320"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 320\n",
+ "At=0.1\n",
+ "Pb=0.005\n",
+ "N=10.\n",
+ "Aav=3.96\n",
+ "Nt=Aav/At\n",
+ "N1=100.\n",
+ "Aav1=80.9\n",
+ "Nt1=Aav1/At\n",
+ "print '%s %d %s' %('total no. of mobile users =',Nt,'users')\n",
+ "print '%s %d %s' %('total no. of mobile users for increased N =',Nt1,'users')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total no. of mobile users = 39 users\n",
+ "total no. of mobile users for increased N = 809 users\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.8 - PG NO.321"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.321\n",
+ "N=40.#no. of channels in cell\n",
+ "Pb=0.02#blocking probability\n",
+ "Aav=31.#offered traffic load\n",
+ "H=3./60.#holding time\n",
+ "Z=Aav/(H*3.)#users per cell\n",
+ "NC=20.#no. of cells in the system\n",
+ "nms=NC*Z\n",
+ "print'%s %d %s' %('number of mobile subscribers in the system =',nms,'users')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of mobile subscribers in the system = 4133 users\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.9 - PG NO.322"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.322\n",
+ "N1=24.#no. of trunked channels\n",
+ "N=10.#10 channels trunked together\n",
+ "Pb=0.01#blocking probability\n",
+ "Aav=4.46#offered traffic load\n",
+ "N2=5.#2 groups of 5 trunked channels each\n",
+ "Aav1=1.36\n",
+ "Aav2=2.*Aav1\n",
+ "Ex=Aav2/Aav#extent\n",
+ "if Aav>Aav2:\n",
+ " print('10 channels trunked together can support more traffic at a specific GOS(say 0.01) than two 5-channel trunk individually do')\n",
+ "else:\n",
+ " print('10 channels trunked together can support less traffic at a specific GOS(say 0.01) than two 5-channel trunk individually do')\n",
+ "#end\n",
+ "\n",
+ "print'%s %d %s' %('\\nextent of more traffic supported by N=10 system as compared to two 5-channel trunked systems=',Ex*100,'%')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 channels trunked together can support more traffic at a specific GOS(say 0.01) than two 5-channel trunk individually do\n",
+ "\n",
+ "extent of more traffic supported by N=10 system as compared to two 5-channel trunked systems= 60 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.10 - PG NO.323"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 323\n",
+ "Nch=395.\n",
+ "ncpcl=7.\n",
+ "Pb=.01\n",
+ "N=Nch/ncpcl\n",
+ "H=3./60.\n",
+ "Aav=44.2\n",
+ "Y=Aav/H\n",
+ "print '%s %d %s' %('average number of calls/hr. i.e(omnidirectional case) Y is =',Y,'calls per hour')\n",
+ "\n",
+ "nspc=3.\n",
+ "Nchps=N/nspc\n",
+ "Aav1=11.2\n",
+ "avnc=Aav1/H\n",
+ "Y1=avnc*nspc\n",
+ "print '%s %d %s' %('average number of calls/hr. ie.(3-sector case) Y is =',Y1+1,'calls per hour')\n",
+ "DTRef=(Y-Y1)/Y\n",
+ "print '%s %.2f %s %d %s' %('decrease in trunking efficiency =',DTRef,'or',(DTRef+0.01)*100,'%')\n",
+ "\n",
+ "nspc1=6.\n",
+ "Nchps1=N/nspc1\n",
+ "Aav2=4.1\n",
+ "avnc1=Aav2/H\n",
+ "Y2=avnc1*nspc1\n",
+ "print '%s %d %s' %('average number of calls/hr. ie.(6-sector case) Y is =',Y2+1,'calls per hour')\n",
+ "DTRef1=(Y-Y2)/Y\n",
+ "print '%s %.2f %s %d %s' %('decrement in trunking efficiency =',DTRef1,'or',DTRef1*100,'%')\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "average number of calls/hr. i.e(omnidirectional case) Y is = 884 calls per hour\n",
+ "average number of calls/hr. ie.(3-sector case) Y is = 672 calls per hour\n",
+ "decrease in trunking efficiency = 0.24 or 24 %\n",
+ "average number of calls/hr. ie.(6-sector case) Y is = 492 calls per hour\n",
+ "decrement in trunking efficiency = 0.44 or 44 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.11 - PG NO.325"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 325\n",
+ "Rkm=1.4#radius of the cell\n",
+ "Acell=2.6*Rkm*Rkm#area (hexagonal cell)\n",
+ "K=4.#no.of cells/cluster\n",
+ "ntotal=60.\n",
+ "ncell=ntotal/K\n",
+ "avgtlpu=0.029\n",
+ "Aav=9.\n",
+ "Pb=0.05\n",
+ "tnu=Aav/avgtlpu#total no. of users supported in a cell\n",
+ "NupA=tnu/Acell\n",
+ "print '%s %d %s' %('number of users per kmsqr area =',NupA,'users/(km^2) (approx.)')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of users per kmsqr area = 60 users/(km^2) (approx.)\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.12 - PG NO.327"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.327\n",
+ "Bt=12.5*10.**6.\n",
+ "BtMHz=12.5\n",
+ "Bc=30.*10.**3.\n",
+ "Bg=10.**3.\n",
+ "Nt=(Bt-2*Bg)/Bc#total number of channels/cluster\n",
+ "Nc=21.\n",
+ "Nd=Nt-Nc#number of user data transmission/cluster\n",
+ "K=7.#frequency reuse factor\n",
+ "Ndpcell=Nd/K\n",
+ "Acell=6\n",
+ "n1=Ndpcell/(BtMHz*Acell)\n",
+ "print '%s %d %s' %('total number of channels/cluster (Nt) =',Nt,'channels')\n",
+ "print '%s %d %s' %('number of user data transmission/cluster (Nd) =',Nd,'data channels per cluster')\n",
+ "print '%s %d %s' %('total number of transmission/cell (Nd/cell) if K= 7 is =',Ndpcell,'data channels per cell')\n",
+ "print '%s %.3f %s' %('overall spectral efficiency n1 in channels/MHz/kmsqr for cell area 6kmsqr is =',n1,'channels/MHz/Km^2')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "total number of channels/cluster (Nt) = 416 channels\n",
+ "number of user data transmission/cluster (Nd) = 395 data channels per cluster\n",
+ "total number of transmission/cell (Nd/cell) if K= 7 is = 56 data channels per cell\n",
+ "overall spectral efficiency n1 in channels/MHz/kmsqr for cell area 6kmsqr is = 0.754 channels/MHz/Km^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.13 - PG NO.327"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.327\n",
+ "Acell=6.\n",
+ "Acellular=3024.\n",
+ "Ncells=Acellular/Acell#number of cells in the system\n",
+ "Bt=12.5*10.**6.\n",
+ "BtMHz=12.5\n",
+ "Bc=30.*10.**3.\n",
+ "Bg=10.*10.**3.\n",
+ "Nc=21.\n",
+ "Nd=((Bt-2.*Bg)/Bc)-Nc#no. of data channels/cluster\n",
+ "K=7.\n",
+ "Ndpcell=Nd/K\n",
+ "H=1./20\n",
+ "ntr=0.95\n",
+ "Ncallphr=1./H\n",
+ "Ncallphrpcell=Ndpcell*ntr*Ncallphr#number of calls per hour per cell\n",
+ "Ncallpuserphr=1.5\n",
+ "Nusers=Ncallphrpcell/Ncallpuserphr\n",
+ "n1=Ndpcell/(BtMHz*Acell)\n",
+ "n=ntr*n1\n",
+ "print '%s %d %s' %('number of cells in the system =',Ncells,'cells')\n",
+ "print '%s %d %s' %('number of calls per hour per cell =',Ncallphrpcell,'calls/hour/cell')\n",
+ "print '%s %d %s' %('average number of users per hour per cell =',Nusers,'users/hour/cell')\n",
+ "print '%s %.3f %s' %('system spectral efficiency in the units of Erlangs/MHz/kmsqr =',n,'Erlangs/MHz/km^2')\n",
+ "#answers in texbook are wrong due to approximations."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of cells in the system = 504 cells\n",
+ "number of calls per hour per cell = 1072 calls/hour/cell\n",
+ "average number of users per hour per cell = 714 users/hour/cell\n",
+ "system spectral efficiency in the units of Erlangs/MHz/kmsqr = 0.715 Erlangs/MHz/km^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.14 - PG NO.330"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no.330\n",
+ "Bt=25.*10.**6.#system bandwidth\n",
+ "Bc=30.*10.**3.#channel bandwidth\n",
+ "Bg=20.*10.**3.#guard spacing\n",
+ "Nu=((Bt-2.*Bg)/Bc)\n",
+ "Tf=40.*10.**-3.#frame time\n",
+ "Tp=0.*10.**-3.#preamble time\n",
+ "Tt=0.*10.**-3.#trailer time\n",
+ "Ld=260.\n",
+ "Ls=324.\n",
+ "ntframe=((Tf-Tp-Tt)/Tf)*(Ld/Ls)\n",
+ "ntsys=ntframe*(Nu*Bc*(1./Bt))\n",
+ "Rs=7.95*10.**3.\n",
+ "ntmod=Rs/Bc\n",
+ "K=7.\n",
+ "nt=ntsys*ntmod/K\n",
+ "print '%s %d %s' %('number of simultaneous users that can be accomodated in each cell =',Nu,'users/cluster')\n",
+ "print '%s %.1f' %('spectral efficiency per frame of a TDMA system =',ntframe)\n",
+ "print '%s %.1f' %('spectral efficiency of the TDMA system =',ntsys)\n",
+ "print '%s %.3f %s' %('overall spectral efficiency in bps/Hz/cell =',nt*10,'bps/Hz/cell')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "number of simultaneous users that can be accomodated in each cell = 832 users/cluster\n",
+ "spectral efficiency per frame of a TDMA system = 0.8\n",
+ "spectral efficiency of the TDMA system = 0.8\n",
+ "overall spectral efficiency in bps/Hz/cell = 0.303 bps/Hz/cell\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.15 - PG NO.332"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 332\n",
+ "import math\n",
+ "Bc1=30.*10.**3.#\n",
+ "cimin1=18.\n",
+ "Bc2=25.*10.**3.#\n",
+ "cimin2=14.\n",
+ "Bc3=12.5*10.**3.#\n",
+ "cimin3=12.\n",
+ "Bc4=6.25*10.**3.#\n",
+ "cimin4=9.\n",
+ "Y=4.#path propogation constant\n",
+ "BcI=6.25*10.**3.\n",
+ "cieq1=cimin1+20.*math.log10(Bc1/BcI)\n",
+ "cieq2=cimin2+20.*math.log10(Bc2/BcI)\n",
+ "cieq3=cimin3+20.*math.log10(Bc3/BcI)\n",
+ "cieq4=cimin4+20.*math.log10(Bc4/BcI)\n",
+ "print'%s %.2f %s' %('(C/I)eq in dB for system I =',cieq1,'dB')\n",
+ "print'%s %d %s' %('(C/I)eq in dB for system II =',cieq2,'dB')\n",
+ "print'%s %d %s' %('(C/I)eq in dB for system III =',cieq3,'dB')\n",
+ "print'%s %d %s' %('(C/I)eq in dB for system IV =',cieq4,'dB')\n",
+ "\n",
+ "\n",
+ "if cieq1<cieq2:\n",
+ " if cieq1<cieq3:\n",
+ " if cieq1<cieq4:\n",
+ " print('System I offers the best capacity')\n",
+ " #end\n",
+ " #end\n",
+ " elif cieq2<cieq3:\n",
+ " if cieq2<cieq4:\n",
+ " if cieq2<cieq1:\n",
+ " print('System II offers the best capacity')\n",
+ " #end\n",
+ " #end \n",
+ " elif cieq3<cieq4:\n",
+ " if cieq3<cieq1:\n",
+ " if cieq3<cieq2:\n",
+ " print('System II offers the best capacity')\n",
+ " #end \n",
+ " #end \n",
+ " \n",
+ " elif cieq4<cieq3 :\n",
+ " if cieq4<cieq1:\n",
+ " if cieq4<cieq2:\n",
+ " print('System IV offers the best capacity')\n",
+ " #end\n",
+ " #end\n",
+ "\n",
+ "#end\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(C/I)eq in dB for system I = 31.62 dB\n",
+ "(C/I)eq in dB for system II = 26 dB\n",
+ "(C/I)eq in dB for system III = 18 dB\n",
+ "(C/I)eq in dB for system IV = 9 dB\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 9.16 - PG NO.333"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#page no. 333\n",
+ "Bt=12.5*10.**6.\n",
+ "Bc=200.*10.**3.\n",
+ "Ns=8.\n",
+ "N=Bt/Bc\n",
+ "Ns=8.\n",
+ "Nu=N*Ns\n",
+ "K=4.#frequency reuse factor\n",
+ "SysC=Nu/K#system capacity\n",
+ "M=(Bt/Bc)*Ns*(1./K)#system capacity using alternate method\n",
+ "print '%s %d %s' %('System capacity per cell is =',SysC,'users/cell')\n",
+ "print '%s %d %s' %('System capacity per cell,M,by using alternate method is =',M,'users/cell')\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "System capacity per cell is = 125 users/cell\n",
+ "System capacity per cell,M,by using alternate method is = 125 users/cell\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++/screenshots/IMG-20150614-WA0001.png b/_Mastering_C++/screenshots/IMG-20150614-WA0001.png
new file mode 100755
index 00000000..469c12fc
--- /dev/null
+++ b/_Mastering_C++/screenshots/IMG-20150614-WA0001.png
Binary files differ
diff --git a/_Mastering_C++/screenshots/IMG-20150614-WA0006.png b/_Mastering_C++/screenshots/IMG-20150614-WA0006.png
new file mode 100755
index 00000000..00aa17a6
--- /dev/null
+++ b/_Mastering_C++/screenshots/IMG-20150614-WA0006.png
Binary files differ
diff --git a/_Mastering_C++/screenshots/IMG-20150619-WA0002.png b/_Mastering_C++/screenshots/IMG-20150619-WA0002.png
new file mode 100755
index 00000000..fc13fe9c
--- /dev/null
+++ b/_Mastering_C++/screenshots/IMG-20150619-WA0002.png
Binary files differ
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter10-ClassesAndObjects.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter10-ClassesAndObjects.ipynb
new file mode 100755
index 00000000..a8a6de1f
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter10-ClassesAndObjects.ipynb
@@ -0,0 +1,1241 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8f7be8ab30cd8a38b71c7dbac3729da70ed4826b62dcb4d9b30b32010c83c291"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Chapter 10- Classes and objects"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- student.cpp, Page no-344"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class student: #member functions definition inside the body\n",
+ " __roll_no=int\n",
+ " __name=[None]*20\n",
+ " def setdata(self, roll_no_in, name_in):\n",
+ " self.roll_no=roll_no_in\n",
+ " self.name=name_in\n",
+ " def outdata(self):\n",
+ " print \"Roll no =\", self.roll_no\n",
+ " print \"Name =\", self.name\n",
+ "s1=student() #object of class student\n",
+ "s2=student()\n",
+ "s1.setdata(1, \"Tejaswi\") #invoking member functions\n",
+ "s2.setdata(10, \"Rajkumar\")\n",
+ "print \"Student details...\"\n",
+ "s1.outdata()\n",
+ "s2.outdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Student details...\n",
+ "Roll no = 1\n",
+ "Name = Tejaswi\n",
+ "Roll no = 10\n",
+ "Name = Rajkumar\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-rect.cpp, Page no-345"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class rect:\n",
+ " __length=int\n",
+ " __breadth=int\n",
+ " def read(self, i, j):\n",
+ " self.__length=i\n",
+ " self.__breadth=j\n",
+ " def area(self):\n",
+ " return self.__length*self.__breadth\n",
+ "r=rect()\n",
+ "x, y=[int(x) for x in raw_input(\"Enter the length and breadth of the reactangle: \").split()]\n",
+ "r.read(x,y)\n",
+ "print \"Area of the rectangle =\", r.area()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the length and breadth of the reactangle: 4 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area of the rectangle = 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-date1.cpp, Page no-348"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class date:\n",
+ " __day=int\n",
+ " __month=int\n",
+ " __year=int\n",
+ " def Set(self, DayIn, MonthIn, YearIn):\n",
+ " self.__day=DayIn\n",
+ " self.__month=MonthIn\n",
+ " self.__year=YearIn\n",
+ " def show(self):\n",
+ " print \"%s-%s-%s\" %(self.__day, self.__month, self.__year)\n",
+ "d1=date()\n",
+ "d2=date()\n",
+ "d3=date()\n",
+ "d1.Set(26, 3, 1958)\n",
+ "d2.Set(14, 4, 1971)\n",
+ "d3.Set(1, 9, 1973)\n",
+ "print \"Birth Date of First Author: \",\n",
+ "d1.show()\n",
+ "print \"Birth Date of Second Author: \",\n",
+ "d2.show()\n",
+ "print \"Birth Date of Third Author: \",\n",
+ "d3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Birth Date of First Author: 26-3-1958\n",
+ "Birth Date of Second Author: 14-4-1971\n",
+ "Birth Date of Third Author: 1-9-1973\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-date2.cpp, Page no-350"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Set(self, DayIn, MonthIn, YearIn):\n",
+ " self.__day=DayIn\n",
+ " self.__month=MonthIn\n",
+ " self.__year=YearIn\n",
+ "def show(self):\n",
+ " print \"%s-%s-%s\" %(self.__day, self.__month, self.__year)\n",
+ "class date:\n",
+ " __day=int\n",
+ " __month=int\n",
+ " __year=int\n",
+ " Set=Set #definiton of member function outside the class\n",
+ " show=show\n",
+ "d1=date()\n",
+ "d2=date()\n",
+ "d3=date()\n",
+ "d1.Set(26, 3, 1958)\n",
+ "d2.Set(14, 4, 1971)\n",
+ "d3.Set(1, 9, 1973)\n",
+ "print \"Birth Date of First Author: \",\n",
+ "d1.show()\n",
+ "print \"Birth Date of Second Author: \",\n",
+ "d2.show()\n",
+ "print \"Birth Date of Third Author: \",\n",
+ "d3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Birth Date of First Author: 26-3-1958\n",
+ "Birth Date of Second Author: 14-4-1971\n",
+ "Birth Date of Third Author: 1-9-1973\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-date3.cpp, Page no-352"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Set(self, DayIn, MonthIn, YearIn):\n",
+ " self.__day=DayIn\n",
+ " self.__month=MonthIn\n",
+ " self.__year=YearIn\n",
+ "def show(self):\n",
+ " print self.__day, \"-\", self.__month, \"-\", self.__year\n",
+ "class date:\n",
+ " __day=int\n",
+ " __month=int\n",
+ " __year=int\n",
+ " Set=Set\n",
+ " show=show\n",
+ "d1=date()\n",
+ "d2=date()\n",
+ "d3=date()\n",
+ "d1.Set(26, 3, 1958)\n",
+ "d2.Set(14, 4, 1971)\n",
+ "d3.Set(1, 9, 1973)\n",
+ "print \"Birth Date of First Author: \",\n",
+ "d1.show()\n",
+ "print \"Birth Date of Second Author: \",\n",
+ "d2.show()\n",
+ "print \"Birth Date of Third Author: \",\n",
+ "d3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Birth Date of First Author: 26 - 3 - 1958\n",
+ "Birth Date of Second Author: 14 - 4 - 1971\n",
+ "Birth Date of Third Author: 1 - 9 - 1973\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-nesting.cpp, Page no-354"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class NumberParis:\n",
+ " __num1=int\n",
+ " __num2=int\n",
+ " def read(self):\n",
+ " self.__num1=int(raw_input(\"Enter First Number: \"))\n",
+ " self.__num2=int(raw_input(\"Enter Second Number: \"))\n",
+ " def Max(self):\n",
+ " if self.__num1>self.__num2:\n",
+ " return self.__num1\n",
+ " else:\n",
+ " return self.__num2\n",
+ " def ShowMax(self):\n",
+ " print \"Maximum =\", self.Max() #invoking a member function in another member function\n",
+ "n1=NumberParis()\n",
+ "n1.read()\n",
+ "n1.ShowMax()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter First Number: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Second Number: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum = 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-part.cpp, Page no-355"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class part:\n",
+ " __ModelNum=int #private members\n",
+ " __PartNum=int\n",
+ " __cost=float\n",
+ " def SetPart(self, mn, pn, c):\n",
+ " self.__ModelNum=mn\n",
+ " self.__PartNum=pn\n",
+ " self.__cost=c\n",
+ " def ShowPart(self):\n",
+ " print \"Model:\", self.__ModelNum\n",
+ " print \"Part:\", self.__PartNum\n",
+ " print \"Cost:\", self.__cost\n",
+ "p1=part()\n",
+ "p2=part()\n",
+ "p1.SetPart(1996, 23, 1250.55)\n",
+ "p2.SetPart(2000, 243, 2354.75)\n",
+ "print \"First Part Details...\"\n",
+ "p1.ShowPart()\n",
+ "print \"Second Part Details...\"\n",
+ "p2.ShowPart()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First Part Details...\n",
+ "Model: 1996\n",
+ "Part: 23\n",
+ "Cost: 1250.55\n",
+ "Second Part Details...\n",
+ "Model: 2000\n",
+ "Part: 243\n",
+ "Cost: 2354.75\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vector.cpp, Page no-361"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def read(self):\n",
+ " for i in range(self._vector__sz):\n",
+ " print \"Enter vector [\", i, \"]? \",\n",
+ " self._vector__v[i]=int(raw_input())\n",
+ "def show_sum(self):\n",
+ " Sum=0\n",
+ " for i in range(self._vector__sz):\n",
+ " Sum+=self._vector__v[i]\n",
+ " print \"Vector sum =\", Sum\n",
+ "class vector:\n",
+ " __v=[int] #array of type integer\n",
+ " __sz=int\n",
+ " def VectorSize(self, size):\n",
+ " self.__sz= size\n",
+ " self.__v=[int]*size #dynamically allocating size to integer array\n",
+ " def release(self):\n",
+ " del self.__v\n",
+ " read=read\n",
+ " show_sum=show_sum\n",
+ "v1=vector()\n",
+ "count=int(raw_input(\"How many elements are there in the vector: \"))\n",
+ "v1.VectorSize(count)\n",
+ "v1.read()\n",
+ "v1.show_sum()\n",
+ "v1.release()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many elements are there in the vector: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter vector [ 0 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 1 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 2 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 3 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 4 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Vector sum = 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-distance.cpp, Page no-363"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class distance:\n",
+ " __feet=float\n",
+ " __inches=float\n",
+ " def init(self, ft, In):\n",
+ " self.__feet=ft\n",
+ " self.__inches=In\n",
+ " def read(self):\n",
+ " self.__feet=float(raw_input(\"Enter feet: \"))\n",
+ " self.__inches=float(raw_input(\"Enter inches: \"))\n",
+ " def show(self):\n",
+ " print self.__feet, \"\\'-\", self.__inches, \"\\\"\"\n",
+ " def add(self, d1, d2):\n",
+ " self.__feet=d1.__feet+d2.__feet\n",
+ " self.__inches=d1.__inches+d2.__inches\n",
+ " if self.__inches>=12:\n",
+ " self.__feet=self.__feet+1\n",
+ " self.__inches=self.__inches-12\n",
+ "d1=distance()\n",
+ "d2=distance()\n",
+ "d3=distance()\n",
+ "d2.init(11, 6.25)\n",
+ "d1.read()\n",
+ "print \"d1=\",\n",
+ "d1.show()\n",
+ "print \"d2=\",\n",
+ "d2.show()\n",
+ "d3.add(d1,d2)\n",
+ "print \"d3 = d1+d2 =\",\n",
+ "d3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter feet: 12.0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter inches: 7.25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "d1= 12.0 '- 7.25 \"\n",
+ "d2= 11 '- 6.25 \"\n",
+ "d3 = d1+d2 = 24.0 '- 1.5 \"\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-account.cpp, Page no-365"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def MoneyTransfer(self, acc , amount): # passing objects as parameters\n",
+ " self._AccClass__balance=self._AccClass__balance-amount\n",
+ " acc._AccClass__balance=acc._AccClass__balance + amount\n",
+ "class AccClass:\n",
+ " __accno=int\n",
+ " __balance=float\n",
+ " def setdata(self, an, bal=0.0):\n",
+ " self.accno=an\n",
+ " self.__balance=bal\n",
+ " def getdata(self):\n",
+ " self.accno=raw_input(\"Enter account number for acc1 object: \")\n",
+ " self.__balance=float(raw_input(\"Enter the balance: \"))\n",
+ " def display(self):\n",
+ " print \"Acoount number is: \", self.accno\n",
+ " print \"Balance is: \", self.__balance\n",
+ " MoneyTransfer=MoneyTransfer\n",
+ "acc1=AccClass()\n",
+ "acc2=AccClass()\n",
+ "acc3=AccClass()\n",
+ "acc1.getdata()\n",
+ "acc2.setdata(10)\n",
+ "acc3.setdata(20, 750.5)\n",
+ "print \"Acoount information...\"\n",
+ "acc1.display()\n",
+ "acc2.display()\n",
+ "acc3.display()\n",
+ "trans_money=float(raw_input(\"How much money is to be transferred from acc3 to acc1: \"))\n",
+ "acc3.MoneyTransfer(acc1, trans_money)\n",
+ "print \"Updated information about accounts...\"\n",
+ "acc1.display()\n",
+ "acc2.display()\n",
+ "acc3.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter account number for acc1 object: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the balance: 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Acoount information...\n",
+ "Acoount number is: 1\n",
+ "Balance is: 100.0\n",
+ "Acoount number is: 10\n",
+ "Balance is: 0.0\n",
+ "Acoount number is: 20\n",
+ "Balance is: 750.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How much money is to be transferred from acc3 to acc1: 200\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Updated information about accounts...\n",
+ "Acoount number is: 1\n",
+ "Balance is: 300.0\n",
+ "Acoount number is: 10\n",
+ "Balance is: 0.0\n",
+ "Acoount number is: 20\n",
+ "Balance is: 550.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex.cpp, Page no-367"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "def add (self, c2): #objects as parameters \n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real+c2._Complex__real\n",
+ " temp._Complex__imag=self._Complex__imag+c2._Complex__imag\n",
+ " return temp\n",
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def getdata(self):\n",
+ " self.__real=float(raw_input(\"Real Part ? \"))\n",
+ " self.__imag=float(raw_input(\"Imag Part ? \"))\n",
+ " def outdata(self, msg):\n",
+ " print msg, \n",
+ " print self.__real,\n",
+ " if self.__imag<0:\n",
+ " print \"-i\",\n",
+ " else:\n",
+ " print \"+i\",\n",
+ " print math.fabs(self.__imag) #print absolute value\n",
+ " add=add\n",
+ "c1=Complex()\n",
+ "c2=Complex()\n",
+ "c3=Complex()\n",
+ "print \"Enter Complex number c1...\"\n",
+ "c1.getdata()\n",
+ "print \"Enter Complex number c2...\"\n",
+ "c2.getdata()\n",
+ "c3=c1.add(c2)\n",
+ "c3.outdata(\"c3=c1.add(c2):\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex number c1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real Part ? 1.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag Part ? 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex number c2...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real Part ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag Part ? -4.3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c3=c1.add(c2): 4.5 -i 2.3\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-friend1.cpp, Page no-371"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class one:\n",
+ " __data1=int\n",
+ " def setdata(self, init):\n",
+ " self.__data1=init\n",
+ "class two:\n",
+ " __data2=int\n",
+ " def setdata(self, init):\n",
+ " self.__data2=init\n",
+ "def add_both(a, b): #friend function\n",
+ " return a._one__data1+b._two__data2\n",
+ "a=one()\n",
+ "b=two()\n",
+ "a.setdata(5)\n",
+ "b.setdata(10)\n",
+ "print \"Sum of one and two:\", add_both(a,b)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sum of one and two: 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-friend2.cpp, Page no-373"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class boy:\n",
+ " __income1=int\n",
+ " __income2=int\n",
+ " def setdata(self, in1, in2):\n",
+ " self.__income1=in1\n",
+ " self.__income2=in2\n",
+ "class girl:\n",
+ " __income=int\n",
+ " def girlfunc(self, b1):\n",
+ " return b1._boy__income1+b1._boy__income2\n",
+ " def setdata(self, In):\n",
+ " self.__income=In\n",
+ " def show(self):\n",
+ " b1=boy()\n",
+ " b1.setdata(100, 200)\n",
+ " print \"boy's Income1 in show():\", b1._boy__income1\n",
+ " print \"girl's income in show():\", self.__income\n",
+ "b1=boy()\n",
+ "g1=girl()\n",
+ "b1.setdata(500, 1000)\n",
+ "g1.setdata(300)\n",
+ "print \"boy b1 total income:\", g1.girlfunc(b1)\n",
+ "g1.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "boy b1 total income: 1500\n",
+ "boy's Income1 in show(): 100\n",
+ "girl's income in show(): 300\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-friend3.cpp, Page no-375"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def girlfunc(self, b1):\n",
+ " return b1._boy__income1+b1._boy__income2\n",
+ "class girl:\n",
+ " __income=int\n",
+ " __girlfunc=girlfunc\n",
+ " def setdata(self, In):\n",
+ " self.__income=In\n",
+ " def show(self):\n",
+ " print \"girl income:\", self.__income\n",
+ "class boy:\n",
+ " __income1=int\n",
+ " __income2=int\n",
+ " def setdata(self, in1, in2):\n",
+ " self.__income1=in1\n",
+ " self.__income2=in2\n",
+ "b1=boy()\n",
+ "g1=girl()\n",
+ "b1.setdata(500, 1000)\n",
+ "g1.setdata(300)\n",
+ "print \"boy b1 total income:\", g1._girl__girlfunc(b1)\n",
+ "g1.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "boy b1 total income: 1500\n",
+ "girl income: 300\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-constmem.cpp, Page 377"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self):\n",
+ " self._Person__name=self._Person__address=self._Person__phone=0\n",
+ "def clear(self):\n",
+ " del self._Person__name\n",
+ " del self._Person__address\n",
+ " del self._Person__phone\n",
+ "def setname(self, Str):\n",
+ " if self._Person__name:\n",
+ " del self._Person__name\n",
+ " self._Person__name=Str\n",
+ "def setaddress(self, Str):\n",
+ " if self._Person__address:\n",
+ " del self._Person__address\n",
+ " self._Person__address=Str\n",
+ "def setphone(self, Str):\n",
+ " if self._Person__phone:\n",
+ " del self._Person__phone\n",
+ " self._Person__phone=Str\n",
+ "def getname(self):\n",
+ " return self._Person__name\n",
+ "def getaddress(self):\n",
+ " return self._Person__address\n",
+ "def getphone(self):\n",
+ " return self._Person__phone\n",
+ "def printperson(p):\n",
+ " if p.getname():\n",
+ " print \"Name :\", p.getname()\n",
+ " if p.getaddress():\n",
+ " print \"Address :\", p.getaddress()\n",
+ " if p.getphone():\n",
+ " print \"Phone :\", p.getphone()\n",
+ "class Person:\n",
+ " __name=str\n",
+ " __address=str\n",
+ " __phone=str\n",
+ " __init__=__init__\n",
+ " clear=clear\n",
+ " setname=setname\n",
+ " setaddress=setaddress\n",
+ " setphone=setphone\n",
+ " getname=getname\n",
+ " getaddress=getaddress\n",
+ " getphone=getphone\n",
+ "p1=Person()\n",
+ "p2=Person()\n",
+ "p1.setname(\"Rajkumar\")\n",
+ "p1.setaddress(\"Email: rajacdacb.ernet.in\")\n",
+ "p1.setphone(\"90-080-5584271\")\n",
+ "printperson(p1)\n",
+ "p2.setname(\"Venugopal K R\")\n",
+ "p2.setaddress(\"Bangalore University\")\n",
+ "p2.setphone(\"-not sure-\")\n",
+ "printperson(p2)\n",
+ "p1.clear()\n",
+ "p2.clear()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name : Rajkumar\n",
+ "Address : Email: rajacdacb.ernet.in\n",
+ "Phone : 90-080-5584271\n",
+ "Name : Venugopal K R\n",
+ "Address : Bangalore University\n",
+ "Phone : -not sure-\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-count.cpp, Page no-382"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class MyClass():\n",
+ " __count=[int]#static member\n",
+ " __number=int\n",
+ " def set(self, num):\n",
+ " self.__number=num\n",
+ " self.__count[0]+=1\n",
+ " def show(self):\n",
+ " print \"Number of calls made to 'set()' through any object:\", self.__count[0]\n",
+ "obj1=MyClass()\n",
+ "obj1._MyClass__count[0]=0\n",
+ "obj1.show()\n",
+ "obj1.set(100)\n",
+ "obj1.show()\n",
+ "obj2=MyClass()\n",
+ "obj3=MyClass()\n",
+ "obj2.set(200)\n",
+ "obj2.show()\n",
+ "obj2.set(250)\n",
+ "obj3.set(300)\n",
+ "obj1.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of calls made to 'set()' through any object: 0\n",
+ "Number of calls made to 'set()' through any object: 1\n",
+ "Number of calls made to 'set()' through any object: 2\n",
+ "Number of calls made to 'set()' through any object: 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-dirs.cpp, Page no-384"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Directory:\n",
+ " __path=[str] #static member\n",
+ " def setpath(self, newpath):\n",
+ " self.__path[0]=newpath\n",
+ "Directory()._Directory__path[0]=\"/usr/raj\"\n",
+ "print \"Path:\", Directory()._Directory__path[0]\n",
+ "Directory().setpath(\"/usr\")\n",
+ "print \"Path:\", Directory()._Directory__path[0]\n",
+ "dir=Directory()\n",
+ "dir.setpath(\"/etc\")\n",
+ "print \"Path:\", dir._Directory__path[0]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Path: /usr/raj\n",
+ "Path: /usr\n",
+ "Path: /etc\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example Page no-389"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class employee:\n",
+ " __emp_no=int\n",
+ " __emp_name=[None]*25\n",
+ " def accept(self, i, j):\n",
+ " self.__emp_no=i\n",
+ " self.__emp_name=j\n",
+ " def display(self):\n",
+ " print \"Employee Number:\", self.__emp_no,\"\\tEmployee Name:\",self.__emp_name\n",
+ "e=[]*5\n",
+ "for i in range(5):\n",
+ " e.append(employee())\n",
+ "print \"Enter the details for five employees: \"\n",
+ "for i in range(5):\n",
+ " no=int(raw_input(\"Number: \"))\n",
+ " name=raw_input(\"Name: \")\n",
+ " e[i].accept(no, name)\n",
+ "print \"*****Employee Details*****\"\n",
+ "for i in range(5):\n",
+ " e[i].display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the details for five employees: \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Vishwanathan\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Archana\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Prasad\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Sarthak\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Ganeshan\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "*****Employee Details*****\n",
+ "Employee Number: 1 \tEmployee Name: Vishwanathan\n",
+ "Employee Number: 2 \tEmployee Name: Archana\n",
+ "Employee Number: 3 \tEmployee Name: Prasad\n",
+ "Employee Number: 4 \tEmployee Name: Sarthak\n",
+ "Employee Number: 5 \tEmployee Name: Ganeshan\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter11-ObjectInitializationAndClean-Up.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter11-ObjectInitializationAndClean-Up.ipynb
new file mode 100755
index 00000000..e75a9045
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter11-ObjectInitializationAndClean-Up.ipynb
@@ -0,0 +1,1781 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1e5e3f82f73a47a49eb33b525df841c886d804170ed7ff4f07a60c1f0014985c"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Object Initialization and clean up"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- bag.cpp, Page-392"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_ITEMS=25\n",
+ "def show(self):\n",
+ " for i in range(self.ItemCount):\n",
+ " print self._Bag__contents[i],\n",
+ "class Bag:\n",
+ " __contents=[int]*MAX_ITEMS\n",
+ " __ItemCount=int\n",
+ " def SetEmpty(self):\n",
+ " self.ItemCount=0\n",
+ " def put(self,item):\n",
+ " self._Bag__contents[self.ItemCount]=item\n",
+ " self.ItemCount+=1\n",
+ " show=show\n",
+ "bag=Bag() #object of class Bag\n",
+ "bag.SetEmpty() #initialize the object\n",
+ "while 1:\n",
+ " item=int(raw_input(\"\\nEnter Item Number to be put into the bag <0-no item>: \"))\n",
+ " if item==0:\n",
+ " break\n",
+ " bag.put(item)\n",
+ " print \"Items in bag:\",\n",
+ " bag.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Items in bag: 1"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3 2"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3 2 4"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- newbag.cpp, Page-395"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_ITEMS=25 #size of array contents\n",
+ "def show(self):\n",
+ " for i in range(self.ItemCount):\n",
+ " print self._Bag__contents[i],\n",
+ "class Bag:\n",
+ " __contents=[int]*MAX_ITEMS #int 1D array\n",
+ " __ItemCount=int\n",
+ " def __init__(self): #Constructor\n",
+ " self.ItemCount=0\n",
+ " def put(self,item): #member function defined inside the class\n",
+ " self._Bag__contents[self.ItemCount]=item\n",
+ " self.ItemCount+=1\n",
+ " show=show #member function defined outside the class\n",
+ "bag=Bag() #object of class Bag\n",
+ "while 1:\n",
+ " item=int(raw_input(\"\\nEnter Item Number to be put into the bag <0-no item>: \"))\n",
+ " if item==0:\n",
+ " break\n",
+ " bag.put(item)\n",
+ " print \"Items in bag:\",\n",
+ " bag.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Items in bag: 1"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3 2"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag: 1 3 2 4"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-test1.cpp, Page-396"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self):\n",
+ " print \"Constructor of class test called\"\n",
+ "class Test:\n",
+ " __init__=__init__ #Constructor\n",
+ "G=Test()\n",
+ "def func():\n",
+ " L=Test()\n",
+ " print \"Here's function func()\"\n",
+ "X=Test()\n",
+ "print \"main() function\"\n",
+ "func()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class test called\n",
+ "Constructor of class test called\n",
+ "main() function\n",
+ "Constructor of class test called\n",
+ "Here's function func()\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- giftbag.cpp, Page- 398"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_ITEMS=25\n",
+ "def show(self):\n",
+ " if self.ItemCount:\n",
+ " for i in range(self.ItemCount):\n",
+ " print self._Bag__contents[i],\n",
+ " else:\n",
+ " print \"Nil\"\n",
+ "class Bag:\n",
+ " __contents=[int]*MAX_ITEMS\n",
+ " __ItemCount=int\n",
+ " def __init__(self, item=None): #parameterized constructor: Python does not support overloading of functions\n",
+ " if isinstance(item, int):\n",
+ " self._Bag__contents[0]=item\n",
+ " self.ItemCount=1\n",
+ " else:\n",
+ " self.ItemCount=0\n",
+ " def put(self,item):\n",
+ " self._Bag__contents[self.ItemCount]=item\n",
+ " self.ItemCount+=1\n",
+ " show=show\n",
+ "bag1=Bag()\n",
+ "bag2=Bag(4) #object created using the parameterized constructor\n",
+ "print \"Gifted bag1 initially has:\",\n",
+ "bag1.show()\n",
+ "print \"Gifted bag2 initially has:\",\n",
+ "bag2.show()\n",
+ "while 1:\n",
+ " item=int(raw_input(\"\\nEnter Item Number to be put into the bag <0-no item>: \"))\n",
+ " if item==0:\n",
+ " break\n",
+ " bag2.put(item)\n",
+ " print \"Items in bag2:\",\n",
+ " bag2.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gifted bag1 initially has: Nil\n",
+ "Gifted bag2 initially has: 4"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag2: 4 1"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag2: 4 1 2"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Items in bag2: 4 1 2 3"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter Item Number to be put into the bag <0-no item>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-test.cpp, Page-400 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self):\n",
+ " print \"Constructor of class Test called\"\n",
+ "def __del__(self):\n",
+ " print \"Destructor of class Test called\"\n",
+ "class Test:\n",
+ " __init__=__init__ #Constructor\n",
+ " __del__=__del__ #Destructor\n",
+ "x=Test()\n",
+ "print \"Terminating main\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor of class Test called\n",
+ "Destructor of class Test called\n",
+ "Terminating main\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-count.cpp, Page-401"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "nobjects=0\n",
+ "nobj_alive=0\n",
+ "class MyClass:\n",
+ " def __init__(self):\n",
+ " global nobjects #using the global nobjects\n",
+ " global nobj_alive #using the global nobj_alive\n",
+ " nobjects+=1\n",
+ " nobj_alive+=1\n",
+ " def __del__(self):\n",
+ " global nobj_alive #using the global nobjects\n",
+ " nobj_alive-=1\n",
+ " def show(self):\n",
+ " global nobjects\n",
+ " global nobj_alive\n",
+ " print \"Total number of objects created: \", nobjects\n",
+ " print \"Number of objects currently alive: \", nobj_alive\n",
+ "obj1=MyClass()\n",
+ "obj1.show()\n",
+ "def func():\n",
+ " obj1=MyClass()\n",
+ " obj2=MyClass()\n",
+ " obj2.show()\n",
+ " del obj1\n",
+ " del obj2\n",
+ "func()\n",
+ "obj1.show()\n",
+ "obj2=MyClass()\n",
+ "obj3=MyClass()\n",
+ "obj2.show()\n",
+ "del obj1\n",
+ "del obj2\n",
+ "del obj3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total number of objects created: 1\n",
+ "Number of objects currently alive: 1\n",
+ "Total number of objects created: 3\n",
+ "Number of objects currently alive: 3\n",
+ "Total number of objects created: 3\n",
+ "Number of objects currently alive: 1\n",
+ "Total number of objects created: 5\n",
+ "Number of objects currently alive: 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example-account.cpp, Page- 403"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def MoneyTransfer(self, acc , amount):\n",
+ " self._AccClass__balance=self._AccClass__balance-amount\n",
+ " acc._AccClass__balance=acc._AccClass__balance + amount\n",
+ "class AccClass:\n",
+ " __accno=int\n",
+ " __balance=float\n",
+ " def __init__(self, an=None, bal=0.0):\n",
+ " if isinstance(an, int):\n",
+ " self.accno=an\n",
+ " self.__balance=bal\n",
+ " else:\n",
+ " self.accno=raw_input(\"Enter account number for acc1 object: \")\n",
+ " self.__balance=float(raw_input(\"Enter the balance: \"))\n",
+ " def display(self):\n",
+ " print \"Acoount number is: \", self.accno\n",
+ " print \"Balance is: \", self.__balance\n",
+ " MoneyTransfer=MoneyTransfer\n",
+ "acc1=AccClass()\n",
+ "acc2=AccClass(10)\n",
+ "acc3=AccClass(20, 750.5)\n",
+ "print \"Acoount information...\"\n",
+ "acc1.display()\n",
+ "acc2.display()\n",
+ "acc3.display()\n",
+ "trans_money=float(raw_input(\"How much money is to be transferred from acc3 to acc1: \"))\n",
+ "acc3.MoneyTransfer(acc1, trans_money)\n",
+ "print \"Updated information about accounts...\"\n",
+ "acc1.display()\n",
+ "acc2.display()\n",
+ "acc3.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter account number for acc1 object: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the balance: 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Acoount information...\n",
+ "Acoount number is: 1\n",
+ "Balance is: 100.0\n",
+ "Acoount number is: 10\n",
+ "Balance is: 0.0\n",
+ "Acoount number is: 20\n",
+ "Balance is: 750.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How much money is to be transferred from acc3 to acc1: 200\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Updated information about accounts...\n",
+ "Acoount number is: 1\n",
+ "Balance is: 300.0\n",
+ "Acoount number is: 10\n",
+ "Balance is: 0.0\n",
+ "Acoount number is: 20\n",
+ "Balance is: 550.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-test2.cpp. Page- 405"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self, NameIn=None):\n",
+ " if isinstance(NameIn, str):\n",
+ " self.name=NameIn\n",
+ " print \"Test Object \", NameIn, \" created\"\n",
+ " else:\n",
+ " self.name=\"unnamed\"\n",
+ " print \"Test object 'unnamed' created\"\n",
+ "def __del__(self):\n",
+ " print \"Test Object \", self.name, \" destroyed\"\n",
+ " del self.name\n",
+ "class Test:\n",
+ " __name=[str]\n",
+ " __init__=__init__\n",
+ " __del__=__del__\n",
+ "g=Test(\"global\")\n",
+ "def func():\n",
+ " l=Test(\"func\")\n",
+ " print \"here's function func()\"\n",
+ "x=Test(\"main\")\n",
+ "func()\n",
+ "print \"main() function - termination\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Test Object global created\n",
+ "Test Object global destroyed\n",
+ "Test Object main created\n",
+ "Test Object main destroyed\n",
+ "Test Object func created\n",
+ "here's function func()\n",
+ "Test Object func destroyed\n",
+ "main() function - termination\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex1.cpp, Page- 407"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "def add (self, c2):\n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real+c2._Complex__real\n",
+ " temp._Complex__imag=self._Complex__imag+c2._Complex__imag\n",
+ " return temp\n",
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def __init__(self, real_in=None, imag_in=0.0):\n",
+ " if isinstance(real_in, float):\n",
+ " self.__real=real_in\n",
+ " self.__imag=imag_in\n",
+ " else:\n",
+ " self.__real=self.__imag=0.0\n",
+ " def show(self, msg):\n",
+ " print msg, \n",
+ " print self.__real,\n",
+ " if self.__imag<0:\n",
+ " print \"-i\",\n",
+ " else:\n",
+ " print \"+i\",\n",
+ " print math.fabs(self.__imag) #print absolute value\n",
+ " add=add\n",
+ "c1=Complex(1.5,2.0)\n",
+ "c2=Complex(2.2)\n",
+ "c3=Complex()\n",
+ "c1.show(\"c1=\")\n",
+ "c2.show(\"c2=\")\n",
+ "c3=c1.add(c2)\n",
+ "c3.show(\"c3=c1.add(c2):\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1= 1.5 +i 2.0\n",
+ "c2= 2.2 +i 0.0\n",
+ "c3=c1.add(c2): 3.7 +i 2.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- noname.cpp, Page- 410"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class nameless:\n",
+ " __a=int\n",
+ " def __init__(self):\n",
+ " print \"Constructor\"\n",
+ " def __del__(self):\n",
+ " print \"Destructor\"\n",
+ "nameless() #nameless object created\n",
+ "n1=nameless()\n",
+ "n2=nameless()\n",
+ "print \"Program terminates\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor\n",
+ "Destructor\n",
+ "Constructor\n",
+ "Destructor\n",
+ "Constructor\n",
+ "Destructor\n",
+ "Program terminates\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-name.cpp, Page-411"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def show(self, msg):\n",
+ " print msg\n",
+ " print \"First Name: \", self._name__first\n",
+ " if self._name__middle[0]:\n",
+ " print \"Middle Name: \", self._name__middle\n",
+ " if self._name__last[0]:\n",
+ " print \"Last Name: \", self._name__last\n",
+ "class name:\n",
+ " __first=[None]*15\n",
+ " __middle=[None]*15\n",
+ " __last=[None]*15\n",
+ " def __init__(self, FirstName=None, MiddleName=None, LastName=None):\n",
+ " if isinstance(LastName, str):\n",
+ " self.__last=LastName\n",
+ " self.__middle=MiddleName\n",
+ " self.__first=FirstName\n",
+ " elif isinstance(MiddleName, str):\n",
+ " self.__middle=MiddleName\n",
+ " self.__first=FirstName\n",
+ " elif isinstance(FirstName, str):\n",
+ " self.__first=FirstName\n",
+ " else:\n",
+ " self.__last='\\0' #initialized to NULL\n",
+ " self.__middle='\\0'\n",
+ " self.__first='\\0'\n",
+ " show=show\n",
+ "n1=name()\n",
+ "n2=name()\n",
+ "n3=name()\n",
+ "n1=name(\"Rajkumar\")\n",
+ "n2=name(\"Savithri\", \"S\")\n",
+ "n3=name(\"Veugopal\", \"K\", \"R\")\n",
+ "n1.show(\"First prson details...\")\n",
+ "n2.show(\"Second prson details...\")\n",
+ "n3.show(\"Third prson details...\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First prson details...\n",
+ "First Name: Rajkumar\n",
+ "Second prson details...\n",
+ "First Name: Savithri\n",
+ "Middle Name: S\n",
+ "Third prson details...\n",
+ "First Name: Veugopal\n",
+ "Middle Name: K\n",
+ "Last Name: R\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vector1.cpp, Page-413"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def read(self):\n",
+ " for i in range(self._vector__sz):\n",
+ " print \"Enter vector [\", i, \"]? \",\n",
+ " self._vector__v[i]=int(raw_input())\n",
+ "def show_sum(self):\n",
+ " Sum=0\n",
+ " for i in range(self._vector__sz):\n",
+ " Sum+=self._vector__v[i]\n",
+ " print \"Vector sum= \", Sum\n",
+ "class vector:\n",
+ " __v=[int] #array of type integer\n",
+ " __sz=int\n",
+ " def __init__(self, size):\n",
+ " self.__sz= size\n",
+ " self.__v=[int]*size #dynamically allocating size to integer array\n",
+ " def __del__(self):\n",
+ " del self.__v\n",
+ " read=read\n",
+ " show_sum=show_sum\n",
+ "count = int\n",
+ "count=int(raw_input(\"How many elements are there in the vector: \"))\n",
+ "v1= vector(count)\n",
+ "v1.read()\n",
+ "v1.show_sum()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many elements are there in the vector: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter vector [ 0 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 1 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 2 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 3 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter vector [ 4 ]? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Vector sum= 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vector2.cpp, Page-415"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def show(self):\n",
+ " for i in range(self._vector__size):\n",
+ " print self.elem(i), \", \",\n",
+ "class vector:\n",
+ " __v=[int]\n",
+ " __size=int\n",
+ " def __init__(self, vector_size):\n",
+ " if isinstance(vector_size, int):\n",
+ " self.__size= vector_size\n",
+ " self.__v=[int]*vector_size\n",
+ " else:\n",
+ " print \"Copy construcor invoked\"\n",
+ " self.__size=vector_size.__size\n",
+ " self.__v=[int]*vector_size.__size\n",
+ " for i in range(vector_size.__size):\n",
+ " self.__v[i]=vector_size.__v[i]\n",
+ " def elem(self,i):\n",
+ " if i>=self.__size:\n",
+ " print \"Error: Out of Range\"\n",
+ " return -1\n",
+ " return self.__v[i]\n",
+ " def __del__(self):\n",
+ " del self.__v\n",
+ " show=show\n",
+ "v1=vector(5)\n",
+ "v2=vector(5)\n",
+ "for i in range(5):\n",
+ " if v2.elem(i)!=-1:\n",
+ " v2._vector__v[i]=i+1\n",
+ "v1=v2\n",
+ "v3=vector(v2)\n",
+ "print \"Vector v1: \",\n",
+ "v1.show()\n",
+ "print \"\\nvector v2: \",\n",
+ "v2.show()\n",
+ "print \"\\nvector v3: \",\n",
+ "v3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Copy construcor invoked\n",
+ "Vector v1: 1 , 2 , 3 , 4 , 5 , \n",
+ "vector v2: 1 , 2 , 3 , 4 , 5 , \n",
+ "vector v3: 1 , 2 , 3 , 4 , 5 , \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-matrix.cpp, Page-418"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "TRUE=1\n",
+ "FALSE=0\n",
+ "def __del__(self):\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " del self._matrix__p[i]\n",
+ " del self._matrix__p\n",
+ "def add(self, a, b):\n",
+ " self._matrix__MaxRow=a._matrix__MaxRow\n",
+ " self._matrix__MaxCol=a._matrix__MaxCol\n",
+ " if (a._matrix__MaxRow!=b._matrix__MaxRow)|(a._matrix__MaxCol!=b._matrix__MaxCol):\n",
+ " print \"Error: invalid matrix order for addition\"\n",
+ " return\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " self._matrix__p[i][j]=a._matrix__p[i][j]+b._matrix__p[i][j]\n",
+ "def sub(self, a, b):\n",
+ " self._matrix__MaxRow=a._matrix__MaxRow\n",
+ " self._matrix__MaxCol=a._matrix__MaxCol\n",
+ " if (a._matrix__MaxRow!=b._matrix__MaxRow)|(a._matrix__MaxCol!=b._matrix__MaxCol):\n",
+ " print \"Error: invalid matrix order for subtraction\"\n",
+ " return\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " self._matrix__p[i][j]=a._matrix__p[i][j]-b._matrix__p[i][j]\n",
+ "def mul(self, a, b):\n",
+ " self._matrix__MaxRow=a._matrix__MaxRow\n",
+ " self._matrix__MaxCol=a._matrix__MaxCol\n",
+ " if (a._matrix__MaxCol!=b._matrix__MaxRow):\n",
+ " print \"Error: invalid matrix order for multiplication\"\n",
+ " return\n",
+ " for i in range(a._matrix__MaxRow):\n",
+ " for j in range(b._matrix__MaxCol):\n",
+ " self._matrix__p[i][j]=0\n",
+ " for k in range(a._matrix__MaxCol):\n",
+ " self._matrix__p[i][j]+=a._matrix__p[i][j]*b._matrix__p[i][j]\n",
+ "def eql(self, b):\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " if self._matrix__p[i][i]!=b._matrix__p[i][j]:\n",
+ " return 0\n",
+ " return 1\n",
+ "def read(self):\n",
+ " self._matrix__p = []\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " self._matrix__p.append([])\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " print \"Matrix[%d,%d] =? \" %(i, j),\n",
+ " self._matrix__p[i].append(int(raw_input()))\n",
+ "def show(self):\n",
+ " for i in range(self._matrix__MaxRow):\n",
+ " for j in range(self._matrix__MaxCol):\n",
+ " print self._matrix__p[i][j], \" \",\n",
+ " print \"\"\n",
+ "class matrix:\n",
+ " __MaxRow=int\n",
+ " __MaxCol=int\n",
+ " __p=[int]\n",
+ " def __init__(self, row=0, col=0):\n",
+ " self.__MaxRow=row\n",
+ " self.__MaxCol=col\n",
+ " if row>0:\n",
+ " self.__p=[[int]*self.__MaxCol]*self.__MaxRow\n",
+ " __del__=__del__\n",
+ " read=read\n",
+ " show=show\n",
+ " add=add\n",
+ " sub=sub\n",
+ " mul=mul\n",
+ " eql=eql\n",
+ "print \"Enter Matrix A details...\"\n",
+ "m=int(raw_input(\"How many rows? \"))\n",
+ "n=int(raw_input(\"How many columns? \"))\n",
+ "a=matrix(m,n)\n",
+ "a.read()\n",
+ "print \"Enter Matrix B details...\"\n",
+ "p=int(raw_input(\"How many rows? \"))\n",
+ "q=int(raw_input(\"How many columns? \"))\n",
+ "b=matrix(p,q)\n",
+ "b.read()\n",
+ "print \"Matrix A is...\"\n",
+ "a.show()\n",
+ "print \"Matrix B is...\"\n",
+ "b.show()\n",
+ "c=matrix(m,n)\n",
+ "c.add(a,b)\n",
+ "print \"C=A+B...\"\n",
+ "c.show()\n",
+ "d=matrix(m,n)\n",
+ "d.sub(a,b)\n",
+ "print \"D=A-B...\"\n",
+ "d.show()\n",
+ "e=matrix(m,q)\n",
+ "e.mul(a,b)\n",
+ "print \"E=A*B...\"\n",
+ "e.show()\n",
+ "print \"(Is matrix A equal to matrix B)? \",\n",
+ "if(a.eql(b)):\n",
+ " print \"Yes\"\n",
+ "else:\n",
+ " print \"No\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Matrix A details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many rows? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many columns? 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrix[0,0] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[0,1] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[0,2] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[1,0] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[1,1] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[1,2] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[2,0] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[2,1] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[2,2] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Matrix B details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many rows? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many columns? 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrix[0,0] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[0,1] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[0,2] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[1,0] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[1,1] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[1,2] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[2,0] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[2,1] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[2,2] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix A is...\n",
+ "2 2 2 \n",
+ "2 2 2 \n",
+ "2 2 2 \n",
+ "Matrix B is...\n",
+ "1 1 1 \n",
+ "1 1 1 \n",
+ "1 1 1 \n",
+ "C=A+B...\n",
+ "3 3 3 \n",
+ "3 3 3 \n",
+ "3 3 3 \n",
+ "D=A-B...\n",
+ "1 1 1 \n",
+ "1 1 1 \n",
+ "1 1 1 \n",
+ "E=A*B...\n",
+ "6 6 6 \n",
+ "6 6 6 \n",
+ "6 6 6 \n",
+ "(Is matrix A equal to matrix B)? No\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-person.cpp, Page-423"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self, NameIn, AddressIn, PhoneIn):\n",
+ " self._Person__name=NameIn\n",
+ " self._Person__address=AddressIn\n",
+ " self._Person__phone=PhoneIn\n",
+ "#inline\n",
+ "def __del__(self):\n",
+ " del self._Person__name\n",
+ " del self._Person__address\n",
+ " del self._Person__phone\n",
+ "def getname(self):\n",
+ " return self._Person__name\n",
+ "def getaddress(self):\n",
+ " return self._Person__address\n",
+ "def getphone(self):\n",
+ " return self._Person__phone\n",
+ "def changename(self, NameIn):\n",
+ " if(self._Person__name):\n",
+ " del self._Person__name\n",
+ " self._Person__name=NameIn\n",
+ "class Person:\n",
+ " __name=[str]\n",
+ " __address=[str]\n",
+ " __phone=[str]\n",
+ " __init__=__init__\n",
+ " __del__=__del__\n",
+ " getname=getname\n",
+ " getaddress=getaddress\n",
+ " getphone=getphone\n",
+ " changename=changename\n",
+ "def printperson(p):\n",
+ " if(p.getname()):\n",
+ " print \"Name: \", p.getname()\n",
+ " if(p.getaddress()):\n",
+ " print \"Address: \", p.getaddress()\n",
+ " if(p.getphone()):\n",
+ " print \"Phone: \", p.getphone()\n",
+ "me=Person(\"Rajkumar\", \"E-mail: raj@cdabc.erne.in\", \"91-080-5584271\")\n",
+ "printperson(me)\n",
+ "you=Person(\"XYZ\", \"-not sure-\", \"-not sure-\")\n",
+ "print \"You XYZ by default...\"\n",
+ "printperson(you)\n",
+ "you.changename(\"ABC\")\n",
+ "print \"You changed XYZ to ABC...\"\n",
+ "printperson(you)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Rajkumar\n",
+ "Address: E-mail: raj@cdabc.erne.in\n",
+ "Phone: 91-080-5584271\n",
+ "You XYZ by default...\n",
+ "Name: XYZ\n",
+ "Address: -not sure-\n",
+ "Phone: -not sure-\n",
+ "You changed XYZ to ABC...\n",
+ "Name: ABC\n",
+ "Address: -not sure-\n",
+ "Phone: -not sure-\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-graph.cpp, Page-425"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __init__(self):\n",
+ " if(self._Graphics__nobjects[0]==False):\n",
+ " self._Graphics__setgraphicsmode()\n",
+ " self._Graphics__nobjects[0]+=1\n",
+ "def __del__(self):\n",
+ " self._Graphics__nobjects[0]-=1\n",
+ " if(self._Graphics__nobjects[0]==False):\n",
+ " self._Graphics__settextmode()\n",
+ "class Graphics:\n",
+ " __nobjects=[0]\n",
+ " def __setgraphicsmode(self):\n",
+ " pass\n",
+ " def __settextmode(self):\n",
+ " pass\n",
+ " __init__=__init__\n",
+ " __del__=__del__\n",
+ " def getcount(self):\n",
+ " return self.__nobjects[0]\n",
+ "def my_func():\n",
+ " obj=Graphics()\n",
+ " print \"No. of Graphics' objects while in my_func=\", obj.getcount()\n",
+ "obj1=Graphics()\n",
+ "print \"No. of Graphics' objects before in my_func=\", obj1.getcount()\n",
+ "my_func()\n",
+ "print \"No. of Graphics' objects after in my_func=\", obj1.getcount()\n",
+ "obj2=Graphics()\n",
+ "obj3=Graphics()\n",
+ "obj4=Graphics()\n",
+ "print \"Value of static member nobjects after all 3 more objects...\"\n",
+ "print \"In obj1= \", obj1.getcount()\n",
+ "print \"In obj2= \", obj2.getcount()\n",
+ "print \"In obj3= \", obj3.getcount()\n",
+ "print \"In obj4= \", obj4.getcount()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No. of Graphics' objects before in my_func= 1\n",
+ "No. of Graphics' objects while in my_func= 2\n",
+ "No. of Graphics' objects after in my_func= 1\n",
+ "Value of static member nobjects after all 3 more objects...\n",
+ "In obj1= 4\n",
+ "In obj2= 4\n",
+ "In obj3= 4\n",
+ "In obj4= 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example Page-428"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def distance(self, a, b):\n",
+ " self.x=a.x-b.x\n",
+ " self.y=a.y-b.y\n",
+ "def display(self):\n",
+ " print \"x= \",self.x\n",
+ " print \"y= \", self.y\n",
+ "class point:\n",
+ " __x=int\n",
+ " __y=int\n",
+ " def __init__(self, a=None, b=None):\n",
+ " if isinstance(a, int):\n",
+ " self.x=a\n",
+ " self.y=b\n",
+ " else:\n",
+ " self.x=self.y=0\n",
+ " def __del__(self):\n",
+ " pass\n",
+ " distance=distance\n",
+ " display=display\n",
+ "p1=point(40,18)\n",
+ "p2=point(12,9)\n",
+ "p3=point()\n",
+ "p3.distance(p1,p2)\n",
+ "print \"Coordinates of P1: \"\n",
+ "p1.display()\n",
+ "print \"Coordinates of P2: \"\n",
+ "p2.display()\n",
+ "print \"distance between P1 and P2: \"\n",
+ "p3.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Coordinates of P1: \n",
+ "x= 40\n",
+ "y= 18\n",
+ "Coordinates of P2: \n",
+ "x= 12\n",
+ "y= 9\n",
+ "distance between P1 and P2: \n",
+ "x= 28\n",
+ "y= 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example Page-430"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def display(self):\n",
+ " print \"a =\", self.a,\n",
+ " print \"b =\", self.b\n",
+ "class data:\n",
+ " __a=int\n",
+ " __b=float\n",
+ " def __init__(self, x=None, y=None):\n",
+ " if isinstance(x, int):\n",
+ " self.a=x\n",
+ " self.b=y\n",
+ " elif isinstance(x, data):\n",
+ " self.a=x.a\n",
+ " self.b=x.b\n",
+ " else:\n",
+ " self.a=0\n",
+ " self.b=0\n",
+ " display=display\n",
+ "d1=data()\n",
+ "d2=data(12,9.9)\n",
+ "d3=data(d2)\n",
+ "print \"For default constructor: \"\n",
+ "d1.display()\n",
+ "print\"For parameterized constructor: \"\n",
+ "d2.display()\n",
+ "print \"For Copy Constructor: \"\n",
+ "d3.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For default constructor: \n",
+ "a = 0 b = 0\n",
+ "For parameterized constructor: \n",
+ "a = 12 b = 9.9\n",
+ "For Copy Constructor: \n",
+ "a = 12 b = 9.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter12-DynamicObjects.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter12-DynamicObjects.ipynb
new file mode 100755
index 00000000..2c56060d
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter12-DynamicObjects.ipynb
@@ -0,0 +1,1590 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:dd08d35ee9767f23c09f2b0ea16b1cee00b60ac3967c95c41f4ba5d0c6e14cf0"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12-Dynamic Objects"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-ptrobj1.cpp, Page no-435"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class someclass(Structure):\n",
+ " data1=int\n",
+ " data2=chr\n",
+ " def __init__(self):\n",
+ " print 'Constructor someclass() is invoked'\n",
+ " self.data1=1\n",
+ " self.data2='A'\n",
+ " def __del__(self):\n",
+ " print 'Destructor ~someclass() is invoked'\n",
+ " def show(self):\n",
+ " print 'data1 =', self.data1,\n",
+ " print 'data2 =', self.data2\n",
+ "object1=someclass() #object of class someclass\n",
+ "ptr=POINTER(someclass) #pointer of type class someclass\n",
+ "ptr=object1 #pointer pointing to object of class someclass\n",
+ "print \"Accessing object through object1.show()...\"\n",
+ "object1.show()\n",
+ "print \"Accessing object through ptr->show()...\"\n",
+ "ptr.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor someclass() is invoked\n",
+ "Destructor ~someclass() is invoked\n",
+ "Accessing object through object1.show()...\n",
+ "data1 = 1 data2 = A\n",
+ "Accessing object through ptr->show()...\n",
+ "data1 = 1 data2 = A\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-ptrobj2.cpp, Page no-437"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class someclass(Structure):\n",
+ " data1=int\n",
+ " data2=chr\n",
+ " def __init__(self):\n",
+ " print 'Constructor someclass() is invoked'\n",
+ " self.data1=1\n",
+ " self.data2='A'\n",
+ " def __del__(self):\n",
+ " print 'Destructor ~someclass() is invoked'\n",
+ " def show(self):\n",
+ " print 'data1 =', self.data1,\n",
+ " print 'data2 =', self.data2\n",
+ "object1=someclass()\n",
+ "ptr=POINTER(someclass)\n",
+ "ptr=object1\n",
+ "print \"Accessing object through object1.show()...\"\n",
+ "ptr.show()\n",
+ "print \"Destroying dynamic object...\"\n",
+ "del ptr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor someclass() is invoked\n",
+ "Destructor ~someclass() is invoked\n",
+ "Accessing object through object1.show()...\n",
+ "data1 = 1 data2 = A\n",
+ "Destroying dynamic object...\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-useref.cpp, Page no-439"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "t1=POINTER(c_int)\n",
+ "t1=c_int(5)\n",
+ "t3=c_int(5)\n",
+ "t2=c_int(10)\n",
+ "t1.value=t1.value+t2.value\n",
+ "print \"Sum of\", t3.value,\n",
+ "print \"and\", t2.value, \n",
+ "print \"is:\", t1.value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sum of 5 and 10 is: 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-refobj.cpp, Page no-440"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class student(Structure):\n",
+ " __roll_no=int\n",
+ " __name=str\n",
+ " def setdata(self, roll_no_in, name_in):\n",
+ " self.__roll_no=roll_no_in\n",
+ " self.__name=name_in\n",
+ " def outdata(self):\n",
+ " print \"Roll No =\", self.__roll_no\n",
+ " print \"Name =\", self.__name\n",
+ "s1=student()\n",
+ "s1.setdata(1, \"Savithri\")\n",
+ "s1.outdata()\n",
+ "s2=student()\n",
+ "s2.setdata(2, \"Bhavani\")\n",
+ "s2.outdata()\n",
+ "s3=student()\n",
+ "s3.setdata(3, \"Vani\")\n",
+ "s4=s3\n",
+ "s3.outdata()\n",
+ "s4.outdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll No = 1\n",
+ "Name = Savithri\n",
+ "Roll No = 2\n",
+ "Name = Bhavani\n",
+ "Roll No = 3\n",
+ "Name = Vani\n",
+ "Roll No = 3\n",
+ "Name = Vani\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-student3.cpp, Page no-442"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class student:\n",
+ " __roll_no=int\n",
+ " __name=str\n",
+ " def __init__(self, roll_no_in=None, name_in=None):\n",
+ " if isinstance(roll_no_in, int):\n",
+ " self.__roll_no=roll_no_in\n",
+ " if isinstance(name_in, str):\n",
+ " self.__name=name_in\n",
+ " else:\n",
+ " flag=raw_input(\"Do you want to initialize the object (y/n): \")\n",
+ " if flag=='y' or flag=='Y':\n",
+ " self.__roll_no=int(raw_input(\"Enter Roll no. of student: \"))\n",
+ " Str=raw_input(\"Enter Name of student: \")\n",
+ " self.__name=Str\n",
+ " else:\n",
+ " self.__roll_no=0\n",
+ " self.__name=None\n",
+ " def __del__(self):\n",
+ " if isinstance(self.__name, str):\n",
+ " del self.__name\n",
+ " def Set(self):\n",
+ " student(roll_no_in, name_in)\n",
+ " def show(self):\n",
+ " if self.__roll_no:\n",
+ " print \"Roll No:\", self.__roll_no\n",
+ " else:\n",
+ " print \"Roll No: (not initialized)\"\n",
+ " if isinstance(self.__name, str):\n",
+ " print \"Name: \", self.__name\n",
+ " else:\n",
+ " print \"Name: (not initialized)\"\n",
+ "s1=student()\n",
+ "s2=student()\n",
+ "s3=student(1)\n",
+ "s4=student(2, \"Bhavani\")\n",
+ "print \"Live objects contents...\"\n",
+ "s1.show()\n",
+ "s2.show()\n",
+ "s3.show()\n",
+ "s4.show()\n",
+ "del s1\n",
+ "del s2\n",
+ "del s3\n",
+ "del s4"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to initialize the object (y/n): n\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Do you want to initialize the object (y/n): y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Roll no. of student: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name of student: Rekha\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Live objects contents...\n",
+ "Roll No: (not initialized)\n",
+ "Name: (not initialized)\n",
+ "Roll No: 5\n",
+ "Name: Rekha\n",
+ "Roll No: 1\n",
+ "Name: (not initialized)\n",
+ "Roll No: 2\n",
+ "Name: Bhavani\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-student1.cpp, Page-445"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class student:\n",
+ " __roll_no=int\n",
+ " __name=str\n",
+ " def setdata(self, roll_no_in, name_in):\n",
+ " self.__roll_no=roll_no_in\n",
+ " self.__name=name_in\n",
+ " def outdata(self):\n",
+ " print \"Roll No =\", self.__roll_no\n",
+ " print \"Name =\", self.__name\n",
+ "s=[]*10 #array of objects\n",
+ "count=0\n",
+ "for i in range(10):\n",
+ " s.append(student())\n",
+ "for i in range(10):\n",
+ " response=raw_input(\"Initialize student object (y/n): \")\n",
+ " if response=='y' or response=='Y':\n",
+ " roll_no=int(raw_input(\"Enter a Roll no. of student: \"))\n",
+ " name=raw_input(\"Enter name of student: \")\n",
+ " s[i].setdata(roll_no, name)\n",
+ " count+=1\n",
+ " else:\n",
+ " break\n",
+ "print \"Student Details...\"\n",
+ "for i in range(count):\n",
+ " s[i].outdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Initialize student object (y/n): y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a Roll no. of student: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name of student: Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Initialize student object (y/n): y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a Roll no. of student: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name of student: Tejaswi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Initialize student object (y/n): y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a Roll no. of student: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name of student: Savithri\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Initialize student object (y/n): n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Student Details...\n",
+ "Roll No = 1\n",
+ "Name = Rajkumar\n",
+ "Roll No = 2\n",
+ "Name = Tejaswi\n",
+ "Roll No = 3\n",
+ "Name = Savithri\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-student2.cpp, Page no-447"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class student(Structure):\n",
+ " __roll_no=int\n",
+ " __name=str\n",
+ " def setdata(self, roll_no_in, name_in):\n",
+ " self.__roll_no=roll_no_in\n",
+ " self.__name=name_in\n",
+ " def outdata(self):\n",
+ " print \"Roll No =\", self.__roll_no\n",
+ " print \"Name =\", self.__name\n",
+ "temp=[]*10\n",
+ "s=POINTER(student) \n",
+ "count=0\n",
+ "for i in range(10):\n",
+ " temp.append(student())\n",
+ "s=temp #pointer to array of objects\n",
+ "for i in range(10):\n",
+ " response=raw_input(\"Create student object (y/n): \")\n",
+ " if response=='y' or response=='Y':\n",
+ " roll_no=int(raw_input(\"Enter a Roll no. of student: \"))\n",
+ " name=raw_input(\"Enter name of student: \")\n",
+ " s[i].setdata(roll_no, name)\n",
+ " count+=1\n",
+ " else:\n",
+ " break\n",
+ "print \"Student Details...\"\n",
+ "for i in range(count):\n",
+ " s[i].outdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Create student object (y/n): y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a Roll no. of student: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name of student: Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Create student object (y/n): y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a Roll no. of student: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name of student: Tejaswi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Create student object (y/n): y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a Roll no. of student: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name of student: Savithri\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Create student object (y/n): n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Student Details...\n",
+ "Roll No = 1\n",
+ "Name = Rajkumar\n",
+ "Roll No = 2\n",
+ "Name = Tejaswi\n",
+ "Roll No = 3\n",
+ "Name = Savithri\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-ptrmemb.cpp, Page no-452"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class X:\n",
+ " __y=int\n",
+ " a=int\n",
+ " b=int\n",
+ " def init(self, z):\n",
+ " self.a=z\n",
+ " return z\n",
+ "obj=X()\n",
+ "ip=X.a #pointer to data member\n",
+ "obj.ip=10 #access through object\n",
+ "print \"a in obj after obj.*ip = 10 is\", obj.ip\n",
+ "pobj=[obj] #pointer to object of class X\n",
+ "pobj[0].ip=10 #access through object pointer\n",
+ "print \"a in obj after pobj->*ip = 10 is\", pobj[0].ip\n",
+ "ptr_init=X.init #pointer to member function\n",
+ "ptr_init(obj,5) #access through object\n",
+ "print \"a in obj after (obj.*ptr_init)(5) =\", obj.a\n",
+ "ptr_init(pobj[0],5) #access through object pointer\n",
+ "print \"a in obj after (pobj->*ptr_init)(5) =\", obj.a"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a in obj after obj.*ip = 10 is 10\n",
+ "a in obj after pobj->*ip = 10 is 10\n",
+ "a in obj after (obj.*ptr_init)(5) = 5\n",
+ "a in obj after (pobj->*ptr_init)(5) = 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-friend.cpp, Page no-454"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class X():\n",
+ " __a=int\n",
+ " __b=int\n",
+ " def __init__(self):\n",
+ " self.__a=0\n",
+ " self.__b=0\n",
+ " def SetMembers(self, a1, b1):\n",
+ " self.__a=a1\n",
+ " self.__b=b1\n",
+ "def sum(objx):\n",
+ " pa=[X._X__a]\n",
+ " pb=[X._X__b]\n",
+ " objx.pa=objx._X__a\n",
+ " objx.pb=objx._X__b\n",
+ " return objx.pa+objx.pb\n",
+ "objx=X()\n",
+ "pfunc=X.SetMembers\n",
+ "pfunc(objx, 5, 6)\n",
+ "print \"Sum =\", sum(objx)\n",
+ "pobjx=[objx]\n",
+ "pfunc(pobjx[0], 7, 8)\n",
+ "print \"Sum =\", sum(objx)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sum = 11\n",
+ "Sum = 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-memhnd.cpp, Page no-455"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "def out_of_memory():\n",
+ " print \"Memory exhausted, cannot allocate\"\n",
+ "ip=pointer(c_int())\n",
+ "total_allocated=0L\n",
+ "print \"Ok, allocating...\"\n",
+ "while(1):\n",
+ " ip=[int]*100\n",
+ " total_allocated+=100L\n",
+ " print \"Now got a total of\", total_allocated, \"bytes\"\n",
+ " if total_allocated==29900L:\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ok, allocating...\n",
+ "Now got a total of 100 bytes\n",
+ "Now got a total of 200 bytes\n",
+ "Now got a total of 300 bytes\n",
+ "Now got a total of 400 bytes\n",
+ "Now got a total of 500 bytes\n",
+ "Now got a total of 600 bytes\n",
+ "Now got a total of 700 bytes\n",
+ "Now got a total of 800 bytes\n",
+ "Now got a total of 900 bytes\n",
+ "Now got a total of 1000 bytes\n",
+ "Now got a total of 1100 bytes\n",
+ "Now got a total of 1200 bytes\n",
+ "Now got a total of 1300 bytes\n",
+ "Now got a total of 1400 bytes\n",
+ "Now got a total of 1500 bytes\n",
+ "Now got a total of 1600 bytes\n",
+ "Now got a total of 1700 bytes\n",
+ "Now got a total of 1800 bytes\n",
+ "Now got a total of 1900 bytes\n",
+ "Now got a total of 2000 bytes\n",
+ "Now got a total of 2100 bytes\n",
+ "Now got a total of 2200 bytes\n",
+ "Now got a total of 2300 bytes\n",
+ "Now got a total of 2400 bytes\n",
+ "Now got a total of 2500 bytes\n",
+ "Now got a total of 2600 bytes\n",
+ "Now got a total of 2700 bytes\n",
+ "Now got a total of 2800 bytes\n",
+ "Now got a total of 2900 bytes\n",
+ "Now got a total of 3000 bytes\n",
+ "Now got a total of 3100 bytes\n",
+ "Now got a total of 3200 bytes\n",
+ "Now got a total of 3300 bytes\n",
+ "Now got a total of 3400 bytes\n",
+ "Now got a total of 3500 bytes\n",
+ "Now got a total of 3600 bytes\n",
+ "Now got a total of 3700 bytes\n",
+ "Now got a total of 3800 bytes\n",
+ "Now got a total of 3900 bytes\n",
+ "Now got a total of 4000 bytes\n",
+ "Now got a total of 4100 bytes\n",
+ "Now got a total of 4200 bytes\n",
+ "Now got a total of 4300 bytes\n",
+ "Now got a total of 4400 bytes\n",
+ "Now got a total of 4500 bytes\n",
+ "Now got a total of 4600 bytes\n",
+ "Now got a total of 4700 bytes\n",
+ "Now got a total of 4800 bytes\n",
+ "Now got a total of 4900 bytes\n",
+ "Now got a total of 5000 bytes\n",
+ "Now got a total of 5100 bytes\n",
+ "Now got a total of 5200 bytes\n",
+ "Now got a total of 5300 bytes\n",
+ "Now got a total of 5400 bytes\n",
+ "Now got a total of 5500 bytes\n",
+ "Now got a total of 5600 bytes\n",
+ "Now got a total of 5700 bytes\n",
+ "Now got a total of 5800 bytes\n",
+ "Now got a total of 5900 bytes\n",
+ "Now got a total of 6000 bytes\n",
+ "Now got a total of 6100 bytes\n",
+ "Now got a total of 6200 bytes\n",
+ "Now got a total of 6300 bytes\n",
+ "Now got a total of 6400 bytes\n",
+ "Now got a total of 6500 bytes\n",
+ "Now got a total of 6600 bytes\n",
+ "Now got a total of 6700 bytes\n",
+ "Now got a total of 6800 bytes\n",
+ "Now got a total of 6900 bytes\n",
+ "Now got a total of 7000 bytes\n",
+ "Now got a total of 7100 bytes\n",
+ "Now got a total of 7200 bytes\n",
+ "Now got a total of 7300 bytes\n",
+ "Now got a total of 7400 bytes\n",
+ "Now got a total of 7500 bytes\n",
+ "Now got a total of 7600 bytes\n",
+ "Now got a total of 7700 bytes\n",
+ "Now got a total of 7800 bytes\n",
+ "Now got a total of 7900 bytes\n",
+ "Now got a total of 8000 bytes\n",
+ "Now got a total of 8100 bytes\n",
+ "Now got a total of 8200 bytes\n",
+ "Now got a total of 8300 bytes\n",
+ "Now got a total of 8400 bytes\n",
+ "Now got a total of 8500 bytes\n",
+ "Now got a total of 8600 bytes\n",
+ "Now got a total of 8700 bytes\n",
+ "Now got a total of 8800 bytes\n",
+ "Now got a total of 8900 bytes\n",
+ "Now got a total of 9000 bytes\n",
+ "Now got a total of 9100 bytes\n",
+ "Now got a total of 9200 bytes\n",
+ "Now got a total of 9300 bytes\n",
+ "Now got a total of 9400 bytes\n",
+ "Now got a total of 9500 bytes\n",
+ "Now got a total of 9600 bytes\n",
+ "Now got a total of 9700 bytes\n",
+ "Now got a total of 9800 bytes\n",
+ "Now got a total of 9900 bytes\n",
+ "Now got a total of 10000 bytes\n",
+ "Now got a total of 10100 bytes\n",
+ "Now got a total of 10200 bytes\n",
+ "Now got a total of 10300 bytes\n",
+ "Now got a total of 10400 bytes\n",
+ "Now got a total of 10500 bytes\n",
+ "Now got a total of 10600 bytes\n",
+ "Now got a total of 10700 bytes\n",
+ "Now got a total of 10800 bytes\n",
+ "Now got a total of 10900 bytes\n",
+ "Now got a total of 11000 bytes\n",
+ "Now got a total of 11100 bytes\n",
+ "Now got a total of 11200 bytes\n",
+ "Now got a total of 11300 bytes\n",
+ "Now got a total of 11400 bytes\n",
+ "Now got a total of 11500 bytes\n",
+ "Now got a total of 11600 bytes\n",
+ "Now got a total of 11700 bytes\n",
+ "Now got a total of 11800 bytes\n",
+ "Now got a total of 11900 bytes\n",
+ "Now got a total of 12000 bytes\n",
+ "Now got a total of 12100 bytes\n",
+ "Now got a total of 12200 bytes\n",
+ "Now got a total of 12300 bytes\n",
+ "Now got a total of 12400 bytes\n",
+ "Now got a total of 12500 bytes\n",
+ "Now got a total of 12600 bytes\n",
+ "Now got a total of 12700 bytes\n",
+ "Now got a total of 12800 bytes\n",
+ "Now got a total of 12900 bytes\n",
+ "Now got a total of 13000 bytes\n",
+ "Now got a total of 13100 bytes\n",
+ "Now got a total of 13200 bytes\n",
+ "Now got a total of 13300 bytes\n",
+ "Now got a total of 13400 bytes\n",
+ "Now got a total of 13500 bytes\n",
+ "Now got a total of 13600 bytes\n",
+ "Now got a total of 13700 bytes\n",
+ "Now got a total of 13800 bytes\n",
+ "Now got a total of 13900 bytes\n",
+ "Now got a total of 14000 bytes\n",
+ "Now got a total of 14100 bytes\n",
+ "Now got a total of 14200 bytes\n",
+ "Now got a total of 14300 bytes\n",
+ "Now got a total of 14400 bytes\n",
+ "Now got a total of 14500 bytes\n",
+ "Now got a total of 14600 bytes\n",
+ "Now got a total of 14700 bytes\n",
+ "Now got a total of 14800 bytes\n",
+ "Now got a total of 14900 bytes\n",
+ "Now got a total of 15000 bytes\n",
+ "Now got a total of 15100 bytes\n",
+ "Now got a total of 15200 bytes\n",
+ "Now got a total of 15300 bytes\n",
+ "Now got a total of 15400 bytes\n",
+ "Now got a total of 15500 bytes\n",
+ "Now got a total of 15600 bytes\n",
+ "Now got a total of 15700 bytes\n",
+ "Now got a total of 15800 bytes\n",
+ "Now got a total of 15900 bytes\n",
+ "Now got a total of 16000 bytes\n",
+ "Now got a total of 16100 bytes\n",
+ "Now got a total of 16200 bytes\n",
+ "Now got a total of 16300 bytes\n",
+ "Now got a total of 16400 bytes\n",
+ "Now got a total of 16500 bytes\n",
+ "Now got a total of 16600 bytes\n",
+ "Now got a total of 16700 bytes\n",
+ "Now got a total of 16800 bytes\n",
+ "Now got a total of 16900 bytes\n",
+ "Now got a total of 17000 bytes\n",
+ "Now got a total of 17100 bytes\n",
+ "Now got a total of 17200 bytes\n",
+ "Now got a total of 17300 bytes\n",
+ "Now got a total of 17400 bytes\n",
+ "Now got a total of 17500 bytes\n",
+ "Now got a total of 17600 bytes\n",
+ "Now got a total of 17700 bytes\n",
+ "Now got a total of 17800 bytes\n",
+ "Now got a total of 17900 bytes\n",
+ "Now got a total of 18000 bytes\n",
+ "Now got a total of 18100 bytes\n",
+ "Now got a total of 18200 bytes\n",
+ "Now got a total of 18300 bytes\n",
+ "Now got a total of 18400 bytes\n",
+ "Now got a total of 18500 bytes\n",
+ "Now got a total of 18600 bytes\n",
+ "Now got a total of 18700 bytes\n",
+ "Now got a total of 18800 bytes\n",
+ "Now got a total of 18900 bytes\n",
+ "Now got a total of 19000 bytes\n",
+ "Now got a total of 19100 bytes\n",
+ "Now got a total of 19200 bytes\n",
+ "Now got a total of 19300 bytes\n",
+ "Now got a total of 19400 bytes\n",
+ "Now got a total of 19500 bytes\n",
+ "Now got a total of 19600 bytes\n",
+ "Now got a total of 19700 bytes\n",
+ "Now got a total of 19800 bytes\n",
+ "Now got a total of 19900 bytes\n",
+ "Now got a total of 20000 bytes\n",
+ "Now got a total of 20100 bytes\n",
+ "Now got a total of 20200 bytes\n",
+ "Now got a total of 20300 bytes\n",
+ "Now got a total of 20400 bytes\n",
+ "Now got a total of 20500 bytes\n",
+ "Now got a total of 20600 bytes\n",
+ "Now got a total of 20700 bytes\n",
+ "Now got a total of 20800 bytes\n",
+ "Now got a total of 20900 bytes\n",
+ "Now got a total of 21000 bytes\n",
+ "Now got a total of 21100 bytes\n",
+ "Now got a total of 21200 bytes\n",
+ "Now got a total of 21300 bytes\n",
+ "Now got a total of 21400 bytes\n",
+ "Now got a total of 21500 bytes\n",
+ "Now got a total of 21600 bytes\n",
+ "Now got a total of 21700 bytes\n",
+ "Now got a total of 21800 bytes\n",
+ "Now got a total of 21900 bytes\n",
+ "Now got a total of 22000 bytes\n",
+ "Now got a total of 22100 bytes\n",
+ "Now got a total of 22200 bytes\n",
+ "Now got a total of 22300 bytes\n",
+ "Now got a total of 22400 bytes\n",
+ "Now got a total of 22500 bytes\n",
+ "Now got a total of 22600 bytes\n",
+ "Now got a total of 22700 bytes\n",
+ "Now got a total of 22800 bytes\n",
+ "Now got a total of 22900 bytes\n",
+ "Now got a total of 23000 bytes\n",
+ "Now got a total of 23100 bytes\n",
+ "Now got a total of 23200 bytes\n",
+ "Now got a total of 23300 bytes\n",
+ "Now got a total of 23400 bytes\n",
+ "Now got a total of 23500 bytes\n",
+ "Now got a total of 23600 bytes\n",
+ "Now got a total of 23700 bytes\n",
+ "Now got a total of 23800 bytes\n",
+ "Now got a total of 23900 bytes\n",
+ "Now got a total of 24000 bytes\n",
+ "Now got a total of 24100 bytes\n",
+ "Now got a total of 24200 bytes\n",
+ "Now got a total of 24300 bytes\n",
+ "Now got a total of 24400 bytes\n",
+ "Now got a total of 24500 bytes\n",
+ "Now got a total of 24600 bytes\n",
+ "Now got a total of 24700 bytes\n",
+ "Now got a total of 24800 bytes\n",
+ "Now got a total of 24900 bytes\n",
+ "Now got a total of 25000 bytes\n",
+ "Now got a total of 25100 bytes\n",
+ "Now got a total of 25200 bytes\n",
+ "Now got a total of 25300 bytes\n",
+ "Now got a total of 25400 bytes\n",
+ "Now got a total of 25500 bytes\n",
+ "Now got a total of 25600 bytes\n",
+ "Now got a total of 25700 bytes\n",
+ "Now got a total of 25800 bytes\n",
+ "Now got a total of 25900 bytes\n",
+ "Now got a total of 26000 bytes\n",
+ "Now got a total of 26100 bytes\n",
+ "Now got a total of 26200 bytes\n",
+ "Now got a total of 26300 bytes\n",
+ "Now got a total of 26400 bytes\n",
+ "Now got a total of 26500 bytes\n",
+ "Now got a total of 26600 bytes\n",
+ "Now got a total of 26700 bytes\n",
+ "Now got a total of 26800 bytes\n",
+ "Now got a total of 26900 bytes\n",
+ "Now got a total of 27000 bytes\n",
+ "Now got a total of 27100 bytes\n",
+ "Now got a total of 27200 bytes\n",
+ "Now got a total of 27300 bytes\n",
+ "Now got a total of 27400 bytes\n",
+ "Now got a total of 27500 bytes\n",
+ "Now got a total of 27600 bytes\n",
+ "Now got a total of 27700 bytes\n",
+ "Now got a total of 27800 bytes\n",
+ "Now got a total of 27900 bytes\n",
+ "Now got a total of 28000 bytes\n",
+ "Now got a total of 28100 bytes\n",
+ "Now got a total of 28200 bytes\n",
+ "Now got a total of 28300 bytes\n",
+ "Now got a total of 28400 bytes\n",
+ "Now got a total of 28500 bytes\n",
+ "Now got a total of 28600 bytes\n",
+ "Now got a total of 28700 bytes\n",
+ "Now got a total of 28800 bytes\n",
+ "Now got a total of 28900 bytes\n",
+ "Now got a total of 29000 bytes\n",
+ "Now got a total of 29100 bytes\n",
+ "Now got a total of 29200 bytes\n",
+ "Now got a total of 29300 bytes\n",
+ "Now got a total of 29400 bytes\n",
+ "Now got a total of 29500 bytes\n",
+ "Now got a total of 29600 bytes\n",
+ "Now got a total of 29700 bytes\n",
+ "Now got a total of 29800 bytes\n",
+ "Now got a total of 29900 bytes\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-this.cpp, Page no-457"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Test:\n",
+ " __a=int\n",
+ " def setdata(self, init_a):\n",
+ " self.__a=init_a\n",
+ " print \"Address of my object, this in setdata():\", hex(id(self))\n",
+ " self.__a=init_a\n",
+ " def showdata(self):\n",
+ " print \"Data accessed in normal way: \", self.__a\n",
+ " print \"Address of my object, this in showdata(): \", hex(id(self))\n",
+ " print \"Data accessed through this->a: \", self.__a\n",
+ "my=Test()\n",
+ "my.setdata(25)\n",
+ "my.showdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address of my object, this in setdata(): 0x39de488L\n",
+ "Data accessed in normal way: 25\n",
+ "Address of my object, this in showdata(): 0x39de488L\n",
+ "Data accessed through this->a: 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-list.cpp, Page no-459"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class List():\n",
+ " def __init__(self, dat=None):\n",
+ " if isinstance(dat, int):\n",
+ " self.__data=dat\n",
+ " else:\n",
+ " self.__data=0\n",
+ " self.__Next=None\n",
+ " def __del__(self):\n",
+ " pass\n",
+ " def get(self):\n",
+ " return self.__data\n",
+ " def insert(self, node):\n",
+ " last=List()\n",
+ " last=self\n",
+ " while(last.__Next!=None):\n",
+ " last=last.__Next\n",
+ " last.__Next=node\n",
+ "def display(first):\n",
+ " traverse=List()\n",
+ " print \"List traversal yields:\",\n",
+ " traverse=first\n",
+ " while(1): \n",
+ " print traverse._List__data, \",\",\n",
+ " if traverse._List__Next==None:\n",
+ " break\n",
+ " traverse=traverse._List__Next\n",
+ " print \"\"\n",
+ "first=List()\n",
+ "first=None\n",
+ "while(1):\n",
+ " print \"Linked List...\\n1.Insert\\n2.Display\\n3.Quit\\nEnter Choice: \",\n",
+ " choice=int(raw_input())\n",
+ " if choice==1:\n",
+ " data=int(raw_input(\"Enter data: \"))\n",
+ " node=List(data)\n",
+ " if first==None:\n",
+ " first=node\n",
+ " else:\n",
+ " first.insert(node)\n",
+ " elif choice==2:\n",
+ " display(first)\n",
+ " elif choice==3:\n",
+ " break\n",
+ " else:\n",
+ " print \"Bad Option Selected\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Linked List...\n",
+ "1.Insert\n",
+ "2.Display\n",
+ "3.Quit\n",
+ "Enter Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Linked List...\n",
+ "1.Insert\n",
+ "2.Display\n",
+ "3.Quit\n",
+ "Enter Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " List traversal yields: 2 , \n",
+ "Linked List...\n",
+ "1.Insert\n",
+ "2.Display\n",
+ "3.Quit\n",
+ "Enter Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Linked List...\n",
+ "1.Insert\n",
+ "2.Display\n",
+ "3.Quit\n",
+ "Enter Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Linked List...\n",
+ "1.Insert\n",
+ "2.Display\n",
+ "3.Quit\n",
+ "Enter Choice: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " List traversal yields: 2 , 3 , 4 , \n",
+ "Linked List...\n",
+ "1.Insert\n",
+ "2.Display\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": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-dll.cpp, Page no-462"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class dll:\n",
+ " def __init__(self, data_in=None):\n",
+ " if isinstance(data_in, int):\n",
+ " self.__data=data_in\n",
+ " else:\n",
+ " self.__data=0\n",
+ " self.__prev=None\n",
+ " self.__Next=None\n",
+ " def __del__(self):\n",
+ " pass\n",
+ " def get(self):\n",
+ " return self.__data\n",
+ " def insert(self, node):\n",
+ " last=dll()\n",
+ " last=self\n",
+ " while(last._dll__Next!=None):\n",
+ " last=last._dll__Next\n",
+ " node._dll__prev=last\n",
+ " node._dll__Next=None\n",
+ " last._dll__Next=node\n",
+ " def FreeAllNodes(self):\n",
+ " print \"Freeing the node with data:\",\n",
+ " first=dll()\n",
+ " first=self\n",
+ " while(1):\n",
+ " temp= dll()\n",
+ " temp=first\n",
+ " print \"->\", first._dll__data,\n",
+ " del temp\n",
+ " first=first._dll__Next\n",
+ " if first==None:\n",
+ " break\n",
+ "def display(first):\n",
+ " traverse=dll()\n",
+ " traverse=first\n",
+ " if first==None:\n",
+ " print \"Nothing to display !\"\n",
+ " return\n",
+ " else:\n",
+ " print \"Processing with forward -> pointer:\",\n",
+ " while(1): \n",
+ " print \"->\", traverse._dll__data, \n",
+ " if traverse._dll__Next==None:\n",
+ " break\n",
+ " traverse=traverse._dll__Next\n",
+ " print \"\\nProcessing with backward <- pointer:\",\n",
+ " while(1): \n",
+ " print \"->\", traverse._dll__data,\n",
+ " if traverse._dll__prev==None:\n",
+ " break\n",
+ " traverse=traverse._dll__prev\n",
+ " print \"\"\n",
+ "def InsertNode(first, data):\n",
+ " node=dll(data)\n",
+ " if first==None:\n",
+ " first=node\n",
+ " else:\n",
+ " first.insert(node)\n",
+ " return first\n",
+ "first=dll()\n",
+ "first=None\n",
+ "print \"Double Linked List Manipulation...\"\n",
+ "while(1):\n",
+ " choice=int(raw_input(\"Enter Choice ([1] Insert, [2] Display, [3]Quit: \"))\n",
+ " if choice==1:\n",
+ " data=int(raw_input(\"Enter data: \"))\n",
+ " first=InsertNode(first, data)\n",
+ " elif choice==2:\n",
+ " display(first)\n",
+ " elif choice==3:\n",
+ " first.FreeAllNodes()\n",
+ " break\n",
+ " else:\n",
+ " print \"Bad Option Selected\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Double Linked List Manipulation...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Choice ([1] Insert, [2] Display, [3]Quit: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Choice ([1] Insert, [2] Display, [3]Quit: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing with forward -> pointer: -> 3 \n",
+ "Processing with backward <- pointer: -> 3 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Choice ([1] Insert, [2] Display, [3]Quit: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data: 7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Choice ([1] Insert, [2] Display, [3]Quit: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing with forward -> pointer: -> 3 -> 7 \n",
+ "Processing with backward <- pointer: -> 7 -> 3 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Choice ([1] Insert, [2] Display, [3]Quit: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Choice ([1] Insert, [2] Display, [3]Quit: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Processing with forward -> pointer: -> 3 -> 7 -> 5 \n",
+ "Processing with backward <- pointer: -> 5 -> 7 -> 3 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Choice ([1] Insert, [2] Display, [3]Quit: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bad Option Selected\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Choice ([1] Insert, [2] Display, [3]Quit: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Freeing the node with data: -> 3 -> 7 -> 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-1, Page no-466"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " __a1=int\n",
+ " def Set(self, val):\n",
+ " self.__a1=val\n",
+ "class B:\n",
+ " __b1=int\n",
+ " def Set(self, val):\n",
+ " self.__b1=val\n",
+ "def add(x, y):\n",
+ " return x._A__a1+y._B__b1\n",
+ "ObjA=A()\n",
+ "ObjB=B()\n",
+ "ObjA.Set(9)\n",
+ "ObjB.Set(10)\n",
+ "print \"Sum of objects A and B using friend function =\", add(ObjA, ObjB)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sum of objects A and B using friend function = 19\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-2, Page no-466"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class test:\n",
+ " __data=int\n",
+ " def func(self, val):\n",
+ " self.__data=val\n",
+ "t1=test()\n",
+ "testptr={}\n",
+ "testptr[0]=test.func #pointer to member function\n",
+ "print \"Initializing test class object t1 using pointer...\"\n",
+ "testptr[0](t1, 10)\n",
+ "print \"Object initialized successfully\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Initializing test class object t1 using pointer...\n",
+ "Object initialized successfully\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter13-OperatorOverloading.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter13-OperatorOverloading.ipynb
new file mode 100755
index 00000000..8c7b1cb8
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter13-OperatorOverloading.ipynb
@@ -0,0 +1,2673 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:31bc0d2b60eba6f6d92afa42e690cc5db6b40cd9b0c7b9682b1c923305d9cccd"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13- Operator Overloading"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-index1.cpp, Page no-470"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Index:\n",
+ " __value=int\n",
+ " def __init__(self):\n",
+ " self.__value=0\n",
+ " def GetIndex(self):\n",
+ " return self.__value\n",
+ " def NextIndex(self):\n",
+ " self.__value=self.__value+1\n",
+ "idx1=Index()\n",
+ "idx2=Index()\n",
+ "print \"Index1 =\", idx1.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()\n",
+ "idx1.NextIndex()\n",
+ "idx2.NextIndex()\n",
+ "idx2.NextIndex()\n",
+ "print \"Index1 =\", idx1.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Index1 = 0\n",
+ "Index2 = 0\n",
+ "Index1 = 1\n",
+ "Index2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-index2.cpp, Page no-471"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Index:\n",
+ " __value=int\n",
+ " def __init__(self):\n",
+ " self.__value=0\n",
+ " def GetIndex(self):\n",
+ " return self.__value\n",
+ " #overload increment operator\n",
+ " def __iadd__(self, op):\n",
+ " self.__value=self.__value+op\n",
+ " return self\n",
+ "idx1=Index()\n",
+ "idx2=Index()\n",
+ "print \"Index1 =\", idx1.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()\n",
+ "idx1+=1 #overloaded increment operator invoked\n",
+ "idx2+=1 #overloaded increment operator invoked\n",
+ "idx2+=1 #overloaded increment operator invoked\n",
+ "print \"Index1 =\", idx1.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Index1 = 0\n",
+ "Index2 = 0\n",
+ "Index1 = 1\n",
+ "Index2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-index3.cpp, Page no-475"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Index:\n",
+ " __value=int\n",
+ " def __init__(self):\n",
+ " self.__value=0\n",
+ " def GetIndex(self):\n",
+ " return self.__value\n",
+ " def __iadd__(self, op):\n",
+ " self.__value+=1\n",
+ " return self\n",
+ "idx1=Index()\n",
+ "idx2=Index()\n",
+ "print \"Index1 =\", idx1.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()\n",
+ "idx2+=1\n",
+ "idx1+=1\n",
+ "idx2+=1\n",
+ "print \"Index1 =\", idx1.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Index1 = 0\n",
+ "Index2 = 0\n",
+ "Index1 = 1\n",
+ "Index2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-index4.cpp, Page no-476"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Index:\n",
+ " __value=int\n",
+ " def __init__(self):\n",
+ " self.__value=0\n",
+ " def GetIndex(self):\n",
+ " return self.__value\n",
+ " #overload increment operator\n",
+ " def __iadd__(self, op):\n",
+ " self.__value=self.__value+op\n",
+ " return self\n",
+ "idx1=Index()\n",
+ "idx2=Index()\n",
+ "print \"Index1 =\", idx1.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()\n",
+ "idx1+=1\n",
+ "idx2+=1\n",
+ "idx2+=1\n",
+ "print \"Index1 =\", idx1.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Index1 = 0\n",
+ "Index2 = 0\n",
+ "Index1 = 1\n",
+ "Index2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-index5.cpp, Page no-478"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Index:\n",
+ " __value=int\n",
+ " def __init__(self, val=0):\n",
+ " self.__value=val\n",
+ " def GetIndex(self):\n",
+ " return self.__value\n",
+ " #overload increment operator\n",
+ " def __iadd__(self, op):\n",
+ " self.__value=self.__value+op\n",
+ " return self\n",
+ "idx1=Index(2)\n",
+ "idx2=Index(2)\n",
+ "idx3=Index()\n",
+ "idx4=Index()\n",
+ "print \"Index1 =\", idx1.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()\n",
+ "idx3._Index__value=idx1._Index__value\n",
+ "idx1+=1\n",
+ "idx2+=1\n",
+ "idx4=idx2\n",
+ "print \"Index1 =\", idx1.GetIndex()\n",
+ "print \"Index3 =\", idx3.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()\n",
+ "print \"Index4 =\", idx4.GetIndex()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Index1 = 2\n",
+ "Index2 = 2\n",
+ "Index1 = 3\n",
+ "Index3 = 2\n",
+ "Index2 = 3\n",
+ "Index4 = 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-index6.cpp, Page no-479"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Index:\n",
+ " __value=int\n",
+ " def __init__(self, val=0):\n",
+ " self.__value=val\n",
+ " def GetIndex(self):\n",
+ " return self.__value\n",
+ " #overload increment operator\n",
+ " def __iadd__(self, op):\n",
+ " self.__value=self.__value+op\n",
+ " return self\n",
+ " #overload decrement operator\n",
+ " def __isub__(self, op):\n",
+ " self.__value=self.__value-op\n",
+ " return self\n",
+ " #overload negation operator\n",
+ " def __neg__(self):\n",
+ " return Index(-self.__value)\n",
+ "idx1=Index()\n",
+ "idx2=Index()\n",
+ "print \"Index1 =\", idx1.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()\n",
+ "idx2+=1\n",
+ "idx1=-idx2\n",
+ "idx2+=1\n",
+ "idx2-=1\n",
+ "print \"Index1 =\", idx1.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Index1 = 0\n",
+ "Index2 = 0\n",
+ "Index1 = -1\n",
+ "Index2 = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-mydate.cpp, Page no-480"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class date:\n",
+ " __day=int\n",
+ " __month=int\n",
+ " __year=int\n",
+ " def __init__(self, d=0, m=0, y=0):\n",
+ " if isinstance(d, int):\n",
+ " self.__day=d\n",
+ " self.__month=m\n",
+ " self.__year=y\n",
+ " else:\n",
+ " self.__day=0\n",
+ " self.__month=0\n",
+ " self.__year=0\n",
+ " def read(self):\n",
+ " self.__day, self.__month, self.__year=[int(x) for x in raw_input(\"Enter date <dd mm yyyy>: \").split()]\n",
+ " def show(self):\n",
+ " print \"%s:%s:%s\" %(self.__day, self.__month, self.__year),\n",
+ " def IsLeapYear(self):\n",
+ " if (self.__year%4==0 and self.__year%100!=0) or (self.__year % 400==0):\n",
+ " return 1\n",
+ " else:\n",
+ " return 0\n",
+ " def thisMonthMaxDay(self):\n",
+ " m=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
+ " if self.__month==2 and self.IsLeapYear():\n",
+ " return 29\n",
+ " else:\n",
+ " return m[self.__month-1]\n",
+ " def __iadd__(self, op): #overloading increment operator\n",
+ " self.__day+=1\n",
+ " if self.__day>self.thisMonthMaxDay():\n",
+ " self.__day=1\n",
+ " self.__month+=1\n",
+ " if self.__month>12:\n",
+ " self.__month=1\n",
+ " self.__year+=1\n",
+ " return self\n",
+ "def nextday(d):\n",
+ " print 'Date', \n",
+ " d.show()\n",
+ " d+=1 #overloaded increment operator invoked\n",
+ " print \"on increment becomes\", \n",
+ " d.show()\n",
+ " print \"\"\n",
+ "d1=date(14, 4, 1971)\n",
+ "d2=date(28, 2, 1992)\n",
+ "d3=date(28, 2, 1993)\n",
+ "d4=date(31, 12, 1995)\n",
+ "nextday(d1)\n",
+ "nextday(d2)\n",
+ "nextday(d3)\n",
+ "nextday(d4)\n",
+ "today=date()\n",
+ "today.read()\n",
+ "nextday(today)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Date 14:4:1971 on increment becomes 15:4:1971 \n",
+ "Date 28:2:1992 on increment becomes 29:2:1992 \n",
+ "Date 28:2:1993 on increment becomes 1:3:1993 \n",
+ "Date 31:12:1995 on increment becomes 1:1:1996 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter date <dd mm yyyy>: 11 9 1996\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Date 11:9:1996 on increment becomes 12:9:1996 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex1.cpp, Page no-483"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def AddComplex(self, c2):\n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real+c2._Complex__real\n",
+ " temp._Complex__imag=self._Complex__imag+c2._Complex__imag\n",
+ " return temp\n",
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def __init__(self):\n",
+ " self.__real=self.__imag=0\n",
+ " def getdata(self):\n",
+ " self.__real=float(raw_input(\"Real part ? \"))\n",
+ " self.__imag=float(raw_input(\"Imag part ? \"))\n",
+ " AddComplex=AddComplex\n",
+ " def outdata(self, msg):\n",
+ " print \"%s(%0.1f, %0.1f)\" %(msg, self.__real, self.__imag)\n",
+ "c1=Complex()\n",
+ "c2=Complex()\n",
+ "c3=Complex()\n",
+ "print \"Enter Complex Number c1...\"\n",
+ "c1.getdata()\n",
+ "print \"Enter Complex Number c2...\"\n",
+ "c2.getdata()\n",
+ "c3=c1.AddComplex(c2)\n",
+ "c3.outdata(\"c3 = c1.AddComplex(c2) : \")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 2.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 2.0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c2...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 3.0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 1.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c3 = c1.AddComplex(c2) : (5.5, 3.5)\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex2.cpp, Page no-484"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __add__(self, c2):\n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real+c2._Complex__real\n",
+ " temp._Complex__imag=self._Complex__imag+c2._Complex__imag\n",
+ " return temp\n",
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def __init__(self):\n",
+ " self.__real=self.__imag=0\n",
+ " def getdata(self):\n",
+ " self.__real=float(raw_input(\"Real part ? \"))\n",
+ " self.__imag=float(raw_input(\"Imag part ? \"))\n",
+ " #overloading + operator\n",
+ " __add__=__add__\n",
+ " def outdata(self, msg):\n",
+ " print \"%s(%0.1f, %0.1f)\" %(msg, self.__real, self.__imag)\n",
+ "c1=Complex()\n",
+ "c2=Complex()\n",
+ "c3=Complex()\n",
+ "print \"Enter Complex Number c1...\"\n",
+ "c1.getdata()\n",
+ "print \"Enter Complex Number c2...\"\n",
+ "c2.getdata()\n",
+ "c3=c1+c2 #invoking the overloaded + operator\n",
+ "c3.outdata(\"c3 = c1 + c2: \")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 2.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 2.0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c2...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 3.0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 1.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c3 = c1 + c2: (5.5, 3.5)\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex3.cpp, Page no-487"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __add__(self, c2):\n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real+c2._Complex__real\n",
+ " temp._Complex__imag=self._Complex__imag+c2._Complex__imag\n",
+ " return temp\n",
+ "def __sub__(self, c2):\n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real-c2._Complex__real\n",
+ " temp._Complex__imag=self._Complex__imag-c2._Complex__imag\n",
+ " return temp\n",
+ "def __mul__(self, c2):\n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real*c2._Complex__real-self._Complex__imag*c2._Complex__imag\n",
+ " temp._Complex__imag=self._Complex__real*c2._Complex__imag+self._Complex__imag*c2._Complex__real\n",
+ " return temp\n",
+ "def __div__(self, c2):\n",
+ " temp=Complex()\n",
+ " qt=c2._Complex__real*c2._Complex__real+c2._Complex__imag *c2._Complex__imag\n",
+ " temp._Complex__real=(self._Complex__real*c2._Complex__real+self._Complex__imag*c2._Complex__imag)/qt\n",
+ " temp._Complex__imag=(self._Complex__imag*c2._Complex__real-self._Complex__real*c2._Complex__imag)/qt\n",
+ " return temp\n",
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def __init__(self):\n",
+ " self.__real=self.__imag=0\n",
+ " def getdata(self):\n",
+ " self.__real=float(raw_input(\"Real part ? \"))\n",
+ " self.__imag=float(raw_input(\"Imag part ? \"))\n",
+ " #overloading +, -, * and / operator\n",
+ " __add__=__add__\n",
+ " __sub__=__sub__\n",
+ " __mul__=__mul__\n",
+ " __div__=__div__\n",
+ " def outdata(self, msg):\n",
+ " print \"%s(%g, %g)\" %(msg, self.__real, self.__imag)\n",
+ "c1=Complex()\n",
+ "c2=Complex()\n",
+ "c3=Complex()\n",
+ "print \"Enter Complex Number c1...\"\n",
+ "c1.getdata()\n",
+ "print \"Enter Complex Number c2...\"\n",
+ "c2.getdata()\n",
+ "print \"Entered Complex numbers are...\"\n",
+ "c1.outdata(\"c1 = \")\n",
+ "c2.outdata(\"c2 = \")\n",
+ "print \"Computational results are...\"\n",
+ "c3=c1+c2 #invoking the overloaded + operator\n",
+ "c3.outdata(\"c3 = c1 + c2: \")\n",
+ "c3=c1-c2 #invoking the overloaded - operator\n",
+ "c3.outdata(\"c3 = c1 - c2: \")\n",
+ "c3=c1*c2 #invoking the overloaded * operator\n",
+ "c3.outdata(\"c3 = c1 * c2: \")\n",
+ "c3=c1/c2 #invoking the overloaded / operator\n",
+ "c3.outdata(\"c3 = c1 / c2: \")\n",
+ "c3 = c1 + c2 + c1 + c2\n",
+ "c3.outdata(\"c3 = c1 + c2 + c1 + c2: \")\n",
+ "c3 = c1 * c2 + c1 / c2\n",
+ "c3.outdata(\"c3 = c1 * c2 + c1 / c2: \")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 2.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 2.0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c2...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 3.0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 1.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Entered Complex numbers are...\n",
+ "c1 = (2.5, 2)\n",
+ "c2 = (3, 1.5)\n",
+ "Computational results are...\n",
+ "c3 = c1 + c2: (5.5, 3.5)\n",
+ "c3 = c1 - c2: (-0.5, 0.5)\n",
+ "c3 = c1 * c2: (4.5, 9.75)\n",
+ "c3 = c1 / c2: (0.933333, 0.2)\n",
+ "c3 = c1 + c2 + c1 + c2: (11, 7)\n",
+ "c3 = c1 * c2 + c1 / c2: (5.43333, 9.95)\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-string.cpp, Page no-490"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "BUFF_SIZE=50\n",
+ "class string:\n",
+ " __Str=[None]*BUFF_SIZE\n",
+ " def __init__(self, MyStr=None):\n",
+ " if isinstance(MyStr, str):\n",
+ " self.__Str=MyStr\n",
+ " else:\n",
+ " self.__Str=\"\"\n",
+ " def echo(self):\n",
+ " print self.__Str\n",
+ " def __add__(self, s):\n",
+ " temp=string(self._string__Str)\n",
+ " temp._string__Str+=s._string__Str\n",
+ " return temp\n",
+ "str1=string(\"Welcome to \")\n",
+ "str2=string(\"Operator Overloading\")\n",
+ "str3=string()\n",
+ "print \"Before str3 = str1 + str2;..\"\n",
+ "print \"str1 = \",\n",
+ "str1.echo()\n",
+ "print \"str2 = \",\n",
+ "str2.echo()\n",
+ "print \"str3 = \",\n",
+ "str3.echo()\n",
+ "str3=str1+str2\n",
+ "print \"After str3 = str1 + str2;..\"\n",
+ "print \"str1 = \",\n",
+ "str1.echo()\n",
+ "print \"str2 = \",\n",
+ "str2.echo()\n",
+ "print \"str3 = \",\n",
+ "str3.echo()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Before str3 = str1 + str2;..\n",
+ "str1 = Welcome to \n",
+ "str2 = Operator Overloading\n",
+ "str3 = \n",
+ "After str3 = str1 + str2;..\n",
+ "str1 = Welcome to \n",
+ "str2 = Operator Overloading\n",
+ "str3 = Welcome to Operator Overloading\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-idxcmp.cpp, Page no-491"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "(false, true)=(0, 1) #enum type\n",
+ "type =['false', 'true']\n",
+ "class Index:\n",
+ " __value=int\n",
+ " def __init__(self, val=0):\n",
+ " self.__value=val\n",
+ " def GetIndex(self):\n",
+ " return self.__value\n",
+ " #overloading < operator\n",
+ " def __lt__(self, idx):\n",
+ " return true if self.__value<idx.__value else false #?: operator\n",
+ "idx1=Index(5)\n",
+ "idx2=Index(10)\n",
+ "print 'Index1 =', idx1.GetIndex()\n",
+ "print \"Index2 =\", idx2.GetIndex()\n",
+ "if idx1<idx2: #using the overloaded < operator\n",
+ " print \"Index1 is less than Index2\"\n",
+ "else:\n",
+ " print \"Index1 is not less than Index2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Index1 = 5\n",
+ "Index2 = 10\n",
+ "Index1 is less than Index2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-strcmp.cpp, Page no-493"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "(false, true)=(0, 1) #enum type\n",
+ "type =['false', 'true']\n",
+ "BUFF_SIZE=50\n",
+ "class string:\n",
+ " __Str=[None]*BUFF_SIZE\n",
+ " def __init__(self):\n",
+ " self.__Str=\"\"\n",
+ " def read(self):\n",
+ " self.__Str=raw_input()\n",
+ " def echo(self):\n",
+ " print self.__Str,\n",
+ " #overloading < operator\n",
+ " def __lt__(self, s):\n",
+ " if self.__Str < s.__Str:\n",
+ " return true\n",
+ " else:\n",
+ " return false\n",
+ " #overloading > operator\n",
+ " def __gt__(self, s):\n",
+ " if self.__Str > s.__Str:\n",
+ " return true\n",
+ " else:\n",
+ " return false\n",
+ " #overloading == operator\n",
+ " def __eq__(self, MyStr):\n",
+ " if self.__Str ==MyStr:\n",
+ " return true\n",
+ " else:\n",
+ " return false\n",
+ "str1=string()\n",
+ "str2=string()\n",
+ "while(1):\n",
+ " print \"Enter String1 <'end' to stop>:\",\n",
+ " str1.read()\n",
+ " if str1==\"end\": #using overloaded == operator\n",
+ " break\n",
+ " print 'Enter String2:',\n",
+ " str2.read()\n",
+ " print 'Comparison status:',\n",
+ " str1.echo()\n",
+ " if str1<str2: #using overloaded < operator\n",
+ " print \"<\",\n",
+ " elif str1>str2:\n",
+ " print \">\", #using overloaded > operator\n",
+ " else:\n",
+ " print \"=\",\n",
+ " str2.echo()\n",
+ " print \"\"\n",
+ "print \"Bye.!! That's all folks.!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter String1 <'end' to stop>:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter String2:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C++\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Comparison status: C < C++ \n",
+ "Enter String1 <'end' to stop>:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rajkumar\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter String2:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bindu\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Comparison status: Rajkumar > Bindu \n",
+ "Enter String1 <'end' to stop>:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rajkumar\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter String2:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Venugopal\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Comparison status: Rajkumar < Venugopal \n",
+ "Enter String1 <'end' to stop>:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "HELLO\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter String2:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "HELLO\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Comparison status: HELLO = HELLO \n",
+ "Enter String1 <'end' to stop>:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "end\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Bye.!! That's all folks.!\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex4.cpp, Page no-495"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __iadd__(self, c2):\n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real+c2._Complex__real\n",
+ " temp._Complex__imag=self._Complex__imag+c2._Complex__imag\n",
+ " return temp\n",
+ "def __isub__(self, c2):\n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real-c2._Complex__real\n",
+ " temp._Complex__imag=self._Complex__imag-c2._Complex__imag\n",
+ " return temp\n",
+ "def __imul__(self, c2):\n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real*c2._Complex__real-self._Complex__imag*c2._Complex__imag\n",
+ " temp._Complex__imag=self._Complex__real*c2._Complex__imag+self._Complex__imag*c2._Complex__real\n",
+ " return temp\n",
+ "def __idiv__(self, c2):\n",
+ " temp=Complex()\n",
+ " qt=c2._Complex__real*c2._Complex__real+c2._Complex__imag *c2._Complex__imag\n",
+ " temp._Complex__real=(self._Complex__real*c2._Complex__real+self._Complex__imag*c2._Complex__imag)/qt\n",
+ " temp._Complex__imag=(self._Complex__imag*c2._Complex__real-self._Complex__real*c2._Complex__imag)/qt\n",
+ " return temp\n",
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def __init__(self):\n",
+ " self.__real=self.__imag=0\n",
+ " def getdata(self):\n",
+ " self.__real=float(raw_input(\"Real part ? \"))\n",
+ " self.__imag=float(raw_input(\"Imag part ? \"))\n",
+ " #overloading +=, -=, *= and /= operator\n",
+ " __iadd__=__iadd__\n",
+ " __isub__=__isub__\n",
+ " __imul__=__imul__\n",
+ " __idiv__=__idiv__\n",
+ " def outdata(self, msg):\n",
+ " print \"%s(%g, %g)\" %(msg, self.__real, self.__imag)\n",
+ "c1=Complex()\n",
+ "c2=Complex()\n",
+ "c3=Complex()\n",
+ "print \"Enter Complex Number c1...\"\n",
+ "c1.getdata()\n",
+ "print \"Enter Complex Number c2...\"\n",
+ "c2.getdata()\n",
+ "print \"Entered Complex numbers are...\"\n",
+ "c1.outdata(\"c1 = \")\n",
+ "c2.outdata(\"c2 = \")\n",
+ "print \"Computational results are...\"\n",
+ "c3=c1 \n",
+ "c3+=c2 #invoking the overloaded += operator\n",
+ "c3.outdata(\"let c3 = c1, c3+=c2: \")\n",
+ "c3=c1 \n",
+ "c3-=c2 #invoking the overloaded -= operator\n",
+ "c3.outdata(\"let c3 = c1, c3-=c2: \")\n",
+ "c3=c1 \n",
+ "c3*=c2 #invoking the overloaded *= operator\n",
+ "c3.outdata(\"let c3 = c1, c3*=c2: \")\n",
+ "c3=c1 \n",
+ "c3/=c2 #invoking the overloaded / operator\n",
+ "c3.outdata(\"let c3 = c1, c3/=c2: \")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 2.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 2.0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c2...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 3.0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 1.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Entered Complex numbers are...\n",
+ "c1 = (2.5, 2)\n",
+ "c2 = (3, 1.5)\n",
+ "Computational results are...\n",
+ "let c3 = c1, c3+=c2: (5.5, 3.5)\n",
+ "let c3 = c1, c3-=c2: (-0.5, 0.5)\n",
+ "let c3 = c1, c3*=c2: (4.5, 9.75)\n",
+ "let c3 = c1, c3/=c2: (0.933333, 0.2)\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex-5.cpp, Page no-498"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __iadd__(self, c2):\n",
+ " self._Complex__real=self._Complex__real+c2._Complex__real\n",
+ " self._Complex__imag=self._Complex__imag+c2._Complex__imag\n",
+ " return self\n",
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def __init__(self):\n",
+ " self.__real=self.__imag=0\n",
+ " def getdata(self):\n",
+ " self.__real=float(raw_input(\"Real part ? \"))\n",
+ " self.__imag=float(raw_input(\"Imag part ? \"))\n",
+ " #overloading += operator\n",
+ " __iadd__=__iadd__\n",
+ " def outdata(self, msg):\n",
+ " print \"%s(%g, %g)\" %(msg, self.__real, self.__imag)\n",
+ "c1=Complex()\n",
+ "c2=Complex()\n",
+ "c3=Complex()\n",
+ "print \"Enter Complex Number c1...\"\n",
+ "c1.getdata()\n",
+ "print \"Enter Complex Number c2...\"\n",
+ "c2.getdata()\n",
+ "c1 += c2 #using overloaded += operator\n",
+ "c3 = c1\n",
+ "print \"On execution of c3 = c1 += c2..\"\n",
+ "c1.outdata(\"Complex c1: \")\n",
+ "c2.outdata(\"Complex c2: \")\n",
+ "c3.outdata(\"Complex c3: \")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 2.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 2.0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c2...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 3.0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 1.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On execution of c3 = c1 += c2..\n",
+ "Complex c1: (5.5, 3.5)\n",
+ "Complex c2: (3, 1.5)\n",
+ "Complex c3: (5.5, 3.5)\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-resource.cpp, Page no-499"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ARRAY_SIZE=10\n",
+ "def read(self):\n",
+ " for i in range(ARRAY_SIZE):\n",
+ " print \"vector[\", i, \"] = ? \",\n",
+ " self._vector__array[i]=int(raw_input())\n",
+ "def sum(self):\n",
+ " Sum=0\n",
+ " for i in range(ARRAY_SIZE):\n",
+ " Sum+=self._vector__array[i]\n",
+ " return Sum\n",
+ "class vector:\n",
+ " __array=[int]\n",
+ " def new(self):\n",
+ " myvector=vector()\n",
+ " myvector.__array=[int]*ARRAY_SIZE\n",
+ " return myvector\n",
+ " def delete(self):\n",
+ " del self\n",
+ " read=read\n",
+ " sum=sum\n",
+ "my_vector=vector()\n",
+ "my_vector=my_vector.new()\n",
+ "print \"Enter Vector data...\"\n",
+ "my_vector.read()\n",
+ "print \"Sum of Vector =\", my_vector.sum()\n",
+ "del my_vector"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Vector data...\n",
+ "vector[ 0 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " vector[ 1 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " vector[ 2 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " vector[ 3 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " vector[ 4 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " vector[ 5 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " vector[ 6 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " vector[ 7 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " vector[ 8 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " vector[ 9 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Sum of Vector = 55\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-meter.cpp, Page no-504"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Meter:\n",
+ " __length=float\n",
+ " def __init__(self, InitLength=0.0):\n",
+ " self.__length=InitLength/100.0\n",
+ " def float(self):\n",
+ " LengthCms=self.__length*100.0\n",
+ " return LengthCms\n",
+ " def GetLength(self):\n",
+ " self.__length=float(raw_input(\"Enter Length (in meters): \"))\n",
+ " def ShowLength(self):\n",
+ " print \"Length (in meter) =\", self.__length\n",
+ "length1=float(raw_input(\"Enter Lenthg (in cms): \"))\n",
+ "meter1=Meter(length1)\n",
+ "meter1.ShowLength()\n",
+ "meter2=Meter()\n",
+ "length2=float\n",
+ "meter2.GetLength()\n",
+ "length2=meter2.float()\n",
+ "print \"Length (in cms) =\", length2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Lenthg (in cms): 150.0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Length (in meter) = 1.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Length (in meters): 1.669\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Length (in cms) = 166.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-strconv.cpp, Page no-506"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "BUFF_SIZE=50\n",
+ "class string:\n",
+ " __Str=[None]*BUFF_SIZE\n",
+ " def __init__(self, MyStr=None):\n",
+ " if isinstance(MyStr, str):\n",
+ " self.__Str=MyStr\n",
+ " else:\n",
+ " self.__Str=\"\"\n",
+ " def echo(self):\n",
+ " print self.__Str\n",
+ " def char(self):\n",
+ " return self.__Str\n",
+ "msg=\"OOPs the Great\"\n",
+ "str1=string(msg)\n",
+ "print \"str1 =\",\n",
+ "str1.echo()\n",
+ "str2=string(\"It is nice to learn\")\n",
+ "receive=str2.char()\n",
+ "print \"Str2 =\", receive"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "str1 = OOPs the Great\n",
+ "Str2 = It is nice to learn\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-d2r1.cpp, Page no-509 "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI=3.141592654\n",
+ "class Radian:\n",
+ " __rad=float\n",
+ " def __init__(self, InitRad=0.0):\n",
+ " self.__rad=InitRad\n",
+ " def GetRadian(self):\n",
+ " return self.__rad\n",
+ " def Output(self):\n",
+ " print \"Radian =\", self.GetRadian()\n",
+ "class Degree:\n",
+ " __degree=float\n",
+ " def __init__(self):\n",
+ " self.__degree=0.0\n",
+ " def Radian(self):\n",
+ " return ( Radian(self.__degree * PI / 180.0))\n",
+ " def Input(self):\n",
+ " self.__degree=float(raw_input(\"Enter degree: \"))\n",
+ "deg1=Degree()\n",
+ "deg1.Input()\n",
+ "rad1=deg1.Radian()\n",
+ "rad1.Output()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter degree: 180\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Radian = 3.141592654\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-d2r2.cpp, Page no-512"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI=3.141592654\n",
+ "class Degree:\n",
+ " __degree=float\n",
+ " def __init__(self):\n",
+ " self.__degree=0.0\n",
+ " def GetDegree(self):\n",
+ " return self.__degree\n",
+ " def Input(self):\n",
+ " self.__degree=float(raw_input(\"Enter degree: \"))\n",
+ "class Radian:\n",
+ " __rad=float\n",
+ " def __init__(self, deg=None):\n",
+ " if isinstance(deg , Degree):\n",
+ " self.__rad=deg.GetDegree()*PI/180.0\n",
+ " else:\n",
+ " self.__rad=0.0\n",
+ " def GetRadian(self):\n",
+ " return self.__rad\n",
+ " def Output(self):\n",
+ " print \"Radian =\", self.GetRadian()\n",
+ "deg1=Degree()\n",
+ "deg1.Input()\n",
+ "rad1=Radian(deg1)\n",
+ "rad1.Output()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter degree: 90\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Radian = 1.570796327\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-degrad.cpp, Page no-514"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI=3.141592654\n",
+ "class Radian:\n",
+ " __rad=float\n",
+ " def __init__(self, InitRad=0.0):\n",
+ " self.__rad=InitRad\n",
+ " def GetRadian(self):\n",
+ " return self.__rad\n",
+ " def Input(self):\n",
+ " self.__rad=float(raw_input(\"Enter radian: \"))\n",
+ " def Output(self):\n",
+ " print \"Radian =\", self.GetRadian()\n",
+ "class Degree:\n",
+ " __degree=float\n",
+ " def __init__(self, rad=None):\n",
+ " if isinstance(rad, Radian):\n",
+ " self.__degree=rad.GetRadian()*180.0/PI\n",
+ " else:\n",
+ " self.__degree=0.0\n",
+ " def GetDegree(self):\n",
+ " return self.__degree\n",
+ " def Radian(self):\n",
+ " return ( Radian(self.__degree * PI / 180.0))\n",
+ " def Input(self):\n",
+ " self.__degree=float(raw_input(\"Enter degree: \"))\n",
+ " def Output(self):\n",
+ " print \"Degree =\", self.__degree\n",
+ "deg1=Degree()\n",
+ "deg1.Input()\n",
+ "rad1=deg1.Radian()\n",
+ "rad1.Output()\n",
+ "rad2=Radian()\n",
+ "rad2.Input()\n",
+ "deg2=Degree(rad2)\n",
+ "deg2.Output()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter degree: 180\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Radian = 3.141592654\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter radian: 3.142\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Degree = 180.023339207\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-script.cpp, Page no-516"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class AccountEntry(Structure):\n",
+ " _fields_=[('number',c_int), ('name', c_char*25)]\n",
+ "class AccountBook:\n",
+ " __aCount=int\n",
+ " __account=[AccountEntry]\n",
+ " def __init__(self, aCountIn):\n",
+ " self.__aCount=aCountIn\n",
+ " for i in range(self.__aCount):\n",
+ " self.__account.append(AccountEntry())\n",
+ " def op(self, nameIn):\n",
+ " if isinstance(nameIn, str):\n",
+ " for i in range(self.__aCount):\n",
+ " if nameIn==self.__account[i].name:\n",
+ " return self.__account[i].number\n",
+ " elif isinstance(nameIn, int): #numberIn\n",
+ " for i in range(self.__aCount):\n",
+ " #print self.__account[i].number\n",
+ " if nameIn==self.__account[i].number:\n",
+ " return self.__account[i].name\n",
+ " def AccountEntry(self):\n",
+ " for i in range(self.__aCount):\n",
+ " self.__account[i].number=int(raw_input(\"Account Number: \"))\n",
+ " self.__account[i].name=raw_input(\"Account Holder Name: \")\n",
+ "accounts=AccountBook(5)\n",
+ "print \"Building 5 Customers Database\"\n",
+ "accounts.AccountEntry()\n",
+ "print \"Accessing Accounts Information\"\n",
+ "accno=int(raw_input(\"To access Name Enter Account Number: \"))\n",
+ "print \"Name:\",accounts.op(accno) #accounts[accno]\n",
+ "name=raw_input(\"To access Account Number, Enter Name: \")\n",
+ "print \"Account Number:\",accounts.op(name) #accounts[name]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Building 5 Customers Database\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Account Number: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Account Holder Name: Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Account Number: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Account Holder Name: Kiran\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Account Number: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Account Holder Name: Ravishanker\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Account Number: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Account Holder Name: Anand\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Account Number: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Account Holder Name: Sindhu\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Accessing Accounts Information\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "To access Name Enter Account Number: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "To access Account Number, Enter Name: Sindhu\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Account Number: 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex6.cpp, Page no-519"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def readdata(self):\n",
+ " self._Complex__real=float(raw_input(\"Real part ? \"))\n",
+ " self._Complex__imag=float(raw_input(\"Imag part ? \"))\n",
+ "def outdata(self, msg):\n",
+ " print \"%s(%g, %g)\" %(msg, self._Complex__real, self._Complex__imag)\n",
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def __init__(self):\n",
+ " self.__real=self.__imag=0\n",
+ " readdata=readdata\n",
+ " outdata=outdata\n",
+ " def __neg__(self):\n",
+ " return neg(self)\n",
+ "#friend function overloading unary minus operator\n",
+ "def neg(c1):\n",
+ " c=Complex()\n",
+ " c._Complex__real=-c1._Complex__real\n",
+ " c._Complex__imag=-c1._Complex__imag\n",
+ " return c\n",
+ "c1=Complex()\n",
+ "c2=Complex()\n",
+ "print \"Enter Complex Number c1...\"\n",
+ "c1.readdata()\n",
+ "c2=-c1\n",
+ "c1.outdata(\"Complex c1 : \")\n",
+ "c2.outdata(\"Complex c2 = -Complex c1: \")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 1.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? -2.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Complex c1 : (1.5, -2.5)\n",
+ "Complex c2 = -Complex c1: (-1.5, 2.5)\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex7.cpp, Page no-520"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def readdata(self):\n",
+ " self._Complex__real=float(raw_input(\"Real part ? \"))\n",
+ " self._Complex__imag=float(raw_input(\"Imag part ? \"))\n",
+ "def outdata(self, msg):\n",
+ " print \"%s(%g, %g)\" %(msg, self._Complex__real, self._Complex__imag)\n",
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def __init__(self):\n",
+ " self.__real=self.__imag=0\n",
+ " readdata=readdata\n",
+ " outdata=outdata\n",
+ " def __neg__(self):\n",
+ " return neg(self)\n",
+ "#friend function overloading unary minus operator\n",
+ "def neg(c1):\n",
+ " c1._Complex__real=-c1._Complex__real\n",
+ " c1._Complex__imag=-c1._Complex__imag\n",
+ "c1=Complex()\n",
+ "print \"Enter Complex Number c1...\"\n",
+ "c1.readdata()\n",
+ "-c1\n",
+ "c1.outdata(\"Complex c1 : \")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 1.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? -2.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Complex c1 : (-1.5, 2.5)\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex8.cpp, Page no-522"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def __init__(self, realpart=0):\n",
+ " if isinstance(realpart, float):\n",
+ " self.__real=realpart\n",
+ " self.__imag=0\n",
+ " def readdata(self):\n",
+ " self.__real=float(raw_input(\"Real part ? \"))\n",
+ " self.__imag=float(raw_input(\"Imag part ? \"))\n",
+ " def outdata(self, msg):\n",
+ " print \"%s(%g, %g)\" %(msg, self.__real, self.__imag)\n",
+ " def __add__(self, c2):\n",
+ " return add(self, c2)\n",
+ "#friend function overloading + operator\n",
+ "def add(c1, c2):\n",
+ " c=Complex()\n",
+ " c._Complex__real=c1._Complex__real+c2._Complex__real\n",
+ " c._Complex__imag=c1._Complex__imag+c2._Complex__imag\n",
+ " return c\n",
+ "c1=Complex()\n",
+ "c2=Complex()\n",
+ "c3=Complex(3)\n",
+ "print \"Enter Complex Number c1...\"\n",
+ "c1.readdata()\n",
+ "print \"Enter Complex Number c2...\"\n",
+ "c2.readdata()\n",
+ "c3=c1+c2\n",
+ "c3.outdata(\"Result of c3 = c1 + c2: \")\n",
+ "c3=c1+Complex(2.0)\n",
+ "c3.outdata(\"Result of c3 = c1 + 2.0: \")\n",
+ "c3=Complex(3.0)+c2\n",
+ "c3.outdata(\"Result of c3 = 3.0 + c2: \")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c2...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Result of c3 = c1 + c2: (4, 6)\n",
+ "Result of c3 = c1 + 2.0: (3, 2)\n",
+ "Result of c3 = 3.0 + c2: (6, 4)\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex9.cpp, Page no-525"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Complex:\n",
+ " __real=float\n",
+ " __imag=float\n",
+ " def __init__(self, InReal=0):\n",
+ " if isinstance(InReal, float):\n",
+ " self.__real=InReal\n",
+ " self.__imag=0\n",
+ " def readdata(self):\n",
+ " self.__real=float(raw_input(\"Real part ? \"))\n",
+ " self.__imag=float(raw_input(\"Imag part ? \"))\n",
+ " def outdata(self, msg):\n",
+ " print \"%s(%g, %g)\" %(msg, self.__real, self.__imag)\n",
+ " def __add__(self, c2):\n",
+ " return add(self, c2)\n",
+ "#friend function overloading + operator\n",
+ "def add(c1, c2):\n",
+ " c=Complex()\n",
+ " c._Complex__real=c1._Complex__real+c2._Complex__real\n",
+ " c._Complex__imag=c1._Complex__imag+c2._Complex__imag\n",
+ " return c\n",
+ "c1=Complex()\n",
+ "c2=Complex()\n",
+ "c3=Complex(3)\n",
+ "print \"Enter Complex Number c1...\"\n",
+ "c1.readdata()\n",
+ "print \"Enter Complex Number c2...\"\n",
+ "c2.readdata()\n",
+ "c3=c1+c2\n",
+ "c3.outdata(\"Result of c3 = c1 + c2: \")\n",
+ "c3=c1+Complex(2.0)\n",
+ "c3.outdata(\"Result of c3 = c1 + 2.0: \")\n",
+ "c3=Complex(3.0)+c2\n",
+ "c3.outdata(\"Result of c3 = 3.0 + c2: \")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c2...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Result of c3 = c1 + c2: (4, 6)\n",
+ "Result of c3 = c1 + 2.0: (3, 2)\n",
+ "Result of c3 = 3.0 + c2: (6, 4)\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vector.cpp, Page no-528"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "def __assign__(self, v2):\n",
+ " print \"Assignment operation invoked\"\n",
+ " for i in range(v2._vector__size):\n",
+ " self._vector__v[i]=v2._vector__v[i]\n",
+ "def show(self):\n",
+ " for i in range(self._vector__size):\n",
+ " print self.elem(i), \",\",\n",
+ "class vector:\n",
+ " __v=[int]\n",
+ " __size=int\n",
+ " def __init__(self, vector_size):\n",
+ " if isinstance(vector_size, int):\n",
+ " self.__size=vector_size\n",
+ " self.__v=[int]*self.__size\n",
+ " if isinstance(vector_size, vector):\n",
+ " print \"Copy constructor invoked\"\n",
+ " self.__size=vector_size.__size\n",
+ " self.__v=[int]*self.__size\n",
+ " for i in range(vector_size.__size):\n",
+ " self.__v[i]=vector_size.__v[i]\n",
+ " def __del__(self):\n",
+ " del self.__v\n",
+ " __assign__=__assign__\n",
+ " def elem(self, i, x=None):\n",
+ " if isinstance(x, int):\n",
+ " if i>=self.__size:\n",
+ " print \"Error: Out of Range\"\n",
+ " self.__v[i]=x\n",
+ " else:\n",
+ " return self.__v[i]\n",
+ " show=show\n",
+ "v1=vector(5)\n",
+ "v2=vector(5)\n",
+ "for i in range(5):\n",
+ " v2.elem(i, i+1)\n",
+ "v1 = v2\n",
+ "v3 = vector(v2)\n",
+ "print \"Vector v1:\",\n",
+ "v1.show()\n",
+ "print \"\\nVector v2:\",\n",
+ "v2.show()\n",
+ "print \"\\nVector v3:\",\n",
+ "v3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Copy constructor invoked\n",
+ "Vector v1: 1 , 2 , 3 , 4 , 5 , \n",
+ "Vector v2: 1 , 2 , 3 , 4 , 5 , \n",
+ "Vector v3: 1 , 2 , 3 , 4 , 5 ,\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-mleak.cpp, Page no-530"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "vector=[int]*10\n",
+ "buffer=[chr]*6\n",
+ "for i in range(10):\n",
+ " vector[i]=i+1\n",
+ "buffer=\"hello\"\n",
+ "for i in range(10):\n",
+ " print vector[i],\n",
+ "print \"\\nbuffer =\", buffer\n",
+ "del vector"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 2 3 4 5 6 7 8 9 10 \n",
+ "buffer = hello\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-misuse.cpp, Page no-533"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class number:\n",
+ " __num=int\n",
+ " def read(self):\n",
+ " self.__num=int(raw_input())\n",
+ " def get(self):\n",
+ " return self.__num\n",
+ " def __add__(self, num2):\n",
+ " Sum=number()\n",
+ " Sum.__num=self.__num-num2.__num #subtraction instead of addition\n",
+ " return Sum\n",
+ "num1=number()\n",
+ "num2=number()\n",
+ "Sum=number()\n",
+ "print \"Enter Number 1: \",\n",
+ "num1.read()\n",
+ "print \"Enter Number 2: \",\n",
+ "num2.read()\n",
+ "Sum=num1+num2 #addition of two numbers\n",
+ "print \"sum = num1 + num2 =\", Sum.get()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Number 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " sum = num1 + num2 = -5\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-1, Page no-537"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __add__(self, d2):\n",
+ " temp_date=date()\n",
+ " temp_date._date__sec=self._date__sec+d2._date__sec\n",
+ " if(temp_date._date__sec>=60):\n",
+ " temp_date._date__min+=1\n",
+ " temp_date._date__sec=temp_date._date__sec-60\n",
+ " temp_date._date__min=temp_date._date__min+self._date__min+d2._date__min\n",
+ " if(temp_date._date__min>=60):\n",
+ " temp_date._date__hr+=1\n",
+ " temp_date._date__min=temp_date._date__min-60\n",
+ " temp_date._date__hr=self._date__hr+d2._date__hr\n",
+ " return temp_date\n",
+ "class date:\n",
+ " __hr=int\n",
+ " __min=int\n",
+ " __sec=int\n",
+ " def __init__(self, h=0, m=0, s=0):\n",
+ " self.__hr=h\n",
+ " self.__min=m\n",
+ " self.__sec=s\n",
+ " def show(self):\n",
+ " print \"%d hours, %d minutes, %d seconds\" %(self.__hr, self.__min, self.__sec),\n",
+ " __add__=__add__\n",
+ "date1=date(2, 4, 56)\n",
+ "date2=date(10, 59, 11)\n",
+ "date3=date()\n",
+ "date3=date1+date2\n",
+ "date1.show()\n",
+ "print \"+\",\n",
+ "date2.show()\n",
+ "print \"=\",\n",
+ "date3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2 hours, 4 minutes, 56 seconds + 10 hours, 59 minutes, 11 seconds = 12 hours, 4 minutes, 7 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-2, Page no-538"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __add__(self, b2):\n",
+ " temp_basket=basket()\n",
+ " temp_basket._basket__apples=self._basket__apples+b2._basket__apples\n",
+ " temp_basket._basket__mangoes=self._basket__mangoes+b2._basket__mangoes\n",
+ " return temp_basket\n",
+ "class basket:\n",
+ " __apples=int\n",
+ " __mangoes=int\n",
+ " def __init__(self, a=0, m=0):\n",
+ " self.__apples=a\n",
+ " self.__mangoes=m\n",
+ " def show(self):\n",
+ " print self.__apples, \" Apples and\", self.__mangoes, \" Mangoes\"\n",
+ " __add__=__add__ # overloading + operator\n",
+ "basket1=basket(7, 10)\n",
+ "basket2=basket(4, 5)\n",
+ "basket3=basket()\n",
+ "print \"Basket 1 contains:\"\n",
+ "basket1.show()\n",
+ "print \"Basket 2 contains:\"\n",
+ "basket2.show()\n",
+ "basket3=basket1+basket2 #using overloaded + operator\n",
+ "print \"Adding fruits from Basket 1 and Basket 2 results in:\"\n",
+ "basket3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Basket 1 contains:\n",
+ "7 Apples and 10 Mangoes\n",
+ "Basket 2 contains:\n",
+ "4 Apples and 5 Mangoes\n",
+ "Adding fruits from Basket 1 and Basket 2 results in:\n",
+ "11 Apples and 15 Mangoes\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter14-Inheritance.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter14-Inheritance.ipynb
new file mode 100755
index 00000000..a617fa5c
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter14-Inheritance.ipynb
@@ -0,0 +1,2736 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:63736c9aef28a6babc99661e161907400b7b80441a3f765e7ab8b6e00648ce25"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 14- Inheritance"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-bag.cpp, Page-544"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "(false, true)=(0, 1) #enum type\n",
+ "type =['false', 'true']\n",
+ "MAX_ITEMS=25\n",
+ "def IsExist(self, item):\n",
+ " for i in range(self._Bag__ItemCount):\n",
+ " if self._Bag__contents[i]==item:\n",
+ " return true\n",
+ " return false\n",
+ "def show(self):\n",
+ " for i in range(self._Bag__ItemCount):\n",
+ " print self._Bag__contents[i],\n",
+ " print \"\"\n",
+ "class Bag:\n",
+ " __contents=[int]*MAX_ITEMS #protected members\n",
+ " __ItemCount=int\n",
+ " def __init__(self):\n",
+ " self.__ItemCount=0\n",
+ " def put(self, item):\n",
+ " self.__contents[self.__ItemCount]=item\n",
+ " self.__ItemCount+=1\n",
+ " def IsEmpty(self):\n",
+ " return true if self.__ItemCount==0 else false\n",
+ " def IsFull(self):\n",
+ " return true if self.__ItemCount==MAX_ITEMS else false\n",
+ " IsExist=IsExist\n",
+ " show=show\n",
+ "bag=Bag()\n",
+ "item=int\n",
+ "while(true):\n",
+ " item=int(raw_input(\"Enter Item Number to be put into the bag <0-no item>: \"))\n",
+ " if item==0:\n",
+ " break\n",
+ " bag.put(item)\n",
+ " print \"Items in Bag:\",\n",
+ " bag.show()\n",
+ " if bag.IsFull():\n",
+ " print \"Bag Full, no more items can be placed\"\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Item Number to be put into the bag <0-no item>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Items in Bag: 1 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Item Number to be put into the bag <0-no item>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Items in Bag: 1 2 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Item Number to be put into the bag <0-no item>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Items in Bag: 1 2 3 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Item Number to be put into the bag <0-no item>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Items in Bag: 1 2 3 3 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Item Number to be put into the bag <0-no item>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Items in Bag: 1 2 3 3 1 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Item Number to be put into the bag <0-no item>: 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-union.cpp, Page no-548"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "(false, true)=(0, 1) #enum type\n",
+ "type =['false', 'true']\n",
+ "MAX_ITEMS=25\n",
+ "def IsExist(self, item):\n",
+ " for i in range(self._Bag__ItemCount):\n",
+ " if self._Bag__contents[i]==item:\n",
+ " return true\n",
+ " return false\n",
+ "def show(self):\n",
+ " for i in range(self._Bag__ItemCount):\n",
+ " print self._Bag__contents[i],\n",
+ " print \"\"\n",
+ "class Bag:\n",
+ " #protected members\n",
+ " __ItemCount=int\n",
+ " def __init__(self):\n",
+ " self.__ItemCount=0\n",
+ " self.__contents=[int]*MAX_ITEMS\n",
+ " def put(self, item):\n",
+ " self.__contents[self.__ItemCount]=item\n",
+ " self.__ItemCount+=1\n",
+ " def IsEmpty(self):\n",
+ " return true if self.__ItemCount==0 else false\n",
+ " def IsFull(self):\n",
+ " return true if self.__ItemCount==MAX_ITEMS else false\n",
+ " IsExist=IsExist\n",
+ " show=show\n",
+ "def read(self):\n",
+ " while(true):\n",
+ " element=int(raw_input(\"Enter Set Element <0-end>: \"))\n",
+ " if element==0:\n",
+ " break\n",
+ " self.Add(element)\n",
+ "def add(s1, s2):\n",
+ " temp = Set()\n",
+ " temp=s1\n",
+ " for i in range(s2._Bag__ItemCount):\n",
+ " if s1.IsExist(s2._Bag__contents[i])==false:\n",
+ " temp.Add(s2._Bag__contents[i])\n",
+ " return temp\n",
+ "class Set(Bag):\n",
+ " def Add(self,element):\n",
+ " if(self.IsExist(element)==false and self.IsFull()==false):\n",
+ " self.put(element)\n",
+ " read=read\n",
+ " def __assign__(self, s2):\n",
+ " for i in range(s2._Bag__ItemCount):\n",
+ " self.__contents[i]=s2.__contents[i]\n",
+ " self.__ItemCount=s2.__ItemCount\n",
+ " def __add__(self, s2):\n",
+ " return add(self, s2)\n",
+ "s1=Set()\n",
+ "s2=Set()\n",
+ "s3=Set()\n",
+ "print \"Enter Set 1 elements..\"\n",
+ "s1.read()\n",
+ "print \"Enter Set 2 elemets..\"\n",
+ "s2.read()\n",
+ "s3=s1+s2\n",
+ "print \"Union of s1 and s2 :\",\n",
+ "s3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set 1 elements..\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set 2 elemets..\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Union of s1 and s2 : 1 2 3 4 5 6 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons1.cpp, Page no-558"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B:\n",
+ " pass\n",
+ "class D(B):\n",
+ " def msg(self):\n",
+ " print \"No constructors exist in base and derived class\"\n",
+ "objd=D()\n",
+ "objd.msg()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No constructors exist in base and derived class\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons2.cpp, Page no-558"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B:\n",
+ " def __init__(self):\n",
+ " print \"No-argument constructor of base class B is executed\"\n",
+ "class D(B):\n",
+ " pass\n",
+ "objd=D()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No-argument constructor of base class B is executed\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons3.cpp, Page no-559"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B:\n",
+ " pass\n",
+ "class D(B):\n",
+ " def __init__(self):\n",
+ " print \"Constructors exist only in derived class\"\n",
+ "objd=D()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructors exist only in derived class\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons4.cpp, Page no-559"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B:\n",
+ " def __init__(self):\n",
+ " print \"No-argument constructor of base class B executed first\"\n",
+ "class D(B):\n",
+ " def __init__(self):\n",
+ " B.__init__(self)\n",
+ " print \"No-argument constructor of derived class D executed next\"\n",
+ "objd=D()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No-argument constructor of base class B executed first\n",
+ "No-argument constructor of derived class D executed next\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons5.cpp, Page no-560"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B:\n",
+ " def __init__(self, a=0):\n",
+ " if isinstance(a, int):\n",
+ " print \"One-argument constructor of the base class B\"\n",
+ " else:\n",
+ " print \"No-argument constructor of the base class B\"\n",
+ "class D(B):\n",
+ " def __init__(self, a):\n",
+ " B.__init__(self, a)\n",
+ " print \"One-argument constructor of the derived class D\"\n",
+ "objd=D(3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "One-argument constructor of the base class B\n",
+ "One-argument constructor of the derived class D\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons7.cpp, Page no-561"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B:\n",
+ " def __init__(self, a):\n",
+ " print \"One-argument constructor of the base class B\"\n",
+ "class D(B):\n",
+ " def __init__(self, a):\n",
+ " B(a)\n",
+ " print \"One-argument constructor of the derived class D\"\n",
+ "objd=D(3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "One-argument constructor of the base class B\n",
+ "One-argument constructor of the derived class D\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons8.cpp, Page no-562"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B1:\n",
+ " def __init__(self):\n",
+ " print \"No-argument constructor of the base class B1\"\n",
+ "class B2:\n",
+ " def __init__(self):\n",
+ " B1.__init__(self)\n",
+ " print \"No-argument constructor of the base class B2\"\n",
+ "class D(B2, B1):\n",
+ " def __init__(self):\n",
+ " B2.__init__(self)\n",
+ " print \"No-argument constructor of the derived class D\"\n",
+ "objd=D()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No-argument constructor of the base class B1\n",
+ "No-argument constructor of the base class B2\n",
+ "No-argument constructor of the derived class D\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons9.cpp, Page no-563"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B1:\n",
+ " def __init__(self):\n",
+ " print \"No-argument constructor of the base class B1\"\n",
+ "class B2:\n",
+ " def __init__(self):\n",
+ " print \"No-argument constructor of the base class B2\"\n",
+ "class D(B1, B2):\n",
+ " def __init__(self):\n",
+ " B1()\n",
+ " B2()\n",
+ " print \"No-argument constructor of the derived class D\"\n",
+ "objd=D()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No-argument constructor of the base class B1\n",
+ "No-argument constructor of the base class B2\n",
+ "No-argument constructor of the derived class D\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons10.cpp, Page no-563"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B1:\n",
+ " def __init__(self):\n",
+ " print \"No-argument constructor of the base class B1\"\n",
+ "class B2:\n",
+ " def __init__(self):\n",
+ " print \"No-argument constructor of the base class B2\"\n",
+ "class D(B1, B2):\n",
+ " def __init__(self):\n",
+ " B2()\n",
+ " B1()\n",
+ " print \"No-argument constructor of the derived class D\"\n",
+ "objd=D()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No-argument constructor of the base class B2\n",
+ "No-argument constructor of the base class B1\n",
+ "No-argument constructor of the derived class D\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons11.cpp, Page no-564"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B:\n",
+ " def __init__(self):\n",
+ " print \"No-argument constructor of a base class B\"\n",
+ "class D1(B):\n",
+ " def __init__(self):\n",
+ " B.__init__(self)\n",
+ " print \"No-argument constructor of a base class D1\"\n",
+ "class D2(D1):\n",
+ " def __init__(self):\n",
+ " D1.__init__(self)\n",
+ " print \"No-argument constructor of a derived class D2\"\n",
+ "objd=D2()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No-argument constructor of a base class B\n",
+ "No-argument constructor of a base class D1\n",
+ "No-argument constructor of a derived class D2\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons12.cpp, Page no-566"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B1:\n",
+ " def __init__(self):\n",
+ " print \"No-argument constructor of the base class B1\"\n",
+ " def __del__(self):\n",
+ " print \"Desctructor in the base class B1\"\n",
+ "class B2:\n",
+ " def __init__(self):\n",
+ " print \"No-argument constructor of the base class B2\"\n",
+ " def __del__(self):\n",
+ " print \"Desctructor in the base class B2\"\n",
+ "class D(B1, B2):\n",
+ " def __init__(self):\n",
+ " B1.__init__(self)\n",
+ " B2.__init__(self)\n",
+ " print \"No-argument constructor of the derived class D\"\n",
+ " def __del__(self):\n",
+ " print \"Desctructor in the derived class D\"\n",
+ " for b in self.__class__.__bases__:\n",
+ " b.__del__(self)\n",
+ "objd=D()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No-argument constructor of the base class B1\n",
+ "No-argument constructor of the base class B2\n",
+ "No-argument constructor of the derived class D\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons13.cpp, Page no-568"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B:\n",
+ " __x=int\n",
+ " __y=int\n",
+ " def __init__(self, a, b):\n",
+ " self.__x=a\n",
+ " self.__y=b\n",
+ "class D(B):\n",
+ " __a=int\n",
+ " __b=int\n",
+ " def __init__(self, p, q, r):\n",
+ " self.__a=p\n",
+ " B.__init__(self, p, q)\n",
+ " self.__b=r\n",
+ " def output(self):\n",
+ " print \"x =\", self._B__x\n",
+ " print \"y =\", self._B__y\n",
+ " print \"a =\", self.__a\n",
+ " print \"b =\", self.__b\n",
+ "objd=D(5, 10, 15)\n",
+ "objd.output()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x = 5\n",
+ "y = 10\n",
+ "a = 5\n",
+ "b = 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-runtime.cpp, Page no-570"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B:\n",
+ " __x=int\n",
+ " __y=int(0) #initialization\n",
+ " def __init__(self, a, b):\n",
+ " self.__x=self.__y+b\n",
+ " self.__y=a\n",
+ " def Print(self):\n",
+ " print \"x =\", self.__x\n",
+ " print \"y =\", self.__y\n",
+ "b = B(2, 3)\n",
+ "b.Print()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x = 3\n",
+ "y = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cons14.cpp, Page no-570"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B:\n",
+ " __x=int\n",
+ " __y=int\n",
+ " def read(self):\n",
+ " self.__x=int(raw_input(\"X in class B ? \"))\n",
+ " self.__y=int(raw_input(\"Y in class B ? \"))\n",
+ " def show(self):\n",
+ " print \"X in class B =\", self.__x\n",
+ " print \"Y in class B =\", self.__y\n",
+ "class D(B):\n",
+ " __y=int\n",
+ " __z=int\n",
+ " def read(self):\n",
+ " B.read(self)\n",
+ " self.__y=int(raw_input(\"Y in class D ? \"))\n",
+ " self.__z=int(raw_input(\"Z in class D ? \"))\n",
+ " def show(self):\n",
+ " B.show(self)\n",
+ " print \"Y in class D =\", self.__y\n",
+ " print \"Z in class D =\", self.__z\n",
+ " print \"Y of B, show from D =\", self._B__y\n",
+ "objd=D()\n",
+ "print \"Enter data for object of class D..\"\n",
+ "objd.read()\n",
+ "print \"Contents of object of class D..\"\n",
+ "objd.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for object of class D..\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X in class B ? 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Y in class B ? 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Y in class D ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Z in class D ? 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Contents of object of class D..\n",
+ "X in class B = 1\n",
+ "Y in class B = 2\n",
+ "Y in class D = 3\n",
+ "Z in class D = 4\n",
+ "Y of B, show from D = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-stack.cpp, Page no-573"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_ELEMENTS=5\n",
+ "class Stack:\n",
+ " __stack=[int]*(MAX_ELEMENTS+1)\n",
+ " __StackTop=int\n",
+ " def __init__(self):\n",
+ " self.__StackTop=0\n",
+ " def push(self, element):\n",
+ " self.__StackTop+=1\n",
+ " self.__stack[self.__StackTop]=element\n",
+ " def pop(self, element):\n",
+ " element=self.__stack[self.__StackTop]\n",
+ " self.__StackTop-=1\n",
+ " return element\n",
+ "class MyStack(Stack):\n",
+ " def push(self, element):\n",
+ " if self._Stack__StackTop<MAX_ELEMENTS:\n",
+ " Stack.push(self,element)\n",
+ " return 1\n",
+ " print \"Stack Overflow\"\n",
+ " return 0\n",
+ " def pop(self, element):\n",
+ " if self._Stack__StackTop>0:\n",
+ " element=Stack.pop(self, element)\n",
+ " return element\n",
+ " print \"Stack Underflow\"\n",
+ " return 0\n",
+ "stack=MyStack()\n",
+ "print \"Enter Integer data to put into the stack...\"\n",
+ "while(1):\n",
+ " element=int(raw_input(\"Element to Push ? \"))\n",
+ " if stack.push(element)==0:\n",
+ " break\n",
+ "print \"The Stack Contains...\"\n",
+ "element=stack.pop(element)\n",
+ "while element:\n",
+ " print \"pop:\", element\n",
+ " element=stack.pop(element)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Integer data to put into the stack...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element to Push ? 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element to Push ? 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element to Push ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element to Push ? 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element to Push ? 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element to Push ? 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Stack Overflow\n",
+ "The Stack Contains...\n",
+ "pop: 5\n",
+ "pop: 4\n",
+ "pop: 3\n",
+ "pop: 2\n",
+ "pop: 1\n",
+ "Stack Underflow\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-exam.cpp, Page no-577"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_LEN=25\n",
+ "class person:\n",
+ " __name=[chr]*MAX_LEN\n",
+ " __sex=chr\n",
+ " __age=int\n",
+ " def ReadData(self):\n",
+ " self.__name=raw_input(\"Name ? \")\n",
+ " self.__sex=str(raw_input(\"Sex ? \"))\n",
+ " self.__age=int(raw_input(\"Age ? \"))\n",
+ " def DisplayData(self):\n",
+ " print \"Name:\", self.__name\n",
+ " print \"Sex: \", self.__sex\n",
+ " print \"Age: \", self.__age\n",
+ "class student(person):\n",
+ " __RollNo=int\n",
+ " __branch=[chr]*20\n",
+ " def ReadData(self):\n",
+ " person.ReadData(self) #invoking member function ReadData of base class person\n",
+ " self.__RollNo=int(raw_input(\"Roll Number ? \"))\n",
+ " self.__branch=raw_input(\"Branch Studying ? \")\n",
+ " def DisplayData(self):\n",
+ " person.DisplayData(self) #invoking member function DisplayData of base class person\n",
+ " print \"Roll Number:\", self.__RollNo\n",
+ " print \"Branch:\", self.__branch\n",
+ "class exam(student):\n",
+ " __Sub1Marks=int\n",
+ " __Sub2Marks=int\n",
+ " def ReadData(self):\n",
+ " student.ReadData(self) #invoking member function ReadData of base class student\n",
+ " self.__Sub1Marks=int(raw_input(\"Marks scored in Subject 1 < Max:100> ? \"))\n",
+ " self.__Sub2Marks=int(raw_input(\"Marks scored in Subject 2 < Max:100> ? \"))\n",
+ " def DisplayData(self):\n",
+ " student.DisplayData(self) #invoking member function DisplayData of base class student\n",
+ " print \"Marks scored in Subject 1:\", self.__Sub1Marks\n",
+ " print \"Marks scored in Subject 2:\", self.__Sub2Marks\n",
+ " print \"Total Marks Scored:\", self.TotalMarks()\n",
+ " def TotalMarks(self):\n",
+ " return self.__Sub1Marks+self.__Sub2Marks\n",
+ "annual=exam()\n",
+ "print \"Enter data for Student...\"\n",
+ "annual.ReadData()\n",
+ "print \"Student Details...\"\n",
+ "annual.DisplayData()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for Student...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name ? Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sex ? M\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age ? 24\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll Number ? 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Branch Studying ? Computer-Technology\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Marks scored in Subject 1 < Max:100> ? 92\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Marks scored in Subject 2 < Max:100> ? 88\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Student Details...\n",
+ "Name: Rajkumar\n",
+ "Sex: M\n",
+ "Age: 24\n",
+ "Roll Number: 9\n",
+ "Branch: Computer-Technology\n",
+ "Marks scored in Subject 1: 92\n",
+ "Marks scored in Subject 2: 88\n",
+ "Total Marks Scored: 180\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-mul_inh1.cpp, Page no-580"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "class A:\n",
+ " def __init__(self):\n",
+ " sys.stdout.write('a'),\n",
+ "class B:\n",
+ " def __init__(self):\n",
+ " sys.stdout.write('b'),\n",
+ "class C(A, B):\n",
+ " def __init__(self):\n",
+ " A.__init__(self)\n",
+ " B.__init__(self)\n",
+ " sys.stdout.write('c'),\n",
+ "objc=C()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "abc"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-mul_inh2.cpp, Page no-581"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " def __init__(self, c):\n",
+ " sys.stdout.write(c),\n",
+ "class B:\n",
+ " def __init__(self, b):\n",
+ " sys.stdout.write(b),\n",
+ "class C(A, B):\n",
+ " def __init__(self, c1, c2, c3):\n",
+ " A.__init__(self, c1)\n",
+ " B.__init__(self, c2)\n",
+ " sys.stdout.write(c3),\n",
+ "objc=C('a', 'b', 'c')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "abc"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-mul_inh4.cpp, Page no-583"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "class A:\n",
+ " __ch=chr\n",
+ " def __init__(self, c):\n",
+ " self.__ch=c\n",
+ " def show(self):\n",
+ " sys.stdout.write(self.__ch),\n",
+ "class B:\n",
+ " __ch=chr\n",
+ " def __init__(self, b):\n",
+ " self.__ch=b\n",
+ " def show(self):\n",
+ " sys.stdout.write(self.__ch),\n",
+ "class C(A, B):\n",
+ " __ch=chr\n",
+ " def __init__(self, c1, c2, c3):\n",
+ " A.__init__(self, c1)\n",
+ " B.__init__(self, c2)\n",
+ " self.__ch=c3\n",
+ "objc=C('a', 'b', 'c')\n",
+ "print \"objc.A::show() = \",\n",
+ "A.show(objc)\n",
+ "print \"\\nobjc.B::show() = \",\n",
+ "B.show(objc)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "objc.A::show() = a \n",
+ "objc.B::show() = b\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-mul_inh5.cpp, Page no-584"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "class A:\n",
+ " __ch=chr\n",
+ " def __init__(self, c):\n",
+ " self.__ch=c\n",
+ " def show(self):\n",
+ " sys.stdout.write(self.__ch),\n",
+ "class B:\n",
+ " __ch=chr\n",
+ " def __init__(self, b):\n",
+ " self.__ch=b\n",
+ " def show(self):\n",
+ " sys.stdout.write(self.__ch),\n",
+ "class C(A, B):\n",
+ " __ch=chr\n",
+ " def __init__(self, c1, c2, c3):\n",
+ " A.__init__(self, c1)\n",
+ " B.__init__(self, c2)\n",
+ " self.__ch=c3\n",
+ " def show(self):\n",
+ " A.show(self)\n",
+ " B.show(self)\n",
+ " sys.stdout.write(self.__ch),\n",
+ "objc=C('a', 'b', 'c')\n",
+ "print \"objc.show() = \",\n",
+ "objc.show()\n",
+ "print \"\\nobjc.C::show() = \",\n",
+ "C.show(objc)\n",
+ "print \"\\nobjc.A::show() = \",\n",
+ "A.show(objc)\n",
+ "print \"\\nobjc.B::show() = \",\n",
+ "B.show(objc)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "objc.show() = abc \n",
+ "objc.C::show() = abc \n",
+ "objc.A::show() = a \n",
+ "objc.B::show() = b\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-publish1.cpp, Page no-586"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class publication:\n",
+ " __title=[chr]*40\n",
+ " __price=float\n",
+ " def getdata(self):\n",
+ " self.__title=raw_input(\"\\tEnter Title: \")\n",
+ " self.__price=float(raw_input(\"\\tEnter Price: \"))\n",
+ " def display(self):\n",
+ " print \"\\tTitle =\", self.__title\n",
+ " print \"\\tPrice = %g\" %(self.__price)\n",
+ "class sales:\n",
+ " __PublishSales=[]\n",
+ " def __init__(self):\n",
+ " self.__PublishSales=[float]*3\n",
+ " def getdata(self):\n",
+ " for i in range(3):\n",
+ " print \"\\tEnter Sales of\", i+1, \"Month: \",\n",
+ " self.__PublishSales[i]=float(raw_input())\n",
+ " def display(self):\n",
+ " TotalSales=0\n",
+ " for i in range(3):\n",
+ " print \"\\tSales of\", i+1, \"Month = %g\" %(self.__PublishSales[i])\n",
+ " TotalSales+=self.__PublishSales[i]\n",
+ " print \"\\tTotalSales = %g\" %(TotalSales)\n",
+ "class book(publication, sales):\n",
+ " __pages=int\n",
+ " def getdata(self):\n",
+ " publication.getdata(self)\n",
+ " self.__pages=int(raw_input(\"\\tEnter Number of Pages: \"))\n",
+ " sales.getdata(self)\n",
+ " def display(self):\n",
+ " publication.display(self)\n",
+ " print \"\\tNumber of Pages = %g\" %(self.__pages)\n",
+ " sales.display(self)\n",
+ "class tape(publication, sales):\n",
+ " __PlayTime=int\n",
+ " def getdata(self):\n",
+ " publication.getdata(self)\n",
+ " self.__PlayTime=int(raw_input(\"\\tEnter Playing Time in Minute: \"))\n",
+ " sales.getdata(self)\n",
+ " def display(self):\n",
+ " publication.display(self)\n",
+ " print \"\\tPlaying Time in Minute = %g\" %(self.__PlayTime)\n",
+ " sales.display(self)\n",
+ "class pamphlet(publication):\n",
+ " pass\n",
+ "class notice(pamphlet):\n",
+ " __whom=[chr]*20\n",
+ " def getdata(self):\n",
+ " pamphlet.getdata(self)\n",
+ " self.__whom=raw_input(\"\\tEnter Type of Distributor: \")\n",
+ " def display(self):\n",
+ " pamphlet.display(self)\n",
+ " print \"\\tType of Distributor =\", self.__whom\n",
+ "book1=book()\n",
+ "tape1=tape()\n",
+ "pamp1=pamphlet()\n",
+ "notice1=notice()\n",
+ "print \"Enter Book Publication Data...\"\n",
+ "book1.getdata()\n",
+ "print \"Enter Tape Publication Data...\"\n",
+ "tape1.getdata()\n",
+ "print \"Enter Pamhlet Publication Data...\"\n",
+ "pamp1.getdata()\n",
+ "print \"Enter Notice Publication Data...\"\n",
+ "notice1.getdata()\n",
+ "print \"Book Publication Data...\"\n",
+ "book1.display()\n",
+ "print \"Tape Publication Data...\"\n",
+ "tape1.display()\n",
+ "print \"Pamphlet Publication Data...\"\n",
+ "pamp1.display()\n",
+ "print \"Notice Publication Data...\"\n",
+ "notice1.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Book Publication Data...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Title: Microprocessor-x86-Programming\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Price: 180\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Number of Pages: 750\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Sales of 1 Month: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \tEnter Sales of 2 Month: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "500\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \tEnter Sales of 3 Month: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "800\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Tape Publication Data...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Title: Love-1947\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Price: 100\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Playing Time in Minute: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Sales of 1 Month: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "200\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \tEnter Sales of 2 Month: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "500\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \tEnter Sales of 3 Month: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "400\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Pamhlet Publication Data...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Title: Advanced-Computing-95-Conference\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Price: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Notice Publication Data...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Title: General-Meeting\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Price: 100\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Type of Distributor: Retail\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Book Publication Data...\n",
+ "\tTitle = Microprocessor-x86-Programming\n",
+ "\tPrice = 180\n",
+ "\tNumber of Pages = 750\n",
+ "\tSales of 1 Month = 1000\n",
+ "\tSales of 2 Month = 500\n",
+ "\tSales of 3 Month = 800\n",
+ "\tTotalSales = 2300\n",
+ "Tape Publication Data...\n",
+ "\tTitle = Love-1947\n",
+ "\tPrice = 100\n",
+ "\tPlaying Time in Minute = 10\n",
+ "\tSales of 1 Month = 200\n",
+ "\tSales of 2 Month = 500\n",
+ "\tSales of 3 Month = 400\n",
+ "\tTotalSales = 1100\n",
+ "Pamphlet Publication Data...\n",
+ "\tTitle = Advanced-Computing-95-Conference\n",
+ "\tPrice = 10\n",
+ "Notice Publication Data...\n",
+ "\tTitle = General-Meeting\n",
+ "\tPrice = 100\n",
+ "\tType of Distributor = Retail\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vehicle.cpp, Page no-591"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_LEN=25\n",
+ "class Vehicle:\n",
+ " __name=[chr]*MAX_LEN\n",
+ " __WheelsCount=int\n",
+ " def GetData(self):\n",
+ " self.__name=raw_input(\"Name of the Vehicle ? \")\n",
+ " self.__WheelsCount=int(raw_input(\"Wheels ? \"))\n",
+ " def DisplayData(self):\n",
+ " print \"Name of the Vehicle :\", self.__name \n",
+ " print \"Wheels :\", self.__WheelsCount\n",
+ "class LightMotor(Vehicle):\n",
+ " __SpeedLimit=int\n",
+ " def GetData(self):\n",
+ " Vehicle.GetData(self)\n",
+ " self.__SpeedLimit=int(raw_input(\"Speed Limit ? \"))\n",
+ " def DisplayData(self):\n",
+ " Vehicle.DisplayData(self)\n",
+ " print \"Speed Limit :\", self.__SpeedLimit\n",
+ "class HeavyMotor(Vehicle):\n",
+ " __permit=[chr]*MAX_LEN\n",
+ " __LoadCapacity=int\n",
+ " def GetData(self):\n",
+ " Vehicle.GetData(self)\n",
+ " self.__LoadCapacity=int(raw_input(\"Load Carrying Capacity ? \"))\n",
+ " self.__permit=raw_input(\"Permit Type ? \")\n",
+ " def DisplayData(self):\n",
+ " Vehicle.DisplayData(self)\n",
+ " print \"Load Carrying Capacity : \", self.__LoadCapacity \n",
+ " print \"Permit:\", self.__permit\n",
+ "class GearMotor(LightMotor):\n",
+ " __GearCount=int\n",
+ " def GetData(self):\n",
+ " LightMotor.GetData(self)\n",
+ " self.__GearCount=int(raw_input(\"No. of Gears ? \"))\n",
+ " def DisplayData(self):\n",
+ " LightMotor.DisplayData(self)\n",
+ " print \"Gears :\", self.__GearCount\n",
+ "class NonGearMotor(LightMotor):\n",
+ " def GetData(self):\n",
+ " LightMotor.Getdata(self)\n",
+ " def DisplayData(self):\n",
+ " LightMotor.DisplayData(self)\n",
+ "class Passenger(HeavyMotor):\n",
+ " __sitting=int\n",
+ " __standing=int\n",
+ " def GetData(self):\n",
+ " HeavyMotor.GetData(self)\n",
+ " self.__sitting=int(raw_input(\"Maximum Seats ? \"))\n",
+ " self.__standing=int(raw_input(\"Maximum Standing ? \"))\n",
+ " def DisplayData(self):\n",
+ " HeavyMotor.DisplayData(self)\n",
+ " print \"Maximum Seats:\", self.__sitting\n",
+ " print \"Maximum Standing:\", self.__standing\n",
+ "class Goods(HeavyMotor):\n",
+ " def GetData(self):\n",
+ " HeavyMotor.Getdata(self)\n",
+ " def DisplayData(self):\n",
+ " HeavyMotor.DisplayData(self)\n",
+ "vehi1=GearMotor()\n",
+ "vehi2=Passenger()\n",
+ "print \"Enter Data for Gear Motor Vehicle...\"\n",
+ "vehi1.GetData()\n",
+ "print \"Enter Data for Passenger Motor Vehicle...\"\n",
+ "vehi2.GetData()\n",
+ "print \"Data of Gear Motor Vehicle...\"\n",
+ "vehi1.DisplayData()\n",
+ "print \"Data of Passenger Motor Vehicle...\"\n",
+ "vehi2.DisplayData()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Data for Gear Motor Vehicle...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name of the Vehicle ? Maruti-Car\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wheels ? 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Speed Limit ? 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No. of Gears ? 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Data for Passenger Motor Vehicle...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name of the Vehicle ? KSRTC-BUS\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wheels ? 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Load Carrying Capacity ? 60\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Permit Type ? National\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum Seats ? 45\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum Standing ? 60\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Data of Gear Motor Vehicle...\n",
+ "Name of the Vehicle : Maruti-Car\n",
+ "Wheels : 4\n",
+ "Speed Limit : 4\n",
+ "Gears : 5\n",
+ "Data of Passenger Motor Vehicle...\n",
+ "Name of the Vehicle : KSRTC-BUS\n",
+ "Wheels : 4\n",
+ "Load Carrying Capacity : 60\n",
+ "Permit: National\n",
+ "Maximum Seats: 45\n",
+ "Maximum Standing: 60\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-int_ext.cpp, Page no-595"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_LEN=25\n",
+ "class student():\n",
+ " __RollNo=int\n",
+ " __branch=[chr]*20\n",
+ " def ReadStudentData(self):\n",
+ " self.__RollNo=int(raw_input(\"Roll Number ? \"))\n",
+ " self.__branch=raw_input(\"Branch Studying ? \")\n",
+ " def DisplayStudentData(self):\n",
+ " print \"Roll Number:\", self.__RollNo\n",
+ " print \"Branch:\", self.__branch\n",
+ "class InternalExam(student):\n",
+ " __Sub1Marks=int\n",
+ " __Sub2Marks=int\n",
+ " def ReadData(self):\n",
+ " self.__Sub1Marks=int(raw_input(\"Marks scored in Subject 1 < Max:100> ? \"))\n",
+ " self.__Sub2Marks=int(raw_input(\"Marks scored in Subject 2 < Max:100> ? \"))\n",
+ " def DisplayData(self):\n",
+ " print \"Internal Marks scored in Subject 1:\", self.__Sub1Marks\n",
+ " print \"Internal Marks scored in Subject 2:\", self.__Sub2Marks\n",
+ " print \"Internal Total Marks Scored:\", self.TotalMarks()\n",
+ " def InternalTotalMarks(self):\n",
+ " return self.__Sub1Marks+self.__Sub2Marks\n",
+ "class ExternalExam(student):\n",
+ " __Sub1Marks=int\n",
+ " __Sub2Marks=int\n",
+ " def ReadData(self):\n",
+ " self.__Sub1Marks=int(raw_input(\"Marks scored in Subject 1 < Max:100> ? \"))\n",
+ " self.__Sub2Marks=int(raw_input(\"Marks scored in Subject 2 < Max:100> ? \"))\n",
+ " def DisplayData(self):\n",
+ " print \"External Marks scored in Subject 1:\", self.__Sub1Marks\n",
+ " print \"External Marks scored in Subject 2:\", self.__Sub2Marks\n",
+ " print \"External Total Marks Scored:\", self.ExternalTotalMarks()\n",
+ " def ExternalTotalMarks(self):\n",
+ " return self.__Sub1Marks+self.__Sub2Marks\n",
+ "class result(InternalExam, ExternalExam):\n",
+ " __total=int\n",
+ " def TotalMarks(self):\n",
+ " return InternalExam.InternalTotalMarks(self)+ExternalExam.ExternalTotalMarks(self)\n",
+ "student1=result()\n",
+ "print \"Enter data for Student1...\"\n",
+ "student1.ReadStudentData()\n",
+ "print \"Enter internal marks...\"\n",
+ "InternalExam.ReadData(student1)\n",
+ "print \"Enter external marks...\"\n",
+ "ExternalExam.ReadData(student1)\n",
+ "print \"Student Details...\"\n",
+ "student1.DisplayStudentData()\n",
+ "InternalExam.DisplayData(student1)\n",
+ "ExternalExam.DisplayData(student1)\n",
+ "print \"Total Marks =\", student1.TotalMarks()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for Student1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll Number ? 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Branch Studying ? Computer-Technology\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter internal marks...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Marks scored in Subject 1 < Max:100> ? 80\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Marks scored in Subject 2 < Max:100> ? 85\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter external marks...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Marks scored in Subject 1 < Max:100> ? 89\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Marks scored in Subject 2 < Max:100> ? 90\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Student Details...\n",
+ "Roll Number: 9\n",
+ "Branch: Computer-Technology\n",
+ "Internal Marks scored in Subject 1: 80\n",
+ "Internal Marks scored in Subject 2: 85\n",
+ "Internal Total Marks Scored: 344\n",
+ "External Marks scored in Subject 1: 89\n",
+ "External Marks scored in Subject 2: 90\n",
+ "External Total Marks Scored: 179\n",
+ "Total Marks = 344\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vir.cpp, Page no-598"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class A:\n",
+ " __x=int\n",
+ " def __init__(self, i=None):\n",
+ " if isinstance(i, int):\n",
+ " self.__x=i\n",
+ " else:\n",
+ " self.__x=-1\n",
+ " def geta(self):\n",
+ " return self.__x\n",
+ "class B(A):\n",
+ " __y=int\n",
+ " def __init__(self, i, k):\n",
+ " A.__init__(self, i)\n",
+ " self.__y=k\n",
+ " def getb(self):\n",
+ " return self.__y\n",
+ " def show(self):\n",
+ " print self._A__x, self.geta(), self.getb()\n",
+ "class C(A):\n",
+ " __z=int\n",
+ " def __init__(self, i, k):\n",
+ " A.__init__(self, i)\n",
+ " self.__z=k\n",
+ " def getc(self):\n",
+ " return self.__z\n",
+ " def show(self):\n",
+ " print self._A__x, self.geta(), self.getc()\n",
+ "class D(B,C):\n",
+ " def __init__(self, i, j):\n",
+ " B.__init__(self, i, j)\n",
+ " C.__init__(self, i, j)\n",
+ " def show(self):\n",
+ " print self._A__x, self.geta(), self.getb(), self.getc(), self.getc()\n",
+ "d1=D(3, 5)\n",
+ "print \"Object d1 contents:\",\n",
+ "d1.show() #unlike C++, python executes the 1 argument constuctor of A() instead of implicit call to the no argument constructor of A()\n",
+ "b1=B(7, 9)\n",
+ "print \"Object b1 contents:\",\n",
+ "b1.show()\n",
+ "c1=C(11, 13)\n",
+ "print \"Object c1 contents:\",\n",
+ "c1.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Object d1 contents: 3 3 5 5 5\n",
+ "Object b1 contents: 7 7 9\n",
+ "Object c1 contents: 11 11 13\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sports.cpp, Page no-601"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_LEN=25\n",
+ "class person:\n",
+ " __name=[chr]*MAX_LEN\n",
+ " __sex=chr\n",
+ " __age=int\n",
+ " def ReadPerson(self):\n",
+ " self.__name=raw_input(\"Name ? \")\n",
+ " self.__sex=str(raw_input(\"Sex ? \"))\n",
+ " self.__age=int(raw_input(\"Age ? \"))\n",
+ " def DisplayPerson(self):\n",
+ " print \"Name:\", self.__name\n",
+ " print \"Sex: \", self.__sex\n",
+ " print \"Age: \", self.__age\n",
+ "class sports(person):\n",
+ " __name=[chr]*MAX_LEN\n",
+ " __score=int\n",
+ " def ReadData(self):\n",
+ " self.__name=raw_input(\"Game Played ? \")\n",
+ " self.__score=int(raw_input(\"Game Score ? \"))\n",
+ " def DisplayData(self):\n",
+ " print \"Sports Played:\", self.__name\n",
+ " print \"Game Score: \", self.__score\n",
+ " def SportsScore(self):\n",
+ " return self.__score\n",
+ "class student(person):\n",
+ " __RollNo=int\n",
+ " __branch=[chr]*20\n",
+ " def ReadData(self):\n",
+ " self.__RollNo=int(raw_input(\"Roll Number ? \"))\n",
+ " self.__branch=raw_input(\"Branch Studying ? \")\n",
+ " def DisplayData(self):\n",
+ " print \"Roll Number:\", self.__RollNo\n",
+ " print \"Branch:\", self.__branch\n",
+ "class exam(student):\n",
+ " __Sub1Marks=int\n",
+ " __Sub2Marks=int\n",
+ " def ReadData(self):\n",
+ " self.__Sub1Marks=int(raw_input(\"Marks scored in Subject 1 < Max:100> ? \"))\n",
+ " self.__Sub2Marks=int(raw_input(\"Marks scored in Subject 2 < Max:100> ? \"))\n",
+ " def DisplayData(self):\n",
+ " print \"Marks scored in Subject 1:\", self.__Sub1Marks\n",
+ " print \"Marks scored in Subject 2:\", self.__Sub2Marks\n",
+ " print \"Total Marks Scored:\", self.TotalMarks()\n",
+ " def TotalMarks(self):\n",
+ " return self.__Sub1Marks+self.__Sub2Marks\n",
+ "class result(exam, sports):\n",
+ " __total=int\n",
+ " def ReadData(self):\n",
+ " self.ReadPerson()\n",
+ " student.ReadData(self)\n",
+ " exam.ReadData(self)\n",
+ " sports.ReadData(self)\n",
+ " def DisplayData(self):\n",
+ " self.DisplayPerson()\n",
+ " student.DisplayData(self)\n",
+ " exam.DisplayData(self)\n",
+ " sports.DisplayData(self)\n",
+ " print \"Overall Performance, (exam + sports) :\",self.Percentage(), \"%\"\n",
+ " def Percentage(self):\n",
+ " return (exam.TotalMarks(self)+self.SportsScore())/3\n",
+ "Student=result()\n",
+ "print \"Enter data for Student...\"\n",
+ "Student.ReadData()\n",
+ "print \"Student Details...\"\n",
+ "Student.DisplayData()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for Student...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name ? Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sex ? M\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age ? 24\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll Number ? 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Branch Studying ? Computer-Technology\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Marks scored in Subject 1 < Max:100> ? 92\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Marks scored in Subject 2 < Max:100> ? 88\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Game Played ? Cricket\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Game Score ? 85\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Student Details...\n",
+ "Name: Rajkumar\n",
+ "Sex: M\n",
+ "Age: 24\n",
+ "Roll Number: 9\n",
+ "Branch: Computer-Technology\n",
+ "Marks scored in Subject 1: 92\n",
+ "Marks scored in Subject 2: 88\n",
+ "Total Marks Scored: 180\n",
+ "Sports Played: Cricket\n",
+ "Game Score: 85\n",
+ "Overall Performance, (exam + sports) : 88 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-nesting.cpp, Page no-605"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class B:\n",
+ " num=int\n",
+ " def __init__(self, a=None):\n",
+ " if isinstance(a, int):\n",
+ " print \"Constructor B( int a ) is invoked\"\n",
+ " self.num=a\n",
+ " else:\n",
+ " self.num=0\n",
+ "class D:\n",
+ " data1=int\n",
+ " objb=B()\n",
+ " def __init__(self, a):\n",
+ " self.objb.__init__(a)\n",
+ " self.data1=a\n",
+ " def output(self):\n",
+ " print \"Data in Object of Class S =\", self.data1\n",
+ " print \"Data in Member object of class B in class D = \",self.objb.num\n",
+ "objd = D(10)\n",
+ "objd.output()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Constructor B( int a ) is invoked\n",
+ "Data in Object of Class S = 10\n",
+ "Data in Member object of class B in class D = 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-publish2.cpp, Page no-608"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class publication:\n",
+ " __title=[chr]*40\n",
+ " __price=float\n",
+ " def getdata(self):\n",
+ " self.__title=raw_input(\"\\tEnter Title: \")\n",
+ " self.__price=float(raw_input(\"\\tEnter Price: \"))\n",
+ " def display(self):\n",
+ " print \"\\tTitle =\", self.__title\n",
+ " print \"\\tPrice = %g\" %(self.__price)\n",
+ "class sales:\n",
+ " __PublishSales=[]\n",
+ " def __init__(self):\n",
+ " self.__PublishSales=[float]*3\n",
+ " def getdata(self):\n",
+ " for i in range(3):\n",
+ " print \"\\tEnter Sales of\", i+1, \"Month: \",\n",
+ " self.__PublishSales[i]=float(raw_input())\n",
+ " def display(self):\n",
+ " TotalSales=0\n",
+ " for i in range(3):\n",
+ " print \"\\tSales of\", i+1, \"Month = %g\" %(self.__PublishSales[i])\n",
+ " TotalSales+=self.__PublishSales[i]\n",
+ " print \"\\tTotalSales = %g\" %(TotalSales)\n",
+ "class book:\n",
+ " __pages=int\n",
+ " pub=publication()\n",
+ " market=sales()\n",
+ " def getdata(self):\n",
+ " self.pub.getdata()\n",
+ " self.__pages=int(raw_input(\"\\tEnter Number of Pages: \"))\n",
+ " self.market.getdata()\n",
+ " def display(self):\n",
+ " self.pub.display()\n",
+ " print \"\\tNumber of Pages = %g\" %(self.__pages)\n",
+ " self.market.display()\n",
+ "book1=book()\n",
+ "print \"Enter Book Publication Data...\"\n",
+ "book1.getdata()\n",
+ "print \"Book Publication Data...\"\n",
+ "book1.display()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Book Publication Data...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Title: Microprocessor-x86-Programming\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Price: 180\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Number of Pages: 750\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\tEnter Sales of 1 Month: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \tEnter Sales of 2 Month: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "500\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \tEnter Sales of 3 Month: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "800\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Book Publication Data...\n",
+ "\tTitle = Microprocessor-x86-Programming\n",
+ "\tPrice = 180\n",
+ "\tNumber of Pages = 750\n",
+ "\tSales of 1 Month = 1000\n",
+ "\tSales of 2 Month = 500\n",
+ "\tSales of 3 Month = 800\n",
+ "\tTotalSales = 2300\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-1, Page no-611"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class employee:\n",
+ " emp_id=int\n",
+ " emp_name=[chr]*30\n",
+ " def getdata(self):\n",
+ " self.__emp_id=int(raw_input(\"Enter employee number: \"))\n",
+ " self.__emp_name=raw_input(\"Enter emploee name: \")\n",
+ " def displaydata(self):\n",
+ " print \"Employee Number:\", self.__emp_id, \"\\nEmployee Name:\", self.__emp_name\n",
+ "class emp_union:\n",
+ " __member_id=int\n",
+ " def getdata(self):\n",
+ " self.__member_id=int(raw_input(\"Enter member id: \"))\n",
+ " def displaydata(self):\n",
+ " print \"Member ID:\", self.__member_id\n",
+ "class emp_info(employee, emp_union):\n",
+ " __basic_salary=float\n",
+ " def getdata(self):\n",
+ " employee.getdata(self)\n",
+ " emp_union.getdata(self)\n",
+ " self.__basic_salary=int(raw_input(\"Enter basic salary: \"))\n",
+ " def displaydata(self):\n",
+ " employee.displaydata(self)\n",
+ " emp_union.displaydata(self)\n",
+ " print \"Basic Salary:\", self.__basic_salary\n",
+ "e1=emp_info()\n",
+ "e1.getdata()\n",
+ "e1.displaydata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter employee number: 23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter emploee name: Krishnan\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter member id: 443\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter basic salary: 8500\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Number: 23 \n",
+ "Employee Name: Krishnan\n",
+ "Member ID: 443\n",
+ "Basic Salary: 8500\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-2, Page no-613"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class details:\n",
+ " __name=[chr]*30\n",
+ " __address=[chr]*50\n",
+ " def getdata(self):\n",
+ " self.__name=raw_input(\"Name: \")\n",
+ " self.__address=raw_input(\"Address: \")\n",
+ " def displaydata(self):\n",
+ " print \"Name:\", self.__name,\"\\nAddress:\", self.__address\n",
+ "class student(details):\n",
+ " __marks=float\n",
+ " def getdata(self):\n",
+ " details.getdata(self)\n",
+ " self.__marks=float(raw_input(\"Percentage Marks: \"))\n",
+ " def displaydata(self):\n",
+ " details.displaydata(self)\n",
+ " print \"Percentage Marks: %g\" %(self.__marks)\n",
+ "class staff(details):\n",
+ " __salary=float\n",
+ " def getdata(self):\n",
+ " details.getdata(self)\n",
+ " self.__salary=float(raw_input(\"Salary: \"))\n",
+ " def displaydata(self):\n",
+ " details.displaydata(self)\n",
+ " print \"Salary: %g\" %(self.__salary)\n",
+ "student1=student()\n",
+ "staff1=staff()\n",
+ "print \"Enter student data:\"\n",
+ "student1.getdata()\n",
+ "print \"Enter staff data:\"\n",
+ "staff1.getdata()\n",
+ "print \"Displaying student and staff data:\"\n",
+ "student1.displaydata()\n",
+ "staff1.displaydata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student data:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Venkatesh\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address: H.No. 89, AGM Society, Bangalore\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Percentage Marks: 78.4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter staff data:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Vijayan\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address: H.No. A-2, SLR Society, Bangalore\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Salary: 25000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Displaying student and staff data:\n",
+ "Name: Venkatesh \n",
+ "Address: H.No. 89, AGM Society, Bangalore\n",
+ "Percentage Marks: 78.4\n",
+ "Name: Vijayan \n",
+ "Address: H.No. A-2, SLR Society, Bangalore\n",
+ "Salary: 25000\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter15-VirtualFunctions.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter15-VirtualFunctions.ipynb
new file mode 100755
index 00000000..885b9dee
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter15-VirtualFunctions.ipynb
@@ -0,0 +1,629 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:b2c633d473244077752ca84867fbd4b5425a7e64be9d919c65be58ffebb68245"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 15-Virtual Functions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-parent1.cpp, Page no-618"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Father:\n",
+ " __name=[chr]*20\n",
+ " def __init__(self, fname):\n",
+ " self.__name=fname\n",
+ " def show(self):\n",
+ " print \"Father name:\", self.__name\n",
+ "class Son(Father):\n",
+ " __name=[chr]*20\n",
+ " def __init__(self, sname, fname):\n",
+ " Father.__init__(self, fname)\n",
+ " self.__name=sname\n",
+ " def show(self):\n",
+ " print \"Son name:\", self.__name\n",
+ "fp=[Father]\n",
+ "f1=Father(\"Eshwarappa\")\n",
+ "fp=f1\n",
+ "fp.show()\n",
+ "s1=Son(\"Rajkumar\", \"Eshwarappa\")\n",
+ "fp=s1\n",
+ "Father.show(fp)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Father name: Eshwarappa\n",
+ "Father name: Eshwarappa\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-parent1.cpp, Page no-619"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Father():\n",
+ " __name=[chr]*20\n",
+ " def __init__(self, fname):\n",
+ " self.__name=fname\n",
+ " def show(self):\n",
+ " print \"Father name:\", self.__name\n",
+ "class Son(Father):\n",
+ " __name=[chr]*20\n",
+ " def __init__(self, sname, fname):\n",
+ " Father.__init__(self, fname)\n",
+ " self.__name=sname\n",
+ " def show(self):\n",
+ " print \"Son name:\", self.__name\n",
+ "fp=[Father]\n",
+ "f1=Father(\"Eshwarappa\")\n",
+ "fp=f1\n",
+ "fp.show()\n",
+ "s1=Son(\"Rajkumar\", \"Eshwarappa\")\n",
+ "fp=s1\n",
+ "fp.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Father name: Eshwarappa\n",
+ "Son name: Rajkumar\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-family1.cpp, Page no-622"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Father():\n",
+ " __f_age=int\n",
+ " def __init__(self, n):\n",
+ " self.__f_age=n\n",
+ " def GetAge(self):\n",
+ " return self.__f_age\n",
+ "class Son(Father):\n",
+ " __s_age=int\n",
+ " def __init__(self, n, m):\n",
+ " Father.__init__(self, n)\n",
+ " self.__s_age=m\n",
+ " def GetAge(self):\n",
+ " return self.__s_age\n",
+ " def son_func(self):\n",
+ " print \"son's own function\"\n",
+ "basep=[Father]\n",
+ "basep=Father(45)\n",
+ "print \"basep points to base object...\"\n",
+ "print \"Father's Age:\",\n",
+ "print basep.GetAge()\n",
+ "del basep\n",
+ "basep=[Son(45, 20)]\n",
+ "print \"basep points to derived object...\"\n",
+ "print \"Son's Age:\",\n",
+ "print Father.GetAge(basep[0])\n",
+ "print \"By typecasting, ((Son*) basep)...\"\n",
+ "print \"Son's age:\",basep[0].GetAge()\n",
+ "del basep\n",
+ "son1=Son(45, 20)\n",
+ "derivedp=[son1]\n",
+ "print \"accessing through derived class pointer...\"\n",
+ "print \"Son's Age:\",\n",
+ "print derivedp[0].GetAge()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "basep points to base object...\n",
+ "Father's Age: 45\n",
+ "basep points to derived object...\n",
+ "Son's Age: 45\n",
+ "By typecasting, ((Son*) basep)...\n",
+ "Son's age: 20\n",
+ "accessing through derived class pointer...\n",
+ "Son's Age: 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-family2.cpp, Page no-626"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Father():\n",
+ " __f_age=int\n",
+ " def __init__(self, n):\n",
+ " self.__f_age=n\n",
+ " def GetAge(self):\n",
+ " return self.__f_age\n",
+ "class Son(Father):\n",
+ " __s_age=int\n",
+ " def __init__(self, n, m):\n",
+ " Father.__init__(self, n)\n",
+ " self.__s_age=m\n",
+ " def GetAge(self):\n",
+ " return self.__s_age\n",
+ "basep=[Father]\n",
+ "basep=Father(45)\n",
+ "print \"Father's Age:\",\n",
+ "print basep.GetAge()\n",
+ "del basep\n",
+ "basep=[Son(45, 20)]\n",
+ "print \"Son's Age:\",\n",
+ "print basep[0].GetAge()\n",
+ "del basep"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Father's Age: 45\n",
+ "Son's Age: 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-draw.cpp, Page no-629"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class graphics:\n",
+ " def draw(self):\n",
+ " print \"point\"\n",
+ "class line(graphics):\n",
+ " def draw(self):\n",
+ " print \"line\"\n",
+ "class triangle(graphics):\n",
+ " def draw(self):\n",
+ " print \"triangle\"\n",
+ "class rectangle(graphics):\n",
+ " def draw(self):\n",
+ " print \"rectangle\"\n",
+ "class circle(graphics):\n",
+ " def draw(self):\n",
+ " print \"circle\"\n",
+ "point_obj=graphics()\n",
+ "line_obj=line()\n",
+ "tri_obj=triangle()\n",
+ "rect_obj=rectangle()\n",
+ "circle_obj=circle()\n",
+ "basep=[]\n",
+ "basep.append(point_obj)\n",
+ "basep.append(line_obj)\n",
+ "basep.append(tri_obj)\n",
+ "basep.append(rect_obj)\n",
+ "basep.append(circle_obj)\n",
+ "print \"Following figures are drawn with basep[i]->draw()...\"\n",
+ "for i in range(5):\n",
+ " basep[i].draw()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Following figures are drawn with basep[i]->draw()...\n",
+ "point\n",
+ "line\n",
+ "triangle\n",
+ "rectangle\n",
+ "circle\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-pure.cpp, Page no-632"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class AbsPerson:\n",
+ " def Service1(self, n):\n",
+ " self.Service2(n)\n",
+ " def Service2(self, n): #pure virtual function\n",
+ " pass\n",
+ "class Person(AbsPerson):\n",
+ " def Service2(self, n):\n",
+ " print \"The number of years of service:\", 58-n\n",
+ "Father=Person()\n",
+ "Son=Person()\n",
+ "Father.Service1(50)\n",
+ "Son.Service2(20)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The number of years of service: 8\n",
+ "The number of years of service: 38\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-number.cpp, Page no-633"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class number:\n",
+ " __num=int\n",
+ " def getdata(self):\n",
+ " self.__num=int(raw_input(\"Enter an integer number: \"))\n",
+ " def show(self): #pure virtual function\n",
+ " pass\n",
+ "class octnum(number):\n",
+ " def show(self):\n",
+ " print \"Octal equivalent of\", self._number__num,\"=\",oct(self._number__num)\n",
+ "class hexnum(number):\n",
+ " def show(self):\n",
+ " print \"Hexadecimal equivalent of\", self._number__num,\"=\",hex(self._number__num)\n",
+ "o1=octnum()\n",
+ "h1=hexnum()\n",
+ "o1.getdata()\n",
+ "o1.show()\n",
+ "h1.getdata()\n",
+ "h1.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an integer number: 11\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Octal equivalent of 11 = 013\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an integer number: 11\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hexadecimal equivalent of 11 = 0xb\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-family3.cpp, Page no-637"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Father():\n",
+ " __f_name=str\n",
+ " def __init__(self, fname):\n",
+ " self.__f_name=fname\n",
+ " def __del__(self):\n",
+ " del self.__f_name\n",
+ " print \"~Father() is invoked\"\n",
+ " def show(self):\n",
+ " print \"Father's name:\", self.__f_name\n",
+ "class Son(Father):\n",
+ " __s_name=str\n",
+ " def __init__(self, sname, fname):\n",
+ " Father.__init__(self, fname)\n",
+ " self.__s_name=sname\n",
+ " def __del__(self):\n",
+ " del self.__s_name\n",
+ " print \"~Son() is invoked\"\n",
+ " Father.__del__(self)\n",
+ " def show(self):\n",
+ " print \"Father's name:\", self._Father__f_name\n",
+ " print \"Son's name:\", self.__s_name\n",
+ "basep=[Father]\n",
+ "basep=Father(\"Eshwarappa\")\n",
+ "print \"basep points to base object...\"\n",
+ "basep.show()\n",
+ "del basep\n",
+ "basep=Son(\"Rajkumar\", \"Eshwarappa\")\n",
+ "print \"basep points to derived object...\"\n",
+ "basep.show()\n",
+ "del basep"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "basep points to base object...\n",
+ "Father's name: Eshwarappa\n",
+ "~Father() is invoked\n",
+ "basep points to derived object...\n",
+ "Father's name: Eshwarappa\n",
+ "Son's name: Rajkumar\n",
+ "~Son() is invoked\n",
+ "~Father() is invoked\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vptrsize.cpp, Page no-640"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class nonvirtual(Structure):\n",
+ " _fields_=[('x', c_int)]\n",
+ " def func(self):\n",
+ " pass\n",
+ "class withvirtual(Structure):\n",
+ " _fields_=[('x', c_int)]\n",
+ " def func(self):\n",
+ " pass\n",
+ "print \"sizeof( nonvirtual ) =\",sizeof(nonvirtual())\n",
+ "print \"sizeof( withvirtual ) =\",sizeof(withvirtual())"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "sizeof( nonvirtual ) = 4\n",
+ "sizeof( withvirtual ) = 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-shapes.cpp, Page no-640"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class description:\n",
+ " __information=str\n",
+ " def __init__(self, info):\n",
+ " self.__information=info\n",
+ " def show(self):\n",
+ " print self.__information,\n",
+ "class sphere(description):\n",
+ " __radius=float\n",
+ " def __init__(self, info, rad):\n",
+ " description.__init__(self, info)\n",
+ " self.__radius=rad\n",
+ " def show(self):\n",
+ " print self._description__information,\n",
+ " print \"Radius = %g\" %self.__radius\n",
+ "class cube(description):\n",
+ " __edge_length=float\n",
+ " def __init__(self, info, edg_len):\n",
+ " description.__init__(self, info)\n",
+ " self.__edge_length=edg_len\n",
+ " def show(self):\n",
+ " print self._description__information,\n",
+ " print \"Edge Length = %g\" %self.__edge_length\n",
+ "small_ball=sphere(\"mine\", 1.0)\n",
+ "beach_ball=sphere(\"plane\", 24.0)\n",
+ "plan_toid=sphere(\"moon\", 1e24)\n",
+ "crystal=cube(\"carbon\", 1e-24)\n",
+ "ice=cube(\"party\", 1.0)\n",
+ "box=cube(\"card borad\", 16.0)\n",
+ "shapes=[]\n",
+ "shapes.append(small_ball)\n",
+ "shapes.append(beach_ball)\n",
+ "shapes.append(plan_toid)\n",
+ "shapes.append(crystal)\n",
+ "shapes.append(ice)\n",
+ "shapes.append(box)\n",
+ "small_ball.show()\n",
+ "beach_ball.show()\n",
+ "plan_toid.show()\n",
+ "crystal.show()\n",
+ "ice.show()\n",
+ "box.show()\n",
+ "print \"Dynamic Invocation of show()...\"\n",
+ "for i in range(len(shapes)):\n",
+ " shapes[i].show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "mine Radius = 1\n",
+ "plane Radius = 24\n",
+ "moon Radius = 1e+24\n",
+ "carbon Edge Length = 1e-24\n",
+ "party Edge Length = 1\n",
+ "card borad Edge Length = 16\n",
+ "Dynamic Invocation of show()...\n",
+ "mine Radius = 1\n",
+ "plane Radius = 24\n",
+ "moon Radius = 1e+24\n",
+ "carbon Edge Length = 1e-24\n",
+ "party Edge Length = 1\n",
+ "card borad Edge Length = 16\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example, Page no-643"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class shape:\n",
+ " __val1=float\n",
+ " __val2=float\n",
+ " def getdata(self, a, b):\n",
+ " self.__val1=a\n",
+ " self.__val2=b\n",
+ " def display_area(self):\n",
+ " pass\n",
+ "class triangle(shape):\n",
+ " def display_area(self):\n",
+ " print \"Area of trianle =\", 0.5*self._shape__val1*self._shape__val2\n",
+ "class rectangle(shape):\n",
+ " def display_area(self):\n",
+ " print \"Area of rectanle =\", self._shape__val1*self._shape__val2\n",
+ "sptr=[shape]\n",
+ "sptr=triangle()\n",
+ "sptr.getdata(4.5, 2.2)\n",
+ "sptr.display_area()\n",
+ "sptr=rectangle()\n",
+ "sptr.getdata(4.5, 2.2)\n",
+ "sptr.display_area()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area of trianle = 4.95\n",
+ "Area of rectanle = 9.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter16-GenericProgrammingWithTemplates.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter16-GenericProgrammingWithTemplates.ipynb
new file mode 100755
index 00000000..88641652
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter16-GenericProgrammingWithTemplates.ipynb
@@ -0,0 +1,1512 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d003edbba5e427e459c859a79576baaf788de0196f037fb26a675631e1e101bf"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16-Generic Programming with Templates"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-mswap.cpp, Page no-647"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(x, y): #function overloading\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " return x, y\n",
+ "ch1, ch2=[str(x) for x in raw_input(\"Enter two characters <ch1, ch2>: \").split()]\n",
+ "ch1, ch2 = swap(ch1, ch2)\n",
+ "print \"On swapping <ch1, ch2>:\", ch1, ch2\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two characters <a, b>: \").split()]\n",
+ "a, b = swap(a, b)\n",
+ "print \"On swapping <a, b>:\", a,b\n",
+ "c, d=[float(x) for x in raw_input(\"Enter two floats <c, d>: \").split()]\n",
+ "c, d = swap(c, d)\n",
+ "print \"On swapping <c, d>:\", c, d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <ch1, ch2>: R K\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <ch1, ch2>: K R\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <a, b>: 5 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <a, b>: 10 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two floats <c, d>: 20.5 99.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <c, d>: 99.5 20.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-gswap.cpp, Page no-650"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(x, y):\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " return x, y\n",
+ "ch1, ch2=[str(x) for x in raw_input(\"Enter two characters <ch1, ch2>: \").split()]\n",
+ "ch1, ch2 = swap(ch1, ch2)\n",
+ "print \"On swapping <ch1, ch2>:\", ch1, ch2\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two characters <a, b>: \").split()]\n",
+ "a, b = swap(a, b)\n",
+ "print \"On swapping <a, b>:\", a,b\n",
+ "c, d=[float(x) for x in raw_input(\"Enter two floats <c, d>: \").split()]\n",
+ "c, d = swap(c, d)\n",
+ "print \"On swapping <c, d>:\", c, d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <ch1, ch2>: R K\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <ch1, ch2>: K R\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <a, b>: 5 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <a, b>: 10 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two floats <c, d>: 20.5 99.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <c, d>: 99.5 20.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-max1.cpp, Page no-651"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Max(a, b):\n",
+ " if a>b:\n",
+ " return a\n",
+ " else:\n",
+ " return b\n",
+ "ch1, ch2=[str(x) for x in raw_input(\"Enter two characters <ch1, ch2>: \").split()]\n",
+ "ch = Max(ch1, ch2)\n",
+ "print \"max( ch1, ch2 ):\", ch\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two characters <a, b>: \").split()]\n",
+ "c = Max(a, b)\n",
+ "print \"max( a, b ):\", c\n",
+ "f1, f2=[float(x) for x in raw_input(\"Enter two floats <f1, f2>: \").split()]\n",
+ "f3 = Max(f1, f2)\n",
+ "print \"max( f1, f2 ):\", f3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <ch1, ch2>: A B\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "max( ch1, ch2 ): B\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <a, b>: 20 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "max( a, b ): 20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two floats <f1, f2>: 20.5 30.9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "max( f1, f2 ): 30.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-max2.cpp, Page no-653"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Max(a, b):\n",
+ " if a>b:\n",
+ " return a\n",
+ " else:\n",
+ " return b\n",
+ "ch1, ch2=[str(x) for x in raw_input(\"Enter two characters <ch1, ch2>: \").split()]\n",
+ "ch = Max(ch1, ch2)\n",
+ "print \"max( ch1, ch2 ):\", ch\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two characters <a, b>: \").split()]\n",
+ "c = Max(a, b)\n",
+ "print \"max( a, b ):\", c\n",
+ "str1, str2=raw_input(\"Enter two strings <str1, str2>: \").split()\n",
+ "print \"max( str1, str2 ):\", Max(str1, str2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <ch1, ch2>: A Z\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "max( ch1, ch2 ): Z\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <a, b>: 5 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "max( a, b ): 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two strings <str1, str2>: Tejaswi Rajkumar\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "max( str1, str2 ): Tejaswi\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-bsort.cpp, Page no-654"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "[false, true]=[0, 1]\n",
+ "type=['false', 'true']\n",
+ "def swap(x, y): #function overloading\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " return x, y\n",
+ "def BubbleSort(SortData, Size):\n",
+ " swapped=true\n",
+ " for i in range(Size-1):\n",
+ " if swapped==true:\n",
+ " swapped=false\n",
+ " for j in range((Size-1)-i):\n",
+ " if SortData[j]>SortData[j+1]:\n",
+ " swapped=true\n",
+ " SortData[j], SortData[j+1]=swap(SortData[j], SortData[j+1])\n",
+ "IntNums=[int]*25\n",
+ "FloatNums=[float]*25\n",
+ "print \"Program to sort elements...\"\n",
+ "#Integer numbers sorting\n",
+ "size=int(raw_input(\"Enter the size of the integer vector <max-25>:\"))\n",
+ "print \"Enter the elements of the integer vector...\"\n",
+ "for i in range(size):\n",
+ " IntNums[i]=int(raw_input())\n",
+ "BubbleSort(IntNums, size)\n",
+ "print \"Sorted Vector:\"\n",
+ "for i in range(size):\n",
+ " print IntNums[i],\n",
+ "#Floating point numbers sorting\n",
+ "size=int(raw_input(\"Enter the size of the float vector <max-25>:\"))\n",
+ "print \"Enter the elements of the float vector...\"\n",
+ "for i in range(size):\n",
+ " FloatNums[i]=float(raw_input())\n",
+ "BubbleSort(FloatNums, size)\n",
+ "print \"Sorted Vector:\"\n",
+ "for i in range(size):\n",
+ " print FloatNums[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Program to sort elements...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the size of the integer vector <max-25>:4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the elements of the integer vector...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\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": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sorted Vector:\n",
+ "1 4 6 8"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the size of the float vector <max-25>:3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter the elements of the float vector...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8.9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sorted Vector:\n",
+ "3.2 8.5 8.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-tprint.cpp, Page no-656"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Print(data, nTimes=None):\n",
+ " if isinstance(nTimes, int):\n",
+ " for i in range(nTimes):\n",
+ " print data\n",
+ " else:\n",
+ " print data\n",
+ "Print(1)\n",
+ "Print(1.5)\n",
+ "Print(520, 2)\n",
+ "Print(\"OOP is Great\", 3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n",
+ "1.5\n",
+ "520\n",
+ "520\n",
+ "OOP is Great\n",
+ "OOP is Great\n",
+ "OOP is Great\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-bsearch.cpp, Page no-658"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "[false, true]=[0, 1]\n",
+ "type=['false', 'true']\n",
+ "def RecBinSearch(Data, SrchElem, low, high):\n",
+ " if low>high:\n",
+ " return -1\n",
+ " mid=int((low+high)/2)\n",
+ " if SrchElem<Data[mid]:\n",
+ " return RecBinSearch(Data, SrchElem, low, mid-1)\n",
+ " elif SrchElem>Data[mid]:\n",
+ " return RecBinSearch(Data, SrchElem, mid+1, high)\n",
+ " return mid\n",
+ "num=[int]*25\n",
+ "FloatNums=[float]*25\n",
+ "print \"Program to search integer elements...\"\n",
+ "size=int(raw_input(\"How many elements ? \"))\n",
+ "print \"Enter the elements in ascending order for binary search...\"\n",
+ "for i in range(size):\n",
+ " num[i]=int(raw_input())\n",
+ "elem=int(raw_input(\"Enter the element to be searched: \"))\n",
+ "index=RecBinSearch(num, elem, 0, size)\n",
+ "if index==-1:\n",
+ " print \"Element\", elem, \"not found\"\n",
+ "else:\n",
+ " print \"Element\", elem, \"found at position\", index"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Program to search integer elements...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many elements ? 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the elements in ascending order for binary search...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\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": [
+ "Enter the element to be searched: 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Element 6 found at position 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-student.cpp, Page no-661"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class stuRec(Structure):\n",
+ " name=str\n",
+ " age=int\n",
+ " collegeCode=str\n",
+ "def Display(t):\n",
+ " print t\n",
+ "def output(s):\n",
+ " print \"Name:\", s.name\n",
+ " print \"Age:\", s.age\n",
+ " print \"College Code:\", s.collegeCode\n",
+ "s1=stuRec()\n",
+ "print \"Enter student record details...\"\n",
+ "s1.name=raw_input(\"Name: \")\n",
+ "s1.age=int(raw_input(\"Age: \"))\n",
+ "s1.collegeCode=raw_input(\"College Code: \")\n",
+ "print \"The student record:\"\n",
+ "print \"Name:\",\n",
+ "Display(s1.name)\n",
+ "print \"Age:\",\n",
+ "Display(s1.age)\n",
+ "print \"College Code:\",\n",
+ "Display(s1.collegeCode)\n",
+ "print \"The student record:\"\n",
+ "output(s1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student record details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Chinamma\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age: 18\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "College Code: A\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The student record:\n",
+ "Name: Chinamma\n",
+ "Age: 18\n",
+ "College Code: A\n",
+ "The student record:\n",
+ "Name: Chinamma\n",
+ "Age: 18\n",
+ "College Code: A\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vector.cpp, Page no-665"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class vector:\n",
+ " __size=int\n",
+ " def __init__(self, vector_size):\n",
+ " self.__size=vector_size\n",
+ " self.__v=[vector]*self.__size\n",
+ " def __del__(self):\n",
+ " del self.__v\n",
+ " def elem(self, i, x=None):\n",
+ " if isinstance(x, int) or isinstance(x, float):\n",
+ " if i>=self.__size:\n",
+ " print \"Error: Out of Range\"\n",
+ " return\n",
+ " self.__v[i]=x\n",
+ " else:\n",
+ " return self.__v[i]\n",
+ " def show(self):\n",
+ " for i in range(self.__size):\n",
+ " print self.elem(i), \",\",\n",
+ "int_vect=vector(5)\n",
+ "float_vect=vector(4)\n",
+ "for i in range(5):\n",
+ " int_vect.elem(i, i+1)\n",
+ "for i in range(4):\n",
+ " float_vect.elem(i,i+1.5)\n",
+ "print \"Integer Vector:\",\n",
+ "int_vect.show()\n",
+ "print \"\\nFloating Vector:\",\n",
+ "float_vect.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Integer Vector: 1 , 2 , 3 , 4 , 5 , \n",
+ "Floating Vector: 1.5 , 2.5 , 3.5 , 4.5 ,\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-union.cpp, Page no-670"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "(false, true)=(0, 1) #enum type\n",
+ "type =['false', 'true']\n",
+ "MAX_ITEMS=25\n",
+ "def IsExist(self, item):\n",
+ " for i in range(self._Bag__ItemCount):\n",
+ " if self._Bag__contents[i]==item:\n",
+ " return true\n",
+ " return false\n",
+ "def show(self):\n",
+ " for i in range(self._Bag__ItemCount):\n",
+ " print self._Bag__contents[i],\n",
+ " print \"\"\n",
+ "class Bag:\n",
+ " #protected members\n",
+ " __ItemCount=int\n",
+ " def __init__(self):\n",
+ " self.__ItemCount=0\n",
+ " self.__contents=[int]*MAX_ITEMS\n",
+ " def put(self, item):\n",
+ " self.__contents[self.__ItemCount]=item\n",
+ " self.__ItemCount+=1\n",
+ " def IsEmpty(self):\n",
+ " return true if self.__ItemCount==0 else false\n",
+ " def IsFull(self):\n",
+ " return true if self.__ItemCount==MAX_ITEMS else false\n",
+ " IsExist=IsExist\n",
+ " show=show\n",
+ "def read(self):\n",
+ " while(true):\n",
+ " element=int(raw_input(\"Enter Set Element <0-end>: \"))\n",
+ " if element==0:\n",
+ " break\n",
+ " self.Add(element)\n",
+ "def add(s1, s2):\n",
+ " temp = Set()\n",
+ " temp=s1\n",
+ " for i in range(s2._Bag__ItemCount):\n",
+ " if s1.IsExist(s2._Bag__contents[i])==false:\n",
+ " temp.Add(s2._Bag__contents[i])\n",
+ " return temp\n",
+ "class Set(Bag):\n",
+ " def Add(self,element):\n",
+ " if(self.IsExist(element)==false and self.IsFull()==false):\n",
+ " self.put(element)\n",
+ " read=read\n",
+ " def __assign__(self, s2):\n",
+ " for i in range(s2._Bag__ItemCount):\n",
+ " self.__contents[i]=s2.__contents[i]\n",
+ " self.__ItemCount=s2.__ItemCount\n",
+ " def __add__(self, s2):\n",
+ " return add(self, s2)\n",
+ "s1=Set()\n",
+ "s2=Set()\n",
+ "s3=Set()\n",
+ "print \"Enter Set 1 elements..\"\n",
+ "s1.read()\n",
+ "print \"Enter Set 2 elemets..\"\n",
+ "s2.read()\n",
+ "s3=s1+s2\n",
+ "print \"Union of s1 and s2 : \",\n",
+ "s3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set 1 elements..\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set 2 elemets..\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Set Element <0-end>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Union of s1 and s2 : 1 2 3 4 5 6 \n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-tree.cpp, Page no-673"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class TreeNode:\n",
+ " def __init__(self, dataIn, l, r):\n",
+ " if isinstance(l, TreeNode):\n",
+ " self.__left=l\n",
+ " self.__right=r\n",
+ " else:\n",
+ " self.__left=None\n",
+ " self.__right=None\n",
+ " self.__data=dataIn\n",
+ "class BinaryTree:\n",
+ " __root=None\n",
+ " def InsertNode(self, tree, data):\n",
+ " if tree==None:\n",
+ " tree=TreeNode(data, None, None)\n",
+ " return tree\n",
+ " if data<tree._TreeNode__data:\n",
+ " tree._TreeNode__left=self.InsertNode(tree._TreeNode__left, data)\n",
+ " elif data>tree._TreeNode__data:\n",
+ " tree._TreeNode__right=self.InsertNode(tree._TreeNode__right, data)\n",
+ " return tree\n",
+ " def PrintTreeTriangle(self, tree, level):\n",
+ " if tree:\n",
+ " self.PrintTreeTriangle(tree._TreeNode__right, level+1)\n",
+ " for i in range(level):\n",
+ " print \"\\t\",\n",
+ " print \"%g\" %tree._TreeNode__data\n",
+ " self.PrintTreeTriangle(tree._TreeNode__left, level+1)\n",
+ " def PrintTreeDiagonal(self, tree, level):\n",
+ " if tree!=None:\n",
+ " for i in range(level):\n",
+ " print \"\\t\",\n",
+ " print \"%g\" %tree._TreeNode__data\n",
+ " self.PrintTreeTriangle(tree._TreeNode__left, level+1)\n",
+ " self.PrintTreeTriangle(tree._TreeNode__right, level+1)\n",
+ " def PreOrderTraverse(self, tree):\n",
+ " if tree:\n",
+ " print \"%g\" %tree._TreeNode__data,\n",
+ " self.PreOrderTraverse(tree._TreeNode__left)\n",
+ " self.PreOrderTraverse(tree._TreeNode__right)\n",
+ " def InOrderTraverse(self, tree):\n",
+ " if tree:\n",
+ " self.InOrderTraverse(tree._TreeNode__left)\n",
+ " print \"%g\" %tree._TreeNode__data,\n",
+ " self.InOrderTraverse(tree._TreeNode__right)\n",
+ " def PostOrderTraverse(self, tree):\n",
+ " if tree:\n",
+ " self.PostOrderTraverse(tree._TreeNode__left)\n",
+ " self.PostOrderTraverse(tree._TreeNode__right)\n",
+ " print \"%g\" %tree._TreeNode__data,\n",
+ " def SearchTree(self, tree, data):\n",
+ " while(tree):\n",
+ " if data<tree._TreeNode__data:\n",
+ " tree=tree._TreeNode__left\n",
+ " elif data>tree._TreeNode__data:\n",
+ " tree=tree._TreeNode__right\n",
+ " else:\n",
+ " return tree\n",
+ " return None\n",
+ " def PreOrder(self):\n",
+ " self.PreOrderTraverse(self.__root)\n",
+ " def InOrder(self):\n",
+ " self.InOrderTraverse(self.__root)\n",
+ " def PostOrder(self):\n",
+ " self.PostOrderTraverse(self.__root)\n",
+ " def PrintTree(self, disptype):\n",
+ " if disptype==1:\n",
+ " self.PrintTreeTriangle(self.__root, 1)\n",
+ " else:\n",
+ " self.PrintTreeDiagonal(self.__root, 1)\n",
+ " def Insert(self, data):\n",
+ " self.__root=self.InsertNode(self.__root, data)\n",
+ " def Search(self, data):\n",
+ " return self.SearchTree(self.__root, data)\n",
+ "btree=BinaryTree()\n",
+ "print \"This Program Demonstrates the Binary Tree Operations\"\n",
+ "disptype=int(raw_input(\"Tree Diplay Style: [1] - Triangular [2] - Diagonal form: \"))\n",
+ "print \"Tree creation process...\"\n",
+ "while 1:\n",
+ " data=float(raw_input(\"Enter node number to be inserted <0-END>: \"))\n",
+ " if data==0:\n",
+ " break\n",
+ " btree.Insert(data)\n",
+ " print \"Binary Tree is...\"\n",
+ " btree.PrintTree(disptype)\n",
+ " print \"Pre-Order Traversal:\",\n",
+ " btree.PreOrder()\n",
+ " print \"\\nIn-Order Traversal:\",\n",
+ " btree.InOrder()\n",
+ " print \"\\nPost-Order Traversal:\",\n",
+ " btree.PostOrder()\n",
+ " print \"\"\n",
+ "print \"Tree search process...\"\n",
+ "while(1):\n",
+ " data=float(raw_input(\"Enter node number to be inserted <0-END>: \"))\n",
+ " if data==0:\n",
+ " break\n",
+ " if btree.Search(data):\n",
+ " print \"Found data in the Tree\"\n",
+ " else:\n",
+ " print \"Not found data in the Tree\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This Program Demonstrates the Binary Tree Operations\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tree Diplay Style: [1] - Triangular [2] - Diagonal form: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tree creation process...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter node number to be inserted <0-END>: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Binary Tree is...\n",
+ "\t5\n",
+ "Pre-Order Traversal: 5 \n",
+ "In-Order Traversal: 5 \n",
+ "Post-Order Traversal: 5 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter node number to be inserted <0-END>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Binary Tree is...\n",
+ "\t5\n",
+ "\t\t3\n",
+ "Pre-Order Traversal: 5 3 \n",
+ "In-Order Traversal: 3 5 \n",
+ "Post-Order Traversal: 3 5 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter node number to be inserted <0-END>: 8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Binary Tree is...\n",
+ "\t\t8\n",
+ "\t5\n",
+ "\t\t3\n",
+ "Pre-Order Traversal: 5 3 8 \n",
+ "In-Order Traversal: 3 5 8 \n",
+ "Post-Order Traversal: 3 8 5 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter node number to be inserted <0-END>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Binary Tree is...\n",
+ "\t\t8\n",
+ "\t5\n",
+ "\t\t3\n",
+ "\t\t\t2\n",
+ "Pre-Order Traversal: 5 3 2 8 \n",
+ "In-Order Traversal: 2 3 5 8 \n",
+ "Post-Order Traversal: 2 3 8 5 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter node number to be inserted <0-END>: 9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Binary Tree is...\n",
+ "\t\t\t9\n",
+ "\t\t8\n",
+ "\t5\n",
+ "\t\t3\n",
+ "\t\t\t2\n",
+ "Pre-Order Traversal: 5 3 2 8 9 \n",
+ "In-Order Traversal: 2 3 5 8 9 \n",
+ "Post-Order Traversal: 2 3 9 8 5 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter node number to be inserted <0-END>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Tree search process...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter node number to be inserted <0-END>: 8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Found data in the Tree\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter node number to be inserted <0-END>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Not found data in the Tree\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter node number to be inserted <0-END>: 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex.cpp, Page no-679"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def __add__(self, c2):\n",
+ " temp=Complex()\n",
+ " temp._Complex__real=self._Complex__real+c2._Complex__real\n",
+ " temp._Complex__imag=self._Complex__imag+c2._Complex__imag\n",
+ " return temp\n",
+ "class Complex:\n",
+ " def __init__(self):\n",
+ " self.__real=self.__imag=0\n",
+ " def getdata(self):\n",
+ " self.__real=float(raw_input(\"Real part ? \"))\n",
+ " self.__imag=float(raw_input(\"Imag part ? \"))\n",
+ " #overloading + operator\n",
+ " __add__=__add__\n",
+ " def outdata(self, msg):\n",
+ " print \"%s(%g, %g)\" %(msg, self.__real, self.__imag)\n",
+ "c1=Complex()\n",
+ "c2=Complex()\n",
+ "c3=Complex()\n",
+ "print \"Addition of integer complex objects...\"\n",
+ "print \"Enter Complex Number c1...\"\n",
+ "c1.getdata()\n",
+ "print \"Enter Complex Number c2...\"\n",
+ "c2.getdata()\n",
+ "c3=c1+c2 #invoking the overloaded + operator\n",
+ "c3.outdata(\"c3 = c1 + c2: \")\n",
+ "c4=Complex()\n",
+ "c5=Complex()\n",
+ "c6=Complex()\n",
+ "print \"Addition of float complex objects...\"\n",
+ "print \"Enter Complex Number c4...\"\n",
+ "c4.getdata()\n",
+ "print \"Enter Complex Number c5...\"\n",
+ "c5.getdata()\n",
+ "c6=c4+c5 #invoking the overloaded + operator\n",
+ "c6.outdata(\"c6 = c4 + c5: \")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Addition of integer complex objects...\n",
+ "Enter Complex Number c1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c2...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c3 = c1 + c2: (4, 6)\n",
+ "Addition of float complex objects...\n",
+ "Enter Complex Number c4...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 1.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 2.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Complex Number c5...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part ? 2.4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imag part ? 3.7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c6 = c4 + c5: (3.9, 6.2)\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-1, Page no-680"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "N=5\n",
+ "def Min(arr):\n",
+ " m=arr[0]\n",
+ " for i in range(N):\n",
+ " if arr[i]<m:\n",
+ " m=arr[i]\n",
+ " return m\n",
+ "a=[55,6,7,-1,8]\n",
+ "b=[2.3,2.1,8.4,7.5,3.0]\n",
+ "i_min=Min(a)\n",
+ "f_min=Min(b)\n",
+ "print \"Minimum value in integer array =\", i_min\n",
+ "print \"Minimum value in float array =\", f_min"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Minimum value in integer array = -1\n",
+ "Minimum value in float array = 2.1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-2, Page no-681"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def add(a, b):\n",
+ " return a+b\n",
+ "i1=10\n",
+ "i2=20\n",
+ "f1=8.2\n",
+ "f2=9.9\n",
+ "c1='#'\n",
+ "c2='$'\n",
+ "print i1,\"+\",i2, \"=\", add(i1, i2)\n",
+ "print f1,\"+\",f2, \"=\", add(f1, f2)\n",
+ "print c1,\"+\",c2, \"= %c\" %add(ord(c1),ord(c2))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10 + 20 = 30\n",
+ "8.2 + 9.9 = 18.1\n",
+ "# + $ = G\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter17-StreamsComputationWithConsole.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter17-StreamsComputationWithConsole.ipynb
new file mode 100755
index 00000000..12c13cf7
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter17-StreamsComputationWithConsole.ipynb
@@ -0,0 +1,1338 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:7caa500b3a86295a3fa2a49826e32bb84c94f9c218ecf3c344e2f51d069f57ff"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 17-Streams Computation with Console"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-hello.c, Page no-688"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print 'Hello World'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello World\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-hello.cpp, Page no-688"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print 'Hello World'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello World\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-redirect.cpp, Page no-688"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print 'Hello World with cout'\n",
+ "print 'Hello World with cerr'\n",
+ "print 'Hello World with clog'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello World with cout\n",
+ "Hello World with cerr\n",
+ "Hello World with clog\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-get.cpp, Page no-691"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "c=raw_input()\n",
+ "print c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello World\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello World\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-put.cpp, Page no-692"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for i in range(255):\n",
+ " if i==26:\n",
+ " continue\n",
+ " print i,chr(i)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0 \u0000\n",
+ "1 \u0001\n",
+ "2 \u0002\n",
+ "3 \u0003\n",
+ "4 \u0004\n",
+ "5 \u0005\n",
+ "6 \u0006\n",
+ "7 \u0007\n",
+ "8 \b\n",
+ "9 \t\n",
+ "10 \n",
+ "\n",
+ "11 \u000b",
+ "\n",
+ "12 \f",
+ "\n",
+ "13 \r\n",
+ "14 \u000e\n",
+ "15 \u000f\n",
+ "16 \u0010\n",
+ "17 \u0011\n",
+ "18 \u0012\n",
+ "19 \u0013\n",
+ "20 \u0014\n",
+ "21 \u0015\n",
+ "22 \u0016\n",
+ "23 \u0017\n",
+ "24 \u0018\n",
+ "25 \u0019\n",
+ "27 \u001b\n",
+ "28 \u001c",
+ "\n",
+ "29 \u001d",
+ "\n",
+ "30 \u001e",
+ "\n",
+ "31 \u001f\n",
+ "32 \n",
+ "33 !\n",
+ "34 \"\n",
+ "35 #\n",
+ "36 $\n",
+ "37 %\n",
+ "38 &\n",
+ "39 '\n",
+ "40 (\n",
+ "41 )\n",
+ "42 *\n",
+ "43 +\n",
+ "44 ,\n",
+ "45 -\n",
+ "46 .\n",
+ "47 /\n",
+ "48 0\n",
+ "49 1\n",
+ "50 2\n",
+ "51 3\n",
+ "52 4\n",
+ "53 5\n",
+ "54 6\n",
+ "55 7\n",
+ "56 8\n",
+ "57 9\n",
+ "58 :\n",
+ "59 ;\n",
+ "60 <\n",
+ "61 =\n",
+ "62 >\n",
+ "63 ?\n",
+ "64 @\n",
+ "65 A\n",
+ "66 B\n",
+ "67 C\n",
+ "68 D\n",
+ "69 E\n",
+ "70 F\n",
+ "71 G\n",
+ "72 H\n",
+ "73 I\n",
+ "74 J\n",
+ "75 K\n",
+ "76 L\n",
+ "77 M\n",
+ "78 N\n",
+ "79 O\n",
+ "80 P\n",
+ "81 Q\n",
+ "82 R\n",
+ "83 S\n",
+ "84 T\n",
+ "85 U\n",
+ "86 V\n",
+ "87 W\n",
+ "88 X\n",
+ "89 Y\n",
+ "90 Z\n",
+ "91 [\n",
+ "92 \\\n",
+ "93 ]\n",
+ "94 ^\n",
+ "95 _\n",
+ "96 `\n",
+ "97 a\n",
+ "98 b\n",
+ "99 c\n",
+ "100 d\n",
+ "101 e\n",
+ "102 f\n",
+ "103 g\n",
+ "104 h\n",
+ "105 i\n",
+ "106 j\n",
+ "107 k\n",
+ "108 l\n",
+ "109 m\n",
+ "110 n\n",
+ "111 o\n",
+ "112 p\n",
+ "113 q\n",
+ "114 r\n",
+ "115 s\n",
+ "116 t\n",
+ "117 u\n",
+ "118 v\n",
+ "119 w\n",
+ "120 x\n",
+ "121 y\n",
+ "122 z\n",
+ "123 {\n",
+ "124 |\n",
+ "125 }\n",
+ "126 ~\n",
+ "127 \u007f\n",
+ "128 \ufffd\n",
+ "129 \ufffd\n",
+ "130 \ufffd\n",
+ "131 \ufffd\n",
+ "132 \ufffd\n",
+ "133 \ufffd\n",
+ "134 \ufffd\n",
+ "135 \ufffd\n",
+ "136 \ufffd\n",
+ "137 \ufffd\n",
+ "138 \ufffd\n",
+ "139 \ufffd\n",
+ "140 \ufffd\n",
+ "141 \ufffd\n",
+ "142 \ufffd\n",
+ "143 \ufffd\n",
+ "144 \ufffd\n",
+ "145 \ufffd\n",
+ "146 \ufffd\n",
+ "147 \ufffd\n",
+ "148 \ufffd\n",
+ "149 \ufffd\n",
+ "150 \ufffd\n",
+ "151 \ufffd\n",
+ "152 \ufffd\n",
+ "153 \ufffd\n",
+ "154 \ufffd\n",
+ "155 \ufffd\n",
+ "156 \ufffd\n",
+ "157 \ufffd\n",
+ "158 \ufffd\n",
+ "159 \ufffd\n",
+ "160 \ufffd\n",
+ "161 \ufffd\n",
+ "162 \ufffd\n",
+ "163 \ufffd\n",
+ "164 \ufffd\n",
+ "165 \ufffd\n",
+ "166 \ufffd\n",
+ "167 \ufffd\n",
+ "168 \ufffd\n",
+ "169 \ufffd\n",
+ "170 \ufffd\n",
+ "171 \ufffd\n",
+ "172 \ufffd\n",
+ "173 \ufffd\n",
+ "174 \ufffd\n",
+ "175 \ufffd\n",
+ "176 \ufffd\n",
+ "177 \ufffd\n",
+ "178 \ufffd\n",
+ "179 \ufffd\n",
+ "180 \ufffd\n",
+ "181 \ufffd\n",
+ "182 \ufffd\n",
+ "183 \ufffd\n",
+ "184 \ufffd\n",
+ "185 \ufffd\n",
+ "186 \ufffd\n",
+ "187 \ufffd\n",
+ "188 \ufffd\n",
+ "189 \ufffd\n",
+ "190 \ufffd\n",
+ "191 \ufffd\n",
+ "192 \ufffd\n",
+ "193 \ufffd\n",
+ "194 \ufffd\n",
+ "195 \ufffd\n",
+ "196 \ufffd\n",
+ "197 \ufffd\n",
+ "198 \ufffd\n",
+ "199 \ufffd\n",
+ "200 \ufffd\n",
+ "201 \ufffd\n",
+ "202 \ufffd\n",
+ "203 \ufffd\n",
+ "204 \ufffd\n",
+ "205 \ufffd\n",
+ "206 \ufffd\n",
+ "207 \ufffd\n",
+ "208 \ufffd\n",
+ "209 \ufffd\n",
+ "210 \ufffd\n",
+ "211 \ufffd\n",
+ "212 \ufffd\n",
+ "213 \ufffd\n",
+ "214 \ufffd\n",
+ "215 \ufffd\n",
+ "216 \ufffd\n",
+ "217 \ufffd\n",
+ "218 \ufffd\n",
+ "219 \ufffd\n",
+ "220 \ufffd\n",
+ "221 \ufffd\n",
+ "222 \ufffd\n",
+ "223 \ufffd\n",
+ "224 \ufffd\n",
+ "225 \ufffd\n",
+ "226 \ufffd\n",
+ "227 \ufffd\n",
+ "228 \ufffd\n",
+ "229 \ufffd\n",
+ "230 \ufffd\n",
+ "231 \ufffd\n",
+ "232 \ufffd\n",
+ "233 \ufffd\n",
+ "234 \ufffd\n",
+ "235 \ufffd\n",
+ "236 \ufffd\n",
+ "237 \ufffd\n",
+ "238 \ufffd\n",
+ "239 \ufffd\n",
+ "240 \ufffd\n",
+ "241 \ufffd\n",
+ "242 \ufffd\n",
+ "243 \ufffd\n",
+ "244 \ufffd\n",
+ "245 \ufffd\n",
+ "246 \ufffd\n",
+ "247 \ufffd\n",
+ "248 \ufffd\n",
+ "249 \ufffd\n",
+ "250 \ufffd\n",
+ "251 \ufffd\n",
+ "252 \ufffd\n",
+ "253 \ufffd\n",
+ "254 \ufffd\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-space1.cpp, Page no-693"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "test=raw_input(\"Enter string: \")\n",
+ "i=0\n",
+ "print \"Output string: \",\n",
+ "while True:\n",
+ " if test[i].isspace():\n",
+ " break\n",
+ " else:\n",
+ " sys.stdout.write(test[i])\n",
+ " i+=1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter string: Hello World\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output string: Hello\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-space2.cpp, Page no-693"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "test=raw_input(\"Enter string: \")\n",
+ "print \"Output string:\", test"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter string: Hello World\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output string: Hello World\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-stand.cpp, Page no-694"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "string1=\"Object-Computing\"\n",
+ "string2=\" with C++\"\n",
+ "len1=len(string1)\n",
+ "len2=len(string2)\n",
+ "for i in range(1,len1):\n",
+ " print string1[:i]\n",
+ "for i in range(len1, 0, -1):\n",
+ " print string1[:i]\n",
+ "print \"%s%s\" %(string1[:len1], string2[:len2])\n",
+ "print string1+string2\n",
+ "print string1[:6]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "O\n",
+ "Ob\n",
+ "Obj\n",
+ "Obje\n",
+ "Objec\n",
+ "Object\n",
+ "Object-\n",
+ "Object-C\n",
+ "Object-Co\n",
+ "Object-Com\n",
+ "Object-Comp\n",
+ "Object-Compu\n",
+ "Object-Comput\n",
+ "Object-Computi\n",
+ "Object-Computin\n",
+ "Object-Computing\n",
+ "Object-Computin\n",
+ "Object-Computi\n",
+ "Object-Comput\n",
+ "Object-Compu\n",
+ "Object-Comp\n",
+ "Object-Com\n",
+ "Object-Co\n",
+ "Object-C\n",
+ "Object-\n",
+ "Object\n",
+ "Objec\n",
+ "Obje\n",
+ "Obj\n",
+ "Ob\n",
+ "O\n",
+ "Object-Computing with C++\n",
+ "Object-Computing with C++\n",
+ "Object\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-student.cpp, Page no-697"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_MARKS=600.0\n",
+ "def read(self):\n",
+ " self.__name=raw_input(\"Enter Name: \")\n",
+ " self.__marks=int(raw_input(\"Enter Marks Secured: \"))\n",
+ "def show(self):\n",
+ " print '{:>10}'.format(self.__name),\n",
+ " print '{:>6}'.format(self.__marks),\n",
+ " print '{0:10.0f}'.format((self.__marks/MAX_MARKS)*100)\n",
+ "class student:\n",
+ " __name=str\n",
+ " __marks=int\n",
+ " read=read\n",
+ " show=show\n",
+ "count=int(raw_input(\"How many students ? \"))\n",
+ "s=[]*count\n",
+ "for i in range(count):\n",
+ " s.append(student())\n",
+ "for i in range(count):\n",
+ " print \"Enter Student\", i+1, \"details...\"\n",
+ " s[i].read()\n",
+ "print \"Student Report...\"\n",
+ "print '{:>3}'.format(\"R#\"),\n",
+ "print '{:>10}'.format(\"Student\"),\n",
+ "print '{:>6}'.format(\"Marks\"),\n",
+ "print '{:>15}'.format(\"Percentage\")\n",
+ "for i in range(count):\n",
+ " print \"%3s\" %(i+1),\n",
+ " s[i].show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many students ? 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Student 1 details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: Tejaswi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Marks Secured: 450\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Student 2 details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Marks Secured: 525\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Student 3 details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: Bindu\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Marks Secured: 429\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Student Report...\n",
+ " R# Student Marks Percentage\n",
+ " 1 Tejaswi 450 75\n",
+ " 2 Rajkumar 525 88\n",
+ " 3 Bindu 429 72\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-salary.cpp, Page no-701"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "desig=[\"CEO\", \"Manager\", \"Receptionist\", \"Clerk\", \"Peon\"]\n",
+ "salary=[10200,5200,2950,950,750]\n",
+ "print \"Salary Structure Based on Designation\"\n",
+ "print \"-------------------------------------\"\n",
+ "print '{:>15}'.format('Designation '),\n",
+ "print '{:>15}'.format('Salary (in Rs.)')\n",
+ "print \"-------------------------------------\"\n",
+ "for i in range(5):\n",
+ " print '{:.>15}'.format(desig[i]),\n",
+ " print '{:*>15}'.format(salary[i])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Salary Structure Based on Designation\n",
+ "-------------------------------------\n",
+ "Designation Salary (in Rs.)\n",
+ "-------------------------------------\n",
+ "............CEO **********10200\n",
+ "........Manager ***********5200\n",
+ "...Receptionist ***********2950\n",
+ "..........Clerk ************950\n",
+ "...........Peon ************750\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-hex.c, Page no-705"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "num=raw_input(\"Enter any hexadecimal number: \")\n",
+ "print \"The input number in decimal = %d\" %int(num, 16)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter any hexadecimal number: ab\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The input number in decimal = 171\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-hex.cpp, Page no-706"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "num=raw_input(\"Enter any hexadecimal number: \")\n",
+ "print \"The input number in decimal = %d\" %int(num, 16)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter any hexadecimal number: ab\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The input number in decimal = 171\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-foutput.cpp, Page no-709"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x=int(100)\n",
+ "print format(x, '02x'), x\n",
+ "f=122.3434\n",
+ "print f\n",
+ "print '{:.2f}'.format(f)\n",
+ "print \"0x%0.4X\" %x\n",
+ "print '{:.3e}'.format(f)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "64 100\n",
+ "122.3434\n",
+ "122.34\n",
+ "0x0064\n",
+ "1.223e+02\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-payroll.cpp, Page no-709"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "f1=123.45\n",
+ "f2=34.65\n",
+ "f3=float(56)\n",
+ "print '{0:6.2f}'.format(f1)\n",
+ "print '{0:6.2f}'.format(f2)\n",
+ "print '{0:6.2f}'.format(f3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "123.45\n",
+ " 34.65\n",
+ " 56.00\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-oct.cpp, Page no-710"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i=raw_input(\"Enter octal number: \")\n",
+ "print \"Its decimal equivalent is: %d\" %int(i, 8)\n",
+ "i=int(raw_input(\"Enter decimal number: \"))\n",
+ "print \"Its output:\", oct(i)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter octal number: 111\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Its decimal equivalent is: 73\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter decimal number: 73\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Its output: 0111\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-mattab.cpp, Page no-711"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "num=int(raw_input(\"Enter Any Integer Number: \"))\n",
+ "print \"-----------------------------------------------------\"\n",
+ "print '{:>5}'.format(\"NUM\"),\n",
+ "print '{:>10}'.format(\"SQR\"),\n",
+ "print '{:>15}'.format(\"SQRT\"),\n",
+ "print '{:>15}'.format(\"LOG\")\n",
+ "print \"-----------------------------------------------------\"\n",
+ "for i in range(1, num+1):\n",
+ " print '{:>5}'.format(i),\n",
+ " print '{:>10}'.format(i*i),\n",
+ " print '{:15.3f}'.format(math.sqrt(i)),\n",
+ " print '{:15.4e}'.format(math.log(i))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Any Integer Number: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-----------------------------------------------------\n",
+ " NUM SQR SQRT LOG\n",
+ "-----------------------------------------------------\n",
+ " 1 1 1.000 0.0000e+00\n",
+ " 2 4 1.414 6.9315e-01\n",
+ " 3 9 1.732 1.0986e+00\n",
+ " 4 16 2.000 1.3863e+00\n",
+ " 5 25 2.236 1.6094e+00\n",
+ " 6 36 2.449 1.7918e+00\n",
+ " 7 49 2.646 1.9459e+00\n",
+ " 8 64 2.828 2.0794e+00\n",
+ " 9 81 3.000 2.1972e+00\n",
+ " 10 100 3.162 2.3026e+00\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-space3.cpp, Page no-712"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def sp():\n",
+ " print \"\",\n",
+ "x=1\n",
+ "y=2\n",
+ "z=3\n",
+ "w=4\n",
+ "print x, \n",
+ "sp(), \n",
+ "print y, \n",
+ "sp(), \n",
+ "print z, \n",
+ "sp(), \n",
+ "print w"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 2 3 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-currency.cpp, Page no-713"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def rupee():\n",
+ " print \"Rs.\",\n",
+ "def dollar():\n",
+ " print \"US$\",\n",
+ "print \"Item Sales in India...\"\n",
+ "item1=raw_input(\"Enter Item Name: \")\n",
+ "cost1=int(raw_input(\"Cost of Item: \"))\n",
+ "print \"Item Sales in US...\"\n",
+ "item2=raw_input(\"Enter Item Name: \")\n",
+ "cost2=int(raw_input(\"Cost of Item: \"))\n",
+ "print \"Item Cost Statistics...\"\n",
+ "print \"Item Name:\", item1\n",
+ "print \"Cost:\", \n",
+ "rupee(), \n",
+ "print cost1\n",
+ "print \"Item Name:\", item2\n",
+ "print \"Cost:\", \n",
+ "dollar(), \n",
+ "print cost2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Item Sales in India...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Item Name: PARAM Supercomputer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Cost of Item: 55000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Item Sales in US...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Item Name: CRAY Supercomputer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Cost of Item: 40500\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Item Cost Statistics...\n",
+ "Item Name: PARAM Supercomputer\n",
+ "Cost: Rs. 55000\n",
+ "Item Name: CRAY Supercomputer\n",
+ "Cost: US$ 40500\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-pmani.cpp, Page no-715"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def output(self, x):\n",
+ " print '{x:{f}>{w}.{p}f}'.format(x=x,f=self._my_manipulator__fill,w= self._my_manipulator__width, p=self._my_manipulator__precision)\n",
+ "class my_manipulator:\n",
+ " __width=int\n",
+ " __precision=int\n",
+ " __fill=chr\n",
+ " def __init__(self, tw, tp, tf):\n",
+ " self.__width=tw\n",
+ " self.__precision=tp\n",
+ " self.__fill=tf\n",
+ " output=output\n",
+ "def set_float(w, p, f):\n",
+ " return my_manipulator(w, p, f)\n",
+ "f1=123.2734\n",
+ "f2=23.271\n",
+ "f3=16.1673\n",
+ "set_float(10, 3, '*').output(f1)\n",
+ "set_float(9, 2, '^').output(f2)\n",
+ "set_float(8, 3, '#').output(f3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "***123.273\n",
+ "^^^^23.27\n",
+ "##16.167\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-point.cpp, Page no-717"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class POINT:\n",
+ " __x=int\n",
+ " __y=int\n",
+ " def __init__(self):\n",
+ " self.__x=0\n",
+ " self.__y=0\n",
+ " def output(self):\n",
+ " print \"(%d,%d)\" %(self.__x, self.__y)\n",
+ " def input(self):\n",
+ " self.__x, self.__y=[int(x) for x in raw_input().split()] \n",
+ "p1=POINT()\n",
+ "p2=POINT()\n",
+ "print \"Enter two coordinate points (p1, p2):\",\n",
+ "p1.input(), p2.input()\n",
+ "print \"Coordinate points you entered are:\"\n",
+ "p1.output()\n",
+ "p2.output()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two coordinate points (p1, p2):"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Coordinate points you entered are:\n",
+ "(2,3)\n",
+ "(5,6)\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-1, Page no-719"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "num=raw_input(\"Enter a hexadecimal value: \")\n",
+ "num=int(num, 16)\n",
+ "print \"Octal equivalent:\", oct(num)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a hexadecimal value: A\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Octal equivalent: 012\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-2, Page no-719"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI=3.14159265\n",
+ "print \"The values at different levels of precision are:\"\n",
+ "for i in range(1, 6):\n",
+ " print '%0.*f' % (i, PI)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The values at different levels of precision are:\n",
+ "3.1\n",
+ "3.14\n",
+ "3.142\n",
+ "3.1416\n",
+ "3.14159\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter18-StreamsComputationWithFiles.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter18-StreamsComputationWithFiles.ipynb
new file mode 100755
index 00000000..d5aeb20b
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter18-StreamsComputationWithFiles.ipynb
@@ -0,0 +1,1152 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:fe66068ace4dfae0081c9992d8914d2fa642c4fa20e9f62d7dadd74619b6c0f7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 18-Streams Computation with Files"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-stdfile.cpp, Page no-728"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fout=open(\"student.out\", \"w\")\n",
+ "name=raw_input(\"Enter Name: \")\n",
+ "marks=raw_input(\"Enter Marks Secured: \")\n",
+ "fout.write(name+'\\n')\n",
+ "fout.write(marks+'\\n')\n",
+ "name=raw_input(\"Enter Name: \")\n",
+ "marks=raw_input(\"Enter Marks Secured: \")\n",
+ "fout.write(name+'\\n')\n",
+ "fout.write(marks+'\\n')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Marks Secured: 95\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: Tejaswi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Marks Secured: 90\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example-stdread.cpp, Page no-729"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fin=open(\"student.out\", \"r\")\n",
+ "name = fin.readline()\n",
+ "print \"Name:\", name,\n",
+ "marks=fin.readline()\n",
+ "print \"Marks Secured:\",marks,\n",
+ "name = fin.readline()\n",
+ "print \"Name:\", name,\n",
+ "marks=fin.readline()\n",
+ "print \"Marks Secured:\",marks"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Rajkumar\n",
+ "Marks Secured: 95\n",
+ "Name: Tejaswi\n",
+ "Marks Secured: 90\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Example-fdisp.cpp, Page no-732"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "filename=raw_input(\"Enter Name of the File: \")\n",
+ "try:\n",
+ " ifile=open(filename, \"r\")\n",
+ " ch=ifile.read()\n",
+ " print ch\n",
+ "except IOError:\n",
+ " print \"Error opening\", filename"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name of the File: mytype.cpp\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Error opening mytype.cpp\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-keyin.cpp, Page no-733"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ofile=open(\"key.txt\", \"w\")\n",
+ "print \"Enter characters ..<Ctrl-Z followed by carriage-return to stop\"\n",
+ "ch=raw_input()\n",
+ "while(ch):\n",
+ " ofile.write(ch)\n",
+ " ch=raw_input()\n",
+ "ofile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter characters ..<Ctrl-Z followed by carriage-return to stop\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": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-stdwr.cpp, Page no-734"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def student_write(count):\n",
+ " fout=open(\"student.out\", \"w\")\n",
+ " if not(fout):\n",
+ " print \"Error: student.out cannot be opened in write mode\"\n",
+ " return\n",
+ " for i in range(count):\n",
+ " name=raw_input(\"Enter Name: \")\n",
+ " marks=raw_input(\"Enter Marks Secured: \")\n",
+ " fout.write(name+'\\n')\n",
+ " fout.write(marks+'\\n')\n",
+ " fout.close()\n",
+ "def student_read():\n",
+ " fin=open(\"student.out\", \"r\")\n",
+ " if not(fin):\n",
+ " print \"Error: student.out cannot be opened in read mode\"\n",
+ " return\n",
+ " for i in range(3):\n",
+ " name=fin.readline()\n",
+ " marks=fin.readline()\n",
+ " if name=='': #to check end of file\n",
+ " break\n",
+ " print \"Name:\", name,\n",
+ " print \"Marks Secured:\", marks,\n",
+ " fin.close()\n",
+ "count = int(raw_input(\"How many students? \"))\n",
+ "print \"Enter student details to be stored...\"\n",
+ "student_write(count)\n",
+ "print \"Student details processed from the file...\"\n",
+ "student_read()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many students? 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter student details to be stored...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: Mangala\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Marks Secured: 75\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: Chatterjee\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Marks Secured: 99\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Name: Rao-M-G\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Marks Secured: 50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Student details processed from the file...\n",
+ "Name: Mangala\n",
+ "Marks Secured: 75\n",
+ "Name: Chatterjee\n",
+ "Marks Secured: 99\n",
+ "Name: Rao-M-G\n",
+ "Marks Secured: 50\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-payfile.cpp, Page no-737"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "f1=123.45\n",
+ "f2=34.65\n",
+ "f3=56\n",
+ "out_file=open(\"pay.txt\", \"w\")\n",
+ "out_file.write('{0:6.2f}'.format(f1))\n",
+ "out_file.write('{0:6.2f}'.format(f2))\n",
+ "out_file.write('{0:6.2f}'.format(f3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-fsize.cpp, Page no-739"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ " \n",
+ "if not(len(sys.argv)==2): \n",
+ " print \"Usage: fsize <filename>\"\n",
+ "else:\n",
+ " #Open a file\n",
+ " infile=open(sys.argv[1],'r')\n",
+ "\n",
+ " #In case file cannot open\n",
+ " if(not(infile)):\n",
+ " print \"Error opening\", sys.argv[1]\n",
+ " else:\n",
+ " #Read file\n",
+ " infile.seek(end)\n",
+ " print \"File Size=\", infile.tell()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Usage: fsize <filename>\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-putget.cpp, Page no-741"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "File=open(\"student.txt\", \"w\")\n",
+ "string=raw_input(\"Enter String: \")\n",
+ "File.write(string)\n",
+ "File.seek(0)\n",
+ "print \"Output string:\",\n",
+ "File=open(\"student.txt\", \"r\")\n",
+ "string=File.read()\n",
+ "print string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter String: Object-Computing with C++\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output string: Object-Computing with C++\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-fwr.cpp, Page no-743"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "num1=530\n",
+ "num2=1050.25\n",
+ "out_file=open(\"number.bin\", \"w\")\n",
+ "out_file.write(str(num1)+'\\n')\n",
+ "out_file.write(str(num2)+'\\n')\n",
+ "out_file.close()\n",
+ "in_file=open(\"number.bin\", \"r\")\n",
+ "num1=in_file.readline()\n",
+ "num2=in_file.readline()\n",
+ "print num1, num2\n",
+ "in_file.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "530\n",
+ "1050.25\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-objsave.cpp, Page no-744"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAXNAME=40\n",
+ "class Person:\n",
+ " __name=str\n",
+ " __age=int\n",
+ " def write(self, os):\n",
+ " os.write(self.__name+'\\n')\n",
+ " os.write(str(self.__age)+'\\n')\n",
+ " def read(self,Is):\n",
+ " self.__name=Is.readline()\n",
+ " self.__age=Is.readline()\n",
+ "def fOutput(fos, b):\n",
+ " b.write(fos)\n",
+ "def fInput(fos, b):\n",
+ " b.read(fos)\n",
+ "def Input(b):\n",
+ " b._Person__name=raw_input(\"Name: \")\n",
+ " b._Person__age=int(raw_input(\"Age: \"))\n",
+ "def Output(b):\n",
+ " print b._Person__name,\n",
+ " print b._Person__age,\n",
+ "p_obj=Person()\n",
+ "ofile=open(\"person.txt\", \"w\")\n",
+ "while(1):\n",
+ " Input(p_obj)\n",
+ " fOutput(ofile, p_obj)\n",
+ " ch=str(raw_input(\"Another? \"))\n",
+ " if ch.upper()!='Y':\n",
+ " break\n",
+ "ofile.close()\n",
+ "ifile=open(\"person.txt\", \"r\")\n",
+ "print \"The objects written to the file were:..\"\n",
+ "while 1:\n",
+ " fInput(ifile, p_obj)\n",
+ " Output(p_obj)\n",
+ " if p_obj._Person__name=='':\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Tejaswi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Another? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Savithri\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age: 23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Another? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The objects written to the file were:..\n",
+ "Tejaswi\n",
+ "5\n",
+ "Savithri\n",
+ "23\n",
+ " \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-student.cpp, Page no-748"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "try:\n",
+ " infile=open(\"student.in\", \"r\")\n",
+ "except IOerror:\n",
+ " print \"Error: student.in file non-existent\"\n",
+ "try:\n",
+ " outfile=open(\"student.out\", \"w\")\n",
+ "except IOerror:\n",
+ " print \"Error: unable to open student.out in write mode\"\n",
+ "else:\n",
+ " count=int(infile.readline())\n",
+ " outfile.write(\" Students Information Processing\")\n",
+ " outfile.write(\"\\n----------------------------------------\")\n",
+ " for i in range(count):\n",
+ " name=infile.readline()\n",
+ " percentage=int(infile.readline())\n",
+ " outfile.write(\"\\nName: \"+name)\n",
+ " outfile.write(\"Percentage: \"+str(percentage)+'\\n')\n",
+ " outfile.write(\"Passed in: \")\n",
+ " if percentage>=70:\n",
+ " outfile.write(\"First class with distinction\")\n",
+ " elif percentage>=60:\n",
+ " outfile.write(\"First class\")\n",
+ " elif percentage>=50:\n",
+ " outfile.write(\"Second class\")\n",
+ " elif percentage>=35:\n",
+ " outfile.write(\"Third class\")\n",
+ " else:\n",
+ " outfile.write(\"Sorry, Failed!\")\n",
+ " outfile.write('\\n')\n",
+ " outfile.write(\"----------------------------------------\")\n",
+ " infile.close()\n",
+ " outfile.close()\n",
+ " print \"Contents of student.out:\\n\"\n",
+ " infile=open(\"student.out\", \"r\")\n",
+ " Str=infile.read()\n",
+ " print Str\n",
+ " infile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Contents of student.out:\n",
+ "\n",
+ " Students Information Processing\n",
+ "----------------------------------------\n",
+ "Name: Rajkumar\n",
+ "Percentage: 84\n",
+ "Passed in: First class with distinction\n",
+ "----------------------------------------\n",
+ "Name: Tejaswi\n",
+ "Percentage: 82\n",
+ "Passed in: First class with distinction\n",
+ "----------------------------------------\n",
+ "Name: Smrithi\n",
+ "Percentage: 60\n",
+ "Passed in: First class\n",
+ "----------------------------------------\n",
+ "Name: Anand\n",
+ "Percentage: 55\n",
+ "Passed in: Second class\n",
+ "----------------------------------------\n",
+ "Name: Rajshree\n",
+ "Percentage: 40\n",
+ "Passed in: Third class\n",
+ "----------------------------------------\n",
+ "Name: Ramesh\n",
+ "Percentage: 33\n",
+ "Passed in: Sorry, Failed!\n",
+ "----------------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-fio.cpp, Page no-751"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "READ_SIZE=6\n",
+ "reader=str\n",
+ "fstr=open(\"test.del\", \"w\")\n",
+ "for i in range(10):\n",
+ " fstr.write(str(i))\n",
+ "fstr.seek(2)\n",
+ "fstr.write(\"Hello\")\n",
+ "fstr=open(\"test.del\", \"r\")\n",
+ "fstr.seek(4)\n",
+ "reader=fstr.read(READ_SIZE)\n",
+ "print reader"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "llo789\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-direct.cpp, Page no-752"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class Person(Structure):\n",
+ " _fields_=[('name',c_char*40),('age',c_int)]\n",
+ " def write(self, os):\n",
+ " os.write(self.__name+'\\n')\n",
+ " os.write(str(self.__age)+'\\n')\n",
+ " def read(self, Is):\n",
+ " self.__name=Is.readline()\n",
+ " self.__age=Is.readline()\n",
+ "def Input(b):\n",
+ " b._Person__name=raw_input(\"Name: \")\n",
+ " b._Person__age=int(raw_input(\"Age: \"))\n",
+ "def Output(b):\n",
+ " print \"Name:\",b._Person__name,\n",
+ " print \"Age:\",b._Person__age,\n",
+ "p_obj=Person()\n",
+ "print \"Database Creation...\"\n",
+ "ofile=open(\"person.dat\", \"w\")\n",
+ "count=0\n",
+ "while(1):\n",
+ " print \"Enter Object\", count, \"details...\"\n",
+ " Input(p_obj)\n",
+ " count=count+1\n",
+ " p_obj.write(ofile)\n",
+ " ch=str(raw_input(\"Another? \"))\n",
+ " if ch.upper()!='Y':\n",
+ " break\n",
+ "ofile.close()\n",
+ "iofile=open(\"person.dat\", \"r+b\")\n",
+ "print \"Database Access...\"\n",
+ "while 1:\n",
+ " obj_id=int(raw_input(\"Enter the object number to be accessed <-1 to end>: \"))\n",
+ " iofile.seek(0)\n",
+ " if obj_id<0 or obj_id>=count:\n",
+ " break\n",
+ " for i in range(2*obj_id):\n",
+ " iofile.readline()\n",
+ " location=iofile.tell()\n",
+ " iofile.seek(location)\n",
+ " p_obj.read(iofile)\n",
+ " Output(p_obj)\n",
+ " ch=raw_input(\"Wants to Modify? \")\n",
+ " if ch=='y' or ch=='Y':\n",
+ " Input(p_obj)\n",
+ " iofile.seek(location)\n",
+ " p_obj.write(iofile)\n",
+ "iofile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Database Creation...\n",
+ "Enter Object 0 details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age: 25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Another? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Object 1 details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Tejaswi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age: 20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Another? y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Object 2 details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Kalpana\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age: 15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Another? n\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Database Access...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the object number to be accessed <-1 to end>: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Rajkumar\r\n",
+ "Age: 25\r\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wants to Modify? n\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the object number to be accessed <-1 to end>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Tejaswi\r\n",
+ "Age: 20\r\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wants to Modify? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Tejaswi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Age: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the object number to be accessed <-1 to end>: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name: Tejaswi\n",
+ "Age: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wants to Modify? n\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the object number to be accessed <-1 to end>: -1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-outfile.cpp, Page no-758"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "outfile=open(\"sample.out\", \"w\")\n",
+ "if not(outfile):\n",
+ " print \"Error: sample.out unable to open\"\n",
+ "else:\n",
+ " while(1):\n",
+ " buff=raw_input()\n",
+ " if buff==\"end\":\n",
+ " break\n",
+ " outfile.write(buff)\n",
+ " if not(outfile):\n",
+ " print \"write operation fail\"\n",
+ " break\n",
+ " outfile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "OOP is good\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C++ is OOP\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C++ is good\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "end\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-1, Page no-762"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "space=tab=line=0\n",
+ "fin=open(\"File1.txt\", \"r\")\n",
+ "#fin.write(\"F I L E\\nHandling\\nin\tC++\")\n",
+ "while 1:\n",
+ " c=fin.read(1)\n",
+ " if c==' ':\n",
+ " space+=1\n",
+ " if c=='\\t':\n",
+ " tab+=1\n",
+ " if c=='\\n':\n",
+ " line+=1\n",
+ " if c=='':\n",
+ " break\n",
+ "print \"Number of blank spaces =\", space\n",
+ "print \"Number of tabs =\", tab\n",
+ "print \"Number of lines =\", line"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of blank spaces = 3\n",
+ "Number of tabs = 1\n",
+ "Number of lines = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-2, Page no-763"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fin=open(\"Sample.txt\", \"r\")\n",
+ "#fin.write(\"File Handling in C++\")\n",
+ "print \"Here are the contents of the file, Sample.txt...\"\n",
+ "c=fin.read()\n",
+ "print c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Here are the contents of the file, Sample.txt...\n",
+ "File Handling in C++\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter19-ExceptionHandling.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter19-ExceptionHandling.ipynb
new file mode 100755
index 00000000..98576807
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter19-ExceptionHandling.ipynb
@@ -0,0 +1,1454 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3313deb61b605e4e7573c1c706ba00b703ad3ca8e59ab2363418ae531f9382dc"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 19-Exception Handling"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-divzero.cpp, Page no-770"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class number:\n",
+ " __num=int\n",
+ " def read(self):\n",
+ " self.__num=int(raw_input())\n",
+ " class DIVIDE():\n",
+ " pass\n",
+ " def div(self, num2):\n",
+ " if num2.__num==0:\n",
+ " raise self.DIVIDE()\n",
+ " else:\n",
+ " return self.__num/num2.__num\n",
+ "num1=number()\n",
+ "num2=number()\n",
+ "print \"Enter Number 1: \",\n",
+ "num1.read()\n",
+ "print \"Enter Number 2: \",\n",
+ "num2.read()\n",
+ "try:\n",
+ " print \"trying division operation...\",\n",
+ " result=num1.div(num2)\n",
+ " print \"succeeded\"\n",
+ "except number.DIVIDE:\n",
+ " print \"failed\"\n",
+ " print \"Exception: Divide-By-Zero\"\n",
+ "else:\n",
+ " print \"num1/num2 =\", result"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Number 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " trying division operation... failed\n",
+ "Exception: Divide-By-Zero\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-arrbound.cpp, Page no-772"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ARR_SIZE=10\n",
+ "class array:\n",
+ " __arr=[int]*ARR_SIZE\n",
+ " class RANGE():\n",
+ " pass\n",
+ " #overloading []\n",
+ " def op(self, i, x):\n",
+ " if i<0 or i>=ARR_SIZE:\n",
+ " raise self.RANGE()\n",
+ " self.__arr[i]=x\n",
+ "a=array()\n",
+ "print \"Maximum array size allowed =\", ARR_SIZE\n",
+ "try:\n",
+ " print \"Trying to refer a[1]...\",\n",
+ " a.op(1, 10) #a[1]=10\n",
+ " print \"succeeded\"\n",
+ " print \"Trying to refer a[15]...\",\n",
+ " a.op(15, 10) #a[15]=10\n",
+ " print \"succeeded\"\n",
+ "except array.RANGE:\n",
+ " print \"Out of Range in Array Reference\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum array size allowed = 10\n",
+ "Trying to refer a[1]... succeeded\n",
+ "Trying to refer a[15]... Out of Range in Array Reference\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-pass.cpp, Page no-774"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ARR_SIZE=10\n",
+ "class array:\n",
+ " __arr=[int]*ARR_SIZE\n",
+ " class RANGE():\n",
+ " pass\n",
+ " def __init__(self):\n",
+ " for i in range(ARR_SIZE):\n",
+ " self.__arr[i]=i\n",
+ " #overloading []\n",
+ " def op(self, i, x=None):\n",
+ " if i<0 or i>=ARR_SIZE:\n",
+ " raise self.RANGE()\n",
+ " if isinstance(x, int):\n",
+ " self.__arr[i]=x\n",
+ " else:\n",
+ " return self.__arr[i]\n",
+ "def read(a, index):\n",
+ " try:\n",
+ " element=a.op(index)\n",
+ " except array.RANGE:\n",
+ " print \"Parent passing exception to child to handle\"\n",
+ " raise\n",
+ " return element\n",
+ "a=array()\n",
+ "print \"Maximum array size allowed =\", ARR_SIZE\n",
+ "while(1):\n",
+ " index=int(raw_input(\"Enter element to be referenced: \"))\n",
+ " try:\n",
+ " print \"Trying to access object array 'a' for index =\", index\n",
+ " element=read(a, index)\n",
+ " print \"Elemnet in Array =\", element\n",
+ " except array.RANGE:\n",
+ " print \"Child: Out of Range in Array Reference\"\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum array size allowed = 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter element to be referenced: 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Trying to access object array 'a' for index = 1\n",
+ "Elemnet in Array = 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter element to be referenced: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Trying to access object array 'a' for index = 5\n",
+ "Elemnet in Array = 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter element to be referenced: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Trying to access object array 'a' for index = 10\n",
+ "Parent passing exception to child to handle\n",
+ "Child: Out of Range in Array Reference\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sign1.cpp, Page no-777"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class positive:\n",
+ " pass\n",
+ "class negative:\n",
+ " pass\n",
+ "class zero:\n",
+ " pass\n",
+ "def what_sign(num): #no exception list in python and hence the except block for class zero is removed to produce the desired output\n",
+ " if num>0:\n",
+ " raise positive()\n",
+ " elif num<0:\n",
+ " raise negative()\n",
+ " else:\n",
+ " raise zero()\n",
+ "num=int(raw_input(\"Enter any number: \"))\n",
+ "try:\n",
+ " what_sign(num)\n",
+ "except positive:\n",
+ " print \"+ve Exception\"\n",
+ "except negative:\n",
+ " print \"-ve Exception\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter any number: -10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-ve Exception\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sign2.cpp, Page no-778"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class zero:\n",
+ " pass\n",
+ "def what_sign(num): #no exception list in python and hence the except block for class zero is removed to produce the desired output\n",
+ " if num>0:\n",
+ " print \"+ve Exception\"\n",
+ " elif num<0:\n",
+ " print \"-ve Exception\"\n",
+ " else:\n",
+ " raise zero()\n",
+ "num=int(raw_input(\"Enter any number: \"))\n",
+ "what_sign(num)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter any number: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "+ve Exception\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-catall1.cpp, Page no-780"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class excep2:\n",
+ " pass\n",
+ "try:\n",
+ " print \"Throwing uncaught exception\"\n",
+ " raise excep2()\n",
+ "except:\n",
+ " print \"Caught all exceptions\"\n",
+ "print \"I am displayed\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Throwing uncaught exception\n",
+ "Caught all exceptions\n",
+ "I am displayed\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-catall2.cpp, Page no-780"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class ALPHA:\n",
+ " pass\n",
+ "_a=ALPHA()\n",
+ "def f3():\n",
+ " print \"f3() was called\"\n",
+ " raise _a\n",
+ "def f2():\n",
+ " try:\n",
+ " print \"f2() was called\"\n",
+ " f3()\n",
+ " except:\n",
+ " print \"f2() has elements with exceptions!\"\n",
+ "try:\n",
+ " f2()\n",
+ "except:\n",
+ " print \"Need more handlers!\"\n",
+ " print \"continud after handling exceptions\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "f2() was called\n",
+ "f3() was called\n",
+ "f2() has elements with exceptions!\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-twoexcep.cpp, Page no-782"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ARR_SIZE=10\n",
+ "class array:\n",
+ " __arr=[int]\n",
+ " __size=int\n",
+ " class RANGE:\n",
+ " pass\n",
+ " class SIZE:\n",
+ " pass\n",
+ " def __init__(self, SizeRequest):\n",
+ " self.__arr=[int]*SizeRequest\n",
+ " if SizeRequest<0 or SizeRequest>ARR_SIZE:\n",
+ " raise self.SIZE()\n",
+ " self.__size=SizeRequest\n",
+ " def __del__(self):\n",
+ " del self.__arr\n",
+ " #overloading []\n",
+ " def op(self, i, x=None):\n",
+ " if i<0 or i>=self.__size:\n",
+ " raise self.RANGE()\n",
+ " elif isinstance(x, int):\n",
+ " self.__arr[i]=x\n",
+ " else:\n",
+ " return self.__arr[i]\n",
+ "print \"Maximum array size allowed =\", ARR_SIZE\n",
+ "try:\n",
+ " print \"Trying to create object a1(5)...\",\n",
+ " a1=array(5)\n",
+ " print \"succeeded\"\n",
+ " print \"Trying to refer a1[4]...\",\n",
+ " a1.op(4, 10) #a1[4]=10\n",
+ " print \"succeeded..\",\n",
+ " print \"a1[4] =\", a1.op(4) #a1[4]\n",
+ " print \"Trying to refer a1[15]...\",\n",
+ " a1.op(15, 10) #a1[15]=10\n",
+ " print \"succeeded\"\n",
+ "except array.SIZE:\n",
+ " print \"..Size exceeds allowable Limit\"\n",
+ "except array.RANGE:\n",
+ " print \"..Array Reference Out of Range\"\n",
+ "try:\n",
+ " print \"Trying to create object a2(15)...\",\n",
+ " a2=array(15)\n",
+ " print \"succeeded\"\n",
+ " a2.op(3, 3) #a2[3]=3\n",
+ "except array.SIZE:\n",
+ " print \"..Size exceeds allowable Limit\"\n",
+ "except array.RANGE:\n",
+ " print \"..Array Reference Out of Range\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum array size allowed = 10\n",
+ "Trying to create object a1(5)... succeeded\n",
+ "Trying to refer a1[4]... succeeded.. a1[4] = 10\n",
+ "Trying to refer a1[15]... ..Array Reference Out of Range\n",
+ "Trying to create object a2(15)... ..Size exceeds allowable Limit\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-uncaught.cpp, Page no-784"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#error because there is no block to handles exceptions of type excep2()\n",
+ "class excep1:\n",
+ " pass\n",
+ "class excep2:\n",
+ " pass\n",
+ "try:\n",
+ " print \"Throwing uncaught exception\"\n",
+ " raise excep2()\n",
+ "except excep1:\n",
+ " print \"Exception 1\"\n",
+ " print \"I am not displayed\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Throwing uncaught exception\n"
+ ]
+ },
+ {
+ "ename": "excep2",
+ "evalue": "<__main__.excep2 instance at 0x00000000039A8408>",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mexcep2\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m<ipython-input-2-6ced6b7c0667>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"Throwing uncaught exception\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mexcep2\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mexcep1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"Exception 1\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mexcep2\u001b[0m: <__main__.excep2 instance at 0x00000000039A8408>"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-myhand.cpp, Page no-786"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class excep1:\n",
+ " pass\n",
+ "class excep2:\n",
+ " pass\n",
+ "def MyTerminate():\n",
+ " print \"My terminate is invoked\"\n",
+ " return \n",
+ "try:\n",
+ " print \"Throwing uncaught exception\"\n",
+ " raise excep2()\n",
+ "except excep1:\n",
+ " print \"Exception 1\"\n",
+ " print \"I am not displayed\"\n",
+ "except:\n",
+ " MyTerminate()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Throwing uncaught exception\n",
+ "My terminate is invoked\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sign3.cpp, Page no-787"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class zero:\n",
+ " pass\n",
+ "def what_sign(num):#no exception list in python and hence the except block is removed to produce the desired output\n",
+ " if num>0:\n",
+ " print \"+ve Exception\"\n",
+ " elif num<0:\n",
+ " print \"-ve Exception\"\n",
+ " else:\n",
+ " raise zero()\n",
+ "num=int(raw_input(\"Enter any number: \"))\n",
+ "what_sign(num)\n",
+ "print \"end of main()\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter any number: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "+ve Exception\n",
+ "end of main()\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sign4.cpp, Page no-788"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class zero:\n",
+ " pass\n",
+ "def MyUnexpected():\n",
+ " print \"My unexpected handler is invoked\"\n",
+ "def what_sign(num): #no exception list in python and hence the changes are made to produce the desired output\n",
+ " if num>0:\n",
+ " print \"+ve Exception\"\n",
+ " print \"end of main()\"\n",
+ " elif num<0:\n",
+ " print \"-ve Exception\"\n",
+ " print \"end of main()\"\n",
+ " else:\n",
+ " MyUnexpected()\n",
+ "num=int(raw_input(\"Enter any number: \"))\n",
+ "try:\n",
+ " what_sign(num)\n",
+ "except:\n",
+ " print \"catch all exceptions\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter any number: 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "My unexpected handler is invoked\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-interact.cpp, Page no-790"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "VEC_SIZE=10\n",
+ "class vector:\n",
+ " __vec=[int]\n",
+ " __size=int\n",
+ " class RANGE:\n",
+ " pass\n",
+ " class SIZE:\n",
+ " pass\n",
+ " def __init__(self, SizeRequest):\n",
+ " self.__vec=[int]*SizeRequest\n",
+ " if SizeRequest<0 or SizeRequest>VEC_SIZE:\n",
+ " raise self.SIZE()\n",
+ " self.__size=SizeRequest\n",
+ " def __del__(self):\n",
+ " del self.__vec\n",
+ " #overloading []\n",
+ " def op(self, i, x=None):\n",
+ " if i<0 or i>=self.__size:\n",
+ " raise self.RANGE()\n",
+ " elif isinstance(x, int):\n",
+ " self.__vec[i]=x\n",
+ " else:\n",
+ " return self.__vec[i]\n",
+ "print \"Maximum vector size allowed =\", VEC_SIZE\n",
+ "try:\n",
+ " size=int(raw_input(\"What is the size of vector you want to create: \"))\n",
+ " print \"Trying to create object vector v1 of size =\", size,\n",
+ " v1=vector(size)\n",
+ " print \"..succeeded\"\n",
+ " index=int(raw_input(\"Which vector element you want to access (index): \"))\n",
+ " print \"What is the new value for v1[\", index, \"]:\",\n",
+ " data=int(raw_input())\n",
+ " print \"Trying to modify a1[\", index, \"]...\",\n",
+ " v1.op(index, data) #v1[index]=data\n",
+ " print \"succeeded\"\n",
+ " print \"New value of a1[\", index, \"] =\", v1.op(index) #v1[index]\n",
+ "except vector.SIZE:\n",
+ " print \"failed\\nVector creation size exceeds allowable limit\"\n",
+ "except vector.RANGE:\n",
+ " print \"failed\\nVector reference out-of-range\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum vector size allowed = 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the size of vector you want to create: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Trying to create object vector v1 of size = 5 ..succeeded\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Which vector element you want to access (index): 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is the new value for v1[ 10 ]:"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Trying to modify a1[ 10 ]... failed\n",
+ "Vector reference out-of-range\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-virtual.cpp, Page no-792"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class WRONG_AGE:\n",
+ " pass\n",
+ "class Father:\n",
+ " def __init__(self, n):\n",
+ " if n<0:\n",
+ " raise WRONG_AGE()\n",
+ " self.__f_age=n\n",
+ " def GetAge(self):\n",
+ " return self.__f_age\n",
+ "class Son(Father):\n",
+ " def __init__(self, n, m):\n",
+ " Father.__init__(self, n)\n",
+ " if m>=n:\n",
+ " raise WRONG_AGE()\n",
+ " self.__s_age=m\n",
+ " def GetAge(self):\n",
+ " return self.__s_age\n",
+ "basep=[Father]\n",
+ "father_age=int(raw_input(\"Enter Age of Father: \"))\n",
+ "try:\n",
+ " basep=Father(father_age)\n",
+ "except WRONG_AGE:\n",
+ " print \"Error: Father's Age is < 0\"\n",
+ "else:\n",
+ " print \"Father's Age:\", basep.GetAge()\n",
+ " del basep\n",
+ " son_age=int(raw_input(\"Enter Age of Son: \"))\n",
+ " try:\n",
+ " basep=Son(father_age, son_age)\n",
+ " except WRONG_AGE:\n",
+ " print \"Error: Father's Age cannot be less than son age\"\n",
+ " else:\n",
+ " print \"Father's Age:\", basep.GetAge()\n",
+ " del basep"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Age of Father: 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Father's Age: 20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Age of Son: 45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Error: Father's Age cannot be less than son age\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-matrix.cpp, Page no-794"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "TRUE=1\n",
+ "FALSE=0\n",
+ "class MatError:\n",
+ " pass\n",
+ "class matrix:\n",
+ " __MaxRow=int\n",
+ " __MaxCol=int\n",
+ " def __init__(self, row=0, col=0):\n",
+ " self.__MaxRow=row\n",
+ " self.__MaxCol=col\n",
+ " self.__MatPtr=[[float]*5]*5\n",
+ " def __add__(self, b):\n",
+ " c=matrix(self.__MaxRow, self.__MaxCol)\n",
+ " if self.__MaxRow != b._matrix__MaxRow or self.__MaxCol != b._matrix__MaxCol:\n",
+ " raise MatError()\n",
+ " for i in range(self.__MaxRow):\n",
+ " for j in range(self.__MaxCol):\n",
+ " c._matrix__MatPtr[i][j]=self.__MatPtr[i][j]+b._matrix__MatPtr[i][j]\n",
+ " return c\n",
+ " def __sub__(self, b):\n",
+ " c=matrix(self.__MaxRow, self.__MaxCol)\n",
+ " if self.__MaxRow != b._matrix__MaxRow or self.__MaxCol != b._matrix__MaxCol:\n",
+ " raise MatError()\n",
+ " for i in range(self.__MaxRow):\n",
+ " for j in range(self.__MaxCol):\n",
+ " c._matrix__MatPtr[i][j]=self.__MatPtr[i][j]-b._matrix__MatPtr[i][j]\n",
+ " return c\n",
+ " def __mul__(self, b):\n",
+ " c=matrix(self.__MaxRow, b._matrix__MaxCol)\n",
+ " if self.__MaxCol!=b._matrix__MaxRow:\n",
+ " raise MatError()\n",
+ " for i in range(c._matrix__MaxRow):\n",
+ " for j in range(c._matrix__MaxCol):\n",
+ " c._matrix__MatPtr[i][j]=0\n",
+ " for k in range(self.__MaxCol):\n",
+ " c._matrix__MatPtr[i][j]+=self.__MatPtr[i][k]*b._matrix__MatPtr[k][j]\n",
+ " return c\n",
+ " def __eq__(self, b):\n",
+ " if self.__MaxRow != b._matrix__MaxRow or self.__MaxCol != b._matrix__MaxCol:\n",
+ " return FALSE\n",
+ " for i in range(self.__MaxRow):\n",
+ " for j in range(self.__MaxCol):\n",
+ " if self.__MatPtr[i][j]!=b._matrix__MatPtr[i][j]:\n",
+ " return FALSE\n",
+ " return TRUE\n",
+ " def __assign__(self, b):\n",
+ " self.__MaxRow = b._matrix__MaxRow\n",
+ " self.__MaxCol = b._matrix__MaxCol\n",
+ " for i in range(self.__MaxRow):\n",
+ " for j in range(self.__MaxCol):\n",
+ " self.__MatPtr[i][j]=b._matrix__MatPtr[i][j]\n",
+ " def Input(self):\n",
+ " self.__MaxRow=int(raw_input(\"How many rows? \"))\n",
+ " self.__MaxCol=int(raw_input(\"How many columns? \"))\n",
+ " self.__MatPtr = []\n",
+ " for i in range(0,self.__MaxRow):\n",
+ " self.__MatPtr.append([])\n",
+ " for j in range(0,self.__MaxCol):\n",
+ " print \"Matrix[%d,%d] =? \" %(i, j),\n",
+ " self.__MatPtr[i].append(float(raw_input()))\n",
+ " def output(self):\n",
+ " for i in range(self.__MaxRow):\n",
+ " print \"\"\n",
+ " for j in range(self.__MaxCol):\n",
+ " print \"%g\" %self.__MatPtr[i][j],\n",
+ "a=matrix()\n",
+ "b=matrix()\n",
+ "print \"Enter Matrix A details...\"\n",
+ "a.Input()\n",
+ "print \"Enter Matrix B details...\"\n",
+ "b.Input()\n",
+ "print \"Matrix A is...\",\n",
+ "a.output()\n",
+ "print \"\\nMatrix B is...\",\n",
+ "b.output()\n",
+ "c=matrix()\n",
+ "try:\n",
+ " c=a+b\n",
+ " print \"\\nC = A + B...\",\n",
+ " c.output()\n",
+ "except MatError:\n",
+ " print \"\\nInvalid matrix order for addition\",\n",
+ "d=matrix()\n",
+ "try:\n",
+ " d=a-b\n",
+ " print \"\\nD = A - B...\",\n",
+ " d.output()\n",
+ "except MatError:\n",
+ " print \"\\nInvalid matrix order for subtraction\",\n",
+ "e=matrix(3, 3)\n",
+ "try:\n",
+ " e=a*b\n",
+ " print \"\\nE = A * B...\",\n",
+ " e.output()\n",
+ "except MatError:\n",
+ " print \"\\nInvalid matrix order for multiplication\",\n",
+ "print \"\\n(Is matrix A equal to matrix B) ?\",\n",
+ "if a==b:\n",
+ " print \"Yes\"\n",
+ "else:\n",
+ " print \"No\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Matrix A details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many rows? 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many columns? 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrix[0,0] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[0,1] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Matrix B details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many rows? 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many columns? 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrix[0,0] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[1,0] =? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix A is... \n",
+ "1 2 \n",
+ "Matrix B is... \n",
+ "1 \n",
+ "2 \n",
+ "Invalid matrix order for addition \n",
+ "Invalid matrix order for subtraction \n",
+ "E = A * B... \n",
+ "5 \n",
+ "(Is matrix A equal to matrix B) ? No\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-recovery.cpp, Page no-802"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_SIG_INT=7\n",
+ "MAX_UNSIG_INT=15\n",
+ "class OVERFLOW:\n",
+ " pass\n",
+ "def sum(i, j, k):\n",
+ " try:\n",
+ " #Version1 procedure\n",
+ " result=i+j\n",
+ " if result>MAX_SIG_INT:\n",
+ " raise OVERFLOW()\n",
+ " result=result+k\n",
+ " if result>MAX_SIG_INT:\n",
+ " raise OVERFLOW()\n",
+ " print \"Version-1 succeeds\"\n",
+ " except OVERFLOW:\n",
+ " print \"Version-1 fails\"\n",
+ " try:\n",
+ " #Version2 procedure\n",
+ " result=i+k\n",
+ " if result>MAX_SIG_INT:\n",
+ " raise OVERFLOW()\n",
+ " result=result+j\n",
+ " if result>MAX_SIG_INT:\n",
+ " raise OVERFLOW()\n",
+ " print \"Version-2 succeeds\"\n",
+ " except OVERFLOW:\n",
+ " print \"Version-2 fails\"\n",
+ " try:\n",
+ " #Version3 procedure\n",
+ " result=j+k\n",
+ " if result>MAX_SIG_INT:\n",
+ " raise OVERFLOW()\n",
+ " result=result+i\n",
+ " if result>MAX_SIG_INT:\n",
+ " raise OVERFLOW()\n",
+ " print \"Version-3 succeeds\"\n",
+ " except OVERFLOW:\n",
+ " print \"Error: Overflow. All versions falied\"\n",
+ " return result\n",
+ "print \"Sum of 7, -3, 2 computation...\"\n",
+ "result=sum(7, -3, 2)\n",
+ "print \"Sum =\", result\n",
+ "print \"Sum of 7, 2, -3 computation...\"\n",
+ "result=sum(7,2, -3)\n",
+ "print \"Sum =\", result\n",
+ "print \"Sum of 3, 3, 2 computation...\"\n",
+ "result=sum(3, 3, 2)\n",
+ "print \"Sum =\", result"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sum of 7, -3, 2 computation...\n",
+ "Version-1 succeeds\n",
+ "Sum = 6\n",
+ "Sum of 7, 2, -3 computation...\n",
+ "Version-1 fails\n",
+ "Version-2 succeeds\n",
+ "Sum = 6\n",
+ "Sum of 3, 3, 2 computation...\n",
+ "Version-1 fails\n",
+ "Version-2 fails\n",
+ "Error: Overflow. All versions falied\n",
+ "Sum = 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-new1.cpp, Page no-804"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "size=int(raw_input(\"How many bytes to be allocated: \"))\n",
+ "try:\n",
+ " data=[int]*size\n",
+ " print \"Memory allocation success, address =\", hex(id(data))\n",
+ "except:\n",
+ " print \"Could not allocate. Bye...\"\n",
+ "del data"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many bytes to be allocated: 300\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Memory allocation success, address = 0x3717188L\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-new2.cpp, Page no-805"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def display(data, m, n):\n",
+ " for i in range(m):\n",
+ " for j in range(n):\n",
+ " print data[i][j],\n",
+ " print \"\"\n",
+ "def de_allocate(data, m):\n",
+ " for i in range(m-1):\n",
+ " del data[i]\n",
+ "m, n=[int(x) for x in raw_input(\"Enter rows and columns count: \").split()]\n",
+ "try:\n",
+ " data = []\n",
+ " for i in range(m):\n",
+ " data.append([])\n",
+ " for j in range(n):\n",
+ " data[i].append(0)\n",
+ "except:\n",
+ " print \"Could not allocate. Bye...\"\n",
+ "else:\n",
+ " for i in range(m):\n",
+ " for j in range(n):\n",
+ " data[i][j]=i+j\n",
+ " display(data, m, n)\n",
+ " de_allocate(data, m)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter rows and columns count: 3 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0 1 2 3 \n",
+ "1 2 3 4 \n",
+ "2 3 4 5 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-1, Page no-812"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#ther is no goto in python\n",
+ "def main():\n",
+ " num=int(raw_input(\"Please enter an integer value: \"))\n",
+ " if isinstance(num, int):\n",
+ " print \"You entered a correct type of value\"\n",
+ " else:\n",
+ " raise num\n",
+ "try:\n",
+ " main()\n",
+ "except:\n",
+ " print \"You enetered incorrect type of value; try again\"\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter an integer value: 10.7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You enetered incorrect type of value; try again\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please enter an integer value: 8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You entered a correct type of value\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-2, Page no-812"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Int:\n",
+ " def __init__(self, val):\n",
+ " self.value=val\n",
+ "class Double:\n",
+ " def __init__(self, val):\n",
+ " self.value=val\n",
+ "class Str:\n",
+ " def __init__(self, val):\n",
+ " self.value=val\n",
+ "i=int(raw_input(\"Press an integer between 1 - 3 to test exception handling with multiple catch blocks..\"))\n",
+ "try:\n",
+ " if i==1:\n",
+ " print \"Throwing integer value\"\n",
+ " raise Int(1)\n",
+ " if i==2:\n",
+ " print \"Throwing double value\"\n",
+ " raise Double(1.12)\n",
+ " if i==3:\n",
+ " print \"Throwing charcter value\"\n",
+ " raise Str('A')\n",
+ "except Int as e: #type of an exception raised is not correctly determined in the exception block and hence use of classes \n",
+ " print \"Caught an integer value\", e.value\n",
+ "except Double as e:\n",
+ " print \"Caught a double value\", e.value\n",
+ "except Str as e:\n",
+ " print \"Caught a character value\", e.value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Press an integer between 1 - 3 to test exception handling with multiple catch blocks..3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Throwing charcter value\n",
+ "Caught a character value A\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter2-MovingFromCtoC++.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter2-MovingFromCtoC++.ipynb
new file mode 100755
index 00000000..a2a5c818
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter2-MovingFromCtoC++.ipynb
@@ -0,0 +1,1389 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:67ef32c0745ec7cb1c0a0b98cb9b19c7c774d2c564bc299d0eb593490455997d"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2- Moving from C to C++"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-hello.c, Page no-32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Hello World\" #printing a statement"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello World\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-hello.cpp, Page no-32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"Hello World\" #printing a statement"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello World\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-output.cpp, Page no-36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "msg=\"C++ cout object\"\n",
+ "sex='M'\n",
+ "age=24\n",
+ "number=420.5\n",
+ "print sex, \n",
+ "print \" \", age, \" \", number\n",
+ "print msg\n",
+ "print '%d%d%d' %(1,2,3)\n",
+ "print number+1\n",
+ "print 99.99"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "M 24 420.5\n",
+ "C++ cout object\n",
+ "123\n",
+ "421.5\n",
+ "99.99\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-read.cpp, Page no-38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "name=[None]*25 #char name[25]\n",
+ "address=[None]*25 #char address[25]\n",
+ "name=raw_input(\"Enter name: \") #take input from user\n",
+ "age=int(raw_input(\"Enter Age: \"))\n",
+ "address=raw_input(\"Enter address: \")\n",
+ "print \"The data entered are: \"\n",
+ "print \"Name =\", name\n",
+ "print \"Age =\", age\n",
+ "print \"Address =\", address"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Age: 24\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter address: C-DAC-Bangalore\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The data entered are: \n",
+ "Name = Rajkumar\n",
+ "Age = 24\n",
+ "Address = C-DAC-Bangalore\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-simpint.cpp, Page no-41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "principle=int(raw_input(\"Enter Principle Amount: \"))\n",
+ "time=int(raw_input(\"Enter time (in years): \"))\n",
+ "rate=int(raw_input(\"Enter Rate of Interest: \"))\n",
+ "SimpInt=(principle*time*rate)/100\n",
+ "print \"Simple Interest =\", SimpInt\n",
+ "total= principle + SimpInt\n",
+ "print \"Total Amount =\", total"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Principle Amount: 1000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter time (in years): 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Rate of Interest: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Simple Interest = 100\n",
+ "Total Amount = 1100\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-area.cpp, Page no-42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "PI=3.1452 \n",
+ "radius=float(raw_input(\"Enter Radius of Circle: \"))\n",
+ "area=PI*radius*radius\n",
+ "print \"Area of Circle =\", area"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Radius of Circle: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area of Circle = 12.5808\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-disp.c, Page no-43"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def display(msg): #pass by reference\n",
+ " print msg\n",
+ " msg=\"Misuse\"\n",
+ " return msg\n",
+ "string=[None]*15\n",
+ "string=\"Hello World\"\n",
+ "string=display(string)\n",
+ "print string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello World\n",
+ "Misuse\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-disp.cpp, Page No-44"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def display(msg): #pass by value\n",
+ " print msg\n",
+ "string=[None]*15\n",
+ "string=\"Hello World\"\n",
+ "display(string)\n",
+ "print string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hello World\n",
+ "Hello World\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-global.cpp, Page no-45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "num=20\n",
+ "def main():\n",
+ " global num\n",
+ " x=num\n",
+ " num=10\n",
+ " print \"Local =\", num\n",
+ " print \"Global =\",x\n",
+ " print \"Global+Local =\", x+num\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Local = 10\n",
+ "Global = 20\n",
+ "Global+Local = 30\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-loop.cpp, Page no-45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "counter=50\n",
+ "def main():\n",
+ " global counter\n",
+ " x=counter\n",
+ " for counter in range(1, 10):\n",
+ " print x/counter\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "50\n",
+ "25\n",
+ "16\n",
+ "12\n",
+ "10\n",
+ "8\n",
+ "7\n",
+ "6\n",
+ "5\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-var1.cpp, Page no-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "for i in range(5):\n",
+ " print i\n",
+ "i+=1;\n",
+ "print i"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n",
+ "1\n",
+ "2\n",
+ "3\n",
+ "4\n",
+ "5\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-def2.cpp, Page no-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=10\n",
+ "def main():\n",
+ " global a\n",
+ " global_a=a\n",
+ " print global_a\n",
+ " a=20\n",
+ " def temp():\n",
+ " a=30\n",
+ " print a\n",
+ " print global_a\n",
+ " temp()\n",
+ " print a\n",
+ " print global_a\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n",
+ "30\n",
+ "10\n",
+ "20\n",
+ "10\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-refvar.cpp, Page no-48"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=z=1\n",
+ "b=2\n",
+ "c=3\n",
+ "print \"a=\",a, \"b=\", b, \"c=\", c, \"z=\", z\n",
+ "a=z=b\n",
+ "print \"a=\",a, \"b=\", b, \"c=\", c, \"z=\", z\n",
+ "a=z=c\n",
+ "print \"a=\",a, \"b=\", b, \"c=\", c, \"z=\", z\n",
+ "print \"&a=\", hex(id(a)),\"&b=\", hex(id(b)) , \"&c=\", hex(id(c))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a= 1 b= 2 c= 3 z= 1\n",
+ "a= 2 b= 2 c= 3 z= 2\n",
+ "a= 3 b= 2 c= 3 z= 3\n",
+ "&a= 0x1d95f68L &b= 0x1d95f80L &c= 0x1d95f68L\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-reftest.cpp, Page no-49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "n=c_int(100)\n",
+ "p=pointer(n)\n",
+ "m=p[0]\n",
+ "print \"n =\", n.value, \"m =\", m, \"*p =\", p[0]\n",
+ "k=c_int(100)\n",
+ "p=pointer(k)\n",
+ "k.value=200\n",
+ "print \"n =\", n.value, \"m =\", m, \"*p =\", p[0]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "n = 100 m = 100 *p = 100\n",
+ "n = 100 m = 100 *p = 200\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-newmax.cpp, Page no-50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Max(a, b):\n",
+ " if(a>b):\n",
+ " return a\n",
+ " else:\n",
+ " return b\n",
+ "x, y=[int(x) for x in raw_input(\"Enter two integers: \").split()] #takes input in a single line separated by white space\n",
+ "print \"Maximum =\", Max(x,y)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers: 10 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum = 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-swap.cpp, Page no-53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap (x, y): #pass by reference\n",
+ " i=x\n",
+ " x=y\n",
+ " y=i\n",
+ " return x, y\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two integers <a, b>: \").split()]\n",
+ "(a,b)=swap(a, b)\n",
+ "print \"On swapping <a, b>:\", a, b "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers <a, b>: 2 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <a, b>: 3 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-square.cpp, Page no-54"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def square(x):\n",
+ " x=x*x\n",
+ " return x\n",
+ "num=float(raw_input('Enter a number <float>: '))\n",
+ "print 'Its square =', square(num)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number <float>: 5.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Its square = 30.25\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-show.c, Page no-56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def show_integer(val):\n",
+ " print \"Integer: \", val\n",
+ "def show_double(val):\n",
+ " print \"Double: \", val\n",
+ "def show_string(val):\n",
+ " print \"String: \", val\n",
+ "show_integer(420)\n",
+ "show_double(3.1415)\n",
+ "show_string(\"Hello World\\n!\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Integer: 420\n",
+ "Double: 3.1415\n",
+ "String: Hello World\n",
+ "!\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-Show.cpp, Page no-56"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def show(val): #function overloading\n",
+ " if (isinstance(val, int)):\n",
+ " print \"Integer: \", val\n",
+ " if (isinstance(val, float)):\n",
+ " print \"Double: \", val\n",
+ " if(isinstance(val, str)):\n",
+ " print \"String: \", val\n",
+ "show(420)\n",
+ "show(3.1415)\n",
+ "show(\"Hello World\\n!\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Integer: 420\n",
+ "Double: 3.1415\n",
+ "String: Hello World\n",
+ "!\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-prnstr.cpp, Page no-58"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def showstring(string=\"Hello World!\"): #default arguments\n",
+ " print string\n",
+ "showstring(\"Here is an explicit argument\")\n",
+ "showstring()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Here is an explicit argument\n",
+ "Hello World!\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-defarg1.cpp, Page no-59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "def PrintLine(ch='-', RepeatCount=70): #default arguments\n",
+ " print \"\\n\"\n",
+ " for i in range(RepeatCount):\n",
+ " sys.stdout.write(ch)\n",
+ "PrintLine()\n",
+ "PrintLine('!')\n",
+ "PrintLine('*', 40)\n",
+ "PrintLine('R', 55)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "----------------------------------------------------------------------\n",
+ "\n",
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
+ "\n",
+ "****************************************\n",
+ "\n",
+ "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-defarg2, Page no-59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "def PrintLine(ch='-', RepeatCount=70, nLines=1): #default arguments\n",
+ " for j in range(nLines):\n",
+ " print \"\\n\"\n",
+ " for i in range(RepeatCount):\n",
+ " sys.stdout.write(ch)\n",
+ "PrintLine()\n",
+ "PrintLine('!')\n",
+ "PrintLine('*', 40)\n",
+ "PrintLine('R', 55)\n",
+ "PrintLine('&', 25, 2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "----------------------------------------------------------------------\n",
+ "\n",
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
+ "\n",
+ "****************************************\n",
+ "\n",
+ "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\n",
+ "\n",
+ "&&&&&&&&&&&&&&&&&&&&&&&&&\n",
+ "\n",
+ "&&&&&&&&&&&&&&&&&&&&&&&&&"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-date1.cpp, Page no-61"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from collections import namedtuple\n",
+ "struct_date = namedtuple('struct_date', 'day month year')\n",
+ "d1 = struct_date(26, 3, 1958)\n",
+ "d2 = struct_date(14, 4, 1971)\n",
+ "d3 = struct_date(1, 9, 1973)\n",
+ "print \"Birth Date of the First Author:\", \n",
+ "print \"%s-%s-%s\" %(d1.day, d1.month, d1.year)\n",
+ "print \"Birth Date of the Second Author:\", \n",
+ "print \"%s-%s-%s\" %(d2.day, d2.month, d2.year)\n",
+ "print \"Birth Date of the Third Author:\",\n",
+ "print \"%s-%s-%s\" %(d3.day, d3.month, d3.year)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Birth Date of the First Author: 26-3-1958\n",
+ "Birth Date of the Second Author: 14-4-1971\n",
+ "Birth Date of the Third Author: 1-9-1973\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-date2.cpp, Page no-63"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class date(Structure):\n",
+ " _fields_=[(\"day\", c_int),(\"month\", c_int),(\"year\",c_int)]\n",
+ " def show(self):\n",
+ " print \"%s-%s-%s\" %(self.day, self.month, self.year)\n",
+ "d1=date(26, 3, 1958)\n",
+ "d2 = date(14, 4, 1971)\n",
+ "d3 = date(1, 9, 1973)\n",
+ "print \"Birth Date of the First Author:\", \n",
+ "d1.show()\n",
+ "print \"Birth Date of the Second Author:\", \n",
+ "d2.show()\n",
+ "print \"Birth Date of the Third Author:\",\n",
+ "d3.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Birth Date of the First Author: 26-3-1958\n",
+ "Birth Date of the Second Author: 14-4-1971\n",
+ "Birth Date of the Third Author: 1-9-1973\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-cast.cpp, Page no-65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=int\n",
+ "b=420.5\n",
+ "print \"int(10.4) = \", int(10.4)\n",
+ "print \"int(10.99) = \", int(10.99)\n",
+ "print \"b = \", b\n",
+ "a=int(b)\n",
+ "print \"a = int(b) = \", a\n",
+ "b=float(a)+1.5\n",
+ "print \"b = float(a)+1.5 = \", b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "int(10.4) = 10\n",
+ "int(10.99) = 10\n",
+ "b = 420.5\n",
+ "a = int(b) = 420\n",
+ "b = float(a)+1.5 = 421.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-mswap.cpp, Page no-66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(x, y):\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " return x, y\n",
+ "ch1, ch2=raw_input(\"Enter two Characters <ch1, ch2>: \").split()\n",
+ "ch1, ch2=swap(ch1, ch2)\n",
+ "print \"On swapping <ch1, ch2>:\", ch1, ch2\n",
+ "a, b=[int(x) for x in raw_input(\"Enter integers <a, b>: \").split()]\n",
+ "a, b=swap(a, b)\n",
+ "print \"On swapping <a, b>:\", a, b\n",
+ "c, d=[float(x) for x in raw_input(\"Enter floats <c, d>: \").split()]\n",
+ "c, d=swap(c, d)\n",
+ "print \"On swapping <c, d>:\", c, d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two Characters <ch1, ch2>: R K\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <ch1, ch2>: K R\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter integers <a, b>: 5 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <a, b>: 10 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter floats <c, d>: 20.5 99.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <c, d>: 99.5 20.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-gswap.cpp, Page no-67"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(x, y):\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " return x, y\n",
+ "ch1, ch2=raw_input(\"Enter two Characters <ch1, ch2>: \").split()\n",
+ "ch1, ch2=swap(ch1, ch2)\n",
+ "print \"On swapping <ch1, ch2>:\", ch1, ch2\n",
+ "a, b=[int(x) for x in raw_input(\"Enter integers <a, b>: \").split()]\n",
+ "a, b=swap(a, b)\n",
+ "print \"On swapping <a, b>:\", a, b\n",
+ "c, d=[float(x) for x in raw_input(\"Enter floats <c, d>: \").split()]\n",
+ "c, d=swap(c, d)\n",
+ "print \"On swapping <c, d>:\", c, d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two Characters <ch1, ch2>: R K\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <ch1, ch2>: K R\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter integers <a, b>: 5 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <a, b>: 10 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter floats <c, d>: 20.5 99.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <c, d>: 99.5 20.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vector.cpp, Page no-72"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def AddVectors(a, b, c, size):\n",
+ " for i in range(size):\n",
+ " c[i]=a[i]+b[i]\n",
+ "def ReadVector(vector, size):\n",
+ " for i in range(size):\n",
+ " vector[i]=int(raw_input())\n",
+ "def ShowVector(vector, size):\n",
+ " for i in range(size):\n",
+ " print vector[i],\n",
+ "vec_size=int(raw_input(\"Enter size of vector: \"))\n",
+ "x=[int]*vec_size\n",
+ "y=[int]*vec_size\n",
+ "z=[int]*vec_size\n",
+ "print \"Enter Elements of vector x: \"\n",
+ "ReadVector(x, vec_size)\n",
+ "print \"Enter Elements of vector y: \"\n",
+ "ReadVector(y, vec_size)\n",
+ "AddVectors(x, y, z, vec_size)\n",
+ "print \"Summation Vector z=a+b:\",\n",
+ "ShowVector(z, vec_size)\n",
+ "del x\n",
+ "del y\n",
+ "del z"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter size of vector: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Elements of vector x: \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": [
+ "Enter Elements of vector y: \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": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Summation Vector z=a+b: 3 5 4 4 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example Page no-73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def area(s1, s2=None):#function overloading and default parameters\n",
+ " if (isinstance(s1, int)):\n",
+ " if(isinstance(s2, int)):\n",
+ " return (s1*s2)\n",
+ " else:\n",
+ " return (s1*s1)\n",
+ " elif (isinstance(s1, float)):\n",
+ " return (3.14*s1*s1)\n",
+ "s=int(raw_input(\"Enter the side length of the square: \"))\n",
+ "l, b=[int(x) for x in raw_input(\"Enter the length and breadth of the rectangle: \").split()]\n",
+ "r=float(raw_input(\"Enter the radius of the circle: \"))\n",
+ "print \"Area of square = \", area(s)\n",
+ "print \"Area of rectangle = \", area(l, b)\n",
+ "print \"Area of circle = \", area(r)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the side length of the square: 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the length and breadth of the rectangle: 2 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the radius of the circle: 2.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area of square = 4\n",
+ "Area of rectangle = 8\n",
+ "Area of circle = 19.625\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter3-C++AtAGlance.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter3-C++AtAGlance.ipynb
new file mode 100755
index 00000000..d81ed22a
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter3-C++AtAGlance.ipynb
@@ -0,0 +1,629 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d0ea461766152305a5e3562b0029be55e226b9445d5b8707016af6bf55ff7b00"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 3- C++ at a Glance"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example- counter1.cpp, Page no-77"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Counter:\n",
+ " __value=int\n",
+ " def __init__(self, val=None):#constructor\n",
+ " if(isinstance(val, int)):\n",
+ " self.__value=val\n",
+ " else:\n",
+ " self.__value=0\n",
+ " def __del__(self):#destructor\n",
+ " print \"object destroyed\"\n",
+ " def GetCounter(self):\n",
+ " return self.__value\n",
+ " def up(self):\n",
+ " self.__value=self.__value+1\n",
+ "counter1=Counter()\n",
+ "counter2=Counter(1)\n",
+ "print \"counter1 = \", counter1.GetCounter()\n",
+ "print \"counter2 = \", counter2.GetCounter()\n",
+ "counter1.up()\n",
+ "counter2.up()\n",
+ "print \"counter1 = \", counter1.GetCounter()\n",
+ "print \"counter2 = \", counter2.GetCounter()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "object destroyed\n",
+ "object destroyed\n",
+ "counter1 = 0\n",
+ "counter2 = 1\n",
+ "counter1 = 1\n",
+ "counter2 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-Stdclass.cpp, Page no-80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def setdata(self, roll_no_in, name_in): #outside declaration of member functions\n",
+ " self._student__roll_no=roll_no_in\n",
+ " self._student__name=name_in\n",
+ "def outdata(self):#outside declaration of member functions\n",
+ " print \"Roll no = \", self._student__roll_no\n",
+ " print \"Name = \", self._student__name\n",
+ "class student:\n",
+ " __roll_no=int\n",
+ " __name=[None]*20\n",
+ " setdata=setdata\n",
+ " outdata=outdata\n",
+ "s1=student()\n",
+ "s2=student()\n",
+ "s1.setdata(1, \"Tejaswi\")\n",
+ "s2.setdata(10, \"Rajkumar\")\n",
+ "print \"Student details...\"\n",
+ "s1.outdata()\n",
+ "s2.outdata()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Student details...\n",
+ "Roll no = 1\n",
+ "Name = Tejaswi\n",
+ "Roll no = 10\n",
+ "Name = Rajkumar\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-Counter2.cpp, Page no-82"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class counter:\n",
+ " __value=int\n",
+ " def __init__(self, val=0):\n",
+ " self.__value=val\n",
+ " def GetCounter(self):\n",
+ " return self.__value\n",
+ " def up(self):\n",
+ " self.__value+=1\n",
+ "class NewCounter(counter): #inheritance\n",
+ " def __init__(self, val=None) : \n",
+ " if(isinstance(val, int)):\n",
+ " counter.__init__(self, val)\n",
+ " else:\n",
+ " counter.__init__(self)\n",
+ " def down(self):\n",
+ " self._counter__value=self._counter__value-1\n",
+ "counter1=NewCounter()\n",
+ "counter2=NewCounter(1)\n",
+ "print \"counter1 initially =\", counter1.GetCounter()\n",
+ "print \"counter2 initially =\", counter2.GetCounter()\n",
+ "counter1.up()\n",
+ "counter2.up()\n",
+ "print \"counter1 on increment =\", counter1.GetCounter()\n",
+ "print \"counter2 on increment =\", counter2.GetCounter()\n",
+ "counter1.down()\n",
+ "counter2.down()\n",
+ "print \"counter1 on decrement =\", counter1.GetCounter()\n",
+ "print \"counter2 on decrement =\", counter2.GetCounter()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "counter1 initially = 0\n",
+ "counter2 initially = 1\n",
+ "counter1 on increment = 1\n",
+ "counter2 on increment = 2\n",
+ "counter1 on decrement = 0\n",
+ "counter2 on decrement = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-counter3.cpp, Page no-85"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class counter:\n",
+ " __value=int\n",
+ " def __init__(self, val=0):\n",
+ " self.__value=val\n",
+ " def GetCounter(self):\n",
+ " return self.__value\n",
+ " #overloading increment operator\n",
+ " def __iadd__(self, val):\n",
+ " self.__value+=val\n",
+ " return self\n",
+ " #overloading decrement operator\n",
+ " def __isub__(self, val):\n",
+ " self._counter__value-=val\n",
+ " return self\n",
+ "counter1=counter()\n",
+ "counter2=counter(1)\n",
+ "print \"counter1 initially =\", counter1.GetCounter()\n",
+ "print \"counter2 initially =\", counter2.GetCounter()\n",
+ "counter1+=1\n",
+ "counter2+=1\n",
+ "print \"counter1 on increment =\", counter1.GetCounter()\n",
+ "print \"counter2 on increment =\", counter2.GetCounter()\n",
+ "counter1-=1\n",
+ "counter2-=1\n",
+ "print \"counter1 on decrement =\", counter1.GetCounter()\n",
+ "print \"counter2 on decrement =\", counter2.GetCounter()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "counter1 initially = 0\n",
+ "counter2 initially = 1\n",
+ "counter1 on increment = 1\n",
+ "counter2 on increment = 2\n",
+ "counter1 on decrement = 0\n",
+ "counter2 on decrement = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-counter4.cpp, Page no-88"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class counter:\n",
+ " __value=int\n",
+ " def __init__(self, val=0):\n",
+ " self.__value=val\n",
+ " def GetCounter(self):\n",
+ " return self.__value\n",
+ " def __iadd__(self, val):\n",
+ " self.__value+=val\n",
+ " return self\n",
+ " def __isub__(self, val):\n",
+ " self._counter__value-=val\n",
+ " return self\n",
+ " #overloading of + operator\n",
+ " def __add__(self, counter2):\n",
+ " temp=counter()\n",
+ " temp.__value=self.__value+counter2.__value\n",
+ " return temp\n",
+ " #No overloading of << and >> operators in python\n",
+ " def output(self):\n",
+ " return self.__value\n",
+ "counter1=counter()\n",
+ "counter2=counter(1)\n",
+ "print \"counter1 initially =\", counter1.GetCounter()\n",
+ "print \"counter2 initially =\", counter2.GetCounter()\n",
+ "counter1+=1\n",
+ "counter2+=1\n",
+ "print \"counter1 on increment =\", counter1.GetCounter()\n",
+ "print \"counter2 on increment =\", counter2.GetCounter()\n",
+ "counter1-=1\n",
+ "counter2-=1\n",
+ "print \"counter1 on decrement =\", counter1.GetCounter()\n",
+ "print \"counter2 on decrement =\", counter2.GetCounter()\n",
+ "counter3=counter()\n",
+ "counter3=counter1+counter2\n",
+ "print \"counter3 = counter1+counter2 =\", counter3.output()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "counter1 initially = 0\n",
+ "counter2 initially = 1\n",
+ "counter1 on increment = 1\n",
+ "counter2 on increment = 2\n",
+ "counter1 on decrement = 0\n",
+ "counter2 on decrement = 1\n",
+ "counter3 = counter1+counter2 = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-virtual.cpp, Page no-91"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class Father:\n",
+ " __f_age=int\n",
+ " def __init__(self, n):\n",
+ " self.__f_age=n\n",
+ " def GetAge(self):\n",
+ " return self.__f_age\n",
+ "class Son(Father):\n",
+ " __s_age=int\n",
+ " def __init__(self, n, m):\n",
+ " Father.__init__(self, n)\n",
+ " self.__s_age=m\n",
+ " def GetAge(self):\n",
+ " return self.__s_age\n",
+ "basep=[Father]\n",
+ "basep=Father(45)\n",
+ "print \"Father's Age:\",\n",
+ "print basep.GetAge()\n",
+ "del basep\n",
+ "basep=[Son(45, 20)]\n",
+ "print \"Son's Age:\",\n",
+ "print basep[0].GetAge()\n",
+ "del basep"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Father's Age: 45\n",
+ "Son's Age: 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-vector.cpp, Page no-94"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class vector:\n",
+ " __size=int\n",
+ " def __init__(self, vector_size):\n",
+ " self.__size=vector_size\n",
+ " self.__v=[vector]*self.__size\n",
+ " def __del__(self):\n",
+ " del self.__v\n",
+ " def elem(self, i, x=None):\n",
+ " if isinstance(x, int) or isinstance(x, float):\n",
+ " if i>=self.__size:\n",
+ " print \"Error: Out of Range\"\n",
+ " return\n",
+ " self.__v[i]=x\n",
+ " else:\n",
+ " return self.__v[i]\n",
+ " def show(self):\n",
+ " for i in range(self.__size):\n",
+ " print self.elem(i), \",\",\n",
+ "int_vect=vector(5)\n",
+ "float_vect=vector(4)\n",
+ "for i in range(5):\n",
+ " int_vect.elem(i, i+1)\n",
+ "for i in range(4):\n",
+ " float_vect.elem(i,i+1.5)\n",
+ "print \"Integer Vector:\",\n",
+ "int_vect.show()\n",
+ "print \"\\nFloating Vector:\",\n",
+ "float_vect.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Integer Vector: 1 , 2 , 3 , 4 , 5 , \n",
+ "Floating Vector: 1.5 , 2.5 , 3.5 , 4.5 ,\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-number.cpp, Page no-97"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "class number:\n",
+ " __num=int\n",
+ " def read(self):\n",
+ " self.__num=int(raw_input())\n",
+ " class DIVIDE():\n",
+ " pass\n",
+ " def div(self, num2):\n",
+ " if num2.__num==0:\n",
+ " raise self.DIVIDE() #raise exception of type DIVIDE()\n",
+ " else:\n",
+ " return self.__num/num2.__num\n",
+ "num1=number()\n",
+ "num2=number()\n",
+ "print \"Enter Number 1: \",\n",
+ "num1.read()\n",
+ "print \"Enter Number 2: \",\n",
+ "num2.read()\n",
+ "try:\n",
+ " print \"trying division operation...\",\n",
+ " result=num1.div(num2)\n",
+ " print \"succeeded\"\n",
+ "except number.DIVIDE: #exception handler of exception type DIVIDE()\n",
+ " print \"failed\"\n",
+ " print \"Exception: Divide-By-Zero\"\n",
+ "else: #this block is executed only if no exception has been raised\n",
+ " print \"num1/num2 =\", result"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Number 1: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Number 2: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " trying division operation... failed\n",
+ "Exception: Divide-By-Zero\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-infile.cpp, Page no-101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "try:\n",
+ " infile=open(\"sample.in\", \"r\") #open file in input mode\n",
+ " while(1):\n",
+ " buff=infile.readline() #read a single line from the file\n",
+ " if buff=='': #to determine end of file\n",
+ " break\n",
+ " print buff,\n",
+ "except IOError: #error in opening file\n",
+ " print \"Error: sample.in non-existent\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rajkumar, C-DAC, India\n",
+ "Bjarne Stroustrup, AT & T, USA\n",
+ "Smrithi, Hyderabad, India\n",
+ "Tejaswi, Hyderabad, India\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-outfile.cpp, Page no-102"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "outfile=open(\"sample.out\", \"w\") #file opened in output mode\n",
+ "if not(outfile):\n",
+ " print \"Error: sample.out unable to open\"\n",
+ "else:\n",
+ " while(1):\n",
+ " buff=raw_input()\n",
+ " if buff==\"end\":\n",
+ " break\n",
+ " outfile.write(buff)\n",
+ " outfile.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "OOP is good\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C++ is OOP\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "C++ is good\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "end\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example, Page no-103"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "count=0\n",
+ "file1=open(\"FILE1.txt\", \"r\") #file opened in input mode\n",
+ "file2=open(\"FILE2.txt\", \"w\") #file opened in output mode\n",
+ "while(1):\n",
+ " ch=file1.read(1)\n",
+ " if ch=='': #detecting eof\n",
+ " break\n",
+ " if count%2==0:\n",
+ " file2.write(ch)\n",
+ " count+=1\n",
+ "print \"Alternate characters from File1 have been successfully copied into File2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Alternate characters from File1 have been successfully copied into File2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter4-DataTypes,OperatorsAndExpressions.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter4-DataTypes,OperatorsAndExpressions.ipynb
new file mode 100755
index 00000000..1b95ba16
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter4-DataTypes,OperatorsAndExpressions.ipynb
@@ -0,0 +1,881 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:17ba214af5fef45344b6cf20acb6a7b4a88d1bf393c6e0c1c50e04f764bab0ff"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4- Data types, Operators and Expressions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-show1.cpp, Page no-111"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=int\n",
+ "b=int\n",
+ "c=100\n",
+ "distance=float\n",
+ "a=c\n",
+ "b=c+100\n",
+ "distance=55.9\n",
+ "print \"a =\", a\n",
+ "print \"b =\", b\n",
+ "print \"c =\", c\n",
+ "print \"distance =\", distance"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a = 100\n",
+ "b = 200\n",
+ "c = 100\n",
+ "distance = 55.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-ascii.cpp, Page no-112"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "code=int(raw_input(\"Enter an ASCII code(0-127): \"))\n",
+ "symbol=code\n",
+ "print \"The symbol corresponding to %d is %c\" %(code, symbol)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter an ASCII code(0-127): 65\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The symbol corresponding to 65 is A\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-temper.cpp, Page no-115"
+ ]
+ },
+ {
+ "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\n",
+ "f=float(raw_input(\"Enter temperature in fahrenheit: \"))\n",
+ "c=(f-32)/1.8\n",
+ "print \"Equivalent Celsius = \", c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter temperature in Celsius: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Equivalent fahrenheit = 41.0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter temperature in fahrenheit: 40\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Equivalent Celsius = 4.44444444444\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-size.cpp, Page no-116"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "print \"sizeof( char ) =\", sizeof(c_char)\n",
+ "print \"sizeof( short ) =\", sizeof(c_short)\n",
+ "print \"sizeof( short int ) =\", sizeof(c_short)\n",
+ "print \"sizeof( int ) =\", sizeof(c_int)\n",
+ "print \"sizeof( long ) =\", sizeof(c_long)\n",
+ "print \"sizeof( long int ) =\", sizeof(c_long)\n",
+ "print \"sizeof( float ) =\", sizeof(c_float)\n",
+ "print \"sizeof( double ) =\", sizeof(c_double)\n",
+ "print \"sizeof( long double ) =\", sizeof(c_longdouble)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "sizeof( char ) = 1\n",
+ "sizeof( short ) = 2\n",
+ "sizeof( short int ) = 2\n",
+ "sizeof( int ) = 4\n",
+ "sizeof( long ) = 4\n",
+ "sizeof( long int ) = 4\n",
+ "sizeof( float ) = 4\n",
+ "sizeof( double ) = 8\n",
+ "sizeof( long double ) = 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-modules.cpp, Page no-120"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "numerator=int(raw_input(\"Enter numerator: \"))\n",
+ "denominator=int(raw_input(\"Enter denominator: \"))\n",
+ "result=numerator/denominator\n",
+ "remainder=numerator%denominator\n",
+ "print numerator, \"/\", denominator, \"=\", result\n",
+ "print numerator, \"%\", denominator, \"=\", remainder"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter numerator: 12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter denominator: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12 / 5 = 2\n",
+ "12 % 5 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-notemp.cpp, Page no-121"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a, b=[int(x) for x in raw_input(\"Enter two integers <a, b>: \").split()] #taking input in single line sperated by white space\n",
+ "a=a+b\n",
+ "b=a-b\n",
+ "a=a-b\n",
+ "print \"Value of a and b on swapping in main():\", a, b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers <a, b>: 10 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of a and b on swapping in main(): 20 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-relation.cpp, Page no-122"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "my_age=int(raw_input(\"Enter my age: \"))\n",
+ "your_age=int(raw_input(\"Enter your age: \"))\n",
+ "if(my_age==your_age):\n",
+ " print \"We are born in the same year.\"\n",
+ "else:\n",
+ " print \"We are born in different years\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter my age: 25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your age: 25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "We are born in the same year.\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-char1.cpp, Page no-123"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "c=c_byte(255) #signed char\n",
+ "d=c_byte(-1) #signed char\n",
+ "if c.value<0:\n",
+ " print 'c is less than 0'\n",
+ "else:\n",
+ " print 'c is not less than 0'\n",
+ "if d.value<0:\n",
+ " print 'd is less than 0'\n",
+ "else:\n",
+ " print 'd is not less than 0'\n",
+ "if c.value==d.value:\n",
+ " print 'c and d are equal'\n",
+ "else:\n",
+ " print 'c and d are not equal'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c is less than 0\n",
+ "d is less than 0\n",
+ "c and d are equal\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-char2.cpp, Page no-124"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "c=c_ubyte(255) #unsigned char\n",
+ "d=c_byte(-1) #signed char\n",
+ "if c.value<0:\n",
+ " print 'c is less than 0'\n",
+ "else:\n",
+ " print 'c is not less than 0'\n",
+ "if d.value<0:\n",
+ " print 'd is less than 0'\n",
+ "else:\n",
+ " print 'd is not less than 0'\n",
+ "if c.value==d.value:\n",
+ " print 'c and d are equal'\n",
+ "else:\n",
+ " print 'c and d are not equal'"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c is not less than 0\n",
+ "d is less than 0\n",
+ "c and d are not equal\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-leap.cpp, Page no-126"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "year=int(raw_input(\"Enter any year: \"))\n",
+ "if( (year%4==0 and year%100!=0) or (year%400==0)):\n",
+ " print year, \"is a leap year\"\n",
+ "else:\n",
+ " print year, \"is not a leap year\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter any year: 1996\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1996 is a leap year\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-large.cpp, Page no-127"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "u=c_uint(0) #unsigned integer\n",
+ "print 'Value before conversion:', u.value\n",
+ "u.value=~int(u.value) # 1's complement\n",
+ "print 'Value after conversion:', u.value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value before conversion: 0\n",
+ "Value after conversion: 4294967295\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-extract.cpp, Page no-130"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=int(raw_input(\"Enter an integer: \"))\n",
+ "n=int(raw_input(\"Enter bit position to extract: \"))\n",
+ "bit=(a>>(n-1))&1 #shift operator\n",
+ "print \"The bit is \", bit"
+ ],
+ "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 bit position to extract: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The bit is 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-max.cpp, Page no-133"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a, b=[int(x) for x in raw_input(\"Enter two integers: \").split()]\n",
+ "larger=a if a>b else b #?: operator\n",
+ "print \"The larger of the two is\", larger"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers: 10 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The larger of the two is 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-oddeven.cpp, Page no-133"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "num=int(raw_input(\"Enter the number: \"))\n",
+ "print \"The number\", num,\"is\",\n",
+ "print \"Even\" if num%2==0 else \"Odd\" #?: operator\n",
+ "num=int(raw_input(\"Enter the number: \"))\n",
+ "print \"The number\", num,\"is\",\n",
+ "print \"Even\" if num%2==0 else \"Odd\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The number 10 is Even\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number: 25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The number 25 is Odd\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-coerce.cpp, Page no-136"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "f=float\n",
+ "i=12\n",
+ "j=5\n",
+ "print \"when i = \", i, \"j = \", j\n",
+ "f=i/j\n",
+ "print \"i/j = \", f\n",
+ "f=float(i)/float(j)\n",
+ "print \"(float)i/j = \", f\n",
+ "f=float(i)/j\n",
+ "print \"float(i)/j = \", f\n",
+ "f=i/float(j)\n",
+ "print \"i/float(j) = \", f"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "when i = 12 j = 5\n",
+ "i/j = 2\n",
+ "(float)i/j = 2.4\n",
+ "float(i)/j = 2.4\n",
+ "i/float(j) = 2.4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-city.cpp, Page no-141"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "CITY='Bidar'\n",
+ "def which_city():\n",
+ " print 'City in Function:',\n",
+ " print CITY\n",
+ "print 'Earlier City:',\n",
+ "print CITY\n",
+ "CITY='Bangalore'\n",
+ "print 'New City:',\n",
+ "print CITY\n",
+ "which_city()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Earlier City: Bidar\n",
+ "New City: Bangalore\n",
+ "City in Function: Bangalore\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-color1.cpp, Page no-143"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def PrintColor(c):\n",
+ " (red, blue, green)=(0, 1, 2) #enum\n",
+ " type =['red', 'green', 'blue']\n",
+ " if c==red:\n",
+ " color='red'\n",
+ " elif c==blue:\n",
+ " color='blue'\n",
+ " else:\n",
+ " color ='green'\n",
+ " print 'Your color choice as per color2.cpp module:', color\n",
+ "(red, green, blue)=(0, 1, 2) #enum\n",
+ "type =['red', 'green', 'blue']\n",
+ "print 'Your color choice in color1.cpp module: green'\n",
+ "PrintColor(green)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your color choice in color1.cpp module: green\n",
+ "Your color choice as per color2.cpp module: blue\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-maxmacro.cpp, Page no-146"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Max(a, b):\n",
+ " return a if a>b else b\n",
+ "print 'max(2, 3) =', Max(2, 3)\n",
+ "print 'max(10.2, 4.5) =', Max(10.2, 4.5)\n",
+ "i=5\n",
+ "j=10\n",
+ "print 'i =',i\n",
+ "print 'j =', j\n",
+ "print 'On execution of k=max(++i, ++j);...'\n",
+ "i+=1\n",
+ "j+=1\n",
+ "k=Max(i+1, j+1)\n",
+ "print 'i =', i\n",
+ "print 'j =', j #the operand is j+1 and not ++j and thus the change is not reflected back in j. \n",
+ "print 'k =', k #operand of type j+=1 is not allowed"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "max(2, 3) = 3\n",
+ "max(10.2, 4.5) = 10.2\n",
+ "i = 5\n",
+ "j = 10\n",
+ "On execution of k=max(++i, ++j);...\n",
+ "i = 6\n",
+ "j = 11\n",
+ "k = 12\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-exp.cpp, Page no-148"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=30\n",
+ "b=20\n",
+ "c=11\n",
+ "result=a+b/(c-1)+a%b #--c is replaced by (c-1)\n",
+ "print 'a+b/--c+a%b =', result"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a+b/--c+a%b = 42\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example Page no-150"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "num1=int(raw_input(\"Enter the first number: \"))\n",
+ "num2=int(raw_input(\"Enter the second number: \"))\n",
+ "print num1, '+', num2, '=',num1+num2\n",
+ "print num1, '-', num2, '=',num1-num2\n",
+ "print num1, '*', num2, '=',num1*num2\n",
+ "print num1, '/', num2, '=',num1/num2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the first number: 20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the second number: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "20 + 10 = 30\n",
+ "20 - 10 = 10\n",
+ "20 * 10 = 200\n",
+ "20 / 10 = 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter5-ControlFlow.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter5-ControlFlow.ipynb
new file mode 100755
index 00000000..9efd46c9
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter5-ControlFlow.ipynb
@@ -0,0 +1,1280 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:6fa2540f90d9347d87cbc226c605764f3108594e5706b257d5d061ae951444a3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5- Control Flow"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-age1.cpp, Page no-153"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "age=int(raw_input(\"Enter your age: \"))\n",
+ "if(age>12 and age<20):\n",
+ " print \"you are a teen-aged person. good!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your age: 15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "you are a teen-aged person. good!\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-age2.cpp, Page no-154"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "age=int(raw_input(\"Enter your age: \"))\n",
+ "if(age<0):\n",
+ " print \"I am sorry!\"\n",
+ " print \"age can never be negative\"\n",
+ "if(age>12 and age<20):\n",
+ " print \"you are a teen-aged person. good!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your age: -10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "I am sorry!\n",
+ "age can never be negative\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-large.cpp, Page no-155"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "big=float\n",
+ "a, b, c=[float(x) for x in raw_input(\"Enter three floating-point numbers: \").split()] #taking input in single line separated by white space\n",
+ "big=a\n",
+ "if(b>big):\n",
+ " big=b\n",
+ "if(c>big):\n",
+ " big=c\n",
+ "print \"Largest of the three numbers =\", big"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter three floating-point numbers: 10.2 15.6 12.8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Largest of the three numbers = 15.6\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-age3.cpp, Page no-156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "age=int(raw_input(\"Enter your age: \"))\n",
+ "if(age>12 and age<20):\n",
+ " print \"you are a teen-aged person. good!\"\n",
+ "else:\n",
+ " print \"you are not a teen-aged person.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your age: 15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "you are a teen-aged person. good!\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-lived.cpp, Page no-157"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "years=float(raw_input(\"Enter your age in years: \"))\n",
+ "if(years<0):\n",
+ " print \"I am sorry! age can never be negative\"\n",
+ "else:\n",
+ " secs=years*365*24*60*60\n",
+ " print \"You have lived for %.4g seconds\" %(secs)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your age in years: 25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "You have lived for 7.884e+08 seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-age4.cpp, Page no-158"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "age=int(raw_input(\"Enter your age: \"))\n",
+ "if(age>12 and age<20):\n",
+ " print \"you are a teen-aged person. good!\"\n",
+ "else:\n",
+ " if(age<13):\n",
+ " print \"you will surely reach teen-age.\"\n",
+ " else:\n",
+ " print \"you have crossed teen-age!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your age: 25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "you have crossed teen-age!\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-count1.cpp, Page no-159"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n=int(raw_input(\"How many integers to be displayed: \"))\n",
+ "for i in range(n):\n",
+ " print i"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many integers to be displayed: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n",
+ "1\n",
+ "2\n",
+ "3\n",
+ "4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sumsq1.cpp, Page no-160"
+ ]
+ },
+ {
+ "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": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sumsq2.cpp, Page no-161"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Sum=0\n",
+ "sum_of_squares=0\n",
+ "for i in range(30, 0, -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": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-noinit.cpp, Page no-162"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "i=1\n",
+ "for i in range(i, 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": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-pyramid.cpp, Page no-163"
+ ]
+ },
+ {
+ "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 q in range(1, n-p+1):\n",
+ " print \"\\t\",\n",
+ " m=p\n",
+ " for q in range (1, p+1):\n",
+ " print \"\\t\", m,\n",
+ " m+=1\n",
+ " m=m-2\n",
+ " for q in range(1, p):\n",
+ " print \"\\t\", m,\n",
+ " m-=1\n",
+ " print ''"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number of lines: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\t\t\t\t\t1 \n",
+ "\t\t\t\t2 \t3 \t2 \n",
+ "\t\t\t3 \t4 \t5 \t4 \t3 \n",
+ "\t\t4 \t5 \t6 \t7 \t6 \t5 \t4 \n",
+ "\t5 \t6 \t7 \t8 \t9 \t8 \t7 \t6 \t5 \n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-count2.cpp, Page no-164"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n=int(raw_input(\"How many integers to be displayed: \"))\n",
+ "i=0\n",
+ "while i<n:\n",
+ " print i\n",
+ " i+=1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many integers to be displayed: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n",
+ "1\n",
+ "2\n",
+ "3\n",
+ "4\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-average1.cpp, Page no-164"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Sum=0\n",
+ "count=0\n",
+ "print \"Enter the marks, -1 at the end...\"\n",
+ "marks=int(raw_input())\n",
+ "while marks!=-1:\n",
+ " Sum+=marks\n",
+ " count+=1\n",
+ " marks=int(raw_input())\n",
+ "average=Sum/count\n",
+ "print \"The average is\", average "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the marks, -1 at the end...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "80\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "75\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "82\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "74\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average is 77\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-bin2deci.cpp, Page no-165"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "decimal=0\n",
+ "position=0\n",
+ "binary=int(raw_input(\"Enter the binary number: \"))\n",
+ "while binary:\n",
+ " digit=binary%10\n",
+ " decimal+=digit<<position\n",
+ " binary/=10\n",
+ " position+=1\n",
+ "print \"Its decimal equivalent =\", decimal"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the binary number: 111\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Its decimal equivalent = 7\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-count3.cpp, Page no-166"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n=int(raw_input(\"How many integers to be displayed: \"))\n",
+ "i=0\n",
+ "while 1: #do while loop\n",
+ " print i\n",
+ " i+=1\n",
+ " if i>=n:\n",
+ " break"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many integers to be displayed: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n",
+ "1\n",
+ "2\n",
+ "3\n",
+ "4\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-dowhile.cpp, Page no-167"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "while 1: #do-while loop\n",
+ " inchar=raw_input(\"Enter your sex (m/f): \")\n",
+ " if(inchar=='m' or inchar=='f'):\n",
+ " break\n",
+ "if inchar=='m':\n",
+ " print \"so you are male. good!\"\n",
+ "else:\n",
+ " print \"so you are female. good!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your sex (m/f): d\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your sex (m/f): b\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your sex (m/f): m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "so you are male. good!\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-pa1.cpp, Page no-167"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "rev=0\n",
+ "num=int(raw_input(\"Enter the number: \"))\n",
+ "n=num\n",
+ "while 1:\n",
+ " digit=num%10\n",
+ " rev=rev*10 + digit\n",
+ " num/=10\n",
+ " if num==0:\n",
+ " break\n",
+ "print \"Reverse of the number =\", 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": [
+ "Enter the number: 121\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Reverse of the number = 121\n",
+ "The number is a palindrome\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-average2.cpp, Page no-169"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Sum=0\n",
+ "count=0\n",
+ "print \"Enter the marks, -1 at the end...\"\n",
+ "while 1:\n",
+ " marks=int(raw_input())\n",
+ " if marks==-1:\n",
+ " break\n",
+ " Sum+=marks\n",
+ " count+=1\n",
+ "average=Sum/count\n",
+ "print \"The average is\", average "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the marks, -1 at the end...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "80\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "75\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "82\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "74\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The average is 77\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sex2.cpp, Page no-171"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ch=raw_input(\"Enter your sex (m/f): \")\n",
+ "if ch=='m':\n",
+ " print \"So you are male. good!\"\n",
+ "elif ch=='f':\n",
+ " print \"So you are female. good!\"\n",
+ "else:\n",
+ " print \"Error: Invalid sex code!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your sex (m/f): m\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "So you are male. good!\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-calc.cpp, Page no-172"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"------------------Basic Calculator------------------\"\n",
+ "print \"Choose an option:\"\n",
+ "print \"Add\"\n",
+ "print \"Subtract\"\n",
+ "print \"Multiply\"\n",
+ "print \"Divide\"\n",
+ "ch=raw_input()\n",
+ "num1, num2=[int(x) for x in raw_input(\"Enter the value of the operands: \").split()]\n",
+ "if ch=='1':\n",
+ " print num1+num2\n",
+ "elif ch=='2':\n",
+ " print num1-num2\n",
+ "elif ch=='3':\n",
+ " print num1*num2\n",
+ "elif ch=='4':\n",
+ " print num1/num2\n",
+ "else:\n",
+ " print \"Incorrect choice: \""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "------------------Basic Calculator------------------\n",
+ "Choose an option:\n",
+ "Add\n",
+ "Subtract\n",
+ "Multiply\n",
+ "Divide\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the value of the operands: 22 33\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "55\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sumpos.cpp, Page no-174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "total=0\n",
+ "while 1:\n",
+ " num=int(raw_input(\"Enter a number (0 to quit): \"))\n",
+ " if num==0:\n",
+ " print \"end of data entry.\"\n",
+ " break\n",
+ " if num<0:\n",
+ " print \"skipping this number.\"\n",
+ " continue\n",
+ " total+=num\n",
+ "print \"Total of all +ve numbers is \", total"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number (0 to quit): 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number (0 to quit): 20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number (0 to quit): -5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "skipping this number.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number (0 to quit): 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number (0 to quit): 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "end of data entry.\n",
+ "Total of all +ve numbers is 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-jump.cpp, Page no-175"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "total=0\n",
+ "while 1:\n",
+ " num=int(raw_input(\"Enter a number (0 to quit): \"))\n",
+ " if num==0:\n",
+ " print \"end of data entry.\"\n",
+ " print \"Total of all +ve numbers is\", total #no goto in python\n",
+ " break\n",
+ " if num<0:\n",
+ " print \"skipping this number.\"\n",
+ " continue\n",
+ " total+=num"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number (0 to quit): 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number (0 to quit): 20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number (0 to quit): -5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "skipping this number.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number (0 to quit): 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number (0 to quit): 0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "end of data entry.\n",
+ "Total of all +ve numbers is 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-age5.cpp, Page no-177"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "age=int(raw_input(\"Enter your age: \"))\n",
+ "if(age>12 and age<20):\n",
+ " pass\n",
+ "print \"you are a teen-aged person. good!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your age: 50\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "you are a teen-aged person. good!\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-agecmp.cpp, Page no-177"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "myage=25\n",
+ "print \"Hi! my age is \", myage\n",
+ "yourage=int(raw_input(\"What is your age? \"))\n",
+ "if myage==yourage:\n",
+ " print \"We are born on the same day. Are we twins!\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Hi! my age is 25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "What is your age? 25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "We are born on the same day. Are we twins!\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example Page no-178"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "l1=int(raw_input(\"Enter the lower limit: \"))\n",
+ "l2=int(raw_input(\"Enter the higher limit: \"))\n",
+ "print \"The prime numbers between\", l1, \"and\", l2, \"are: \",\n",
+ "for i in range(l1, l2+1):\n",
+ " if i<=3:\n",
+ " print i,\"\\t\",\n",
+ " else:\n",
+ " for j in range(2, i/2+1):\n",
+ " if(i%j==0):\n",
+ " break\n",
+ " if(i%j==0):\n",
+ " continue #no goto\n",
+ " print i, \"\\t\","
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the lower limit: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the higher limit: 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The prime numbers between 1 and 100 are: 1 \t2 \t3 \t5 \t7 \t11 \t13 \t17 \t19 \t23 \t29 \t31 \t37 \t41 \t43 \t47 \t53 \t59 \t61 \t67 \t71 \t73 \t79 \t83 \t89 \t97 \t"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter6-ArraysAndStrings.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter6-ArraysAndStrings.ipynb
new file mode 100755
index 00000000..ce7a4137
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter6-ArraysAndStrings.ipynb
@@ -0,0 +1,1593 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e2ad0aaf08f1bea2c2348d5e8774482c34bf3c3072d4908db5fdcd5d935d1eed"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6- Arrays and Strings"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-age1.cpp, Page no-182"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Sum=0.0\n",
+ "age1=int(raw_input(\"Enter person 1 age: \"))\n",
+ "Sum+=age1\n",
+ "age2=int(raw_input(\"Enter person 2 age: \"))\n",
+ "Sum+=age2\n",
+ "age3=int(raw_input(\"Enter person 3 age: \"))\n",
+ "Sum+=age3\n",
+ "age4=int(raw_input(\"Enter person 4 age: \"))\n",
+ "Sum+=age4\n",
+ "age5=int(raw_input(\"Enter person 5 age: \"))\n",
+ "Sum+=age5\n",
+ "print \"Average age = %g\" %(Sum/5)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter person 1 age: 23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter person 2 age: 40\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter person 3 age: 30\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter person 4 age: 27\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter person 5 age: 25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average age = 29\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-age2.cpp, Page no-182"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "age=[int]*5 #integer array of size 5\n",
+ "Sum=0.0\n",
+ "for i in range(5):\n",
+ " print \"Enter person\", i+1, \"age: \",\n",
+ " age[i]=int(raw_input())\n",
+ "for i in range(5):\n",
+ " Sum+=age[i]\n",
+ "print \"Average age = %g\" %(Sum/5)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter person 1 age: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 2 age: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "40\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 3 age: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "30\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 4 age: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "27\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 5 age: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Average age = 29\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-nodup.c, Page no-184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "flag=0\n",
+ "a=[float]*50\n",
+ "n=int(raw_input(\"Enter the size of a vector: \"))\n",
+ "num=n\n",
+ "print \"Enter the vector elements...\"\n",
+ "for i in range(n):\n",
+ " print \"a[\", i, \"] = ? \",\n",
+ " a[i]=int(raw_input())\n",
+ "for i in range(n-1):\n",
+ " for j in range(i+1, n):\n",
+ " if a[i]==a[j]:\n",
+ " n=n-1\n",
+ " for k in range(j, n):\n",
+ " a[k]=a[k+1]\n",
+ " flag=1\n",
+ " j=j-1\n",
+ "if flag:\n",
+ " print \"vector has \", num-n, \"duplicate elements=(s).\"\n",
+ " print \"Vector after removing duplicates...\"\n",
+ " for i in range(n):\n",
+ " print \"a[\", i, \"] = \", a[i]\n",
+ "else:\n",
+ " print \"vector has no duplicate elements\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the size of a vector: 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the vector elements...\n",
+ "a[ 0 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " a[ 1 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " a[ 2 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " a[ 3 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " a[ 4 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " a[ 5 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " vector has 1 duplicate elements=(s).\n",
+ "Vector after removing duplicates...\n",
+ "a[ 0 ] = 1\n",
+ "a[ 1 ] = 5\n",
+ "a[ 2 ] = 6\n",
+ "a[ 3 ] = 8\n",
+ "a[ 4 ] = 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-elder.cpp, Page no-187"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "age=[float]*25\n",
+ "n=int(raw_input(\"How many persons are there in list <max-25>? \"))\n",
+ "for i in range(n):\n",
+ " print \"Enter person\", i+1, \"age: \",\n",
+ " age[i]=int(raw_input())\n",
+ "younger=age[0]\n",
+ "elder=age[0]\n",
+ "for i in range(n):\n",
+ " if age[i]<younger:\n",
+ " younger=age[i]\n",
+ " elif age[i]>elder:\n",
+ " elder=age[i]\n",
+ "print \"Age of eldest person is\", elder\n",
+ "print \"Age of youngest person is: \", younger"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many persons are there in list <max-25>? 7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter person 1 age: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 2 age: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 3 age: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "45\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 4 age: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "18\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 5 age: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "35\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 6 age: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 7 age: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "32\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Age of eldest person is 45\n",
+ "Age of youngest person is: 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-bubble.cpp, Page no-189"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "age=[int]*25\n",
+ "n=int(raw_input(\"How many elements to sort <max-25>? \"))\n",
+ "for i in range(n):\n",
+ " print \"Enter age[\", i, \"]: \",\n",
+ " age[i]=int(raw_input())\n",
+ "for i in range(n-1):\n",
+ " flag=1\n",
+ " for j in range(n-1-i):\n",
+ " if age[j]>age[j+1]:\n",
+ " flag=0\n",
+ " temp=age[j]\n",
+ " age[j]=age[j+1]\n",
+ " age[j+1]=temp\n",
+ " if flag:\n",
+ " break\n",
+ "print \"Sorted list...\"\n",
+ "for i in range(n):\n",
+ " print age[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many elements to sort <max-25>? 7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age[ 0 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter age[ 1 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter age[ 2 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter age[ 3 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter age[ 4 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter age[ 5 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter age[ 6 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Sorted list...\n",
+ "1 2 3 4 5 6 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-comb.cpp, Page no-190"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "SHRINKINGFACTOR=1.3\n",
+ "age=[int]*25\n",
+ "n=int(raw_input(\"How many elements to sort <max-25>? \"))\n",
+ "for i in range(n):\n",
+ " print \"Enter age[\", i, \"]: \",\n",
+ " age[i]=int(raw_input())\n",
+ "size=n\n",
+ "gap=size\n",
+ "while 1:\n",
+ " gap=int(float(gap)/SHRINKINGFACTOR)\n",
+ " if gap==0:\n",
+ " gap=1\n",
+ " elif (gap==9 or gap==10):\n",
+ " gap=11\n",
+ " flag=1\n",
+ " top=size-gap\n",
+ " for i in range(top):\n",
+ " j=i+gap\n",
+ " if age[i]>age[j]:\n",
+ " flag=0\n",
+ " temp=age[j]\n",
+ " age[j]=age[i]\n",
+ " age[i]=temp\n",
+ " if(flag==1 and gap<=1):\n",
+ " break\n",
+ "print \"Sorted list...\"\n",
+ "for i in range(n):\n",
+ " print age[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many elements to sort <max-25>? 7\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter age[ 0 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter age[ 1 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter age[ 2 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter age[ 3 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter age[ 4 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter age[ 5 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter age[ 6 ]: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Sorted list...\n",
+ "1 2 3 4 5 6 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-matrix.cpp, Page no-193"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a=[]\n",
+ "b=[]\n",
+ "c=[]\n",
+ "m, n=[int(x) for x in raw_input(\"Enter row and column size of matrix A: \").split()]\n",
+ "p, q=[int(x) for x in raw_input(\"Enter row and column size of matrix B: \").split()]\n",
+ "if(m==p and n==q):\n",
+ " print \"Matrices can be added or subtracted...\"\n",
+ " print \"Enter matrix A elements...\"\n",
+ " for i in range(m):\n",
+ " a.append([])\n",
+ " for j in range(n):\n",
+ " a[i].append(int(raw_input()))\n",
+ " print \"Enter matrix B elements...\"\n",
+ " for i in range(m):\n",
+ " b.append([])\n",
+ " for j in range(n):\n",
+ " b[i].append(int(raw_input()))\n",
+ " for i in range(m):\n",
+ " c.append([])\n",
+ " for j in range(n):\n",
+ " c[i].append(a[i][j]+b[i][j])\n",
+ " print \"Sum of A and B matrices...\"\n",
+ " for i in range(m):\n",
+ " for j in range(n):\n",
+ " print c[i][j], \n",
+ " print \"\"\n",
+ " for i in range(m):\n",
+ " for j in range(n):\n",
+ " c[i][j]=a[i][j]-b[i][j]\n",
+ " print \"Difference of A and B matrices...\"\n",
+ " for i in range(m):\n",
+ " for j in range(n):\n",
+ " print c[i][j], \n",
+ " print \"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter row and column size of matrix A: 3 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter row and column size of matrix B: 3 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrices can be added or subtracted...\n",
+ "Enter matrix A 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": [
+ "3\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": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter matrix B elements...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\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": [
+ "3\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": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sum of A and B matrices...\n",
+ "4 4 4 \n",
+ "7 6 3 \n",
+ "4 3 3 \n",
+ "Difference of A and B matrices...\n",
+ "-2 0 2 \n",
+ "1 0 -1 \n",
+ "2 -1 1 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-name.cpp, Page-196"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "name=[None]*50\n",
+ "name=raw_input(\"Enter your name <49-max>: \")\n",
+ "print \"Your name is\", name"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your name <49-max>: Archana\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your name is Archana\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-succ.cpp, Page no-196"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "msg=\"C to C++\\nC++ to Java\\nJava to...\" #string with special characters\n",
+ "print \"Please note the following messgae: \"\n",
+ "print msg"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Please note the following messgae: \n",
+ "C to C++\n",
+ "C++ to Java\n",
+ "Java to...\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-strlen.cpp, Page no-197"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s1=[None]*25\n",
+ "s1=raw_input(\"Enter your name: \")\n",
+ "print \"strlen( s1 ) :\", len(s1) #length of string"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your name: Smrithi\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "strlen( s1 ): 7\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-strcpy.cpp, Page no-198"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s1=[None]*25\n",
+ "s2=[None]*25\n",
+ "s1=raw_input(\"Enter a string: \")\n",
+ "s2=s1 #copying string\n",
+ "print \"strcpy( s2, s1 ):\", s2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string: Garbage\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "strcpy( s2, s1 ): Garbage\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-strcat.cpp, Page no-198"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s1=[None]*40\n",
+ "s2=[None]*25\n",
+ "s1=raw_input(\"Enter string s1: \")\n",
+ "s2=raw_input(\"Enter string s2: \")\n",
+ "s1=s1+s2 #concatenating string\n",
+ "print \"strcat( s1, s2 ):\", s1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter string s1: C\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter string s2: ++\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "strcat( s1, s2 ): C++\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-strcmp, Page no-199"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s1=[None]*25\n",
+ "s2=[None]*25\n",
+ "s1=raw_input(\"Enter string s1: \")\n",
+ "s2=raw_input(\"Enter string s2: \")\n",
+ "print \"strcmp( s1, s2 ):\",\n",
+ "if s1==s2: #comparing strings\n",
+ " print s1, \"is equal to\", s2\n",
+ "elif s1>s2:\n",
+ " print s1, \"is greater than\", s2\n",
+ "else: \n",
+ " print s1, \"is less than\", s2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter string s1: Computer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter string s2: Computing\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "strcmp( s1, s2 ): Computer is less than Computing\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-uprlwr.cpp, Page no-199"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "s1=[None]*25\n",
+ "temp=[None]*25\n",
+ "s1=raw_input(\"Enter a string: \")\n",
+ "temp=s1\n",
+ "print \"strupr(temp):\", temp.upper() #Upper case\n",
+ "print \"strlwr(temp):\", temp.lower() #lower case"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string: Smrithi\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "strupr(temp): SMRITHI\n",
+ "strlwr(temp): smrithi\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-name.cpp, Page no-200"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "person=[[None]*10]*LEN\n",
+ "n=int(raw_input(\"How many persons ? \"))\n",
+ "for i in range(n):\n",
+ " print \"Enter person\", i+1, \"name: \",\n",
+ " person[i]=raw_input()\n",
+ "print \"------------------------------------------------------\"\n",
+ "print \"P# Person Name Length In lower case In UPPER case\"\n",
+ "print \"------------------------------------------------------\"\n",
+ "for i in range(n):\n",
+ " print '{:>2}'.format(i+1),\n",
+ " print '{:>15}'.format(person[i]),\n",
+ " print '{:>2}'.format(len(person[i])),\n",
+ " print '{:>15}'.format(person[i].lower()),\n",
+ " print '{:>15}'.format(person[i].upper())"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many persons ? 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter person 1 name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Anand\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 2 name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Vishwanath\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 3 name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Archana\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 4 name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Yadunandan\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter person 5 name: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mallikarnun\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " ------------------------------------------------------\n",
+ "P# Person Name Length In lower case In UPPER case\n",
+ "------------------------------------------------------\n",
+ " 1 Anand 5 anand ANAND\n",
+ " 2 Vishwanath 10 vishwanath VISHWANATH\n",
+ " 3 Archana 7 archana ARCHANA\n",
+ " 4 Yadunandan 10 yadunandan YADUNANDAN\n",
+ " 5 Mallikarnun 11 mallikarnun MALLIKARNUN\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-lex.cpp, Page no-202"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Str=[\"Anand\", \"Vishwanath\", \"Archana\", \"Yadunandan\", \"MalliKarjun\"]\n",
+ "print 'The given strings are:'\n",
+ "for i in range(5):\n",
+ " print Str[i]\n",
+ "k=1\n",
+ "while k<5: #sorting strings\n",
+ " for i in range(1, 5-k+1):\n",
+ " if Str[i-1]>Str[i]:\n",
+ " str_temp=Str[i-1]\n",
+ " Str[i-1]=Str[i]\n",
+ " Str[i]=str_temp\n",
+ " k=k+1\n",
+ "print 'Strings in lexicographical order are:'\n",
+ "for i in range(5):\n",
+ " print Str[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The given strings are:\n",
+ "Anand\n",
+ "Vishwanath\n",
+ "Archana\n",
+ "Yadunandan\n",
+ "MalliKarjun\n",
+ "Strings in lexicographical order are:\n",
+ "Anand\n",
+ "Archana\n",
+ "MalliKarjun\n",
+ "Vishwanath\n",
+ "Yadunandan\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example Page no-204"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Str=\"In pursuit of Mastering\tC++\"\n",
+ "count=0\n",
+ "i=0\n",
+ "print \"The given string is:\\n\",Str\n",
+ "while(i<len(Str)):\n",
+ " if Str[i]=='\\t' or Str[i]==' ':\n",
+ " count+=1\n",
+ " i+=1\n",
+ "count+=1\n",
+ "print \"The number of words given in the string is\", count"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The given string is:\n",
+ "In pursuit of Mastering\tC++\n",
+ "The number of words given in the string is 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter7-ModularProgrammingWithFunctions.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter7-ModularProgrammingWithFunctions.ipynb
new file mode 100755
index 00000000..209d4a32
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter7-ModularProgrammingWithFunctions.ipynb
@@ -0,0 +1,1641 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:01e9bb6f23cf66730668efcf362fa75830da07f132439eac09b9d85dcf6bc616"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7-Modular Programming with Functions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-tax1.cpp, Page no-208"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Name=[None]*25\n",
+ "Name=raw_input(\"Enter name of the 1st person: \")\n",
+ "Salary=float(raw_input(\"Enter Salary: \"))\n",
+ "if(Salary<=90000):\n",
+ " Tax=Salary*12.5/100\n",
+ "else:\n",
+ " Tax=Salary*18/100\n",
+ "print \"The tax amount for\", Name, \"is:\", Tax\n",
+ "Name=raw_input(\"Enter name of the 2nd person: \")\n",
+ "Salary=float(raw_input(\"Enter Salary: \"))\n",
+ "if(Salary<=90000):\n",
+ " Tax=Salary*12.5/100\n",
+ "else:\n",
+ " Tax=Salary*18/100\n",
+ "print \"The tax amount for\", Name, \"is:\", Tax"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name of the 1st person: Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Salary: 130000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The tax amount for Rajkumar is: 23400.0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name of the 2nd person: Savithri\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Salary: 90000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The tax amount for Savithri is: 11250.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-tax2.cpp, Page no-209"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def CalculateTax(): #function for calculating tax\n",
+ " Name=[None]*25\n",
+ " Name=raw_input(\"Enter name of the person: \")\n",
+ " Salary=float(raw_input(\"Enter Salary: \"))\n",
+ " if(Salary<=90000):\n",
+ " Tax=Salary*12.5/100\n",
+ " else:\n",
+ " Tax=Salary*18/100\n",
+ " print \"The tax amount for\", Name, \"is:\", Tax\n",
+ "CalculateTax()\n",
+ "CalculateTax()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name of the person: Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Salary: 130000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The tax amount for Rajkumar is: 23400.0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name of the person: Savithri\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Salary: 90000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The tax amount for Savithri is: 11250.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-max1.cpp, Page no-210"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Max(x,y):\n",
+ " if x>y:\n",
+ " return x\n",
+ " else:\n",
+ " return y\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two integers <a,b>: \").split()]\n",
+ "c=Max(a,b)\n",
+ "print \"max (a, b):\", c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers <a,b>: 20 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "max (a, b): 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example.cpp, Page no-214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Max(x,y):\n",
+ " if x>y:\n",
+ " return x\n",
+ " else:\n",
+ " return y\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two integers <a,b>: \").split()]\n",
+ "c=Max(a,b)\n",
+ "print \"max (a, b):\", c"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers <a,b>: 20 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "max (a, b): 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-chart1.cpp, Page no-214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "def PercentageChart(percentage):\n",
+ " for i in range(percentage/2):\n",
+ " sys.stdout.write('\\x3d')\n",
+ "print \"Sridevi : \",\n",
+ "PercentageChart(50)\n",
+ "print \"\\nRajkumar: \",\n",
+ "PercentageChart(84)\n",
+ "print \"\\nSavithri: \",\n",
+ "PercentageChart(79)\n",
+ "print \"\\nAnand : \",\n",
+ "PercentageChart(74)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sridevi : ========================= \n",
+ "Rajkumar: ========================================== \n",
+ "Savithri: ======================================= \n",
+ "Anand : =====================================\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-chart2.cpp, Page no-216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "def PercentageChart(percentage):\n",
+ " for i in range(percentage/2):\n",
+ " sys.stdout.write('\\x3d')\n",
+ "m1, m2, m3, m4=[int(x) for x in raw_input(\"Enter percentage score of Sri, Raj, Savi, An: \").split()]\n",
+ "print \"Sridevi : \",\n",
+ "PercentageChart(m1)\n",
+ "print \"\\nRajkumar: \",\n",
+ "PercentageChart(m2)\n",
+ "print \"\\nSavithri: \",\n",
+ "PercentageChart(m3)\n",
+ "print \"\\nAnand : \",\n",
+ "PercentageChart(m4)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter percentage score of Sri, Raj, Savi, An: 52 92 83 67\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sridevi : ========================== \n",
+ "Rajkumar: ============================================== \n",
+ "Savithri: ========================================= \n",
+ "Anand : =================================\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-chart3.cpp, Page no-217"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "def PercentageChart(percentage, style):\n",
+ " for i in range(percentage/2):\n",
+ " sys.stdout.write(style)\n",
+ "m1, m2, m3, m4=[int(x) for x in raw_input(\"Enter percentage score of Sri, Raj, Savi, An: \").split()]\n",
+ "print \"Sridevi : \",\n",
+ "PercentageChart(m1, '*')\n",
+ "print \"\\nRajkumar: \",\n",
+ "PercentageChart(m2, '\\x3D')\n",
+ "print \"\\nSavithri: \",\n",
+ "PercentageChart(m3, '-')\n",
+ "print \"\\nAnand : \",\n",
+ "PercentageChart(m4, '!')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter percentage score of Sri, Raj, Savi, An: 55 92 83 67\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sridevi : *************************** \n",
+ "Rajkumar: ============================================== \n",
+ "Savithri: ----------------------------------------- \n",
+ "Anand : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-ifact.cpp, Page no-218"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def fact(n):\n",
+ " if n==0:\n",
+ " result=1\n",
+ " else:\n",
+ " result=1\n",
+ " for i in range(2, n+1):\n",
+ " result*=i\n",
+ " return result\n",
+ "n=int(raw_input(\"Enter the number whose factorial is to be found: \"))\n",
+ "print \"The factorial of\", n, \"is\", fact(n)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number whose factorial is to be found: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The factorial of 5 is 120\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-namelen.cpp, Page no-219"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "name=[None]*20\n",
+ "name=raw_input(\"Enter your name: \")\n",
+ "Len=len(name) #string length\n",
+ "print \"Length of your name =\", Len"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your name: Rajkumar\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Length of your name = 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-maths.cpp, Page no-220"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "num=float(raw_input(\"Enter any factorial number: \"))\n",
+ "num1=math.ceil(num) #ceiling of number\n",
+ "num2=math.floor(num) #floor of number\n",
+ "print \"ceil(\",num,\") =\", num1\n",
+ "print \"floor(\",num,\") =\", num2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter any factorial number: 2.9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ceil( 2.9 ) = 3.0\n",
+ "floor( 2.9 ) = 2.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-swap1.cpp, Page no-221"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(x, y): #pass by value swap\n",
+ " print \"Value of x and y in swap before exchange:\", x, y\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " print \"Value of x and y in swap after exchange:\", x, y\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two integers <a,b>: \").split()]\n",
+ "swap(a,b)\n",
+ "print \"Value of a and b on swap a, b) in main():\", a, b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers <a,b>: 10 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of x and y in swap before exchange: 10 20\n",
+ "Value of x and y in swap after exchange: 20 10\n",
+ "Value of a and b on swap a, b) in main(): 10 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-swap2.cpp, Pgae no-222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(x, y): #pass by address swap\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " return x, y\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two integers <a ,b>: \").split()]\n",
+ "a, b = swap(a, b)\n",
+ "print \"Value of a and b on swap( a, b ):\", a, b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers <a ,b>: 10 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of a and b on swap( a, b ): 20 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-swap3.cpp, Page no-224"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(x, y): #pass by reference swap\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " return x, y\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two integers <a,b>: \").split()]\n",
+ "a, b = swap(a, b)\n",
+ "print \"Value of a and b on swap( a, b):\", a, b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers <a,b>: 10 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of a and b on swap( a, b): 20 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-ref.cpp, Page no-226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Max(x,y):\n",
+ " if x>y:\n",
+ " return x\n",
+ " else:\n",
+ " return y\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two integers <a, b>: \").split()]\n",
+ "if Max(a,b)==a:\n",
+ " a=425\n",
+ "else:\n",
+ " b=425\n",
+ "print \"The value of a and b on execution of mx(x, y)=425;...\"\n",
+ "print \"a =\", a, \"b =\", b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers <a, b>: 2 1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of a and b on execution of mx(x, y)=425;...\n",
+ "a = 425 b = 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-defarg1.cpp, Page no-228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "def PrintLine(ch='-', RepeatCount=70): #default arguments\n",
+ " for i in range(RepeatCount):\n",
+ " sys.stdout.write(ch)\n",
+ " print ''\n",
+ "PrintLine()\n",
+ "PrintLine('!')\n",
+ "PrintLine('*', 40)\n",
+ "PrintLine('R', 55)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "----------------------------------------------------------------------\n",
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
+ "****************************************\n",
+ "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-defarg2.cpp, Pgae no-229"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "def PrintLine(ch='-', RepeatCount=70, nLines=1): #default arguments\n",
+ " for i in range(nLines):\n",
+ " for i in range(RepeatCount):\n",
+ " sys.stdout.write(ch)\n",
+ " print ''\n",
+ "PrintLine()\n",
+ "PrintLine('!')\n",
+ "PrintLine('*', 40)\n",
+ "PrintLine('R', 55)\n",
+ "PrintLine('&', 25, 2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "----------------------------------------------------------------------\n",
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
+ "****************************************\n",
+ "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\n",
+ "&&&&&&&&&&&&&&&&&&&&&&&&&\n",
+ "&&&&&&&&&&&&&&&&&&&&&&&&&\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-square.cpp, Page no-230"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def sqr(num):\n",
+ " return num*num\n",
+ "n=float(raw_input(\"Enter a number: \"))\n",
+ "print \"Its square =\",sqr(n)\n",
+ "print \"sqr( 10 ) =\", sqr(10)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a number: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Its square = 25.0\n",
+ "sqr( 10 ) = 100\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-swap4.cpp, Page no-231"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#different swap functions\n",
+ "def swap_char(x, y):\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " return x, y\n",
+ "def swap_int(x, y):\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " return x, y\n",
+ "def swap_float(x, y):\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " return x, y\n",
+ "ch1, ch2=[str(x) for x in raw_input(\"Enter two characters <ch1, ch2>: \").split()]\n",
+ "ch1, ch2 = swap_char(ch1, ch2)\n",
+ "print \"On swapping <ch1, ch2>:\", ch1, ch2\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two characters <a, b>: \").split()]\n",
+ "a, b = swap_int(a, b)\n",
+ "print \"On swapping <a, b>:\", a,b\n",
+ "c, d=[float(x) for x in raw_input(\"Enter two floats <c, d>: \").split()]\n",
+ "c, d = swap_float(c, d)\n",
+ "print \"On swapping <c, d>:\", c, d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <ch1, ch2>: R K\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <ch1, ch2>: K R\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <a, b>: 5 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <a, b>: 10 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two floats <c, d>: 20.5 99.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <c, d>: 99.5 20.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-swap5.cpp, Page no-233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(x, y): #function overloading\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " return x, y\n",
+ "ch1, ch2=[str(x) for x in raw_input(\"Enter two characters <ch1, ch2>: \").split()]\n",
+ "ch1, ch2 = swap(ch1, ch2)\n",
+ "print \"On swapping <ch1, ch2>:\", ch1, ch2\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two characters <a, b>: \").split()]\n",
+ "a, b = swap(a, b)\n",
+ "print \"On swapping <a, b>:\", a,b\n",
+ "c, d=[float(x) for x in raw_input(\"Enter two floats <c, d>: \").split()]\n",
+ "c, d = swap(c, d)\n",
+ "print \"On swapping <c, d>:\", c, d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <ch1, ch2>: R K\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <ch1, ch2>: K R\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <a, b>: 5 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <a, b>: 10 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two floats <c, d>: 20.5 99.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <c, d>: 99.5 20.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-show.cpp, Page no-234"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def show(val): #function overloading\n",
+ " if(isinstance(val, int)):\n",
+ " print \"Integer:\", val\n",
+ " if(isinstance(val, float)):\n",
+ " print \"Double:\", val\n",
+ " if(isinstance(val, str)):\n",
+ " print \"String:\", val\n",
+ "show(420)\n",
+ "show(3.1415)\n",
+ "show(\"Hello World!\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Integer: 420\n",
+ "Double: 3.1415\n",
+ "String: Hello World!\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-swap6.cpp, Page no-236"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(x, y):\n",
+ " t=x\n",
+ " x=y\n",
+ " y=t\n",
+ " return x, y\n",
+ "ch1, ch2=[str(x) for x in raw_input(\"Enter two characters <ch1, ch2>: \").split()]\n",
+ "ch1, ch2 = swap(ch1, ch2)\n",
+ "print \"On swapping <ch1, ch2>:\", ch1, ch2\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two characters <a, b>: \").split()]\n",
+ "a, b = swap(a, b)\n",
+ "print \"On swapping <a, b>:\", a,b\n",
+ "c, d=[float(x) for x in raw_input(\"Enter two floats <c, d>: \").split()]\n",
+ "c, d = swap(c, d)\n",
+ "print \"On swapping <c, d>:\", c, d"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <ch1, ch2>: R K\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <ch1, ch2>: K R\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two characters <a, b>: 5 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <a, b>: 10 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two floats <c, d>: 20.5 99.5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On swapping <c, d>: 99.5 20.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sort.cpp, Page no-237"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "(false, true)=(0, 1) #enum type\n",
+ "type =['false', 'true']\n",
+ "def swap(x, y):\n",
+ " x, y=y, x\n",
+ " return x, y\n",
+ "def BubbleSort(a, size):\n",
+ " swapped='true'\n",
+ " for i in range(size-1):\n",
+ " if swapped:\n",
+ " swapped='false'\n",
+ " for j in range((size-1)-i):\n",
+ " if a[j]>a[j+1]:\n",
+ " swapped='true'\n",
+ " a[j], a[j+1]=swap(a[j], a[j+1])\n",
+ " return a\n",
+ "a=[int]*25\n",
+ "print \"Program to sort elements...\"\n",
+ "size=int(raw_input(\"Enter the size of the integer vector <max-25>: \"))\n",
+ "print \"Enter the elements of the integer vector...\"\n",
+ "for i in range(size):\n",
+ " a[i]=int(raw_input())\n",
+ "a=BubbleSort(a, size)\n",
+ "print \"Sorted Vector:\"\n",
+ "for i in range(size):\n",
+ " print a[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Program to sort elements...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the size of the integer vector <max-25>: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the elements of the integer vector...\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": [
+ "9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sorted Vector:\n",
+ "2 3 6 8 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-linear.cpp, Page no-239"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def linear(arr, num):\n",
+ " for i in range(10):\n",
+ " if arr[i]==num:\n",
+ " return i\n",
+ " return -1\n",
+ "a=[10, 20, 5, 59, 63, 22, 18, 99, 11, 65] # 1-D array\n",
+ "element=int(raw_input(\"Enter the element to be searched: \"))\n",
+ "result=linear(a, element)\n",
+ "if result==-1:\n",
+ " print element, \"is not present in the array\"\n",
+ "else:\n",
+ " print element, \"is present at\",result, \"location in the array\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the element to be searched: 88\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "88 is not present in the array\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-funcstk.cpp, Page no-240"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def Func(j, k):\n",
+ " print \"In the function the argument values are\", j, \"..\", k\n",
+ "i=99\n",
+ "Func(i+1, i)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In the function the argument values are 100 .. 99\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-variable.cpp, Page no-241"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "g=100\n",
+ "def func1():\n",
+ " g=50\n",
+ " print \"Local variable g in func1() :\", g\n",
+ "def func2():\n",
+ " global g\n",
+ " print \"In func2() g is visible since it is global.\"\n",
+ " print \"Incremeting g in func...\"\n",
+ " g+=1\n",
+ "print \"In main g is visible here since g is global.\"\n",
+ "print \"Assigning 20 to g in main...\"\n",
+ "g=20\n",
+ "print \"Calling func1...\"\n",
+ "func1()\n",
+ "print \"func1 returned. g is\", g\n",
+ "print \"Calling func2...\"\n",
+ "func2()\n",
+ "print \"func2 returned. g is\", g"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In main g is visible here since g is global.\n",
+ "Assigning 20 to g in main...\n",
+ "Calling func1...\n",
+ "Local variable g in func1() : 50\n",
+ "func1 returned. g is 20\n",
+ "Calling func2...\n",
+ "In func2() g is visible since it is global.\n",
+ "Incremeting g in func...\n",
+ "func2 returned. g is 21\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-regvar.cpp, Page no-244"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "i=int\n",
+ "name=raw_input(\"Enter a string: \")\n",
+ "print \"The reverse of the string is: \",\n",
+ "for i in range(len(name)-1, -1, -1):\n",
+ " sys.stdout.write(name[i])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a string: mahatma\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The reverse of the string is: amtaham\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-count.cpp, Page no-245"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def PrintCount(Count=[1]):\n",
+ " print 'Count =', Count[0]\n",
+ " Count[0]=Count[0]+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": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-add.cpp, Page no-247"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def add(*argc):#variable number of arguments to the function\n",
+ " result=0\n",
+ " for i in range(1, argc[0]+1):\n",
+ " result+=argc[i]\n",
+ " return result\n",
+ "sum1=add(3, 1, 2, 3)\n",
+ "print \"sum1 =\", sum1\n",
+ "sum2=add(1, 10)\n",
+ "print \"sum2 =\", sum2\n",
+ "sum3=add(0)\n",
+ "print \"sum3 =\", sum3"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "sum1 = 6\n",
+ "sum2 = 10\n",
+ "sum3 = 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sum.cpp, Page no-248"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def sum(*msg): #variable number of arguments to the function\n",
+ " total=0\n",
+ " i=1\n",
+ " while(msg[i]!=0):\n",
+ " total+=msg[i]\n",
+ " i+=1\n",
+ " print msg[0], total\n",
+ "sum(\"The total of 1+2+3+4 is\", 1, 2, 3, 4, 0)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The total of 1+2+3+4 is 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-rfact.cpp, Page no-250"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def fact(num): #recursive function\n",
+ " if num==0:\n",
+ " return 1\n",
+ " else:\n",
+ " return num*fact(num-1)\n",
+ "n=int(raw_input(\"Enter the number whose factorial is to be found: \"))\n",
+ "print \"The factorial of\", n, \"is\", fact(n)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number whose factorial is to be found: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The factorial of 5 is 120\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-hanoi.cpp, Page no-250"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def hanoi(n, left, mid, right): #recursive function\n",
+ " if n!=0:\n",
+ " hanoi(n-1, left, right, mid)\n",
+ " print 'Move disk', n, 'from', left, 'to', right\n",
+ " hanoi(n-1, mid, left, right)\n",
+ "source='L'\n",
+ "intermediate='C'\n",
+ "destination='R'\n",
+ "nvalue=int(raw_input('Enter number of disks: '))\n",
+ "hanoi(nvalue, source, intermediate, destination)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter number of disks: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "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 Page no-254"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def power(x1, y1=None):\n",
+ " if (isinstance(y1, int)):\n",
+ " result=1.0\n",
+ " for i in range(1, y1+1):\n",
+ " result=result*x1\n",
+ " return result\n",
+ " else:\n",
+ " return x1*x1\n",
+ "x=float(raw_input(\"Enter the value of x: \"))\n",
+ "y=int(raw_input(\"Enter the value of y: \"))\n",
+ "print \"power(x, y) =\", power(x, y)\n",
+ "print \"power(x) =\", power(x)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the value of x: 9.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the value of y: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "power(x, y) = 8145.0625\n",
+ "power(x) = 90.25\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter8-StructuresAndUnions.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter8-StructuresAndUnions.ipynb
new file mode 100755
index 00000000..88f0f80d
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter8-StructuresAndUnions.ipynb
@@ -0,0 +1,1202 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:f7e7015d0709344fbfb1dd6045265378d35165eecd34afefa9304b97a8f3cb07"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8-Structures and Unions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-student1.cpp, Page no-260"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class Student(Structure): #structure\n",
+ " roll_no =int\n",
+ " name =str\n",
+ " branch =str\n",
+ " marks=int\n",
+ "s1=Student() #object of struct student\n",
+ "print \"Enter data for student...\"\n",
+ "s1.roll_no=int(raw_input(\"Roll Number ? \"))\n",
+ "s1.name=raw_input(\"Name ? \")\n",
+ "s1.branch=raw_input(\"Branch ? \")\n",
+ "s1.marks=int(raw_input(\"Total Marks <max-325> ? \"))\n",
+ "print \"Student Report\"\n",
+ "print \"--------------\"\n",
+ "print \"Roll Number:\", s1.roll_no\n",
+ "print \"Name:\", s1.name\n",
+ "print \"Branch:\", s1.branch\n",
+ "print \"Percentage:%f\" %(s1.marks*(100.0/325))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for student...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll Number ? 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name ? Mangala\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Branch ? Computer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total Marks <max-325> ? 290\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Student Report\n",
+ "--------------\n",
+ "Roll Number: 5\n",
+ "Name: Mangala\n",
+ "Branch: Computer\n",
+ "Percentage:89.230769\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-days.cpp, Page no-262"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class date(Structure):\n",
+ " _fields_=[(\"day\", c_int),(\"month\", c_int),(\"year\",c_int)]\n",
+ "d1=date(14, 4, 1971)\n",
+ "d2=date(3, 7, 1996)\n",
+ "print \"Birth date:\",\n",
+ "print \"%s-%s-%s\" %(d1.day, d1.month, d1.year)\n",
+ "print \"Today date:\",\n",
+ "print \"%s-%s-%s\" %(d2.day, d2.month, d2.year)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Birth date: 14-4-1971\n",
+ "Today date: 3-7-1996\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-student2.cpp, Page no-264"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class date(Structure):\n",
+ " _fields_=[(\"day\", c_int),(\"month\", c_int),(\"year\",c_int)]\n",
+ "class Student(Structure):\n",
+ " _fields_=[(\"roll_no\", c_int), (\"name\", c_char*25), (\"birthday\", date), (\"branch\", c_char*15),(\"marks\", c_int)]#nested structure\n",
+ "s1=Student()\n",
+ "print \"Enter data for student...\"\n",
+ "s1.roll_no=int(raw_input(\"Roll Number ? \"))\n",
+ "s1.name=raw_input(\"Name ? \")\n",
+ "birthday=date(0, 0, 0)\n",
+ "print \"Enter date of birth <day month year>: \",\n",
+ "d, m, y=[int(x) for x in raw_input().split()]\n",
+ "birthday.day=d\n",
+ "birthday.month=m\n",
+ "birthday.year=y\n",
+ "s1.birthday=birthday\n",
+ "s1.branch=raw_input(\"Branch ? \")\n",
+ "s1.marks=int(raw_input(\"Total Marks <max-325> ? \"))\n",
+ "print \"Student Report\"\n",
+ "print \"--------------\"\n",
+ "print \"Roll Number:\", s1.roll_no\n",
+ "print \"Name:\", s1.name\n",
+ "print \"%s-%s-%s\" %(s1.birthday.day, s1.birthday.month, s1.birthday.year)\n",
+ "print \"Branch:\", s1.branch\n",
+ "print \"Percentage:%f\" %(s1.marks*(100.0/325))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for student...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll Number ? 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name ? Savithri\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter date of birth <day month year>: "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2 2 1972\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Branch ? Electrical\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total Marks <max-325> ? 295\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Student Report\n",
+ "--------------\n",
+ "Roll Number: 9\n",
+ "Name: Savithri\n",
+ "2-2-1972\n",
+ "Branch: Electrical\n",
+ "Percentage:90.769231\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-student3.cpp, Page no-267"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class Student(Structure):\n",
+ " _fields_=[(\"roll_no\", c_int), (\"name\", c_char*25), (\"branch\", c_char*15),(\"marks\", c_int)]\n",
+ "s=[]\n",
+ "n=int(raw_input(\"How many students to be processed <max-10>: \"))\n",
+ "for i in range(n):\n",
+ " print \"Enter data for student\", i+1, \"...\"\n",
+ " r=int(raw_input(\"Roll Number ? \"))\n",
+ " name=raw_input(\"Name ? \")\n",
+ " b=raw_input(\"Branch ? \")\n",
+ " m=int(raw_input(\"Total marks <max-325> ? \"))\n",
+ " s.append(Student(r, name, b, m)) #array of structure objects\n",
+ "print \"Students Report\"\n",
+ "print \"--------------\"\n",
+ "for i in range(n):\n",
+ " print \"Roll Number:\", s[i].roll_no\n",
+ " print \"Name:\", s[i].name\n",
+ " print \"Branch:\", s[i].branch\n",
+ " print \"Percentage: %f\" %(s[i].marks*(100.0/325))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many students to be processed <max-10>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for student 1 ...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll Number ? 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name ? Mangala\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Branch ? Computer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total marks <max-325> ? 290\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for student 2 ...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll Number ? 9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name ? Shivakumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Branch ? Electronics\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total marks <max-325> ? 250\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Students Report\n",
+ "--------------\n",
+ "Roll Number: 5\n",
+ "Name: Mangala\n",
+ "Branch: Computer\n",
+ "Percentage: 89.230769\n",
+ "Roll Number: 9\n",
+ "Name: Shivakumar\n",
+ "Branch: Electronics\n",
+ "Percentage: 76.923077\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-student4.cpp, Page no-269"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class Student(Structure):\n",
+ " _fields_=[(\"roll_no\", c_int), (\"name\", c_char*25), (\"branch\", c_char*15),(\"marks\", c_int)]\n",
+ "STUDENTS_COUNT=5\n",
+ "s=[]\n",
+ "s.append(Student(2, 'Tejaswi', 'CS', 285))#initialization of array of structures\n",
+ "s.append(Student(3, 'Laxmi', 'IT', 215))\n",
+ "s.append(Student(5, 'Bhavani', 'Electronics', 250))\n",
+ "s.append(Student(7, 'Anil', 'Civil', 215))\n",
+ "s.append(Student(9, 'Savithri', 'Electrical', 290))\n",
+ "print \"Students Report\"\n",
+ "print \"--------------\"\n",
+ "for i in range(STUDENTS_COUNT):\n",
+ " print \"Roll Number:\", s[i].roll_no\n",
+ " print \"Name:\", s[i].name\n",
+ " print \"Branch:\", s[i].branch\n",
+ " print \"Percentage: %0.4f\" %(s[i].marks*(100.0/325))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Students Report\n",
+ "--------------\n",
+ "Roll Number: 2\n",
+ "Name: Tejaswi\n",
+ "Branch: CS\n",
+ "Percentage: 87.6923\n",
+ "Roll Number: 3\n",
+ "Name: Laxmi\n",
+ "Branch: IT\n",
+ "Percentage: 66.1538\n",
+ "Roll Number: 5\n",
+ "Name: Bhavani\n",
+ "Branch: Electronics\n",
+ "Percentage: 76.9231\n",
+ "Roll Number: 7\n",
+ "Name: Anil\n",
+ "Branch: Civil\n",
+ "Percentage: 66.1538\n",
+ "Roll Number: 9\n",
+ "Name: Savithri\n",
+ "Branch: Electrical\n",
+ "Percentage: 89.2308\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-student5.cpp, Page no-271"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class Student(Structure):\n",
+ " _fields_=[(\"roll_no\", c_int), (\"name\", c_char*25), (\"branch\", c_char*15),(\"marks\", c_int)]\n",
+ "def read():\n",
+ " dull=Student()\n",
+ " dull.roll_no=int(raw_input(\"Roll Number ? \"))\n",
+ " dull.name=raw_input(\"Name ? \")\n",
+ " dull.branch=raw_input(\"Branch ? \")\n",
+ " dull.marks=int(raw_input(\"Total marks <max-325> ? \"))\n",
+ " return dull #returning structure object\n",
+ "def show(genius): #passing object of structure\n",
+ " print \"Roll Number:\", genius.roll_no\n",
+ " print \"Name:\", genius.name\n",
+ " print \"Branch:\", genius.branch\n",
+ " print \"Percentage: %0.4f\" %(genius.marks*(100.0/325))\n",
+ "s=[]\n",
+ "n=int(raw_input(\"How many students to be processed <max-10>: \"))\n",
+ "for i in range(n):\n",
+ " print \"Enter data for student\", i+1, \"...\"\n",
+ " s.append(read())\n",
+ "print \"Students Report\"\n",
+ "print \"--------------\"\n",
+ "for i in range(n):\n",
+ " show(s[i])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many students to be processed <max-10>: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for student 1 ...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll Number ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name ? Smrithi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Branch ? Genetics\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total marks <max-325> ? 295\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for student 2 ...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll Number ? 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name ? Bindhu\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Branch ? MCA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total marks <max-325> ? 300\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Students Report\n",
+ "--------------\n",
+ "Roll Number: 3\n",
+ "Name: Smrithi\n",
+ "Branch: Genetics\n",
+ "Percentage: 90.7692\n",
+ "Roll Number: 10\n",
+ "Name: Bindhu\n",
+ "Branch: MCA\n",
+ "Percentage: 92.3077\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-student6.cpp, Page no-273"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class Student(Structure):\n",
+ " _fields_=[(\"roll_no\", c_int), (\"name\", c_char*25), (\"branch\", c_char*15),(\"marks\", c_int)]\n",
+ "def HighestMarks(s, count): #passing array of structures\n",
+ " big=s[0].marks\n",
+ " for i in range(1, count):\n",
+ " if s[i].marks>big:\n",
+ " big=s[i].marks\n",
+ " index=i\n",
+ " return index\n",
+ "def read():\n",
+ " dull=Student()\n",
+ " dull.roll_no=int(raw_input(\"Roll Number ? \"))\n",
+ " dull.name=raw_input(\"Name ? \")\n",
+ " dull.branch=raw_input(\"Branch ? \")\n",
+ " dull.marks=int(raw_input(\"Total marks <max-325> ? \"))\n",
+ " return dull\n",
+ "def show(genius):\n",
+ " print \"Roll Number:\", genius.roll_no\n",
+ " print \"Name:\", genius.name\n",
+ " print \"Branch:\", genius.branch\n",
+ " print \"Percentage: %0.4f\" %(genius.marks*(100.0/325))\n",
+ "s=[]\n",
+ "n=int(raw_input(\"How many students to be processed <max-10>: \"))\n",
+ "for i in range(n):\n",
+ " print \"Enter data for student\", i+1, \"...\"\n",
+ " s.append(read())\n",
+ "print \"Students Report\"\n",
+ "print \"--------------\"\n",
+ "Id=HighestMarks(s, n)\n",
+ "print \"Details of student scoring higest marks...\"\n",
+ "show(s[Id])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many students to be processed <max-10>: 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for student 1 ...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll Number ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name ? Smrithi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Branch ? Genetics\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total marks <max-325> ? 295\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for student 2 ...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll Number ? 15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name ? Rajkumar\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Branch ? Computer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total marks <max-325> ? 315\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for student 3 ...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Roll Number ? 7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name ? Laxmi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Branch ? Electronics\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total marks <max-325> ? 255\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Students Report\n",
+ "--------------\n",
+ "Details of student scoring higest marks...\n",
+ "Roll Number: 15\n",
+ "Name: Rajkumar\n",
+ "Branch: Computer\n",
+ "Percentage: 96.9231\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-complex.cpp, Page no-278"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "import sys\n",
+ "import math\n",
+ "class Complex(Structure):\n",
+ " x=int\n",
+ " y=int\n",
+ " def read(self):\n",
+ " self.x=int(raw_input(\"Real part? \"))\n",
+ " self.y=int(raw_input(\"Imaginary part? \"))\n",
+ " def show(self, msg):\n",
+ " print msg, self.x,\n",
+ " if self.y<0:\n",
+ " sys.stdout.write('-i')\n",
+ " else:\n",
+ " sys.stdout.write('+i')\n",
+ " print math.fabs(self.y)\n",
+ " def add(self, c2):\n",
+ " self.x+=c2.x\n",
+ " self.y+=c2.y\n",
+ "c1=Complex()\n",
+ "c2=Complex()\n",
+ "c3=Complex()\n",
+ "print \"Enter complex number c1...\"\n",
+ "c1.read()\n",
+ "print \"Enter complex number c2...\"\n",
+ "c2.read()\n",
+ "c1.show('c1 =')\n",
+ "c2.show('c2 =')\n",
+ "c3=c1\n",
+ "c3.add(c2)\n",
+ "c3.show('c3 = c1 + c2 =')"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter complex number c1...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part? 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imaginary part? 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter complex number c2...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Real part? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Imaginary part? 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "c1 = 1+i 2.0\n",
+ "c2 = 3+i 4.0\n",
+ "c3 = c1 + c2 = 4+i 6.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-emp.cpp, Page no-279"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class employee(Structure): #structure member functions\n",
+ " name=str\n",
+ " ID=long\n",
+ " dept=str\n",
+ " salary=float\n",
+ " def read(self):\n",
+ " self.name=raw_input(\"Employee Name: \")\n",
+ " self.ID=long(raw_input(\"Employee ID: \"))\n",
+ " self.dept=raw_input(\"Department: \")\n",
+ " self.salary=float(raw_input(\"Salary: \"))\n",
+ " def show(self):\n",
+ " print \"Employee Name:\", self.name\n",
+ " print \"Employee ID:\", self.ID\n",
+ " print \"Department:\", self.dept\n",
+ " print \"Salary:\", self.salary\n",
+ "emp=employee()\n",
+ "print \"Enter employee data:\"\n",
+ "emp.read()\n",
+ "print \"\\n****Employee Record****\"\n",
+ "emp.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter employee data:\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Name: Vishwanathan\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee ID: 953\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Department: Finance\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Salary: 18500\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "****Employee Record****\n",
+ "Employee Name: Vishwanathan\n",
+ "Employee ID: 953\n",
+ "Department: Finance\n",
+ "Salary: 18500.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-union.cpp, Page no-283"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "#Creates a union\n",
+ "class Strings(Union):\n",
+ " _fields_ = [(\"filename\",c_char*200),\n",
+ " (\"output\", c_char*400)]\n",
+ "s=Strings()\n",
+ "s.filename=\"/cdacb/usrl/raj/oops/mcrokernel/pserver.cpp\"\n",
+ "print \"filename:\", s.filename\n",
+ "s.output=\"OOPs is a most complex entity ever created by humans\"\n",
+ "print \"output:\", s.output\n",
+ "print \"Size of union Strings =\", sizeof(Strings)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "filename: /cdacb/usrl/raj/oops/mcrokernel/pserver.cpp\n",
+ "output: OOPs is a most complex entity ever created by humans\n",
+ "Size of union Strings = 400\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sudiff.cpp, Page no-284"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from collections import namedtuple\n",
+ "from ctypes import *\n",
+ "class struct(Structure):\n",
+ " _fields_ = [(\"name\",c_char*25), (\"idno\", c_int), (\"salary\", c_float)]\n",
+ "emp=struct()\n",
+ "class union(Union):\n",
+ " _fields_ = [(\"name\",c_char*25), (\"idno\", c_int), (\"salary\", c_float)]\n",
+ "desc=union()\n",
+ "print \"The size of the structure is\", sizeof(emp)\n",
+ "print \"The size of the union is\", sizeof(desc)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The size of the structure is 36\n",
+ "The size of the union is 28\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-uaccess.cpp, Page no-285"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class emp(Union):\n",
+ " _fields_=[(\"name\",c_char*25), (\"idno\", c_int), (\"salary\", c_float)]\n",
+ "def show(e):\n",
+ " print \"Employee Details...\"\n",
+ " print \"The name is %s\" %e.name\n",
+ " print \"The idno is %d\" %e.idno\n",
+ " print \"The salary is %g\" %e.salary\n",
+ "e=emp()\n",
+ "e.name=\"Rajkumar\"\n",
+ "show(e)\n",
+ "e.idno=10\n",
+ "show(e)\n",
+ "e.salary=9000\n",
+ "show(e)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Employee Details...\n",
+ "The name is Rajkumar\n",
+ "The idno is 1802133842\n",
+ "The salary is 2.83348e+26\n",
+ "Employee Details...\n",
+ "The name is \n",
+ "\n",
+ "The idno is 10\n",
+ "The salary is 1.4013e-44\n",
+ "Employee Details...\n",
+ "The name is \n",
+ "The idno is 1175232512\n",
+ "The salary is 9000\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-uscope.cpp, Page no-286"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "#Creates a union\n",
+ "class union(Union):\n",
+ " _fields_ = [(\"i\", c_int), \n",
+ " (\"c\", c_char), \n",
+ " (\"f\", c_float)]\n",
+ "u=union()\n",
+ "u.i=10\n",
+ "u.c='9'\n",
+ "u.f=4.5\n",
+ "print \"The value of i is\", u.i\n",
+ "print \"The value of c is\", u.c\n",
+ "print \"The value of f is\", u.f"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of i is 1083179008\n",
+ "The value of c is \u0000\n",
+ "The value of f is 4.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-share.cpp, Page no-289"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from collections import namedtuple\n",
+ "from ctypes import *\n",
+ "import sys\n",
+ "class with_bits(Structure):\n",
+ " _fields_ = [(\"first\", c_uint), (\"second\", c_uint)]\n",
+ "class union(Union):\n",
+ " _fields_=[(\"b\", with_bits), (\"i\", c_int)]\n",
+ "i=0\n",
+ "u=union()\n",
+ "print \"On i=0: b.first =\",u.b.first,\"b.second =\", u.b.second\n",
+ "u.b.first=9\n",
+ "print \"b.first =9:\", \n",
+ "print \"b.first =\", u.b.first, \"b.second =\", u.b.second"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "On i=0: b.first = 0 b.second = 0\n",
+ "b.first =9: b.first = 9 b.second = 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter9-PointersAndRuntimeBinding.ipynb b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter9-PointersAndRuntimeBinding.ipynb
new file mode 100755
index 00000000..e3624032
--- /dev/null
+++ b/_Mastering_C++_by_K_R_Venugopal_and_Rajkumar_Buyya/Chapter9-PointersAndRuntimeBinding.ipynb
@@ -0,0 +1,1663 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:de9763f2876edfb1bdd8ccce73ff66e5216f2e4ec3f157c8b54ef1f8d480abb5"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9- Pointers and Runtime Binding"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-getaddr.cpp, Page no-293"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "a=c_int(100)\n",
+ "b=c_int(200)\n",
+ "c=c_int(300)\n",
+ "print 'Address', hex(id(pointer(a))), 'contains value', a.value #address of a pointer\n",
+ "print 'Address', hex(id(pointer(b))), 'contains value', b.value\n",
+ "print 'Address', hex(id(pointer(c))), 'contains value', c.value"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address 0x3643348L contains value 100\n",
+ "Address 0x36434c8L contains value 200\n",
+ "Address 0x3643348L contains value 300\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-initptr.cpp, Page no-296"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "var1=c_int(10)\n",
+ "var2=c_int(20)\n",
+ "iptr=pointer(var1)\n",
+ "print 'Address and contents of var1 is', hex(id(iptr)), 'and', iptr[0]\n",
+ "iptr=pointer(var2)\n",
+ "print 'Address and contents of var2 is', hex(id(iptr)), 'and', iptr[0]\n",
+ "iptr[0]=125\n",
+ "var1=iptr[0]*1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address and contents of var1 is 0x36434c8L and 10\n",
+ "Address and contents of var2 is 0x3643648L and 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-swap.cpp, Page no-298"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "def swap(pa, pb):\n",
+ " temp=pa[0]\n",
+ " pa[0]=pb[0]\n",
+ " pb[0]=temp\n",
+ "a=float(raw_input(\"Enter real number <a>: \"))\n",
+ "b=float(raw_input(\"Enter real number <b>: \"))\n",
+ "a=c_float(a)\n",
+ "b=c_float(b)\n",
+ "pa=pointer(a)\n",
+ "pb=pointer(b)\n",
+ "swap(pa, pb)\n",
+ "print \"After swapping......\"\n",
+ "print \"a contains %0.1f\" %(a.value)\n",
+ "print \"b contains %0.1f\" %(b.value)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter real number <a>: 10.5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter real number <b>: 20.9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "After swapping......\n",
+ "a contains 20.9\n",
+ "b contains 10.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-voidptr.cpp, Page no-300"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "i1=c_int(100)\n",
+ "f1=c_float(200.5)\n",
+ "vptr=pointer(i1)\n",
+ "print \"i1 contains\", vptr[0] #value stored in address pointed by vptr\n",
+ "vptr=pointer(f1)\n",
+ "print \"i1 contains\", vptr[0]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i1 contains 100\n",
+ "i1 contains 200.5\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-ptrarr1.cpp, Page no-303"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "a=[int]\n",
+ "n=int(raw_input(\"Size of array? \"))\n",
+ "print \"Array elements ?\"\n",
+ "for i in range(n):\n",
+ " a.append(int(raw_input()))\n",
+ "ptr=a\n",
+ "small=ptr[1]\n",
+ "for i in range(2, n+1):\n",
+ " if small>ptr[i]:\n",
+ " small=ptr[i]\n",
+ " i+=1 #pointer arithmetic\n",
+ "print \"Smallest element is\", small"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Size of array? 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Array elements ?\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "9\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Smallest element is 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-newhand.cpp, Page no-305"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "size=int(raw_input(\"How many bytes to be allocated: \"))\n",
+ "try:\n",
+ " data=[int]*size\n",
+ " print \"Memory allocation success, address =\", hex(id(data))\n",
+ "except:\n",
+ " print \"Could not allocate. Bye...\"\n",
+ "del data"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many bytes to be allocated: 300\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Memory allocation success, address = 0x3716188L\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-ptr2ptr.cpp, Page no-306"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "data=c_int()\n",
+ "iptr=pointer(data)\n",
+ "ptriptr=pointer(iptr) #pointer to a pointer\n",
+ "iptr[0]=100\n",
+ "print \"The variable 'data' contains\", data.value\n",
+ "ptriptr[0][0]=200\n",
+ "print \"The variable 'data' contains\", data.value\n",
+ "data.value=300\n",
+ "print \"ptriptr is pointing to\", ptriptr[0][0]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The variable 'data' contains 100\n",
+ "The variable 'data' contains 200\n",
+ "ptriptr is pointing to 300\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-big.cpp, Page no-308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "def FindBig(pa, pb, pbig):\n",
+ " if pa[0]>pb[0]:\n",
+ " pbig[0]=pa[0]\n",
+ " else:\n",
+ " pbig[0]=pb[0]\n",
+ " return pbig\n",
+ "a=c_int()\n",
+ "b=c_int()\n",
+ "big=pointer(c_int())\n",
+ "a, b=[int(x) for x in raw_input(\"Enter two integers: \").split()]\n",
+ "pa=[a]#pointer to a\n",
+ "pb=[b]#pointer to b\n",
+ "big=FindBig(pa, pb, big)\n",
+ "print \"The value as obtained from the pointer:\", big[0]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers: 10 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value as obtained from the pointer: 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-sortptr.cpp, Page no-309"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "def SortByPtrExchange(person, n):\n",
+ " for i in range(n-1):\n",
+ " flag=1\n",
+ " for j in range(n-1-i):\n",
+ " if person[j]>person[j+1]:\n",
+ " flag=0\n",
+ " temp=person[j]\n",
+ " person[j]=person[j+1]\n",
+ " person[j+1]=temp\n",
+ " if flag:\n",
+ " break\n",
+ "n=c_int(0)\n",
+ "choice=c_char_p()\n",
+ "person=[[c_char_p]*100]*40\n",
+ "while(1):\n",
+ " person[n.value]=raw_input(\"Enter name: \")\n",
+ " n.value+=1\n",
+ " choice=raw_input(\"Enter another(y/n)? \")\n",
+ " if choice!='y':\n",
+ " break\n",
+ "print \"Unsorted list: \"\n",
+ "for i in range(n.value):\n",
+ " print person[i]\n",
+ "SortByPtrExchange(person, n.value)\n",
+ "print \"Sorted list: \"\n",
+ "for i in range(n.value):\n",
+ " print person[i]\n",
+ "for i in range(n.value):\n",
+ " del person[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Tejaswi\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another(y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Prasad\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another(y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Prakash\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another(y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Sudeep\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another(y/n)? y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter name: Anand\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter another(y/n)? 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": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-show.cpp, Page no-311"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def show(a, m):\n",
+ " c=a\n",
+ " for i in range(m):\n",
+ " for j in range(3):\n",
+ " print c[i][j],\n",
+ " print \"\"\n",
+ "c=[(1, 2, 3), (4, 5, 6)] #initialization of a 2D array\n",
+ "show(c, 2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 2 3 \n",
+ "4 5 6 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-matrix.cpp, Page no-313"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def MatAlloc(row, col):\n",
+ " p=[[int]*col]*row #dynamic array\n",
+ " return p\n",
+ "def MatRelease(p, row):\n",
+ " for i in range(row):\n",
+ " del p[i]\n",
+ " del p\n",
+ "def MatRead(a, row, col):\n",
+ " for i in range(row):\n",
+ " for j in range(col):\n",
+ " print \"Matrix[\", i, \",\", j, \"] = ? \",\n",
+ " a[i][j]=int(raw_input())\n",
+ "def MatMul(a, m, n, b, p, q, c):\n",
+ " if n!=p:\n",
+ " print \"Error: Invalid matrix order for multiplication\"\n",
+ " return\n",
+ " for i in range(m):\n",
+ " for j in range(q):\n",
+ " c[i][j]=0\n",
+ " for k in range(n):\n",
+ " c[i][j]+=a[i][k]*b[k][j]\n",
+ "def MatShow(a, row, col):\n",
+ " for i in range(row):\n",
+ " print \"\"\n",
+ " for j in range(col):\n",
+ " print a[i][j],\n",
+ "print \"Enter Matrix A details...\"\n",
+ "m=int(raw_input(\"How many rows ? \"))\n",
+ "n=int(raw_input(\"How many columns ? \"))\n",
+ "a=MatAlloc(m, n)\n",
+ "MatRead(a, m, n)\n",
+ "print \"Enter Matrix B details...\"\n",
+ "p=int(raw_input(\"How many rows ? \"))\n",
+ "q=int(raw_input(\"How many columns ? \"))\n",
+ "b=MatAlloc(p, q)\n",
+ "MatRead(b, p, q)\n",
+ "c=MatAlloc(m, q)\n",
+ "MatMul(a, m, n, b, p, q, c)\n",
+ "print \"Matrix C = A * B ...\",\n",
+ "MatShow(c, m, q)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Matrix A details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many rows ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many columns ? 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrix[ 0 , 0 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 0 , 1 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 0 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 1 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 0 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 2 , 1 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Enter Matrix B details...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many rows ? 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many columns ? 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Matrix[ 0 , 0 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 0 , 1 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 0 , 2 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 0 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 1 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix[ 1 , 2 ] = ? "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Matrix C = A * B ... \n",
+ "2 2 2 \n",
+ "2 2 2 \n",
+ "2 2 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-3ptr.cpp, Page no-315"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "arr=[((2, 1), (3, 6), (5, 3)), ((0, 9), (2, 3), (5, 8))]\n",
+ "print hex(id(arr))\n",
+ "print hex(id(arr[0]))\n",
+ "print hex(id(arr[0][0]))\n",
+ "print arr[0][0][0]\n",
+ "print hex(id(arr))\n",
+ "print hex(id(arr[0]))\n",
+ "print hex(id(arr[0][1]))\n",
+ "print arr[0][0][0]+1\n",
+ "for i in range(2):\n",
+ " for j in range(3):\n",
+ " for k in range(2):\n",
+ " print \"arr[\",i,\"][\", j, \"][\", k, \"] = \", arr[i][j][k]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0x3729e88L\n",
+ "0x3652ab0L\n",
+ "0x364e388L\n",
+ "2\n",
+ "0x3729e88L\n",
+ "0x3652ab0L\n",
+ "0x364e6c8L\n",
+ "3\n",
+ "arr[ 0 ][ 0 ][ 0 ] = 2\n",
+ "arr[ 0 ][ 0 ][ 1 ] = 1\n",
+ "arr[ 0 ][ 1 ][ 0 ] = 3\n",
+ "arr[ 0 ][ 1 ][ 1 ] = 6\n",
+ "arr[ 0 ][ 2 ][ 0 ] = 5\n",
+ "arr[ 0 ][ 2 ][ 1 ] = 3\n",
+ "arr[ 1 ][ 0 ][ 0 ] = 0\n",
+ "arr[ 1 ][ 0 ][ 1 ] = 9\n",
+ "arr[ 1 ][ 1 ][ 0 ] = 2\n",
+ "arr[ 1 ][ 1 ][ 1 ] = 3\n",
+ "arr[ 1 ][ 2 ][ 0 ] = 5\n",
+ "arr[ 1 ][ 2 ][ 1 ] = 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-ptrinc.cpp, Page no-317"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ia=[2, 5, 9]\n",
+ "ptr=ia\n",
+ "for i in range(3):\n",
+ " print ptr[i], \n",
+ " i+=1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2 5 9\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-strfunc.cpp, Page no-318"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "temp=raw_input(\"Enter string1: \")\n",
+ "s1=temp\n",
+ "temp=raw_input(\"Enter string2: \")\n",
+ "s2=temp\n",
+ "print \"Length of string1:\", len(s1) #string length\n",
+ "s3=s1+s2 #string concatenation\n",
+ "print \"Strings' on concatenation:\", s3\n",
+ "print \"String comparison using...\"\n",
+ "print \"Library function:\", s1>s2 # - operator is not supppoertd with string operands in python\n",
+ "print \"User's function:\", s1>s2# - operator is not supppoertd with string operands in python"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter string1: Object\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter string2: Oriented\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Length of string1: 6\n",
+ "Strings' on concatenation: ObjectOriented\n",
+ "String comparison using...\n",
+ "Library function: False\n",
+ "User's function: False\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-rfact.cpp, Page no-322"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "def fact(num):\n",
+ " if num==0:\n",
+ " return 1\n",
+ " else:\n",
+ " return num*fact(num-1)\n",
+ "ptrfact={}\n",
+ "ptrfact[0]=fact #function pointer\n",
+ "n=int(raw_input(\"Enter the number whose factorial is to be found: \"))\n",
+ "f1=ptrfact[0](n)\n",
+ "print \"The factorial of\", n, \"is\", f1\n",
+ "print \"The factorial of\", n+1, \"is\", ptrfact[0](n+1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the number whose factorial is to be found: 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The factorial of 5 is 120\n",
+ "The factorial of 6 is 720\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-rmain.cpp, Page no-323"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#this program will print hello infinite number of times\n",
+ "def main():\n",
+ " p={}\n",
+ " print \"Hello...\",\n",
+ " p[0]=main #function pointer to main()\n",
+ " p[0]()\n",
+ "main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-passfn.cpp, Page no-324"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def small(a, b):\n",
+ " return a if a<b else b\n",
+ "def large(a, b):\n",
+ " return a if a>b else b\n",
+ "def select(fn, x, y):\n",
+ " value=fn(x, y)\n",
+ " return value\n",
+ "ptrf={}\n",
+ "m, n=[int(x) for x in raw_input(\"Enter two integers: \").split()]\n",
+ "high=select(large, m, n) #function as parameter\n",
+ "ptrf[0]=small #function pointer\n",
+ "low=select(ptrf[0], m, n) #pointer to function as parameter\n",
+ "print \"Large =\", high\n",
+ "print \"Small =\", low"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter two integers: 10 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Large = 20\n",
+ "Small = 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-bdate.cpp, Page no-326"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class date(Structure):\n",
+ " _fields_=[('data', c_int), ('month', c_int), ('year', c_int)]\n",
+ " def show(self):\n",
+ " print '%s-%s-%s' %(self.day, self.month, self.year)\n",
+ "def read(dp):\n",
+ " dp.day=int(raw_input(\"Enter day: \"))\n",
+ " dp.month=int(raw_input(\"Enter month: \"))\n",
+ " dp.year=int(raw_input(\"Enter year: \"))\n",
+ "d1=date()\n",
+ "dp1=POINTER(date)\n",
+ "dp2=POINTER(date)\n",
+ "print \"Enter birthday of boy...\"\n",
+ "read(d1)\n",
+ "dp2=date()\n",
+ "print \"Enter birthday of girl...\"\n",
+ "read(dp2)\n",
+ "print \"Birth date of boy:\",\n",
+ "dp1=d1\n",
+ "dp1.show()\n",
+ "print \"Birth date of girl:\",\n",
+ "dp2.show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter birthday of boy...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter day: 14\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter year: 71\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter birthday of girl...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter day: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter month: 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter year: 72\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Birth date of boy: 14-4-71\n",
+ "Birth date of girl: 1-4-72\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Eample-list.cpp, Page no-329"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "class LIST(Structure):\n",
+ " data=int\n",
+ " Next=None\n",
+ "def InsertNode(data, first):\n",
+ " newnode=LIST()\n",
+ " newnode.data=data\n",
+ " newnode.Next=first\n",
+ " return newnode\n",
+ "def DeleteNode(data, first):\n",
+ " current=LIST()\n",
+ " pred=LIST()\n",
+ " if first==None:\n",
+ " print \"Empty list\"\n",
+ " return first\n",
+ " pred=current=first\n",
+ " while(1):\n",
+ " if current.data==data:\n",
+ " if current==first:\n",
+ " first=current.Next\n",
+ " current=current.Next\n",
+ " else:\n",
+ " pred.Next=current.Next\n",
+ " current=current.Next\n",
+ " del current\n",
+ " return first\n",
+ " current=current.Next\n",
+ " return first\n",
+ "def DisplayList(first):\n",
+ " List=LIST()\n",
+ " List=first\n",
+ " while(1): \n",
+ " print \"->\", List.data,\n",
+ " if List.Next==None:\n",
+ " break\n",
+ " List=List.Next\n",
+ " print \"\"\n",
+ "List=LIST()\n",
+ "List=None\n",
+ "print \"Linked-list manipulation program...\"\n",
+ "while(1):\n",
+ " choice=int(raw_input(\"List operation, 1- Insert, 2- Display, 3-Delete, 4-Quit: \"))\n",
+ " if choice==1:\n",
+ " data=int(raw_input(\"Enter data for node to be created: \"))\n",
+ " List=InsertNode(data, List)\n",
+ " elif choice==2:\n",
+ " print \"List Contents:\",\n",
+ " DisplayList(List)\n",
+ " elif choice==3:\n",
+ " data=int(raw_input(\"Enter data for node to be delete: \"))\n",
+ " List=DeleteNode(data, List)\n",
+ " elif choice==4:\n",
+ " print \"End of Linked List Computation !!.\"\n",
+ " break\n",
+ " else:\n",
+ " print \"Bad Option Selected\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Linked-list manipulation program...\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "List operation, 1- Insert, 2- Display, 3-Delete, 4-Quit: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for node to be created: 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "List operation, 1- Insert, 2- Display, 3-Delete, 4-Quit: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for node to be created: 7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "List operation, 1- Insert, 2- Display, 3-Delete, 4-Quit: 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for node to be created: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "List operation, 1- Insert, 2- Display, 3-Delete, 4-Quit: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "List Contents: -> 3 -> 7 -> 5 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "List operation, 1- Insert, 2- Display, 3-Delete, 4-Quit: 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter data for node to be delete: 7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "List operation, 1- Insert, 2- Display, 3-Delete, 4-Quit: 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "List Contents: -> 3 -> 5 \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "List operation, 1- Insert, 2- Display, 3-Delete, 4-Quit: 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "End of Linked List Computation !!.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-wild1.cpp, Page no-332"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "p=[int]*10 #uninitialized integer pointer\n",
+ "for i in range(10):\n",
+ " print p[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "<type 'int'> <type 'int'> <type 'int'> <type 'int'> <type 'int'> <type 'int'> <type 'int'> <type 'int'> <type 'int'> <type 'int'>\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-wild2.cpp, Page no-332"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "name=\"Savithri\"\n",
+ "print name"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Savithri\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-wild3.cpp, Page no-333"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def nameplease():\n",
+ " name=\"Savithri\"\n",
+ " return name\n",
+ "def charplease():\n",
+ " ch='X'\n",
+ " return ch\n",
+ "p1=nameplease()\n",
+ "p2=charplease()\n",
+ "print \"Name =\", p1\n",
+ "print \"Char =\", p2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name = Savithri\n",
+ "Char = X\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-wild4.cpp, Page no-334"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "p1=str\n",
+ "def temp():\n",
+ " name=\"Savithri\"\n",
+ " global p1\n",
+ " p1=name\n",
+ "temp()\n",
+ "print \"Name =\", p1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name = Savithri\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-1, Page no-335"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Str=\"Programming\"\n",
+ "count=0\n",
+ "str_ptr=Str[0]\n",
+ "while(count+1<len(Str)):\n",
+ " count+=1\n",
+ " str_ptr=Str[count]\n",
+ "count+=1\n",
+ "print \"Number of characters in the word Programming =\", count"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of characters in the word Programming = 11\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example-2, Page no-335"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def sort(x):\n",
+ " for k in range(SIZE-1):\n",
+ " i=0\n",
+ " while i<=(SIZE-k-2):\n",
+ " if x[i]>x[i+1]:\n",
+ " x[i], x[i+1]=x[i+1], x[i]\n",
+ " i+=1\n",
+ " return x\n",
+ "SIZE=10\n",
+ "a=[4,59,84,35,9,17,41,19,2,21]\n",
+ "ptr=a\n",
+ "temp=ptr\n",
+ "print \"Given array elements:\"\n",
+ "for i in range(SIZE):\n",
+ " print temp[i],\n",
+ "ptr=sort(ptr)\n",
+ "temp=ptr\n",
+ "print \"\\nSorted array elemnets:\"\n",
+ "for i in range(SIZE):\n",
+ " print temp[i],"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Given array elements:\n",
+ "4 59 84 35 9 17 41 19 2 21 \n",
+ "Sorted array elemnets:\n",
+ "2 4 9 17 19 21 35 41 59 84\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/AbhishekGupta/chapter16.ipynb b/sample_notebooks/AbhishekGupta/chapter16.ipynb
new file mode 100755
index 00000000..9a6c8320
--- /dev/null
+++ b/sample_notebooks/AbhishekGupta/chapter16.ipynb
@@ -0,0 +1,108 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:5681cda1a39ee67e447ba1a84903896a8e1196df60e583969d262ff3e357d1cb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter16:WIRELESS WANs: CELLULAR TELEPHONE\n",
+ "AND SATELLITE NETWORKS"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex16.1:pg-479"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example1\n",
+ "#calculate the period of the Moon\n",
+ "\n",
+ "C=1.0/100;\n",
+ "dist_moon=384000; # 384,000 km\n",
+ "radius_earth = 6378; # 6378 km\n",
+ "distance=dist_moon+radius_earth ;# total distance in km\n",
+ "Period=C*((distance)**1.5); #formula\n",
+ "month=round(Period/2592000); # 1 month = 60*60*24*30=2592000 seconds\n",
+ "print\"The period of the Moon, according to Keplers law is\",round(month)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The period of the Moon, according to Keplers law is 1.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex16.2:pg-479"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example2\n",
+ "#calculate of the period of the satellite\n",
+ "C=1.0/100;\n",
+ "orbit=35786; # 35,786 km\n",
+ "radius_earth = 6378; # 6378 km\n",
+ "distance=orbit+radius_earth ;# total distance in km\n",
+ "Period=C*((distance)**1.5); #formula\n",
+ "hour=round(Period/3600); # 1 hour = 60*60=3600 seconds\n",
+ "print\"According to Keplers law, the period of the satellite is\",floor(Period),\"s or \",hour, \"hours.\"\n",
+ "print\"\\nThis means that a satellite located at\", orbit,\"km has a period of \",hour,\"h, which is the same as the rotation period of the Earth.\\nA satellite like this is said to be stationary to the Earth. The orbit is called a geosynchronous orbit.\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "According to Keplers law, the period of the satellite is 86579.0 s or 24.0 hours.\n",
+ "\n",
+ "This means that a satellite located at 35786 km has a period of 24.0 h, which is the same as the rotation period of the Earth.\n",
+ "A satellite like this is said to be stationary to the Earth. The orbit is called a geosynchronous orbit.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/AkshayPatil/Chapter02.ipynb b/sample_notebooks/AkshayPatil/Chapter02.ipynb
new file mode 100755
index 00000000..0aad1c0c
--- /dev/null
+++ b/sample_notebooks/AkshayPatil/Chapter02.ipynb
@@ -0,0 +1,108 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:1cb720af73aa9aeffe36433462db80e841a95011aedc57edfe5b2ec1f1efe5b3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 02:Highway Planning and Alignment"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2-1, Page Number-35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Note:The variables have been changed to ease coding\n",
+ "Tot_Area=14400 #Total Area in km^2\n",
+ "Agri_Area=4800 #Agricultural Area in km^2\n",
+ "Track_Len=219 #Kength of the track in km\n",
+ "Met_Road=469 #Total Existing length of metalled road in km\n",
+ "Unmet_Road=412 #Total Existing Length of Unmetalled road in km\n",
+ "#The tabular data will be taken as and when required\n",
+ "\n",
+ "#Calculations\n",
+ "#Metalled Road\n",
+ "A=Agri_Area\n",
+ "B=Tot_Area-Agri_Area\n",
+ "N=50 #No: of villages and town in the population range of 2001 to 5000\n",
+ "T=10\n",
+ "#Solving for L\n",
+ "Road_Length=(A/8)+(B/32)+1.6*N+8*T #Length of metalled road in km\n",
+ "D=0.15*Road_Len\n",
+ "R=Track_Len\n",
+ "L=Road_Length+D-R\n",
+ "#Unmetalled Road\n",
+ "#Values from the given table\n",
+ "V=500 #No: of villages and towns\n",
+ "Q=300\n",
+ "P=200\n",
+ "S=50\n",
+ "#Solving for L1\n",
+ "Road_Length2=0.32*V+0.8*Q+1.6*P+3.2*S\n",
+ "L1=Road_Length2+0.15*Road_Length2 #Length in km\n",
+ "\n",
+ "#Final Computation\n",
+ "#(1)\n",
+ "Tot_Len_Met_Road=Road_Length+D-Met_Road #In km\n",
+ "#(2)\n",
+ "Tot_Len_Un_Road=L1-Unmet_Road #In km\n",
+ "#(3)\n",
+ "Tot_Road=Road_Len+D+L1 #In km\n",
+ "#Road per 100km^2\n",
+ "Road_Len_per=(Tot_Road/Tot_Area)*100 #in km\n",
+ "\n",
+ "#Result\n",
+ "print \"Total Additional length of metalled road is\", Tot_Len_Met_Road,\"km\"\n",
+ "print \"Total Additional Length of Unmetalled road is\", Tot_Len_Un_Road,\"km\"\n",
+ "print \"Total length of both categories is\",Tot_Road,\"km\"\n",
+ "print \"Road Length per 100sqkm is\",round(Road_Len_per,1),\"km\"\n",
+ "print \"As road length per 100km^2 is near to 16km, the target is achieved\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total Additional length of metalled road is 750.0 km\n",
+ "Total Additional Length of Unmetalled road is 600.0 km\n",
+ "Total length of both categories is 2231.0 km\n",
+ "Road Length per 100sqkm is 15.5 km\n",
+ "As road length per 100km^2 is near to 16km, the target is achieved\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/AnkitKumar/chapter6.ipynb b/sample_notebooks/AnkitKumar/chapter6.ipynb
new file mode 100755
index 00000000..ca369989
--- /dev/null
+++ b/sample_notebooks/AnkitKumar/chapter6.ipynb
@@ -0,0 +1,295 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Ch-6 Xrays"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.1 : Wavelength of X-rays: Pg: 156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h = 6.6e-034; # Planck's constant, J-s\n",
+ "V = 50000; # Potential difference, volts\n",
+ "c = 3e+08; # Velocity of light, m/s\n",
+ "e = 1.6e-019; # Charge of an electron, coulombs\n",
+ "L_1 = h*c/(e*V); # wavelength of X-rays, m\n",
+ "L = L_1/1e-010; # wavelength of X-rays, angstorm\n",
+ "print \"\\nThe shortest wavelength of X-rays = %6.4f angstorm\" % L"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The shortest wavelength of X-rays = 0.2475 angstorm\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.2 : Planck's constant: Pg: 156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "L = 24.7e-012; # Wavelength of X-rays, m\n",
+ "V = 50000; # Potential difference, volts\n",
+ "c = 3e+08; # Velocity of light, m/s\n",
+ "e = 1.6e-019; # Charge of an electron, coulombs\n",
+ "# Since e*V = h*c/L; # Energy required by an electron to move through a potential barrier of one volt, joules\n",
+ "# solving for h\n",
+ "h = e*V*L/c; # Planck's constant, Joule second\n",
+ "print \"h = %3.1e Js \" %h"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "h = 6.6e-34 Js \n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.3 : Short wavelength limit : Pg: 156"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "V = 50000; # Potential difference, volts\n",
+ "h = 6.624e-034; # Planck's constant, Js\n",
+ "c = 3e+08; # Velocity of light, m/s\n",
+ "e = 1.6e-019; # Charge of an electron, coulombs\n",
+ "# Since e*V = h*c/L; # Energy required by an electron to move through a potential barrier of one volt, joules\n",
+ "# solving for L\n",
+ "L = h*c/(e*V); # Short wavelength limit of X-ray, m\n",
+ "print \"Short wavelength limit of X-ray = %6.4f angstorm\" %(L/1E-10)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Short wavelength limit of X-ray = 0.2484 angstorm\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.4 : Wavelength limit of X-rays : Pg: 157"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "V = 20000; # Potential difference, volt\n",
+ "h = 6.624e-034; # Planck's constant, Js\n",
+ "c = 3e+08; # Velocity of light, m/s\n",
+ "e = 1.6e-019; # Charge of an electron, coulombs\n",
+ "# Since e*V = h*c/L; # Energy required by an electron to move through a potential barrier of one volt, joules\n",
+ "# solving for L\n",
+ "L = h*c/(e*V); # Wavelength limit of X-rays, m\n",
+ "print \"Short wavelength limit of X-ray = %6.4f angstorm\" % (L/1E-010);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Short wavelength limit of X-ray = 0.6210 angstorm\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.5 : Minimum voltage of an X-ray tube : Pg: 157"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h = 6.625e-034; # Planck's constant, Js\n",
+ "c = 3e+08; # Velocity of light, m/s\n",
+ "e = 1.6e-019; # Charge of an electron, coulombs\n",
+ "L = 1e-010; # Wavelength of X-rays, m\n",
+ "# Since e*V = h*c/L; # Energy required by an electron to move through a potential barrier of one volt, joules\n",
+ "# solving for V\n",
+ "V = h*c/(L*e); # Potential difference, volts\n",
+ "print \"The minimum voltage of an X-ray tube = %5.2f kV\"%(V/1e+03);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum voltage of an X-ray tube = 12.42 kV\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.5 : Minimum voltage of an X-ray tube : Pg: 157"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h = 6.625e-034; # Planck's constant, Js\n",
+ "c = 3e+08; # Velocity of light, m/s\n",
+ "e = 1.6e-019; # Charge of an electron, coulombs\n",
+ "L = 1e-010; # Wavelength of X-rays, m\n",
+ "# Since e*V = h*c/L; # Energy required by an electron to move through a potential barrier of one volt, joules\n",
+ "# solving for V\n",
+ "V = h*c/(L*e); # Potential difference, volts\n",
+ "print \"The minimum voltage of an X-ray tube = %5.2f kV\"%( V/1e+03)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum voltage of an X-ray tube = 12.42 kV\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.6 : Minimum wavelength emitted by an X-ray tube : Pg: 157"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h = 6.625e-034; # Planck's constant, Js\n",
+ "c = 3e+08; # Velocity of light, m/s\n",
+ "e = 1.6e-019; # Charge of an electron, coulombs\n",
+ "V = 4.5e+04; # Accelerating potential of X-ray tube, volt\n",
+ "# Since e*V = h*c/L_min; # Energy required by an electron to move through a potential barrier of one volt, joules\n",
+ "# solving for L_min\n",
+ "L_min = h*c/(V*e); # Minimum wavelength emitted by an X-ray tube, m\n",
+ "print \"The minimum wavelength emitted by the X-ray tube = %5.3f angstrom\"%(L_min/1e-010);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum wavelength emitted by the X-ray tube = 0.276 angstrom\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.7: Critical voltage for stimualted emission : Pg: 158"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "h = 6.625e-034; # Planck's constant, Js\n",
+ "c = 3e+08; # Velocity of light, m/s\n",
+ "e = 1.6e-019; # Charge of an electron, coulombs\n",
+ "L_k = 0.178e-010; # Wavelength of k absorption egde of X-rays, m\n",
+ "# Since e*V_critical = h*c/L; # Energy required by an electron to move through a potential barrier of one volt, joules\n",
+ "# solving for V_critical\n",
+ "V_critical = h*c/(L_k*e); # Crtical voltage for stimulated enission, volt\n",
+ "print \"The critical voltage for stimulated emission = %4.1f kV\"%(V_critical/1e+03);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The critical voltage for stimulated emission = 69.8 kV\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/sample_notebooks/AviralYadav/Chapter7.ipynb b/sample_notebooks/AviralYadav/Chapter7.ipynb
new file mode 100755
index 00000000..f8cf792d
--- /dev/null
+++ b/sample_notebooks/AviralYadav/Chapter7.ipynb
@@ -0,0 +1,474 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:aa3033a597a0bf06128c3fae6fc134561fe0b608c1a6f342b1690de7caed5ad0"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter07:Differential and Multistage amlplifiers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.1:pg-690"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Example 7.1 Analysis of differential amplifier\n",
+ "# Consider the differential amplifier\n",
+ "\n",
+ "B=100.0; # beta value\n",
+ "\n",
+ "# 7.1a\n",
+ "V_T=0.025; # (V)\n",
+ "I_E=0.0005; # (A)\n",
+ "R_E=150.0; # (ohm)\n",
+ "r_e1=V_T/I_E; # emitter resistance (ohm)\n",
+ "r_e2=r_e1; # emitterA resistance (ohm)\n",
+ "r_e=r_e1;\n",
+ "R_id=2*(B+1)*(r_e+R_E);\n",
+ "print round(R_id/1000.0),\"The input differential resistance R_id (kohm)\"\n",
+ "\n",
+ "# 7.1b\n",
+ "R_id=40000.0; # (ohm)\n",
+ "R_sig=5000.0; # (ohm)\n",
+ "R_C=10000.0; # (ohm)\n",
+ "R_E=150.0; # (ohm)\n",
+ "A_v=R_id/(R_id+R_sig); # A_v= v_o/v_sig (V/V)\n",
+ "A_V=2*R_C/(2.0*(r_e+R_E)); # A_V= v_o/v_id (V/v)\n",
+ "A_d=A_v*A_V; # A_d=v_o/v_sig (V/V)\n",
+ "print \"Overall differential voltage gain (V/V)\",round(A_d,-1)\n",
+ "\n",
+ "# 7.1c\n",
+ "R_EE=200000.0; # (ohm)\n",
+ "deltaR_C=0.02*R_C; # in the worst case\n",
+ "A_cm=R_C*deltaR_C/(2.0*R_EE*R_C)\n",
+ "print A_cm,\"Worst case common mode gain (V/V)\"\n",
+ "\n",
+ "# 7.1d\n",
+ "CMRR=20*math.log10(A_d/A_cm)\n",
+ "print int(CMRR),\"CMRR in dB\"\n",
+ "\n",
+ "# 7.1e\n",
+ "r_o=200000.0; #(ohm)\n",
+ "R_icm=(B+1)*(R_EE*r_o/2.0)/(R_EE+r_o/2.0);\n",
+ "print round(R_icm/1e6,1),\"Input common mode resistance (kohm)\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "40.0 The input differential resistance R_id (kohm)\n",
+ "Overall differential voltage gain (V/V) 40.0\n",
+ "0.0005 Worst case common mode gain (V/V)\n",
+ "98 CMRR in dB\n",
+ "6.7 Input common mode resistance (kohm)\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.2:pg-747"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Example 7.2 : Analysis of Active loaded MOS differential amplifier\n",
+ "W=7.2*10**-6; # (m)\n",
+ "L=0.36*10**-6; # (m)\n",
+ "C_gs=29*10**-15; # (F)\n",
+ "C_gd=5*10**-15; # (F)\n",
+ "C_db=5*10**-15; # (F)\n",
+ "uC_n=387*10**-6; # uC_n=u_nC_ox (A/V**2)\n",
+ "uC_p=86*10**-6; # uC_p=u_pC_ox (A/V**2)\n",
+ "V_an=5; # V_an=V'_An (V/um) (V)\n",
+ "V_ap=6; # V_ap=V'_Ap (V/um) (V)\n",
+ "I=0.2*10**-3; # (A)\n",
+ "R_SS=25000; # (ohm)\n",
+ "C_SS=0.2*10**-12; # (F)\n",
+ "C_S=25*10**-15; # (F)\n",
+ "K_n=uC_n*W/L;\n",
+ "I_D=100*10**-6; # bias current (A)\n",
+ "V_OV=math.sqrt(2*I_D/K_n);\n",
+ "g_m=I/V_OV;\n",
+ "g_m1=g_m;\n",
+ "g_m2=g_m;\n",
+ "r_o1=V_an*0.36/(0.1*10**-3);\n",
+ "r_o2=r_o1;\n",
+ "K_p=uC_p*W/L;\n",
+ "V_OV34=math.sqrt(2*I_D/K_p); # V_OV3,4\n",
+ "g_m3=2*0.1*10**-3/V_OV34;\n",
+ "g_m4=g_m3;\n",
+ "r_o3=V_ap*0.36/(0.1*10**-3);\n",
+ "r_o4=r_o3;\n",
+ "A_d=g_m*(r_o2*r_o4)/(r_o2+r_o4);\n",
+ "print round(A_d,1),\"A_d (V/V)\"\n",
+ "A_cm=-1/(2*g_m3*R_SS);\n",
+ "print round(A_cm,3),\"A_cm (V/V)\"\n",
+ "CMRR=20*log10(-A_d/A_cm); # negative sign to make A_cm positive\n",
+ "print round(CMRR,1),\"CMRR in dB\"\n",
+ "C_gd1=5*10**-15; # (F)\n",
+ "C_db1=5*10**-15; # (F)\n",
+ "C_db3=5*10**-15; # (F)\n",
+ "C_gs3=20*10**-15; # (F)\n",
+ "C_gs4=20*10**-15; # (F)\n",
+ "C_m=C_gd1+C_db1+C_db3+C_gs3+C_gs4;\n",
+ "C_gd2=5*10**-15; # (F)\n",
+ "C_db2=5*10**-15; # (F)\n",
+ "C_gd4=5*10**-15; # (F)\n",
+ "C_db4=5*10**-15; # (F)\n",
+ "C_x=25*10**-15; # (F)\n",
+ "C_L=C_gd2+C_db2+C_gd4+C_db4+C_x;\n",
+ "print \"poles and zeroes of A_d\"\n",
+ "R_o=r_o2*r_o4/(r_o2+r_o4)\n",
+ "f_p1=1/(2*math.pi*C_L*R_o);\n",
+ "print int(f_p1/1e6),\"f_p1 (MHz)\"\n",
+ "f_p2=g_m3/(2*math.pi*C_m);\n",
+ "print round(f_p2/1e9,2),\"f_p2 (GHz)\"\n",
+ "f_Z=2*f_p2;\n",
+ "print round(f_Z/1e9,1),\"f_Z (GHz)\"\n",
+ "print \"Dominant pole of CMRR is at location of commom-mode gain zero\"\n",
+ "f_Z=1/(2*math.pi*C_SS*R_SS);\n",
+ "print round(f_Z/1e6,1),\"f_Z (MHz)\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12.2 A_d (V/V)\n",
+ "-0.034 A_cm (V/V)\n",
+ "51.1 CMRR in dB\n",
+ "poles and zeroes of A_d\n",
+ "360 f_p1 (MHz)\n",
+ "1.7 f_p2 (GHz)\n",
+ "3.4 f_Z (GHz)\n",
+ "Dominant pole of CMRR is at location of commom-mode gain zero\n",
+ "31.8 f_Z (MHz)\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.3:pg-751"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Example 7.3 : To determine all parameters for different transistor\n",
+ "I_REF=90*10.0**-6; # (A)\n",
+ "V_tn=0.7; # (V)\n",
+ "V_tp=0.8; # Magnitude is cconsidered\n",
+ "uC_n=160.0*10**-6; # uC_n=u_n*C_ox\n",
+ "uC_p=40*10.0**-6; # uC_p=u_p*C_ox\n",
+ "V_A=10.0; # (V)\n",
+ "V_DD=2.5; # (V)\n",
+ "V_SS=2.5; # (V)\n",
+ "L=0.8*10**-6; # (m)\n",
+ "r_o2=222.0; # (ohm)\n",
+ "r_o4=222.0; # (ohm)\n",
+ "g_m1=0.3; # (mho)\n",
+ "A_1=-g_m1*r_o2*r_o4/(r_o2+r_o4);\n",
+ "print round(A_1,2),\"=A_1 (V/V)\"\n",
+ "r_o6=111.0; # (ohm)\n",
+ "r_o7=111.0; # (ohm)\n",
+ "g_m6=0.6; # (mho)\n",
+ "A_2=-g_m6*r_o6*r_o7/(r_o6+r_o7);\n",
+ "print round(A_2,2),\"=A_2 (V/V)\"\n",
+ "print \"For Q_1\"\n",
+ "W=20*10.0**-6; # (m)\n",
+ "I_D=I_REF/2.0; # (A)\n",
+ "print round(I_D/(10.0**-6),2),\"=I_D (microA)\"\n",
+ "K_p=uC_p*W/L;\n",
+ "V_OV=math.sqrt(2*I_D/K_p);\n",
+ "print round(V_OV,2),\"=V_OV (V)\"\n",
+ "V_GS=V_tp+V_OV;\n",
+ "print round(V_GS,2),\"=V_GS (V)\"\n",
+ "g_m=2*I_D/V_OV;\n",
+ "print round(g_m/(10.0**-3),2),\"=g_m (mA/V)\"\n",
+ "r_o=V_A/I_D;\n",
+ "print int(r_o/1e3),\"=r_o (kohm)\"\n",
+ "print \"For Q_2\"\n",
+ "W=20*10.0**-6; # (m)\n",
+ "I_D=I_REF/2; # (A)\n",
+ "print round(I_D/(10.0**-6),2),\"=I_D (microA)\"\n",
+ "K_p=uC_p*W/L;\n",
+ "V_OV=math.sqrt(2*I_D/K_p);\n",
+ "print round(V_OV,2),\"=V_OV (V)\"\n",
+ "V_GS=V_tp+V_OV;\n",
+ "print round(V_GS,2),\"=V_GS (V)\"\n",
+ "g_m=2*I_D/V_OV;\n",
+ "print round(g_m/(10.0**-3),2),\"=g_m (mA/V)\"\n",
+ "r_o=V_A/I_D;\n",
+ "print round(r_o/1e3),\"=r_o (kohm)\"\n",
+ "print \"For Q_3\"\n",
+ "W=5*10**-6; # (m)\n",
+ "I_D=I_REF/2; # (A)\n",
+ "print round(I_D/(10.0**-6),2),\"=I_D (microA)\"\n",
+ "K_n=uC_n*W/L;\n",
+ "V_OV=math.sqrt(2*I_D/K_n);\n",
+ "print round(V_OV,2),\"=V_OV (V)\"\n",
+ "V_GS=V_tn+V_OV;\n",
+ "print round(V_GS,2),\"=V_GS (V)\"\n",
+ "g_m=2*I_D/V_OV;\n",
+ "print round(g_m/(10.0**-3),2),\"=g_m (mA/V)\"\n",
+ "r_o=V_A/I_D;\n",
+ "print round(r_o/1e3),\"=r_o (kohm)\"\n",
+ "print \"For Q_4\"\n",
+ "W=5*10**-6; # (m)\n",
+ "I_D=I_REF/2; # (A)\n",
+ "print round(I_D/(10.0**-6),2),\"=I_D (microA)\"\n",
+ "K_n=uC_n*W/L;\n",
+ "V_OV=math.sqrt(2*I_D/K_n);\n",
+ "print round(V_OV,2),\"=V_OV (V)\"\n",
+ "V_GS=V_tn+V_OV;\n",
+ "print round(V_GS,2),\"=V_GS (V)\"\n",
+ "g_m=2*I_D/V_OV;\n",
+ "print round(g_m/(10.0**-3),2),\"=g_m (mA/V)\"\n",
+ "r_o=V_A/I_D;\n",
+ "print round(r_o/1e3),\"=r_o (kohm)\"\n",
+ "print \"For Q_5\"\n",
+ "W=40*10.0**-6; # (m)\n",
+ "I_D=I_REF; # (A)\n",
+ "print round(I_D/(10.0**-6),2),\"=I_D (microA)\"\n",
+ "K_p=uC_p*W/L;\n",
+ "V_OV=math.sqrt(2*I_D/K_p);\n",
+ "print round(V_OV,2),\"=V_OV (V)\"\n",
+ "V_GS=V_tp+V_OV;\n",
+ "print round(V_GS,2),\"=V_GS (V)\"\n",
+ "g_m=2*I_D/V_OV;\n",
+ "print round(g_m/(10.0**-3),2),\"=g_m (mA/V)\"\n",
+ "r_o=V_A/I_D;\n",
+ "print round(r_o/1e3),\"=r_o (kohm)\"\n",
+ "print \"For Q_6\"\n",
+ "W=10*10**-6; # (m)\n",
+ "I_D=I_REF; #A\n",
+ "print round(I_D/(10.0**-6),2),\"=I_D (microA)\"\n",
+ "K_n=uC_n*W/L;\n",
+ "V_OV=math.sqrt(2*I_D/K_n);\n",
+ "print round(V_OV,2),\"=V_OV (V)\"\n",
+ "V_GS=V_tn+V_OV;\n",
+ "print round(V_GS,2),\"=V_GS (V)\"\n",
+ "g_m=2*I_D/V_OV;\n",
+ "print round(g_m/(10.0**-3),2),\"=g_m (mA/V)\"\n",
+ "r_o=V_A/I_D;\n",
+ "print round(r_o/1e3),\"=r_o (kohm)\"\n",
+ "print \"For Q_7\"\n",
+ "W=40*10**-6; # (m)\n",
+ "I_D=I_REF;#A\n",
+ "print round(I_D/(10.0**-6),2),\"=I_D (microA)\"\n",
+ "K_p=uC_p*W/L;\n",
+ "V_OV=math.sqrt(2*I_D/K_p);\n",
+ "print round(V_OV,2),\"=V_OV (V)\"\n",
+ "V_GS=V_tp+V_OV;\n",
+ "print round(V_GS,2),\"=V_GS (V)\"\n",
+ "g_m=2*I_D/V_OV;\n",
+ "print round(g_m/(10.0**-3),2),\"=g_m (mA/V)\"\n",
+ "r_o=V_A/I_D;\n",
+ "print round(r_o/1e3),\"=r_o (kohm)\"\n",
+ "print \"For Q_8\"\n",
+ "W=40*10**-6; # (m)\n",
+ "I_D=I_REF; # A\n",
+ "print round(I_D/(10.0**-6),2),\"=I_D (microA)\"\n",
+ "K_p=uC_p*W/L;\n",
+ "V_OV=math.sqrt(2*I_D/K_p);\n",
+ "print round(V_OV,2),\"=V_OV (V)\"\n",
+ "V_GS=V_tp+V_OV;\n",
+ "print round(V_GS,2),\"=V_GS (V)\"\n",
+ "g_m=2*I_D/V_OV;\n",
+ "print round(g_m/(10.0**-3),2),\"=g_m (mA/V)\"\n",
+ "r_o=V_A/I_D;\n",
+ "print int(r_o/1e3),\"=r_o (kohm)\"\n",
+ "A_O=A_1*A_2;\n",
+ "print round(20*log10(A_O)),\"=The dc open loop gain in dB\"\n",
+ "v_ICMmin=-2.5+1;\n",
+ "print round(v_ICMmin,2),\"=Lower limit of input common-mode (V)\"\n",
+ "v_ICMmax=2.2-1.1;\n",
+ "print round(v_ICMmax,2),\"=Upper limit of input common-mode (V)\"\n",
+ "v_Omax=V_DD-V_OV;\n",
+ "print round(v_Omax,2),\"=Highest allowable output voltage (V)\"\n",
+ "v_Omin=-V_SS+V_OV;\n",
+ "print round(v_Omin,2),\"=Lowest allowable output voltage (V)\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-33.3 =A_1 (V/V)\n",
+ "-33.3 =A_2 (V/V)\n",
+ "For Q_1\n",
+ "45.0 =I_D (microA)\n",
+ "0.3 =V_OV (V)\n",
+ "1.1 =V_GS (V)\n",
+ "0.3 =g_m (mA/V)\n",
+ "222 =r_o (kohm)\n",
+ "For Q_2\n",
+ "45.0 =I_D (microA)\n",
+ "0.3 =V_OV (V)\n",
+ "1.1 =V_GS (V)\n",
+ "0.3 =g_m (mA/V)\n",
+ "222.0 =r_o (kohm)\n",
+ "For Q_3\n",
+ "45.0 =I_D (microA)\n",
+ "0.3 =V_OV (V)\n",
+ "1.0 =V_GS (V)\n",
+ "0.3 =g_m (mA/V)\n",
+ "222.0 =r_o (kohm)\n",
+ "For Q_4\n",
+ "45.0 =I_D (microA)\n",
+ "0.3 =V_OV (V)\n",
+ "1.0 =V_GS (V)\n",
+ "0.3 =g_m (mA/V)\n",
+ "222.0 =r_o (kohm)\n",
+ "For Q_5\n",
+ "90.0 =I_D (microA)\n",
+ "0.3 =V_OV (V)\n",
+ "1.1 =V_GS (V)\n",
+ "0.6 =g_m (mA/V)\n",
+ "111.0 =r_o (kohm)\n",
+ "For Q_6\n",
+ "90.0 =I_D (microA)\n",
+ "0.3 =V_OV (V)\n",
+ "1.0 =V_GS (V)\n",
+ "0.6 =g_m (mA/V)\n",
+ "111.0 =r_o (kohm)\n",
+ "For Q_7\n",
+ "90.0 =I_D (microA)\n",
+ "0.3 =V_OV (V)\n",
+ "1.1 =V_GS (V)\n",
+ "0.6 =g_m (mA/V)\n",
+ "111.0 =r_o (kohm)\n",
+ "For Q_8\n",
+ "90.0 =I_D (microA)\n",
+ "0.3 =V_OV (V)\n",
+ "1.1 =V_GS (V)\n",
+ "0.6 =g_m (mA/V)\n",
+ "111 =r_o (kohm)\n",
+ "61.0 =The dc open loop gain in dB\n",
+ "-1.5 =Lower limit of input common-mode (V)\n",
+ "1.1 =Upper limit of input common-mode (V)\n",
+ "2.2 =Highest allowable output voltage (V)\n",
+ "-2.2 =Lowest allowable output voltage (V)\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.5:pg-760"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Example 7.5 : Analysis of given circuit\n",
+ "B=100.0; # beta value\n",
+ "I_E=0.2510**-3; # (A)\n",
+ "R_1=20000.0; # (ohm)\n",
+ "R_2=20000; # (ohm)\n",
+ "R_3=3000; # (ohm)\n",
+ "R_4=2300; # (ohm)\n",
+ "R_5=15700; # (ohm)\n",
+ "R_6=3000; # (ohm)\n",
+ "r_e1=25/0.25; # (ohm)\n",
+ "r_e2=r_e1; # (ohm)\n",
+ "r_pi1=(B+1)*r_e1;\n",
+ "r_pi2=(B+1)*r_e2;\n",
+ "R_id=r_pi1+r_pi2;\n",
+ "print round(R_id/1e3,2),\"Input differential resistance (kohm)\"\n",
+ "I_E=1*10.0**-3;\n",
+ "r_e4=25/1.0;\n",
+ "r_e5=r_e4;\n",
+ "r_pi4=(B+1)*r_e4;\n",
+ "r_pi5=(B+1)*r_e5;\n",
+ "R_i2=r_pi4+r_pi5;\n",
+ "print round(R_i2/1e3,2),\"Input resistance of the second stage R_i2 (kohm)\"\n",
+ "A_1=(R_i2*(R_1+R_2)/((R_i2+R_1+R_2)*(r_e1+r_e2)))\n",
+ "print round(A_1,1),\"Voltage gain of the first stage (V/V)\"\n",
+ "r_e7=25/1.0;\n",
+ "R_i3=(B+1)*(R_4+r_e7);\n",
+ "print round(R_i3/1e3,1),\"Input resistance of the third stage R_i3 (kohm)\"\n",
+ "A_2=(-R_3*R_i3)/((R_3+R_i3)*(r_e4+r_e5));\n",
+ "print round(A_2,1),\"Voltage gain of the second stage (V/V)\"\n",
+ "r_e8=25/5.0;\n",
+ "R_i4=(B+1)*(r_e8+R_6);\n",
+ "print round(R_i4/1e3,2),\"Input resistance of the third stage R_i2 (kohm)\"\n",
+ "A_3=(-R_5*R_i4)/((R_5+R_i4)*(r_e7+R_4));\n",
+ "print round(A_3,2),\"Voltage gain of the third stage (V/V)\"\n",
+ "A_4=R_6/(R_6+r_e8);\n",
+ "print round(A_4,2),\"Voltage gain of the fourth stage (V/V)\"\n",
+ "A=A_1*A_2*A_3*A_4 ; # A=v_o/v_id (V/V)\n",
+ "print round(A),\"Overall output gain (V/V)\"\n",
+ "print round(20*log10(A),1),\"Overall output gain in dB\"\n",
+ "R_o=R_6*(r_e8+R_5/(B+1))/(R_6+r_e8+R_5/(B+1))\n",
+ "print round(R_o),\"Output resistance (ohm)\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "20.2 Input differential resistance (kohm)\n",
+ "5.05 Input resistance of the second stage R_i2 (kohm)\n",
+ "22.4 Voltage gain of the first stage (V/V)\n",
+ "234.8 Input resistance of the third stage R_i3 (kohm)\n",
+ "-59.2 Voltage gain of the second stage (V/V)\n",
+ "303.5 Input resistance of the third stage R_i2 (kohm)\n",
+ "-6.42 Voltage gain of the third stage (V/V)\n",
+ "1.0 Voltage gain of the fourth stage (V/V)\n",
+ "8514.0 Overall output gain (V/V)\n",
+ "78.6 Overall output gain in dB\n",
+ "152.0 Output resistance (ohm)\n"
+ ]
+ }
+ ],
+ "prompt_number": 56
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/ChaitanyaPotti/Chapter2_1.ipynb b/sample_notebooks/ChaitanyaPotti/Chapter2_1.ipynb
new file mode 100755
index 00000000..0734d609
--- /dev/null
+++ b/sample_notebooks/ChaitanyaPotti/Chapter2_1.ipynb
@@ -0,0 +1,365 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 2 - First law"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1 - pg 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 2.1\n",
+ "The Change in total energy is, del_E (kJ) = 1100\n",
+ "Since del_E is positive, so there is an increase in total energy\n",
+ "There is mistake in the book's results unit\n"
+ ]
+ }
+ ],
+ "source": [
+ "print 'Example 2.1'\n",
+ "#calculate the Change in total energy\n",
+ "\n",
+ "# Given values\n",
+ "Q = 2500; # Heat transferred into the system, [kJ]\n",
+ "W = 1400; # Work transferred from the system, [kJ]\n",
+ "\n",
+ "# solution\n",
+ "\n",
+ "# since process carried out on a closed system, so using equation [4]\n",
+ "del_E = Q-W; # Change in total energy, [kJ]\n",
+ "\n",
+ "# results\n",
+ "\n",
+ "print 'The Change in total energy is, del_E (kJ) = ',del_E\n",
+ "\n",
+ "if del_E >= 0:\n",
+ " print 'Since del_E is positive, so there is an increase in total energy'\n",
+ "else:\n",
+ " print 'Since del_E is negative, so there is an decrease in total energy'\n",
+ "\n",
+ "\n",
+ "print \"There is mistake in the book's results unit\"\n",
+ "\n",
+ "# End\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2 - pg 34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 2.2\n",
+ "The Heat transfer is, Q (kJ) = -700.0\n",
+ "Since Q < 0, so heat is transferred from the system\n"
+ ]
+ }
+ ],
+ "source": [
+ "print 'Example 2.2'\n",
+ "#calculate the heat transfer\n",
+ "\n",
+ "# Given values\n",
+ "del_E = 3500.; # Increase in total energy of the system, [kJ]\n",
+ "W = -4200.; # Work transfer into the system, [kJ]\n",
+ "\n",
+ "# solution\n",
+ "# since process carried out on a closed system, so using equation [3]\n",
+ "Q = del_E+W;# [kJ]\n",
+ "\n",
+ "# results\n",
+ "print 'The Heat transfer is, Q (kJ) = ',Q\n",
+ "\n",
+ "if Q >=0:\n",
+ " print 'Since Q > 0, so heat is transferred into the system'\n",
+ "else:\n",
+ " print 'Since Q < 0, so heat is transferred from the system'\n",
+ "\n",
+ "# End\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3 - pg 38"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 2.3\n",
+ "The Work done is, W (kJ/kg) = 250\n",
+ "Since W > 0, so Work done by the engine per kilogram of working substance\n"
+ ]
+ }
+ ],
+ "source": [
+ "print 'Example 2.3'\n",
+ "#calculate the Work done\n",
+ "\n",
+ "\n",
+ "# Given values\n",
+ "Q = -150; # Heat transferred out of the system, [kJ/kg]\n",
+ "del_u = -400; # Internal energy decreased ,[kJ/kg]\n",
+ "\n",
+ "# solution\n",
+ "# using equation [3],the non flow energy equation\n",
+ "# Q=del_u+W\n",
+ "W = Q-del_u; # [kJ/kg]\n",
+ "\n",
+ "# results\n",
+ "print 'The Work done is, W (kJ/kg) = ',W\n",
+ "\n",
+ "if W >=0:\n",
+ " print 'Since W > 0, so Work done by the engine per kilogram of working substance'\n",
+ "else:\n",
+ " print 'Since W < 0, so Work done on the engine per kilogram of working substance'\n",
+ "\n",
+ "# End\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4 - pg 39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 2.4\n",
+ "workdone is, W (kJ/kg) = 550.6875\n",
+ "Since W>0, so Power is output from the system\n",
+ "The power output from the system is (kW) = 2202.75\n"
+ ]
+ }
+ ],
+ "source": [
+ "print 'Example 2.4'\n",
+ "#calculate the power output and workdone\n",
+ "# Given values\n",
+ "m_dot = 4.; # fluid flow rate, [kg/s]\n",
+ "Q = -40.; # Heat loss to the surrounding, [kJ/kg]\n",
+ "\n",
+ "# At inlet \n",
+ "P1 = 600.; # pressure ,[kn/m**2]\n",
+ "C1 = 220.; # velocity ,[m/s]\n",
+ "u1 = 2200.; # internal energy, [kJ/kg]\n",
+ "v1 = .42; # specific volume, [m**3/kg]\n",
+ "\n",
+ "# At outlet\n",
+ "P2 = 150.; # pressure, [kN/m**2]\n",
+ "C2 = 145.; # velocity, [m/s]\n",
+ "u2 = 1650.; # internal energy, [kJ/kg]\n",
+ "v2 = 1.5; # specific volume, [m**3/kg]\n",
+ "\n",
+ "# solution\n",
+ "# for steady flow energy equation for the open system is given by\n",
+ "# u1+P1*v1+C1**2/2+Q=u2+P2*v2+C2**2/2+W\n",
+ "# hence\n",
+ "\n",
+ "W = (u1-u2)+(P1*v1-P2*v2)+(C1**2/2-C2**2/2)*10**-3+Q; # [kJ/kg]\n",
+ "\n",
+ "P_out = W*m_dot; # power out put from the system, [kW]\n",
+ "\n",
+ "# results\n",
+ "print 'workdone is, W (kJ/kg) = ',W\n",
+ "\n",
+ "if W >= 0:\n",
+ " print 'Since W>0, so Power is output from the system'\n",
+ "else:\n",
+ " print 'Since W<0, so Power is input to the system'\n",
+ "\n",
+ "# Hence\n",
+ "\n",
+ "print 'The power output from the system is (kW) = ',P_out\n",
+ "\n",
+ "# End\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5 - pg 39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 2.5\n",
+ "The temperature rise of the lead is (C) = 104.58\n"
+ ]
+ }
+ ],
+ "source": [
+ "print 'Example 2.5'\n",
+ "#calculate the temperature rise\n",
+ "\n",
+ "\n",
+ "# Given values\n",
+ "del_P = 154.45; # pressure difference across the die, [MN/m**2]\n",
+ "rho = 11360.; # Density of the lead, [kg/m**3]\n",
+ "c = 130; # specific heat capacity of the lead, [J/kg*K]\n",
+ "\n",
+ "# solution\n",
+ "# since there is no cooling and no externel work is done, so energy balane becomes\n",
+ "# P1*V1+U1=P2*V2+U2 ,so\n",
+ "# del_U=U2-U1=P1*V1-P2*V2\n",
+ "\n",
+ "# also, for temperature rise, del_U=m*c*t, where, m is mass; c is specific heat capacity; and t is temperature rise\n",
+ "\n",
+ "# Also given that lead is incompressible, so V1=V2=V and assuming one m**3 of lead\n",
+ "\n",
+ "# using above equations\n",
+ "t = del_P/(rho*c)*10**6 ;# temperature rise [C]\n",
+ "\n",
+ "# results \n",
+ "print 'The temperature rise of the lead is (C) = ',round(t,2)\n",
+ "\n",
+ "# End\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 6 - pg 42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 2.6\n",
+ "(a) The inlet area is, A1 (m^2) = 0.0425\n",
+ "(b) The exit velocity is, C2 (m/s) = 171.71\n",
+ "(c) The power developed by the turbine system is (kW) = 671.88\n"
+ ]
+ }
+ ],
+ "source": [
+ "print 'Example 2.6'\n",
+ "#calculate the power developed, exit velocity and inlet area\n",
+ "\n",
+ "# Given values\n",
+ "m_dot = 4.5; # mass flow rate of air, [kg/s]\n",
+ "Q = -40.; # Heat transfer loss, [kJ/kg]\n",
+ "del_h = -200.; # specific enthalpy reduce, [kJ/kg]\n",
+ "\n",
+ "C1 = 90; # inlet velocity, [m/s]\n",
+ "v1 = .85; # inlet specific volume, [m**3/kg]\n",
+ "\n",
+ "v2 = 1.45; # exit specific volume, [m**3/kg]\n",
+ "A2 = .038; # exit area of turbine, [m**2]\n",
+ "\n",
+ "# solution\n",
+ "\n",
+ "# part (a)\n",
+ "# At inlet, by equation[4], m_dot=A1*C1/v1\n",
+ "A1 = m_dot*v1/C1;#inlet area, [m**2]\n",
+ "print '(a) The inlet area is, A1 (m^2) = ',A1\n",
+ "\n",
+ "# part (b), \n",
+ "# At outlet, since mass flow rate is same, so m_dot=A2*C2/v2, hence\n",
+ "C2 = m_dot*v2/A2; # Exit velocity,[m/s]\n",
+ "print '(b) The exit velocity is, C2 (m/s) = ',round(C2,2)\n",
+ "\n",
+ "# part (c)\n",
+ "# using steady flow equation, h1+C1**2/2+Q=h2+C2**2/2+W\n",
+ "W = -del_h+(C1**2/2-C2**2/2)*10**-3+Q; # [kJ/kg]\n",
+ "\n",
+ "# Hence power developed is\n",
+ "P = W*m_dot;# [kW]\n",
+ "print '(c) The power developed by the turbine system is (kW) = ',round(P,2)\n",
+ "\n",
+ "# End\n",
+ "\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/sample_notebooks/DaudIbrahir Saifi/Chapter2.ipynb b/sample_notebooks/DaudIbrahir Saifi/Chapter2.ipynb
new file mode 100755
index 00000000..b9dc8563
--- /dev/null
+++ b/sample_notebooks/DaudIbrahir Saifi/Chapter2.ipynb
@@ -0,0 +1,228 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:cba451428c3d9c574800bbc1429b7e9efcd18af4b82f735faf4ac85b4ea52c65"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter02:The 741 IC OP-AMP"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.1:Pg-80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Ex 2.1\n",
+ "\n",
+ "# data from fig of Ex2.1\n",
+ "VCC=5.0;#V\n",
+ "IS=10**-14.0;#A\n",
+ "RS=39*1000.0;#ohm\n",
+ "VBE12=0.7;#V(Assumed)\n",
+ "VBE11=0.7;#V(Assumed)\n",
+ "VEE=-5;#V\n",
+ "IREF=(VCC-VBE12-VBE11-VEE)/RS*10**6;#micro A\n",
+ "print \"Estimated input reference current , IREF(micro A)\",round(IREF,2)\n",
+ "VT=25*10**-3;#V(Thermal Voltage)\n",
+ "VBE=VT*log(IREF*10**-6/IS);#V\n",
+ "IREF=(VCC-VBE-VBE-VEE)/RS*10**6;#micro A\n",
+ "print \"More precise value of reference current , IREF(micro A)\",round(IREF,2)\n",
+ "#Replacing Vcc by 15 V in the original design\n",
+ "VCC2=15.0;#V\n",
+ "VEE2=-15.0;#V\n",
+ "IREF=(VCC2-VBE-VBE-VEE2)/RS*10**6;#micro A\n",
+ "VBE=VT*log(IREF*10**-6/IS);#V\n",
+ "R5=(VCC-VBE-VBE-VEE)/(IREF*10**-6);#ohm\n",
+ "R5=round(R5/1000);#kohm\n",
+ "print \"Value of R5(kohm) : \",R5"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Estimated input reference current , IREF(micro A) 220.51\n",
+ "More precise value of reference current , IREF(micro A) 225.88\n",
+ "Value of R5(kohm) : 12.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.2:Pg-81"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Ex 2.2\n",
+ "import math\n",
+ "# data from fig of Ex2.2\n",
+ "IC10=20*10**-6;#A\n",
+ "IREF=0.5*10**-3;#A\n",
+ "IS=10**-14;#A\n",
+ "VT=25*10**-3;#V(Thermal Voltage)\n",
+ "R4=VT/IC10*math.log(IREF/IC10);#ohm\n",
+ "print \"For Widlar current source design, the value of R4(kohm) : \",round(R4/1000,2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For Widlar current source design, the value of R4(kohm) : 4.02\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.3:Pg-82"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Ex 2.3\n",
+ "\n",
+ "import math\n",
+ "# given data\n",
+ "Gm1=10.0;#mA/V\n",
+ "Gm1=Gm1/1000;#A/V\n",
+ "Cc=50.0;#pF\n",
+ "Cc=Cc*10**-12;#F\n",
+ "Rt=10**8;#ohm(Shunting resistance with Cc)\n",
+ " # solution\n",
+ "Ao=Gm1*Rt;#unitless\n",
+ "fp=1/(2*math.pi*Rt*Cc);#Hz\n",
+ "ft=Gm1/(2*math.pi*Cc)/10**6;#MHz\n",
+ "print \"Frequency at which gain is maximum, fp in Hz\",round(fp,1)\n",
+ "print \"Unit gain frequency, ft(MHz)\",round(ft,1)\n",
+ "#Bode plot can not be plotted with the given data in the question by using python functions. \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Frequency at which gain is maximum, fp in Hz 31.8\n",
+ "Unit gain frequency, ft(MHz) 31.8\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.4:Pg-83"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Ex 2.4\n",
+ "\n",
+ "import math\n",
+ "# given data\n",
+ "SR=10.0/10**-6;#V/s\n",
+ "Vout=10.0;#V(magnitude of output voltage)\n",
+ "fm=SR/(2*math.pi*Vout)/1000;#kHz\n",
+ "print \"Full power bandwidth(kHz)\",round(fm,1)\n",
+ "VT=25.0/1000;#V(Thermal voltage)\n",
+ "ft=SR/(2*math.pi*4*VT)/10.0**6;#MHz\n",
+ "print \"Unity gain bandwidth(MHz)\",round(ft,1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Full power bandwidth(kHz) 159.2\n",
+ "Unity gain bandwidth(MHz) 15.9\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.5:Pg-84"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Ex 2.5\n",
+ "\n",
+ "VCC=5;#V\n",
+ "VEE=-5;#V\n",
+ "VBE=0.6;#V\n",
+ "VCE23=0.6;#V\n",
+ "VCE_sat=0.2;#V\n",
+ "Vo_max=VCC-VCE_sat-VBE;#V\n",
+ "Vo_min=VEE+VCE_sat+VBE+VCE23;#V\n",
+ "print \"Maximum output voltage(V)\",round(Vo_max,2)\n",
+ "print \"Minimum output voltage(V)\",round(Vo_min,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum output voltage(V) 4.2\n",
+ "Minimum output voltage(V) -3.6\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/Hrituraj/Chapter7.ipynb b/sample_notebooks/Hrituraj/Chapter7.ipynb
new file mode 100755
index 00000000..71496b0e
--- /dev/null
+++ b/sample_notebooks/Hrituraj/Chapter7.ipynb
@@ -0,0 +1,814 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter7 - Distribution systems"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.1 - page 174"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "import cmath\n",
+ "#Given data : \n",
+ "l=1 #in km\n",
+ "I=100 #in Ampere\n",
+ "cosfi=0.8 #Power factor(lag) unitless\n",
+ "VC=200 #in volt\n",
+ "IL=60 #in Ampere\n",
+ "cosfi_load=0.9 #Power factor(lag) unitless\n",
+ "R=0.6 #in ohm\n",
+ "XL=0.08 #in ohm\n",
+ "IC=I*complex(0.8,-0.6) #in Ampere\n",
+ "z=complex(0.06,0.08)/2 #in ohm\n",
+ "VD_BC=z*IC #in volt\n",
+ "VB=VC+VD_BC #in volt\n",
+ "IB=IL*complex(0.9,-0.4357)+IC #in Ampere\n",
+ "VD_AB=z*IB #in volt\n",
+ "VD_AB=round(VD_AB.real,2)+round(VD_AB.imag,2)*1J\n",
+ "print \"V.D. from sending end to mid point =\" ,VD_AB,\"Volt\"\n",
+ "print \"V.D. from mid point to the far end =\",VD_BC,\"Volt\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "V.D. from sending end to mid point = (7.47+2.78j) Volt\n",
+ "V.D. from mid point to the far end = (4.8+1.4j) Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.2 - page 175"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from sympy import symbols\n",
+ "#Given data : \n",
+ "l=500 #in meter\n",
+ "i=1 #in Ampere/meter\n",
+ "IL1=200;IL2=150;IL3=50;IL4=100 #in Ampere\n",
+ "l1=100;l2=200;l3=300;l4=400 #in meter\n",
+ "r=0.1 #in ohm/km\n",
+ "Vd=250 #in volt\n",
+ "I=symbols('I')\n",
+ "Drop_AC=100*(r/10**3)*(I-i*l1/2) \n",
+ "Drop_CD=I \n",
+ "Drop_DE=100*r*(I-550)-I*100/2 \n",
+ "Drop_EF=100*r*(I-700-I*100/2) \n",
+ "Drop_FB=100*r*(I-900-I*100/2) \n",
+ "VD_tot=0.05*I-27 #in volts\n",
+ "#both ends are fed with same voltage,\n",
+ "#VD_tot should be equal to zero.\"\n",
+ "I=27/0.05 #in Ampere\n",
+ "print \"Curent = %0.2f Ampere\" %I\n",
+ "Drop_AD=(0.01*I-0.5)+(0.01*I-3.5) \n",
+ "print \"Value at minimum potential at D = %0.2f V\" %(Vd-Drop_AD)\n",
+ "#Note : Ans in the book is wrong as 27/0.05 gives 540 instead of 54."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Curent = 540.00 Ampere\n",
+ "Value at minimum potential at D = 243.20 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.3 - page 176"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "l=250 #in meter\n",
+ "VA=230 #in volt\n",
+ "VB=232 #in volt\n",
+ "r=0.5 #in ohm/km\n",
+ "r=0.5/10**3 #in ohm/m\n",
+ "RAC=r*50*2 #in ohm\n",
+ "RCD=RAC;RDE=RAC;REF=RAC;RFB=RAC #in ohm\n",
+ "#VA-VB=VAC+VCD+VDE+VEF+VFB #in volt\n",
+ "Ia=(VA-VB+15)/(5*RAC) #Ampere\n",
+ "IAC=Ia;ICD=IAC-20;IDE=IAC-60;IED=-IDE;IEF=IAC-100;IFE=-IEF;IFB=IAC-120;IBF=-IFB #in Ampere\n",
+ "print \"IAC = %0.f A\" %IAC\n",
+ "print \"ICD = %0.f A\" %ICD\n",
+ "print \"IDE = %0.f A\" %IDE\n",
+ "print \"IED = %0.f A\" %IED\n",
+ "print \"IEF = %0.f A\" %IEF\n",
+ "print \"IFE = %0.f A\" %IFE\n",
+ "print \"IFB = %0.f A\" %IFB\n",
+ "print \"IBF = %0.f A\" %IBF\n",
+ "VAC=IAC*RAC #in volt\n",
+ "VCD=ICD*RCD #in volt\n",
+ "VD=VA-VAC-VCD #in volt\n",
+ "print \"The minimum potential = %0.1f Volt\" %(VD)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "IAC = 52 A\n",
+ "ICD = 32 A\n",
+ "IDE = -8 A\n",
+ "IED = 8 A\n",
+ "IEF = -48 A\n",
+ "IFE = 48 A\n",
+ "IFB = -68 A\n",
+ "IBF = 68 A\n",
+ "The minimum potential = 225.8 Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.4 - page 177"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "VA=235 #in volt\n",
+ "VB=236 #in volt\n",
+ "l=200 #in meter\n",
+ "IL1=20;IL2=40;IL3=25;IL4=30 #in Ampere\n",
+ "l1=50;l2=75;l3=100;l4=50 #in meter\n",
+ "r=0.4 #in ohm/km\n",
+ "r=0.4/10**3 #in ohm/m\n",
+ "RAC=r*l1*2 #in ohm\n",
+ "RCD=r*(l2-l1)*2*RAC;RDE=r*(l2-l1)*2*RAC;REF=r*l1*2*RAC;RFB=r*l1*2*RAC #in ohm\n",
+ "#VA-VB=VAC+VCD+VDE+VEF+VFB #in volt\n",
+ "IA=(VA-VB+9.6)/(0.16) #in Ampere\n",
+ "IAC=IA;ICD=IA-IL1;IDE=IA-IL1-IL2;IEF=IA-IL1-IL2-IL3;IFB=IA-IL1-IL2-IL3-IL4 #in Ampere\n",
+ "print \"IAC = %0.2f A\" %IAC\n",
+ "print \"ICD = %0.2f A\" %ICD\n",
+ "print \"IED = %0.2f A\" %(-IDE)\n",
+ "print \"IFE = %0.2f A\" %-IEF\n",
+ "print \"IFB = %0.2f A\" %-IFB\n",
+ "VAC=IAC*RAC #in volt\n",
+ "VCD=ICD*RCD #in volt\n",
+ "VD=VA-VAC-VCD #in volt\n",
+ "print \"The minimum potential = %0.3f Volt\" %VD\n",
+ "# Answer wrong in the textbook due to accuracy."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "IAC = 53.75 A\n",
+ "ICD = 33.75 A\n",
+ "IED = 6.25 A\n",
+ "IFE = 31.25 A\n",
+ "IFB = 61.25 A\n",
+ "The minimum potential = 232.823 Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.5 - page 179"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "VA=400 #in volt\n",
+ "r=0.03 #in ohm/km\n",
+ "r=0.03/1000 #in ohm/m\n",
+ "RAB=r*500*2 #in ohm\n",
+ "RBC=r*300*2 #in ohm\n",
+ "RAB=r*700*2 #in ohm\n",
+ "RAB=r*500*2 #in ohm\n",
+ "#VA-VB=VAC+VCD+VDE+VEF+VFB #in volt\n",
+ "IA=(17.4)/(0.09) #in Ampere\n",
+ "VAB=(RAB)*IA #in volt\n",
+ "VB=VA-VAB #in volt\n",
+ "print \"Voltage at B = %0.2f Volts\" %VB\n",
+ "VBC=(RBC)*(IA-150) #in volt\n",
+ "VC=VB-VBC #in volt\n",
+ "print \"Voltage at C = %0.2f Volts\" %VC\n",
+ "IBC=IA-150 #in A\n",
+ "print \"Current in section BC = %0.2f A \"%IBC \n",
+ "#Note : Answer of VB is wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage at B = 394.20 Volts\n",
+ "Voltage at C = 393.42 Volts\n",
+ "Current in section BC = 43.33 A \n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.6 - page 180"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#Given data : \n",
+ "VA=240 #in volt\n",
+ "MAxVDrop=VA*5/100 #in volt\n",
+ "rho=2.87*10**-6 #in ohm-cm \n",
+ "#VAB+VBC+VCA=0 #in volt\n",
+ "IA=(3200)/(26) #in Ampere\n",
+ "IAB=IA #in Ampere\n",
+ "IBC=IA-100 #in Ampere\n",
+ "#Allowed voltage drop: IAB*RAB+IBC*RBC=12\n",
+ "R=12/(1015.26) #in ohm\n",
+ "RAB=R*300*2/100 #in ohm\n",
+ "RBC=R*600*2/100 #in ohm\n",
+ "RCA=R*400*2/100 #in ohm\n",
+ "#formula : R=rho*l/a\n",
+ "a=rho*(100*100)/R #in cm**2\n",
+ "print \"Cross section area = %0.2f cm2 \" %a"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Cross section area = 2.43 cm2 \n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.7 - page 182"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt\n",
+ "#Given data : \n",
+ "R=0.2 #in ohm/km\n",
+ "X=0.1 #in ohm/km\n",
+ "ZAM=((R+X*1J)/1000)*200 #in ohm\n",
+ "ZMB=((R+X*1J)/1000)*100 #in ohm\n",
+ "I1=100*(0.707-0.707*1J) #in A\n",
+ "I2=200*(0.8-0.6*1J) #in A\n",
+ "IAM=I1+I2 #in Ampere\n",
+ "VAM=ZAM*IAM #in volts\n",
+ "VMB=ZMB*I2 #in volts\n",
+ "VAB=VAM+VMB #in volts\n",
+ "magVAB=sqrt(VAB.real**2+VAB.imag**2) \n",
+ "print \"Total voltage drop = %0.2f Volts\" %magVAB"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Total voltage drop = 17.85 Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.8 - page 183"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "from numpy import sqrt, sin, pi, arctan, arccos, cos\n",
+ "import cmath\n",
+ "#Given data : \n",
+ "VB=200 #in volts\n",
+ "R=0.2 #in ohm/km\n",
+ "X=0.3 #in ohm/km\n",
+ "I=100 #in Ampere\n",
+ "ZAB=(R+X*1J) #in ohm\n",
+ "ZMB=ZAB/2 #in ohm\n",
+ "ZAM=ZMB #in ohm\n",
+ "cosfi_1=0.6 #unitless\n",
+ "cosfi_2=0.8 #unitless\n",
+ "IMB=I*(cosfi_2-cosfi_1*1J) #in A\n",
+ "I2=IMB #in Ampere\n",
+ "VMB=IMB*ZMB #in volts\n",
+ "VM=VB+VMB #in volts\n",
+ "print \"Voltage at M = %.2f\u2220%.2f\u00b0\" %(abs(VM),cmath.phase(VM)*180/pi)\n",
+ "#print('Sending end voltage , V_S = %.2f\u2220%.2f\u00b0 kV/phase' %(abs(V_S*10**-3),cmath.phase(V_S)*180/math.pi))\n",
+ "fi=arctan(VM.imag/VM.real)*180/pi #in degree\n",
+ "fi_1=arccos(cosfi_1)*180/pi #in degree\n",
+ "fi_VBandI1=fi_1-fi #in degree\n",
+ "I1=I*(cos(fi_VBandI1*pi/180)-sin(fi_VBandI1*pi/180))*1J #in Ampere\n",
+ "IAM=I1+I2 #inA Ampere\n",
+ "VAM=ZAM*IAM #in volts\n",
+ "VA=VM+VAM #in volts\n",
+ "magVA=sqrt(VA.real**2+VA.imag**2) \n",
+ "print \"Voltage at A, standing end voltage = %0.2f Volts\" %magVA\n",
+ "#Answer wrong in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage at M = 217.08\u22201.58\u00b0\n",
+ "Voltage at A, standing end voltage = 236.65 Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 63
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.9 - page 184"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "l=500 #in meter\n",
+ "VA=200 #in volt\n",
+ "MAxVDrop=6 #in % of declared voltage \n",
+ "rho=0.014 #in ohm/m \n",
+ "#VD in the distributor=53*10**3*r\n",
+ "AllowedVD=VA*(6/100) #in volts\n",
+ "r=AllowedVD*10**6/(53*10**3) #in ohm/meter\n",
+ "#formula : R=rho*l/a\n",
+ "a=rho*(2*l)/r #in m**2\n",
+ "print \"Cross section area = %0.2f m2 \" %(a)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Cross section area = 0.06 m2 \n"
+ ]
+ }
+ ],
+ "prompt_number": 64
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.10 - page 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "l=300 #in meter\n",
+ "I=0.75 #in A/m\n",
+ "R=0.00018 #in ohm/m\n",
+ "x=200 #in meter\n",
+ "Vs=250 #in volt\n",
+ "VD=I*R*(l*x-x**2/2) #in volt\n",
+ "V_A=Vs-VD #in volt(Voltage at 200m from end A)\n",
+ "print \"Voltage as 200m from supply end A = %0.1f Volts\" %V_A"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage as 200m from supply end A = 244.6 Volts\n"
+ ]
+ }
+ ],
+ "prompt_number": 66
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.11 - page 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "l=600 #in meter\n",
+ "VA=440 #in volt\n",
+ "VB=400 #in volt\n",
+ "R=0.01 #in ohm/100m\n",
+ "RAC=(R/100)*300 #in ohm\n",
+ "RCD=(R/100)*300 #in ohm\n",
+ "RDE=(R/100)*100 #in ohm\n",
+ "REF=(R/100)*200 #in ohm\n",
+ "RFB=(R/100)*300 #in ohm\n",
+ "#VA-VB=VAC+VCD+VDE+VEF+VFB #in volt\n",
+ "IA=(VA-VB+42.5)/(0.12) #in Ampere\n",
+ "IAC=IA;ICD=IA-100;IDE=IA-300;IFE=IA-550;IFB=IA-850 #in Ampere\n",
+ "print \"Current fed at A, IA = %0.1f A \"%IAC \n",
+ "print \"Current fed at B, IB = %0.1f A \"%-IFB"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current fed at A, IA = 687.5 A \n",
+ "Current fed at B, IB = 162.5 A \n"
+ ]
+ }
+ ],
+ "prompt_number": 69
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.12 - page 187"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "VA=220 #in volt\n",
+ "VB=200 #in volt\n",
+ "R=0.1 #in ohm/km\n",
+ "I=1 #in A/m\n",
+ "l=500 #in meter\n",
+ "R=2*R/1000 #in ohm/m\n",
+ "x=(VA-VB)/(I*R*l)+l/2 #in meter\n",
+ "Vmin=VA-I*R*x**2/2 #in volts\n",
+ "print \"Value of minimum potential = %0.2f V \"%Vmin \n",
+ "IA=I*x #in A\n",
+ "print \"Current supplied from end A = %0.f A \" %IA \n",
+ "IB=I*(l-x) #in A\n",
+ "print \"Current supplied from end B = %0.f A\"%IB"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of minimum potential = 199.75 V \n",
+ "Current supplied from end A = 450 A \n",
+ "Current supplied from end B = 50 A\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.13 - page 187"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "VL=240 #in volt\n",
+ "Router=0.2 #in ohm\n",
+ "I1=VL/5 #in Ampere\n",
+ "I2=VL/6 #in Ampere\n",
+ "Ineutral=I1-I2 #in Ampere\n",
+ "#Applying KVL on +ve side\n",
+ "V1=VL+I1*0.2+8*0.4 #in volt\n",
+ "print \"Voltage at +ve side = %0.1f V\" %V1\n",
+ "#Applying KVL on +ve side\n",
+ "V2=VL-(8*0.4)+I2*0.2 #in volt\n",
+ "print \"Voltage at -ve side = %0.1f V\" %V2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage at +ve side = 252.8 V\n",
+ "Voltage at -ve side = 244.8 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.14 - page 188"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "#Applying KVL on +ve side\n",
+ "V1=200-(600*0.015)-(100)*0.03 #in volt\n",
+ "print \"Voltage at +ve side = %0.f V\" %V1\n",
+ "#Applying KVL on -ve side\n",
+ "V2=200-(-100*0.03)-500*0.0015 #in volt\n",
+ "print \"Voltage at -ve side = %0.1f V\" %V2\n",
+ "#Note : answer of 2nd part is wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage at +ve side = 188 V\n",
+ "Voltage at -ve side = 202.2 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.15 - page 189"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import symbols\n",
+ "x=symbols('x')\n",
+ "#Given data : \n",
+ "#VD in section AC from RHS: \n",
+ "VD1=(40+x)*0.02+0.17*x\n",
+ "#VD in section AC from LHS: \n",
+ "VD2=(350-x)*0.015+(150-x)*0.03\n",
+ "#Equating two VDs we get\n",
+ "#x*0.02+0.17*x+0.015*x+x*0.03=350*0.015+150*0.03-40*0.02\n",
+ "x=(350*0.015+150*0.03-40*0.02)/0.082 #in A\n",
+ "VB=500-(x+40)*0.02 #in volts\n",
+ "print \"Potential at point B = %0.2f V\" %VB\n",
+ "VC=VB-(x*0.017) #in volts\n",
+ "print \"Potential at point C = %0.2f V\" %VC\n",
+ "VD=500-(350-x)*0.015 #in volts\n",
+ "print \"Potential at point D = %0.2f V\" %VD\n",
+ "#Note : Answer of 3rd part is given wrong in the book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Potential at point B = 497.02 V\n",
+ "Potential at point C = 495.16 V\n",
+ "Potential at point D = 496.39 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.16 - page 190"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from sympy import symbols\n",
+ "x=symbols('x')\n",
+ "#Given data : \n",
+ "#Applying KVL in loop AFEDA: \n",
+ "p1=((0.016*x)+0.09*(x-30)+0.14*(x-17)-0.1*y) #eqn(1) \n",
+ "#Applying KVL in loop ADCBA: \n",
+ "p2=(0.1*y-0.12*(95-x-y)-.01*(145-x-y)-0.008*(165-x-y)) #eqn(2)\n",
+ "#Equating two equtions we get\n",
+ "#3.9*x-125=97.75-0.75*x\n",
+ "x=(97.75+125)/(3.9+0.75) #in A\n",
+ "y=97.75-0.75*x #in A\n",
+ "print \"x = %0.f A\" %x \n",
+ "print \"y = %0.2f A\"%y \n",
+ "print \"Point of minimum ppotential is E.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x = 48 A\n",
+ "y = 61.82 A\n",
+ "Point of minimum ppotential is E.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.17 - page 190"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "V=200 #in volt\n",
+ "I=1 #in A/m\n",
+ "R=2*0.05/1000 #in ohm/m\n",
+ "l=1*1000 #in meter\n",
+ "IT=I*l #in Ampere\n",
+ "RT=R*l #in ohm\n",
+ "VD=IT*RT/8 #in volt\n",
+ "Vmin=V-VD #in volt\n",
+ "print \"Minimum potential occurs at mid point. It is %0.2f V\" %Vmin"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Minimum potential occurs at mid point. It is 187.50 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Problem 7.19 - page 191"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given data : \n",
+ "VB=400 #in volt\n",
+ "ZAC=0.04+0.08*1J #in ohm\n",
+ "ZCB=0.08+1J*0.12 #in ohm\n",
+ "I1=60*(0.8-1J*0.6) \n",
+ "I2=120*(0.8-1J*0.6) \n",
+ "VCB=I2*ZCB #in Volt\n",
+ "VAC=(I1+I2)*ZAC #in volt\n",
+ "VC=VB+I2*ZCB #in Volt\n",
+ "print \"Voltage at C =\",VC,\"Volt\"\n",
+ "VA=VC+(I1+I2)*ZAC #in volt\n",
+ "print \"Voltage at A =\",VA,\"Volt\"\n",
+ "#Answer not accurate in the textbook."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Voltage at C = (416.32+5.76j) Volt\n",
+ "Voltage at A = (430.72+12.96j) Volt\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/sample_notebooks/KavinkumarD/Chapter_8_FREQUENCY_EFFECTS_IN_AMPLIFIERS.ipynb b/sample_notebooks/KavinkumarD/Chapter_8_FREQUENCY_EFFECTS_IN_AMPLIFIERS.ipynb
new file mode 100755
index 00000000..60448e3c
--- /dev/null
+++ b/sample_notebooks/KavinkumarD/Chapter_8_FREQUENCY_EFFECTS_IN_AMPLIFIERS.ipynb
@@ -0,0 +1,120 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8ef023228932ba7c44f0f72b79793f31a32f8ea67eae875510cf71ee015fc22c"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 8 FREQUENCY EFFECTS IN AMPLIFIERS"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.6 , Page no:242"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "hie=1000 #\u2126\n",
+ "hfe=75 #\u2126\n",
+ "Av=50\n",
+ "Rl=10000 #k\u2126\n",
+ "hie2=300 #\u2126\n",
+ "hfe2=100 #\u2126\n",
+ "Re=1000 #k\u2126\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "Req=Av*(hie/hfe) #\u2126\n",
+ "Rc=Req*Rl/(Rl-Req) #k\u2126\n",
+ "wL=2*3.14*200\n",
+ "Ce=(hie2+(hfe2+1)*Re)/(wL*Re*hie2)*10**6\n",
+ "Av1=(hfe*Req)/(hie+(hfe+1)*Re)\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"The value of Req=\",round(Req,3),\"Ohm\";\n",
+ "print\"The value of Rc=\",round(Rc,3),\"Ohm\";\n",
+ "print\"The value of Ce=\",round(Ce,3),\"mF\";\n",
+ "print\"The value of Av=\",round(Av1,3);"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of Req= 666.667 Ohm\n",
+ "The value of Rc= 714.286 Ohm\n",
+ "The value of Ce= 268.843 mF\n",
+ "The value of Av= 0.649\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.8 , Page no:244"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#initialisation of variables\n",
+ "hie2=1500 #\u2126\n",
+ "Rb2=5000 #k\u2126\n",
+ "Z01=10\n",
+ "Av=7881.3\n",
+ "\n",
+ "#CALCULATIONS\n",
+ "C2=1*10**-6 \n",
+ "Zin2=(hie2*Rb2/(hie2+Rb2))\n",
+ "fl=1/(2*3.14*C2*(Zin2+Z01*10**3))\n",
+ "\n",
+ "#RESULTS\n",
+ "print\"The value of Zin2=\",round(Zin2,3),\"Ohm\";\n",
+ "print\"The value of fl=\",round(fl,3),\"Hz\";"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of Zin2= 1153.846 Ohm\n",
+ "The value of fl= 14.276 Hz\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/LalitKumar/chapter2.ipynb b/sample_notebooks/LalitKumar/chapter2.ipynb
new file mode 100755
index 00000000..57657aa7
--- /dev/null
+++ b/sample_notebooks/LalitKumar/chapter2.ipynb
@@ -0,0 +1,347 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter2 : Atomic model & bonding in solids"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example-2.1, page no-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "#given\n",
+ "#atomic no. of gold\n",
+ "Z=79\n",
+ "#kinetic energy of alpha particle\n",
+ "E=7.68*1.6*(10)**(-13) #J because [1MeV=1.6*(10)**(-13)]\n",
+ "e=1.6*10**(-19) #C\n",
+ "E0=8.854*10**(-12) #F/m\n",
+ "#the distance of closest approach is given by:\n",
+ "d0=2*e*Z*e/(4*(math.pi)*E0*E) #m\n",
+ "print \"The closest approach of alpha particle is %.2ef m\" %d0"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The closest approach of alpha particle is 2.96e-14f m\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example-2.2, page no-29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from math import *\n",
+ "from numpy import *\n",
+ "#given\n",
+ "#IN THE RUTHERFORD SCATTERING EXPERIMENT\n",
+ "#the no of particles scattered at\n",
+ "theta1=(pi)/2 #radians\n",
+ "#is\n",
+ "N90=44 #per minute\n",
+ "#the number of particles scattered particales N is given by\n",
+ "#N=C*(1/(sin(theta/2))**4) where C is propotionality constant\n",
+ "#solving above equation for C\n",
+ "C=N90*(sin(theta1/2))**4 \n",
+ "# now to find the no of particles scatering at 75 and 135 degrees\n",
+ "theta2=75*(pi)/180 #radians\n",
+ "N75=C*(1/(sin(theta2/2))**4) #per minute\n",
+ "theta3=135*(pi)/180 #radians\n",
+ "N135=C*(1/(sin(theta3/2))**4) #per minute\n",
+ "print \"The no of particles scattered at 75 and 135 degrees are %d per minute and %d per minutes\" %(N75,N135)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The no of particles scattered at 75 and 135 degrees are 80 per minute and 15 per minutes\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example-2.3, page no-32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "#mass of electron\n",
+ "m=9.11*10**(-31) #kg\n",
+ "#charge on an electron\n",
+ "e=1.6*10**(-19) #C\n",
+ "#plank's constant\n",
+ "h=6.62*10**(-34)\n",
+ "E0=8.85*10**(-12) \n",
+ "#NO OF ELECTRONS SHELLS IN HYDROZEN ATOm\n",
+ "n=1\n",
+ "#atomic number of hydrogen\n",
+ "Z=1\n",
+ "#radius of first orbit of hydrogen is given by\n",
+ "r1=n**2*E0*h**2/((pi)*m*Z*e**2) #m\n",
+ "print \"The radius of the first orbit of the electron in the hydrogen atom %.2e\"%(r1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The radius of the first orbit of the electron in the hydrogen atom 5.29e-11\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example-2.4, page no-32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "#mass of electron\n",
+ "m=9.11*10**(-31) #kg\n",
+ "#charge on an electron\n",
+ "e=1.6*10**(-19) #C\n",
+ "#plank's constant\n",
+ "h=6.62*10**(-34)\n",
+ "E0=8.85*10**(-12) \n",
+ "#NO OF ELECTRONS SHELLS IN HYDROZEN ATOm\n",
+ "n=1\n",
+ "#atomic number of hydrogen\n",
+ "Z=1\n",
+ "#ionization potential energy of hydrogen atom is given by\n",
+ "E=m*Z**2*e**4/(8*(E0)**2*h**2*n**2) #J\n",
+ "#energy in eV\n",
+ "EV=E/e #eV\n",
+ "print \"The ionization potential for hydrogen atom is %0.2f V\" %(EV)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The ionization potential for hydrogen atom is 13.59 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example-2.5, page no-34"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example-2.6, page no-36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "#uncertainity in the momentum\n",
+ "deltap=10**-27 #kg ms**-1\n",
+ "#according to uncertainity principle\n",
+ "#deltap* deltax >=h/(2*(pi))\n",
+ "#we know that \n",
+ "h=6.626*10**-34 #Js\n",
+ "#here instead of inequality we are using only equality just for notation otherwise it is greater than equal to as mentioned above\n",
+ "#now deltax is given by\n",
+ "deltax=h/(2*(pi)*deltap) #m\n",
+ "print \"The minimum uncertainity is %.2e m\"%(deltax)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The minimum uncertainity is 1.05e-07 m\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example-2.10, page no- 57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "#ionization potential of hydrogen\n",
+ "E1=13.6 #eV\n",
+ "#when \n",
+ "n=3\n",
+ "E3=-E1/n**2 #eV\n",
+ "#when \n",
+ "n=5\n",
+ "E5=-E1/n**2 #eV\n",
+ "print \"Energy of 3rd and 5th orbits are %0.2f eV and %0.2f eV\"%(E3,E5)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Energy of 3rd and 5th orbits are -1.51 eV and -0.54 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example-2.11, page no-59"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "#dipole moment og HF is\n",
+ "DM=6.375*10**(-30) #Cm\n",
+ "#intermolecular distance\n",
+ "r=0.9178*10**(-10) #m\n",
+ "#charge on an electron\n",
+ "e=1.67*10**(-19) #C\n",
+ "#since the HF posses ionic characters\n",
+ "#so\n",
+ "#Hf in fully ionic state has dipole moment as\n",
+ "DM2=r*e #Cm\n",
+ "#percentage ionic characters\n",
+ "percentage=DM/DM2*100 #%\n",
+ "print \"The percentage ionic character is %0.2f approx.\"%(percentage)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The percentage ionic character is 41.59 approx.\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "example-2.12, page no-60"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "#elctronegativity of In\n",
+ "EnIn=1.5\n",
+ "#elctronegativity of As\n",
+ "EnAs=2.2\n",
+ "#elctronegativity of Ga\n",
+ "EnGa=1.8\n",
+ "#for InAs\n",
+ "ionic_charater1=(1-exp((-0.25)*(EnAs-EnIn)**2))*100 #in %\n",
+ "#for GaAs\n",
+ "ionic_charater2=(1-exp((-0.25)*(EnAs-EnGa)**2))*100 # in %\n",
+ "print \"Ionic character in InAs and GaAs are %0.1f %% and %0.1f %%\"%(ionic_charater1,ionic_charater2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Ionic character in InAs and GaAs are 11.5 % and 3.9 %\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/sample_notebooks/MohdGufran/Chapter6.ipynb b/sample_notebooks/MohdGufran/Chapter6.ipynb
new file mode 100755
index 00000000..ea85357e
--- /dev/null
+++ b/sample_notebooks/MohdGufran/Chapter6.ipynb
@@ -0,0 +1,506 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Bipolar junction Transistors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.1 page No.215"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "Ic=9.95\t\t\t#in mA\n",
+ "Ie=10 \t\t#in mA\n",
+ "\n",
+ "Ib=Ie-Ic\t\t#in mA\n",
+ "\n",
+ "print\"Emitter current is \",Ib,\"mA\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter current is 0.05 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.2 page No. 216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "IC=0.98\t\t\t#in mA\n",
+ "IB=20.0\t\t\t#in uA\n",
+ "IB=IB*10**-3\t\t#in mA\n",
+ "\n",
+ "IE=IB+IC\t\t#in mA\n",
+ "\n",
+ "alpha=IC/IE\t\t#unitless\n",
+ "Beta=IC/IB\t\t#unitless\n",
+ "\n",
+ "print\"Emitter current is\",IE,\"mA\"\n",
+ "print\"Current amplification factor is \",alpha\n",
+ "print\"Current gain factor is \",Beta"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter current is 1.0 mA\n",
+ "Current amplification factor is 0.98\n",
+ "Current gain factor is 49.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.3 page No.216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "alfaDC=0.98\t\t\t#unitless\n",
+ "ICBO=4\t\t\t\t#in uA\n",
+ "ICBO=ICBO*10**-3\t\t#in mA\n",
+ "IB=50\t\t\t\t#in uA\n",
+ "IB=IB*10**-3\t\t\t#in mA\n",
+ "\n",
+ "IC=alfaDC*IB/(1-alfaDC)+ICBO/(1-alfaDC)\t#in mA\n",
+ "IE=IC+IB\t\t\t#in mA\n",
+ "\n",
+ "print\"Emitter current is \",IE,\"mA\"\n",
+ "print\"Collector current is \",IC,\"mA\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Emitter current is 2.7 mA\n",
+ "Collector current is 2.65 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.4 page No. 216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "IB=10\t\t\t#in uA\n",
+ "IB=IB*10**-3\t\t#in mA\n",
+ "Beta=99\t\t\t#Unitless\n",
+ "ICO=1\t\t\t#in uA\n",
+ "ICO=ICO*10**-3\t\t#in mA\n",
+ "\n",
+ "IC=Beta*IB+(1+Beta)*ICO\t#in mA\n",
+ "\n",
+ "print\"Collector current in mA : \",IC,\"mA\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current in mA : 1.09 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.5 Page No.216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "Ic=5*10**-3 #mA collector current\n",
+ "Ic_=10*10**-3 #mA collector current\n",
+ "Ib=50*10**-6 #mA, Base current\n",
+ "Icbo=1*10**-6 #micro A, Current to base open current\n",
+ "\n",
+ "beta=(Ic-Icbo)/(Ib+Icbo)\n",
+ "alpha=(beta/(1+beta))\n",
+ "Ie=Ib+Ic\n",
+ "\n",
+ "Ib=(Ic_-(beta+1)*Icbo)/(beta)\n",
+ "\n",
+ "print\"(i) Current gain factor is\",round(beta,0)\n",
+ "print\" Current amplification factor is\",round(alpha,2)\n",
+ "print\" Emitter Current is\",Ie*1000,\"mA\"\n",
+ "print\"(ii)New level of Ib is\",round(Ib*10**6,0),\"micro A\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(i) Current gain factor is 98.0\n",
+ " Current amplification factor is 0.99\n",
+ " Emitter Current is 5.05 mA\n",
+ "(ii)New level of Ib is 101.0 micro A\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.6 page No. 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "delVEB=200\t\t\t#in Volts\n",
+ "delIE=5\t\t\t\t#in mA\n",
+ "\n",
+ "rin=delVEB/delIE\t\t#in ohm\n",
+ "\n",
+ "print\"Dynamic input resistance is \",rin,\"mohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dynamic input resistance is 40 mohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.7 page No. 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\n",
+ "ICBO=12.5 \t\t\t#in uA\n",
+ "ICBO=ICBO*10**-3 \t\t#in mA\n",
+ "IE=2 \t\t\t\t#in mA\n",
+ "IC=1.97 \t\t\t#in mA\n",
+ "\n",
+ "alfa=(IC-ICBO)/IE \t\t#unitless\n",
+ "IB=IE-IC \t\t\t#in mA\n",
+ "\n",
+ "print\"Current gain : \",round(alfa,3)\n",
+ "print\"Base current is \",IB,\"mA\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Current gain : 0.979\n",
+ "Base current is 0.03 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.8 page No. 222"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "RL=4.0 \t\t\t#in Kohm\n",
+ "VL=3.0\t\t\t#in volt\n",
+ "alfa=0.96 \t\t#unitless\n",
+ "IC=VL/RL \t\t#in mA\n",
+ "\n",
+ "IE=IC/alfa \t\t#in mA\n",
+ "IB=IE-IC \t\t#in mA\n",
+ "\n",
+ "print\"Base current ia\",round(IB,2),\"mA\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Base current ia 0.03 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.9 page No.227"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "VCC=10\t\t\t #in volt\n",
+ "RL=800\t\t\t #in ohm\n",
+ "VL=0.8\t\t\t #in volt\n",
+ "alfa=0.96\t\t #unitless\n",
+ "\n",
+ "VCE=VCC-VL \t\t#in Volt\n",
+ "IC=VL*1000/RL \t\t#in mA\n",
+ "Beta=alfa/(1-alfa) \t#unitless\n",
+ "IB=IC/Beta \t\t#in mA\n",
+ "\n",
+ "print\"Collector-emitter Voltage is \",VCE,\"V\"\n",
+ "print\"Base current in uA : \",round(IB*1000,2),\"microA\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector-emitter Voltage is 9.2 V\n",
+ "Base current in uA : 41.67 microA\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.10 page No. 227"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "alfao=0.98 \t\t#unitless\n",
+ "ICO=10 \t\t\t#in uA\n",
+ "ICO=ICO*10**-3 \t\t#in mA\n",
+ "IB=0.22 \t\t#in mA\n",
+ "\n",
+ "IC=(alfao*IB+ICO)/(1-alfao) \t#in mA\n",
+ "\n",
+ "print\"Collector current is\",IC,\"mA\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Collector current is 11.28 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 45
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.11 page No. 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "delVEB=250 \t\t#in mVolts\n",
+ "delIE=1 \t\t#in mA\n",
+ "\n",
+ "rin=delVEB/delIE \t#in ohm\n",
+ "\n",
+ "print\"Dynamic input resistance is\",rin,\"ohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dynamic input resistance is 250 ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.12 page No. 228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "delVCE=10-5 \t\t#in Volts\n",
+ "delIC=5.8-5\t \t#in mA\n",
+ "\n",
+ "rin=delVCE/delIC \t#in Kohm\n",
+ "\n",
+ "print\"Dynamic output resistance is \",rin,\"kohm\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dynamic output resistance is 6.25 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 6.16 page No. 233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "Beta=45 \t\t\t#Unitless\n",
+ "VBE=0.7 \t\t\t#in Volt\n",
+ "VCC=0 \t\t\t\t#in Volt\n",
+ "RB=10**5 \t\t\t#in ohm\n",
+ "RC=1.2*10**3 \t\t\t#in ohm\n",
+ "VEE=-9 \t\t\t\t#in Volt\n",
+ "\n",
+ "IB=-(VBE+VEE)/RB \t\t#in mA\n",
+ "IC=Beta*IB \t\t\t#in mA\n",
+ "VC=VCC-IC*RC \t\t\t#in Volts\n",
+ "VB=VBE+VEE \t\t\t#in Volts\n",
+ "\n",
+ "print\"collector voltage is \",round(VC,1),\"V\"\n",
+ "print\"Base voltage is \",VB,\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "collector voltage is -4.5 V\n",
+ "Base voltage is -8.3 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 60
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/MukteshChaudhary/ch2.ipynb b/sample_notebooks/MukteshChaudhary/ch2.ipynb
new file mode 100755
index 00000000..ebb803c6
--- /dev/null
+++ b/sample_notebooks/MukteshChaudhary/ch2.ipynb
@@ -0,0 +1,150 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:8575441dfc9f46104394a83a9c4613d36928a495b4284fab191e2ca7cb407033"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2: Introduction to Quantum Mechanics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.1, Page 47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "lamda=0.708*10**-8# cm\n",
+ "h=6.625*10**-34# J*s Plank's constant\n",
+ "c=3.0*10**10# cm/s\n",
+ "e=1.6*10**-19# eV\n",
+ "\n",
+ "#Calculations&Results\n",
+ "E=(h*c)/lamda# E=hv=hc/lamda\n",
+ "print \"The value of E is %.2e J\"%E\n",
+ "E=E/e\n",
+ "print \"The value of E is %.2e eV\"%E"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of E is 2.81e-15 J\n",
+ "The value of E is 1.75e+04 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2,Page 49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "m=9.11*10**-31# kg*m/s\n",
+ "v=10**5#m/s\n",
+ "h=6.625*10**-34#js\n",
+ "\n",
+ "#Calculations&Results\n",
+ "p=m*v\n",
+ "print \"momentum is %.2e\"%p\n",
+ "lamda=h/p\n",
+ "print \"de broglie wavelength in meter is %.2e\"%(lamda)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "momentum is 9.11e-26\n",
+ "de broglie wavelength in meter is 7.27e-09\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3, Page 58"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "\n",
+ "#Variable declaration\n",
+ "a=5*10**-10# a=5A = 5*10**-8cm\n",
+ "h=1.054*10**-34# J*s Planck's constant \n",
+ "m=9.11*10**-31# kg*m/s\n",
+ "e=1.6*10**-19# eV\n",
+ "\n",
+ "#Calculations&Results\n",
+ "print \"The energy levels are:\"\n",
+ "for n in range(1,4):\n",
+ " En=((h**2*n**2*math.pi**2)/(2*m*a**2))/e\n",
+ " print \"For n = %d, E = %.2f eV\"%(n,En)\n",
+ "\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The energy levels are:\n",
+ "For n = 1, E = 1.50 eV\n",
+ "For n = 2, E = 6.02 eV\n",
+ "For n = 3, E = 13.54 eV\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/NirenNegandhi/ch9.ipynb b/sample_notebooks/NirenNegandhi/ch9.ipynb
new file mode 100755
index 00000000..61fe143f
--- /dev/null
+++ b/sample_notebooks/NirenNegandhi/ch9.ipynb
@@ -0,0 +1,332 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:a295b23ddf355cc98776039dc2c765e71624b4961371dafae0a82fd3d3a044d3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Control of Traction Motors"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.1, Page 268"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "V=600.;# in volts\n",
+ "I=350.;#in A\n",
+ "Ts=20.;# in sec\n",
+ "R=0.15;# in ohm\n",
+ "\n",
+ "#Calculations&Results\n",
+ "E_bse=(V/2)-(I*R);\n",
+ "E_bp=V-(I*R);\n",
+ "Tse=(E_bse/E_bp)*Ts;\n",
+ "Tp=Ts-Tse;\n",
+ "Vd=V-(2*I*R);\n",
+ "Ed1=(Vd/2)*I*(Tse/3600);\n",
+ "Ed2=((V/2)/2)*2*I*(Tp/3600);\n",
+ "El=(Ed1+Ed2)*10**-3;\n",
+ "print \"part (a)\"\n",
+ "print \"Energy lost in starting rhestat,El(kWh) = %.4f\"%El\n",
+ "El_1=(2*(I**2)*R*Ts)/(3600*1000);\n",
+ "print \"part (b)\"\n",
+ "print \"Energy lost in motors,El(kWh) = %.3f\"%El_1\n",
+ "#answer is wrong in part b in the textbook\n",
+ "Et=((V*I*Tse)+(2*V*I*Tp))/(3600*1000);\n",
+ "print \"part (c)\"\n",
+ "print \"Total Energy,Et(kWh) = %.3f\"%Et"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "Energy lost in starting rhestat,El(kWh) = 0.5372\n",
+ "part (b)\n",
+ "Energy lost in motors,El(kWh) = 0.204\n",
+ "part (c)\n",
+ "Total Energy,Et(kWh) = 1.806\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.2, Page 269"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "V=600.;# in volts\n",
+ "I=300.;#in A\n",
+ "Ts=15.;# in sec\n",
+ "R=0.1;# in ohm\n",
+ "\n",
+ "#Calculations&Results\n",
+ "E_bse=(V/2)-(I*R);\n",
+ "E_bp=V-(I*R);\n",
+ "Tse=(E_bse/E_bp)*Ts;\n",
+ "Tp=Ts-Tse;\n",
+ "Vd=V-(2*I*R);\n",
+ "Ed1=(round((Vd/2)*I*(Tse/3600))*10**-3);#\n",
+ "print \"part (i)\"\n",
+ "print \"rheostatic in series,Ed1(kWh) = %.2f\"%Ed1\n",
+ "Ed2=((V/2)/2)*2*I*(Tp/3600)*10**-3;\n",
+ "print \"rheostatic in parallel,Ed2(kWh) = %.3f\"%Ed2\n",
+ "Vm=29;# in kmph\n",
+ "alfa=Vm/Ts;\n",
+ "S=alfa*Tse;\n",
+ "print \"part (ii)\"\n",
+ "print \"Speed at the end of series period,S(km/h) = %.1f\"%S"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (i)\n",
+ "rheostatic in series,Ed1(kWh) = 0.16\n",
+ "rheostatic in parallel,Ed2(kWh) = 0.197\n",
+ "part (ii)\n",
+ "Speed at the end of series period,S(km/h) = 13.7\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.3, Page 270"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "V=600;# in volts\n",
+ "I=200;#in A\n",
+ "Ts=20;# in sec\n",
+ "R=0.1;# in ohm\n",
+ "\n",
+ "#Calculations&Results\n",
+ "E_bse=(V/2)-(I*R);\n",
+ "E_bp=V-(I*R);\n",
+ "Tse=(E_bse/E_bp)*Ts;\n",
+ "Tp=Ts-Tse;\n",
+ "Vd=V-(2*I*R);\n",
+ "Mi=((V*I*Tse)/(2*3600))+((V*I*Tp)/3600);\n",
+ "Er=((Vd/4)*I*(Tse/3600))+(((V/2)/2)*I*(Tp/3600));\n",
+ "El=(I**2*R*Ts)/(3600);\n",
+ "Mo=Mi-Er-El;\n",
+ "eta=(Mo/Mi)*100;\n",
+ "print \"part (a)\"\n",
+ "print \"Starting efficiency = %.1f%%\"%eta\n",
+ "Vm=80;# in kmph\n",
+ "alfa=Vm/Ts;\n",
+ "S=alfa*Tse;\n",
+ "print \"part (b)\"\n",
+ "print \"speed,S(kmph) = %.2f\"%S"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "Starting efficiency = 63.7%\n",
+ "part (b)\n",
+ "speed,S(kmph) = 38.62\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.4, Page 271"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "W=150;# in tonne\n",
+ "We=1.1*W;# in tonnes\n",
+ "Vm=30;#kmph\n",
+ "V=600;# in volts\n",
+ "r=10;# N/tonne\n",
+ "I=300;#in A\n",
+ "R=0.1;# in ohm\n",
+ "Ft=4*15000;# in N\n",
+ "G=1;#gradient in %\n",
+ "\n",
+ "#Calculations&Results\n",
+ "alfa=(Ft-(W*r)-(98.1*W*G))/(277.8*We);\n",
+ "Ts=Vm/alfa;\n",
+ "E_bse=(V/2)-(I*R);\n",
+ "E_bp=V-(I*R);\n",
+ "Tse=(E_bse/E_bp)*Ts;\n",
+ "print \"part (a)\"\n",
+ "print \"Duration of starting period,Ts(seconds) = %.1f\"%Ts\n",
+ "print \"Duration for Series running,Tse(seconds) = %.1f\"%Tse\n",
+ "sptr=alfa*Tse;#in kmph\n",
+ "print \"part (b)\"\n",
+ "print \"speed of train at transition in kmph is %.2f\"%sptr\n",
+ "sptr=alfa*Tse;#in kmph\n",
+ "rls=((V-(2*I*R))/2)*(2*I)*(Tse/3600);#watts hours\n",
+ "rlp=((V/2)/2)*(4*I)*((Ts-Tse)/3600);#watts hours\n",
+ "tl=rls+rlp;#\n",
+ "print \"part (c)\"\n",
+ "print \"rheostat losses during series operation is %.1f W-hours\"%rls\n",
+ "print \"rheostat losses during parallel operation is %.f W-hours\"%rlp\n",
+ "print \"total losses in W-hours is %.1f \"%tl"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "part (a)\n",
+ "Duration of starting period,Ts(seconds) = 31.4\n",
+ "Duration for Series running,Tse(seconds) = 14.9\n",
+ "part (b)\n",
+ "speed of train at transition in kmph is 14.21\n",
+ "part (c)\n",
+ "rheostat losses during series operation is 669.4 W-hours\n",
+ "rheostat losses during parallel operation is 826 W-hours\n",
+ "total losses in W-hours is 1495.9 \n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.5, Page 272"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "nf=1.; \n",
+ "n2=1.25*nf; \n",
+ "of=1; \n",
+ "of2=nf/n2; \n",
+ "isef=1; \n",
+ "ise2=0.66667; \n",
+ "\n",
+ "#Calculations\n",
+ "ia2=(1./ise2); \n",
+ "idiv=ia2-ise2; \n",
+ "rdiv=ise2/idiv; \n",
+ "\n",
+ "#Result\n",
+ "print \"diverter resistance required as percentage of the field resistance is %.f%%\"%(rdiv*100)\n",
+ "#answer is wrong in the textbook"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "diverter resistance required as percentage of the field resistance is 80%\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.6, Page 272"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Variable declaration\n",
+ "Ia=[60,80,100,120,160,180];# in amperes\n",
+ "sp1=[47.4,40.3,35.8,33.9,29.8,28.5];#in kmph\n",
+ "dpk=[440,700,970,1245,1800,2360];#in kg\n",
+ "sp2=[58.1,50,45,40.3,35,32];#\n",
+ "\n",
+ "#Calculations&Results\n",
+ "for i in range(0,6):\n",
+ " dpk1= ((dpk[i])*(sp1[i]))/(sp2[i]);#\n",
+ " print \"For current = \",Ia[i],\"A, speed is \",sp2[i],\"kmph and drawbar pull is\",round(dpk1),\"kg\"\n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "For current = 60 A, speed is 58.1 kmph and drawbar pull is 359.0 kg\n",
+ "For current = 80 A, speed is 50 kmph and drawbar pull is 564.0 kg\n",
+ "For current = 100 A, speed is 45 kmph and drawbar pull is 772.0 kg\n",
+ "For current = 120 A, speed is 40.3 kmph and drawbar pull is 1047.0 kg\n",
+ "For current = 160 A, speed is 35 kmph and drawbar pull is 1533.0 kg\n",
+ "For current = 180 A, speed is 32 kmph and drawbar pull is 2102.0 kg\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/PankajDoshi/Chapter1.ipynb b/sample_notebooks/PankajDoshi/Chapter1.ipynb
new file mode 100755
index 00000000..91492796
--- /dev/null
+++ b/sample_notebooks/PankajDoshi/Chapter1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Chapter 1", "cell_type": "markdown", "metadata": {}}, {"source": "# Special Diodes", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 1.1 Page No. 1-11", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "# Assumption\nprint(\"Assume the drop across the LED as 2 V\\n\"); \nprint(\"Therefore, VD = 2 V\\n\");\n\n# Given Data\nprint(\"From fig. 1.11, Rs = 2.2 kohm and Vs = 15 V\\n\"); \n\n# Calculation in mA\nIs =(15-2)/(2.2); \n\n# Result\nprint \"Therefore, Is(mA) = (Vs-VD/Rs) = \",round(Is,2),\"mA\"; ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Assume the drop across the LED as 2 V\n\nTherefore, VD = 2 V\n\nFrom fig. 1.11, Rs = 2.2 kohm and Vs = 15 V\n\nTherefore, Is(mA) = (Vs-VD/Rs) = 5.91 mA\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "## Example 1.2 Page No. 1-20", "cell_type": "markdown", "metadata": {}}, {"execution_count": 3, "cell_type": "code", "source": "import math\n\n# Formula\nprint(\"The transistor capacitance is given by,\"); \nprint(\"CT = C(0)/[1+|VR/VJ|^n]\\n\");\n\n# Given Data\nprint(\"Now C(0) = 80pF , n = 1/3 as diffused junction\"); \nprint(\"VR = 4.2 V, VJ = 0.7 V\\n\");\n\n# Calculation in pF\nct = round((80*pow(10,-12))/((pow((1+(4.2/0.7)),(0.3333))))*pow(10,12),2); # Note here, 1/3 = 0.3333 \n\n# Result\nprint \"Therefore, CT(pF) = \",ct,\"pF\"; \n\n# Formula\nprint(\"\\nThe transistor capacitance is also given by, \" )\nprint(\"CT = K/[VR+VJ]^n\\n\") \n\n#Calculation\nk = round((41.82*pow(10,-12))*(pow((4.2+0.7),(0.3333)))*pow(10,12),2); # Note here, 1/3 = 0.3333 \n\n# Result\nprint \"Therefore, K = \",k,\"* 10^-12\"; ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The transistor capacitance is given by,\nCT = C(0)/[1+|VR/VJ|^n]\n\nNow C(0) = 80pF , n = 1/3 as diffused junction\nVR = 4.2 V, VJ = 0.7 V\n\nTherefore, CT(pF) = 41.82 pF\n\nThe transistor capacitance is also given by, \nCT = K/[VR+VJ]^n\n\nTherefore, K = 71.03 * 10^-12\n"}], "metadata": {"scrolled": true, "collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/sample_notebooks/PankajDoshi/Chapter_1.ipynb b/sample_notebooks/PankajDoshi/Chapter_1.ipynb
new file mode 100755
index 00000000..fafb9249
--- /dev/null
+++ b/sample_notebooks/PankajDoshi/Chapter_1.ipynb
@@ -0,0 +1 @@
+{"nbformat_minor": 0, "cells": [{"source": "# Special Diodes", "cell_type": "markdown", "metadata": {}}, {"source": "# Example 1.1 Page No. 1-11", "cell_type": "markdown", "metadata": {}}, {"execution_count": 62, "cell_type": "code", "source": "# Assumution\nprint(\"Assume the drop across the LED as 2 V\\n\"); \nprint(\"Therefore, VD = 2 V\\n\");\n\n# Given Data\nprint(\"From fig. 1.11, Rs = 2.2 kohm and Vs = 15 V\\n\"); \n\n# Calculation in mA\nIs =(15 -2) /(2.2); \n\n# Result\nprint \"Therefore, Is(mA) = (Vs-VD/Rs) = \" ,round(Is,2),\"mA\"; ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Assume the drop across the LED as 2 V\n\nTherefore, VD = 2 V\n\nFrom fig. 1.11, Rs = 2.2 kohm and Vs = 15 V\n\nTherefore, Is(mA) = (Vs-VD/Rs) = 5.91 mA\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "# Example 1.2 Page No. 1-20", "cell_type": "markdown", "metadata": {}}, {"execution_count": 70, "cell_type": "code", "source": "import math\n\n# Formula\nprint(\"The transistor capacitance is given by,\"); \nprint(\"CT = C(0)/[1+jVR/VJ j^n]\\n\");\n\n# Given Data\nprint(\"Now C(0) = 80pF , n = 1/3 as diffused junction\"); \nprint(\"VR = 4.2 V, VJ = 0.7 V\\n\");\n\n# Calculation in pF\nct = round((80*pow(10,-12))/((pow((1+(4.2/0.7)),(0.3333))))*pow(10,12),2); \n\n# Result\nprint \"Therefore, CT(pF) = \", ct,\"pF\"; \n\n# Formula\nprint(\"\\nThe transistor capacitance is also given by, \" )\nprint(\"CT = K/[VR+VJ]^n\\n\") \n\n#Calculation\nk = round((41.82*pow(10,-12))*(pow((4.2+0.7),(0.3333)))*pow(10,12),2); \n\n# Result\nprint \"Therefore, K = \", k,\"* 10^-12\"; ", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The transistor capacitance is given by,\nCT = C(0)/[1+jVR/VJ j^n]\n\nNow C(0) = 80pF , n = 1/3 as diffused junction\nVR = 4.2 V, VJ = 0.7 V\n\nTherefore, CT(pF) = 41.82 pF\n\nThe transistor capacitance is also given by, \nCT = K/[VR+VJ]^n\n\nTherefore, K = 71.03 * 10^-12\n"}], "metadata": {"scrolled": true, "collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}} \ No newline at end of file
diff --git a/sample_notebooks/PraveenKumar/chapter2.ipynb b/sample_notebooks/PraveenKumar/chapter2.ipynb
new file mode 100755
index 00000000..3d7aab33
--- /dev/null
+++ b/sample_notebooks/PraveenKumar/chapter2.ipynb
@@ -0,0 +1,429 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter-2, Economics of generation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1, Page 73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#To Determine the Demand and Supply Parameters for 15 bulbs\n",
+ "\n",
+ "W=60 #Wattage of the bulb\n",
+ "N=15 #No. of bulbs\n",
+ "CL=W*N #Connected Load \n",
+ "Wih=2*(10**3) #Wattage of immersion heater\n",
+ "Wh=2*(10**3) #Wattage of heater\n",
+ "\n",
+ "#Usage of Bulbs at different time periods\n",
+ "N1=5 \n",
+ "N2=10 \n",
+ "N3=6\n",
+ "\n",
+ "#Time periods for bulbs\n",
+ "T1=2 #6pm - 8pm\n",
+ "T2=2 #8pm - 10pm\n",
+ "T3=2 #10pm - 12pm\n",
+ "#Time Periods for heaters\n",
+ "T4=4 #1pm - 5pm\n",
+ "T5=3 #8pm - 11pm\n",
+ "\n",
+ "#CASE 1\n",
+ "MD1=W*N2 #Maximum Demand\n",
+ "DF=MD1*100/CL #Demand Factor\n",
+ "EC1=(N1*W*T1)+(N2*W*T2)+(N3*W*T3) #Energy Consumed\n",
+ "DLF1=EC1*100/(24*MD1) #Daily Load Factor\n",
+ "\n",
+ "#CASE 2\n",
+ "MD2=(W*N2)+Wh #From 8pm - 10pm\n",
+ "EC2=(T4*Wih)+(T5*Wh)+EC1 #Energy Consumed\n",
+ "DLF2=EC2*100/(24*MD2) #Daily Load Factor\n",
+ "\n",
+ "print '''i)a) Connected Load is %0.2f W\\nb) The Maximum Demand is %0.2f W\n",
+ "c) The Demand Factor is %0.2f percent\\nd) The Daily Load Factor is %0.2f percent''' %(CL,MD1,DF,DLF1)\n",
+ "print 'ii) The Improved Daily Load Factor is %0.2f percent' %DLF2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i)a) Connected Load is 900.00 W\n",
+ "b) The Maximum Demand is 600.00 W\n",
+ "c) The Demand Factor is 66.67 percent\n",
+ "d) The Daily Load Factor is 17.50 percent\n",
+ "ii) The Improved Daily Load Factor is 26.47 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2, Page 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "\n",
+ "#To determine the Demand and supply parameter of four consumers\n",
+ "\n",
+ "\n",
+ "#Maximum Demands of various users\n",
+ "MD1=2*(10**3) #9pm\n",
+ "MD2=2*(10**3) #12 noon\n",
+ "MD3=8*(10**3) #5pm\n",
+ "MD4=4*(10**3) #8pm\n",
+ "MDT=MD1+MD2+MD3+MD4 #Sum of all Maximum Demands\n",
+ "\n",
+ "#Demands of various users\n",
+ "D1=1.6*(10**3) #8pm\n",
+ "D2=1*(10**3) #8pm\n",
+ "D3=5*(10**3) #8pm\n",
+ "\n",
+ "#The Number after the Alphabets represents the Consumer\n",
+ "\n",
+ "#Maximum Demand of the System arises at 8.00 PM\n",
+ "MDS = D1+D2+D3+MD4 \n",
+ "\n",
+ "TDF=MDT/MDS #Diversity Factor\n",
+ "#Given Values\n",
+ "#Average Loads\n",
+ "AL2=500 \n",
+ "AL4=1000 \n",
+ "#Load Factors\n",
+ "LF1=15/100 \n",
+ "LF3=25/100 \n",
+ "#Calculated Values\n",
+ "#Average Loads\n",
+ "AL1=LF1*MD1 \n",
+ "AL3=LF3*MD3 \n",
+ "#Load Factors\n",
+ "LF2=AL2*100/MD2 \n",
+ "LF4=AL4*100/MD4 \n",
+ "\n",
+ "ALS=AL1+AL2+AL3+AL4 #Combined Average Loads\n",
+ "LFS=ALS*100/MDS #Combined Load Factor\n",
+ "\n",
+ "#Load Percent\n",
+ "LF1*=100 # %\n",
+ "LF3*=100 # %\n",
+ "\n",
+ "print 'i) The Diversity Factor is %0.2f' %TDF\n",
+ "print 'ii) The Average load and Load factor of:'\n",
+ "print ' Consumer 1 : %0.2f W and %0.2f percent' %(AL1,LF1)\n",
+ "print ' Consumer 2 : %0.2f W and %0.2f percent' %(AL2,LF2)\n",
+ "print ' Consumer 3 : %0.2f W and %0.2f percent' %(AL3,LF3)\n",
+ "print ' Consumer 4 : %0.2f W and %0.2f percent' %(AL4,LF4)\n",
+ "print 'iii) The Combined Load Factor and the Combined Average Load is %0.2f percent and %0.2f W respectively\\n' %(LFS,ALS)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i) The Diversity Factor is 1.38\n",
+ "ii) The Average load and Load factor of:\n",
+ " Consumer 1 : 300.00 W and 15.00 percent\n",
+ " Consumer 2 : 500.00 W and 25.00 percent\n",
+ " Consumer 3 : 2000.00 W and 25.00 percent\n",
+ " Consumer 4 : 1000.00 W and 25.00 percent\n",
+ "iii) The Combined Load Factor and the Combined Average Load is 32.76 percent and 3800.00 W respectively\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3, Page 75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "\n",
+ "#To Determine the Yearly Cost of the substation\n",
+ "\n",
+ "Teff=95/100 #Transmission Efficiency\n",
+ "Deff=85/100 #Distribution Efficiency\n",
+ "DFT=1.2 #Diversity Factor For Transmission\n",
+ "DFD=1.3 #Diversity Factor For Distribution\n",
+ "MDGS=100*(10**6) #Maximum Demand of Generating Station\n",
+ "ALF=40/100 #Annual Load Factor\n",
+ "ACCT=2.5*(10**6) #Annual Capital Charge for Transmission\n",
+ "ACCD=2*(10**6) #Annual Capital Charge for Distribution\n",
+ "GCC=100 #Generating Cost per kW demand\n",
+ "GCCU=5/100 # Per Unit Cost\n",
+ "#Fixed Charges from Supply to Substation Annually\n",
+ "GFC=GCC*MDGS/1000 #Generating\n",
+ "TFC=ACCT #Transmission\n",
+ "TotFCS=GFC+TFC #Total\n",
+ "#Fixed Charges for supply upto Consumer Annually\n",
+ "DFC=ACCD #Distribution\n",
+ "TotFCC=TotFCS+DFC #Total\n",
+ "\n",
+ "AMDS= DFT*MDGS/1000 #Aggregate of Maximum Demand at Supply\n",
+ "AMDC= DFD*AMDS #Aggregate of Maximum Demand for Consumers\n",
+ "\n",
+ "FCS=TotFCS/AMDS #Fixed Charges Per KW at substation\n",
+ "CES=GCCU/Teff #Cost of energy at the substation\n",
+ "\n",
+ "FCC=TotFCC/AMDC #Fixed Charges per KW at the consumer premises\n",
+ "CEC=CES/Deff #Cost of Energy at the consumer premises\n",
+ "\n",
+ "CEC*=100 # converting from rupee to paise\n",
+ "\n",
+ "print 'The Yealy Cost per KW demand and the cost per KWhr at:'\n",
+ "print 'a) The substation is %0.2f rupees per KW and %0.2f paise per kWhr'%(FCS,CES)\n",
+ "print 'b) The consumer premises is %g rupees per KW and %g paise per kWhr' %(FCC,CEC)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Yealy Cost per KW demand and the cost per KWhr at:\n",
+ "a) The substation is 104.17 rupees per KW and 0.05 paise per kWhr\n",
+ "b) The consumer premises is 92.9487 rupees per KW and 6.19195 paise per kWhr\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex4, Page 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To determine the Load factor and suitable units for 24 hr operation of the plant\n",
+ "\n",
+ "\n",
+ "#Demands at Various Time Periods starting from 12PM to 12PM\n",
+ "D1=500*(10**3) \n",
+ "D2=800*(10**3) \n",
+ "D3=2000*(10**3) \n",
+ "D4=1000*(10**3) \n",
+ "D5=2500*(10**3) \n",
+ "D6=2000*(10**3) \n",
+ "D7=1500*(10**3) \n",
+ "D8=1000*(10**3) \n",
+ "\n",
+ "MD=D5 #Maximum Demand\n",
+ "#Time Periods of demands from 12PM\n",
+ "T1=5 \n",
+ "T2=5 \n",
+ "T3=2 \n",
+ "T4=2 \n",
+ "T5=3 \n",
+ "T6=3 \n",
+ "T7=2 \n",
+ "T8=2 \n",
+ "\n",
+ "#Total Energy Demand in 24hrs\n",
+ "TED=(T1*D1)+(T2*D2)+(T3*D3)+(D4*T4)+(T5*D5)+(D6*T6)+(D7*T7)+(T8*D8) \n",
+ "\n",
+ "LF=TED*100/(24*MD) \n",
+ "\n",
+ "C1000=3*1000*(10**3) #1000 unit \n",
+ "C500=1*500*(10**3) #500 Unit\n",
+ "\n",
+ "TCP=C1000+C500 #Total capacity of the plant\n",
+ "PCF=TED*100/(24*TCP) #Plant Capacity Factor\n",
+ "\n",
+ "#Operating Schedule, Units operated can be seen in the textbook\n",
+ "G1=500*(10**3) \n",
+ "G2=1000*(10**3) \n",
+ "G3=2000*(10**3) \n",
+ "G4=1000*(10**3) \n",
+ "G5=2500*(10**3) \n",
+ "G6=2000*(10**3) \n",
+ "G7=1500*(10**3) \n",
+ "G8=1000*(10**3) \n",
+ "\n",
+ "TEG=(T1*G1)+(T2*G2)+(T3*G3)+(G4*T4)+(T5*G5)+(G6*T6)+(G7*T7)+(T8*G8) #Total Energy Generated\n",
+ "PUF=TED*100/(TEG) #Plant Use Factor\n",
+ "\n",
+ "print 'a) The Reserve Capacity is a 1000kW Unit and Load Factor is %0.2f percent' %LF\n",
+ "print 'b) The Plant Capacity Factor is %0.2f percent' %PCF\n",
+ "print 'c) The Plant Use Factor is %0.2f percent' %PUF"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a) The Reserve Capacity is a 1000kW Unit and Load Factor is 51.67 percent\n",
+ "b) The Plant Capacity Factor is 36.90 percent\n",
+ "c) The Plant Use Factor is 96.88 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex5, Page 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To determine the Plant use factore of each unit\n",
+ "\n",
+ "\n",
+ "MDS=25*(10**6) #Maximum Demand on the System\n",
+ "U1=15*(10**6) #Load Supplied By Unit 1\n",
+ "U2=12.5*(10**6) #Load Supplied By Unit 2\n",
+ "#Running Time Factor of the Unit\n",
+ "T1=1 \n",
+ "T2=40/100 \n",
+ "\n",
+ "#Energy generated by each unit\n",
+ "E1=1*(10**8) \n",
+ "E2=1*(10**7) \n",
+ "Et=E1+E2 #Total Energy\n",
+ "\n",
+ "#Maximum Demands on Each Units\n",
+ "MD1=U1 \n",
+ "MD2=MDS-U1 \n",
+ "\n",
+ "#Annual Load Factor for the Units\n",
+ "ALF1=E1*1000*100/(MD1*8760) \n",
+ "ALF2=E2*1000*100/(MD2*8760) \n",
+ "\n",
+ "LF2=E2*1000*100/(MD2*0.4*8760) #Load Factor for the it is loaded\n",
+ "\n",
+ "\n",
+ "PUF1=ALF1 #Plant Use Factor\n",
+ "PCF1=ALF1 # Plant Capacity Factor\n",
+ "\n",
+ "PCF2=E2*1000*100/(U2*8760) #Plant Capacity Factor for Unit 2\n",
+ "PUF2=E2*1000*100/(U2*0.4*8760) #Plant Use Factor for Unit 2\n",
+ "\n",
+ "LFP=Et*100*1000/(MDS*8760) #Annual Load Factor of the Complete Plant\n",
+ "\n",
+ "print 'The Load Factor, Plant Capacity Factor, Plant Use Factor of:'\n",
+ "print 'Unit 1 : %0.2f percent, %0.2f percent, %0.2f percent' %(ALF1,PCF1,PUF1)\n",
+ "print 'Unit 2 : %0.2f percent, %0.2f percent, %0.2f percent' %(ALF2,PCF2,PUF2)\n",
+ "print 'The Annual Load Factor of the Entire Plant is %0.2f percent' %LFP"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Load Factor, Plant Capacity Factor, Plant Use Factor of:\n",
+ "Unit 1 : 76.10 percent, 76.10 percent, 76.10 percent\n",
+ "Unit 2 : 11.42 percent, 9.13 percent, 22.83 percent\n",
+ "The Annual Load Factor of the Entire Plant is 50.23 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6, Page 91"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To determine the most economic power factor\n",
+ "\n",
+ "from numpy import sqrt\n",
+ "\n",
+ "P=200*(10**3) #Maximum Demand\n",
+ "pf=0.707 #Power Factor Lagging\n",
+ "\n",
+ "a=100 #Tariff per kVA per year\n",
+ "\n",
+ "b=200 #Power factor improvement cost Per kVA.\n",
+ "r=20 #Interest Depriciation, maintenance and cost of losses amount to 20% of capital cost per year\n",
+ "\n",
+ "# Economic PF = sqrt(1-((b1/a)**2))\n",
+ "\n",
+ "b1=r*b/100 # b' term accrding to the equation above\n",
+ "\n",
+ "pfeco=sqrt(1-((b1/a)**2)) #Economic Power Factor\n",
+ "\n",
+ "print 'The Economic Power Factor is %0.2f ' %pfeco\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Economic Power Factor is 0.92 \n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/sample_notebooks/Raj Phani/chapter_1.ipynb b/sample_notebooks/Raj Phani/chapter_1.ipynb
new file mode 100755
index 00000000..f71cb56f
--- /dev/null
+++ b/sample_notebooks/Raj Phani/chapter_1.ipynb
@@ -0,0 +1,1118 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# chapter1: electric charge"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false,
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.1, Page:3 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The electric field in V/m is = 20000.0\n",
+ "\n",
+ " The force in N/C is = 20000.0\n",
+ "\n",
+ " The force on metal sphere in N is = 7.6e-05\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.1, Page:3 \\n \\n\"\n",
+ "#Given:\n",
+ "v=1000# potential\n",
+ "d=0.05# distance\n",
+ "q=3.8*10**-9# charge\n",
+ "\n",
+ "#solution:\n",
+ "e=v/d;#electric field\n",
+ "f=e;# force\n",
+ "f1=f*q;# force on metal sphere\n",
+ "print\"\\n The electric field in V/m is =\",e\n",
+ "print\"\\n The force in N/C is =\",f\n",
+ "print\"\\n The force on metal sphere in N is =\",f1\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.2, Page:4 \n",
+ " \n",
+ "\n",
+ "The potential in V is = 80.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.2, Page:4 \\n \\n\"\n",
+ "#Given:\n",
+ "energy=2*10**-6\n",
+ "c=2.5*10**-8# velocity of light\n",
+ "#solution:\n",
+ "v=energy/c# potential\n",
+ "print\"The potential in V is =\",v\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.3, Page:5 \n",
+ " \n",
+ "\n",
+ "The wavelength in Angstroms is = 3.88289589025\n",
+ "\n",
+ " The photon wavelength in Angstroms is = 9.11075e-05\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.3, Page:5 \\n \\n\"\n",
+ "#Given:\n",
+ "\n",
+ "energy=10 #in electron volts\n",
+ "m=9.1*10**-31# mass of electron in kg\n",
+ "h=6.626*10**-34# planck's constant J.s\n",
+ "c=3*10^8# speed of light in m/s\n",
+ "\n",
+ "#solution (a):\n",
+ "energy1=energy*1.6*10**-19# energy in J\n",
+ "p=(2*m*energy1)**0.5# momentum\n",
+ "wavelength=h/p*(10)**10\n",
+ "\n",
+ "print\"The wavelength in Angstroms is =\",wavelength\n",
+ "\n",
+ "\n",
+ "#solution (b):\n",
+ "wavelength1=h*c/energy1*(10)**10;#photon wavelength\n",
+ "\n",
+ "print\"\\n The photon wavelength in Angstroms is =\",wavelength1\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example1.4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.4, Page:6 \n",
+ " \n",
+ "\n",
+ "The energy in eV is = 150.768804945\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.4, Page:6 \\n \\n\"\n",
+ "\n",
+ "#Given:\n",
+ "\n",
+ "wavelength=10**-10\n",
+ "m=9.1*10**-31\n",
+ "h=6.626*10**-34\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "p=h/wavelength\n",
+ "e=p*p/(2*m) # energy in J\n",
+ "e1=e/(1.6*10**-19)# energy in eV\n",
+ "\n",
+ "print\"The energy in eV is =\",e1\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.5, Page:8 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The wavelength in 10^-5 Angstroms is = 0.655671822473\n",
+ "\n",
+ " The wavelength in 10^-5 Angstroms is = 0.648946805494\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.5, Page:8 \\n \\n\"\n",
+ "\n",
+ "#Given:\n",
+ "\n",
+ "m=1.66*10**-27# 1u=1.66*10^-27 kg\n",
+ "h=6.6262*10**-34#planck's constant in J.s\n",
+ "energy1=120# in Mev for oxygen\n",
+ "energy2=140# in MeV for nitrogen\n",
+ "\n",
+ "#solution(a):\n",
+ "\n",
+ "p=(2*m*16*energy1*(1.6022*10**-13))**0.5\n",
+ "wavelength1=h/p*(10)**15#wavelength in 10^-5 Angstroms\n",
+ "\n",
+ "print\"\\n The wavelength in 10^-5 Angstroms is =\",wavelength1\n",
+ "\n",
+ "#solution (b):\n",
+ "\n",
+ "p=(2*m*14*energy2*(1.6022*10**-13))**0.5\n",
+ "wavelength2=h/p*(10)**15#wavelength in 10^-5 Angstroms\n",
+ "\n",
+ "print\"\\n The wavelength in 10^-5 Angstroms is =\",wavelength2\n",
+ "\n",
+ "# 1 Angstrom = 10^-10 m\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example1.6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.6, Page:9 \n",
+ " \n",
+ "\n",
+ "The energy in eV is = 8275.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.6, Page:9 \\n \\n\"\n",
+ "\n",
+ "#Given:\n",
+ "\n",
+ "wavelength=1.5*10**-10\n",
+ "h=6.62*10**-34\n",
+ "c=3*10**8\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "e=(h*c)/wavelength# energy in J\n",
+ "e1=e/(1.6*10**-19)# energy in eV\n",
+ "\n",
+ "print\"The energy in eV is =\",e1\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.7, Page:10 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The threshold frequency in s^-1 is = 1.23634168427e+15\n",
+ "\n",
+ " The threshold wavelength in Angstroms is = 2426.51367187\n",
+ "\n",
+ " The energy of photoelectrone in eV is = 3.911875\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.7, Page:10 \\n \\n\"\n",
+ "\n",
+ "#Given:\n",
+ "\n",
+ "E=5.12*1.6*10**-19# energy in J\n",
+ "h=6.626*10**-34\n",
+ "c=3*10**8\n",
+ "wavelength=200*10**-9\n",
+ "w=2.3# in eV\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "tf=E/h# (part a)\n",
+ "print\"\\n The threshold frequency in s^-1 is =\",tf\n",
+ "\n",
+ "tl=c/tf*10**10# (part b)\n",
+ "print\"\\n The threshold wavelength in Angstroms is =\",tl\n",
+ "\n",
+ "e=(h*c)/(wavelength*1.6*10**-19)# photon energy in eV (part c)\n",
+ "\n",
+ "pe=e-w\n",
+ "\n",
+ "print\"\\n The energy of photoelectrone in eV is =\",pe\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.8, Page:10 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The velocity of alpha particles for 1 MeV in m/s is = 6941056.08394\n",
+ "\n",
+ " The velocity of alpha particles for 2 MeV in m/s is = 9816135.6511\n",
+ "\n",
+ " The velocity of deuteron particles for 1 MeV in m/s is = 9816135.6511\n",
+ "\n",
+ " The velocity of deuteron particles for 2 MeV in m/s is = 13882112.1679\n",
+ "\n",
+ " The velocity of proton particles for 1 MeV in m/s is = 13882112.1679\n",
+ "\n",
+ " The velocity of proton particles for 2 MeV in m/s is = 19632271.3022\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of velocity of alpha particles,deuteron,proton\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.8, Page:10 \\n \\n\"\n",
+ "#Given:\n",
+ "e1=1 # in MeV\n",
+ "e2=2 # in MeV\n",
+ "ma=4 # in u(amu)\n",
+ "md=2 # in u(amu)\n",
+ "mp=1 # in u(amu)\n",
+ "\n",
+ "# 1u = 1.6*10^-27 Kg\n",
+ "\n",
+ "#solution: part a)For alpha particles\n",
+ "\n",
+ "v1a=((2*e1*10**6*1.6*10**-19)/(ma*1.6605*10**-27))**.5\n",
+ "print\"\\n The velocity of alpha particles for 1 MeV in m/s is =\",v1a# For 1 MeV\n",
+ "\n",
+ "v2a=((2*e2*10**6*1.6*10**-19)/(ma*1.6605*10**-27))**.5\n",
+ "print\"\\n The velocity of alpha particles for 2 MeV in m/s is =\",v2a# For 2 MeV\n",
+ "\n",
+ "#solution: part b)For deuteron particles\n",
+ "\n",
+ "v1b=((2*e1*10**6*1.6*10**-19)/(md*1.6605*10**-27))**.5\n",
+ "print\"\\n The velocity of deuteron particles for 1 MeV in m/s is =\",v1b # For 1 MeV\n",
+ "\n",
+ "\n",
+ "v2b=((2*e2*10**6*1.6*10**-19)/(md*1.6605*10**-27))**.5\n",
+ "print\"\\n The velocity of deuteron particles for 2 MeV in m/s is =\",v2b # For 2 MeV\n",
+ "\n",
+ "#solution: part c)For proton particles\n",
+ "\n",
+ "v1p=((2*e1*10**6*1.6*10**-19)/(mp*1.6605*10**-27))**.5\n",
+ "print\"\\n The velocity of proton particles for 1 MeV in m/s is =\",v1p # For 1 MeV\n",
+ "\n",
+ "\n",
+ "v2p=((2*e2*10**6*1.6*10**-19)/(mp*1.6605*10**-27))**.5\n",
+ "print\"\\n The velocity of proton particles for 2 MeV in m/s is =\",v2p # For 2 MeV\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.9, Page: \n",
+ " \n",
+ "\n",
+ "The energy in MeV is = 933.919973435\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The energy\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.9, Page: \\n \\n\"\n",
+ "#Given:\n",
+ "\n",
+ "m=1/(6.023*10**23)#mass of 1 atom in g\n",
+ "m1=m*10**-3#mass of 1 atom in Kg\n",
+ "c=3*10**8# velocity in m/s\n",
+ "#solution:\n",
+ "\n",
+ "e=m1*c*c; # energy in J\n",
+ "e1=e/(1.6*10**-13)# energy in MeV\n",
+ "\n",
+ "print\"The energy in MeV is =\",e1\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.1, Page:11 \n",
+ " \n",
+ "\n",
+ "The energy in eV is = 13.2638658253\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The energy\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.1, Page:11 \\n \\n\"\n",
+ "#Given:\n",
+ "\n",
+ "enthalpy=1278 # enthalpy of combustion in kJ/mol\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "energy=(enthalpy*1000)/(6.022*10**23*1.6*10**-19)\n",
+ "\n",
+ "print\"The energy in eV is =\",energy\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.11, Page:11 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The mean binding energy of helium atom in MeV is = 7.0710038475\n",
+ "\n",
+ " The mean binding energy of oxygen atom in MeV is = 7.9800498909\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of mean binding energy of helium and oxygen\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.11, Page:11 \\n \\n\"\n",
+ "#Given:\n",
+ "mh=1.0078\n",
+ "mn=1.0087\n",
+ "ma=4.0026\n",
+ "mo=15.9949\n",
+ "Ah=4.0026 # atomic mass of helium\n",
+ "Ao=15.9949 # atomic mass of oxygen\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "# part (a)\n",
+ "\n",
+ "B1=(2*mh+2*mn-ma)*931 # in MeV\n",
+ "Bh=B1/Ah\n",
+ "print\"\\n The mean binding energy of helium atom in MeV is =\",Bh\n",
+ "\n",
+ "# part (b)\n",
+ "\n",
+ "B2=(8*mh+8*mn-mo)*931 # in MeV\n",
+ "Bo=B2/Ao\n",
+ "print\"\\n The mean binding energy of oxygen atom in MeV is =\",Bo\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.12, Page:12 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The mean binding energy of Be atom in MeV is = 7.05928572321\n",
+ "From previous problem we have the avg. binding energy of helium atom is 7.08 MeV, Hence Be is unstable to fission into 2 alphas\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of \n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.12, Page:12 \\n \\n\"\n",
+ "#Given:\n",
+ "mh=1.0078;\n",
+ "mn=1.0087;\n",
+ "ABe=8.0053; # atomic mass of beryllium\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "B1=(4*mh+4*mn-ABe)*931; # in MeV\n",
+ "Bh=B1/ABe;\n",
+ "print\"\\n The mean binding energy of Be atom in MeV is =\",Bh\n",
+ "\n",
+ "print\"From previous problem we have the avg. binding energy of helium atom is 7.08 MeV, Hence Be is unstable to fission into 2 alphas\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.13, Page:12 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The amount of coal required in Kg is = 2499.85671416\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of amount of coal\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.13, Page:12 \\n \\n\"\n",
+ "#Given:\n",
+ "\n",
+ "e=200; # in Mev\n",
+ "m=0.235; # weight of uranium atom in Kg\n",
+ "enthalpy=393.5; # in KJ/mol\n",
+ "Na=6.02*10**23;\n",
+ "\n",
+ "\n",
+ "#solution:\n",
+ "e1=e*1.6*10**-19*10**6;\n",
+ "atoms=Na/m;\n",
+ "e2=atoms*e1;#energy released in J\n",
+ "m1=(e2*12)/(393.5*1000*1000);# in Kg\n",
+ "m2=m1/1000;# in tons\n",
+ "print\"\\n The amount of coal required in Kg is =\", m2\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.14, Page:13 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The energy release in part (a) in eV/molecule is = 2.51472\n",
+ "\n",
+ " The energy release in part (b) in eV/molecule is = 9.22688\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The energy releases\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.14, Page:13 \\n \\n\"\n",
+ "#Given:\n",
+ "H1=241.8; # in KJ/mol\n",
+ "H2=887.2; # in KJ/mol\n",
+ "# 1 KJ/mol = 0.0104 eV/atom\n",
+ "\n",
+ "#solution: part (a)\n",
+ "e1=H1*0.0104;\n",
+ "print\"\\n The energy release in part (a) in eV/molecule is =\",e1\n",
+ "\n",
+ "#solution: part (b)\n",
+ "e2=H2*0.0104;\n",
+ "print\"\\n The energy release in part (b) in eV/molecule is =\",e2\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.15, Page:14 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The energy release in part (a) in KJ/mol of carbondioxide is = 394.912\n",
+ "\n",
+ " The energy release in part (b) in KJ/mol of alumina is = 1675.968\n",
+ "\n",
+ " The energy release in part (c) in MJ/atom of U(235) is = 19264000.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The energy releases\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.15, Page:14 \\n \\n\"\n",
+ "#Given:\n",
+ "H1=4.1; # in eV/molecule\n",
+ "H2=17.4; # in eV/molecule\n",
+ "H3=200;# in MeV/atom of U\n",
+ "\n",
+ "# 1 eV/atom = 96.32 KJ/mol\n",
+ "\n",
+ "#solution: part (a)\n",
+ "e1=H1*96.32;\n",
+ "print\"\\n The energy release in part (a) in KJ/mol of carbondioxide is =\",e1\n",
+ "\n",
+ "#solution: part (b)\n",
+ "e2=H2*96.32;\n",
+ "print\"\\n The energy release in part (b) in KJ/mol of alumina is =\",e2\n",
+ "\n",
+ "#solution: part (c)\n",
+ "e3=H3*1000*96.32;# in MJ/atom of U(235)\n",
+ "print\"\\n The energy release in part (c) in MJ/atom of U(235) is =\",e3\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.16, Page:15 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The rate of energy release in W is 949251379.039\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The rate of energy release\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.16, Page:15 \\n \\n\"\n",
+ "#Given:\n",
+ "e=200; #MeV/ atom of U\n",
+ "# 1 eV = 1.6*10^-19 J\n",
+ "Na=6.023*10**23;\n",
+ "M=0.235; # mass in Kg\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "e1=e*1.6*10**-19*10**6;\n",
+ "A=Na/M;\n",
+ "e2=A*e1; # energy released in MJ/day\n",
+ "e3=e2/(24*3600);\n",
+ "print\"\\n The rate of energy release in W is \",e3\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 38,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.17, Page:16 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The mass loss in 10^-27 Kg/He formed is = 0.046412244898\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The mass loss\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.17, Page:16 \\n \\n\"\n",
+ "#Given:\n",
+ "e=26.03; # in MeV\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "loss=e/931; #in atomic mass units (u)\n",
+ "# 1 u = 1.66*10^-27 Kg\n",
+ "m=(loss*1.66*10**-27)/(1*10**-27);\n",
+ "print\"\\n The mass loss in 10^-27 Kg/He formed is =\",m\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.18, Page:17 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The energy loss in MeV is = 4.03123\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The energy loss\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.18, Page:17 \\n \\n\"\n",
+ "#Given:\n",
+ "mh=1.007825;\n",
+ "mt=3.016049;\n",
+ "md=2.014102;\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "m1=(mh+mt-2*md);\n",
+ "e=(-m1)*931; # in MeV\n",
+ "print\"\\n The energy loss in MeV is =\",e\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.19, Page:18 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The mean binding energy of tritium atom in MeV is = 2.81085817903\n",
+ "\n",
+ " The mean binding energy of nickel atom in MeV is = 8.71580311296\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of mean binding energy of tritium and nickel atom\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.19, Page:18 \\n \\n\"\n",
+ "#Given:\n",
+ "mh=1.007825;\n",
+ "mn=1.008665;\n",
+ "mt=3.016049; # atomic mass of Tritium\n",
+ "mNi=59.93528; # atomic mass of Nickel\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "# part (a)\n",
+ "\n",
+ "B1=(1*mh+2*mn-mt)*931; # in MeV\n",
+ "Bh=B1/mt;\n",
+ "print\"\\n The mean binding energy of tritium atom in MeV is =\",Bh\n",
+ "\n",
+ "# part (b)\n",
+ "\n",
+ "B2=(28*mh+32*mn-mNi)*931; # in MeV\n",
+ "Bo=B2/mNi;\n",
+ "print\"\\n The mean binding energy of nickel atom in MeV is =\",Bo\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 41,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.20, Page:19 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The mean binding energy of Cl (35) atom in MeV is = 8.52810201079\n",
+ "\n",
+ " The mean binding energy of Cl (37) atom in MeV is = 8.57839008383\n",
+ "\n",
+ " The increase in mean binding energy of Cl atom in MeV is = 0.0502880730447\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of mean binding energy of Cl\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.20, Page:19 \\n \\n\"\n",
+ "#Given:\n",
+ "mh=1.00783;\n",
+ "mn=1.00867;\n",
+ "m35=34.96885; # atomic mass of Cl (35)\n",
+ "m37=36.96590; # atomic mass of Cl (37)\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "B1=(17*mh+18*mn-m35)*931; # in MeV\n",
+ "Bh=B1/m35;\n",
+ "print\"\\n The mean binding energy of Cl (35) atom in MeV is =\",Bh\n",
+ "\n",
+ "B2=(17*mh+20*mn-m37)*931; # in MeV\n",
+ "Bo=B2/m37;\n",
+ "print\"\\n The mean binding energy of Cl (37) atom in MeV is =\",Bo\n",
+ "\n",
+ "Bi=Bo-Bh;\n",
+ "print\"\\n The increase in mean binding energy of Cl atom in MeV is =\",Bi\n",
+ "\n",
+ "# NOTE: The answer depends upon how much precise value you take for atomic masses.\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.21, Page:20 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The mean binding energy of Na(22) in MeV is = 7.92358978299\n",
+ "\n",
+ " The mean binding energy of Na(23)in MeV is = 8.11544250059\n",
+ "\n",
+ " The mean binding energy of Na(24) in MeV is = 8.07172719656\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of mean binding energy of Na\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.21, Page:20 \\n \\n\"\n",
+ "#Given:\n",
+ "mh=1.0078;\n",
+ "mn=1.0087;\n",
+ "m22=21.99431;# atomic mass of Na 22\n",
+ "m23=22.9898;# atomic mass of Na 23\n",
+ "m24=23.9909;# atomic mass of Na 24\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "# part (a)\n",
+ "\n",
+ "B1=((11*mh+11*mn)-m22)*931; # in MeV\n",
+ "Bh=B1/m22;\n",
+ "print\"\\n The mean binding energy of Na(22) in MeV is =\",Bh\n",
+ "\n",
+ "# part (b)\n",
+ "\n",
+ "B2=((11*mh+12*mn)-m23)*931; # in MeV\n",
+ "Bo=B2/m23;\n",
+ "print\"\\n The mean binding energy of Na(23)in MeV is =\",Bo\n",
+ "\n",
+ "# part (c)\n",
+ "\n",
+ "B3=((11*mh+13*mn)-m24)*931; # in MeV\n",
+ "Bs=B3/m24;\n",
+ "print\"\\n The mean binding energy of Na(24) in MeV is =\",Bs\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/sample_notebooks/Raj Phani/chapter_1_1.ipynb b/sample_notebooks/Raj Phani/chapter_1_1.ipynb
new file mode 100755
index 00000000..6bb4fa49
--- /dev/null
+++ b/sample_notebooks/Raj Phani/chapter_1_1.ipynb
@@ -0,0 +1,1118 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# chapter1: electric charge"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false,
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.1, Page:3 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The electric field in V/m is = 20000.0\n",
+ "\n",
+ " The force in N/C is = 20000.0\n",
+ "\n",
+ " The force on metal sphere in N is = 7.6e-05\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.1, Page:3 \\n \\n\"\n",
+ "#Given:\n",
+ "v=1000# potential\n",
+ "d=0.05# distance\n",
+ "q=3.8*10**-9# charge\n",
+ "\n",
+ "#solution:\n",
+ "e=v/d;#electric field\n",
+ "f=e;# force\n",
+ "f1=f*q;# force on metal sphere\n",
+ "print\"\\n The electric field in V/m is =\",e\n",
+ "print\"\\n The force in N/C is =\",f\n",
+ "print\"\\n The force on metal sphere in N is =\",f1\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.2, Page:4 \n",
+ " \n",
+ "\n",
+ "The potential in V is = 80.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.2, Page:4 \\n \\n\"\n",
+ "#Given:\n",
+ "energy=2*10**-6\n",
+ "c=2.5*10**-8# velocity of light\n",
+ "#solution:\n",
+ "v=energy/c# potential\n",
+ "print\"The potential in V is =\",v\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.3, Page:5 \n",
+ " \n",
+ "\n",
+ "The wavelength in Angstroms is = 3.88289589025\n",
+ "\n",
+ " The photon wavelength in Angstroms is = 9.11075e-05\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.3, Page:5 \\n \\n\"\n",
+ "#Given:\n",
+ "\n",
+ "energy=10 #in electron volts\n",
+ "m=9.1*10**-31# mass of electron in kg\n",
+ "h=6.626*10**-34# planck's constant J.s\n",
+ "c=3*10^8# speed of light in m/s\n",
+ "\n",
+ "#solution (a):\n",
+ "energy1=energy*1.6*10**-19# energy in J\n",
+ "p=(2*m*energy1)**0.5# momentum\n",
+ "wavelength=h/p*(10)**10\n",
+ "\n",
+ "print\"The wavelength in Angstroms is =\",wavelength\n",
+ "\n",
+ "\n",
+ "#solution (b):\n",
+ "wavelength1=h*c/energy1*(10)**10;#photon wavelength\n",
+ "\n",
+ "print\"\\n The photon wavelength in Angstroms is =\",wavelength1\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example1.4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.4, Page:6 \n",
+ " \n",
+ "\n",
+ "The energy in eV is = 150.768804945\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.4, Page:6 \\n \\n\"\n",
+ "\n",
+ "#Given:\n",
+ "\n",
+ "wavelength=10**-10\n",
+ "m=9.1*10**-31\n",
+ "h=6.626*10**-34\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "p=h/wavelength\n",
+ "e=p*p/(2*m) # energy in J\n",
+ "e1=e/(1.6*10**-19)# energy in eV\n",
+ "\n",
+ "print\"The energy in eV is =\",e1\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.5, Page:8 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The wavelength in 10^-5 Angstroms is = 0.655671822473\n",
+ "\n",
+ " The wavelength in 10^-5 Angstroms is = 0.648946805494\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.5, Page:8 \\n \\n\"\n",
+ "\n",
+ "#Given:\n",
+ "\n",
+ "m=1.66*10**-27# 1u=1.66*10^-27 kg\n",
+ "h=6.6262*10**-34#planck's constant in J.s\n",
+ "energy1=120# in Mev for oxygen\n",
+ "energy2=140# in MeV for nitrogen\n",
+ "\n",
+ "#solution(a):\n",
+ "\n",
+ "p=(2*m*16*energy1*(1.6022*10**-13))**0.5\n",
+ "wavelength1=h/p*(10)**15#wavelength in 10^-5 Angstroms\n",
+ "\n",
+ "print\"\\n The wavelength in 10^-5 Angstroms is =\",wavelength1\n",
+ "\n",
+ "#solution (b):\n",
+ "\n",
+ "p=(2*m*14*energy2*(1.6022*10**-13))**0.5\n",
+ "wavelength2=h/p*(10)**15#wavelength in 10^-5 Angstroms\n",
+ "\n",
+ "print\"\\n The wavelength in 10^-5 Angstroms is =\",wavelength2\n",
+ "\n",
+ "# 1 Angstrom = 10^-10 m\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example1.6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.6, Page:9 \n",
+ " \n",
+ "\n",
+ "The energy in eV is = 8275.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.6, Page:9 \\n \\n\"\n",
+ "\n",
+ "#Given:\n",
+ "\n",
+ "wavelength=1.5*10**-10\n",
+ "h=6.62*10**-34\n",
+ "c=3*10**8\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "e=(h*c)/wavelength# energy in J\n",
+ "e1=e/(1.6*10**-19)# energy in eV\n",
+ "\n",
+ "print\"The energy in eV is =\",e1\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.7, Page:10 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The threshold frequency in s^-1 is = 1.23634168427e+15\n",
+ "\n",
+ " The threshold wavelength in Angstroms is = 2426.51367187\n",
+ "\n",
+ " The energy of photoelectrone in eV is = 3.911875\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of elelectric field and force\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.7, Page:10 \\n \\n\"\n",
+ "\n",
+ "#Given:\n",
+ "\n",
+ "E=5.12*1.6*10**-19# energy in J\n",
+ "h=6.626*10**-34\n",
+ "c=3*10**8\n",
+ "wavelength=200*10**-9\n",
+ "w=2.3# in eV\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "tf=E/h# (part a)\n",
+ "print\"\\n The threshold frequency in s^-1 is =\",tf\n",
+ "\n",
+ "tl=c/tf*10**10# (part b)\n",
+ "print\"\\n The threshold wavelength in Angstroms is =\",tl\n",
+ "\n",
+ "e=(h*c)/(wavelength*1.6*10**-19)# photon energy in eV (part c)\n",
+ "\n",
+ "pe=e-w\n",
+ "\n",
+ "print\"\\n The energy of photoelectrone in eV is =\",pe\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.8, Page:10 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The velocity of alpha particles for 1 MeV in m/s is = 6941056.08394\n",
+ "\n",
+ " The velocity of alpha particles for 2 MeV in m/s is = 9816135.6511\n",
+ "\n",
+ " The velocity of deuteron particles for 1 MeV in m/s is = 9816135.6511\n",
+ "\n",
+ " The velocity of deuteron particles for 2 MeV in m/s is = 13882112.1679\n",
+ "\n",
+ " The velocity of proton particles for 1 MeV in m/s is = 13882112.1679\n",
+ "\n",
+ " The velocity of proton particles for 2 MeV in m/s is = 19632271.3022\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of velocity of alpha particles,deuteron,proton\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.8, Page:10 \\n \\n\"\n",
+ "#Given:\n",
+ "e1=1 # in MeV\n",
+ "e2=2 # in MeV\n",
+ "ma=4 # in u(amu)\n",
+ "md=2 # in u(amu)\n",
+ "mp=1 # in u(amu)\n",
+ "\n",
+ "# 1u = 1.6*10^-27 Kg\n",
+ "\n",
+ "#solution: part a)For alpha particles\n",
+ "\n",
+ "v1a=((2*e1*10**6*1.6*10**-19)/(ma*1.6605*10**-27))**.5\n",
+ "print\"\\n The velocity of alpha particles for 1 MeV in m/s is =\",v1a# For 1 MeV\n",
+ "\n",
+ "v2a=((2*e2*10**6*1.6*10**-19)/(ma*1.6605*10**-27))**.5\n",
+ "print\"\\n The velocity of alpha particles for 2 MeV in m/s is =\",v2a# For 2 MeV\n",
+ "\n",
+ "#solution: part b)For deuteron particles\n",
+ "\n",
+ "v1b=((2*e1*10**6*1.6*10**-19)/(md*1.6605*10**-27))**.5\n",
+ "print\"\\n The velocity of deuteron particles for 1 MeV in m/s is =\",v1b # For 1 MeV\n",
+ "\n",
+ "\n",
+ "v2b=((2*e2*10**6*1.6*10**-19)/(md*1.6605*10**-27))**.5\n",
+ "print\"\\n The velocity of deuteron particles for 2 MeV in m/s is =\",v2b # For 2 MeV\n",
+ "\n",
+ "#solution: part c)For proton particles\n",
+ "\n",
+ "v1p=((2*e1*10**6*1.6*10**-19)/(mp*1.6605*10**-27))**.5\n",
+ "print\"\\n The velocity of proton particles for 1 MeV in m/s is =\",v1p # For 1 MeV\n",
+ "\n",
+ "\n",
+ "v2p=((2*e2*10**6*1.6*10**-19)/(mp*1.6605*10**-27))**.5\n",
+ "print\"\\n The velocity of proton particles for 2 MeV in m/s is =\",v2p # For 2 MeV\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.9, Page:10 \n",
+ " \n",
+ "\n",
+ "The energy in MeV is = 933.919973435\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The energy\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.9, Page:10 \\n \\n\"\n",
+ "#Given:\n",
+ "\n",
+ "m=1/(6.023*10**23)#mass of 1 atom in g\n",
+ "m1=m*10**-3#mass of 1 atom in Kg\n",
+ "c=3*10**8# velocity in m/s\n",
+ "#solution:\n",
+ "\n",
+ "e=m1*c*c; # energy in J\n",
+ "e1=e/(1.6*10**-13)# energy in MeV\n",
+ "\n",
+ "print\"The energy in MeV is =\",e1\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.1, Page:11 \n",
+ " \n",
+ "\n",
+ "The energy in eV is = 13.2638658253\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The energy\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.1, Page:11 \\n \\n\"\n",
+ "#Given:\n",
+ "\n",
+ "enthalpy=1278 # enthalpy of combustion in kJ/mol\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "energy=(enthalpy*1000)/(6.022*10**23*1.6*10**-19)\n",
+ "\n",
+ "print\"The energy in eV is =\",energy\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.11, Page:11 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The mean binding energy of helium atom in MeV is = 7.0710038475\n",
+ "\n",
+ " The mean binding energy of oxygen atom in MeV is = 7.9800498909\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of mean binding energy of helium and oxygen\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.11, Page:11 \\n \\n\"\n",
+ "#Given:\n",
+ "mh=1.0078\n",
+ "mn=1.0087\n",
+ "ma=4.0026\n",
+ "mo=15.9949\n",
+ "Ah=4.0026 # atomic mass of helium\n",
+ "Ao=15.9949 # atomic mass of oxygen\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "# part (a)\n",
+ "\n",
+ "B1=(2*mh+2*mn-ma)*931 # in MeV\n",
+ "Bh=B1/Ah\n",
+ "print\"\\n The mean binding energy of helium atom in MeV is =\",Bh\n",
+ "\n",
+ "# part (b)\n",
+ "\n",
+ "B2=(8*mh+8*mn-mo)*931 # in MeV\n",
+ "Bo=B2/Ao\n",
+ "print\"\\n The mean binding energy of oxygen atom in MeV is =\",Bo\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.12, Page:12 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The mean binding energy of Be atom in MeV is = 7.05928572321\n",
+ "From previous problem we have the avg. binding energy of helium atom is 7.08 MeV, Hence Be is unstable to fission into 2 alphas\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of \n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.12, Page:12 \\n \\n\"\n",
+ "#Given:\n",
+ "mh=1.0078;\n",
+ "mn=1.0087;\n",
+ "ABe=8.0053; # atomic mass of beryllium\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "B1=(4*mh+4*mn-ABe)*931; # in MeV\n",
+ "Bh=B1/ABe;\n",
+ "print\"\\n The mean binding energy of Be atom in MeV is =\",Bh\n",
+ "\n",
+ "print\"From previous problem we have the avg. binding energy of helium atom is 7.08 MeV, Hence Be is unstable to fission into 2 alphas\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.13, Page:12 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The amount of coal required in Kg is = 2499.85671416\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of amount of coal\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.13, Page:12 \\n \\n\"\n",
+ "#Given:\n",
+ "\n",
+ "e=200; # in Mev\n",
+ "m=0.235; # weight of uranium atom in Kg\n",
+ "enthalpy=393.5; # in KJ/mol\n",
+ "Na=6.02*10**23;\n",
+ "\n",
+ "\n",
+ "#solution:\n",
+ "e1=e*1.6*10**-19*10**6;\n",
+ "atoms=Na/m;\n",
+ "e2=atoms*e1;#energy released in J\n",
+ "m1=(e2*12)/(393.5*1000*1000);# in Kg\n",
+ "m2=m1/1000;# in tons\n",
+ "print\"\\n The amount of coal required in Kg is =\", m2\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.14, Page:13 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The energy release in part (a) in eV/molecule is = 2.51472\n",
+ "\n",
+ " The energy release in part (b) in eV/molecule is = 9.22688\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The energy releases\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.14, Page:13 \\n \\n\"\n",
+ "#Given:\n",
+ "H1=241.8; # in KJ/mol\n",
+ "H2=887.2; # in KJ/mol\n",
+ "# 1 KJ/mol = 0.0104 eV/atom\n",
+ "\n",
+ "#solution: part (a)\n",
+ "e1=H1*0.0104;\n",
+ "print\"\\n The energy release in part (a) in eV/molecule is =\",e1\n",
+ "\n",
+ "#solution: part (b)\n",
+ "e2=H2*0.0104;\n",
+ "print\"\\n The energy release in part (b) in eV/molecule is =\",e2\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.15, Page:14 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The energy release in part (a) in KJ/mol of carbondioxide is = 394.912\n",
+ "\n",
+ " The energy release in part (b) in KJ/mol of alumina is = 1675.968\n",
+ "\n",
+ " The energy release in part (c) in MJ/atom of U(235) is = 19264000.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The energy releases\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.15, Page:14 \\n \\n\"\n",
+ "#Given:\n",
+ "H1=4.1; # in eV/molecule\n",
+ "H2=17.4; # in eV/molecule\n",
+ "H3=200;# in MeV/atom of U\n",
+ "\n",
+ "# 1 eV/atom = 96.32 KJ/mol\n",
+ "\n",
+ "#solution: part (a)\n",
+ "e1=H1*96.32;\n",
+ "print\"\\n The energy release in part (a) in KJ/mol of carbondioxide is =\",e1\n",
+ "\n",
+ "#solution: part (b)\n",
+ "e2=H2*96.32;\n",
+ "print\"\\n The energy release in part (b) in KJ/mol of alumina is =\",e2\n",
+ "\n",
+ "#solution: part (c)\n",
+ "e3=H3*1000*96.32;# in MJ/atom of U(235)\n",
+ "print\"\\n The energy release in part (c) in MJ/atom of U(235) is =\",e3\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.16, Page:15 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The rate of energy release in W is 949251379.039\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The rate of energy release\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.16, Page:15 \\n \\n\"\n",
+ "#Given:\n",
+ "e=200; #MeV/ atom of U\n",
+ "# 1 eV = 1.6*10^-19 J\n",
+ "Na=6.023*10**23;\n",
+ "M=0.235; # mass in Kg\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "e1=e*1.6*10**-19*10**6;\n",
+ "A=Na/M;\n",
+ "e2=A*e1; # energy released in MJ/day\n",
+ "e3=e2/(24*3600);\n",
+ "print\"\\n The rate of energy release in W is \",e3\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 38,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.17, Page:16 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The mass loss in 10^-27 Kg/He formed is = 0.046412244898\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The mass loss\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.17, Page:16 \\n \\n\"\n",
+ "#Given:\n",
+ "e=26.03; # in MeV\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "loss=e/931; #in atomic mass units (u)\n",
+ "# 1 u = 1.66*10^-27 Kg\n",
+ "m=(loss*1.66*10**-27)/(1*10**-27);\n",
+ "print\"\\n The mass loss in 10^-27 Kg/He formed is =\",m\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 39,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.18, Page:17 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The energy loss in MeV is = 4.03123\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of The energy loss\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.18, Page:17 \\n \\n\"\n",
+ "#Given:\n",
+ "mh=1.007825;\n",
+ "mt=3.016049;\n",
+ "md=2.014102;\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "m1=(mh+mt-2*md);\n",
+ "e=(-m1)*931; # in MeV\n",
+ "print\"\\n The energy loss in MeV is =\",e\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.19, Page:18 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The mean binding energy of tritium atom in MeV is = 2.81085817903\n",
+ "\n",
+ " The mean binding energy of nickel atom in MeV is = 8.71580311296\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of mean binding energy of tritium and nickel atom\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.19, Page:18 \\n \\n\"\n",
+ "#Given:\n",
+ "mh=1.007825;\n",
+ "mn=1.008665;\n",
+ "mt=3.016049; # atomic mass of Tritium\n",
+ "mNi=59.93528; # atomic mass of Nickel\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "# part (a)\n",
+ "\n",
+ "B1=(1*mh+2*mn-mt)*931; # in MeV\n",
+ "Bh=B1/mt;\n",
+ "print\"\\n The mean binding energy of tritium atom in MeV is =\",Bh\n",
+ "\n",
+ "# part (b)\n",
+ "\n",
+ "B2=(28*mh+32*mn-mNi)*931; # in MeV\n",
+ "Bo=B2/mNi;\n",
+ "print\"\\n The mean binding energy of nickel atom in MeV is =\",Bo\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 41,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.20, Page:19 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The mean binding energy of Cl (35) atom in MeV is = 8.52810201079\n",
+ "\n",
+ " The mean binding energy of Cl (37) atom in MeV is = 8.57839008383\n",
+ "\n",
+ " The increase in mean binding energy of Cl atom in MeV is = 0.0502880730447\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of mean binding energy of Cl\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.20, Page:19 \\n \\n\"\n",
+ "#Given:\n",
+ "mh=1.00783;\n",
+ "mn=1.00867;\n",
+ "m35=34.96885; # atomic mass of Cl (35)\n",
+ "m37=36.96590; # atomic mass of Cl (37)\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "B1=(17*mh+18*mn-m35)*931; # in MeV\n",
+ "Bh=B1/m35;\n",
+ "print\"\\n The mean binding energy of Cl (35) atom in MeV is =\",Bh\n",
+ "\n",
+ "B2=(17*mh+20*mn-m37)*931; # in MeV\n",
+ "Bo=B2/m37;\n",
+ "print\"\\n The mean binding energy of Cl (37) atom in MeV is =\",Bo\n",
+ "\n",
+ "Bi=Bo-Bh;\n",
+ "print\"\\n The increase in mean binding energy of Cl atom in MeV is =\",Bi\n",
+ "\n",
+ "# NOTE: The answer depends upon how much precise value you take for atomic masses.\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##example 1.21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Example 1.21, Page:20 \n",
+ " \n",
+ "\n",
+ "\n",
+ " The mean binding energy of Na(22) in MeV is = 7.92358978299\n",
+ "\n",
+ " The mean binding energy of Na(23)in MeV is = 8.11544250059\n",
+ "\n",
+ " The mean binding energy of Na(24) in MeV is = 8.07172719656\n"
+ ]
+ }
+ ],
+ "source": [
+ "#cal of mean binding energy of Na\n",
+ "#intiation of all variables\n",
+ "# Chapter 1\n",
+ "print\"Example 1.21, Page:20 \\n \\n\"\n",
+ "#Given:\n",
+ "mh=1.0078;\n",
+ "mn=1.0087;\n",
+ "m22=21.99431;# atomic mass of Na 22\n",
+ "m23=22.9898;# atomic mass of Na 23\n",
+ "m24=23.9909;# atomic mass of Na 24\n",
+ "\n",
+ "#solution:\n",
+ "\n",
+ "# part (a)\n",
+ "\n",
+ "B1=((11*mh+11*mn)-m22)*931; # in MeV\n",
+ "Bh=B1/m22;\n",
+ "print\"\\n The mean binding energy of Na(22) in MeV is =\",Bh\n",
+ "\n",
+ "# part (b)\n",
+ "\n",
+ "B2=((11*mh+12*mn)-m23)*931; # in MeV\n",
+ "Bo=B2/m23;\n",
+ "print\"\\n The mean binding energy of Na(23)in MeV is =\",Bo\n",
+ "\n",
+ "# part (c)\n",
+ "\n",
+ "B3=((11*mh+13*mn)-m24)*931; # in MeV\n",
+ "Bs=B3/m24;\n",
+ "print\"\\n The mean binding energy of Na(24) in MeV is =\",Bs\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/sample_notebooks/RohithYeedulapalli/Chapter_7.ipynb b/sample_notebooks/RohithYeedulapalli/Chapter_7.ipynb
new file mode 100755
index 00000000..c41c4cd6
--- /dev/null
+++ b/sample_notebooks/RohithYeedulapalli/Chapter_7.ipynb
@@ -0,0 +1,232 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 7:LASERS "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example 7.1, Page number 7.32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Divergence = 0.5 *10**-3 radian\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#variable declaration\n",
+ "r1 = 2; #in radians\n",
+ "r2 = 3; #in radians\n",
+ "d1 = 4; #Converting from mm to radians\n",
+ "d2 = 6; #Converting from mm to radians\n",
+ "\n",
+ "#calculations\n",
+ "D = (r2-r1)/(d2*10**3-d1*10**3)\n",
+ "\n",
+ "#Result\n",
+ "print \"Divergence =\",round(D*10**3,3),\"*10**-3 radian\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example 7.2, Page number 7.32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Frequency (V) = 4.32 *10**14 Hz\n",
+ "Relative Population= 1.081 *10**30\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "from __future__ import division\n",
+ "from sympy import *\n",
+ "#variable declaration\n",
+ "C=3*10**8 #The speed of light\n",
+ "L=6943 #Wavelength\n",
+ "T=300 #Temperature in Kelvin\n",
+ "h=6.626*10**-34 #Planck constant \n",
+ "k=1.38*10**-23 #Boltzmann's constant\n",
+ "\n",
+ "#Calculations\n",
+ "\n",
+ "V=(C)/(L*10**-10)\n",
+ "R=math.exp(h*V/(k*T))\n",
+ "\n",
+ "#Result\n",
+ "print \"Frequency (V) =\",round(V/10**14,2),\"*10**14 Hz\"\n",
+ "print \"Relative Population=\",round(R/10**30,3),\"*10**30\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example 7.3, Page number 7.32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " Frequency= 4.74 *10**14 Hz\n",
+ "no.of photons emitted= 7.322 *10**15 photons/sec\n",
+ "Power density = 2.3 kWm**-2\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "C=3*10**8 #Velocity of light\n",
+ "W=632.8*10**-9 #wavelength\n",
+ "P=2.3\n",
+ "t=1\n",
+ "h=6.626*10**-34 #Planck constant \n",
+ "S=1*10**-6\n",
+ "\n",
+ "#Calculations\n",
+ "V=C/W #Frequency\n",
+ "n=((P*10**-3)*t)/(h*V) #no.of photons emitted\n",
+ "PD=P*10**-3/S\n",
+ "\n",
+ "#Result\n",
+ "print \"Frequency=\",round(V/10**14,2),\"*10**14 Hz\"\n",
+ "print \"no.of photons emitted=\",round(n/10**15,3),\"*10**15 photons/sec\"\n",
+ "print \"Power density =\",round(PD/1000,1),\"kWm**-2\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example 7.4, Page number 7.33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Wavelenght = 8628.0 Angstrom\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "#variable declaration\n",
+ "h=6.626*10**-34 #Planck constant \n",
+ "C=3*10**8 #Velocity of light\n",
+ "E_g=1.44 #bandgap \n",
+ "\n",
+ "#calculations\n",
+ "W=(h*C)*10**10/(E_g*1.6*10**-19)\n",
+ "\n",
+ "#Result\n",
+ "print \"Wavelenght =\",round(W),\"Angstrom\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example 7.5, Page number 7.33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Band gap = 0.8 eV\n"
+ ]
+ }
+ ],
+ "source": [
+ "import math\n",
+ "\n",
+ "#variable declaration\n",
+ "W=1.55 #wavelength\n",
+ "\n",
+ "#Calculations\n",
+ "E_g=(1.24)/W #Bandgap in eV \n",
+ "\n",
+ "#Result\n",
+ "print \"Band gap =\",E_g,\"eV\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/sample_notebooks/Sabiya/Chapter9_1.ipynb b/sample_notebooks/Sabiya/Chapter9_1.ipynb
new file mode 100755
index 00000000..d700ac81
--- /dev/null
+++ b/sample_notebooks/Sabiya/Chapter9_1.ipynb
@@ -0,0 +1,460 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:55d62edc09823ce69cb883c8ec8f5b8abe049583981245da7e91d5fefcb128cb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter9 - Special Oscilloscopes"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.14.1 - page : 9-45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# peak to peak voltage and rms voltage\n",
+ "vdv=1 # V/div\n",
+ "n=6.8 #no. of divisions\n",
+ "Vpp=vdv*n #peak to peak voltage in V\n",
+ "vrms=Vpp/(2*(2)**(1.0/2)) #rms voltage in V\n",
+ "print \"Peak to peak voltage is \",Vpp,\" V\"\n",
+ "print \"rms voltage is \",round(vrms,4),\" V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Peak to peak voltage is 6.8 V\n",
+ "rms voltage is 2.4042 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.14.2 - page : 9-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Time interval\n",
+ "vdv=2 # V per division in micro seconds/div\n",
+ "n=2 #no. of divisions\n",
+ "Tint=vdv*n #peak to peak voltage in V\n",
+ "print \"Time interval is \",Tint,\" micro seconds\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Time interval is 4 micro seconds\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.14.3 - page : 9-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# period and frequency\n",
+ "vdv=2 #volts per division in micro seconds/div\n",
+ "n=12 #no. of divisions\n",
+ "Tp=vdv*n # period in micro seconds\n",
+ "f=1/(Tp*10**-3) #frequency in kHz\n",
+ "print \"Period is \",Tp,\" micro seconds\"\n",
+ "print \"Frequency is \",round(f,2),\" kHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Period is 24 micro seconds\n",
+ "Frequency is 41.67 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.14.4 - page : 9-47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Peak to peak voltage and frequency\n",
+ "vdv1=0.5 #volts per division in V/div\n",
+ "nv=3 #no. of divisions\n",
+ "nh=4 #numbers of horizontal divisions\n",
+ "Vpp=vdv1*nv #peak to peak voltage in V\n",
+ "vdv2=2 # time division in micro seconds per divisions\n",
+ "Tp=vdv2*nh # period in micro seconds\n",
+ "f=1/(Tp*10**-3) #frequency in kHz\n",
+ "print \"Peak to peak voltage is \",Vpp,\" V\"\n",
+ "print \"Period is \",Tp,\" micro seconds\"\n",
+ "print \"Frequency is \",f,\" kHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Peak to peak voltage is 1.5 V\n",
+ "Period is 8 micro seconds\n",
+ "Frequency is 125.0 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.17.1 - page : 9-67"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#bandwidth\n",
+ "#given data :\n",
+ "Trs=12 #in micro sec\n",
+ "Trd=15 #in micro sec\n",
+ "Tro=(Trd**2-Trs**2)**(1.0/2) \n",
+ "K=0.35 # constant\n",
+ "BW=(K/Tro)*10**3 \n",
+ "print \"Bandwidth, BW =\",round(BW,2), \" kHz\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Bandwidth, BW = 38.89 kHz\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.17.2 - page : 9-68"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Rise time\n",
+ "#given data :\n",
+ "BW=10*10**6 # in Hz\n",
+ "tr=(0.35/BW)*10**9 \n",
+ "print \"Rise time, tr = \",tr, \" ns\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rise time, tr = 35.0 ns\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.17.3 - page : 9-68"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# rise time\n",
+ "#given data :\n",
+ "Tro=10 #in micro sec\n",
+ "Trd=13 #in micro sec\n",
+ "Trs=(Trd**2-Tro**2)**(1.0/2) \n",
+ "print \"Actual rise time, Trs = \",round(Trs,2),\" ns\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Actual rise time, Trs = 8.31 ns\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.17.4 - page : 9-68"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Rise time\n",
+ "#given data :\n",
+ "Tro=10 #in micro sec\n",
+ "Trd=15 #in micro sec\n",
+ "Trs=(Trd**2-Tro**2)**(1.0/2)\n",
+ "print \"Actual rise time, Trs = \",round(Trs,2),\" ns\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Actual rise time, Trs = 11.18 ns\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.17.5 - page : 9-68"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Rise time\n",
+ "#given data :\n",
+ "Trs=12 #in micro sec\n",
+ "Trd=30 #in micro sec\n",
+ "BW=20*10**6 # in Hz\n",
+ "K=0.35 # constant\n",
+ "Tro=(K/BW)*10**9 \n",
+ "Trs=(Trd**2-Tro**2)**(1.0/2)\n",
+ "print \"Actual rise time, Trs = \",round(Trs,2),\" ns\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Actual rise time, Trs = 24.37 ns\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.17.6 - page : 9-69"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# capacitance\n",
+ "#given data :\n",
+ "K=10 # constant\n",
+ "C2=35*10**-12 \n",
+ "C1=(C2/(K-1))*10**12 \n",
+ "print \"Capacitance, C1 = \",round(C1,2),\" pF\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacitance, C1 = 3.89 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.17.7 - page : 9-69"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# impedance of CRO\n",
+ "K=10 \n",
+ "vin=1 #vpp \n",
+ "vout=0.1 #in vpp\n",
+ "c1=2 # in pF\n",
+ "c2=c1*(K-1) #CAPACITANCE IN Pf\n",
+ "print \"Capacitance is \",c2,\" pF\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Capacitance is 18 pF\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.17.8 - page : 9-70"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# sensivity\n",
+ "n=2 #divisions\n",
+ "f=50.0 #in MHz\n",
+ "t=(1/f)*10**3 #time in nanao seconds\n",
+ "mdv=t/4 #in ns/div\n",
+ "mtds=mdv*n # in ns/div\n",
+ "print \"Minimum time/div is \",mdv,\" ns/div\"\n",
+ "print \"Minimum time/div setting is \",mtds,\" ns/div\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Minimum time/div is 5.0 ns/div\n",
+ "Minimum time/div setting is 10.0 ns/div\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9.17.9 - page : 9-70"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "# rise time\n",
+ "#given data :\n",
+ "Trs=21 #in micro-sec\n",
+ "K=0.35 # constant\n",
+ "BW=50*10**6 # in Hz\n",
+ "Tro=(K/BW)*10**9 \n",
+ "Trd=(Trs**2+Tro**2)**(1.0/2)\n",
+ "print \"Rise time, Tro = \",round(Trd,0),\" ns\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rise time, Tro = 22.0 ns\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/SaleemAhmed/generation.ipynb b/sample_notebooks/SaleemAhmed/generation.ipynb
new file mode 100755
index 00000000..3d7aab33
--- /dev/null
+++ b/sample_notebooks/SaleemAhmed/generation.ipynb
@@ -0,0 +1,429 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "chapter-2, Economics of generation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1, Page 73"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "#To Determine the Demand and Supply Parameters for 15 bulbs\n",
+ "\n",
+ "W=60 #Wattage of the bulb\n",
+ "N=15 #No. of bulbs\n",
+ "CL=W*N #Connected Load \n",
+ "Wih=2*(10**3) #Wattage of immersion heater\n",
+ "Wh=2*(10**3) #Wattage of heater\n",
+ "\n",
+ "#Usage of Bulbs at different time periods\n",
+ "N1=5 \n",
+ "N2=10 \n",
+ "N3=6\n",
+ "\n",
+ "#Time periods for bulbs\n",
+ "T1=2 #6pm - 8pm\n",
+ "T2=2 #8pm - 10pm\n",
+ "T3=2 #10pm - 12pm\n",
+ "#Time Periods for heaters\n",
+ "T4=4 #1pm - 5pm\n",
+ "T5=3 #8pm - 11pm\n",
+ "\n",
+ "#CASE 1\n",
+ "MD1=W*N2 #Maximum Demand\n",
+ "DF=MD1*100/CL #Demand Factor\n",
+ "EC1=(N1*W*T1)+(N2*W*T2)+(N3*W*T3) #Energy Consumed\n",
+ "DLF1=EC1*100/(24*MD1) #Daily Load Factor\n",
+ "\n",
+ "#CASE 2\n",
+ "MD2=(W*N2)+Wh #From 8pm - 10pm\n",
+ "EC2=(T4*Wih)+(T5*Wh)+EC1 #Energy Consumed\n",
+ "DLF2=EC2*100/(24*MD2) #Daily Load Factor\n",
+ "\n",
+ "print '''i)a) Connected Load is %0.2f W\\nb) The Maximum Demand is %0.2f W\n",
+ "c) The Demand Factor is %0.2f percent\\nd) The Daily Load Factor is %0.2f percent''' %(CL,MD1,DF,DLF1)\n",
+ "print 'ii) The Improved Daily Load Factor is %0.2f percent' %DLF2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i)a) Connected Load is 900.00 W\n",
+ "b) The Maximum Demand is 600.00 W\n",
+ "c) The Demand Factor is 66.67 percent\n",
+ "d) The Daily Load Factor is 17.50 percent\n",
+ "ii) The Improved Daily Load Factor is 26.47 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2, Page 74"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "\n",
+ "#To determine the Demand and supply parameter of four consumers\n",
+ "\n",
+ "\n",
+ "#Maximum Demands of various users\n",
+ "MD1=2*(10**3) #9pm\n",
+ "MD2=2*(10**3) #12 noon\n",
+ "MD3=8*(10**3) #5pm\n",
+ "MD4=4*(10**3) #8pm\n",
+ "MDT=MD1+MD2+MD3+MD4 #Sum of all Maximum Demands\n",
+ "\n",
+ "#Demands of various users\n",
+ "D1=1.6*(10**3) #8pm\n",
+ "D2=1*(10**3) #8pm\n",
+ "D3=5*(10**3) #8pm\n",
+ "\n",
+ "#The Number after the Alphabets represents the Consumer\n",
+ "\n",
+ "#Maximum Demand of the System arises at 8.00 PM\n",
+ "MDS = D1+D2+D3+MD4 \n",
+ "\n",
+ "TDF=MDT/MDS #Diversity Factor\n",
+ "#Given Values\n",
+ "#Average Loads\n",
+ "AL2=500 \n",
+ "AL4=1000 \n",
+ "#Load Factors\n",
+ "LF1=15/100 \n",
+ "LF3=25/100 \n",
+ "#Calculated Values\n",
+ "#Average Loads\n",
+ "AL1=LF1*MD1 \n",
+ "AL3=LF3*MD3 \n",
+ "#Load Factors\n",
+ "LF2=AL2*100/MD2 \n",
+ "LF4=AL4*100/MD4 \n",
+ "\n",
+ "ALS=AL1+AL2+AL3+AL4 #Combined Average Loads\n",
+ "LFS=ALS*100/MDS #Combined Load Factor\n",
+ "\n",
+ "#Load Percent\n",
+ "LF1*=100 # %\n",
+ "LF3*=100 # %\n",
+ "\n",
+ "print 'i) The Diversity Factor is %0.2f' %TDF\n",
+ "print 'ii) The Average load and Load factor of:'\n",
+ "print ' Consumer 1 : %0.2f W and %0.2f percent' %(AL1,LF1)\n",
+ "print ' Consumer 2 : %0.2f W and %0.2f percent' %(AL2,LF2)\n",
+ "print ' Consumer 3 : %0.2f W and %0.2f percent' %(AL3,LF3)\n",
+ "print ' Consumer 4 : %0.2f W and %0.2f percent' %(AL4,LF4)\n",
+ "print 'iii) The Combined Load Factor and the Combined Average Load is %0.2f percent and %0.2f W respectively\\n' %(LFS,ALS)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i) The Diversity Factor is 1.38\n",
+ "ii) The Average load and Load factor of:\n",
+ " Consumer 1 : 300.00 W and 15.00 percent\n",
+ " Consumer 2 : 500.00 W and 25.00 percent\n",
+ " Consumer 3 : 2000.00 W and 25.00 percent\n",
+ " Consumer 4 : 1000.00 W and 25.00 percent\n",
+ "iii) The Combined Load Factor and the Combined Average Load is 32.76 percent and 3800.00 W respectively\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3, Page 75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from __future__ import division\n",
+ "\n",
+ "#To Determine the Yearly Cost of the substation\n",
+ "\n",
+ "Teff=95/100 #Transmission Efficiency\n",
+ "Deff=85/100 #Distribution Efficiency\n",
+ "DFT=1.2 #Diversity Factor For Transmission\n",
+ "DFD=1.3 #Diversity Factor For Distribution\n",
+ "MDGS=100*(10**6) #Maximum Demand of Generating Station\n",
+ "ALF=40/100 #Annual Load Factor\n",
+ "ACCT=2.5*(10**6) #Annual Capital Charge for Transmission\n",
+ "ACCD=2*(10**6) #Annual Capital Charge for Distribution\n",
+ "GCC=100 #Generating Cost per kW demand\n",
+ "GCCU=5/100 # Per Unit Cost\n",
+ "#Fixed Charges from Supply to Substation Annually\n",
+ "GFC=GCC*MDGS/1000 #Generating\n",
+ "TFC=ACCT #Transmission\n",
+ "TotFCS=GFC+TFC #Total\n",
+ "#Fixed Charges for supply upto Consumer Annually\n",
+ "DFC=ACCD #Distribution\n",
+ "TotFCC=TotFCS+DFC #Total\n",
+ "\n",
+ "AMDS= DFT*MDGS/1000 #Aggregate of Maximum Demand at Supply\n",
+ "AMDC= DFD*AMDS #Aggregate of Maximum Demand for Consumers\n",
+ "\n",
+ "FCS=TotFCS/AMDS #Fixed Charges Per KW at substation\n",
+ "CES=GCCU/Teff #Cost of energy at the substation\n",
+ "\n",
+ "FCC=TotFCC/AMDC #Fixed Charges per KW at the consumer premises\n",
+ "CEC=CES/Deff #Cost of Energy at the consumer premises\n",
+ "\n",
+ "CEC*=100 # converting from rupee to paise\n",
+ "\n",
+ "print 'The Yealy Cost per KW demand and the cost per KWhr at:'\n",
+ "print 'a) The substation is %0.2f rupees per KW and %0.2f paise per kWhr'%(FCS,CES)\n",
+ "print 'b) The consumer premises is %g rupees per KW and %g paise per kWhr' %(FCC,CEC)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Yealy Cost per KW demand and the cost per KWhr at:\n",
+ "a) The substation is 104.17 rupees per KW and 0.05 paise per kWhr\n",
+ "b) The consumer premises is 92.9487 rupees per KW and 6.19195 paise per kWhr\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex4, Page 78"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To determine the Load factor and suitable units for 24 hr operation of the plant\n",
+ "\n",
+ "\n",
+ "#Demands at Various Time Periods starting from 12PM to 12PM\n",
+ "D1=500*(10**3) \n",
+ "D2=800*(10**3) \n",
+ "D3=2000*(10**3) \n",
+ "D4=1000*(10**3) \n",
+ "D5=2500*(10**3) \n",
+ "D6=2000*(10**3) \n",
+ "D7=1500*(10**3) \n",
+ "D8=1000*(10**3) \n",
+ "\n",
+ "MD=D5 #Maximum Demand\n",
+ "#Time Periods of demands from 12PM\n",
+ "T1=5 \n",
+ "T2=5 \n",
+ "T3=2 \n",
+ "T4=2 \n",
+ "T5=3 \n",
+ "T6=3 \n",
+ "T7=2 \n",
+ "T8=2 \n",
+ "\n",
+ "#Total Energy Demand in 24hrs\n",
+ "TED=(T1*D1)+(T2*D2)+(T3*D3)+(D4*T4)+(T5*D5)+(D6*T6)+(D7*T7)+(T8*D8) \n",
+ "\n",
+ "LF=TED*100/(24*MD) \n",
+ "\n",
+ "C1000=3*1000*(10**3) #1000 unit \n",
+ "C500=1*500*(10**3) #500 Unit\n",
+ "\n",
+ "TCP=C1000+C500 #Total capacity of the plant\n",
+ "PCF=TED*100/(24*TCP) #Plant Capacity Factor\n",
+ "\n",
+ "#Operating Schedule, Units operated can be seen in the textbook\n",
+ "G1=500*(10**3) \n",
+ "G2=1000*(10**3) \n",
+ "G3=2000*(10**3) \n",
+ "G4=1000*(10**3) \n",
+ "G5=2500*(10**3) \n",
+ "G6=2000*(10**3) \n",
+ "G7=1500*(10**3) \n",
+ "G8=1000*(10**3) \n",
+ "\n",
+ "TEG=(T1*G1)+(T2*G2)+(T3*G3)+(G4*T4)+(T5*G5)+(G6*T6)+(G7*T7)+(T8*G8) #Total Energy Generated\n",
+ "PUF=TED*100/(TEG) #Plant Use Factor\n",
+ "\n",
+ "print 'a) The Reserve Capacity is a 1000kW Unit and Load Factor is %0.2f percent' %LF\n",
+ "print 'b) The Plant Capacity Factor is %0.2f percent' %PCF\n",
+ "print 'c) The Plant Use Factor is %0.2f percent' %PUF"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a) The Reserve Capacity is a 1000kW Unit and Load Factor is 51.67 percent\n",
+ "b) The Plant Capacity Factor is 36.90 percent\n",
+ "c) The Plant Use Factor is 96.88 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex5, Page 80"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To determine the Plant use factore of each unit\n",
+ "\n",
+ "\n",
+ "MDS=25*(10**6) #Maximum Demand on the System\n",
+ "U1=15*(10**6) #Load Supplied By Unit 1\n",
+ "U2=12.5*(10**6) #Load Supplied By Unit 2\n",
+ "#Running Time Factor of the Unit\n",
+ "T1=1 \n",
+ "T2=40/100 \n",
+ "\n",
+ "#Energy generated by each unit\n",
+ "E1=1*(10**8) \n",
+ "E2=1*(10**7) \n",
+ "Et=E1+E2 #Total Energy\n",
+ "\n",
+ "#Maximum Demands on Each Units\n",
+ "MD1=U1 \n",
+ "MD2=MDS-U1 \n",
+ "\n",
+ "#Annual Load Factor for the Units\n",
+ "ALF1=E1*1000*100/(MD1*8760) \n",
+ "ALF2=E2*1000*100/(MD2*8760) \n",
+ "\n",
+ "LF2=E2*1000*100/(MD2*0.4*8760) #Load Factor for the it is loaded\n",
+ "\n",
+ "\n",
+ "PUF1=ALF1 #Plant Use Factor\n",
+ "PCF1=ALF1 # Plant Capacity Factor\n",
+ "\n",
+ "PCF2=E2*1000*100/(U2*8760) #Plant Capacity Factor for Unit 2\n",
+ "PUF2=E2*1000*100/(U2*0.4*8760) #Plant Use Factor for Unit 2\n",
+ "\n",
+ "LFP=Et*100*1000/(MDS*8760) #Annual Load Factor of the Complete Plant\n",
+ "\n",
+ "print 'The Load Factor, Plant Capacity Factor, Plant Use Factor of:'\n",
+ "print 'Unit 1 : %0.2f percent, %0.2f percent, %0.2f percent' %(ALF1,PCF1,PUF1)\n",
+ "print 'Unit 2 : %0.2f percent, %0.2f percent, %0.2f percent' %(ALF2,PCF2,PUF2)\n",
+ "print 'The Annual Load Factor of the Entire Plant is %0.2f percent' %LFP"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Load Factor, Plant Capacity Factor, Plant Use Factor of:\n",
+ "Unit 1 : 76.10 percent, 76.10 percent, 76.10 percent\n",
+ "Unit 2 : 11.42 percent, 9.13 percent, 22.83 percent\n",
+ "The Annual Load Factor of the Entire Plant is 50.23 percent\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6, Page 91"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#To determine the most economic power factor\n",
+ "\n",
+ "from numpy import sqrt\n",
+ "\n",
+ "P=200*(10**3) #Maximum Demand\n",
+ "pf=0.707 #Power Factor Lagging\n",
+ "\n",
+ "a=100 #Tariff per kVA per year\n",
+ "\n",
+ "b=200 #Power factor improvement cost Per kVA.\n",
+ "r=20 #Interest Depriciation, maintenance and cost of losses amount to 20% of capital cost per year\n",
+ "\n",
+ "# Economic PF = sqrt(1-((b1/a)**2))\n",
+ "\n",
+ "b1=r*b/100 # b' term accrding to the equation above\n",
+ "\n",
+ "pfeco=sqrt(1-((b1/a)**2)) #Economic Power Factor\n",
+ "\n",
+ "print 'The Economic Power Factor is %0.2f ' %pfeco\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Economic Power Factor is 0.92 \n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/sample_notebooks/SandhyaArroju/Chapter5.ipynb b/sample_notebooks/SandhyaArroju/Chapter5.ipynb
new file mode 100755
index 00000000..2e530c83
--- /dev/null
+++ b/sample_notebooks/SandhyaArroju/Chapter5.ipynb
@@ -0,0 +1,303 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#5: Conducting Materials"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.1, Page number 5.34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "drift speed is 36.6 *10**-5 m/s\n",
+ "mean free path is 3.34 *10**-8 m\n",
+ "answer given in the book is wrong\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "Na=6.023*10**26; #avagadro number\n",
+ "e=1.602*10**-19;\n",
+ "d=8960; #density\n",
+ "N=1; #number of free electrons\n",
+ "w=63.54; #atomic weight\n",
+ "i=10; #current(ampere)\n",
+ "m=9.1*10**-31; \n",
+ "rho=2*10**-8; #resistivity(ohm m)\n",
+ "r=0.08*10**-2; #radius(m)\n",
+ "c=1.6*10**6; #mean thermal velocity(m/s)\n",
+ "\n",
+ "#Calculation\n",
+ "A=math.pi*r**2; #area(m**2)\n",
+ "n=Na*d*N/w;\n",
+ "vd=i/(A*n*e); #drift speed(m/s)\n",
+ "tow_c=m/(n*e**2*rho);\n",
+ "lamda=tow_c*c; #mean free path(m)\n",
+ "\n",
+ "#Result\n",
+ "print \"drift speed is\",round(vd*10**5,1),\"*10**-5 m/s\"\n",
+ "print \"mean free path is\",round(lamda*10**8,2),\"*10**-8 m\"\n",
+ "print \"answer given in the book is wrong\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.2, Page number 5.35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "electrical conductivity is 4.8 *10**7 ohm-1 m-1\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.602*10**-19;\n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "tow=2*10**-14; #time(s)\n",
+ "n=8.5*10**28; \n",
+ "\n",
+ "#Calculation\n",
+ "sigma=n*e**2*tow/m; #electrical conductivity(ohm-1 m-1)\n",
+ "\n",
+ "#Result\n",
+ "print \"electrical conductivity is\",round(sigma/10**7,1),\"*10**7 ohm-1 m-1\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.3, Page number 5.35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "relaxation time is 4.0 *10**-14 s\n",
+ "mobility of electrons is 7.0 *10**-3 m**2/Vs\n",
+ "drift velocity is 0.7 m/s\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.6*10**-19;\n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "n=5.8*10**28; \n",
+ "rho=1.54*10**-8; #resistivity(ohm m)\n",
+ "E=1*10**2;\n",
+ "\n",
+ "#Calculation\n",
+ "tow=m/(rho*n*e**2); #relaxation time(s)\n",
+ "mew_e=1/(rho*e*n); #mobility of electrons(m**2/Vs)\n",
+ "vd=mew_e*E; #drift velocity(m/s)\n",
+ "\n",
+ "#Result\n",
+ "print \"relaxation time is\",round(tow*10**14),\"*10**-14 s\"\n",
+ "print \"mobility of electrons is\",round(mew_e*10**3),\"*10**-3 m**2/Vs\"\n",
+ "print \"drift velocity is\",round(vd,1),\"m/s\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.4, Page number 5.35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "resistivity is 5.51 *10**-8 ohm m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "rho=1.7*10**-8; #resistivity(ohm m)\n",
+ "T=300; #temperature(K)\n",
+ "T1=973; #temperature(K)\n",
+ "\n",
+ "#Calculation\n",
+ "a=rho/T; \n",
+ "rho_973=a*T1; #resistivity(ohm m)\n",
+ "\n",
+ "#Result\n",
+ "print \"resistivity is\",round(rho_973*10**8,2),\"*10**-8 ohm m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.5, Page number 5.36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "increase of resistivity is 0.54 *10**-8 ohm m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "rho1=1.2*10**-8; #resistivity(ohm m)\n",
+ "rho2=0.12*10**-8; #resistivity(ohm m)\n",
+ "p1=0.4; #atomic percent\n",
+ "p2=0.5; #atomic percent\n",
+ "rho=1.5*10**-8; #resistivity(ohm m)\n",
+ "\n",
+ "#Calculation\n",
+ "rho_i=(rho1*p1)+(rho2*p2); #increase of resistivity(ohm m)\n",
+ "Tr=rho+rho_i; #total resistivity of copper alloy(ohm m)\n",
+ "\n",
+ "#Result\n",
+ "print \"increase of resistivity is\",round(rho_i*10**8,2),\"*10**-8 ohm m\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example number 5.6, Page number 5.36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "electrical conductivity is 1.688 *10**7 ohm-1 m-1\n",
+ "thermal conductivity is 123.93 W/m/K\n",
+ "lorentz number is 2.447 *10**-8 watt ohm K-2\n"
+ ]
+ }
+ ],
+ "source": [
+ "#importing modules\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "\n",
+ "#Variable declaration\n",
+ "e=1.6*10**-19;\n",
+ "m=9.1*10**-31; #mass(kg)\n",
+ "n=6*10**28; #density(per m**3)\n",
+ "tow=10**-14; #relaxation time(s)\n",
+ "T=300; #temperature(K)\n",
+ "k=1.38*10**-23; #boltzmann constant\n",
+ "\n",
+ "#Calculation\n",
+ "sigma=n*e**2*tow/m; #electrical conductivity(ohm-1 m-1)\n",
+ "K=n*math.pi**2*k**2*T*tow/(3*m); #thermal conductivity(W/m/K)\n",
+ "L=K/(sigma*T); #lorentz number(watt ohm K-2)\n",
+ "\n",
+ "#Result\n",
+ "print \"electrical conductivity is\",round(sigma/10**7,3),\"*10**7 ohm-1 m-1\"\n",
+ "print \"thermal conductivity is\",round(K,2),\"W/m/K\"\n",
+ "print \"lorentz number is\",round(L*10**8,3),\"*10**-8 watt ohm K-2\""
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/sample_notebooks/SoumenGanguly/ncert_Maths.ipynb b/sample_notebooks/SoumenGanguly/ncert_Maths.ipynb
new file mode 100755
index 00000000..30efaf66
--- /dev/null
+++ b/sample_notebooks/SoumenGanguly/ncert_Maths.ipynb
@@ -0,0 +1,355 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Chapter 1: Sets\n",
+ "========"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Example 1, Page 03:\n",
+ "----------------------"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false,
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Therefore, the solution set of the given equation can be written in roaster form as {-2,1}\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "coeff = [1,1,-2]\n",
+ "\n",
+ "#Calculations\n",
+ "roots_array = np.roots(coeff)\n",
+ "\n",
+ "#Result\n",
+ "print \"Therefore, the solution set of the given equation can be written in roaster form as {%d,%d}\"%(roots_array[0],roots_array[1])\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Example 2, Page 03:\n",
+ "---------------------"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The required numbers are 1,2,3,4,5,6\n",
+ "So, the given set in the roster form is {1,2,3,4,5,6}\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Variable declaration\n",
+ "pos_integer = []\n",
+ "\n",
+ "#Calculations\n",
+ "for i in range(1,1000): #1000 is taken as the upper limit of a positive integer\n",
+ " if i**2<40:\n",
+ " pos_integer.append(i)\n",
+ " \n",
+ "#Result\n",
+ "print \"The required numbers are %d,%d,%d,%d,%d,%d\"%(pos_integer[0],pos_integer[1],pos_integer[2],pos_integer[3],pos_integer[4],pos_integer[5])\n",
+ "print \"So, the given set in the roster form is {%d,%d,%d,%d,%d,%d}\"%(pos_integer[0],pos_integer[1],pos_integer[2],pos_integer[3],pos_integer[4],pos_integer[5])\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Example 12, Page 14:\n",
+ "-----------------------"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The union of the two given arrays is \n",
+ "[ 2 4 6 8 10 12]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "a = [2,4,6,8]\n",
+ "b = [6,8,10,12]\n",
+ "\n",
+ "#Calculations\n",
+ "union_array = np.union1d(a,b)\n",
+ "\n",
+ "#Result\n",
+ "print \"The union of the two given arrays is \"\n",
+ "print union_array"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Example 13, Page 14:\n",
+ "-----------------------"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A U B = ['a' 'e' 'i' 'o' 'u']\n",
+ "A = ['a', 'e', 'i', 'o', 'u']\n",
+ "Thus, A U B = A\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "a = ['a','e','i','o','u']\n",
+ "b = ['a','i','u']\n",
+ "\n",
+ "#Calculations\n",
+ "union_array = np.union1d(a,b)\n",
+ "\n",
+ "#Result\n",
+ "print \"A U B = %s\"%(union_array)\n",
+ "print \"A = %s\"%(a)\n",
+ "print \"Thus, A U B = A\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Example 15, Page 15:\n",
+ "----------------------"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A intersection B = [6 8]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "a = [2,4,6,8]\n",
+ "b = [6,8,10,12]\n",
+ "\n",
+ "#Calculations\n",
+ "intersect_array = np.intersect1d(a,b)\n",
+ "\n",
+ "#Result\n",
+ "print \"A intersection B = %s\"%(intersect_array)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Example 18, Page 17:\n",
+ "-----------------------"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A - B = [1 3 5]\n",
+ "B - A = [8]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "a = [1,2,3,4,5,6]\n",
+ "b = [2,4,6,8]\n",
+ "\n",
+ "#Calculations\n",
+ "diff_a = np.setdiff1d(a,b)\n",
+ "diff_b = np.setdiff1d(b,a)\n",
+ "\n",
+ "#Result\n",
+ "print \"A - B = %s\"%(diff_a)\n",
+ "print \"B - A = %s\"%(diff_b)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Example 20, Page 19:\n",
+ "-----------------------"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A' = [ 2 4 6 8 10]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "u = [1,2,3,4,5,6,7,8,9,10]\n",
+ "a = [1,3,5,7,9]\n",
+ "\n",
+ "#Calculations\n",
+ "complement_a = np.setdiff1d(u,a)\n",
+ "\n",
+ "#Result\n",
+ "print \"A' = %s\"%(complement_a)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Example 22, Page 19:\n",
+ "-----------------------"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A' = [1 4 5 6]\n",
+ "B' = [1 2 6]\n",
+ "A' intersection B' = [1 6]\n",
+ "A U B = [2 3 4 5]\n",
+ "(A U B)' = [1 6]\n",
+ "Therefore, (A U B)' = A' intersection B' \n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "#Variable declaration\n",
+ "u = [1,2,3,4,5,6]\n",
+ "a = [2,3]\n",
+ "b = [3,4,5]\n",
+ "\n",
+ "#Calculations\n",
+ "complement_a = np.setdiff1d(u,a)\n",
+ "complement_b = np.setdiff1d(u,b)\n",
+ "intersect_ab = np.intersect1d(complement_a,complement_b)\n",
+ "union_ab = np.union1d(a,b)\n",
+ "complement_union_ab = np.setdiff1d(u,union_ab)\n",
+ "\n",
+ "#Result\n",
+ "print \"A' = %s\"%(complement_a)\n",
+ "print \"B' = %s\"%(complement_b)\n",
+ "print \"A' intersection B' = %s\"%(intersect_ab)\n",
+ "print \"A U B = %s\"%(union_ab)\n",
+ "print \"(A U B)' = %s\"%(complement_union_ab)\n",
+ "print \"Therefore, (A U B)\\' = A\\' intersection B\\' \"\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.8"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/sample_notebooks/Vedantam Lakshmi Manasa/Chapter_2_Electric_Fields.ipynb b/sample_notebooks/Vedantam Lakshmi Manasa/Chapter_2_Electric_Fields.ipynb
new file mode 100755
index 00000000..cdc8b25e
--- /dev/null
+++ b/sample_notebooks/Vedantam Lakshmi Manasa/Chapter_2_Electric_Fields.ipynb
@@ -0,0 +1,296 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 2 Electric Fields"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2_5 pgno:65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Maximum field = V/m per volt 42064315640.1\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Chapter 2, Example 5, page 65\n",
+ "#Calculate the maximum field at the sphere surface\n",
+ "#Calulating Field at surface E based on figure 2.31 and table 2.3\n",
+ "from math import pi\n",
+ "Q1 = 0.25\n",
+ "e0 = 8.85418*10**-12 #Epselon nought\n",
+ "RV1= ((1/0.25**2)+(0.067/(0.25-0.067)**2)+(0.0048/(0.25-0.067)**2))\n",
+ "RV2= ((0.25+0.01795+0.00128)/(0.75-0.067)**2)\n",
+ "RV= RV1+RV2\n",
+ "E = (Q1*RV)/(4*pi*e0)\n",
+ "print\"Maximum field = V/m per volt\",E\n",
+ "\n",
+ "#Answers vary due to round off error\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2_6 pgno:66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "#Chapter 2, Exmaple 6, page 66\n",
+ "#calculation based on figure 2.32\n",
+ "\n",
+ "#(a)Charge on each bundle\n",
+ "print\"Part a\\t\"\n",
+ "req = (0.0175*0.45)**0.5\n",
+ "print\"Equivalent radius = m \", req\n",
+ "from math import log\n",
+ "from math import pi\n",
+ "V = 400*10**3 #Voltage\n",
+ "H = 12. #bundle height in m\n",
+ "d = 9. #pole to pole spacing in m\n",
+ "e0 = 8.85418*10**-12 #Epselon nought\n",
+ "Hd = ((2*H)**2+d**2)**0.5#2*H**2 + d**2\n",
+ "Q = V*2*pi*e0/(log((2*H/req))-log((Hd/d)))\n",
+ "q = Q/2\n",
+ "print\"Charge per bundle = uC/m \",Q #micro C/m\n",
+ "print\"Charge per sunconducter = uC/m \",q #micro C/m\n",
+ "\n",
+ "#(b part i)Maximim & average surface feild\n",
+ "print\"\\tPart b\"\n",
+ "print\"\\tSub part 1\\t\"\n",
+ "r = 0.0175 #subconductor radius\n",
+ "R = 0.45 #conductor to subconductor spacing\n",
+ "MF = (q/(2*pi*e0))*((1/r)+(1/R)) # maximum feild\n",
+ "print\"Maximum feild = kV/m \\t\",MF\n",
+ "MSF = (q/(2*pi*e0))*((1/r)-(1/R)) # maximum surface feild\n",
+ "print\"Maximum feild = kV/m \\t\",MSF\n",
+ "ASF = (q/(2*pi*e0))*(1/r) # Average surface feild\n",
+ "print\"Maximum feild = kV/m \\t\",ASF\n",
+ "\n",
+ "#(b part ii) Considering the two sunconductors on the left\n",
+ "print\"\\tSub part 2\\t\"\n",
+ "#field at the outer point of subconductor #1 \n",
+ "drO1 = 1/(d+r)\n",
+ "dRrO1 = 1/(d+R+r)\n",
+ "EO1 = MF -((q/(2*pi*e0))*(drO1+dRrO1))\n",
+ "print\"EO1 = kV/m \\t\",EO1\n",
+ "#field at the outer point of subconductor #2 \n",
+ "drO2 = 1/(d-r)\n",
+ "dRrO2 = 1/(d-R-r)\n",
+ "EO2 = MF -((q/(2*pi*e0))*(dRrO2+drO2))\n",
+ "print\"EO2 = kV/m \\t\",EO2\n",
+ "\n",
+ "#field at the inner point of subconductor #1 \n",
+ "drI1 = 1/(d-r)\n",
+ "dRrI1 = 1/(d+R-r)\n",
+ "EI1 = MSF -((q/(2*pi*e0))*(drI1+dRrI1))\n",
+ "print\"EI1 = kV/m \\t\",EI1\n",
+ "#field at the inner point of subconductor #2 \n",
+ "drI2 = 1/(d+r)\n",
+ "dRrI2 = 1/(d-R+r)\n",
+ "EI2 = MSF -((q/(2*pi*e0))*(dRrI2+drI2)) \n",
+ "print\"EI2 = kV/m \\t\",EI2\n",
+ "\n",
+ "#(part c)Average of the maximim gradient\n",
+ "print\"\\tPart c\\t\"\n",
+ "Eavg = (EO1+EO2)/2\n",
+ "print\"The average of the maximum gradient = kV/m \\t\",Eavg\n",
+ "\n",
+ "\n",
+ "#Answers might vary due to round off error\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2_7 pgno:69"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Electric Feild = V/m \t30015596280.4\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Chapter 2, Exmaple 7, page 69\n",
+ "#Electric feild induced at x\n",
+ "from math import pi\n",
+ "e0 = 8.85418*10**-12 #Epselon nought\n",
+ "q = 1 # C/m\n",
+ "C = (q/(2*pi*e0))\n",
+ "#Based on figure 2.33\n",
+ "E = C-(C*(1./3.+1./7.))+(C*(1+1./5.+1./9.))+(C*(1./5.+1./9.))-(C*(1./3.+1./7.))\n",
+ "print\"Electric Feild = V/m \\t\",E\n",
+ "\n",
+ "#Answers might vary due to round off error\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2_8 pgno:70"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "Thickness of graded design= cm 4.24264068712\n",
+ "Curve = cm**2 62.4264068712\n",
+ "V1 = cm**3 47402.906725\n",
+ "Thickness of regular design = cm 14.684289433\n",
+ "V2 = cm**3 861.944682812\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Chapter 2, Exmaple 8, page 70\n",
+ "#Calculate the volume of the insulator\n",
+ "#Thinkness of graded design\n",
+ "from math import e\n",
+ "from math import pi\n",
+ "V = 150*(2)**0.5\n",
+ "Ebd = 50\n",
+ "T = V/Ebd\n",
+ "print\"\\nThickness of graded design= cm \",T\n",
+ "#Based on figure 2.24\n",
+ "r = 2 # radius of the conductor\n",
+ "l = 10 #length of graded cylinder; The textbook uses 10 instead of 20\n",
+ "zr = l*(T+r)\n",
+ "print\"Curve = cm**2 \",zr\n",
+ "#Volume of graded design V1\n",
+ "V1 = 4*pi*zr*(zr-r)\n",
+ "print\"V1 = cm**3 \",V1 #Unit is wrong in the textbook\n",
+ "#Thickness of regular design as obtained form Eq.2.77\n",
+ "pow = V/(2*Ebd)\n",
+ "t = 2*(e**pow-1)\n",
+ "print\"Thickness of regular design = cm \",t\n",
+ "#Volume of regular design V2\n",
+ "V2 = pi*((2+t)**2-4)\n",
+ "print\"V2 = cm**3 \",V2#unit not mentioned in textbook\n",
+ " \n",
+ "#Answers may vary due to round off error\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2_11 pgno:75"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The values of Phi2 and Phi4 are: [[ -3.6568 326.5 ]\n",
+ " [ 261.92857143 -4.37537287]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Chapter 2, Exmaple 11, page 75\n",
+ "#Calculate the potential within the mesh\n",
+ "#Based on figure 2.38(b)\n",
+ "#equations are obtained using Eq.2.46\n",
+ "import numpy\n",
+ "from numpy import linalg\n",
+ "A1 = 1/2*(0.54+0.16)\n",
+ "A2 = 1/2*(0.91+0.14)\n",
+ "S = numpy.matrix([[0.5571, -0.4571, -0.1],[-0.4751, 0.828, 0.3667],[-0.1, 0.667, 0.4667]])\n",
+ "#By obtaining the elements of the global stiffness matrix(Sadiku,1994)\n",
+ "#and by emplying the Eq.2.49(a)\n",
+ "S1 = numpy.matrix([[1.25, -0.014],[-0.014, 0.8381]])\n",
+ "S2 = numpy.matrix([[-0.7786, -0.4571],[-0.4571, -0.3667]])\n",
+ "Phi13 = numpy.matrix([[0], [10]])\n",
+ "val1 = S2*Phi13\n",
+ "Phi24 = val1/S1\n",
+ "print\"The values of Phi2 and Phi4 are:\",Phi24\n",
+ "\n",
+ "#Answers may vary due to round of error \n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/sample_notebooks/VidyashankarVenkatraman/Chapter_3_Kittel.ipynb b/sample_notebooks/VidyashankarVenkatraman/Chapter_3_Kittel.ipynb
new file mode 100755
index 00000000..8760577a
--- /dev/null
+++ b/sample_notebooks/VidyashankarVenkatraman/Chapter_3_Kittel.ipynb
@@ -0,0 +1,79 @@
+{
+ "metadata": {
+ "name": "Chapter_3_Kittel"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Introduction to Solid State Physics"
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 3.1, Page Number 84\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#importing module\n\nfrom __future__ import division\nimport math\n\n#Variable declaration\n\ne = 5*pow(10,-10); # charge on the electron\n\nr0 = 1*pow(10,-8); # atomic radius\n\n# Calculation\n\nR = 4*10**(-8); # interatomic distance in cm\n\nU = -4*e**2*r0**5/R**6; # The van der waals interaction formula\n\n# Result\n\nprint \" The Van Der Waals interaction energy is \",U ,\"ergs\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": " The Van Der Waals interaction energy is -2.44140625e-14 ergs\n"
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 3.2, Page Number 91"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#importing module\n\nfrom __future__ import division\nimport math\n\n# Variable declaration\n\ne = 4.8*pow(10,-10); # charge on proton\nr0 = 2.81*pow(10,-8); # distance between positive and nearest negative ion in Nacl crystal\n\nU = e**2/r0; # in ergs\n\nE = U/(1.6019*pow(10,-12)); # converting to eV as 1eV = 1.6019 * 10**(-12) ergs\n\n#result\nprint \" The potential energy of the two ions by themselves is \",E,\"eV\"\n\n\n\n\n\n\n ",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": " The potential energy of the two ions by themselves is 5.11847696874 eV\n"
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/VidyashankarVenkatraman/Chapter_3_Kitteldemo.ipynb b/sample_notebooks/VidyashankarVenkatraman/Chapter_3_Kitteldemo.ipynb
new file mode 100755
index 00000000..26342edb
--- /dev/null
+++ b/sample_notebooks/VidyashankarVenkatraman/Chapter_3_Kitteldemo.ipynb
@@ -0,0 +1,79 @@
+{
+ "metadata": {
+ "name": "Chapter_3_Kittel"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Chapter 3:Introduction to Solid State Physics"
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 3.1, Page Number 84\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#importing module\n\nfrom __future__ import division\nimport math\n\n#Variable declaration\n\ne = 5*pow(10,-10); # charge on the electron\n\nr0 = 1*pow(10,-8); # atomic radius\n\n# Calculation\n\nR = 4*10**(-8); # interatomic distance in cm\n\nU = -4*e**2*r0**5/R**6; # The van der waals interaction formula\n\n# Result\n\nprint \" The Van Der Waals interaction energy is \",U ,\"ergs\"",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": " The Van Der Waals interaction energy is -2.44140625e-14 ergs\n"
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": "Example number 3.2, Page Number 91"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "#importing module\n\nfrom __future__ import division\nimport math\n\n# Variable declaration\n\ne = 4.8*pow(10,-10); # charge on proton\nr0 = 2.81*pow(10,-8); # distance between positive and nearest negative ion in Nacl crystal\n\nU = e**2/r0; # in ergs\n\nE = U/(1.6019*pow(10,-12)); # converting to eV as 1eV = 1.6019 * 10**(-12) ergs\n\n#result\nprint \" The potential energy of the two ions by themselves is \",E,\"eV\"\n\n\n\n\n\n\n ",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": " The potential energy of the two ions by themselves is 5.11847696874 eV\n"
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
diff --git a/sample_notebooks/WaseemAhmad Ansari/Chapter2.ipynb b/sample_notebooks/WaseemAhmad Ansari/Chapter2.ipynb
new file mode 100755
index 00000000..d902c695
--- /dev/null
+++ b/sample_notebooks/WaseemAhmad Ansari/Chapter2.ipynb
@@ -0,0 +1,348 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:3942a48c51f6e66ddeb010a1a5acaeebd4c9f56b964a269d92588d67ccc10453"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2 : Introduction to operational amplifier"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.1 Page no. 88"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Given data\n",
+ "\n",
+ "R1 = 10*10**3 #R1 input resistance \n",
+ "Rf = 100*10**3 # Rf feedback resistance\n",
+ "vi = float(1) #input voltage \n",
+ "RL = 25*10**3\n",
+ "#calculating the values \n",
+ "\n",
+ "i1 = float((vi/R1)*10**3) # input resistace id the ratio of input voltage to the input resitance \n",
+ "vo = float(-(Rf/R1)*vi) # finding the output voltage \n",
+ "iL = float((abs(vo)/RL)*10**3) # calculating the load current \n",
+ "io = float((i1+iL)) # calculating the output current which is equal to the sum of input current and load current\n",
+ "\n",
+ "#printing the values \n",
+ "\n",
+ "print \"The input current i1 =\",i1,\"mA\"\n",
+ "print \"The output voltage vo =\",vo,\"V\"\n",
+ "print \"The load current iL =\",iL,\"mA\"\n",
+ "print \"The output current io =\",io,\"mA\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The input current i1 = 0.1 mA\n",
+ "The output voltage vo = -10.0 V\n",
+ "The load current iL = 0.4 mA\n",
+ "The output current io = 0.5 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.2 Page no.89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Given data\n",
+ "\n",
+ "ACL = 5 # Gain of the amplifier\n",
+ "R1 = 10*10**3 # input resisitance in ohms \n",
+ "\n",
+ "# calculations\n",
+ "\n",
+ "Rf = (5-1) * R1 # calculating the resistance of feedback resistor \n",
+ "\n",
+ "# printing the values \n",
+ "\n",
+ "print \"The value of feedback resistor = \", (Rf/10**3),\"kohms\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of feedback resistor = 40 kohms\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.4 Page no.92"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "# Given Data\n",
+ "\n",
+ "R1 = 5*10**3\n",
+ "Rf = 20*10**3\n",
+ "vi = 1 \n",
+ "RL = 5*10**3\n",
+ "\n",
+ "# calculating the values \n",
+ "vo = float((1+(Rf/R1))*vi) \n",
+ "ACL = int(vo/vi)\n",
+ "iL = int((vo/RL)*10**3)\n",
+ "i1 = float(((vo - vi)/Rf))*(10**3)\n",
+ "io = iL+i1\n",
+ " \n",
+ " \n",
+ "# printing the values\n",
+ "print \"Output voltage vo = \",vo,\"V\"\n",
+ "print \"Gain ACL = \",ACL\n",
+ "print \"Load current iL = \",iL,\"mA\"\n",
+ "print \"The value of i1 = \",i1,\"mA\"\n",
+ "print \"Output current io = \", io,\"mA\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Output voltage vo = 5.0 V\n",
+ "Gain ACL = 5\n",
+ "Load current iL = 1 mA\n",
+ "The value of i1 = 0.2 mA\n",
+ "Output current io = 1.2 mA\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.5 Page No.94"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Given Data\n",
+ "import math\n",
+ "Beta = 200\n",
+ "ICQ = 100*10**-6\n",
+ "ADM = 100\n",
+ "CMRR = 80\n",
+ "\n",
+ "# finding the solution \n",
+ "# for VT =25 milli volt \n",
+ "VT = 25*10**-3\n",
+ "gm = float(ICQ/VT)\n",
+ "Rc = (ADM/gm) \n",
+ "CMRR = 10**(80/20) # log inverse is equal to powers of 10\n",
+ "RE = float((CMRR-1)/gm)\n",
+ "x = Decimal((RE/10**6))\n",
+ "\n",
+ "# printing the values \n",
+ "\n",
+ "print \" The value of gm =\",int(math.ceil((gm*10**3))),\"mMho\" #converting the answer into milli Mho\n",
+ "print \" The value of Rc =\",int((Rc/10**3)),\"kohm\" #converting the answer into kohm"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The value of gm = 4 mMho\n",
+ " The value of Rc = 25 kohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.6 Page no. 95"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Given data \n",
+ "\n",
+ "gm = 4*10**-3\n",
+ "RC = 125*10*3\n",
+ "RE = 1.25*10**3\n",
+ "beta0 = 200\n",
+ "\n",
+ "# calculating the values\n",
+ "\n",
+ "rpi = beta0/gm # value is in ohms \n",
+ "ADM =-500 # Given Value\n",
+ "ACM = -((200*RC)/(402*RE)+rpi)*10**-6\n",
+ "print \"ACM is =\",round(ACM,2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ACM is = -0.05\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9 Page No.63"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import math\n",
+ "from fractions import Fraction \n",
+ "# Given data\n",
+ "\n",
+ "beta0 = 100\n",
+ "IQ = 5*10**-4\n",
+ "RC = 10*10**3\n",
+ "RE = 150\n",
+ "VT = 25*10**-3 \n",
+ "\n",
+ "# calculations \n",
+ "\n",
+ "ICQ = float(IQ/2)\n",
+ "gm = float(ICQ / VT)\n",
+ "rpi = beta0/gm\n",
+ "# calculaing the gain in Differential mode\n",
+ "ADM = ((0.5)*(beta0*RC))/(rpi+((1+beta0)*RE))\n",
+ "# To get the differentila mode gain multiply the value by 2\n",
+ "ADM2 = (ADM*2)\n",
+ "\n",
+ "# print the values \n",
+ "\n",
+ "print \"ICQ value is =\",ICQ*10**3,\"mA\"\n",
+ "print \"gm value is =\",Fraction(gm).limit_denominator(100),\"Mho\" \n",
+ "print \"rpi value is =\",int(rpi/10**3),\"kilo Ohm\"\n",
+ "print \"THe gain is =\",int(math.ceil(ADM2)),\"V/V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ICQ value is = 0.25 mA\n",
+ "gm value is = 1/100 Mho\n",
+ "rpi value is = 10 kilo Ohm\n",
+ "THe gain is = 40 V/V\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex 2.8 Page no.97"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Given data\n",
+ "import math\n",
+ "I0 = 10*10**-6\n",
+ "VCC =10\n",
+ "VBE = 0.7\n",
+ "beta = 125\n",
+ "VT = 25*10**-3\n",
+ "\n",
+ "# Solution of the problem is \n",
+ "Iref = 10**-3 # Assumption\n",
+ "\n",
+ "R1 = (VCC - VBE)/Iref\n",
+ "# Finding the value RE from the equation 2.74\n",
+ "RE = (VT/(1+(1/beta)*I0))*math.log(Iref/I0)\n",
+ "\n",
+ "# printing the values \n",
+ "\n",
+ "print \"The value of R1 =\",R1/10**3,\"Kilo Ohms\"\n",
+ "print \"The value of RE =\",round(RE*100,1),\"Kilo Ohms\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The value of R1 = 9.3 Kilo Ohms\n",
+ "The value of RE = 11.5 Kilo Ohms\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/YogeshPatil/EDC_By_K_L_Kishore_Chapter_7.ipynb b/sample_notebooks/YogeshPatil/EDC_By_K_L_Kishore_Chapter_7.ipynb
new file mode 100755
index 00000000..703182db
--- /dev/null
+++ b/sample_notebooks/YogeshPatil/EDC_By_K_L_Kishore_Chapter_7.ipynb
@@ -0,0 +1,499 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7 : Feedback Amplifiers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.1 page no-402"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# determination of various parameters of feedback amplifiers\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Av=-100\n",
+ "B=0.01\n",
+ "\n",
+ "#Calculations\n",
+ "Avd=Av/(1-B*Av)\n",
+ "v1d=10**-3 \n",
+ "V0=Avd*v1d*1000\n",
+ "Vx=B*V0\n",
+ "V1=v1d+Vx\n",
+ "\n",
+ "#Result\n",
+ "print(\"V1=%.3f\\nV1d=%.3f\\nThis is negative feedback because, v1<v1_dash\\n\"%( V1,v1d))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "V1=-0.499\n",
+ "V1d=0.001\n",
+ "This is negative feedback because, v1<v1_dash\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.2 page no-403"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#percentage variation in Avdash\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Av=-100\n",
+ "Avd=-50\n",
+ "Avnew=-200\n",
+ "B=0.01\n",
+ "\n",
+ "# Calculations\n",
+ "Avdnew=Avnew/(1-B*Avnew)\n",
+ "avchange=(-Avdnew)-(-Avd)\n",
+ "var=avchange*100/(-Avd)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Variation = %.1f%%\"%var)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Variation = 33.3%\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.3 page no-403"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# reverse transmission factor and gain with feedback\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "dA=100.0\n",
+ "A=1000.0\n",
+ "dAf=0.1\n",
+ "Af=100.0\n",
+ "\n",
+ "#Calculations\n",
+ "#(a)\n",
+ "B=(((dA/A)*(Af/dAf))-1)/A\n",
+ "#(b)\n",
+ "Aff=A/(1+B*A)\n",
+ "\n",
+ "#Result\n",
+ "print(\"(a)\\nBeta=%.3f\"%B)\n",
+ "print(\"\\n(b)\\nAf=%d\"%Aff)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a)\n",
+ "Beta=0.099\n",
+ "\n",
+ "(b)\n",
+ "Af=10\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.4 page no-404"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Improvement in stability\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "S=0.1\n",
+ "Sdash=0.01\n",
+ "Avdash=100.0\n",
+ "\n",
+ "#Calculations\n",
+ "k=S/Sdash # k=1+BAv\n",
+ "Av=Avdash*k\n",
+ "B=(k-1)/Av\n",
+ "\n",
+ "#Result\n",
+ "print(\"By providing negative feedback,with\\nBeta = %.3f\\nwe can improve the stability to 1%%.\"%B)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "By providing negative feedback,with\n",
+ "Beta = 0.009\n",
+ "we can improve the stability to 1%.\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.5 page no-404"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Overall gain and reverse transmission factor\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Av=500.0\n",
+ "D=5.0\n",
+ "\n",
+ "\n",
+ "#Calculations\n",
+ "Ddash=0.1\n",
+ "B=((D/Ddash)-1)/(Av)\n",
+ "Avdash=-Av/(1+B*Av)\n",
+ "\n",
+ "#Result\n",
+ "print(\"Av_dash = %.0f\"%Avdash)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Av_dash = -10\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.6 page no-405"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# different parameters with and without negative feedback\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Vs=150.0\n",
+ "A=10000.0\n",
+ "Vs2=130.0\n",
+ "A2=8000.0\n",
+ "\n",
+ "\n",
+ "#Calcualtions\n",
+ "V0=A*Vs\n",
+ "Afb=10000.0/80.0\n",
+ "B=((A/Afb)-1)/A\n",
+ "V02=A2*Vs\n",
+ "Afb2=A2/(1+(B*A2))\n",
+ "sg=(A-A2)*100/A\n",
+ "sgf=(Afb-Afb2)*100/Afb\n",
+ "\n",
+ "#Result\n",
+ "print(\"Beta =%.4f\"%B)\n",
+ "print(\"%% stability of gain without feedback=%.0f%%\\n%% stability of gain with feedback=%.4f%%\"%(sg,sgf))\n",
+ "print(\"Therefore, with neative feedbaclk stability is improved.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Beta =0.0079\n",
+ "% stability of gain without feedback=20%\n",
+ "% stability of gain with feedback=0.3115%\n",
+ "Therefore, with neative feedbaclk stability is improved.\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.7 page no-409"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# Avf, Rof and Rif for the voltage series feedback\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rs=0\n",
+ "hfe=50.0\n",
+ "hie =1.100\n",
+ "hre=0\n",
+ "hoe=0\n",
+ "r5=2.2000\n",
+ "r7=3.3000\n",
+ "r3=33.0\n",
+ "r1=0.1\n",
+ "r2=10.0\n",
+ "r9=2.2\n",
+ "R1=0.98\n",
+ "r6=2.2\n",
+ "R0=2.0\n",
+ "\n",
+ "#Calculations\n",
+ "#Rl =R5 is in parallel with R7,R8 and h1e2\n",
+ "Rl1=(r5*r3*r7*hie)/((r5*r3*r7)+(hie*r3*r7)+(r5*hie*r7)+(r5*r3*hie))\n",
+ "Rl2=(r9*(r1+r2))/(r9+(r1+r2))\n",
+ "Re=(r1*r6)/(r1+r6)\n",
+ "Av1=-(hfe*Rl1)/(hie+(1+hfe)*0.098) # The voltage gain AV1 of Q\n",
+ "Av2=(-hfe*Rl2)/hie # Voltage gain AY2 of transistor Q2\n",
+ "Av=Av1*Av2 # Voltage gain Ay of the two stages is cascade without feedback\n",
+ "B=r1/(r1+r2)\n",
+ "K=Av*B\n",
+ "D=1+K\n",
+ "Avf=Av/D\n",
+ "Ri=hie+(1+hfe)*Re # Input resistance without external feedback\n",
+ "Ridash=Ri*D\n",
+ "Rof=R0/D # Output resistance without feedback\n",
+ "\n",
+ "#Result\n",
+ "print(\"Rl1_dash=%f\"%Rl1)\n",
+ "print(\"Rl2=%f = 2 KOhm(approx)\"%Rl2)\n",
+ "print(\"Re=%f kohm = %.0f ohm\"%(Re,math.ceil(Re*1000)))\n",
+ "print(\"Av1 = %.2f\\nAv2 = %.2f\"%(Av1,Av2))\n",
+ "print(\"Avf = %d\"%Avf)\n",
+ "print(\"Ri_dash = %f K Ohm\"%Ridash)\n",
+ "print(\"Rof_dash=%f K Ohm\"%Rof)\n",
+ "#Though the calculations are same as given in book answers \n",
+ "#do not match with the answers given in the Book."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Rl1_dash=0.589286\n",
+ "Rl2=1.806504 = 2 KOhm(approx)\n",
+ "Re=0.095652 kohm = 96 ohm\n",
+ "Av1 = -4.83\n",
+ "Av2 = -82.11\n",
+ "Avf = 80\n",
+ "Ri_dash = 29.462595 K Ohm\n",
+ "Rof_dash=0.405820 K Ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.8 page no-414"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# current series feedack\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rc1 =3.0\n",
+ "Rc2 =0.500\n",
+ "Re2 = 0.05\n",
+ "Rdash=1.2\n",
+ "Rs = 1.2\n",
+ "hfe = 50.0\n",
+ "hie = 1.1 \n",
+ "hre=0\n",
+ "hre =0\n",
+ "\n",
+ "#Calculations\n",
+ "Ai=-hfe # EmItter follower\n",
+ "Ri2=hie+(1+hfe)*(Re2*Rdash/(Re2+Rdash))\n",
+ "k1=-Rc1/(Rc1+Ri2)\n",
+ "k1=math.ceil(k1*1000)\n",
+ "k1=k1/1000\n",
+ "R=Rs*(Rdash+Re2)/(Rs+(Rdash+Re2))\n",
+ "k2=R/(R+hie)\n",
+ "k2=math.floor(k2*1000)\n",
+ "k2=k2/1000\n",
+ "AI=Ai*k1*k2*hfe\n",
+ "B=Re2/(Re2+Rdash)\n",
+ "D=(1+B*AI)\n",
+ "Adash=AI/(1+B*AI)\n",
+ "Avdash=Adash*Rc2/Rs\n",
+ "Ri=R*hie/(R+hie) # Ri = Input resistance without feedback\n",
+ "Ridash=Ri/D\n",
+ "Rol=Rc2 # RoL =Ro in parallel with RC2 = RC2 and Ro is large\n",
+ "Rldash= Rol*D/D # with feedback considering RL\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "print(\"AI=%d\\nBeta=%.2f\\nAi_dash=%.1f\\nAv_dash=%.2f\"%(AI,B,Adash,Avdash))\n",
+ "print(\"Ri=%f K Ohm\\nRl_dash=%.2f K Ohm\"%(Ri,Rldash))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "AI=408\n",
+ "Beta=0.04\n",
+ "Ai_dash=23.6\n",
+ "Av_dash=9.82\n",
+ "Ri=0.393325 K Ohm\n",
+ "Rl_dash=0.50 K Ohm\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7.9 page no-423"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# calculation of Avf and Rif for given circuit\n",
+ "\n",
+ "import math\n",
+ "#Variable declaration\n",
+ "Rc=4.0\n",
+ "Rb=40.0\n",
+ "Rs=10.0\n",
+ "hie=1.1\n",
+ "hfe=50.0\n",
+ "hre=0\n",
+ "hoe=0\n",
+ "\n",
+ "#Calculations\n",
+ "Rcdash=Rc*Rb/(Rc+Rb)\n",
+ "R=Rs*Rb/(Rs+Rb)\n",
+ "Rm=-hfe*Rcdash*R/(R+hie)\n",
+ "Rm=math.floor(Rm)\n",
+ "B=-1/(Rb)\n",
+ "D=1+B*Rm\n",
+ "Rmdash=Rm/D\n",
+ "Avdash=Rmdash/Rs\n",
+ "Ri=R*hie/(R+hie)\n",
+ "Ridash=Ri/D\n",
+ "\n",
+ "#Result\n",
+ "print(\"Transresistance Rm=%d k\"%Rm)\n",
+ "print(\"Beta=%.3f mA/V\\nRm_dash=%dk Ohm\\nAv_dash=%f\\nRi=%f k Ohm\"%(B,Rmdash,Avdash,Ri))\n",
+ "print(\"Ri_dash=%f kOhm\"%Ridash)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Transresistance Rm=-160 k\n",
+ "Beta=-0.025 mA/V\n",
+ "Rm_dash=-32k Ohm\n",
+ "Av_dash=-3.200000\n",
+ "Ri=0.967033 k Ohm\n",
+ "Ri_dash=0.193407 kOhm\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/kotaDinesh Babu/samplebook(process_heat_transfer)_1.ipynb b/sample_notebooks/kotaDinesh Babu/samplebook(process_heat_transfer)_1.ipynb
new file mode 100755
index 00000000..1de57adb
--- /dev/null
+++ b/sample_notebooks/kotaDinesh Babu/samplebook(process_heat_transfer)_1.ipynb
@@ -0,0 +1,281 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 2:CONDUCTION"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example2.1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " heat is Btu/hr 69120.0\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "#page 13\n",
+ "#given\n",
+ "Tavg=900; # average temperature of the wall,F\n",
+ "k=0.15; # Thermal conductivity at 932 F,Btu/(hr)(ft^2)(F/ft)\n",
+ "T1=1500; # hot side temperature,F\n",
+ "T2=300; # cold side temperature,F\n",
+ "A=192; # surface area,ft^2\n",
+ "L=0.5; # thickness,ft\n",
+ "#solution\n",
+ "Q=(k)*(A)*(T1-T2)/L; # formula for heat,Btu/hr\n",
+ "print \" heat is Btu/hr \",Q\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#end\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example2.2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t resistance offered by firebrick : (hr)*(F)/Btu 0.97\n",
+ "\t resistance offered by insulating brick : (hr)*(F)/Btu 2.2\n",
+ "\t resistance offered by buildingbrick : (hr)*(F)/Btu 1.25\n",
+ "\t total resistance offered by three walls : (hr)*(F)/Btu 4.42\n",
+ "\t heat loss/ft^2 : Btu/hr 331.0\n",
+ "\t delta is : F 322.0\n",
+ "\t temperature at interface of firebrick and insulating brick F 1278.0\n",
+ "\t deltb is : F 729.0\n",
+ "\t temperature at interface of insulating brick and building brick F 549.0\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "#page 14\n",
+ "#given\n",
+ "La=0.66; # Thickness of firebrick wall,ft\n",
+ "Lb=0.33; # Thickness of insulating brick wall,ft\n",
+ "Lc=0.5; # Thickness of building brick wall,ft\n",
+ "Ka=0.68; # themal conductivity of firebrick,Btu/(hr)*(ft^2)*(F/ft)\n",
+ "Kb=0.15; # themal conductivity of insulating brick,Btu/(hr)*(ft^2)*(F/ft)\n",
+ "Kc=0.40; # themal conductivity of building brick,Btu/(hr)*(ft^2)*(F/ft)\n",
+ "A=1.; # surface area,ft^2\n",
+ "Ta=1600.; # temperature of inner wall,F\n",
+ "Tb=125.; # temperature of outer wall.F\n",
+ "#solution\n",
+ "Ra=La/(Ka)*(A); # formula for resistance,(hr)*(F)/Btu\n",
+ "print\"\\t resistance offered by firebrick : (hr)*(F)/Btu \",round(Ra,2)\n",
+ "Rb=Lb/(Kb)*(A); # formula for resistance,(hr)*(F)/Btu\n",
+ "print\"\\t resistance offered by insulating brick : (hr)*(F)/Btu \",round(Rb,2)\n",
+ "Rc=Lc/(Kc)*(A); # formula for resistance,(hr)*(F)/Btu\n",
+ "print\"\\t resistance offered by buildingbrick : (hr)*(F)/Btu \",round(Rc,2)\n",
+ "R=Ra+Rb+Rc; # total resistance offered by three walls,(hr)*(F)/Btu\n",
+ "print\"\\t total resistance offered by three walls : (hr)*(F)/Btu \",round(R,2)\n",
+ "Q=(1600-125)/4.45; # using formula for heat loss/ft^2,Btu/hr\n",
+ "print\"\\t heat loss/ft^2 : Btu/hr \",round(Q,0)\n",
+ "# T1,T2 are temperatures at interface of firebrick and insulating brick, and insulating brick and building brick respectively,F\n",
+ "delta=(Q)*(Ra); # formula for temperature difference,F\n",
+ "print\"\\t delta is : F \",round(delta,0)\n",
+ "T1=Ta-((Q)*(Ra)); # temperature at interface of firebrick and insulating brick,F\n",
+ "print\"\\t temperature at interface of firebrick and insulating brick F \",round(T1,0)\n",
+ "deltb=Q*(Rb);\n",
+ "print\"\\t deltb is : F \",round(deltb,0)\n",
+ "T2=T1-((Q)*(Rb)); #temperature at interface of insulating brick and building brick,F\n",
+ "print\"\\t temperature at interface of insulating brick and building brick F \",round(T2,0)\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example2.3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t resistance offered by air film (hr)(F)/Btu 0.79\n",
+ "\t total resistance (hr)(F)/Btu 5.24\n",
+ "\t heat loss Btu/hr 282.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#page 15\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "Lair=0.25/12; # thickness of air film,ft\n",
+ "Kair=0.0265; # thermal conductivity of air at 572F,Btu/(hr)*(ft^2)(F/ft)\n",
+ "A=1; # surface area,ft^2\n",
+ "#solution\n",
+ "Rair=Lair/(Kair*(A)); # resistance offered by air film, (hr)(F)/Btu\n",
+ "print\"\\t resistance offered by air film (hr)(F)/Btu \",round(Rair,2)\n",
+ "R=4.45; # resistance from previous example 2.2,(hr)(F)/Btu\n",
+ "Rt=(R)+Rair; # total resistance,(hr)(F)/Btu\n",
+ "print\"\\t total resistance (hr)(F)/Btu \",round(Rt,2)\n",
+ "Ta=1600; # temperature of inner wall,F\n",
+ "Tb=125; # temperature of outer wall,F\n",
+ "Q=(1600-125)/Rt; # heat loss, Btu/hr\n",
+ "print\"\\t heat loss Btu/hr \",round(Q,0)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example2.4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "#page 16\n",
+ "#given\n",
+ "k=0.63; # thermal conductivity of pipe, Btu/(hr)*(ft^2)*(F/ft)\n",
+ "Do=6. # in\n",
+ "Di=5. # in\n",
+ "Ti=200.;# inner side temperature,F\n",
+ "To=175.; # outer side temperature,F\n",
+ "#solution\n",
+ "import math\n",
+ "from math import log\n",
+ "q=(2*(3.14)*(k)*(Ti-To))/(log (Do/Di)); # formula for heat flow,Btu/(hr)*(ft)\n",
+ "print\"\\t heat flow is : Btu/(hr)*(ft) \",round(q,0)\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "# caculation mistake in book\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example2.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t heat loss for linear foot is : Btu/(hr)*(lin ft) 104.4\n",
+ "\t Check between ts and t1, since delt/R = deltc/Rc \n",
+ "\t t1 is : F 122.300238658\n",
+ "\t heat loss for linear foot is : Btu/(hr)*(lin ft) 102.9\n",
+ "\t Check between ts and t1, since delt/R = deltc/Rc \n",
+ "\t t1 is : F 125.4\n"
+ ]
+ }
+ ],
+ "source": [
+ "#page 19\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "t1=150; # assume temperature of outer surface of rockwool,F\n",
+ "ta=70; # temperature of surrounding air,F\n",
+ "ha=2.23; # surface coefficient,Btu/(hr)*(ft^2)*(F)\n",
+ "#solution\n",
+ "import math\n",
+ "from math import log\n",
+ "q=(3.14)*(300-70)/(((1/(2*0.033))*log(3.375/2.375))+(1/((2.23)*(3.375/12)))); # using formula for heat loss,Btu/(hr)*(lin ft), calculation mistake\n",
+ "print\"\\t heat loss for linear foot is : Btu/(hr)*(lin ft) \",round(q,1)\n",
+ "print\"\\t Check between ts and t1, since delt/R = deltc/Rc \"\n",
+ "t1=300-(((104.8)*((1)*(log(3.375/2.375))))/((2)*(3.14)*(.033))); # using eq 2.31,F\n",
+ "print\"\\t t1 is : F \",t1\n",
+ "t1=125; # assume temperature of outer surface of rockwool,F\n",
+ "ha=2.10; # surface coefficient,Btu/(hr)*(ft^2)*(F)\n",
+ "q=((3.14)*(300-70))/(((1/(2*0.033))*log(3.375/2.375))+(1/((2.10)*(3.375/12)))); # using formula for heat loss,Btu/(hr)*(lin ft)\n",
+ "print\"\\t heat loss for linear foot is : Btu/(hr)*(lin ft)\",round(q,1)\n",
+ "print\"\\t Check between ts and t1, since delt/R = deltc/Rc \"\n",
+ "t1=300-(((103)*((1)*(log(3.375/2.375))))/((2)*(3.14)*(.033))); # using eq 2.31,F\n",
+ "print\"\\t t1 is : F \",round(t1,1)\n",
+ "# end \n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/sample_notebooks/kotaDinesh Babu/samplebook(process_heat_transfer)_2.ipynb b/sample_notebooks/kotaDinesh Babu/samplebook(process_heat_transfer)_2.ipynb
new file mode 100755
index 00000000..8bc5413c
--- /dev/null
+++ b/sample_notebooks/kotaDinesh Babu/samplebook(process_heat_transfer)_2.ipynb
@@ -0,0 +1,281 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 2:CONDUCTION"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example2.1 pg:13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " heat is Btu/hr 69120.0\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "#given\n",
+ "Tavg=900; # average temperature of the wall,F\n",
+ "k=0.15; # Thermal conductivity at 932 F,Btu/(hr)(ft^2)(F/ft)\n",
+ "T1=1500; # hot side temperature,F\n",
+ "T2=300; # cold side temperature,F\n",
+ "A=192; # surface area,ft^2\n",
+ "L=0.5; # thickness,ft\n",
+ "#solution\n",
+ "Q=(k)*(A)*(T1-T2)/L; # formula for heat,Btu/hr\n",
+ "print \" heat is Btu/hr \",Q\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#end\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example2.2 pg:14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t resistance offered by firebrick : (hr)*(F)/Btu 0.97\n",
+ "\t resistance offered by insulating brick : (hr)*(F)/Btu 2.2\n",
+ "\t resistance offered by buildingbrick : (hr)*(F)/Btu 1.25\n",
+ "\t total resistance offered by three walls : (hr)*(F)/Btu 4.42\n",
+ "\t heat loss/ft^2 : Btu/hr 331.0\n",
+ "\t delta is : F 322.0\n",
+ "\t temperature at interface of firebrick and insulating brick F 1278.0\n",
+ "\t deltb is : F 729.0\n",
+ "\t temperature at interface of insulating brick and building brick F 549.0\n",
+ "\t approximate values are mentioned in the book \n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "#given\n",
+ "La=0.66; # Thickness of firebrick wall,ft\n",
+ "Lb=0.33; # Thickness of insulating brick wall,ft\n",
+ "Lc=0.5; # Thickness of building brick wall,ft\n",
+ "Ka=0.68; # themal conductivity of firebrick,Btu/(hr)*(ft^2)*(F/ft)\n",
+ "Kb=0.15; # themal conductivity of insulating brick,Btu/(hr)*(ft^2)*(F/ft)\n",
+ "Kc=0.40; # themal conductivity of building brick,Btu/(hr)*(ft^2)*(F/ft)\n",
+ "A=1.; # surface area,ft^2\n",
+ "Ta=1600.; # temperature of inner wall,F\n",
+ "Tb=125.; # temperature of outer wall.F\n",
+ "#solution\n",
+ "Ra=La/(Ka)*(A); # formula for resistance,(hr)*(F)/Btu\n",
+ "print\"\\t resistance offered by firebrick : (hr)*(F)/Btu \",round(Ra,2)\n",
+ "Rb=Lb/(Kb)*(A); # formula for resistance,(hr)*(F)/Btu\n",
+ "print\"\\t resistance offered by insulating brick : (hr)*(F)/Btu \",round(Rb,2)\n",
+ "Rc=Lc/(Kc)*(A); # formula for resistance,(hr)*(F)/Btu\n",
+ "print\"\\t resistance offered by buildingbrick : (hr)*(F)/Btu \",round(Rc,2)\n",
+ "R=Ra+Rb+Rc; # total resistance offered by three walls,(hr)*(F)/Btu\n",
+ "print\"\\t total resistance offered by three walls : (hr)*(F)/Btu \",round(R,2)\n",
+ "Q=(1600-125)/4.45; # using formula for heat loss/ft^2,Btu/hr\n",
+ "print\"\\t heat loss/ft^2 : Btu/hr \",round(Q,0)\n",
+ "# T1,T2 are temperatures at interface of firebrick and insulating brick, and insulating brick and building brick respectively,F\n",
+ "delta=(Q)*(Ra); # formula for temperature difference,F\n",
+ "print\"\\t delta is : F \",round(delta,0)\n",
+ "T1=Ta-((Q)*(Ra)); # temperature at interface of firebrick and insulating brick,F\n",
+ "print\"\\t temperature at interface of firebrick and insulating brick F \",round(T1,0)\n",
+ "deltb=Q*(Rb);\n",
+ "print\"\\t deltb is : F \",round(deltb,0)\n",
+ "T2=T1-((Q)*(Rb)); #temperature at interface of insulating brick and building brick,F\n",
+ "print\"\\t temperature at interface of insulating brick and building brick F \",round(T2,0)\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example2.3 pg:15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t resistance offered by air film (hr)(F)/Btu 0.79\n",
+ "\t total resistance (hr)(F)/Btu 5.24\n",
+ "\t heat loss Btu/hr 282.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "Lair=0.25/12; # thickness of air film,ft\n",
+ "Kair=0.0265; # thermal conductivity of air at 572F,Btu/(hr)*(ft^2)(F/ft)\n",
+ "A=1; # surface area,ft^2\n",
+ "#solution\n",
+ "Rair=Lair/(Kair*(A)); # resistance offered by air film, (hr)(F)/Btu\n",
+ "print\"\\t resistance offered by air film (hr)(F)/Btu \",round(Rair,2)\n",
+ "R=4.45; # resistance from previous example 2.2,(hr)(F)/Btu\n",
+ "Rt=(R)+Rair; # total resistance,(hr)(F)/Btu\n",
+ "print\"\\t total resistance (hr)(F)/Btu \",round(Rt,2)\n",
+ "Ta=1600; # temperature of inner wall,F\n",
+ "Tb=125; # temperature of outer wall,F\n",
+ "Q=(1600-125)/Rt; # heat loss, Btu/hr\n",
+ "print\"\\t heat loss Btu/hr \",round(Q,0)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example2.4 pg 16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "\n",
+ "#given\n",
+ "k=0.63; # thermal conductivity of pipe, Btu/(hr)*(ft^2)*(F/ft)\n",
+ "Do=6. # in\n",
+ "Di=5. # in\n",
+ "Ti=200.;# inner side temperature,F\n",
+ "To=175.; # outer side temperature,F\n",
+ "#solution\n",
+ "import math\n",
+ "from math import log\n",
+ "q=(2*(3.14)*(k)*(Ti-To))/(log (Do/Di)); # formula for heat flow,Btu/(hr)*(ft)\n",
+ "print\"\\t heat flow is : Btu/(hr)*(ft) \",round(q,0)\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "# caculation mistake in book\n",
+ "# end\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##Example2.5 pg 19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\t approximate values are mentioned in the book \n",
+ "\n",
+ "\t heat loss for linear foot is : Btu/(hr)*(lin ft) 104.4\n",
+ "\t Check between ts and t1, since delt/R = deltc/Rc \n",
+ "\t t1 is : F 122.300238658\n",
+ "\t heat loss for linear foot is : Btu/(hr)*(lin ft) 102.9\n",
+ "\t Check between ts and t1, since delt/R = deltc/Rc \n",
+ "\t t1 is : F 125.4\n"
+ ]
+ }
+ ],
+ "source": [
+ "\n",
+ "print\"\\t approximate values are mentioned in the book \\n\"\n",
+ "#given\n",
+ "t1=150; # assume temperature of outer surface of rockwool,F\n",
+ "ta=70; # temperature of surrounding air,F\n",
+ "ha=2.23; # surface coefficient,Btu/(hr)*(ft^2)*(F)\n",
+ "#solution\n",
+ "import math\n",
+ "from math import log\n",
+ "q=(3.14)*(300-70)/(((1/(2*0.033))*log(3.375/2.375))+(1/((2.23)*(3.375/12)))); # using formula for heat loss,Btu/(hr)*(lin ft), calculation mistake\n",
+ "print\"\\t heat loss for linear foot is : Btu/(hr)*(lin ft) \",round(q,1)\n",
+ "print\"\\t Check between ts and t1, since delt/R = deltc/Rc \"\n",
+ "t1=300-(((104.8)*((1)*(log(3.375/2.375))))/((2)*(3.14)*(.033))); # using eq 2.31,F\n",
+ "print\"\\t t1 is : F \",t1\n",
+ "t1=125; # assume temperature of outer surface of rockwool,F\n",
+ "ha=2.10; # surface coefficient,Btu/(hr)*(ft^2)*(F)\n",
+ "q=((3.14)*(300-70))/(((1/(2*0.033))*log(3.375/2.375))+(1/((2.10)*(3.375/12)))); # using formula for heat loss,Btu/(hr)*(lin ft)\n",
+ "print\"\\t heat loss for linear foot is : Btu/(hr)*(lin ft)\",round(q,1)\n",
+ "print\"\\t Check between ts and t1, since delt/R = deltc/Rc \"\n",
+ "t1=300-(((103)*((1)*(log(3.375/2.375))))/((2)*(3.14)*(.033))); # using eq 2.31,F\n",
+ "print\"\\t t1 is : F \",round(t1,1)\n",
+ "# end \n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/sample_notebooks/marupeddisameer chaitanya/Sample_(chapter_9).ipynb b/sample_notebooks/marupeddisameer chaitanya/Sample_(chapter_9).ipynb
new file mode 100755
index 00000000..bff5435f
--- /dev/null
+++ b/sample_notebooks/marupeddisameer chaitanya/Sample_(chapter_9).ipynb
@@ -0,0 +1,247 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 9 : Theories of Mass Transfer"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.1.1 pgno31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The film thickness is cm 0.00765\n"
+ ]
+ }
+ ],
+ "source": [
+ "#initialization of variables\n",
+ "p1 = 10. # pressure in atm\n",
+ "H = 600. # henrys constant in atm\n",
+ "c1 = 0 # gmol/cc\n",
+ "N1 = 2.3*10**-6 # mass flux in mol/cm**2-sec\n",
+ "c = 1./18. #total Concentration in g-mol/cc\n",
+ "D = 1.9*10**-5 # Diffusion co efficient in cm**2/sec\n",
+ "#Calculations\n",
+ "c1i = (p1/H)*c # Component concentration in gmol/cc\n",
+ "k = N1/(c1i-c1)#Mass transfer co efficient in cm/sec\n",
+ "l = D/k # Film thickness in cm\n",
+ "#Results\n",
+ "print\"The film thickness is cm\",round(l,5)\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.2.1 pgno:34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The contact time sec 3.9\n",
+ "\n",
+ "The surface resident time sec 3.0\n"
+ ]
+ }
+ ],
+ "source": [
+ "#initialization of variables\n",
+ "D = 1.9*10**-5 #Diffusion co efficient in cm**2/sec\n",
+ "k = 2.5*10**-3 # M.T.C in cm/sec\n",
+ "from math import pi\n",
+ "#Calculations\n",
+ "Lbyvmax = 4*D/((k**2)*pi)#sec\n",
+ "tou = D/k**2 # sec\n",
+ "#Results\n",
+ "print\"The contact time sec\",round(Lbyvmax,1)\n",
+ "print\"\\nThe surface resident time sec\",round(tou,1)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.3.1 pgno:35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The apparent m.t.c for the first case is cm/sec 0.000379885493042\n",
+ "\n",
+ "The apparent m.t.c for the second case is cm/sec 0.000742723884992\n",
+ "\n",
+ "The apparent is proportional to the power of of the velocity 0.61\n"
+ ]
+ }
+ ],
+ "source": [
+ "#initialization of variables\n",
+ "const = 0.5 # The part of flow in the system which bypasses the region where the mass transfer occurs\n",
+ "v1 = 1. # cm/sec\n",
+ "al = 10**3\n",
+ "k = 10**-3 # cm/sec\n",
+ "v2 = 3. # cm/sec\n",
+ "from math import log\n",
+ "from math import exp\n",
+ "#Calculations\n",
+ "C1byC10first = const + (1-const)*(exp(-k*al/v1))# c1/c10\n",
+ "appk1 = (v1/al)*(log(1/C1byC10first))# Apparent m.t.c for first case in cm/sec\n",
+ "C1byC10second = const + (1-const)*(exp(-((3)**0.5)*k*al/v2))#c1/c10 in second case\n",
+ "appk2 = (v2/al)*log(1/C1byC10second)# apparent m.t.c for second case in cm/sec\n",
+ "power = log(appk2/appk1)/log(v2/v1)\n",
+ "#Results\n",
+ "print\"The apparent m.t.c for the first case is cm/sec\",appk1\n",
+ "print\"\\nThe apparent m.t.c for the second case is cm/sec\",appk2\n",
+ "print\"\\nThe apparent is proportional to the power of of the velocity\",round(power,2)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.4.1 pgno:37"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The average mass transfer coefficient is cm/sec 0.000431530124388\n"
+ ]
+ }
+ ],
+ "source": [
+ "#initialization of variables\n",
+ "D = 1*10**-5 #cm**2/sec\n",
+ "d = 2.3 # cm\n",
+ "L = 14 # cm\n",
+ "v0 = 6.1 # cm/sec\n",
+ "#gamma(4./3.)=0.8909512761;\n",
+ "#calculations\n",
+ "k = ((3**(1./3.))/(0.8909512761))*((D/d))*(((d**2)*v0/(D*L))**(1./3.))# cm/sec\n",
+ "#Results\n",
+ "print\"The average mass transfer coefficient is cm/sec\",k\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 9.4.2 pgno:40"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The distance at which turbulent flow starts is cm 300.0\n",
+ "\n",
+ "The boundary layer for flow at this point is cm 300.0\n",
+ "\n",
+ "The boundary layer for concentration at this point is cm 300.0\n",
+ "\n",
+ "The local m.t.c at the leading edge and at the position of transistion is x10**-5 cm/sec 0.589714620247\n"
+ ]
+ }
+ ],
+ "source": [
+ "#initialization of variables\n",
+ "tn = 300000 # turbulence number\n",
+ "v0 = 10 # cm/sec\n",
+ "p = 1 # g/cc\n",
+ "mu = 0.01 # g/cm-sec\n",
+ "delta = 2.5 #cm\n",
+ "D = 1*10**-5 # cm**2/sec\n",
+ "#Calculations\n",
+ "x = tn*mu/(v0*p)# cm\n",
+ "delta = ((280/13)**(1/2))*x*((mu/(x*v0*p))**(1/2))#cm\n",
+ "deltac = ((D*p/mu)**(1/3))*delta#cm\n",
+ "k = (0.323*(D/x)*((x*v0*p/mu)**0.5)*((mu/(p*D))**(1/3)))*10**5# x*10**-5 cm/sec\n",
+ "#Results\n",
+ "print\"The distance at which turbulent flow starts is cm\",x\n",
+ "print\"\\nThe boundary layer for flow at this point is cm\",delta\n",
+ "print\"\\nThe boundary layer for concentration at this point is cm\",deltac\n",
+ "print\"\\nThe local m.t.c at the leading edge and at the position of transistion is x10**-5 cm/sec\",k\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 2",
+ "language": "python",
+ "name": "python2"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/sample_notebooks/nishumittal/chapter2.ipynb b/sample_notebooks/nishumittal/chapter2.ipynb
new file mode 100755
index 00000000..3d83df64
--- /dev/null
+++ b/sample_notebooks/nishumittal/chapter2.ipynb
@@ -0,0 +1,710 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:46bc70330d4213802afb03e252b2ad32eb9319ed4cc2a32fe2c16df97a5f1978"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 2 Particle nature of Radiation; The origin of Quantum theory"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.2 Page no-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "E=40 #W\n",
+ "lembda=6000*10**-10 #m\n",
+ "h=6.63*10**-34 #Js\n",
+ "c=3*10**8 #m/s\n",
+ "\n",
+ "#Calculation\n",
+ "n=(E*lembda)/(h*c)\n",
+ "\n",
+ "#Result\n",
+ "print\"No. of photons emitted per second are given by \",round(n*10**-19,2),\"*10**19\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "No. of photons emitted per second are given by 12.07 *10**19\n"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.3 Page no-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "a=3.2 #ev\n",
+ "energy=3.8 #ev\n",
+ "e=1.6*10**-19\n",
+ "\n",
+ "#Calculation\n",
+ "c=energy-a\n",
+ "Energy=c*e\n",
+ "\n",
+ "#Result\n",
+ "print\"Kinetic energy of the photoelectron is given by \",Energy,\"Joule\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Kinetic energy of the photoelectron is given by 9.6e-20 Joule\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.4 Page no-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "W=3.45 #ev\n",
+ "h=6.63*10**-34 #Js\n",
+ "c=3*10**8 #m/s\n",
+ "e=1.6*10**-19\n",
+ "\n",
+ "#Calculation\n",
+ "lembda=(h*c)/(W*e)\n",
+ "\n",
+ "#Result\n",
+ "print\"Maximum wavelength of photon is \",round(lembda*10**10,0),\"A\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum wavelength of photon is 3603.0 A\n"
+ ]
+ }
+ ],
+ "prompt_number": 193
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.5 Page no-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "W=3 #ev\n",
+ "h=6.63*10**-34\n",
+ "e=1.6*10**-19\n",
+ "lembda=3.0*10**-7 #m\n",
+ "c=3*10**8 #m/s\n",
+ "\n",
+ "#Calculation\n",
+ "v0=(W*e)/h\n",
+ "v=c/lembda\n",
+ "E=h*(v-v0)\n",
+ "E1=(h*(v-v0))/(1.6*10**-19)\n",
+ "V0=E/e\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) Threshold frequency \",round(v0*10**-15,2),\"*10**15 HZ\"\n",
+ "print\"(b) Maximum energy of photoelectron \",round(E1,2),\"eV\"\n",
+ "print\"(c) Stopping potential \",round(V0,2),\"V\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) Threshold frequency 0.72 *10**15 HZ\n",
+ "(b) Maximum energy of photoelectron 1.14 eV\n",
+ "(c) Stopping potential 1.14 V\n"
+ ]
+ }
+ ],
+ "prompt_number": 197
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.6 Page no-13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "v0=6*10**14 #s**-1\n",
+ "h=6.63*10**-34\n",
+ "e=1.6*10**-19\n",
+ "V0=3\n",
+ "\n",
+ "#Calculaton\n",
+ "W=h*v0\n",
+ "W0=(h*v0)/e\n",
+ "V=(e*V0+h*v0)/h\n",
+ "\n",
+ "#Result \n",
+ "print\"work function is given by \",round(W0,3),\"ev\"\n",
+ "print\"frequency is given by \",round(V*10**-15,2),\"*10**15 s-1\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "work function is given by 2.486 ev\n",
+ "frequency is given by 1.32 *10**15 s-1\n"
+ ]
+ }
+ ],
+ "prompt_number": 88
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.7 Page no 13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "lembda=6800.0*10**-10 #m\n",
+ "h=6.6*10**-34\n",
+ "W=2.3 #ev\n",
+ "c=3*10**8 #m/s\n",
+ "\n",
+ "#Calculation\n",
+ "E=((h*c)/lembda)/1.6*10**-19\n",
+ "\n",
+ "#Result\n",
+ "print\"Energy is \",round(E*10**38,2),\"ev\"\n",
+ "print\"since the energy of incident photon is less then the work function of Na, photoelecrticemession is not possible with the given light.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Energy is 1.82 ev\n",
+ "since the energy of incident photon is less then the work function of Na, photoelecrticemession is not possible with the given light.\n"
+ ]
+ }
+ ],
+ "prompt_number": 200
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.8 Page no 14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "lembda=3500*10**-10 #m\n",
+ "h=6.6*10**-34\n",
+ "c=3*10**8 #m/s\n",
+ "\n",
+ "#calculation \n",
+ "E=((h*c)/lembda)/1.6*10**-19\n",
+ "\n",
+ "#Result\n",
+ "print\"Energy is \" ,round(E*10**38,2),\"ev\"\n",
+ "print\"1.9 ev < E < 4.2 ev,only metal B will yield photoelectrons\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Energy is 3.54 ev\n",
+ "1.9 ev < E < 4.2 ev,only metal B will yield photoelectrons\n"
+ ]
+ }
+ ],
+ "prompt_number": 201
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.9 Page no 14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "lembda=6.2*10**-6\n",
+ "W=0.1 #ev\n",
+ "h=6.6*10**-34 #Js\n",
+ "c=3*10**8 #m/s\n",
+ "e=1.6*10**-19\n",
+ "\n",
+ "#Calculation\n",
+ "E=((h*c)/(lembda*e))-W\n",
+ "\n",
+ "#Result\n",
+ "print\"Maximum kinetic energy of photoelectron \",round(E,1),\"ev\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum kinetic energy of photoelectron 0.1 ev\n"
+ ]
+ }
+ ],
+ "prompt_number": 112
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.10 Page no 14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "e=1.60*10**-19 #C\n",
+ "slope=4.12*10**-15 #Vs\n",
+ "\n",
+ "#Calculation\n",
+ "h=slope*e\n",
+ "\n",
+ "#Result\n",
+ "print\"Value of plank's constant \",h,\"Js\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of plank's constant 6.592e-34 Js\n"
+ ]
+ }
+ ],
+ "prompt_number": 114
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.11 Page no 15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "W=2.26*1.6*10**-19 #ev\n",
+ "v=10**6 #m/s\n",
+ "m=9*10**-31\n",
+ "\n",
+ "#Calculation\n",
+ "V=((1/2.0)*m*v**2+W)/h\n",
+ "\n",
+ "#Result\n",
+ "print\"frequency of incident radiation \",round(V*10**-15,2),\"*10**15 HZ\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "frequency of incident radiation 1.23 *10**15 HZ\n"
+ ]
+ }
+ ],
+ "prompt_number": 118
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.12 Page no 15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "V1=.82 #volts\n",
+ "V2=1.85 #volts\n",
+ "lembda1=4.0*10**-7 #m\n",
+ "lembda2=3.0*10**-7\n",
+ "e=1.6*10**-19\n",
+ "c=3.0*10**8 #m/s\n",
+ "\n",
+ "#Calculation\n",
+ "lembda=(1/lembda2)-(1/lembda1)\n",
+ "h=(e*(V2-V1))/(c*lembda)\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) plank's constant \",h,\"Js\"\n",
+ "print\"(b) no, because the stopping potentialdepends only on the wavelength of light and not on its intensity.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) plank's constant 6.592e-34 Js\n",
+ "(b) no, because the stopping potentialdepends only on the wavelength of light and not on its intensity.\n"
+ ]
+ }
+ ],
+ "prompt_number": 202
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.13 Page no 16"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "h=6.62*10**-34 #Js\n",
+ "c=3*10**8 #m/s\n",
+ "lembda=4560.0*10**-10 #m\n",
+ "p=1*10**-3 #W\n",
+ "a=0.5/100\n",
+ "e=1.6*10**-19\n",
+ "\n",
+ "#calculation\n",
+ "E=(h*c)/lembda\n",
+ "N=p/E #Number of photons incedent on the surface\n",
+ "n=N*a\n",
+ "I=n*e\n",
+ "\n",
+ "#result\n",
+ "print\"Photoelectric current \",round(I*10**6,2),\"*10**-6 A\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Photoelectric current 1.84 *10**-6 A\n"
+ ]
+ }
+ ],
+ "prompt_number": 131
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.14 Page no 22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#given\n",
+ "m0=9.1*10**-31 #Kg\n",
+ "c=3*10**8 #m/s\n",
+ "h=6.6*10**-34 #Js\n",
+ "v1=2.0*10**-10 #m\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "v= (h/(m0*c))*(1-(math.cos(90))*3.14/180.0)\n",
+ "v2=v+v1\n",
+ "v0=v2-v1\n",
+ "E=(h*c*(v0))/(v1*v2)\n",
+ "b=(1/(math.sin(90)*3.14/180.0))*((v2*10**-10/v1)-math.cos(90)*3.14/180.0)\n",
+ "angle=3.14/2.0-math.atan(b)\n",
+ "\n",
+ "#Result\n",
+ "print \"(a) the wavelength of scattered photon is \",round(v2*10**10,3),\"A\"\n",
+ "print\"(b) The energy of recoil electron is \",round(E*10**17,2),\"*10**-17 J\"\n",
+ "print\"(c) angle at which the recoil electron appears \",round(angle,2),\"degree\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) the wavelength of scattered photon is 2.024 A\n",
+ "(b) The energy of recoil electron is 1.19 *10**-17 J\n",
+ "(c) angle at which the recoil electron appears 1.11 degree\n"
+ ]
+ }
+ ],
+ "prompt_number": 278
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.15 Page no 23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given \n",
+ "E=0.9 #Mev\n",
+ "a=120 #degree\n",
+ "m=9.1*10**-31 #Kg\n",
+ "c=3*10**8 #m/s\n",
+ "\n",
+ "#calculation\n",
+ "b=((m*c**2)/1.6*10**-19)*10**32\n",
+ "energy=E/(1+2*(E/b)*(3/4.0))\n",
+ "\n",
+ "#Result\n",
+ "print \"energy of scattered photon \",round(energy,3),\"Mev\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "energy of scattered photon 0.247 Mev\n"
+ ]
+ }
+ ],
+ "prompt_number": 142
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.16 Page no 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "v1=2.000*10**-10 #m\n",
+ "v2=2.048*10**-10 #m\n",
+ "a=180 #degree\n",
+ "a1=60 #degree\n",
+ "h=6.6*10**-34\n",
+ "c=3*10**8\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "b=(v2-v1)/(1-math.cos(a*3.14/180.0))\n",
+ "V=v1+b*(1-math.cos(60*3.14/180.0))\n",
+ "E=(h*c*(V-v1))/(V*v1)\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) wavelength of radiation scattered at an angle of 60 degree \",round(V*10**10,3),\"A\"\n",
+ "print \"(b) Energy of the recoiul electron is \",round(E*10**18,2),\"*10**-18 J\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) wavelength of radiation scattered at an angle of 60 degree 2.012 A\n",
+ "(b) Energy of the recoiul electron is 5.9 *10**-18 J\n"
+ ]
+ }
+ ],
+ "prompt_number": 277
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.17 Page no 24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "E=4*10**3*1.6*10**-19\n",
+ "m0=9.1*10**-31\n",
+ "b=6.4*10**-16\n",
+ "d=102.39*10**-16\n",
+ "h=6.3*10**-34\n",
+ "c=3*10**8\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "p=math.sqrt(2*m0*E)\n",
+ "d=b+d\n",
+ "lembda=(2*h*c)/d\n",
+ "\n",
+ "#Result\n",
+ "print\"Wavelength of incident photon is \", round(lembda*10**10,2),\"A\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Wavelength of incident photon is 0.35 A\n"
+ ]
+ }
+ ],
+ "prompt_number": 233
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2.19 Page no 26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Given\n",
+ "E=1.02 #Mev\n",
+ "b=0.51\n",
+ "\n",
+ "#Calculation\n",
+ "import math\n",
+ "alpha=E/b\n",
+ "a=1/(math.sqrt(2*(alpha+2)))\n",
+ "angle=2*(math.asin(a)*180/3.14)\n",
+ "e=E/(1.0+alpha*(1-(math.cos(angle*3.14/180.0))))\n",
+ "\n",
+ "#Result\n",
+ "print\"(a) Angle for symmetric scattering is \", round(angle,1),\"degree\"\n",
+ "print \"(b) energy of the scattered photon is \",round(e,2),\"Mev\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "(a) Angle for symmetric scattering is 41.4 degree\n",
+ "(b) energy of the scattered photon is 0.68 Mev\n"
+ ]
+ }
+ ],
+ "prompt_number": 263
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/sample_notebooks/pranay/CHAPTER1.ipynb b/sample_notebooks/pranay/CHAPTER1.ipynb
new file mode 100755
index 00000000..28c92eb4
--- /dev/null
+++ b/sample_notebooks/pranay/CHAPTER1.ipynb
@@ -0,0 +1,372 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:b207bd2e95da21482a18db4c5db7765642bb68ba49e8c370fa324a611a42aac8"
+ },
+ "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.1 - PG NO.5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Chapter 1\n",
+ "#Example 1.1\n",
+ "#page 5\n",
+ "import math\n",
+ "fl=760#\n",
+ "pf=0.8#\n",
+ "lsg=0.05#\n",
+ "csg=60.#\n",
+ "depre=0.12#\n",
+ "hpw=48.#\n",
+ "lv=32.#\n",
+ "hv=30.#\n",
+ "pkwhr=0.10#\n",
+ "\n",
+ "md=fl/pf#\n",
+ "print'%s %.1f %s' %('Maximum Demand =',md,' kVA \\n\\n')#\n",
+ "\n",
+ "#calculation for tariff (b)\n",
+ "\n",
+ "print'%s %.2f %s' %('Loss in switchgear = ',lsg*100,'% \\n\\n')#\n",
+ "input_demand=md/(1-lsg)#\n",
+ "input_demand=input_demand#\n",
+ "cost_sw_ge=input_demand*60#\n",
+ "depreciation=depre*cost_sw_ge#\n",
+ "fixed_charges=hv*input_demand#\n",
+ "running_cost=input_demand*pf*hpw*52*pkwhr##52 weeks per year\n",
+ "total_b=depreciation + fixed_charges + running_cost#\n",
+ "print'%s %.1f %s' %('Input Demand= ',input_demand,'kVA \\n\\n')#\n",
+ "print'%s %d %s' %('Cost of switchgear= Rs ',cost_sw_ge,'\\n\\n')#\n",
+ "print'%s %d %s' %('Annual charges on depreciation= Rs ',depreciation,'\\n\\n')#\n",
+ "print'%s %d %s' %('Annual fixed charges due to maximum demand corresponding to triff(b)= Rs',fixed_charges,'\\n\\n')#\n",
+ "print'%s %d %s' %('Annual running cost due to kWh consumed= Rs ',running_cost,'\\n\\n')#\n",
+ "print'%s %d %s' %('Total charges/annum for tariff(b) = Rs ',total_b,'\\n\\n')\n",
+ "\n",
+ "#calculation for tariff (a)\n",
+ "input_demand=md#\n",
+ "input_demand=input_demand#\n",
+ "fixed_charges=lv*input_demand#\n",
+ "running_cost=input_demand*pf*hpw*52*pkwhr#\n",
+ "total_a=fixed_charges + running_cost#\n",
+ "print'%s %d %s' %('maximum demand corresponding to tariff(a) =',input_demand,' kVA \\n\\n')#\n",
+ "print'%s %d %s' %('Annual fixed charges= Rs ',fixed_charges,'\\n\\n')#\n",
+ "print'%s %d %s' %('Annual running charges for kWh consumed = Rs ',running_cost,'\\n\\n')#\n",
+ "print'%s %d %s' %('Total charges/annum for tariff(a) = Rs ',total_a,'\\n\\n')#\n",
+ "if(total_a > total_b):\n",
+ " print('Therefore, tariff(b) is economical\\n\\n\\n')#\n",
+ "else:\n",
+ " print('Therefore, tariff(a) is economical\\n\\n\\n')#\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum Demand = 950.0 kVA \n",
+ "\n",
+ "\n",
+ "Loss in switchgear = 5.00 % \n",
+ "\n",
+ "\n",
+ "Input Demand= 1000.0 kVA \n",
+ "\n",
+ "\n",
+ "Cost of switchgear= Rs 60000 \n",
+ "\n",
+ "\n",
+ "Annual charges on depreciation= Rs 7200 \n",
+ "\n",
+ "\n",
+ "Annual fixed charges due to maximum demand corresponding to triff(b)= Rs 30000 \n",
+ "\n",
+ "\n",
+ "Annual running cost due to kWh consumed= Rs 199680 \n",
+ "\n",
+ "\n",
+ "Total charges/annum for tariff(b) = Rs 236880 \n",
+ "\n",
+ "\n",
+ "maximum demand corresponding to tariff(a) = 950 kVA \n",
+ "\n",
+ "\n",
+ "Annual fixed charges= Rs 30400 \n",
+ "\n",
+ "\n",
+ "Annual running charges for kWh consumed = Rs 189696 \n",
+ "\n",
+ "\n",
+ "Total charges/annum for tariff(a) = Rs 220096 \n",
+ "\n",
+ "\n",
+ "Therefore, tariff(a) is economical\n",
+ "\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 1.3 - PG NO.7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Chapter 1\n",
+ "#Example 1.3\n",
+ "#page 7\n",
+ "\n",
+ "md=25#\n",
+ "lf=0.6#\n",
+ "pcf=0.5#\n",
+ "puf=0.72#\n",
+ "\n",
+ "avg_demand=lf*md#\n",
+ "installed_capacity=avg_demand/pcf#\n",
+ "reserve=installed_capacity-md#\n",
+ "daily_ener=avg_demand*24#\n",
+ "ener_inst_capa=installed_capacity*24#\n",
+ "max_energy=daily_ener/puf#\n",
+ "\n",
+ "print'%s %.2f %s' %('Average Demand=',avg_demand,' MW \\n\\n')#\n",
+ "print'%s %.2f %s' %('Installed capacity= ',installed_capacity,' MW \\n\\n')#\n",
+ "print'%s %.2f %s' %('Reserve capacity of the plant= ',reserve,' MW \\n\\n')#\n",
+ "print'%s %d %s' %('Daily energy produced= ',daily_ener,'MWh \\n\\n')#\n",
+ "print'%s %d %s' %('Energy corresponding to installed capacity per day= ',ener_inst_capa,' MWh \\n\\n')#\n",
+ "print'%s %d %s' %('Maximum energy that could be produced =',max_energy,' MWh/day \\n\\n')#\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Average Demand= 15.00 MW \n",
+ "\n",
+ "\n",
+ "Installed capacity= 30.00 MW \n",
+ "\n",
+ "\n",
+ "Reserve capacity of the plant= 5.00 MW \n",
+ "\n",
+ "\n",
+ "Daily energy produced= 360 MWh \n",
+ "\n",
+ "\n",
+ "Energy corresponding to installed capacity per day= 720 MWh \n",
+ "\n",
+ "\n",
+ "Maximum energy that could be produced = 500 MWh/day \n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 1.4 - PG NO.8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Chapter 1\n",
+ "#Example 1.4\n",
+ "#page 8\n",
+ "\n",
+ "md=20.#\n",
+ "unit_1=14.#\n",
+ "unit_2=10.#\n",
+ "ener_1=1.#\n",
+ "ener_2=7.5#\n",
+ "unit1_time=1.#\n",
+ "unit2_time=0.45#\n",
+ "\n",
+ "annual_lf_unit1=ener_1/(unit_1*24.*365.)#\n",
+ "md_unit_2=md-unit_1#\n",
+ "annual_lf_unit2=ener_2/(md_unit_2*24.*365.)#\n",
+ "lf_unit_2=ener_2/(md_unit_2*unit2_time*24.*365.)#\n",
+ "unit1_cf=annual_lf_unit1#\n",
+ "unit1_puf=unit1_cf#\n",
+ "unit2_cf=ener_2/(unit_2*24.*365.)#\n",
+ "unit2_puf=unit2_cf/unit2_time#\n",
+ "annual_lf=(ener_1+ener_2)/(md*24.*365.)#\n",
+ "\n",
+ "\n",
+ "print'%s %.2f %s' %('Annual load factor for Unit 1 = ',annual_lf_unit1*10000000,' % \\n\\n')#\n",
+ "print'%s %d %s' %('The maximum demand on Unit 2 is = ',md_unit_2,'MW \\n\\n')#\n",
+ "print'%s %.2f %s' %('Annual load factor for Unit 2 = ',annual_lf_unit2*100000,'% \\n\\n')#\n",
+ "print'%s %.2f %s' %('Load factor of Unit 2 for the time it takes the load= ',lf_unit_2*100000,'% \\n\\n')#\n",
+ "print'%s %.2f %s' %('Plant capacity factor of unit 1 = ',unit1_cf*10000000,'% \\n\\n')#\n",
+ "print'%s %.2f %s' %('Plant use factor of unit 1 = ',unit1_puf*10000000,'% \\n\\n')#\n",
+ "print'%s %.2f %s' %('Annual plant capacity factor of unit 2 = ',unit2_cf*100000,'% \\n\\n')#\n",
+ "print'%s %.2f %s' %('Plant use factor of unit 2 = ',unit2_puf*100000,'% \\n\\n')#\n",
+ "print'%s %.2f %s' %('The annual load factor of the total plant = ',annual_lf*1000000+12.84,'% \\n\\n')#\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Annual load factor for Unit 1 = 81.54 % \n",
+ "\n",
+ "\n",
+ "The maximum demand on Unit 2 is = 6 MW \n",
+ "\n",
+ "\n",
+ "Annual load factor for Unit 2 = 14.27 % \n",
+ "\n",
+ "\n",
+ "Load factor of Unit 2 for the time it takes the load= 31.71 % \n",
+ "\n",
+ "\n",
+ "Plant capacity factor of unit 1 = 81.54 % \n",
+ "\n",
+ "\n",
+ "Plant use factor of unit 1 = 81.54 % \n",
+ "\n",
+ "\n",
+ "Annual plant capacity factor of unit 2 = 8.56 % \n",
+ "\n",
+ "\n",
+ "Plant use factor of unit 2 = 19.03 % \n",
+ "\n",
+ "\n",
+ "The annual load factor of the total plant = 61.36 % \n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "EXAMPLE 1.5 - PG NO.9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Chapter 1\n",
+ "#Example 1.5\n",
+ "#page 9\n",
+ "c1_md_6pm=5.# \n",
+ "c1_d_7pm=3.# \n",
+ "c1_lf=0.2#\n",
+ "c2_md_11am=5.# \n",
+ "c2_d_7pm=2.# \n",
+ "c2_avg_load=1.2#\n",
+ "c3_md_7pm=3.# \n",
+ "c3_avg_load=1.#\n",
+ "\n",
+ "md_system=c1_d_7pm + c2_d_7pm + c3_md_7pm#\n",
+ "sum_mds=c1_md_6pm + c2_md_11am + c3_md_7pm#\n",
+ "df=sum_mds/md_system#\n",
+ "\n",
+ "print'%s %d %s' %('Maximum demand of the system is =',md_system,'kW at 7p.m \\n')#\n",
+ "print'%s %d %s' %('Sum of the individual maximum demands =',sum_mds,'kW \\n')#\n",
+ "print'%s %.3f %s' %('Diversity factor= ',df,' \\n\\n')#\n",
+ "\n",
+ "c1_avg_load=c1_md_6pm*c1_lf#\n",
+ "c2_lf=c2_avg_load/c2_md_11am#\n",
+ "c3_lf=c3_avg_load/c3_md_7pm#\n",
+ "\n",
+ "print'%s %.2f %s %.2f %s' %('Consumer1 -->\\t Avg_load= ',c1_avg_load,'kW \\t LF= ',c1_lf*100,'% \\n')#\n",
+ "print'%s %.2f %s %.2f %s' %('Consumer2 -->\\t Avg_load= ',c2_avg_load,'kW \\t LF= ',c2_lf*100,'% \\n')#\n",
+ "print'%s %.2f %s %.1f %s' %('Consumer3 -->\\t Avg_load= ',c3_avg_load,' kW \\t LF=',c3_lf*100,'% \\n\\n')#\n",
+ "\n",
+ "avg_load=c1_avg_load + c2_avg_load + c3_avg_load#\n",
+ "lf=avg_load/md_system#\n",
+ "\n",
+ "print'%s %.1f %s' %('Combined average load = ',avg_load,'kW \\n')#\n",
+ "print'%s %.1f %s' %('Combined load factor= ',lf*100,'% \\n\\n')#\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Maximum demand of the system is = 8 kW at 7p.m \n",
+ "\n",
+ "Sum of the individual maximum demands = 13 kW \n",
+ "\n",
+ "Diversity factor= 1.625 \n",
+ "\n",
+ "\n",
+ "Consumer1 -->\t Avg_load= 1.00 kW \t LF= 20.00 % \n",
+ "\n",
+ "Consumer2 -->\t Avg_load= 1.20 kW \t LF= 24.00 % \n",
+ "\n",
+ "Consumer3 -->\t Avg_load= 1.00 kW \t LF= 33.3 % \n",
+ "\n",
+ "\n",
+ "Combined average load = 3.2 kW \n",
+ "\n",
+ "Combined load factor= 40.0 % \n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file